From: Dan Carpenter <dan@pereq.eu>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
Fuad Tabba <fuad.tabba@linux.dev>,
Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Rusty Russell <rusty@rustcorp.com.au>,
James Morse <james.morse@arm.com>,
Eric Auger <eric.auger@redhat.com>,
Sebastian Ott <sebott@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <shuah@kernel.org>
Cc: "Karthik Bhargavan" <karthik@pereq.eu>,
"Clément Blaudeau" <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, "Dan Carpenter" <dan@pereq.eu>,
stable@vger.kernel.org
Subject: [PATCH v4 3/9] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
Date: Fri, 04 Dec 2026 11:48:07 +0300 [thread overview]
Message-ID: <20261204-double_exception_v4-v4-3-523921511673@pereq.eu> (raw)
In-Reply-To: <20261204-double_exception_v4-v4-0-523921511673@pereq.eu>
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 <seiden@linux.ibm.com>
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
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;
kvm_reset_fpsimd(vcpu);
vcpu->arch.ctxt.spsr_abt = 0;
vcpu->arch.ctxt.spsr_und = 0;
--
2.53.0
next prev parent reply other threads:[~2026-12-04 8:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 8:48 [PATCH v4 0/9] KVM: arm64: Fix kvm_reset_vcpu() and SError handling for nested virt Dan Carpenter
2026-12-04 8:48 ` [PATCH v4 1/9] KVM: arm64: nv: Use a vcpu request to reprogram the PMU Dan Carpenter
2026-12-04 8:48 ` [PATCH v4 2/9] KVM: arm64: Drop an incomplete MMIO access when resetting a vcpu Dan Carpenter
2026-12-04 9:24 ` Steffen Eiden
2026-12-04 8:48 ` Dan Carpenter [this message]
2026-12-06 11:47 ` [PATCH v4 3/9] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 " Marc Zyngier
2026-12-04 8:48 ` [PATCH v4 4/9] KVM: arm64: Discard a pending SError " Dan Carpenter
2026-12-06 12:00 ` Marc Zyngier
2026-12-04 8:48 ` [PATCH v4 5/9] KVM: arm64: nv: Discard nested SError in kvm_reset_vcpu() Dan Carpenter
2026-12-04 8:48 ` [PATCH v4 6/9] KVM: arm64: nv: Replace a pending SError when injecting a new one Dan Carpenter
2026-12-04 8:48 ` [PATCH v4 7/9] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest Dan Carpenter
2026-12-04 8:48 ` [PATCH v4 8/9] KVM: arm64: nv: Re-inject a stored SError after the exit is handled Dan Carpenter
2026-12-04 8:48 ` [PATCH v4 9/9] KVM: arm64: selftests: Test that a vcpu reset clears the vcpu's state Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204-double_exception_v4-v4-3-523921511673@pereq.eu \
--to=dan@pereq.eu \
--cc=catalin.marinas@arm.com \
--cc=clement@cryspen.com \
--cc=eric.auger@redhat.com \
--cc=fuad.tabba@linux.dev \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=karthik@pereq.eu \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mtosatti@redhat.com \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=seanjc@google.com \
--cc=sebott@redhat.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®