Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection
@ 2026-09-09  8:32 Bibo Mao
  2026-09-09  8:32 ` [PATCH 1/2] LoongArch: KVM: Remove parameter line when inject MSI Bibo Mao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bibo Mao @ 2026-09-09  8:32 UTC (permalink / raw)
  To: Huacai Chen; +Cc: WANG Xuerui, kvm, loongarch, linux-kernel

Here is to remove some unnecessary parameter checking when injecting
MSI interrupt, include MSI level parameter and vcpu::arch::dmsintc_state
NULL pointer etc.

Bibo Mao (2):
  LoongArch: KVM: Remove parameter line when inject MSI
  LoongArch: KVM: Remove duplicated checking with DMSI irq injection

 arch/loongarch/include/asm/kvm_dmsintc.h |  3 +--
 arch/loongarch/include/asm/kvm_pch_pic.h |  2 +-
 arch/loongarch/kvm/intc/dmsintc.c        | 19 +++----------------
 arch/loongarch/kvm/intc/pch_pic.c        |  6 +++---
 arch/loongarch/kvm/irqfd.c               |  6 +++---
 5 files changed, 11 insertions(+), 25 deletions(-)


base-commit: df2908090cda368b01ff43709f51890076c56157
-- 
2.39.3


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

* [PATCH 1/2] LoongArch: KVM: Remove parameter line when inject MSI
  2026-09-09  8:32 [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection Bibo Mao
@ 2026-09-09  8:32 ` Bibo Mao
  2026-09-09  8:32 ` [PATCH 2/2] LoongArch: KVM: Remove duplicated checking with DMSI irq injection Bibo Mao
  2026-09-10  3:06 ` [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection Tao Cui
  2 siblings, 0 replies; 4+ messages in thread
From: Bibo Mao @ 2026-09-09  8:32 UTC (permalink / raw)
  To: Huacai Chen; +Cc: WANG Xuerui, kvm, loongarch, linux-kernel

With MSI interrupt, there is intterupt set injection, no interrupt
clear action. DMSI interrupt controller is specially for MSI irqchip.
And there is checking with parameter level in most upper function
kvm_set_msi() and kvm_arch_set_irq_inatomic() already, here remove
duplicated line parameter checking in MSI injection leaf functions.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 arch/loongarch/include/asm/kvm_dmsintc.h | 3 +--
 arch/loongarch/include/asm/kvm_pch_pic.h | 2 +-
 arch/loongarch/kvm/intc/dmsintc.c        | 9 +++------
 arch/loongarch/kvm/intc/pch_pic.c        | 6 +++---
 arch/loongarch/kvm/irqfd.c               | 6 +++---
 5 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/arch/loongarch/include/asm/kvm_dmsintc.h b/arch/loongarch/include/asm/kvm_dmsintc.h
index 7c0158764d84..e19b3f5b3c52 100644
--- a/arch/loongarch/include/asm/kvm_dmsintc.h
+++ b/arch/loongarch/include/asm/kvm_dmsintc.h
@@ -22,7 +22,6 @@ struct dmsintc_state {
 int kvm_loongarch_register_dmsintc_device(void);
 void kvm_loongarch_unregister_dmsintc_device(void);
 void dmsintc_inject_irq(struct kvm_vcpu *vcpu);
-int dmsintc_set_irq(struct kvm *kvm, u64 addr, int data, int level);
-int dmsintc_deliver_msi_to_vcpu(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 vector, int level);
+int dmsintc_set_irq(struct kvm *kvm, u64 addr, int data);
 
 #endif
diff --git a/arch/loongarch/include/asm/kvm_pch_pic.h b/arch/loongarch/include/asm/kvm_pch_pic.h
index 887b0431fd20..19ed1494c114 100644
--- a/arch/loongarch/include/asm/kvm_pch_pic.h
+++ b/arch/loongarch/include/asm/kvm_pch_pic.h
@@ -72,6 +72,6 @@ struct kvm_kernel_irq_routing_entry;
 int kvm_loongarch_register_pch_pic_device(void);
 void kvm_loongarch_unregister_pch_pic_device(void);
 void pch_pic_set_irq(struct loongarch_pch_pic *s, int irq, int level);
-int pch_msi_set_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, int level);
+int pch_msi_set_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e);
 
 #endif /* __ASM_KVM_PCH_PIC_H */
diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c
index 89f980d867be..79e56e330aeb 100644
--- a/arch/loongarch/kvm/intc/dmsintc.c
+++ b/arch/loongarch/kvm/intc/dmsintc.c
@@ -43,13 +43,10 @@ void dmsintc_inject_irq(struct kvm_vcpu *vcpu)
 	}
 }
 
-int dmsintc_deliver_msi_to_vcpu(struct kvm *kvm,
-				struct kvm_vcpu *vcpu, u32 vector, int level)
+static int dmsintc_deliver_msi_to_vcpu(struct kvm_vcpu *vcpu, u32 vector)
 {
 	struct dmsintc_state *ds = &vcpu->arch.dmsintc_state;
 
-	if (!level)
-		return 0;
 	if (!vcpu || vector >= 256)
 		return -EINVAL;
 	if (!ds)
@@ -65,7 +62,7 @@ int dmsintc_deliver_msi_to_vcpu(struct kvm *kvm,
 	return 0;
 }
 
-int dmsintc_set_irq(struct kvm *kvm, u64 addr, int data, int level)
+int dmsintc_set_irq(struct kvm *kvm, u64 addr, int data)
 {
 	unsigned int irq, cpu;
 	struct kvm_vcpu *vcpu;
@@ -78,7 +75,7 @@ int dmsintc_set_irq(struct kvm *kvm, u64 addr, int data, int level)
 	if (!vcpu)
 		return -EINVAL;
 
-	return dmsintc_deliver_msi_to_vcpu(kvm, vcpu, irq, level);
+	return dmsintc_deliver_msi_to_vcpu(vcpu, irq);
 }
 
 static int kvm_dmsintc_ctrl_access(struct kvm_device *dev,
diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
index 2b63b0c2c7ce..220fc23ffe8c 100644
--- a/arch/loongarch/kvm/intc/pch_pic.c
+++ b/arch/loongarch/kvm/intc/pch_pic.c
@@ -68,20 +68,20 @@ void pch_pic_set_irq(struct loongarch_pch_pic *s, int irq, int level)
 }
 
 /* msi irq handler */
-int pch_msi_set_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, int level)
+int pch_msi_set_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e)
 {
 	u64 msg_addr = (((u64)e->msi.address_hi) << 32) | e->msi.address_lo;
 
 	if (cpu_has_msgint && kvm->arch.dmsintc &&
 		msg_addr >= kvm->arch.dmsintc->msg_addr_base &&
 		msg_addr < (kvm->arch.dmsintc->msg_addr_base + kvm->arch.dmsintc->msg_addr_size)) {
-		return dmsintc_set_irq(kvm, msg_addr, e->msi.data, level);
+		return dmsintc_set_irq(kvm, msg_addr, e->msi.data);
 	}
 
 	if (e->msi.data >= EIOINTC_IRQS)
 		return -EINVAL;
 
-	eiointc_set_irq(kvm->arch.eiointc, e->msi.data, level);
+	eiointc_set_irq(kvm->arch.eiointc, e->msi.data, 1);
 
 	return 0;
 }
diff --git a/arch/loongarch/kvm/irqfd.c b/arch/loongarch/kvm/irqfd.c
index 40ed1081c4b6..686097ca5906 100644
--- a/arch/loongarch/kvm/irqfd.c
+++ b/arch/loongarch/kvm/irqfd.c
@@ -27,9 +27,9 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
 		struct kvm *kvm, int irq_source_id, int level, bool line_status)
 {
 	if (!level)
-		return -1;
+		return -EINVAL;
 
-	return pch_msi_set_irq(kvm, e, level);
+	return pch_msi_set_irq(kvm, e);
 }
 
 /*
@@ -78,7 +78,7 @@ int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e,
 		pch_pic_set_irq(kvm->arch.pch_pic, e->irqchip.pin, level);
 		return 0;
 	case KVM_IRQ_ROUTING_MSI:
-		return pch_msi_set_irq(kvm, e, level);
+		return pch_msi_set_irq(kvm, e);
 	default:
 		return -EWOULDBLOCK;
 	}
-- 
2.39.3


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

* [PATCH 2/2] LoongArch: KVM: Remove duplicated checking with DMSI irq injection
  2026-09-09  8:32 [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection Bibo Mao
  2026-09-09  8:32 ` [PATCH 1/2] LoongArch: KVM: Remove parameter line when inject MSI Bibo Mao
@ 2026-09-09  8:32 ` Bibo Mao
  2026-09-10  3:06 ` [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection Tao Cui
  2 siblings, 0 replies; 4+ messages in thread
From: Bibo Mao @ 2026-09-09  8:32 UTC (permalink / raw)
  To: Huacai Chen; +Cc: WANG Xuerui, kvm, loongarch, linux-kernel

There are some duplicated error checking in DMSI interrupt injection
function, also vcpu::arch::dmsintc_state is structure rather than pointer,
NULL pointer checking with dmsintc_state is not necessary, here remove
these unnecessary checking.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 arch/loongarch/kvm/intc/dmsintc.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c
index 79e56e330aeb..cd2cd7a5c01e 100644
--- a/arch/loongarch/kvm/intc/dmsintc.c
+++ b/arch/loongarch/kvm/intc/dmsintc.c
@@ -14,9 +14,6 @@ void dmsintc_inject_irq(struct kvm_vcpu *vcpu)
 	unsigned long vector[4], old;
 	struct dmsintc_state *ds = &vcpu->arch.dmsintc_state;
 
-	if (!ds)
-		return;
-
 	for (i = 0; i < 4; i++) {
 		old = atomic64_read(&(ds->vector_map[i]));
 		vector[i] = old ? atomic64_xchg(&(ds->vector_map[i]), 0) : 0;
@@ -47,11 +44,6 @@ static int dmsintc_deliver_msi_to_vcpu(struct kvm_vcpu *vcpu, u32 vector)
 {
 	struct dmsintc_state *ds = &vcpu->arch.dmsintc_state;
 
-	if (!vcpu || vector >= 256)
-		return -EINVAL;
-	if (!ds)
-		return -ENODEV;
-
 	if (!kvm_guest_has_msgint(&vcpu->arch))
 		return -EINVAL;
 
@@ -69,8 +61,6 @@ int dmsintc_set_irq(struct kvm *kvm, u64 addr, int data)
 
 	irq = (addr >> AVEC_IRQ_SHIFT) & AVEC_IRQ_MASK;
 	cpu = (addr >> AVEC_CPU_SHIFT) & kvm->arch.dmsintc->cpu_mask;
-	if (cpu >= KVM_MAX_VCPUS)
-		return -EINVAL;
 	vcpu = kvm_get_vcpu_by_cpuid(kvm, cpu);
 	if (!vcpu)
 		return -EINVAL;
-- 
2.39.3


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

* Re: [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection
  2026-09-09  8:32 [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection Bibo Mao
  2026-09-09  8:32 ` [PATCH 1/2] LoongArch: KVM: Remove parameter line when inject MSI Bibo Mao
  2026-09-09  8:32 ` [PATCH 2/2] LoongArch: KVM: Remove duplicated checking with DMSI irq injection Bibo Mao
@ 2026-09-10  3:06 ` Tao Cui
  2 siblings, 0 replies; 4+ messages in thread
From: Tao Cui @ 2026-09-10  3:06 UTC (permalink / raw)
  To: Bibo Mao, Huacai Chen; +Cc: cui.tao, WANG Xuerui, kvm, loongarch, linux-kernel

Hi, Bibo

在 2026/9/9 16:32, Bibo Mao 写道:
> Here is to remove some unnecessary parameter checking when injecting
> MSI interrupt, include MSI level parameter and vcpu::arch::dmsintc_state
> NULL pointer etc.
> 
> Bibo Mao (2):
>   LoongArch: KVM: Remove parameter line when inject MSI
>   LoongArch: KVM: Remove duplicated checking with DMSI irq injection
> 
>  arch/loongarch/include/asm/kvm_dmsintc.h |  3 +--
>  arch/loongarch/include/asm/kvm_pch_pic.h |  2 +-
>  arch/loongarch/kvm/intc/dmsintc.c        | 19 +++----------------
>  arch/loongarch/kvm/intc/pch_pic.c        |  6 +++---
>  arch/loongarch/kvm/irqfd.c               |  6 +++---
>  5 files changed, 11 insertions(+), 25 deletions(-)
> 
> 
> base-commit: df2908090cda368b01ff43709f51890076c56157

The series looks good to me.

Reviewed-by: Tao Cui <cuitao@kylinos.cn>

Minor question: kvm_set_msi() now returns -EINVAL for !level instead
of -1. Since MSI is edge-triggered, returning 0 to ignore a deassert
would also work, though nothing looks at the return value today.



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

end of thread, other threads:[~2026-09-10  3:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09  8:32 [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection Bibo Mao
2026-09-09  8:32 ` [PATCH 1/2] LoongArch: KVM: Remove parameter line when inject MSI Bibo Mao
2026-09-09  8:32 ` [PATCH 2/2] LoongArch: KVM: Remove duplicated checking with DMSI irq injection Bibo Mao
2026-09-10  3:06 ` [PATCH 0/2] LoongArch: KVM: Code cleanup with MSI intterupt injection Tao Cui

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