[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250903001133.8a02cf5db5ab4fd23c9a334f@kernel.org>
Date: Wed, 3 Sep 2025 00:11:33 +0900
From: Masami Hiramatsu (Google) <mhiramat@...nel.org>
To: Jiri Olsa <jolsa@...nel.org>
Cc: Oleg Nesterov <oleg@...hat.com>, Peter Zijlstra <peterz@...radead.org>,
Andrii Nakryiko <andrii@...nel.org>, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
x86@...nel.org, Song Liu <songliubraving@...com>, Yonghong Song
<yhs@...com>, John Fastabend <john.fastabend@...il.com>, Hao Luo
<haoluo@...gle.com>, Steven Rostedt <rostedt@...dmis.org>, Ingo Molnar
<mingo@...nel.org>
Subject: Re: [PATCH perf/core 01/11] uprobes: Add unique flag to uprobe
consumer
On Tue, 2 Sep 2025 16:34:54 +0200
Jiri Olsa <jolsa@...nel.org> wrote:
> Adding unique flag to uprobe consumer to ensure it's the only consumer
> attached on the uprobe.
>
> This is helpful for use cases when consumer wants to change user space
> registers, which might confuse other consumers. With this change we can
> ensure there's only one consumer on specific uprobe.
nit: Does this mean one callback (consumer) is exclusively attached?
If so, "exclusive" will be better wording?
The logic looks good to me.
Thanks,
>
> Signed-off-by: Jiri Olsa <jolsa@...nel.org>
> ---
> include/linux/uprobes.h | 1 +
> kernel/events/uprobes.c | 30 ++++++++++++++++++++++++++++--
> 2 files changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
> index 08ef78439d0d..0df849dee720 100644
> --- a/include/linux/uprobes.h
> +++ b/include/linux/uprobes.h
> @@ -60,6 +60,7 @@ struct uprobe_consumer {
> struct list_head cons_node;
>
> __u64 id; /* set when uprobe_consumer is registered */
> + bool is_unique; /* the only consumer on uprobe */
> };
>
> #ifdef CONFIG_UPROBES
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 996a81080d56..b9b088f7333a 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1024,14 +1024,35 @@ static struct uprobe *alloc_uprobe(struct inode *inode, loff_t offset,
> return uprobe;
> }
>
> -static void consumer_add(struct uprobe *uprobe, struct uprobe_consumer *uc)
> +static bool consumer_can_add(struct list_head *head, struct uprobe_consumer *uc)
> +{
> + /* Uprobe has no consumer, we can add any. */
> + if (list_empty(head))
> + return true;
> + /* Uprobe has consumer/s, we can't add unique one. */
> + if (uc->is_unique)
> + return false;
> + /*
> + * Uprobe has consumer/s, we can add nother consumer only if the
> + * current consumer is not unique.
> + **/
> + return !list_first_entry(head, struct uprobe_consumer, cons_node)->is_unique;
> +}
> +
> +static int consumer_add(struct uprobe *uprobe, struct uprobe_consumer *uc)
> {
> static atomic64_t id;
> + int ret = -EBUSY;
>
> down_write(&uprobe->consumer_rwsem);
> + if (!consumer_can_add(&uprobe->consumers, uc))
> + goto unlock;
> list_add_rcu(&uc->cons_node, &uprobe->consumers);
> uc->id = (__u64) atomic64_inc_return(&id);
> + ret = 0;
> +unlock:
> up_write(&uprobe->consumer_rwsem);
> + return ret;
> }
>
> /*
> @@ -1420,7 +1441,12 @@ struct uprobe *uprobe_register(struct inode *inode,
> return uprobe;
>
> down_write(&uprobe->register_rwsem);
> - consumer_add(uprobe, uc);
> + ret = consumer_add(uprobe, uc);
> + if (ret) {
> + put_uprobe(uprobe);
> + up_write(&uprobe->register_rwsem);
> + return ERR_PTR(ret);
> + }
> ret = register_for_each_vma(uprobe, uc);
> up_write(&uprobe->register_rwsem);
>
> --
> 2.51.0
>
--
Masami Hiramatsu (Google) <mhiramat@...nel.org>
Powered by blists - more mailing lists