From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
David Matlack <dmatlack@google.com>,
Isaku Yamahata <isaku.yamahata@intel.com>
Subject: [PATCH v4 10/11] KVM: x86/mmu: Use static key/branches for checking if TDP MMU is enabled
Date: Wed, 12 Oct 2022 18:17:01 +0000 [thread overview]
Message-ID: <20221012181702.3663607-11-seanjc@google.com> (raw)
In-Reply-To: <20221012181702.3663607-1-seanjc@google.com>
Now that the TDP MMU being enabled is read-only after the vendor module
is loaded, use a static key to track whether or not the TDP MMU is
enabled to avoid conditional branches in hot paths, e.g. in
direct_page_fault() and fast_page_fault().
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/mmu.h | 5 +++--
arch/x86/kvm/mmu/mmu.c | 14 ++++++++++----
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 1ad6d02e103f..bc0d8a5c09f9 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -2,6 +2,7 @@
#ifndef __KVM_X86_MMU_H
#define __KVM_X86_MMU_H
+#include <linux/jump_label.h>
#include <linux/kvm_host.h>
#include "kvm_cache_regs.h"
#include "cpuid.h"
@@ -230,13 +231,13 @@ static inline bool kvm_shadow_root_allocated(struct kvm *kvm)
}
#ifdef CONFIG_X86_64
-extern bool tdp_mmu_enabled;
+DECLARE_STATIC_KEY_TRUE(tdp_mmu_enabled);
#endif
static inline bool is_tdp_mmu_enabled(void)
{
#ifdef CONFIG_X86_64
- return tdp_mmu_enabled;
+ return static_branch_likely(&tdp_mmu_enabled);
#else
return false;
#endif
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 4792d76edd6d..a5ba7b41263d 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -101,8 +101,10 @@ bool tdp_enabled = false;
#ifdef CONFIG_X86_64
static bool __ro_after_init tdp_mmu_allowed;
-bool __read_mostly tdp_mmu_enabled = true;
-module_param_named(tdp_mmu, tdp_mmu_enabled, bool, 0444);
+static bool __read_mostly __tdp_mmu_enabled = true;
+module_param_named(tdp_mmu, __tdp_mmu_enabled, bool, 0444);
+
+DEFINE_STATIC_KEY_TRUE(tdp_mmu_enabled);
#endif
static int max_huge_page_level __read_mostly;
@@ -5702,7 +5704,11 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,
max_tdp_level = tdp_max_root_level;
#ifdef CONFIG_X86_64
- tdp_mmu_enabled = tdp_mmu_allowed && tdp_enabled;
+ __tdp_mmu_enabled = tdp_mmu_allowed && tdp_enabled;
+ if (__tdp_mmu_enabled)
+ static_branch_enable(&tdp_mmu_enabled);
+ else
+ static_branch_disable(&tdp_mmu_enabled);
#endif
/*
* max_huge_page_level reflects KVM's MMU capabilities irrespective
@@ -6712,7 +6718,7 @@ void __init kvm_mmu_x86_module_init(void)
* TDP MMU is actually enabled is determined in kvm_configure_mmu()
* when the vendor module is loaded.
*/
- tdp_mmu_allowed = tdp_mmu_enabled;
+ tdp_mmu_allowed = __tdp_mmu_enabled;
#endif
kvm_mmu_spte_module_init();
--
2.38.0.rc1.362.ged0d419d3c-goog
next prev parent reply other threads:[~2022-10-12 18:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 18:16 [PATCH v4 00/11] KVM: x86/mmu: Make tdp_mmu a read-only parameter Sean Christopherson
2022-10-12 18:16 ` [PATCH v4 01/11] KVM: x86/mmu: Change tdp_mmu to " Sean Christopherson
2022-10-12 21:37 ` Huang, Kai
2022-10-12 18:16 ` [PATCH v4 02/11] KVM: x86/mmu: Move TDP MMU VM init/uninit behind tdp_mmu_enabled Sean Christopherson
2022-10-12 18:16 ` [PATCH v4 03/11] KVM: x86/mmu: Grab mmu_invalidate_seq in kvm_faultin_pfn() Sean Christopherson
2022-10-12 18:16 ` [PATCH v4 04/11] KVM: x86/mmu: Handle error PFNs " Sean Christopherson
2022-10-12 18:16 ` [PATCH v4 05/11] KVM: x86/mmu: Avoid memslot lookup during KVM_PFN_ERR_HWPOISON handling Sean Christopherson
2022-10-12 18:16 ` [PATCH v4 06/11] KVM: x86/mmu: Handle no-slot faults in kvm_faultin_pfn() Sean Christopherson
2022-10-12 18:16 ` [PATCH v4 07/11] KVM: x86/mmu: Pivot on "TDP MMU enabled" when handling direct page faults Sean Christopherson
2022-10-12 18:16 ` [PATCH v4 08/11] KVM: x86/mmu: Pivot on "TDP MMU enabled" to check if active MMU is TDP MMU Sean Christopherson
2022-10-12 18:17 ` [PATCH v4 09/11] KVM: x86/mmu: Replace open coded usage of tdp_mmu_page with is_tdp_mmu_page() Sean Christopherson
2022-10-12 18:17 ` Sean Christopherson [this message]
2022-10-12 18:17 ` [PATCH v4 11/11] KVM: x86/mmu: Stop needlessly making MMU pages available for TDP MMU Sean Christopherson
2022-10-13 17:21 ` [PATCH v4 00/11] KVM: x86/mmu: Make tdp_mmu a read-only parameter David Matlack
2022-10-13 20:12 ` Sean Christopherson
2022-10-13 22:56 ` David Matlack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221012181702.3663607-11-seanjc@google.com \
--to=seanjc@google.com \
--cc=dmatlack@google.com \
--cc=isaku.yamahata@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox