From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C30A47799B for ; Thu, 30 Apr 2026 16:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777564974; cv=none; b=JjmLmw2ZXfPiC+qHPuK4aG/xY8VbaUsbMJd7gF+6RdqVtURty9PNegjBMMRl+EIjt7Wl+IH8zEuWyXjxgVb22dPRlfqfTxXQ751imdwLRBTaX7JkcYZ6mYtzXgrbvkbGLKKigNd6XaTCwrJQKzdEMqFbpm/oCoYiytCn4nOKSSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777564974; c=relaxed/simple; bh=PEQ/hH8f9EfEO3m9jfnl1sYEE2Fvx6y97vzN398bHFI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C8/5XkHk+MRQ2W4X0SOiN+DpA+Ha1urGJlUIi5Zo0h/RMlHkiiJdbAwI52pd92rt80efCEvuH3JTll9md2hwFt2m4DEc9/tslKxAmQkIl/9Q6g/lxt41ljahywJfPYfNaCX0gBrW/28POdCVHVfVz6ssjDZsgdqvg+CqKD9468w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=X+qkJI6Q; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="X+qkJI6Q" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-38e12c67a6fso12236011fa.1 for ; Thu, 30 Apr 2026 09:02:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1777564969; x=1778169769; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=da/3P3gWrWPT2pVZ+wpt21mcmTeD9JLfhBM9QpqBcIo=; b=X+qkJI6QaHKcI1BgFcwcOAaz9Bqoz+B2o458ZSCefTkB6DC3ENx+A9Bllj/XpAWfv9 o691rg6qe9nDR3JhdF4AH70hDdLvsHZ+seSd3yl2YIoJxyBR3IQ1J6hEprX16Mkwttvy uU5xOP85nQTMcp83ZSoK/Vl6i3ZiCa/imjoP5noc2a+nR6wK0E/rTSfWG7/6F905UKd0 Mo3esLJDML8hAnIHiyyQZlne4OjK0TZxIkmvAqv8sfqS521BzKq2liT83UAYGZ/me9gZ 7T/0z/C61sbCKhJHPrgLshiAvwM1RqzpMpfvhVjYo+omL0h5mWbw7FTBOX2cTkj/knF1 le3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777564970; x=1778169770; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=da/3P3gWrWPT2pVZ+wpt21mcmTeD9JLfhBM9QpqBcIo=; b=tJVRgSAD6N4znUifHibcDU3DVd/799gNd3igGsYNXSVhG2bJrwq1b02Rw+b3dKvtW3 C9FADFNC4MW4+q8W5bru2MSLJFcQyGF8QvAK193A30MKi33vUniEXJpIUlg6EfoWRFRl TynVgDMSrUG3U+nJZ/sqVSqQROFSFjP1/VUttqDUi7owGEkGfZKRBQxTNwLkozEQhQ8U WB4jyIC/XWWJzKs1uKsAj0o3hGyKopnkxlWTmVx4dsXf9nkkcnrMfEBD2AUWQMETsY+7 h3JHp5pTlFPvnnKpA4Wa7+haeKAQeYHSWtPeLL1etpX/Q/oflO8RTmponH3pS+OCEbOK foLQ== X-Forwarded-Encrypted: i=1; AFNElJ/xRUrBn29H9YfmAUUnK8CGAU+LIADdBDj7mUVo6pwZdFClA1eTDmoN2l+oRwb1qO7FpVMZrbB29/VH2EE=@vger.kernel.org X-Gm-Message-State: AOJu0YyxQ5X0kUBqwUSKVCJ7Dapp46pRXvn3Nnh/a0KHbsoTkbkXHUK6 wlvfoeCaae4LdzjHmtL1U5iRwB3qFn9tRUL55gy2nO3c1sma31dtqOro6TyVgAC68g8= X-Gm-Gg: AeBDiesdDbBi14hP5v1X/326VdhauTEZYwFLhHcSj3yojCG3yaDeJKvU5oateINwJ9W jE+ssUuL0iQddc+0BoYcVwJzX1dw/iB8vfweYoNUr9zMk4EtOcEBSbB0hYOQ6IPNeoOhmLssnEx tcIXiZBZfMufdfTCr2jsA+sSAKRBIWQnJzTwoJDNxXGPLOdbYgFq1XQqrV9BXTEpMs4u5olxhmV JBUOyy1CDwWHAYXwGVsJMfgvDJ6Wfz/ClWTEifoENt3AU2B5IcJuYxtsVeGA3PuzuTtBJ76ydRR yg1d97BTWB2GMXCTeEmTXRM5zUp4FMIz0A3egJHEppHwg4o9aUs5aarJVUadioKz8I0z6ZcU3Q1 Pteqsafq9b/P60N2vURD/vSUwMbjFlsAQNoBw66bQIQq2XJV7+tw36JE4V8rEGGAp6fwnun+Qpx rb5/jsXPEUd70dpV7XTbc9uRtm X-Received: by 2002:a05:6512:3c85:b0:5a4:a85:ba43 with SMTP id 2adb3069b0e04-5a8522d80ccmr1131964e87.33.1777564969409; Thu, 30 Apr 2026 09:02:49 -0700 (PDT) Received: from localhost ([2804:7f0:b765:105d:ce28:aaff:fe86:149c]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ee3b783a95sm351904eec.22.2026.04.30.09.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 09:02:48 -0700 (PDT) From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Date: Thu, 30 Apr 2026 13:02:11 -0300 Subject: [PATCH bpf-next v11 10/11] selftests/bpf: Provide weak definitions for cross-test functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260430-selftests-bpf_misconfig-v11-10-e11f7a8c4fdc@suse.com> References: <20260430-selftests-bpf_misconfig-v11-0-e11f7a8c4fdc@suse.com> In-Reply-To: <20260430-selftests-bpf_misconfig-v11-0-e11f7a8c4fdc@suse.com> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Alan Maguire , "Ricardo B. Marliere" X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1777564926; l=5710; i=rbm@suse.com; h=from:subject:message-id; bh=PEQ/hH8f9EfEO3m9jfnl1sYEE2Fvx6y97vzN398bHFI=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgguRCc5X8/UX9M40lkMnr//aFGOhce x5ezt8MFNUFlqYAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QARd9MqO5u0wPoP+w/Wba+9N2KtAGMi1fCK+PM8eJuubbNpb8RtUIs+C+HRfnluzsj3dbuwbtnY D0RxNqGIy2AU= X-Developer-Key: i=rbm@suse.com; a=openssh; fpr=SHA256:pzhe0fJpYLz+3cZ33FFPhIfaUElk9CXPFFXmalIH+1g 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 for alloca() so the build does not rely on glibc's implicit declaration via . Signed-off-by: Ricardo B. Marlière --- .../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 -#include #include #include -#include -#include #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 #include #include +#include +#include #include #include #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