From mboxrd@z Thu Jan 1 00:00:00 1970 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 3289D353EE3; Mon, 16 Mar 2026 07:55:39 +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=1773647739; cv=none; b=YtT6meVJybrPhkMY6V/N5vjQQHlioLpoAMAHRggvkVIt5cKrXDO+WcKsPkAh7HJhjVJmTHrFnMX6bfeusP3O74+NzbqVYLoyPgB/m9cdATQ8H0tCSdD+LlXpaGTO8VOlHKKM6zFiq8iCzKm9t3DGaxshFiPLEC7HI7r1TgFff+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773647739; c=relaxed/simple; bh=IrjCmBBF8WVTVC3+KnRqpse8p2Wy6jeeBlKmPPtfVa8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UMaCOGpgaldvhE7XdK8vrTefbtGqs8mt8N2YSB5eqchyijba+LpORnk5sXmYIF1p1LJwk0NqNp4TsVFX+a516IEDSxEU7iBdoh5TyLBOOlPrJvE+vRxjQ42p2vQ+QlFRG5YP0iXPj7ymN/c4+r0J7Yxy7Pu9adSCZ6WANZ8ks9I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X0Qc4xJL; 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="X0Qc4xJL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDBB5C19421; Mon, 16 Mar 2026 07:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773647739; bh=IrjCmBBF8WVTVC3+KnRqpse8p2Wy6jeeBlKmPPtfVa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X0Qc4xJLuIqoIq+MNouIQZPOU1l/RpKLvAlPI/mXcuonwujkAfTij8YJNyzARpFvj M7091OVWBliIltQp0DNkZ/ftFY3J34Zmc9a5+yvuFM5W1pwR92oRs6zCb2bm+h8S16 9mY5MV2XkJuYGuTRx84Mv78dJTZvRGnb2CFzr73C+TwqgPUVzM00BKibzTqE+Ih3wR QA7Yh8Xw+YlujOdMKAujKxyC/TODGTjWKSg3E1zOiVQfhBVv0va4dwb5kijWozSrgf TUI9lTykVcO4XDgsKdFjvFYvDVYbSlVmNZdSI5mkV5e561aJoHFClaEcrpe/b1FP9m Nzdp5QUykLKLw== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , Menglong Dong , Steven Rostedt Subject: [PATCHv3 bpf-next 22/24] selftests/bpf: Add tracing multi attach fails test Date: Mon, 16 Mar 2026 08:51:36 +0100 Message-ID: <20260316075138.465430-23-jolsa@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260316075138.465430-1-jolsa@kernel.org> References: <20260316075138.465430-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Adding tests for attach fails on tracing multi link. Signed-off-by: Jiri Olsa --- .../selftests/bpf/prog_tests/tracing_multi.c | 74 +++++++++++++++++++ .../selftests/bpf/progs/tracing_multi_fail.c | 19 +++++ 2 files changed, 93 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_fail.c diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c index 04d83c37495b..9f4c5af88e21 100644 --- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c +++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c @@ -8,6 +8,7 @@ #include "tracing_multi_module.skel.h" #include "tracing_multi_intersect.skel.h" #include "tracing_multi_session.skel.h" +#include "tracing_multi_fail.skel.h" #include "trace_helpers.h" static __u64 bpf_fentry_test_cookies[] = { @@ -480,6 +481,77 @@ static void test_session(void) tracing_multi_session__destroy(skel); } +static void test_attach_api_fails(void) +{ + LIBBPF_OPTS(bpf_tracing_multi_opts, opts); + static const char * const func[] = { + "bpf_fentry_test2", + }; + struct tracing_multi_fail *skel = NULL; + __u32 ids[2], *ids2; + __u64 cookies[2]; + + skel = tracing_multi_fail__open_and_load(); + if (!ASSERT_OK_PTR(skel, "tracing_multi_fail__open_and_load")) + return; + + /* fail#1 pattern and opts NULL */ + skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry, + NULL, NULL); + if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi")) + goto cleanup; + + /* fail#2 pattern and ids */ + opts.ids = ids; + opts.cnt = 2; + + skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry, + "bpf_fentry_test*", &opts); + if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi")) + goto cleanup; + + /* fail#3 pattern and cookies */ + opts.ids = NULL; + opts.cnt = 2; + opts.cookies = cookies; + + skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry, + "bpf_fentry_test*", &opts); + if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi")) + goto cleanup; + + /* fail#4 bogus pattern */ + skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry, + "bpf_not_really_a_function*", NULL); + if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi")) + goto cleanup; + + /* fail#5 abnormal cnt */ + opts.ids = ids; + opts.cnt = INT_MAX; + + skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry, + NULL, &opts); + if (!ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi")) + goto cleanup; + + /* fail#6 attach sleepable program to not-allowed function */ + ids2 = get_ids(func, 1, NULL); + if (!ASSERT_OK_PTR(ids, "get_ids")) + goto cleanup; + + opts.ids = ids2; + opts.cnt = 1; + + skel->links.test_fentry_s = bpf_program__attach_tracing_multi(skel->progs.test_fentry_s, + NULL, &opts); + ASSERT_ERR_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"); + free(ids2); + +cleanup: + tracing_multi_fail__destroy(skel); +} + void test_tracing_multi_test(void) { #ifndef __x86_64__ @@ -505,4 +577,6 @@ void test_tracing_multi_test(void) test_link_api_ids(true); if (test__start_subtest("session")) test_session(); + if (test__start_subtest("attach_api_fails")) + test_attach_api_fails(); } diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_fail.c b/tools/testing/selftests/bpf/progs/tracing_multi_fail.c new file mode 100644 index 000000000000..8f769ddb9136 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/tracing_multi_fail.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +char _license[] SEC("license") = "GPL"; + +SEC("fentry.multi") +int BPF_PROG(test_fentry) +{ + return 0; +} + +SEC("fentry.multi.s") +int BPF_PROG(test_fentry_s) +{ + return 0; +} -- 2.53.0