cpu: lower CPUID and XGETBV in an opt-in host-CPU profile #962
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/969"
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 legacy-code-archaeologist on 2026-11-23T19:15:19Z.
Change
Lowers CPUID and XGETBV in
tools/ffx_version_query.pyas the opt-in host-CPU profile agreed in #937. The profile is enabled bylower(..., host_cpu=True); the default profile still rejects both instructions.They report the host processor, not a console CPU. No guest feature table is applied.
__cpuidexand writes EAX, EBX, ECX and EDX zero-extended._xgetbvand writes EDX:EAX zero-extended./O2: a probe withcl /O2(MSVC 19.52) showed that a discarded__cpuidexkeeps itscpuid, while a discarded_xgetbvis removed. So XGETBV keeps its result in avolatilelocal, and itsplaincontrol repeats the finding inside the test.Tests
cpu_aot_cpuid(cpuid.asm) andcpu_aot_xgetbv(xgetbv.asm) have separate fixtures. A native harness supplies the expected values; it is never translated.Pinning. Both checks pin the thread, in its processor group, to the logical processor it is on, and confirm it runs there. Every native and translated read, and the harness reads they are compared with, run there. The previous group affinity is restored in a
finally.CPUID check:
add r8, r8presets, all four results must equal the host's, with zero upper halves and ZF/CF kept.XGETBV check:
0x7fffffff) runs in a child process. Native and translated code must report the same fault. This checks fault passthrough only, not XINUSE.Controls (mutations of the generated C++, each must break a property; every replacement is anchored on the new statement):
noext: keeps an upper half.swap: exchanges EBX and EDX for CPUID, or the two halves for XGETBV.nosubleaf(CPUID): drops ECX. It is measurable only when a covered leaf differs between subleaf 0 and 1; otherwise the test exits 77 after its other checks.constant: a fixed result. XGETBV uses 0, which is never XCR0 because bit 0 is always set.flags: flips ZF and CF./O2: the translations are also built withcl /O2. A walk that follows every branch must find each CPUID or XGETBV, including the discarded one, and the rules must still hold. XGETBV'splaincontrol (novolatile) must lose the discarded read.Verification
At
d10c6fe(onmaina48c2b9) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ (OSXSAVE set, XCR00x1f), MSVC 19.52, Python 3.12:ctest --preset dev --no-tests=error -R '^cpu_aot_(cpuid|xgetbv)$' -V: both pass.nosubleafis measured (CPUID(0x4, 1) gave … 0x1c004121 …, host … 0x1c004122 …).0x1fmatches.cpu_xgetbv_plain_o2reports{'xgetbv_op': 1, 'xgetbv_unused': 0}. The reserved index faults alike in both children:exception: access violation reading 0xFFFFFFFFFFFFFFFF, which is how Windows reports the #GP.has_osxsaveforced to 0, every XGETBV call raising):cpu_aot_xgetbvexits 77 before any XGETBV.ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 185 of 186 pass, with three capability skips (cpu_aot_fences_hints_clwb,cpu_aot_crypto_sha,cpu_shim_chain_hardware).cpu_shim_shadow_hardwarein its native run, independent of this change and reported in #799.tools/form_coverage.pyon a JUnit run of that suite no longer listscpuidorxgetbv.tests/docs_links_check.py,tests/bidi_controls_check.pyandtests/form_coverage_check.pypass.No README row lists individual lowered instructions (as for #789 and #807), so the README is unchanged.
Limits
Refs #937
AI-assisted: written with Claude Code; design and diff reviewed by fresh agents; checked and submitted by the account owner.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:24:33Z.
The pinned-thread comparison and discarded-read control match #937. The docs currently say XGETBV reads XCR0 only, while the emitted code forwards any ECX to the host intrinsic. Please distinguish the supported caller contract (OSXSAVE and XCR0) from what the passthrough may execute. An invalid-index child verifies native fault behavior. It does not verify XINUSE on a host where index 1 is valid and observes the current extended-state use. Keep that state outside the first profile unless it has its own native differential.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T19:41:35Z.
Thanks.
b22457dseparates the two in the docs, the lowering comment and the PR description:_xgetbvunchanged.The generated C++ is unchanged.
cpu_aot_cpuidandcpu_aot_xgetbvstill pass, andtests/docs_links_check.pyandtests/bidi_controls_check.pypass.AI-assisted (Claude Code).