Repository navigation
cpu: lower CPUID and XGETBV in an opt-in host-CPU profile - #969
Conversation
As agreed in R0Y00#937, lower(..., host_cpu=True) lowers CPUID and XGETBV; the default profile still rejects both. They report the host processor; no guest feature table is applied. CPUID passes the guest EAX leaf and ECX subleaf to __cpuidex and writes all four results zero-extended. XGETBV passes ECX to _xgetbv and writes EDX:EAX zero-extended. Both keep the flags. A discarded CPUID stays in /O2 code; XGETBV keeps a volatile result, because /O2 removes a discarded one without it. cpu_aot_cpuid and cpu_aot_xgetbv pin the thread to its logical processor and restore the previous group affinity afterwards. They compare native, translated and harness reads for twelve leaf/subleaf pairs and for XCR0, with zero-extended results and kept flags. XGETBV exits 77 without OSXSAVE before any XGETBV runs, reads XCR0 only, and checks a reserved index in a child process, where native and translated code report the same fault. Mutated controls must each break a property, and /O2 builds are walked to confirm every read survives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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. |
… executes The lowering passes any ECX to the host; the supported contract is a caller that checked OSXSAVE and reads XCR0. The invalid-index child checks fault passthrough only, and XINUSE stays outside the profile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks.
The generated C++ is unchanged. AI-assisted (Claude Code). |
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 Create the EXE shadow device through the Xbox shim #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