Skip to content

Commit e7e6902

Browse files
romank-msftliuw
authored andcommitted
Drivers: hv: Provide arch-neutral implementation of get_vtl()
To run in the VTL mode, Hyper-V drivers have to know what VTL the system boots in, and the arm64/hyperv code does not have the means to compute that. Refactor the code to hoist the function that detects VTL, make it arch-neutral to be able to employ it to get the VTL on arm64. Signed-off-by: Roman Kisel <romank@linux.microsoft.com> Reviewed-by: Michael Kelley <mhklinux@outlook.com> Reviewed-by: Tianyu Lan <tiala@microsoft.com> Link: https://lore.kernel.org/r/20250428210742.435282-5-romank@linux.microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org> Message-ID: <20250428210742.435282-5-romank@linux.microsoft.com>
1 parent f41ceff commit e7e6902

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -390,40 +390,6 @@ static void __init hv_stimer_setup_percpu_clockev(void)
390390
old_setup_percpu_clockev();
391391
}
392392

393-
#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
394-
static u8 __init get_vtl(void)
395-
{
396-
u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
397-
struct hv_input_get_vp_registers *input;
398-
struct hv_output_get_vp_registers *output;
399-
unsigned long flags;
400-
u64 ret;
401-
402-
local_irq_save(flags);
403-
input = *this_cpu_ptr(hyperv_pcpu_input_arg);
404-
output = *this_cpu_ptr(hyperv_pcpu_output_arg);
405-
406-
memset(input, 0, struct_size(input, names, 1));
407-
input->partition_id = HV_PARTITION_ID_SELF;
408-
input->vp_index = HV_VP_INDEX_SELF;
409-
input->input_vtl.as_uint8 = 0;
410-
input->names[0] = HV_REGISTER_VSM_VP_STATUS;
411-
412-
ret = hv_do_hypercall(control, input, output);
413-
if (hv_result_success(ret)) {
414-
ret = output->values[0].reg8 & HV_X64_VTL_MASK;
415-
} else {
416-
pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
417-
BUG();
418-
}
419-
420-
local_irq_restore(flags);
421-
return ret;
422-
}
423-
#else
424-
static inline u8 get_vtl(void) { return 0; }
425-
#endif
426-
427393
/*
428394
* This function is to be invoked early in the boot sequence after the
429395
* hypervisor has been detected.

drivers/hv/hv_common.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,37 @@ void __init hv_get_partition_id(void)
317317
pr_err("Hyper-V: failed to get partition ID: %#x\n",
318318
hv_result(status));
319319
}
320+
#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
321+
u8 __init get_vtl(void)
322+
{
323+
u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
324+
struct hv_input_get_vp_registers *input;
325+
struct hv_output_get_vp_registers *output;
326+
unsigned long flags;
327+
u64 ret;
328+
329+
local_irq_save(flags);
330+
input = *this_cpu_ptr(hyperv_pcpu_input_arg);
331+
output = *this_cpu_ptr(hyperv_pcpu_output_arg);
332+
333+
memset(input, 0, struct_size(input, names, 1));
334+
input->partition_id = HV_PARTITION_ID_SELF;
335+
input->vp_index = HV_VP_INDEX_SELF;
336+
input->input_vtl.as_uint8 = 0;
337+
input->names[0] = HV_REGISTER_VSM_VP_STATUS;
338+
339+
ret = hv_do_hypercall(control, input, output);
340+
if (hv_result_success(ret)) {
341+
ret = output->values[0].reg8 & HV_VTL_MASK;
342+
} else {
343+
pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
344+
BUG();
345+
}
346+
347+
local_irq_restore(flags);
348+
return ret;
349+
}
350+
#endif
320351

321352
int __init hv_common_init(void)
322353
{

include/asm-generic/mshyperv.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,10 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
378378
}
379379
#endif /* CONFIG_MSHV_ROOT */
380380

381+
#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
382+
u8 __init get_vtl(void);
383+
#else
384+
static inline u8 get_vtl(void) { return 0; }
385+
#endif
386+
381387
#endif

include/hyperv/hvgdk_mini.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ struct hv_send_ipi { /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI */
12281228
u64 cpu_mask;
12291229
} __packed;
12301230

1231-
#define HV_X64_VTL_MASK GENMASK(3, 0)
1231+
#define HV_VTL_MASK GENMASK(3, 0)
12321232

12331233
/* Hyper-V memory host visibility */
12341234
enum hv_mem_host_visibility {

0 commit comments

Comments
 (0)