[PATCH v2 0/2] KVM: arm64: Fix and test MMIO sign-extending loads

From: Fuad Tabba

Date: Thu Jun 25 2026 - 10:48:23 EST


Hi folks,

Changes since v1 [1]:
- Patch 1: rewrote the commit msg in the Arm ARM's terms, with the Mem
accessor performing the access keyed on the access size and SignExtend
handling the register width. No code change. (Marc)
- Patch 2: added a big-endian pass to the test. The big-endian loads run
at EL0 with SCTLR_EL1.E0E set, so the access is big-endian while the
stage-1 walk stays little-endian. (Marc)

Oliver's Reviewed-by is on patch 1 only: the code there is unchanged, while
the test in patch 2 gained the big-endian coverage above.

A sign-extending load (LDRSB/LDRSH/LDRSW) from emulated MMIO returns a
zero-extended value rather than the sign-extended one the architecture
requires; vcpu_data_host_to_guest() strips the sign bits when it masks
the data to the access width.

If my git archeology is right, the masking dates to 2014 (b30070862edbd,
big-endian support) and has been wrong ever since, but sign-extending
loads from device memory are rare enough that nobody hit it. Patch 1
fixes it; patch 2 adds a selftest so it doesn't regress.

Based on Linux 7.1 (8cd9520d35a6c).

Cheers,
/fuad

[1] https://lore.kernel.org/all/20260622190701.2039766-1-fuad.tabba@xxxxxxxxx/

Fuad Tabba (2):
KVM: arm64: Fix sign-extension of MMIO loads
KVM: arm64: selftests: Add MMIO sign-extending load test

arch/arm64/kvm/mmio.c | 7 +-
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/arm64/mmio_sign_ext.c | 259 ++++++++++++++++++
3 files changed, 264 insertions(+), 3 deletions(-)
create mode 100644 tools/testing/selftests/kvm/arm64/mmio_sign_ext.c

--
2.39.5