The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Waiman Long <llong@redhat.com>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	"H. Peter Anvin" <hpa@zytor.com>, Rik van Riel <riel@surriel.com>
Subject: Re: [PATCH v4] x86/nmi: Add an emergency handler in nmi_desc & use it in nmi_shootdown_cpus()
Date: Thu, 06 Feb 2025 17:14:19 +0100	[thread overview]
Message-ID: <871pwbnj8k.ffs@tglx> (raw)
In-Reply-To: <cf3a8f45-683e-4fbc-bee7-cfae73d9061c@redhat.com>

On Wed, Feb 05 2025 at 21:46, Waiman Long wrote:
> On 2/5/25 4:20 AM, Thomas Gleixner wrote:
>>> +int set_emergency_nmi_handler(unsigned int type, nmi_handler_t handler)
>>> +{
>>> +	struct nmi_desc *desc = nmi_to_desc(type);
>>> +	nmi_handler_t orig = NULL;
>>> +
>>> +	if (!handler) {
>>> +		orig = READ_ONCE(desc->emerg_handler);
>>> +		WARN_ON_ONCE(!orig);
>>> +	}
>>> +
>>> +	if (try_cmpxchg(&desc->emerg_handler, &orig, handler))
>>> +		return 0;
>> What's the point of this cmpxchg()? What's the concurrency problem this
>> tries to address?
> It is because I am not sure if there can only be one instance of 
> nmi_shootdown_cpus() at any time. If there can't be more than one 
> instance, I can remove the atomic instruction.

There are two ways to get there:

  1) crash(), which installs a handler

  2) emergency_reboot(), which sets the handler to NULL

If they interfere, then the callback is the least of your
worries. That's already broken today in so many other ways.

> I do remove the smp_wmb() in nmi_shootdown_cpus(). If I don't use an
> atomic instruction, I will have to add it smp_wmb() here.

Right.

Thanks,

        tglx

  reply	other threads:[~2025-02-06 16:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-19 15:06 [PATCH v4] x86/nmi: Add an emergency handler in nmi_desc & use it in nmi_shootdown_cpus() Waiman Long
2025-02-05  4:03 ` Waiman Long
2025-02-05  9:20 ` Thomas Gleixner
2025-02-06  2:46   ` Waiman Long
2025-02-06 16:14     ` Thomas Gleixner [this message]
2025-02-06 17:00       ` Waiman Long

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=871pwbnj8k.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llong@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=x86@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