Re: Process-wide watchpoints
From: Peter Zijlstra
Date: Wed Feb 03 2021 - 07:22:55 EST
On Sun, Jan 31, 2021 at 11:04:43AM +0100, Dmitry Vyukov wrote:
> PERF_EVENT_IOC_{ENABLE,DISABLE} work as advertised.
> However, PERF_EVENT_IOC_MODIFY_ATTRIBUTES does not work for inherited
> child events.
> Does something like this make any sense to you? Are you willing to
> accept such change?
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 55d18791a72d..f6974807a32c 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -3174,7 +3174,7 @@ int perf_event_refresh(struct perf_event *event,
> int refresh)
> }
> EXPORT_SYMBOL_GPL(perf_event_refresh);
>
> -static int perf_event_modify_breakpoint(struct perf_event *bp,
> +static int _perf_event_modify_breakpoint(struct perf_event *bp,
> struct perf_event_attr *attr)
> {
> int err;
> @@ -3189,6 +3189,28 @@ static int perf_event_modify_breakpoint(struct
> perf_event *bp,
> return err;
> }
>
> +static int perf_event_modify_breakpoint(struct perf_event *bp,
> + struct perf_event_attr *attr)
> +{
> + struct perf_event *child;
> + int err;
> +
> + WARN_ON_ONCE(bp->ctx->parent_ctx);
> +
> + mutex_lock(&bp->child_mutex);
> + err = _perf_event_modify_breakpoint(bp, attr);
> + if (err)
> + goto unlock;
> + list_for_each_entry(child, &bp->child_list, child_list) {
> + err = _perf_event_modify_breakpoint(child, attr);
> + if (err)
> + goto unlock;
> + }
> +unlock:
> + mutex_unlock(&bp->child_mutex);
> + return err;
> +}
> +
> static int perf_event_modify_attr(struct perf_event *event,
> struct perf_event_attr *attr)
Oh.. yeah, normal ioctl()s go through the perf_event_for_each_child()
thing, but that doesn't work here.
So yeah, I suppose your patch makes sense.