From: Sean Christopherson <seanjc@google.com>
To: Chao Gao <chao.gao@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/12] KVM: x86: Add a framework for enabling KVM-governed x86 features
Date: Fri, 30 Jun 2023 08:31:11 -0700 [thread overview]
Message-ID: <ZJ71P+i4aRg3S5TL@google.com> (raw)
In-Reply-To: <ZJ6L4oWE9refbXnX@chao-email>
On Fri, Jun 30, 2023, Chao Gao wrote:
> On Fri, Feb 17, 2023 at 03:10:11PM -0800, Sean Christopherson wrote:
> >+static __always_inline void kvm_governed_feature_set(struct kvm_vcpu *vcpu,
> >+ unsigned int x86_feature)
> >+{
> >+ BUILD_BUG_ON(KVM_NR_GOVERNED_FEATURES >
> >+ sizeof(vcpu->arch.governed_features.enabled) * BITS_PER_BYTE);
> >+
> >+ vcpu->arch.governed_features.enabled |= kvm_governed_feature_bit(x86_feature);
> >+}
> >+
> >+static __always_inline void kvm_governed_feature_check_and_set(struct kvm_vcpu *vcpu,
> >+ unsigned int x86_feature)
> >+{
> >+ if (guest_cpuid_has(vcpu, x86_feature))
>
> Most callers in this series are conditional on either boot_cpu_has() or some
> local variables. Can we convert them to kvm_cpu_cap_has() and incorporate them
> within this function? i.e.,
>
> if (kvm_cpu_cap_has(x86_feature) && guest_cpuid_has(vcpu, x86_feature))
Hmm, I was going to say "no", as most callers don't check kvm_cpu_cap_has() verbatim,
but it doesn't have to be that way. The majority of SVM features factor in module
params, but KVM should set the kvm_cpu capability if and only if a feature is supported
in hardware *and* enabled by its module param.
And arguably that's kinda sorta a bug fix, because this
if (lbrv)
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LBRV);
technically should be
if (lbrv && nested)
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LBRV);
Heh, and it's kinda sorta a bug fix for XSAVES on VMX, because this
if (cpu_has_vmx_xsaves() && boot_cpu_has(X86_FEATURE_XSAVE) &&
guest_cpuid_has(vcpu, X86_FEATURE_XSAVE))
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_XSAVES);
should technically be
if (kvm_cpu_cap_has(X86_FEATURE_XSAVES) &&
boot_cpu_has(X86_FEATURE_XSAVE) &&
guest_cpuid_has(vcpu, X86_FEATURE_XSAVE))
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_XSAVES);
> The benefits of doing so are
> 1. callers needn't repeat
>
> if (kvm_cpu_cap_has(x86_feature))
> kvm_governed_feature_check_and_set(x86_feature)
>
> 2. this fits the idea better that guests can use a governed feature only if host
> supports it _and_ QEMU exposes it to the guest.
Agreed, especially since we'll still have kvm_governed_feature_set() for the
extra special cases.
Thanks for the input!
next prev parent reply other threads:[~2023-06-30 15:32 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 23:10 [PATCH 00/12] KVM: x86: Add "governed" X86_FEATURE framework Sean Christopherson
2023-02-17 23:10 ` [PATCH 01/12] KVM: x86: Add a framework for enabling KVM-governed x86 features Sean Christopherson
2023-02-21 17:12 ` Vitaly Kuznetsov
2023-06-29 2:40 ` Binbin Wu
2023-06-29 16:26 ` Sean Christopherson
2023-06-30 8:01 ` Chao Gao
2023-06-30 15:31 ` Sean Christopherson [this message]
2023-02-17 23:10 ` [PATCH 02/12] KVM: x86/mmu: Use KVM-governed feature framework to track "GBPAGES enabled" Sean Christopherson
2023-02-17 23:10 ` [PATCH 03/12] KVM: VMX: Recompute "XSAVES enabled" only after CPUID update Sean Christopherson
2023-02-17 23:10 ` [PATCH 04/12] KVM: VMX: Rename XSAVES control to follow KVM's preferred "ENABLE_XYZ" Sean Christopherson
2023-02-17 23:10 ` [PATCH 05/12] KVM: x86: Use KVM-governed feature framework to track "XSAVES enabled" Sean Christopherson
2023-02-21 14:56 ` Yu Zhang
2023-02-22 18:56 ` Sean Christopherson
2023-02-24 9:54 ` Yu Zhang
2023-02-17 23:10 ` [PATCH 06/12] KVM: nSVM: Use KVM-governed feature framework to track "NRIPS enabled" Sean Christopherson
2023-02-17 23:10 ` [PATCH 07/12] KVM: nSVM: Use KVM-governed feature framework to track "TSC scaling enabled" Sean Christopherson
2023-02-17 23:10 ` [PATCH 08/12] KVM: nSVM: Use KVM-governed feature framework to track "vVM{SAVE,LOAD} enabled" Sean Christopherson
2023-02-21 15:23 ` Yu Zhang
2023-02-21 15:33 ` Yu Zhang
2023-02-21 23:48 ` Sean Christopherson
2023-02-22 6:49 ` Yu Zhang
2023-02-22 16:39 ` Sean Christopherson
2023-02-24 9:25 ` Yu Zhang
2023-02-24 16:16 ` Sean Christopherson
[not found] ` <20230227065437.j7f7rfadut532fud@linux.intel.com>
2023-03-07 16:32 ` Sean Christopherson
2023-06-29 16:50 ` Sean Christopherson
2023-06-30 10:00 ` Yu Zhang
2023-02-17 23:10 ` [PATCH 09/12] KVM: nSVM: Use KVM-governed feature framework to track "LBRv enabled" Sean Christopherson
2023-02-17 23:10 ` [PATCH 10/12] KVM: nSVM: Use KVM-governed feature framework to track "Pause Filter enabled" Sean Christopherson
2023-02-17 23:10 ` [PATCH 11/12] KVM: nSVM: Use KVM-governed feature framework to track "vGIF enabled" Sean Christopherson
2023-02-17 23:10 ` [PATCH 12/12] KVM: x86: Disallow guest CPUID lookups when IRQs are disabled 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=ZJ71P+i4aRg3S5TL@google.com \
--to=seanjc@google.com \
--cc=chao.gao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vkuznets@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;
as well as URLs for NNTP newsgroup(s).