Skip to contentSkip to conversation

kvm/x86: simplify kvm_mmu_do_page_fault() a little bit

PATCH In review Juergen Gross 2 participants 3 messages Oct 22, 2024 – Oct 24, 2024

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

PATCH 1/1 kvm/x86: simplify kvm_mmu_do_page_fault() a little bit

Testing whether to call kvm_tdp_page_fault() or vcpu->arch.mmu->page_fault() doesn't make sense, as kvm_tdp_page_fault() is selected only if vcpu->arch.mmu->page_fault == kvm_tdp_page_fault.

---
 arch/x86/kvm/mmu/mmu_internal.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/kvm/mmu/mmu_internal.h +1 -4
index c98827840e07..6eae54aa1160 100644
@@ -322,10 +322,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
 		fault.slot = kvm_vcpu_gfn_to_memslot(vcpu, fault.gfn);
 	}
 
-	if (IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) && fault.is_tdp)
-		r = kvm_tdp_page_fault(vcpu, &fault);
-	else
-		r = vcpu->arch.mmu->page_fault(vcpu, &fault);
+	r = vcpu->arch.mmu->page_fault(vcpu, &fault);
 
 	/*
 	 * Not sure what's happening, but punt to userspace and hope that
Signature · 1 line
2.43.0
#1 lore raw
Quoted 3 lines · Juergen Gross

Testing whether to call kvm_tdp_page_fault() or vcpu->arch.mmu->page_fault() doesn't make sense, as kvm_tdp_page_fault() is selected only if vcpu->arch.mmu->page_fault == kvm_tdp_page_fault.

It does when retpolines are enabled and significantly inflate the cost of the indirect call. This is a hot path in various scenarios, but KVM can't use static_call() to avoid the retpoline due to mmu->page_fault being a property of the current vCPU. Only kvm_tdp_page_fault() is special cased because all other mmu->page_fault targets are slow-ish and/or we don't care terribly about their performance.

Quoted 24 lines
---
 arch/x86/kvm/mmu/mmu_internal.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/kvm/mmu/mmu_internal.h +1 -4
index c98827840e07..6eae54aa1160 100644
@@ -322,10 +322,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
 		fault.slot = kvm_vcpu_gfn_to_memslot(vcpu, fault.gfn);
 	}
 
-	if (IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) && fault.is_tdp)
-		r = kvm_tdp_page_fault(vcpu, &fault);
-	else
-		r = vcpu->arch.mmu->page_fault(vcpu, &fault);
+	r = vcpu->arch.mmu->page_fault(vcpu, &fault);
 
 	/*
 	 * Not sure what's happening, but punt to userspace and hope that
Signature · 1 line
2.43.0
#2 lore raw
Quoted 11 lines · Sean Christopherson
Quoted 3 lines · Juergen Gross

Testing whether to call kvm_tdp_page_fault() or vcpu->arch.mmu->page_fault() doesn't make sense, as kvm_tdp_page_fault() is selected only if vcpu->arch.mmu->page_fault == kvm_tdp_page_fault.

It does when retpolines are enabled and significantly inflate the cost of the indirect call. This is a hot path in various scenarios, but KVM can't use static_call() to avoid the retpoline due to mmu->page_fault being a property of the current vCPU. Only kvm_tdp_page_fault() is special cased because all other mmu->page_fault targets are slow-ish and/or we don't care terribly about their performance.

Fair enough. :-)

I'll modify the patch to add a comment in this regard in order to avoid similar simplification attempts in the future.

Juergen