irqfd enhancements, and irq_routing fixes
v3 cover irqfd enhancements, and irq_routing fixes
(Applies to kvm.git/master:11b06403)
The following patches are cleanups/enhancements for IRQFD now that we have lockless interrupt injection. For more details, please see the patch headers.
These patches pass checkpatch, and are fully tested. Please consider for merging. Patch 1/3 is a fix for an issue that may exist upstream and should be considered for a more timely push upstream. Patches 2/3
- 3/3 are an enhancement only, so there is no urgency to push to mainline until a suitable merge window presents itself.
Kind Regards,
-Greg
[ Change log:
v3:
*) Added patch 1/3 as a fix for a race condition
*) Minor cleanup to 2/3 to ensure that all shared vectors conform
to a unified locking model.
v2:
*) dropped original cleanup which relied on the user registering
MSI based GSIs or we may crash at runtime. Instead, we now check at registration whether the GSI supports lockless operation and dynamically adapt to either the original deferred path for lock-based injections, or direct for lockless.
v1:
*) original release
]
---
Gregory Haskins (3):
KVM: Directly inject interrupts if they support lockless operation
KVM: export lockless GSI attribute
KVM: fix race in irq_routing logic
include/linux/kvm_host.h | 8 ++++ virt/kvm/eventfd.c | 31 +++++++++++++++-- virt/kvm/irq_comm.c | 85 ++++++++++++++++++++++++++++++++++------------ virt/kvm/kvm_main.c | 1 + 4 files changed, 98 insertions(+), 27 deletions(-)
Signature · 1 line
Signature
PATCH v3 1/3 KVM: fix race in irq_routing logic
The current code suffers from the following race condition:
thread-1 thread-2
-----------------------------------------------------------
kvm_set_irq() {
rcu_read_lock()
irq_rt = rcu_dereference(table);
rcu_read_unlock();
kvm_set_irq_routing() {
mutex_lock();
irq_rt = table;
rcu_assign_pointer();
mutex_unlock();
synchronize_rcu();
kfree(irq_rt); irq_rt->entry->set(); /* bad */
-------------------------------------------------------------
Because the pointer is accessed outside of the read-side critical section. There are two basic patterns we can use to fix this bug:
1) Switch to sleeping-rcu and encompass the ->set() access within the read-side critical section,
OR
2) Add reference counting to the irq_rt structure, and simply acquire the reference from within the RSCS.
This patch implements solution (1).
---
include/linux/kvm_host.h | 6 +++++- virt/kvm/irq_comm.c | 50 +++++++++++++++++++++++++++------------------- virt/kvm/kvm_main.c | 1 + 3 files changed, 35 insertions(+), 22 deletions(-)
include/linux/kvm_host.h +5 -1
@@ -185,7 +185,10 @@ struct kvm {struct mutex irq_lock;#ifdef CONFIG_HAVE_KVM_IRQCHIP -struct kvm_irq_routing_table *irq_routing; +struct { +struct srcu_struct srcu; +struct kvm_irq_routing_table *table; + } irq_routing;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list;#endif
@@ -541,6 +544,7 @@ int kvm_set_irq_routing(struct kvm *kvm,const struct kvm_irq_routing_entry *entries, unsigned nr, unsigned flags); +void kvm_init_irq_routing (struct kvm *kvm);void kvm_free_irq_routing (struct kvm *kvm);#else
virt/kvm/irq_comm.c +29 -21
98 lines not on this page · raw message
virt/kvm/kvm_main.c +1 -0
@@ -388,6 +388,7 @@ static struct kvm *kvm_create_vm(void)atomic_inc (&kvm->mm->mm_count);spin_lock_init (&kvm->mmu_lock);spin_lock_init (&kvm->requests_lock); +kvm_init_irq_routing (kvm);kvm_io_bus_init (&kvm->pio_bus);kvm_eventfd_init (kvm);mutex_init (&kvm->lock);