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 4964EC87FCB for ; Tue, 5 Aug 2025 18:44:15 +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=fWs9/Ib/1jF9TVWyFyfDPNXwVg0uexEn3Ebjh4xvOx4=; b=lTjGmNNF/1cFIVqwZVLWAwXYIf T/TCElSjWAoGoW6sp0v7oXHqQehRXzu3Nfu0+CYMv2fIEXno3DsKxm0S/bpuYu9eXPLXe2KLaclqa bxPG5qv3wlP6bh5SxXUORQpfDDo4JcYvE6DplgwvvB+aSsTWoz9UVBHR9+pcs013TpVoTlM2MecUg DW0GdbKvDONXjA7lOgkuk4CiTFyDH4MeqLfo36QjMvcUYwT3OSL3Tsgm9KaDjfpoYYha15hnQYQi4 sCJ+alS0BZ3H+Q4KcM6SUQN5Una1kPWMaQhXPIaxbPhX5HS+uaRS1Sy9BkhLHnOchB815e6Qlw9OM adR9/Q+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ujMdu-0000000Daey-2fKW; Tue, 05 Aug 2025 18:44:10 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1ujMbK-0000000DaPf-07dt for linux-arm-kernel@lists.infradead.org; Tue, 05 Aug 2025 18:41:30 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 43E77601D1; Tue, 5 Aug 2025 18:41:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8238C4CEF0; Tue, 5 Aug 2025 18:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754419289; bh=uD11fUjResybtgXeRjv89oPYdFDMt5vMpFniG+hDzd8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BZlDorHxq6qUpw+ESL8LNjn4/KQtwOQtiyp2gso4NevuBnyOmX7dF/d8BR4FBTCJ9 +bRV6K4Hi6t1ldnVjfwQrURP50Dppd2O4f8VRFq6rGSXgNOUQJoE1LO1FQf3HMpYvw oC6ozpTr+8oVDTEZDJhOR+QxZGPicxKcJ4cyBRa9ydzgkDgWjqlNzlrbbMcGyP8Lli yNjEd9zS9a+viAFkNuAXjIMs6Bbw9FtyQrDfkl45+GIyIbB9Rk1YT8R152XLaC/dAz Bp5OmEQaoTbbpLZ0viPsv2VS7UPY12r3YQjOqHsQGSdUYr1OY3UOeE+SEwSnIQmkjo I69VD6kwInbfQ== 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 1ujMbG-004FWi-QC; Tue, 05 Aug 2025 19:41:26 +0100 Date: Tue, 05 Aug 2025 19:41:26 +0100 Message-ID: <86cy99a9wp.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, vdonnefort@google.com, qperret@google.com, sebastianene@google.com, keirf@google.com, smostafa@google.com Subject: Re: [PATCH v1 3/4] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception In-Reply-To: <20250805135617.831971-4-tabba@google.com> References: <20250805135617.831971-1-tabba@google.com> <20250805135617.831971-4-tabba@google.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: tabba@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, vdonnefort@google.com, qperret@google.com, sebastianene@google.com, keirf@google.com, smostafa@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false 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 Tue, 05 Aug 2025 14:56:16 +0100, Fuad Tabba wrote: > > In pKVM, a race condition can occur if a guest updates its VBAR_EL1 > register and, before a vCPU exit synchronizes this change, the > hypervisor needs to inject an undefined exception into a protected > guest. > > In this scenario, the vCPU still holds the stale VBAR_EL1 value from > before the guest's update. When pKVM injects the exception, it ends up > using the stale value. > > Explicitly read the live value of VBAR_EL1 from the guest and update the > vCPU value immediately before pending the exception. This ensures the > vCPU's value is the same as the guest's and that the exception will be > handled at the correct address upon resuming the guest. > > Signed-off-by: Fuad Tabba > --- > arch/arm64/kvm/hyp/nvhe/sys_regs.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c > index bbd60013cf9e..b34b10be1ad7 100644 > --- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c > +++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c > @@ -253,6 +253,7 @@ static void inject_undef64(struct kvm_vcpu *vcpu) > > *vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR); > *vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR); > + vcpu_write_sys_reg(vcpu, read_sysreg_el1(SYS_VBAR), VBAR_EL1); > > kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC); > There is something I don't understand. vcpu_write_sys_reg() is only useful if you make use of the SYSREGS_ON_CPU flag. Which is only driven by the VHE code (in arch/arm64/kvm/hyp/vhe/sysreg-sr.c). As a consequence, this only writes to memory, since the flag is always false, and we take the following path: static inline void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg) { u64 (*xlate)(u64) = NULL; unsigned int el1r; if (!vcpu_get_flag(vcpu, SYSREGS_ON_CPU)) goto memory_write; [...] memory_write: __vcpu_assign_sys_reg(vcpu, reg, val); } My conclusion so far is that you only ever need to write to the shadow view of the register, and that the previous patch serves no purpose. Am I missing anything? M. -- Without deviation from the norm, progress is not possible.