From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BEE1606A31F for ; Sun, 6 Dec 2026 11:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fi93kaAO; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eH5bFl6E 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-Unsubscribe-Post:List-Owner; bh=/tjPV1TJwe/yznhlXKYtgL63Qo0pdV2R0LTSLXN9wT8=; b=fi93kaAOk6rXkS3WfYB+eADODo tDNHhlsqjBTO3M1fkLj2eiaZdGfQJSTvtts6JV88GwufRnjYeNEFjkUaPkyMCwF1XVWQEAIM9PEWT Et820cJ38AFn71dG3isjCUDhZlYiy2gxCBXmhK7ZuZSLphL/FAutlc+1QfO6cV7ydmBAnSTMVqC2u u3keODYWV8X0Mz9+0MK5rVWA/JkxL17LLQnJBliAqvubHCqSb8VWr5Rcw0eq1UApJMIuZqRNGhw+4 FK/PTj5PzxNM+TD6hTos3YoC8g26z2Wh1I4ic4Cd8domQVxMAcLg8c8bx2V3elbyrKYi37JtNxT7D 9xfYVIBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaAip-00000003Xyc-14rz; Sun, 06 Dec 2026 11:48:03 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaAin-00000003XyT-37qt for linux-arm-kernel@lists.infradead.org; Sun, 06 Dec 2026 11:48:01 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 2F6E844880; Sun, 6 Dec 2026 11:48:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D82E1F0092B; Sun, 6 Dec 2026 11:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796557681; bh=/tjPV1TJwe/yznhlXKYtgL63Qo0pdV2R0LTSLXN9wT8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=eH5bFl6EpdAiiVh1EOhTV4+sWdy57lWfsgGs6rQASK1j5Jkywe0QY8wJE6+Zkx/hD bk6P6m6b4c9yRy8YVFVK7bTAAtmTZlSHfIU7TW8skQJgblHbhY4gP9WMJ1i7x0rqGs NhoSSTgcieTf2CeGhEJiYyiP832eZnU6QczO8Z+N7f3xG7+zmGfVHVwzpHUEXlhnDe ORJu4Xe8CpoELRXRq5y0MLKICTI5/fh+bqC4fOK0imWkeg1XzxXqjI3TWsxP4bCK9n IRgliM9ZOVZx3dE9BwZgppqNSFxpkeGgpsboy3gE39c11WAolBYMi/DdxgfmrVoSV3 UVCsYC6cmg/eg== 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.98.2) (envelope-from ) id 1xaAik-00000007kCw-21a2; Sun, 06 Dec 2026 11:47:58 +0000 Date: Sun, 06 Dec 2026 11:47:57 +0000 Message-ID: <86mrqiwryq.wl-maz@kernel.org> From: Marc Zyngier To: Dan Carpenter Cc: Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Marcelo Tosatti , Rusty Russell , James Morse , Eric Auger , Sebastian Ott , Paolo Bonzini , Sean Christopherson , Shuah Khan , Karthik Bhargavan , =?UTF-8?B?Q2zDqW1lbnQ=?= Blaudeau , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v4 3/9] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu In-Reply-To: <20261204-double_exception_v4-v4-3-523921511673@pereq.eu> References: <20261204-double_exception_v4-v4-0-523921511673@pereq.eu> <20261204-double_exception_v4-v4-3-523921511673@pereq.eu> 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) X-Archived-By: 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: dan@pereq.eu, oupton@kernel.org, fuad.tabba@linux.dev, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, mtosatti@redhat.com, rusty@rustcorp.com.au, james.morse@arm.com, eric.auger@redhat.com, sebott@redhat.com, pbonzini@redhat.com, seanjc@google.com, shuah@kernel.org, karthik@pereq.eu, clement@cryspen.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, stable@vger.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-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, 04 Dec 2026 08:48:07 +0000, Dan Carpenter wrote: > > Resetting a vcpu keeps the old values of SP_EL1, ELR_EL1 and SPSR_EL1. > Commit e47c2055c68e ("KVM: arm64: Make struct kvm_regs userspace-only") > changed the reset to only clear the general purpose registers, SP, PC > and PSTATE, and later commits moved these three registers to the system > register array without a reset value. Commit 85d703746154 ("KVM: arm64: > Fully zero the vcpu state on reset") fixed the FP registers and the > 32-bit SPSRs the same commit missed, but not these three. > > The impact is that the guest that boots next can read the previous > kernel's stack pointer and exception return address. KVM_GET_ONE_REG > also returns the old values to userspace, and a rebooted VM doesn't > start in the same state as a new one. > > Zero them in kvm_reset_vcpu_core(), which pkvm_reset_vcpu() also uses > when a protected vcpu is turned on with PSCI CPU_ON. > > Fixes: e47c2055c68e ("KVM: arm64: Make struct kvm_regs userspace-only") > Fixes: 9d4ec80be2eb ("KVM: arm64: Handle PSCI calls for protected VMs at EL2") > Cc: stable@vger.kernel.org > Reviewed-by: Steffen Eiden > Signed-off-by: Dan Carpenter > --- > v4: Drop the "NULL on s390" comment (Steffen Eiden) > v3: Suzuki K Poulose pointed out this should be done in > kvm_reset_vcpu_core() instead of kvm_reset_vcpu(). > v2: new patch > --- > arch/arm64/include/asm/kvm_emulate.h | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index 2d7c82cfb8a4..b66689818515 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -777,6 +777,8 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu) > /* Reset a vcpu's core registers. */ > static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) > { > + u64 *elr_el1 = __ctxt_sys_reg(&vcpu->arch.ctxt, ELR_EL1); > + u64 *spsr_el1 = __ctxt_sys_reg(&vcpu->arch.ctxt, SPSR_EL1); > u32 pstate; > > if (vcpu_el1_is_32bit(vcpu)) > @@ -790,6 +792,11 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) > memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu))); > *vcpu_pc(vcpu) = 0; > *vcpu_sp_el0(vcpu) = 0; > + *vcpu_sp_el1(vcpu) = 0; > + if (elr_el1) > + *elr_el1 = 0; > + if (spsr_el1) > + *spsr_el1 = 0; I don't think we should be concerned with checking for NULL at all. ELR_EL1 and SPSR_EL1 must exist, always, and if that is an issue for S390, that's where it needs to be fixed. I'll drop that when applying the fixes. Thanks, M. -- Without deviation from the norm, progress is not possible.