Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dan Carpenter" <dan@pereq.eu>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
	"Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
Date: Wed, 25 Nov 2026 07:15:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-232760@kernel.org> (raw)
In-Reply-To: <20261125-double_exception-v2-2-224689d8a764@pereq.eu>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: arm64: SP_EL1, ELR_EL1, and SPSR_EL1 unreset in
  pkvm_reset_vcpu() and core
--

commit d315f26d12c1dd260ed62612065ad5e34b6f9f03
Author: Dan Carpenter <dan@pereq.eu>

KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu

This commit zeroes SP_EL1, ELR_EL1, and SPSR_EL1 in kvm_reset_vcpu() when
resetting a vCPU.

> diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
> index 26081d2734087..9c1b42890c966 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);
>  	vcpu->mmio_needed = false;
>  
>  	/* Reset system registers */

[Severity: Medium]
Should SP_EL1, ELR_EL1, and SPSR_EL1 be reset in the shared helpers instead
of only in host kvm_reset_vcpu()?

For pKVM protected VMs, flush_hyp_vcpu() does not copy host_vcpu->arch.ctxt
into hyp_vcpu->vcpu.arch.ctxt.  Instead, on PSCI CPU_ON,
handle___kvm_vcpu_run() calls pkvm_reset_vcpu() at EL2:

arch/arm64/kvm/hyp/nvhe/pkvm.c:pkvm_reset_vcpu() {
	...
	kvm_reset_vcpu_core(&hyp_vcpu->vcpu);
	kvm_reset_pvm_sys_regs(&hyp_vcpu->vcpu);

	/* Must be done after resetting sys registers. */
	kvm_reset_vcpu_psci(&hyp_vcpu->vcpu, reset_state);
	...
}

Because neither kvm_reset_vcpu_core() nor pvm_sys_reg_reset_vals[] resets
SP_EL1, ELR_EL1, or SPSR_EL1, a protected vCPU that cycles through PSCI
CPU_OFF and CPU_ON re-enters in PSR_MODE_EL1h with stale SP_EL1, ELR_EL1,
and SPSR_EL1 values.  Resetting *vcpu_sp_el1(vcpu) = 0 in
kvm_reset_vcpu_core() (which also covers arch/s390/kvm/arm64/reset.c) and
ensuring ELR_EL1 and SPSR_EL1 are reset for pvm_sys_reg_reset_vals[] as
well would keep all vCPU reset paths consistent.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-double_exception-v2-0-224689d8a764@pereq.eu?part=2

  reply	other threads:[~2026-11-25  7:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:56 [PATCH v2 0/8] KVM: arm64: Fix kvm_reset_vcpu() and SError handling for nested virt Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 1/8] KVM: arm64: Drop an incomplete MMIO access when resetting a vcpu Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 " Dan Carpenter
2026-11-25  7:15   ` sashiko-bot [this message]
2026-11-25  6:56 ` [PATCH v2 3/8] KVM: arm64: Discard a pending SError " Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 4/8] KVM: arm64: nv: Discard nested SError in kvm_reset_vcpu() Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 5/8] KVM: arm64: nv: Replace a pending SError when injecting a new one Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 6/8] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest Dan Carpenter
2026-11-25  7:24   ` sashiko-bot
2026-11-25  6:56 ` [PATCH v2 7/8] KVM: arm64: nv: Re-inject a stored SError after the exit is handled Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 8/8] 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=sashiko-outbox-232760@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dan@pereq.eu \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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