BPF List
 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>, Song Liu <song@kernel.org>,
	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>,
	Yafang Shao <laoar.shao@gmail.com>
Subject: Re: [PATCHv3 bpf-next 5/6] selftests/bpf: Add link_info test for uprobe_multi link
Date: Tue, 21 Nov 2023 12:29:24 +0100	[thread overview]
Message-ID: <ZVyUlD8Unm0hSU54@krava> (raw)
In-Reply-To: <a76c9ee4-d381-477d-b7f6-19f4dc4c0b42@linux.dev>

On Mon, Nov 20, 2023 at 10:22:26AM -0800, Yonghong Song wrote:
> 
> On 11/20/23 9:56 AM, Jiri Olsa wrote:
> > Adding fill_link_info test for uprobe_multi link.
> > 
> > Setting up uprobes with bogus ref_ctr_offsets and cookie values
> > to test all the bpf_link_info::uprobe_multi fields.
> > 
> > Acked-by: Song Liu <song@kernel.org>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >   .../selftests/bpf/prog_tests/fill_link_info.c | 191 ++++++++++++++++++
> >   .../selftests/bpf/progs/test_fill_link_info.c |   6 +
> >   2 files changed, 197 insertions(+)
> > 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> > index 9294cb8d7743..fdf2c6b8c0cf 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> > @@ -7,6 +7,7 @@
> >   #include <test_progs.h>
> >   #include "trace_helpers.h"
> >   #include "test_fill_link_info.skel.h"
> > +#include "bpf/libbpf_internal.h"
> >   #define TP_CAT "sched"
> >   #define TP_NAME "sched_switch"
> > @@ -300,6 +301,189 @@ static void test_kprobe_multi_fill_link_info(struct test_fill_link_info *skel,
> >   	bpf_link__destroy(link);
> >   }
> > +/* Initialize semaphore variables so they don't end up in bss
> > + * section and we could get retrieve their offsets.
> > + */
> > +static short uprobe_link_info_sema_1 = 1;
> > +static short uprobe_link_info_sema_2 = 1;
> > +static short uprobe_link_info_sema_3 = 1;
> 
> I guess The typical sema value starting value should be 0, right?
> If this is the case, the above is not a good example.
> So the issue is that current libbpf does not support
> retrieving offset from .bss section? Do you know why?

hum, I can't recall why it was the problem, because it seems to work
with .bss now when I try it ... anyway I think your suggestion below
is better

> 
> In selftest udst.c, we have semaphore defined as
> usdt.c:unsigned short test_usdt0_semaphore SEC(".probes");
> usdt.c:unsigned short test_usdt3_semaphore SEC(".probes");
> usdt.c:unsigned short test_usdt12_semaphore SEC(".probes");
> 
> Will the following work?
> static short uprobe_link_info_sema_1 SEC(".probes");

yes, that will work and it's better

> ...
> 
> > +
> > +noinline void uprobe_link_info_func_1(void)
> > +{
> > +	uprobe_link_info_sema_1++;
> > +	asm volatile ("");
> 
> The 'asm volatile' above intends to prevent compiler from
> doing 'implicit' inlining. So as a convention let us
> switch statement order to
> 
> 	asm volatile ("");
> 	uprobe_link_info_sema_1++;
> 
> Similarly for below.

ok

SNIP

> > +static void test_uprobe_multi_fill_link_info(struct test_fill_link_info *skel,
> > +					     bool retprobe, bool invalid)
> > +{
> > +	LIBBPF_OPTS(bpf_uprobe_multi_opts, opts,
> > +		.retprobe = retprobe,
> > +	);
> > +	const char *syms[3] = {
> > +		"uprobe_link_info_func_1",
> > +		"uprobe_link_info_func_2",
> > +		"uprobe_link_info_func_3",
> > +	};
> > +	__u64 cookies[3] = {
> > +		0xdead,
> > +		0xbeef,
> > +		0xcafe,
> > +	};
> > +	const char *sema[3] = {
> > +		"uprobe_link_info_sema_1",
> > +		"uprobe_link_info_sema_2",
> > +		"uprobe_link_info_sema_3",
> > +	};
> > +	__u64 *offsets, *ref_ctr_offsets;
> > +	struct bpf_link *link;
> > +	int link_fd, err;
> > +
> > +	err = elf_resolve_syms_offsets("/proc/self/exe", 3, sema,
> > +				       (unsigned long **) &ref_ctr_offsets, STT_OBJECT);
> > +	if (!ASSERT_OK(err, "elf_resolve_syms_offsets_object"))
> > +		return;
> > +
> > +	err = elf_resolve_syms_offsets("/proc/self/exe", 3, syms,
> > +				       (unsigned long **) &offsets, STT_FUNC);
> > +	if (!ASSERT_OK(err, "elf_resolve_syms_offsets_func"))
> > +		return;
> 
> potential leak of ref_ctr_offsets?

ugh yep, will fix

> 
> > +
> > +	opts.syms = syms;
> > +	opts.cookies = &cookies[0];
> > +	opts.ref_ctr_offsets = (unsigned long *) &ref_ctr_offsets[0];
> > +	opts.cnt = ARRAY_SIZE(syms);
> > +
> > +	link = bpf_program__attach_uprobe_multi(skel->progs.umulti_run, 0,
> > +						"/proc/self/exe", NULL, &opts);
> > +	if (!ASSERT_OK_PTR(link, "bpf_program__attach_uprobe_multi"))
> > +		goto out;
> > +
> > +	link_fd = bpf_link__fd(link);
> > +	if (invalid)
> > +		verify_umulti_invalid_user_buffer(link_fd);
> > +	else
> > +		verify_umulti_link_info(link_fd, retprobe, offsets, cookies, ref_ctr_offsets);
> > +
> > +	bpf_link__destroy(link);
> > +out:
> > +	free(offsets);
> 
> Should we free ref_ctr_offsets here?

yes, thanks

jirka

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

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-20 14:56 [PATCHv3 bpf-next 0/6] bpf: Add link_info support for uprobe multi link Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 1/6] libbpf: Add st_type argument to elf_resolve_syms_offsets function Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 2/6] bpf: Store ref_ctr_offsets values in bpf_uprobe array Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 3/6] bpf: Add link_info support for uprobe multi link Jiri Olsa
2023-11-20 18:04   ` Yonghong Song
2023-11-22 21:50     ` Jiri Olsa
2023-11-23  9:20       ` Jiri Olsa
2023-11-23 18:26         ` Yonghong Song
2023-11-21 18:41   ` Andrii Nakryiko
2023-11-22 13:48     ` Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 4/6] selftests/bpf: Use bpf_link__destroy in fill_link_info tests Jiri Olsa
2023-11-20 18:06   ` Yonghong Song
2023-11-20 14:56 ` [PATCHv3 bpf-next 5/6] selftests/bpf: Add link_info test for uprobe_multi link Jiri Olsa
2023-11-20 18:22   ` Yonghong Song
2023-11-21 11:29     ` Jiri Olsa [this message]
2023-11-20 14:56 ` [PATCHv3 bpf-next 6/6] bpftool: Add support to display uprobe_multi links Jiri Olsa
2023-11-20 18:32   ` Yonghong Song
2023-11-21 11:35     ` 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=ZVyUlD8Unm0hSU54@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=song@kernel.org \
    --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