public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH v2 4/4] KVM: Avoid synchronize_srcu() in kvm_io_bus_register_dev()
@ 2025-08-16  0:23 Li,Rongqing
  0 siblings, 0 replies; 2+ messages in thread
From: Li,Rongqing @ 2025-08-16  0:23 UTC (permalink / raw)
  To: Keir Fraser, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
  Cc: Sean Christopherson, Eric Auger, Oliver Upton, Marc Zyngier,
	Will Deacon, Paolo Bonzini



> 
> Device MMIO registration may happen quite frequently during VM boot, and
> the SRCU synchronization each time has a measurable effect on VM startup
> time. In our experiments it can account for around 25% of a VM's startup time.
> 
> Replace the synchronization with a deferred free of the old kvm_io_bus
> structure.
> 

Tested-by: Li RongQing <lirongqing@baidu.com>

Thanks

-Li

> Signed-off-by: Keir Fraser <keirf@google.com>
> ---
>  include/linux/kvm_host.h |  1 +
>  virt/kvm/kvm_main.c      | 10 ++++++++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index
> 9132148fb467..802ca46f7537 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -205,6 +205,7 @@ struct kvm_io_range {  struct kvm_io_bus {
>  	int dev_count;
>  	int ioeventfd_count;
> +	struct rcu_head rcu;
>  	struct kvm_io_range range[];
>  };
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index
> 9ec3b96b9666..f690a4997a0f 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -5948,6 +5948,13 @@ int kvm_io_bus_read(struct kvm_vcpu *vcpu,
> enum kvm_bus bus_idx, gpa_t addr,  }
> EXPORT_SYMBOL_GPL(kvm_io_bus_read);
> 
> +static void __free_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)  { @@ -5986,8
> +5993,7 @@ 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_bus);
> 
>  	return 0;
>  }
> --
> 2.50.0.727.gbf7dc18ff4-goog
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread
* [PATCH v2 0/4] KVM: Speed up MMIO registrations
@ 2025-07-16 11:07 Keir Fraser
  2025-07-16 11:07 ` [PATCH v2 4/4] KVM: Avoid synchronize_srcu() in kvm_io_bus_register_dev() Keir Fraser
  0 siblings, 1 reply; 2+ messages in thread
From: Keir Fraser @ 2025-07-16 11:07 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel, kvm
  Cc: Sean Christopherson, Eric Auger, Oliver Upton, Marc Zyngier,
	Will Deacon, Paolo Bonzini, Keir Fraser

This is version 2 of the patches I previously posted here:

 https://lore.kernel.org/all/20250624092256.1105524-1-keirf@google.com/

Changes since v1:

 * Memory barriers introduced (or implied and documented) on the
   kvm->buses[] SRCU read paths

 * Disallow kvm_get_bus() from SRCU readers

 * Rebased to v6.16-rc6

Thanks to Sean for the review feedback and patch suggestions!

Keir Fraser (4):
  KVM: arm64: vgic-init: Remove vgic_ready() macro
  KVM: arm64: vgic: Explicitly implement vgic_dist::ready ordering
  KVM: Implement barriers before accessing kvm->buses[] on SRCU read
    paths
  KVM: Avoid synchronize_srcu() in kvm_io_bus_register_dev()

 arch/arm64/kvm/vgic/vgic-init.c | 14 +++--------
 arch/x86/kvm/vmx/vmx.c          |  7 ++++++
 include/kvm/arm_vgic.h          |  1 -
 include/linux/kvm_host.h        | 11 ++++++---
 virt/kvm/kvm_main.c             | 43 +++++++++++++++++++++++++++------
 5 files changed, 53 insertions(+), 23 deletions(-)

-- 
2.50.0.727.gbf7dc18ff4-goog


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

end of thread, other threads:[~2025-08-16  0:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-16  0:23 [PATCH v2 4/4] KVM: Avoid synchronize_srcu() in kvm_io_bus_register_dev() Li,Rongqing
  -- strict thread matches above, loose matches on Subject: below --
2025-07-16 11:07 [PATCH v2 0/4] KVM: Speed up MMIO registrations Keir Fraser
2025-07-16 11:07 ` [PATCH v2 4/4] KVM: Avoid synchronize_srcu() in kvm_io_bus_register_dev() Keir Fraser

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