diff mbox series

[RFC] LoongArch: KVM: Handle interrupt early before enabling irq

Message ID 20250220084306.323967-1-maobibo@loongson.cn (mailing list archive)
State New
Headers show
Series [RFC] LoongArch: KVM: Handle interrupt early before enabling irq | expand

Commit Message

bibo mao Feb. 20, 2025, 8:43 a.m. UTC
If interrupt arrive when vCPU is running, vCPU will exit because of
interrupt exception. Currently interrupt exception is handled after
local_irq_enable() is called, and it is handled by host kernel rather
than KVM hypervisor. It will introduce extra another interrupt
exception and then host will handle irq.

If KVM hypervisor detect that it is interrupt exception, interrupt
can be handle early in KVM hypervisor before local_irq_enable() is
called.

On 3C5000 dual-way machine, there will be 10% -- 15% performance
improvement with netperf UDP_RR option with 10G ethernet card.
                   original     with patch    improvement
  netperf UDP_RR     7200          8100           +12%

The total performance is low because irqchip is emulated in qemu VMM,
however from the same testbed, there is performance improvement
actually.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 arch/loongarch/kernel/traps.c |  1 +
 arch/loongarch/kvm/vcpu.c     | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)


base-commit: 2408a807bfc3f738850ef5ad5e3fd59d66168996
diff mbox series

Patch

diff --git a/arch/loongarch/kernel/traps.c b/arch/loongarch/kernel/traps.c
index 2ec3106c0da3..eed0d8b02ee3 100644
--- a/arch/loongarch/kernel/traps.c
+++ b/arch/loongarch/kernel/traps.c
@@ -1114,6 +1114,7 @@  asmlinkage void noinstr do_vint(struct pt_regs *regs, unsigned long sp)
 
 	irqentry_exit(regs, state);
 }
+EXPORT_SYMBOL(do_vint);
 
 unsigned long eentry;
 unsigned long tlbrentry;
diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index 20f941af3e9e..775f7aa6d904 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -5,6 +5,7 @@ 
 
 #include <linux/kvm_host.h>
 #include <linux/entry-kvm.h>
+#include <asm/exception.h>
 #include <asm/fpu.h>
 #include <asm/lbt.h>
 #include <asm/loongarch.h>
@@ -304,6 +305,17 @@  static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
 	return ret;
 }
 
+static void kvm_handle_irq(struct kvm_vcpu *vcpu)
+{
+	struct pt_regs regs;
+
+	/* Construct pseudo pt_regs, only necessary registers is added */
+	regs.csr_prmd = CSR_PRMD_PIE;
+	regs.csr_era = vcpu->arch.pc;
+	regs.regs[3] = vcpu->arch.host_sp;
+	do_vint(&regs, (unsigned long)&regs);
+}
+
 /*
  * Return 1 for resume guest and "<= 0" for resume host.
  */
@@ -323,6 +335,12 @@  static int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 
 	guest_timing_exit_irqoff();
 	guest_state_exit_irqoff();
+	/*
+	 * VM exit because of host interrupt
+	 * Handle irq directly before enabling irq
+	 */
+	if (!ecode && intr)
+		kvm_handle_irq(vcpu);
 	local_irq_enable();
 
 	trace_kvm_exit(vcpu, ecode);