From: "Ricardo B. Marlière" <rbm@suse.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
Alan Maguire <alan.maguire@oracle.com>,
"Ricardo B. Marliere" <rbm@suse.com>
Subject: [PATCH bpf-next v11 10/11] selftests/bpf: Provide weak definitions for cross-test functions
Date: Thu, 30 Apr 2026 13:02:11 -0300 [thread overview]
Message-ID: <20260430-selftests-bpf_misconfig-v11-10-e11f7a8c4fdc@suse.com> (raw)
In-Reply-To: <20260430-selftests-bpf_misconfig-v11-0-e11f7a8c4fdc@suse.com>
Some test files reference functions defined in other translation units that
may not be compiled when skeletons are missing. Replace forward
declarations of uprobe_multi_func_{1,2,3}() with weak no-op stubs so the
linker resolves them regardless of which objects are present.
The stub bodies are `asm volatile ("")` rather than empty, matching the
shape of the strong definitions in prog_tests/uprobe_multi_test.c. This
keeps the weak and strong sides on the same footing for the optimiser
(noinline + asm-barrier), which is the form upstream already relies on
for these functions.
Move stack_mprotect() from test_lsm.c into testing_helpers.c so it is
always available. The previous weak-stub approach returned 0, which would
cause callers expecting -1/EPERM to fail their assertions
deterministically. Having the real implementation in a shared utility
avoids this problem entirely.
Include <alloca.h> for alloca() so the build does not rely on glibc's
implicit declaration via <stdlib.h>.
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
.../testing/selftests/bpf/prog_tests/bpf_cookie.c | 17 +++++++++++------
tools/testing/selftests/bpf/prog_tests/iters.c | 2 --
tools/testing/selftests/bpf/prog_tests/test_lsm.c | 22 ----------------------
tools/testing/selftests/bpf/testing_helpers.c | 18 ++++++++++++++++++
tools/testing/selftests/bpf/testing_helpers.h | 1 +
5 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
index 35adc3f6d443..fa484d00a7a5 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -252,10 +252,17 @@ static void kprobe_multi_attach_api_subtest(void)
kprobe_multi__destroy(skel);
}
-/* defined in prog_tests/uprobe_multi_test.c */
-void uprobe_multi_func_1(void);
-void uprobe_multi_func_2(void);
-void uprobe_multi_func_3(void);
+/*
+ * Weak uprobe target stubs. noinline is required because
+ * uprobe_multi_test_run() takes their addresses to configure the BPF
+ * program's attachment points; an inlined function has no stable
+ * address in the binary to probe. The strong definitions in
+ * uprobe_multi_test.c take precedence when that translation unit is
+ * linked.
+ */
+noinline __weak void uprobe_multi_func_1(void) { asm volatile (""); }
+noinline __weak void uprobe_multi_func_2(void) { asm volatile (""); }
+noinline __weak void uprobe_multi_func_3(void) { asm volatile (""); }
static void uprobe_multi_test_run(struct uprobe_multi *skel)
{
@@ -574,8 +581,6 @@ static void tracing_subtest(struct test_bpf_cookie *skel)
close(fmod_ret_fd);
}
-int stack_mprotect(void);
-
static void lsm_subtest(struct test_bpf_cookie *skel)
{
__u64 cookie;
diff --git a/tools/testing/selftests/bpf/prog_tests/iters.c b/tools/testing/selftests/bpf/prog_tests/iters.c
index a539980a2fbe..c0b6082f345a 100644
--- a/tools/testing/selftests/bpf/prog_tests/iters.c
+++ b/tools/testing/selftests/bpf/prog_tests/iters.c
@@ -202,8 +202,6 @@ static void subtest_task_iters(void)
iters_task__destroy(skel);
}
-extern int stack_mprotect(void);
-
static void subtest_css_task_iters(void)
{
struct iters_css_task *skel = NULL;
diff --git a/tools/testing/selftests/bpf/prog_tests/test_lsm.c b/tools/testing/selftests/bpf/prog_tests/test_lsm.c
index bdc4fc06bc5a..d7495efd4a56 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_lsm.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_lsm.c
@@ -5,36 +5,14 @@
*/
#include <test_progs.h>
-#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
-#include <malloc.h>
-#include <stdlib.h>
#include "lsm.skel.h"
#include "lsm_tailcall.skel.h"
char *CMD_ARGS[] = {"true", NULL};
-#define GET_PAGE_ADDR(ADDR, PAGE_SIZE) \
- (char *)(((unsigned long) (ADDR + PAGE_SIZE)) & ~(PAGE_SIZE-1))
-
-int stack_mprotect(void)
-{
- void *buf;
- long sz;
- int ret;
-
- sz = sysconf(_SC_PAGESIZE);
- if (sz < 0)
- return sz;
-
- buf = alloca(sz * 3);
- ret = mprotect(GET_PAGE_ADDR(buf, sz), sz,
- PROT_READ | PROT_WRITE | PROT_EXEC);
- return ret;
-}
-
int exec_cmd(int *monitored_pid)
{
int child_pid, child_status;
diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c
index 6fbe1e995660..c970e7793dfc 100644
--- a/tools/testing/selftests/bpf/testing_helpers.c
+++ b/tools/testing/selftests/bpf/testing_helpers.c
@@ -5,6 +5,8 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <sys/mman.h>
+#include <alloca.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#include "disasm.h"
@@ -516,3 +518,19 @@ bool is_jit_enabled(void)
return enabled;
}
+
+int stack_mprotect(void)
+{
+ void *buf;
+ long sz;
+ int ret;
+
+ sz = sysconf(_SC_PAGESIZE);
+ if (sz < 0)
+ return sz;
+
+ buf = alloca(sz * 3);
+ ret = mprotect((void *)(((unsigned long)(buf + sz)) & ~(sz - 1)), sz,
+ PROT_READ | PROT_WRITE | PROT_EXEC);
+ return ret;
+}
diff --git a/tools/testing/selftests/bpf/testing_helpers.h b/tools/testing/selftests/bpf/testing_helpers.h
index 2ca2356a0b58..2edc6fb7fc52 100644
--- a/tools/testing/selftests/bpf/testing_helpers.h
+++ b/tools/testing/selftests/bpf/testing_helpers.h
@@ -59,5 +59,6 @@ struct bpf_insn;
int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt);
int testing_prog_flags(void);
bool is_jit_enabled(void);
+int stack_mprotect(void);
#endif /* __TESTING_HELPERS_H */
--
2.54.0
next prev parent reply other threads:[~2026-04-30 16:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 16:02 [PATCH bpf-next v11 00/11] selftests/bpf: Tolerate partial builds across kernel configs Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 01/11] selftests/bpf: Add BPF_STRICT_BUILD toggle Ricardo B. Marlière
2026-04-30 16:41 ` bot+bpf-ci
2026-05-04 14:05 ` Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 02/11] selftests/bpf: Fix test_kmods KDIR to honor O= and distro kernels Ricardo B. Marlière
2026-04-30 16:42 ` bot+bpf-ci
2026-05-04 14:05 ` Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 03/11] selftests/bpf: Tolerate BPF and skeleton generation failures Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 04/11] selftests/bpf: Avoid rebuilds when running emit_tests Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 05/11] selftests/bpf: Make skeleton headers order-only prerequisites of .test.d Ricardo B. Marlière
2026-04-30 16:41 ` bot+bpf-ci
2026-04-30 16:02 ` [PATCH bpf-next v11 06/11] selftests/bpf: Tolerate test file compilation failures Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 07/11] selftests/bpf: Skip tests whose objects were not built Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 08/11] selftests/bpf: Allow test_progs to link with a partial object set Ricardo B. Marlière
2026-04-30 16:02 ` [PATCH bpf-next v11 09/11] selftests/bpf: Tolerate benchmark build failures Ricardo B. Marlière
2026-04-30 16:02 ` Ricardo B. Marlière [this message]
2026-04-30 16:02 ` [PATCH bpf-next v11 11/11] selftests/bpf: Tolerate missing files during install Ricardo B. Marlière
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=20260430-selftests-bpf_misconfig-v11-10-e11f7a8c4fdc@suse.com \
--to=rbm@suse.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jolsa@kernel.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--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