* [PATCH] kvm/x86: simplify kvm_mmu_do_page_fault() a little bit
@ 2024-10-22 10:08 Juergen Gross
2024-10-22 17:01 ` Sean Christopherson
0 siblings, 1 reply; 3+ messages in thread
From: Juergen Gross @ 2024-10-22 10:08 UTC (permalink / raw)
To: linux-kernel, x86, kvm
Cc: Juergen Gross, Sean Christopherson, Paolo Bonzini,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin
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.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
arch/x86/kvm/mmu/mmu_internal.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
index c98827840e07..6eae54aa1160 100644
--- a/arch/x86/kvm/mmu/mmu_internal.h
+++ b/arch/x86/kvm/mmu/mmu_internal.h
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kvm/x86: simplify kvm_mmu_do_page_fault() a little bit
2024-10-22 10:08 [PATCH] kvm/x86: simplify kvm_mmu_do_page_fault() a little bit Juergen Gross
@ 2024-10-22 17:01 ` Sean Christopherson
2024-10-24 10:37 ` Jürgen Groß
0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2024-10-22 17:01 UTC (permalink / raw)
To: Juergen Gross
Cc: linux-kernel, x86, kvm, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin
On Tue, Oct 22, 2024, Juergen Gross wrote:
> 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.
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> arch/x86/kvm/mmu/mmu_internal.h | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
> index c98827840e07..6eae54aa1160 100644
> --- a/arch/x86/kvm/mmu/mmu_internal.h
> +++ b/arch/x86/kvm/mmu/mmu_internal.h
> @@ -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
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kvm/x86: simplify kvm_mmu_do_page_fault() a little bit
2024-10-22 17:01 ` Sean Christopherson
@ 2024-10-24 10:37 ` Jürgen Groß
0 siblings, 0 replies; 3+ messages in thread
From: Jürgen Groß @ 2024-10-24 10:37 UTC (permalink / raw)
To: Sean Christopherson
Cc: linux-kernel, x86, kvm, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin
[-- Attachment #1.1.1: Type: text/plain, Size: 879 bytes --]
On 22.10.24 19:01, Sean Christopherson wrote:
> On Tue, Oct 22, 2024, Juergen Gross wrote:
>> 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
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-24 10:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 10:08 [PATCH] kvm/x86: simplify kvm_mmu_do_page_fault() a little bit Juergen Gross
2024-10-22 17:01 ` Sean Christopherson
2024-10-24 10:37 ` Jürgen Groß
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox