* [PATCH] KVM: arm64: Give AArch32 guests' CLIDR reads the vCPU's CLIDR_EL1
@ 2026-12-01 22:50 Ben Avison
0 siblings, 0 replies; only message in thread
From: Ben Avison @ 2026-12-01 22:50 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton
Cc: Fuad Tabba, Joey Gouly, Steffen Eiden, Suzuki K Poulose,
Zenghui Yu, Akihiko Odaki, kvmarm, linux-arm-kernel, linux-kernel,
Ben Avison, stable
Since commit 7af0c2534f4c ("KVM: arm64: Normalize cache configuration"),
access_clidr() returns __vcpu_sys_reg(vcpu, r->reg), but the cp15_regs[]
entry for the AArch32 CLIDR (MRC p15, 1, <Rt>, c0, c0, 1) names no
register, so r->reg is 0 (__INVALID_SYSREG__) and a 32-bit EL1 guest
reads 0: no caches, LoC 0. The register is trapped (HCR_EL2.TID2, or
TID4 with FEAT_EVT), so the hardware's value never shows either. The
AArch32 CLIDR is architecturally mapped to CLIDR_EL1[31:0], so it should
read what the vCPU's CLIDR_EL1 holds, as 64-bit guests already do. Name
CLIDR_EL1 in the entry, as its neighbour CSSELR does with CSSELR_EL1.
Seen on a Raspberry Pi 4 (Cortex-A72) with QEMU -cpu host,aarch64=off:
my guest kernel stops in its CPU set-up because CLIDR doesn't report
separate L1 instruction and data caches. With this patch the guest reads
0x09200003 (separate L1 I and D; LoUIS, LoC and LoUU 1), the value KVM
fabricates for CLIDR_EL1 on that machine.
The bug was found, and this patch written, with the help of an AI coding
assistant (Claude, in Claude Code); I have reviewed and tested it.
Fixes: 7af0c2534f4c ("KVM: arm64: Normalize cache configuration")
Cc: stable@vger.kernel.org
Signed-off-by: Ben Avison <bavison@riscosopen.org>
---
Testing: on a Raspberry Pi 4 Model B (Cortex-A72: nVHE, no FEAT_EVT or
FEAT_S2FWB) with the Raspberry Pi kernel tree (rpi-6.18.y, 6.18.65) plus
this patch, QEMU 10.0.13, -accel kvm -cpu host,aarch64=off. A minimal
AArch32 guest that reads its ID registers at EL1 sees CLIDR 0x00000000
under the stock 6.18.50 kernel and 0x09200003 with the patch; CTR and
MIDR read the same under both. My 32-bit kernel now gets past the CLIDR
check in its CPU set-up. 64-bit guests (bare-metal test kernels and
benchmarks under -cpu host) behave as before. On v7.4-rc1, the base
here, it was only build-tested (clang, arm64 defconfig, W=1: no
warnings). Not run: the KVM selftests and kvm-unit-tests (as far as I
know, none of them reads CLIDR from a 32-bit EL1 guest). Only nVHE was
tested: the A72 has no VHE.
checkpatch --strict flags the changed line's "CRn( 0)" spacing and the
Op1/CRn/CRm/Op2 macro names: that is the style of every entry in the
table, kept as it is.
arch/arm64/kvm/sys_regs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 850eba167..955bf1e4e 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -4809,7 +4809,7 @@ static const struct sys_reg_desc cp15_regs[] = {
{ CP15_PMU_SYS_REG(DIRECT, 0, 14, 15, 7), .access = access_pmu_evtyper },
{ Op1(1), CRn( 0), CRm( 0), Op2(0), access_ccsidr },
- { Op1(1), CRn( 0), CRm( 0), Op2(1), access_clidr },
+ { Op1(1), CRn( 0), CRm( 0), Op2(1), access_clidr, NULL, CLIDR_EL1 },
/* CCSIDR2 */
{ Op1(1), CRn( 0), CRm( 0), Op2(2), undef_access },
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 22:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 22:50 [PATCH] KVM: arm64: Give AArch32 guests' CLIDR reads the vCPU's CLIDR_EL1 Ben Avison
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox