Repository navigation
kernelx: physical pages as section slices that can be mapped at many addresses - #2293
adiologydev wants to merge 1 commit into
Conversation
…addresses On the console a physical page mapped at several addresses is one page. XCL keeps a page at one address at a time and copies it when the title maps it elsewhere (`move_away`), so the other addresses go stale; a retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). `kernelx::sections` is the base for real aliasing: a block of physical pages is one pagefile-backed SEC_RESERVE section, and a page is mapped as a view of its 64 KiB slice into a placeholder (MapViewOfFile3 with MEM_REPLACE_PLACEHOLDER). Every view of a slice is the same memory and a page takes commit once, when it is committed through any view. Unmapping leaves a placeholder for the next view. Ordinary reserved memory (write-watched if asked) can replace part of a placeholder and go back to one. Nothing calls it yet. Measured in a standalone program on Windows 11 26200 over 200 000 pages: map 2.2 us, unmap 2.75 us, commit 0.9 us a page. GetWriteWatch refuses a range that holds a view (error 87), and one call cannot span two neighbouring reservations either.
…sing stack) Integrates upstream PR stack xcl-dev#2293 -> xcl-dev#2294 -> xcl-dev#2307 -> xcl-dev#2308 (opt-in real section-slice physical page aliasing across virtual views via XCL_PAGE_ALIAS=1).
|
NVIDIA test report for
AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
RX 7800 XT (RDNA3, wave32/wave64) report on exact head Tested
Not tested
AI use
|
|
Independent AMD RDNA4 / Linux (Proton/Wine, RADV, native wave64) test report for head Hardware & environment
Unit tests (
Not tested
AI use
|
bmjask
left a comment
There was a problem hiding this comment.
No concrete source defect found; SEC_RESERVE/view splitting/aliasing/write-watch tests are internally consistent. Current head lacks Windows CI and the module remains unused, so no runtime alias lifecycle/concurrency integration exists. Also, failed MapViewOfFile3 occurs after placeholder split and leaves reservation fragmented; document this recoverable state or restore transactionally before wiring into callers. Provide current CI and integration once connected.
|
Independent desktop NVIDIA verification of PR #2293 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib hle::kernelx::sections:: -- --test-threads=1 --nocapture (3 consecutive runs) |
7 passed; 0 failed; 0 ignored; 1124 filtered out × 3 (0.00s × 3, 0 skipped: a_page_mapped_at_two_addresses_is_one_page, a_run_of_pages_is_one_view, a_section_of_no_pages_is_refused, committing_through_one_view_commits_the_page_for_all, splitting_a_range_that_is_already_a_placeholder_is_a_no_op, unmapping_leaves_a_placeholder_for_the_next_page, write_watched_memory_lives_beside_views_in_one_placeholder) |
cargo test --release -p xcl --lib hle::kernelx:: -- --test-threads=1 (3 consecutive runs) |
45 passed; 0 failed; 1 ignored; 1085 filtered out × 3 (1.15s, 1.17s, 1.16s, 0 skipped) |
cargo build --release -p xcl |
Clean build (1m 18s, exit 0, 0 new warnings) |
Paired quiet 60 s retail smoke (title: 29640639)
Exact parent & merge-base (568e7db7729c8fa6c8f0f4b32d798faaf11462bb, cached baseline on the same machine):
xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14527 MB
PR #2293 (03ceddb0be3d06287ca21ae800dbb0d7f98049e7):
xcl-smoke v1
commit: 03ceddb0be3d06287ca21ae800dbb0d7f98049e7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1580 (PresentX 1580)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14520 MB
Limits of coverage
- Windows 11
VirtualAlloc2placeholder splitting/coalescing andMapViewOfFile3multi-address section-slice mapping were directly verified via all 7 newhle::kernelx::sections::tests(3/3,0skipped) and the fullhle::kernelx::suite (45/45× 3). - PR kernelx: physical pages as section slices that can be mapped at many addresses #2293 adds the
sectionsbuilding block without wiringXCL_PAGE_ALIAS=1into the retail runtime path yet (wired in stacked PR kernelx: XCL_PAGE_ALIAS=1 shows a physical page at every address it is mapped at #2307), so the 60 s retail smoke confirms default-path non-regression ontitle: 29640639(single-run frame/commit delta reflects normal startup variance, not this PR).
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
… stand down, and the log says which is at work Lab port of the upstream alias stack (xcl-dev#2293, xcl-dev#2294, xcl-dev#2307, xcl-dev#2308, xcl-dev#3074, xcl-dev#3075). The lab's two stopgaps for a physical page at more than one address keep the page at ONE address and move it (bring_page / bring_range, XCL_PAGE_BRING) or its video memory (sparse::share_page, XCL_PAGE_SHARE=1). With real aliases a page is at every address the title mapped it at, outside the sparse windows, and an address it is not at was unmapped by the title: both stand down when XCL_PAGE_ALIAS=1. With the switch not set they are as they were. One line at start-up (the first time the switch is asked) names which of the three is at work; with aliases, a line at the first view and at each power of two from 1024 on says how many pages are shown at how many addresses and how many of them at more than one (guards::view_counts). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
merge-check claim |
|
merge-check failing: test_title_runs_and_game_folder_is_untouched correction: this check first reported the PR as "not yet" because of a test failure that is not the PR's. The base-comparison step failed to run (test names contain a double colon, not a legal Windows filename), so an empty read was mistaken for "passes on base". |
|
merge-check claim |
|
I checked two independent failure cases in the current section helper. I reproduced both on a local candidate rebased onto current
The two new regression tests both fail when their respective fix is removed, and pass with the candidate. Local candidate verification
Candidate diff against PR headdiff --git a/crates/xcl/src/hle/kernelx/sections.rs b/crates/xcl/src/hle/kernelx/sections.rs
index 99356862..17b78958 100644
--- a/crates/xcl/src/hle/kernelx/sections.rs
+++ b/crates/xcl/src/hle/kernelx/sections.rs
@@ -44,9 +44,9 @@ impl Section {
pub fn new(pages: usize) -> Option<Section> {
let bytes = pages.checked_mul(PAGE).filter(|&b| b > 0)?;
// SAFETY: a pagefile-backed mapping with no name and default security.
let handle = unsafe { CreateFileMappingW(INVALID_HANDLE_VALUE, std::ptr::null(), PAGE_READWRITE | SEC_RESERVE, (bytes >> 32) as u32, bytes as u32, std::ptr::null()) };
- (!handle.is_null()).then_some(Section { handle, pages })
+ section_from_handle(handle, pages)
}
pub fn pages(&self) -> usize {
self.pages
@@ -69,8 +69,12 @@ impl Section {
v.Value as usize == at
}
}
+fn section_from_handle(handle: HANDLE, pages: usize) -> Option<Section> {
+ (!handle.is_null()).then(|| Section { handle, pages })
+}
+
impl Drop for Section {
fn drop(&mut self) {
// views still mapped keep the section alive until they are unmapped
// SAFETY: the handle is ours and closed once.
@@ -82,13 +86,20 @@ impl Drop for Section {
///
/// # Safety
/// Only reserves address space; the caller releases it with `release`.
pub unsafe fn reserve(at: Option<usize>, len: usize) -> Option<usize> {
- if len == 0 || !len.is_multiple_of(PAGE) {
+ reserve_with(at, len, |want, len| {
+ // SAFETY: the helper validates the requested placeholder range before calling here.
+ unsafe { VirtualAlloc2(GetCurrentProcess(), want as *const c_void, len, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, PAGE_NOACCESS, std::ptr::null_mut(), 0) as usize }
+ })
+}
+
+fn reserve_with(at: Option<usize>, len: usize, allocate: impl FnOnce(usize, usize) -> usize) -> Option<usize> {
+ if at == Some(0) || len == 0 || !len.is_multiple_of(PAGE) {
return None;
}
let want = at.unwrap_or(0);
- let p = VirtualAlloc2(GetCurrentProcess(), want as *const c_void, len, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, PAGE_NOACCESS, std::ptr::null_mut(), 0) as usize;
+ let p = allocate(want, len);
(p != 0 && (at.is_none() || p == want)).then_some(p)
}
/// The allocation `p` lies in: (base, size, state, type), from one VirtualQuery.
@@ -304,5 +315,24 @@ mod tests {
#[test]
fn a_section_of_no_pages_is_refused() {
assert!(Section::new(0).is_none());
}
+
+ #[test]
+ fn failed_section_creation_does_not_close_a_null_handle() {
+ use windows_sys::Win32::Foundation::{GetLastError, SetLastError, ERROR_ACCESS_DENIED};
+
+ unsafe { SetLastError(ERROR_ACCESS_DENIED) };
+ assert!(section_from_handle(std::ptr::null_mut(), 1).is_none());
+ assert_eq!(unsafe { GetLastError() }, ERROR_ACCESS_DENIED);
+ }
+
+ #[test]
+ fn an_explicit_zero_base_is_rejected_before_reserving() {
+ let mut called = false;
+ assert_eq!(reserve_with(Some(0), PAGE, |_, _| {
+ called = true;
+ PAGE
+ }), None);
+ assert!(!called, "Some(0) must not be passed to VirtualAlloc2 as an OS-chosen base");
+ }
}The candidate leaves the existing view-replacement failure/placeholder-fragmentation question unchanged. AI-assisted: Codex (GPT-6.2 Sol) prepared the candidate and ran the tests; GPT-6.2 Astra reviewed the Win32 handle and reservation semantics. |
|
merge-check |
|
Tested
Not tested
AI use
|
|
No open or merged PR makes the same change: main has no section-backed physical pages ( AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
First part of the plan on #1031 (real aliasing of physical pages): a block of physical pages as one pagefile-backed section, mapped as views into placeholders, so a page can show at every address it is mapped at. Nothing calls it yet; part of #1031 / #697.
On the console a physical page mapped at several addresses is one page. XCL keeps a page at one address at a time and copies it when the title maps it elsewhere (
kernelx::move_away); a retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view.What is in it
crates/xcl/src/hle/kernelx/sections.rs(new):Section(aSEC_RESERVEpagefile-backed section of N 64 KiB pages),Section::map(a view of pagesfirst..first+ninto a placeholder withMapViewOfFile3/MEM_REPLACE_PLACEHOLDER),reserve/split/unmap(keeps the placeholder) /commit/release, andreplace_with_reservation/reservation_to_placeholder(ordinary, optionally write-watched memory in part of a placeholder). 7 unit tests.crates/xcl/src/hle/kernelx.rs: the module declaration.Measured in a standalone program (not part of the PR) on the machine below, 200 000 pages: map 2.2 µs, unmap 2.75 µs, commit 0.9 µs,
VirtualProtect0.5 µs a page.GetWriteWatchrefuses a range that holds a view (error 87) and one call cannot span two neighbouring reservations; one call per small reservation costs 0.83 µs.Tested
XCL_DXC_DIR), debug tests, release runs.cargo test --workspace -- --test-threads=4on03ceddb: 1101 passed, 4 failed, 26 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(CreateComputePipelineState→E_OUTOFMEMORYon this card, DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905);main568e7db fails the same 4 here (1094 passed, 4 failed, 26 ignored). SKIPPED (23, the same onmain): 20 need 64-lane waves ("no wave64"), 3 per-lane f16 refusals inlower_dxil::tests::{f16,f32}_programs_on_the_gpu.cargo test -p xcl --lib kernelx::sections: 7 passed.Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 60, no input,mainfirst, same machine (each run'sxcl.exebuilt from a clean checkout of its commit):Not tested
MapViewOfFile3need a Windows 10 1803+ kernel – not tried under Wine).AI use