From: Sean Christopherson <seanjc@google.com>
To: Maxim Levitsky <mlevitsk@redhat.com>
Cc: Yang Weijiang <weijiang.yang@intel.com>,
pbonzini@redhat.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, dave.hansen@intel.com,
peterz@infradead.org, chao.gao@intel.com,
rick.p.edgecombe@intel.com, john.allen@amd.com
Subject: Re: [PATCH v6 18/25] KVM: x86: Use KVM-governed feature framework to track "SHSTK/IBT enabled"
Date: Wed, 1 Nov 2023 08:46:52 -0700 [thread overview]
Message-ID: <ZUJy7A5Hp6lnZVyq@google.com> (raw)
In-Reply-To: <ea3609bf7c7759b682007042b98191d91d10a751.camel@redhat.com>
On Tue, Oct 31, 2023, Maxim Levitsky wrote:
> On Thu, 2023-09-14 at 02:33 -0400, Yang Weijiang wrote:
> > Use the governed feature framework to track whether X86_FEATURE_SHSTK
> > and X86_FEATURE_IBT features can be used by userspace and guest, i.e.,
> > the features can be used iff both KVM and guest CPUID can support them.
> >
> > Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
> > ---
> > arch/x86/kvm/governed_features.h | 2 ++
> > arch/x86/kvm/vmx/vmx.c | 2 ++
> > 2 files changed, 4 insertions(+)
> >
> > diff --git a/arch/x86/kvm/governed_features.h b/arch/x86/kvm/governed_features.h
> > index 423a73395c10..db7e21c5ecc2 100644
> > --- a/arch/x86/kvm/governed_features.h
> > +++ b/arch/x86/kvm/governed_features.h
> > @@ -16,6 +16,8 @@ KVM_GOVERNED_X86_FEATURE(PAUSEFILTER)
> > KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD)
> > KVM_GOVERNED_X86_FEATURE(VGIF)
> > KVM_GOVERNED_X86_FEATURE(VNMI)
> > +KVM_GOVERNED_X86_FEATURE(SHSTK)
> > +KVM_GOVERNED_X86_FEATURE(IBT)
> >
> > #undef KVM_GOVERNED_X86_FEATURE
> > #undef KVM_GOVERNED_FEATURE
> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > index 9409753f45b0..fd5893b3a2c8 100644
> > --- a/arch/x86/kvm/vmx/vmx.c
> > +++ b/arch/x86/kvm/vmx/vmx.c
> > @@ -7765,6 +7765,8 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
> > kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_XSAVES);
> >
> > kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VMX);
> > + kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_SHSTK);
> > + kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_IBT);
> >
> > vmx_setup_uret_msrs(vmx);
> >
>
> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
>
>
> PS: IMHO The whole 'governed feature framework' is very confusing and
> somewhat poorly documented.
>
> Currently the only partial explanation of it, is at 'governed_features',
> which doesn't explain how to use it.
To be honest, terrible name aside, I thought kvm_governed_feature_check_and_set()
would be fairly self-explanatory, at least relative to all the other CPUID handling
in KVM.
> For the reference this is how KVM expects governed features to be used in the
> common case (there are some exceptions to this but they are rare)
>
> 1. If a feature is not enabled in host CPUID or KVM doesn't support it,
> KVM is expected to not enable it in KVM cpu caps.
>
> 2. Userspace uploads guest CPUID.
>
> 3. After the guest CPUID upload, the vendor code calls
> kvm_governed_feature_check_and_set() which sets governed features = True iff
> feature is supported in both kvm cpu caps and in guest CPUID.
>
> 4. kvm/vendor code uses 'guest_can_use()' to query the value of the governed
> feature instead of reading guest CPUID.
>
> It might make sense to document the above somewhere at least.
>
> Now about another thing I am thinking:
>
> I do know that the mess of boolean flags that svm had is worse than these
> governed features and functionality wise these are equivalent.
>
> However thinking again about the whole thing:
>
> IMHO the 'governed features' is another quite confusing term that a KVM
> developer will need to learn and keep in memory.
I 100% agree, but I explicitly called out the terrible name in the v1 and v2
cover letters[1][2], and the patches were on the list for 6 months before I
applied them. I'm definitely still open to a better name, but I'm also not
exactly chomping at the bit to get behind the bikehsed.
v1:
: Note, I don't like the name "governed", but it was the least awful thing I
: could come up with. Suggestions most definitely welcome.
v2:
: Note, I still don't like the name "governed", but no one has suggested
: anything else, let alone anything better :-)
[1] https://lore.kernel.org/all/20230217231022.816138-1-seanjc@google.com
[2] https://lore.kernel.org/all/20230729011608.1065019-1-seanjc@google.com
> Because of that, can't we just use guest CPUID as a single source of truth
> and drop all the governed features code?
No, not without a rather massive ABI break. To make guest CPUID the single source
of true, KVM would need to modify guest CPUID to squash features that userspace
has set, but that are not supported by hardware. And that is most definitely a
can of worms I don't want to reopen, e.g. see the mess that got created when KVM
tried to "help" userspace by mucking with VMX capability MSRs in response to
CPUID changes.
There aren't many real use cases for advertising "unsupported" features via guest
CPUID, but there are some, and I have definitely abused KVM_SET_CPUID2 for testing
purposes.
And as above, that doesn't work for X86_FEATURE_XSAVES or X86_FEATURE_GBPAGES.
We'd also have to overhaul guest CPUID lookups to be significantly faster (which
is doable), as one of the motiviations for the framework was to avoid the overhead
of looking through guest CPUID without needing one-off boolean fields.
> In most cases, when the governed feature value will differ from the guest
> CPUID is when a feature is enabled in the guest CPUID, but not enabled in the
> KVM caps.
>
> I do see two exceptions to this: XSAVES on AMD and X86_FEATURE_GBPAGES, in
> which the opposite happens, governed feature is enabled, even when the
> feature is hidden from the guest CPUID, but it might be better from
> readability wise point, to deal with these cases manually and we unlikely to
> have many new such cases in the future.
>
> So for the common case of CPUID mismatch, when the governed feature is
> disabled but guest CPUID is enabled, does it make sense to allow this?
Yes and no. For "governed features", probably not. But for CPUID as a whole, there
are legimiate cases where userspace needs to enumerate things that aren't officially
"supported" by KVM. E.g. topology, core crystal frequency (CPUID 0x15), defeatures
that KVM hasn't yet learned about, features that don't have virtualization controls
and KVM hasn't yet learned about, etc. And for things like Xen and Hyper-V paravirt
features, it's very doable to implement features that are enumerate by CPUID fully
in userspace, e.g. using MSR filters.
But again, it's a moot point because KVM has (mostly) allowed userspace to fully
control guest CPUID for a very long time.
> Such a feature which is advertised as supported but not really working is a
> recipe of hard to find guest bugs IMHO.
>
> IMHO it would be much better to just check this condition and do
> kvm_vm_bugged() or something in case when a feature is enabled in the guest
> CPUID but KVM can't support it, and then just use guest CPUID in
> 'guest_can_use()'.
Maybe, if we were creating KVM from scratch, e.g. didn't have to worry about
existing uesrspace behavior and could implement a more forward-looking API than
KVM_GET_SUPPORTED_CPUID. But even then the enforcement would need to be limited
to "pure" hardware-defined feature bits, and I suspect that there would still be
exceptions. And there would likely be complexitly in dealing with CPUID leafs
that are completely unknown to KVM, e.g. unless KVM completely disallowed non-zero
values for unknown CPUID leafs, adding restrictions when a feature is defined by
Intel or AMD would be at constant risk of breaking userspace.
next prev parent reply other threads:[~2023-11-01 15:47 UTC|newest]
Thread overview: 120+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 6:33 [PATCH v6 00/25] Enable CET Virtualization Yang Weijiang
2023-09-14 6:33 ` [PATCH v6 01/25] x86/fpu/xstate: Manually check and add XFEATURE_CET_USER xstate bit Yang Weijiang
2023-09-14 22:39 ` Edgecombe, Rick P
2023-09-15 2:32 ` Yang, Weijiang
2023-09-15 16:35 ` Edgecombe, Rick P
2023-09-18 7:16 ` Yang, Weijiang
2023-10-31 17:43 ` Maxim Levitsky
2023-11-01 9:19 ` Yang, Weijiang
2023-09-14 6:33 ` [PATCH v6 02/25] x86/fpu/xstate: Fix guest fpstate allocation size calculation Yang Weijiang
2023-09-14 22:45 ` Edgecombe, Rick P
2023-09-15 2:45 ` Yang, Weijiang
2023-09-15 16:35 ` Edgecombe, Rick P
2023-10-21 0:39 ` Sean Christopherson
2023-10-24 8:50 ` Yang, Weijiang
2023-10-24 16:32 ` Sean Christopherson
2023-10-25 13:49 ` Yang, Weijiang
2023-10-31 17:43 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 03/25] x86/fpu/xstate: Add CET supervisor mode state support Yang Weijiang
2023-09-15 0:06 ` Edgecombe, Rick P
2023-09-15 6:30 ` Yang, Weijiang
2023-10-31 17:44 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 04/25] x86/fpu/xstate: Introduce kernel dynamic xfeature set Yang Weijiang
2023-09-15 0:24 ` Edgecombe, Rick P
2023-09-15 6:42 ` Yang, Weijiang
2023-10-31 17:44 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 05/25] x86/fpu/xstate: Remove kernel dynamic xfeatures from kernel default_features Yang Weijiang
2023-09-14 16:22 ` Dave Hansen
2023-09-15 1:52 ` Yang, Weijiang
2023-10-31 17:44 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 06/25] x86/fpu/xstate: Opt-in kernel dynamic bits when calculate guest xstate size Yang Weijiang
2023-09-14 17:40 ` Dave Hansen
2023-09-15 2:22 ` Yang, Weijiang
2023-10-24 17:07 ` Sean Christopherson
2023-10-25 14:49 ` Yang, Weijiang
2023-10-26 17:24 ` Sean Christopherson
2023-10-26 22:06 ` Edgecombe, Rick P
2023-10-31 17:45 ` Maxim Levitsky
2023-11-01 14:16 ` Sean Christopherson
2023-11-02 18:20 ` Maxim Levitsky
2023-11-03 14:33 ` Sean Christopherson
2023-11-07 18:04 ` Maxim Levitsky
2023-11-14 9:13 ` Yang, Weijiang
2023-09-14 6:33 ` [PATCH v6 07/25] x86/fpu/xstate: Tweak guest fpstate to support kernel dynamic xfeatures Yang Weijiang
2023-10-31 17:45 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 08/25] x86/fpu/xstate: WARN if normal fpstate contains " Yang Weijiang
2023-10-31 17:45 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 09/25] KVM: x86: Rework cpuid_get_supported_xcr0() to operate on vCPU data Yang Weijiang
2023-10-31 17:46 ` Maxim Levitsky
2023-11-01 14:41 ` Sean Christopherson
2023-11-02 18:25 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 10/25] KVM: x86: Add kvm_msr_{read,write}() helpers Yang Weijiang
2023-10-31 17:47 ` Maxim Levitsky
2023-11-01 19:32 ` Sean Christopherson
2023-11-02 18:26 ` Maxim Levitsky
2023-11-15 9:00 ` Yang, Weijiang
2023-09-14 6:33 ` [PATCH v6 11/25] KVM: x86: Report XSS as to-be-saved if there are supported features Yang Weijiang
2023-10-31 17:47 ` Maxim Levitsky
2023-11-01 19:18 ` Sean Christopherson
2023-11-02 18:31 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 12/25] KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSS Yang Weijiang
2023-10-08 5:54 ` Chao Gao
2023-10-10 0:49 ` Yang, Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-11-01 17:20 ` Sean Christopherson
2023-11-15 7:18 ` Binbin Wu
2023-09-14 6:33 ` [PATCH v6 13/25] KVM: x86: Initialize kvm_caps.supported_xss Yang Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 14/25] KVM: x86: Load guest FPU state when access XSAVE-managed MSRs Yang Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-11-01 18:05 ` Sean Christopherson
2023-11-02 18:31 ` Maxim Levitsky
2023-11-03 8:46 ` Yang, Weijiang
2023-11-03 14:02 ` Sean Christopherson
2023-09-14 6:33 ` [PATCH v6 15/25] KVM: x86: Add fault checks for guest CR4.CET setting Yang Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 16/25] KVM: x86: Report KVM supported CET MSRs as to-be-saved Yang Weijiang
2023-10-08 6:19 ` Chao Gao
2023-10-10 0:54 ` Yang, Weijiang
2023-10-31 17:52 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 17/25] KVM: VMX: Introduce CET VMCS fields and control bits Yang Weijiang
2023-10-31 17:52 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 18/25] KVM: x86: Use KVM-governed feature framework to track "SHSTK/IBT enabled" Yang Weijiang
2023-10-31 17:54 ` Maxim Levitsky
2023-11-01 15:46 ` Sean Christopherson [this message]
2023-11-02 18:35 ` Maxim Levitsky
2023-11-04 0:07 ` Sean Christopherson
2023-11-07 18:05 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 19/25] KVM: VMX: Emulate read and write to CET MSRs Yang Weijiang
2023-10-31 17:55 ` Maxim Levitsky
2023-11-01 16:31 ` Sean Christopherson
2023-11-02 18:38 ` Maxim Levitsky
2023-11-02 23:58 ` Sean Christopherson
2023-11-07 18:12 ` Maxim Levitsky
2023-11-07 18:39 ` Sean Christopherson
2023-11-03 8:18 ` Yang, Weijiang
2023-11-03 22:26 ` Sean Christopherson
2023-09-14 6:33 ` [PATCH v6 20/25] KVM: x86: Save and reload SSP to/from SMRAM Yang Weijiang
2023-10-31 17:55 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 21/25] KVM: VMX: Set up interception for CET MSRs Yang Weijiang
2023-10-31 17:56 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 22/25] KVM: VMX: Set host constant supervisor states to VMCS fields Yang Weijiang
2023-10-31 17:56 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 23/25] KVM: x86: Enable CET virtualization for VMX and advertise to userspace Yang Weijiang
2023-09-24 13:38 ` kernel test robot
2023-09-25 0:26 ` Yang, Weijiang
2023-10-31 17:56 ` Maxim Levitsky
2023-11-01 22:14 ` Sean Christopherson
2023-09-14 6:33 ` [PATCH v6 24/25] KVM: nVMX: Introduce new VMX_BASIC bit for event error_code delivery to L1 Yang Weijiang
2023-10-31 17:57 ` Maxim Levitsky
2023-11-01 4:21 ` Chao Gao
2023-11-15 8:31 ` Yang, Weijiang
2023-11-15 13:27 ` Sean Christopherson
2023-09-14 6:33 ` [PATCH v6 25/25] KVM: nVMX: Enable CET support for nested guest Yang Weijiang
2023-10-31 17:57 ` Maxim Levitsky
2023-11-01 2:09 ` Chao Gao
2023-11-01 9:22 ` Yang, Weijiang
2023-11-01 9:54 ` Maxim Levitsky
2023-11-15 8:56 ` Yang, Weijiang
2023-11-15 8:23 ` Yang, Weijiang
2023-09-25 0:31 ` [PATCH v6 00/25] Enable CET Virtualization Yang, Weijiang
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=ZUJy7A5Hp6lnZVyq@google.com \
--to=seanjc@google.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=john.allen@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=weijiang.yang@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