Re: [PATCH v2 3/5] tracing/user_events: Add auto cleanup and a flag to persist events

From: Steven Rostedt
Date: Tue Jun 13 2023 - 15:26:35 EST


On Mon, 5 Jun 2023 16:38:58 -0700
Beau Belgrave <beaub@xxxxxxxxxxxxxxxxxxx> wrote:

Continuing on what Alexei was saying ...

> + /*
> + * Unfortunately we have to attempt the actual destroy in a work
> + * queue. This is because not all cases handle a trace_event_call
> + * being removed within the class->reg() operation for unregister.
> + */
> + INIT_WORK(&user->put_work, delayed_destroy_user_event);

We initialize the work here.

> +
> + /*
> + * Since the event is still in the hashtable, we have to re-inc
> + * the ref count to 1. This count will be decremented and checked
> + * in the work queue to ensure it's still the last ref. This is
> + * needed because a user-process could register the same event in
> + * between the time of event_mutex release and the work queue
> + * running the delayed destroy. If we removed the item now from
> + * the hashtable, this would result in a timing window where a
> + * user process would fail a register because the trace_event_call
> + * register would fail in the tracing layers.
> + */
> + refcount_set(&user->refcnt, 1);
> +
> + if (!schedule_work(&user->put_work)) {

>From what I understand, schedule_work() can only fail if the work is
already queued. That should never happen if we just initialized it.

That means we need a WARN_ON_ONCE() here. Because it's a major bug if that
does return false.

-- Steve


> + /*
> + * If we fail we must wait for an admin to attempt delete or
> + * another register/close of the event, whichever is first.
> + */
> + pr_warn("user_events: Unable to queue delayed destroy\n");
> + }