cpu: select a host-disabled XCOMP_BV bit for native compacted XRSTOR #GP checks #1679
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1686"
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 R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-24T17:03:50Z.
Fixes #1647.
Change
tests/cpu/xsave_state_check.pypreviously required native compactedXRSTORto raise#GPon fixedXCOMP_BVcomponent bits (xcomp-bit3,xcomp-bit4,xcomp-bit3-only,xcomp-bit9,xcomp-bit62). On a host whoseXCR0enables any of those bits (for example MPX bits 3 and 4 whenXCR0=0x1f, or PKRU bit 9), nativeXRSTORvalidly accepts the header while the lifted profile still rejects it under the fixedx87|SSE|AVXguest contract.XCR0via the existinghost_xcr0()export and log it alongside the host XSAVE area size.XCOMP_BVrefusals (xcomp-bit3,xcomp-bit4,xcomp-bit9,xcomp-bit62,xcomp-bit3-only) enforced on the lifted DLL and incheck_compacted_controls.native_compacted_header_must_fault(image, host_xcr0, mxcsr_mask)so fixed guest-profileXCOMP_BVcases whose listed components are all enabled inhost_xcr0stay lifted-only, while all other invalid headers (subset violations includingxstate-bit3, nonzero reserved bytes, standard-format nonzeroXCOMP_BV, invalidMXCSR) remain checked natively.select_host_disabled_xcomp_bit(host_xcr0)to pick the lowest disabled component bit in the usableXCOMP_BV[62:3]range, compare a valid compacted restore control (XSTATE_BV=7,XCOMP_BV=bit63|7,RFBM=7) against the identical header with that single disabled bit set (plus anRFBM=0variant), and report the selected bit and observed native exception in the test output.check_host_xcr0_selection_controls(34 synthetic/mutation controls coveringXCR0=0x7,0x1fMPX,0xe7,0xff,0x2e7,0x2ff,0x3ff,(1<<62)-1, invalid masks, and a mutation verifying that hardcoded bit 3 fails the native-fault predicate forXCR0=0x1fwhile selected bit 5 passes both the predicate and the compiled lifted DLL refusal).Verification
Tested on Windows 11 x64 (MSVC 19.44.35230, Windows SDK 10.0.26100.0, DXC 1.9.2602.17, CMake 3.31.6, Ninja 1.12.1) on an AVX-512 host (
CPUID.0D.0:EBX = 2432 bytes,XCR0 = 0xe7), based onupstream/main(abb24b67).--preset dev): 1/1 passed (0.35 s):Host XSAVE area (CPUID.0D.0:EBX): 2432 bytes, XCR0=0xe7compacted xrstor: 50 xsavec round trips, 220 valid and 27 #GP header cases (native host-disabled XCOMP_BV bit 3 (XCR0=0xe7, exc='exception: access violation reading 0xFFFFFFFFFFFFFFFF', valid restore control matched)), ALTER_OP diverged on {'op_xsavec_xrstor_all': 10, 'op_xsavec_xrstor_avx_only': 10}, 11 mutation controls and 34 host-XCR0 controls passed/O2(--preset release): 1/1 passed (0.46 s), matching output.XCR0=0xe7:A direct probe against the built
cpu_xsave_state_original.dllandcpu_xsave_state_compacted_lifted.dllconfirmed that setting host-enabled bit 5 (XCOMP_BV = bit63 | 7 | (1 << 5)) is accepted natively (native_faulted=False) while refused by the lifted DLL (access violation reading 0xFFFFFFFFFFFFFFFF), whereas setting selected disabled bit 3 raises#GPon both native and lifted.--preset pr): 22 passed, 4 skipped (spirv_minlod_warp,spirv_minlod_exact_warp,spirv_minlod_levels_warp,spirv_minlod_fractional_warp— pinned local SPIR-V tools not installed), 0 failed..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: passed (16 Markdown files, 351 links).\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: passed (1279 tracked files).\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: passedgit diff --check: cleanEvidence scope
This machine's CPU has
XCR0=0xe7(AVX-512, without MPX). The MPX configuration (XCR0=0x1f) is covered here by synthetic selection/classification/mutation controls and by the analogous live bit-5 acceptance vs. bit-3#GPcheck onXCR0=0xe7; a retest on an MPX-enabled host (XCR0=0x1f, cc @legacy-code-archaeologist) would directly confirm the native MPX run.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:15:50Z.
Review: COMMENTED
Verification review for commit
9ebcb5e14483c2e7074afd585a68736b2ac8e816:Scope & Audit
tests/cpu/xsave_state_check.py, +181/-12): readshost_xcr0()from the lifted DLL, selects the lowest disabled bit inXCOMP_BV[62:3]viaselect_host_disabled_xcomp_bit, filters native#GPexpectations on fixed guest-unsupported cases vianative_compacted_header_must_faultwhile keeping all lifted checks unconditional, adds host-XCR0-derived native+lifted#GP+ valid-control comparisons, and adds syntheticXCR0=0x1f/0x2e7selection controls.Checks Executed
git diff --check origin/main...HEAD: clean.python3 -I tests/docs_links_check.py: passed (16 Markdown files, 351 links).python3 -I tests/bidi_controls_check.py: passed (1,279 files, no bidirectional controls).python3 -B -m py_compile tests/cpu/xsave_state_check.py: passed.XCR0=0x7):--preset dev): 8 XSAVE targets built (1.11s, configure1.78s);ctest --preset dev -R '^cpu_aot_xsave_state$' --no-tests=error: 1/1 passed (0.45s)./O2(--preset release): 8 XSAVE targets built (0.76s, configure1.78s);ctest --preset release -R '^cpu_aot_xsave_state$' --no-tests=error: 1/1 passed (0.46s).--patch, cache bypassed, repo restored after each run):select_host_disabled_xcomp_bittoreturn 3:cpu_aot_xsave_statefailed (AssertionError: ('0x1f', 3, 5)).(1 << disabled_bit)fromhost_fault:cpu_aot_xsave_statefailed (AssertionErroron the single-bitXCOMP_BVdelta guard vsvalid_ctrl).Verdict: 0 P1, 0 P2. Clean Tier B merge candidate.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T17:29:09Z.
Retest on the MPX host from #1647: Windows 11 Pro 26100.9168, Intel i7-6820HQ (Skylake),
XCR0=0x1f, MSVC 19.52, head9ebcb5e1.Both pass; on main they fail with
native op_xrstor64_compacted_dynmask xcomp-bit3 accepted a header the instruction rejects. The relevant output, identical in both presets:0x1fdisables, so the selection works as specified.STATUS_ACCESS_VIOLATIONwith the fault address0xFFFFFFFFFFFFFFFF, which is what ctypes prints here.I didn't change anything.