Re: [PATCH v3 3/9] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
From: Steffen Eiden
Date: Mon Nov 30 2026 - 08:37:52 EST
On Mon, Nov 30, 2026 at 11:48:15AM +0300, 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@xxxxxxxxxxxxxxx
> Signed-off-by: Dan Carpenter <dan@xxxxxxxx>
Reviewed-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>
> ---
> 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 | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> index 2d7c82cfb8a4..a40f434b64f0 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -777,6 +777,9 @@ 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)
> {
> + /* NULL on s390 */
You can drop this comment. This will be wrong in the near future.
> + 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 +793,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
>
Steffen