[PATCH] x86/smp: Fix mwait_play_dead() and acpi_processor_ffh_play_dead() noreturn behavior

Josh Poimboeuf posted 1 patch 11 months, 1 week ago
There is a newer version of this series
arch/x86/include/asm/smp.h    | 4 ++--
arch/x86/kernel/acpi/cstate.c | 2 +-
include/acpi/processor.h      | 6 +++---
tools/objtool/noreturns.h     | 2 ++
4 files changed, 8 insertions(+), 6 deletions(-)
[PATCH] x86/smp: Fix mwait_play_dead() and acpi_processor_ffh_play_dead() noreturn behavior
Posted by Josh Poimboeuf 11 months, 1 week ago
Fix some related issues (done in a single patch to avoid introducing
intermediate bisect warnings):

  1) The SMP version of mwait_play_dead() doesn't return, but its
     !SMP counterpart does.  Make its calling behavior consistent by
     resolving the !SMP version to a BUG().  It should never be called
     anyway, this just enforces that at runtime and enables its callers
     to be marked as __noreturn.

  2) While the SMP definition of mwait_play_dead() is annotated as
     __noreturn, the declaration isn't.  Nor is it listed in
     tools/objtool/noreturns.h.  Fix that.

  3) Similar to #1, the SMP version of acpi_processor_ffh_play_dead()
     doesn't return but its !SMP counterpart does.  Make the !SMP
     version a BUG().  It should never be called.

  4) acpi_processor_ffh_play_dead() doesn't return, but is lacking any
     __noreturn annotations.  Fix that.

This fixes the following warnings:

  vmlinux.o: warning: objtool: acpi_processor_ffh_play_dead+0x67: mwait_play_dead() is missing a __noreturn annotation
  vmlinux.o: warning: objtool: acpi_idle_play_dead+0x3c: acpi_processor_ffh_play_dead() is missing a __noreturn annotation

Fixes: a7dd183f0b38 ("x86/smp: Allow calling mwait_play_dead with an arbitrary hint")
Fixes: 541ddf31e300 ("ACPI/processor_idle: Add FFH state handling")
Reported-by: Paul E. McKenney <paulmck@kernel.org>
Tested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 arch/x86/include/asm/smp.h    | 4 ++--
 arch/x86/kernel/acpi/cstate.c | 2 +-
 include/acpi/processor.h      | 6 +++---
 tools/objtool/noreturns.h     | 2 ++
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 80f8bfd83fc7..1d3b11eba084 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -114,7 +114,7 @@ void wbinvd_on_cpu(int cpu);
 int wbinvd_on_all_cpus(void);
 
 void smp_kick_mwait_play_dead(void);
-void mwait_play_dead(unsigned int eax_hint);
+void __noreturn mwait_play_dead(unsigned int eax_hint);
 
 void native_smp_send_reschedule(int cpu);
 void native_send_call_func_ipi(const struct cpumask *mask);
@@ -166,7 +166,7 @@ static inline struct cpumask *cpu_llc_shared_mask(int cpu)
 	return (struct cpumask *)cpumask_of(0);
 }
 
-static inline void mwait_play_dead(unsigned int eax_hint) { }
+static inline void __noreturn mwait_play_dead(unsigned int eax_hint) { BUG(); }
 #endif /* CONFIG_SMP */
 
 #ifdef CONFIG_DEBUG_NMI_SELFTEST
diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c
index 86c87c01d23d..d25584255ab8 100644
--- a/arch/x86/kernel/acpi/cstate.c
+++ b/arch/x86/kernel/acpi/cstate.c
@@ -206,7 +206,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,
 }
 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe);
 
-void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
+void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
 {
 	unsigned int cpu = smp_processor_id();
 	struct cstate_entry *percpu_entry;
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 63a37e72b721..d0eccbd920e5 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -280,7 +280,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,
 				    struct acpi_processor_cx *cx,
 				    struct acpi_power_register *reg);
 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
-void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx);
+void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx);
 #else
 static inline void acpi_processor_power_init_bm_check(struct
 						      acpi_processor_flags
@@ -301,9 +301,9 @@ static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
 {
 	return;
 }
-static inline void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
+static inline void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
 {
-	return;
+	BUG();
 }
 #endif
 
diff --git a/tools/objtool/noreturns.h b/tools/objtool/noreturns.h
index b2174894f9f7..5a4aec4c4639 100644
--- a/tools/objtool/noreturns.h
+++ b/tools/objtool/noreturns.h
@@ -16,6 +16,7 @@ NORETURN(__tdx_hypercall_failed)
 NORETURN(__ubsan_handle_builtin_unreachable)
 NORETURN(__x64_sys_exit)
 NORETURN(__x64_sys_exit_group)
+NORETURN(acpi_processor_ffh_play_dead)
 NORETURN(arch_cpu_idle_dead)
 NORETURN(bch2_trans_in_restart_error)
 NORETURN(bch2_trans_restart_error)
@@ -34,6 +35,7 @@ NORETURN(kunit_try_catch_throw)
 NORETURN(machine_real_restart)
 NORETURN(make_task_dead)
 NORETURN(mpt_halt_firmware)
+NORETURN(mwait_play_dead)
 NORETURN(nmi_panic_self_stop)
 NORETURN(panic)
 NORETURN(panic_smp_self_stop)
-- 
2.48.1
Re: [PATCH] x86/smp: Fix mwait_play_dead() and acpi_processor_ffh_play_dead() noreturn behavior
Posted by Wysocki, Rafael J 11 months, 1 week ago
On 3/3/2025 1:48 AM, Josh Poimboeuf wrote:
> Fix some related issues (done in a single patch to avoid introducing
> intermediate bisect warnings):
>
>    1) The SMP version of mwait_play_dead() doesn't return, but its
>       !SMP counterpart does.  Make its calling behavior consistent by
>       resolving the !SMP version to a BUG().  It should never be called
>       anyway, this just enforces that at runtime and enables its callers
>       to be marked as __noreturn.
>
>    2) While the SMP definition of mwait_play_dead() is annotated as
>       __noreturn, the declaration isn't.  Nor is it listed in
>       tools/objtool/noreturns.h.  Fix that.
>
>    3) Similar to #1, the SMP version of acpi_processor_ffh_play_dead()
>       doesn't return but its !SMP counterpart does.  Make the !SMP
>       version a BUG().  It should never be called.
>
>    4) acpi_processor_ffh_play_dead() doesn't return, but is lacking any
>       __noreturn annotations.  Fix that.
>
> This fixes the following warnings:
>
>    vmlinux.o: warning: objtool: acpi_processor_ffh_play_dead+0x67: mwait_play_dead() is missing a __noreturn annotation
>    vmlinux.o: warning: objtool: acpi_idle_play_dead+0x3c: acpi_processor_ffh_play_dead() is missing a __noreturn annotation
>
> Fixes: a7dd183f0b38 ("x86/smp: Allow calling mwait_play_dead with an arbitrary hint")
> Fixes: 541ddf31e300 ("ACPI/processor_idle: Add FFH state handling")
> Reported-by: Paul E. McKenney <paulmck@kernel.org>
> Tested-by: Paul E. McKenney <paulmck@kernel.org>
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>


> ---
>   arch/x86/include/asm/smp.h    | 4 ++--
>   arch/x86/kernel/acpi/cstate.c | 2 +-
>   include/acpi/processor.h      | 6 +++---
>   tools/objtool/noreturns.h     | 2 ++
>   4 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
> index 80f8bfd83fc7..1d3b11eba084 100644
> --- a/arch/x86/include/asm/smp.h
> +++ b/arch/x86/include/asm/smp.h
> @@ -114,7 +114,7 @@ void wbinvd_on_cpu(int cpu);
>   int wbinvd_on_all_cpus(void);
>   
>   void smp_kick_mwait_play_dead(void);
> -void mwait_play_dead(unsigned int eax_hint);
> +void __noreturn mwait_play_dead(unsigned int eax_hint);
>   
>   void native_smp_send_reschedule(int cpu);
>   void native_send_call_func_ipi(const struct cpumask *mask);
> @@ -166,7 +166,7 @@ static inline struct cpumask *cpu_llc_shared_mask(int cpu)
>   	return (struct cpumask *)cpumask_of(0);
>   }
>   
> -static inline void mwait_play_dead(unsigned int eax_hint) { }
> +static inline void __noreturn mwait_play_dead(unsigned int eax_hint) { BUG(); }
>   #endif /* CONFIG_SMP */
>   
>   #ifdef CONFIG_DEBUG_NMI_SELFTEST
> diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c
> index 86c87c01d23d..d25584255ab8 100644
> --- a/arch/x86/kernel/acpi/cstate.c
> +++ b/arch/x86/kernel/acpi/cstate.c
> @@ -206,7 +206,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,
>   }
>   EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe);
>   
> -void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
> +void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
>   {
>   	unsigned int cpu = smp_processor_id();
>   	struct cstate_entry *percpu_entry;
> diff --git a/include/acpi/processor.h b/include/acpi/processor.h
> index 63a37e72b721..d0eccbd920e5 100644
> --- a/include/acpi/processor.h
> +++ b/include/acpi/processor.h
> @@ -280,7 +280,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,
>   				    struct acpi_processor_cx *cx,
>   				    struct acpi_power_register *reg);
>   void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
> -void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx);
> +void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx);
>   #else
>   static inline void acpi_processor_power_init_bm_check(struct
>   						      acpi_processor_flags
> @@ -301,9 +301,9 @@ static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
>   {
>   	return;
>   }
> -static inline void acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
> +static inline void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx)
>   {
> -	return;
> +	BUG();
>   }
>   #endif
>   
> diff --git a/tools/objtool/noreturns.h b/tools/objtool/noreturns.h
> index b2174894f9f7..5a4aec4c4639 100644
> --- a/tools/objtool/noreturns.h
> +++ b/tools/objtool/noreturns.h
> @@ -16,6 +16,7 @@ NORETURN(__tdx_hypercall_failed)
>   NORETURN(__ubsan_handle_builtin_unreachable)
>   NORETURN(__x64_sys_exit)
>   NORETURN(__x64_sys_exit_group)
> +NORETURN(acpi_processor_ffh_play_dead)
>   NORETURN(arch_cpu_idle_dead)
>   NORETURN(bch2_trans_in_restart_error)
>   NORETURN(bch2_trans_restart_error)
> @@ -34,6 +35,7 @@ NORETURN(kunit_try_catch_throw)
>   NORETURN(machine_real_restart)
>   NORETURN(make_task_dead)
>   NORETURN(mpt_halt_firmware)
> +NORETURN(mwait_play_dead)
>   NORETURN(nmi_panic_self_stop)
>   NORETURN(panic)
>   NORETURN(panic_smp_self_stop)