Skip to contentSkip to conversation

KVM: x86: sync old tmr with ioapic to update

PATCH Superseded Wei Wang 2 participants 2 messages Aug 26, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH 1/1 KVM: x86: sync old tmr with ioapic to update

kvm_ioapic_scan_entry() needs to update tmr. The previous lapic tmr value (old_tmr) needs to sync with ioapic to get an accurate updated tmr value before the updating work.

---
 arch/x86/kvm/lapic.c |   11 ++++++++++-
 arch/x86/kvm/x86.c   |    2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)
arch/x86/kvm/lapic.c +10 -1
index 08e8a89..93c2e93 100644
@@ -518,10 +518,19 @@ static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu)
 void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
+	u32 irr[8];
+	u32 isr[8];
+	u32 old_tmr[8];
 	int i;
 
-	for (i = 0; i < 8; i++)
+	for (i = 0; i < 8; i++) {
+		irr[i] = kvm_apic_get_reg(apic, APIC_IRR + 0x10 * i);
+		isr[i] = kvm_apic_get_reg(apic, APIC_ISR + 0x10 * i);
+		old_tmr[i] = kvm_apic_get_reg(apic, APIC_TMR + 0x10 * i);
+		tmr[i] = (~(irr[i] | isr[i]) & tmr[i])
+				| ((irr[i] | isr[i]) & old_tmr[i]);
 		apic_set_reg(apic, APIC_TMR + 0x10 * i, tmr[i]);
+	}
 }
 
 static void apic_update_ppr(struct kvm_lapic *apic)
arch/x86/kvm/x86.c +1 -1
index 5f5edb6..d401684 100644
@@ -5991,8 +5991,8 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
 	memset(tmr, 0, 32);
 
 	kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr);
-	kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
 	kvm_apic_update_tmr(vcpu, tmr);
+	kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
 }
 
 /*
Signature · 1 line
1.7.1
maintainer
#1 lore raw

Il 26/08/2014 18:27, Wei Wang ha scritto:

arch/x86/kvm/lapic.c static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu) · line 523

Quoted 7 lines

kvm_ioapic_scan_entry() needs to update tmr. The previous lapic tmr value (old_tmr) needs to sync with ioapic to get an accurate updated tmr value before the updating work.

arch/x86/kvm/lapic.c +3 -0
+	u32 irr[8];
+	u32 isr[8];
+	u32 old_tmr[8];

These do not need to be arrays. You can use a single variable for each of irr, isr and old_tmr.

arch/x86/kvm/lapic.c static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu) · line 531

Quoted 9 lines
arch/x86/kvm/lapic.c +6 -1
 	int i;
 
-	for (i = 0; i < 8; i++)
+	for (i = 0; i < 8; i++) {
+		irr[i] = kvm_apic_get_reg(apic, APIC_IRR + 0x10 * i);
+		isr[i] = kvm_apic_get_reg(apic, APIC_ISR + 0x10 * i);
+		old_tmr[i] = kvm_apic_get_reg(apic, APIC_TMR + 0x10 * i);
+		tmr[i] = (~(irr[i] | isr[i]) & tmr[i])
+				| ((irr[i] | isr[i]) & old_tmr[i]);

Please do not modify the tmr array. Instead, use kvm_apic_get_reg in the next patch to read the TMR.

Also, please add a comment about how the code works and why the old TMR is used if IRR=1 || ISR=1.

Paolo

Quoted 1 line

apic_set_reg(apic, APIC_TMR + 0x10 * i, tmr[i]);