Skip to contentSkip to conversation

KVM: LAPIC: Return 0 when getting the tscdeadline timer if the lapic is hw disabled

PATCH Superseded Wanpeng Li 2 participants 7 messages Aug 12, 2020 – Aug 25, 2020

Subsystems (3)
lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH v2 1/2 KVM: LAPIC: Return 0 when getting the tscdeadline timer if the lapic is hw disabled

From: Wanpeng Li <[email protected]>

Return 0 when getting the tscdeadline timer if the lapic is hw disabled.

---
v1 -> v2:
* fix indentation

 arch/x86/kvm/lapic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/lapic.c +1 -2
index 5ccbee7..79599af 100644
@@ -2183,8 +2183,7 @@ u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
 
-	if (!lapic_in_kernel(vcpu) ||
-		!apic_lvtt_tscdeadline(apic))
+	if (!kvm_apic_present(vcpu) || !apic_lvtt_tscdeadline(apic))
 		return 0;
 
 	return apic->lapic_timer.tscdeadline;
Signature · 1 line
2.7.4 
author
#1 lore raw

PATCH v2 2/2 KVM: LAPIC: Guarantee the timer is in tsc-deadline mode when setting

From: Wanpeng Li <[email protected]>

Check apic_lvtt_tscdeadline() mode directly instead of apic_lvtt_oneshot() and apic_lvtt_period() to guarantee the timer is in tsc-deadline mode when wrmsr MSR_IA32_TSCDEADLINE.

---
v1 -> v2:
* fix indentation

 arch/x86/kvm/lapic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/lapic.c +1 -2
index 79599af..abaf48e 100644
@@ -2193,8 +2193,7 @@ void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
 
-	if (!kvm_apic_present(vcpu) || apic_lvtt_oneshot(apic) ||
-			apic_lvtt_period(apic))
+	if (!kvm_apic_present(vcpu) || !apic_lvtt_tscdeadline(apic))
 		return;
 
 	hrtimer_cancel(&apic->lapic_timer.timer);
Signature · 1 line
2.7.4
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] KVM: LAPIC: Guarantee the timer is in tsc-deadline mode when setting

Quoted 7 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Check apic_lvtt_tscdeadline() mode directly instead of apic_lvtt_oneshot() and apic_lvtt_period() to guarantee the timer is in tsc-deadline mode when wrmsr MSR_IA32_TSCDEADLINE.

Gah, I take back my comment about squashing these, I assumed this was the same fix but just in the write path.

Quoted 24 lines

---
v1 -> v2:
* fix indentation

 arch/x86/kvm/lapic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/lapic.c +1 -2
index 79599af..abaf48e 100644
@@ -2193,8 +2193,7 @@ void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data)
 {
 	struct kvm_lapic *apic = vcpu->arch.apic;
 
-	if (!kvm_apic_present(vcpu) || apic_lvtt_oneshot(apic) ||
-			apic_lvtt_period(apic))
+	if (!kvm_apic_present(vcpu) || !apic_lvtt_tscdeadline(apic))
 		return;
 
 	hrtimer_cancel(&apic->lapic_timer.timer);
Signature · 1 line
2.7.4
author
#3 lore raw

Re: [PATCH v2 2/2] KVM: LAPIC: Guarantee the timer is in tsc-deadline mode when setting

In reply to Wanpeng Li

ping :)

Quoted 32 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Check apic_lvtt_tscdeadline() mode directly instead of apic_lvtt_oneshot() and apic_lvtt_period() to guarantee the timer is in tsc-deadline mode when wrmsr MSR_IA32_TSCDEADLINE.

---
v1 -> v2:
* fix indentation

 arch/x86/kvm/lapic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/lapic.c +1 -3
index 79599af..abaf48e 100644
@@ -2193,8 +2193,7 @@ void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data)
 {
        struct kvm_lapic *apic = vcpu->arch.apic;
 
-       if (!kvm_apic_present(vcpu) || apic_lvtt_oneshot(apic) ||
-                       apic_lvtt_period(apic))
+       if (!kvm_apic_present(vcpu) || !apic_lvtt_tscdeadline(apic))
                return;
 
        hrtimer_cancel(&apic->lapic_timer.timer);
--

2.7.4

Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] KVM: LAPIC: Guarantee the timer is in tsc-deadline mode when setting

In reply to Wanpeng Li
Quoted 8 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Check apic_lvtt_tscdeadline() mode directly instead of apic_lvtt_oneshot() and apic_lvtt_period() to guarantee the timer is in tsc-deadline mode when wrmsr MSR_IA32_TSCDEADLINE.

---

Reviewed-by on v2 1/2
#5 lore raw
In reply to Wanpeng Li
Quoted 3 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Return 0 when getting the tscdeadline timer if the lapic is hw disabled.

It'd be helpful to reference the SDM for the general behavior of the MSR.

In other timer modes (LVT bit 18 = 0), the IA32_TSC_DEADLINE MSR reads zero and writes are ignored.

I'd also vote to squash the two patches together, they really are paired changes to match the architectural behavior.