Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/8] KVM: arm64: Drop an incomplete MMIO access when resetting a vcpu
       [not found] <20261125-double_exception-v2-0-224689d8a764@pereq.eu>
@ 2026-11-25  6:56 ` Dan Carpenter
  2026-11-25  6:56 ` [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 " Dan Carpenter
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-11-25  6:56 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Christoffer Dall, Rusty Russell, Marcelo Tosatti,
	Sebastian Ott, Eric Auger, James Morse, Paolo Bonzini,
	Sean Christopherson, Shuah Khan
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-arm-kernel,
	kvmarm, Dan Carpenter, linux-kernel, kvm, linux-kselftest, stable

When a vcpu exits to userspace for an MMIO access, the next KVM_RUN
completes it.  So for a read, the next run increments the PC counter
and copies data from userspace to the destination vcpu register.

A reset should cancel the MMIO read/write access.  Otherwise the next
run will copy memory from userspace to the vcpu and increment the PC
which skips the first instruction.

Clear vcpu->mmio_needed in kvm_reset_vcpu().

Fixes: 45e96ea6b369 ("KVM: ARM: Handle I/O aborts")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
v2: new patch
---
 arch/arm64/kvm/reset.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 10eb7249aa9e..26081d273408 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -199,6 +199,7 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
 
 	/* Reset core registers */
 	kvm_reset_vcpu_core(vcpu);
+	vcpu->mmio_needed = false;
 
 	/* Reset system registers */
 	kvm_reset_sys_regs(vcpu);

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu
       [not found] <20261125-double_exception-v2-0-224689d8a764@pereq.eu>
  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 ` Dan Carpenter
  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
  3 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-11-25  6:56 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Christoffer Dall, Rusty Russell, Marcelo Tosatti,
	Sebastian Ott, Eric Auger, James Morse, Paolo Bonzini,
	Sean Christopherson, Shuah Khan
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-arm-kernel,
	kvmarm, Dan Carpenter, linux-kernel, kvm, linux-kselftest, stable

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@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@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);
 	vcpu->mmio_needed = false;
 
 	/* Reset system registers */

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/8] KVM: arm64: Discard a pending SError when resetting a vcpu
       [not found] <20261125-double_exception-v2-0-224689d8a764@pereq.eu>
  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  6:56 ` Dan Carpenter
  2026-11-25  6:56 ` [PATCH v2 4/8] KVM: arm64: nv: Discard nested SError in kvm_reset_vcpu() Dan Carpenter
  3 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-11-25  6:56 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Christoffer Dall, Rusty Russell, Marcelo Tosatti,
	Sebastian Ott, Eric Auger, James Morse, Paolo Bonzini,
	Sean Christopherson, Shuah Khan
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-arm-kernel,
	kvmarm, Dan Carpenter, linux-kernel, kvm, linux-kselftest, stable

Resetting a vcpu with the KVM_ARM_VCPU_INIT ioctl keeps a pending
SError.  We used to rely on vcpu_reset_hcr() to clear the SError but
commit f1ff3fc5209a ("KVM: arm64: unify code to prepare traps") changed
it to only reset HCR_EL2 before the vcpu's very first KVM_RUN.

If we reboot a guest while there is a pending SError then KVM delivers
it to the freshly booted guest.

Clear HCR_EL2.VSE in kvm_reset_vcpu().

Fixes: f1ff3fc5209a ("KVM: arm64: unify code to prepare traps")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
v2: new patch
---
 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 9c1b42890c96..a5d298d5ce61 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -207,6 +207,9 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
 	/* Reset system registers */
 	kvm_reset_sys_regs(vcpu);
 
+	/* Discard a pending SError */
+	vcpu->arch.hcr_el2 &= ~HCR_EL2_VSE;
+
 	/*
 	 * Additional reset state handling that PSCI may have imposed on us.
 	 * Must be done after all the sys_reg reset.

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 4/8] KVM: arm64: nv: Discard nested SError in kvm_reset_vcpu()
       [not found] <20261125-double_exception-v2-0-224689d8a764@pereq.eu>
                   ` (2 preceding siblings ...)
  2026-11-25  6:56 ` [PATCH v2 3/8] KVM: arm64: Discard a pending SError " Dan Carpenter
@ 2026-11-25  6:56 ` Dan Carpenter
  3 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-11-25  6:56 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Mark Rutland, Christoffer Dall, Rusty Russell, Marcelo Tosatti,
	Sebastian Ott, Eric Auger, James Morse, Paolo Bonzini,
	Sean Christopherson, Shuah Khan
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-arm-kernel,
	kvmarm, Dan Carpenter, linux-kernel, kvm, linux-kselftest, stable

Vanilla KVM stores a pending SError in ->hcr_el2 but nested KVM stores
it in the NESTED_SERROR_PENDING flag.  Clear the flag for nested
SErrors when we reset the vcpu.

Fixes: 77ee70a07357 ("KVM: arm64: nv: Honor SError exception routing / masking")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
v2: New patch.  I split it up like this to make backporting easier.
---
 arch/arm64/kvm/reset.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index a5d298d5ce61..d80b38b2ce6c 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -209,6 +209,7 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
 
 	/* Discard a pending SError */
 	vcpu->arch.hcr_el2 &= ~HCR_EL2_VSE;
+	vcpu_clear_flag(vcpu, NESTED_SERROR_PENDING);
 
 	/*
 	 * Additional reset state handling that PSCI may have imposed on us.

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25  6:57 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>
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  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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox