linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, x86@kernel.org,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Hao Luo <haoluo@google.com>, Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH perf/core 01/11] uprobes: Add unique flag to uprobe consumer
Date: Wed, 3 Sep 2025 00:11:33 +0900	[thread overview]
Message-ID: <20250903001133.8a02cf5db5ab4fd23c9a334f@kernel.org> (raw)
In-Reply-To: <20250902143504.1224726-2-jolsa@kernel.org>

On Tue,  2 Sep 2025 16:34:54 +0200
Jiri Olsa <jolsa@kernel.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@kernel.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@kernel.org>

  reply	other threads:[~2025-09-02 15:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 14:34 [PATCH perf/core 00/11] uprobes: Add unique uprobe Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 01/11] uprobes: Add unique flag to uprobe consumer Jiri Olsa
2025-09-02 15:11   ` Masami Hiramatsu [this message]
2025-09-03  6:35     ` Jiri Olsa
2025-09-03 10:49   ` Oleg Nesterov
2025-09-03 12:02     ` Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 02/11] uprobes: Skip emulate/sstep on unique uprobe when ip is changed Jiri Olsa
2025-09-03 11:26   ` Oleg Nesterov
2025-09-03 18:20     ` Andrii Nakryiko
2025-09-03 19:57       ` Jiri Olsa
2025-09-03 19:50     ` Jiri Olsa
2025-09-04  8:49       ` Oleg Nesterov
2025-09-04 10:46         ` Jiri Olsa
2025-09-04 11:23           ` Oleg Nesterov
2025-09-04 15:01             ` Alexei Starovoitov
2025-09-04 18:06               ` Andrii Nakryiko
2025-09-04 18:55                 ` Oleg Nesterov
2025-09-04 19:42                   ` Andrii Nakryiko
2025-09-05  8:51                     ` Oleg Nesterov
2025-09-02 14:34 ` [PATCH perf/core 03/11] perf: Add support to attach standard unique uprobe Jiri Olsa
2025-09-02 16:13   ` Alexei Starovoitov
2025-09-03  3:32   ` kernel test robot
2025-09-03 11:59   ` Oleg Nesterov
2025-09-03 13:03     ` Jiri Olsa
2025-09-03 13:22       ` Oleg Nesterov
2025-09-02 14:34 ` [PATCH perf/core 04/11] bpf: Add support to attach uprobe_multi " Jiri Olsa
2025-09-02 16:11   ` Alexei Starovoitov
2025-09-03  6:35     ` Jiri Olsa
2025-09-03 15:32       ` Alexei Starovoitov
2025-09-03 19:55         ` Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 05/11] bpf: Allow uprobe program to change context registers Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 06/11] libbpf: Add support to attach unique uprobe_multi uprobe Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 07/11] libbpf: Add support to attach generic unique uprobe Jiri Olsa
2025-09-03 18:26   ` Andrii Nakryiko
2025-09-02 14:35 ` [PATCH perf/core 08/11] selftests/bpf: Add uprobe multi context registers changes test Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 09/11] selftests/bpf: Add uprobe multi context ip register change test Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 10/11] selftests/bpf: Add uprobe multi unique attach test Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 11/11] selftests/bpf: Add uprobe " Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250903001133.8a02cf5db5ab4fd23c9a334f@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=x86@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).