tests: a released page is read back without racing the tests beside it #3017
Closed
leonida/mandy
fiestorra wants to merge 0 commits from
loader-page-race into main
pull from: loader-page-race
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!3017
Loading…
Reference in a new issue
No description provided.
Delete branch "loader-page-race"
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.
tests: a released page is read back without racing the tests beside it
memory_at_names_what_an_access_hitreleases a four-page reservation and then reads one ofthe pages back to see
nothing mapped there. Another test in the same binary mapping in themicroseconds between the
VirtualFreeand the read takes that address, and the read saysread-writeinstead - which is exactly what CI did on two unrelated pull requests:The read is now over a fresh reservation released immediately before it, retried: the first
attempt whose address nobody took is the answer, and 64 taken in a row is a real failure
rather than a busy neighbour. Each attempt is a
VirtualAllocand aVirtualFreeof 4 KiB.Why not a lock: the window is between the release and the read, and the neighbour is any of
six files in this crate that map pages in their tests (
console_insn,descriptor_sites,game_actions,thunks,tls,write_sites), so a lock held by this module alone would notremove it; a crate-wide one would touch all seven. The retry costs nothing and holds whatever
the neighbour does.
What I could not do: reproduce the failure on demand.
cargo test -p leonida-loader --lib crash::testspassed 19/19 six times in a row here, so the negative control is the CI logabove and not a local red. With the change: 19/19 four more times, clippy 0.
Written with an AI assistant.
Ran the Windows leonida-loader library suite 25 times at parent 913b88b90 and 25 times at PR head a607df12e. I rebuilt at each revision with cargo test --locked -p leonida-loader --lib --no-run, then launched the resulting test executable in a fresh process each time with --test-threads 16.
All 85 tests passed in each of the 50 runs (2,125 test executions per revision). I could not reproduce the original intermittent failure on this machine, so this confirms repeated parallel passes on the PR but does not establish a reduction in flake rate.
Codex-assisted.
VERIFY-3017 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game files
Verdict: PASS. The old line reads an address back after handing it to the free pool, and anything else can already be in it; the pull request keeps the property the line was checking (a released page reads back free) and stops failing on a neighbour taking it. I reproduced the race it is defending against.
Head
a607df12, base the currentmain(0ae5a266), merge base913b88b9, 1 file, +17/−1:d3d12/crates/leonida-loader/src/crash.rs.1. What it changes
One test,
crash::tests::memory_at_names_what_an_access_hit, which reserves four pages, commits three with different protections, asks [memory_at] to name each, releases them all, and then asks what the released range is. The base asserts that directly, which is the flaky part:The release hands those pages back to the process, and a test running beside this one can take them between the
VirtualFreeand the read. The replacement makes a fresh reservation instead and treats a taken range as "try again":and it keeps the base's remaining lines,
memory_at(0),memory_at(usize::MAX)and the check that the test's own code is a read-execute image page named by its module. Everything is insidemod tests, so no production code moves.2. The new test checks the property that matters
This is test-only, so the red side (merge base plus the test hunks) compiles and passes the same way the green side does, and the harness cannot show red-then-green. Two things were worth checking instead.
First, that the race is real. I wrote a small standalone program (cross-compiled with the same toolchain and run under Wine) where one thread reserves the same range as
PAGE_READWRITE, commits it, spins, and releases it, while the main thread reserves, commits,MEM_RELEASEs and reads the range back 200 000 times:memory_atwould sayMEM_FREEnothing mapped there— 52 156, 54 991, 58 621 over three runsMEM_COMMIT/PAGE_READWRITE— 6 399, 5 882, 6 590VirtualAllocfailed)So the base line is not deterministic: in about one round out of thirty the range already holds somebody else's
PAGE_READWRITE, and the assertion fails for a reason nothing to do with the code. That is the bug, and it explains aread-writefrom CI.Second, that the replacement is not vacuous. I mutated the loop body so no attempt can ever match (
memory_at(fresh + 8) == "a string that is never returned"), rebuilt, and the test failed with the new message:Restoring the line, it passes again. So the assertion still has teeth, and it still says something the base said — a released page really does read back free — rather than giving that up.
Compared with the sibling pull request #2939, which fixes the same test by querying addresses Windows never maps, this one is the more conservative fix: it retains the property under test. The cost is the
anyover 64 attempts, and theassert!(!fresh.is_null())inside it, which would panic rather than retry if a neighbour held the address space in that round. Sixty-four 16 KiB allocations is nothing to exhaust, and the retry loop was intended to absorb exactly that, but it is a panic path rather than a skipped one.3. What the tests do here
loads_binds_and_calls_probeRun by hand on the head, the crate's unit suite is 84 passed / 0 failed three times in a row, and
memory_at_names_what_an_access_hiton its own is 30/30. The red side has one test fewer than the green side because the merge base here is newer than the one #2939 branched from, not because this pull request removed anything.4. Any failure I saw, and why it is not this pull request
loads_binds_and_calls_probefails on the red side and on the green side alike, so it is not caused here. It is an integration test (d3d12/crates/leonida-loader/tests/load_probe.rs) and it dies building its own fixture:The test shells out to
cargoto compile a probe, and there is nocargoon the Wine side of this machine, and the manifest path is written with backslashes that only Windows accepts. It needs a native Windows box. Nothing else failed on either side.5. What I did not check
VirtualAllocnext, so ~3 % is a ceiling and not a measurement. I did not measure how often the 64 attempts would all be beaten, and the panic path on a nullVirtualAllocwas exercised by reasoning only, not by forcing an exhaustion.PAGE_NOACCESSreservation versus the base's mixed protections. The fresh block reserves four pages asPAGE_NOACCESSand commits one asPAGE_READWRITE; the base committed read-only, guard and no-access pages. Both endMEM_FREEafter the release, and that is the point, but the fresh loop does not re-exercise the three protections — the lines above it do, so nothing is lost.The program was scratch work under
/tmp/opencode, cross-compiled with the same toolchain, and is not part of this pull request: nothing was committed and nothing was pushed.Closing:
mainfixed this in561bbc19c("leonida-loader: remove post-MEM_RELEASE VA-reuse race in memory_at test"), and its fix is the better one.Theirs: after the release, the test no longer reads the address it just gave back. It reads
0x1008, inside the low 64 KiB that Windows keeps permanently unmapped:Mine retried a fresh reservation 64 times. Deterministic beats retried, and it needs no
VirtualAllocin the test at all.And the branch is not what it was: while trying to rebase this onto
mainI created it frommainby mistake and force-pushed that over the commit (a607df12e), which is why the diff looked empty before this. The commit is recoverable and I did recover it (git cat-file -t a607df12e-> commit), but there is nothing to restore it to: the flake is gone frommainand this PR would be a second fix for it. My mistake, said plainly - the check that would have caught it isgit rev-parse HEADbefore the push, which I ran one command too late.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.