hyperv: Move hv_current_partition_id to arch-generic code
authorNuno Das Neves <nunodasneves@linux.microsoft.com>
Fri, 7 Feb 2025 19:03:21 +0000 (11:03 -0800)
committerWei Liu <wei.liu@kernel.org>
Thu, 13 Feb 2025 23:38:47 +0000 (23:38 +0000)
Move hv_current_partition_id and hv_get_partition_id() to hv_common.c,
and call hv_get_partition_id() on arm64 in hyperv_init(). These aren't
specific to x86_64 and will be needed by common code.

Set hv_current_partition_id to HV_PARTITION_ID_SELF by default.

Rename struct hv_get_partition_id to hv_output_get_partition_id, to
make it distinct from the function hv_get_partition_id(), and match
the original Hyper-V struct name.

Remove the BUG()s. Failing to get the id need not crash the machine.

Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1738955002-20821-2-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1738955002-20821-2-git-send-email-nunodasneves@linux.microsoft.com>

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

index fc49949b7df6222e5ed0645b48ff93820268e288..29fcfd595f48067d85b9c0c343d648d67b7a6f4c 100644 (file)
@@ -72,6 +72,9 @@ static int __init hyperv_init(void)
                return ret;
        }
 
+       if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID)
+               hv_get_partition_id();
+
        ms_hyperv_late_init();
 
        hyperv_initialized = true;
index 173005e6a95dafaf134d74419b15eddb10512699..9be1446f5bd380b4af01de8f160d8b53113faf9f 100644 (file)
@@ -34,9 +34,6 @@
 #include <clocksource/hyperv_timer.h>
 #include <linux/highmem.h>
 
-u64 hv_current_partition_id = ~0ull;
-EXPORT_SYMBOL_GPL(hv_current_partition_id);
-
 void *hv_hypercall_pg;
 EXPORT_SYMBOL_GPL(hv_hypercall_pg);
 
@@ -393,24 +390,6 @@ static void __init hv_stimer_setup_percpu_clockev(void)
                old_setup_percpu_clockev();
 }
 
-static void __init hv_get_partition_id(void)
-{
-       struct hv_get_partition_id *output_page;
-       u64 status;
-       unsigned long flags;
-
-       local_irq_save(flags);
-       output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
-       status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page);
-       if (!hv_result_success(status)) {
-               /* No point in proceeding if this failed */
-               pr_err("Failed to get partition ID: %lld\n", status);
-               BUG();
-       }
-       hv_current_partition_id = output_page->partition_id;
-       local_irq_restore(flags);
-}
-
 #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
 static u8 __init get_vtl(void)
 {
@@ -605,11 +584,9 @@ skip_hypercall_pg_init:
 
        register_syscore_ops(&hv_syscore_ops);
 
-       if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID)
+       if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID)
                hv_get_partition_id();
 
-       BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull);
-
 #ifdef CONFIG_PCI_MSI
        /*
         * If we're running as root, we want to create our own PCI MSI domain.
index f91ab1e75f9ffc456f08241550b865b93c5f34ef..8d3ada3e8d0debb27892476eb9e280c59f2145a1 100644 (file)
@@ -43,8 +43,6 @@ extern bool hyperv_paravisor_present;
 
 extern void *hv_hypercall_pg;
 
-extern u64 hv_current_partition_id;
-
 extern union hv_ghcb * __percpu *hv_ghcb_pg;
 
 bool hv_isolation_type_snp(void);
index f2e6f55d6ca629d339e3280c40b3e4913ae8429d..ee3083937b4fdbd17b7c7eb374c12e2e66fd7010 100644 (file)
@@ -31,6 +31,9 @@
 #include <hyperv/hvhdk.h>
 #include <asm/mshyperv.h>
 
+u64 hv_current_partition_id = HV_PARTITION_ID_SELF;
+EXPORT_SYMBOL_GPL(hv_current_partition_id);
+
 /*
  * hv_root_partition, ms_hyperv and hv_nested are defined here with other
  * Hyper-V specific globals so they are shared across all architectures and are
@@ -283,6 +286,25 @@ static inline bool hv_output_page_exists(void)
        return hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE);
 }
 
+void __init hv_get_partition_id(void)
+{
+       struct hv_output_get_partition_id *output;
+       unsigned long flags;
+       u64 status, pt_id;
+
+       local_irq_save(flags);
+       output = *this_cpu_ptr(hyperv_pcpu_input_arg);
+       status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, &output);
+       pt_id = output->partition_id;
+       local_irq_restore(flags);
+
+       if (hv_result_success(status))
+               hv_current_partition_id = pt_id;
+       else
+               pr_err("Hyper-V: failed to get partition ID: %#x\n",
+                      hv_result(status));
+}
+
 int __init hv_common_init(void)
 {
        int i;
index a7bbe504e4f326f6360fffc60e1a95703052f7ed..febeddf6cd8ad9c92e380c767b3eb103080d3ab6 100644 (file)
@@ -58,6 +58,7 @@ struct ms_hyperv_info {
 };
 extern struct ms_hyperv_info ms_hyperv;
 extern bool hv_nested;
+extern u64 hv_current_partition_id;
 
 extern void * __percpu *hyperv_pcpu_input_arg;
 extern void * __percpu *hyperv_pcpu_output_arg;
@@ -207,6 +208,7 @@ extern u64 (*hv_read_reference_counter)(void);
 #define VP_INVAL       U32_MAX
 
 int __init hv_common_init(void);
+void __init hv_get_partition_id(void);
 void __init hv_common_free(void);
 void __init ms_hyperv_late_init(void);
 int hv_common_cpu_init(unsigned int cpu);
index 155615175965fc970bf0dc23c28b64464c510184..58895883f6366aa773ddd6ccb79f4000a93ceba5 100644 (file)
@@ -182,7 +182,7 @@ struct hv_tsc_emulation_control {    /* HV_TSC_INVARIANT_CONTROL */
 
 #endif /* CONFIG_X86 */
 
-struct hv_get_partition_id {    /* HV_OUTPUT_GET_PARTITION_ID */
+struct hv_output_get_partition_id {
        u64 partition_id;
 } __packed;