From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E89023D7CF; Wed, 13 Aug 2025 06:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755068106; cv=none; b=l6s+oNAxEhljNLlQY0CEKR1PgjcwiqrY7Nm0Q7FEECGACUmmPDdo6ows+WJqPgeoIj9QjVUBq8BDxMLIb4okLrcEuvh/OocVydnUBGOzBpbOaHXT2+/LS6VArGBBAs+yK8ll8AksiKr+sRRA1lGU+nemeJMChPBQgcfzs+m/n3E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755068106; c=relaxed/simple; bh=R697c/HBZYtRS8/J/tGfw/3B8h/z4SXcEWejW3uErCI=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=V9vE+T1WI9QdusResUP3bxbB+zCtDvR5GT7ahuzkcm5tKgncpaSvWNyQPNXu+tawb+JtzAn1YuB1G8EmN9lpSWKdkjKZ6m9yztJVBXsvfj+xGJy1HVFaz1170RNnvJfQ7VugSFB4KhTy6jhAH7lZWaI8aOsByodW4laJrr8C3JQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sljCin8S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sljCin8S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 000C2C4CEEB; Wed, 13 Aug 2025 06:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755068106; bh=R697c/HBZYtRS8/J/tGfw/3B8h/z4SXcEWejW3uErCI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sljCin8SEFm48vxdfwnj+wQpjbnb8rGMLQKURBN92hKOvOwcJc9k0pPl6dfbzWyOM xXcswj+NSQ6Zn1QGFxpj6KKZGbmPLfMw5TTP//HXCij5s0ffjFefxCGuyLetXTFvEZ 0tLdVHIn65PQuQCPYBtH7ag4X7O81sPjxf64UPqZDKa1njY4b4W3TMNBU4mvouCW6Z 38YPuo0qccrITHN55Gm1Pmut472oeI5LmHe5EN2MClR5FRBLQvzKiok4eHvYpn+qy9 OZH50wZzvc8Cb5t91+/l1zwHuJvHUMqrJT34mE+PRX07zMp80VuR+Xtt07sLToA916 p2Lp4myYT12Mw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1um5Ny-006x5m-Fu; Wed, 13 Aug 2025 07:54:58 +0100 Date: Wed, 13 Aug 2025 07:54:58 +0100 Message-ID: <86jz3790e5.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Volodymyr Babchuk , Joey Gouly , Suzuki K Poulose , Zenghui Yu Subject: Re: [PATCH 2/2] KVM: arm64: Fix vcpu_{read,write}_sys_reg() accessors In-Reply-To: References: <20250809144811.2314038-1-maz@kernel.org> <20250809144811.2314038-3-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, volodymyr_babchuk@epam.com, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Hey Oliver, Thanks for looking into this. On Tue, 12 Aug 2025 21:23:33 +0100, Oliver Upton wrote: > > On Sat, Aug 09, 2025 at 03:48:11PM +0100, Marc Zyngier wrote: > > @@ -144,125 +156,120 @@ static bool get_el2_to_el1_mapping(unsigned int reg, > > MAPPED_EL2_SYSREG(ZCR_EL2, ZCR_EL1, NULL ); > > MAPPED_EL2_SYSREG(CONTEXTIDR_EL2, CONTEXTIDR_EL1, NULL ); > > MAPPED_EL2_SYSREG(SCTLR2_EL2, SCTLR2_EL1, NULL ); > > + case CNTHCTL_EL2: > > + /* CNTHCTL_EL2 is super special, until we support NV2.1 */ > > + loc->loc = ((is_hyp_ctxt(vcpu) && vcpu_el2_e2h_is_set(vcpu)) ? > > + SR_LOC_SPECIAL : SR_LOC_MEMORY); > > + break; > > + case TPIDR_EL0: > > + case TPIDRRO_EL0: > > + case TPIDR_EL1: > > + case PAR_EL1: > > + /* These registers are always loaded, no matter what */ > > + loc->loc = SR_LOC_LOADED; > > + break; > > default: > > - return false; > > + /* > > + * Non-mapped EL2 registers are by definition in memory, but > > + * we don't need to distinguish them here, as the CPU > > + * register accessors will bail out and we'll end-up using > > + * the backing store. > > + * > > + * EL1 registers are, however, only loaded if we're > > + * not in hypervisor context. > > + */ > > + loc->loc = is_hyp_ctxt(vcpu) ? SR_LOC_MEMORY : SR_LOC_LOADED; > > Hmm... I get the feeling that this flow is becoming even more subtle. > There's some implicit coupling between this switch statement and the > __vcpu_{read,write}_sys_reg_from_cpu() which feels like it could be > error prone. Especially since we're gonna lose the WARN() that would > inform us if an on-CPU register was actually redirected to memory. This implicit behaviour was already present, and nobody noticed it. See how the FGT2 registers are currently missing from the list of "pure" registers. We didn't see the problem because the fallback saves us. This is what decided me to throw away the "pure" annotation and lump both non-remapped EL2 and EL1 registers together. > I'm wondering if we need some macro hell containing the block of > registers we handle on-CPU and expand that can be expanded into this > triage switch case as well as the sysreg accessor. That's an interesting approach. A bit tricky, because we do rely on heavy inlining and constant propagation in the CPU accessors, but maybe there's a way to deal with that... > What you have definitely seems correct, though. I'll twiddle a bit and > see if I come up with something, although I imagine what you have is > what we'll use in the end anyway. I'll have a look in parallel and post my findings, if any. Thanks, M. -- Without deviation from the norm, progress is not possible.