Skip to contentSkip to conversation

selftests/bpf: livepatch_trampoline: skip when prerequisites are missing

PATCH Superseded Sun Jian 2 participants 3 messages Mar 5 – Mar 9

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sun Jian

author
#0 lore raw

PATCH v2 1/1 selftests/bpf: livepatch_trampoline: skip when prerequisites are missing

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.

---

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/[email protected]/

 .../bpf/prog_tests/livepatch_trampoline.c     | 28 ++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c +27 -1
index 72aa5376c30e..75336d9c2313 100644
@@ -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

Signature · 1 line
2.43.0
#1 lore raw
Quoted 66 lines · 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.

---

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/[email protected]/

 .../bpf/prog_tests/livepatch_trampoline.c     | 28 ++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c +19 -1
index 72aa5376c30e..75336d9c2313 100644
@@ -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),

tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c void test_livepatch_trampoline(void) · line 112

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c +8 -0
+			 "%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