All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hou Tao <houtao@huaweicloud.com>
To: bpf@vger.kernel.org
Cc: Martin KaFai Lau <kafai@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Song Liu <songliubraving@fb.com>, Hao Luo <haoluo@google.com>,
	Yonghong Song <yhs@fb.com>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	KP Singh <kpsingh@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Jiri Olsa <jolsa@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	houtao1@huawei.com
Subject: [PATCH bpf-next v2 02/13] bpf: Add helper btf_find_dynptr()
Date: Sat, 24 Sep 2022 21:36:09 +0800	[thread overview]
Message-ID: <20220924133620.4147153-3-houtao@huaweicloud.com> (raw)
In-Reply-To: <20220924133620.4147153-1-houtao@huaweicloud.com>

From: Hou Tao <houtao1@huawei.com>

Add helper btf_find_dynptr() to check whether or not the passed btf type
is bpf_dynptr. It can be extend to find an embedded dynptr in passed btf
type if needed later.

It will be used by bpf map (e.g. qp-trie) with bpf_dynptr key.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 include/linux/btf.h |  1 +
 kernel/bpf/btf.c    | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/linux/btf.h b/include/linux/btf.h
index f9aababc5d78..5bf508c2bad2 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -165,6 +165,7 @@ int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t);
 int btf_find_timer(const struct btf *btf, const struct btf_type *t);
 struct bpf_map_value_off *btf_parse_kptrs(const struct btf *btf,
 					  const struct btf_type *t);
+int btf_find_dynptr(const struct btf *btf, const struct btf_type *t);
 bool btf_type_is_void(const struct btf_type *t);
 s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind);
 const struct btf_type *btf_type_skip_modifiers(const struct btf *btf,
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index a44ad4b347ff..fefbe84c6998 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -3522,6 +3522,19 @@ struct bpf_map_value_off *btf_parse_kptrs(const struct btf *btf,
 	return ERR_PTR(ret);
 }
 
+/* Now only allow to use 'struct bpf_dynptr' as map key.
+ * Map key with embedded bpf_dynptr is not allowed.
+ */
+int btf_find_dynptr(const struct btf *btf, const struct btf_type *t)
+{
+	/* Only allow struct type */
+	if (__btf_type_is_struct(t) && t->size == sizeof(struct bpf_dynptr) &&
+	    !strcmp("bpf_dynptr", __btf_name_by_offset(btf, t->name_off)))
+		return 0;
+
+	return -EINVAL;
+}
+
 static void __btf_struct_show(const struct btf *btf, const struct btf_type *t,
 			      u32 type_id, void *data, u8 bits_offset,
 			      struct btf_show *show)
-- 
2.29.2


  parent reply	other threads:[~2022-09-24 13:18 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-24 13:36 [PATCH bpf-next v2 00/13] Add support for qp-trie with dynptr key Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 01/13] bpf: Export bpf_dynptr_set_size() Hou Tao
2022-09-24 13:36 ` Hou Tao [this message]
2022-09-24 13:36 ` [PATCH bpf-next v2 03/13] bpf: Support bpf_dynptr-typed map key in bpf syscall Hou Tao
2022-09-29  0:16   ` Andrii Nakryiko
2022-09-29  2:11     ` Hou Tao
2022-09-30 21:35       ` Andrii Nakryiko
2022-10-08  2:40         ` Hou Tao
2022-10-13 18:04           ` Andrii Nakryiko
2022-10-14  4:02             ` Hou Tao
2022-10-18 22:50               ` Andrii Nakryiko
2022-09-24 13:36 ` [PATCH bpf-next v2 04/13] bpf: Support bpf_dynptr-typed map key in verifier Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 05/13] libbpf: Add helpers for bpf_dynptr_user Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 06/13] bpf: Add support for qp-trie map with dynptr key Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 07/13] libbpf: Add probe support for BPF_MAP_TYPE_QP_TRIE Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 08/13] bpftool: Add support for qp-trie map Hou Tao
2022-09-27 11:24   ` Quentin Monnet
2022-09-28  4:14     ` Hou Tao
2022-09-28  8:40       ` Quentin Monnet
2022-09-28  9:05         ` Hou Tao
2022-09-28  9:23           ` Quentin Monnet
2022-09-28 10:54             ` Hou Tao
2022-09-28 11:49               ` Quentin Monnet
2022-09-24 13:36 ` [PATCH bpf-next v2 09/13] selftests/bpf: Add two new dynptr_fail cases for map key Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 10/13] selftests/bpf: Move ENOTSUPP into bpf_util.h Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 11/13] selftests/bpf: Add prog tests for qp-trie map Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 12/13] selftests/bpf: Add benchmark " Hou Tao
2022-09-24 13:36 ` [PATCH bpf-next v2 13/13] selftests/bpf: Add map tests for qp-trie by using bpf syscall Hou Tao
2022-09-26  1:25 ` [PATCH bpf-next v2 00/13] Add support for qp-trie with dynptr key Alexei Starovoitov
2022-09-26 13:18   ` Hou Tao
2022-09-27  1:19     ` Alexei Starovoitov
2022-09-27  3:08       ` Hou Tao
2022-09-27  3:18         ` Alexei Starovoitov
2022-09-27 14:07           ` Hou Tao
2022-09-28  1:08             ` Alexei Starovoitov
2022-09-28  3:27               ` Hou Tao
2022-09-28  4:37                 ` Alexei Starovoitov
2022-09-28  8:45               ` Hou Tao
2022-09-28  8:49                 ` Hou Tao
2022-09-29  3:22                 ` Alexei Starovoitov
2022-10-08  1:56                   ` Hou Tao
2022-10-08  1:59                     ` Alexei Starovoitov
2022-10-08 13:22                       ` Paul E. McKenney
2022-10-08 16:40                         ` Alexei Starovoitov
2022-10-08 20:11                           ` Paul E. McKenney
2022-10-09  1:09                             ` Hou Tao
2022-10-09  9:05                               ` Paul E. McKenney
2022-10-09 10:45                                 ` Hou Tao
2022-10-09 11:04                                   ` Paul E. McKenney
2022-10-19 17:01 ` Tony Finch
2022-10-27 18:52   ` Andrii Nakryiko
2022-11-01 12:07     ` 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=20220924133620.4147153-3-houtao@huaweicloud.com \
    --to=houtao@huaweicloud.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=haoluo@google.com \
    --cc=houtao1@huawei.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=sdf@google.com \
    --cc=songliubraving@fb.com \
    --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 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.