All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David Wang" <00107082@163.com>
To: "Peter Zijlstra" <peterz@infradead.org>
Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org,
	mingo@kernel.org, yeoreum.yun@arm.com, leo.yan@arm.com,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] perf/core: restore __perf_remove_from_context when DETACH_EXIT not set
Date: Tue, 3 Jun 2025 18:44:58 +0800 (CST)	[thread overview]
Message-ID: <2633d43d.ae30.1973564f5e5.Coremail.00107082@163.com> (raw)
In-Reply-To: <20250603091352.GJ21197@noisy.programming.kicks-ass.net>


At 2025-06-03 17:13:52, "Peter Zijlstra" <peterz@infradead.org> wrote:
>On Tue, Jun 03, 2025 at 04:33:04PM +0800, David Wang wrote:
>> commit a3c3c66670ce ("perf/core: Fix child_total_time_enabled accounting
>> bug at task exit") made changes to __perf_remove_from_context() to
>> coordinate its changes with perf_event_exit_event(), but the change are
>> unconditional, it impacts callpaths to __perf_remove_from_context()
>> other than from perf_event_exit_event(). One of the impact is to cgroup,
>> which is not properly handled and would cause kernel panic with high
>> probalibity during reboot on some system[1].
>
>Sorry, but no. This does not describe the problem adequately. I would
>have to go read your [1] to figure out what is actually broken.
>
>That is, having read the above, I'm still clueless as to what the actual
>problem is.

well, short story is commit a3c3c66670ce introduce a kernel panic when reboot the system
after perf_event_open with cgroup.
My understanding is commit a3c3c66670ce make changes to call path
perf_event_exit_event() --> __perf_remove_from_context(), but this changes affect other
call path as well, for example
perf_event_release_kernel() --> perf_remove_from_context()
(As yeoreum.yun@arm.com pointed out,  the change in perf_remove_from_context() made
perf_event_set_state() happened before list_del_event(), resulting in perf_cgroup_event_disable()
not called.)

My suggestion here is to confine the effect of commit a3c3c66670ce only to call chain
perf_event_exit_event() --> __perf_remove_from_context()


(But this v2 version is totally wrong, should be ignored; it breaks commit a3c3c66670ce)



>
>> To confine the side effects, make the changes to
>> __perf_remove_from_context() conditional, restore to its previous state
>> except when DETACH_EXIT is set.
>> 
>> Closes: https://lore.kernel.org/lkml/20250601173603.3920-1-00107082@163.com/ [1]
>> Fixes: a3c3c66670ce ("perf/core: Fix child_total_time_enabled accounting bug at task exit")
>> Signed-off-by: David Wang <00107082@163.com>
>> ---
>> Changes:
>> Address yeoreum.yun@arm.com's concern about missing cgroup event.
>> ---
>>  kernel/events/core.c | 11 ++++++-----
>>  1 file changed, 6 insertions(+), 5 deletions(-)
>> 
>> diff --git a/kernel/events/core.c b/kernel/events/core.c
>> index 95e703891b24..e2c0f34b0789 100644
>> --- a/kernel/events/core.c
>> +++ b/kernel/events/core.c
>> @@ -2466,7 +2466,7 @@ __perf_remove_from_context(struct perf_event *event,
>>  			   void *info)
>>  {
>>  	struct perf_event_pmu_context *pmu_ctx = event->pmu_ctx;
>> -	enum perf_event_state state = PERF_EVENT_STATE_OFF;
>> +	enum perf_event_state exit_state = PERF_EVENT_STATE_EXIT;
>>  	unsigned long flags = (unsigned long)info;
>>  
>>  	ctx_time_update(cpuctx, ctx);
>> @@ -2475,19 +2475,20 @@ __perf_remove_from_context(struct perf_event *event,
>>  	 * Ensure event_sched_out() switches to OFF, at the very least
>>  	 * this avoids raising perf_pending_task() at this time.
>>  	 */
>> -	if (flags & DETACH_EXIT)
>> -		state = PERF_EVENT_STATE_EXIT;
>>  	if (flags & DETACH_DEAD) {
>>  		event->pending_disable = 1;
>> -		state = PERF_EVENT_STATE_DEAD;
>> +		exit_state = PERF_EVENT_STATE_DEAD;
>>  	}
>>  	event_sched_out(event, ctx);
>> -	perf_event_set_state(event, min(event->state, state));
>>  	if (flags & DETACH_GROUP)
>>  		perf_group_detach(event);
>>  	if (flags & DETACH_CHILD)
>>  		perf_child_detach(event);
>>  	list_del_event(event, ctx);
>> +	if (flags & DETACH_EXIT)
>> +		perf_event_set_state(event, min(event->state, exit_state));
>> +	if (flags & DETACH_DEAD)
>> +		event->state = PERF_EVENT_STATE_DEAD;
>
>Urgh, no. Trying to reverse engineer the above, the intent appears to be
>to not set OFF.
>
>This can be achieved by doing:
>
>-       enum perf_event_state state = PERF_EVENT_STATE_OFF;
>+       enum perf_event_state state = event->state;
>
>No other changes required. You also move the location of
>perf_event_set_state(), but it is entirely unclear to me if that is
>actually needed.
>
>Worse, you split the means of setting state -- that is entirely uncalled
>for. 
Yes, that is very wired to me too..... commit  a3c3c66670ce wants to use perf_event_set_state to update time,
but the original code use just event->state = ...





  reply	other threads:[~2025-06-03 10:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-03  3:26 [PATCH] perf/core: restore __perf_remove_from_context when DETACH_EXIT not set David Wang
2025-06-03  8:33 ` [PATCH v2] " David Wang
2025-06-03  9:13   ` Peter Zijlstra
2025-06-03 10:44     ` David Wang [this message]
2025-06-03 12:50       ` Peter Zijlstra
2025-06-03 12:54         ` Peter Zijlstra
2025-06-03 13:03           ` David Wang
2025-06-03 13:49             ` David Wang
2025-06-03 13:22           ` Yeoreum Yun
2025-06-03 14:08             ` Peter Zijlstra

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=2633d43d.ae30.1973564f5e5.Coremail.00107082@163.com \
    --to=00107082@163.com \
    --cc=acme@kernel.org \
    --cc=leo.yan@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yeoreum.yun@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.