Re: [RFC 2/3] perf/x86: Control RDPMC access from .enable() hook

From: Rob Herring
Date: Thu Aug 26 2021 - 15:09:32 EST


On Thu, Aug 26, 2021 at 1:13 PM Andy Lutomirski <luto@xxxxxxxxxx> wrote:
>
>
>
> On Thu, Aug 12, 2021, at 11:16 AM, Rob Herring wrote:
> > On Thu, Aug 12, 2021 at 11:50 AM Andy Lutomirski <luto@xxxxxxxxxx> wrote:
> > >
> > > On 7/28/21 4:02 PM, Rob Herring wrote:
> > > > Rather than controlling RDPMC access behind the scenes from switch_mm(),
> > > > move RDPMC access controls to the PMU .enable() hook. The .enable() hook
> > > > is called whenever the perf CPU or task context changes which is when
> > > > the RDPMC access may need to change.
> > > >
> > > > This is the first step in moving the RDPMC state tracking out of the mm
> > > > context to the perf context.
> > >
> > > Is this series supposed to be a user-visible change or not? I'm confused.
> >
> > It should not be user-visible. Or at least not user-visible for what
> > any user would notice. If an event is not part of the perf context on
> > another thread sharing the mm, does that thread need rdpmc access? No
> > access would be a user-visible change, but I struggle with how that's
> > a useful scenario?
> >
>
> This is what I mean by user-visible -- it changes semantics in a way that a user program could detect. I'm not saying it's a problem, but I do think you need to document the new semantics.

After testing some scenarios and finding perf_event_tests[1], this
series isn't going to work for x86 unless rdpmc is restricted to task
events only or allowed to segfault on CPU events when read on the
wrong CPU rather than just returning garbage. It's been discussed
before here[2].

Ultimately, I'm just trying to define the behavior for arm64 where we
don't have an existing ABI to maintain and don't have to recreate the
mistakes of x86 rdpmc ABI. Tying the access to mmap is messy. As we
explicitly request user access on perf_event_open(), I think it may be
better to just enable access when the event's context is active and
ignore mmap(). Maybe you have an opinion there since you added the
mmap() part?

Rob

[1] https://github.com/deater/perf_event_tests
[2] https://lore.kernel.org/lkml/alpine.DEB.2.21.1901101229010.3358@macbook-air/