Lease committed XMem section pages for GPU access #2272

Merged
R0Y00 merged 2 commits from upstream-pr/2280 into main 2026-11-25 09:41:40 +00:00
R0Y00 commented 2026-11-25 09:29:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T09:29:52Z.


Refs #1914.

Add a versioned in-process XMem section lease for a bounded span of committed mirrored pages. The lease requires matching CPU and mirrored page identities and consecutive physical slots in one section. Callers can map just those slots as one view and open it as a desktop D3D12 heap. Unmapping and freeing the original grant leaves the slots pinned until the caller releases the lease after GPU completion. Existing export names and ordinals 1–18 are preserved.

The fixture uses the XMem shim’s own section pool. WARP and the RTX 4060 Laptop GPU (driver 616.56, Windows 11 build 26200.9974, D3D12 debug layer) read and write the same 4,096 bytes across two 64 KiB pages. It checks late CPU writes, a remap before GPU submission, fence-delayed reuse and zeroing, and refusal of holes, reversed slots, a wrong address space, a wrong ABI version, a wrong structure size, and repeated release.

cmake --build --preset release --target xmem_section_lease_check xmem_lazy_imports_check xmem_startup_below_40_check
ctest --preset release --no-tests=error -R '^xmem_(section_lease_|shim_mapped_pages$|shim_page_runs$|lazy_imports$|startup_below_40$)' --output-on-failure

Six tests passed with zero skips. dumpbin /exports checked the existing export names and ordinals against the base definition.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6601371309 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2280). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T09:29:52Z. --- Refs #1914. Add a versioned in-process XMem section lease for a bounded span of committed mirrored pages. The lease requires matching CPU and mirrored page identities and consecutive physical slots in one section. Callers can map just those slots as one view and open it as a desktop D3D12 heap. Unmapping and freeing the original grant leaves the slots pinned until the caller releases the lease after GPU completion. Existing export names and ordinals 1–18 are preserved. The fixture uses the XMem shim’s own section pool. WARP and the RTX 4060 Laptop GPU (driver 616.56, Windows 11 build 26200.9974, D3D12 debug layer) read and write the same 4,096 bytes across two 64 KiB pages. It checks late CPU writes, a remap before GPU submission, fence-delayed reuse and zeroing, and refusal of holes, reversed slots, a wrong address space, a wrong ABI version, a wrong structure size, and repeated release. ```powershell cmake --build --preset release --target xmem_section_lease_check xmem_lazy_imports_check xmem_startup_below_40_check ctest --preset release --no-tests=error -R '^xmem_(section_lease_|shim_mapped_pages$|shim_page_runs$|lazy_imports$|startup_below_40$)' --output-on-failure ``` Six tests passed with zero skips. `dumpbin /exports` checked the existing export names and ordinals against the base definition.
tedin7 commented 2026-11-25 09:32:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:32:58Z.

Review: COMMENTED


Review of head 5d20b85875ec6304ff23bfe52a74134a47f95da4 (comment only, no approval).

Scope: src/xmem_mapped_pages.cpp, new src/xmem_section_lease.h, xmem_shim.def (+2 exports), new tests/xmem_section_lease_check.cpp, CMake, docs/experiments.md. Mergeable; title is neutral; no clean-room concerns seen.

Commands executed locally (Linux worktree of the PR head)

  • git diff --stat origin/main...HEAD: 6 files, +289/-1.
  • python3 tests/docs_links_check.py: passed (18 files, 435 links).
  • python3 tests/bidi_controls_check.py: passed (1568 files).
  • git diff --check origin/main...HEAD: clean.
  • gh pr checks 2280: "Run platform-independent Python checks on Linux" is red. The log shows TypeError: 'NoneType' object is not an iterator at tools/mesh_entry_aot.py:882 (next(steps)), hit by tests/mesh_dynamic_geometry_check.py and tests/mesh_dynamic_aot_check.py. This PR touches none of those files, so it looks like a failure that is not caused by this change. The branch is also 2 commits behind main, so a rebase and a re-run are worth doing. The Windows jobs were still pending when I looked.

Logic read (P1/P2)

  • P1: none found.
  • P2: none found. The pin and retire flow is consistent. free_pages marks a pinned slot retired and does not release it. unpin_slot releases it on the last reference. Lease rollback after bad_alloc unpins exactly the pinned count and closes the duplicate handle. I could not trigger a leak or a double release by reading it.

Nits

  1. src/xmem_mapped_pages.cpp x2w_xmem_lease_section: first = address & ~(page_bytes - 1) aligns the absolute GPU address. This is only right if mirror_gpu is 64 KiB aligned. Aligning offset instead (mirror_gpu + (offset & ~(page_bytes-1))) would not depend on that. The test's reservation is aligned, so this passes today.
  2. unpin_slot dereferences pins.find(slot) without an end() check. It holds today because every lease slot was pinned under the same lock. A debug assert would document that.
  3. Leases still open at process exit are not reported. A count in x2w_xmem_slab_stats would make leaks visible.

Not run

  • The new D3D12 fixture (xmem_section_lease_{warp,hardware}) is Windows-only, so I did not run it. I did not run a Win2025 job: the code is C++ runtime with no shader lowering, and the Windows CI jobs cover the build.
  • Mutation testing needs a Windows build, so I did not run it. I suggest mutating the retire path in free_pages. Make it release the slot even when it is pinned, then check that the fixture's "late CPU update after free" assertion fails.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055033168 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2280#pullrequestreview-6055033168). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T09:32:58Z. **Review:** COMMENTED --- Review of head `5d20b85875ec6304ff23bfe52a74134a47f95da4` (comment only, no approval). **Scope**: `src/xmem_mapped_pages.cpp`, new `src/xmem_section_lease.h`, `xmem_shim.def` (+2 exports), new `tests/xmem_section_lease_check.cpp`, CMake, `docs/experiments.md`. Mergeable; title is neutral; no clean-room concerns seen. **Commands executed locally (Linux worktree of the PR head)** - `git diff --stat origin/main...HEAD`: 6 files, +289/-1. - `python3 tests/docs_links_check.py`: passed (18 files, 435 links). - `python3 tests/bidi_controls_check.py`: passed (1568 files). - `git diff --check origin/main...HEAD`: clean. - `gh pr checks 2280`: "Run platform-independent Python checks on Linux" is red. The log shows `TypeError: 'NoneType' object is not an iterator` at `tools/mesh_entry_aot.py:882` (`next(steps)`), hit by `tests/mesh_dynamic_geometry_check.py` and `tests/mesh_dynamic_aot_check.py`. This PR touches none of those files, so it looks like a failure that is not caused by this change. The branch is also 2 commits behind main, so a rebase and a re-run are worth doing. The Windows jobs were still pending when I looked. **Logic read (P1/P2)** - P1: none found. - P2: none found. The pin and retire flow is consistent. `free_pages` marks a pinned slot retired and does not release it. `unpin_slot` releases it on the last reference. Lease rollback after `bad_alloc` unpins exactly the `pinned` count and closes the duplicate handle. I could not trigger a leak or a double release by reading it. **Nits** 1. `src/xmem_mapped_pages.cpp` `x2w_xmem_lease_section`: `first = address & ~(page_bytes - 1)` aligns the absolute GPU address. This is only right if `mirror_gpu` is 64 KiB aligned. Aligning `offset` instead (`mirror_gpu + (offset & ~(page_bytes-1))`) would not depend on that. The test's reservation is aligned, so this passes today. 2. `unpin_slot` dereferences `pins.find(slot)` without an `end()` check. It holds today because every lease slot was pinned under the same lock. A debug assert would document that. 3. Leases still open at process exit are not reported. A count in `x2w_xmem_slab_stats` would make leaks visible. **Not run** - The new D3D12 fixture (`xmem_section_lease_{warp,hardware}`) is Windows-only, so I did not run it. I did not run a Win2025 job: the code is C++ runtime with no shader lowering, and the Windows CI jobs cover the build. - Mutation testing needs a Windows build, so I did not run it. I suggest mutating the retire path in `free_pages`. Make it release the slot even when it is pinned, then check that the fixture's "late CPU update after free" assertion fails. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 09:42:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:42:13Z.

Review: COMMENTED


Re-review of head 4e4c2777b7c397f896770994feb92512b30b78fc (comment only, no approval). My earlier review was on 5d20b85.

What changed since the last review

  • The new head is a merge of main into the branch. The six PR files (CMakeLists.txt, docs/experiments.md, src/xmem_mapped_pages.cpp, src/xmem_section_lease.h, src/xmem_shim.def, tests/xmem_section_lease_check.cpp) are byte-identical to 5d20b85: git diff 5d20b85 HEAD -- <those files> is empty.
  • The other files in the delta (README.md, docs/startup-runtime.md, src/startup_stubs/gameinput.cpp, tests/startup_gameinput_contracts_check.cpp, tools/mesh_entry_aot.py) come from main, not from this PR. The PR diff against main is still 6 files, +289/-1.

Commands executed locally (Linux worktree of this head)

  • git diff --stat origin/main...HEAD: 6 files, +289/-1.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: passed (18 files, 435 links).
  • python3 tests/bidi_controls_check.py: passed (1568 files).
  • gh pr checks 2280: "Run platform-independent Python checks on Linux" now passes. The mesh_entry_aot.py failure I reported before was fixed on main and is gone after the merge. "Build and test on Windows" and "Assemble and translate gfx1013 fixtures" also pass. The /O2 job and the chart job are skipped.
  • Re-read the lease, release and free_pages retire logic: unchanged, and my earlier conclusions still hold.

Findings

  • P1: none.
  • P2: none.
  • The three nits from my earlier review are still open and optional. (1) Align offset rather than the absolute address in x2w_xmem_lease_section. (2) Add a debug assert for pins.find() in unpin_slot. (3) Report open leases in the slab stats.

Not run

  • The D3D12 fixture xmem_section_lease_{warp,hardware} is Windows-only. I read it but did not run it. The Windows CI build passes.
  • A mutation run needs an MSVC build. The MinGW syntax check fails in src/startup_stubs/local_log.h on __except, which is unrelated to this PR. I ran no mutation. I still suggest mutating the retire path in free_pages (always release) to confirm the fixture catches it.
  • No Win2025 job: the change is C++ runtime code with no shader lowering.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055163258 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2280#pullrequestreview-6055163258). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T09:42:13Z. **Review:** COMMENTED --- Re-review of head `4e4c2777b7c397f896770994feb92512b30b78fc` (comment only, no approval). My earlier review was on `5d20b85`. **What changed since the last review** - The new head is a merge of main into the branch. The six PR files (`CMakeLists.txt`, `docs/experiments.md`, `src/xmem_mapped_pages.cpp`, `src/xmem_section_lease.h`, `src/xmem_shim.def`, `tests/xmem_section_lease_check.cpp`) are byte-identical to `5d20b85`: `git diff 5d20b85 HEAD -- <those files>` is empty. - The other files in the delta (`README.md`, `docs/startup-runtime.md`, `src/startup_stubs/gameinput.cpp`, `tests/startup_gameinput_contracts_check.cpp`, `tools/mesh_entry_aot.py`) come from main, not from this PR. The PR diff against main is still 6 files, +289/-1. **Commands executed locally (Linux worktree of this head)** - `git diff --stat origin/main...HEAD`: 6 files, +289/-1. - `git diff --check origin/main...HEAD`: clean. - `python3 tests/docs_links_check.py`: passed (18 files, 435 links). - `python3 tests/bidi_controls_check.py`: passed (1568 files). - `gh pr checks 2280`: "Run platform-independent Python checks on Linux" now passes. The `mesh_entry_aot.py` failure I reported before was fixed on main and is gone after the merge. "Build and test on Windows" and "Assemble and translate gfx1013 fixtures" also pass. The /O2 job and the chart job are skipped. - Re-read the lease, release and `free_pages` retire logic: unchanged, and my earlier conclusions still hold. **Findings** - P1: none. - P2: none. - The three nits from my earlier review are still open and optional. (1) Align `offset` rather than the absolute address in `x2w_xmem_lease_section`. (2) Add a debug assert for `pins.find()` in `unpin_slot`. (3) Report open leases in the slab stats. **Not run** - The D3D12 fixture `xmem_section_lease_{warp,hardware}` is Windows-only. I read it but did not run it. The Windows CI build passes. - A mutation run needs an MSVC build. The MinGW syntax check fails in `src/startup_stubs/local_log.h` on `__except`, which is unrelated to this PR. I ran no mutation. I still suggest mutating the retire path in `free_pages` (always release) to confirm the fixture catches it. - No Win2025 job: the change is C++ runtime code with no shader lowering. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 10:05:30 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2272
No description provided.