lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <44e1c864-a6e1-41a8-9f11-0ea25999131c@linux.intel.com>
Date: Tue, 27 May 2025 15:30:06 -0400
From: "Liang, Kan" <kan.liang@...ux.intel.com>
To: Leo Yan <leo.yan@....com>
Cc: peterz@...radead.org, mingo@...hat.com, namhyung@...nel.org,
 irogers@...gle.com, mark.rutland@....com, linux-kernel@...r.kernel.org,
 linux-perf-users@...r.kernel.org, eranian@...gle.com, ctshao@...gle.com,
 tmricht@...ux.ibm.com, Aishwarya.TCV@....com
Subject: Re: [PATCH V4 01/16] perf: Fix the throttle logic for a group



On 2025-05-27 12:16 p.m., Leo Yan wrote:
> Hi Kan,
> 
> [ + Aishwarya ]
> 
> On Tue, May 20, 2025 at 11:16:29AM -0700, kan.liang@...ux.intel.com wrote:
> 
> [...]
> 
>> @@ -10331,8 +10358,7 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle)
>>  	if (unlikely(throttle && hwc->interrupts >= max_samples_per_tick)) {
>>  		__this_cpu_inc(perf_throttled_count);
>>  		tick_dep_set_cpu(smp_processor_id(), TICK_DEP_BIT_PERF_EVENTS);
>> -		hwc->interrupts = MAX_INTERRUPTS;
>> -		perf_log_throttle(event, 0);
>> +		perf_event_throttle_group(event);
>>  		ret = 1;
>>  	}
> 
> Our (Arm) CI reports RCU stall that caused by this patch.  I can use a
> simple command to trigger system stuck with cpu-clock:
> 
>   perf record -a -e cpu-clock -- sleep 2
> 
> I confirmed that if removing throttling code for cpu-clock event, then
> the issue can be dimissed.  Based on reading code, the flow below:
> 
>   hrtimer interrupt:
>    `> __perf_event_account_interrupt()
>        `> perf_event_throttle_group()
>            `> perf_event_throttle()
>                `> cpu_clock_event_stop()
>                    `> perf_swevent_cancel_hrtimer()
>                        `> hrtimer_cancel()  -> Inifite loop.
> 
> In the hrtimer interrupt handler, it tries to cancel itself and causes
> inifite loop.  Please consider to fix the issue.
> 

The cpu-clock and task_clock are two special SW events, which rely on
the hrtimer. I missed them when checking the SW events. :(

For the two events, instead of invoking the stop(), the
HRTIMER_NORESTART is returned to stop the timer. Invoking the stop()
cause the issue.

There may be two ways to fix it.
- Add a check of MAX_INTERRUPTS in the event_stop. Return immediately if
the stop is invoked by the throttle.
- Introduce a PMU flag to track the case. Avoid the event_stop in
perf_event_throttle() if the flag is detected.

The latter looks more generic. It may be used if there are other cases
that want to avoid the stop. So the latter is implemented as below.

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 947ad12dfdbe..66f02f46595c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -303,6 +303,7 @@ struct perf_event_pmu_context;
 #define PERF_PMU_CAP_AUX_OUTPUT			0x0080
 #define PERF_PMU_CAP_EXTENDED_HW_TYPE		0x0100
 #define PERF_PMU_CAP_AUX_PAUSE			0x0200
+#define PERF_PMU_CAP_NO_THROTTLE_STOP		0x0400

 /**
  * pmu::scope
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8327ab0ee641..596597886d96 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2655,7 +2655,8 @@ static void perf_event_unthrottle(struct
perf_event *event, bool start)

 static void perf_event_throttle(struct perf_event *event)
 {
-	event->pmu->stop(event, 0);
+	if (!(event->pmu->capabilities & PERF_PMU_CAP_NO_THROTTLE_STOP))
+		event->pmu->stop(event, 0);
 	event->hw.interrupts = MAX_INTERRUPTS;
 	perf_log_throttle(event, 0);
 }
@@ -11846,7 +11847,8 @@ static int cpu_clock_event_init(struct
perf_event *event)
 static struct pmu perf_cpu_clock = {
 	.task_ctx_nr	= perf_sw_context,

-	.capabilities	= PERF_PMU_CAP_NO_NMI,
+	.capabilities	= PERF_PMU_CAP_NO_NMI |
+			  PERF_PMU_CAP_NO_THROTTLE_STOP,
 	.dev		= PMU_NULL_DEV,

 	.event_init	= cpu_clock_event_init,
@@ -11928,7 +11930,8 @@ static int task_clock_event_init(struct
perf_event *event)
 static struct pmu perf_task_clock = {
 	.task_ctx_nr	= perf_sw_context,

-	.capabilities	= PERF_PMU_CAP_NO_NMI,
+	.capabilities	= PERF_PMU_CAP_NO_NMI |
+			  PERF_PMU_CAP_NO_THROTTLE_STOP,
 	.dev		= PMU_NULL_DEV,

 	.event_init	= task_clock_event_init,


Thanks,
Kan



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ