Re: [PATCH 1/1] Return EINVAL when precise_ip perf events are requested on Arm

Mark Rutland
2020-01-20T15:34:02Z

On Fri, Jan 17, 2020 at 04:16:58PM +0100, Peter Zijlstra wrote:
> On Fri, Jan 17, 2020 at 03:00:37PM +0000, James Clark wrote:
> > Hi Peter,
> >
> > Do you mean something like this?
>
> Yes.
>
> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index 43d1d4945433..f74acd085bea 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -10812,6 +10812,12 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
> > goto err_pmu;
> > }
> >
> > + if (event->attr.precise_ip &&
> > + !(pmu->capabilities & PERF_PMU_CAP_PRECISE_IP)) {
> > + err = -EOPNOTSUPP;
> > + goto err_pmu;
> > + }
> > +
> > err = exclusive_event_init(event);
> > if (err)
> > goto err_pmu;
> >
> >
> > Or should it only be done via sysfs to not break userspace?
>
> So we've added checks like this in the past and gotten away with it. Do
> you already know of some userspace that will break due to it?
>
> An alternative approach is adding a sysctl like kernel.perf_nostrict
> which would disable this or something, that way 'old' userspace has a
> chicken bit.

Could we allocate a "strict" bit from perf_event_attr::__reserved_1, and
update drivers to expose a whitelist of fields they support?

Then the core could do something like:

if (attr->strict && !pmu_check_whitelist(pmu, attr))
return -EOPNOTSUPP;

... and we could also expose the whitelist somewhere in sysfs.

Thanks,
Mark,