Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Avison <bavison@riscosopen.org>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: Fuad Tabba <fuad.tabba@linux.dev>,
	Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Akihiko Odaki <akihiko.odaki@daynix.com>,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Ben Avison <bavison@riscosopen.org>,
	stable@vger.kernel.org
Subject: [PATCH] KVM: arm64: Give AArch32 guests' CLIDR reads the vCPU's CLIDR_EL1
Date: Tue,  1 Dec 2026 22:50:16 +0000	[thread overview]
Message-ID: <20261201225016.62335-1-bavison@riscosopen.org> (raw)

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



                 reply	other threads:[~2026-12-01 22:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201225016.62335-1-bavison@riscosopen.org \
    --to=bavison@riscosopen.org \
    --cc=akihiko.odaki@daynix.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=seiden@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox