kernelx: keep physical page release local to the page ID #3608
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3608"
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?
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T19:12:43Z.
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
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T19:26:20Z.
merge-check claim
head:
95b00f6f54Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T20:20:25Z.
merge-check
base:
6bfb5c5153head:
95b00f6f54merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2907 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (both commits,
kernelx.rs, +159 -35). No correctness problem found.PhysicalBlockkeeps a freed bitmap per allocation. A second free of a page does nothing (free_pagereturns false), soliveno longer drops for it, andpage_homerefuses a freed page while its siblings live.FreeTitlePhysicalPagesis the only place that holds bothAWAYandPHYS_BLOCKS, in that order.page_homeandAllocateTitlePhysicalPagestakePHYS_BLOCKSalone and briefly, and map / read takeAWAYbefore callingpage_home. So I see no lock-order inversion. The block homes are released after both locks are dropped.lazy::unmark,note_mapping_at,mirrors::page_freed,Away::title) now runs only for pages this call freed. Before, it ran for every page in the array, including repeats.physical_page_liveness_crosses_bitmap_wordsrepeated_physical_page_release_preserves_live_siblingsrepeated_free_then_freeing_a_page_mapped_away_keeps_the_last_siblingfree_pagewithout its already-freed check (a repeat free counts again, as on main) fails all three. Good.hle::kernelx::tests::at--test-threads=8, 30 runs on each tree. The failures are the same tests on both, so not this PR:a_page_whose_move_fails_stays_mapped_where_it_was(4) andan_address_keeps_the_page_the_title_mapped_there_last(1);6bfb5c5: 22 of 30 ok, 1 segmentation fault; the others faileda_page_whose_move_fails_stays_mapped_where_it_was(4),an_address_keeps_the_page_the_title_mapped_there_last(4) andchanged_gpu_view_pages_are_told_once_in_order(1).8ad21c61keeps its author.performance:
FreeTitlePhysicalPagesnow holdsAWAYwhile it walks the blocks; one bitmap check per freed page. Not measured.verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T21:02:29Z.
merge-check
base:
f07e426dadhead:
95b00f6f54(same as the claim)merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2907 passed, 0 failed, 51 ignored; 25 SKIPPED lines (no wave64 / heap windows / driver-cache test on this adapter), no test binary ended abnormally
review: none found after reading the whole diff (248 lines). PHYS_BLOCKS entries move from a (count, live, home) tuple to a PhysicalBlock with a per-page freed bitmap, so freeing a page twice (or a page already freed) no longer decrements the live count and no longer frees siblings or the block early; page_home now checks the single page. FreeTitlePhysicalPages takes AWAY then PHYS_BLOCKS (stated as the same order as map/read; I did not verify that every other site uses it, a deadlock risk if one takes them reversed), collects freed pages first, then unmaps and releases the block homes after dropping both locks. Behaviour change: pages not live are skipped, so away/mirror cleanup now runs only for pages actually freed. Tests: a unit test of the bitmap across word boundaries (runs everywhere) and two integration tests through the real Allocate/Free/Map entry points, which return early with skip_test("no UMA") when the UMA arena is missing, so those two can pass without running their bodies. Scope: one logical change.
performance: frees do a bitmap update and a map lookup per page, same order as before; memory is 1 bit per page per block (negligible). No per-frame cost. Reasoned, not measured.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T22:07:29Z.
Merged at the checked head after a combined trial of #3600, #3493, #3608 and #3607 on
mainf07e426d(RTX 4080 16 GB,cargo test --workspace --no-fail-fast -- --test-threads=4: 2909 passed, 0 failed, 51 ignored, 25 SKIPPED lines). Two merge checks each.AI use: Claude Code (Claude Opus 5.5).