Skip to contentSkip to conversation

KVM: i8259: initialize IMR to 0xff on reset

PATCH In review Avi Kivity 2 participants 4 messages Aug 30, 2010

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 KVM: i8259: initialize IMR to 0xff on reset

Otherwise, a wily interrupt can slip through while the guest isn't prepared for it (and while the irq base is zero).

---
 arch/x86/kvm/i8259.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/i8259.c +1 -1
index 8d10c06..5de9ee0 100644
@@ -275,7 +275,7 @@ void kvm_pic_reset(struct kvm_kpic_state *s)
 
 	s->last_irr = 0;
 	s->irr = 0;
-	s->imr = 0;
+	s->imr = 0xff;
 	s->isr = 0;
 	s->isr_ack = 0xff;
 	s->priority_add = 0;
Signature · 1 line
1.7.1
author
#1 lore raw

arch/x86/kvm/i8259.c void kvm_pic_reset(struct kvm_kpic_state *s) · line 281

Quoted 11 lines · Avi Kivity

Otherwise, a wily interrupt can slip through while the guest isn't prepared for it (and while the irq base is zero).

  	s->last_irr = 0;
  	s->irr = 0;
arch/x86/kvm/i8259.c +1 -1
-	s->imr = 0;
+	s->imr = 0xff;
  	s->isr = 0;
  	s->isr_ack = 0xff;
  	s->priority_add = 0;

For some reason, this bug only shows on the non-atomic-injection branch (specifically, the KVM_REQ_EVENT part).

Signature · 1 line
error compiling committee.c: too many arguments to function
maintainer
#2 lore raw
In reply to Avi Kivity
Quoted 13 lines · Avi Kivity

Otherwise, a wily interrupt can slip through while the guest isn't prepared for it (and while the irq base is zero).

---
  arch/x86/kvm/i8259.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/i8259.c +0 -0
index 8d10c06..5de9ee0 100644

arch/x86/kvm/i8259.c void kvm_pic_reset(struct kvm_kpic_state *s) · line 281

Quoted 8 lines
arch/x86/kvm/i8259.c +1 -1
@@ -275,7 +275,7 @@ void kvm_pic_reset(struct kvm_kpic_state *s)
 
  	s->last_irr = 0;
  	s->irr = 0;
-	s->imr = 0;
+	s->imr = 0xff;
  	s->isr = 0;
  	s->isr_ack = 0xff;
  	s->priority_add = 0;

Sounds sane, but the datasheet says explicitly that upon reset "The Interrupt Mask Register is cleared"... (FWIW, I checked because it looked like QEMU and Xen also had the same behavior of setting IMR to zero).

Paolo

author
#3 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Avi Kivity

Otherwise, a wily interrupt can slip through while the guest isn't prepared for it (and while the irq base is zero).

---
  arch/x86/kvm/i8259.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/i8259.c +0 -0
index 8d10c06..5de9ee0 100644
@@ -275,7 +275,7 @@ void kvm_pic_reset(struct kvm_kpic_state *s)
 
Quoted 9 lines

arch/x86/kvm/i8259.c void kvm_pic_reset(struct kvm_kpic_state *s) · line 281

Quoted 7 lines
arch/x86/kvm/i8259.c +1 -1
      s->last_irr = 0;
      s->irr = 0;
-    s->imr = 0;
+    s->imr = 0xff;
      s->isr = 0;
      s->isr_ack = 0xff;
      s->priority_add = 0;

Sounds sane, but the datasheet says explicitly that upon reset "The Interrupt Mask Register is cleared"... (FWIW, I checked because it looked like QEMU and Xen also had the same behavior of setting IMR to zero).

Hm, right.

Reading the spec, the correct approach is not to do a full reset on ICW1(D4=1), instead just do what the spec says (which is different from reset). I'll try it out.

Signature · 1 line
error compiling committee.c: too many arguments to function