public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Yonghong Song <yonghong.song@linux.dev>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Yafang Shao <laoar.shao@gmail.com>,
	bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>
Subject: Re: [PATCHv6 bpf-next 03/28] bpf: Add multi uprobe link
Date: Sat, 5 Aug 2023 23:11:20 +0200	[thread overview]
Message-ID: <ZM66+KHkfhNE79Kj@krava> (raw)
In-Reply-To: <8f678d1a-d2c2-c979-f37e-db0f4bf6e933@linux.dev>

On Fri, Aug 04, 2023 at 02:55:29PM -0700, Yonghong Song wrote:

SNIP

> > +static int uprobe_prog_run(struct bpf_uprobe *uprobe,
> > +			   unsigned long entry_ip,
> > +			   struct pt_regs *regs)
> > +{
> > +	struct bpf_uprobe_multi_link *link = uprobe->link;
> > +	struct bpf_uprobe_multi_run_ctx run_ctx = {
> > +		.entry_ip = entry_ip,
> > +	};
> > +	struct bpf_prog *prog = link->link.prog;
> > +	bool sleepable = prog->aux->sleepable;
> > +	struct bpf_run_ctx *old_run_ctx;
> > +	int err = 0;
> > +
> > +	might_fault();
> 
> Could you explain what you try to protect here
> with might_fault()?
> 
> In my opinion, might_fault() is unnecessary here
> since the calling context is process context and
> there is no mmap_lock held, so might_fault()
> won't capture anything.
> 
> might_fault() is used in iter.c and trampoline.c
> since their calling context is more complex
> than here and might_fault() may actually capture
> issues.

hum, I followed bpf_prog_run_array_sleepable, which is called
the same way.. will check

> 
> > +
> > +	migrate_disable();
> > +
> > +	if (sleepable)
> > +		rcu_read_lock_trace();
> > +	else
> > +		rcu_read_lock();
> 
> Looking at trampoline.c and iter.c, typical
> usage is
> 	rcu_read_lock_trace()/rcu_read_lock()
> 	migrate_disable()
> 
> Your above sequenence could be correct too. But it
> is great if we can keep consistency here.

ok, will switch that

SNIP

> > +	link->cnt = cnt;
> > +	link->uprobes = uprobes;
> > +	link->path = path;
> > +
> > +	bpf_link_init(&link->link, BPF_LINK_TYPE_UPROBE_MULTI,
> > +		      &bpf_uprobe_multi_link_lops, prog);
> > +
> > +	err = bpf_link_prime(&link->link, &link_primer);
> > +	if (err)
> > +		goto error_free;
> > +
> > +	for (i = 0; i < cnt; i++) {
> > +		err = uprobe_register_refctr(d_real_inode(link->path.dentry),
> > +					     uprobes[i].offset,
> > +					     ref_ctr_offsets ? ref_ctr_offsets[i] : 0,
> > +					     &uprobes[i].consumer);
> > +		if (err) {
> > +			bpf_uprobe_unregister(&path, uprobes, i);
> > +			bpf_link_cleanup(&link_primer);
> > +			kvfree(ref_ctr_offsets);
> 
> Is it possible we may miss some of below 'error_free' cleanups?
> In my opinion, we should replace
> 			kvfree(ref_ctr_offsets);
> 			return err;
> with
> 			goto error_free;
> 
> Could you double check?

the problem here is that bpf_link_cleanup calls link's dealloc callback,
so it get's released in bpf_uprobe_multi_link_dealloc.. which is missing
task release :-\

I think we could init the link only after we create all the uprobes,
and have single release function dealloc callback and error path in here

thanks,
jirka

> 
> > +			return err;
> > +		}
> > +	}
> > +
> > +	kvfree(ref_ctr_offsets);
> > +	return bpf_link_settle(&link_primer);
> > +
> > +error_free:
> > +	kvfree(ref_ctr_offsets);
> > +	kvfree(uprobes);
> > +	kfree(link);
> > +error_path_put:
> > +	path_put(&path);
> > +	return err;
> > +}
> > +#else /* !CONFIG_UPROBES */
> > +int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
> > +{
> > +	return -EOPNOTSUPP;
> > +}
> > +#endif /* CONFIG_UPROBES */
> [...]

  reply	other threads:[~2023-08-05 21:11 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03  7:33 [PATCHv6 bpf-next 00/28] bpf: Add multi uprobe link Jiri Olsa
2023-08-03  7:33 ` [PATCHv6 bpf-next 01/28] bpf: Switch BPF_F_KPROBE_MULTI_RETURN macro to enum Jiri Olsa
2023-08-03  7:33 ` [PATCHv6 bpf-next 02/28] bpf: Add attach_type checks under bpf_prog_attach_check_attach_type Jiri Olsa
2023-08-03  7:33 ` [PATCHv6 bpf-next 03/28] bpf: Add multi uprobe link Jiri Olsa
2023-08-04 21:55   ` Yonghong Song
2023-08-05 21:11     ` Jiri Olsa [this message]
2023-08-03  7:33 ` [PATCHv6 bpf-next 04/28] bpf: Add cookies support for uprobe_multi link Jiri Olsa
2023-08-03  7:33 ` [PATCHv6 bpf-next 05/28] bpf: Add pid filter " Jiri Olsa
2023-08-03  7:33 ` [PATCHv6 bpf-next 06/28] bpf: Add bpf_get_func_ip helper support for uprobe link Jiri Olsa
2023-08-03  7:33 ` [PATCHv6 bpf-next 07/28] libbpf: Add uprobe_multi attach type and link names Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 08/28] libbpf: Move elf_find_func_offset* functions to elf object Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 09/28] libbpf: Add elf_open/elf_close functions Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 10/28] libbpf: Add elf symbol iterator Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 11/28] libbpf: Add elf_resolve_syms_offsets function Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 12/28] libbpf: Add elf_resolve_pattern_offsets function Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 13/28] libbpf: Add bpf_link_create support for multi uprobes Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 14/28] libbpf: Add bpf_program__attach_uprobe_multi function Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 15/28] libbpf: Add support for u[ret]probe.multi[.s] program sections Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 16/28] libbpf: Add uprobe multi link detection Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 17/28] libbpf: Add uprobe multi link support to bpf_program__attach_usdt Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 18/28] selftests/bpf: Move get_time_ns to testing_helpers.h Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 19/28] selftests/bpf: Add uprobe_multi skel test Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 20/28] selftests/bpf: Add uprobe_multi api test Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 21/28] selftests/bpf: Add uprobe_multi link test Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 22/28] selftests/bpf: Add uprobe_multi test program Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 23/28] selftests/bpf: Add uprobe_multi bench test Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 24/28] selftests/bpf: Add uprobe_multi usdt test code Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 25/28] selftests/bpf: Add uprobe_multi usdt bench test Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 26/28] selftests/bpf: Add uprobe_multi cookie test Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 27/28] selftests/bpf: Add uprobe_multi pid filter tests Jiri Olsa
2023-08-03  7:34 ` [PATCHv6 bpf-next 28/28] selftests/bpf: Add extra link to uprobe_multi tests 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=ZM66+KHkfhNE79Kj@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=laoar.shao@gmail.com \
    --cc=sdf@google.com \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    --cc=yonghong.song@linux.dev \
    /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