Skip to contentSkip to conversation

KVM: x86: check ISR and TMR to construct eoi exit bitmap

PATCH In review Wei Wang 5 participants 5 messages Aug 13, 2014 – Aug 18, 2014

Subsystems (3)
lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH v2 1/1 KVM: x86: check ISR and TMR to construct eoi exit bitmap

From: Yang Zhang <[email protected]>

Guest may mask the IOAPIC entry before issue EOI. In such case, EOI will not be intercepted by hypervisor due to the corrensponding bit in eoi exit bitmap is not setting.

The solution is to check ISR + TMR to construct the EOI exit bitmap.

This patch is a better fixing for the issue that commit "0f6c0a740b" tries to solve.

---
 arch/x86/kvm/lapic.c |   17 +++++++++++++++++
 arch/x86/kvm/lapic.h |    2 ++
 arch/x86/kvm/x86.c   |    9 +++++++++
 virt/kvm/ioapic.c    |    7 ++++---
 4 files changed, 32 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +17 -0
index 08e8a89..0ed4bcb 100644
@@ -515,6 +515,23 @@ static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
 	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
 }
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr)
+{
+	u32 i, reg_off, intr_in_service;
+	struct kvm_lapic *apic = vcpu->arch.apic;
+
+	for (i = 0; i < 8; i++) {
+		reg_off = 0x10 * i;
+		intr_in_service = apic_read_reg(apic, APIC_ISR + reg_off) &
+			kvm_apic_get_reg(apic, APIC_TMR + reg_off);
+		if (intr_in_service) {
+			*((u32 *)eoi_exit_bitmap + i) |= intr_in_service;
+			tmr[i] |= intr_in_service;
+		}
+	}
+}
+
 void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
arch/x86/kvm/lapic.h +2 -0
index 6a11845..4ee3d70 100644
@@ -53,6 +53,8 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
 u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
 void kvm_apic_set_version(struct kvm_vcpu *vcpu);
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr);
 void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr);
 void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir);
 int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
arch/x86/kvm/x86.c +9 -0
index 204422d..755b556 100644
@@ -6005,6 +6005,15 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
 	memset(tmr, 0, 32);
 
 	kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr);
+	/*
+	 * Guest may mask the IOAPIC entry before issue EOI. In such case,
+	 * EOI will not be intercepted by hypervisor due to the corrensponding
+	 * bit in eoi exit bitmap is not setting.
+	 *
+	 * The solution is to check ISR + TMR to construct the EOI exit bitmap.
+	 */
+	kvm_apic_zap_eoi_exitmap(vcpu, eoi_exit_bitmap, tmr);
+
 	kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
 	kvm_apic_update_tmr(vcpu, tmr);
 }
virt/kvm/ioapic.c +4 -3
index e8ce34c..2458a1d 100644
@@ -254,9 +254,10 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
 	spin_lock(&ioapic->lock);
 	for (index = 0; index < IOAPIC_NUM_PINS; index++) {
 		e = &ioapic->redirtbl[index];
-		if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
-		    kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) ||
-		    index == RTC_GSI) {
+		if (!e->fields.mask &&
+			(e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
+			 kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC,
+				 index) || index == RTC_GSI)) {
 			if (kvm_apic_match_dest(vcpu, NULL, 0,
 				e->fields.dest_id, e->fields.dest_mode)) {
 				__set_bit(e->fields.vector,
Signature · 1 line
1.7.1
#1 lore raw

Hi Wei,

Quoted 11 lines · Wei Wang

From: Yang Zhang <[email protected]>

Guest may mask the IOAPIC entry before issue EOI. In such case, EOI will not be intercepted by hypervisor due to the corrensponding bit in eoi exit bitmap is not setting.

The solution is to check ISR + TMR to construct the EOI exit bitmap.

This patch is a better fixing for the issue that commit "0f6c0a740b" tries to solve.

I think you miss the changlog.

Regards,
Wanpeng Li

Quoted 96 lines

---

arch/x86/kvm/lapic.c |   17 +++++++++++++++++
arch/x86/kvm/lapic.h |    2 ++
arch/x86/kvm/x86.c   |    9 +++++++++
virt/kvm/ioapic.c    |    7 ++++---
4 files changed, 32 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +17 -0
index 08e8a89..0ed4bcb 100644
@@ -515,6 +515,23 @@ static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
 	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
 }
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr)
+{
+	u32 i, reg_off, intr_in_service;
+	struct kvm_lapic *apic = vcpu->arch.apic;
+
+	for (i = 0; i < 8; i++) {
+		reg_off = 0x10 * i;
+		intr_in_service = apic_read_reg(apic, APIC_ISR + reg_off) &
+			kvm_apic_get_reg(apic, APIC_TMR + reg_off);
+		if (intr_in_service) {
+			*((u32 *)eoi_exit_bitmap + i) |= intr_in_service;
+			tmr[i] |= intr_in_service;
+		}
+	}
+}
+
 void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
arch/x86/kvm/lapic.h +2 -0
index 6a11845..4ee3d70 100644
@@ -53,6 +53,8 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
 u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
 void kvm_apic_set_version(struct kvm_vcpu *vcpu);
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr);
 void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr);
 void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir);
 int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
arch/x86/kvm/x86.c +9 -0
index 204422d..755b556 100644
@@ -6005,6 +6005,15 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
 	memset(tmr, 0, 32);
 
 	kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr);
+	/*
+	 * Guest may mask the IOAPIC entry before issue EOI. In such case,
+	 * EOI will not be intercepted by hypervisor due to the corrensponding
+	 * bit in eoi exit bitmap is not setting.
+	 *
+	 * The solution is to check ISR + TMR to construct the EOI exit bitmap.
+	 */
+	kvm_apic_zap_eoi_exitmap(vcpu, eoi_exit_bitmap, tmr);
+
 	kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
 	kvm_apic_update_tmr(vcpu, tmr);
 }
virt/kvm/ioapic.c +4 -3
index e8ce34c..2458a1d 100644
@@ -254,9 +254,10 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
 	spin_lock(&ioapic->lock);
 	for (index = 0; index < IOAPIC_NUM_PINS; index++) {
 		e = &ioapic->redirtbl[index];
-		if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
-		    kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) ||
-		    index == RTC_GSI) {
+		if (!e->fields.mask &&
+			(e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
+			 kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC,
+				 index) || index == RTC_GSI)) {
 			if (kvm_apic_match_dest(vcpu, NULL, 0,
 				e->fields.dest_id, e->fields.dest_mode)) {
 				__set_bit(e->fields.vector,
Signature · 6 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to Wei Wang
Quoted 4 lines · Wei Wang

From: Yang Zhang <[email protected]>

Guest may mask the IOAPIC entry before issue EOI. In such case, EOI will not be intercepted by hypervisor due to the corrensponding

s/corrensponding/corresponding

Quoted 63 lines

bit in eoi exit bitmap is not setting.

The solution is to check ISR + TMR to construct the EOI exit bitmap.

This patch is a better fixing for the issue that commit "0f6c0a740b" tries to solve.

---
  arch/x86/kvm/lapic.c |   17 +++++++++++++++++
  arch/x86/kvm/lapic.h |    2 ++
  arch/x86/kvm/x86.c   |    9 +++++++++
  virt/kvm/ioapic.c    |    7 ++++---
  4 files changed, 32 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +17 -0
index 08e8a89..0ed4bcb 100644
@@ -515,6 +515,23 @@ static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
  	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
  }
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr)
+{
+	u32 i, reg_off, intr_in_service;
+	struct kvm_lapic *apic = vcpu->arch.apic;
+
+	for (i = 0; i < 8; i++) {
+		reg_off = 0x10 * i;
+		intr_in_service = apic_read_reg(apic, APIC_ISR + reg_off) &
+			kvm_apic_get_reg(apic, APIC_TMR + reg_off);
+		if (intr_in_service) {
+			*((u32 *)eoi_exit_bitmap + i) |= intr_in_service;
+			tmr[i] |= intr_in_service;
+		}
+	}
+}
+
  void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr)
  {
  	struct kvm_lapic *apic = vcpu->arch.apic;
arch/x86/kvm/lapic.h +2 -0
index 6a11845..4ee3d70 100644
@@ -53,6 +53,8 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
  u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
  void kvm_apic_set_version(struct kvm_vcpu *vcpu);
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr);
  void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr);
  void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir);
  int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
arch/x86/kvm/x86.c +0 -0
index 204422d..755b556 100644

arch/x86/kvm/x86.c static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu) · line 6010

Quoted 6 lines
arch/x86/kvm/x86.c +3 -0
@@ -6005,6 +6005,15 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
  	memset(tmr, 0, 32);
 
  	kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr);
+	/*
+	 * Guest may mask the IOAPIC entry before issue EOI. In such case,
+	 * EOI will not be intercepted by hypervisor due to the corrensponding

s/corrensponding/corresponding

Quoted 28 lines
arch/x86/kvm/x86.c +6 -0
+	 * bit in eoi exit bitmap is not setting.
+	 *
+	 * The solution is to check ISR + TMR to construct the EOI exit bitmap.
+	 */
+	kvm_apic_zap_eoi_exitmap(vcpu, eoi_exit_bitmap, tmr);
+
  	kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
  	kvm_apic_update_tmr(vcpu, tmr);
  }
virt/kvm/ioapic.c +4 -3
index e8ce34c..2458a1d 100644
@@ -254,9 +254,10 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
  	spin_lock(&ioapic->lock);
  	for (index = 0; index < IOAPIC_NUM_PINS; index++) {
  		e = &ioapic->redirtbl[index];
-		if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
-		    kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) ||
-		    index == RTC_GSI) {
+		if (!e->fields.mask &&
+			(e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
+			 kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC,
+				 index) || index == RTC_GSI)) {
  			if (kvm_apic_match_dest(vcpu, NULL, 0,
  				e->fields.dest_id, e->fields.dest_mode)) {
  				__set_bit(e->fields.vector,
#3 lore raw

Chen, Tiejun wrote on 2014-08-15:

Quoted 15 lines · Wei Wang
Quoted 4 lines

From: Yang Zhang <[email protected]>

Guest may mask the IOAPIC entry before issue EOI. In such case, EOI will not be intercepted by hypervisor due to the corrensponding

s/corrensponding/corresponding

Quoted 7 lines

bit in eoi exit bitmap is not setting.

The solution is to check ISR + TMR to construct the EOI exit bitmap.

This patch is a better fixing for the issue that commit "0f6c0a740b" tries to solve.

Hi Paolo and Alex,

Any other comments with this version?

Quoted 69 lines

arch/x86/kvm/lapic.c static void pv_eoi_clr_pending(struct kvm_vcpu

Quoted 14 lines
---
  arch/x86/kvm/lapic.c |   17 +++++++++++++++++
  arch/x86/kvm/lapic.h |    2 ++
  arch/x86/kvm/x86.c   |    9 +++++++++
  virt/kvm/ioapic.c    |    7 ++++---
  4 files changed, 32 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +0 -0
index 08e8a89..0ed4bcb 100644
@@ -515,6 +515,23 @@ static void pv_eoi_clr_pending(struct kvm_vcpu

*vcpu)

arch/x86/kvm/lapic.h void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64

Quoted 16 lines
arch/x86/kvm/lapic.c +3 -0
  	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention); }
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64
 *eoi_exit_bitmap, +		u32 *tmr) +{ +	u32 i, reg_off, intr_in_service;
+	struct kvm_lapic *apic = vcpu->arch.apic; + +	for (i = 0; i < 8; i++)
 { +		reg_off = 0x10 * i; +		intr_in_service = apic_read_reg(apic,
 APIC_ISR + reg_off) & +			kvm_apic_get_reg(apic, APIC_TMR + reg_off);
+		if (intr_in_service) { +			*((u32 *)eoi_exit_bitmap + i) |=

intr_in_service; + tmr[i] |= intr_in_service; + } + } +} +
void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr) {
struct kvm_lapic *apic = vcpu->arch.apic;

arch/x86/kvm/lapic.h +0 -0
index 6a11845..4ee3d70 100644
@@ -53,6 +53,8 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64

value);

arch/x86/kvm/x86.c static void vcpu_scan_ioapic(struct kvm_vcpu

Quoted 12 lines
arch/x86/kvm/lapic.h +1 -0
  u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
  void kvm_apic_set_version(struct kvm_vcpu *vcpu);
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64
 *eoi_exit_bitmap, +		u32 *tmr);
  void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr);
  void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir);
  int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
arch/x86/kvm/x86.c +0 -0
index 204422d..755b556 100644
@@ -6005,6 +6005,15 @@ static void vcpu_scan_ioapic(struct kvm_vcpu

*vcpu)

arch/x86/kvm/x86.c static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu) · line 6010

Quoted 6 lines
arch/x86/kvm/x86.c +3 -0
  	memset(tmr, 0, 32);
 
  	kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr);
+	/*
+	 * Guest may mask the IOAPIC entry before issue EOI. In such case,
+	 * EOI will not be intercepted by hypervisor due to the corrensponding

s/corrensponding/corresponding

virt/kvm/ioapic.c void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu,

Quoted 14 lines
arch/x86/kvm/x86.c +6 -0
+	 * bit in eoi exit bitmap is not setting.
+	 *
+	 * The solution is to check ISR + TMR to construct the EOI exit bitmap.
+	 */
+	kvm_apic_zap_eoi_exitmap(vcpu, eoi_exit_bitmap, tmr);
+
  	kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
  	kvm_apic_update_tmr(vcpu, tmr);
  }
virt/kvm/ioapic.c +0 -0
index e8ce34c..2458a1d 100644
@@ -254,9 +254,10 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu,

u64 *eoi_exit_bitmap,

Quoted 11 lines
Quoted 11 lines
virt/kvm/ioapic.c +0 -1
  	spin_lock(&ioapic->lock);
  	for (index = 0; index < IOAPIC_NUM_PINS; index++) {
  		e = &ioapic->redirtbl[index];
-		if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG || -		   

kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) || -
index == RTC_GSI) { + if (!e->fields.mask && + (e->fields.trig_mode
== IOAPIC_LEVEL_TRIG || + kvm_irq_has_notifier(ioapic->kvm,
KVM_IRQCHIP_IOAPIC, + index) || index == RTC_GSI)) {
if (kvm_apic_match_dest(vcpu, NULL, 0,
e->fields.dest_id, e->fields.dest_mode)) { __set_bit(e->fields.vector,

Best regards,
Yang

maintainer
#4 lore raw
In reply to Wei Wang

Il 13/08/2014 21:16, Wei Wang ha scritto:

Quoted 91 lines

From: Yang Zhang <[email protected]>

Guest may mask the IOAPIC entry before issue EOI. In such case, EOI will not be intercepted by hypervisor due to the corrensponding bit in eoi exit bitmap is not setting.

The solution is to check ISR + TMR to construct the EOI exit bitmap.

This patch is a better fixing for the issue that commit "0f6c0a740b" tries to solve.

---
 arch/x86/kvm/lapic.c |   17 +++++++++++++++++
 arch/x86/kvm/lapic.h |    2 ++
 arch/x86/kvm/x86.c   |    9 +++++++++
 virt/kvm/ioapic.c    |    7 ++++---
 4 files changed, 32 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +17 -0
index 08e8a89..0ed4bcb 100644
@@ -515,6 +515,23 @@ static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
 	__clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
 }
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr)
+{
+	u32 i, reg_off, intr_in_service;
+	struct kvm_lapic *apic = vcpu->arch.apic;
+
+	for (i = 0; i < 8; i++) {
+		reg_off = 0x10 * i;
+		intr_in_service = apic_read_reg(apic, APIC_ISR + reg_off) &
+			kvm_apic_get_reg(apic, APIC_TMR + reg_off);
+		if (intr_in_service) {
+			*((u32 *)eoi_exit_bitmap + i) |= intr_in_service;
+			tmr[i] |= intr_in_service;
+		}
+	}
+}
+
 void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
arch/x86/kvm/lapic.h +2 -0
index 6a11845..4ee3d70 100644
@@ -53,6 +53,8 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
 u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
 void kvm_apic_set_version(struct kvm_vcpu *vcpu);
 
+void kvm_apic_zap_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+		u32 *tmr);
 void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr);
 void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir);
 int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
arch/x86/kvm/x86.c +9 -0
index 204422d..755b556 100644
@@ -6005,6 +6005,15 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
 	memset(tmr, 0, 32);
 
 	kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr);
+	/*
+	 * Guest may mask the IOAPIC entry before issue EOI. In such case,
+	 * EOI will not be intercepted by hypervisor due to the corrensponding
+	 * bit in eoi exit bitmap is not setting.
+	 *
+	 * The solution is to check ISR + TMR to construct the EOI exit bitmap.
+	 */
+	kvm_apic_zap_eoi_exitmap(vcpu, eoi_exit_bitmap, tmr);
+
 	kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
 	kvm_apic_update_tmr(vcpu, tmr);
 }
virt/kvm/ioapic.c +0 -0
index e8ce34c..2458a1d 100644
@@ -254,9 +254,10 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
 	spin_lock(&ioapic->lock);
 	for (index = 0; index < IOAPIC_NUM_PINS; index++) {
 		e = &ioapic->redirtbl[index];

virt/kvm/ioapic.c void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap, · line 263

Quoted 10 lines
virt/kvm/ioapic.c +4 -3
-		if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
-		    kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) ||
-		    index == RTC_GSI) {
+		if (!e->fields.mask &&
+			(e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
+			 kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC,
+				 index) || index == RTC_GSI)) {
 			if (kvm_apic_match_dest(vcpu, NULL, 0,
 				e->fields.dest_id, e->fields.dest_mode)) {
 				__set_bit(e->fields.vector,

Understanding the patch is complicated because of the subtle difference between tmr[] and apic_get_reg(..., APIC_TMR). I'd rather avoid that by first cleaning up the handling of TMR.

Please split the patch in two:

1) one patch should move kvm_apic_update_tmr before kvm_x86_ops->load_eoi_exitmap, and it should set TMR to

    (~(IRR | ISR) & new_TMR) | ((IRR | ISR) & old_TMR)

I'm using IRR|ISR here because the SDM says the TMR is only modified upon "acceptance of an interrupt into the IRR". We deviate from the spec by setting a value for the TMR even when the corresponding bit in IRR|ISR is 0; that's mostly invisible to guests, so it doesn't matter, but still the TMR should not change between acceptance of an interrupt into the IRR and the corresponding EOI cycle.

2) the second patch then can introduce the new logic to add ISR & TMR to the EOI exit map, and add back the !e->fields.mask check to ioapic.c, and make lapic.c OR the ISR & TMR value into the EOI exit map. This second patch need not handle the tmr[] array at all.

Paolo