Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ravi Bangoria" <ravi.bangoria@amd.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 3/3] perf/amd/ibs: Simplify event state handling with IBS_CAPS_DIS
Date: Thu, 15 Oct 2026 06:24:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-172339@kernel.org> (raw)
In-Reply-To: <20261015060430.5877-4-ravi.bangoria@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf/amd/ibs: Unhandled NMI panic due to 50us timeout
--

commit be4cf40ba3750348ffc77933b0cfe40c48e335e7
Author: Ravi Bangoria <ravi.bangoria@amd.com>
Subject: perf/amd/ibs: Simplify event state handling with IBS_CAPS_DIS

This commit simplifies event state handling on systems supporting
IBS_CAPS_DIS. It introduces a separate stop path that preserves the
Val bit while disabling the event to catch delayed NMIs.

Link: https://lore.kernel.org/r/20261007234815.4026028-1-jmattson@google.com

> diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
> --- a/arch/x86/events/amd/ibs.c
> +++ b/arch/x86/events/amd/ibs.c

[ ... ]

> @@ -575,23 +583,87 @@ static void perf_ibs_start(struct perf_event *event, int flags)

[ ... ]

> +	if (ibs_caps & IBS_CAPS_DIS) {
> +		/*
> +		 *      IBS HW                     SW
> +		 *
> +		 *  o Capture sample       o ->stop()
> +		 *  o Set VAL bit            CTL2[Dis] = 1
> +		 *  o Raise NMI --.        o ...
> +		 *                 \       o ->start()
> +		 *                  \        wrmsr(IBS_{FETCH|OP}_CTL, new value);
> +		 *                   \       (wrmsr clears the VAL bit)
> +		 *                    `--> o Receives delayed NMI
> +		 *                           (Unknown NMI since VAL bit is cleared)
> +		 *
> +		 * Handle this with induced delay.
> +		 */
> +		rdmsrq(hwc->config_base, ctl);
> +		while ((ctl & perf_ibs->valid_mask) && delay--) {
> +			udelay(1);
> +			rdmsrq(hwc->config_base, ctl);
> +		}

[Severity: High]
What happens if the delayed NMI takes longer than 50us to arrive, for
example due to hypervisor scheduling, nested virtualization, or SMIs?

If this delay loop expires, the code proceeds to call
perf_ibs_enable_event() which clears the VAL and CTL2[Dis] bits. When the
delayed NMI eventually arrives, it appears it will be treated as an
unhandled NMI.

[ ... ]

> @@ -1419,19 +1494,43 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)

[ ... ]

> +	} else {
> +		if (!test_bit(IBS_STARTED, pcpu->state)) {
> +fail:
> +			/*
> +			 * Catch spurious interrupts after stopping IBS: After
> +			 * disabling IBS there could be still incoming NMIs
> +			 * with samples that even have the valid bit cleared.
> +			 * Mark all this NMIs as handled.
> +			 */
> +			if (test_and_clear_bit(IBS_STOPPED, pcpu->state))
> +				return 1;
>  
> -		return 0;
> +			return 0;
> +		}
> +	}

[Severity: High]
If the NMI is delayed past the 50us timeout in perf_ibs_start(), won't
perf_ibs_handle_irq() return 0 here?

Since IBS_STOPPED is intentionally not set for systems with IBS_CAPS_DIS,
when the delayed NMI arrives, CTL2[Dis] == 0 and VAL == 0. If the code
jumps to the 'fail' label due to the cleared VAL bit, IBS_STOPPED will be
clear, causing it to return 0.

Could this result in an unhandled NMI and a subsequent kernel panic?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015060430.5877-1-ravi.bangoria@amd.com?part=3

  reply	other threads:[~2026-10-15  6:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  6:04 [PATCH 0/3] perf/amd/ibs: Assorted fixes Ravi Bangoria
2026-10-15  6:04 ` [PATCH 1/3] perf/amd/ibs: Reset CPU0 IBS state on syscore resume Ravi Bangoria
2026-10-15  6:15   ` sashiko-bot
2026-10-15  6:04 ` [PATCH 2/3] perf/amd/ibs: Fix kernel address leak via REGS_USER Ravi Bangoria
2026-10-15  6:13   ` sashiko-bot
2026-10-15  6:04 ` [PATCH 3/3] perf/amd/ibs: Simplify event state handling with IBS_CAPS_DIS Ravi Bangoria
2026-10-15  6:24   ` sashiko-bot [this message]
2026-10-15  6:49     ` Ravi Bangoria

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=sashiko-outbox-172339@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=ravi.bangoria@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