From: Michael Kelley <[email protected]>

hv_smp_prepare_cpus() current handles two disjoint cases: a fully
enlightened SNP guest and running in the root partition. The root
partition case has recently added more steps, and as a result the
function is getting somewhat messy.

Refactor the code by putting the SNP and root cases into separate
functions. For the root case, move most of the code into hv_proc.c,
which is built only when MSHV_ROOT is configured. The move reduces
the surface area between the main code and the root partition
extensions. Several stubs go away, with an overall modest reduction
in lines of code.

No functional change.

Signed-off-by: Michael Kelley <[email protected]>
---
 arch/x86/kernel/cpu/mshyperv.c | 52 +++++++---------------------------
 drivers/hv/hv_proc.c           | 35 +++++++++++++++++++++--
 include/asm-generic/mshyperv.h | 17 ++---------
 3 files changed, 45 insertions(+), 59 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 640e6b223c2d..442156056cd2 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -32,7 +32,6 @@
 #include <asm/msr.h>
 #include <asm/nmi.h>
 #include <clocksource/hyperv_timer.h>
-#include <asm/numa.h>
 #include <asm/svm.h>
 
 /* Is Linux running on nested Microsoft Hypervisor */
@@ -413,46 +412,16 @@ static void __init hv_smp_prepare_boot_cpu(void)
 #endif
 }
 
-static void __init hv_smp_prepare_cpus(unsigned int max_cpus)
+static void __init hv_smp_prepare_cpus_for_snp(unsigned int max_cpus)
 {
-#ifdef CONFIG_X86_64
-       int i;
-       int ret;
-#endif
-
        native_smp_prepare_cpus(max_cpus);
+       apic->wakeup_secondary_cpu_64 = hv_snp_boot_ap;
+}
 
-       /*
-        *  Override wakeup_secondary_cpu_64 callback for SEV-SNP
-        *  enlightened guest.
-        */
-       if (!ms_hyperv.paravisor_present && hv_isolation_type_snp()) {
-               apic->wakeup_secondary_cpu_64 = hv_snp_boot_ap;
-               return;
-       }
-
-#ifdef CONFIG_X86_64
-       /* If AP LPs exist, we are in a kexec'd kernel and VPs already exist */
-       if (num_present_cpus() == 1 || hv_lp_exists(1))
-               return;
-
-       for_each_present_cpu(i) {
-               if (i == 0)
-                       continue;
-               ret = hv_call_add_logical_proc(numa_cpu_node(i), i, 
cpu_physical_id(i));
-               BUG_ON(ret);
-       }
-
-       ret = hv_call_notify_all_processors_started();
-       WARN_ON(ret);
-
-       for_each_present_cpu(i) {
-               if (i == 0)
-                       continue;
-               ret = hv_call_create_vp(numa_cpu_node(i), 
hv_current_partition_id, i, i);
-               BUG_ON(ret);
-       }
-#endif
+static void __init hv_smp_prepare_cpus_for_root(unsigned int max_cpus)
+{
+       native_smp_prepare_cpus(max_cpus);
+       hv_smp_prep_cpus();
 }
 #endif
 
@@ -722,9 +691,10 @@ static void __init ms_hyperv_init_platform(void)
 
 # ifdef CONFIG_SMP
        smp_ops.smp_prepare_boot_cpu = hv_smp_prepare_boot_cpu;
-       if (hv_root_partition() ||
-           (!ms_hyperv.paravisor_present && hv_isolation_type_snp()))
-               smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus;
+       if (!ms_hyperv.paravisor_present && hv_isolation_type_snp())
+               smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus_for_snp;
+       else if (hv_root_partition())
+               smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus_for_root;
 # endif
 
        /*
diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index 57b2c64197cb..b8aa76a7b19b 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -8,6 +8,7 @@
 #include <linux/minmax.h>
 #include <linux/export.h>
 #include <asm/mshyperv.h>
+#include <asm/numa.h>
 
 /*
  * See struct hv_deposit_memory. The first u64 is partition ID, the rest
@@ -154,7 +155,7 @@ bool hv_result_needs_memory(u64 status)
 }
 EXPORT_SYMBOL_GPL(hv_result_needs_memory);
 
-int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
+static int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 {
        struct hv_input_add_logical_processor *input;
        struct hv_output_add_logical_processor *output;
@@ -240,7 +241,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 
vp_index, u32 flags)
 }
 EXPORT_SYMBOL_GPL(hv_call_create_vp);
 
-int hv_call_notify_all_processors_started(void)
+static int hv_call_notify_all_processors_started(void)
 {
        struct hv_input_notify_partition_event *input;
        u64 status;
@@ -262,7 +263,7 @@ int hv_call_notify_all_processors_started(void)
        return ret;
 }
 
-bool hv_lp_exists(u32 lp_index)
+static bool hv_lp_exists(u32 lp_index)
 {
        struct hv_input_get_logical_processor_run_time *input;
        struct hv_output_get_logical_processor_run_time *output;
@@ -286,3 +287,31 @@ bool hv_lp_exists(u32 lp_index)
 
        return hv_result_success(status);
 }
+
+void hv_smp_prep_cpus(void)
+{
+#ifdef CONFIG_X86_64
+       int i, ret;
+
+       /* If AP LPs exist, we are in a kexec'd kernel and VPs already exist */
+       if (num_present_cpus() == 1 || hv_lp_exists(1))
+               return;
+
+       for_each_present_cpu(i) {
+               if (i == 0)
+                       continue;
+               ret = hv_call_add_logical_proc(numa_cpu_node(i), i, 
cpu_physical_id(i));
+               BUG_ON(ret);
+       }
+
+       ret = hv_call_notify_all_processors_started();
+       WARN_ON(ret);
+
+       for_each_present_cpu(i) {
+               if (i == 0)
+                       continue;
+               ret = hv_call_create_vp(numa_cpu_node(i), 
hv_current_partition_id, i, i);
+               BUG_ON(ret);
+       }
+#endif
+}
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index bf601d67cecb..ea1c4acda1ec 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -346,9 +346,7 @@ static inline bool hv_parent_partition(void)
 bool hv_result_needs_memory(u64 status);
 int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
-int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
-int hv_call_notify_all_processors_started(void);
-bool hv_lp_exists(u32 lp_index);
+void hv_smp_prep_cpus(void);
 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
 
 #else /* CONFIG_MSHV_ROOT */
@@ -364,18 +362,7 @@ static inline int hv_call_deposit_pages(int node, u64 
partition_id, u32 num_page
 {
        return -EOPNOTSUPP;
 }
-static inline int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id)
-{
-       return -EOPNOTSUPP;
-}
-static inline int hv_call_notify_all_processors_started(void)
-{
-       return -EOPNOTSUPP;
-}
-static inline bool hv_lp_exists(u32 lp_index)
-{
-       return false;
-}
+static inline void hv_smp_prep_cpus(void) {}
 static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, 
u32 flags)
 {
        return -EOPNOTSUPP;
-- 
2.25.1


Reply via email to