diff mbox series

[1/2] x86/cpufeatures: Add the Virtual SPEC_CTRL feature

Message ID 160738067105.28590.10158084163761735153.stgit@bmoger-ubuntu (mailing list archive)
State New, archived
Headers show
Series x86: Add the feature Virtual SPEC_CTRL | expand

Commit Message

Moger, Babu Dec. 7, 2020, 10:37 p.m. UTC
Newer AMD processors have a feature to virtualize the use of the SPEC_CTRL
MSR. This feature is identified via CPUID 0x8000000A_EDX[20]. When present,
the SPEC_CTRL MSR is automatically virtualized and no longer requires
hypervisor intervention.

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
 arch/x86/include/asm/cpufeatures.h |    1 +
 1 file changed, 1 insertion(+)

Comments

Jim Mattson Dec. 7, 2020, 11:22 p.m. UTC | #1
On Mon, Dec 7, 2020 at 2:38 PM Babu Moger <babu.moger@amd.com> wrote:
>
> Newer AMD processors have a feature to virtualize the use of the SPEC_CTRL
> MSR. This feature is identified via CPUID 0x8000000A_EDX[20]. When present,
> the SPEC_CTRL MSR is automatically virtualized and no longer requires
> hypervisor intervention.
>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
>  arch/x86/include/asm/cpufeatures.h |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
> index dad350d42ecf..d649ac5ed7c7 100644
> --- a/arch/x86/include/asm/cpufeatures.h
> +++ b/arch/x86/include/asm/cpufeatures.h
> @@ -335,6 +335,7 @@
>  #define X86_FEATURE_AVIC               (15*32+13) /* Virtual Interrupt Controller */
>  #define X86_FEATURE_V_VMSAVE_VMLOAD    (15*32+15) /* Virtual VMSAVE VMLOAD */
>  #define X86_FEATURE_VGIF               (15*32+16) /* Virtual GIF */
> +#define X86_FEATURE_V_SPEC_CTRL                (15*32+20) /* Virtual SPEC_CTRL */

Shouldn't this bit be reported by KVM_GET_SUPPORTED_CPUID when it's
enumerated on the host?

>  /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */
>  #define X86_FEATURE_AVX512VBMI         (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
>
Moger, Babu Dec. 9, 2020, 10:39 p.m. UTC | #2
On 12/7/20 5:22 PM, Jim Mattson wrote:
> On Mon, Dec 7, 2020 at 2:38 PM Babu Moger <babu.moger@amd.com> wrote:
>>
>> Newer AMD processors have a feature to virtualize the use of the SPEC_CTRL
>> MSR. This feature is identified via CPUID 0x8000000A_EDX[20]. When present,
>> the SPEC_CTRL MSR is automatically virtualized and no longer requires
>> hypervisor intervention.
>>
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
>>  arch/x86/include/asm/cpufeatures.h |    1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
>> index dad350d42ecf..d649ac5ed7c7 100644
>> --- a/arch/x86/include/asm/cpufeatures.h
>> +++ b/arch/x86/include/asm/cpufeatures.h
>> @@ -335,6 +335,7 @@
>>  #define X86_FEATURE_AVIC               (15*32+13) /* Virtual Interrupt Controller */
>>  #define X86_FEATURE_V_VMSAVE_VMLOAD    (15*32+15) /* Virtual VMSAVE VMLOAD */
>>  #define X86_FEATURE_VGIF               (15*32+16) /* Virtual GIF */
>> +#define X86_FEATURE_V_SPEC_CTRL                (15*32+20) /* Virtual SPEC_CTRL */
> 
> Shouldn't this bit be reported by KVM_GET_SUPPORTED_CPUID when it's
> enumerated on the host?

Jim, I am not sure if this needs to be reported by
KVM_GET_SUPPORTED_CPUID. I dont see V_VMSAVE_VMLOAD or VGIF being reported
via KVM_GET_SUPPORTED_CPUID. Do you see the need for that?


>>  /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */
>>  #define X86_FEATURE_AVX512VBMI         (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
>>
Jim Mattson Dec. 9, 2020, 11:11 p.m. UTC | #3
On Wed, Dec 9, 2020 at 2:39 PM Babu Moger <babu.moger@amd.com> wrote:
>
>
>
> On 12/7/20 5:22 PM, Jim Mattson wrote:
> > On Mon, Dec 7, 2020 at 2:38 PM Babu Moger <babu.moger@amd.com> wrote:
> >>
> >> Newer AMD processors have a feature to virtualize the use of the SPEC_CTRL
> >> MSR. This feature is identified via CPUID 0x8000000A_EDX[20]. When present,
> >> the SPEC_CTRL MSR is automatically virtualized and no longer requires
> >> hypervisor intervention.
> >>
> >> Signed-off-by: Babu Moger <babu.moger@amd.com>
> >> ---
> >>  arch/x86/include/asm/cpufeatures.h |    1 +
> >>  1 file changed, 1 insertion(+)
> >>
> >> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
> >> index dad350d42ecf..d649ac5ed7c7 100644
> >> --- a/arch/x86/include/asm/cpufeatures.h
> >> +++ b/arch/x86/include/asm/cpufeatures.h
> >> @@ -335,6 +335,7 @@
> >>  #define X86_FEATURE_AVIC               (15*32+13) /* Virtual Interrupt Controller */
> >>  #define X86_FEATURE_V_VMSAVE_VMLOAD    (15*32+15) /* Virtual VMSAVE VMLOAD */
> >>  #define X86_FEATURE_VGIF               (15*32+16) /* Virtual GIF */
> >> +#define X86_FEATURE_V_SPEC_CTRL                (15*32+20) /* Virtual SPEC_CTRL */
> >
> > Shouldn't this bit be reported by KVM_GET_SUPPORTED_CPUID when it's
> > enumerated on the host?
>
> Jim, I am not sure if this needs to be reported by
> KVM_GET_SUPPORTED_CPUID. I dont see V_VMSAVE_VMLOAD or VGIF being reported
> via KVM_GET_SUPPORTED_CPUID. Do you see the need for that?

Every little bit helps. No, it isn't *needed*. But then again, this
entire patchset isn't *needed*, is it?
Moger, Babu Dec. 22, 2020, 4:14 p.m. UTC | #4
On 12/9/20 5:11 PM, Jim Mattson wrote:
> On Wed, Dec 9, 2020 at 2:39 PM Babu Moger <babu.moger@amd.com> wrote:
>>
>>
>>
>> On 12/7/20 5:22 PM, Jim Mattson wrote:
>>> On Mon, Dec 7, 2020 at 2:38 PM Babu Moger <babu.moger@amd.com> wrote:
>>>>
>>>> Newer AMD processors have a feature to virtualize the use of the SPEC_CTRL
>>>> MSR. This feature is identified via CPUID 0x8000000A_EDX[20]. When present,
>>>> the SPEC_CTRL MSR is automatically virtualized and no longer requires
>>>> hypervisor intervention.
>>>>
>>>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>>>> ---
>>>>  arch/x86/include/asm/cpufeatures.h |    1 +
>>>>  1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
>>>> index dad350d42ecf..d649ac5ed7c7 100644
>>>> --- a/arch/x86/include/asm/cpufeatures.h
>>>> +++ b/arch/x86/include/asm/cpufeatures.h
>>>> @@ -335,6 +335,7 @@
>>>>  #define X86_FEATURE_AVIC               (15*32+13) /* Virtual Interrupt Controller */
>>>>  #define X86_FEATURE_V_VMSAVE_VMLOAD    (15*32+15) /* Virtual VMSAVE VMLOAD */
>>>>  #define X86_FEATURE_VGIF               (15*32+16) /* Virtual GIF */
>>>> +#define X86_FEATURE_V_SPEC_CTRL                (15*32+20) /* Virtual SPEC_CTRL */
>>>
>>> Shouldn't this bit be reported by KVM_GET_SUPPORTED_CPUID when it's
>>> enumerated on the host?
>>
>> Jim, I am not sure if this needs to be reported by
>> KVM_GET_SUPPORTED_CPUID. I dont see V_VMSAVE_VMLOAD or VGIF being reported
>> via KVM_GET_SUPPORTED_CPUID. Do you see the need for that?
> 
> Every little bit helps. No, it isn't *needed*. But then again, this
> entire patchset isn't *needed*, is it?
> 

Working on v2 of these patches. Saw this code comment(in
arch/x86/kvm/cpuid.c) on about exposing SVM features to the guest.


        /*
         * Hide all SVM features by default, SVM will set the cap bits for
         * features it emulates and/or exposes for L1.
         */
        kvm_cpu_cap_mask(CPUID_8000_000A_EDX, 0);


Should we go ahead with the changes here?

Thanks
Babu
Sean Christopherson Dec. 22, 2020, 5:41 p.m. UTC | #5
On Tue, Dec 22, 2020, Babu Moger wrote:
> 
> On 12/9/20 5:11 PM, Jim Mattson wrote:
> > On Wed, Dec 9, 2020 at 2:39 PM Babu Moger <babu.moger@amd.com> wrote:
> >>
> >> On 12/7/20 5:22 PM, Jim Mattson wrote:
> >>> On Mon, Dec 7, 2020 at 2:38 PM Babu Moger <babu.moger@amd.com> wrote:
> >>>> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
> >>>> index dad350d42ecf..d649ac5ed7c7 100644
> >>>> --- a/arch/x86/include/asm/cpufeatures.h
> >>>> +++ b/arch/x86/include/asm/cpufeatures.h
> >>>> @@ -335,6 +335,7 @@
> >>>>  #define X86_FEATURE_AVIC               (15*32+13) /* Virtual Interrupt Controller */
> >>>>  #define X86_FEATURE_V_VMSAVE_VMLOAD    (15*32+15) /* Virtual VMSAVE VMLOAD */
> >>>>  #define X86_FEATURE_VGIF               (15*32+16) /* Virtual GIF */
> >>>> +#define X86_FEATURE_V_SPEC_CTRL                (15*32+20) /* Virtual SPEC_CTRL */
> >>>
> >>> Shouldn't this bit be reported by KVM_GET_SUPPORTED_CPUID when it's
> >>> enumerated on the host?
> >>
> >> Jim, I am not sure if this needs to be reported by
> >> KVM_GET_SUPPORTED_CPUID. I dont see V_VMSAVE_VMLOAD or VGIF being reported
> >> via KVM_GET_SUPPORTED_CPUID. Do you see the need for that?
> > 
> > Every little bit helps. No, it isn't *needed*. But then again, this
> > entire patchset isn't *needed*, is it?
> > 
> 
> Working on v2 of these patches. Saw this code comment(in
> arch/x86/kvm/cpuid.c) on about exposing SVM features to the guest.
> 
> 
>         /*
>          * Hide all SVM features by default, SVM will set the cap bits for
>          * features it emulates and/or exposes for L1.
>          */
>         kvm_cpu_cap_mask(CPUID_8000_000A_EDX, 0);
> 
> 
> Should we go ahead with the changes here?

Probably not, as the current SVM implementation aligns with the intended use of
KVM_GET_SUPPORTED_CPUID.  The current approach is to enumerate what SVM features
KVM can virtualize or emulate for a nested VM, i.e. what SVM features an L1 VMM
can use and thus can be set in a vCPU's CPUID model.  For V_SPEC_CTRL, I'm
pretty sure Jim was providing feedback for the non-nested case of reporting
host/KVM support of the feature itself.

There is the question of whether or not KVM should have an ioctl() to report
what virtualization features are supported/enabled.  AFAIK, it's not truly
required as userspace can glean the information via /proc/cpuinfo (especially
now that vmx_features exists), raw CPUID, and KVM module params.  Providing an
ioctl() would likely be a bit cleaner for userspace, but I'm guessing that ship
has already sailed for most VMMs.
Moger, Babu Dec. 22, 2020, 6:07 p.m. UTC | #6
On 12/22/20 11:41 AM, Sean Christopherson wrote:
> On Tue, Dec 22, 2020, Babu Moger wrote:
>>
>> On 12/9/20 5:11 PM, Jim Mattson wrote:
>>> On Wed, Dec 9, 2020 at 2:39 PM Babu Moger <babu.moger@amd.com> wrote:
>>>>
>>>> On 12/7/20 5:22 PM, Jim Mattson wrote:
>>>>> On Mon, Dec 7, 2020 at 2:38 PM Babu Moger <babu.moger@amd.com> wrote:
>>>>>> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
>>>>>> index dad350d42ecf..d649ac5ed7c7 100644
>>>>>> --- a/arch/x86/include/asm/cpufeatures.h
>>>>>> +++ b/arch/x86/include/asm/cpufeatures.h
>>>>>> @@ -335,6 +335,7 @@
>>>>>>  #define X86_FEATURE_AVIC               (15*32+13) /* Virtual Interrupt Controller */
>>>>>>  #define X86_FEATURE_V_VMSAVE_VMLOAD    (15*32+15) /* Virtual VMSAVE VMLOAD */
>>>>>>  #define X86_FEATURE_VGIF               (15*32+16) /* Virtual GIF */
>>>>>> +#define X86_FEATURE_V_SPEC_CTRL                (15*32+20) /* Virtual SPEC_CTRL */
>>>>>
>>>>> Shouldn't this bit be reported by KVM_GET_SUPPORTED_CPUID when it's
>>>>> enumerated on the host?
>>>>
>>>> Jim, I am not sure if this needs to be reported by
>>>> KVM_GET_SUPPORTED_CPUID. I dont see V_VMSAVE_VMLOAD or VGIF being reported
>>>> via KVM_GET_SUPPORTED_CPUID. Do you see the need for that?
>>>
>>> Every little bit helps. No, it isn't *needed*. But then again, this
>>> entire patchset isn't *needed*, is it?
>>>
>>
>> Working on v2 of these patches. Saw this code comment(in
>> arch/x86/kvm/cpuid.c) on about exposing SVM features to the guest.
>>
>>
>>         /*
>>          * Hide all SVM features by default, SVM will set the cap bits for
>>          * features it emulates and/or exposes for L1.
>>          */
>>         kvm_cpu_cap_mask(CPUID_8000_000A_EDX, 0);
>>
>>
>> Should we go ahead with the changes here?
> 
> Probably not, as the current SVM implementation aligns with the intended use of
> KVM_GET_SUPPORTED_CPUID.  The current approach is to enumerate what SVM features
> KVM can virtualize or emulate for a nested VM, i.e. what SVM features an L1 VMM
> can use and thus can be set in a vCPU's CPUID model.  For V_SPEC_CTRL, I'm
> pretty sure Jim was providing feedback for the non-nested case of reporting
> host/KVM support of the feature itself.
> 
> There is the question of whether or not KVM should have an ioctl() to report
> what virtualization features are supported/enabled.  AFAIK, it's not truly
> required as userspace can glean the information via /proc/cpuinfo (especially
> now that vmx_features exists), raw CPUID, and KVM module params.  Providing an
> ioctl() would likely be a bit cleaner for userspace, but I'm guessing that ship
> has already sailed for most VMMs.
> 

Sean, Thanks for the clarifications.
diff mbox series

Patch

diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index dad350d42ecf..d649ac5ed7c7 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -335,6 +335,7 @@ 
 #define X86_FEATURE_AVIC		(15*32+13) /* Virtual Interrupt Controller */
 #define X86_FEATURE_V_VMSAVE_VMLOAD	(15*32+15) /* Virtual VMSAVE VMLOAD */
 #define X86_FEATURE_VGIF		(15*32+16) /* Virtual GIF */
+#define X86_FEATURE_V_SPEC_CTRL		(15*32+20) /* Virtual SPEC_CTRL */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */
 #define X86_FEATURE_AVX512VBMI		(16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/