Commit 5e9cf77d authored by Menglong Dong's avatar Menglong Dong Committed by Alexei Starovoitov
Browse files

selftests/bpf: add testcase for TRACING with 6+ arguments



Add fentry_many_args.c and fexit_many_args.c to test the fentry/fexit
with 7/11 arguments. As this feature is not supported by arm64 yet, we
disable these testcases for arm64 in DENYLIST.aarch64. We can combine
them with fentry_test.c/fexit_test.c when arm64 is supported too.

Correspondingly, add bpf_testmod_fentry_test7() and
bpf_testmod_fentry_test11() to bpf_testmod.c

Meanwhile, add bpf_modify_return_test2() to test_run.c to test the
MODIFY_RETURN with 7 arguments.

Add bpf_testmod_test_struct_arg_7/bpf_testmod_test_struct_arg_7 in
bpf_testmod.c to test the struct in the arguments.

And the testcases passed on x86_64:

./test_progs -t fexit
Summary: 5/14 PASSED, 0 SKIPPED, 0 FAILED

./test_progs -t fentry
Summary: 3/2 PASSED, 0 SKIPPED, 0 FAILED

./test_progs -t modify_return
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

./test_progs -t tracing_struct
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20230713040738.1789742-4-imagedong@tencent.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 473e3150
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -565,6 +565,13 @@ __bpf_kfunc int bpf_modify_return_test(int a, int *b)
	return a + *b;
}

__bpf_kfunc int bpf_modify_return_test2(int a, int *b, short c, int d,
					void *e, char f, int g)
{
	*b += 1;
	return a + *b + c + d + (long)e + f + g;
}

int noinline bpf_fentry_shadow_test(int a)
{
	return a + 1;
@@ -600,6 +607,7 @@ __diag_pop();

BTF_SET8_START(bpf_test_modify_return_ids)
BTF_ID_FLAGS(func, bpf_modify_return_test)
BTF_ID_FLAGS(func, bpf_modify_return_test2)
BTF_ID_FLAGS(func, bpf_fentry_test1, KF_SLEEPABLE)
BTF_SET8_END(bpf_test_modify_return_ids)

@@ -667,7 +675,11 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
	case BPF_MODIFY_RETURN:
		ret = bpf_modify_return_test(1, &b);
		if (b != 2)
			side_effect = 1;
			side_effect++;
		b = 2;
		ret += bpf_modify_return_test2(1, &b, 3, 4, (void *)5, 6, 7);
		if (b != 2)
			side_effect++;
		break;
	default:
		goto out;
+2 −0
Original line number Diff line number Diff line
@@ -10,3 +10,5 @@ kprobe_multi_test/link_api_addrs # link_fd unexpected link_fd: a
kprobe_multi_test/link_api_syms                  # link_fd unexpected link_fd: actual -95 < expected 0
kprobe_multi_test/skel_api                       # libbpf: failed to load BPF skeleton 'kprobe_multi': -3
module_attach                                    # prog 'kprobe_multi': failed to auto-attach: -95
fentry_test/fentry_many_args                     # fentry_many_args:FAIL:fentry_many_args_attach unexpected error: -524
fexit_test/fexit_many_args                       # fexit_many_args:FAIL:fexit_many_args_attach unexpected error: -524
+48 −1
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@ struct bpf_testmod_struct_arg_3 {
	int b[];
};

struct bpf_testmod_struct_arg_4 {
	u64 a;
	int b;
};

__diag_push();
__diag_ignore_all("-Wmissing-prototypes",
		  "Global functions as their definitions will be in bpf_testmod.ko BTF");
@@ -75,6 +80,24 @@ bpf_testmod_test_struct_arg_6(struct bpf_testmod_struct_arg_3 *a) {
	return bpf_testmod_test_struct_arg_result;
}

noinline int
bpf_testmod_test_struct_arg_7(u64 a, void *b, short c, int d, void *e,
			      struct bpf_testmod_struct_arg_4 f)
{
	bpf_testmod_test_struct_arg_result = a + (long)b + c + d +
		(long)e + f.a + f.b;
	return bpf_testmod_test_struct_arg_result;
}

noinline int
bpf_testmod_test_struct_arg_8(u64 a, void *b, short c, int d, void *e,
			      struct bpf_testmod_struct_arg_4 f, int g)
{
	bpf_testmod_test_struct_arg_result = a + (long)b + c + d +
		(long)e + f.a + f.b + g;
	return bpf_testmod_test_struct_arg_result;
}

__bpf_kfunc void
bpf_testmod_test_mod_kfunc(int i)
{
@@ -191,6 +214,20 @@ 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, char f, int g)
{
	return a + (long)b + c + d + (long)e + f + g;
}

noinline int bpf_testmod_fentry_test11(u64 a, void *b, short c, int d,
				       void *e, char f, int g,
				       unsigned int h, long i, __u64 j,
				       unsigned long k)
{
	return a + (long)b + c + d + (long)e + f + g + h + i + j + k;
}

int bpf_testmod_fentry_ok;

noinline ssize_t
@@ -206,6 +243,7 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
	struct bpf_testmod_struct_arg_1 struct_arg1 = {10};
	struct bpf_testmod_struct_arg_2 struct_arg2 = {2, 3};
	struct bpf_testmod_struct_arg_3 *struct_arg3;
	struct bpf_testmod_struct_arg_4 struct_arg4 = {21, 22};
	int i = 1;

	while (bpf_testmod_return_ptr(i))
@@ -216,6 +254,11 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
	(void)bpf_testmod_test_struct_arg_3(1, 4, struct_arg2);
	(void)bpf_testmod_test_struct_arg_4(struct_arg1, 1, 2, 3, struct_arg2);
	(void)bpf_testmod_test_struct_arg_5();
	(void)bpf_testmod_test_struct_arg_7(16, (void *)17, 18, 19,
					    (void *)20, struct_arg4);
	(void)bpf_testmod_test_struct_arg_8(16, (void *)17, 18, 19,
					    (void *)20, struct_arg4, 23);


	struct_arg3 = kmalloc((sizeof(struct bpf_testmod_struct_arg_3) +
				sizeof(int)), GFP_KERNEL);
@@ -243,7 +286,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_test11(16, (void *)17, 18, 19, (void *)20,
			21, 22, 23, 24, 25, 26) != 231)
		goto out;

	bpf_testmod_fentry_ok = 1;
+39 −4
Original line number Diff line number Diff line
@@ -2,8 +2,9 @@
/* Copyright (c) 2019 Facebook */
#include <test_progs.h>
#include "fentry_test.lskel.h"
#include "fentry_many_args.skel.h"

static int fentry_test(struct fentry_test_lskel *fentry_skel)
static int fentry_test_common(struct fentry_test_lskel *fentry_skel)
{
	int err, prog_fd, i;
	int link_fd;
@@ -37,7 +38,7 @@ static int fentry_test(struct fentry_test_lskel *fentry_skel)
	return 0;
}

void test_fentry_test(void)
static void fentry_test(void)
{
	struct fentry_test_lskel *fentry_skel = NULL;
	int err;
@@ -46,13 +47,47 @@ void test_fentry_test(void)
	if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"))
		goto cleanup;

	err = fentry_test(fentry_skel);
	err = fentry_test_common(fentry_skel);
	if (!ASSERT_OK(err, "fentry_first_attach"))
		goto cleanup;

	err = fentry_test(fentry_skel);
	err = fentry_test_common(fentry_skel);
	ASSERT_OK(err, "fentry_second_attach");

cleanup:
	fentry_test_lskel__destroy(fentry_skel);
}

static void fentry_many_args(void)
{
	struct fentry_many_args *fentry_skel = NULL;
	int err;

	fentry_skel = fentry_many_args__open_and_load();
	if (!ASSERT_OK_PTR(fentry_skel, "fentry_many_args_skel_load"))
		goto cleanup;

	err = fentry_many_args__attach(fentry_skel);
	if (!ASSERT_OK(err, "fentry_many_args_attach"))
		goto cleanup;

	ASSERT_OK(trigger_module_test_read(1), "trigger_read");

	ASSERT_EQ(fentry_skel->bss->test1_result, 1,
		  "fentry_many_args_result1");
	ASSERT_EQ(fentry_skel->bss->test2_result, 1,
		  "fentry_many_args_result2");
	ASSERT_EQ(fentry_skel->bss->test3_result, 1,
		  "fentry_many_args_result3");

cleanup:
	fentry_many_args__destroy(fentry_skel);
}

void test_fentry_test(void)
{
	if (test__start_subtest("fentry"))
		fentry_test();
	if (test__start_subtest("fentry_many_args"))
		fentry_many_args();
}
+39 −4
Original line number Diff line number Diff line
@@ -2,8 +2,9 @@
/* Copyright (c) 2019 Facebook */
#include <test_progs.h>
#include "fexit_test.lskel.h"
#include "fexit_many_args.skel.h"

static int fexit_test(struct fexit_test_lskel *fexit_skel)
static int fexit_test_common(struct fexit_test_lskel *fexit_skel)
{
	int err, prog_fd, i;
	int link_fd;
@@ -37,7 +38,7 @@ static int fexit_test(struct fexit_test_lskel *fexit_skel)
	return 0;
}

void test_fexit_test(void)
static void fexit_test(void)
{
	struct fexit_test_lskel *fexit_skel = NULL;
	int err;
@@ -46,13 +47,47 @@ void test_fexit_test(void)
	if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load"))
		goto cleanup;

	err = fexit_test(fexit_skel);
	err = fexit_test_common(fexit_skel);
	if (!ASSERT_OK(err, "fexit_first_attach"))
		goto cleanup;

	err = fexit_test(fexit_skel);
	err = fexit_test_common(fexit_skel);
	ASSERT_OK(err, "fexit_second_attach");

cleanup:
	fexit_test_lskel__destroy(fexit_skel);
}

static void fexit_many_args(void)
{
	struct fexit_many_args *fexit_skel = NULL;
	int err;

	fexit_skel = fexit_many_args__open_and_load();
	if (!ASSERT_OK_PTR(fexit_skel, "fexit_many_args_skel_load"))
		goto cleanup;

	err = fexit_many_args__attach(fexit_skel);
	if (!ASSERT_OK(err, "fexit_many_args_attach"))
		goto cleanup;

	ASSERT_OK(trigger_module_test_read(1), "trigger_read");

	ASSERT_EQ(fexit_skel->bss->test1_result, 1,
		  "fexit_many_args_result1");
	ASSERT_EQ(fexit_skel->bss->test2_result, 1,
		  "fexit_many_args_result2");
	ASSERT_EQ(fexit_skel->bss->test3_result, 1,
		  "fexit_many_args_result3");

cleanup:
	fexit_many_args__destroy(fexit_skel);
}

void test_fexit_test(void)
{
	if (test__start_subtest("fexit"))
		fexit_test();
	if (test__start_subtest("fexit_many_args"))
		fexit_many_args();
}
Loading