public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Jiri Olsa <olsajiri@gmail.com>, Tianyi Liu <i.pear@outlook.com>,
	andrii.nakryiko@gmail.com, mhiramat@kernel.org, ajor@meta.com,
	albancrequy@linux.microsoft.com, bpf@vger.kernel.org,
	flaniel@linux.microsoft.com, linux-trace-kernel@vger.kernel.org,
	linux@jordanrome.com, mathieu.desnoyers@efficios.com
Subject: Re: [PATCH v2] tracing/uprobe: Add missing PID filter for uretprobe
Date: Thu, 29 Aug 2024 21:46:25 +0200	[thread overview]
Message-ID: <ZtDQEVN1-BAfWuMU@krava> (raw)
In-Reply-To: <20240829152032.GA23996@redhat.com>

On Thu, Aug 29, 2024 at 05:20:33PM +0200, Oleg Nesterov wrote:

SNIP

> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index f7443e996b1b..e4eaa0363742 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -1364,7 +1364,7 @@ static bool uprobe_perf_filter(struct uprobe_consumer *uc, struct mm_struct *mm)
>  	return ret;
>  }
>  
> -static void __uprobe_perf_func(struct trace_uprobe *tu,
> +static int __uprobe_perf_func(struct trace_uprobe *tu,
>  			       unsigned long func, struct pt_regs *regs,
>  			       struct uprobe_cpu_buffer **ucbp)
>  {
> @@ -1375,6 +1375,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu,
>  	void *data;
>  	int size, esize;
>  	int rctx;
> +	int ret = 0;
>  
>  #ifdef CONFIG_BPF_EVENTS
>  	if (bpf_prog_array_valid(call)) {
> @@ -1382,7 +1383,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu,
>  
>  		ret = bpf_prog_run_array_uprobe(call->prog_array, regs, bpf_prog_run);
>  		if (!ret)
> -			return;
> +			return -1;
>  	}
>  #endif /* CONFIG_BPF_EVENTS */
>  
> @@ -1392,12 +1393,13 @@ static void __uprobe_perf_func(struct trace_uprobe *tu,
>  	size = esize + ucb->dsize;
>  	size = ALIGN(size + sizeof(u32), sizeof(u64)) - sizeof(u32);
>  	if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough"))
> -		return;
> +		return -1;
>  
>  	preempt_disable();
>  	head = this_cpu_ptr(call->perf_events);
>  	if (hlist_empty(head))
>  		goto out;

right.. if the event is not added by perf_trace_add on this cpu
it won't go pass this point, so no problem for perf

but the issue is with bpf program triggered earlier by return uprobe
created via perf event and [1] patch seems to fix that

I sent out the bpf selftest that triggers the issue [2]

thanks,
jirka


[1] https://lore.kernel.org/linux-trace-kernel/ME0P300MB0416034322B9915ECD3888649D882@ME0P300MB0416.AUSP300.PROD.OUTLOOK.COM/
[2] https://lore.kernel.org/bpf/20240829194505.402807-1-jolsa@kernel.org/T/#u


> +	ret = 1;
>  
>  	entry = perf_trace_buf_alloc(size, NULL, &rctx);
>  	if (!entry)
> @@ -1421,6 +1423,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu,
>  			      head, NULL);
>   out:
>  	preempt_enable();
> +	return ret;
>  }
>  
>  /* uprobe profile handler */
> @@ -1439,7 +1442,15 @@ static void uretprobe_perf_func(struct trace_uprobe *tu, unsigned long func,
>  				struct pt_regs *regs,
>  				struct uprobe_cpu_buffer **ucbp)
>  {
> -	__uprobe_perf_func(tu, func, regs, ucbp);
> +	struct trace_uprobe_filter *filter = tu->tp.event->filter;
> +	struct perf_event *event = list_first_entry(&filter->perf_events,
> +					struct perf_event, hw.tp_list);
> +
> +	int r = __uprobe_perf_func(tu, func, regs, ucbp);
> +
> +	pr_crit("HANDLER pid=%d consumers_target=%d stored=%d\n",
> +		current->pid, event->hw.target ? event->hw.target->pid : -1, r);
> +
>  }
>  
>  int bpf_get_uprobe_info(const struct perf_event *event, u32 *fd_type,
> 

  reply	other threads:[~2024-08-29 19:46 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ME0P300MB0416034322B9915ECD3888649D882@ME0P300MB0416.AUSP300.PROD.OUTLOOK.COM>
2024-08-23 17:44 ` [PATCH v2] tracing/uprobe: Add missing PID filter for uretprobe Masami Hiramatsu
2024-08-23 19:07   ` Andrii Nakryiko
2024-08-24  5:49     ` Tianyi Liu
2024-08-24 17:27       ` Masami Hiramatsu
2024-08-25 17:14       ` Oleg Nesterov
2024-08-25 18:43         ` Oleg Nesterov
2024-08-25 22:40         ` Oleg Nesterov
2024-08-26 10:05           ` Jiri Olsa
2024-08-26 11:57             ` Oleg Nesterov
2024-08-26 12:24               ` Oleg Nesterov
2024-08-26 13:48               ` Jiri Olsa
2024-08-26 18:56                 ` Oleg Nesterov
2024-08-26 21:25                 ` Oleg Nesterov
2024-08-26 22:01                   ` Jiri Olsa
2024-08-26 22:08                     ` Andrii Nakryiko
2024-08-26 22:29                     ` Oleg Nesterov
2024-08-27 13:07                       ` Jiri Olsa
2024-08-27 13:45                         ` Jiri Olsa
2024-08-27 16:45                         ` Oleg Nesterov
2024-08-28 11:40                           ` Jiri Olsa
2024-08-27 20:19                         ` Oleg Nesterov
2024-08-28 11:46                           ` Jiri Olsa
2024-08-29 15:20                             ` Oleg Nesterov
2024-08-29 19:46                               ` Jiri Olsa [this message]
2024-08-29 21:12                                 ` Oleg Nesterov
2024-08-29 23:22                                   ` Jiri Olsa
2024-08-27  6:27                   ` Tianyi Liu
2024-08-27 10:08               ` Jiri Olsa
2024-08-27 10:20                 ` Jiri Olsa
2024-08-27 10:54                   ` Oleg Nesterov
2024-08-27 10:40                 ` Oleg Nesterov
2024-08-27 13:32                   ` Jiri Olsa
2024-08-27 14:26                     ` Oleg Nesterov
2024-08-27 14:41                       ` Jiri Olsa
2024-08-26 14:52           ` Tianyi Liu
2024-08-25 17:00     ` Oleg Nesterov
2024-08-30 10:12 ` Oleg Nesterov
2024-08-30 12:23   ` Oleg Nesterov
2024-08-30 13:34   ` Jiri Olsa
2024-08-30 15:51     ` Andrii Nakryiko
2024-09-02  9:11       ` Jiri Olsa
2024-09-03 18:09         ` Andrii Nakryiko
2024-09-03 18:11           ` Andrii Nakryiko
2024-09-03 19:15             ` Jiri Olsa
2024-09-01 19:22   ` Tianyi Liu
2024-09-01 23:26     ` Oleg Nesterov
2024-09-02 17:17       ` Oleg Nesterov
2024-09-03 14:33         ` Jiri Olsa
2024-09-06 10:43     ` Jiri Olsa
2024-09-06 19:18       ` Oleg Nesterov
2024-09-09 10:41         ` Jiri Olsa
2024-09-09 18:34           ` Oleg Nesterov
2024-09-10  8:45             ` Jiri Olsa
2024-09-07 19:19       ` Tianyi Liu
2024-09-08 13:15         ` Oleg Nesterov
2024-09-09  1:16           ` Andrii Nakryiko

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=ZtDQEVN1-BAfWuMU@krava \
    --to=olsajiri@gmail.com \
    --cc=ajor@meta.com \
    --cc=albancrequy@linux.microsoft.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=flaniel@linux.microsoft.com \
    --cc=i.pear@outlook.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linux@jordanrome.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=oleg@redhat.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