From patchwork Thu Jun 4 18:08:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 27990 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n54IFsnV002204 for ; Thu, 4 Jun 2009 18:15:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753276AbZFDSMy (ORCPT ); Thu, 4 Jun 2009 14:12:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753434AbZFDSMx (ORCPT ); Thu, 4 Jun 2009 14:12:53 -0400 Received: from mx2.redhat.com ([66.187.237.31]:50795 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753458AbZFDSMs (ORCPT ); Thu, 4 Jun 2009 14:12:48 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n54ICp09019375 for ; Thu, 4 Jun 2009 14:12:51 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n54ICoub002651; Thu, 4 Jun 2009 14:12:50 -0400 Received: from amt.cnet (vpn-10-27.str.redhat.com [10.32.10.27]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n54ICl9X006168; Thu, 4 Jun 2009 14:12:48 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 29ACD680263; Thu, 4 Jun 2009 15:11:50 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n54IBopt014197; Thu, 4 Jun 2009 15:11:50 -0300 Message-Id: <20090604180939.078561065@localhost.localdomain> References: <20090604180820.644455695@localhost.localdomain> User-Agent: quilt/0.46-1 Date: Thu, 04 Jun 2009 15:08:23 -0300 From: Marcelo Tosatti To: avi@redhat.com, kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [patch 3/4] KVM: introduce irq_lock, use it to protect ioapic Content-Disposition: inline; filename=ioapic-lock X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Introduce irq_lock, and use to protect ioapic data structures. Signed-off-by: Marcelo Tosatti Index: kvm/include/linux/kvm_host.h =================================================================== --- kvm.orig/include/linux/kvm_host.h +++ kvm/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; Index: kvm/virt/kvm/ioapic.c =================================================================== --- kvm.orig/virt/kvm/ioapic.c +++ kvm/virt/kvm/ioapic.c @@ -243,6 +243,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: @@ -269,6 +270,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, @@ -280,6 +282,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 { @@ -305,6 +309,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/virt/kvm/kvm_main.c =================================================================== --- kvm.orig/virt/kvm/kvm_main.c +++ kvm/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);