Skip to contentSkip to conversation

KVM: arm64: Give AArch32 guests' CLIDR reads the vCPU's CLIDR_EL1

PATCH Applied Ben Avison 2 participants 2 messages Dec 1 – Dec 4

Subsystems (3)
lore
Share & tools
lore

Ben Avison

author
#0 lore raw

PATCH 1/1 KVM: arm64: Give AArch32 guests' CLIDR reads the vCPU's CLIDR_EL1

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")

---
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(-)
arch/arm64/kvm/sys_regs.c +1 -1
index 850eba167..955bf1e4e 100644
@@ -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

Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 11 lines · Ben Avison

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.

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: Give AArch32 guests' CLIDR reads the vCPU's CLIDR_EL1

      commit: 1eca9d70e9e04e5cbd3a9efc927013b4e94ad889

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.