From nobody Wed Nov 27 10:42:40 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 396D31D31B2; Thu, 10 Oct 2024 20:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728591182; cv=none; b=Fwg1sCCgyeaqu1kEtKgLxy2cDETmlgm6yOeafTl00iXGfQBdf2IoqyNFE/e3ytwHsLm+6x+NKzs+v7Aw5SywgNEE7cPrASHchwH4EHVxR4XQQwsOHa0sh42jvCbQ5pJMR3n2zb7yFZSZ7rJDBHLpCqP59Z9XVxHanlOTTYObIMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728591182; c=relaxed/simple; bh=JGc9i062+P//gbMEIPHizp07D5rtK3D6ZFWovEKATw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gwI1i7pxqMUebe75aAaPNGaz0OEw4dTj6zwaddcMejSIcIyrquIf/Ry/UTRhrhv2X//XysmbPuJh2zgQpfFqUWBzn4DvI4RIuKu8uEE4sAXk11pCoRUrHTM08Q32Td0mO1F/Ti5POX8bsQLR7wJexHPDPM8Qzu6xuOABTFx8aW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A9xq3G4a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A9xq3G4a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90DA6C4CEC5; Thu, 10 Oct 2024 20:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728591181; bh=JGc9i062+P//gbMEIPHizp07D5rtK3D6ZFWovEKATw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A9xq3G4ajGFnJ/xOnKI7s8+OWKGqLUrSGPBZuZlFZXqfhz5Y6DqpEwel3Tw/50Yzg 2NkNsbMBWI4CF34SzQBIVi2BzVtSJvbsy2vKaimyVy6q0yiumrZvpsaPdCWagudUJP gahhyJbmOaaBx7hr7FfszBqGWY0Sk3qZ3AoRq4vXE/RH1uYRzYbpskuAjYya1NvV4G Kziry/YV8hny2lf/Q3cGlx9kGqtmLL5V9A1VLEEBg+FDUVdMr6JL8hx7n/kbXjlK92 pXgUxP0Sh052+n44GtzK1AS4Yg4/lzPXtYqR5esskfWHswouxIb7eoCjFlFepE+f/1 hEfmUn08pRGvw== From: Jiri Olsa To: Oleg Nesterov , Peter Zijlstra , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCHv6 bpf-next 15/16] selftests/bpf: Add uprobe sessions to consumer test Date: Thu, 10 Oct 2024 22:09:56 +0200 Message-ID: <20241010200957.2750179-16-jolsa@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241010200957.2750179-1-jolsa@kernel.org> References: <20241010200957.2750179-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adding uprobe session consumers to the consumer test, so we get the session into the test mix. Signed-off-by: Jiri Olsa --- .../bpf/prog_tests/uprobe_multi_test.c | 63 +++++++++++++++---- .../bpf/progs/uprobe_multi_consumers.c | 16 ++++- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/t= ools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c index 2effe4d693b4..df9314309bc3 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c @@ -761,6 +761,10 @@ get_program(struct uprobe_multi_consumers *skel, int p= rog) return skel->progs.uprobe_0; case 1: return skel->progs.uprobe_1; + case 2: + return skel->progs.uprobe_2; + case 3: + return skel->progs.uprobe_3; default: ASSERT_FAIL("get_program"); return NULL; @@ -775,6 +779,10 @@ get_link(struct uprobe_multi_consumers *skel, int link) return &skel->links.uprobe_0; case 1: return &skel->links.uprobe_1; + case 2: + return &skel->links.uprobe_2; + case 3: + return &skel->links.uprobe_3; default: ASSERT_FAIL("get_link"); return NULL; @@ -793,8 +801,11 @@ static int uprobe_attach(struct uprobe_multi_consumers= *skel, int idx) /* * bit/prog: 0 uprobe entry * bit/prog: 1 uprobe return + * bit/prog: 2 uprobe session without return + * bit/prog: 3 uprobe session with return */ opts.retprobe =3D idx =3D=3D 1; + opts.session =3D idx =3D=3D 2 || idx =3D=3D 3; =20 *link =3D bpf_program__attach_uprobe_multi(prog, 0, "/proc/self/exe", "uprobe_consumer_test", @@ -824,7 +835,7 @@ uprobe_consumer_test(struct uprobe_multi_consumers *ske= l, int idx; =20 /* detach uprobe for each unset programs in 'before' state ... */ - for (idx =3D 0; idx < 1; idx++) { + for (idx =3D 0; idx < 4; idx++) { if (test_bit(idx, before) && !test_bit(idx, after)) uprobe_detach(skel, idx); } @@ -847,7 +858,7 @@ static int consumer_test(struct uprobe_multi_consumers = *skel, printf("consumer_test before %lu after %lu\n", before, after); =20 /* 'before' is each, we attach uprobe for every set idx */ - for (idx =3D 0; idx < 1; idx++) { + for (idx =3D 0; idx < 4; idx++) { if (test_bit(idx, before)) { if (!ASSERT_OK(uprobe_attach(skel, idx), "uprobe_attach_before")) goto cleanup; @@ -858,11 +869,13 @@ static int consumer_test(struct uprobe_multi_consumer= s *skel, if (!ASSERT_EQ(err, 0, "uprobe_consumer_test")) goto cleanup; =20 - for (idx =3D 0; idx < 1; idx++) { + for (idx =3D 0; idx < 4; idx++) { + unsigned long had_uretprobes; const char *fmt =3D "BUG"; __u64 val =3D 0; =20 - if (idx =3D=3D 0) { + switch (idx) { + case 0: /* * uprobe entry * +1 if define in 'before' @@ -870,18 +883,42 @@ static int consumer_test(struct uprobe_multi_consumer= s *skel, if (test_bit(idx, before)) val++; fmt =3D "prog 0: uprobe"; - } else { + break; + case 1: /* * to trigger uretprobe consumer, the uretprobe needs to be installed, * which means one of the 'return' uprobes was alive when probe was hit: * - * idxs: 2/3 uprobe return in 'installed' mask + * idxs: 1/2 uprobe return in 'installed' mask */ - unsigned long had_uretprobes =3D before & 0b10; /* is uretprobe install= ed */ + had_uretprobes =3D before & 0b0110; /* is uretprobe installed */ =20 if (had_uretprobes && test_bit(idx, after)) val++; fmt =3D "prog 1: uretprobe"; + break; + case 2: + /* + * session with return + * +1 if defined in 'before' + * +1 if defined in 'after' + */ + if (test_bit(idx, before)) { + val++; + if (test_bit(idx, after)) + val++; + } + fmt =3D "prog 2 : session with return"; + break; + case 3: + /* + * session without return + * +1 if defined in 'before' + */ + if (test_bit(idx, before)) + val++; + fmt =3D "prog 3 : session with NO return"; + break; } =20 if (!ASSERT_EQ(skel->bss->uprobe_result[idx], val, fmt)) @@ -892,7 +929,7 @@ static int consumer_test(struct uprobe_multi_consumers = *skel, ret =3D 0; =20 cleanup: - for (idx =3D 0; idx < 1; idx++) + for (idx =3D 0; idx < 4; idx++) uprobe_detach(skel, idx); return ret; } @@ -912,9 +949,11 @@ static void test_consumers(void) * * - 1 uprobe entry consumer * - 1 uprobe exit consumer + * - 1 uprobe session with return + * - 1 uprobe session without return * - * The test uses 2 uprobes attached on single function, but that - * translates into single uprobe with 2 consumers in kernel. + * The test uses 4 uprobes attached on single function, but that + * translates into single uprobe with 4 consumers in kernel. * * The before/after values present the state of attached consumers * before and after the probed function: @@ -943,8 +982,8 @@ static void test_consumers(void) * before/after bits. */ =20 - for (before =3D 0; before < 4; before++) { - for (after =3D 0; after < 4; after++) + for (before =3D 0; before < 16; before++) { + for (after =3D 0; after < 16; after++) if (consumer_test(skel, before, after)) goto out; } diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_consumers.c b/t= ools/testing/selftests/bpf/progs/uprobe_multi_consumers.c index 1c64d7263911..93752bb5690b 100644 --- a/tools/testing/selftests/bpf/progs/uprobe_multi_consumers.c +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_consumers.c @@ -8,7 +8,7 @@ =20 char _license[] SEC("license") =3D "GPL"; =20 -__u64 uprobe_result[2]; +__u64 uprobe_result[4]; =20 SEC("uprobe.multi") int uprobe_0(struct pt_regs *ctx) @@ -23,3 +23,17 @@ int uprobe_1(struct pt_regs *ctx) uprobe_result[1]++; return 0; } + +SEC("uprobe.session") +int uprobe_2(struct pt_regs *ctx) +{ + uprobe_result[2]++; + return 0; +} + +SEC("uprobe.session") +int uprobe_3(struct pt_regs *ctx) +{ + uprobe_result[3]++; + return 1; +} --=20 2.46.2