diff mbox

[06/12] Make the PIC use interrupt safe locking.

Message ID 1259678201-11203-7-git-send-email-clalance@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Lalancette Dec. 1, 2009, 2:36 p.m. UTC
None
diff mbox

Patch

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;
 }