From patchwork Tue Dec 1 14:36:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Lalancette X-Patchwork-Id: 63975 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 nB1Ebb3X013545 for ; Tue, 1 Dec 2009 14:37:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753482AbZLAOhH (ORCPT ); Tue, 1 Dec 2009 09:37:07 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752936AbZLAOhG (ORCPT ); Tue, 1 Dec 2009 09:37:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14256 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751940AbZLAOhE (ORCPT ); Tue, 1 Dec 2009 09:37:04 -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 nB1EbAjv004109 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 1 Dec 2009 09:37:10 -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 nB1Eb36P002533; Tue, 1 Dec 2009 09:37:09 -0500 From: Chris Lalancette To: kvm@vger.kernel.org Cc: Chris Lalancette Subject: [PATCH 06/12] Make the PIC use interrupt safe locking. Date: Tue, 1 Dec 2009 15:36:35 +0100 Message-Id: <1259678201-11203-7-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/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index 59a8a68..8285f0d 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c @@ -52,10 +52,12 @@ static void pic_clear_isr(struct kvm_kpic_state *s, int irq) void kvm_pic_clear_isr_ack(struct kvm *kvm) { struct kvm_pic *s = pic_irqchip(kvm); - spin_lock(&s->lock); + unsigned long flags; + + spin_lock_irqsave(&s->lock, flags); s->pics[0].isr_ack = 0xff; s->pics[1].isr_ack = 0xff; - spin_unlock(&s->lock); + spin_unlock_irqrestore(&s->lock, flags); } /* @@ -156,24 +158,27 @@ static void pic_update_irq(struct kvm_pic *s) void kvm_pic_update_irq(struct kvm_pic *s) { - spin_lock(&s->lock); + unsigned long flags; + + spin_lock_irqsave(&s->lock, flags); pic_update_irq(s); - spin_unlock(&s->lock); + spin_unlock_irqrestore(&s->lock, flags); } int kvm_pic_set_irq(void *opaque, int irq, int level) { struct kvm_pic *s = opaque; int ret = -1; + unsigned long flags; - spin_lock(&s->lock); + spin_lock_irqsave(&s->lock, flags); if (irq >= 0 && irq < PIC_NUM_PINS) { ret = pic_set_irq1(&s->pics[irq >> 3], irq & 7, level); pic_update_irq(s); trace_kvm_pic_set_irq(irq >> 3, irq & 7, s->pics[irq >> 3].elcr, s->pics[irq >> 3].imr, ret == 0); } - spin_unlock(&s->lock); + spin_unlock_irqrestore(&s->lock, flags); return ret; } @@ -202,8 +207,9 @@ int kvm_pic_read_irq(struct kvm *kvm) { int irq, irq2, intno; struct kvm_pic *s = pic_irqchip(kvm); + unsigned long flags; - spin_lock(&s->lock); + spin_lock_irqsave(&s->lock, flags); irq = pic_get_irq(&s->pics[0]); if (irq >= 0) { pic_intack(&s->pics[0], irq); @@ -228,7 +234,7 @@ int kvm_pic_read_irq(struct kvm *kvm) intno = s->pics[0].irq_base + irq; } pic_update_irq(s); - spin_unlock(&s->lock); + spin_unlock_irqrestore(&s->lock, flags); return intno; } @@ -434,6 +440,8 @@ static int picdev_write(struct kvm_io_device *this, { struct kvm_pic *s = to_pic(this); unsigned char data = *(unsigned char *)val; + unsigned long flags; + if (!picdev_in_range(addr)) return -EOPNOTSUPP; @@ -442,7 +450,7 @@ static int picdev_write(struct kvm_io_device *this, printk(KERN_ERR "PIC: non byte write\n"); return 0; } - spin_lock(&s->lock); + spin_lock_irqsave(&s->lock, flags); switch (addr) { case 0x20: case 0x21: @@ -455,7 +463,7 @@ static int picdev_write(struct kvm_io_device *this, elcr_ioport_write(&s->pics[addr & 1], addr, data); break; } - spin_unlock(&s->lock); + spin_unlock_irqrestore(&s->lock, flags); return 0; } @@ -464,6 +472,8 @@ static int picdev_read(struct kvm_io_device *this, { struct kvm_pic *s = to_pic(this); unsigned char data = 0; + unsigned long flags; + if (!picdev_in_range(addr)) return -EOPNOTSUPP; @@ -472,7 +482,7 @@ static int picdev_read(struct kvm_io_device *this, printk(KERN_ERR "PIC: non byte read\n"); return 0; } - spin_lock(&s->lock); + spin_lock_irqsave(&s->lock, flags); switch (addr) { case 0x20: case 0x21: @@ -486,7 +496,7 @@ static int picdev_read(struct kvm_io_device *this, break; } *(unsigned char *)val = data; - spin_unlock(&s->lock); + spin_unlock_irqrestore(&s->lock, flags); return 0; }