Repository navigation
kernelx: keep physical page release local to the page ID - #3608
Conversation
Track released IDs within each allocation so a duplicate cannot consume a live sibling. Reject released IDs in home lookups while preserving repeated lookup of live pages. Assisted-by: Codex (GPT-6.2 Sol)
The previous commit drops a freed page's mapping away from home only when that free released the page, and no kernelx test reached that path (a review question on xcl-dev#608). This test maps one page of a block away from home, frees another page twice, then frees the mapped page: the mapping goes (the address keeps its bytes), and the block stays for the page still allocated. On main the repeated free releases that page's block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
merge-check claim |
|
merge-check
|
|
merge-check |
Replaces #608 so it can be merged as is: it carries Babyhamsta's commit from #608, rebased onto main with the conflict resolved (author kept), plus one test-only commit. All credit for the fix goes to Babyhamsta.
Freeing one physical page twice could retire a sibling the title still owned. A freed page could also continue resolving to its home until the last page in the allocation was released. Related PR #187 addressed when XCL returns backing memory.
Rebased onto main
6bfb5c51. Since this PR's old base, main added the mirrors bookkeeping (mirrors::page_freed), the lazy unmark from #1221 andsource_goingtoFreeTitlePhysicalPages. The rebase keeps all three, run once for each page that the call frees. A repeated free of a page that is already freed now does nothing.What is in it
kernelx: keep physical page release local to the page ID(Babyhamsta,crates/xcl/src/hle/kernelx.rs): released page IDs are tracked with a bitmap per allocation.page_home(and with it map, read, write,physical_pages_liveand the GPU-view page record) refuses a freed ID while its siblings are live.FreeTitlePhysicalPagestakesAWAYand thenPHYS_BLOCKS, the same order as map and read, and marks the pages freed in the bitmap. It then drops the away mapping, the lazy mark, the GPU-view pages and theAway::titleentries, only for the pages this call freed. A block's home is released after both locks are dropped. Repeated frees keep returning 1. Tests: the bitmap across a word boundary, and the read, write and map of a freed page and its live siblings.Tests: a page freed while mapped away loses its mapping, its block stays(crates/xcl/src/hle/kernelx.rs, test only): maps one page away from home, frees another page twice, then frees the mapped page. It checks thatphysical_page_atclears, that the address keeps its bytes, and that the last page still reads. This covers the review question about the away-mapping cleanup.Tested
stable-x86_64-pc-windows-msvc, debug for the tests, release for the smoke runs. Head95b00f6f, clean tree.cargo build --workspace: ok, no new warnings.cargo test --workspace --no-fail-fast -- --test-threads=4: 2907 passed, 0 failed, 51 ignored across 43 test binaries (xcllib: 2759 passed, 0 failed, 31 ignored). The 3 physical-page tests ran on the GPU (no SKIPPED).no wave64(thegpu::recomp::lower/lower_dxilGPU comparisons,dispatch_chain_native_wave64_builds_whole,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware);no heap windows;no d3d12SDKLayers.dll(debug-layer title runs);no D3D12 debug layer;repeated_free_then_freeing_a_page_mapped_away_keeps_the_last_siblingfails atthe page still allocated keeps its block: on main, the repeated free plus one more free releases the block while a page is still allocated.repeated_physical_page_release_preserves_live_siblingsfails at!read_physical_pages(&[first], 0, &mut bytes): a freed page is still read.away.at.remove(&at)taken out ofFreeTitlePhysicalPages, the new test fails ata freed page is no longer mapped there, and the other kernelx tests pass.MapTitlePhysicalPages/XMemMapPhysicalPagesScatter, which go through the changedpage_home), and the queue's page-mapping calls ran too.Regression run
main:
this PR's head:
Not tested
FreeTitlePhysicalPagescalls, so the runs show only that the map paths still work.AWAY→PHYS_BLOCKS, no other lock taken underPHYS_BLOCKS) was checked by reading the code only.AI use
Codex (GPT-6.2 Sol) implemented the fix and regression tests. Codex (GPT-6) reviewed the diff, checked related PRs, ran the smoke comparison, and prepared the original description. For Foniass, Claude Code (Claude Opus 5.5) did the rebase onto main and resolved the conflict in
FreeTitlePhysicalPages. It also reviewed the rebased code, wrote the added test commit, ran the test suite, the fail-on-main check, the mutation check and the smoke pair above, and updated this description.🤖 Generated with Claude Code