cpu: lift RDFSBASE, RDGSBASE, and RDPID in cpu_switch_aot #1442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1449"
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 Ammmae0x on 2026-11-24T11:45:40Z.
Change
Add opt-in
--host-cpu(host_cpu=True, CMakeHOST_CPU) lifting intools/cpu_switch_aot.pyandCMakeLists.txt(cpu_translation), along with a source-built MASM fixture (tests/cpu/switch_fsgsbase_rdpid.asm,tests/cpu/switch_fsgsbase_rdpid.def), differential/control harness (tests/cpu/switch_fsgsbase_rdpid_check.py), and experiment documentation (docs/experiments.md) covering three read-only / processor-ID x64 mnemonics fromdocs/coverage/x64_zen2.tsvgroupInteger:rdfsbase(32- and 64-bit register forms via_readfsbase_u32/_readfsbase_u64)rdgsbase(32- and 64-bit register forms via_readgsbase_u32/_readgsbase_u64)rdpid(64-bit register form via_rdpid_u32)All three instructions are registered in
FLAG_NEUTRAL, preserve unreferenced reads under/O2viaconst volatile, and are rejected whenhost_cpuis omitted, whenrsp/espis addressed, when alock/rep/repne/segment prefix is present, or whenrdpiduses its 32-bit encoding. Host segment-base writes (wrfsbase,wrgsbase) are explicitly excluded from this profile and rejected both with and without--host-cpu.Verification
Verified at commit
3f445536:& .\tools\dev.ps1; ctest --preset dev -Nandctest --preset release -N->Total Tests: 918on both presets (0 dropped tests).cmake --build --preset dev --target cpu_switch_fsgsbase_rdpid cpu_switch_fsgsbase_rdpid_lifted cpu_register_probe cpu_switch_bswap cpu_switch_bswap_lifted-> exited 0 (0 errors, 0 warnings).cmake --build --preset release --target cpu_switch_fsgsbase_rdpid cpu_switch_fsgsbase_rdpid_lifted-> exited 0 (0 errors, 0 warnings).ctest --preset dev --no-tests=error -R '^(cpu_aot_switch_fsgsbase_rdpid|cpu_aot_switch_bswap)$' -V->2/2passed:cpu_aot_switch_bswap(27357 differential comparisons passed) andcpu_aot_switch_fsgsbase_rdpid(232 CMake-lifted + 232 /O2-lifted checks across 4 pinned CPU(s), including canonicalFS_BASEsweeps via the native-onlynative_with_fsbasehelper,RDTSCPIA32_TSC_AUXcross-checks, 5/O2mutated-C++ controlskeep_high32/truncate_64/swap_fs_gs/constant_rdpid/clobber_flags,27unit/MASM rejections includingwrfsbase/wrgsbase32/64-bit, and9PE-patched DLL rejections).ctest --preset release --no-tests=error -R '^cpu_aot_switch_fsgsbase_rdpid$' -V->1/1passed with identical232 CMake-lifted + 232 /O2-lifted checks, 5 mutated-C++ controls, and all rejections passing.out/build/dev/form_coverage/cpu_aot_switch_fsgsbase_rdpid.txtrecorded:add,mov,pop,push,rdfsbase,rdgsbase,rdpid,ret,setb,sete,seto,setp,sets,xor..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py-> exited 0 (form coverage checks passed)..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py-> exited 0 (Checked 16 Markdown files and 332 links.)..\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py-> exited 0 (Checked 1201 tracked source, script and build/CI files: no bidirectional controls.).Evidence and follow-up
tests/cpu/switch_fsgsbase_rdpid.asmandtests/cpu/switch_fsgsbase_rdpid.defare source-built in-repo MASM fixtures gated at runtime byCPUID.07H(FSGSBASEEBX[0]andRDPIDECX[22], returning exit code77on hosts without support).wrfsbase/wrgsbase) require a separate write profile with an explicit isolation/restoration contract; cross-threadFS_BASE/GS_BASEmigration and title CPU code execution are not covered.Checklist
AI-assisted.
[PR #1449] cpu: lift RDFSBASE, RDGSBASE, WRFSBASE, WRGSBASE, and RDPID in cpu_switch_aotto [PR #1449] cpu: lift RDFSBASE, RDGSBASE, and RDPID in cpu_switch_aotImported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:17:36Z.
Review: CHANGES_REQUESTED
The source-built checks show that these particular functions restore their host state. The public --host-cpu switch also permits an arbitrary accepted PE function to write the host thread's FS/GS bases from a defined guest register. The profile does not enforce the fixture's restoration or protect host runtime accesses during the call. Please split the read-only and processor-ID work from host segment-base writes. Any later write profile needs a defined isolation/restoration contract and rejection outside it.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T12:32:03Z.
Split
WRFSBASE/WRGSBASEout oftools/cpu_switch_aot.py(--host-cpu) in commit3f445536so this PR only lifts read-onlyRDFSBASE,RDGSBASE, andRDPIDand rejects host segment-base writes both with and without--host-cpu:WRFSBASE/WRGSBASEfromFLAG_NEUTRAL,HOST_CPU_READ_BASE_CODES,Lifter.lower, andPRELUDE(<atomic>).tests/cpu/switch_fsgsbase_rdpid.asmwith read-only nonvolatile reads (read_host_nonvolatile) plus a native-onlynative_with_fsbasehelper for canonicalFS_BASEdifferential coverage, and added explicitwrfsbase/wrgsbase32/64-bit rejection controls in MASM negative exports,Lifter.lower, and PE-patched DLL checks.cpu_aot_switch_fsgsbase_rdpidacrossdevandreleasebuilds (232 CMake-lifted + 232/O2-lifted checks, 5 mutated-C++ controls, 27 unit/MASM rejections, 9 PE-patched rejections),cpu_aot_switch_bswap,form_coverage_check.py,docs_links_check.py, andbidi_controls_check.py.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:06:18Z.
Review: APPROVED
Windows Release native and lifted comparison passed. The opt-in now permits the read-only forms. The previous FS/GS base writes are excluded, and the unsupported mode and flag-preservation controls still execute.