From: sashiko-bot@kernel.org
To: "Guanghui Feng" <guanghuifeng@linux.alibaba.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2] perf/x86/amd: Move NMI latency window to last-resort suppression
Date: Wed, 16 Sep 2026 12:59:43 +0000 [thread overview]
Message-ID: <20260916125944.017161F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260916125016.2266596-1-guanghuifeng@linux.alibaba.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] x86/nmi: TOCTOU race in perf_nmi_window_active() causes spurious panic
--
commit 48f851c34890a3a07c65994472936573ea009e9e
Author: Guanghui Feng <guanghuifeng@linux.alibaba.com>
perf/x86/amd: Move NMI latency window to last-resort suppression
This commit delays claiming NMIs in the perf handler when no counter
overflowed, allowing other NMI handlers to run first. It updates the NMI
dispatch path to consult the latency window twice: once to skip the
reason port read, and a second time as a last resort to suppress
bogus unknown NMI reports.
> diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
> index 3c9f60d6ca5a7..1226c18e37a61 100644
> --- a/arch/x86/kernel/nmi.c
> +++ b/arch/x86/kernel/nmi.c
[ ... ]
> @@ -407,38 +430,50 @@ static noinstr void default_do_nmi(struct pt_regs *regs)
> }
>
> /*
> - * Non-CPU-specific NMI: NMI sources can be processed on any CPU.
> + * If the perf NMI latency window is still open, a recently handled PMC
> + * overflow may have generated a latent NMI that arrives too late to be
> + * paired with that overflow. Skip the expensive reason port read
> + * (inb 0x61 + global nmi_reason_lock) which is a known scalability
> + * bottleneck when spurious PMIs arrive at high frequency on AMD.
> *
> - * Another CPU may be processing panic routines while holding
> - * nmi_reason_lock. Check if the CPU issued the IPI for crash dumping,
> - * and if so, call its callback directly. If there is no CPU preparing
> - * crash dump, we simply loop here.
> + * NMI_UNKNOWN handlers (hpwdt, etc.) are still invoked below via
> + * unknown_nmi_error(), so hardware watchdog NMIs are not lost.
> */
> - while (!raw_spin_trylock(&nmi_reason_lock)) {
> - run_crash_ipi_callback(regs);
> - cpu_relax();
> - }
> + if (!perf_nmi_window_active()) {
[Severity: High]
Could this introduce a race condition with jiffies updates on other CPUs?
Looking at perf_nmi_window_active(), it evaluates the window state against
the globally incrementing jiffies variable:
arch/x86/events/amd/core.c:perf_nmi_window_active() {
...
return !time_after(jiffies, this_cpu_read(perf_nmi_tstamp));
}
If perf_nmi_window_active() returns true here in default_do_nmi(), the
NMI reason port read is skipped and execution proceeds down to
unknown_nmi_error().
If a timer interrupt on another CPU increments jiffies between this first
check and the second check inside unknown_nmi_error():
arch/x86/kernel/nmi.c:unknown_nmi_error() {
...
if (perf_nmi_window_active())
return;
...
}
Would this cause the second check to evaluate to false, resulting in a
fall-through that logs a bogus "unknown NMI" error and potentially triggers
a spurious kernel panic if unknown_nmi_panic is set?
> + /*
> + * Non-CPU-specific NMI: NMI sources can be processed on any CPU.
> + *
> + * Another CPU may be processing panic routines while holding
> + * nmi_reason_lock. Check if the CPU issued the IPI for crash
> + * dumping, and if so, call its callback directly. If there is no
> + * CPU preparing crash dump, we simply loop here.
> + */
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260916125016.2266596-1-guanghuifeng@linux.alibaba.com?part=1
next prev parent reply other threads:[~2026-09-16 12:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 6:57 [PATCH] perf/x86/amd: Move NMI latency window to last-resort suppression Guanghui Feng
2026-09-16 7:10 ` sashiko-bot
2026-09-16 9:32 ` Peter Zijlstra
2026-09-16 12:50 ` [PATCH v2] " Guanghui Feng
2026-09-16 12:59 ` sashiko-bot [this message]
2026-09-16 13:04 ` Peter Zijlstra
2026-09-16 13:18 ` [PATCH] " guanghuifeng
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=20260916125944.017161F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=guanghuifeng@linux.alibaba.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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