x86/hyperv: Restrict get_vtl to only VTL platforms
Subsystems (3)
PATCH 1/1 x86/hyperv: Restrict get_vtl to only VTL platforms
For non VTL platforms vtl is always 0, and there is no need of get_vtl function. For VTL platforms get_vtl should always succeed and should return the correct VTL.
--- arch/x86/hyperv/hv_init.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/hyperv/hv_init.c +5 -3
@@ -416,8 +416,8 @@ static u8 __init get_vtl(void)if (hv_result_success (ret)) { ret = output->as64.low &HV_X64_VTL_MASK ; }else { -pr_err ("Failed to get VTL(%lld) and set VTL to zero by default.\n" , ret); - ret =0 ; +pr_err ("Failed to get VTL(error: %lld) exiting...\n" , ret); +BUG (); }local_irq_restore (flags);
@@ -604,8 +604,10 @@ void __init hyperv_init(void)hv_query_ext_cap (0 );/* Find the VTL */ -if (!ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) +if (IS_ENABLED (CONFIG_HYPERV_VTL_MODE )) ms_hyperv.vtl =get_vtl (); +else + ms_hyperv.vtl =0 ;return ;
Signature · 1 line
2.34.1
Quoted 14 lines · Saurabh Sengar
For non VTL platforms vtl is always 0, and there is no need of
get_vtlfunction. For VTL platformsget_vtlshould always succeed and should return the correct VTL.Signed-off-by Saurabh Sengar <[email protected]>--- arch/x86/hyperv/hv_init.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)arch/x86/hyperv/hv_init.c +0
-0
arch/x86/hyperv/hv_init.c static u8 __init get_vtl(void) · line 419
Quoted 6 lines
arch/x86/hyperv/hv_init.c +1
-2@@ -416,8 +416,8 @@ static u8 __init get_vtl(void)if (hv_result_success (ret)) { ret = output->as64.low &HV_X64_VTL_MASK ; }else { -pr_err ("Failed to get VTL(%lld) and set VTL to zero by default.\n" , ret); - ret =0 ; +pr_err ("Failed to get VTL(error: %lld) exiting...\n" , ret);
Nitpick: arch/x86/hyperv/hv_init.c lacks pr_fmt so the message won't get prefixed with "Hyper-V". I'm not sure 'VTL' abbreviation has the only, Hyper-V specific meaning. I'd suggest we add
#define pr_fmt(fmt) "Hyper-V: " fmt
to the beginning of the file.
arch/x86/hyperv/hv_init.c void __init hyperv_init(void) · line 610
Quoted 13 lines
arch/x86/hyperv/hv_init.c +4
-1+BUG (); }local_irq_restore (flags);@@ -604,8 +604,10 @@ void __init hyperv_init(void)hv_query_ext_cap (0 );/* Find the VTL */ -if (!ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) +if (IS_ENABLED (CONFIG_HYPERV_VTL_MODE )) ms_hyperv.vtl =get_vtl (); +else + ms_hyperv.vtl =0 ;
Is 'else' branch really needed? 'ms_hyperv' seems to be a statically allocated global. But instead of doing this, what about putting the whole get_vtl() funtion under '#if (IS_ENABLED(CONFIG_HYPERV_VTL_MODE))', i.e.:
#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
static u8 __init get_vtl(void)
{
u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;...
}
#else
static inline get_vtl(void) { return 0; }
#endif
and then we can always do
ms_hyperv.vtl = get_vtl();
unconditionally?
Quoted 2 lines
arch/x86/hyperv/hv_init.c +0
-0return ;
Signature · 1 line
Vitaly
Quoted 27 lines · Vitaly Kuznetsov
Quoted 14 lines · Saurabh Sengar
For non VTL platforms vtl is always 0, and there is no need of
get_vtlfunction. For VTL platformsget_vtlshould always succeed and should return the correct VTL.Signed-off-by Saurabh Sengar <[email protected]>--- arch/x86/hyperv/hv_init.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)arch/x86/hyperv/hv_init.c +0
-0arch/x86/hyperv/hv_init.c static u8 __init get_vtl(void) · line 419
Quoted 6 lines
arch/x86/hyperv/hv_init.c +1
-2@@ -416,8 +416,8 @@ static u8 __init get_vtl(void)if (hv_result_success (ret)) { ret = output->as64.low &HV_X64_VTL_MASK ; }else { -pr_err ("Failed to get VTL(%lld) and set VTL to zero by default.\n" , ret); - ret =0 ; +pr_err ("Failed to get VTL(error: %lld) exiting...\n" , ret);Nitpick:
arch/x86/hyperv/hv_init.clackspr_fmtso the message won't get prefixed with "Hyper-V". I'm not sure 'VTL' abbreviation has the only, Hyper-V specific meaning. I'd suggest we add
Quoted 3 lines
#define
pr_fmt(fmt)"Hyper-V: " fmtto the beginning of the file.
Good suggestion, I can do this as a separate patch.
Quoted 29 lines
Quoted 6 lines
arch/x86/hyperv/hv_init.c +1
-0+BUG (); }local_irq_restore (flags);arch/x86/hyperv/hv_init.c void __init hyperv_init(void) · line 610
Quoted 8 lines
arch/x86/hyperv/hv_init.c +3
-1@@ -604,8 +604,10 @@ void __init hyperv_init(void)hv_query_ext_cap (0 );/* Find the VTL */ -if (!ms_hyperv.paravisor_present &&hv_isolation_type_snp ()) +if (IS_ENABLED (CONFIG_HYPERV_VTL_MODE )) ms_hyperv.vtl =get_vtl (); +else + ms_hyperv.vtl =0 ;Is 'else' branch really needed? '
ms_hyperv' seems to be a statically allocated global. But instead of doing this, what about putting the wholeget_vtl()funtion under '#if (IS_ENABLED(CONFIG_HYPERV_VTL_MODE))', i.e.:#if
IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
static u8__initget_vtl(void){ u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;...
}
#else
static inlineget_vtl(void){ return 0; }
#endif
Quoted 5 lines
and then we can always do
ms_hyperv.vtl = get_vtl();unconditionally?
Fine with me, can update in v2.
- Saurabh
Quoted 7 lines
Quoted 3 lines
arch/x86/hyperv/hv_init.c +0
-0return ;Signature · 1 line
Vitaly