cpu,sched: Mark arch_cpu_idle_dead() __noreturn
Subsystems (19)
Josh Poimboeuf
maintainercover cpu,sched: Mark arch_cpu_idle_dead() __noreturn
These are some minor changes to enable the __noreturn attribute for arch_cpu_idle_dead(). (If there are no objections, I can merge the entire set through the tip tree.)
Until recently [1], in Xen, when a previously offlined CPU was brought back online, it unexpectedly resumed execution where it left off in the middle of the idle loop by returning from play_dead() and its caller arch_cpu_idle_dead().
There were some clever hacks to make that work, but the behavior was surprising as do_idle() doesn't expect an offlined CPU to return from the dead in the middle of the function.
Now that Xen has been fixed, make sure arch_cpu_idle_dead() never returns by marking it __noreturn. This causes the compiler to complain if an arch-specific implementation might return. It also improves code generation for both caller and callee.
Patches 1-20 update the arch-specific implementations of the function so they don't actually return (even in error cases), and make that visible to the compiler. That's typically done by ending the function with a call to another noreturn function, or with a BUG().
Patch 21 fixes the weak implementation.
Patch 22 actually adds the __noreturn attribute.
[1] 076cbf5d2163 ("x86/xen: don't let xen_pv_play_dead() return")
Josh Poimboeuf (22):
alpha/cpu: Expose arch_cpu_idle_dead()'s prototype declaration alpha/cpu: Make sure arch_cpu_idle_dead() doesn't return arm/cpu: Make sure arch_cpu_idle_dead() doesn't return arm64/cpu: Mark cpu_die() __noreturn
csky/cpu: Make sure arch_cpu_idle_dead() doesn't return ia64/cpu: Mark play_dead() __noreturn
loongarch/cpu: Make sure play_dead() doesn't return loongarch/cpu: Mark play_dead() __noreturn
mips/cpu: Expose play_dead()'s prototype definition mips/cpu: Make sure play_dead() doesn't return mips/cpu: Mark play_dead() __noreturn
powerpc/cpu: Mark start_secondary_resume() __noreturn sh/cpu: Make sure play_dead() doesn't return
sh/cpu: Mark play_dead() __noreturn
sh/cpu: Expose arch_cpu_idle_dead()'s prototype definition sparc/cpu: Mark cpu_play_dead() __noreturn
x86/cpu: Make sure play_dead() doesn't return
x86/cpu: Mark play_dead() __noreturn
xtensa/cpu: Make sure cpu_die() doesn't return xtensa/cpu: Mark cpu_die() __noreturn
sched/idle: Make sure weak version of arch_cpu_idle_dead() doesn't
return
sched/idle: Mark arch_cpu_idle_dead() __noreturn
arch/alpha/kernel/process.c | 2 ++ arch/arm/kernel/smp.c | 2 ++ arch/arm64/include/asm/smp.h | 2 +- arch/csky/kernel/smp.c | 2 ++ arch/ia64/kernel/process.c | 4 ++-- arch/loongarch/include/asm/smp.h | 2 +- arch/loongarch/kernel/smp.c | 2 +- arch/mips/include/asm/smp.h | 2 +- arch/mips/kernel/smp-bmips.c | 3 +++ arch/mips/loongson64/smp.c | 1 + arch/powerpc/include/asm/smp.h | 2 +- arch/sh/include/asm/smp-ops.h | 5 +++-- arch/sh/kernel/idle.c | 1 + arch/sparc/include/asm/smp_64.h | 2 +- arch/x86/include/asm/smp.h | 3 ++- arch/x86/kernel/process.c | 2 +- arch/xtensa/include/asm/smp.h | 2 +- arch/xtensa/kernel/smp.c | 2 ++ include/linux/cpu.h | 2 +- kernel/sched/idle.c | 2 +- tools/objtool/check.c | 1 + 21 files changed, 31 insertions(+), 15 deletions(-)
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 1/22 alpha/cpu: Expose arch_cpu_idle_dead()'s prototype declaration
Include <linux/cpu.h> to make sure arch_cpu_idle_dead() matches its prototype going forward.
--- arch/alpha/kernel/process.c | 1 + 1 file changed, 1 insertion(+)
arch/alpha/kernel/process.c +1 -0
@@ -9,6 +9,7 @@* This file handles the architecture-dependent parts of process handling. */ +#include <linux/cpu.h> #include <linux/errno.h> #include <linux/module.h> #include <linux/sched.h>
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 2/22 alpha/cpu: Make sure arch_cpu_idle_dead() doesn't return
In reply to Josh Poimboeufarch_cpu_idle_dead() doesn't return. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/alpha/kernel/process.c | 1 + 1 file changed, 1 insertion(+)
arch/alpha/kernel/process.c +1 -0
@@ -63,6 +63,7 @@ void arch_cpu_idle(void)void arch_cpu_idle_dead (void ) {wtint (INT_MAX ); +BUG (); }#endif /* ALPHA_WTINT */
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 3/22 arm/cpu: Make sure arch_cpu_idle_dead() doesn't return
In reply to Josh Poimboeufarch_cpu_idle_dead() doesn't return. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/arm/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/kernel/smp.c +2 -0
@@ -382,6 +382,8 @@ void arch_cpu_idle_dead(void) : "r" (task_stack_page(current) + THREAD_SIZE - 8), "r" (current) : "r0"); + + BUG(); }#endif /* CONFIG_HOTPLUG_CPU */
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 4/22 arm64/cpu: Mark cpu_die() __noreturn
In reply to Josh Poimboeufcpu_die() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/arm64/include/asm/smp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/smp.h +1 -1
@@ -100,7 +100,7 @@ static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask)extern int __cpu_disable (void );extern void __cpu_die (unsigned int cpu); -extern void cpu_die (void ); +extern void __noreturn cpu_die (void );extern void cpu_die_early (void );static inline void cpu_park_loop (void )
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 5/22 csky/cpu: Make sure arch_cpu_idle_dead() doesn't return
In reply to Josh Poimboeufarch_cpu_idle_dead() doesn't return. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/csky/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+)
arch/csky/kernel/smp.c +2 -0
@@ -317,5 +317,7 @@ void arch_cpu_idle_dead(void) "jmpi csky_start_secondary" : : "r" (secondary_stack)); + + BUG(); }#endif
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 6/22 ia64/cpu: Mark play_dead() __noreturn
In reply to Josh Poimboeufplay_dead() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/ia64/kernel/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/ia64/kernel/process.c +2 -2
@@ -201,7 +201,7 @@ __setup("nohalt", nohalt_setup);#ifdef CONFIG_HOTPLUG_CPU /* We don't actually take CPU down, just spin without interrupts. */ -static inline void play_dead (void ) +static inline void __noreturn play_dead (void ) {unsigned int this_cpu =smp_processor_id ();
@@ -219,7 +219,7 @@ static inline void play_dead(void) BUG(); }#else -static inline void play_dead (void ) +static inline void __noreturn play_dead (void ) {BUG (); }
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 7/22 loongarch/cpu: Make sure play_dead() doesn't return
In reply to Josh Poimboeufplay_dead() doesn't return. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/loongarch/kernel/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/kernel/smp.c +1 -1
@@ -336,7 +336,7 @@ void play_dead(void)iocsr_write32 (0xffffffff ,LOONGARCH_IOCSR_IPI_CLEAR );init_fn (); - unreachable(); + BUG(); }#endif
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 8/22 loongarch/cpu: Mark play_dead() __noreturn
In reply to Josh Poimboeufplay_dead() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/loongarch/include/asm/smp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/include/asm/smp.h +1 -1
@@ -99,7 +99,7 @@ static inline void __cpu_die(unsigned int cpu)loongson_cpu_die (cpu); } -extern void play_dead (void ); +extern void __noreturn play_dead (void );#endif #endif /* __ASM_SMP_H */
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 9/22 mips/cpu: Expose play_dead()'s prototype definition
In reply to Josh PoimboeufInclude <asm/smp.h> to make sure play_dead() matches its prototype going forward.
--- arch/mips/kernel/smp-bmips.c | 1 + 1 file changed, 1 insertion(+)
arch/mips/kernel/smp-bmips.c +1 -0
@@ -38,6 +38,7 @@#include <asm/traps.h> #include <asm/barrier.h> #include <asm/cpu-features.h> +#include <asm/smp.h> static int __maybe_unused max_cpus =1 ;
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 10/22 mips/cpu: Make sure play_dead() doesn't return
In reply to Josh Poimboeufplay_dead() doesn't return. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/mips/kernel/smp-bmips.c | 2 ++ arch/mips/loongson64/smp.c | 1 + 2 files changed, 3 insertions(+)
arch/mips/kernel/smp-bmips.c +2 -0
@@ -414,6 +414,8 @@ void __ref play_dead(void) " wait\n" " j bmips_secondary_reentry\n" : : : "memory"); + + BUG(); }#endif /* CONFIG_HOTPLUG_CPU */
arch/mips/loongson64/smp.c +1 -0
@@ -822,6 +822,7 @@ void play_dead(void) state_addr = &per_cpu (cpu_state, cpu);mb ();play_dead_at_ckseg1 (state_addr); +BUG (); }static int loongson3_disable_clock (unsigned int cpu)
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 11/22 mips/cpu: Mark play_dead() __noreturn
In reply to Josh Poimboeufplay_dead() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/mips/include/asm/smp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/smp.h +1 -1
@@ -88,7 +88,7 @@ static inline void __cpu_die(unsigned int cpu) mp_ops->cpu_die(cpu); } -extern void play_dead (void ); +extern void __noreturn play_dead (void );#endif #ifdef CONFIG_KEXEC
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 12/22 powerpc/cpu: Mark start_secondary_resume() __noreturn
In reply to Josh Poimboeufstart_secondary_resume() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/powerpc/include/asm/smp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/smp.h +1 -1
@@ -66,7 +66,7 @@ void start_secondary(void *unused);extern int smp_send_nmi_ipi (int cpu,void (*fn)(struct pt_regs *),u64 delay_us);extern int smp_send_safe_nmi_ipi (int cpu,void (*fn)(struct pt_regs *),u64 delay_us);extern void smp_send_debugger_break (void ); -extern void start_secondary_resume (void ); +extern void __noreturn start_secondary_resume (void );extern void smp_generic_give_timebase (void );extern void smp_generic_take_timebase (void );
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 13/22 sh/cpu: Make sure play_dead() doesn't return
In reply to Josh Poimboeufplay_dead() doesn't return. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/sh/include/asm/smp-ops.h | 1 + 1 file changed, 1 insertion(+)
arch/sh/include/asm/smp-ops.h +1 -0
@@ -27,6 +27,7 @@ static inline void plat_smp_setup(void)static inline void play_dead (void ) { mp_ops->play_dead (); +BUG (); }extern void register_smp_ops (struct plat_smp_ops *ops);
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 14/22 sh/cpu: Mark play_dead() __noreturn
In reply to Josh Poimboeufplay_dead() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/sh/include/asm/smp-ops.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/sh/include/asm/smp-ops.h +2 -2
@@ -24,7 +24,7 @@ static inline void plat_smp_setup(void) mp_ops->smp_setup (); } -static inline void play_dead (void ) +static inline void __noreturn play_dead (void ) { mp_ops->play_dead ();BUG ();
@@ -43,7 +43,7 @@ static inline void register_smp_ops(struct plat_smp_ops *ops) { } -static inline void play_dead (void ) +static inline void __noreturn play_dead (void ) {BUG (); }
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 15/22 sh/cpu: Expose arch_cpu_idle_dead()'s prototype definition
In reply to Josh PoimboeufInclude <linux/cpu.h> to make sure arch_cpu_idle_dead() matches its prototype going forward.
--- arch/sh/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)
arch/sh/kernel/idle.c +1 -0
@@ -4,6 +4,7 @@* * Copyright (C) 2002 - 2009 Paul Mundt */ +#include <linux/cpu.h> #include <linux/module.h> #include <linux/init.h> #include <linux/mm.h>
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 16/22 sparc/cpu: Mark cpu_play_dead() __noreturn
In reply to Josh Poimboeufcpu_play_dead() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/sparc/include/asm/smp_64.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/include/asm/smp_64.h +1 -1
@@ -49,7 +49,7 @@ int hard_smp_processor_id(void);void smp_fill_in_cpu_possible_map (void );void smp_fill_in_sib_core_maps (void ); -void cpu_play_dead (void ); +void __noreturn cpu_play_dead (void );void smp_fetch_global_regs (void );void smp_fetch_global_pmu (void );
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 17/22 x86/cpu: Make sure play_dead() doesn't return
In reply to Josh PoimboeufAfter commit 076cbf5d2163 ("x86/xen: don't let xen_pv_play_dead() return"), play_dead() never returns. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/x86/include/asm/smp.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/smp.h +1 -0
@@ -96,6 +96,7 @@ static inline void __cpu_die(unsigned int cpu)static inline void play_dead (void ) { smp_ops.play_dead (); +BUG (); }static inline void smp_send_reschedule (int cpu)
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 18/22 x86/cpu: Mark play_dead() __noreturn
In reply to Josh Poimboeufplay_dead() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/x86/include/asm/smp.h | 2 +- arch/x86/kernel/process.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/smp.h +1 -1
@@ -93,7 +93,7 @@ static inline void __cpu_die(unsigned int cpu) smp_ops.cpu_die (cpu); } -static inline void play_dead (void ) +static inline void __noreturn play_dead (void ) { smp_ops.play_dead ();BUG ();
arch/x86/kernel/process.c +1 -1
@@ -715,7 +715,7 @@ static bool x86_idle_set(void) }#ifndef CONFIG_SMP -static inline void play_dead (void ) +static inline void __noreturn play_dead (void ) {BUG (); }
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 19/22 xtensa/cpu: Make sure cpu_die() doesn't return
In reply to Josh Poimboeufcpu_die() doesn't return. Make that more explicit with a BUG().
BUG() is preferable to unreachable() because BUG() is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.
--- arch/xtensa/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+)
arch/xtensa/kernel/smp.c +2 -0
@@ -341,6 +341,8 @@ void __ref cpu_die(void) __asm__ __volatile__(" movi a2, cpu_restart\n" " jx a2\n" ); + + BUG(); }#endif /* CONFIG_HOTPLUG_CPU */
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 20/22 xtensa/cpu: Mark cpu_die() __noreturn
In reply to Josh Poimboeufcpu_die() doesn't return. Annotate it as such. By extension this also makes arch_cpu_idle_dead() noreturn.
--- arch/xtensa/include/asm/smp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/xtensa/include/asm/smp.h +1 -1
@@ -33,7 +33,7 @@ void show_ipi_list(struct seq_file *p, int prec);void __cpu_die (unsigned int cpu);int __cpu_disable (void ); -void cpu_die (void ); +void __noreturn cpu_die (void );void cpu_restart (void );#endif /* CONFIG_HOTPLUG_CPU */
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 21/22 sched/idle: Make sure weak version of arch_cpu_idle_dead() doesn't return
In reply to Josh Poimboeufarch_cpu_idle_dead() should never return. Make it so.
--- kernel/sched/idle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/idle.c +1 -1
@@ -75,7 +75,7 @@ static noinline int __cpuidle cpu_idle_poll(void)void __weak arch_cpu_idle_prepare (void ) { }void __weak arch_cpu_idle_enter (void ) { }void __weak arch_cpu_idle_exit (void ) { } -void __weak arch_cpu_idle_dead (void ) { } +void __weak arch_cpu_idle_dead (void ) {while (1 ); }void __weak arch_cpu_idle (void ) { cpu_idle_force_poll =1 ;
Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerPATCH 22/22 sched/idle: Mark arch_cpu_idle_dead() __noreturn
In reply to Josh PoimboeufBefore commit 076cbf5d2163 ("x86/xen: don't let xen_pv_play_dead() return"), in Xen, when a previously offlined CPU was brought back online, it unexpectedly resumed execution where it left off in the middle of the idle loop.
There were some hacks to make that work, but the behavior was surprising as do_idle() doesn't expect an offlined CPU to return from the dead (in arch_cpu_idle_dead()).
Now that Xen has been fixed, and the arch-specific implementations of arch_cpu_idle_dead() also don't return, give it a __noreturn attribute.
This will cause the compiler to complain if an arch-specific implementation might return. It also improves code generation for both caller and callee.
Also fixes the following warning:
vmlinux.o: warning: objtool: do_idle+0x25f: unreachable instruction
--- include/linux/cpu.h | 2 +- tools/objtool/check.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/cpu.h +1 -1
@@ -182,7 +182,7 @@ void arch_cpu_idle(void);void arch_cpu_idle_prepare (void );void arch_cpu_idle_enter (void );void arch_cpu_idle_exit (void ); -void arch_cpu_idle_dead (void ); +void __noreturn arch_cpu_idle_dead (void );int cpu_report_state (int cpu);int cpu_check_up_prepare (int cpu);
tools/objtool/check.c +1 -0
@@ -167,6 +167,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,"__reiserfs_panic" ,"__stack_chk_fail" ,"__ubsan_handle_builtin_unreachable" , +"arch_cpu_idle_dead" ,"cpu_bringup_and_idle" ,"cpu_startup_entry" , "do_exit",
Signature · 1 line
2.39.0
Guo Ren
maintainerRe: [PATCH 05/22] csky/cpu: Make sure arch_cpu_idle_dead() doesn't return
In reply to Josh PoimboeufQuoted 18 lines · Josh Poimboeuf
arch_cpu_idle_dead()doesn't return. Make that more explicit with aBUG().
BUG()is preferable tounreachable()becauseBUG()is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.Signed-off-by Josh Poimboeuf <[email protected]>--- arch/csky/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+)arch/csky/kernel/smp.c +0
-0
arch/csky/kernel/smp.c void arch_cpu_idle_dead(void) · line 321
Quoted 5 lines
arch/csky/kernel/smp.c +2
-0@@ -317,5 +317,7 @@ void arch_cpu_idle_dead(void) "jmpi csky_start_secondary" : : "r" (secondary_stack)); + +BUG ();
Why not:
kernel/sched/idle.c +1 -0
@@ -285,6 +285,7 @@ static void do_idle(void)tick_nohz_idle_stop_tick ();cpuhp_report_idle_dead ();arch_cpu_idle_dead (); +BUG (); }arch_cpu_idle_enter ();
Quoted 5 lines
arch/csky/kernel/smp.c +0
-1}#endif --2.39.0
Signature · 2 lines
Best Regards Guo Ren
Josh Poimboeuf
maintainerRe: [PATCH 05/22] csky/cpu: Make sure arch_cpu_idle_dead() doesn't return
Quoted 30 lines · Guo Ren
Quoted 18 lines · Josh Poimboeuf
arch_cpu_idle_dead()doesn't return. Make that more explicit with aBUG().
BUG()is preferable tounreachable()becauseBUG()is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.Signed-off-by Josh Poimboeuf <[email protected]>--- arch/csky/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+)arch/csky/kernel/smp.c +0
-0arch/csky/kernel/smp.c void arch_cpu_idle_dead(void) · line 321
Quoted 5 lines
arch/csky/kernel/smp.c +2
-0@@ -317,5 +317,7 @@ void arch_cpu_idle_dead(void) "jmpi csky_start_secondary" : : "r" (secondary_stack)); + +BUG ();Why not:
kernel/sched/idle.c +0
-0
kernel/sched/idle.c static void do_idle(void) · line 288
Quoted 4 lines
kernel/sched/idle.c +1
-0@@ -285,6 +285,7 @@ static void do_idle(void)tick_nohz_idle_stop_tick ();cpuhp_report_idle_dead ();arch_cpu_idle_dead (); +BUG ();
Without the BUG() in csky arch_cpu_idle_dead(), the compiler will warn about arch_cpu_idle_dead() returning, because it's marked __noreturn but doesn't clearly return (as far as the compiler knows).
And we want it marked __noreturn so we'll be more likely to catch such bugs at build time.
And as a bonus we get better code generation and clearer code semantics which helps both humans and tooling understand the intent of the code.
Signature · 1 line
Josh
Re: [PATCH 05/22] csky/cpu: Make sure arch_cpu_idle_dead() doesn't return
Quoted 41 lines · Josh Poimboeuf
Quoted 30 lines · Guo Ren
Quoted 18 lines · Josh Poimboeuf
arch_cpu_idle_dead()doesn't return. Make that more explicit with aBUG().
BUG()is preferable tounreachable()becauseBUG()is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.Signed-off-by Josh Poimboeuf <[email protected]>--- arch/csky/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+)arch/csky/kernel/smp.c +0
-0arch/csky/kernel/smp.c void arch_cpu_idle_dead(void) · line 321
Quoted 5 lines
arch/csky/kernel/smp.c +2
-0@@ -317,5 +317,7 @@ void arch_cpu_idle_dead(void) "jmpi csky_start_secondary" : : "r" (secondary_stack)); + +BUG ();Why not:
kernel/sched/idle.c +0
-0kernel/sched/idle.c static void do_idle(void) · line 288
Quoted 4 lines
kernel/sched/idle.c +1
-0@@ -285,6 +285,7 @@ static void do_idle(void)tick_nohz_idle_stop_tick ();cpuhp_report_idle_dead ();arch_cpu_idle_dead (); +BUG ();Without the
BUG()in cskyarch_cpu_idle_dead(), the compiler will warn aboutarch_cpu_idle_dead()returning, because it's marked__noreturnbut doesn't clearly return (as far as the compiler knows).
Quoted 5 lines
And we want it marked
__noreturnso we'll be more likely to catch such bugs at build time.And as a bonus we get better code generation and clearer code semantics which helps both humans and tooling understand the intent of the code.
Thx for the clarification.
Quoted 3 lines
--
Josh
Signature · 2 lines
Best Regards Guo Ren
Re: [PATCH 12/22] powerpc/cpu: Mark start_secondary_resume() __noreturn
In reply to Josh PoimboeufQuoted 2 lines · Josh Poimboeuf
start_secondary_resume()doesn't return. Annotate it as such. By extension this also makesarch_cpu_idle_dead()noreturn.
Can we also mark arch_cpu_idle_dead() (the C function) __noreturn ?
Seems like it would be good documentation, even if it's not required once the generic prototype is __noreturn.
But not a show-stopper.
cheers
Quoted 15 lines
arch/powerpc/include/asm/smp.h +1
-1@@ -66,7 +66,7 @@ void start_secondary(void *unused);extern int smp_send_nmi_ipi (int cpu,void (*fn)(struct pt_regs *),u64 delay_us);extern int smp_send_safe_nmi_ipi (int cpu,void (*fn)(struct pt_regs *),u64 delay_us);extern void smp_send_debugger_break (void ); -extern void start_secondary_resume (void ); +extern void __noreturn start_secondary_resume (void );extern void smp_generic_give_timebase (void );extern void smp_generic_take_timebase (void );Signature · 1 line
2.39.0
Josh Poimboeuf
maintainerRe: [PATCH 12/22] powerpc/cpu: Mark start_secondary_resume() __noreturn
Quoted 8 lines · Michael Ellerman
Quoted 2 lines · Josh Poimboeuf
start_secondary_resume()doesn't return. Annotate it as such. By extension this also makesarch_cpu_idle_dead()noreturn.Can we also mark
arch_cpu_idle_dead()(the C function)__noreturn?Seems like it would be good documentation, even if it's not required once the generic prototype is
__noreturn.
Yeah, agreed. Maybe I'll do that (for all the implementations) with patch 22.
Quoted 3 lines
But not a show-stopper.
Thanks!
Signature · 1 line
Josh
Re: [PATCH 09/22] mips/cpu: Expose play_dead()'s prototype definition
In reply to Josh PoimboeufQuoted 4 lines · Josh Poimboeuf
Include <
asm/smp.h> to make sureplay_dead()matches its prototype going forward.Signed-off-by Josh Poimboeuf <[email protected]>
Signature · 1 line
Florian
Re: [PATCH 10/22] mips/cpu: Make sure play_dead() doesn't return
In reply to Josh PoimboeufQuoted 7 lines · Josh Poimboeuf
play_dead()doesn't return. Make that more explicit with aBUG().
BUG()is preferable tounreachable()becauseBUG()is a more explicit failure mode and avoids undefined behavior like falling off the edge of the function into whatever code happens to be next.Signed-off-by Josh Poimboeuf <[email protected]>
Signature · 1 line
Florian
Re: [PATCH 11/22] mips/cpu: Mark play_dead() __noreturn
In reply to Josh PoimboeufQuoted 4 lines · Josh Poimboeuf
play_dead()doesn't return. Annotate it as such. By extension this also makesarch_cpu_idle_dead()noreturn.Signed-off-by Josh Poimboeuf <[email protected]>
Signature · 1 line
Florian
Josh Poimboeuf
maintainerPATCH 22/22 sched/idle: Mark arch_cpu_idle_dead() __noreturn
In reply to Josh PoimboeufBefore commit 076cbf5d2163 ("x86/xen: don't let xen_pv_play_dead() return"), in Xen, when a previously offlined CPU was brought back online, it unexpectedly resumed execution where it left off in the middle of the idle loop.
There were some hacks to make that work, but the behavior was surprising as do_idle() doesn't expect an offlined CPU to return from the dead (in arch_cpu_idle_dead()).
Now that Xen has been fixed, and the arch-specific implementations of arch_cpu_idle_dead() also don't return, give it a __noreturn attribute.
This will cause the compiler to complain if an arch-specific implementation might return. It also improves code generation for both caller and callee.
Also fixes the following warning:
vmlinux.o: warning: objtool: do_idle+0x25f: unreachable instruction
---
v1.1:
- add __noreturn to the implementations (in addition to just the prototype)
arch/alpha/kernel/process.c | 2 +- arch/arm/kernel/smp.c | 2 +- arch/arm64/kernel/process.c | 2 +- arch/csky/kernel/smp.c | 2 +- arch/ia64/kernel/process.c | 2 +- arch/loongarch/kernel/process.c | 2 +- arch/mips/kernel/process.c | 2 +- arch/parisc/kernel/process.c | 2 +- arch/powerpc/kernel/smp.c | 2 +- arch/riscv/kernel/cpu-hotplug.c | 2 +- arch/s390/kernel/idle.c | 2 +- arch/sh/kernel/idle.c | 2 +- arch/sparc/kernel/process_64.c | 2 +- arch/x86/kernel/process.c | 2 +- arch/xtensa/kernel/smp.c | 2 +- include/linux/cpu.h | 2 +- tools/objtool/check.c | 1 + 17 files changed, 17 insertions(+), 16 deletions(-)
arch/alpha/kernel/process.c +1 -1
@@ -60,7 +60,7 @@ void arch_cpu_idle(void)wtint (0 ); } -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {wtint (INT_MAX );BUG ();
arch/arm/kernel/smp.c +1 -1
@@ -320,7 +320,7 @@ void __cpu_die(unsigned int cpu)* of the other hotplug-cpu capable cores, so presumably coming * out of idle fixes this. */ -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {unsigned int cpu =smp_processor_id ();
arch/arm64/kernel/process.c +1 -1
@@ -69,7 +69,7 @@ void (*pm_power_off)(void);EXPORT_SYMBOL_GPL (pm_power_off);#ifdef CONFIG_HOTPLUG_CPU -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {cpu_die (); }
arch/csky/kernel/smp.c +1 -1
@@ -300,7 +300,7 @@ void __cpu_die(unsigned int cpu)pr_notice ("CPU%u: shutdown\n" , cpu); } -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {idle_task_exit ();
arch/ia64/kernel/process.c +1 -1
@@ -225,7 +225,7 @@ static inline void __noreturn play_dead(void) }#endif /* CONFIG_HOTPLUG_CPU */ -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {play_dead (); }
arch/loongarch/kernel/process.c +1 -1
@@ -61,7 +61,7 @@ unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;EXPORT_SYMBOL (boot_option_idle_override);#ifdef CONFIG_HOTPLUG_CPU -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {play_dead (); }
arch/mips/kernel/process.c +1 -1
@@ -40,7 +40,7 @@#include <asm/stacktrace.h> #ifdef CONFIG_HOTPLUG_CPU -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {play_dead (); }
arch/parisc/kernel/process.c +1 -1
@@ -159,7 +159,7 @@ EXPORT_SYMBOL(running_on_qemu);/* * Called from the idle thread for the CPU which has been shutdown. */ -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {#ifdef CONFIG_HOTPLUG_CPU idle_task_exit ();
arch/powerpc/kernel/smp.c +1 -1
@@ -1752,7 +1752,7 @@ void __cpu_die(unsigned int cpu) smp_ops->cpu_die (cpu); } -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {/* * Disable on the down path. This will be re-enabled by
arch/riscv/kernel/cpu-hotplug.c +1 -1
@@ -71,7 +71,7 @@ void __cpu_die(unsigned int cpu)/* * Called from the idle thread for the CPU which has been shutdown. */ -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {idle_task_exit ();
arch/s390/kernel/idle.c +1 -1
@@ -143,7 +143,7 @@ void arch_cpu_idle_exit(void) { } -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {cpu_die (); }
arch/sh/kernel/idle.c +1 -1
@@ -30,7 +30,7 @@ void default_idle(void)clear_bl_bit (); } -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {play_dead (); }
arch/sparc/kernel/process_64.c +1 -1
@@ -95,7 +95,7 @@ void arch_cpu_idle(void) }#ifdef CONFIG_HOTPLUG_CPU -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {sched_preempt_enable_no_resched ();cpu_play_dead ();
arch/x86/kernel/process.c +1 -1
@@ -727,7 +727,7 @@ void arch_cpu_idle_enter(void)local_touch_nmi (); } -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {play_dead (); }
arch/xtensa/kernel/smp.c +1 -1
@@ -322,7 +322,7 @@ void __cpu_die(unsigned int cpu)pr_err ("CPU%u: unable to kill\n" , cpu); } -void arch_cpu_idle_dead (void ) +void __noreturn arch_cpu_idle_dead (void ) {cpu_die (); }
include/linux/cpu.h +1 -1
@@ -182,7 +182,7 @@ void arch_cpu_idle(void);void arch_cpu_idle_prepare (void );void arch_cpu_idle_enter (void );void arch_cpu_idle_exit (void ); -void arch_cpu_idle_dead (void ); +void __noreturn arch_cpu_idle_dead (void );int cpu_report_state (int cpu);int cpu_check_up_prepare (int cpu);
tools/objtool/check.c +1 -0
@@ -167,6 +167,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,"__reiserfs_panic" ,"__stack_chk_fail" ,"__ubsan_handle_builtin_unreachable" , +"arch_cpu_idle_dead" ,"cpu_bringup_and_idle" ,"cpu_startup_entry" , "do_exit",
Signature · 1 line
2.39.0