Skip to contentSkip to conversation

If interrupt injection is not possible do not scan IRR.

PATCH In review Gleb Natapov 2 participants 5 messages May 18, 2009 – May 19, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 If interrupt injection is not possible do not scan IRR.

---
 arch/x86/kvm/i8259.c |    5 +++++
 arch/x86/kvm/irq.c   |    1 -
 arch/x86/kvm/x86.c   |    9 +++++----
 3 files changed, 10 insertions(+), 5 deletions(-)
arch/x86/kvm/i8259.c +5 -0
index 1ccb50c..d32ceac 100644
@@ -218,6 +218,11 @@ int kvm_pic_read_irq(struct kvm *kvm)
 	struct kvm_pic *s = pic_irqchip(kvm);
 
 	pic_lock(s);
+	if (!s->output) {
+		pic_unlock(s);
+		return -1;
+	}
+	s->output = 0;
 	irq = pic_get_irq(&s->pics[0]);
 	if (irq >= 0) {
 		pic_intack(&s->pics[0], irq);
arch/x86/kvm/irq.c +0 -1
index 96dfbb6..e93405a 100644
@@ -78,7 +78,6 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
 	if (vector == -1) {
 		if (kvm_apic_accept_pic_intr(v)) {
 			s = pic_irqchip(v->kvm);
-			s->output = 0;		/* PIC */
 			vector = kvm_pic_read_irq(v->kvm);
 		}
 	}
arch/x86/kvm/x86.c +5 -4
index 44e87a5..a08d96f 100644
@@ -3174,10 +3174,11 @@ static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 			vcpu->arch.nmi_injected = true;
 			kvm_x86_ops->set_nmi(vcpu);
 		}
-	} else if (kvm_cpu_has_interrupt(vcpu)) {
-		if (kvm_x86_ops->interrupt_allowed(vcpu)) {
-			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
-					    false);
+	} else if (kvm_x86_ops->interrupt_allowed(vcpu)) {
+		int vec = kvm_cpu_get_interrupt(vcpu);
+		if (vec != -1) {
+			printk(KERN_ERR"inject %d rip=%x\n", vec, kvm_rip_read(vcpu));
+			kvm_queue_interrupt(vcpu, vec, false);
 			kvm_x86_ops->set_irq(vcpu);
 		}
 	}
Signature · 1 line
1.6.2.1
#1 lore raw
Quoted 6 lines · Gleb Natapov
arch/x86/kvm/x86.c +0 -2
@@ -3174,10 +3174,11 @@ static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 			vcpu->arch.nmi_injected = true;
 			kvm_x86_ops->set_nmi(vcpu);
 		}
-	} else if (kvm_cpu_has_interrupt(vcpu)) {
-		if (kvm_x86_ops->interrupt_allowed(vcpu)) {

arch/x86/kvm/x86.c static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) · line 3184

Quoted 10 lines
arch/x86/kvm/x86.c +5 -2
-			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
-					    false);
+	} else if (kvm_x86_ops->interrupt_allowed(vcpu)) {
+		int vec = kvm_cpu_get_interrupt(vcpu);
+		if (vec != -1) {
+			printk(KERN_ERR"inject %d rip=%x\n", vec, kvm_rip_read(vcpu));
+			kvm_queue_interrupt(vcpu, vec, false);
 			kvm_x86_ops->set_irq(vcpu);
 		} 	}
 

Not sure if this is a win. Usually interrupts are allowed, so we'll have to do both calculations. On vmx ->interrupt_allowed() reads the vmcs, which is slow.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Gleb Natapov
arch/x86/kvm/x86.c +4 -4
@@ -3174,10 +3174,11 @@ static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 			vcpu->arch.nmi_injected = true;
 			kvm_x86_ops->set_nmi(vcpu);
 		}
-	} else if (kvm_cpu_has_interrupt(vcpu)) {
-		if (kvm_x86_ops->interrupt_allowed(vcpu)) {
-			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
-					    false);
+	} else if (kvm_x86_ops->interrupt_allowed(vcpu)) {
+		int vec = kvm_cpu_get_interrupt(vcpu);
+		if (vec != -1) {
+			printk(KERN_ERR"inject %d rip=%x\n", vec, kvm_rip_read(vcpu));
Quoted 9 lines

arch/x86/kvm/x86.c static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)

Quoted 4 lines
arch/x86/kvm/x86.c +1 -0
+			kvm_queue_interrupt(vcpu, vec, false);
 			kvm_x86_ops->set_irq(vcpu);
 		} 	}
 

Not sure if this is a win. Usually interrupts are allowed, so we'll have to do both calculations. On vmx ->interrupt_allowed() reads the vmcs, which is slow.

Depend on how slow vmcs read is. In case when interrupt is available we also scan IRR twice with current code: first time in kvm_cpu_has_interrupt() and another in kvm_cpu_get_interrupt().

If we want to optimize vmcs access, and for nested virtualization we may want to do it, we can read common ones on exit and use in memory copy.

--
Gleb.

#3 lore raw
In reply to Gleb Natapov

Forget to remove debug output before submitting. Resending.

arch/x86/kvm/i8259.c +5 -0
index 1ccb50c..d32ceac 100644
@@ -218,6 +218,11 @@ int kvm_pic_read_irq(struct kvm *kvm)
 	struct kvm_pic *s = pic_irqchip(kvm);
 
 	pic_lock(s);
+	if (!s->output) {
+		pic_unlock(s);
+		return -1;
+	}
+	s->output = 0;
 	irq = pic_get_irq(&s->pics[0]);
 	if (irq >= 0) {
 		pic_intack(&s->pics[0], irq);
arch/x86/kvm/irq.c +0 -1
index 96dfbb6..e93405a 100644
@@ -78,7 +78,6 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
 	if (vector == -1) {
 		if (kvm_apic_accept_pic_intr(v)) {
 			s = pic_irqchip(v->kvm);
-			s->output = 0;		/* PIC */
 			vector = kvm_pic_read_irq(v->kvm);
 		}
 	}
arch/x86/kvm/x86.c +4 -4
index 44e87a5..854e8c9 100644
@@ -3174,10 +3174,10 @@ static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 			vcpu->arch.nmi_injected = true;
 			kvm_x86_ops->set_nmi(vcpu);
 		}
-	} else if (kvm_cpu_has_interrupt(vcpu)) {
-		if (kvm_x86_ops->interrupt_allowed(vcpu)) {
-			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
-					    false);
+	} else if (kvm_x86_ops->interrupt_allowed(vcpu)) {
+		int vec = kvm_cpu_get_interrupt(vcpu);
+		if (vec != -1) {
+			kvm_queue_interrupt(vcpu, vec, false);
 			kvm_x86_ops->set_irq(vcpu);
 		}
 	}

--
Gleb.

#4 lore raw
Quoted 25 lines · Gleb Natapov

Forget to remove debug output before submitting. Resending.

arch/x86/kvm/i8259.c +5 -0
index 1ccb50c..d32ceac 100644
@@ -218,6 +218,11 @@ int kvm_pic_read_irq(struct kvm *kvm)
 	struct kvm_pic *s = pic_irqchip(kvm);
 
 	pic_lock(s);
+	if (!s->output) {
+		pic_unlock(s);
+		return -1;
+	}
+	s->output = 0;
 	irq = pic_get_irq(&s->pics[0]);
 	if (irq >= 0) {
 		pic_intack(&s->pics[0], irq);
arch/x86/kvm/irq.c +0 -0
index 96dfbb6..e93405a 100644

arch/x86/kvm/irq.c int kvm_cpu_get_interrupt(struct kvm_vcpu *v) · line 83

Quoted 7 lines
arch/x86/kvm/irq.c +0 -1
@@ -78,7 +78,6 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
 	if (vector == -1) {
 		if (kvm_apic_accept_pic_intr(v)) {
 			s = pic_irqchip(v->kvm);
-			s->output = 0;		/* PIC */
 			vector = kvm_pic_read_irq(v->kvm);
 		}
 	}

Please split into a different patch. Even though it is a lot simpler, it contains non-local changes and is therefore relatively dangerous.

Quoted 10 lines
arch/x86/kvm/x86.c +0 -1
index 44e87a5..854e8c9 100644
@@ -3174,10 +3174,10 @@ static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 			vcpu->arch.nmi_injected = true;
 			kvm_x86_ops->set_nmi(vcpu);
 		}
-	} else if (kvm_cpu_has_interrupt(vcpu)) {

arch/x86/kvm/x86.c static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) · line 3183

Quoted 10 lines
arch/x86/kvm/x86.c +4 -3
-		if (kvm_x86_ops->interrupt_allowed(vcpu)) {
-			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
-					    false);
+	} else if (kvm_x86_ops->interrupt_allowed(vcpu)) {
+		int vec = kvm_cpu_get_interrupt(vcpu);
+		if (vec != -1) {
+			kvm_queue_interrupt(vcpu, vec, false);
 			kvm_x86_ops->set_irq(vcpu);
 		}
 	}

Again, I don't think this is a win. Usually ->interrupts_allowed() == true so we'll execute the rest anyway.

Perhaps we could move the call to has_interrupt into get_interrupt.

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