Skip to contentSkip to conversation

ACPI: processor: Fix build when CONFIG_ACPI_PROCESSOR=m

PATCH Superseded Vitaly Kuznetsov 2 participants 3 messages Apr 6, 2021

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: processor: Fix build when CONFIG_ACPI_PROCESSOR=m

Commit 8cdddd182bd7 ("ACPI: processor: Fix CPU0 wakeup in acpi_idle_play_dead()") tried to fix CPU0 hotplug breakage by copying wakeup_cpu0() + start_cpu0() logic from hlt_play_dead()//mwait_play_dead() into acpi_idle_play_dead(). The problem is that these functions are not exported to modules so when CONFIG_ACPI_PROCESSOR=m build fails.

The issue could've been fixed by exporting both wakeup_cpu0()/start_cpu0() (the later from assembly) but it seems putting the whole pattern into a new function and exporting it instead is better.

Fixes 8cdddd182bd7 ("CPI: processor: Fix CPU0 wakeup in acpi_idle_play_dead()")
Cc <[email protected]> # 5.10+
---
 arch/x86/include/asm/smp.h    |  2 +-
 arch/x86/kernel/smpboot.c     | 15 ++++++++++-----
 drivers/acpi/processor_idle.c |  3 +--
 3 files changed, 12 insertions(+), 8 deletions(-)
arch/x86/include/asm/smp.h +1 -1
index 57ef2094af93..6f79deb1f970 100644
@@ -132,7 +132,7 @@ void native_play_dead(void);
 void play_dead_common(void);
 void wbinvd_on_cpu(int cpu);
 int wbinvd_on_all_cpus(void);
-bool wakeup_cpu0(void);
+void wakeup_cpu0_if_needed(void);
 
 void native_smp_send_reschedule(int cpu);
 void native_send_call_func_ipi(const struct cpumask *mask);
arch/x86/kernel/smpboot.c +10 -5
index f877150a91da..9547d870ee27 100644
@@ -1659,7 +1659,7 @@ void play_dead_common(void)
 	local_irq_disable();
 }
 
-bool wakeup_cpu0(void)
+static bool wakeup_cpu0(void)
 {
 	if (smp_processor_id() == 0 && enable_start_cpu0)
 		return true;
@@ -1667,6 +1667,13 @@ bool wakeup_cpu0(void)
 	return false;
 }
 
+void wakeup_cpu0_if_needed(void)
+{
+	if (wakeup_cpu0())
+		start_cpu0();
+}
+EXPORT_SYMBOL_GPL(wakeup_cpu0_if_needed);
+
 /*
  * We need to flush the caches before going to sleep, lest we have
  * dirty data in our caches when we come back up.
@@ -1737,8 +1744,7 @@ static inline void mwait_play_dead(void)
 		/*
 		 * If NMI wants to wake up CPU0, start CPU0.
 		 */
-		if (wakeup_cpu0())
-			start_cpu0();
+		wakeup_cpu0_if_needed();
 	}
 }
 
@@ -1752,8 +1758,7 @@ void hlt_play_dead(void)
 		/*
 		 * If NMI wants to wake up CPU0, start CPU0.
 		 */
-		if (wakeup_cpu0())
-			start_cpu0();
+		wakeup_cpu0_if_needed();
 	}
 }
 
drivers/acpi/processor_idle.c +1 -2
index 768a6b4d2368..de15116b754a 100644
@@ -545,8 +545,7 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
 
 #if defined(CONFIG_X86) && defined(CONFIG_HOTPLUG_CPU)
 		/* If NMI wants to wake up CPU0, start CPU0. */
-		if (wakeup_cpu0())
-			start_cpu0();
+		wakeup_cpu0_if_needed();
 #endif
 	}
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 48 lines · Vitaly Kuznetsov

Commit 8cdddd182bd7 ("ACPI: processor: Fix CPU0 wakeup in acpi_idle_play_dead()") tried to fix CPU0 hotplug breakage by copying wakeup_cpu0() + start_cpu0() logic from hlt_play_dead()//mwait_play_dead() into acpi_idle_play_dead(). The problem is that these functions are not exported to modules so when CONFIG_ACPI_PROCESSOR=m build fails.

The issue could've been fixed by exporting both wakeup_cpu0()/start_cpu0() (the later from assembly) but it seems putting the whole pattern into a new function and exporting it instead is better.

Fixes 8cdddd182bd7 ("CPI: processor: Fix CPU0 wakeup in acpi_idle_play_dead()")
Cc <[email protected]> # 5.10+
---
 arch/x86/include/asm/smp.h    |  2 +-
 arch/x86/kernel/smpboot.c     | 15 ++++++++++-----
 drivers/acpi/processor_idle.c |  3 +--
 3 files changed, 12 insertions(+), 8 deletions(-)
arch/x86/include/asm/smp.h +1 -1
index 57ef2094af93..6f79deb1f970 100644
@@ -132,7 +132,7 @@ void native_play_dead(void);
 void play_dead_common(void);
 void wbinvd_on_cpu(int cpu);
 int wbinvd_on_all_cpus(void);
-bool wakeup_cpu0(void);
+void wakeup_cpu0_if_needed(void);
 
 void native_smp_send_reschedule(int cpu);
 void native_send_call_func_ipi(const struct cpumask *mask);
arch/x86/kernel/smpboot.c +1 -1
index f877150a91da..9547d870ee27 100644
@@ -1659,7 +1659,7 @@ void play_dead_common(void)
        local_irq_disable();
 }
 
-bool wakeup_cpu0(void)
+static bool wakeup_cpu0(void)
 {
        if (smp_processor_id() == 0 && enable_start_cpu0)
                return true;

arch/x86/kernel/smpboot.c bool wakeup_cpu0(void) · line 1673

Quoted 7 lines
arch/x86/kernel/smpboot.c +4 -0
@@ -1667,6 +1667,13 @@ bool wakeup_cpu0(void)
        return false;
 }
 
+void wakeup_cpu0_if_needed(void)
+{
+       if (wakeup_cpu0())
+               start_cpu0();

Note that all of the callers of wakeup_cpu0 do the above, so maybe make them all use the new function?

In which case it can be rewritten in the following way

void cond_wakeup_cpu0(void)

{
        if (smp_processor_id() == 0 && enable_start_cpu0)
                start_cpu0();
}

EXPORT_SYMBOL_GPL(cond_wakeup_cpu0);

Also please add a proper kerneldoc comment to it and maybe drop the comments at the call sites?

Quoted 43 lines
arch/x86/kernel/smpboot.c +5 -4
+}
+EXPORT_SYMBOL_GPL(wakeup_cpu0_if_needed);
+
 /*
  * We need to flush the caches before going to sleep, lest we have
  * dirty data in our caches when we come back up.
@@ -1737,8 +1744,7 @@ static inline void mwait_play_dead(void)
                /*
                 * If NMI wants to wake up CPU0, start CPU0.
                 */
-               if (wakeup_cpu0())
-                       start_cpu0();
+               wakeup_cpu0_if_needed();
        }
 }
 
@@ -1752,8 +1758,7 @@ void hlt_play_dead(void)
                /*
                 * If NMI wants to wake up CPU0, start CPU0.
                 */
-               if (wakeup_cpu0())
-                       start_cpu0();
+               wakeup_cpu0_if_needed();
        }
 }
 
drivers/acpi/processor_idle.c +1 -3
index 768a6b4d2368..de15116b754a 100644
@@ -545,8 +545,7 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
 
 #if defined(CONFIG_X86) && defined(CONFIG_HOTPLUG_CPU)
                /* If NMI wants to wake up CPU0, start CPU0. */
-               if (wakeup_cpu0())
-                       start_cpu0();
+               wakeup_cpu0_if_needed();
 #endif
        }
 
--

2.30.2

#2 lore raw
Quoted 60 lines · Rafael J. Wysocki
Quoted 48 lines · Vitaly Kuznetsov

Commit 8cdddd182bd7 ("ACPI: processor: Fix CPU0 wakeup in acpi_idle_play_dead()") tried to fix CPU0 hotplug breakage by copying wakeup_cpu0() + start_cpu0() logic from hlt_play_dead()//mwait_play_dead() into acpi_idle_play_dead(). The problem is that these functions are not exported to modules so when CONFIG_ACPI_PROCESSOR=m build fails.

The issue could've been fixed by exporting both wakeup_cpu0()/start_cpu0() (the later from assembly) but it seems putting the whole pattern into a new function and exporting it instead is better.

Fixes 8cdddd182bd7 ("CPI: processor: Fix CPU0 wakeup in acpi_idle_play_dead()")
Cc <[email protected]> # 5.10+
---
 arch/x86/include/asm/smp.h    |  2 +-
 arch/x86/kernel/smpboot.c     | 15 ++++++++++-----
 drivers/acpi/processor_idle.c |  3 +--
 3 files changed, 12 insertions(+), 8 deletions(-)
arch/x86/include/asm/smp.h +1 -1
index 57ef2094af93..6f79deb1f970 100644
@@ -132,7 +132,7 @@ void native_play_dead(void);
 void play_dead_common(void);
 void wbinvd_on_cpu(int cpu);
 int wbinvd_on_all_cpus(void);
-bool wakeup_cpu0(void);
+void wakeup_cpu0_if_needed(void);
 
 void native_smp_send_reschedule(int cpu);
 void native_send_call_func_ipi(const struct cpumask *mask);
arch/x86/kernel/smpboot.c +1 -1
index f877150a91da..9547d870ee27 100644
@@ -1659,7 +1659,7 @@ void play_dead_common(void)
        local_irq_disable();
 }
 
-bool wakeup_cpu0(void)
+static bool wakeup_cpu0(void)
 {
        if (smp_processor_id() == 0 && enable_start_cpu0)
                return true;

arch/x86/kernel/smpboot.c bool wakeup_cpu0(void) · line 1673

Quoted 7 lines
arch/x86/kernel/smpboot.c +4 -0
@@ -1667,6 +1667,13 @@ bool wakeup_cpu0(void)
        return false;
 }
 
+void wakeup_cpu0_if_needed(void)
+{
+       if (wakeup_cpu0())
+               start_cpu0();

Note that all of the callers of wakeup_cpu0 do the above, so maybe make them all use the new function?

Quoted 9 lines

In which case it can be rewritten in the following way

void cond_wakeup_cpu0(void)

{
        if (smp_processor_id() == 0 && enable_start_cpu0)
                start_cpu0();
}

EXPORT_SYMBOL_GPL(cond_wakeup_cpu0);

Sure, separate wakeup_cpu0() is no longer needed.

Quoted 2 lines

Also please add a proper kerneldoc comment to it and maybe drop the comments at the call sites?

Also a good idea. v2 is coming, thanks!

Quoted 46 lines
Quoted 45 lines
arch/x86/kernel/smpboot.c +5 -4
+}
+EXPORT_SYMBOL_GPL(wakeup_cpu0_if_needed);
+
 /*
  * We need to flush the caches before going to sleep, lest we have
  * dirty data in our caches when we come back up.
@@ -1737,8 +1744,7 @@ static inline void mwait_play_dead(void)
                /*
                 * If NMI wants to wake up CPU0, start CPU0.
                 */
-               if (wakeup_cpu0())
-                       start_cpu0();
+               wakeup_cpu0_if_needed();
        }
 }
 
@@ -1752,8 +1758,7 @@ void hlt_play_dead(void)
                /*
                 * If NMI wants to wake up CPU0, start CPU0.
                 */
-               if (wakeup_cpu0())
-                       start_cpu0();
+               wakeup_cpu0_if_needed();
        }
 }
 
drivers/acpi/processor_idle.c +1 -3
index 768a6b4d2368..de15116b754a 100644
@@ -545,8 +545,7 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
 
 #if defined(CONFIG_X86) && defined(CONFIG_HOTPLUG_CPU)
                /* If NMI wants to wake up CPU0, start CPU0. */
-               if (wakeup_cpu0())
-                       start_cpu0();
+               wakeup_cpu0_if_needed();
 #endif
        }
 
--

2.30.2

Signature · 1 line
Vitaly