From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 963B8C87FD3 for ; Wed, 6 Aug 2025 18:59:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hhUZCtksJ+hyH3WiEydSN1GE2wQHlKztpYeqRz+1MhE=; b=eSziPjyrue/PL+7Ye1MIuLIoha z5ldCm45dSdL/dXAKQeMY38G3x+xMs2o7b5B3cPt7VxH1yh3zRI2nsL9aBtrGEQQBqqchDAMgvnIM dL5us/y2jwyQsOtQYgGM8vaXxKFyowHd+4d4l7apEe5yPZo6+QrAnKg0kH4urTXl9fVc4Hljtim6O ngKVd5X1XeL2Yr8+AibT0qK3N1urhG8B/lgTCNuZWSvqE++596shjPmFBkongn4tRHPBCYJkY2woc b64KMUc8YNldRFnFWZeHEpnsVRhmcePLFDZLQHoy8aQgNobPTVbgAXIil9C3+rOSIeOi96EIwRfee xbVAGekQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ujjMK-0000000G98N-3opb; Wed, 06 Aug 2025 18:59:32 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1ujjJl-0000000G8WY-3Pt2 for linux-arm-kernel@lists.infradead.org; Wed, 06 Aug 2025 18:56:55 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B786F5C28F6; Wed, 6 Aug 2025 18:56:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ECA3C4CEE7; Wed, 6 Aug 2025 18:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754506612; bh=om1aWa/B7Oy/fsSLhs55XzyydC9EjqsVE/7K+ztsDSs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sb5UxwWMSQUxbLB7MzB5pEw56XpOE1zygr73grW+FdGaVGx2g3qeoP/jp+H8oqTK+ pQXnW7KR5mKYtvtBZLmlSOUpLMa0jTStxgV6peAMyAOFeIrjpOT/BWtVOJxLQfqYlg 85vb4+xbkeOoM9PREQGug3Gi3lpLzv5n7QKk0HrVlTbZEGD1JosaDjpJHJH4yX+YgB wsgFbZCMfGmb04wRyMGkbWEGM+G59T+zB+tg6Ew/EA9EnlPk4S6G9SVCFSVGB1SgN5 VlU4JiQ5zoCrudWrWmjkwQS7He0ehkVGdoN63KR+XD5R9qtx79BuHhTjPigr5Af45c AWZYis9BefrDQ== 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 1ujjJi-004by9-1y; Wed, 06 Aug 2025 19:56:50 +0100 Date: Wed, 06 Aug 2025 19:56:49 +0100 Message-ID: <865xf09t3i.wl-maz@kernel.org> From: Marc Zyngier To: Volodymyr Babchuk Cc: "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.linux.dev" , "linux-kernel@vger.kernel.org" , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon Subject: Re: [PATCH v1 2/2] KVM: arm64: nv: update CPU register PAR_EL1 after 'at s*' In-Reply-To: <20250806141707.3479194-3-volodymyr_babchuk@epam.com> References: <20250806141707.3479194-1-volodymyr_babchuk@epam.com> <20250806141707.3479194-3-volodymyr_babchuk@epam.com> 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) 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: Volodymyr_Babchuk@epam.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250806_115653_930866_3EC4417E X-CRM114-Status: GOOD ( 26.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 06 Aug 2025 15:17:55 +0100, Volodymyr Babchuk wrote: > > Previously this code update only vCPU's in-memory value, which is good, > but not enough, as there will be no context switch after exiting > exception handler, so in-memory value will not get into actual > register. > > It worked good enough for VHE guests because KVM code tried fast path, > which of course updated real PAR_EL1. Nothing to do with VHE, I'm afraid. We can take the slow path for any odd reason, even on VHE. This is more of a structural problem, see below. > > Signed-off-by: Volodymyr Babchuk > --- > arch/arm64/kvm/sys_regs.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 7b8a0a6f26468..ab2b5e261d312 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -3463,6 +3463,9 @@ static bool handle_at_s1e2(struct kvm_vcpu *vcpu, struct sys_reg_params *p, > > __kvm_at_s1e2(vcpu, op, p->regval); > > + /* No context switch happened, so we need to update PAR_EL1 manually */ > + write_sysreg(vcpu_read_sys_reg(vcpu, PAR_EL1), par_el1); > + This looks like the wrong fix, as it papers over another issue. The core problem is vcpu_write_sys_reg() (resp. read) does the wrong thing with registers such as PAR_EL1, which are not translated between EL1 and EL2, and therefore are always live, no matter what. Can you please try the hack below? I don't like it, but at least it shows where the actual problem lies. Thanks, M. diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index ad25484772574..167f0d411a708 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -95,7 +95,13 @@ static bool write_to_read_only(struct kvm_vcpu *vcpu, return true; \ } -static bool get_el2_to_el1_mapping(unsigned int reg, +#define COMMON_SYSREG(r) \ + case r: { \ + *el1r = __INVALID_SYSREG__; \ + return is_hyp_ctxt(vcpu); \ + } + +static bool get_el2_to_el1_mapping(const struct kvm_vcpu *vcpu, unsigned int reg, unsigned int *el1r, u64 (**xlate)(u64)) { switch (reg) { @@ -119,6 +125,7 @@ static bool get_el2_to_el1_mapping(unsigned int reg, PURE_EL2_SYSREG( HAFGRTR_EL2 ); PURE_EL2_SYSREG( CNTVOFF_EL2 ); PURE_EL2_SYSREG( CNTHCTL_EL2 ); + COMMON_SYSREG( PAR_EL1 ); MAPPED_EL2_SYSREG(SCTLR_EL2, SCTLR_EL1, translate_sctlr_el2_to_sctlr_el1 ); MAPPED_EL2_SYSREG(CPTR_EL2, CPACR_EL1, @@ -158,7 +165,7 @@ u64 vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg) if (!vcpu_get_flag(vcpu, SYSREGS_ON_CPU)) goto memory_read; - if (unlikely(get_el2_to_el1_mapping(reg, &el1r, &xlate))) { + if (unlikely(get_el2_to_el1_mapping(vcpu, reg, &el1r, &xlate))) { if (!is_hyp_ctxt(vcpu)) goto memory_read; @@ -219,7 +226,7 @@ void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg) if (!vcpu_get_flag(vcpu, SYSREGS_ON_CPU)) goto memory_write; - if (unlikely(get_el2_to_el1_mapping(reg, &el1r, &xlate))) { + if (unlikely(get_el2_to_el1_mapping(vcpu, reg, &el1r, &xlate))) { if (!is_hyp_ctxt(vcpu)) goto memory_write; -- Without deviation from the norm, progress is not possible.