diff mbox series

[2/8] x86/hyperv: detect absolutely necessary MSRs

Message ID 20191229183341.14877-3-liuwe@microsoft.com (mailing list archive)
State Superseded
Headers show
Series More Hyper-V infrastructure | expand

Commit Message

Wei Liu Dec. 29, 2019, 6:33 p.m. UTC
If they are not available, disable Hyper-V related features.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
 xen/arch/x86/guest/hyperv/hyperv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Paul Durrant Jan. 3, 2020, 11:01 a.m. UTC | #1
On Sun, 29 Dec 2019 at 18:34, Wei Liu <wl@xen.org> wrote:
>
> If they are not available, disable Hyper-V related features.
>
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
>  xen/arch/x86/guest/hyperv/hyperv.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
> index 2e70b4aa82..c6a26c5453 100644
> --- a/xen/arch/x86/guest/hyperv/hyperv.c
> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> @@ -32,6 +32,8 @@ static const struct hypervisor_ops ops = {
>  const struct hypervisor_ops *__init hyperv_probe(void)
>  {
>      uint32_t eax, ebx, ecx, edx;
> +    uint64_t required_msrs = HV_X64_MSR_HYPERCALL_AVAILABLE |
> +        HV_X64_MSR_VP_INDEX_AVAILABLE;
>
>      cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
>      if ( !((ebx == 0x7263694d) &&  /* "Micr" */
> @@ -57,6 +59,15 @@ const struct hypervisor_ops *__init hyperv_probe(void)
>      ms_hyperv.max_vp_index = eax;
>      ms_hyperv.max_lp_index = ebx;
>
> +    if ( (ms_hyperv.features & required_msrs) != required_msrs )
> +    {
> +        /* Oops, required MSRs are not available. Treat this as
> +         * "Hyper-V is not available".
> +         */

That block comment violates default coding style.

  Paul

> +        memset(&ms_hyperv, 0, sizeof(ms_hyperv));
> +        return NULL;
> +    }
> +
>      return &ops;
>  }
>
> --
> 2.20.1
>
Jan Beulich Jan. 3, 2020, 4:14 p.m. UTC | #2
On 03.01.2020 12:01, Paul Durrant wrote:
> On Sun, 29 Dec 2019 at 18:34, Wei Liu <wl@xen.org> wrote:
>> --- a/xen/arch/x86/guest/hyperv/hyperv.c
>> +++ b/xen/arch/x86/guest/hyperv/hyperv.c
>> @@ -32,6 +32,8 @@ static const struct hypervisor_ops ops = {
>>  const struct hypervisor_ops *__init hyperv_probe(void)
>>  {
>>      uint32_t eax, ebx, ecx, edx;
>> +    uint64_t required_msrs = HV_X64_MSR_HYPERCALL_AVAILABLE |
>> +        HV_X64_MSR_VP_INDEX_AVAILABLE;
>>
>>      cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
>>      if ( !((ebx == 0x7263694d) &&  /* "Micr" */
>> @@ -57,6 +59,15 @@ const struct hypervisor_ops *__init hyperv_probe(void)
>>      ms_hyperv.max_vp_index = eax;
>>      ms_hyperv.max_lp_index = ebx;
>>
>> +    if ( (ms_hyperv.features & required_msrs) != required_msrs )
>> +    {
>> +        /* Oops, required MSRs are not available. Treat this as
>> +         * "Hyper-V is not available".
>> +         */
> 
> That block comment violates default coding style.

And with it corrected
Acked-by: Jan Beulich <jbeulich@suse.com>

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c
index 2e70b4aa82..c6a26c5453 100644
--- a/xen/arch/x86/guest/hyperv/hyperv.c
+++ b/xen/arch/x86/guest/hyperv/hyperv.c
@@ -32,6 +32,8 @@  static const struct hypervisor_ops ops = {
 const struct hypervisor_ops *__init hyperv_probe(void)
 {
     uint32_t eax, ebx, ecx, edx;
+    uint64_t required_msrs = HV_X64_MSR_HYPERCALL_AVAILABLE |
+        HV_X64_MSR_VP_INDEX_AVAILABLE;
 
     cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
     if ( !((ebx == 0x7263694d) &&  /* "Micr" */
@@ -57,6 +59,15 @@  const struct hypervisor_ops *__init hyperv_probe(void)
     ms_hyperv.max_vp_index = eax;
     ms_hyperv.max_lp_index = ebx;
 
+    if ( (ms_hyperv.features & required_msrs) != required_msrs )
+    {
+        /* Oops, required MSRs are not available. Treat this as
+         * "Hyper-V is not available".
+         */
+        memset(&ms_hyperv, 0, sizeof(ms_hyperv));
+        return NULL;
+    }
+
     return &ops;
 }