public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Use call_rcu() in kvm_io_bus_register_dev
@ 2025-04-23  9:25 lirongqing
  2025-04-23 14:59 ` Sean Christopherson
  0 siblings, 1 reply; 6+ messages in thread
From: lirongqing @ 2025-04-23  9:25 UTC (permalink / raw)
  To: pbonzini, kvm, linux-kernel; +Cc: Li RongQing, lizhaoxin

From: Li RongQing <lirongqing@baidu.com>

Use call_rcu() instead of costly synchronize_srcu_expedited(), this
can reduce the VM bootup time, and reduce VM migration downtime

Signed-off-by: lizhaoxin <lizhaoxin04@baidu.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 include/linux/kvm_host.h |  1 +
 virt/kvm/kvm_main.c      | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 291d49b..e772704 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -203,6 +203,7 @@ struct kvm_io_range {
 #define NR_IOBUS_DEVS 1000
 
 struct kvm_io_bus {
+	struct rcu_head rcu;
 	int dev_count;
 	int ioeventfd_count;
 	struct kvm_io_range range[];
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2e591cc..af730a5 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5865,6 +5865,13 @@ int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
 	return r < 0 ? r : 0;
 }
 
+static void free_kvm_io_bus(struct rcu_head *rcu)
+{
+	struct kvm_io_bus *bus = container_of(rcu, struct kvm_io_bus, rcu);
+
+	kfree(bus);
+}
+
 int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 			    int len, struct kvm_io_device *dev)
 {
@@ -5903,8 +5910,8 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 	memcpy(new_bus->range + i + 1, bus->range + i,
 		(bus->dev_count - i) * sizeof(struct kvm_io_range));
 	rcu_assign_pointer(kvm->buses[bus_idx], new_bus);
-	synchronize_srcu_expedited(&kvm->srcu);
-	kfree(bus);
+
+	call_srcu(&kvm->srcu, &bus->rcu, free_kvm_io_bus);
 
 	return 0;
 }
-- 
2.9.4


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

end of thread, other threads:[~2025-05-12  5:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23  9:25 [PATCH] KVM: Use call_rcu() in kvm_io_bus_register_dev lirongqing
2025-04-23 14:59 ` Sean Christopherson
2025-04-24  2:56   ` 答复: [????] " Li,Rongqing
2025-05-07 14:32     ` Sean Christopherson
2025-05-12  5:03       ` 答复: [????] Re: ??: " Li,Rongqing
2025-04-29  2:13   ` 答复: " Li,Rongqing

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