Skip to contentSkip to conversation

KVM: PPC: Book3S HV: Avoid spurious interrupts caused by LPCR_MER bit

PATCH Applied Gautam Menghani 4 participants 4 messages Nov 2 – Nov 18

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 KVM: PPC: Book3S HV: Avoid spurious interrupts caused by LPCR_MER bit

A huge number of spurious interrupts can be seen immediately after a KVM on PowerNV guest boots up in XIVE mode.

$ cat /proc/interrupts  | grep SPU
SPU:     223705     192439     273526     147623   Spurious interrupts

This bug was introduced by commit ecd10702baae5 ("KVM: PPC: Book3S HV:
Handle pending exceptions on guest entry with MSR_EE"). The root cause is that once LPCR_MER bit is set, it is supposed to be reset by software. But when a vCPU starts running with LPCR_MER set, the vCPU does not exit back to the host until the decrementer expires or there is an hcall, etc. This is because KVM on PowerNV guests have support for native XIVE, so they are not dependent on host for interrupt emulation. Due to this behaviour, a huge number of spurious interrupts are seen since LPCR_MER continues to be set and LPCR_MER cannot be reset until the vCPU exits to the host.

Fix this behaviour by not using the LPCR_MER bit whenever native XIVE is available (currently in case of KVM on PowerNV only), as the XIVE hardware can present interrupts to the KVM guest vCPU directly. So the LPCR_MER functionality is not required. This reduces the number of spurious interrupts drastically.

Fixes ecd10702baae5 ("KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE")

---
v5:
1. Drop the redundant check for the presence of the native XIVE device. (Ritesh)

v4:
1. If interrupt mode is changed to XICS during guest reboot, MER should be used. (Amit)

v3:
1. Continue the use of LPCR_MER when kernel-irqchip=off (Sashiko)

v2:
1. Handle the case where xive_interrupt_pending() is true and also the external exception bit is set. (Narayana)

 arch/powerpc/kvm/book3s_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +1 -1
index 22283d46e8fe..41012b0accf4 100644
@@ -4984,7 +4984,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
 			if (!kvmhv_on_pseries() && (__kvmppc_get_msr_hv(vcpu) & MSR_EE))
 				kvmppc_inject_interrupt_hv(vcpu,
 							   BOOK3S_INTERRUPT_EXTERNAL, 0);
-			else
+			else if (!kvmppc_xive_enabled(vcpu))
 				lpcr |= LPCR_MER;
 		} else {
 			/*
Signature · 1 line
2.55.0
reviewer Reviewed-by on v5 1/1
#1 lore raw
Quoted 28 lines · Gautam Menghani

A huge number of spurious interrupts can be seen immediately after a KVM on PowerNV guest boots up in XIVE mode.

$ cat /proc/interrupts  | grep SPU
SPU:     223705     192439     273526     147623   Spurious interrupts

This bug was introduced by commit ecd10702baae5 ("KVM: PPC: Book3S HV:
Handle pending exceptions on guest entry with MSR_EE"). The root cause is that once LPCR_MER bit is set, it is supposed to be reset by software. But when a vCPU starts running with LPCR_MER set, the vCPU does not exit back to the host until the decrementer expires or there is an hcall, etc. This is because KVM on PowerNV guests have support for native XIVE, so they are not dependent on host for interrupt emulation. Due to this behaviour, a huge number of spurious interrupts are seen since LPCR_MER continues to be set and LPCR_MER cannot be reset until the vCPU exits to the host.

Fix this behaviour by not using the LPCR_MER bit whenever native XIVE is available (currently in case of KVM on PowerNV only), as the XIVE hardware can present interrupts to the KVM guest vCPU directly. So the LPCR_MER functionality is not required. This reduces the number of spurious interrupts drastically.

Fixes ecd10702baae5 ("KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE")
Quoted 5 lines

---
v5:
1. Drop the redundant check for the presence of the native XIVE device. (Ritesh)

Thanks Gautam for confirming that.

The patch looks good to me. Feel free to add:

Reviewed-by
#2 lore raw

Hi Gautam,

Thanks for the update.

Quoted 36 lines · Ritesh Harjani (IBM)
Quoted 28 lines · Gautam Menghani

A huge number of spurious interrupts can be seen immediately after a KVM on PowerNV guest boots up in XIVE mode.

$ cat /proc/interrupts  | grep SPU
SPU:     223705     192439     273526     147623   Spurious interrupts

This bug was introduced by commit ecd10702baae5 ("KVM: PPC: Book3S HV:
Handle pending exceptions on guest entry with MSR_EE"). The root cause is that once LPCR_MER bit is set, it is supposed to be reset by software. But when a vCPU starts running with LPCR_MER set, the vCPU does not exit back to the host until the decrementer expires or there is an hcall, etc. This is because KVM on PowerNV guests have support for native XIVE, so they are not dependent on host for interrupt emulation. Due to this behaviour, a huge number of spurious interrupts are seen since LPCR_MER continues to be set and LPCR_MER cannot be reset until the vCPU exits to the host.

Fix this behaviour by not using the LPCR_MER bit whenever native XIVE is available (currently in case of KVM on PowerNV only), as the XIVE hardware can present interrupts to the KVM guest vCPU directly. So the LPCR_MER functionality is not required. This reduces the number of spurious interrupts drastically.

Fixes ecd10702baae5 ("KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE")
Quoted 5 lines

---
v5:
1. Drop the redundant check for the presence of the native XIVE device. (Ritesh)

Quoted 4 lines

Thanks Gautam for confirming that.

The patch looks good to me. Feel free to add:

Using kvmppc_xive_enabled(vcpu) looks sufficient here since KVMPPC_IRQ_XIVE specifically represents XIVE native exploitation mode. It also preserves the required behaviour when switching back to XICS and when the in-kernel irqchip is not being used.

The earlier case where both BOOK3S_IRQPRIO_EXTERNAL and xive_interrupt_pending() are set also remains handled by the outer condition.

Quoted 1 line
maintainer Applied
#3 lore raw
In reply to Gautam Menghani
Quoted 17 lines · Gautam Menghani

A huge number of spurious interrupts can be seen immediately after a KVM on PowerNV guest boots up in XIVE mode.

$ cat /proc/interrupts  | grep SPU
SPU:     223705     192439     273526     147623   Spurious interrupts

This bug was introduced by commit ecd10702baae5 ("KVM: PPC: Book3S HV:
Handle pending exceptions on guest entry with MSR_EE"). The root cause is that once LPCR_MER bit is set, it is supposed to be reset by software. But when a vCPU starts running with LPCR_MER set, the vCPU does not exit back to the host until the decrementer expires or there is an hcall, etc. This is because KVM on PowerNV guests have support for native XIVE, so they are not dependent on host for interrupt emulation. Due to this behaviour, a huge number of spurious interrupts are seen since LPCR_MER continues to be set and LPCR_MER cannot be reset until the vCPU exits to the host.

Quoted 1 line

[...]

Applied to powerpc/fixes.

[1/1] KVM: PPC: Book3S HV: Avoid spurious interrupts caused by LPCR_MER bit

      https://git.kernel.org/powerpc/c/9751c361cb234f000261879b1b5015bf08f6a428

cheers