cpu: select a host-disabled XCOMP_BV bit for native compacted XRSTOR #GP checks #1679

Merged
R0D4X merged 1 commit from upstream-pr/1686 into main 2026-11-24 17:25:00 +00:00
R0D4X commented 2026-11-24 17:03:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-24T17:03:50Z.


Fixes #1647.

Change

tests/cpu/xsave_state_check.py previously required native compacted XRSTOR to raise #GP on fixed XCOMP_BV component bits (xcomp-bit3, xcomp-bit4, xcomp-bit3-only, xcomp-bit9, xcomp-bit62). On a host whose XCR0 enables any of those bits (for example MPX bits 3 and 4 when XCR0=0x1f, or PKRU bit 9), native XRSTOR validly accepts the header while the lifted profile still rejects it under the fixed x87|SSE|AVX guest contract.

  • Read the measured host XCR0 via the existing host_xcr0() export and log it alongside the host XSAVE area size.
  • Keep all fixed guest-unsupported XCOMP_BV refusals (xcomp-bit3, xcomp-bit4, xcomp-bit9, xcomp-bit62, xcomp-bit3-only) enforced on the lifted DLL and in check_compacted_controls.
  • Add native_compacted_header_must_fault(image, host_xcr0, mxcsr_mask) so fixed guest-profile XCOMP_BV cases whose listed components are all enabled in host_xcr0 stay lifted-only, while all other invalid headers (subset violations including xstate-bit3, nonzero reserved bytes, standard-format nonzero XCOMP_BV, invalid MXCSR) remain checked natively.
  • Add select_host_disabled_xcomp_bit(host_xcr0) to pick the lowest disabled component bit in the usable XCOMP_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 an RFBM=0 variant), and report the selected bit and observed native exception in the test output.
  • Add check_host_xcr0_selection_controls (34 synthetic/mutation controls covering XCR0=0x7, 0x1f MPX, 0xe7, 0xff, 0x2e7, 0x2ff, 0x3ff, (1<<62)-1, invalid masks, and a mutation verifying that hardcoded bit 3 fails the native-fault predicate for XCR0=0x1f while 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 on upstream/main (abb24b67).

  • Debug (--preset dev):
    ctest --preset dev --no-tests=error -R '^cpu_aot_xsave_state$' -V
    
    1/1 passed (0.35 s):
    Host XSAVE area (CPUID.0D.0:EBX): 2432 bytes, XCR0=0xe7
    compacted 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
  • Release /O2 (--preset release):
    cmake --build --preset release --target cpu_xsave_state_original cpu_xsave_state_original_lifted cpu_xsave_state_altered cpu_xsave_state_altered_lifted cpu_xsave_state_canonical_lifted cpu_xsave_state_canonical_altered_lifted cpu_xsave_state_compacted_lifted cpu_xsave_state_compacted_altered_lifted
    ctest --preset release --no-tests=error -R '^cpu_aot_xsave_state$' -V
    
    1/1 passed (0.46 s), matching output.
  • Live host-enabled vs. host-disabled check on XCR0=0xe7:
    A direct probe against the built cpu_xsave_state_original.dll and cpu_xsave_state_compacted_lifted.dll confirmed 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 #GP on both native and lifted.
  • PR smoke suite (--preset pr):
    cmake --build --preset pr
    ctest --preset pr --no-tests=error -j 1 --output-on-failure
    
    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.
  • Lint and Python checks:
    • .\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: passed
    • git diff --check: clean

Evidence 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 #GP check on XCR0=0xe7; a retest on an MPX-enabled host (XCR0=0x1f, cc @legacy-code-archaeologist) would directly confirm the native MPX run.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587166252 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1686). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-24T17:03:50Z. --- Fixes #1647. ## Change `tests/cpu/xsave_state_check.py` previously required native compacted `XRSTOR` to raise `#GP` on fixed `XCOMP_BV` component bits (`xcomp-bit3`, `xcomp-bit4`, `xcomp-bit3-only`, `xcomp-bit9`, `xcomp-bit62`). On a host whose `XCR0` enables any of those bits (for example MPX bits 3 and 4 when `XCR0=0x1f`, or PKRU bit 9), native `XRSTOR` validly accepts the header while the lifted profile still rejects it under the fixed `x87|SSE|AVX` guest contract. - Read the measured host `XCR0` via the existing `host_xcr0()` export and log it alongside the host XSAVE area size. - Keep all fixed guest-unsupported `XCOMP_BV` refusals (`xcomp-bit3`, `xcomp-bit4`, `xcomp-bit9`, `xcomp-bit62`, `xcomp-bit3-only`) enforced on the lifted DLL and in `check_compacted_controls`. - Add `native_compacted_header_must_fault(image, host_xcr0, mxcsr_mask)` so fixed guest-profile `XCOMP_BV` cases whose listed components are all enabled in `host_xcr0` stay lifted-only, while all other invalid headers (subset violations including `xstate-bit3`, nonzero reserved bytes, standard-format nonzero `XCOMP_BV`, invalid `MXCSR`) remain checked natively. - Add `select_host_disabled_xcomp_bit(host_xcr0)` to pick the lowest disabled component bit in the usable `XCOMP_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 an `RFBM=0` variant), and report the selected bit and observed native exception in the test output. - Add `check_host_xcr0_selection_controls` (34 synthetic/mutation controls covering `XCR0=0x7`, `0x1f` MPX, `0xe7`, `0xff`, `0x2e7`, `0x2ff`, `0x3ff`, `(1<<62)-1`, invalid masks, and a mutation verifying that hardcoded bit 3 fails the native-fault predicate for `XCR0=0x1f` while 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 on `upstream/main` (`abb24b67`). - **Debug (`--preset dev`):** ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_xsave_state$' -V ``` 1/1 passed (0.35 s): `Host XSAVE area (CPUID.0D.0:EBX): 2432 bytes, XCR0=0xe7` `compacted 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` - **Release `/O2` (`--preset release`):** ```powershell cmake --build --preset release --target cpu_xsave_state_original cpu_xsave_state_original_lifted cpu_xsave_state_altered cpu_xsave_state_altered_lifted cpu_xsave_state_canonical_lifted cpu_xsave_state_canonical_altered_lifted cpu_xsave_state_compacted_lifted cpu_xsave_state_compacted_altered_lifted ctest --preset release --no-tests=error -R '^cpu_aot_xsave_state$' -V ``` 1/1 passed (0.46 s), matching output. - **Live host-enabled vs. host-disabled check on `XCR0=0xe7`:** A direct probe against the built `cpu_xsave_state_original.dll` and `cpu_xsave_state_compacted_lifted.dll` confirmed 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 `#GP` on both native and lifted. - **PR smoke suite (`--preset pr`):** ```powershell cmake --build --preset pr ctest --preset pr --no-tests=error -j 1 --output-on-failure ``` 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. - **Lint and Python checks:** - `.\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`: passed - `git diff --check`: clean ## Evidence 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 `#GP` check on `XCR0=0xe7`; a retest on an MPX-enabled host (`XCR0=0x1f`, cc @legacy-code-archaeologist) would directly confirm the native MPX run.
upstream-sync closed this pull request 2026-11-24 18:02:31 +00:00
tedin7 commented 2026-11-24 18:02:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:15:50Z.

Review: COMMENTED


Verification review for commit 9ebcb5e14483c2e7074afd585a68736b2ac8e816:

Scope & Audit

  • Tests-only diff (tests/cpu/xsave_state_check.py, +181/-12): reads host_xcr0() from the lifted DLL, selects the lowest disabled bit in XCOMP_BV[62:3] via select_host_disabled_xcomp_bit, filters native #GP expectations on fixed guest-unsupported cases via native_compacted_header_must_fault while keeping all lifted checks unconditional, adds host-XCR0-derived native+lifted #GP + valid-control comparisons, and adds synthetic XCR0=0x1f / 0x2e7 selection controls.
  • Zero production code changes, zero weakened assertions, zero temp-file/process leaks, clean-room/title-neutral.

Checks Executed

  • Linux:
    • 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.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP, host XCR0=0x7):
    • Debug (--preset dev): 8 XSAVE targets built (1.11s, configure 1.78s); ctest --preset dev -R '^cpu_aot_xsave_state$' --no-tests=error: 1/1 passed (0.45s).
    • Release /O2 (--preset release): 8 XSAVE targets built (0.76s, configure 1.78s); ctest --preset release -R '^cpu_aot_xsave_state$' --no-tests=error: 1/1 passed (0.46s).
  • Mutation checks (Win2025 Debug via --patch, cache bypassed, repo restored after each run):
    1. Hardcoded select_host_disabled_xcomp_bit to return 3: cpu_aot_xsave_state failed (AssertionError: ('0x1f', 3, 5)).
    2. Omitted (1 << disabled_bit) from host_fault: cpu_aot_xsave_state failed (AssertionError on the single-bit XCOMP_BV delta guard vs valid_ctrl).

Verdict: 0 P1, 0 P2. Clean Tier B merge candidate.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043991979 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1686#pullrequestreview-6043991979). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:15:50Z. **Review:** COMMENTED --- Verification review for commit `9ebcb5e14483c2e7074afd585a68736b2ac8e816`: ### Scope & Audit - Tests-only diff (`tests/cpu/xsave_state_check.py`, +181/-12): reads `host_xcr0()` from the lifted DLL, selects the lowest disabled bit in `XCOMP_BV[62:3]` via `select_host_disabled_xcomp_bit`, filters native `#GP` expectations on fixed guest-unsupported cases via `native_compacted_header_must_fault` while keeping all lifted checks unconditional, adds host-XCR0-derived native+lifted `#GP` + valid-control comparisons, and adds synthetic `XCR0=0x1f` / `0x2e7` selection controls. - Zero production code changes, zero weakened assertions, zero temp-file/process leaks, clean-room/title-neutral. ### Checks Executed - **Linux**: - `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. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP, host `XCR0=0x7`)**: - **Debug (`--preset dev`)**: 8 XSAVE targets built (`1.11s`, configure `1.78s`); `ctest --preset dev -R '^cpu_aot_xsave_state$' --no-tests=error`: **1/1 passed** (`0.45s`). - **Release `/O2` (`--preset release`)**: 8 XSAVE targets built (`0.76s`, configure `1.78s`); `ctest --preset release -R '^cpu_aot_xsave_state$' --no-tests=error`: **1/1 passed** (`0.46s`). - **Mutation checks (Win2025 Debug via `--patch`, cache bypassed, repo restored after each run)**: 1. Hardcoded `select_host_disabled_xcomp_bit` to `return 3`: `cpu_aot_xsave_state` **failed** (`AssertionError: ('0x1f', 3, 5)`). 2. Omitted `(1 << disabled_bit)` from `host_fault`: `cpu_aot_xsave_state` **failed** (`AssertionError` on the single-bit `XCOMP_BV` delta guard vs `valid_ctrl`). Verdict: 0 P1, 0 P2. Clean Tier B merge candidate. AI-assisted; commands listed were executed locally.
legacy-code-archaeologist commented 2026-11-24 18:02:58 +00:00 (Migrated from github.com)

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, head 9ebcb5e1.

ctest --preset dev --no-tests=error -R '^cpu_aot_xsave_state$' -V
ctest --preset release --no-tests=error -R '^cpu_aot_xsave_state$' -V

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:

Host XSAVE area (CPUID.0D.0:EBX): 1088 bytes, XCR0=0x1f
compacted xrstor: 50 xsavec round trips, 220 valid and 27 #GP header cases
  (native host-disabled XCOMP_BV bit 5 (XCR0=0x1f, exc='exception: access violation reading 0xFFFFFFFFFFFFFFFF',
   valid restore control matched), lifted-only guest XCOMP_BV refusals=['xcomp-bit3', 'xcomp-bit4', 'xcomp-bit3-only'])
11 mutation controls and 34 host-XCR0 controls passed
  • Selected bit: bit 5 is the lowest bit in 3..62 that 0x1f disables, so the selection works as specified.
  • The native exception: it is the expected one. Windows delivers a user-mode #GP as STATUS_ACCESS_VIOLATION with the fault address 0xFFFFFFFFFFFFFFFF, which is what ctypes prints here.
  • Lifted-only refusals: the three MPX cases stay refused on the lifted side, as R0Y00 asked.

I didn't change anything.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7139265234 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1686#issuecomment-7139265234). Originally posted by [legacy-code-archaeologist](https://github.com/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, head 9ebcb5e1. ``` ctest --preset dev --no-tests=error -R '^cpu_aot_xsave_state$' -V ctest --preset release --no-tests=error -R '^cpu_aot_xsave_state$' -V ``` 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: ``` Host XSAVE area (CPUID.0D.0:EBX): 1088 bytes, XCR0=0x1f compacted xrstor: 50 xsavec round trips, 220 valid and 27 #GP header cases (native host-disabled XCOMP_BV bit 5 (XCR0=0x1f, exc='exception: access violation reading 0xFFFFFFFFFFFFFFFF', valid restore control matched), lifted-only guest XCOMP_BV refusals=['xcomp-bit3', 'xcomp-bit4', 'xcomp-bit3-only']) 11 mutation controls and 34 host-XCR0 controls passed ``` - **Selected bit:** bit 5 is the lowest bit in 3..62 that `0x1f` disables, so the selection works as specified. - **The native exception:** it is the expected one. Windows delivers a user-mode #GP as `STATUS_ACCESS_VIOLATION` with the fault address `0xFFFFFFFFFFFFFFFF`, which is what ctypes prints here. - **Lifted-only refusals:** the three MPX cases stay refused on the lifted side, as R0Y00 asked. I didn't change anything.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1679
No description provided.