All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Sun Jian <sun.jian.kdev@gmail.com>
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	andrii@kernel.org, shuah@kernel.org, ast@kernel.org,
	daniel@iogearbox.net, eddyz87@gmail.com, martin.lau@linux.dev
Subject: Re: [PATCH] selftests/bpf: modify_return: isolate fmod_ret hooks by pid
Date: Thu, 12 Mar 2026 13:24:42 +0100	[thread overview]
Message-ID: <abKwikMNfT0lhfl3@krava> (raw)
In-Reply-To: <20260312104219.1208802-1-sun.jian.kdev@gmail.com>

On Thu, Mar 12, 2026 at 06:42:19PM +0800, Sun Jian wrote:

SNIP

> diff --git a/tools/testing/selftests/bpf/progs/modify_return.c b/tools/testing/selftests/bpf/progs/modify_return.c
> index 3376d4849f58..5ff18ddb3050 100644
> --- a/tools/testing/selftests/bpf/progs/modify_return.c
> +++ b/tools/testing/selftests/bpf/progs/modify_return.c
> @@ -7,16 +7,29 @@
>  #include <linux/bpf.h>
>  #include <bpf/bpf_helpers.h>
>  #include <bpf/bpf_tracing.h>
> +#include <stdbool.h>
>  
>  char _license[] SEC("license") = "GPL";
>  
>  static int sequence = 0;
>  __s32 input_retval = 0;
> +__u32 test_pid = 0;
> +
> +static __always_inline bool match_pid(void)
> +{
> +	__u64 pid_tgid = bpf_get_current_pid_tgid();
> +
> +	if (!test_pid)
> +		return false;
> +	return (__u32)(pid_tgid >> 32) == test_pid;
> +}
>  
>  __u64 fentry_result = 0;
>  SEC("fentry/bpf_modify_return_test")
>  int BPF_PROG(fentry_test, int a, __u64 b)
>  {
> +	if (!match_pid())
> +		return 0;

I think just simple pid check like we do in other places
should be enough:

	if (bpf_get_current_pid_tgid() >> 32 != test_pid)
		return 0;

jirka


>  	sequence++;
>  	fentry_result = (sequence == 1);
>  	return 0;
> @@ -26,6 +39,8 @@ __u64 fmod_ret_result = 0;
>  SEC("fmod_ret/bpf_modify_return_test")
>  int BPF_PROG(fmod_ret_test, int a, int *b, int ret)
>  {
> +	if (!match_pid())
> +		return ret;
>  	sequence++;
>  	/* This is the first fmod_ret program, the ret passed should be 0 */
>  	fmod_ret_result = (sequence == 2 && ret == 0);
> @@ -36,6 +51,8 @@ __u64 fexit_result = 0;
>  SEC("fexit/bpf_modify_return_test")
>  int BPF_PROG(fexit_test, int a, __u64 b, int ret)
>  {
> +	if (!match_pid())
> +		return 0;
>  	sequence++;
>  	/* If the input_reval is non-zero a successful modification should have
>  	 * occurred.
> @@ -55,6 +72,8 @@ SEC("fentry/bpf_modify_return_test2")
>  int BPF_PROG(fentry_test2, int a, int *b, short c, int d, void *e, char f,
>  	     int g)
>  {
> +	if (!match_pid())
> +		return 0;
>  	sequence2++;
>  	fentry_result2 = (sequence2 == 1);
>  	return 0;
> @@ -65,6 +84,8 @@ SEC("fmod_ret/bpf_modify_return_test2")
>  int BPF_PROG(fmod_ret_test2, int a, int *b, short c, int d, void *e, char f,
>  	     int g, int ret)
>  {
> +	if (!match_pid())
> +		return ret;
>  	sequence2++;
>  	/* This is the first fmod_ret program, the ret passed should be 0 */
>  	fmod_ret_result2 = (sequence2 == 2 && ret == 0);
> @@ -76,6 +97,8 @@ SEC("fexit/bpf_modify_return_test2")
>  int BPF_PROG(fexit_test2, int a, int *b, short c, int d, void *e, char f,
>  	     int g, int ret)
>  {
> +	if (!match_pid())
> +		return 0;
>  	sequence2++;
>  	/* If the input_reval is non-zero a successful modification should have
>  	 * occurred.
> 
> base-commit: 80234b5ab240f52fa45d201e899e207b9265ef91
> -- 
> 2.43.0
> 
> 

  reply	other threads:[~2026-03-12 12:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 10:42 [PATCH] selftests/bpf: modify_return: isolate fmod_ret hooks by pid Sun Jian
2026-03-12 12:24 ` Jiri Olsa [this message]
2026-03-13  3:45 ` [PATCH v2] " Sun Jian
2026-03-19  0:44   ` patchwork-bot+netdevbpf

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=abKwikMNfT0lhfl3@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=shuah@kernel.org \
    --cc=sun.jian.kdev@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.