bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@meta.com>
To: menglong8.dong@gmail.com, andrii.nakryiko@gmail.com,
	alan.maguire@oracle.com
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
	haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Menglong Dong <imagedong@tencent.com>
Subject: Re: [PATCH bpf-next v4 3/3] selftests/bpf: add testcase for FENTRY/FEXIT with 6+ arguments
Date: Fri, 9 Jun 2023 20:29:33 -0700	[thread overview]
Message-ID: <50d29ea7-09b8-9026-e127-8c21a4bb9706@meta.com> (raw)
In-Reply-To: <20230609095653.1406173-4-imagedong@tencent.com>



On 6/9/23 2:56 AM, menglong8.dong@gmail.com wrote:
> From: Menglong Dong <imagedong@tencent.com>
> 
> Add test9/test10 in fexit_test.c and fentry_test.c to test the fentry
> and fexit whose target function have 7/12 arguments.
> 
> Correspondingly, add bpf_testmod_fentry_test7() and
> bpf_testmod_fentry_test12() to bpf_testmod.c
> 
> And the testcases passed:
> 
> ./test_progs -t fexit
> Summary: 5/12 PASSED, 0 SKIPPED, 0 FAILED
> 
> ./test_progs -t fentry
> Summary: 3/0 PASSED, 0 SKIPPED, 0 FAILED
> 
> Signed-off-by: Menglong Dong <imagedong@tencent.com>
> ---
> v4:
> - use different type for args in bpf_testmod_fentry_test{7,12}
> - add testcase for grabage values in ctx
> v3:
> - move bpf_fentry_test{7,12} to bpf_testmod.c and rename them to
>    bpf_testmod_fentry_test{7,12} meanwhile
> - get return value by bpf_get_func_ret() in
>    "fexit/bpf_testmod_fentry_test12", as we don't change ___bpf_ctx_cast()
>    in this version
> ---
>   .../selftests/bpf/bpf_testmod/bpf_testmod.c   | 19 ++++++-
>   .../selftests/bpf/prog_tests/fentry_fexit.c   |  4 +-
>   .../selftests/bpf/prog_tests/fentry_test.c    |  2 +
>   .../selftests/bpf/prog_tests/fexit_test.c     |  2 +
>   .../testing/selftests/bpf/progs/fentry_test.c | 33 +++++++++++
>   .../testing/selftests/bpf/progs/fexit_test.c  | 57 +++++++++++++++++++
>   6 files changed, 115 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> index cf216041876c..66615fdbe3df 100644
> --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> @@ -191,6 +191,19 @@ noinline int bpf_testmod_fentry_test3(char a, int b, u64 c)
>   	return a + b + c;
>   }
>   
> +noinline int bpf_testmod_fentry_test7(u64 a, void *b, short c, int d,
> +				      void *e, u64 f, u64 g)
> +{
> +	return a + (long)b + c + d + (long)e + f + g;
> +}
> +
> +noinline int bpf_testmod_fentry_test12(u64 a, void *b, short c, int d,
> +				       void *e, u64 f, u64 g, u64 h,
> +				       u64 i, u64 j, u64 k, u64 l)
> +{
> +	return a + (long)b + c + d + (long)e + f + g + h + i + j + k + l;
> +}

It would be great to add a couple cases with struct arguments
where each struct has 8 < struct_size <= 16.
>   __diag_pop();
>   
>   int bpf_testmod_fentry_ok;
> @@ -245,7 +258,11 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
>   
>   	if (bpf_testmod_fentry_test1(1) != 2 ||
>   	    bpf_testmod_fentry_test2(2, 3) != 5 ||
> -	    bpf_testmod_fentry_test3(4, 5, 6) != 15)
> +	    bpf_testmod_fentry_test3(4, 5, 6) != 15 ||
> +	    bpf_testmod_fentry_test7(16, (void *)17, 18, 19, (void *)20,
> +				     21, 22) != 133 ||
> +	    bpf_testmod_fentry_test12(16, (void *)17, 18, 19, (void *)20,
> +				      21, 22, 23, 24, 25, 26, 27) != 258)
>   		goto out;
>   
>   	bpf_testmod_fentry_ok = 1;
[...]
> diff --git a/tools/testing/selftests/bpf/progs/fexit_test.c b/tools/testing/selftests/bpf/progs/fexit_test.c
> index 8f1ccb7302e1..a6d8e03ff5b7 100644
> --- a/tools/testing/selftests/bpf/progs/fexit_test.c
> +++ b/tools/testing/selftests/bpf/progs/fexit_test.c
> @@ -78,3 +78,60 @@ int BPF_PROG(test8, struct bpf_fentry_test_t *arg)
>   		test8_result = 1;
>   	return 0;
>   }
> +
> +__u64 test9_result = 0;
> +SEC("fexit/bpf_testmod_fentry_test7")
> +int BPF_PROG(test9, __u64 a, void *b, short c, int d, void *e, char f,
> +	     int g, int ret)
> +{
> +	test9_result = a == 16 && b == (void *)17 && c == 18 && d == 19 &&
> +		e == (void *)20 && f == 21 && g == 22 && ret == 133;
> +	return 0;
> +}
> +
> +__u64 test10_result = 0;
> +SEC("fexit/bpf_testmod_fentry_test12")
> +int BPF_PROG(test10, __u64 a, void *b, short c, int d, void *e, char f,
> +	     int g, unsigned int h, long i, __u64 j, unsigned long k,
> +	     unsigned char l)
> +{
> +	__u64 ret;
> +	int err;
> +
> +	/* BPF_PROG() don't support 14 arguments, and ctx[12] can't be
> +	 * accessed yet. So we get the return value by bpf_get_func_ret()
> +	 * for now.
> +	 */
> +	err = bpf_get_func_ret(ctx, &ret);

Maybe just have 11 arguments for this test case?

> +	if (err)
> +		return 0;
> +
> +	test10_result = a == 16 && b == (void *)17 && c == 18 && d == 19 &&
> +		e == (void *)20 && f == 21 && g == 22 && h == 23 &&
> +		i == 24 && j == 25 && k == 26 && l == 27 &&
> +		(int)ret == 258;
> +	return 0;
> +}
> +
> +__u64 test11_result = 0;
> +SEC("fexit/bpf_testmod_fentry_test12")
> +int BPF_PROG(test11, __u64 a, __u64 b, __u64 c, __u64 d, __u64 e, __u64 f,
> +	     __u64 g, __u64 h, __u64 i, __u64 j, __u64 k, __u64 l)
> +{
> +	__u64 ret;
> +	int err;
> +
> +	/* BPF_PROG() don't support 14 arguments, and ctx[12] can't be
> +	 * accessed yet. So we get the return value by bpf_get_func_ret()
> +	 * for now.
> +	 */
> +	err = bpf_get_func_ret(ctx, &ret);
> +	if (err)
> +		return 0;
> +
> +	test11_result = a == 16 && b == 17 && c == 18 && d == 19 &&
> +		e == 20 && f == 21 && g == 22 && h == 23 &&
> +		i == 24 && j == 25 && k == 26 && l == 27 &&
> +		ret == 258;
> +	return 0;
> +}

  reply	other threads:[~2023-06-10  3:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09  9:56 [PATCH bpf-next v4 0/3] bpf, x86: allow function arguments up to 12 for TRACING menglong8.dong
2023-06-09  9:56 ` [PATCH bpf-next v4 1/3] " menglong8.dong
2023-06-10  3:05   ` Yonghong Song
2023-06-10  6:59     ` Menglong Dong
2023-06-09  9:56 ` [PATCH bpf-next v4 2/3] bpf, x86: clean garbage value in the stack of trampoline menglong8.dong
2023-06-10  3:20   ` Yonghong Song
2023-06-10  6:33     ` Menglong Dong
2023-06-09  9:56 ` [PATCH bpf-next v4 3/3] selftests/bpf: add testcase for FENTRY/FEXIT with 6+ arguments menglong8.dong
2023-06-10  3:29   ` Yonghong Song [this message]
2023-06-10  7:01     ` Menglong Dong
2023-06-10  3:51 ` [PATCH bpf-next v4 0/3] bpf, x86: allow function arguments up to 12 for TRACING Yonghong Song
2023-06-10  6:59   ` Menglong Dong

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=50d29ea7-09b8-9026-e127-8c21a4bb9706@meta.com \
    --to=yhs@meta.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=imagedong@tencent.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=menglong8.dong@gmail.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).