[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211016124806.1547989-5-houtao1@huawei.com>
Date: Sat, 16 Oct 2021 20:48:05 +0800
From: Hou Tao <houtao1@...wei.com>
To: Alexei Starovoitov <ast@...nel.org>
CC: Martin KaFai Lau <kafai@...com>, Yonghong Song <yhs@...com>,
"Daniel Borkmann" <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, <netdev@...r.kernel.org>,
<bpf@...r.kernel.org>, <houtao1@...wei.com>
Subject: [PATCH bpf-next v2 4/5] bpf: hook .test_run for struct_ops program
bpf_struct_ops_test_run() will be used to run struct_ops program
from bpf_dummy_ops and now its main purpose is to test the handling
of return value and multiple arguments.
Signed-off-by: Hou Tao <houtao1@...wei.com>
---
kernel/bpf/bpf_struct_ops.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index 44be101f2562..ceedc9f0f786 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -11,6 +11,9 @@
#include <linux/refcount.h>
#include <linux/mutex.h>
+static int bpf_struct_ops_test_run(struct bpf_prog *prog,
+ const union bpf_attr *kattr,
+ union bpf_attr __user *uattr);
enum bpf_struct_ops_state {
BPF_STRUCT_OPS_STATE_INIT,
BPF_STRUCT_OPS_STATE_INUSE,
@@ -93,6 +96,7 @@ const struct bpf_verifier_ops bpf_struct_ops_verifier_ops = {
};
const struct bpf_prog_ops bpf_struct_ops_prog_ops = {
+ .test_run = bpf_struct_ops_test_run,
};
static const struct btf_type *module_type;
@@ -667,3 +671,16 @@ void bpf_struct_ops_put(const void *kdata)
call_rcu(&st_map->rcu, bpf_struct_ops_put_rcu);
}
}
+
+static int bpf_struct_ops_test_run(struct bpf_prog *prog,
+ const union bpf_attr *kattr,
+ union bpf_attr __user *uattr)
+{
+ const struct bpf_struct_ops *st_ops;
+
+ st_ops = bpf_struct_ops_find(prog->aux->attach_btf_id);
+ if (st_ops != &bpf_bpf_dummy_ops)
+ return -EOPNOTSUPP;
+
+ return bpf_dummy_struct_ops_test_run(prog, kattr, uattr);
+}
--
2.29.2
Powered by blists - more mailing lists