2021-04-07 21:06:16

by Vineeth Pillai

[permalink] [raw]
Subject: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM

Detect nested features exposed by Hyper-V if SVM is enabled.

Signed-off-by: Vineeth Pillai <[email protected]>
---
arch/x86/kernel/cpu/mshyperv.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 3546d3e21787..4d364acfe95d 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -325,9 +325,17 @@ static void __init ms_hyperv_init_platform(void)
ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
}

- if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
+ /*
+ * AMD does not need enlightened VMCS as VMCB is already a
+ * datastructure in memory. We need to get the nested
+ * features if SVM is enabled.
+ */
+ if (boot_cpu_has(X86_FEATURE_SVM) ||
+ ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
ms_hyperv.nested_features =
cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
+ pr_info("Hyper-V nested_features: 0x%x\n",
+ ms_hyperv.nested_features);
}

/*
--
2.25.1


2021-04-07 21:32:40

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM

On Wed, Apr 07, 2021 at 02:41:22PM +0000, Vineeth Pillai wrote:
> Detect nested features exposed by Hyper-V if SVM is enabled.
>
> Signed-off-by: Vineeth Pillai <[email protected]>
> ---
> arch/x86/kernel/cpu/mshyperv.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 3546d3e21787..4d364acfe95d 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -325,9 +325,17 @@ static void __init ms_hyperv_init_platform(void)
> ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
> }
>
> - if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> + /*
> + * AMD does not need enlightened VMCS as VMCB is already a
> + * datastructure in memory. We need to get the nested
> + * features if SVM is enabled.
> + */
> + if (boot_cpu_has(X86_FEATURE_SVM) ||

Pls use:

cpu_feature_enabled

here.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

2021-04-07 21:58:57

by Michael Kelley (LINUX)

[permalink] [raw]
Subject: RE: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM

From: Vineeth Pillai <[email protected]> Sent: Wednesday, April 7, 2021 7:41 AM
>
> Detect nested features exposed by Hyper-V if SVM is enabled.
>
> Signed-off-by: Vineeth Pillai <[email protected]>
> ---
> arch/x86/kernel/cpu/mshyperv.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 3546d3e21787..4d364acfe95d 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -325,9 +325,17 @@ static void __init ms_hyperv_init_platform(void)
> ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
> }
>
> - if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> + /*
> + * AMD does not need enlightened VMCS as VMCB is already a
> + * datastructure in memory. We need to get the nested
> + * features if SVM is enabled.
> + */
> + if (boot_cpu_has(X86_FEATURE_SVM) ||
> + ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> ms_hyperv.nested_features =
> cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
> + pr_info("Hyper-V nested_features: 0x%x\n",

Nit: Most other similar lines put the colon in a different place:

pr_info("Hyper-V: nested features 0x%x\n",

One of these days, I'm going to fix the ones that don't follow this
pattern. :-)

> + ms_hyperv.nested_features);
> }
>
> /*
> --
> 2.25.1

2021-04-07 22:50:53

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM

On Wed, Apr 07, 2021, Michael Kelley wrote:
> From: Vineeth Pillai <[email protected]> Sent: Wednesday, April 7, 2021 7:41 AM
> >
> > Detect nested features exposed by Hyper-V if SVM is enabled.
> >
> > Signed-off-by: Vineeth Pillai <[email protected]>
> > ---
> > arch/x86/kernel/cpu/mshyperv.c | 10 +++++++++-
> > 1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> > index 3546d3e21787..4d364acfe95d 100644
> > --- a/arch/x86/kernel/cpu/mshyperv.c
> > +++ b/arch/x86/kernel/cpu/mshyperv.c
> > @@ -325,9 +325,17 @@ static void __init ms_hyperv_init_platform(void)
> > ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
> > }
> >
> > - if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> > + /*
> > + * AMD does not need enlightened VMCS as VMCB is already a
> > + * datastructure in memory. We need to get the nested
> > + * features if SVM is enabled.
> > + */
> > + if (boot_cpu_has(X86_FEATURE_SVM) ||
> > + ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> > ms_hyperv.nested_features =
> > cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
> > + pr_info("Hyper-V nested_features: 0x%x\n",
>
> Nit: Most other similar lines put the colon in a different place:
>
> pr_info("Hyper-V: nested features 0x%x\n",
>
> One of these days, I'm going to fix the ones that don't follow this
> pattern. :-)

Any reason not to use pr_fmt?

2021-04-08 11:07:47

by Vitaly Kuznetsov

[permalink] [raw]
Subject: Re: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM

Vineeth Pillai <[email protected]> writes:

> Detect nested features exposed by Hyper-V if SVM is enabled.
>
> Signed-off-by: Vineeth Pillai <[email protected]>
> ---
> arch/x86/kernel/cpu/mshyperv.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 3546d3e21787..4d364acfe95d 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -325,9 +325,17 @@ static void __init ms_hyperv_init_platform(void)
> ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
> }
>
> - if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> + /*
> + * AMD does not need enlightened VMCS as VMCB is already a
> + * datastructure in memory.

Well, VMCS is also a structure in memory, isn't it? It's just that we
don't have a 'clean field' concept for it and we can't use normal memory
accesses.

> We need to get the nested
> + * features if SVM is enabled.
> + */
> + if (boot_cpu_has(X86_FEATURE_SVM) ||
> + ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {

Do I understand correctly that we can just look at CPUID.0x40000000.EAX
and in case it is >= 0x4000000A we can read HYPERV_CPUID_NESTED_FEATURES
leaf? I'd suggest we do that intead then.

> ms_hyperv.nested_features =
> cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
> + pr_info("Hyper-V nested_features: 0x%x\n",
> + ms_hyperv.nested_features);
> }
>
> /*

--
Vitaly

2021-04-08 13:19:03

by Vineeth Pillai

[permalink] [raw]
Subject: Re: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM

Hi Vitaly,

On 4/8/21 7:06 AM, Vitaly Kuznetsov wrote:
> - if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> + /*
> + * AMD does not need enlightened VMCS as VMCB is already a
> + * datastructure in memory.
> Well, VMCS is also a structure in memory, isn't it? It's just that we
> don't have a 'clean field' concept for it and we can't use normal memory
> accesses.

Yes, you are right. I was referring to the fact that we cant use normal
memory accesses, but is a bit mis-worded.

>
>> We need to get the nested
>> + * features if SVM is enabled.
>> + */
>> + if (boot_cpu_has(X86_FEATURE_SVM) ||
>> + ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> Do I understand correctly that we can just look at CPUID.0x40000000.EAX
> and in case it is >= 0x4000000A we can read HYPERV_CPUID_NESTED_FEATURES
> leaf? I'd suggest we do that intead then.
I agree, that is a better way to consolidate both the cases.
Will change it in the next iteration. Probably the above code
comment is not needed when we consolidate the cases here.

Thanks,
Vineeth

2021-04-08 13:28:08

by Vineeth Pillai

[permalink] [raw]
Subject: Re: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM


On 4/7/21 6:48 PM, Sean Christopherson wrote:
> On Wed, Apr 07, 2021, Michael Kelley wrote:
>>
>>> + pr_info("Hyper-V nested_features: 0x%x\n",
>> Nit: Most other similar lines put the colon in a different place:
>>
>> pr_info("Hyper-V: nested features 0x%x\n",
>>
>> One of these days, I'm going to fix the ones that don't follow this
>> pattern. :-)
> Any reason not to use pr_fmt?
Yes, that would be the best way to go. As Michael suggested,
it would be better to fix the whole file as a cleanup patch.
I shall fix this one to conform to the previous style and use
pr_fmt as a separate fixup patch.

Thanks,
Vineeth

2021-04-08 15:26:27

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM

On Thu, Apr 08, 2021, Vineeth Pillai wrote:
> Hi Vitaly,
>
> On 4/8/21 7:06 AM, Vitaly Kuznetsov wrote:
> > - if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
> > + /*
> > + * AMD does not need enlightened VMCS as VMCB is already a
> > + * datastructure in memory.
> > Well, VMCS is also a structure in memory, isn't it? It's just that we
> > don't have a 'clean field' concept for it and we can't use normal memory
> > accesses.

Technically, you can use normal memory accesses, so long as software guarantees
the VMCS isn't resident in the VMCS cache and knows the field offsets for the
underlying CPU. The lack of an architecturally defined layout is the biggest
issue, e.g. tacking on dirty bits through a PV ABI would be trivial.

> Yes, you are right. I was referring to the fact that we cant use normal
> memory accesses, but is a bit mis-worded.

If you slot in "architectural" it will read nicely, i.e. "VMCB is already an
architectural datastructure in memory".

2021-04-09 12:24:11

by Vineeth Pillai

[permalink] [raw]
Subject: Re: [PATCH 1/7] hyperv: Detect Nested virtualization support for SVM


On 4/8/21 11:24 AM, Sean Christopherson wrote:
>
> Technically, you can use normal memory accesses, so long as software guarantees
> the VMCS isn't resident in the VMCS cache and knows the field offsets for the
> underlying CPU. The lack of an architecturally defined layout is the biggest
> issue, e.g. tacking on dirty bits through a PV ABI would be trivial.
>
>> Yes, you are right. I was referring to the fact that we cant use normal
>> memory accesses, but is a bit mis-worded.
> If you slot in "architectural" it will read nicely, i.e. "VMCB is already an
> architectural datastructure in memory".
Yes, this makes sense. Thanks for the suggestion, will reword as you
suggested.

Thanks,
Vineeth