xmem: a slot-31 copy leaves the title's own mappings at the paired CPU range (RT-SLOT31-CPU-TWIN-TITLE-PAGES) #1972
Closed
leonida/mandy
kurrutako wants to merge 0 commits from
rt/slot31-cpu-twin-title-pages into main
pull from: rt/slot31-cpu-twin-title-pages
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!1972
Loading…
Reference in a new issue
No description provided.
Delete branch "rt/slot31-cpu-twin-title-pages"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: RT-SLOT31-CPU-TWIN-TITLE-PAGES
What and why
copy_page_mappings(queue slot 31,CopyPageMappingsBatchX) mirrors every page it maps or unmaps at a GPU-only destination onto the paired CPU range (title_gpu_views::to_cpu, from 255f17001). It did this even where the title had mapped that CPU page itself. A copy replaced the title's page, and an unmap (kind 2) left the title's CPU page only reserved. The title's next read of it was a fault in a window, left to the title, and the run ended. The commit that added the mirror names this risk: if the pairing is wrong, "the mirror replaces the title's own mappings in that CPU range".The console's
CopyPageMappingsBatchXedits only the GPU-only range's page table. So a CPU page that holds one of the title's own mappings (XMemMapPhysicalPages,XMemMapPhysicalPagesScatter, or a slot-31 copy onto that address) is now left as it is. Pages the mirror made itself, zero plants and pages with no mapping still follow the GPU-only range, so the D3D12 layer's reads at the CPU view still work. Each page left alone is counted, and the first ones are logged.The unmaps on these paths now carry their own label in the read-fault report, instead of the default
unmap:CopyPageMappingsBatchX: unmap, paired CPU page, remap, holeXMemMapPhysicalPagesScatter: unmap, remapTested
xmem_test(MSVC, RelWithDebInfo):test_copy_page_mappings_cpu_viewgains two checks. A copy onto, and an unmap of, a GPU-only page whose paired CPU page the title mapped must keep the title's bytes at the CPU page. Both checks fail on the old code and the whole test passes with the fix.Retail boot, own copy, RTX 5070: current
mainplus #1851, #1827, #1849, #1862 and #1886, Series S device type, same switches every time.scattermappingsBefore the change, each read fault's report matched a default-cause unmap of the same page 0.7–1.9 s earlier. The screen stays black at about 0.4 frames/s at this stage, as it did before the change. One boot is not proof that the crash is gone, but none of these reads came back.
GPUs tested: NVIDIA RTX 5070
AI-assisted.
Checklist
mainand merges cleanly.🤖 Generated with Claude Code
Retail result for this in the world phase (RTX 5080, NVIDIA 621.24, Windows 11), with
LEONIDA_POOL_ZERO_PAGESunset. Without it, two runs with fast submissions ended the way you describe (exe+0x465a75on an uncommitted page at 154 s; withLEONIDA_POOL_ZERO_PAGES=1,+0x17df6cwith "unmap ... ms ago 1016" and then a null read at+0x22bfc0at 139 s), and a third had 18 zero plants before I stopped it. With this: no title read fault and no zero plant in 417 s, stopped by me. One run.A helper of mine came to the same function from the logs and wrote a version with a clock instead of the owner check (keep only pages the title mapped after the remap was queued); yours was open first and is simpler, so I use yours and will not send mine. In the runs that failed, the log counted deferred remaps (7, 8 and 4 in three of them, 0 in the runs that did not fail), which fits a remap that runs late.
xmem_testpasses with this merged. AI-assisted (Claude Code).Second retail boot with this change, same setup: it ran 1,739 s with the game still submitting (about 30,000 submissions in all) until I closed the window, and the process exited with code 0. It logged no title read faults and 9 faults left to the title. The five boots before the change ended by themselves after 210 to 1,308 s.
Thanks for the review. Two points I checked in the code:
set_copy_page_mappings_hook(d3d12_xmem_placed_test.cpp,xs_proxy_mock_test.cpp); nothing inruntime/srcor the shims installs it. So in a retail runqueue_copy_page_mappingsfalls back tocopy_page_mappings_default, which callsrt::xmem::copy_page_mappings_fn, the per-range function this PR changes. The batchrt::xmem::copy_page_mappingsmirrors onto the CPU view only withLEONIDA_SLOT31_CPU_TWIN=1, and itschangescheck already skips CPU pages whose view isn'tMapOwner::mirror. So the boots in the description ran the fixed route. Logging the route once is a good idea, and I'll add it.maponce the queue reaches the point. So the owner check runs when the remap is applied, not when it is queued: a CPU page the title maps in between is seen as the title's.I'll add a regression through the queue proxy's default adapter (no hook installed) that covers the case you describe: the source backed only through its CPU alias, a title-owned page at the destination's CPU twin, then a copy and an unmap. If the list-value fences can be held in that test, I'll cover the deferred order too. AI-assisted.
Tested on an RX 7900 XTX (RADV, Mesa 26.3.1, Wine) with the retail game, two runs each, same settings:
So the mirror seems to keep something on the GPU side consistent too. We're tracing which data goes stale; until then, this probably shouldn't merge as is.
AI-assisted (Claude Code, Claude Opus 5.5).
Pushed 28fc0262d, as said above:
queue_copy_page_mappingslogs once which route remaps (installed batch hook, or the default adapter overcopy_page_mappings_fn).d3d12_xmem_placed_testgainsqueue_remap_default_route. It runs with no hook, a legacy-paired destination and a pool backed only through its CPU alias. The title maps its own page at one CPU twin while the remap waits behind held queue work. After the copy and then an unmap, the GPU-only pages change and the title's page keeps its bytes.LEONIDA_LIST_VALUES=0, and on the code before this PR it fails at the title-page check.xmemandxs_proxy_mockpass too.AI-assisted.
Thanks for the new test. It shows the mechanism we suspect behind the device losses: after a copy, the GPU-only pages change while the paired CPU page keeps the title's bytes.
But the layer reads the title's GPU-only memory through that CPU view (
title_gpu_views::to_cpu, used bygeometry_vaandrebase_title_vsharp;set_independent_pagesis never called, soto_cpualways returns the CPU twin). With this PR those reads get the title's page instead of what slot 31 mapped, so geometry copies and rebased V#s can carry the wrong data: addresses or counts. That matches the wild read and the runaway work we saw. The update notices also go only to where the page is mapped (note_mapping), so those copies never refresh.A way to keep your protection of the title's pages without this: give the layer a private copy of each pair that the title never sees, with every slot-31 copy and unmap mapped there, and point
to_cpuand the update notices at it. We're adding a log of diverging pages to measure how often it happens.AI-assisted (Claude Code, Claude Opus 5.5).
Agreed, that is a real gap: with this PR, a layer read through
to_cpuat a pair whose CPU page is the title's gets the title's page, not what slot 31 mapped, andnote_mappingrefreshes only the address that was mapped. Before it, the title lost its own page instead. Neither is right where the two diverge.A private layer view per pair fits both: it has every slot-31 copy and unmap at the GPU address, and the CPU twin's page wherever slot 31 has mapped nothing (the legacy pairs, read through the CPU view today).
to_cpuand the update notices point at it, and the title's CPU range stays the title's. I can do that in this PR, unless you are writing it: tell me and I'll leave it to you.Before that, I'll make the "left the title's mapping" log say whether the title's page holds the same physical page as the copy, so a boot shows how often they really diverge. In the boots in the description every kept page was a
scattermapping. AI-assisted.I measured how often the kept CPU page really differs, using a logging-only patch on top of this PR (head
28fc0262d). At each slot-31 copy or unmap that leaves the title's mapping in place, the patch compares the physical page the title has at the CPU twin with the page the copy maps at the GPU-only address.Setup: a retail boot on the Ryzen 7000 iGPU (gfx1036, RADV, Mesa 26.3.1, Wine), headless. So far it has run 25 minutes and about 35,000 submissions, and it is still running.
to_cpuis right.So the gap is real but rare in this boot. A private layer view per pair, as you describe, covers both cases. Please go ahead with it in this PR; we aren't writing it.
AI-assisted (Claude Code, Claude Opus 5.5).
Closing for now under the new rule of one open PR until two are merged; I am keeping #1722 open. The private layer view discussed above is written, but in my retail boots it moved the faults left to the title into the GPU-only range, and one boot ended in a device loss. I will reopen this once I have found out why. Thanks for the measurements and the review.
AI-assisted (Claude Code, Claude Opus 5.5).
Thank you, @kurrutako. Although you closed this, its commits went into
mainthrough #2350 (RT-LINUX-AMD-WORLD), merged at your head28fc0262dwith your authorship kept. The build that first drew the world on Linux with an AMD GPU had it, so we kept it in.The gap discussed above is still open: a layer read through the CPU twin can see the title's page where slot 31 mapped a different one. Your private-layer-view follow-up, or another fix for that gap, is welcome as a new PR.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)