Skip to content

Commit f2a55d0

Browse files
Saurabh Sengarliuw
authored andcommitted
x86/hyperv: Restrict get_vtl to only VTL platforms
When Linux runs in a non-default VTL (CONFIG_HYPERV_VTL_MODE=y), get_vtl() must never fail as its return value is used in negotiations with the host. In the more generic case, (CONFIG_HYPERV_VTL_MODE=n) the VTL is always zero so there's no need to do the hypercall. Make get_vtl() BUG() in case of failure and put the implementation under "if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)" to avoid the call altogether in the most generic use case. Signed-off-by: Saurabh Sengar <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Wei Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ce9ecca commit f2a55d0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ static void __init hv_get_partition_id(void)
394394
local_irq_restore(flags);
395395
}
396396

397+
#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
397398
static u8 __init get_vtl(void)
398399
{
399400
u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
@@ -416,13 +417,16 @@ static u8 __init get_vtl(void)
416417
if (hv_result_success(ret)) {
417418
ret = output->as64.low & HV_X64_VTL_MASK;
418419
} else {
419-
pr_err("Failed to get VTL(%lld) and set VTL to zero by default.\n", ret);
420-
ret = 0;
420+
pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
421+
BUG();
421422
}
422423

423424
local_irq_restore(flags);
424425
return ret;
425426
}
427+
#else
428+
static inline u8 get_vtl(void) { return 0; }
429+
#endif
426430

427431
/*
428432
* This function is to be invoked early in the boot sequence after the
@@ -604,8 +608,7 @@ void __init hyperv_init(void)
604608
hv_query_ext_cap(0);
605609

606610
/* Find the VTL */
607-
if (!ms_hyperv.paravisor_present && hv_isolation_type_snp())
608-
ms_hyperv.vtl = get_vtl();
611+
ms_hyperv.vtl = get_vtl();
609612

610613
return;
611614

0 commit comments

Comments
 (0)