From patchwork Tue Dec 1 14:36:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Lalancette X-Patchwork-Id: 63976 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 nB1Ebb3Y013545 for ; Tue, 1 Dec 2009 14:37:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753070AbZLAOhI (ORCPT ); Tue, 1 Dec 2009 09:37:08 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752936AbZLAOhH (ORCPT ); Tue, 1 Dec 2009 09:37:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31420 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752557AbZLAOhD (ORCPT ); Tue, 1 Dec 2009 09:37:03 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB1Eb9o2006447 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 1 Dec 2009 09:37:09 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB1Eb36O002533; Tue, 1 Dec 2009 09:37:08 -0500 From: Chris Lalancette To: kvm@vger.kernel.org Cc: Chris Lalancette Subject: [PATCH 05/12] Make the IOAPIC lock a spinlock. Date: Tue, 1 Dec 2009 15:36:34 +0100 Message-Id: <1259678201-11203-6-git-send-email-clalance@redhat.com> In-Reply-To: <1259678201-11203-1-git-send-email-clalance@redhat.com> References: <1259678201-11203-1-git-send-email-clalance@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index fd52949..3d68826 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c @@ -192,8 +192,9 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) u32 mask = 1 << irq; union kvm_ioapic_redirect_entry entry; int ret = 1; + unsigned long flags; - mutex_lock(&ioapic->lock); + spin_lock_irqsave(&ioapic->lock, flags); if (irq >= 0 && irq < IOAPIC_NUM_PINS) { entry = ioapic->redirtbl[irq]; level ^= entry.fields.polarity; @@ -210,7 +211,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) } trace_kvm_ioapic_set_irq(entry.bits, irq, ret == 0); } - mutex_unlock(&ioapic->lock); + spin_unlock_irqrestore(&ioapic->lock, flags); return ret; } @@ -234,9 +235,9 @@ static void __kvm_ioapic_update_eoi(struct kvm_ioapic *ioapic, int vector, * is dropped it will be put into irr and will be delivered * after ack notifier returns. */ - mutex_unlock(&ioapic->lock); + spin_unlock(&ioapic->lock); kvm_notify_acked_irq(ioapic->kvm, KVM_IRQCHIP_IOAPIC, i); - mutex_lock(&ioapic->lock); + spin_lock(&ioapic->lock); if (trigger_mode != IOAPIC_LEVEL_TRIG) continue; @@ -251,10 +252,11 @@ static void __kvm_ioapic_update_eoi(struct kvm_ioapic *ioapic, int vector, void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode) { struct kvm_ioapic *ioapic = kvm->arch.vioapic; + unsigned long flags; - mutex_lock(&ioapic->lock); + spin_lock_irqsave(&ioapic->lock, flags); __kvm_ioapic_update_eoi(ioapic, vector, trigger_mode); - mutex_unlock(&ioapic->lock); + spin_unlock_irqrestore(&ioapic->lock, flags); } static inline struct kvm_ioapic *to_ioapic(struct kvm_io_device *dev) @@ -273,6 +275,8 @@ static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, { struct kvm_ioapic *ioapic = to_ioapic(this); u32 result; + unsigned long flags; + if (!ioapic_in_range(ioapic, addr)) return -EOPNOTSUPP; @@ -280,7 +284,7 @@ static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, ASSERT(!(addr & 0xf)); /* check alignment */ addr &= 0xff; - mutex_lock(&ioapic->lock); + spin_lock_irqsave(&ioapic->lock, flags); switch (addr) { case IOAPIC_REG_SELECT: result = ioapic->ioregsel; @@ -294,7 +298,7 @@ static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, result = 0; break; } - mutex_unlock(&ioapic->lock); + spin_unlock_irqrestore(&ioapic->lock, flags); switch (len) { case 8: @@ -316,6 +320,8 @@ static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, { struct kvm_ioapic *ioapic = to_ioapic(this); u32 data; + unsigned long flags; + if (!ioapic_in_range(ioapic, addr)) return -EOPNOTSUPP; @@ -331,7 +337,7 @@ static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, } addr &= 0xff; - mutex_lock(&ioapic->lock); + spin_lock_irqsave(&ioapic->lock, flags); switch (addr) { case IOAPIC_REG_SELECT: ioapic->ioregsel = data; @@ -349,7 +355,7 @@ static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, default: break; } - mutex_unlock(&ioapic->lock); + spin_unlock_irqrestore(&ioapic->lock, flags); return 0; } @@ -378,7 +384,7 @@ int kvm_ioapic_init(struct kvm *kvm) ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL); if (!ioapic) return -ENOMEM; - mutex_init(&ioapic->lock); + spin_lock_init(&ioapic->lock); kvm->arch.vioapic = ioapic; kvm_ioapic_reset(ioapic); kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops); @@ -393,23 +399,27 @@ int kvm_ioapic_init(struct kvm *kvm) int kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state) { struct kvm_ioapic *ioapic = ioapic_irqchip(kvm); + unsigned long flags; + if (!ioapic) return -EINVAL; - mutex_lock(&ioapic->lock); + spin_lock_irqsave(&ioapic->lock, flags); memcpy(state, ioapic, sizeof(struct kvm_ioapic_state)); - mutex_unlock(&ioapic->lock); + spin_unlock_irqrestore(&ioapic->lock, flags); return 0; } int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state) { struct kvm_ioapic *ioapic = ioapic_irqchip(kvm); + unsigned long flags; + if (!ioapic) return -EINVAL; - mutex_lock(&ioapic->lock); + spin_lock_irqsave(&ioapic->lock, flags); memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); - mutex_unlock(&ioapic->lock); + spin_unlock_irqrestore(&ioapic->lock, flags); return 0; } diff --git a/virt/kvm/ioapic.h b/virt/kvm/ioapic.h index 419c43b..5b4f756 100644 --- a/virt/kvm/ioapic.h +++ b/virt/kvm/ioapic.h @@ -45,7 +45,7 @@ struct kvm_ioapic { struct kvm_io_device dev; struct kvm *kvm; void (*ack_notifier)(void *opaque, int irq); - struct mutex lock; + spinlock_t lock; }; #ifdef DEBUG