* [PATCH v2 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
@ 2026-03-05 3:02 Sun Jian
2026-03-05 9:01 ` Jiri Olsa
0 siblings, 1 reply; 3+ messages in thread
From: Sun Jian @ 2026-03-05 3:02 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Shuah Khan,
Steven Rostedt, Song Liu, Jiri Olsa, Martin KaFai Lau,
Eduard Zingerman, Yonghong Song, John Fastabend, KP Singh,
Stanislav Fomichev, Hao Luo, linux-kselftest, Sun Jian
livepatch_trampoline relies on livepatch sysfs and livepatch-sample.ko.
When CONFIG_LIVEPATCH is disabled or the samples module isn't built, the
test fails with ENOENT and causes false failures in minimal CI configs.
Skip the test when livepatch sysfs or the sample module is unavailable.
Also avoid writing to livepatch sysfs when it's not present.
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
v2:
- Add missing Cc's suggested by get_maintainer.pl
- Prefix subject with bpf-next to avoid Patchwork tree mis-detection
- Drop Fixes tag to avoid verify_fixes issues due to tree mismatch
- No code changes
v1: https://patchew.org/linux/20260227042354.20926-1-sun.jian.kdev@gmail.com/
.../bpf/prog_tests/livepatch_trampoline.c | 28 ++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
index 72aa5376c30e..75336d9c2313 100644
--- a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
+++ b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
@@ -2,9 +2,12 @@
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
+#include <unistd.h>
#include "testing_helpers.h"
#include "livepatch_trampoline.skel.h"
+#define LIVEPATCH_ENABLED_PATH "/sys/kernel/livepatch/livepatch_sample/enabled"
+
static int load_livepatch(void)
{
char path[4096];
@@ -19,7 +22,8 @@ static int load_livepatch(void)
static void unload_livepatch(void)
{
/* Disable the livepatch before unloading the module */
- system("echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled");
+ if (!access(LIVEPATCH_ENABLED_PATH, F_OK))
+ system("echo 0 > " LIVEPATCH_ENABLED_PATH);
unload_module("livepatch_sample", env_verbosity > VERBOSE_NONE);
}
@@ -82,6 +86,28 @@ void test_livepatch_trampoline(void)
{
int retry_cnt = 0;
+ /* Skip if kernel was built without CONFIG_LIVEPATCH */
+ if (access("/sys/kernel/livepatch", F_OK)) {
+ test__skip();
+ return;
+ }
+
+ /*
+ * Skip if livepatch-sample.ko was not built (same path logic as
+ * load_livepatch()).
+ */
+ {
+ char path[4096];
+
+ snprintf(path, sizeof(path),
+ "%s/samples/livepatch/livepatch-sample.ko",
+ getenv("KBUILD_OUTPUT") ? : "../../../..");
+ if (access(path, R_OK)) {
+ test__skip();
+ return;
+ }
+ }
+
retry:
if (load_livepatch()) {
if (retry_cnt) {
base-commit: 0b3bb205808195159be633a8cefb602670e856fb
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
2026-03-05 3:02 [PATCH v2 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing Sun Jian
@ 2026-03-05 9:01 ` Jiri Olsa
2026-03-09 3:50 ` sun jian
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2026-03-05 9:01 UTC (permalink / raw)
To: Sun Jian
Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Shuah Khan, Steven Rostedt, Song Liu, Martin KaFai Lau,
Eduard Zingerman, Yonghong Song, John Fastabend, KP Singh,
Stanislav Fomichev, Hao Luo, linux-kselftest
On Thu, Mar 05, 2026 at 11:02:58AM +0800, Sun Jian wrote:
> livepatch_trampoline relies on livepatch sysfs and livepatch-sample.ko.
> When CONFIG_LIVEPATCH is disabled or the samples module isn't built, the
> test fails with ENOENT and causes false failures in minimal CI configs.
>
> Skip the test when livepatch sysfs or the sample module is unavailable.
> Also avoid writing to livepatch sysfs when it's not present.
>
> Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
> ---
>
> v2:
> - Add missing Cc's suggested by get_maintainer.pl
> - Prefix subject with bpf-next to avoid Patchwork tree mis-detection
> - Drop Fixes tag to avoid verify_fixes issues due to tree mismatch
> - No code changes
>
> v1: https://patchew.org/linux/20260227042354.20926-1-sun.jian.kdev@gmail.com/
>
> .../bpf/prog_tests/livepatch_trampoline.c | 28 ++++++++++++++++++-
> 1 file changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> index 72aa5376c30e..75336d9c2313 100644
> --- a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> +++ b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> @@ -2,9 +2,12 @@
> /* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
>
> #include <test_progs.h>
> +#include <unistd.h>
> #include "testing_helpers.h"
> #include "livepatch_trampoline.skel.h"
>
> +#define LIVEPATCH_ENABLED_PATH "/sys/kernel/livepatch/livepatch_sample/enabled"
> +
> static int load_livepatch(void)
> {
> char path[4096];
> @@ -19,7 +22,8 @@ static int load_livepatch(void)
> static void unload_livepatch(void)
> {
> /* Disable the livepatch before unloading the module */
> - system("echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled");
> + if (!access(LIVEPATCH_ENABLED_PATH, F_OK))
> + system("echo 0 > " LIVEPATCH_ENABLED_PATH);
>
> unload_module("livepatch_sample", env_verbosity > VERBOSE_NONE);
> }
> @@ -82,6 +86,28 @@ void test_livepatch_trampoline(void)
> {
> int retry_cnt = 0;
>
> + /* Skip if kernel was built without CONFIG_LIVEPATCH */
> + if (access("/sys/kernel/livepatch", F_OK)) {
> + test__skip();
> + return;
> + }
> +
> + /*
> + * Skip if livepatch-sample.ko was not built (same path logic as
> + * load_livepatch()).
> + */
> + {
> + char path[4096];
> +
> + snprintf(path, sizeof(path),
> + "%s/samples/livepatch/livepatch-sample.ko",
> + getenv("KBUILD_OUTPUT") ? : "../../../..");
> + if (access(path, R_OK)) {
> + test__skip();
> + return;
> + }
> + }
> +
> retry:
> if (load_livepatch()) {
load_livepatch returns -ENOENT if we fail to open the file, we could
check for it instead of putting together the path again
jirka
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
2026-03-05 9:01 ` Jiri Olsa
@ 2026-03-09 3:50 ` sun jian
0 siblings, 0 replies; 3+ messages in thread
From: sun jian @ 2026-03-09 3:50 UTC (permalink / raw)
To: Jiri Olsa
Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Shuah Khan, Steven Rostedt, Song Liu, Martin KaFai Lau,
Eduard Zingerman, Yonghong Song, John Fastabend, KP Singh,
Stanislav Fomichev, Hao Luo, linux-kselftest
On Thu, Mar 5, 2026 at 5:02 PM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> load_livepatch returns -ENOENT if we fail to open the file, we could
> check for it instead of putting together the path again
>
Hi Jiri,
Thanks for the suggestion. v3 sent:
https://lore.kernel.org/bpf/20260309033712.728133-1-sun.jian.kdev@gmail.com/
Regards,
Sun Jian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-09 3:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 3:02 [PATCH v2 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing Sun Jian
2026-03-05 9:01 ` Jiri Olsa
2026-03-09 3:50 ` sun jian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox