From: Leo Liang <ycliang@andestech.com>
To: <linux-kernel@vger.kernel.org>
Cc: <rd-sw-linux@andestech.com>, <daniel.thompson@linaro.org>,
<rmk+kernel@armlinux.org.uk>, <ying.huang@intel.com>
Subject: [QUESTION] NMI: Understanding ARCH_HAVE_NMI_SAFE_CMPXCHG usage
Date: Mon, 2 Jun 2025 15:02:48 +0800 [thread overview]
Message-ID: <aD1MmIi8o2vyi-Zs@swlinux02> (raw)
Hi everyone,
I came across the `ARCH_HAVE_NMI_SAFE_CMPXCHG` definition recently
and could not fully understand how an architecture indicates its support for it.
From my initial review of the code,
it seems to indicate whether a compare-exchange operation is safe
within an NMI context (handler) without causing a deadlock or other issues.
I have checked the initial commit and the architectures that enabled this config
with that commit. My inference is that if an architecture implements cmpxchg
with a lockless algorithm, it should be able to enable this config.
The reason is that I can only think of one constraint: "taking a lock"
should be avoided in an NMI context in case the NMI encounters a deadlock.
Therefore, if the architecture does not use interrupt masking and locking algorithm
to implement cmpxchg then it should be safe for the architecture to enable this config.
However, PARISC implements cmpxchg using interrupt masking and a while loop[1],
and `ARCH_HAVE_NMI_SAFE_CMPXCHG` is also enabled for this architecture, so I am
unsure if my inference is valid.
Could someone please clarify the specific implications of this definition
and in which scenarios it becomes particularly critical? Are there
any specific hardware capabilities or kernel architecture-specific APIs
that govern its presence or absence?
I've searched lore.kernel.org and kernel documentation for a detailed
explanation of `ARCH_HAVE_NMI_SAFE_CMPXCHG`'s history and current
usage guarantees, but haven't found a definitive overview.
Any pointers or explanations would be greatly appreciated.
[1] https://github.com/torvalds/linux/blob/master/arch/parisc/lib/bitops.c#L59
Thanks,
Leo
reply other threads:[~2025-06-02 7:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=aD1MmIi8o2vyi-Zs@swlinux02 \
--to=ycliang@andestech.com \
--cc=daniel.thompson@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rd-sw-linux@andestech.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=ying.huang@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.