From: Yuan Yao <yuan.yao@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Zeng Guang <guang.zeng@intel.com>, Yuan Yao <yuan.yao@intel.com>
Subject: Re: [PATCH v3 02/15] KVM: x86/mmu: Use KVM-governed feature framework to track "GBPAGES enabled"
Date: Wed, 16 Aug 2023 10:10:40 +0800 [thread overview]
Message-ID: <20230816021040.tl2r5luajsqbb5al@yy-desk-7060> (raw)
In-Reply-To: <20230815203653.519297-3-seanjc@google.com>
On Tue, Aug 15, 2023 at 01:36:40PM -0700, Sean Christopherson wrote:
> Use the governed feature framework to track whether or not the guest can
> use 1GiB pages, and drop the one-off helper that wraps the surprisingly
> non-trivial logic surrounding 1GiB page usage in the guest.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/cpuid.c | 17 +++++++++++++++++
> arch/x86/kvm/governed_features.h | 2 ++
> arch/x86/kvm/mmu/mmu.c | 20 +++-----------------
> 3 files changed, 22 insertions(+), 17 deletions(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 4ba43ae008cb..67e9f79fe059 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -312,11 +312,28 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
> {
> struct kvm_lapic *apic = vcpu->arch.apic;
> struct kvm_cpuid_entry2 *best;
> + bool allow_gbpages;
>
> BUILD_BUG_ON(KVM_NR_GOVERNED_FEATURES > KVM_MAX_NR_GOVERNED_FEATURES);
> bitmap_zero(vcpu->arch.governed_features.enabled,
> KVM_MAX_NR_GOVERNED_FEATURES);
>
> + /*
> + * If TDP is enabled, let the guest use GBPAGES if they're supported in
> + * hardware. The hardware page walker doesn't let KVM disable GBPAGES,
> + * i.e. won't treat them as reserved, and KVM doesn't redo the GVA->GPA
> + * walk for performance and complexity reasons. Not to mention KVM
> + * _can't_ solve the problem because GVA->GPA walks aren't visible to
> + * KVM once a TDP translation is installed. Mimic hardware behavior so
> + * that KVM's is at least consistent, i.e. doesn't randomly inject #PF.
> + * If TDP is disabled, honor *only* guest CPUID as KVM has full control
> + * and can install smaller shadow pages if the host lacks 1GiB support.
> + */
> + allow_gbpages = tdp_enabled ? boot_cpu_has(X86_FEATURE_GBPAGES) :
> + guest_cpuid_has(vcpu, X86_FEATURE_GBPAGES);
tdp_enabled only changes at kvm_configure_mmu() when hardware setup for
VMX and SVM, so:
Reviewed-by: Yuan Yao <yuan.yao@intel.com>
> + if (allow_gbpages)
> + kvm_governed_feature_set(vcpu, X86_FEATURE_GBPAGES);
> +
> best = kvm_find_cpuid_entry(vcpu, 1);
> if (best && apic) {
> if (cpuid_entry_has(best, X86_FEATURE_TSC_DEADLINE_TIMER))
> diff --git a/arch/x86/kvm/governed_features.h b/arch/x86/kvm/governed_features.h
> index 40ce8e6608cd..b29c15d5e038 100644
> --- a/arch/x86/kvm/governed_features.h
> +++ b/arch/x86/kvm/governed_features.h
> @@ -5,5 +5,7 @@ BUILD_BUG()
>
> #define KVM_GOVERNED_X86_FEATURE(x) KVM_GOVERNED_FEATURE(X86_FEATURE_##x)
>
> +KVM_GOVERNED_X86_FEATURE(GBPAGES)
> +
> #undef KVM_GOVERNED_X86_FEATURE
> #undef KVM_GOVERNED_FEATURE
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 5bdda75bfd10..9e4cd8b4a202 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -4779,28 +4779,13 @@ static void __reset_rsvds_bits_mask(struct rsvd_bits_validate *rsvd_check,
> }
> }
>
> -static bool guest_can_use_gbpages(struct kvm_vcpu *vcpu)
> -{
> - /*
> - * If TDP is enabled, let the guest use GBPAGES if they're supported in
> - * hardware. The hardware page walker doesn't let KVM disable GBPAGES,
> - * i.e. won't treat them as reserved, and KVM doesn't redo the GVA->GPA
> - * walk for performance and complexity reasons. Not to mention KVM
> - * _can't_ solve the problem because GVA->GPA walks aren't visible to
> - * KVM once a TDP translation is installed. Mimic hardware behavior so
> - * that KVM's is at least consistent, i.e. doesn't randomly inject #PF.
> - */
> - return tdp_enabled ? boot_cpu_has(X86_FEATURE_GBPAGES) :
> - guest_cpuid_has(vcpu, X86_FEATURE_GBPAGES);
> -}
> -
> static void reset_guest_rsvds_bits_mask(struct kvm_vcpu *vcpu,
> struct kvm_mmu *context)
> {
> __reset_rsvds_bits_mask(&context->guest_rsvd_check,
> vcpu->arch.reserved_gpa_bits,
> context->cpu_role.base.level, is_efer_nx(context),
> - guest_can_use_gbpages(vcpu),
> + guest_can_use(vcpu, X86_FEATURE_GBPAGES),
> is_cr4_pse(context),
> guest_cpuid_is_amd_or_hygon(vcpu));
> }
> @@ -4877,7 +4862,8 @@ static void reset_shadow_zero_bits_mask(struct kvm_vcpu *vcpu,
> __reset_rsvds_bits_mask(shadow_zero_check, reserved_hpa_bits(),
> context->root_role.level,
> context->root_role.efer_nx,
> - guest_can_use_gbpages(vcpu), is_pse, is_amd);
> + guest_can_use(vcpu, X86_FEATURE_GBPAGES),
> + is_pse, is_amd);
>
> if (!shadow_me_mask)
> return;
> --
> 2.41.0.694.ge786442a9b-goog
>
next prev parent reply other threads:[~2023-08-16 2:11 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 20:36 [PATCH v3 00/15] KVM: x86: Add "governed" X86_FEATURE framework Sean Christopherson
2023-08-15 20:36 ` [PATCH v3 01/15] KVM: x86: Add a framework for enabling KVM-governed x86 features Sean Christopherson
2023-08-16 1:36 ` Huang, Kai
2023-08-16 14:20 ` Sean Christopherson
2023-08-16 22:46 ` Huang, Kai
2023-08-16 23:01 ` Yuan Yao
2023-08-17 2:11 ` Binbin Wu
2023-08-15 20:36 ` [PATCH v3 02/15] KVM: x86/mmu: Use KVM-governed feature framework to track "GBPAGES enabled" Sean Christopherson
2023-08-16 2:10 ` Yuan Yao [this message]
2023-08-15 20:36 ` [PATCH v3 03/15] KVM: VMX: Recompute "XSAVES enabled" only after CPUID update Sean Christopherson
2023-08-16 2:26 ` Yuan Yao
2023-08-15 20:36 ` [PATCH v3 04/15] KVM: VMX: Check KVM CPU caps, not just VMX MSR support, for XSAVE enabling Sean Christopherson
2023-08-16 8:07 ` Yuan Yao
2023-08-15 20:36 ` [PATCH v3 05/15] KVM: VMX: Rename XSAVES control to follow KVM's preferred "ENABLE_XYZ" Sean Christopherson
2023-08-16 7:50 ` Vitaly Kuznetsov
2023-08-16 14:15 ` Sean Christopherson
2023-08-15 20:36 ` [PATCH v3 06/15] KVM: x86: Use KVM-governed feature framework to track "XSAVES enabled" Sean Christopherson
2023-08-16 2:58 ` Yuan Yao
2023-08-16 3:21 ` Yuan Yao
2023-08-15 20:36 ` [PATCH v3 07/15] KVM: nVMX: Use KVM-governed feature framework to track "nested VMX enabled" Sean Christopherson
2023-08-16 2:25 ` Huang, Kai
2023-08-16 2:45 ` Huang, Kai
2023-08-16 14:42 ` Sean Christopherson
2023-08-15 20:36 ` [PATCH v3 08/15] KVM: nSVM: Use KVM-governed feature framework to track "NRIPS enabled" Sean Christopherson
2023-08-16 6:18 ` Yuan Yao
2023-08-15 20:36 ` [PATCH v3 09/15] KVM: nSVM: Use KVM-governed feature framework to track "TSC scaling enabled" Sean Christopherson
2023-08-16 6:35 ` Yuan Yao
2023-08-16 13:44 ` Sean Christopherson
2023-08-16 23:03 ` Yuan Yao
2023-08-15 20:36 ` [PATCH v3 10/15] KVM: nSVM: Use KVM-governed feature framework to track "vVM{SAVE,LOAD} enabled" Sean Christopherson
2023-08-15 20:36 ` [PATCH v3 11/15] KVM: nSVM: Use KVM-governed feature framework to track "LBRv enabled" Sean Christopherson
2023-08-15 20:36 ` [PATCH v3 12/15] KVM: nSVM: Use KVM-governed feature framework to track "Pause Filter enabled" Sean Christopherson
2023-08-16 7:24 ` Yuan Yao
2023-08-15 20:36 ` [PATCH v3 13/15] KVM: nSVM: Use KVM-governed feature framework to track "vGIF enabled" Sean Christopherson
2023-08-16 7:27 ` Yuan Yao
2023-08-15 20:36 ` [PATCH v3 14/15] KVM: nSVM: Use KVM-governed feature framework to track "vNMI enabled" Sean Christopherson
2023-08-15 20:36 ` [PATCH v3 15/15] KVM: x86: Disallow guest CPUID lookups when IRQs are disabled Sean Christopherson
2023-08-18 0:09 ` [PATCH v3 00/15] KVM: x86: Add "governed" X86_FEATURE framework Sean Christopherson
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=20230816021040.tl2r5luajsqbb5al@yy-desk-7060 \
--to=yuan.yao@linux.intel.com \
--cc=guang.zeng@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=yuan.yao@intel.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
all inboxes | Powered by JetHome®