All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, Christian Borntraeger <borntraeger@de.ibm.com>
Subject: Re: [patch 0/4] move irq protection role to separate lock v2
Date: Thu, 21 May 2009 01:50:15 -0300	[thread overview]
Message-ID: <20090521045015.GA1104@amt.cnet> (raw)
In-Reply-To: <20090520184841.954066003@localhost.localdomain>

On Wed, May 20, 2009 at 03:48:41PM -0300, Marcelo Tosatti wrote:
> Addressing comment and covering irqfd (did not remove the deadlock avoidance 
> there since it might be useful later).

I can't see any reason why serializing the vm ioctl is a bad idea.

There is one indication of disagreement here:

http://patchwork.kernel.org/patch/5661/

"The original intent was that kvm_arch_vcpu_create() not "link in" the
vcpu to any registers. That allows most of the vcpu creation to happen
outside a lock."

But I fail to see the case where vcpu creation is a fast path (unless
you're benchmarking cpu hotplug/hotunplug).

Note there is no risk of a deadlock in case a vcpu thread attempts to
execute vm_ioctl.

Also vm_ioctl_lock will always be the first lock grabbed in the vm_ioctl
path, and not used in any other path, there's no risk of deadlock.

The reason for this is there are sites, such as KVM_CREATE_PIT, which
handle concurrency properly (with custom locking that becomes obsolete),
but some don't.


Index: kvm/include/linux/kvm_host.h
===================================================================
--- kvm.orig/include/linux/kvm_host.h
+++ kvm/include/linux/kvm_host.h
@@ -131,9 +131,9 @@ struct kvm {
 					KVM_PRIVATE_MEM_SLOTS];
 	struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
 	struct list_head vm_list;
+	struct mutex vm_ioctl_lock; /* protects concurrent vm fd ioctls */
 	struct mutex lock; /*
 			    * - protects mmio_bus, pio_bus.
-			    * - protects a few concurrent ioctl's (FIXME).
 			    * - protects concurrent create_vcpu, but
 			    *   kvm->vcpus walkers do it locklessly (FIXME).
 			    */
Index: kvm/virt/kvm/kvm_main.c
===================================================================
--- kvm.orig/virt/kvm/kvm_main.c
+++ kvm/virt/kvm/kvm_main.c
@@ -988,6 +988,7 @@ static struct kvm *kvm_create_vm(void)
 	INIT_LIST_HEAD(&kvm->irqfds);
 	mutex_init(&kvm->lock);
 	mutex_init(&kvm->irq_lock);
+	mutex_init(&kvm->vm_ioctl_lock);
 	kvm_io_bus_init(&kvm->mmio_bus);
 	init_rwsem(&kvm->slots_lock);
 	atomic_set(&kvm->users_count, 1);
@@ -2053,6 +2054,9 @@ static long kvm_vm_ioctl(struct file *fi
 
 	if (kvm->mm != current->mm)
 		return -EIO;
+
+	mutex_lock(&kvm->vm_ioctl_lock);
+
 	switch (ioctl) {
 	case KVM_CREATE_VCPU:
 		r = kvm_vm_ioctl_create_vcpu(kvm, arg);
@@ -2228,6 +2232,7 @@ static long kvm_vm_ioctl(struct file *fi
 		r = kvm_arch_vm_ioctl(filp, ioctl, arg);
 	}
 out:
+	mutex_unlock(&kvm->vm_ioctl_lock);
 	return r;
 }
 

  parent reply	other threads:[~2009-05-21  4:50 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 16:56 [patch 0/4] move irq protection role to separate kvm->irq_lock Marcelo Tosatti
2009-05-18 16:56 ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-05-18 16:56 ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Marcelo Tosatti
2009-05-20 12:06   ` Avi Kivity
2009-05-20 14:09     ` Marcelo Tosatti
2009-05-20 14:29       ` Avi Kivity
2009-05-20 15:13         ` Marcelo Tosatti
2009-05-20 15:22           ` Marcelo Tosatti
2009-05-20 15:22           ` Avi Kivity
2009-05-20 18:48         ` [patch 0/4] move irq protection role to separate lock v2 Marcelo Tosatti
2009-05-20 18:48           ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-05-20 18:48           ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Marcelo Tosatti
2009-05-24 14:04             ` Avi Kivity
2009-05-25 11:04               ` Marcelo Tosatti
2009-05-26 11:24                 ` Avi Kivity
2009-05-26 13:15                   ` Marcelo Tosatti
2009-05-26 13:27                     ` Avi Kivity
2009-05-20 18:48           ` [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic Marcelo Tosatti
2009-05-24 14:10             ` Avi Kivity
2009-05-25 11:11               ` Marcelo Tosatti
2009-05-26 11:33                 ` Avi Kivity
2009-05-28  4:45               ` [patch 0/4] move irq protection role to separate lock v3 Marcelo Tosatti
2009-05-28  4:45               ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-05-28  4:45               ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Marcelo Tosatti
2009-05-31 12:14                 ` Avi Kivity
2009-06-01 21:23                   ` Marcelo Tosatti
2009-06-01 21:43                     ` Avi Kivity
2009-06-04 18:08                   ` [patch 0/4] move irq protection role to separate lock v4 Marcelo Tosatti
2009-06-04 18:08                     ` [patch 1/4] KVM: x86: grab pic lock in kvm_pic_clear_isr_ack Marcelo Tosatti
2009-06-04 18:08                     ` [patch 2/4] KVM: move coalesced_mmio locking to its own device Marcelo Tosatti
2009-06-04 18:08                     ` [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic Marcelo Tosatti
2009-06-04 18:08                     ` [patch 4/4] KVM: switch irq injection/acking data structures to irq_lock Marcelo Tosatti
2009-06-08  9:18                     ` [patch 0/4] move irq protection role to separate lock v4 Avi Kivity
2009-05-28  4:45               ` [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic Marcelo Tosatti
2009-05-28  4:45               ` [patch 4/4] KVM: switch irq injection/acking data structures to irq_lock Marcelo Tosatti
2009-05-20 18:48           ` [patch 4/4] KVM: switch irq injection/acking " Marcelo Tosatti
2009-05-21  4:50           ` Marcelo Tosatti [this message]
2009-05-21  6:55             ` [patch 0/4] move irq protection role to separate lock v2 Christian Bornträger
2009-05-21  7:26               ` Avi Kivity
2009-05-21 14:32                 ` Marcelo Tosatti
2009-05-21 15:02                   ` Avi Kivity
2009-05-18 16:56 ` [patch 3/4] KVM: introduce irq_lock, use it protect ioapic Marcelo Tosatti
2009-05-20 12:11   ` Avi Kivity
2009-05-20 14:11     ` Marcelo Tosatti
2009-05-20 14:29       ` Avi Kivity
2009-05-18 16:56 ` [patch 4/4] KVM: switch irq injection/acking to irq_lock Marcelo Tosatti
2009-05-20 12:15   ` Gregory Haskins
2009-05-20 14:16     ` Marcelo Tosatti
2009-05-24 14:53     ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090521045015.GA1104@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.