public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>, kvm@vger.kernel.org
Cc: Gregory Haskins <gregory.haskins@gmail.com>,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic
Date: Wed, 20 May 2009 15:48:44 -0300	[thread overview]
Message-ID: <20090520185134.748295218@localhost.localdomain> (raw)
In-Reply-To: 20090520184841.954066003@localhost.localdomain

[-- Attachment #1: ioapic-lock --]
[-- Type: text/plain, Size: 3320 bytes --]

Subject says it all.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: kvm-irqlock/include/linux/kvm_host.h
===================================================================
--- kvm-irqlock.orig/include/linux/kvm_host.h
+++ kvm-irqlock/include/linux/kvm_host.h
@@ -123,7 +123,6 @@ struct kvm_kernel_irq_routing_entry {
 };
 
 struct kvm {
-	struct mutex lock; /* protects the vcpus array and APIC accesses */
 	spinlock_t mmu_lock;
 	struct rw_semaphore slots_lock;
 	struct mm_struct *mm; /* userspace tied to this vm */
@@ -132,6 +131,12 @@ struct kvm {
 					KVM_PRIVATE_MEM_SLOTS];
 	struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
 	struct list_head vm_list;
+	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).
+			    */
 	struct kvm_io_bus mmio_bus;
 	struct kvm_io_bus pio_bus;
 	struct list_head irqfds;
@@ -143,6 +148,7 @@ struct kvm {
 	struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
 #endif
 
+	struct mutex irq_lock; /* protects high level irq logic, ioapic */
 #ifdef CONFIG_HAVE_KVM_IRQCHIP
 	struct list_head irq_routing; /* of kvm_kernel_irq_routing_entry */
 	struct hlist_head mask_notifier_list;
Index: kvm-irqlock/virt/kvm/ioapic.c
===================================================================
--- kvm-irqlock.orig/virt/kvm/ioapic.c
+++ kvm-irqlock/virt/kvm/ioapic.c
@@ -225,6 +225,10 @@ static int ioapic_in_range(struct kvm_io
 {
 	struct kvm_ioapic *ioapic = (struct kvm_ioapic *)this->private;
 
+	/*
+	 * Lockless check for ioapic->base_address on the hazy assumption
+	 * it does not change during the lifetime of a VM.
+	 */
 	return ((addr >= ioapic->base_address &&
 		 (addr < ioapic->base_address + IOAPIC_MEM_LENGTH)));
 }
@@ -238,6 +242,7 @@ static void ioapic_mmio_read(struct kvm_
 	ioapic_debug("addr %lx\n", (unsigned long)addr);
 	ASSERT(!(addr & 0xf));	/* check alignment */
 
+	mutex_lock(&ioapic->kvm->irq_lock);
 	addr &= 0xff;
 	switch (addr) {
 	case IOAPIC_REG_SELECT:
@@ -264,6 +269,7 @@ static void ioapic_mmio_read(struct kvm_
 	default:
 		printk(KERN_WARNING "ioapic: wrong length %d\n", len);
 	}
+	mutex_unlock(&ioapic->kvm->irq_lock);
 }
 
 static void ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len,
@@ -275,6 +281,8 @@ static void ioapic_mmio_write(struct kvm
 	ioapic_debug("ioapic_mmio_write addr=%p len=%d val=%p\n",
 		     (void*)addr, len, val);
 	ASSERT(!(addr & 0xf));	/* check alignment */
+
+	mutex_lock(&ioapic->kvm->irq_lock);
 	if (len == 4 || len == 8)
 		data = *(u32 *) val;
 	else {
@@ -300,6 +308,7 @@ static void ioapic_mmio_write(struct kvm
 	default:
 		break;
 	}
+	mutex_unlock(&ioapic->kvm->irq_lock);
 }
 
 void kvm_ioapic_reset(struct kvm_ioapic *ioapic)
Index: kvm-irqlock/virt/kvm/kvm_main.c
===================================================================
--- kvm-irqlock.orig/virt/kvm/kvm_main.c
+++ kvm-irqlock/virt/kvm/kvm_main.c
@@ -985,6 +985,7 @@ static struct kvm *kvm_create_vm(void)
 	kvm_io_bus_init(&kvm->pio_bus);
 	INIT_LIST_HEAD(&kvm->irqfds);
 	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);

-- 


  parent reply	other threads:[~2009-05-20 18:54 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           ` Marcelo Tosatti [this message]
2009-05-24 14:10             ` [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic 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           ` [patch 0/4] move irq protection role to separate lock v2 Marcelo Tosatti
2009-05-21  6:55             ` 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=20090520185134.748295218@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=gregory.haskins@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox