1. 24 Sep, 2021 1 commit
  2. 21 Sep, 2021 1 commit
  3. 10 Sep, 2021 1 commit
  4. 08 Sep, 2021 1 commit
    • Clemens Backes's avatar
      [wasm] Add unit tests for code protection · c9704cf7
      Clemens Backes authored
      This adds some basic tests for WebAssembly code protection, in four
      different configurations:
      - no protection
      - mprotect-based protection
      - PKU-based protection
      - PKU with fallback to mprotect
      
      If PKU is not supported by the OS or hardware, then PKU is identical to
      no protection, and PKU with fallback is identical to mprotect. We always
      execute all four configurations anyway.
      If protection is effective, we expect code to be writable within a
      {CodeSpaceWriteScope}, and not writable otherwise. When trying to write
      to non-writable code, we expect a crash of the process (checked via
      {ASSERT_DEATH_IF_SUPPORTED}).
      
      R=jkummerow@chromium.org
      CC=​mpdenton@chromium.org
      
      Bug: v8:11974
      Cq-Include-Trybots: luci.v8.try:v8_mac_arm64_rel_ng
      Cq-Include-Trybots: luci.v8.try:v8_mac_arm64_dbg_ng
      Change-Id: I4ec0ce9426f70ff41a292b9ea25be1e8956a670e
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3138210
      Commit-Queue: Clemens Backes <clemensb@chromium.org>
      Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#76726}
      c9704cf7
  5. 03 Sep, 2021 1 commit
  6. 01 Sep, 2021 1 commit
  7. 17 Aug, 2021 1 commit
  8. 11 Aug, 2021 1 commit
    • Clemens Backes's avatar
      [wasm] Disable permission switching if MAP_JIT is available · 2890419f
      Clemens Backes authored
      The combination of --wasm-write-protect-code-memory and MAP_JIT was not
      handled correctly. We were trying to unnecessarily switch permissions,
      and a DCHECK was failing because the writers count was not increased
      previously (because the {CodeSpaceWriteScope} uses a separate
      implementation if MAP_JIT is available).
      
      This CL fixes the issues by explicitly setting
      {WasmCodeAllocator::protect_code_memory_} to false if MAP_JIT is being
      used.
      
      R=jkummerow@chromium.org
      
      Bug: v8:12070
      Change-Id: Ifb05ba01f8e2e7781d7c29fe80d1144a3d65543b
      Cq-Include-Trybots: luci.v8.try:v8_mac_arm64_rel_ng
      Cq-Include-Trybots: luci.v8.try:v8_mac_arm64_dbg_ng
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3089159Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Commit-Queue: Clemens Backes <clemensb@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#76233}
      2890419f
  9. 09 Aug, 2021 1 commit
    • Clemens Backes's avatar
      [wasm] Only make needed regions writable · 0e447c4a
      Clemens Backes authored
      On Windows, the overhead of {SetPermissions} (which maps to a
      {VirtualAlloc} call) heavily depends on the amount of memory on which
      permissions are switched. Hence this CL changes permission switching
      to only switch the code regions that are actually needed. This will
      increase the number of system calls, but reduce the total size of
      switched memory.
      
      On a Unity benchmark, this reduced the lazy compilation time on Windows
      from 13.7 seconds to 3.6 seconds (3.0 seconds without write protection).
      On Linux, there is no measurable effect, but permission switching
      generally seems to have way less overhead on Linux.
      
      R=jkummerow@chromium.org
      
      Bug: v8:11974
      Change-Id: I46dd4ae9997587226b3d81166cf2e1128383ab34
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3077144
      Commit-Queue: Clemens Backes <clemensb@chromium.org>
      Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#76163}
      0e447c4a
  10. 14 Jul, 2021 1 commit
  11. 13 Jul, 2021 4 commits
    • Clemens Backes's avatar
      Reland "[wasm] Fix fallback from PKU to mprotect" · 7f58edd5
      Clemens Backes authored
      This is a reland of dacce720
      
      Original change's description:
      > [wasm] Fix fallback from PKU to mprotect
      >
      > The {WasmCodeManager::SetThreadWritable} method would return true if
      > called in a nested scope, even if PKU is not available. The caller
      > cannot tell then whether permission switching happened or not.
      >
      > This CL refactors the code to do an explicit check for PKU support, and
      > removes the boolean return value from {SetThreadWritable}.
      >
      > R=jkummerow@chromium.org
      >
      > Bug: v8:11959, v8:11974
      > Change-Id: I2d45f1fa240305c6f92f63cdf190131d637bfe95
      > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021383
      > Commit-Queue: Clemens Backes <clemensb@chromium.org>
      > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
      > Cr-Commit-Position: refs/heads/master@{#75699}
      
      Bug: v8:11959, v8:11974
      Change-Id: I7086aa3f1cd12615e6f12bbd061084ecd325eb11
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021180Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Commit-Queue: Clemens Backes <clemensb@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#75707}
      7f58edd5
    • Clemens Backes's avatar
      Revert "[wasm] Fix fallback from PKU to mprotect" · f4f14bbb
      Clemens Backes authored
      This reverts commit dacce720.
      
      Reason for revert: Needs a fix.
      
      Original change's description:
      > [wasm] Fix fallback from PKU to mprotect
      >
      > The {WasmCodeManager::SetThreadWritable} method would return true if
      > called in a nested scope, even if PKU is not available. The caller
      > cannot tell then whether permission switching happened or not.
      >
      > This CL refactors the code to do an explicit check for PKU support, and
      > removes the boolean return value from {SetThreadWritable}.
      >
      > R=​jkummerow@chromium.org
      >
      > Bug: v8:11959, v8:11974
      > Change-Id: I2d45f1fa240305c6f92f63cdf190131d637bfe95
      > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021383
      > Commit-Queue: Clemens Backes <clemensb@chromium.org>
      > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
      > Cr-Commit-Position: refs/heads/master@{#75699}
      
      Bug: v8:11959, v8:11974
      Change-Id: I199cf6dd6e12a209649fcf86f922e2500b50bbde
      No-Presubmit: true
      No-Tree-Checks: true
      No-Try: true
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021179
      Auto-Submit: Clemens Backes <clemensb@chromium.org>
      Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
      Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
      Cr-Commit-Position: refs/heads/master@{#75700}
      f4f14bbb
    • Clemens Backes's avatar
      [wasm] Fix fallback from PKU to mprotect · dacce720
      Clemens Backes authored
      The {WasmCodeManager::SetThreadWritable} method would return true if
      called in a nested scope, even if PKU is not available. The caller
      cannot tell then whether permission switching happened or not.
      
      This CL refactors the code to do an explicit check for PKU support, and
      removes the boolean return value from {SetThreadWritable}.
      
      R=jkummerow@chromium.org
      
      Bug: v8:11959, v8:11974
      Change-Id: I2d45f1fa240305c6f92f63cdf190131d637bfe95
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021383
      Commit-Queue: Clemens Backes <clemensb@chromium.org>
      Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#75699}
      dacce720
    • Clemens Backes's avatar
      [wasm] Move SetThreadWritable to the WasmCodeManager · 29d7cca5
      Clemens Backes authored
      Since PKU-based switching always switches the permissions for all wasm
      code memory in the process, the method should not be on the
      {NativeModule} or {WasmCodeAllocator}, but instead on the process-wide
      {WasmCodeManager}.
      
      R=jkummerow@chromium.org
      
      Bug: v8:11974
      Change-Id: I75a82e51401b2572977c134077e1669cf5077049
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021382
      Commit-Queue: Clemens Backes <clemensb@chromium.org>
      Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#75694}
      29d7cca5
  12. 05 Jul, 2021 1 commit
  13. 24 Jun, 2021 2 commits
  14. 22 Jun, 2021 1 commit
    • Clemens Backes's avatar
      Reland "[wasm] Provide a global WasmCodeManager" · 4e19455b
      Clemens Backes authored
      This is a reland of 0f90a2aa.
      The issue was inverted destructor order between WasmCodeManager and
      WasmEngine. WasmEngine has to be destructed first, because it contains
      a barrier to ensure that background compile threads finished before
      global state is being destructed.
      
      Original change's description:
      > [wasm] Provide a global WasmCodeManager
      >
      > The WasmCodeManager was part of the WasmEngine so far, but there is only
      > exactly one WasmEngine. Hence we can pull it out, and also remove the
      > pointer in the WasmCodeAllocator.
      >
      > The argument passed from the single constructor call is now inlined in
      > the constructor itself.
      >
      > Drive-by: Replace "GetPlatformPageAllocator()->CommitPageSize()" by just
      > "CommitPageSize()".
      >
      > R=jkummerow@chromium.org
      >
      > Bug: v8:11879
      > Change-Id: I6c0e74cea308f5806d1aa479945d90b6ef8d1613
      > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972909
      > Commit-Queue: Clemens Backes <clemensb@chromium.org>
      > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
      > Cr-Commit-Position: refs/heads/master@{#75270}
      
      Bug: v8:11879
      Change-Id: I0eaa2395f5c1e30f3f7303c5f3df70c227b74d3d
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2975859
      Auto-Submit: Clemens Backes <clemensb@chromium.org>
      Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
      Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#75289}
      4e19455b
  15. 21 Jun, 2021 4 commits
    • Maya Lekova's avatar
      Revert "[wasm] Provide a global WasmCodeManager" · c46e8205
      Maya Lekova authored
      This reverts commit 0f90a2aa.
      
      Reason for revert: Breaks MSAN, please see https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux%20-%20arm64%20-%20sim%20-%20MSAN/38941/overview
      
      Original change's description:
      > [wasm] Provide a global WasmCodeManager
      >
      > The WasmCodeManager was part of the WasmEngine so far, but there is only
      > exactly one WasmEngine. Hence we can pull it out, and also remove the
      > pointer in the WasmCodeAllocator.
      >
      > The argument passed from the single constructor call is now inlined in
      > the constructor itself.
      >
      > Drive-by: Replace "GetPlatformPageAllocator()->CommitPageSize()" by just
      > "CommitPageSize()".
      >
      > R=​jkummerow@chromium.org
      >
      > Bug: v8:11879
      > Change-Id: I6c0e74cea308f5806d1aa479945d90b6ef8d1613
      > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972909
      > Commit-Queue: Clemens Backes <clemensb@chromium.org>
      > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
      > Cr-Commit-Position: refs/heads/master@{#75270}
      
      Bug: v8:11879
      Change-Id: I110eec313762d73073f530aec7cf0be82c4db344
      No-Presubmit: true
      No-Tree-Checks: true
      No-Try: true
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972921
      Auto-Submit: Maya Lekova <mslekova@chromium.org>
      Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
      Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
      Cr-Commit-Position: refs/heads/master@{#75274}
      c46e8205
    • Daniel Lehmann's avatar
      [wasm] Merge code space write scope implementations · 8a3c4881
      Daniel Lehmann authored
      Merges `NativeModuleModificationScope` (with an implementation using
      Intel PKU, if available, and mprotect otherwise) and
      `CodeSpaceWriteScope` (for Apple Silicon, where switching to RWX with
      mprotect is disallowed anyway, so MAP_JIT and thread-local switching
      must be used).
      
      Because `CodeSpaceWriteScope` sounded better (and is shorter), we kept
      its name (which unfortunately makes the diff a bit harder to read).
      
      R=clemensb@chromium.org
      CC=jkummerow@chromium.org
      
      Bug: v8:11714
      
      Cq-Include-Trybots: luci.v8.try:v8_linux64_fyi_rel_ng
      Change-Id: Ib2a7d18e72797a725ed34b904c70769166d811dd
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972911Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
      Commit-Queue: Daniel Lehmann <dlehmann@google.com>
      Cr-Commit-Position: refs/heads/master@{#75272}
      8a3c4881
    • Clemens Backes's avatar
      [wasm] Provide a global WasmCodeManager · 0f90a2aa
      Clemens Backes authored
      The WasmCodeManager was part of the WasmEngine so far, but there is only
      exactly one WasmEngine. Hence we can pull it out, and also remove the
      pointer in the WasmCodeAllocator.
      
      The argument passed from the single constructor call is now inlined in
      the constructor itself.
      
      Drive-by: Replace "GetPlatformPageAllocator()->CommitPageSize()" by just
      "CommitPageSize()".
      
      R=jkummerow@chromium.org
      
      Bug: v8:11879
      Change-Id: I6c0e74cea308f5806d1aa479945d90b6ef8d1613
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972909
      Commit-Queue: Clemens Backes <clemensb@chromium.org>
      Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#75270}
      0f90a2aa
    • Daniel Lehmann's avatar
      [wasm] Move NativeModuleModificationScope impl · 2ef8f917
      Daniel Lehmann authored
      In an effort to merge `CODE_SPACE_WRITE_SCOPE` and
      `NativeModuleModificationScope`, this CL moves the interface and
      implementation of the latter into code-space-access.{h,cc}, where the
      former already lives. No other changes to the code itself.
      
      R=clemensb@chromium.org
      CC=jkummerow@chromium.org
      
      Bug: v8:11714
      
      Cq-Include-Trybots: luci.v8.try:v8_linux64_fyi_rel_ng
      Change-Id: I1aabce26f2033430523a7a3a0a4864e7267bee21
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972803Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
      Commit-Queue: Daniel Lehmann <dlehmann@google.com>
      Cr-Commit-Position: refs/heads/master@{#75267}
      2ef8f917
  16. 18 Jun, 2021 2 commits
  17. 16 Jun, 2021 1 commit
  18. 15 Jun, 2021 1 commit
  19. 14 Jun, 2021 2 commits
  20. 07 Jun, 2021 2 commits
  21. 02 Jun, 2021 2 commits
  22. 27 May, 2021 1 commit
    • Manos Koukoutos's avatar
      [wasm-gc] Implement array.copy (experimental) · dfdc8f68
      Manos Koukoutos authored
      Changes:
      - Add --experimental-wasm-gc-experiments flag.
      - Add array.copy opcode. Implement it in decoding and code generation
        behind the new flag.
      - Add WasmCodeBuilder::BoundsCheckArrayCopy. Move BoundsCheckArray to
        the private section.
      - Add WasmArrayCopy and WasmArrayCopyWithChecks builtin.
      - Add WasmArrayCopy runtime function.
      - Add WasmArray::ElementSlot.
      - Always print two hex digits in CHECK_PROTOTYPE_OPCODE.
      - In test-gc, print the thrown-error message if the function should not
        throw.
      - In test-gc, add GetResultObject with one argument.
      
      Bug: v8:7748
      Change-Id: I58f4d37e254154596cdef5e78482b55260dd3782
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2912729
      Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
      Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#74806}
      dfdc8f68
  23. 26 May, 2021 1 commit
  24. 25 May, 2021 1 commit
  25. 20 May, 2021 1 commit
  26. 19 May, 2021 1 commit
  27. 18 May, 2021 1 commit
  28. 17 May, 2021 1 commit
  29. 11 May, 2021 1 commit
    • Daniel Lehmann's avatar
      [wasm] Use PKUs for code space write protection · 826642c7
      Daniel Lehmann authored
      This is the second CL in a line of two to implement PKU-based
      WebAssembly code space write protection. The first CL added two
      low-level PKU functions; this CL uses them to grant/withdraw writable
      permissions, local to each thread that wants to modify the code space.
      
      In particular, when {--wasm-memory-protection-keys} is enabled, we first
      associate a memory protection key with all code pages, which by
      default does not allow any write access. Then, before each location that
      needs to modify the code space, we open
      {NativeModuleModificationScope}s (which are already present for
      mprotect-based write protection). When the PKU flag is given, this then
      first tries to set permissions of a memory protection key (which is
      fast), and otherwise when {--wasm-write-protect-code-memory} is enabled,
      falls back to mprotect-based write protection (which is much more
      expensive and also not thread-local, but for the whole process).
      
      R=clemensb@chromium.org
      
      Bug: v8:11714
      Change-Id: I3527906a8d9f776ed44c8d5db52539e78e1c52fd
      Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2882800
      Commit-Queue: Daniel Lehmann <dlehmann@google.com>
      Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#74501}
      826642c7