tests: a released page is read back without racing the tests beside it #3017
Closed
github-bot
wants to merge 0 commits from
github-bot/gh-3017 into main
AGit
pull from: github-bot/gh-3017
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
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
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!3017
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3017"
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?
@fiestorra on GitHub · 2026-12-01 23:45 UTC · original
fiestorra:loader-page-race→main· +0 −0 · 0 files · 0 commits · closed without mergingtests: 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.
`memory_at_names_what_an_access_hit` releases a four-page reservation and then reads one of the pages back to see `nothing mapped there`. Another test in the same binary mapping in the microseconds between the `VirtualFree` and the read takes that address, and the read says `read-write` instead - which is exactly what CI did on two unrelated pull requests: ---- crash::tests::memory_at_names_what_an_access_hit assertion `left == right` failed left: "read-write" right: "nothing mapped there" 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 `VirtualAlloc` and a `VirtualFree` of 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 not remove 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::tests` passed 19/19 six times in a row here, so the negative control is the CI log above and not a local red. With the change: 19/19 four more times, clippy 0. Written with an AI assistant.@andrew-ai on GitHub · 2026-12-01 23:48 UTC · original
Ran the Windows leonida-loader library suite 25 times at parent
913b88b90and 25 times at PR heada607df12e. 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.
@imShangLi on GitHub · 2026-12-02 07:09 UTC · original
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.a607df12e2to69cd4106ce@fiestorra on GitHub · 2026-12-02 14:24 UTC · original
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.
Pull request closed