2023-02-14 07:07:39

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 00/24] cpu,sched: Mark arch_cpu_idle_dead() __noreturn

v2:
- make arch_call_rest_init() and rest_init() __noreturn
- make objtool 'global_returns' work for weak functions
- rebase on tip/objtool/core with dependencies merged in (mingo)
- add acks

v1.1:
- add __noreturn to all arch_cpu_idle_dead() implementations (mpe)

Josh Poimboeuf (24):
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
objtool: Include weak functions in 'global_noreturns' check
init: Make arch_call_rest_init() and rest_init() __noreturn
sched/idle: Mark arch_cpu_idle_dead() __noreturn

arch/alpha/kernel/process.c | 4 +++-
arch/arm/kernel/smp.c | 4 +++-
arch/arm64/include/asm/smp.h | 2 +-
arch/arm64/kernel/process.c | 2 +-
arch/csky/kernel/smp.c | 4 +++-
arch/ia64/kernel/process.c | 6 +++---
arch/loongarch/include/asm/smp.h | 2 +-
arch/loongarch/kernel/process.c | 2 +-
arch/loongarch/kernel/smp.c | 2 +-
arch/mips/include/asm/smp.h | 2 +-
arch/mips/kernel/process.c | 2 +-
arch/mips/kernel/smp-bmips.c | 3 +++
arch/mips/loongson64/smp.c | 1 +
arch/parisc/kernel/process.c | 2 +-
arch/powerpc/include/asm/smp.h | 2 +-
arch/powerpc/kernel/smp.c | 2 +-
arch/riscv/kernel/cpu-hotplug.c | 2 +-
arch/s390/kernel/idle.c | 2 +-
arch/s390/kernel/setup.c | 2 +-
arch/sh/include/asm/smp-ops.h | 5 +++--
arch/sh/kernel/idle.c | 3 ++-
arch/sparc/include/asm/smp_64.h | 2 +-
arch/sparc/kernel/process_64.c | 2 +-
arch/x86/include/asm/smp.h | 3 ++-
arch/x86/kernel/process.c | 4 ++--
arch/xtensa/include/asm/smp.h | 2 +-
arch/xtensa/kernel/smp.c | 4 +++-
include/linux/cpu.h | 2 +-
include/linux/start_kernel.h | 4 ++--
init/main.c | 4 ++--
kernel/sched/idle.c | 2 +-
tools/objtool/check.c | 11 +++++++----
32 files changed, 57 insertions(+), 39 deletions(-)

--
2.39.1



2023-02-14 07:07:42

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 04/24] arm64/cpu: Mark cpu_die() __noreturn

cpu_die() doesn't return. Annotate it as such. By extension this also
makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/arm64/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index fc55f5a57a06..5733a31bab08 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -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)
--
2.39.1


2023-02-14 07:07:44

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 01/24] 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.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/alpha/kernel/process.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index ce20c31828a0..d1f2e8b6b107 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -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>
--
2.39.1


2023-02-14 07:07:47

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 03/24] arm/cpu: Make sure arch_cpu_idle_dead() doesn't return

arch_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.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/arm/kernel/smp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 0b8c25763adc..adcd417c526b 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -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 */

--
2.39.1


2023-02-14 07:07:50

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 05/24] csky/cpu: Make sure arch_cpu_idle_dead() doesn't return

arch_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.

Acked-by: Guo Ren <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/csky/kernel/smp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/csky/kernel/smp.c b/arch/csky/kernel/smp.c
index b45d1073307f..0ec20efaf5fd 100644
--- a/arch/csky/kernel/smp.c
+++ b/arch/csky/kernel/smp.c
@@ -317,5 +317,7 @@ void arch_cpu_idle_dead(void)
"jmpi csky_start_secondary"
:
: "r" (secondary_stack));
+
+ BUG();
}
#endif
--
2.39.1


2023-02-14 07:07:53

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 07/24] loongarch/cpu: Make sure play_dead() doesn't return

play_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.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/loongarch/kernel/smp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c
index 8c6e227cb29d..51f328169a7b 100644
--- a/arch/loongarch/kernel/smp.c
+++ b/arch/loongarch/kernel/smp.c
@@ -336,7 +336,7 @@ void play_dead(void)
iocsr_write32(0xffffffff, LOONGARCH_IOCSR_IPI_CLEAR);

init_fn();
- unreachable();
+ BUG();
}

#endif
--
2.39.1


2023-02-14 07:08:09

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 12/24] powerpc/cpu: Mark start_secondary_resume() __noreturn

start_secondary_resume() doesn't return. Annotate it as such. By
extension this also makes arch_cpu_idle_dead() noreturn.

Acked-by: Michael Ellerman <[email protected]> (powerpc)
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/powerpc/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
index f63505d74932..cfd42ca8765c 100644
--- a/arch/powerpc/include/asm/smp.h
+++ b/arch/powerpc/include/asm/smp.h
@@ -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);

--
2.39.1


2023-02-14 07:08:42

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 10/24] mips/cpu: Make sure play_dead() doesn't return

play_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.

Acked-by: Florian Fainelli <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/kernel/smp-bmips.c | 2 ++
arch/mips/loongson64/smp.c | 1 +
2 files changed, 3 insertions(+)

diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index df9158e8329d..be85fa075830 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -414,6 +414,8 @@ void __ref play_dead(void)
" wait\n"
" j bmips_secondary_reentry\n"
: : : "memory");
+
+ BUG();
}

#endif /* CONFIG_HOTPLUG_CPU */
diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index 660e1de4412a..c81c2bd07c62 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -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)
--
2.39.1


2023-02-14 07:08:46

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 09/24] mips/cpu: Expose play_dead()'s prototype definition

Include <asm/smp.h> to make sure play_dead() matches its prototype going
forward.

Acked-by: Florian Fainelli <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/kernel/smp-bmips.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index f5d7bfa3472a..df9158e8329d 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -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;

--
2.39.1


2023-02-14 07:08:55

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 11/24] mips/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Acked-by: Florian Fainelli <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
index 5d9ff61004ca..4eee29b7845c 100644
--- a/arch/mips/include/asm/smp.h
+++ b/arch/mips/include/asm/smp.h
@@ -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
--
2.39.1


2023-02-14 07:08:58

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 08/24] loongarch/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/loongarch/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/include/asm/smp.h b/arch/loongarch/include/asm/smp.h
index d82687390b4a..416b653bccb4 100644
--- a/arch/loongarch/include/asm/smp.h
+++ b/arch/loongarch/include/asm/smp.h
@@ -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 */
--
2.39.1


2023-02-14 07:09:03

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 06/24] ia64/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/ia64/kernel/process.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index f6195a0a00ae..78f5794b2dde 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -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();
}
--
2.39.1


2023-02-14 07:09:22

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 17/24] x86/cpu: Make sure play_dead() doesn't return

After 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.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/x86/include/asm/smp.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index b4dbb20dab1a..8f628e08b25a 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -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)
--
2.39.1


2023-02-14 07:09:25

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

cpu_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.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/xtensa/kernel/smp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
index 4dc109dd6214..7bad78495536 100644
--- a/arch/xtensa/kernel/smp.c
+++ b/arch/xtensa/kernel/smp.c
@@ -341,6 +341,8 @@ void __ref cpu_die(void)
__asm__ __volatile__(
" movi a2, cpu_restart\n"
" jx a2\n");
+
+ BUG();
}

#endif /* CONFIG_HOTPLUG_CPU */
--
2.39.1


2023-02-14 07:09:29

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 14/24] sh/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sh/include/asm/smp-ops.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
index 63866b1595a0..97331fcb7b85 100644
--- a/arch/sh/include/asm/smp-ops.h
+++ b/arch/sh/include/asm/smp-ops.h
@@ -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();
}
--
2.39.1


2023-02-14 07:09:34

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 18/24] x86/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/x86/include/asm/smp.h | 2 +-
arch/x86/kernel/process.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 8f628e08b25a..e6d1d2810e38 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -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();
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index e57cd31bfec4..4433d13edd44 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -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();
}
--
2.39.1


2023-02-14 07:09:38

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 20/24] xtensa/cpu: Mark cpu_die() __noreturn

cpu_die() doesn't return. Annotate it as such. By extension this also
makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/xtensa/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/xtensa/include/asm/smp.h b/arch/xtensa/include/asm/smp.h
index 4e43f5643891..5dc5bf8cdd77 100644
--- a/arch/xtensa/include/asm/smp.h
+++ b/arch/xtensa/include/asm/smp.h
@@ -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 */
--
2.39.1


2023-02-14 07:09:40

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 15/24] sh/cpu: Expose arch_cpu_idle_dead()'s prototype definition

Include <linux/cpu.h> to make sure arch_cpu_idle_dead() matches its
prototype going forward.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sh/kernel/idle.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/sh/kernel/idle.c b/arch/sh/kernel/idle.c
index 3418c40f0099..114f0c4abeac 100644
--- a/arch/sh/kernel/idle.c
+++ b/arch/sh/kernel/idle.c
@@ -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>
--
2.39.1


2023-02-14 07:09:44

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 13/24] sh/cpu: Make sure play_dead() doesn't return

play_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.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sh/include/asm/smp-ops.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
index e27702130eb6..63866b1595a0 100644
--- a/arch/sh/include/asm/smp-ops.h
+++ b/arch/sh/include/asm/smp-ops.h
@@ -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);
--
2.39.1


2023-02-14 07:10:05

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 22/24] objtool: Include weak functions in 'global_noreturns' check

If a global __noreturn function prototype has a corresponding weak
function, it should also be __noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
tools/objtool/check.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index ba07a8ebaf73..0a1cf867d9b2 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -193,14 +193,14 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
if (!func)
return false;

- if (func->bind == STB_WEAK)
- return false;
-
- if (func->bind == STB_GLOBAL)
+ if (func->bind == STB_GLOBAL || func->bind == STB_WEAK)
for (i = 0; i < ARRAY_SIZE(global_noreturns); i++)
if (!strcmp(func->name, global_noreturns[i]))
return true;

+ if (func->bind == STB_WEAK)
+ return false;
+
if (!func->len)
return false;

--
2.39.1


2023-02-14 07:10:05

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 21/24] sched/idle: Make sure weak version of arch_cpu_idle_dead() doesn't return

arch_cpu_idle_dead() should never return. Make it so.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
kernel/sched/idle.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index e9ef66be2870..56e152f06d0f 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -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;
--
2.39.1


2023-02-14 07:10:05

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 16/24] sparc/cpu: Mark cpu_play_dead() __noreturn

cpu_play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sparc/include/asm/smp_64.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/smp_64.h b/arch/sparc/include/asm/smp_64.h
index e75783b6abc4..505b6700805d 100644
--- a/arch/sparc/include/asm/smp_64.h
+++ b/arch/sparc/include/asm/smp_64.h
@@ -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);
--
2.39.1


2023-02-14 07:10:05

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 23/24] init: Make arch_call_rest_init() and rest_init() __noreturn

arch_call_rest_init() and rest_init() don't return. Annotate them as
such.

Fixes the following warning:

init/main.o: warning: objtool: start_kernel+0x4ad: unreachable instruction

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/s390/kernel/setup.c | 2 +-
include/linux/start_kernel.h | 4 ++--
init/main.c | 4 ++--
tools/objtool/check.c | 2 ++
4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index 696c9e007a36..85abff362f29 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -393,7 +393,7 @@ int __init arch_early_irq_init(void)
return 0;
}

-void __init arch_call_rest_init(void)
+void __init __noreturn arch_call_rest_init(void)
{
unsigned long stack;

diff --git a/include/linux/start_kernel.h b/include/linux/start_kernel.h
index 8b369a41c03c..864921e54c92 100644
--- a/include/linux/start_kernel.h
+++ b/include/linux/start_kernel.h
@@ -9,7 +9,7 @@
up something else. */

extern asmlinkage void __init start_kernel(void);
-extern void __init arch_call_rest_init(void);
-extern void __ref rest_init(void);
+extern void __init __noreturn arch_call_rest_init(void);
+extern void __ref __noreturn rest_init(void);

#endif /* _LINUX_START_KERNEL_H */
diff --git a/init/main.c b/init/main.c
index e1c3911d7c70..ef71a9902e47 100644
--- a/init/main.c
+++ b/init/main.c
@@ -683,7 +683,7 @@ static void __init setup_command_line(char *command_line)

static __initdata DECLARE_COMPLETION(kthreadd_done);

-noinline void __ref rest_init(void)
+noinline void __ref __noreturn rest_init(void)
{
struct task_struct *tsk;
int pid;
@@ -889,7 +889,7 @@ static int __init early_randomize_kstack_offset(char *buf)
early_param("randomize_kstack_offset", early_randomize_kstack_offset);
#endif

-void __init __weak arch_call_rest_init(void)
+void __init __weak __noreturn arch_call_rest_init(void)
{
rest_init();
}
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 0a1cf867d9b2..f79baae3e338 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -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_call_rest_init",
"cpu_bringup_and_idle",
"cpu_startup_entry",
"do_exit",
@@ -181,6 +182,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
"machine_real_restart",
"make_task_dead",
"panic",
+ "rest_init",
"rewind_stack_and_make_dead",
"sev_es_terminate",
"snp_abort",
--
2.39.1


2023-02-14 07:10:16

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2 24/24] sched/idle: Mark arch_cpu_idle_dead() __noreturn

Before 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

Reported-by: Paul E. McKenney <[email protected]>
Tested-by: Paul E. McKenney <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
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 +-
kernel/sched/idle.c | 2 +-
tools/objtool/check.c | 1 +
18 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index d0ff06eda8fa..9bae2fc4910f 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -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();
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index adcd417c526b..c2daa0f2f784 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -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();

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 269ac1c25ae2..8d606bbb4a9a 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -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();
}
diff --git a/arch/csky/kernel/smp.c b/arch/csky/kernel/smp.c
index 0ec20efaf5fd..9c7a20b73ac6 100644
--- a/arch/csky/kernel/smp.c
+++ b/arch/csky/kernel/smp.c
@@ -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();

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index 78f5794b2dde..9a5cd9fad3a9 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -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();
}
diff --git a/arch/loongarch/kernel/process.c b/arch/loongarch/kernel/process.c
index edfd220a3737..ba70e94eb996 100644
--- a/arch/loongarch/kernel/process.c
+++ b/arch/loongarch/kernel/process.c
@@ -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();
}
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 093dbbd6b843..a3225912c862 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -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();
}
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index c064719b49b0..97c6f875bd0e 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -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();
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 6b90f10a6c81..f62e5e651bcd 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -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
diff --git a/arch/riscv/kernel/cpu-hotplug.c b/arch/riscv/kernel/cpu-hotplug.c
index f7a832e3a1d1..59b80211c25f 100644
--- a/arch/riscv/kernel/cpu-hotplug.c
+++ b/arch/riscv/kernel/cpu-hotplug.c
@@ -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();

diff --git a/arch/s390/kernel/idle.c b/arch/s390/kernel/idle.c
index b04fb418307c..45b5ee28dbe3 100644
--- a/arch/s390/kernel/idle.c
+++ b/arch/s390/kernel/idle.c
@@ -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();
}
diff --git a/arch/sh/kernel/idle.c b/arch/sh/kernel/idle.c
index 114f0c4abeac..d662503b0665 100644
--- a/arch/sh/kernel/idle.c
+++ b/arch/sh/kernel/idle.c
@@ -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();
}
diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
index 91c2b8124527..b51d8fb0ecdc 100644
--- a/arch/sparc/kernel/process_64.c
+++ b/arch/sparc/kernel/process_64.c
@@ -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();
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 4433d13edd44..e52158263d30 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -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();
}
diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
index 7bad78495536..054bd64eab19 100644
--- a/arch/xtensa/kernel/smp.c
+++ b/arch/xtensa/kernel/smp.c
@@ -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();
}
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index f83e4519c5f0..8582a7142623 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -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);
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 56e152f06d0f..342f58a329f5 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -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) { while (1); }
+void __weak __noreturn arch_cpu_idle_dead(void) { while (1); }
void __weak arch_cpu_idle(void)
{
cpu_idle_force_poll = 1;
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f79baae3e338..4be38a40aaca 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -168,6 +168,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
"__stack_chk_fail",
"__ubsan_handle_builtin_unreachable",
"arch_call_rest_init",
+ "arch_cpu_idle_dead",
"cpu_bringup_and_idle",
"cpu_startup_entry",
"do_exit",
--
2.39.1


2023-02-14 07:19:37

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH v2 12/24] powerpc/cpu: Mark start_secondary_resume() __noreturn



Le 14/02/2023 à 08:05, Josh Poimboeuf a écrit :
> start_secondary_resume() doesn't return. Annotate it as such. By
> extension this also makes arch_cpu_idle_dead() noreturn.
>
> Acked-by: Michael Ellerman <[email protected]> (powerpc)
> Signed-off-by: Josh Poimboeuf <[email protected]>

Reviewed-by: Christophe Leroy <[email protected]>

> ---
> arch/powerpc/include/asm/smp.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
> index f63505d74932..cfd42ca8765c 100644
> --- a/arch/powerpc/include/asm/smp.h
> +++ b/arch/powerpc/include/asm/smp.h
> @@ -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);

Would have been a good opportunity to drop the pointless 'extern' keyword.

Checkpatch reports:

CHECK: extern prototypes should be avoided in .h files
#19: FILE: arch/powerpc/include/asm/smp.h:69:
+extern void __noreturn start_secondary_resume(void);


> extern void smp_generic_give_timebase(void);
> extern void smp_generic_take_timebase(void);
>

2023-02-14 07:46:52

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 09/24] mips/cpu: Expose play_dead()'s prototype definition

Hi Josh,

On 14/2/23 08:05, Josh Poimboeuf wrote:
> Include <asm/smp.h> to make sure play_dead() matches its prototype going
> forward.
>
> Acked-by: Florian Fainelli <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/mips/kernel/smp-bmips.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
> index f5d7bfa3472a..df9158e8329d 100644
> --- a/arch/mips/kernel/smp-bmips.c
> +++ b/arch/mips/kernel/smp-bmips.c
> @@ -38,6 +38,7 @@
> #include <asm/traps.h>
> #include <asm/barrier.h>
> #include <asm/cpu-features.h>
> +#include <asm/smp.h>

What about the other implementations?

$ git grep -L asm/smp.h $(git grep -wlF 'play_dead(void)' arch/mips)
arch/mips/cavium-octeon/smp.c
arch/mips/kernel/smp-bmips.c
arch/mips/kernel/smp-cps.c
arch/mips/loongson64/smp.c


2023-02-14 07:50:55

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 10/24] mips/cpu: Make sure play_dead() doesn't return

On 14/2/23 08:05, Josh Poimboeuf wrote:
> play_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.
>
> Acked-by: Florian Fainelli <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/mips/kernel/smp-bmips.c | 2 ++
> arch/mips/loongson64/smp.c | 1 +
> 2 files changed, 3 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>


2023-02-14 07:51:09

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 11/24] mips/cpu: Mark play_dead() __noreturn

On 14/2/23 08:05, Josh Poimboeuf wrote:
> play_dead() doesn't return. Annotate it as such. By extension this
> also makes arch_cpu_idle_dead() noreturn.
>
> Acked-by: Florian Fainelli <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/mips/include/asm/smp.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>



2023-02-14 07:52:48

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 16/24] sparc/cpu: Mark cpu_play_dead() __noreturn

On 14/2/23 08:05, Josh Poimboeuf wrote:
> cpu_play_dead() doesn't return. Annotate it as such. By extension this
> also makes arch_cpu_idle_dead() noreturn.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/sparc/include/asm/smp_64.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>


2023-02-14 07:56:16

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

Hi Josh,

On 14/2/23 08:05, Josh Poimboeuf wrote:
> cpu_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.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/xtensa/kernel/smp.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
> index 4dc109dd6214..7bad78495536 100644
> --- a/arch/xtensa/kernel/smp.c
> +++ b/arch/xtensa/kernel/smp.c

Can you update the documentation along? Currently we have:

/*
* Called from the idle thread for the CPU which has been shutdown.
*
* Note that we disable IRQs here, but do not re-enable them
* before returning to the caller. This is also the behaviour
* of the other hotplug-cpu capable cores, so presumably coming
* out of idle fixes this.
*/

> @@ -341,6 +341,8 @@ void __ref cpu_die(void)
> __asm__ __volatile__(
> " movi a2, cpu_restart\n"
> " jx a2\n");
> +
> + BUG();
> }
>
> #endif /* CONFIG_HOTPLUG_CPU */


2023-02-14 07:58:16

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 13/24] sh/cpu: Make sure play_dead() doesn't return

On 14/2/23 08:05, Josh Poimboeuf wrote:
> play_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.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/sh/include/asm/smp-ops.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
> index e27702130eb6..63866b1595a0 100644
> --- a/arch/sh/include/asm/smp-ops.h
> +++ b/arch/sh/include/asm/smp-ops.h
> @@ -27,6 +27,7 @@ static inline void plat_smp_setup(void)
> static inline void play_dead(void)
> {
> mp_ops->play_dead();
> + BUG();
> }

Shouldn't we decorate plat_smp_ops::play_dead() as noreturn first?

2023-02-14 08:05:37

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 17/24] x86/cpu: Make sure play_dead() doesn't return

On 14/2/23 08:05, Josh Poimboeuf wrote:
> After 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.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/x86/include/asm/smp.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
> index b4dbb20dab1a..8f628e08b25a 100644
> --- a/arch/x86/include/asm/smp.h
> +++ b/arch/x86/include/asm/smp.h
> @@ -96,6 +96,7 @@ static inline void __cpu_die(unsigned int cpu)
> static inline void play_dead(void)
> {
> smp_ops.play_dead();
> + BUG();
> }

Similarly, smp_ops::play_dead() should be decorated noreturn first.

2023-02-14 08:06:49

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 08/24] loongarch/cpu: Mark play_dead() __noreturn

On 14/2/23 08:05, Josh Poimboeuf wrote:
> play_dead() doesn't return. Annotate it as such. By extension this
> also makes arch_cpu_idle_dead() noreturn.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/loongarch/include/asm/smp.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>



2023-02-14 08:07:38

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 06/24] ia64/cpu: Mark play_dead() __noreturn

On 14/2/23 08:05, Josh Poimboeuf wrote:
> play_dead() doesn't return. Annotate it as such. By extension this
> also makes arch_cpu_idle_dead() noreturn.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/ia64/kernel/process.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>


2023-02-14 08:13:34

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 04/24] arm64/cpu: Mark cpu_die() __noreturn

On 14/2/23 08:05, Josh Poimboeuf wrote:
> cpu_die() doesn't return. Annotate it as such. By extension this also
> makes arch_cpu_idle_dead() noreturn.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/arm64/include/asm/smp.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
> index fc55f5a57a06..5733a31bab08 100644
> --- a/arch/arm64/include/asm/smp.h
> +++ b/arch/arm64/include/asm/smp.h
> @@ -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);

Shouldn't cpu_operations::cpu_die() be declared noreturn first?


2023-02-14 08:39:37

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: [PATCH v2 25/24] x86/cpu: Expose arch_cpu_idle_dead()'s prototype definition

Include <linux/cpu.h> to make sure arch_cpu_idle_dead() matches its
prototype going forward.

Inspired-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
Josh, feel free to include in your v3.
---
arch/x86/kernel/process.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 40d156a31676..7d27181a2518 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -5,6 +5,7 @@
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/smp.h>
+#include <linux/cpu.h>
#include <linux/prctl.h>
#include <linux/slab.h>
#include <linux/sched.h>
--
2.38.1


2023-02-14 09:26:37

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 00/24] cpu,sched: Mark arch_cpu_idle_dead() __noreturn

On 14/2/23 08:05, Josh Poimboeuf wrote:
> v2:
> - make arch_call_rest_init() and rest_init() __noreturn
> - make objtool 'global_returns' work for weak functions
> - rebase on tip/objtool/core with dependencies merged in (mingo)
> - add acks
>
> v1.1:
> - add __noreturn to all arch_cpu_idle_dead() implementations (mpe)

Possible similar candidates: panic_smp_self_stop, nmi_panic_self_stop
and kexec.


2023-02-14 11:16:02

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH v2 03/24] arm/cpu: Make sure arch_cpu_idle_dead() doesn't return

On Mon, Feb 13, 2023 at 11:05:37PM -0800, Josh Poimboeuf wrote:
> arch_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.

This is silly. Just mark the function __noreturn and be done with it.
If the CPU ever executes code past the "b" instruction, it's already
really broken that the extra instructions that BUG() gives will be
meaningless.

This patch does nothing except add yet more bloat the kernel.

Sorry, but NAK.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

2023-02-14 12:47:31

by Max Filippov

[permalink] [raw]
Subject: Re: [PATCH v2 20/24] xtensa/cpu: Mark cpu_die() __noreturn

On Mon, Feb 13, 2023 at 11:07 PM Josh Poimboeuf <[email protected]> wrote:
>
> cpu_die() doesn't return. Annotate it as such. By extension this also
> makes arch_cpu_idle_dead() noreturn.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/xtensa/include/asm/smp.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Max Filippov <[email protected]>

--
Thanks.
-- Max

2023-02-14 18:11:20

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2 09/24] mips/cpu: Expose play_dead()'s prototype definition

On Tue, Feb 14, 2023 at 08:46:41AM +0100, Philippe Mathieu-Daudé wrote:
> Hi Josh,
>
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > Include <asm/smp.h> to make sure play_dead() matches its prototype going
> > forward.
> >
> > Acked-by: Florian Fainelli <[email protected]>
> > Signed-off-by: Josh Poimboeuf <[email protected]>
> > ---
> > arch/mips/kernel/smp-bmips.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
> > index f5d7bfa3472a..df9158e8329d 100644
> > --- a/arch/mips/kernel/smp-bmips.c
> > +++ b/arch/mips/kernel/smp-bmips.c
> > @@ -38,6 +38,7 @@
> > #include <asm/traps.h>
> > #include <asm/barrier.h>
> > #include <asm/cpu-features.h>
> > +#include <asm/smp.h>
>
> What about the other implementations?
>
> $ git grep -L asm/smp.h $(git grep -wlF 'play_dead(void)' arch/mips)
> arch/mips/cavium-octeon/smp.c
> arch/mips/kernel/smp-bmips.c
> arch/mips/kernel/smp-cps.c
> arch/mips/loongson64/smp.c

Indeed. I really wish we had -Wmissing-prototypes.

I'll squash this in:

diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
index 89954f5f87fb..4212584e6efa 100644
--- a/arch/mips/cavium-octeon/smp.c
+++ b/arch/mips/cavium-octeon/smp.c
@@ -20,6 +20,7 @@
#include <asm/mmu_context.h>
#include <asm/time.h>
#include <asm/setup.h>
+#include <asm/smp.h>

#include <asm/octeon/octeon.h>

diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index bcd6a944b839..6d69a9ba8167 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -20,6 +20,7 @@
#include <asm/mipsregs.h>
#include <asm/pm-cps.h>
#include <asm/r4kcache.h>
+#include <asm/smp.h>
#include <asm/smp-cps.h>
#include <asm/time.h>
#include <asm/uasm.h>
diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index c81c2bd07c62..df8d789ede3c 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -14,6 +14,7 @@
#include <linux/cpufreq.h>
#include <linux/kexec.h>
#include <asm/processor.h>
+#include <asm/smp.h>
#include <asm/time.h>
#include <asm/tlbflush.h>
#include <asm/cacheflush.h>

2023-02-14 18:23:33

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

On Tue, Feb 14, 2023 at 08:55:32AM +0100, Philippe Mathieu-Daudé wrote:
> Hi Josh,
>
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > cpu_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.
> >
> > Signed-off-by: Josh Poimboeuf <[email protected]>
> > ---
> > arch/xtensa/kernel/smp.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
> > index 4dc109dd6214..7bad78495536 100644
> > --- a/arch/xtensa/kernel/smp.c
> > +++ b/arch/xtensa/kernel/smp.c
>
> Can you update the documentation along? Currently we have:
>
> /*
> * Called from the idle thread for the CPU which has been shutdown.
> *
> * Note that we disable IRQs here, but do not re-enable them
> * before returning to the caller. This is also the behaviour
> * of the other hotplug-cpu capable cores, so presumably coming
> * out of idle fixes this.
> */

void __ref cpu_die(void)
{
idle_task_exit();
local_irq_disable();
__asm__ __volatile__(
" movi a2, cpu_restart\n"
" jx a2\n");

BUG();
}

Hm, not only is the comment wrong, but it seems to be branching to
cpu_restart? That doesn't seem right at all.

Max/Chris?

--
Josh

2023-02-14 18:28:47

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2 13/24] sh/cpu: Make sure play_dead() doesn't return

On Tue, Feb 14, 2023 at 08:57:39AM +0100, Philippe Mathieu-Daudé wrote:
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > play_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.
> >
> > Signed-off-by: Josh Poimboeuf <[email protected]>
> > ---
> > arch/sh/include/asm/smp-ops.h | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
> > index e27702130eb6..63866b1595a0 100644
> > --- a/arch/sh/include/asm/smp-ops.h
> > +++ b/arch/sh/include/asm/smp-ops.h
> > @@ -27,6 +27,7 @@ static inline void plat_smp_setup(void)
> > static inline void play_dead(void)
> > {
> > mp_ops->play_dead();
> > + BUG();
> > }
>
> Shouldn't we decorate plat_smp_ops::play_dead() as noreturn first?

I guess it really depends on how far we want to go down the __noreturn
rabbit hole. To keep the patch set constrained yet still useful I
stopped when I got to a function pointer, as I think it still needs a
BUG() afterwards either way.

That said, there would still be benefits of adding __noreturn to
function pointers, I just wanted to keep the patch set down to a
manageable size ;-)

--
Josh

2023-02-14 18:30:04

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2 00/24] cpu,sched: Mark arch_cpu_idle_dead() __noreturn

On Tue, Feb 14, 2023 at 10:25:50AM +0100, Philippe Mathieu-Daudé wrote:
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > v2:
> > - make arch_call_rest_init() and rest_init() __noreturn
> > - make objtool 'global_returns' work for weak functions
> > - rebase on tip/objtool/core with dependencies merged in (mingo)
> > - add acks
> >
> > v1.1:
> > - add __noreturn to all arch_cpu_idle_dead() implementations (mpe)
>
> Possible similar candidates: panic_smp_self_stop, nmi_panic_self_stop
> and kexec.

Agreed. Any volunteers?

--
Josh

2023-02-14 18:39:38

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2 03/24] arm/cpu: Make sure arch_cpu_idle_dead() doesn't return

On Tue, Feb 14, 2023 at 11:15:23AM +0000, Russell King (Oracle) wrote:
> On Mon, Feb 13, 2023 at 11:05:37PM -0800, Josh Poimboeuf wrote:
> > arch_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.
>
> This is silly. Just mark the function __noreturn and be done with it.
> If the CPU ever executes code past the "b" instruction, it's already
> really broken that the extra instructions that BUG() gives will be
> meaningless.
>
> This patch does nothing except add yet more bloat the kernel.
>
> Sorry, but NAK.

Problem is, the compiler can't read inline asm. So you'd get a
"'noreturn' function does return" warning.

We can do an unreachable() instead of a BUG() here if you prefer
undefined behavior.

--
Josh

2023-02-14 19:29:56

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

On Tue, 14 Feb 2023 10:23:22 -0800
Josh Poimboeuf <[email protected]> wrote:


> void __ref cpu_die(void)
> {
> idle_task_exit();
> local_irq_disable();
> __asm__ __volatile__(
> " movi a2, cpu_restart\n"
> " jx a2\n");
>
> BUG();
> }
>
> Hm, not only is the comment wrong, but it seems to be branching to
> cpu_restart? That doesn't seem right at all.

Agreed, that does not look right at all.

-- Steve

>
> Max/Chris?
>


2023-02-14 19:48:59

by Max Filippov

[permalink] [raw]
Subject: Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

On Tue, Feb 14, 2023 at 10:23 AM Josh Poimboeuf <[email protected]> wrote:
> On Tue, Feb 14, 2023 at 08:55:32AM +0100, Philippe Mathieu-Daudé wrote:
> > Can you update the documentation along? Currently we have:
> >
> > /*
> > * Called from the idle thread for the CPU which has been shutdown.
> > *
> > * Note that we disable IRQs here, but do not re-enable them
> > * before returning to the caller. This is also the behaviour
> > * of the other hotplug-cpu capable cores, so presumably coming
> > * out of idle fixes this.
> > */
>
> void __ref cpu_die(void)
> {
> idle_task_exit();
> local_irq_disable();
> __asm__ __volatile__(
> " movi a2, cpu_restart\n"
> " jx a2\n");
>
> BUG();
> }
>
> Hm, not only is the comment wrong, but it seems to be branching to
> cpu_restart? That doesn't seem right at all.

Perhaps the name is a bit misleading. The CPU that enters 'cpu_restart'
loops there until a call to 'boot_secondary' releases it, after which it goes
to '_startup'. So it is a restart, but not immediate.

--
Thanks.
-- Max

2023-02-14 20:19:23

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

On Tue, Feb 14, 2023 at 11:48:41AM -0800, Max Filippov wrote:
> On Tue, Feb 14, 2023 at 10:23 AM Josh Poimboeuf <[email protected]> wrote:
> > On Tue, Feb 14, 2023 at 08:55:32AM +0100, Philippe Mathieu-Daudé wrote:
> > > Can you update the documentation along? Currently we have:
> > >
> > > /*
> > > * Called from the idle thread for the CPU which has been shutdown.
> > > *
> > > * Note that we disable IRQs here, but do not re-enable them
> > > * before returning to the caller. This is also the behaviour
> > > * of the other hotplug-cpu capable cores, so presumably coming
> > > * out of idle fixes this.
> > > */
> >
> > void __ref cpu_die(void)
> > {
> > idle_task_exit();
> > local_irq_disable();
> > __asm__ __volatile__(
> > " movi a2, cpu_restart\n"
> > " jx a2\n");
> >
> > BUG();
> > }
> >
> > Hm, not only is the comment wrong, but it seems to be branching to
> > cpu_restart? That doesn't seem right at all.
>
> Perhaps the name is a bit misleading. The CPU that enters 'cpu_restart'
> loops there until a call to 'boot_secondary' releases it, after which it goes
> to '_startup'. So it is a restart, but not immediate.

Ah, I see. That sounds similar to what Xen does.

--
Josh

2023-02-14 22:02:40

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH v2 03/24] arm/cpu: Make sure arch_cpu_idle_dead() doesn't return

On Tue, Feb 14, 2023 at 10:39:26AM -0800, Josh Poimboeuf wrote:
> On Tue, Feb 14, 2023 at 11:15:23AM +0000, Russell King (Oracle) wrote:
> > On Mon, Feb 13, 2023 at 11:05:37PM -0800, Josh Poimboeuf wrote:
> > > arch_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.
> >
> > This is silly. Just mark the function __noreturn and be done with it.
> > If the CPU ever executes code past the "b" instruction, it's already
> > really broken that the extra instructions that BUG() gives will be
> > meaningless.
> >
> > This patch does nothing except add yet more bloat the kernel.
> >
> > Sorry, but NAK.
>
> Problem is, the compiler can't read inline asm. So you'd get a
> "'noreturn' function does return" warning.
>
> We can do an unreachable() instead of a BUG() here if you prefer
> undefined behavior.

That's fine.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

2023-02-15 08:29:32

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2 09/24] mips/cpu: Expose play_dead()'s prototype definition

On 14/2/23 19:11, Josh Poimboeuf wrote:
> On Tue, Feb 14, 2023 at 08:46:41AM +0100, Philippe Mathieu-Daudé wrote:
>> Hi Josh,
>>
>> On 14/2/23 08:05, Josh Poimboeuf wrote:
>>> Include <asm/smp.h> to make sure play_dead() matches its prototype going
>>> forward.
>>>
>>> Acked-by: Florian Fainelli <[email protected]>
>>> Signed-off-by: Josh Poimboeuf <[email protected]>
>>> ---
>>> arch/mips/kernel/smp-bmips.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
>>> index f5d7bfa3472a..df9158e8329d 100644
>>> --- a/arch/mips/kernel/smp-bmips.c
>>> +++ b/arch/mips/kernel/smp-bmips.c
>>> @@ -38,6 +38,7 @@
>>> #include <asm/traps.h>
>>> #include <asm/barrier.h>
>>> #include <asm/cpu-features.h>
>>> +#include <asm/smp.h>
>>
>> What about the other implementations?
>>
>> $ git grep -L asm/smp.h $(git grep -wlF 'play_dead(void)' arch/mips)
>> arch/mips/cavium-octeon/smp.c
>> arch/mips/kernel/smp-bmips.c
>> arch/mips/kernel/smp-cps.c
>> arch/mips/loongson64/smp.c
>
> Indeed. I really wish we had -Wmissing-prototypes.
>
> I'll squash this in:
>
> diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
> index 89954f5f87fb..4212584e6efa 100644
> --- a/arch/mips/cavium-octeon/smp.c
> +++ b/arch/mips/cavium-octeon/smp.c
> @@ -20,6 +20,7 @@
> #include <asm/mmu_context.h>
> #include <asm/time.h>
> #include <asm/setup.h>
> +#include <asm/smp.h>
>
> #include <asm/octeon/octeon.h>
>
> diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
> index bcd6a944b839..6d69a9ba8167 100644
> --- a/arch/mips/kernel/smp-cps.c
> +++ b/arch/mips/kernel/smp-cps.c
> @@ -20,6 +20,7 @@
> #include <asm/mipsregs.h>
> #include <asm/pm-cps.h>
> #include <asm/r4kcache.h>
> +#include <asm/smp.h>
> #include <asm/smp-cps.h>
> #include <asm/time.h>
> #include <asm/uasm.h>
> diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
> index c81c2bd07c62..df8d789ede3c 100644
> --- a/arch/mips/loongson64/smp.c
> +++ b/arch/mips/loongson64/smp.c
> @@ -14,6 +14,7 @@
> #include <linux/cpufreq.h>
> #include <linux/kexec.h>
> #include <asm/processor.h>
> +#include <asm/smp.h>
> #include <asm/time.h>
> #include <asm/tlbflush.h>
> #include <asm/cacheflush.h>

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>

Thanks.

2023-02-15 13:09:40

by Mark Rutland

[permalink] [raw]
Subject: Re: [PATCH v2 04/24] arm64/cpu: Mark cpu_die() __noreturn

On Tue, Feb 14, 2023 at 09:13:08AM +0100, Philippe Mathieu-Daudé wrote:
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > cpu_die() doesn't return. Annotate it as such. By extension this also
> > makes arch_cpu_idle_dead() noreturn.
> >
> > Signed-off-by: Josh Poimboeuf <[email protected]>
> > ---
> > arch/arm64/include/asm/smp.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
> > index fc55f5a57a06..5733a31bab08 100644
> > --- a/arch/arm64/include/asm/smp.h
> > +++ b/arch/arm64/include/asm/smp.h
> > @@ -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);
>
> Shouldn't cpu_operations::cpu_die() be declared noreturn first?

The cpu_die() function ends with a BUG(), and so does not return, even if a
cpu_operations::cpu_die() function that it calls erroneously returned.

We *could* mark cpu_operations::cpu_die() as noreturn, but I'd prefer that we
did not so that the compiler doesn't optimize away the BUG() which is there to
catch such erroneous returns.

That said, could we please add __noreturn to the implementation of cpu_die() in
arch/arm64/kernel/smp.c? i.e. the fixup below.

With that fixup:

Acked-by: Mark Rutland <[email protected]>

Mark.

---->8----
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index ffc5d76cf695..a98a76f7c1c6 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -361,7 +361,7 @@ void __cpu_die(unsigned int cpu)
* Called from the idle thread for the CPU which has been shutdown.
*
*/
-void cpu_die(void)
+void __noreturn cpu_die(void)
{
unsigned int cpu = smp_processor_id();
const struct cpu_operations *ops = get_cpu_ops(cpu);

2023-02-15 19:45:49

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2 04/24] arm64/cpu: Mark cpu_die() __noreturn

On Wed, Feb 15, 2023 at 01:09:21PM +0000, Mark Rutland wrote:
> On Tue, Feb 14, 2023 at 09:13:08AM +0100, Philippe Mathieu-Daudé wrote:
> > On 14/2/23 08:05, Josh Poimboeuf wrote:
> > > cpu_die() doesn't return. Annotate it as such. By extension this also
> > > makes arch_cpu_idle_dead() noreturn.
> > >
> > > Signed-off-by: Josh Poimboeuf <[email protected]>
> > > ---
> > > arch/arm64/include/asm/smp.h | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
> > > index fc55f5a57a06..5733a31bab08 100644
> > > --- a/arch/arm64/include/asm/smp.h
> > > +++ b/arch/arm64/include/asm/smp.h
> > > @@ -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);
> >
> > Shouldn't cpu_operations::cpu_die() be declared noreturn first?
>
> The cpu_die() function ends with a BUG(), and so does not return, even if a
> cpu_operations::cpu_die() function that it calls erroneously returned.
>
> We *could* mark cpu_operations::cpu_die() as noreturn, but I'd prefer that we
> did not so that the compiler doesn't optimize away the BUG() which is there to
> catch such erroneous returns.
>
> That said, could we please add __noreturn to the implementation of cpu_die() in
> arch/arm64/kernel/smp.c? i.e. the fixup below.

Done.

> With that fixup:
>
> Acked-by: Mark Rutland <[email protected]>

Thanks!

--
Josh

2023-02-15 22:23:04

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH v2 00/24] cpu,sched: Mark arch_cpu_idle_dead() __noreturn

On Mon, Feb 13, 2023 at 11:05:34PM -0800, Josh Poimboeuf wrote:
> v2:
> - make arch_call_rest_init() and rest_init() __noreturn
> - make objtool 'global_returns' work for weak functions
> - rebase on tip/objtool/core with dependencies merged in (mingo)
> - add acks
>
> v1.1:
> - add __noreturn to all arch_cpu_idle_dead() implementations (mpe)

With this, rcutorture no longer gets objtool complaints on x86, thank you!

Tested-by: Paul E. McKenney <[email protected]>

> Josh Poimboeuf (24):
> 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
> objtool: Include weak functions in 'global_noreturns' check
> init: Make arch_call_rest_init() and rest_init() __noreturn
> sched/idle: Mark arch_cpu_idle_dead() __noreturn
>
> arch/alpha/kernel/process.c | 4 +++-
> arch/arm/kernel/smp.c | 4 +++-
> arch/arm64/include/asm/smp.h | 2 +-
> arch/arm64/kernel/process.c | 2 +-
> arch/csky/kernel/smp.c | 4 +++-
> arch/ia64/kernel/process.c | 6 +++---
> arch/loongarch/include/asm/smp.h | 2 +-
> arch/loongarch/kernel/process.c | 2 +-
> arch/loongarch/kernel/smp.c | 2 +-
> arch/mips/include/asm/smp.h | 2 +-
> arch/mips/kernel/process.c | 2 +-
> arch/mips/kernel/smp-bmips.c | 3 +++
> arch/mips/loongson64/smp.c | 1 +
> arch/parisc/kernel/process.c | 2 +-
> arch/powerpc/include/asm/smp.h | 2 +-
> arch/powerpc/kernel/smp.c | 2 +-
> arch/riscv/kernel/cpu-hotplug.c | 2 +-
> arch/s390/kernel/idle.c | 2 +-
> arch/s390/kernel/setup.c | 2 +-
> arch/sh/include/asm/smp-ops.h | 5 +++--
> arch/sh/kernel/idle.c | 3 ++-
> arch/sparc/include/asm/smp_64.h | 2 +-
> arch/sparc/kernel/process_64.c | 2 +-
> arch/x86/include/asm/smp.h | 3 ++-
> arch/x86/kernel/process.c | 4 ++--
> arch/xtensa/include/asm/smp.h | 2 +-
> arch/xtensa/kernel/smp.c | 4 +++-
> include/linux/cpu.h | 2 +-
> include/linux/start_kernel.h | 4 ++--
> init/main.c | 4 ++--
> kernel/sched/idle.c | 2 +-
> tools/objtool/check.c | 11 +++++++----
> 32 files changed, 57 insertions(+), 39 deletions(-)
>
> --
> 2.39.1
>

2023-02-16 18:39:04

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2.1 03/24] arm/cpu: Add unreachable() to arch_cpu_idle_dead()

arch_cpu_idle_dead() doesn't return. Make that visible to the compiler
with an unreachable() code annotation.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/arm/kernel/smp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 0b8c25763adc..441ea5cff390 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -382,6 +382,8 @@ void arch_cpu_idle_dead(void)
: "r" (task_stack_page(current) + THREAD_SIZE - 8),
"r" (current)
: "r0");
+
+ unreachable();
}
#endif /* CONFIG_HOTPLUG_CPU */

--
2.39.1


2023-02-16 18:42:10

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2.1 04/24] arm64/cpu: Mark cpu_die() __noreturn

cpu_die() doesn't return. Annotate it as such. By extension this also
makes arch_cpu_idle_dead() noreturn.

Acked-by: Mark Rutland <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/arm64/include/asm/smp.h | 2 +-
arch/arm64/kernel/smp.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index fc55f5a57a06..5733a31bab08 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -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)
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 4e8327264255..d5d09a18b4f8 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -361,7 +361,7 @@ void __cpu_die(unsigned int cpu)
* Called from the idle thread for the CPU which has been shutdown.
*
*/
-void cpu_die(void)
+void __noreturn cpu_die(void)
{
unsigned int cpu = smp_processor_id();
const struct cpu_operations *ops = get_cpu_ops(cpu);
--
2.39.1


2023-02-16 18:43:07

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH v2.1 09/24] mips/cpu: Expose play_dead()'s prototype definition

Include <asm/smp.h> to make sure play_dead() matches its prototype going
forward.

Acked-by: Florian Fainelli <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/cavium-octeon/smp.c | 1 +
arch/mips/kernel/smp-bmips.c | 1 +
arch/mips/kernel/smp-cps.c | 1 +
arch/mips/loongson64/smp.c | 1 +
4 files changed, 4 insertions(+)

diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
index 89954f5f87fb..4212584e6efa 100644
--- a/arch/mips/cavium-octeon/smp.c
+++ b/arch/mips/cavium-octeon/smp.c
@@ -20,6 +20,7 @@
#include <asm/mmu_context.h>
#include <asm/time.h>
#include <asm/setup.h>
+#include <asm/smp.h>

#include <asm/octeon/octeon.h>

diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index f5d7bfa3472a..df9158e8329d 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -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;

diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index bcd6a944b839..6d69a9ba8167 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -20,6 +20,7 @@
#include <asm/mipsregs.h>
#include <asm/pm-cps.h>
#include <asm/r4kcache.h>
+#include <asm/smp.h>
#include <asm/smp-cps.h>
#include <asm/time.h>
#include <asm/uasm.h>
diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index 660e1de4412a..4e24b317e7cb 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -14,6 +14,7 @@
#include <linux/cpufreq.h>
#include <linux/kexec.h>
#include <asm/processor.h>
+#include <asm/smp.h>
#include <asm/time.h>
#include <asm/tlbflush.h>
#include <asm/cacheflush.h>
--
2.39.1


2023-03-01 18:17:25

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v2.1 09/24] mips/cpu: Expose play_dead()'s prototype definition

On Thu, Feb 16, 2023 at 10:42:52AM -0800, Josh Poimboeuf wrote:
> Include <asm/smp.h> to make sure play_dead() matches its prototype going
> forward.
>
> Acked-by: Florian Fainelli <[email protected]>
> Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>

The latest version of this patch triggered a new kbuild warning which is
fixed by the below patch. If there are no objections I'll bundle it in
with the rest of the set for merging.

---8<---

Subject: [PATCH] mips/smp: Add CONFIG_SMP guard for raw_smp_processor_id()
Content-type: text/plain

Without CONFIG_SMP, raw_smp_processor_id() is not expected to be defined
by the arch.

Reported-by: kernel test robot <[email protected]>
Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/include/asm/smp.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
index 4eee29b7845c..cf992b8b1e46 100644
--- a/arch/mips/include/asm/smp.h
+++ b/arch/mips/include/asm/smp.h
@@ -25,6 +25,7 @@ extern cpumask_t cpu_sibling_map[];
extern cpumask_t cpu_core_map[];
extern cpumask_t cpu_foreign_map[];

+#ifdef CONFIG_SMP
static inline int raw_smp_processor_id(void)
{
#if defined(__VDSO__)
@@ -36,6 +37,7 @@ static inline int raw_smp_processor_id(void)
#endif
}
#define raw_smp_processor_id raw_smp_processor_id
+#endif

/* Map from cpu id to sequential logical cpu number. This will only
not be idempotent when cpus failed to come on-line. */
--
2.39.1


2023-03-02 10:55:18

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2.1 09/24] mips/cpu: Expose play_dead()'s prototype definition

On 1/3/23 19:16, Josh Poimboeuf wrote:

> The latest version of this patch triggered a new kbuild warning which is
> fixed by the below patch. If there are no objections I'll bundle it in
> with the rest of the set for merging.
>
> ---8<---
>
> Subject: [PATCH] mips/smp: Add CONFIG_SMP guard for raw_smp_processor_id()
> Content-type: text/plain
>
> Without CONFIG_SMP, raw_smp_processor_id() is not expected to be defined
> by the arch.
>
> Reported-by: kernel test robot <[email protected]>
> Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/mips/include/asm/smp.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
> index 4eee29b7845c..cf992b8b1e46 100644
> --- a/arch/mips/include/asm/smp.h
> +++ b/arch/mips/include/asm/smp.h
> @@ -25,6 +25,7 @@ extern cpumask_t cpu_sibling_map[];
> extern cpumask_t cpu_core_map[];
> extern cpumask_t cpu_foreign_map[];
>
> +#ifdef CONFIG_SMP
> static inline int raw_smp_processor_id(void)
> {
> #if defined(__VDSO__)
> @@ -36,6 +37,7 @@ static inline int raw_smp_processor_id(void)
> #endif
> }
> #define raw_smp_processor_id raw_smp_processor_id
> +#endif
>
> /* Map from cpu id to sequential logical cpu number. This will only
> not be idempotent when cpus failed to come on-line. */

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>


2023-03-02 10:56:09

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH v2.1 04/24] arm64/cpu: Mark cpu_die() __noreturn

On 16/2/23 19:41, Josh Poimboeuf wrote:
> cpu_die() doesn't return. Annotate it as such. By extension this also
> makes arch_cpu_idle_dead() noreturn.
>
> Acked-by: Mark Rutland <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> arch/arm64/include/asm/smp.h | 2 +-
> arch/arm64/kernel/smp.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>


Subject: [tip: objtool/core] sched/idle: Mark arch_cpu_idle_dead() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 071c44e4278156f18a6a56958617223b6bffa6ab
Gitweb: https://git.kernel.org/tip/071c44e4278156f18a6a56958617223b6bffa6ab
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:58 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:28 -08:00

sched/idle: Mark arch_cpu_idle_dead() __noreturn

Before 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

Reported-by: Paul E. McKenney <[email protected]>
Tested-by: Paul E. McKenney <[email protected]>
Link: https://lore.kernel.org/r/60d527353da8c99d4cf13b6473131d46719ed16d.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
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 +-
kernel/sched/idle.c | 2 +-
tools/objtool/check.c | 1 +
18 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index a82fefa..582d965 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -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();
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 441ea5c..d6be450 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -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();

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 71d59b5..089ced6 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -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();
}
diff --git a/arch/csky/kernel/smp.c b/arch/csky/kernel/smp.c
index 0ec20ef..9c7a20b 100644
--- a/arch/csky/kernel/smp.c
+++ b/arch/csky/kernel/smp.c
@@ -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();

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index 78f5794..9a5cd9f 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -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();
}
diff --git a/arch/loongarch/kernel/process.c b/arch/loongarch/kernel/process.c
index fa2443c..b71e17c 100644
--- a/arch/loongarch/kernel/process.c
+++ b/arch/loongarch/kernel/process.c
@@ -62,7 +62,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();
}
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 093dbbd..a322591 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -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();
}
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index c064719..97c6f87 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -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();
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 6b90f10..f62e5e6 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -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
diff --git a/arch/riscv/kernel/cpu-hotplug.c b/arch/riscv/kernel/cpu-hotplug.c
index f7a832e..59b8021 100644
--- a/arch/riscv/kernel/cpu-hotplug.c
+++ b/arch/riscv/kernel/cpu-hotplug.c
@@ -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();

diff --git a/arch/s390/kernel/idle.c b/arch/s390/kernel/idle.c
index 38e267c..e7239aa 100644
--- a/arch/s390/kernel/idle.c
+++ b/arch/s390/kernel/idle.c
@@ -88,7 +88,7 @@ void arch_cpu_idle_exit(void)
{
}

-void arch_cpu_idle_dead(void)
+void __noreturn arch_cpu_idle_dead(void)
{
cpu_die();
}
diff --git a/arch/sh/kernel/idle.c b/arch/sh/kernel/idle.c
index 114f0c4..d662503 100644
--- a/arch/sh/kernel/idle.c
+++ b/arch/sh/kernel/idle.c
@@ -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();
}
diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
index 91c2b81..b51d8fb 100644
--- a/arch/sparc/kernel/process_64.c
+++ b/arch/sparc/kernel/process_64.c
@@ -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();
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index f1ec36c..3e30147 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -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();
}
diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
index 7bad784..054bd64 100644
--- a/arch/xtensa/kernel/smp.c
+++ b/arch/xtensa/kernel/smp.c
@@ -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();
}
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index f83e451..8582a71 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -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);
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 56e152f..342f58a 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -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) { while (1); }
+void __weak __noreturn arch_cpu_idle_dead(void) { while (1); }
void __weak arch_cpu_idle(void)
{
cpu_idle_force_poll = 1;
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f937be1..37c36dc 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -202,6 +202,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",

Subject: [tip: objtool/core] xtensa/cpu: Make sure cpu_die() doesn't return

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: d08e12e8126ec88d6cb1a7eb160d8d7b52c8699f
Gitweb: https://git.kernel.org/tip/d08e12e8126ec88d6cb1a7eb160d8d7b52c8699f
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:53 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:27 -08:00

xtensa/cpu: Make sure cpu_die() doesn't return

cpu_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.

Link: https://lore.kernel.org/r/cca346b5c87693499e630291d78fb0bf12c24290.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/xtensa/kernel/smp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
index 4dc109d..7bad784 100644
--- a/arch/xtensa/kernel/smp.c
+++ b/arch/xtensa/kernel/smp.c
@@ -341,6 +341,8 @@ void __ref cpu_die(void)
__asm__ __volatile__(
" movi a2, cpu_restart\n"
" jx a2\n");
+
+ BUG();
}

#endif /* CONFIG_HOTPLUG_CPU */

Subject: [tip: objtool/core] xtensa/cpu: Mark cpu_die() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 69dee6f0338a20c76a7bc61c0a6b59f25e1b25c8
Gitweb: https://git.kernel.org/tip/69dee6f0338a20c76a7bc61c0a6b59f25e1b25c8
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:54 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:27 -08:00

xtensa/cpu: Mark cpu_die() __noreturn

cpu_die() doesn't return. Annotate it as such. By extension this also
makes arch_cpu_idle_dead() noreturn.

Acked-by: Max Filippov <[email protected]>
Link: https://lore.kernel.org/r/ad801544cab7c26a0f3bbf7cfefb67303f4cd866.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/xtensa/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/xtensa/include/asm/smp.h b/arch/xtensa/include/asm/smp.h
index 4e43f56..5dc5bf8 100644
--- a/arch/xtensa/include/asm/smp.h
+++ b/arch/xtensa/include/asm/smp.h
@@ -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 */

Subject: [tip: objtool/core] sched/idle: Make sure weak version of arch_cpu_idle_dead() doesn't return

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: dfb0f170cadb03da4f408ae53cc2908120e1f90e
Gitweb: https://git.kernel.org/tip/dfb0f170cadb03da4f408ae53cc2908120e1f90e
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:55 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:27 -08:00

sched/idle: Make sure weak version of arch_cpu_idle_dead() doesn't return

arch_cpu_idle_dead() should never return. Make it so.

Link: https://lore.kernel.org/r/cf5ad95eef50f7704bb30e7770c59bfe23372af7.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
kernel/sched/idle.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index e9ef66b..56e152f 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -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;

Subject: [tip: objtool/core] x86/cpu: Expose arch_cpu_idle_dead()'s prototype definition

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: b4c108d7daf1039cf19388baff30a94563de3f3e
Gitweb: https://git.kernel.org/tip/b4c108d7daf1039cf19388baff30a94563de3f3e
Author: Philippe Mathieu-Daudé <[email protected]>
AuthorDate: Tue, 14 Feb 2023 09:38:57 +01:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:30 -08:00

x86/cpu: Expose arch_cpu_idle_dead()'s prototype definition

Include <linux/cpu.h> to make sure arch_cpu_idle_dead() matches its
prototype going forward.

Inspired-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/x86/kernel/process.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 3e30147..d9ecaa6 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -5,6 +5,7 @@
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/smp.h>
+#include <linux/cpu.h>
#include <linux/prctl.h>
#include <linux/slab.h>
#include <linux/sched.h>

Subject: [tip: objtool/core] sparc/cpu: Mark cpu_play_dead() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: b9952d5009440b01dedd793a57abbe6cfe10f995
Gitweb: https://git.kernel.org/tip/b9952d5009440b01dedd793a57abbe6cfe10f995
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:50 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:25 -08:00

sparc/cpu: Mark cpu_play_dead() __noreturn

cpu_play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lore.kernel.org/r/847fdb53cc7124bb7c94e3e104e443a29be85184.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sparc/include/asm/smp_64.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/smp_64.h b/arch/sparc/include/asm/smp_64.h
index e75783b..505b670 100644
--- a/arch/sparc/include/asm/smp_64.h
+++ b/arch/sparc/include/asm/smp_64.h
@@ -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);

Subject: [tip: objtool/core] x86/cpu: Mark play_dead() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: eab89405b6b59947ee29cc21fb39ead66142c9b5
Gitweb: https://git.kernel.org/tip/eab89405b6b59947ee29cc21fb39ead66142c9b5
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:52 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:26 -08:00

x86/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Link: https://lore.kernel.org/r/f3a069e6869c51ccfdda656b76882363bc9fcfa4.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/x86/include/asm/smp.h | 2 +-
arch/x86/kernel/process.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 8f628e0..e6d1d28 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -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();
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index b650cde..f1ec36c 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -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();
}

Subject: [tip: objtool/core] x86/cpu: Make sure play_dead() doesn't return

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: a02f50b573b3c90a3633a5ab67435fe4c0de144d
Gitweb: https://git.kernel.org/tip/a02f50b573b3c90a3633a5ab67435fe4c0de144d
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:51 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:26 -08:00

x86/cpu: Make sure play_dead() doesn't return

After 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.

Link: https://lore.kernel.org/r/11e6ac1cf10f92967882926e3ac16287b50642f2.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/x86/include/asm/smp.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index b4dbb20..8f628e0 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -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)

Subject: [tip: objtool/core] sh/cpu: Make sure play_dead() doesn't return

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 243971885418fcf772f18019eb3fabadcf0205d1
Gitweb: https://git.kernel.org/tip/243971885418fcf772f18019eb3fabadcf0205d1
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:47 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:24 -08:00

sh/cpu: Make sure play_dead() doesn't return

play_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.

Link: https://lore.kernel.org/r/d0c3ff5349adfe8fd227acc236ae2c278a05eb4c.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sh/include/asm/smp-ops.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
index e277021..63866b1 100644
--- a/arch/sh/include/asm/smp-ops.h
+++ b/arch/sh/include/asm/smp-ops.h
@@ -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);

Subject: [tip: objtool/core] powerpc/cpu: Mark start_secondary_resume() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 5e00d69cdef4cd1c737e6286a39f83ce20a91034
Gitweb: https://git.kernel.org/tip/5e00d69cdef4cd1c737e6286a39f83ce20a91034
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:46 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:24 -08:00

powerpc/cpu: Mark start_secondary_resume() __noreturn

start_secondary_resume() doesn't return. Annotate it as such. By
extension this also makes arch_cpu_idle_dead() noreturn.

Acked-by: Michael Ellerman <[email protected]> (powerpc)
Reviewed-by: Christophe Leroy <[email protected]>
Link: https://lore.kernel.org/r/b6b2141f832d8cd8ade65f190d04b011cda5f9bb.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/powerpc/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
index 6c6cb53..aaaa576 100644
--- a/arch/powerpc/include/asm/smp.h
+++ b/arch/powerpc/include/asm/smp.h
@@ -67,7 +67,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);


Subject: [tip: objtool/core] sh/cpu: Expose arch_cpu_idle_dead()'s prototype definition

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: fd49efb3c75475b65d7541ee40603498807ff110
Gitweb: https://git.kernel.org/tip/fd49efb3c75475b65d7541ee40603498807ff110
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:49 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:25 -08:00

sh/cpu: Expose arch_cpu_idle_dead()'s prototype definition

Include <linux/cpu.h> to make sure arch_cpu_idle_dead() matches its
prototype going forward.

Link: https://lore.kernel.org/r/3d9661e97828fb464a48d4becf18f12604831903.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sh/kernel/idle.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/sh/kernel/idle.c b/arch/sh/kernel/idle.c
index 3418c40..114f0c4 100644
--- a/arch/sh/kernel/idle.c
+++ b/arch/sh/kernel/idle.c
@@ -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>

Subject: [tip: objtool/core] sh/cpu: Mark play_dead() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 1644b74192265875cdf37dadfa33f34e0ea4fcc8
Gitweb: https://git.kernel.org/tip/1644b74192265875cdf37dadfa33f34e0ea4fcc8
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:48 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:24 -08:00

sh/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Link: https://lore.kernel.org/r/03549a74fad9f73576d57e6fc0b5102322f9cff4.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/sh/include/asm/smp-ops.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
index 63866b1..97331fc 100644
--- a/arch/sh/include/asm/smp-ops.h
+++ b/arch/sh/include/asm/smp-ops.h
@@ -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();
}

Subject: [tip: objtool/core] mips/cpu: Make sure play_dead() doesn't return

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: a80ceed6c9c24088d7a2e3c414eae1fe88a8ccbe
Gitweb: https://git.kernel.org/tip/a80ceed6c9c24088d7a2e3c414eae1fe88a8ccbe
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:44 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:23 -08:00

mips/cpu: Make sure play_dead() doesn't return

play_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.

Acked-by: Florian Fainelli <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lore.kernel.org/r/b195e4da190bb06b7d4af15d66ce6129e2347630.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/kernel/smp-bmips.c | 2 ++
arch/mips/loongson64/smp.c | 1 +
2 files changed, 3 insertions(+)

diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index 51d5dae..15466d4 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -415,6 +415,8 @@ void __ref play_dead(void)
" wait\n"
" j bmips_secondary_reentry\n"
: : : "memory");
+
+ BUG();
}

#endif /* CONFIG_HOTPLUG_CPU */
diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index 4e24b31..df8d789 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -823,6 +823,7 @@ out:
state_addr = &per_cpu(cpu_state, cpu);
mb();
play_dead_at_ckseg1(state_addr);
+ BUG();
}

static int loongson3_disable_clock(unsigned int cpu)

Subject: [tip: objtool/core] mips/cpu: Mark play_dead() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 9e57f049d1571db1dc77c69c87403defc9d3e5ae
Gitweb: https://git.kernel.org/tip/9e57f049d1571db1dc77c69c87403defc9d3e5ae
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:45 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:23 -08:00

mips/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Acked-by: Florian Fainelli <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lore.kernel.org/r/2897b51a9b8beb5b594fe66fb1d3a479ddd2a0e2.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
index 5d9ff61..4eee29b 100644
--- a/arch/mips/include/asm/smp.h
+++ b/arch/mips/include/asm/smp.h
@@ -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

Subject: [tip: objtool/core] mips/cpu: Expose play_dead()'s prototype definition

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 142dbcf3b6a93ecfe8ccbee60c611175f5459c23
Gitweb: https://git.kernel.org/tip/142dbcf3b6a93ecfe8ccbee60c611175f5459c23
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 16 Feb 2023 10:42:52 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Wed, 08 Mar 2023 08:44:19 -08:00

mips/cpu: Expose play_dead()'s prototype definition

Include <asm/smp.h> to make sure play_dead() matches its prototype going
forward.

Acked-by: Florian Fainelli <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lkml.kernel.org/r/20230216184249.ogaqsaykottpxtcb@treble
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/mips/cavium-octeon/smp.c | 1 +
arch/mips/kernel/smp-bmips.c | 2 ++
arch/mips/kernel/smp-cps.c | 1 +
arch/mips/loongson64/smp.c | 1 +
4 files changed, 5 insertions(+)

diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
index 89954f5..4212584 100644
--- a/arch/mips/cavium-octeon/smp.c
+++ b/arch/mips/cavium-octeon/smp.c
@@ -20,6 +20,7 @@
#include <asm/mmu_context.h>
#include <asm/time.h>
#include <asm/setup.h>
+#include <asm/smp.h>

#include <asm/octeon/octeon.h>

diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index f5d7bfa..51d5dae 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -54,6 +54,8 @@ static void bmips_set_reset_vec(int cpu, u32 val);

#ifdef CONFIG_SMP

+#include <asm/smp.h>
+
/* initial $sp, $gp - used by arch/mips/kernel/bmips_vec.S */
unsigned long bmips_smp_boot_sp;
unsigned long bmips_smp_boot_gp;
diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index 4fc288b..00a0e25 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -20,6 +20,7 @@
#include <asm/mipsregs.h>
#include <asm/pm-cps.h>
#include <asm/r4kcache.h>
+#include <asm/smp.h>
#include <asm/smp-cps.h>
#include <asm/time.h>
#include <asm/uasm.h>
diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index 660e1de..4e24b31 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -14,6 +14,7 @@
#include <linux/cpufreq.h>
#include <linux/kexec.h>
#include <asm/processor.h>
+#include <asm/smp.h>
#include <asm/time.h>
#include <asm/tlbflush.h>
#include <asm/cacheflush.h>

Subject: [tip: objtool/core] loongarch/cpu: Mark play_dead() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 6c0f2d071eded22cb72413e0abfaa5b3373b4d96
Gitweb: https://git.kernel.org/tip/6c0f2d071eded22cb72413e0abfaa5b3373b4d96
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:42 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Mon, 06 Mar 2023 15:34:06 -08:00

loongarch/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lore.kernel.org/r/4da55acfdec8a9132c4e21ffb7edb1f846841193.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/loongarch/include/asm/smp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/include/asm/smp.h b/arch/loongarch/include/asm/smp.h
index d826873..416b653 100644
--- a/arch/loongarch/include/asm/smp.h
+++ b/arch/loongarch/include/asm/smp.h
@@ -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 */

Subject: [tip: objtool/core] ia64/cpu: Mark play_dead() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 93c0edffbc92abe1efb8c7081df0cc1577a79ace
Gitweb: https://git.kernel.org/tip/93c0edffbc92abe1efb8c7081df0cc1577a79ace
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:40 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Mon, 06 Mar 2023 15:34:05 -08:00

ia64/cpu: Mark play_dead() __noreturn

play_dead() doesn't return. Annotate it as such. By extension this
also makes arch_cpu_idle_dead() noreturn.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lore.kernel.org/r/7575bb38417bd8bcb5be980443f99cab29319342.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/ia64/kernel/process.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index f6195a0..78f5794 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -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();
}

Subject: [tip: objtool/core] loongarch/cpu: Make sure play_dead() doesn't return

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 13bf7923a4dd34f3d2681768a148b10ddbdb95ed
Gitweb: https://git.kernel.org/tip/13bf7923a4dd34f3d2681768a148b10ddbdb95ed
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:41 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Mon, 06 Mar 2023 15:34:06 -08:00

loongarch/cpu: Make sure play_dead() doesn't return

play_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.

Link: https://lore.kernel.org/r/21245d687ffeda34dbcf04961a2df3724f04f7c8.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/loongarch/kernel/smp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c
index 8c6e227..51f3281 100644
--- a/arch/loongarch/kernel/smp.c
+++ b/arch/loongarch/kernel/smp.c
@@ -336,7 +336,7 @@ void play_dead(void)
iocsr_write32(0xffffffff, LOONGARCH_IOCSR_IPI_CLEAR);

init_fn();
- unreachable();
+ BUG();
}

#endif

Subject: [tip: objtool/core] arm64/cpu: Mark cpu_die() __noreturn

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 9bdc61ef27db5eaac48f1cc5deb8224603e79c89
Gitweb: https://git.kernel.org/tip/9bdc61ef27db5eaac48f1cc5deb8224603e79c89
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 16 Feb 2023 10:42:01 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Mon, 06 Mar 2023 15:34:04 -08:00

arm64/cpu: Mark cpu_die() __noreturn

cpu_die() doesn't return. Annotate it as such. By extension this also
makes arch_cpu_idle_dead() noreturn.

Acked-by: Mark Rutland <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lkml.kernel.org/r/20230216184157.4hup6y6mmspr2kll@treble
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/arm64/include/asm/smp.h | 2 +-
arch/arm64/kernel/smp.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index fc55f5a..5733a31 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -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)
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 4e83272..d5d09a1 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -361,7 +361,7 @@ void __cpu_die(unsigned int cpu)
* Called from the idle thread for the CPU which has been shutdown.
*
*/
-void cpu_die(void)
+void __noreturn cpu_die(void)
{
unsigned int cpu = smp_processor_id();
const struct cpu_operations *ops = get_cpu_ops(cpu);

Subject: [tip: objtool/core] csky/cpu: Make sure arch_cpu_idle_dead() doesn't return

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 1b2442a835a0acc7d76ae2f48ca7a94f962b29c8
Gitweb: https://git.kernel.org/tip/1b2442a835a0acc7d76ae2f48ca7a94f962b29c8
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:39 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Mon, 06 Mar 2023 15:34:05 -08:00

csky/cpu: Make sure arch_cpu_idle_dead() doesn't return

arch_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.

Acked-by: Guo Ren <[email protected]>
Link: https://lore.kernel.org/r/1e9ecc3d248e82973e80bc336fc9f97e3ba2708d.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/csky/kernel/smp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/csky/kernel/smp.c b/arch/csky/kernel/smp.c
index b45d107..0ec20ef 100644
--- a/arch/csky/kernel/smp.c
+++ b/arch/csky/kernel/smp.c
@@ -317,5 +317,7 @@ void arch_cpu_idle_dead(void)
"jmpi csky_start_secondary"
:
: "r" (secondary_stack));
+
+ BUG();
}
#endif

Subject: [tip: objtool/core] alpha/cpu: Expose arch_cpu_idle_dead()'s prototype declaration

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 1e8a0be5ed3aaa26dd77927df32bbd0df3449a1e
Gitweb: https://git.kernel.org/tip/1e8a0be5ed3aaa26dd77927df32bbd0df3449a1e
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 Feb 2023 23:05:35 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Mon, 06 Mar 2023 15:34:03 -08:00

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.

Link: https://lore.kernel.org/r/b0405c2ac5686303b6026e1ac27cfd769b21a7d0.1676358308.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/alpha/kernel/process.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index e9cf719..3251102 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -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>

Subject: [tip: objtool/core] arm/cpu: Add unreachable() to arch_cpu_idle_dead()

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: b40c7d6d31ac2f6b78371cdc08bc1b6b62f01375
Gitweb: https://git.kernel.org/tip/b40c7d6d31ac2f6b78371cdc08bc1b6b62f01375
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 16 Feb 2023 10:38:55 -08:00
Committer: Josh Poimboeuf <[email protected]>
CommitterDate: Mon, 06 Mar 2023 15:34:04 -08:00

arm/cpu: Add unreachable() to arch_cpu_idle_dead()

arch_cpu_idle_dead() doesn't return. Make that visible to the compiler
with an unreachable() code annotation.

Link: https://lkml.kernel.org/r/20230216183851.s5bnvniomq44rytu@treble
Signed-off-by: Josh Poimboeuf <[email protected]>
---
arch/arm/kernel/smp.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 0b8c257..441ea5c 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -382,6 +382,8 @@ void arch_cpu_idle_dead(void)
: "r" (task_stack_page(current) + THREAD_SIZE - 8),
"r" (current)
: "r0");
+
+ unreachable();
}
#endif /* CONFIG_HOTPLUG_CPU */