Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sandipan Das" <sandipan.das@amd.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf/x86/amd/core: Always use the NMI latency mitigation
Date: Mon, 01 Jun 2026 15:13:04 +0000	[thread overview]
Message-ID: <20260601151305.33A631F00893@smtp.kernel.org> (raw)
In-Reply-To: <29a3c970da289ab8f24282933bdb36545c0403e8.1780325517.git.sandipan.das@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Uninitialized `perf_nmi_tstamp` combined with `INITIAL_JIFFIES` causes the AMD PMU to silently swallow unhandled NMIs during the first ~5 minutes of system uptime on 32-bit x86.
--

commit 71c3691b558a0c49eaeaca25067c0e97960a98e6
Author: Sandipan Das <sandipan.das@amd.com>

perf/x86/amd/core: Always use the NMI latency mitigation

This commit unconditionally enables the NMI latency mitigation by setting up
the perf_nmi_window during initialization. Previously, this was restricted
to processors with X86_FEATURE_PERFCTR_CORE.

> diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
> index 44656d2fb5550..ec0b74b9da4fa 100644
> --- a/arch/x86/events/amd/core.c
> +++ b/arch/x86/events/amd/core.c
> @@ -1412,12 +1412,12 @@ static int __init amd_core_pmu_init(void)
>  	u64 even_ctr_mask = 0ULL;
>  	int i;
>  
> -	if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
> -		return 0;
> -
>  	/* Avoid calculating the value each time in the NMI handler */
>  	perf_nmi_window = msecs_to_jiffies(100);

[Severity: High]
This is a pre-existing issue, but does enabling this mitigation globally
expose 32-bit systems without PERFCTR_CORE to swallowed NMIs during
early boot?

The per-CPU variable perf_nmi_tstamp is zero-initialized:

arch/x86/events/amd/core.c:
    static DEFINE_PER_CPU(unsigned long, perf_nmi_tstamp);

On 32-bit x86, jiffies starts at INITIAL_JIFFIES (a large positive 32-bit
integer like -300 * HZ). If an unhandled NMI occurs before any PMU event
sets perf_nmi_tstamp, amd_pmu_adjust_nmi_window() checks:

arch/x86/events/amd/core.c:amd_pmu_adjust_nmi_window() {
    ...
    if (time_after(jiffies, this_cpu_read(perf_nmi_tstamp)))
        return NMI_DONE;

    return NMI_HANDLED;
}

Due to 32-bit modulo arithmetic, time_after(INITIAL_JIFFIES, 0) evaluates
to false for the first ~5 minutes of uptime.

Could this cause the AMD PMU NMI handler to incorrectly return NMI_HANDLED
instead of NMI_DONE, silently dropping external hardware watchdog and PCI
error NMIs until jiffies wraps past 0?

>  
> +	if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
> +		return 0;
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/29a3c970da289ab8f24282933bdb36545c0403e8.1780325517.git.sandipan.das@amd.com?part=1

      reply	other threads:[~2026-06-01 15:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 14:58 [PATCH] perf/x86/amd/core: Always use the NMI latency mitigation Sandipan Das
2026-06-01 15:13 ` sashiko-bot [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=20260601151305.33A631F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sandipan.das@amd.com \
    --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