Skip to contentSkip to conversation

KVM: x86: reset RVI upon system reset

PATCH In review Wei Wang 5 participants 15 messages Nov 5, 2014 – Dec 15, 2014

Subsystems (3)
lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH 1/1 KVM: x86: reset RVI upon system reset

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This patch has fixed the problem.

---
 arch/x86/kvm/lapic.c |    3 +++
 arch/x86/kvm/vmx.c   |   12 ++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/lapic.c +3 -0
index 66dd173..6942742 100644
@@ -1712,6 +1712,9 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu,
 	apic->isr_count = kvm_apic_vid_enabled(vcpu->kvm) ?
 				1 : count_vectors(apic->regs + APIC_ISR);
 	apic->highest_isr_cache = -1;
+	if (kvm_x86_ops->hwapic_irr_update)
+		kvm_x86_ops->hwapic_irr_update(vcpu,
+				apic_find_highest_irr(apic));
 	kvm_x86_ops->hwapic_isr_update(vcpu->kvm, apic_find_highest_isr(apic));
 	kvm_make_request(KVM_REQ_EVENT, vcpu);
 	kvm_rtc_eoi_tracking_restore_one(vcpu);
arch/x86/kvm/vmx.c +6 -6
index fe4d2f4..d632548 100644
@@ -7292,19 +7292,19 @@ static void vmx_set_rvi(int vector)
 static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
 {
 	if (max_irr == -1)
+		max_irr = 0;
+
+	if (!is_guest_mode(vcpu)) {
+		vmx_set_rvi(max_irr);
 		return;
+	}
 
 	/*
 	 * If a vmexit is needed, vmx_check_nested_events handles it.
 	 */
-	if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
+	if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr == 0)
 		return;
 
-	if (!is_guest_mode(vcpu)) {
-		vmx_set_rvi(max_irr);
-		return;
-	}
-
 	/*
 	 * Fall back to pre-APICv interrupt injection since L2
 	 * is run without virtual interrupt delivery.
Signature · 1 line
1.7.1
#1 lore raw
Quoted 17 lines · Wei Wang

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This patch has fixed the problem.

---
  arch/x86/kvm/lapic.c |    3 +++
  arch/x86/kvm/vmx.c   |   12 ++++++------
  2 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/lapic.c +0 -0
index 66dd173..6942742 100644

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu, · line 1717

Quoted 6 lines
arch/x86/kvm/lapic.c +3 -0
@@ -1712,6 +1712,9 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu,
  	apic->isr_count = kvm_apic_vid_enabled(vcpu->kvm) ?
  				1 : count_vectors(apic->regs + APIC_ISR);
  	apic->highest_isr_cache = -1;
+	if (kvm_x86_ops->hwapic_irr_update)
+		kvm_x86_ops->hwapic_irr_update(vcpu,
+				apic_find_highest_irr(apic));

Could we pass 0 directly? Because looks we just need to clear RVI.

kvm_x86_ops->hwapic_irr_update(vcpu, 0);

I think this already makes sense based on your description.

Thanks
Tiejun

Quoted 34 lines
arch/x86/kvm/lapic.c +0 -0
  	kvm_x86_ops->hwapic_isr_update(vcpu->kvm, apic_find_highest_isr(apic));
  	kvm_make_request(KVM_REQ_EVENT, vcpu);
  	kvm_rtc_eoi_tracking_restore_one(vcpu);
arch/x86/kvm/vmx.c +6 -6
index fe4d2f4..d632548 100644
@@ -7292,19 +7292,19 @@ static void vmx_set_rvi(int vector)
  static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
  {
  	if (max_irr == -1)
+		max_irr = 0;
+
+	if (!is_guest_mode(vcpu)) {
+		vmx_set_rvi(max_irr);
  		return;
+	}
 
  	/*
  	 * If a vmexit is needed, vmx_check_nested_events handles it.
  	 */
-	if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
+	if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr == 0)
  		return;
 
-	if (!is_guest_mode(vcpu)) {
-		vmx_set_rvi(max_irr);
-		return;
-	}
-
  	/*
  	 * Fall back to pre-APICv interrupt injection since L2
  	 * is run without virtual interrupt delivery.
#2 lore raw
Quoted 29 lines · Tiejun Chen
Quoted 3 lines

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This

patch has fixed the problem.

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct

Quoted 15 lines

<[email protected]>

---
  arch/x86/kvm/lapic.c |    3 +++
  arch/x86/kvm/vmx.c   |   12 ++++++------
  2 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/lapic.c index renamed from arch/x86/kvm/lapic.c +0 -0

66dd173..6942742 100644

arch/x86/kvm/lapic.c +0 -0
@@ -1712,6 +1712,9 @@ void kvm_apic_post_state_restore(struct

kvm_vcpu *vcpu,

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu, · line 1717

Quoted 6 lines
arch/x86/kvm/lapic.c +3 -0
  	apic->isr_count = kvm_apic_vid_enabled(vcpu->kvm) ?
  				1 : count_vectors(apic->regs + APIC_ISR);
  	apic->highest_isr_cache = -1;
+	if (kvm_x86_ops->hwapic_irr_update)
+		kvm_x86_ops->hwapic_irr_update(vcpu,
+				apic_find_highest_irr(apic));

Could we pass 0 directly? Because looks we just need to clear RVI.

Quoted 6 lines

kvm_x86_ops->hwapic_irr_update(vcpu, 0);

I think this already makes sense based on your description.

Thanks
Tiejun

No. This is a restore function, and we cannot assume that the callers always need to reset to the initial state.

Wei

Quoted 38 lines

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct · line 1718

Quoted 2 lines
arch/x86/kvm/lapic.c +0 -0
  	kvm_x86_ops->hwapic_isr_update(vcpu->kvm,

apic_find_highest_isr(apic));

Quoted 12 lines
arch/x86/kvm/lapic.c +0 -0
  	kvm_make_request(KVM_REQ_EVENT, vcpu);
  	kvm_rtc_eoi_tracking_restore_one(vcpu);
arch/x86/kvm/vmx.c index renamed from arch/x86/kvm/vmx.c +0 -0

fe4d2f4..d632548 100644

arch/x86/kvm/vmx.c +2 -0
@@ -7292,19 +7292,19 @@ static void vmx_set_rvi(int vector)
  static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
  {
  	if (max_irr == -1)
+		max_irr = 0;
+

arch/x86/kvm/vmx.c static void vmx_set_rvi(int vector) · line 7305

Quoted 10 lines
arch/x86/kvm/vmx.c +4 -1
+	if (!is_guest_mode(vcpu)) {
+		vmx_set_rvi(max_irr);
  		return;
+	}
 
  	/*
  	 * If a vmexit is needed, vmx_check_nested_events handles it.
  	 */
-	if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
+	if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr

==

Quoted 12 lines
arch/x86/kvm/vmx.c +1 -5
+0)
  		return;
 
-	if (!is_guest_mode(vcpu)) {
-		vmx_set_rvi(max_irr);
-		return;
-	}
-
  	/*
  	 * Fall back to pre-APICv interrupt injection since L2
  	 * is run without virtual interrupt delivery.
#3 lore raw
Quoted 30 lines · Wei W
Quoted 29 lines · Tiejun Chen
Quoted 3 lines

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This

patch has fixed the problem.

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct

Quoted 15 lines

<[email protected]>

---
   arch/x86/kvm/lapic.c |    3 +++
   arch/x86/kvm/vmx.c   |   12 ++++++------
   2 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/lapic.c index renamed from arch/x86/kvm/lapic.c +0 -0

66dd173..6942742 100644

arch/x86/kvm/lapic.c +0 -0
@@ -1712,6 +1712,9 @@ void kvm_apic_post_state_restore(struct

kvm_vcpu *vcpu,

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct · line 1717

Quoted 6 lines
arch/x86/kvm/lapic.c +3 -0
   	apic->isr_count = kvm_apic_vid_enabled(vcpu->kvm) ?
   				1 : count_vectors(apic->regs + APIC_ISR);
   	apic->highest_isr_cache = -1;
+	if (kvm_x86_ops->hwapic_irr_update)
+		kvm_x86_ops->hwapic_irr_update(vcpu,
+				apic_find_highest_irr(apic));

Could we pass 0 directly? Because looks we just need to clear RVI.

Quoted 8 lines
Quoted 6 lines

kvm_x86_ops->hwapic_irr_update(vcpu, 0);

I think this already makes sense based on your description.

Thanks
Tiejun

No. This is a restore function, and we cannot assume that the callers always need to reset to the initial state.

Okay. Maybe I'm confused by the following change.

Quoted 29 lines

Wei

Quoted 27 lines

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct · line 1718

Quoted 2 lines
arch/x86/kvm/lapic.c +0 -0
   	kvm_x86_ops->hwapic_isr_update(vcpu->kvm,

apic_find_highest_isr(apic));

Quoted 12 lines
arch/x86/kvm/lapic.c +0 -0
   	kvm_make_request(KVM_REQ_EVENT, vcpu);
   	kvm_rtc_eoi_tracking_restore_one(vcpu);
arch/x86/kvm/vmx.c index renamed from arch/x86/kvm/vmx.c +0 -0

fe4d2f4..d632548 100644

arch/x86/kvm/vmx.c +2 -0
@@ -7292,19 +7292,19 @@ static void vmx_set_rvi(int vector)
   static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
   {
   	if (max_irr == -1)
+		max_irr = 0;
+

arch/x86/kvm/vmx.c static void vmx_set_rvi(int vector) · line 7305

Quoted 10 lines
arch/x86/kvm/vmx.c +4 -1
+	if (!is_guest_mode(vcpu)) {
+		vmx_set_rvi(max_irr);
   		return;
+	}
 
   	/*
   	 * If a vmexit is needed, vmx_check_nested_events handles it.
   	 */
-	if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
+	if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr

==

Quoted 1 line
arch/x86/kvm/vmx.c +1 -0
+0)

Its really not readable to modify max_irr as 0 and check that here, and especially when you read the original comment.

So what about this?

arch/x86/kvm/vmx.c +6 -3
index 0cd99d8..bc4558b 100644
@@ -7280,6 +7280,9 @@ static void vmx_set_rvi(int vector)
        u16 status;
        u8 old;
 
+       if (vector == -1)
+               vector = 0;
+
        status = vmcs_read16(GUEST_INTR_STATUS);
        old = (u8)status & 0xff;
        if ((u8)vector != old) {
@@ -7291,9 +7294,6 @@ static void vmx_set_rvi(int vector)
 
 static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
 {
-       if (max_irr == -1)
-               return;
-
        /*
         * If a vmexit is needed, vmx_check_nested_events handles it.
         */
@@ -7305,6 +7305,9 @@ static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
                return;
        }
 
+       if (max_irr == -1)
+               return;
+
        /*
         * Fall back to pre-APICv interrupt injection since L2
         * is run without virtual interrupt delivery.

Thanks
Tiejun

Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
arch/x86/kvm/vmx.c +0 -5
   		return;
 
-	if (!is_guest_mode(vcpu)) {
-		vmx_set_rvi(max_irr);
-		return;
-	}
-
   	/*
   	 * Fall back to pre-APICv interrupt injection since L2
   	 * is run without virtual interrupt delivery.
#4 lore raw
Quoted 70 lines · Tiejun Chen
Quoted 30 lines
Quoted 30 lines
Quoted 4 lines

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This

patch has fixed the problem.

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct

Quoted 15 lines

<[email protected]>

---
   arch/x86/kvm/lapic.c |    3 +++
   arch/x86/kvm/vmx.c   |   12 ++++++------
   2 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/lapic.c index renamed from arch/x86/kvm/lapic.c +0 -0

66dd173..6942742 100644

arch/x86/kvm/lapic.c +0 -0
@@ -1712,6 +1712,9 @@ void kvm_apic_post_state_restore(struct

kvm_vcpu *vcpu,

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct · line 1717

Quoted 6 lines
arch/x86/kvm/lapic.c +3 -0
   	apic->isr_count = kvm_apic_vid_enabled(vcpu->kvm) ?
   				1 : count_vectors(apic->regs + APIC_ISR);
   	apic->highest_isr_cache = -1;
+	if (kvm_x86_ops->hwapic_irr_update)
+		kvm_x86_ops->hwapic_irr_update(vcpu,
+				apic_find_highest_irr(apic));

Could we pass 0 directly? Because looks we just need to clear RVI.

Quoted 8 lines
Quoted 6 lines

kvm_x86_ops->hwapic_irr_update(vcpu, 0);

I think this already makes sense based on your description.

Thanks
Tiejun

No. This is a restore function, and we cannot assume that the callers

always need to reset to the initial state.

Okay. Maybe I'm confused by the following change.

Quoted 28 lines

Wei

Quoted 26 lines

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct · line 1718

Quoted 2 lines
arch/x86/kvm/lapic.c +0 -0
   	kvm_x86_ops->hwapic_isr_update(vcpu->kvm,

apic_find_highest_isr(apic));

Quoted 12 lines
arch/x86/kvm/lapic.c +0 -0
   	kvm_make_request(KVM_REQ_EVENT, vcpu);
   	kvm_rtc_eoi_tracking_restore_one(vcpu);
arch/x86/kvm/vmx.c index renamed from arch/x86/kvm/vmx.c +0 -0

fe4d2f4..d632548 100644

arch/x86/kvm/vmx.c +2 -0
@@ -7292,19 +7292,19 @@ static void vmx_set_rvi(int vector)
   static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
   {
   	if (max_irr == -1)
+		max_irr = 0;
+

arch/x86/kvm/vmx.c static void vmx_set_rvi(int vector) · line 7305

Quoted 10 lines
arch/x86/kvm/vmx.c +4 -1
+	if (!is_guest_mode(vcpu)) {
+		vmx_set_rvi(max_irr);
   		return;
+	}
 
   	/*
   	 * If a vmexit is needed, vmx_check_nested_events handles it.
   	 */
-	if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
+	if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr

==

Quoted 6 lines
Quoted 1 line
Quoted 1 line

arch/x86/kvm/vmx.c static void vmx_set_rvi(int vector) · line 7306

Quoted 1 line
arch/x86/kvm/vmx.c +1 -0
+0)

Its really not readable to modify max_irr as 0 and check that here, and especially when you read the original comment.

So what about this?

I think both are ok.
If we zero max_irr in vmx_set_rvi(), we still need this check:
if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr == -1)

Let's see if Paolo has any comments, then send out a second version.

Wei

Quoted 54 lines
arch/x86/kvm/vmx.c index renamed from arch/x86/kvm/vmx.c +0 -0

0cd99d8..bc4558b 100644

arch/x86/kvm/vmx.c +6 -3
@@ -7280,6 +7280,9 @@ static void vmx_set_rvi(int vector)
         u16 status;
         u8 old;
 
+       if (vector == -1)
+               vector = 0;
+
         status = vmcs_read16(GUEST_INTR_STATUS);
         old = (u8)status & 0xff;
         if ((u8)vector != old) {
@@ -7291,9 +7294,6 @@ static void vmx_set_rvi(int vector)
 
  static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
  {
-       if (max_irr == -1)
-               return;
-
         /*
          * If a vmexit is needed, vmx_check_nested_events handles it.
          */
@@ -7305,6 +7305,9 @@ static void vmx_hwapic_irr_update(struct
 kvm_vcpu *vcpu, int max_irr)
                 return;
         }
 
+       if (max_irr == -1)
+               return;
+
         /*
          * Fall back to pre-APICv interrupt injection since L2

* is run without virtual interrupt delivery.

Thanks
Tiejun

Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
arch/x86/kvm/vmx.c +0 -5
   		return;
 
-	if (!is_guest_mode(vcpu)) {
-		vmx_set_rvi(max_irr);
-		return;
-	}
-
   	/*
   	 * Fall back to pre-APICv interrupt injection since L2
   	 * is run without virtual interrupt delivery.
#5 lore raw
Quoted 76 lines · Wei W
Quoted 75 lines · Tiejun Chen
Quoted 30 lines
Quoted 30 lines
Quoted 4 lines

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This

patch has fixed the problem.

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct

Quoted 15 lines

<[email protected]>

---
    arch/x86/kvm/lapic.c |    3 +++
    arch/x86/kvm/vmx.c   |   12 ++++++------
    2 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/kvm/lapic.c index renamed from arch/x86/kvm/lapic.c +0 -0

66dd173..6942742 100644

arch/x86/kvm/lapic.c +0 -0
@@ -1712,6 +1712,9 @@ void kvm_apic_post_state_restore(struct

kvm_vcpu *vcpu,

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct · line 1717

Quoted 6 lines
arch/x86/kvm/lapic.c +3 -0
    	apic->isr_count = kvm_apic_vid_enabled(vcpu->kvm) ?
    				1 : count_vectors(apic->regs + APIC_ISR);
    	apic->highest_isr_cache = -1;
+	if (kvm_x86_ops->hwapic_irr_update)
+		kvm_x86_ops->hwapic_irr_update(vcpu,
+				apic_find_highest_irr(apic));

Could we pass 0 directly? Because looks we just need to clear RVI.

Quoted 8 lines
Quoted 6 lines

kvm_x86_ops->hwapic_irr_update(vcpu, 0);

I think this already makes sense based on your description.

Thanks
Tiejun

No. This is a restore function, and we cannot assume that the callers

always need to reset to the initial state.

Okay. Maybe I'm confused by the following change.

Quoted 29 lines

Wei

Quoted 27 lines

arch/x86/kvm/lapic.c void kvm_apic_post_state_restore(struct · line 1718

Quoted 2 lines
arch/x86/kvm/lapic.c +0 -0
    	kvm_x86_ops->hwapic_isr_update(vcpu->kvm,

apic_find_highest_isr(apic));

Quoted 12 lines
arch/x86/kvm/lapic.c +0 -0
    	kvm_make_request(KVM_REQ_EVENT, vcpu);
    	kvm_rtc_eoi_tracking_restore_one(vcpu);
arch/x86/kvm/vmx.c index renamed from arch/x86/kvm/vmx.c +0 -0

fe4d2f4..d632548 100644

arch/x86/kvm/vmx.c +2 -0
@@ -7292,19 +7292,19 @@ static void vmx_set_rvi(int vector)
    static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
    {
    	if (max_irr == -1)
+		max_irr = 0;
+

arch/x86/kvm/vmx.c static void vmx_set_rvi(int vector) · line 7305

Quoted 10 lines
arch/x86/kvm/vmx.c +4 -1
+	if (!is_guest_mode(vcpu)) {
+		vmx_set_rvi(max_irr);
    		return;
+	}
 
    	/*
    	 * If a vmexit is needed, vmx_check_nested_events handles it.
    	 */
-	if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
+	if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr

==

Quoted 1 line
arch/x86/kvm/vmx.c +1 -0
+0)

Its really not readable to modify max_irr as 0 and check that here, and especially when you read the original comment.

Quoted 6 lines
Quoted 1 line

So what about this?

I think both are ok.
If we zero max_irr in vmx_set_rvi(), we still need this check:
if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr == -1)

No, I don't think we need to add this.

Quoted 34 lines

Let's see if Paolo has any comments, then send out a second version.

Wei

Quoted 30 lines
arch/x86/kvm/vmx.c index renamed from arch/x86/kvm/vmx.c +0 -0

0cd99d8..bc4558b 100644

arch/x86/kvm/vmx.c +3 -3
@@ -7280,6 +7280,9 @@ static void vmx_set_rvi(int vector)
          u16 status;
          u8 old;
 
+       if (vector == -1)
+               vector = 0;
+
          status = vmcs_read16(GUEST_INTR_STATUS);
          old = (u8)status & 0xff;
          if ((u8)vector != old) {
@@ -7291,9 +7294,6 @@ static void vmx_set_rvi(int vector)
 
   static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
   {
-       if (max_irr == -1)
-               return;
-
          /*
           * If a vmexit is needed, vmx_check_nested_events handles it.
           */
@@ -7305,6 +7305,9 @@ static void vmx_hwapic_irr_update(struct
 kvm_vcpu *vcpu, int max_irr)
                  return;
          }
 
Quoted 3 lines

arch/x86/kvm/vmx.c static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr) · line 7310

Quoted 3 lines
arch/x86/kvm/vmx.c +3 -0
+       if (max_irr == -1)
+               return;
+

Did you see this?

Tiejun

Quoted 23 lines
Quoted 21 lines
arch/x86/kvm/vmx.c +0 -0
          /*
           * Fall back to pre-APICv interrupt injection since L2

* is run without virtual interrupt delivery.

Thanks
Tiejun

Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
arch/x86/kvm/vmx.c +0 -5
    		return;
 
-	if (!is_guest_mode(vcpu)) {
-		vmx_set_rvi(max_irr);
-		return;
-	}
-
    	/*
    	 * Fall back to pre-APICv interrupt injection since L2
    	 * is run without virtual interrupt delivery.
maintainer
#6 lore raw
Quoted 5 lines · Tiejun
Quoted 3 lines

I think both are ok.
If we zero max_irr in vmx_set_rvi(), we still need this check:
if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr == -1)

No, I don't think we need to add this.

You don't, because the code will look like:

        if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
                return;

        if (!is_guest_mode(vcpu)) {
                vmx_set_rvi(max_irr);
                return;
        }

        if (max_irr == -1)
                return;

and thus vmx_set_rvi() is never reached if is_guest_mode(vcpu) && !nested_exit_on_intr(vcpu).

I applied the lapic.c part of Wei's patch, and the vmx.c part of Tiejun's patch.

Paolo

#7 lore raw

Paolo Bonzini wrote on 2014-11-05:

Quoted 22 lines · Tiejun
Quoted 7 lines
Quoted 5 lines

I think both are ok.
If we zero max_irr in vmx_set_rvi(), we still need this check:
if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr ==
-1)

No, I don't think we need to add this.

You don't, because the code will look like:

        if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
                return;
        if (!is_guest_mode(vcpu)) {
                vmx_set_rvi(max_irr);
                return;
        }
        
        if (max_irr == -1)
                return;
Quoted 2 lines

and thus vmx_set_rvi() is never reached if is_guest_mode(vcpu) && !nested_exit_on_intr(vcpu).

I don't think the above code is perfect. Since hwapic_irr_update() is a hot point, it's better to move the first check after the second check. In this case, Wei's patch looks more reasonable.

Quoted 4 lines

I applied the lapic.c part of Wei's patch, and the vmx.c part of Tiejun's patch.

Paolo

Best regards,
Yang

#8 lore raw

Then?

Quoted 32 lines
Quoted 20 lines · Tiejun
Quoted 7 lines
Quoted 5 lines

I think both are ok.
If we zero max_irr in vmx_set_rvi(), we still need this check:
if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr ==
-1)

No, I don't think we need to add this.

You don't, because the code will look like:

        if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
                return;
        if (!is_guest_mode(vcpu)) {
                vmx_set_rvi(max_irr);
                return;
        }
        
        if (max_irr == -1)
                return;
Quoted 2 lines

and thus vmx_set_rvi() is never reached if is_guest_mode(vcpu) && !nested_exit_on_intr(vcpu).

I don't think the above code is perfect. Since hwapic_irr_update() is a hot point, it's better to move the first check after the second check. In this case, Wei's patch looks more reasonable.

Quoted 4 lines

I applied the lapic.c part of Wei's patch, and the vmx.c part of Tiejun's patch.

Paolo

Best regards,

Tested-by Rongrong Liu
#9 lore raw

Zhang Haoyu wrote on 2014-12-11:

Quoted 1 line

Then?

It's already in upstream KVM

commit 4114c27d450bef228be9c7b0c40a888e18a3a636

Author: Wei Wang <[email protected]>
Date:   Wed Nov 5 10:53:43 2014 +0800

KVM: x86: reset RVI upon system reset

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This patch has fixed the problem.

Quoted 22 lines
Quoted 22 lines
Quoted 21 lines · Tiejun
Quoted 7 lines
Quoted 5 lines

I think both are ok.
If we zero max_irr in vmx_set_rvi(), we still need this check:
if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr ==
-1)

No, I don't think we need to add this.

You don't, because the code will look like:

        if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
                return; if (!is_guest_mode(vcpu)) {
                vmx_set_rvi(max_irr); return;
        }
        
        if (max_irr == -1)
                return;

and thus vmx_set_rvi() is never reached if is_guest_mode(vcpu) && !nested_exit_on_intr(vcpu).

Quoted 12 lines
Quoted 2 lines

I don't think the above code is perfect. Since hwapic_irr_update() is a hot point,

it's better to move the first check after the second check. In this case, Wei's patch looks more reasonable.

Quoted 8 lines
Quoted 5 lines

I applied the lapic.c part of Wei's patch, and the vmx.c part of Tiejun's patch.

Paolo

Best regards,

Best regards,
Yang

maintainer
#14 lore raw
In reply to Zhang Haoyu
Quoted 7 lines · Zhang Haoyu
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
        if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
                return;
        if (!is_guest_mode(vcpu)) {
                vmx_set_rvi(max_irr);
                return;
        }
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
        if (max_irr == -1)
                return;

and thus vmx_set_rvi() is never reached if is_guest_mode(vcpu) && !nested_exit_on_intr(vcpu).

I don't think the above code is perfect. Since hwapic_irr_update() is a hot point, it's better to move the first check after the second check. In this case, Wei's patch looks more

The behavior for max_irr == -1 is different for is_guest_mode(vcpu) (write 0 to RVI) and !is_guest_mode(vcpu) (do nothing). So you have to check is_guest_mode first, as in the patch that was applied.

Paolo

#10 lore raw
In reply to Zhang, Yang Z
Quoted 5 lines · Yang Z

Zhang Haoyu wrote on 2014-12-11:

Quoted 1 line

Then?

It's already in upstream KVM

Strange, I didn't find this commit in https://git.kernel.org/cgit/virt/kvm/kvm.git/log/
but found it from the repository downloaded by git clone git://git.kernel.org/pub/scm/virt/kvm/kvm.git

Thanks,
Zhang Haoyu

Quoted 54 lines

commit 4114c27d450bef228be9c7b0c40a888e18a3a636

Author: Wei Wang <[email protected]>
Date:   Wed Nov 5 10:53:43 2014 +0800

KVM: x86: reset RVI upon system reset

A bug was reported as follows: when running Windows 7 32-bit guests on qemu-kvm, sometimes the guests run into blue screen during reboot. The problem was that a guest's RVI was not cleared when it rebooted. This patch has fixed the problem.

Quoted 22 lines
Quoted 22 lines
Quoted 21 lines · Tiejun
Quoted 7 lines
Quoted 5 lines

I think both are ok.
If we zero max_irr in vmx_set_rvi(), we still need this check:
if ((is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) || max_irr ==
-1)

No, I don't think we need to add this.

You don't, because the code will look like:

        if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu))
                return; if (!is_guest_mode(vcpu)) {
                vmx_set_rvi(max_irr); return;
        }
        
        if (max_irr == -1)
                return;

and thus vmx_set_rvi() is never reached if is_guest_mode(vcpu) && !nested_exit_on_intr(vcpu).

Quoted 12 lines
Quoted 2 lines

I don't think the above code is perfect. Since hwapic_irr_update() is a hot point,

it's better to move the first check after the second check. In this case, Wei's patch looks more reasonable.

Quoted 8 lines
Quoted 5 lines

I applied the lapic.c part of Wei's patch, and the vmx.c part of Tiejun's patch.

Paolo

Best regards,

Best regards,
Yang

#12 lore raw
Quoted 12 lines · Paolo Bonzini
Quoted 2 lines · Zhang Haoyu

Strange, I didn't find this commit in https://git.kernel.org/cgit/virt/kvm/kvm.git/log/
but found it from the repository downloaded by git clone git://git.kernel.org/pub/scm/virt/kvm/kvm.git

It's here:

https://git.kernel.org/cgit/virt/kvm/kvm.git/log/?h=next

(on the second page)

Yes, I find it,
but what's the relationship between https://git.kernel.org/cgit/virt/kvm/kvm.git/log/?h=next
and
https://git.kernel.org/cgit/virt/kvm/kvm.git/log/ ?
e.g.,
https://git.kernel.org/cgit/virt/kvm/kvm.git/log/?h=next&ofs=50
https://git.kernel.org/cgit/virt/kvm/kvm.git/log/?ofs=50

Thanks,
Zhang Haoyu

Quoted 1 line

Paolo