The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Bradley Morgan <include@grrlz.net>
Cc: akpm@linux-foundation.org, feng.tang@linux.alibaba.com,
	Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] panic: make force_cpu redirect work from an NMI
Date: Wed, 8 Jul 2026 14:44:09 +0200	[thread overview]
Message-ID: <ak5GGf7ypVthkZk_@pathway.suse.cz> (raw)
In-Reply-To: <20260707205921.15247-1-include@grrlz.net>

Adding more people into Cc.

I wonder if smp_call_function_single_async() can be called
safely from NMI. Maybe, we should skip the redirection
completely in this case.

On Tue 2026-07-07 20:59:21, Bradley Morgan wrote:
> nmi_panic sets panic_cpu first. Bail only on a different
> owner, and hand panic_cpu to the target after the IPI.

This is quite cryptic.
Who should bail?
What is target?
What IPI?

Please, do more descriptive commit messages and better
explain the problematic situation.

> Found by sashiko [1].

Better to use:
Reported-by: Sashiko <sashiko-bot@kernel.org>

> [1]
> https://sashiko.dev/#/patchset/20260707183253.9793-1-include@grrlz.net

Closes: https://sashiko.dev/#/patchset/20260707183253.9793-1-include@grrlz.net

> Signed-off-by: Bradley Morgan <include@grrlz.net>

> --- a/kernel/panic.c
> +++ b/kernel/panic.c
> @@ -396,8 +396,8 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)
>  		return false;
>  	}
>  
> -	/* Another panic already in progress */
> -	if (panic_in_progress())
> +	/* Bail only if a different CPU is already handling it. */
> +	if (panic_in_progress() && atomic_read(&panic_cpu) != this_cpu)

There already exist panic_on_other_cpu()...

>  		return false;

This looks strange. "return false" means that vpanic() will
continue with panic. I would expect that this CPU should end up
offline.

It would actually work because vpanic() continues with:

	if (panic_try_start()) {
		/* go ahead */
	} else if (panic_on_other_cpu())
		panic_smp_self_stop();

And panic_try_start() would obviously fail while panic_on_other_cpu()
succeed.

But still, it would be more straightforward to do here: 

	/* Stop this CPU when the panic is already proceed elsewhere. */
	if (panic_on_other_cpu())
		return true;

> -	/* Another panic already in progress */
> -	if (panic_in_progress())
> +	/* Bail only if a different CPU is already handling it. */
> +	if (panic_in_progress() && atomic_read(&panic_cpu) != this_cpu)
>  
>  	/* Which CPU won the race? */
> @@ -440,6 +440,9 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)
>  		return false;
>  	}
>  
> +	/* Hand panic_cpu to the target so it wins its own panic_try_start. */
> +	atomic_set(&panic_cpu, panic_force_cpu);

As I already mentioned, this is too late. The panic_force_cpu might
already be offline because it called panic_try_start() earlier it
it failed.

The main question is whether we could safely call
smp_call_function_single_async() from NMI at all.

If not then we will need to proceed panic() on this CPU.

If yes then we need to fix this in nmi_panic(). It should
call panic_try_force_cpu() first. It should call panic_try_start()
only when panic_try_force_cpu() returns false, like when
it did not forced another CPU.
r
>  	/* IPI/NMI sent, this CPU should stop */
>  	return true;

Best Regards,
Petr

      reply	other threads:[~2026-07-08 12:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 20:59 [PATCH] panic: make force_cpu redirect work from an NMI Bradley Morgan
2026-07-08 12:44 ` Petr Mladek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ak5GGf7ypVthkZk_@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=feng.tang@linux.alibaba.com \
    --cc=include@grrlz.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox