1. 16 Aug, 2022 1 commit
    • Samuel Groß's avatar
      [sandbox] Implement external pointer table compaction · 76d74489
      Samuel Groß authored
      The external pointer table is already to some degree self-compacting: as
      the freelist is sorted in ascending order, free entries at the start of
      the table should quickly fill up. However, any live entry at the end of
      the table makes it impossible to shrink the table, thereby causing
      higher memory consumption. To solve this, this CL implements a simple
      table compaction algorithm, used when the freelist has become
      sufficiently large (currently >= 10% of the table capacity):
       - The goal of the algorithm is to shrink the table by freelist_size/2
         entries at the end of compaction (during sweeping).
       - At the start of the marking phase, the compaction area is computed as
         roughly [capacity - freelist_size/2, capacity).
       - When an entry is marked as alive that lies inside the compaction
         area, a new "relocation entry" is allocated for it from the freelist
         and the address of the handle for that entry is stored in that entry.
         If there are no more free entries before the compaction area,
         compaction is aborted. This is expected to happen rarely and is
         logged into a histogram.
       - During sweeping, all relocation entries are "resolved": the content
         of the old entry is copied into the new entry and the handle is
         updated to point to the new entry.
       - Finally, the table is shrunk and the last initial_freelist_size/2
         entries are decommitted.
      
      See also the comments in the ExternalPointerTable class for more details.
      
      Bug: v8:10391
      Change-Id: I28d475c3596590e860421f0a054e2ad4dbebd487
      Cq-Include-Trybots: luci.v8.try:v8_linux64_heap_sandbox_dbg_ng,v8_linux_arm64_sim_heap_sandbox_dbg_ng
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3794645Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
      Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
      Commit-Queue: Samuel Groß <saelo@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#82484}
      76d74489
  2. 09 Aug, 2022 1 commit
  3. 28 Jul, 2022 1 commit
  4. 26 Jul, 2022 1 commit
    • Shu-yu Guo's avatar
      [sandbox] Make external ptr table usable under pointer compression · 2679a36e
      Shu-yu Guo authored
      This CL moves the external pointer table out of V8_ENABLE_SANDBOX and
      into V8_COMPRESS_POINTERS. The external pointer table is also useful
      even when not sandboxing external pointers to ease alignment
      requirements under pointer compression.
      
      It is onerous for the allocator to support non-tagged-size alignment.
      Under pointer compression, tagged is 4 bytes while system pointers are
      8 bytes. Because external pointer table indices are 4-bytes, fields that
      require natural alignment (e.g. the state field in JSAtomicsMutex) when
      the system pointer size is 8-bytes can use an indirection via the
      pointer table to ease the alignment restriction back to 4-bytes under
      pointer compression.
      
      Bug: v8:10391
      Change-Id: Iac1200e40c987128cd6a227cd279ba4dac0e5c56
      Cq-Include-Trybots: luci.v8.try:v8_linux64_pointer_compression_rel_ng
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3783076Reviewed-by: 's avatarSamuel Groß <saelo@chromium.org>
      Commit-Queue: Shu-yu Guo <syg@chromium.org>
      Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#81977}
      2679a36e
  5. 19 Jul, 2022 1 commit
  6. 11 Jul, 2022 1 commit
    • Samuel Groß's avatar
      [sandbox] Prepare ExternalPointerTable rollout · 8a59678b
      Samuel Groß authored
      This CL does the following:
      - It enables (i.e. allocates and initializes) the per-Isolate
        ExternalPointerTable when the sandbox is enabled.
      - It refactors the list of external pointer tags to mark them as
        "sandboxed" or "unsandboxed". An unsandboxed external pointer has a
        null tag.
      - It changes V8_SANDBOXED_EXTERNAL_POINTERS to now essentially just
        enable sandboxing for all available tags.
      - It modifies all low-level external pointer accessors to perform the
        ExternalPointerLookup only if the tag is non-zero and otherwise treat
        the slot as containing a raw pointer.
      
      This now allows rolling out external pointer sandboxing incrementally
      (separately for each external pointer type), which will in turn allow
      for more precise performance measurements of the impact of the sandbox.
      
      Note: when an external pointer tag is now marked as sandboxed (and
      V8_SANDBOXED_EXTERNAL_POINTERS is not enabled), the underlying slots are
      still 64-bits in size. This simplifies the implementation as we would
      otherwise need to deal with variably-sized external pointer slots. Local
      benchmarking suggests that the benefits from 32-bit external pointer
      slots are insignificant on typical benchmarks, so this should be ok.
      
      Drive-by: rename kExternalPointerSize to kExternalPointerSlotSize to
      make it more clear what it refers to (the on-heap storage size). Also
      delete CodeStubAssembler::InitializeExternalPointerField as it is not
      currently used and the implementation is fairly inefficient.
      
      Bug: v8:10391
      Change-Id: I7c38729c7e9048d737a1a8ced84749f5b1f7feab
      Cq-Include-Trybots: luci.v8.try:v8_linux64_heap_sandbox_dbg_ng,v8_linux_arm64_sim_heap_sandbox_dbg_ng
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3736447Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
      Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
      Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
      Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
      Commit-Queue: Samuel Groß <saelo@chromium.org>
      Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#81636}
      8a59678b
  7. 07 Jul, 2022 1 commit
  8. 05 Jul, 2022 3 commits
  9. 27 Jun, 2022 2 commits
  10. 23 Jun, 2022 1 commit
  11. 15 Jun, 2022 1 commit
  12. 14 Jun, 2022 1 commit
  13. 10 Jun, 2022 1 commit
  14. 08 Jun, 2022 1 commit
  15. 03 Jun, 2022 1 commit
  16. 01 Jun, 2022 1 commit
  17. 28 May, 2022 2 commits
  18. 25 May, 2022 1 commit
  19. 19 May, 2022 1 commit
  20. 17 May, 2022 1 commit
  21. 16 May, 2022 3 commits
  22. 12 May, 2022 1 commit
  23. 11 May, 2022 2 commits
  24. 09 May, 2022 2 commits
  25. 28 Apr, 2022 2 commits
    • Igor Sheludko's avatar
      Reland "[rwx][mac] Support fast W^X permission switching on Apple Silicon (M1)" · 449ece38
      Igor Sheludko authored
      This is a reland of commit 9d31f866
      There were issues with --future flag implications on M1.
      
      Original change's description:
      > [rwx][mac] Support fast W^X permission switching on Apple Silicon (M1)
      >
      > ... for V8 code space. The feature is currently disabled.
      >
      > In order to use fast W^X permission switching we must allocate
      > executable pages with readable writable executable permissions (RWX).
      > However, MacOS on ARM64 ("Apple M1"/Apple Silicon) prohibits further
      > permission changing of RWX memory pages. This means that the code page
      > headers must be allocated with RWX permissions too because otherwise
      > it wouldn't be possible to allocate a large code page over the freed
      > regular code page and vice versa.
      >
      > When enabled, the new machinery works as follows:
      >
      > 1) when memory region is reserved for allocating executable pages, the
      >    whole region is committed with RWX permissions and then decommitted,
      > 2) since reconfiguration of RWX page permissions is not allowed on
      >    MacOS on ARM64 ("Apple M1"/Apple Silicon), there must be no attempts
      >    to change them,
      > 3) the request to set RWX permissions in the executable page region
      >    just recommits the pages without changing permissions (see (1), they
      >    were already allocated as RWX and then discarded),
      > 4) in order to make executable pages inaccessible one must use
      >    OS::DiscardSystemPages() instead of OS::DecommitPages() or
      >    setting permissions to kNoAccess because the latter two are not
      >    allowed by the MacOS (see (2)).
      > 5) since code space page headers are allocated as RWX pages it's also
      >    necessary to switch between W^X modes when updating the data in the
      >    page headers (i.e. when marking, updating stats, wiring pages in
      >    lists, etc.). The new CodePageHeaderModificationScope class is used
      >    in the respective places. On unrelated configurations it's a no-op.
      >
      > The fast permission switching can't be used for V8 configuration with
      > enabled pointer compression and disabled external code space because
      > a) the pointer compression cage has to be reserved with MAP_JIT flag
      >    which is too expensive,
      > b) in case of shared pointer compression cage if the code range will
      >    be deleted while the cage is still alive then attempt to configure
      >    permissions of pages that were previously set to RWX will fail.
      >
      > This also CL extends the unmapper unit tests with permissions tracking
      > for discarded pages.
      >
      > Bug: v8:12797
      > Change-Id: Idb28cbc481306477589eee9962d2e75167d87c61
      > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3579303
      > Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
      > Reviewed-by: Clemens Backes <clemensb@chromium.org>
      > Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
      > Commit-Queue: Igor Sheludko <ishell@chromium.org>
      > Cr-Commit-Position: refs/heads/main@{#80238}
      
      Bug: v8:12797
      Change-Id: I0fe86666f31bad37d7074e217555c95900d2afba
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3610433Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
      Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
      Commit-Queue: Igor Sheludko <ishell@chromium.org>
      Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#80259}
      449ece38
    • Camillo Bruni's avatar
      [api] Rename isolate variables · 759e841a
      Camillo Bruni authored
      * Prefix all isolate variables with i_ for i::Isolate and
        v8_ for v8::Isolate
      * Change _DO_NOT_USE macro suffix to _INTERNAL
      
      Change-Id: I005efbe0192cf202741448c63a4263e6a4b1fa1b
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3610429
      Commit-Queue: Camillo Bruni <cbruni@chromium.org>
      Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
      Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#80252}
      759e841a
  26. 27 Apr, 2022 3 commits
    • Adam Klein's avatar
      Revert "[rwx][mac] Support fast W^X permission switching on Apple Silicon (M1)" · 10807c9f
      Adam Klein authored
      This reverts commit 9d31f866.
      
      Reason for revert: crashes on Mac/arm64 bots:
      https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Mac%20-%20arm64%20-%20debug/5923/overview
      
      Original change's description:
      > [rwx][mac] Support fast W^X permission switching on Apple Silicon (M1)
      >
      > ... for V8 code space. The feature is currently disabled.
      >
      > In order to use fast W^X permission switching we must allocate
      > executable pages with readable writable executable permissions (RWX).
      > However, MacOS on ARM64 ("Apple M1"/Apple Silicon) prohibits further
      > permission changing of RWX memory pages. This means that the code page
      > headers must be allocated with RWX permissions too because otherwise
      > it wouldn't be possible to allocate a large code page over the freed
      > regular code page and vice versa.
      >
      > When enabled, the new machinery works as follows:
      >
      > 1) when memory region is reserved for allocating executable pages, the
      >    whole region is committed with RWX permissions and then decommitted,
      > 2) since reconfiguration of RWX page permissions is not allowed on
      >    MacOS on ARM64 ("Apple M1"/Apple Silicon), there must be no attempts
      >    to change them,
      > 3) the request to set RWX permissions in the executable page region
      >    just recommits the pages without changing permissions (see (1), they
      >    were already allocated as RWX and then discarded),
      > 4) in order to make executable pages inaccessible one must use
      >    OS::DiscardSystemPages() instead of OS::DecommitPages() or
      >    setting permissions to kNoAccess because the latter two are not
      >    allowed by the MacOS (see (2)).
      > 5) since code space page headers are allocated as RWX pages it's also
      >    necessary to switch between W^X modes when updating the data in the
      >    page headers (i.e. when marking, updating stats, wiring pages in
      >    lists, etc.). The new CodePageHeaderModificationScope class is used
      >    in the respective places. On unrelated configurations it's a no-op.
      >
      > The fast permission switching can't be used for V8 configuration with
      > enabled pointer compression and disabled external code space because
      > a) the pointer compression cage has to be reserved with MAP_JIT flag
      >    which is too expensive,
      > b) in case of shared pointer compression cage if the code range will
      >    be deleted while the cage is still alive then attempt to configure
      >    permissions of pages that were previously set to RWX will fail.
      >
      > This also CL extends the unmapper unit tests with permissions tracking
      > for discarded pages.
      >
      > Bug: v8:12797
      > Change-Id: Idb28cbc481306477589eee9962d2e75167d87c61
      > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3579303
      > Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
      > Reviewed-by: Clemens Backes <clemensb@chromium.org>
      > Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
      > Commit-Queue: Igor Sheludko <ishell@chromium.org>
      > Cr-Commit-Position: refs/heads/main@{#80238}
      
      Bug: v8:12797
      Change-Id: Ic07948e036db36326d464a2a901d052aa060a406
      No-Presubmit: true
      No-Tree-Checks: true
      No-Try: true
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3611665
      Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
      Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
      Auto-Submit: Adam Klein <adamk@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#80239}
      10807c9f
    • Igor Sheludko's avatar
      [rwx][mac] Support fast W^X permission switching on Apple Silicon (M1) · 9d31f866
      Igor Sheludko authored
      ... for V8 code space. The feature is currently disabled.
      
      In order to use fast W^X permission switching we must allocate
      executable pages with readable writable executable permissions (RWX).
      However, MacOS on ARM64 ("Apple M1"/Apple Silicon) prohibits further
      permission changing of RWX memory pages. This means that the code page
      headers must be allocated with RWX permissions too because otherwise
      it wouldn't be possible to allocate a large code page over the freed
      regular code page and vice versa.
      
      When enabled, the new machinery works as follows:
      
      1) when memory region is reserved for allocating executable pages, the
         whole region is committed with RWX permissions and then decommitted,
      2) since reconfiguration of RWX page permissions is not allowed on
         MacOS on ARM64 ("Apple M1"/Apple Silicon), there must be no attempts
         to change them,
      3) the request to set RWX permissions in the executable page region
         just recommits the pages without changing permissions (see (1), they
         were already allocated as RWX and then discarded),
      4) in order to make executable pages inaccessible one must use
         OS::DiscardSystemPages() instead of OS::DecommitPages() or
         setting permissions to kNoAccess because the latter two are not
         allowed by the MacOS (see (2)).
      5) since code space page headers are allocated as RWX pages it's also
         necessary to switch between W^X modes when updating the data in the
         page headers (i.e. when marking, updating stats, wiring pages in
         lists, etc.). The new CodePageHeaderModificationScope class is used
         in the respective places. On unrelated configurations it's a no-op.
      
      The fast permission switching can't be used for V8 configuration with
      enabled pointer compression and disabled external code space because
      a) the pointer compression cage has to be reserved with MAP_JIT flag
         which is too expensive,
      b) in case of shared pointer compression cage if the code range will
         be deleted while the cage is still alive then attempt to configure
         permissions of pages that were previously set to RWX will fail.
      
      This also CL extends the unmapper unit tests with permissions tracking
      for discarded pages.
      
      Bug: v8:12797
      Change-Id: Idb28cbc481306477589eee9962d2e75167d87c61
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3579303Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
      Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
      Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
      Commit-Queue: Igor Sheludko <ishell@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#80238}
      9d31f866
    • Camillo Bruni's avatar
      [runtime] DHECK that builtins correctly return the exception object · 1332c740
      Camillo Bruni authored
      Runtime and Builtin function should always return the exception object
      as a marker if there is a pending_exception on the current isolate.
      
      Change-Id: I7c255aa501800384c288664a9ca6578afbe0a103
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3610449Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
      Commit-Queue: Camillo Bruni <cbruni@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#80237}
      1332c740
  27. 26 Apr, 2022 1 commit
    • Patrick Thier's avatar
      Reland "[string] Non-transitioning shared strings" · fa1caae9
      Patrick Thier authored
      This is a reland of commit 8ba60b7a
      
      Changes to original:
      - Weaken DCHECK in MakeThin to allow direct transitions of shared
        strings during deserialization. This is safe as the string to be
        transitioned is freshly created and hasn't escaped the thread yet.
        - To enable this, add has_active_deserializer() to LocalIsolate
      
      - Shared thin string transitions are subject to the same layout changes
        as non-shared thin string transitions, thus treat them equally when
        checking if a map transition is safe.
      
      Original change's description:
      > [string] Non-transitioning shared strings
      >
      > Instead of transitioning shared strings to ThinString on
      > internalization, use a forwarding table to the internalized string and
      > store the index into the forwarding table in the string's hash field.
      >
      > This way we don't need to handle concurrent string transitions that
      > modify the underlying string data.
      >
      > During stop-the-world GC, live strings in the forwarding table are
      > migrated to regular ThinStrings.
      >
      > Bug: v8:12007
      > Change-Id: I6c6f3d41c6f644e0aaeafbf25ecec5ce0aa0d2d8
      > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3536647
      > Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
      > Reviewed-by: Jakob Linke <jgruber@chromium.org>
      > Reviewed-by: Shu-yu Guo <syg@chromium.org>
      > Reviewed-by: Igor Sheludko <ishell@chromium.org>
      > Commit-Queue: Patrick Thier <pthier@chromium.org>
      > Cr-Commit-Position: refs/heads/main@{#79801}
      
      Bug: v8:12007
      Change-Id: I022e5c4768b763a86bb28c9c82218c3b807371a0
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3571817Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
      Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
      Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
      Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
      Commit-Queue: Patrick Thier <pthier@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#80183}
      fa1caae9
  28. 22 Apr, 2022 1 commit
  29. 20 Apr, 2022 1 commit