Reland "[native] Guarantee thread safety during the map async callback."

- This is a reland of commit fd625322444f0c207ac196e258d218a9237ce72e
- Moves locking in map callback in tests. The lock should be held for
  the entire duration of the expectation handling, not only during the
  callback because the callback captures a reference to the `slot`
  which could be invalidated if the expectation states were modified.
  On top of that, it was causing a lock inversion issue under TSAN
  noted in the bug. The original lock was also incorrect because we
  would take that lock when we access all the buffers to Unmap or
  Destroy the expectation buffers, but also try to take the lock again
  in the callback. That means it could have been possible to deadlock
  if we were using AllowSpontaneous instead of AllowProcessEvents,
  i.e. imagine taking the lock, calling Unmap which spontaneously
  calls the callback which tries to take the lock again in the same
  thread.

Bug: 517692772
Original change's description:
> [native] Guarantee thread safety during the map async callback.
>
> - This change makes the pending map mutex into a recursive one so
>   that it can be held throughout the duration of the map async
>   callback. This ensures that during the callback, there cannot be
>   a race with Unmap or Destroy.
> - This addresses the security bug below by because on the server,
>   the call to GetMappedRange always happens in the scope of the map
>   async callback. This means that even if an Unmap or Destroy
>   races, either the Unmap/Destroy will happen first, thereby
>   resulting in a failed map async callback, or the callback will
>   happen first before the Unmap goes through.
> - Note that we needed to use a recursive mutex instead of a normal
>   one because otherwise, a map async callback that calls Unmap
>   would deadlock.
>
> Bug: 517692772
> Change-Id: I25068c3722a138ec3014a5b942457e5d484462ec
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/313216
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Reviewed-by: Kyle Charbonneau <kylechar@google.com>
> Commit-Queue: Loko Kung <lokokung@google.com>

Bug: 517692772
Change-Id: Ic07bacc8e99cf8305038c1489458218a3f138e6c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/313915
Auto-Submit: Loko Kung <lokokung@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
3 files changed
tree: e47721032ea12e4d302fed91a7ecfe9407138823
  1. .github/
  2. .vscode/
  3. agents/
  4. build_overrides/
  5. docs/
  6. generator/
  7. include/
  8. infra/
  9. scripts/
  10. src/
  11. test/
  12. third_party/
  13. tools/
  14. webgpu-cts/
  15. .bazelrc
  16. .bazelversion
  17. .clang-format
  18. .clang-format-ignore
  19. .clang-tidy
  20. .git-blame-ignore-revs
  21. .gitattributes
  22. .gitignore
  23. .gitmodules
  24. .gn
  25. .style.yapf
  26. .vpython3
  27. AUTHORS
  28. BUILD.bazel
  29. BUILD.gn
  30. CMakeLists.txt
  31. CMakeSettings.json
  32. CODE_OF_CONDUCT.md
  33. codereview.settings
  34. CONTRIBUTING.md
  35. CPPLINT.cfg
  36. DEPS
  37. DIR_METADATA
  38. go.mod
  39. go.sum
  40. go_presubmit_support.py
  41. LICENSE
  42. MODULE.bazel
  43. MODULE.bazel.lock
  44. OWNERS
  45. PRESUBMIT.py
  46. PRESUBMIT_test.py
  47. README.chromium
  48. README.md
  49. unsafe_buffers_paths.txt
  50. WATCHLISTS
  51. WORKSPACE.bazel
README.md

Build Status Matrix Space

Dawn, a WebGPU implementation

Dawn is an open-source and cross-platform implementation of the WebGPU standard. More precisely it implements webgpu.h that is a one-to-one mapping with the WebGPU IDL. Dawn is meant to be integrated as part of a larger system and is the underlying implementation of WebGPU in Chromium.

Dawn provides several WebGPU building blocks:

  • WebGPU C/C++ headers that applications and other building blocks use.
    • The webgpu.h version that Dawn implements.
    • A C++ wrapper for the webgpu.h.
  • A “native” implementation of WebGPU using platforms' GPU APIs: D3D12, Metal, Vulkan and OpenGL. See per API support for more details.
  • A client-server implementation of WebGPU for applications that are in a sandbox without access to native drivers
  • Tint is a compiler for the WebGPU Shader Language (WGSL) that can be used in standalone to convert shaders from and to WGSL.

Helpful links:

Documentation table of content

Developer documentation:

User documentation: (TODO, figure out what overlaps with the webgpu.h docs)

License

BSD 3-Clause License, please see LICENSE.

Disclaimer

This is not an officially supported Google product.