From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796557681; b=Ld5DUoZuBIBswUgwIres4fZKVsYYHF7OkPVmlGB9Oo5Ayta8J8MHicUwV/PDXvmp5WxH Ej+FhEkEm/8RPAenOkCytJep1rE912GTF9KmKc52Z9JzKgf7NqmHkGfzmbtBmjetpI16r mhLyy7RcmxBx46sWGdxKaIqUcnoU9lVFvi1GxTrVZB/YRKchAmKPABDalxRl8E6BTS4ZV G2pXGCInxDxsAM6vDTWDesX5SE+CQzmu60dJ8NBMN5ZozPebA6wkWjxzQMh4NKuKK0EEC /mF/8nvOCRsW1u353b0PVK1v/YDp2QxZ2oW8WrsbPzfcodHqcE3fCVCbL9hGChtx2NQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796557681; h=Received:DKIM-Signature:Received:Date:Message-ID:From:To:Cc:Subject: In-Reply-To:References:User-Agent:MIME-Version:Content-Type: X-SA-Exim-Connect-IP:X-SA-Exim-Rcpt-To:X-SA-Exim-Mail-From: X-SA-Exim-Scanned; bh=/tjPV1TJwe/yznhlXKYtgL63Qo0pdV2R0LTSLXN9wT8=; b=L30G3Sziwciq52fWKC7/mwF9LsAKXqxRxY6SBaIanfsPdjihpNVmT9A4zW/pDxNXHrM7 zQwqhG3yURLtL28yMdd4HNsOU+5XelzwOg282oaNyOD3gvosMH60eJXz9ss2nARt0o3Dc qpLUHS2PEcn0Xb+zR4vYNvnzVC1JmviZWZTwL1PBH/s6sq1tRLPPJndkfpIben+wgUdmI dHZ77rsGWQswqVJ5/7zZMqzPEx8gp0c3uQhcRmV+K5OQLjeDsGDM/LByyXaH2SClt7HFr W0um7idQ60Ue1FSjvAQE3XwaENDvtWR40aJlxltO3D3CrN+b6E/mzAc1Ol+djGlx7dA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eH5bFl6E; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8550A606A31F; Sun, 6 Dec 2026 11:48:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eH5bFl6E 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-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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.