* [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus()
@ 2026-05-21 19:23 Michael Kelley
2026-05-25 7:37 ` kernel test robot
2026-05-25 11:42 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: Michael Kelley @ 2026-05-21 19:23 UTC (permalink / raw)
To: kys, haiyangz, wei.liu, decui, longli, tglx, mingo, bp,
dave.hansen, x86, hpa, linux-hyperv, linux-kernel, linux-arch
From: Michael Kelley <mhklinux@outlook.com>
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 <mhklinux@outlook.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus()
2026-05-21 19:23 [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus() Michael Kelley
@ 2026-05-25 7:37 ` kernel test robot
2026-05-25 11:42 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-05-25 7:37 UTC (permalink / raw)
To: Michael Kelley, kys, haiyangz, wei.liu, decui, longli, tglx,
mingo, bp, dave.hansen, x86, hpa, linux-hyperv, linux-kernel,
linux-arch
Cc: oe-kbuild-all
Hi Michael,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/master]
[also build test ERROR on linus/master v7.1-rc5 next-20260522]
[cannot apply to tip/x86/core arnd-asm-generic/master tip/auto-latest]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Michael-Kelley/x86-hyperv-Refactor-hv_smp_prepare_cpus/20260522-032610
base: tip/master
patch link: https://lore.kernel.org/r/20260521192336.99623-1-mhklkml%40zohomail.com
patch subject: [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus()
config: x86_64-buildonly-randconfig-006-20260525 (https://download.01.org/0day-ci/archive/20260525/202605251528.eVtKHPbX-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260525/202605251528.eVtKHPbX-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605251528.eVtKHPbX-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/hv/hv_proc.c: In function 'hv_smp_prep_cpus':
>> drivers/hv/hv_proc.c:303:69: error: implicit declaration of function 'cpu_physical_id' [-Wimplicit-function-declaration]
303 | ret = hv_call_add_logical_proc(numa_cpu_node(i), i, cpu_physical_id(i));
| ^~~~~~~~~~~~~~~
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for MFD_STMFX
Depends on [n]: HAS_IOMEM [=y] && I2C [=y] && OF [=n]
Selected by [y]:
- PINCTRL_STMFX [=y] && PINCTRL [=y] && I2C [=y] && HAS_IOMEM [=y]
vim +/cpu_physical_id +303 drivers/hv/hv_proc.c
290
291 void hv_smp_prep_cpus(void)
292 {
293 #ifdef CONFIG_X86_64
294 int i, ret;
295
296 /* If AP LPs exist, we are in a kexec'd kernel and VPs already exist */
297 if (num_present_cpus() == 1 || hv_lp_exists(1))
298 return;
299
300 for_each_present_cpu(i) {
301 if (i == 0)
302 continue;
> 303 ret = hv_call_add_logical_proc(numa_cpu_node(i), i, cpu_physical_id(i));
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus()
2026-05-21 19:23 [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus() Michael Kelley
2026-05-25 7:37 ` kernel test robot
@ 2026-05-25 11:42 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-05-25 11:42 UTC (permalink / raw)
To: Michael Kelley, kys, haiyangz, wei.liu, decui, longli, tglx,
mingo, bp, dave.hansen, x86, hpa, linux-hyperv, linux-kernel,
linux-arch
Cc: llvm, oe-kbuild-all
Hi Michael,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/master]
[also build test ERROR on linus/master v7.1-rc5 next-20260522]
[cannot apply to tip/x86/core arnd-asm-generic/master tip/auto-latest]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Michael-Kelley/x86-hyperv-Refactor-hv_smp_prepare_cpus/20260522-032610
base: tip/master
patch link: https://lore.kernel.org/r/20260521192336.99623-1-mhklkml%40zohomail.com
patch subject: [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus()
config: x86_64-randconfig-076-20260524 (https://download.01.org/0day-ci/archive/20260525/202605251945.TesslTvF-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260525/202605251945.TesslTvF-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605251945.TesslTvF-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/hv/hv_proc.c:303:55: error: call to undeclared function 'cpu_physical_id'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
303 | ret = hv_call_add_logical_proc(numa_cpu_node(i), i, cpu_physical_id(i));
| ^
1 error generated.
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for MFD_STMFX
Depends on [n]: HAS_IOMEM [=y] && I2C [=y] && OF [=n]
Selected by [y]:
- PINCTRL_STMFX [=y] && PINCTRL [=y] && I2C [=y] && HAS_IOMEM [=y]
vim +/cpu_physical_id +303 drivers/hv/hv_proc.c
290
291 void hv_smp_prep_cpus(void)
292 {
293 #ifdef CONFIG_X86_64
294 int i, ret;
295
296 /* If AP LPs exist, we are in a kexec'd kernel and VPs already exist */
297 if (num_present_cpus() == 1 || hv_lp_exists(1))
298 return;
299
300 for_each_present_cpu(i) {
301 if (i == 0)
302 continue;
> 303 ret = hv_call_add_logical_proc(numa_cpu_node(i), i, cpu_physical_id(i));
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-25 11:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-21 19:23 [PATCH 1/1] x86/hyperv: Refactor hv_smp_prepare_cpus() Michael Kelley
2026-05-25 7:37 ` kernel test robot
2026-05-25 11:42 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox