* Re: [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
[not found] ` <sashiko-outbox-232760@kernel.org>
@ 2026-11-25 9:14 ` Dan Carpenter
2026-11-25 9:18 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2026-11-25 9:14 UTC (permalink / raw)
To: sashiko-reviews
Cc: kvmarm, kvm, Oliver Upton, Marc Zyngier, linux-s390,
Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
Steffen Eiden, Karthik Bhargavan, Clément Blaudeau
Let me add the s390 maintainers to the CC list.
I considered doing it the way Sashiko suggests but s390 doesn't have the
__vcpu_assign_sys_reg() helpers so it broke the build. The registers are
not the same so, either way, some of this is going to be specific to
arm64. But Sashiko is correct that s390 probably keeps a stale SP_EL1
across a reset. The s390 maintainers could probably take the selftest in
patch 8 and modify it for s390. :)
The pKVM part was my fault. I had a patch for that but I screwed up
and didn't include it. Sorry!
I guess what I'd like to do is keep this patch as-is and let the s390
maintainers fix s390. When I send v3, I will include the pKVM fix.
regards,
dan carpenter
#HashTagTopPostingRules!
On Wed, Nov 25, 2026 at 07:15:46AM +0000, sashiko-bot@kernel.org wrote:
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
2026-11-25 9:14 ` [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu Dan Carpenter
@ 2026-11-25 9:18 ` Dan Carpenter
2026-11-26 13:37 ` Steffen Eiden
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2026-11-25 9:18 UTC (permalink / raw)
To: sashiko-reviews
Cc: kvmarm, kvm, Oliver Upton, Marc Zyngier, linux-s390,
Christian Borntraeger, Janosch Frank, Claudio Imbrenda,
Steffen Eiden, Karthik Bhargavan, Clément Blaudeau
On Wed, Nov 25, 2026 at 12:14:10PM +0300, Dan Carpenter wrote:
> Let me add the s390 maintainers to the CC list.
>
> I considered doing it the way Sashiko suggests but s390 doesn't have the
> __vcpu_assign_sys_reg() helpers so it broke the build. The registers are
> not the same so, either way, some of this is going to be specific to
> arm64. But Sashiko is correct that s390 probably keeps a stale SP_EL1
> across a reset. The s390 maintainers could probably take the selftest in
> patch 8 and modify it for s390. :)
>
Actually, never mind. This can be done in kvm_reset_vcpu_core() like
Suzuki Poulose suggests.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
2026-11-25 9:18 ` Dan Carpenter
@ 2026-11-26 13:37 ` Steffen Eiden
2026-11-26 14:04 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Steffen Eiden @ 2026-11-26 13:37 UTC (permalink / raw)
To: Dan Carpenter
Cc: sashiko-reviews, kvmarm, kvm, Oliver Upton, Marc Zyngier,
linux-s390, Christian Borntraeger, Janosch Frank,
Claudio Imbrenda, Karthik Bhargavan, Clément Blaudeau
On Wed, Nov 25, 2026 at 12:18:42PM +0300, Dan Carpenter wrote:
> On Wed, Nov 25, 2026 at 12:14:10PM +0300, Dan Carpenter wrote:
> > Let me add the s390 maintainers to the CC list.
> >
> > I considered doing it the way Sashiko suggests but s390 doesn't have the
> > __vcpu_assign_sys_reg() helpers so it broke the build. The registers are
> > not the same so, either way, some of this is going to be specific to
> > arm64. But Sashiko is correct that s390 probably keeps a stale SP_EL1
> > across a reset. The s390 maintainers could probably take the selftest in
> > patch 8 and modify it for s390. :)
> >
FYI: the arm on s390 KVM in the current upstream state has no idea what
SP_EL1 is :)
>
> Actually, never mind. This can be done in kvm_reset_vcpu_core() like
> Suzuki Poulose suggests.
>
We share kvm_reset_vcpu_core() as well :)
I assume this fix series should go into 7.4. right?
I have a series posted adding the required functions and infrastructure
for s390 [1]. This will likely go to 7.5.
For 7.4: Add a patch just providing a stub that does nothing for the
required helper (untested):
diff --git a/arch/s390/include/asm/kvm_host_arm64.h b/arch/s390/include/asm/kvm_host_arm64.h
index 3e69724f17c9..bdca7ebf6405 100644
--- a/arch/s390/include/asm/kvm_host_arm64.h
+++ b/arch/s390/include/asm/kvm_host_arm64.h
@@ -206,4 +206,6 @@ static inline void kvm_arch_async_page_present_queued(struct kvm_vcpu *vcpu)
#define kvm_supports_32bit_el0() false
+#define __vcpu_assign_sys_reg(__vcpu, __reg, __val) (void)
+
#endif /* ASM_KVM_HOST_ARM64_H */
If this does goes to 7.5 queuing that after the corresponding s390
patches would be the simpler approach.
Thanks for fixing the bugs
Steffen
[1] https://lore.kernel.org/all/20261106-sysreg-v3-0-75e95980fb10@linux.ibm.com
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
2026-11-26 13:37 ` Steffen Eiden
@ 2026-11-26 14:04 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-11-26 14:04 UTC (permalink / raw)
To: Steffen Eiden
Cc: sashiko-reviews, kvmarm, kvm, Oliver Upton, Marc Zyngier,
linux-s390, Christian Borntraeger, Janosch Frank,
Claudio Imbrenda, Karthik Bhargavan, Clément Blaudeau
On Thu, Nov 26, 2026 at 02:37:44PM +0100, Steffen Eiden wrote:
> On Wed, Nov 25, 2026 at 12:18:42PM +0300, Dan Carpenter wrote:
> > On Wed, Nov 25, 2026 at 12:14:10PM +0300, Dan Carpenter wrote:
> > > Let me add the s390 maintainers to the CC list.
> > >
> > > I considered doing it the way Sashiko suggests but s390 doesn't have the
> > > __vcpu_assign_sys_reg() helpers so it broke the build. The registers are
> > > not the same so, either way, some of this is going to be specific to
> > > arm64. But Sashiko is correct that s390 probably keeps a stale SP_EL1
> > > across a reset. The s390 maintainers could probably take the selftest in
> > > patch 8 and modify it for s390. :)
> > >
>
> FYI: the arm on s390 KVM in the current upstream state has no idea what
> SP_EL1 is :)
>
> >
> > Actually, never mind. This can be done in kvm_reset_vcpu_core() like
> > Suzuki Poulose suggests.
> >
>
> We share kvm_reset_vcpu_core() as well :)
>
Yes, Suzuki Poulose told me about kvm_reset_vcpu_core(). If I put it there
then I don't need __vcpu_assign_sys_reg(). Thanks, though!
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-26 14:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261125-double_exception-v2-0-224689d8a764@pereq.eu>
[not found] ` <20261125-double_exception-v2-2-224689d8a764@pereq.eu>
[not found] ` <sashiko-outbox-232760@kernel.org>
2026-11-25 9:14 ` [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu Dan Carpenter
2026-11-25 9:18 ` Dan Carpenter
2026-11-26 13:37 ` Steffen Eiden
2026-11-26 14:04 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox