[PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu

Suzuki K Poulose suzuki.poulose at arm.com
Wed Nov 25 01:08:36 PST 2026


On 25/11/2026 06:56, 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().
> 
> Fixes: e47c2055c68e ("KVM: arm64: Make struct kvm_regs userspace-only")
> Cc: stable at vger.kernel.org
> Signed-off-by: Dan Carpenter <dan at pereq.eu>
> ---
>   arch/arm64/kvm/reset.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
> index 26081d273408..9c1b42890c96 100644
> --- a/arch/arm64/kvm/reset.c
> +++ b/arch/arm64/kvm/reset.c
> @@ -199,6 +199,9 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
>   
>   	/* Reset core registers */
>   	kvm_reset_vcpu_core(vcpu);
> +	__vcpu_assign_sys_reg(vcpu, SP_EL1, 0);
> +	__vcpu_assign_sys_reg(vcpu, ELR_EL1, 0);
> +	__vcpu_assign_sys_reg(vcpu, SPSR_EL1, 0);

nit: Please could we move these into kvm_reset_vcpu_core() where we
reset other registers ?

With that:

Reviewed-by: Suzuki K Poulose <suzuki.poulose at arm.com>


>   	vcpu->mmio_needed = false;
>   
>   	/* Reset system registers */
> 




More information about the linux-arm-kernel mailing list