]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Drivers: hv: Provide arch-neutral implementation of get_vtl()
authorRoman Kisel <romank@linux.microsoft.com>
Mon, 28 Apr 2025 21:07:35 +0000 (14:07 -0700)
committerWei Liu <wei.liu@kernel.org>
Fri, 23 May 2025 16:30:55 +0000 (16:30 +0000)
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>

arch/x86/hyperv/hv_init.c
drivers/hv/hv_common.c
include/asm-generic/mshyperv.h
include/hyperv/hvgdk_mini.h

index ddeb40930bc8027e06fe586eabb9d82b86dc54b8..3b569291dfede2b966061a5f7d1f89bc495a0013 100644 (file)
@@ -390,40 +390,6 @@ static void __init hv_stimer_setup_percpu_clockev(void)
                old_setup_percpu_clockev();
 }
 
-#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
-static u8 __init get_vtl(void)
-{
-       u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
-       struct hv_input_get_vp_registers *input;
-       struct hv_output_get_vp_registers *output;
-       unsigned long flags;
-       u64 ret;
-
-       local_irq_save(flags);
-       input = *this_cpu_ptr(hyperv_pcpu_input_arg);
-       output = *this_cpu_ptr(hyperv_pcpu_output_arg);
-
-       memset(input, 0, struct_size(input, names, 1));
-       input->partition_id = HV_PARTITION_ID_SELF;
-       input->vp_index = HV_VP_INDEX_SELF;
-       input->input_vtl.as_uint8 = 0;
-       input->names[0] = HV_REGISTER_VSM_VP_STATUS;
-
-       ret = hv_do_hypercall(control, input, output);
-       if (hv_result_success(ret)) {
-               ret = output->values[0].reg8 & HV_X64_VTL_MASK;
-       } else {
-               pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
-               BUG();
-       }
-
-       local_irq_restore(flags);
-       return ret;
-}
-#else
-static inline u8 get_vtl(void) { return 0; }
-#endif
-
 /*
  * This function is to be invoked early in the boot sequence after the
  * hypervisor has been detected.
index 59792e00cecf38d672629cb0492618961df89125..f8e4330bd4c7ec7e5f0ed9baf41968fd722dfdd0 100644 (file)
@@ -317,6 +317,37 @@ void __init hv_get_partition_id(void)
                pr_err("Hyper-V: failed to get partition ID: %#x\n",
                       hv_result(status));
 }
+#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
+u8 __init get_vtl(void)
+{
+       u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
+       struct hv_input_get_vp_registers *input;
+       struct hv_output_get_vp_registers *output;
+       unsigned long flags;
+       u64 ret;
+
+       local_irq_save(flags);
+       input = *this_cpu_ptr(hyperv_pcpu_input_arg);
+       output = *this_cpu_ptr(hyperv_pcpu_output_arg);
+
+       memset(input, 0, struct_size(input, names, 1));
+       input->partition_id = HV_PARTITION_ID_SELF;
+       input->vp_index = HV_VP_INDEX_SELF;
+       input->input_vtl.as_uint8 = 0;
+       input->names[0] = HV_REGISTER_VSM_VP_STATUS;
+
+       ret = hv_do_hypercall(control, input, output);
+       if (hv_result_success(ret)) {
+               ret = output->values[0].reg8 & HV_VTL_MASK;
+       } else {
+               pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
+               BUG();
+       }
+
+       local_irq_restore(flags);
+       return ret;
+}
+#endif
 
 int __init hv_common_init(void)
 {
index ccccb1cbf7df753ea32dc8617c502b741d226e77..6c51a25ed7b5732f68a0653f6a6c037e0aa95be8 100644 (file)
@@ -378,4 +378,10 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
 }
 #endif /* CONFIG_MSHV_ROOT */
 
+#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
+u8 __init get_vtl(void);
+#else
+static inline u8 get_vtl(void) { return 0; }
+#endif
+
 #endif
index abf0bd76e3703a1e00768bde621ee522cd4721cb..cf0923dc727daa08fb05e8d8ef23fd65a3440e6b 100644 (file)
@@ -1228,7 +1228,7 @@ struct hv_send_ipi {       /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI */
        u64 cpu_mask;
 } __packed;
 
-#define        HV_X64_VTL_MASK                 GENMASK(3, 0)
+#define        HV_VTL_MASK                     GENMASK(3, 0)
 
 /* Hyper-V memory host visibility */
 enum hv_mem_host_visibility {