From: Marcelo Tosatti <[email protected]>

Introduce irq_lock, and use to protect ioapic data structures.

Signed-off-by: Marcelo Tosatti <[email protected]>
Signed-off-by: Avi Kivity <[email protected]>

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index bcb94eb..c32df81 100644
--- a/include/linux/kvm_host.h
+++ b/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,7 @@ struct kvm {
                                        KVM_PRIVATE_MEM_SLOTS];
        struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
        struct list_head vm_list;
+       struct mutex lock;
        struct kvm_io_bus mmio_bus;
        struct kvm_io_bus pio_bus;
 #ifdef CONFIG_HAVE_KVM_EVENTFD
@@ -145,6 +145,7 @@ struct kvm {
        struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
 #endif
 
+       struct mutex irq_lock;
 #ifdef CONFIG_HAVE_KVM_IRQCHIP
        struct list_head irq_routing; /* of kvm_kernel_irq_routing_entry */
        struct hlist_head mask_notifier_list;
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
index 6b00433..1665961 100644
--- a/virt/kvm/ioapic.c
+++ b/virt/kvm/ioapic.c
@@ -243,6 +243,7 @@ static void ioapic_mmio_read(struct kvm_io_device *this, 
gpa_t addr, int len,
        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:
@@ -269,6 +270,7 @@ static void ioapic_mmio_read(struct kvm_io_device *this, 
gpa_t addr, int len,
        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,
@@ -280,6 +282,8 @@ static void ioapic_mmio_write(struct kvm_io_device *this, 
gpa_t addr, int len,
        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 {
@@ -305,6 +309,7 @@ static void ioapic_mmio_write(struct kvm_io_device *this, 
gpa_t addr, int len,
        default:
                break;
        }
+       mutex_unlock(&ioapic->kvm->irq_lock);
 }
 
 void kvm_ioapic_reset(struct kvm_ioapic *ioapic)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 3dca047..e1032fd 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -979,6 +979,7 @@ 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);
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to