public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: irqchip: synchronize srcu only if needed
@ 2024-01-12  9:11 Yi Wang
  2024-01-12 16:28 ` Sean Christopherson
  0 siblings, 1 reply; 7+ messages in thread
From: Yi Wang @ 2024-01-12  9:11 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel
  Cc: wanpengli, up2wing, Yi Wang

From: Yi Wang <foxywang@tencent.com>

We found that it may cost more than 20 milliseconds very accidentally
to enable cap of KVM_CAP_SPLIT_IRQCHIP on a host which has many vms
already.

The reason is that when vmm(qemu/CloudHypervisor) invokes
KVM_CAP_SPLIT_IRQCHIP kvm will call synchronize_srcu_expedited() and
might_sleep and kworker of srcu may cost some delay during this period.
Since this happens during creating vm, it's no need to synchronize srcu
now 'cause everything is not ready(vcpu/irqfd) and none uses irq_srcu now.

Signed-off-by: Yi Wang <foxywang@tencent.com>
---
 arch/x86/kvm/irq_comm.c  | 2 +-
 include/linux/kvm_host.h | 2 ++
 virt/kvm/irqchip.c       | 3 ++-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
index 16d076a1b91a..37c92b7486c7 100644
--- a/arch/x86/kvm/irq_comm.c
+++ b/arch/x86/kvm/irq_comm.c
@@ -394,7 +394,7 @@ static const struct kvm_irq_routing_entry empty_routing[] = {};
 
 int kvm_setup_empty_irq_routing(struct kvm *kvm)
 {
-	return kvm_set_irq_routing(kvm, empty_routing, 0, 0);
+	return kvm_set_irq_routing(kvm, empty_routing, 0, NONEED_SYNC_SRCU);
 }
 
 void kvm_arch_post_irq_routing_update(struct kvm *kvm)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 4944136efaa2..a46370cca355 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1995,6 +1995,8 @@ static inline int mmu_invalidate_retry_hva(struct kvm *kvm,
 
 #define KVM_MAX_IRQ_ROUTES 4096 /* might need extension/rework in the future */
 
+#define NONEED_SYNC_SRCU	(1U << 0)
+
 bool kvm_arch_can_set_irq_routing(struct kvm *kvm);
 int kvm_set_irq_routing(struct kvm *kvm,
 			const struct kvm_irq_routing_entry *entries,
diff --git a/virt/kvm/irqchip.c b/virt/kvm/irqchip.c
index 1e567d1f6d3d..cea5c43c1a49 100644
--- a/virt/kvm/irqchip.c
+++ b/virt/kvm/irqchip.c
@@ -224,7 +224,8 @@ int kvm_set_irq_routing(struct kvm *kvm,
 
 	kvm_arch_post_irq_routing_update(kvm);
 
-	synchronize_srcu_expedited(&kvm->irq_srcu);
+	if (!(flags & NONEED_SYNC_SRCU))
+		synchronize_srcu_expedited(&kvm->irq_srcu);
 
 	new = old;
 	r = 0;
-- 
2.39.3


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

end of thread, other threads:[~2024-01-17  0:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12  9:11 [PATCH] KVM: irqchip: synchronize srcu only if needed Yi Wang
2024-01-12 16:28 ` Sean Christopherson
2024-01-15 16:01   ` Yi Wang
2024-01-16 16:50     ` Christian Borntraeger
2024-01-16 16:58       ` Sean Christopherson
2024-01-17  0:56         ` Yi Wang
2024-01-17  0:46       ` Yi Wang

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