mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:40:52 +01:00
[PR #2143] x64_recomp: the QEMU harness maps guest RAM as Normal memory, so unaligned accesses work (X64-RECOMP-QEMU-UNALIGNED) #2147
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2147
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2143
Author: @kevincommits
Created: 11/26/2026
Status: 🔄 Open
Base:
main← Head:x64-recomp-qemu-unaligned📝 Commits (2)
8fe4123fix: x64_recomp QEMU harness maps guest RAM as Normal memory so unaligned accesses workc6029b8test: x64_recomp guest call and ret under the QEMU harness at any code length📊 Changes
2 files changed (+62 additions, -0 deletions)
View changed files
📝
tests/test_x64_recomp.py(+36 -0)📝
tools/x64_recomp.py(+26 -0)📄 Description
Claimed in the coordination issue as: X64-RECOMP-QEMU-UNALIGNED (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7177136024)
What and why
Under
qemu-system-aarch64, every unaligned guest memory access in thetools/x64_recomp.pytest harness hangs until the 15 s timeout. This is onmain, with QEMU 11.1.3:-d intshows why:build_test_kernel's boot stub never turns the MMU on. With the MMU off every data access is Device memory, and an unaligned access to Device memory is an alignment fault. x86 code reads and writes unaligned everywhere, so the guest needs Normal memory.The fix is in the boot stub only:
_emit_identity_mmuwrites 1 GiB block entries for the image and the RW window into one level-1 table page atKERNEL_RW + 0x10000(between the guest stack at+0x8000and the tests' scratch at+0x100000), setsMAIR_EL1,TCR_EL1(39-bit VA, 4 KiB granule) andTTBR0_EL1, then setsSCTLR_EL1M, C and I with A clear. The map is an identity map, so no address the translator or the tests use changes. The Linux ELF path and the translator itself are untouched.I found this while running #1213, whose
test_std_overlapping_backward_rep_movsbends inmov edi, [rbx+2]and times out for this reason.Tested
Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew, at
8564bb48b.ExecTests.test_unaligned_memory_access: 2-, 4- and 8-byte unaligned loads and stores, seven cases. Withmain'stools/x64_recomp.pyall seven time out; with this change all seven return the expected value.python -I tests/test_x64_recomp.py: 34/34 under QEMU (33/33 onmain, so the existing exec tests are unaffected by the MMU being on).python -I tests/test_recomp_census.py: 11/11.tests/test_*.pyunderpython -I: 511 run, 507 pass; the 4 that fail are the same 4 that fail onmain.Not tested: any QEMU older than 11.1.3 (I expect the MMU setup to be valid there too, but did not run it),
qemu-system-aarch64on Linux or Windows hosts, and real arm64 hardware. The table relies on QEMU zeroing RAM at reset.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no shader translator change)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.