From: "Yang, Weijiang" <weijiang.yang@intel.com>
To: Sean Christopherson <seanjc@google.com>,
Maxim Levitsky <mlevitsk@redhat.com>
Cc: <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 14/25] KVM: x86: Load guest FPU state when access XSAVE-managed MSRs
Date: Fri, 3 Nov 2023 16:46:29 +0800 [thread overview]
Message-ID: <10fd9a3e-1bc2-7d4d-0535-162854fc5e9d@intel.com> (raw)
In-Reply-To: <ZUKTd_a00fs1nyyk@google.com>
On 11/2/2023 2:05 AM, Sean Christopherson wrote:
> On Tue, Oct 31, 2023, Maxim Levitsky wrote:
>> On Thu, 2023-09-14 at 02:33 -0400, Yang Weijiang wrote:
>>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>> index 66edbed25db8..a091764bf1d2 100644
>>> --- a/arch/x86/kvm/x86.c
>>> +++ b/arch/x86/kvm/x86.c
>>> @@ -133,6 +133,9 @@ static int __set_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2);
>>> static void __get_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2);
>>>
>>> static DEFINE_MUTEX(vendor_module_lock);
>>> +static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
>>> +static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
>>> +
>>> struct kvm_x86_ops kvm_x86_ops __read_mostly;
>>>
>>> #define KVM_X86_OP(func) \
>>> @@ -4372,6 +4375,22 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>>> }
>>> EXPORT_SYMBOL_GPL(kvm_get_msr_common);
>>>
>>> +static const u32 xstate_msrs[] = {
>>> + MSR_IA32_U_CET, MSR_IA32_PL0_SSP, MSR_IA32_PL1_SSP,
>>> + MSR_IA32_PL2_SSP, MSR_IA32_PL3_SSP,
>>> +};
>>> +
>>> +static bool is_xstate_msr(u32 index)
>>> +{
>>> + int i;
>>> +
>>> + for (i = 0; i < ARRAY_SIZE(xstate_msrs); i++) {
>>> + if (index == xstate_msrs[i])
>>> + return true;
>>> + }
>>> + return false;
>>> +}
>> The name 'xstate_msr' IMHO is not clear.
>>
>> How about naming it 'guest_fpu_state_msrs', together with adding a comment like that:
> Maybe xstate_managed_msrs? I'd prefer not to include "guest" because the behavior
> is more a property of the architecture and/or the host kernel. I understand where
> you're coming from, but it's the MSR *values* are part of guest state, whereas the
> check is a query on how KVM manages the MSR value, if that makes sense.
>
> And I really don't like "FPU". I get why the the kernel uses the "FPU" terminology,
> but for this check in particular I want to tie the behavior back to the architecture,
> i.e. provide the hint that the reason why these MSRs are special is because Intel
> defined them to be context switched via XSTATE.
>
> Actually, this is unnecesary bikeshedding to some extent, using an array is silly.
> It's easier and likely far more performant (not that that matters in this case)
> to use a switch statement.
>
> Is this better?
The change looks good to me! Thanks!
> /*
> * Returns true if the MSR in question is managed via XSTATE, i.e. is context
> * switched with the rest of guest FPU state.
> */
> static bool is_xstate_managed_msr(u32 index)
How about is_xfeature_msr()? xfeature is XSAVE-Supported-Feature, just to align with SDM
convention.
> {
> switch (index) {
> case MSR_IA32_U_CET:
> case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:
> return true;
> default:
> return false;
> }
> }
>
> /*
> * Read or write a bunch of msrs. All parameters are kernel addresses.
> *
> * @return number of msrs set successfully.
> */
> static int __msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs *msrs,
> struct kvm_msr_entry *entries,
> int (*do_msr)(struct kvm_vcpu *vcpu,
> unsigned index, u64 *data))
> {
> bool fpu_loaded = false;
> int i;
>
> for (i = 0; i < msrs->nmsrs; ++i) {
> /*
> * If userspace is accessing one or more XSTATE-managed MSRs,
> * temporarily load the guest's FPU state so that the guest's
> * MSR value(s) is resident in hardware, i.e. so that KVM can
> * get/set the MSR via RDMSR/WRMSR.
> */
> if (vcpu && !fpu_loaded && kvm_caps.supported_xss &&
> is_xstate_managed_msr(entries[i].index)) {
> kvm_load_guest_fpu(vcpu);
> fpu_loaded = true;
> }
> if (do_msr(vcpu, entries[i].index, &entries[i].data))
> break;
> }
> if (fpu_loaded)
> kvm_put_guest_fpu(vcpu);
>
> return i;
> }
next prev parent reply other threads:[~2023-11-03 8:46 UTC|newest]
Thread overview: 119+ 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 [this message]
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
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-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=10fd9a3e-1bc2-7d4d-0535-162854fc5e9d@intel.com \
--to=weijiang.yang@intel.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=seanjc@google.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®