From patchwork Thu Jul 20 11:35:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 13320386 X-Patchwork-Delegate: bpf@iogearbox.net 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 886EC174E9 for ; Thu, 20 Jul 2023 11:40:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 329FAC433C8; Thu, 20 Jul 2023 11:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689853245; bh=DOXfV2v9IkE/pqUWX3FSB5m5gENMBhjCs5yGOVfBsYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1+kskgo2U8LR83aHLo69JPqRiZxnhnsZ1FfpgDDA/Bs71+j5HFGLYMyid3QjFeFt ZSIDV9ifi7Bi+iQecbztSyDi3nym2XPjMxpxmA9HcZ2NxY3RwU3vGL1jvY6kjP5alJ Ypsy1sCPj435O1xtuv3vX8Rdc1VQZv25GujTlt11PTpfakJTFaW0W8WqvV87dsJMyQ aa5z71y8PBDJkHZcxEVB1pxBAOgggiDm3CSxQLZyy6r7TlVwx7ffuT0GzFJ16k6fdG oUX1tqRFHi4zICmYQ49QbL6S9XHuiObF9Eit/W3Ac9qxt5Aj11Jjh2M8GwKV+CYOKl PhPBuKN6fkYsg== From: Jiri Olsa To: 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 Subject: [PATCHv4 bpf-next 28/28] selftests/bpf: Add extra link to uprobe_multi tests Date: Thu, 20 Jul 2023 13:35:50 +0200 Message-ID: <20230720113550.369257-29-jolsa@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720113550.369257-1-jolsa@kernel.org> References: <20230720113550.369257-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Attaching extra program to same functions system wide for api and link tests. This way we can test the pid filter works properly when there's extra system wide consumer on the same uprobe that will trigger the original uprobe handler. We expect to have the same counts as before. Signed-off-by: Jiri Olsa --- .../bpf/prog_tests/uprobe_multi_test.c | 17 +++++++++++++++++ .../testing/selftests/bpf/progs/uprobe_multi.c | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c index 3267a1a458a6..485e3c8c885f 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c @@ -183,6 +183,12 @@ __test_attach_api(const char *binary, const char *pattern, struct bpf_uprobe_mul if (!ASSERT_OK_PTR(skel->links.uretprobe_sleep, "bpf_program__attach_uprobe_multi")) goto cleanup; + opts->retprobe = false; + skel->links.uprobe_extra = bpf_program__attach_uprobe_multi(skel->progs.uprobe_extra, -1, + binary, pattern, opts); + if (!ASSERT_OK_PTR(skel->links.uprobe_extra, "bpf_program__attach_uprobe_multi")) + goto cleanup; + uprobe_multi_test_run(skel, child); cleanup: @@ -239,6 +245,7 @@ static void __test_link_api(struct child *child) "uprobe_multi_func_2", "uprobe_multi_func_3", }; + int link_extra_fd = -1; int err; err = elf_resolve_syms_offsets(path, 3, syms, (unsigned long **) &offsets); @@ -277,6 +284,14 @@ static void __test_link_api(struct child *child) link4_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts); if (!ASSERT_GE(link4_fd, 0, "link4_fd")) goto cleanup; + + opts.kprobe_multi.flags = 0; + opts.uprobe_multi.pid = 0; + prog_fd = bpf_program__fd(skel->progs.uprobe_extra); + link_extra_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts); + if (!ASSERT_GE(link_extra_fd, 0, "link_extra_fd")) + goto cleanup; + uprobe_multi_test_run(skel, child); cleanup: @@ -288,6 +303,8 @@ static void __test_link_api(struct child *child) close(link3_fd); if (link4_fd >= 0) close(link4_fd); + if (link_extra_fd >= 0) + close(link_extra_fd); uprobe_multi__destroy(skel); free(offsets); diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi.c b/tools/testing/selftests/bpf/progs/uprobe_multi.c index ec648a6699e6..419d9aa28fce 100644 --- a/tools/testing/selftests/bpf/progs/uprobe_multi.c +++ b/tools/testing/selftests/bpf/progs/uprobe_multi.c @@ -93,3 +93,9 @@ int uretprobe_sleep(struct pt_regs *ctx) uprobe_multi_check(ctx, true, true); return 0; } + +SEC("uprobe.multi//proc/self/exe:uprobe_multi_func_*") +int uprobe_extra(struct pt_regs *ctx) +{ + return 0; +}