Skip to contentSkip to conversation

KVM: lapic: Check for in-kernel LAPIC before deferencing apic pointer

PATCH Applied Sean Christopherson 3 participants 3 messages Apr 26, 2019 – Apr 30, 2019

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

PATCH 1/1 KVM: lapic: Check for in-kernel LAPIC before deferencing apic pointer

...to avoid dereferencing a null pointer when querying the per-vCPU timer advance.

Fixes 39497d7660d98 ("KVM: lapic: Track lapic timer advance per vCPU")
Reported-by [email protected]
---
 arch/x86/kvm/lapic.c | 3 ---
 arch/x86/kvm/x86.c   | 3 ++-
 2 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/kvm/lapic.c +0 -3
index 7decd58c9cea..35b8ac8f04fe 100644
@@ -1487,9 +1487,6 @@ void wait_lapic_expire(struct kvm_vcpu *vcpu)
 	u32 timer_advance_ns = apic->lapic_timer.timer_advance_ns;
 	u64 guest_tsc, tsc_deadline, ns;
 
-	if (!lapic_in_kernel(vcpu))
-		return;
-
 	if (apic->lapic_timer.expired_tscdeadline == 0)
 		return;
 
arch/x86/kvm/x86.c +2 -1
index aa26a3cfc765..21cb34d8ae01 100644
@@ -7872,7 +7872,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 	}
 
 	trace_kvm_entry(vcpu->vcpu_id);
-	if (vcpu->arch.apic->lapic_timer.timer_advance_ns)
+	if (lapic_in_kernel(vcpu) &&
+	    vcpu->arch.apic->lapic_timer.timer_advance_ns)
 		wait_lapic_expire(vcpu);
 	guest_enter_irqoff();
 
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Sean Christopherson

...to avoid dereferencing a null pointer when querying the per-vCPU timer advance.

Fixes 39497d7660d98 ("KVM: lapic: Track lapic timer advance per vCPU")
Reported-by [email protected]
Quoted 37 lines
---
 arch/x86/kvm/lapic.c | 3 ---
 arch/x86/kvm/x86.c   | 3 ++-
 2 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/kvm/lapic.c +0 -3
index 7decd58c9cea..35b8ac8f04fe 100644
@@ -1487,9 +1487,6 @@ void wait_lapic_expire(struct kvm_vcpu *vcpu)
 	u32 timer_advance_ns = apic->lapic_timer.timer_advance_ns;
 	u64 guest_tsc, tsc_deadline, ns;
 
-	if (!lapic_in_kernel(vcpu))
-		return;
-
 	if (apic->lapic_timer.expired_tscdeadline == 0)
 		return;
 
arch/x86/kvm/x86.c +2 -1
index aa26a3cfc765..21cb34d8ae01 100644
@@ -7872,7 +7872,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 	}
 
 	trace_kvm_entry(vcpu->vcpu_id);
-	if (vcpu->arch.apic->lapic_timer.timer_advance_ns)
+	if (lapic_in_kernel(vcpu) &&
+	    vcpu->arch.apic->lapic_timer.timer_advance_ns)
 		wait_lapic_expire(vcpu);
 	guest_enter_irqoff();
 
Signature · 1 line
2.21.0