History

bpf: libbpf: Provide basic API support to specify BPF obj name

This patch extends the libbpf to provide API support to allow specifying BPF object name. In tools/lib/bpf/libbpf, the C symbol of the function and the map is used. Regarding section name, all maps are under the same section named "maps". Hence, section name is not a good choice for map's name. To be consistent with map, bpf_prog also follows and uses its function symbol as the prog's name. This patch adds logic to collect function's symbols in libbpf. There is existing codes to collect the map's symbols and no change is needed. The bpf_load_program_name() and bpf_map_create_name() are added to take the name argument. For the other bpf_map_create_xxx() variants, a name argument is directly added to them. In samples/bpf, bpf_load.c in particular, the symbol is also used as the map's name and the map symbols has already been collected in the existing code. For bpf_prog, bpf_load.c does not collect the function symbol name. We can consider to collect them later if there is a need to continue supporting the bpf_load.c.

Martin KaFai Lau committed 9 years ago

Commit 88cda1c1 parent ad5b1777 files · +157 −47Browse files

Showing the changes to tools/include/uapi (1 of 7 files). Show all

Unified · Split

tools/include/uapi/linux/bpf.h+10−0
@@ -175,6 +175,8 @@ enum bpf_attach_type { · 174 unmodified lines
175175 /* Specify numa node during map creation */
176176 #define BPF_F_NUMA_NODE (1U << 2)
177177
178+#define BPF_OBJ_NAME_LEN 16U
179+
178180 union bpf_attr {
179181 struct { /* anonymous struct used by BPF_MAP_CREATE command */
180182 __u32 map_type; /* one of enum bpf_map_type */
@@ -188,6 +190,7 @@ union bpf_attr { · 7 unmodified lines
188190 __u32 numa_node; /* numa node (effective only if
189191 * BPF_F_NUMA_NODE is set).
190192 */
193+ __u8 map_name[BPF_OBJ_NAME_LEN];
191194 };
192195
193196 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -210,6 +213,7 @@ union bpf_attr { · 16 unmodified lines
210213 __aligned_u64 log_buf; /* user supplied buffer */
211214 __u32 kern_version; /* checked when prog_type=kprobe */
212215 __u32 prog_flags;
216+ __u8 prog_name[BPF_OBJ_NAME_LEN];
213217 };
214218
215219 struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -812,6 +816,11 @@ struct bpf_prog_info { · 596 unmodified lines
812816 __u32 xlated_prog_len;
813817 __aligned_u64 jited_prog_insns;
814818 __aligned_u64 xlated_prog_insns;
819+ __u64 load_time; /* ns since boottime */
820+ __u32 created_by_uid;
821+ __u32 nr_map_ids;
822+ __aligned_u64 map_ids;
823+ __u8 name[BPF_OBJ_NAME_LEN];
815824 } __attribute__((aligned(8)));
816825
817826 struct bpf_map_info {
@@ -821,6 +830,7 @@ struct bpf_map_info { · 3 unmodified lines
821830 __u32 value_size;
822831 __u32 max_entries;
823832 __u32 map_flags;
833+ __u8 name[BPF_OBJ_NAME_LEN];
824834 } __attribute__((aligned(8)));
825835
826836 /* User bpf_sock_ops struct to access socket values and specify request ops