[PATCH bpf-next v2 07/13] libbpf: Add probe support for BPF_MAP_TYPE_QP_TRIE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hou Tao <houtao1@xxxxxxxxxx>

BPF_MAP_TYPE_QP_TRIE requires BTF, so create a BTF fd to pass the types
of key and value to kernel and initialize map_extra to specify the
maximum size of bpf_dynptr-typed key.

Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx>
---
 tools/lib/bpf/libbpf.c        |  1 +
 tools/lib/bpf/libbpf_probes.c | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e691f08a297f..21b5b33fa010 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -164,6 +164,7 @@ static const char * const map_type_name[] = {
 	[BPF_MAP_TYPE_TASK_STORAGE]		= "task_storage",
 	[BPF_MAP_TYPE_BLOOM_FILTER]		= "bloom_filter",
 	[BPF_MAP_TYPE_USER_RINGBUF]             = "user_ringbuf",
+	[BPF_MAP_TYPE_QP_TRIE]			= "qp_trie",
 };
 
 static const char * const prog_type_name[] = {
diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c
index f3a8e8e74eb8..c4d1b595a4fe 100644
--- a/tools/lib/bpf/libbpf_probes.c
+++ b/tools/lib/bpf/libbpf_probes.c
@@ -188,6 +188,19 @@ static int load_local_storage_btf(void)
 				     strs, sizeof(strs));
 }
 
+static int load_qp_trie_btf(void)
+{
+	const char strs[] = "\0bpf_dynptr";
+	__u32 types[] = {
+		/* struct bpf_dynptr */				/* [1] */
+		BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 0), 16),
+		/* unsigned int */				/* [2] */
+		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),
+	};
+	return libbpf__load_raw_btf((char *)types, sizeof(types),
+				    strs, sizeof(strs));
+}
+
 static int probe_map_create(enum bpf_map_type map_type)
 {
 	LIBBPF_OPTS(bpf_map_create_opts, opts);
@@ -264,6 +277,18 @@ static int probe_map_create(enum bpf_map_type map_type)
 	case BPF_MAP_TYPE_SOCKHASH:
 	case BPF_MAP_TYPE_REUSEPORT_SOCKARRAY:
 		break;
+	case BPF_MAP_TYPE_QP_TRIE:
+		key_size = sizeof(struct bpf_dynptr);
+		value_size = 4;
+		btf_key_type_id = 1;
+		btf_value_type_id = 2;
+		max_entries = 1;
+		opts.map_flags = BPF_F_NO_PREALLOC;
+		opts.map_extra = 1;
+		btf_fd = load_qp_trie_btf();
+		if (btf_fd < 0)
+			return btf_fd;
+		break;
 	case BPF_MAP_TYPE_UNSPEC:
 	default:
 		return -EOPNOTSUPP;
-- 
2.29.2




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux