Skip to contentSkip to conversation

panic: stop CPUs that lose the panic_redirect_cpu race

PATCH Superseded Bradley Morgan 2 participants 3 messages Jul 7

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 panic: stop CPUs that lose the panic_redirect_cpu race

Loser of the redirect cmpxchg must stop, not fall through to panic_try_start().

This issue was found by sashiko [1].

[1] https://sashiko.dev/#/patchset/20260705164123.18746-1-include%40grrlz.net

---
 kernel/panic.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/panic.c +2 -5
index 03f1eef07b17..8ba3ec12db3a 100644
@@ -400,12 +400,9 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)
 	if (panic_in_progress())
 		return false;
 
-	/*
-	 * Only one CPU can do the redirect. Use atomic cmpxchg to ensure
-	 * we don't race with another CPU also trying to redirect.
-	 */
+	/* Only one CPU redirects, the loser stops and lets it finish. */
 	if (!atomic_try_cmpxchg(&panic_redirect_cpu, &old_cpu, this_cpu))
-		return false;
+		return true;
 
 	/*
 	 * Use dynamically allocated buffer if available, otherwise
Signature · 1 line
2.53.0
#1 lore raw
Quoted 16 lines · On Tue, 7 Jul 2026 17:22:52 +0000 Bradley Morgan <[email protected]> wrote:

Loser of the redirect cmpxchg must stop, not fall through to panic_try_start().

This issue was found by sashiko [1].

[1] https://sashiko.dev/#/patchset/20260705164123.18746-1-include%40grrlz.net

...

kernel/panic.c +0 -1
@@ -400,12 +400,9 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)
 	if (panic_in_progress())
 		return false;
 
-	/*

kernel/panic.c static bool panic_try_force_cpu(const char *fmt, va_list args) · line 408

Quoted 10 lines
kernel/panic.c +2 -4
-	 * Only one CPU can do the redirect. Use atomic cmpxchg to ensure
-	 * we don't race with another CPU also trying to redirect.
-	 */
+	/* Only one CPU redirects, the loser stops and lets it finish. */
 	if (!atomic_try_cmpxchg(&panic_redirect_cpu, &old_cpu, this_cpu))
-		return false;
+		return true;
 
 	/*
 	 * Use dynamically allocated buffer if available, otherwise

Sashiko is at it again:

	https://sashiko.dev/#/patchset/[email protected]
#2 lore raw
Quoted 29 lines · Andrew Morton
Quoted 6 lines · On Tue, 7 Jul 2026 17:22:52 +0000 Bradley Morgan <[email protected]> wrote:

Loser of the redirect cmpxchg must stop, not fall through to panic_try_start().

This issue was found by sashiko [1].

[1]

https://sashiko.dev/#/patchset/20260705164123.18746-1-include%40grrlz.net

kernel/panic.c static bool panic_try_force_cpu(const char *fmt,

Quoted 6 lines

...

kernel/panic.c +0 -0
@@ -400,12 +400,9 @@ static bool panic_try_force_cpu(const char *fmt,

va_list args)

Quoted 12 lines
kernel/panic.c +2 -5
 	if (panic_in_progress())
 		return false;
 
-	/*
-	 * Only one CPU can do the redirect. Use atomic cmpxchg to ensure
-	 * we don't race with another CPU also trying to redirect.
-	 */
+	/* Only one CPU redirects, the loser stops and lets it finish. */
 	if (!atomic_try_cmpxchg(&panic_redirect_cpu, &old_cpu, this_cpu))
-		return false;
+		return true;
 
Quoted 7 lines

kernel/panic.c static bool panic_try_force_cpu(const char *fmt, va_list args) · line 408

Quoted 2 lines
kernel/panic.c +0 -0
 	/*
 	 * Use dynamically allocated buffer if available, otherwise

Sashiko is at it again:

	https://sashiko.dev/#/patchset/[email protected]

touche, already onto the fix.

I tend to overengineer, this time I UNDERengineered.

V2 is coming

Thanks!