Repository navigation
Conversation
There was a problem hiding this comment.
Review of 81d047a against its merge base 47efa2e (the head of main when this was read), by reading the code; nothing was built or run here, and no script of my own was run. The PR had no comments or reviews when read, so nothing below repeats an earlier point. The bug it describes is real on main: map_pages took page_home(pages[0]) as the home of the whole array when the numbers were consecutive and the last page had any home (crates/xcl/src/hle/kernelx.rs:1223-1224 on main), and AllocateTitlePhysicalPages numbers pages from one global counter (:1171), so two allocations with consecutive numbers were committed and returned as [H1, H1 + n * PHYS_PAGE) by commit_homes (:995-1012). contiguous_home_in (:859-868) closes that: I found no defect in its arithmetic or its bounds (one page, page 0, a non-multiple of FRAMES, an index past the block, a block with nothing live all return None), and it takes PHYS_BLOCKS under AWAY in the same order page_home already does.
-
CONFIRMED by tracing the code (minor): with an address given, the same array now takes the "mapped away" path at its own home (
kernelx.rs:1241, then:1271-1322). The description speaks only ofNULL, buthome == Some(va)changes too. Scenario:MapTitlePhysicalPages(H1, 2, [p1, p2])withp1,p2from two allocations andH1the home ofp1in a sparse window.homeis nowNone, so the loop runs withat == H1:H1is committed (:1306),copy_nonoverlapping(home, at)is called with the same range as source and destination (:1311; undefined behaviour forcopy_nonoverlapping, though harmless in practice),move_home_awayqueuesH1(:1312,:946-948),p1is recorded as away atH1(:1321-1322), andgive_back_homesdecommitsH1when the call ends (:1222,:973-976): the page is recorded at an address that was just decommitted.mainhas the same path for non-consecutive pages mapped at the first one's home, so this is not new in kind; the PR sends one more case into it (which onmainreturned the wrong memory forp2instead). Fix: in the loop, treatat == page_home(p)as "at home" (commit the home, no copy, nomove_home_away), or say under Not tested that the address-given case is not covered; the new test only calls withNULL(:2171). -
Overlap with open PRs on the same functions.
- #608 (
2a3c7f4) changes the value type ofPHYS_BLOCKSfrom the tuple to aPhysicalBlockwith a per-page freed bitmap.contiguous_home_intakes&BTreeMap<usize, (usize, usize, usize)>(:859) and its unit test builds tuples (:2194-2198), so whichever merges second has to be rebased. - #1055 and #1102 add
away.title.insert(home + i * PHYS_PAGE, p)to the at-home branch ofmap_pages, the branch whose condition this PR changes. - No other open or merged PR found for this defect (searched "physical pages",
MapTitlePhysicalPages,page_home,PHYS_BLOCKS,FreeTitlePhysicalPages).
- #608 (
Question: when two allocations' homes happen to be adjacent, main mapped MapTitlePhysicalPages(NULL, n, ...) over both and every page was at H1 + i * PHYS_PAGE; this head refuses that with ERROR_NOT_SUPPORTED (kernelx.rs:867, asserted at :2197-2198, :2206). Is refusing that case intended? If so, it would help to say so in the description.
About the test: consecutive_pages_from_separate_allocations_do_not_map_as_one_home returns without checking anything when unified memory is absent (:2140), and panics rather than skips if 32 tries do not produce the layout (:2167). It does test what the description claims: on main the call at :2171 returns h1.
Against CONTRIBUTING: the sections are all there, both xcl-smoke blocks name the right commits (47efa2e on main, 81d047a for the head), 101 added / 3 removed lines in one file, one commit with the subject in the repository's style. Only the PR description check had reported on this head when read; CI had not.
Verdict: the fix is correct for the case it describes and small enough to merge; finding 1 is minor and can be a follow-up, and #608 needs a rebase on one side.
Review by Claude Code (written by Claude Fable 5.2, checked and edited with Claude Opus 5.5); each point checked by a person before posting.
|
Independent verification on current Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
AI use: test runs by Devin (Cognition, SWE-2); no code changes. |
AllocateTitlePhysicalPages assigns consecutive page numbers from a global counter (NEXT_PAGE_INDEX) even across separate allocations whose home blocks are not adjacent in virtual memory. map_pages only checked that page numbers were consecutive and that the last page had a home, so MapTitlePhysicalPages(NULL, ...) on pages from two separate allocations committed and returned the first block's home over unrelated memory next to it. Check that all pages in the slice fall within one live PHYS_BLOCKS entry (contiguous_home) with checked arithmetic before treating them as a single contiguous home block (even when two separate allocations happen to land adjacent, commit_homes / VirtualAlloc(MEM_COMMIT) and lazy_home / is_sparse assume a single backing reservation). Also handle `home == at` inside map_pages's per-page loop so an address-given call that maps a page at its own home keeps it committed at home instead of copying it onto itself and decommitting it via move_home_away / give_back_homes. Assisted-by: OpenCode (Gemini 4 Neon)
81d047a to
076d027
Compare
|
Thanks @pvfreis for the thorough review! Addressed in \ |
|
Follow-up at
Reply by Claude Code (Claude Opus 5.5); checked by a person before posting. |
|
A run on Linux under Wine. Tested
Not tested
AI use
|
Port upstream xcl-dev#1143 (head 076d027): add contiguous_home_in / contiguous_home so consecutive page numbers resolve to a single host block only when they belong to one live PHYS_BLOCKS entry. The NULL-address MapTitlePhysicalPages path copies that block whole and falls back to the per-page loop otherwise, so consecutive numbers from two allocations never merge into one block over unrelated memory. Add contiguous_home_requires_one_allocation (ported) plus an end-to-end test for one-block mapping, cross-allocation split, and unmap/free neighbor preservation. The upstream home == at handling has no twin counterpart (Linux homes are private malloc, targets always gfx-pool).
AllocateTitlePhysicalPagesassigns consecutive page numbers from a global counter (NEXT_PAGE_INDEX) even across separate allocations whose home blocks are not adjacent in virtual memory (e.g. separated by another UMA allocation or falling back to plain memory).map_pagesonly checked that page numbers were consecutive and thatpages[n - 1]had a home, soMapTitlePhysicalPages(NULL, ...)on pages spanning two separate allocations committed and returned[H1, H1 + n * PHYS_PAGE), overlapping unrelated memory next to the first block.This adds
contiguous_home_in/contiguous_hometo require that all consecutive pages belong to one livePHYS_BLOCKSentry (using checked arithmetic) before treating them as a single contiguous home block. Refusing two separate allocations even when their home addresses happen to be adjacent is intentional:commit_homes(VirtualAlloc(..., MEM_COMMIT)),lazy_home, andis_sparseassume a single backing reservation of one memory kind.It also handles
home == atinsidemap_pages's per-page loop so an address-given call (e.g.MapTitlePhysicalPages(H1, 2, [p1, p2])spanning two allocations) keepsp1committed at its own home instead of copyingH1onto itself and decommitting it viamove_home_away/give_back_homes.What is in it
crates/xcl/src/hle/kernelx.rs: addcontiguous_home_in/contiguous_homeand use it inmap_pages; handlehome == atinsidemap_pages's per-page loop; addconsecutive_pages_from_separate_allocations_do_not_map_as_one_home,contiguous_home_requires_one_allocation, andmapping_page_at_its_own_home_in_mixed_call_keeps_it_committed.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 754 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib:consecutive_pages_from_separate_allocations_do_not_map_as_one_home,contiguous_home_requires_one_allocation, andmapping_page_at_its_own_home_in_mixed_call_keeps_it_committedall passRegression run
main:
PR:
Not tested
AI use
kernelx.rs, wrote the fix and regression tests, addressed @pvfreis's review finding onhome == atin the per-page loop, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.