From: Peter Zijlstra <peterz@infradead.org>
To: "Liang, Kan" <kan.liang@linux.intel.com>
Cc: mingo@redhat.com, tglx@linutronix.de, bp@alien8.de,
acme@kernel.org, namhyung@kernel.org, irogers@google.com,
linux-kernel@vger.kernel.org, ak@linux.intel.com,
eranian@google.com
Subject: Re: [PATCH V9 3/7] perf: attach/detach PMU specific data
Date: Fri, 14 Mar 2025 22:03:58 +0100 [thread overview]
Message-ID: <20250314210358.GA21786@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <1ec56e83-be22-480c-be60-5b898fc5f5b7@linux.intel.com>
On Fri, Mar 14, 2025 at 10:38:29AM -0400, Liang, Kan wrote:
> I think the attach_perf_ctx_data() should be moved even earlier, right
> after the perf_init_event(). Because the PERF_ATTACH_TASK_DATA is set in
> the event_init()->hw_config(), rather than after perf attach the data.
>
> So any errors between perf_init_event() and attach_perf_ctx_data(event)
> would cause the detach_perf_ctx_data() mistakenly invoked.
>
> @@ -5393,6 +5607,9 @@ static void __free_event(struct perf_event *event)
> if (is_cgroup_event(event))
> perf_detach_cgroup(event);
>
> + if (event->attach_state & PERF_ATTACH_TASK_DATA)
> + detach_perf_ctx_data(event);
> +
> if (event->destroy)
> event->destroy(event);
> @@ -12481,6 +12746,18 @@ perf_event_alloc(struct perf_event_attr *attr,
> int cpu,
> if (IS_ERR(pmu))
> return (void*)pmu;
>
> + /*
> + * The PERF_ATTACH_TASK_DATA is set in the event_init()->hw_config().
> + * The attach should be right after the perf_init_event().
> + * Otherwise, the __free_event() would mistakenly detach the non-exist
> + * perf_ctx_data because of the other errors between them.
> + */
> + if (event->attach_state & PERF_ATTACH_TASK_DATA) {
> + err = attach_perf_ctx_data(event);
> + if (err)
> + return ERR_PTR(err);
> + }
> +
AFAICT it is possible for perF_init_event() to return an error *and* set
ATTACH_TASK_DATA, at which point we're up a creek with __free_event().
I'm afraid we need more state to track this.
(additionally, I'll need to rebase the pmu_unregister patch on top of
this -- that needs more changes still).
Anyway, let me go poke at this a bit, see what I can do with v10.
I'll reply there.
next prev parent reply other threads:[~2025-03-14 21:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 0:02 [PATCH V9 1/7] perf: Save PMU specific data in task_struct kan.liang
2025-03-14 0:02 ` [PATCH V9 2/7] locking/percpu-rwsem: Add guard support kan.liang
2025-03-14 0:02 ` [PATCH V9 3/7] perf: attach/detach PMU specific data kan.liang
2025-03-14 12:59 ` Peter Zijlstra
2025-03-14 13:50 ` Liang, Kan
2025-03-14 14:38 ` Liang, Kan
2025-03-14 21:03 ` Peter Zijlstra [this message]
2025-03-14 0:02 ` [PATCH V9 4/7] perf: Supply task information to sched_task() kan.liang
2025-03-14 0:02 ` [PATCH V9 5/7] perf/x86/lbr: Fix shorter LBRs call stacks for the system-wide mode kan.liang
2025-03-14 0:02 ` [PATCH V9 6/7] perf/x86: Remove swap_task_ctx() kan.liang
2025-03-14 0:02 ` [PATCH V9 7/7] perf: Clean up pmu specific data kan.liang
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=20250314210358.GA21786@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=bp@alien8.de \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
/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