mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Adriano Cordova <adrianox@gmail.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH 2/2] uprobes: Hide unprepared uprobes from the breakpoint paths
Date: Sun, 20 Sep 2026 16:38:00 +0200	[thread overview]
Message-ID: <aq_vyA_eIfvpCuj1@redhat.com> (raw)
In-Reply-To: <20260918143209.709291-2-adrianox@gmail.com>

On 09/18, Adriano Cordova wrote:
>
> find_uprobe_rcu() backs handle_swbp() and handle_syscall_uprobe(). Make
> it skip a uprobe whose instruction has not been analyzed yet, so neither
> path can use an uninitialized ->arch. An unprepared uprobe has no
> breakpoint installed (install_breakpoint() prepares before set_swbp()),
> so the trap path treats it as not registered yet. This also gives
> handle_syscall_uprobe() the check it was missing.

Sorry, I am confused.

Can you explain in more details what problem(s) this series tries to fix?

handle_swbp() checks UPROBE_COPY_INSN.

handle_syscall_uprobe() is only called by sys_uprobe() which checks
in_uprobe_trampoline(). So it can only be called after the probed insn
has been analyzed and optimized.

Oleg.

> Signed-off-by: Adriano Cordova <adrianox@gmail.com>
> ---
>  kernel/events/uprobes.c | 35 +++++++++++++++--------------------
>  1 file changed, 15 insertions(+), 20 deletions(-)
> 
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 686585539ebf..bdc05fdce0a0 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -924,8 +924,20 @@ static struct uprobe *find_uprobe_rcu(struct inode *inode, loff_t offset)
>  		 * try again as we might have missed the element (false
>  		 * negative). If seqcount is unchanged, search truly failed.
>  		 */
> -		if (node)
> -			return __node_2_uprobe(node);
> +		if (node) {
> +			struct uprobe *uprobe = __node_2_uprobe(node);
> +
> +			/*
> +			 * A uprobe is inserted before it is prepared; do
> +			 * not hand it out until ->arch is usable.
> +			 */
> +			if (!test_bit(UPROBE_COPY_INSN, &uprobe->flags))
> +				return NULL;
> +
> +			/* Pairs with the smp_wmb() in prepare_uprobe(). */
> +			smp_rmb();
> +			return uprobe;
> +		}
>  	} while (read_seqcount_retry(&uprobes_seqcount, seq));
>  
>  	return NULL;
> @@ -1123,7 +1135,7 @@ static int prepare_uprobe(struct uprobe *uprobe, struct file *file,
>  	if (ret)
>  		goto out;
>  
> -	smp_wmb(); /* pairs with the smp_rmb() in handle_swbp() */
> +	smp_wmb(); /* pairs with the smp_rmb() in find_uprobe_rcu() */
>  	set_bit(UPROBE_COPY_INSN, &uprobe->flags);
>  
>   out:
> @@ -2743,23 +2755,6 @@ static void handle_swbp(struct pt_regs *regs)
>  	/* change it in advance for ->handler() and restart */
>  	instruction_pointer_set(regs, bp_vaddr);
>  
> -	/*
> -	 * TODO: move copy_insn/etc into _register and remove this hack.
> -	 * After we hit the bp, _unregister + _register can install the
> -	 * new and not-yet-analyzed uprobe at the same address, restart.
> -	 */
> -	if (unlikely(!test_bit(UPROBE_COPY_INSN, &uprobe->flags)))
> -		goto out;
> -
> -	/*
> -	 * Pairs with the smp_wmb() in prepare_uprobe().
> -	 *
> -	 * Guarantees that if we see the UPROBE_COPY_INSN bit set, then
> -	 * we must also see the stores to &uprobe->arch performed by the
> -	 * prepare_uprobe() call.
> -	 */
> -	smp_rmb();
> -
>  	/* Tracing handlers use ->utask to communicate with fetch methods */
>  	if (!get_utask())
>  		goto out;
> -- 
> 2.51.0
> 


  reply	other threads:[~2026-09-20 14:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 14:32 [PATCH 1/2] uprobes: Use a dedicated mutex to serialize prepare_uprobe() Adriano Cordova
2026-09-18 14:32 ` [PATCH 2/2] uprobes: Hide unprepared uprobes from the breakpoint paths Adriano Cordova
2026-09-20 14:38   ` Oleg Nesterov [this message]
2026-09-20 14:35 ` [PATCH 1/2] uprobes: Use a dedicated mutex to serialize prepare_uprobe() Oleg Nesterov

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=aq_vyA_eIfvpCuj1@redhat.com \
    --to=oleg@redhat.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=adrianox@gmail.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andrii@kernel.org \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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

all inboxes | Powered by JetHome®