All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hou Tao <houtao1@huawei.com>
To: Martin KaFai Lau <kafai@fb.com>, Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, <netdev@vger.kernel.org>,
	<bpf@vger.kernel.org>, <houtao1@huawei.com>
Subject: [PATCH bpf-next 4/5] bpf: hook .test_run for struct_ops program
Date: Tue, 28 Sep 2021 10:52:27 +0800	[thread overview]
Message-ID: <20210928025228.88673-5-houtao1@huawei.com> (raw)
In-Reply-To: <20210928025228.88673-1-houtao1@huawei.com>

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.

Signed-off-by: Hou Tao <houtao1@huawei.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 ec3c25174923..3cedd2f489db 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;
@@ -666,3 +670,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_st_ops_test_run(prog, kattr, uattr);
+}
-- 
2.29.2


  parent reply	other threads:[~2021-09-28  2:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28  2:52 [PATCH bpf-next 0/5] introduce dummy BPF STRUCT_OPS Hou Tao
2021-09-28  2:52 ` [PATCH bpf-next 1/5] bpf: add dummy BPF STRUCT_OPS for test purpose Hou Tao
2021-09-28  2:52 ` [PATCH bpf-next 2/5] bpf: factor out a helper to prepare trampoline for struct_ops prog Hou Tao
2021-09-29 17:56   ` Martin KaFai Lau
2021-09-30 10:17     ` Hou Tao
2021-10-01 17:39       ` Martin KaFai Lau
2021-09-28  2:52 ` [PATCH bpf-next 3/5] bpf: do .test_run in dummy BPF STRUCT_OPS Hou Tao
2021-09-29 18:55   ` Martin KaFai Lau
2021-09-30 11:05     ` Hou Tao
2021-10-01 19:09       ` Martin KaFai Lau
2021-09-28  2:52 ` Hou Tao [this message]
2021-09-28  2:52 ` [PATCH bpf-next 5/5] selftests/bpf: test return value handling for struct_ops prog Hou Tao
2021-09-28 23:19   ` Andrii Nakryiko
2021-09-30 11:08     ` Hou Tao

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=20210928025228.88673-5-houtao1@huawei.com \
    --to=houtao1@huawei.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    /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.