Skip to content

Commit f3e613e

Browse files
sean-jcliuw
authored andcommitted
x86/hyperv: Move required MSRs check to initial platform probing
Explicitly check for MSR_HYPERCALL and MSR_VP_INDEX support when probing for running as a Hyper-V guest instead of waiting until hyperv_init() to detect the bogus configuration. Add messages to give the admin a heads up that they are likely running on a broken virtual machine setup. At best, silently disabling Hyper-V is confusing and difficult to debug, e.g. the kernel _says_ it's using all these fancy Hyper-V features, but always falls back to the native versions. At worst, the half baked setup will crash/hang the kernel. Reviewed-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent daf9721 commit f3e613e

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,20 +386,13 @@ static void __init hv_get_partition_id(void)
386386
*/
387387
void __init hyperv_init(void)
388388
{
389-
u64 guest_id, required_msrs;
389+
u64 guest_id;
390390
union hv_x64_msr_hypercall_contents hypercall_msr;
391391
int cpuhp;
392392

393393
if (x86_hyper_type != X86_HYPER_MS_HYPERV)
394394
return;
395395

396-
/* Absolutely required MSRs */
397-
required_msrs = HV_MSR_HYPERCALL_AVAILABLE |
398-
HV_MSR_VP_INDEX_AVAILABLE;
399-
400-
if ((ms_hyperv.features & required_msrs) != required_msrs)
401-
return;
402-
403396
if (hv_common_init())
404397
return;
405398

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,22 @@ static uint32_t __init ms_hyperv_platform(void)
163163
cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS,
164164
&eax, &hyp_signature[0], &hyp_signature[1], &hyp_signature[2]);
165165

166-
if (eax >= HYPERV_CPUID_MIN &&
167-
eax <= HYPERV_CPUID_MAX &&
168-
!memcmp("Microsoft Hv", hyp_signature, 12))
169-
return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
166+
if (eax < HYPERV_CPUID_MIN || eax > HYPERV_CPUID_MAX ||
167+
memcmp("Microsoft Hv", hyp_signature, 12))
168+
return 0;
170169

171-
return 0;
170+
/* HYPERCALL and VP_INDEX MSRs are mandatory for all features. */
171+
eax = cpuid_eax(HYPERV_CPUID_FEATURES);
172+
if (!(eax & HV_MSR_HYPERCALL_AVAILABLE)) {
173+
pr_warn("x86/hyperv: HYPERCALL MSR not available.\n");
174+
return 0;
175+
}
176+
if (!(eax & HV_MSR_VP_INDEX_AVAILABLE)) {
177+
pr_warn("x86/hyperv: VP_INDEX MSR not available.\n");
178+
return 0;
179+
}
180+
181+
return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
172182
}
173183

174184
static unsigned char hv_get_nmi_reason(void)

0 commit comments

Comments
 (0)