public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
@ 2026-03-09 10:44 Sun Jian
  2026-03-09 11:46 ` Jiayuan Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sun Jian @ 2026-03-09 10:44 UTC (permalink / raw)
  To: bpf
  Cc: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Shuah Khan, Steven Rostedt, Jiayuan Chen, 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>
---
v4:
  - Drop redundant <errno.h> and <unistd.h> includes; both are already included by test_progs.h (per Jiayuan Chen)
  - Tested: ./test_progs -t livepatch_trampoline -vv (SKIP when livepatch-sample.ko missing)

v3:
  - Skip on -ENOENT from load_livepatch() instead of duplicating module path logic (suggested by Jiri Olsa)
  - Tested: ./test_progs -t livepatch_trampoline (SKIP when livepatch-sample.ko missing)

v2:
  - Skip when /sys/kernel/livepatch is missing
  - Guard sysfs write in unload_livepatch() when enabled knob is absent

v3: https://lore.kernel.org/bpf/20260309033712.728133-1-sun.jian.kdev@gmail.com/
v2: https://patchwork.kernel.org/project/netdevbpf/patch/20260305030258.5273-1-sun.jian.kdev@gmail.com/
v1: https://patchew.org/linux/20260227042354.20926-1-sun.jian.kdev@gmail.com/

 .../bpf/prog_tests/livepatch_trampoline.c     | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
index 72aa5376c30e..0a12af924a99 100644
--- a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
+++ b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
@@ -5,6 +5,8 @@
 #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 +21,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);
 }
@@ -81,9 +84,22 @@ static void __test_livepatch_trampoline(bool fexit_first)
 void test_livepatch_trampoline(void)
 {
 	int retry_cnt = 0;
+	int err;
+
+	/* Skip if kernel was built without CONFIG_LIVEPATCH */
+	if (access("/sys/kernel/livepatch", F_OK)) {
+		test__skip();
+		return;
+	}
 
 retry:
-	if (load_livepatch()) {
+	err = load_livepatch();
+	if (err) {
+		if (err == -ENOENT) {
+			test__skip();
+			return;
+		}
+
 		if (retry_cnt) {
 			ASSERT_OK(1, "load_livepatch");
 			goto out;

base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
  2026-03-09 10:44 [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing Sun Jian
@ 2026-03-09 11:46 ` Jiayuan Chen
  2026-03-09 13:36 ` Jiri Olsa
  2026-03-11 16:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jiayuan Chen @ 2026-03-09 11:46 UTC (permalink / raw)
  To: Sun Jian, bpf
  Cc: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Shuah Khan, Steven Rostedt, linux-kselftest, Sun Jian

March 9, 2026 at 18:44, "Sun Jian" <sun.jian.kdev@gmail.com mailto:sun.jian.kdev@gmail.com?to=%22Sun%20Jian%22%20%3Csun.jian.kdev%40gmail.com%3E > 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>
> ---
> v4:
>  - Drop redundant <errno.h> and <unistd.h> includes; both are already included by test_progs.h (per Jiayuan Chen)
>  - Tested: ./test_progs -t livepatch_trampoline -vv (SKIP when livepatch-sample.ko missing)
> 
> v3:
>  - Skip on -ENOENT from load_livepatch() instead of duplicating module path logic (suggested by Jiri Olsa)
>  - Tested: ./test_progs -t livepatch_trampoline (SKIP when livepatch-sample.ko missing)
> 
> v2:
>  - Skip when /sys/kernel/livepatch is missing
>  - Guard sysfs write in unload_livepatch() when enabled knob is absent
> 
> v3: https://lore.kernel.org/bpf/20260309033712.728133-1-sun.jian.kdev@gmail.com/
> v2: https://patchwork.kernel.org/project/netdevbpf/patch/20260305030258.5273-1-sun.jian.kdev@gmail.com/
> v1: https://patchew.org/linux/20260227042354.20926-1-sun.jian.kdev@gmail.com/
> 
>  .../bpf/prog_tests/livepatch_trampoline.c | 20 +++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> index 72aa5376c30e..0a12af924a99 100644
> --- a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> +++ b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> @@ -5,6 +5,8 @@
>  #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 +21,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);
>  }
> @@ -81,9 +84,22 @@ static void __test_livepatch_trampoline(bool fexit_first)
>  void test_livepatch_trampoline(void)
>  {
>  int retry_cnt = 0;
> + int err;
> +
> + /* Skip if kernel was built without CONFIG_LIVEPATCH */
> + if (access("/sys/kernel/livepatch", F_OK)) {
> + test__skip();
> + return;
> + }
>  


I think Jiri's suggestion in v2 means that you should drop the path check 
here and in unload_livepatch() and just keep checking -ENOENT.

-ENOENT returned by load_livepatch() means the ko doesn't exist,
which happens when either CONFIG_LIVEPATCH is disabled or livepatch_sample 
is not compiled.


>  retry:
> - if (load_livepatch()) {
> + err = load_livepatch();
> + if (err) {
> + if (err == -ENOENT) {
> + test__skip();
> + return;
> + }
> +

>  if (retry_cnt) {
>  ASSERT_OK(1, "load_livepatch");
>  goto out;
> 
> base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
> -- 
> 2.43.0
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
  2026-03-09 10:44 [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing Sun Jian
  2026-03-09 11:46 ` Jiayuan Chen
@ 2026-03-09 13:36 ` Jiri Olsa
  2026-03-11 16:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jiri Olsa @ 2026-03-09 13:36 UTC (permalink / raw)
  To: Sun Jian
  Cc: bpf, Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Shuah Khan,
	Steven Rostedt, Jiayuan Chen, linux-kselftest

On Mon, Mar 09, 2026 at 06:44:48PM +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>
> ---
> v4:
>   - Drop redundant <errno.h> and <unistd.h> includes; both are already included by test_progs.h (per Jiayuan Chen)
>   - Tested: ./test_progs -t livepatch_trampoline -vv (SKIP when livepatch-sample.ko missing)

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
> v3:
>   - Skip on -ENOENT from load_livepatch() instead of duplicating module path logic (suggested by Jiri Olsa)
>   - Tested: ./test_progs -t livepatch_trampoline (SKIP when livepatch-sample.ko missing)
> 
> v2:
>   - Skip when /sys/kernel/livepatch is missing
>   - Guard sysfs write in unload_livepatch() when enabled knob is absent
> 
> v3: https://lore.kernel.org/bpf/20260309033712.728133-1-sun.jian.kdev@gmail.com/
> v2: https://patchwork.kernel.org/project/netdevbpf/patch/20260305030258.5273-1-sun.jian.kdev@gmail.com/
> v1: https://patchew.org/linux/20260227042354.20926-1-sun.jian.kdev@gmail.com/
> 
>  .../bpf/prog_tests/livepatch_trampoline.c     | 20 +++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> index 72aa5376c30e..0a12af924a99 100644
> --- a/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> +++ b/tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c
> @@ -5,6 +5,8 @@
>  #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 +21,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);
>  }
> @@ -81,9 +84,22 @@ static void __test_livepatch_trampoline(bool fexit_first)
>  void test_livepatch_trampoline(void)
>  {
>  	int retry_cnt = 0;
> +	int err;
> +
> +	/* Skip if kernel was built without CONFIG_LIVEPATCH */
> +	if (access("/sys/kernel/livepatch", F_OK)) {
> +		test__skip();
> +		return;
> +	}
>  
>  retry:
> -	if (load_livepatch()) {
> +	err = load_livepatch();
> +	if (err) {
> +		if (err == -ENOENT) {
> +			test__skip();
> +			return;
> +		}
> +
>  		if (retry_cnt) {
>  			ASSERT_OK(1, "load_livepatch");
>  			goto out;
> 
> base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
  2026-03-09 10:44 [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing Sun Jian
  2026-03-09 11:46 ` Jiayuan Chen
  2026-03-09 13:36 ` Jiri Olsa
@ 2026-03-11 16:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-11 16:40 UTC (permalink / raw)
  To: sun jian
  Cc: bpf, andrii, eddyz87, ast, daniel, martin.lau, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah,
	rostedt, jiayuan.chen, linux-kselftest

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Mon,  9 Mar 2026 18:44:48 +0800 you 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.
> 
> [...]

Here is the summary with links:
  - [v4,bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
    https://git.kernel.org/bpf/bpf-next/c/c02e0ab8aeec

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-11 16:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 10:44 [PATCH v4 bpf-next] selftests/bpf: livepatch_trampoline: skip when prerequisites are missing Sun Jian
2026-03-09 11:46 ` Jiayuan Chen
2026-03-09 13:36 ` Jiri Olsa
2026-03-11 16:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox