linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/4] Subject: [PATCH bpf-next v2 0/4] Enable struct_ops programs to be sleepable
@ 2023-01-25  5:03 David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 1/4] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS " David Vernet
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: David Vernet @ 2023-01-25  5:03 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, linux-kernel, kernel-team, tj

This is part 3 of https://lore.kernel.org/bpf/20230123232228.646563-1-void@manifault.com/

Part 2: https://lore.kernel.org/all/20230124160802.1122124-1-void@manifault.com/

Changelog:
----------
v2 -> v3:
- Don't call a KF_SLEEPABLE kfunc from the dummy_st_ops testsuite, and
  remove the newly added bpf_kfunc_call_test_sleepable() test kfunc
  (Martin).
- Include vmlinux.h from progs/dummy_st_ops_success.c (previously
  progs/dummy_st_ops.c) rather than manually defining
  struct bpf_dummy_ops_state and struct bpf_dummy_ops.
  (Martin).
- Fix a typo added to prog_tests/dummy_st_ops.c in a previous version:
  s/trace_dummy_st_ops_success__open/trace_dummy_st_ops__open.

v1 -> v2:
- Add support for specifying sleepable struct_ops programs with
  struct_ops.s in libbpf (Alexei).
- Move failure test case into new dummy_st_ops_fail.c prog file.
- Update test_dummy_sleepable() to use struct_ops.s instead of manually
  setting prog flags. Also remove open_load_skel() helper which is no
  longer needed.
- Fix verifier tests to expect new sleepable prog failure message.


David Vernet (4):
  bpf: Allow BPF_PROG_TYPE_STRUCT_OPS programs to be sleepable
  libbpf: Support sleepable struct_ops.s section
  bpf: Pass const struct bpf_prog * to .check_member
  bpf/selftests: Verify struct_ops prog sleepable behavior

 include/linux/bpf.h                           |  4 +-
 kernel/bpf/verifier.c                         |  7 ++-
 net/bpf/bpf_dummy_struct_ops.c                | 18 ++++++
 net/ipv4/bpf_tcp_ca.c                         |  3 +-
 tools/lib/bpf/libbpf.c                        |  1 +
 .../selftests/bpf/prog_tests/dummy_st_ops.c   | 56 ++++++++++++++-----
 .../selftests/bpf/progs/dummy_st_ops_fail.c   | 27 +++++++++
 ...{dummy_st_ops.c => dummy_st_ops_success.c} | 19 +++----
 .../selftests/bpf/verifier/sleepable.c        |  2 +-
 9 files changed, 105 insertions(+), 32 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
 rename tools/testing/selftests/bpf/progs/{dummy_st_ops.c => dummy_st_ops_success.c} (72%)

-- 
2.39.0


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

* [PATCH bpf-next v3 1/4] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS programs to be sleepable
  2023-01-25  5:03 [PATCH bpf-next v3 0/4] Subject: [PATCH bpf-next v2 0/4] Enable struct_ops programs to be sleepable David Vernet
@ 2023-01-25  5:03 ` David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 2/4] libbpf: Support sleepable struct_ops.s section David Vernet
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: David Vernet @ 2023-01-25  5:03 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, linux-kernel, kernel-team, tj

BPF struct_ops programs currently cannot be marked as sleepable. This
need not be the case -- struct_ops programs can be sleepable, and e.g.
invoke kfuncs that export the KF_SLEEPABLE flag. So as to allow future
struct_ops programs to invoke such kfuncs, this patch updates the
verifier to allow struct_ops programs to be sleepable. A follow-on patch
will add support to libbpf for specifying struct_ops.s as a sleepable
struct_ops program, and then another patch will add testcases to the
dummy_st_ops selftest suite which test sleepable struct_ops behavior.

Signed-off-by: David Vernet <void@manifault.com>
---
 kernel/bpf/verifier.c                            | 5 +++--
 tools/testing/selftests/bpf/verifier/sleepable.c | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 800488289297..2b8f0c0aa0cc 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -17054,7 +17054,8 @@ static bool can_be_sleepable(struct bpf_prog *prog)
 		}
 	}
 	return prog->type == BPF_PROG_TYPE_LSM ||
-	       prog->type == BPF_PROG_TYPE_KPROBE; /* only for uprobes */
+	       prog->type == BPF_PROG_TYPE_KPROBE /* only for uprobes */ ||
+	       prog->type == BPF_PROG_TYPE_STRUCT_OPS;
 }
 
 static int check_attach_btf_id(struct bpf_verifier_env *env)
@@ -17076,7 +17077,7 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
 	}
 
 	if (prog->aux->sleepable && !can_be_sleepable(prog)) {
-		verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter and uprobe programs can be sleepable\n");
+		verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter, uprobe, and struct_ops programs can be sleepable\n");
 		return -EINVAL;
 	}
 
diff --git a/tools/testing/selftests/bpf/verifier/sleepable.c b/tools/testing/selftests/bpf/verifier/sleepable.c
index bea0daef908a..1f0d2bdc673f 100644
--- a/tools/testing/selftests/bpf/verifier/sleepable.c
+++ b/tools/testing/selftests/bpf/verifier/sleepable.c
@@ -85,7 +85,7 @@
 	.expected_attach_type = BPF_TRACE_RAW_TP,
 	.kfunc = "sched_switch",
 	.result = REJECT,
-	.errstr = "Only fentry/fexit/fmod_ret, lsm, iter and uprobe programs can be sleepable",
+	.errstr = "Only fentry/fexit/fmod_ret, lsm, iter, uprobe, and struct_ops programs can be sleepable",
 	.flags = BPF_F_SLEEPABLE,
 	.runs = -1,
 },
-- 
2.39.0


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

* [PATCH bpf-next v3 2/4] libbpf: Support sleepable struct_ops.s section
  2023-01-25  5:03 [PATCH bpf-next v3 0/4] Subject: [PATCH bpf-next v2 0/4] Enable struct_ops programs to be sleepable David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 1/4] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS " David Vernet
@ 2023-01-25  5:03 ` David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 3/4] bpf: Pass const struct bpf_prog * to .check_member David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior David Vernet
  3 siblings, 0 replies; 7+ messages in thread
From: David Vernet @ 2023-01-25  5:03 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, linux-kernel, kernel-team, tj

In a prior change, the verifier was updated to support sleepable
BPF_PROG_TYPE_STRUCT_OPS programs. A caller could set the program as
sleepable with bpf_program__set_flags(), but it would be more ergonomic
and more in-line with other sleepable program types if we supported
suffixing a struct_ops section name with .s to indicate that it's
sleepable.

Signed-off-by: David Vernet <void@manifault.com>
---
 tools/lib/bpf/libbpf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 27d9faa80471..eed5cec6f510 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8605,6 +8605,7 @@ static const struct bpf_sec_def section_defs[] = {
 	SEC_DEF("cgroup/setsockopt",	CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT, SEC_ATTACHABLE),
 	SEC_DEF("cgroup/dev",		CGROUP_DEVICE, BPF_CGROUP_DEVICE, SEC_ATTACHABLE_OPT),
 	SEC_DEF("struct_ops+",		STRUCT_OPS, 0, SEC_NONE),
+	SEC_DEF("struct_ops.s+",	STRUCT_OPS, 0, SEC_SLEEPABLE),
 	SEC_DEF("sk_lookup",		SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
 };
 
-- 
2.39.0


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

* [PATCH bpf-next v3 3/4] bpf: Pass const struct bpf_prog * to .check_member
  2023-01-25  5:03 [PATCH bpf-next v3 0/4] Subject: [PATCH bpf-next v2 0/4] Enable struct_ops programs to be sleepable David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 1/4] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS " David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 2/4] libbpf: Support sleepable struct_ops.s section David Vernet
@ 2023-01-25  5:03 ` David Vernet
  2023-01-25  5:03 ` [PATCH bpf-next v3 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior David Vernet
  3 siblings, 0 replies; 7+ messages in thread
From: David Vernet @ 2023-01-25  5:03 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, linux-kernel, kernel-team, tj

The .check_member field of struct bpf_struct_ops is currently passed the
member's btf_type via const struct btf_type *t, and a const struct
btf_member *member. This allows the struct_ops implementation to check
whether e.g. an ops is supported, but it would be useful to also enforce
that the struct_ops prog being loaded for that member has other
qualities, like being sleepable (or not). This patch therefore updates
the .check_member() callback to also take a const struct bpf_prog *prog
argument.

Signed-off-by: David Vernet <void@manifault.com>
---
 include/linux/bpf.h   | 3 ++-
 kernel/bpf/verifier.c | 2 +-
 net/ipv4/bpf_tcp_ca.c | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index ad4bb36d4c10..50123afab9bf 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1422,7 +1422,8 @@ struct bpf_struct_ops {
 	const struct bpf_verifier_ops *verifier_ops;
 	int (*init)(struct btf *btf);
 	int (*check_member)(const struct btf_type *t,
-			    const struct btf_member *member);
+			    const struct btf_member *member,
+			    const struct bpf_prog *prog);
 	int (*init_member)(const struct btf_type *t,
 			   const struct btf_member *member,
 			   void *kdata, const void *udata);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 2b8f0c0aa0cc..20dd03498e56 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -16732,7 +16732,7 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
 	}
 
 	if (st_ops->check_member) {
-		int err = st_ops->check_member(t, member);
+		int err = st_ops->check_member(t, member, prog);
 
 		if (err) {
 			verbose(env, "attach to unsupported member %s of struct %s\n",
diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c
index 4517d2bd186a..13fc0c185cd9 100644
--- a/net/ipv4/bpf_tcp_ca.c
+++ b/net/ipv4/bpf_tcp_ca.c
@@ -248,7 +248,8 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t,
 }
 
 static int bpf_tcp_ca_check_member(const struct btf_type *t,
-				   const struct btf_member *member)
+				   const struct btf_member *member,
+				   const struct bpf_prog *prog)
 {
 	if (is_unsupported(__btf_member_bit_offset(t, member) / 8))
 		return -ENOTSUPP;
-- 
2.39.0


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

* [PATCH bpf-next v3 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior
  2023-01-25  5:03 [PATCH bpf-next v3 0/4] Subject: [PATCH bpf-next v2 0/4] Enable struct_ops programs to be sleepable David Vernet
                   ` (2 preceding siblings ...)
  2023-01-25  5:03 ` [PATCH bpf-next v3 3/4] bpf: Pass const struct bpf_prog * to .check_member David Vernet
@ 2023-01-25  5:03 ` David Vernet
  2023-01-25 16:06   ` Alexei Starovoitov
  3 siblings, 1 reply; 7+ messages in thread
From: David Vernet @ 2023-01-25  5:03 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, linux-kernel, kernel-team, tj

In a set of prior changes, we added the ability for struct_ops programs
to be sleepable. This patch enhances the dummy_st_ops selftest suite to
validate this behavior by adding a new sleepable struct_ops entry to
dummy_st_ops.

Signed-off-by: David Vernet <void@manifault.com>
---
 include/linux/bpf.h                           |  1 +
 net/bpf/bpf_dummy_struct_ops.c                | 18 +++++++
 .../selftests/bpf/prog_tests/dummy_st_ops.c   | 54 ++++++++++++++-----
 .../selftests/bpf/progs/dummy_st_ops_fail.c   | 27 ++++++++++
 ...{dummy_st_ops.c => dummy_st_ops_success.c} | 19 +++----
 5 files changed, 94 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
 rename tools/testing/selftests/bpf/progs/{dummy_st_ops.c => dummy_st_ops_success.c} (72%)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 50123afab9bf..d92a6e0fde97 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1474,6 +1474,7 @@ struct bpf_dummy_ops {
 	int (*test_1)(struct bpf_dummy_ops_state *cb);
 	int (*test_2)(struct bpf_dummy_ops_state *cb, int a1, unsigned short a2,
 		      char a3, unsigned long a4);
+	int (*test_sleepable)(struct bpf_dummy_ops_state *cb);
 };
 
 int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr,
diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c
index 1ac4467928a9..ff4f89a2b02a 100644
--- a/net/bpf/bpf_dummy_struct_ops.c
+++ b/net/bpf/bpf_dummy_struct_ops.c
@@ -154,6 +154,23 @@ static bool bpf_dummy_ops_is_valid_access(int off, int size,
 	return bpf_tracing_btf_ctx_access(off, size, type, prog, info);
 }
 
+static int bpf_dummy_ops_check_member(const struct btf_type *t,
+				      const struct btf_member *member,
+				      const struct bpf_prog *prog)
+{
+	u32 moff = __btf_member_bit_offset(t, member) / 8;
+
+	switch (moff) {
+	case offsetof(struct bpf_dummy_ops, test_sleepable):
+		break;
+	default:
+		if (prog->aux->sleepable)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int bpf_dummy_ops_btf_struct_access(struct bpf_verifier_log *log,
 					   const struct bpf_reg_state *reg,
 					   int off, int size, enum bpf_access_type atype,
@@ -208,6 +225,7 @@ static void bpf_dummy_unreg(void *kdata)
 struct bpf_struct_ops bpf_bpf_dummy_ops = {
 	.verifier_ops = &bpf_dummy_verifier_ops,
 	.init = bpf_dummy_init,
+	.check_member = bpf_dummy_ops_check_member,
 	.init_member = bpf_dummy_init_member,
 	.reg = bpf_dummy_reg,
 	.unreg = bpf_dummy_unreg,
diff --git a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
index c11832657d2b..135514fad83a 100644
--- a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
+++ b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
@@ -1,7 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (C) 2021. Huawei Technologies Co., Ltd */
 #include <test_progs.h>
-#include "dummy_st_ops.skel.h"
+#include "dummy_st_ops_success.skel.h"
+#include "dummy_st_ops_fail.skel.h"
 #include "trace_dummy_st_ops.skel.h"
 
 /* Need to keep consistent with definition in include/linux/bpf.h */
@@ -11,17 +12,17 @@ struct bpf_dummy_ops_state {
 
 static void test_dummy_st_ops_attach(void)
 {
-	struct dummy_st_ops *skel;
+	struct dummy_st_ops_success *skel;
 	struct bpf_link *link;
 
-	skel = dummy_st_ops__open_and_load();
+	skel = dummy_st_ops_success__open_and_load();
 	if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load"))
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.dummy_1);
 	ASSERT_EQ(libbpf_get_error(link), -EOPNOTSUPP, "dummy_st_ops_attach");
 
-	dummy_st_ops__destroy(skel);
+	dummy_st_ops_success__destroy(skel);
 }
 
 static void test_dummy_init_ret_value(void)
@@ -31,10 +32,10 @@ static void test_dummy_init_ret_value(void)
 		.ctx_in = args,
 		.ctx_size_in = sizeof(args),
 	);
-	struct dummy_st_ops *skel;
+	struct dummy_st_ops_success *skel;
 	int fd, err;
 
-	skel = dummy_st_ops__open_and_load();
+	skel = dummy_st_ops_success__open_and_load();
 	if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load"))
 		return;
 
@@ -43,7 +44,7 @@ static void test_dummy_init_ret_value(void)
 	ASSERT_OK(err, "test_run");
 	ASSERT_EQ(attr.retval, 0xf2f3f4f5, "test_ret");
 
-	dummy_st_ops__destroy(skel);
+	dummy_st_ops_success__destroy(skel);
 }
 
 static void test_dummy_init_ptr_arg(void)
@@ -58,10 +59,10 @@ static void test_dummy_init_ptr_arg(void)
 		.ctx_size_in = sizeof(args),
 	);
 	struct trace_dummy_st_ops *trace_skel;
-	struct dummy_st_ops *skel;
+	struct dummy_st_ops_success *skel;
 	int fd, err;
 
-	skel = dummy_st_ops__open_and_load();
+	skel = dummy_st_ops_success__open_and_load();
 	if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load"))
 		return;
 
@@ -91,7 +92,7 @@ static void test_dummy_init_ptr_arg(void)
 	ASSERT_EQ(trace_skel->bss->val, exp_retval, "fentry_val");
 
 done:
-	dummy_st_ops__destroy(skel);
+	dummy_st_ops_success__destroy(skel);
 	trace_dummy_st_ops__destroy(trace_skel);
 }
 
@@ -102,12 +103,12 @@ static void test_dummy_multiple_args(void)
 		.ctx_in = args,
 		.ctx_size_in = sizeof(args),
 	);
-	struct dummy_st_ops *skel;
+	struct dummy_st_ops_success *skel;
 	int fd, err;
 	size_t i;
 	char name[8];
 
-	skel = dummy_st_ops__open_and_load();
+	skel = dummy_st_ops_success__open_and_load();
 	if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load"))
 		return;
 
@@ -119,10 +120,31 @@ static void test_dummy_multiple_args(void)
 		ASSERT_EQ(skel->bss->test_2_args[i], args[i], name);
 	}
 
-	dummy_st_ops__destroy(skel);
+	dummy_st_ops_success__destroy(skel);
 }
 
-void test_dummy_st_ops(void)
+static void test_dummy_sleepable(void)
+{
+	__u64 args[1] = {0};
+	LIBBPF_OPTS(bpf_test_run_opts, attr,
+		.ctx_in = args,
+		.ctx_size_in = sizeof(args),
+	);
+	struct dummy_st_ops_success *skel;
+	int fd, err;
+
+	skel = dummy_st_ops_success__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load"))
+		return;
+
+	fd = bpf_program__fd(skel->progs.test_sleepable);
+	err = bpf_prog_test_run_opts(fd, &attr);
+	ASSERT_OK(err, "test_run");
+
+	dummy_st_ops_success__destroy(skel);
+}
+
+void test_dummy_st_ops_success(void)
 {
 	if (test__start_subtest("dummy_st_ops_attach"))
 		test_dummy_st_ops_attach();
@@ -132,4 +154,8 @@ void test_dummy_st_ops(void)
 		test_dummy_init_ptr_arg();
 	if (test__start_subtest("dummy_multiple_args"))
 		test_dummy_multiple_args();
+	if (test__start_subtest("dummy_sleepable"))
+		test_dummy_sleepable();
+
+	RUN_TESTS(dummy_st_ops_fail);
 }
diff --git a/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c b/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
new file mode 100644
index 000000000000..0bf969a0b5ed
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";
+
+SEC("struct_ops.s/test_2")
+__failure __msg("attach to unsupported member test_2 of struct bpf_dummy_ops")
+int BPF_PROG(test_unsupported_field_sleepable,
+	     struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
+	     char a3, unsigned long a4)
+{
+	/* Tries to mark an unsleepable field in struct bpf_dummy_ops as sleepable. */
+	return 0;
+}
+
+SEC(".struct_ops")
+struct bpf_dummy_ops dummy_1 = {
+	.test_1 = NULL,
+	.test_2 = (void *)test_unsupported_field_sleepable,
+	.test_sleepable = (void *)NULL,
+};
diff --git a/tools/testing/selftests/bpf/progs/dummy_st_ops.c b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c
similarity index 72%
rename from tools/testing/selftests/bpf/progs/dummy_st_ops.c
rename to tools/testing/selftests/bpf/progs/dummy_st_ops_success.c
index ead87edb75e2..1efa746c25dc 100644
--- a/tools/testing/selftests/bpf/progs/dummy_st_ops.c
+++ b/tools/testing/selftests/bpf/progs/dummy_st_ops_success.c
@@ -1,19 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (C) 2021. Huawei Technologies Co., Ltd */
-#include <linux/bpf.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 
-struct bpf_dummy_ops_state {
-	int val;
-} __attribute__((preserve_access_index));
-
-struct bpf_dummy_ops {
-	int (*test_1)(struct bpf_dummy_ops_state *state);
-	int (*test_2)(struct bpf_dummy_ops_state *state, int a1, unsigned short a2,
-		      char a3, unsigned long a4);
-};
-
 char _license[] SEC("license") = "GPL";
 
 SEC("struct_ops/test_1")
@@ -43,8 +33,15 @@ int BPF_PROG(test_2, struct bpf_dummy_ops_state *state, int a1, unsigned short a
 	return 0;
 }
 
+SEC("struct_ops.s/test_sleepable")
+int BPF_PROG(test_sleepable, struct bpf_dummy_ops_state *state)
+{
+	return 0;
+}
+
 SEC(".struct_ops")
 struct bpf_dummy_ops dummy_1 = {
 	.test_1 = (void *)test_1,
 	.test_2 = (void *)test_2,
+	.test_sleepable = (void *)test_sleepable,
 };
-- 
2.39.0


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

* Re: [PATCH bpf-next v3 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior
  2023-01-25  5:03 ` [PATCH bpf-next v3 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior David Vernet
@ 2023-01-25 16:06   ` Alexei Starovoitov
  2023-01-25 16:33     ` David Vernet
  0 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2023-01-25 16:06 UTC (permalink / raw)
  To: David Vernet
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, LKML,
	Kernel Team, Tejun Heo

On Tue, Jan 24, 2023 at 9:04 PM David Vernet <void@manifault.com> wrote:
>
> In a set of prior changes, we added the ability for struct_ops programs
> to be sleepable. This patch enhances the dummy_st_ops selftest suite to
> validate this behavior by adding a new sleepable struct_ops entry to
> dummy_st_ops.
>
> Signed-off-by: David Vernet <void@manifault.com>
> ---
>  include/linux/bpf.h                           |  1 +
>  net/bpf/bpf_dummy_struct_ops.c                | 18 +++++++
>  .../selftests/bpf/prog_tests/dummy_st_ops.c   | 54 ++++++++++++++-----
>  .../selftests/bpf/progs/dummy_st_ops_fail.c   | 27 ++++++++++
>  ...{dummy_st_ops.c => dummy_st_ops_success.c} | 19 +++----
>  5 files changed, 94 insertions(+), 25 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
>  rename tools/testing/selftests/bpf/progs/{dummy_st_ops.c => dummy_st_ops_success.c} (72%)

It fails on s390:
dummy_st_ops_success/dummy_multiple_args:FAIL

Please add to DENYLIST as part of this patch.

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

* Re: [PATCH bpf-next v3 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior
  2023-01-25 16:06   ` Alexei Starovoitov
@ 2023-01-25 16:33     ` David Vernet
  0 siblings, 0 replies; 7+ messages in thread
From: David Vernet @ 2023-01-25 16:33 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, LKML,
	Kernel Team, Tejun Heo

On Wed, Jan 25, 2023 at 08:06:11AM -0800, Alexei Starovoitov wrote:
> On Tue, Jan 24, 2023 at 9:04 PM David Vernet <void@manifault.com> wrote:
> >
> > In a set of prior changes, we added the ability for struct_ops programs
> > to be sleepable. This patch enhances the dummy_st_ops selftest suite to
> > validate this behavior by adding a new sleepable struct_ops entry to
> > dummy_st_ops.
> >
> > Signed-off-by: David Vernet <void@manifault.com>
> > ---
> >  include/linux/bpf.h                           |  1 +
> >  net/bpf/bpf_dummy_struct_ops.c                | 18 +++++++
> >  .../selftests/bpf/prog_tests/dummy_st_ops.c   | 54 ++++++++++++++-----
> >  .../selftests/bpf/progs/dummy_st_ops_fail.c   | 27 ++++++++++
> >  ...{dummy_st_ops.c => dummy_st_ops_success.c} | 19 +++----
> >  5 files changed, 94 insertions(+), 25 deletions(-)
> >  create mode 100644 tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
> >  rename tools/testing/selftests/bpf/progs/{dummy_st_ops.c => dummy_st_ops_success.c} (72%)
> 
> It fails on s390:
> dummy_st_ops_success/dummy_multiple_args:FAIL
> 
> Please add to DENYLIST as part of this patch.

Sorry, this was just a dumb replace-all mistake on my part -- accidentally
changed the name of the testsuite to dummy_st_ops_success when changing the
name of the BPF prog in prog_tests/dummy_st_ops. It's already in the DENYLIST.
This should fix it:

diff --git a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
index 135514fad83a..f43fcb13d2c4 100644
--- a/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
+++ b/tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
@@ -144,7 +144,7 @@ static void test_dummy_sleepable(void)
        dummy_st_ops_success__destroy(skel);
 }

-void test_dummy_st_ops_success(void)
+void test_dummy_st_ops(void)
 {
        if (test__start_subtest("dummy_st_ops_attach"))
                test_dummy_st_ops_attach();


Will send out the v4 with that fix shortly.

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

end of thread, other threads:[~2023-01-25 16:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25  5:03 [PATCH bpf-next v3 0/4] Subject: [PATCH bpf-next v2 0/4] Enable struct_ops programs to be sleepable David Vernet
2023-01-25  5:03 ` [PATCH bpf-next v3 1/4] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS " David Vernet
2023-01-25  5:03 ` [PATCH bpf-next v3 2/4] libbpf: Support sleepable struct_ops.s section David Vernet
2023-01-25  5:03 ` [PATCH bpf-next v3 3/4] bpf: Pass const struct bpf_prog * to .check_member David Vernet
2023-01-25  5:03 ` [PATCH bpf-next v3 4/4] bpf/selftests: Verify struct_ops prog sleepable behavior David Vernet
2023-01-25 16:06   ` Alexei Starovoitov
2023-01-25 16:33     ` David Vernet

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).