more fine grained locking for IRQ injection
cover more fine grained locking for IRQ injection
kvm->irq_lock protects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking. This patch series split kvm->irq_lock mutex to smaller spinlocks each one protects only one thing. Irq routing, irq notifier lists and ioapic gain their own spinlock. pic is already uses its own lock. This patch series also makes interrupt injection to lapic lockless (several kvm_irq_delivery_to_apic() may run in parallel), but access to lapic was never fully locked in the first place. VCPU could access lapic in parallel with interrupt injection.
The patch series is on top of my previous series that converts ack notifiers to the RCU locking.
Gleb Natapov (5):
Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock Move irq routing to its own locking.
Move irq notifiers lists to its own locking.
Move IO APIC to its own lock.
Drop kvm->irq_lock lock.
arch/ia64/kvm/kvm-ia64.c | 29 +++++++++++++++++++-------- arch/x86/kvm/i8254.c | 4 +- arch/x86/kvm/lapic.c | 7 +----- arch/x86/kvm/x86.c | 32 +++++++++++++++++++----------- include/linux/kvm_host.h | 3 +- virt/kvm/eventfd.c | 2 - virt/kvm/ioapic.c | 47 +++++++++++++++++++++++++++------------------ virt/kvm/ioapic.h | 1 + virt/kvm/irq_comm.c | 35 ++++++++++++++------------------- virt/kvm/kvm_main.c | 7 ++--- 10 files changed, 92 insertions(+), 75 deletions(-)
PATCH 1/5 Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
It is already protected by kvm->lock on device assignment path. Just take the same lock in the PIT code.
--- arch/x86/kvm/i8254.c | 2 ++ virt/kvm/irq_comm.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-)
arch/x86/kvm/i8254.c +2 -0
@@ -596,7 +596,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)if (!pit)return NULL ; +mutex_lock (&kvm->lock); pit->irq_source_id =kvm_request_irq_source_id (kvm); +mutex_unlock (&kvm->lock);if (pit->irq_source_id <0 ) {kfree (pit);return NULL ;
virt/kvm/irq_comm.c +4 -4
@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id; -mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock)); + irq_source_id =find_first_zero_bit (bitmap,sizeof (kvm->arch.irq_sources_bitmap));
@@ -221,7 +222,6 @@ int kvm_request_irq_source_id(struct kvm *kvm)ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID );set_bit (irq_source_id, bitmap); -mutex_unlock (&kvm->irq_lock);return irq_source_id; }
@@ -230,9 +230,10 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) {int i; +/* during vm destruction this function is called without locking */ +WARN_ON (!mutex_is_locked (&kvm->lock) &&atomic_read (&kvm->users_count));ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID ); -mutex_lock (&kvm->irq_lock);if (irq_source_id <0 || irq_source_id >=sizeof (kvm->arch.irq_sources_bitmap)) {printk (KERN_ERR "kvm: IRQ source ID out of range!\n" );
@@ -241,7 +242,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)for (i =0 ; i <KVM_IOAPIC_NUM_PINS ; i++)clear_bit (irq_source_id, &kvm->arch.irq_states[i]);clear_bit (irq_source_id, &kvm->arch.irq_sources_bitmap); -mutex_unlock (&kvm->irq_lock); } void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
Signature · 1 line
1.6.2.1
PATCH 2/5 Move irq routing to its own locking.
In reply to Gleb Natapov--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 5 ++--- virt/kvm/kvm_main.c | 1 + 3 files changed, 4 insertions(+), 3 deletions(-)
include/linux/kvm_host.h +1 -0
@@ -162,6 +162,7 @@ struct kvm {struct mutex irq_lock;#ifdef CONFIG_HAVE_KVM_IRQCHIP struct kvm_kernel_irq_routing_entry *irq_routing; +spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list;#endif
virt/kvm/irq_comm.c +2 -3
@@ -350,11 +350,10 @@ int kvm_set_irq_routing(struct kvm *kvm, ++ue; } -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_routing_lock); old = kvm->irq_routing;rcu_assign_pointer (kvm->irq_routing, new); -mutex_unlock (&kvm->irq_lock); - +spin_unlock (&kvm->irq_routing_lock);synchronize_rcu (); r =0 ;
virt/kvm/kvm_main.c +1 -0
@@ -945,6 +945,7 @@ static struct kvm *kvm_create_vm(void)if (IS_ERR (kvm)) goto out;#ifdef CONFIG_HAVE_KVM_IRQCHIP +spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list);#endif
Signature · 1 line
1.6.2.1
PATCH 4/5 Move IO APIC to its own lock.
In reply to Gleb Natapov--- arch/ia64/kvm/kvm-ia64.c | 27 ++++++++++++++++++------ arch/x86/kvm/lapic.c | 5 +--- arch/x86/kvm/x86.c | 30 ++++++++++++++++++--------- virt/kvm/ioapic.c | 50 ++++++++++++++++++++++++++++----------------- virt/kvm/ioapic.h | 1 + 5 files changed, 73 insertions(+), 40 deletions(-)
arch/ia64/kvm/kvm-ia64.c +20 -7
@@ -850,9 +850,16 @@ static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, r =0 ;switch (chip->chip_id) { -case KVM_IRQCHIP_IOAPIC : -memcpy (&chip->chip.ioapic,ioapic_irqchip (kvm), -sizeof (struct kvm_ioapic_state )); +case KVM_IRQCHIP_IOAPIC : { +struct kvm_ioapic *ioapic =ioapic_irqchip (kvm); +if (ioapic) { +spin_lock (&ioapic->lock); +memcpy (&chip->chip.ioapic, ioapic, +sizeof (struct kvm_ioapic_state )); +spin_unlock (&ioapic->lock); + }else + r = -EINVAL ; + }break ;default : r = -EINVAL ;
@@ -867,10 +874,16 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) r =0 ;switch (chip->chip_id) { -case KVM_IRQCHIP_IOAPIC : -memcpy (ioapic_irqchip (kvm), - &chip->chip.ioapic, -sizeof (struct kvm_ioapic_state )); +case KVM_IRQCHIP_IOAPIC : { +struct kvm_ioapic *ioapic =ioapic_irqchip (kvm); +if (ioapic) { +spin_lock (&ioapic->lock); +memcpy (ioapic, &chip->chip.ioapic, +sizeof (struct kvm_ioapic_state )); +spin_unlock (&ioapic->lock); + }else + r = -EINVAL ; + }break ;default : r = -EINVAL ;
arch/x86/kvm/lapic.c +1 -4
@@ -471,11 +471,8 @@ static void apic_set_eoi(struct kvm_lapic *apic) trigger_mode =IOAPIC_LEVEL_TRIG ; else trigger_mode =IOAPIC_EDGE_TRIG ; -if (!(apic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI )) { -mutex_lock (&apic->vcpu->kvm->irq_lock); +if (!(apic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ))kvm_ioapic_update_eoi (apic->vcpu->kvm, vector, trigger_mode); -mutex_unlock (&apic->vcpu->kvm->irq_lock); - } }static void apic_send_ipi (struct kvm_lapic *apic)
arch/x86/kvm/x86.c +20 -10
@@ -2005,10 +2005,16 @@ static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) &pic_irqchip (kvm)->pics[1 ], sizeof(struct kvm_pic_state));break ; -case KVM_IRQCHIP_IOAPIC : -memcpy (&chip->chip.ioapic, -ioapic_irqchip (kvm), -sizeof (struct kvm_ioapic_state )); +case KVM_IRQCHIP_IOAPIC : { +struct kvm_ioapic *ioapic =ioapic_irqchip (kvm); +if (ioapic) { +spin_lock (&ioapic->lock); +memcpy (&chip->chip.ioapic, ioapic, +sizeof (struct kvm_ioapic_state )); +spin_unlock (&ioapic->lock); + }else + r = -EINVAL ; + }break ;default : r = -EINVAL ;
@@ -2037,12 +2043,16 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) sizeof(struct kvm_pic_state));spin_unlock (&pic_irqchip (kvm)->lock);break ; -case KVM_IRQCHIP_IOAPIC : -mutex_lock (&kvm->irq_lock); -memcpy (ioapic_irqchip (kvm), - &chip->chip.ioapic, -sizeof (struct kvm_ioapic_state )); -mutex_unlock (&kvm->irq_lock); +case KVM_IRQCHIP_IOAPIC : { +struct kvm_ioapic *ioapic =ioapic_irqchip (kvm); +if (ioapic) { +spin_lock (&ioapic->lock); +memcpy (ioapic, &chip->chip.ioapic, +sizeof (struct kvm_ioapic_state )); +spin_unlock (&ioapic->lock); + }else + r = -EINVAL ; + }break ;default : r = -EINVAL ;
virt/kvm/ioapic.c +31 -19
128 lines not on this page · raw message
virt/kvm/ioapic.h +1 -0
@@ -44,6 +44,7 @@ struct kvm_ioapic {struct kvm_io_device dev;struct kvm *kvm;void (*ack_notifier)(void *opaque,int irq); +spinlock_t lock; };#ifdef DEBUG
Signature · 1 line
1.6.2.1
PATCH 3/5 Move irq notifiers lists to its own locking.
In reply to Gleb Natapov--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)
include/linux/kvm_host.h +1 -0
@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER
virt/kvm/irq_comm.c +8 -8
@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }
@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }
virt/kvm/kvm_main.c +1 -0
@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
Signature · 1 line
1.6.2.1
PATCH 5/5 Drop kvm->irq_lock lock.
In reply to Gleb NatapovThe only thing it protects now is interrupt injection into lapic and this can work lockless. Even now with kvm->irq_lock in place access to lapic is not entirely serialized since vcpu access doesn't take kvm->irq_lock.
--- arch/ia64/kvm/kvm-ia64.c | 2 -- arch/x86/kvm/i8254.c | 2 -- arch/x86/kvm/lapic.c | 2 -- arch/x86/kvm/x86.c | 2 -- include/linux/kvm_host.h | 1 - virt/kvm/eventfd.c | 2 -- virt/kvm/irq_comm.c | 6 +----- virt/kvm/kvm_main.c | 5 +---- 8 files changed, 2 insertions(+), 20 deletions(-)
arch/ia64/kvm/kvm-ia64.c +0 -2
@@ -998,10 +998,8 @@ long kvm_arch_vm_ioctl(struct file *filp, goto out;if (irqchip_in_kernel (kvm)) {__s32 status; -mutex_lock (&kvm->irq_lock); status =kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , irq_event.irq, irq_event.level); -mutex_unlock (&kvm->irq_lock);if (ioctl ==KVM_IRQ_LINE_STATUS ) { irq_event.status = status; if (copy_to_user(argp, &irq_event,
arch/x86/kvm/i8254.c +0 -2
@@ -660,10 +660,8 @@ static void __inject_pit_timer_intr(struct kvm *kvm)struct kvm_vcpu *vcpu;int i; -mutex_lock (&kvm->irq_lock);kvm_set_irq (kvm, kvm->arch.vpit->irq_source_id,0 ,1 );kvm_set_irq (kvm, kvm->arch.vpit->irq_source_id,0 ,0 ); -mutex_unlock (&kvm->irq_lock);/* * Provides NMI watchdog support via Virtual Wire mode.
arch/x86/kvm/lapic.c +0 -2
@@ -501,9 +501,7 @@ static void apic_send_ipi(struct kvm_lapic *apic) irq.trig_mode, irq.level, irq.dest_mode, irq.delivery_mode, irq.vector); -mutex_lock (&apic->vcpu->kvm->irq_lock);kvm_irq_delivery_to_apic (apic->vcpu->kvm, apic, &irq); -mutex_unlock (&apic->vcpu->kvm->irq_lock); }static u32 apic_get_tmcct (struct kvm_lapic *apic)
arch/x86/kvm/x86.c +0 -2
@@ -2230,10 +2230,8 @@ long kvm_arch_vm_ioctl(struct file *filp, goto out;if (irqchip_in_kernel (kvm)) {__s32 status; -mutex_lock (&kvm->irq_lock); status =kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , irq_event.irq, irq_event.level); -mutex_unlock (&kvm->irq_lock);if (ioctl ==KVM_IRQ_LINE_STATUS ) { irq_event.status = status; if (copy_to_user(argp, &irq_event,
include/linux/kvm_host.h +0 -1
@@ -159,7 +159,6 @@ struct kvm {struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;#endif -struct mutex irq_lock;#ifdef CONFIG_HAVE_KVM_IRQCHIP struct kvm_kernel_irq_routing_entry *irq_routing;spinlock_t irq_routing_lock;
virt/kvm/eventfd.c +0 -2
@@ -57,10 +57,8 @@ irqfd_inject(struct work_struct *work) struct _irqfd *irqfd = container_of(work, struct _irqfd, inject);struct kvm *kvm = irqfd->kvm; -mutex_lock (&kvm->irq_lock);kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , irqfd->gsi,1 );kvm_set_irq (kvm,KVM_USERSPACE_IRQ_SOURCE_ID , irqfd->gsi,0 ); -mutex_unlock (&kvm->irq_lock); }/*
virt/kvm/irq_comm.c +1 -5
@@ -63,8 +63,6 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,int i, r =-1 ;struct kvm_vcpu *vcpu, *lowest =NULL ; -WARN_ON (!mutex_is_locked (&kvm->irq_lock)); -if (irq->dest_mode ==0 && irq->dest_id ==0xff &&kvm_is_dm_lowest_prio (irq))printk (KERN_INFO "kvm: apic: phys broadcast and lowest prio\n" );
@@ -116,7 +114,7 @@ static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,return kvm_irq_delivery_to_apic (kvm,NULL , &irq); } -/* This should be called with the kvm->irq_lock mutex held +/* * Return value: * < 0 Interrupt was ignored (masked or not delivered for other reasons) * = 0 Interrupt was coalesced (previous irq is still pending)
@@ -130,8 +128,6 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, int irq, int level)trace_kvm_set_irq (irq, level, irq_source_id); -WARN_ON (!mutex_is_locked (&kvm->irq_lock)); -if (irq <KVM_IOAPIC_NUM_PINS ) { irq_state = (unsigned long *)&kvm->arch.irq_states[irq];
virt/kvm/kvm_main.c +1 -4
@@ -68,7 +68,7 @@ MODULE_LICENSE("GPL");/* * Ordering of locks: * -* kvm->slots_lock --> kvm->lock --> kvm->irq_lock +* kvm->slots_lock --> kvm->lock */ DEFINE_SPINLOCK (kvm_lock);
@@ -137,7 +137,6 @@ static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work) interrupt_work); kvm = assigned_dev->kvm; -mutex_lock (&kvm->irq_lock);spin_lock_irq (&assigned_dev->assigned_dev_lock);if (assigned_dev->irq_requested_type &KVM_DEV_IRQ_HOST_MSIX ) { struct kvm_guest_msix_entry *guest_entries =
@@ -156,7 +155,6 @@ static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work) assigned_dev->guest_irq, 1);spin_unlock_irq (&assigned_dev->assigned_dev_lock); -mutex_unlock (&assigned_dev->kvm->irq_lock); }static irqreturn_t kvm_assigned_dev_intr (int irq,void *dev_id)
@@ -983,7 +981,6 @@ static struct kvm *kvm_create_vm(void)kvm_io_bus_init (&kvm->pio_bus);kvm_irqfd_init (kvm);mutex_init (&kvm->lock); -mutex_init (&kvm->irq_lock);kvm_io_bus_init (&kvm->mmio_bus);init_rwsem (&kvm->slots_lock);atomic_set (&kvm->users_count,1 );
Signature · 1 line
1.6.2.1
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Gleb NatapovQuoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>
This one is probably better off left as is, with RCU in place list modifications are slow anyway.
Quoted 86 lines
--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)include/linux/kvm_host.h +1
-0@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER virt/kvm/irq_comm.c +8
-8@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }virt/kvm/kvm_main.c +1
-0@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET Signature · 6 lines
1.6.2.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
Quoted 80 lines
with RCU in place list modifications are slow anyway.
Quoted 78 lines
--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)include/linux/kvm_host.h +1
-0@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER virt/kvm/irq_comm.c +8
-8@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }virt/kvm/kvm_main.c +1
-0@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif
Quoted 8 lines
Quoted 8 lines
virt/kvm/kvm_main.c +0
-0#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET Signature · 6 lines
1.6.2.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.
At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
Quoted 34 lines
This patch
series splitkvm->irq_lockmutex to smaller spinlocks each one protects only one thing. Irq routing, irq notifier lists and ioapic gain their own spinlock. pic is already uses its own lock. This patch series also makes interrupt injection to lapic lockless (severalkvm_irq_delivery_to_apic()may run in parallel), but access to lapic was never fully locked in the first place. VCPU could access lapic in parallel with interrupt injection.The patch series is on top of my previous series that converts ack notifiers to the RCU locking.
Gleb Natapov (5):
Protectirq_sources_bitmapbykvm->lockinstead ofkvm->irq_lockMove irq routing to its own locking.
Move irq notifiers lists to its own locking.
Move IO APIC to its own lock.
Dropkvm->irq_locklock.arch/ia64/kvm/kvm-ia64.c | 29 +++++++++++++++++++-------- arch/x86/kvm/i8254.c | 4 +- arch/x86/kvm/lapic.c | 7 +----- arch/x86/kvm/x86.c | 32 +++++++++++++++++++----------- include/linux/kvm_host.h | 3 +- virt/kvm/eventfd.c | 2 - virt/kvm/ioapic.c | 47 +++++++++++++++++++++++++++------------------ virt/kvm/ioapic.h | 1 + virt/kvm/irq_comm.c | 35 ++++++++++++++------------------- virt/kvm/kvm_main.c | 7 ++--- 10 files changed, 92 insertions(+), 75 deletions(-)--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
When you have one big lock and you want to eliminate it you look at all things it protects and you start introducing different locking for unrelated stuff. This is what this patch series does, so I don't really get you point.
Quoted 30 lines
Quoted 30 lines
This patch
series splitkvm->irq_lockmutex to smaller spinlocks each one protects only one thing. Irq routing, irq notifier lists and ioapic gain their own spinlock. pic is already uses its own lock. This patch series also makes interrupt injection to lapic lockless (severalkvm_irq_delivery_to_apic()may run in parallel), but access to lapic was never fully locked in the first place. VCPU could access lapic in parallel with interrupt injection.The patch series is on top of my previous series that converts ack notifiers to the RCU locking.
Gleb Natapov (5):
Protectirq_sources_bitmapbykvm->lockinstead ofkvm->irq_lockMove irq routing to its own locking.
Move irq notifiers lists to its own locking.
Move IO APIC to its own lock.
Dropkvm->irq_locklock.arch/ia64/kvm/kvm-ia64.c | 29 +++++++++++++++++++-------- arch/x86/kvm/i8254.c | 4 +- arch/x86/kvm/lapic.c | 7 +----- arch/x86/kvm/x86.c | 32 +++++++++++++++++++----------- include/linux/kvm_host.h | 3 +- virt/kvm/eventfd.c | 2 - virt/kvm/ioapic.c | 47 +++++++++++++++++++++++++++------------------ virt/kvm/ioapic.h | 1 + virt/kvm/irq_comm.c | 35 ++++++++++++++------------------- virt/kvm/kvm_main.c | 7 ++--- 10 files changed, 92 insertions(+), 75 deletions(-)
Quoted 4 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Quoted 6 lines · Gleb Natapov
Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.
Quoted 8 lines
Quoted 4 lines
At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
When you have one big lock and you want to eliminate it you look at all things it protects and you start introducing different locking for unrelated stuff. This is what this patch series does, so I don't really get you point.
But why do you want to eliminate it? What is the operation that this will speed up? Is there a contention issue and which operations contend on the lock?
Quoted 41 lines
Quoted 30 lines
Quoted 30 lines
This patch
series splitkvm->irq_lockmutex to smaller spinlocks each one protects only one thing. Irq routing, irq notifier lists and ioapic gain their own spinlock. pic is already uses its own lock. This patch series also makes interrupt injection to lapic lockless (severalkvm_irq_delivery_to_apic()may run in parallel), but access to lapic was never fully locked in the first place. VCPU could access lapic in parallel with interrupt injection.The patch series is on top of my previous series that converts ack notifiers to the RCU locking.
Gleb Natapov (5):
Protectirq_sources_bitmapbykvm->lockinstead ofkvm->irq_lockMove irq routing to its own locking.
Move irq notifiers lists to its own locking.
Move IO APIC to its own lock.
Dropkvm->irq_locklock.arch/ia64/kvm/kvm-ia64.c | 29 +++++++++++++++++++-------- arch/x86/kvm/i8254.c | 4 +- arch/x86/kvm/lapic.c | 7 +----- arch/x86/kvm/x86.c | 32 +++++++++++++++++++----------- include/linux/kvm_host.h | 3 +- virt/kvm/eventfd.c | 2 - virt/kvm/ioapic.c | 47 +++++++++++++++++++++++++++------------------ virt/kvm/ioapic.h | 1 + virt/kvm/irq_comm.c | 35 ++++++++++++++------------------- virt/kvm/kvm_main.c | 7 ++--- 10 files changed, 92 insertions(+), 75 deletions(-)Quoted 4 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Gleb Natapov
Quoted 9 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
Quoted 9 lines
Quoted 4 lines
When you have one big lock and you want to eliminate it you look at all things it protects and you start introducing different locking for unrelated stuff. This is what this patch series does, so I don't really get you point.
But why do you want to eliminate it? What is the operation that this will speed up? Is there a contention issue and which operations contend on the lock?
Interrupt injection. I want to be able to inject interrupts without the lock at all. At least msi one. PCI/ISA interrupts still take lock in ioapic code. It can be eliminated too if needed.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 34 lines
This patch
series splitkvm->irq_lockmutex to smaller spinlocks each one protects only one thing. Irq routing, irq notifier lists and ioapic gain their own spinlock. pic is already uses its own lock. This patch series also makes interrupt injection to lapic lockless (severalkvm_irq_delivery_to_apic()may run in parallel), but access to lapic was never fully locked in the first place. VCPU could access lapic in parallel with interrupt injection.The patch series is on top of my previous series that converts ack notifiers to the RCU locking.
Gleb Natapov (5):
Protectirq_sources_bitmapbykvm->lockinstead ofkvm->irq_lockMove irq routing to its own locking.
Move irq notifiers lists to its own locking.
Move IO APIC to its own lock.
Dropkvm->irq_locklock.arch/ia64/kvm/kvm-ia64.c | 29 +++++++++++++++++++-------- arch/x86/kvm/i8254.c | 4 +- arch/x86/kvm/lapic.c | 7 +----- arch/x86/kvm/x86.c | 32 +++++++++++++++++++----------- include/linux/kvm_host.h | 3 +- virt/kvm/eventfd.c | 2 - virt/kvm/ioapic.c | 47 +++++++++++++++++++++++++++------------------ virt/kvm/ioapic.h | 1 + virt/kvm/irq_comm.c | 35 ++++++++++++++------------------- virt/kvm/kvm_main.c | 7 ++--- 10 files changed, 92 insertions(+), 75 deletions(-)--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines
Quoted 6 lines
--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Quoted 17 lines · Gleb Natapov
Quoted 16 lines · Michael S. Tsirkin
Quoted 14 lines · Gleb Natapov
Quoted 9 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
When you have one big lock and you want to eliminate it you look at all things it protects and you start introducing different locking for unrelated stuff. This is what this patch series does, so I don't really get you point.
Quoted 6 lines
Quoted 4 lines
But why do you want to eliminate it? What is the operation that this will speed up? Is there a contention issue and which operations contend on the lock?
Interrupt injection. I want to be able to inject interrupts without the lock at all.
You are talking about the lapic changes below, right? OK. But how do the other changes help, specifically? I'm less familiar with ioapic, but I think irq routing and irq notifier list changes are done off data path.
Quoted 51 lines
At least msi one. PCI/ISA interrupts still take lock in ioapic code. It can be eliminated too if needed.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 34 lines
This patch
series splitkvm->irq_lockmutex to smaller spinlocks each one protects only one thing. Irq routing, irq notifier lists and ioapic gain their own spinlock. pic is already uses its own lock. This patch series also makes interrupt injection to lapic lockless (severalkvm_irq_delivery_to_apic()may run in parallel), but access to lapic was never fully locked in the first place. VCPU could access lapic in parallel with interrupt injection.The patch series is on top of my previous series that converts ack notifiers to the RCU locking.
Gleb Natapov (5):
Protectirq_sources_bitmapbykvm->lockinstead ofkvm->irq_lockMove irq routing to its own locking.
Move irq notifiers lists to its own locking.
Move IO APIC to its own lock.
Dropkvm->irq_locklock.arch/ia64/kvm/kvm-ia64.c | 29 +++++++++++++++++++-------- arch/x86/kvm/i8254.c | 4 +- arch/x86/kvm/lapic.c | 7 +----- arch/x86/kvm/x86.c | 32 +++++++++++++++++++----------- include/linux/kvm_host.h | 3 +- virt/kvm/eventfd.c | 2 - virt/kvm/ioapic.c | 47 +++++++++++++++++++++++++++------------------ virt/kvm/ioapic.h | 1 + virt/kvm/irq_comm.c | 35 ++++++++++++++------------------- virt/kvm/kvm_main.c | 7 ++--- 10 files changed, 92 insertions(+), 75 deletions(-)--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlQuoted 6 lines
Quoted 6 lines
--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Gleb NatapovQuoted 7 lines · Gleb Natapov
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
This is a slow operation. It seems that we could use irq_lock or switch to slot lock or kvm lock here. Why do we need another one?
Quoted 95 lines
Quoted 80 lines
with RCU in place list modifications are slow anyway.
Quoted 78 lines
--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)include/linux/kvm_host.h +1
-0@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER virt/kvm/irq_comm.c +8
-8@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }virt/kvm/kvm_main.c +1
-0@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif Quoted 8 lines
Quoted 8 lines
virt/kvm/kvm_main.c +0
-0#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET Signature · 6 lines
1.6.2.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
In reply to Gleb NatapovQuoted 28 lines · Gleb Natapov
It is already protected by
kvm->lockon device assignment path. Just take the same lock in the PIT code.Signed-off-by Gleb Natapov <[email protected]>--- arch/x86/kvm/i8254.c | 2 ++ virt/kvm/irq_comm.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-)arch/x86/kvm/i8254.c +2
-0@@ -596,7 +596,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)if (!pit)return NULL ; +mutex_lock (&kvm->lock); pit->irq_source_id =kvm_request_irq_source_id (kvm); +mutex_unlock (&kvm->lock);if (pit->irq_source_id <0 ) {kfree (pit);return NULL ;virt/kvm/irq_comm.c +0
-0
virt/kvm/irq_comm.c int kvm_request_irq_source_id(struct kvm *kvm) · line 214
Quoted 6 lines
virt/kvm/irq_comm.c +1
-1@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id; -mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock));
Shouldn't this be fatal? (e.g. BUG_ON). I know the usage between BUG/WARN is controversial, but it seems to me that something is completely broken if you expect it to be locked and its not. Might as well fail the system, IMO.
Regards,
-Greg
Quoted 33 lines
virt/kvm/irq_comm.c +3
-3+ irq_source_id =find_first_zero_bit (bitmap,sizeof (kvm->arch.irq_sources_bitmap));@@ -221,7 +222,6 @@ int kvm_request_irq_source_id(struct kvm *kvm)ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID );set_bit (irq_source_id, bitmap); -mutex_unlock (&kvm->irq_lock);return irq_source_id; }@@ -230,9 +230,10 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) {int i; +/* during vm destruction this function is called without locking */ +WARN_ON (!mutex_is_locked (&kvm->lock) &&atomic_read (&kvm->users_count));ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID ); -mutex_lock (&kvm->irq_lock);if (irq_source_id <0 || irq_source_id >=sizeof (kvm->arch.irq_sources_bitmap)) {printk (KERN_ERR "kvm: IRQ source ID out of range!\n" );@@ -241,7 +242,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)for (i =0 ; i <KVM_IOAPIC_NUM_PINS ; i++)clear_bit (irq_source_id, &kvm->arch.irq_states[i]);clear_bit (irq_source_id, &kvm->arch.irq_sources_bitmap); -mutex_unlock (&kvm->irq_lock); } void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
Quoted 22 lines · Michael S. Tsirkin
Quoted 21 lines · Gleb Natapov
Quoted 20 lines · Michael S. Tsirkin
Quoted 6 lines · Gleb Natapov
Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.Quoted 8 lines
Quoted 4 lines
At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
When you have one big lock and you want to eliminate it you look at all things it protects and you start introducing different locking for unrelated stuff. This is what this patch series does, so I don't really get you point.
But why do you want to eliminate it? What is the operation that this will speed up? Is there a contention issue and which operations contend on the lock?
Quoted 8 lines
Quoted 2 lines
Interrupt injection. I want to be able to inject interrupts without the lock at all.
You are talking about the lapic changes below, right? OK. But how do the other changes help, specifically? I'm less familiar with ioapic, but I think irq routing and irq notifier list changes are done off data path.
irq_routing is accessed on irq injection path, so making in lockless is necessary to achieve the goal. Making ack notifiers lockless removes one lock from EOI path.
--
Gleb.
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Michael S. TsirkinQuoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Gleb Natapov
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
This is a slow operation. It seems that we could use
irq_lockor switch to slot lock or kvm lock here. Why do we need another one?
irq_lock is completely removed. So either we don't remove it and use it here (and we don't need mutex so we change it to spinlock too), or we add another lock with the name that actually tell us what its purpose. I prefer second option. I am not sure you can use kvm lock without deadlock, and slot lock? How this connected to slots management?!
And this is not about speed of the operation. It is about making reader lockless.
Quoted 84 lines
Quoted 84 lines
Quoted 84 lines
with RCU in place list modifications are slow anyway.
Quoted 82 lines
--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)include/linux/kvm_host.h +1
-0@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER virt/kvm/irq_comm.c +8
-8@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }virt/kvm/kvm_main.c +1
-0@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET Signature · 1 line
1.6.2.1
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
In reply to Gregory HaskinsQuoted 32 lines · Gregory Haskins
Quoted 31 lines · Gleb Natapov
It is already protected by
kvm->lockon device assignment path. Just take the same lock in the PIT code.Signed-off-by Gleb Natapov <[email protected]>--- arch/x86/kvm/i8254.c | 2 ++ virt/kvm/irq_comm.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-)arch/x86/kvm/i8254.c +2
-0@@ -596,7 +596,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)if (!pit)return NULL ; +mutex_lock (&kvm->lock); pit->irq_source_id =kvm_request_irq_source_id (kvm); +mutex_unlock (&kvm->lock);if (pit->irq_source_id <0 ) {kfree (pit);return NULL ;virt/kvm/irq_comm.c +0
-0@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id;
Quoted 9 lines
virt/kvm/irq_comm.c int kvm_request_irq_source_id(struct kvm *kvm) · line 217
Quoted 3 lines
virt/kvm/irq_comm.c +1
-1-mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock));Shouldn't this be fatal? (e.g.
BUG_ON). I know the usage between BUG/WARN is controversial, but it seems to me that something is completely broken if you expect it to be locked and its not. Might as well fail the system, IMO.
Well I don't really care but we have WARN_ON() in the code currently. Besides the chances are good that even without locking around this function nothing will break, so why kill host kernel?
Quoted 34 lines
Regards,
-GregQuoted 31 lines
virt/kvm/irq_comm.c +3
-3+ irq_source_id =find_first_zero_bit (bitmap,sizeof (kvm->arch.irq_sources_bitmap));@@ -221,7 +222,6 @@ int kvm_request_irq_source_id(struct kvm *kvm)ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID );set_bit (irq_source_id, bitmap); -mutex_unlock (&kvm->irq_lock);return irq_source_id; }@@ -230,9 +230,10 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) {int i; +/* during vm destruction this function is called without locking */ +WARN_ON (!mutex_is_locked (&kvm->lock) &&atomic_read (&kvm->users_count));ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID ); -mutex_lock (&kvm->irq_lock);if (irq_source_id <0 || irq_source_id >=sizeof (kvm->arch.irq_sources_bitmap)) {printk (KERN_ERR "kvm: IRQ source ID out of range!\n" );@@ -241,7 +242,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)for (i =0 ; i <KVM_IOAPIC_NUM_PINS ; i++)clear_bit (irq_source_id, &kvm->arch.irq_states[i]);clear_bit (irq_source_id, &kvm->arch.irq_sources_bitmap); -mutex_unlock (&kvm->irq_lock); }
Quoted 4 lines
virt/kvm/irq_comm.c void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) · line 247
Quoted 2 lines
virt/kvm/irq_comm.c +0
-0void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
--
Gleb.
Quoted 26 lines · Gleb Natapov
Quoted 25 lines · Michael S. Tsirkin
Quoted 23 lines · Gleb Natapov
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Gleb Natapov
Quoted 9 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
Quoted 9 lines
Quoted 4 lines
When you have one big lock and you want to eliminate it you look at all things it protects and you start introducing different locking for unrelated stuff. This is what this patch series does, so I don't really get you point.
But why do you want to eliminate it? What is the operation that this will speed up? Is there a contention issue and which operations contend on the lock?
Interrupt injection. I want to be able to inject interrupts without the lock at all.
Quoted 8 lines
Quoted 5 lines
You are talking about the lapic changes below, right? OK. But how do the other changes help, specifically? I'm less familiar with ioapic, but I think irq routing and irq notifier list changes are done off data path.
irq_routingis accessed on irq injection path, so making in lockless is necessary to achieve the goal. Making ack notifiers lockless removes one lock from EOI path.
But this is done with RCU patches, right?
Signature · 1 line
MST
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Gleb NatapovQuoted 13 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Gleb Natapov
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
This is a slow operation. It seems that we could use
irq_lockor switch to slot lock or kvm lock here. Why do we need another one?
Quoted 8 lines
irq_lockis completely removed. So either we don't remove it and use it here (and we don't need mutex so we change it to spinlock too), or we add another lock with the name that actually tell us what its purpose. I prefer second option. I am not sure you can use kvm lock without deadlock, and slot lock? How this connected to slots management?!And this is not about speed of the operation. It is about making reader lockless.
So, to summarize: this patch does not help speed irq injection up, the only reason to change locking here is cosmetical. Is this a fair summary?
Quoted 102 lines
Quoted 84 lines
Quoted 84 lines
Quoted 84 lines
with RCU in place list modifications are slow anyway.
Quoted 82 lines
--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)include/linux/kvm_host.h +1
-0@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER virt/kvm/irq_comm.c +8
-8@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }virt/kvm/kvm_main.c +1
-0@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET Signature · 1 line
1.6.2.1Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
In reply to Gleb NatapovQuoted 42 lines · Gleb Natapov
Quoted 32 lines · Gregory Haskins
Quoted 31 lines · Gleb Natapov
It is already protected by
kvm->lockon device assignment path. Just take the same lock in the PIT code.Signed-off-by Gleb Natapov <[email protected]>--- arch/x86/kvm/i8254.c | 2 ++ virt/kvm/irq_comm.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-)arch/x86/kvm/i8254.c +2
-0@@ -596,7 +596,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)if (!pit)return NULL ; +mutex_lock (&kvm->lock); pit->irq_source_id =kvm_request_irq_source_id (kvm); +mutex_unlock (&kvm->lock);if (pit->irq_source_id <0 ) {kfree (pit);return NULL ;virt/kvm/irq_comm.c +0
-0@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id;Quoted 9 lines
virt/kvm/irq_comm.c int kvm_request_irq_source_id(struct kvm *kvm) · line 217
Quoted 3 lines
virt/kvm/irq_comm.c +1
-1-mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock));Shouldn't this be fatal? (e.g.
BUG_ON). I know the usage between BUG/WARN is controversial, but it seems to me that something is completely broken if you expect it to be locked and its not. Might as well fail the system, IMO.
Quoted 3 lines
Well I don't really care but we have
WARN_ON()in the code currently. Besides the chances are good that even without locking around this function nothing will break, so why kill host kernel?
Yea. Might as well replace with a comment saying the function expects the mutex to be locked.
Quoted 47 lines
Quoted 34 lines
Regards,
-GregQuoted 31 lines
virt/kvm/irq_comm.c +3
-3+ irq_source_id =find_first_zero_bit (bitmap,sizeof (kvm->arch.irq_sources_bitmap));@@ -221,7 +222,6 @@ int kvm_request_irq_source_id(struct kvm *kvm)ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID );set_bit (irq_source_id, bitmap); -mutex_unlock (&kvm->irq_lock);return irq_source_id; }@@ -230,9 +230,10 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) {int i; +/* during vm destruction this function is called without locking */ +WARN_ON (!mutex_is_locked (&kvm->lock) &&atomic_read (&kvm->users_count));ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID ); -mutex_lock (&kvm->irq_lock);if (irq_source_id <0 || irq_source_id >=sizeof (kvm->arch.irq_sources_bitmap)) {printk (KERN_ERR "kvm: IRQ source ID out of range!\n" );@@ -241,7 +242,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)for (i =0 ; i <KVM_IOAPIC_NUM_PINS ; i++)clear_bit (irq_source_id, &kvm->arch.irq_states[i]);clear_bit (irq_source_id, &kvm->arch.irq_sources_bitmap); -mutex_unlock (&kvm->irq_lock); }Quoted 4 lines
virt/kvm/irq_comm.c void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) · line 247
Quoted 2 lines
virt/kvm/irq_comm.c +0
-0void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
Quoted 43 lines · Michael S. Tsirkin
Quoted 42 lines · Gleb Natapov
Quoted 41 lines · Gregory Haskins
Quoted 28 lines · Gleb Natapov
It is already protected by
kvm->lockon device assignment path. Just take the same lock in the PIT code.Signed-off-by Gleb Natapov <[email protected]>--- arch/x86/kvm/i8254.c | 2 ++ virt/kvm/irq_comm.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-)arch/x86/kvm/i8254.c +2
-0@@ -596,7 +596,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)if (!pit)return NULL ; +mutex_lock (&kvm->lock); pit->irq_source_id =kvm_request_irq_source_id (kvm); +mutex_unlock (&kvm->lock);if (pit->irq_source_id <0 ) {kfree (pit);return NULL ;virt/kvm/irq_comm.c +0
-0virt/kvm/irq_comm.c int kvm_request_irq_source_id(struct kvm *kvm) · line 214
Quoted 6 lines
virt/kvm/irq_comm.c +1
-1@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id; -mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock));Shouldn't this be fatal? (e.g.
BUG_ON). I know the usage between BUG/WARN is controversial, but it seems to me that something is completely broken if you expect it to be locked and its not. Might as well fail the system, IMO.
Quoted 7 lines
Quoted 3 lines
Well I don't really care but we have
WARN_ON()in the code currently. Besides the chances are good that even without locking around this function nothing will break, so why kill host kernel?Yea. Might as well replace with a comment saying the function expects the mutex to be locked.
No. The we will not get bug reports if there are problems. Otherwise you can say the same about each and every WARN_ON() in the code.
Quoted 41 lines
Quoted 41 lines
Quoted 38 lines
Regards,
-GregQuoted 33 lines
virt/kvm/irq_comm.c +3
-3+ irq_source_id =find_first_zero_bit (bitmap,sizeof (kvm->arch.irq_sources_bitmap));@@ -221,7 +222,6 @@ int kvm_request_irq_source_id(struct kvm *kvm)ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID );set_bit (irq_source_id, bitmap); -mutex_unlock (&kvm->irq_lock);return irq_source_id; }@@ -230,9 +230,10 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) {int i; +/* during vm destruction this function is called without locking */ +WARN_ON (!mutex_is_locked (&kvm->lock) &&atomic_read (&kvm->users_count));ASSERT (irq_source_id !=KVM_USERSPACE_IRQ_SOURCE_ID ); -mutex_lock (&kvm->irq_lock);if (irq_source_id <0 || irq_source_id >=sizeof (kvm->arch.irq_sources_bitmap)) {printk (KERN_ERR "kvm: IRQ source ID out of range!\n" );@@ -241,7 +242,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)for (i =0 ; i <KVM_IOAPIC_NUM_PINS ; i++)clear_bit (irq_source_id, &kvm->arch.irq_states[i]);clear_bit (irq_source_id, &kvm->arch.irq_sources_bitmap); -mutex_unlock (&kvm->irq_lock); } void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
Quoted 6 lines
Quoted 6 lines
--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
In reply to Gleb NatapovQuoted 22 lines · Gleb Natapov
Quoted 10 lines · Gregory Haskins
Quoted 8 lines · Gleb Natapov
virt/kvm/irq_comm.c +0
-0@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id;Quoted 10 lines
virt/kvm/irq_comm.c int kvm_request_irq_source_id(struct kvm *kvm)
Quoted 4 lines
virt/kvm/irq_comm.c +1
-1-mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock));Shouldn't this be fatal? (e.g.
BUG_ON). I know the usage between BUG/WARN is controversial, but it seems to me that something is completely broken if you expect it to be locked and its not. Might as well fail the system, IMO.
Quoted 2 lines
Well I don't really care but we have
WARN_ON()in the code currently.
Well, that is perhaps unfortunate, but not relevant. I am not reviewing those patches ;)
Quoted 3 lines
Besides the chances are good that even without locking around this function nothing will break, so why kill host kernel?
The question to ask is: Is it legal to continue to run if the mutex is found unlocked? If not, the offending caller should be found/fixed as early as possible IMO, and an oops should be sufficient to do so. I think WARN_ON tends to gets overused/abused, so lets not perpetuate it simply because of precedence.
Kind Regards,
-Greg
Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
Quoted 41 lines · Gregory Haskins
Quoted 26 lines · Gleb Natapov
Quoted 11 lines · Gregory Haskins
Quoted 8 lines · Gleb Natapov
virt/kvm/irq_comm.c +0
-0@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id;Quoted 12 lines
virt/kvm/irq_comm.c int kvm_request_irq_source_id(struct kvm *kvm)
Quoted 5 lines
virt/kvm/irq_comm.c +1
-1-mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock));Shouldn't this be fatal? (e.g.
BUG_ON). I know the usage between BUG/WARN is controversial, but it seems to me that something is completely broken if you expect it to be locked and its not. Might as well fail the system, IMO.Quoted 3 lines
Well I don't really care but we have
WARN_ON()in the code currently.Well, that is perhaps unfortunate, but not relevant. I am not reviewing those patches ;)
Quoted 4 lines
Besides the chances are good that even without locking around this function nothing will break, so why kill host kernel?
Quoted 6 lines
The question to ask is: Is it legal to continue to run if the mutex is found unlocked? If not, the offending caller should be found/fixed as early as possible IMO, and an oops should be sufficient to do so. I think
WARN_ONtends to gets overused/abused, so lets not perpetuate it simply because of precedence.
Err..precedent, I mean. Heh.
/me needs more coffee.
-Greg
Quoted 5 lines
Kind Regards,
-Greg
Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
In reply to Gregory HaskinsQuoted 33 lines · Gregory Haskins
Quoted 22 lines · Gleb Natapov
Quoted 10 lines · Gregory Haskins
Quoted 8 lines · Gleb Natapov
virt/kvm/irq_comm.c +0
-0@@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;int irq_source_id;Quoted 10 lines
virt/kvm/irq_comm.c int kvm_request_irq_source_id(struct kvm *kvm)
Quoted 4 lines
virt/kvm/irq_comm.c +1
-1-mutex_lock (&kvm->irq_lock); +WARN_ON (!mutex_is_locked (&kvm->lock));Shouldn't this be fatal? (e.g.
BUG_ON). I know the usage between BUG/WARN is controversial, but it seems to me that something is completely broken if you expect it to be locked and its not. Might as well fail the system, IMO.Quoted 2 lines
Well I don't really care but we have
WARN_ON()in the code currently.Well, that is perhaps unfortunate, but not relevant. I am not reviewing those patches ;)
Quoted 3 lines
Besides the chances are good that even without locking around this function nothing will break, so why kill host kernel?
Quoted 6 lines
The question to ask is: Is it legal to continue to run if the mutex is found unlocked? If not, the offending caller should be found/fixed as early as possible IMO, and an oops should be sufficient to do so. I think
WARN_ONtends to gets overused/abused, so lets not perpetuate it simply because of precedence.
I will have to end this particular thread about WARN_ON by stating that Avi told me to put it there. I'll let him decide.
--
Gleb.
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Gleb Natapov
Quoted 30 lines · Michael S. Tsirkin
Quoted 17 lines · Gleb Natapov
Quoted 16 lines · Michael S. Tsirkin
Quoted 14 lines · Gleb Natapov
Quoted 9 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
kvm->irq_lockprotects too much stuff, but still fail to protect everything it was design to protect (see ack notifiers call in pic). I want to make IRQ injection logic use more fine grained locking.At least irq routing changes and notifier list changes do not seem to be involved in irq injection. So why do we want fine-grained locking there?
When you have one big lock and you want to eliminate it you look at all things it protects and you start introducing different locking for unrelated stuff. This is what this patch series does, so I don't really get you point.
Quoted 6 lines
Quoted 4 lines
But why do you want to eliminate it? What is the operation that this will speed up? Is there a contention issue and which operations contend on the lock?
Interrupt injection. I want to be able to inject interrupts without the lock at all.
You are talking about the lapic changes below, right? OK. But how do the other changes help, specifically? I'm less familiar with ioapic, but I think irq routing and irq notifier list changes are done off data path.
Quoted 6 lines
Quoted 3 lines
irq_routingis accessed on irq injection path, so making in lockless is necessary to achieve the goal. Making ack notifiers lockless removes one lock from EOI path.But this is done with RCU patches, right?
No, not right. Only rcu patch is meaningless since irq injection is still done under irq_lock. Look at the whole series, not each line by itself.
--
Gleb.
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Michael S. TsirkinQuoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Gleb Natapov
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Gleb Natapov
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Gleb Natapov
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
This is a slow operation. It seems that we could use
irq_lockor switch to slot lock or kvm lock here. Why do we need another one?
irq_lockis completely removed. So either we don't remove it and use it here (and we don't need mutex so we change it to spinlock too), or we add another lock with the name that actually tell us what its purpose. I prefer second option. I am not sure you can use kvm lock without deadlock, and slot lock? How this connected to slots management?!
Quoted 7 lines
Quoted 2 lines
And this is not about speed of the operation. It is about making reader lockless.
So, to summarize: this patch does not help speed irq injection up, the only reason to change locking here is cosmetical. Is this a fair summary?
The whole series helps to speed irq injection up. This patch is one step towards the goal.
Quoted 97 lines
Quoted 97 lines
Quoted 96 lines
Quoted 96 lines
Quoted 81 lines
with RCU in place list modifications are slow anyway.
Quoted 78 lines
--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)include/linux/kvm_host.h +1
-0@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER virt/kvm/irq_comm.c +8
-8@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }virt/kvm/kvm_main.c +1
-0@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif Quoted 8 lines
Quoted 8 lines
virt/kvm/kvm_main.c +0
-0#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET Signature · 6 lines
1.6.2.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines
Quoted 6 lines
--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
Quoted 31 lines · Gleb Natapov
Quoted 29 lines · Michael S. Tsirkin
Quoted 27 lines · Gleb Natapov
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines · Gleb Natapov
Quoted 2 lines · Michael S. Tsirkin
On Mon, Jul 13, 2009 at 12:12:33PM +0300, Gleb Natapov wrote:
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
This is a slow operation. It seems that we could use
irq_lockor switch to slot lock or kvm lock here. Why do we need another one?
irq_lockis completely removed. So either we don't remove it and use it here (and we don't need mutex so we change it to spinlock too), or we add another lock with the name that actually tell us what its purpose. I prefer second option. I am not sure you can use kvm lock without deadlock, and slot lock? How this connected to slots management?!And this is not about speed of the operation. It is about making reader lockless.
Quoted 8 lines
Quoted 5 lines
So, to summarize: this patch does not help speed irq injection up, the only reason to change locking here is cosmetical. Is this a fair summary?
The whole series helps to speed irq injection up. This patch is one step towards the goal.
FWIW: Improving the injection path in the manner Gleb is proposing will pave the way to skip the work-queue deferrment in the irqfd signal path. This is a good thing.
Regards,
-Greg
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Gleb NatapovQuoted 6 lines · Gleb Natapov
Quoted 4 lines
So, to summarize: this patch does not help speed irq injection up, the only reason to change locking here is cosmetical. Is this a fair summary?
The whole series helps to speed irq injection up. This patch is one step towards the goal.
Let me rephrase: it's possible to drop patches 2 and 3 from the series and irq injection will still be lockless. Correct?
Signature · 1 line
MST
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Gleb NatapovQuoted 10 lines · Gleb Natapov
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Gleb Natapov
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
Quoted 8 lines
Quoted 3 lines
This is a slow operation. It seems that we could use
irq_lockor switch to slot lock or kvm lock here. Why do we need another one?
irq_lockis completely removed. So either we don't remove it and use it here (and we don't need mutex so we change it to spinlock too), or we add another lock with the name that actually tell us what its purpose. I prefer second option. I am not sure you can use kvm lock without deadlock, and slot lock? How this connected to slots management?!
slots_lock is just a bad name now. See slots_lock is taken for read on every exit. So taking slots_lock for write means all guests are stopped in a known synchronization state.
If the write side of the operation is very unfrequent (such as registration of irq ack/mask notifiers), down_write(slots_lock) works as a simpler replacement for RCU.
We want to get rid of slots_lock on every exit at some point, though.
Quoted 101 lines
And this is not about speed of the operation. It is about making reader lockless.
Quoted 84 lines
Quoted 84 lines
Quoted 84 lines
with RCU in place list modifications are slow anyway.
Quoted 82 lines
--- include/linux/kvm_host.h | 1 + virt/kvm/irq_comm.c | 16 ++++++++-------- virt/kvm/kvm_main.c | 1 + 3 files changed, 10 insertions(+), 8 deletions(-)include/linux/kvm_host.h +1
-0@@ -165,6 +165,7 @@ struct kvm {spinlock_t irq_routing_lock;struct hlist_head mask_notifier_list;struct hlist_head irq_ack_notifier_list; +spinlock_t irq_notifier_list_lock;#endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER virt/kvm/irq_comm.c +8
-8@@ -191,17 +191,17 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)void kvm_register_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_add_head_rcu (&kian->link, &kvm->irq_ack_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_ack_notifier (struct kvm *kvm,struct kvm_irq_ack_notifier *kian) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_init_rcu (&kian->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }@@ -247,18 +247,18 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)void kvm_register_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock); kimn->irq = irq;hlist_add_head_rcu (&kimn->link, &kvm->mask_notifier_list); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock); }void kvm_unregister_irq_mask_notifier (struct kvm *kvm,int irq,struct kvm_irq_mask_notifier *kimn) { -mutex_lock (&kvm->irq_lock); +spin_lock (&kvm->irq_notifier_list_lock);hlist_del_rcu (&kimn->link); -mutex_unlock (&kvm->irq_lock); +spin_unlock (&kvm->irq_notifier_list_lock);synchronize_rcu (); }virt/kvm/kvm_main.c +1
-0@@ -948,6 +948,7 @@ static struct kvm *kvm_create_vm(void)spin_lock_init (&kvm->irq_routing_lock);INIT_HLIST_HEAD (&kvm->mask_notifier_list);INIT_HLIST_HEAD (&kvm->irq_ack_notifier_list); +spin_lock_init (&kvm->irq_notifier_list_lock);#endif #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET Signature · 1 line
1.6.2.1Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Gleb.
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Michael S. TsirkinQuoted 11 lines · Michael S. Tsirkin
Quoted 6 lines · Gleb Natapov
Quoted 4 lines
So, to summarize: this patch does not help speed irq injection up, the only reason to change locking here is cosmetical. Is this a fair summary?
The whole series helps to speed irq injection up. This patch is one step towards the goal.
Let me rephrase: it's possible to drop patches 2 and 3 from the series and irq injection will still be lockless. Correct?
You can use here any one of million locks that is available in linux that is not taken at the moment this functions are called. So yes you can drop them.
--
Gleb.
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
In reply to Marcelo TosattiQuoted 14 lines · Marcelo Tosatti
Quoted 13 lines · Gleb Natapov
Quoted 12 lines · Michael S. Tsirkin
Quoted 7 lines · Gleb Natapov
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>This one is probably better off left as is,
What do you mean "as is"?
This is a slow operation. It seems that we could use
irq_lockor switch to slot lock or kvm lock here. Why do we need another one?
Quoted 8 lines
Quoted 5 lines
irq_lockis completely removed. So either we don't remove it and use it here (and we don't need mutex so we change it to spinlock too), or we add another lock with the name that actually tell us what its purpose. I prefer second option. I am not sure you can use kvm lock without deadlock, and slot lock? How this connected to slots management?!
slots_lockis just a bad name now. Seeslots_lockis taken for read on every exit. So takingslots_lockfor write means all guests are stopped
^^^^^^
all vcpus
Quoted 10 lines
in a known synchronization state.
If the write side of the operation is very unfrequent (such as registration of irq ack/mask notifiers),
down_write(slots_lock)works as a simpler replacement for RCU.We want to get rid of
slots_lockon every exit at some point, though.Quoted 2 lines
And this is not about speed of the operation. It is about making reader lockless.
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
Quoted 6 lines · Marcelo Tosatti
Quoted 2 lines
slots_lockis just a bad name now. Seeslots_lockis taken for read on every exit. So takingslots_lockfor write means all guests are stopped^^^^^^all vcpus
That is a very good reason to not wanting slots_lock near interrupt injection path.
--
Gleb.
Re: [PATCH 3/5] Move irq notifiers lists to its own locking.
Quoted 9 lines · Gleb Natapov
Quoted 6 lines · Marcelo Tosatti
Quoted 2 lines
slots_lockis just a bad name now. Seeslots_lockis taken for read on every exit. So takingslots_lockfor write means all guests are stopped^^^^^^all vcpus
That is a very good reason to not wanting
slots_locknear interrupt injection path.
Indeed.