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

Peter Zijlstra
2020-01-17T15:17:19Z

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.