mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Richter <tmricht@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, hca@linux.ibm.com, sumanthk@linux.ibm.com
Subject: Re: [PATCH] perf/core: Allow list_del during perf_event_overflow()
Date: Tue, 8 Sep 2026 12:14:04 +0200	[thread overview]
Message-ID: <20260908101404.GP4121339@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260908064759.1241413-1-tmricht@linux.ibm.com>

On Tue, Sep 08, 2026 at 08:47:59AM +0200, Thomas Richter wrote:
> A PMU might use perf_sched_cb_inc() and perf_sched_cb_dec()
> interface to get the PMU call back function pmu::sched_task
> invoked at schedule in and schedule out. This is achieved
> by walking along the list anchored by sched_cb_list.
> 
> The following scenario might lead to a list corruption.
> 
>    perf_pmu_sched_task()
>       for_each_list_entry(..., &sched_cb_list)
>       +--> __perf_pmu_sched_task()
>            +--> event->pmu->sched_task())
>                 +--> PMU_push_sample()
>                      +--> perf_event_overflow()
>                           +--> __perf_event_overflow()
>                                +--> pmu->stop()
>                                     +--> perf_sched_cb_dec()
>                                          remove entry from sched_cb_list
>                                          while list node in use.
> 
> This happens when ioctl(fd, PERF_EVENT_IOC_REFRESH, xxx) has been
> invoked and perf_event::event_limit hits zero.
> 
> Prevent the list corruption and convert for_each_list_entry()
> to for_each_list_entry_safe().
> 

This reads like it wants a Fixes tag.

> Cc: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
> ---
>  kernel/events/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index a6c8e38a3110..cdd9518ac046 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -3925,13 +3925,13 @@ static void perf_pmu_sched_task(struct task_struct *prev,
>  				bool sched_in)
>  {
>  	struct perf_cpu_context *cpuctx = this_cpu_ptr(&perf_cpu_context);
> -	struct perf_cpu_pmu_context *cpc;
> +	struct perf_cpu_pmu_context *cpc, *cpc2;
>  
>  	/* cpuctx->task_ctx will be handled in perf_event_context_sched_in/out */
>  	if (prev == next || cpuctx->task_ctx)
>  		return;
>  
> -	list_for_each_entry(cpc, this_cpu_ptr(&sched_cb_list), sched_cb_entry)
> +	list_for_each_entry_safe(cpc, cpc2, this_cpu_ptr(&sched_cb_list), sched_cb_entry)
>  		__perf_pmu_sched_task(cpc, sched_in ? next : prev, sched_in);
>  }
>  
> -- 
> 2.55.0
> 

      reply	other threads:[~2026-09-08 10:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  6:47 Thomas Richter
2026-09-08 10:14 ` Peter Zijlstra [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=20260908101404.GP4121339@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=hca@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sumanthk@linux.ibm.com \
    --cc=tmricht@linux.ibm.com \
    /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

all inboxes | Powered by JetHome®