From: Ravi Bangoria <ravi.bangoria@amd.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: acme@kernel.org, alexander.shishkin@linux.intel.com,
jolsa@redhat.com, namhyung@kernel.org, songliubraving@fb.com,
eranian@google.com, ak@linux.intel.com, mark.rutland@arm.com,
frederic@kernel.org, maddy@linux.ibm.com, irogers@google.com,
will@kernel.org, robh@kernel.org, mingo@redhat.com,
catalin.marinas@arm.com, ndesaulniers@google.com,
srw@sladewatkins.net, linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
sandipan.das@amd.com, ananth.narayan@amd.com,
kim.phillips@amd.com, santosh.shukla@amd.com,
Ravi Bangoria <ravi.bangoria@amd.com>
Subject: Re: [PATCH v2] perf: Rewrite core context handling
Date: Thu, 13 Oct 2022 15:37:23 +0530 [thread overview]
Message-ID: <99caec5f-dcdf-70c6-8909-11552ce42a20@amd.com> (raw)
In-Reply-To: <Y0cn1xazYpNmqhRo@hirez.programming.kicks-ass.net>
On 13-Oct-22 2:17 AM, Peter Zijlstra wrote:
> On Wed, Oct 12, 2022 at 02:16:29PM +0200, Peter Zijlstra wrote:
>
>> That's the intent yeah. But due to not always holding ctx->mutex over
>> put_pmu_ctx() this might be moot. I'm almost through auditing epc usage
>> and I think ctx->lock is sufficient, fingers crossed.
>
> So the very last epc usage threw a spanner into the works and made
> things complicated.
>
> Specifically sys_perf_event_open()'s group_leader case uses
> event->pmu_ctx while only holding ctx->mutex. Therefore we can't fully
> let go of ctx->mutex locking and purely rely on ctx->lock.
>
> Now the good news is that the annoying put_pmu_ctx() without holding
> ctx->mutex case doesn't actually matter here. Since we hold a reference
> on the group_leader (per the filedesc) the event can't go away,
> therefore it must have a pmu_ctx, and then holding ctx->mutex ensures
> the pmu_ctx is stable -- iow it serializes against
> sys_perf_event_open()'s move_group and perf_pmu_migrate_context()
> changing the epc around.
>
> So we're going with the normal mutex+lock for modification rule, but
> allow the weird put_pmu_ctx() exception.
>
> I have the below delta.
>
> I'm hoping we can call this done -- I'm going to see if I can bribe Mark
> to take a look at the arm64 thing soon and then hopefully queue the
> whole thing once -rc1 happens. That should give us a good long soak
> until the next merge window.
Sounds good. Thanks for all the help!
I've glanced through the changes and they looks fine, below are few minor
points.
> + * Specificially, sys_perf_event_open()'s group_leader case depends on
> + * ctx->mutex pinning the configuration. Since we hold a reference on
> + * group_leader (through the filedesc) it can't fo away, therefore it's
typo: can't go away
> - refcount_t refcount;
> + refcount_t refcount; /* event <-> ctx */
Ok. We need to remove all those // XXX get/put_ctx() from code
which we added to make refcount a pmu_ctx <-> ctx.
> +#define double_list_for_each_entry(pos1, pos2, head1, head2, member) \
> + for (pos1 = list_first_entry(head1, typeof(*pos1), member), \
> + pos2 = list_first_entry(head2, typeof(*pos2), member); \
> + !list_entry_is_head(pos1, head1, member) && \
> + !list_entry_is_head(pos2, head2, member); \
> + pos1 = list_next_entry(pos1, member), \
> + pos2 = list_next_entry(pos2, member))
> +
> static void perf_event_swap_task_ctx_data(struct perf_event_context *prev_ctx,
> struct perf_event_context *next_ctx)
While this is unrelated to this patch, shouldn't we also need to swap
event->hw.target? A purely hypothetical scenario: Consider two processes
having clone contexts (for example, two children of the same parent).
While process switch between these two, the perf event context would get
swapped but event->hw.target will point to other sibling's task_struct.
If any one process exit just after single context swap, _free_event()
will call put_task_context() on sibling process' task_struct.
> @@ -12436,6 +12463,9 @@ SYSCALL_DEFINE5(perf_event_open,
> * Allow the addition of software events to hw
> * groups, this is safe because software events
> * never fail to schedule.
> + *
> + * Note the comment that goes with struct
> + * pmu_event_pmu_context.
typo: perf_event_pmu_context
The good (or bad? ;)) news is, perf test and Vince's perf_event_tests
are running fine without any regression on my machine.
Thanks,
Ravi
next prev parent reply other threads:[~2022-10-13 10:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20221008062424.313-1-ravi.bangoria@amd.com>
2022-10-11 11:29 ` [PATCH v2] perf: Rewrite core context handling Peter Zijlstra
2022-10-11 13:19 ` Ravi Bangoria
2022-10-11 14:02 ` Peter Zijlstra
2022-10-11 17:47 ` Peter Zijlstra
2022-10-12 8:39 ` Ravi Bangoria
2022-10-12 12:16 ` Peter Zijlstra
2022-10-12 20:47 ` Peter Zijlstra
2022-10-13 10:07 ` Ravi Bangoria [this message]
2022-10-13 10:59 ` Peter Zijlstra
2022-10-14 9:56 ` Ravi Bangoria
2022-10-14 14:50 ` Peter Zijlstra
2022-10-17 9:33 ` Ravi Bangoria
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=99caec5f-dcdf-70c6-8909-11552ce42a20@amd.com \
--to=ravi.bangoria@amd.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ananth.narayan@amd.com \
--cc=catalin.marinas@arm.com \
--cc=eranian@google.com \
--cc=frederic@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=kim.phillips@amd.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=robh@kernel.org \
--cc=sandipan.das@amd.com \
--cc=santosh.shukla@amd.com \
--cc=songliubraving@fb.com \
--cc=srw@sladewatkins.net \
--cc=will@kernel.org \
/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