Sashiko discussions
 help / color / mirror / Atom feed
From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: sashiko@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [Patch v7 23/24] perf/x86: Activate back-to-back NMI detection for arch-PEBS induced NMIs
Date: Wed, 29 Apr 2026 14:00:10 +0800	[thread overview]
Message-ID: <6818d74c-7fe9-4cdb-9123-65683f60a5ed@linux.intel.com> (raw)
In-Reply-To: <20260425033158.D3A29C19425@smtp.kernel.org>


On 4/25/2026 11:31 AM, sashiko-bot@kernel.org wrote:
> Sashiko AI review found 2 potential issue(s):
> - [High] Incorrect bitwise operation in intel_pmu_drain_pebs_nhm() corrupts the processed events count.
> - [High] Removing the unconditional `handled` increment causes valid PMIs to be reported as unhandled when `drain_pebs()` returns 0.
> --
>
> commit 0317f48597bdef9b4d93c696bde043840ac1fc6b
> Author: Dapeng Mi <dapeng1.mi@linux.intel.com>
>
> perf/x86: Activate back-to-back NMI detection for arch-PEBS induced NMIs
>
> This patch modifies the PEBS handlers to return the count of actually
> processed events instead of void. This count is used in the PMI handler
> to activate back-to-back NMI detection and avoid "suspicious NMI" warnings.
>
>> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
>> --- a/arch/x86/events/intel/core.c
>> +++ b/arch/x86/events/intel/core.c
> [ ... ]
>
>> @@ -3558,9 +3558,8 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
>>  	if (__test_and_clear_bit(GLOBAL_STATUS_BUFFER_OVF_BIT, (unsigned long *)&status)) {
>>  		u64 pebs_enabled = cpuc->pebs_enabled;
>>  
>> -		handled++;
>>  		x86_pmu_handle_guest_pebs(regs, &data);
>> -		static_call(x86_pmu_drain_pebs)(regs, &data);
>> +		handled += static_call(x86_pmu_drain_pebs)(regs, &data);
> If x86_pmu_drain_pebs() returns 0, will handled fail to increment even though
> the hardware asserted an NMI and set the MSR status bit?
>
> This might happen if the host PEBS buffer is empty, such as when a guest PEBS
> event triggers the PMI and is handled by x86_pmu_handle_guest_pebs() right
> above it. 
>
> Could this cause the core NMI framework to treat the interrupt as unhandled
> and trigger an unknown NMI warning? Is it necessary to ensure handled
> increments by at least 1 when the status bit is explicitly acknowledged?

It's indeed an issue of the guest PEBS event. But for other host events, if
x86_pmu_drain_pebs() returns 0, then it means there must be something
wrong, we should not hide the issue.

I would add an exception for the guest PEBS event.


>
>>  		/*
>>  		 * PMI throttle may be triggered, which stops the PEBS event.
> [ ... ]
>
>> @@ -3587,8 +3586,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
>>  	 */
>>  	if (__test_and_clear_bit(GLOBAL_STATUS_ARCH_PEBS_THRESHOLD_BIT,
>>  				 (unsigned long *)&status)) {
>> -		handled++;
>> -		static_call(x86_pmu_drain_pebs)(regs, &data);
>> +		handled += static_call(x86_pmu_drain_pebs)(regs, &data);
> Does this share the same issue as above, where a return value of 0 from
> drain_pebs() would result in handled not being incremented for a valid PMI?

As the above mentioned, we should expose the issue if there are something
wrong.


>
> [ ... ]
>
>> diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
>> --- a/arch/x86/events/intel/ds.c
>> +++ b/arch/x86/events/intel/ds.c
> [ ... ]
>
>> @@ -3189,6 +3192,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d
>>  		if ((counts[bit] == 0) && (error[bit] == 0))
>>  			continue;
>>  
>> +		events_bitmap |= bit;
>>  		event = cpuc->events[bit];
> Will this perform a bitwise OR with the integer index itself rather than
> the expected bitmask?
>
> Because bit is an integer index (e.g., 0 for PMC0, 3 for PMC3), if only PMC3
> overflows, events_bitmap |= 3 (binary 011) results in hweight64(3) returning
> 2. If PMC0 overflows, events_bitmap |= 0 leaves the bitmap at 0.
>
> Should this be events_bitmap |= BIT_ULL(bit) or 1ULL << bit to correctly
> record the processed events?

Yes, we also found this issue locally. Would fix it in next version.

Thanks.


>

           reply	other threads:[~2026-04-29  6:00 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20260425033158.D3A29C19425@smtp.kernel.org>]

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=6818d74c-7fe9-4cdb-9123-65683f60a5ed@linux.intel.com \
    --to=dapeng1.mi@linux.intel.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko@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