History

bpf: Add BPF_OBJ_GET_INFO_BY_FD

A single BPF_OBJ_GET_INFO_BY_FD cmd is used to obtain the info for both bpf_prog and bpf_map. The kernel can figure out the fd is associated with a bpf_prog or bpf_map. The suggested struct bpf_prog_info and struct bpf_map_info are not meant to be a complete list and it is not the goal of this patch. New fields can be added in the future patch. The focus of this patch is to create the interface, BPF_OBJ_GET_INFO_BY_FD cmd for exposing the bpf_prog's and bpf_map's info. The obj's info, which will be extended (and get bigger) over time, is separated from the bpf_attr to avoid bloating the bpf_attr.

Martin KaFai Lau committed 9 years ago

Commit 1e270971 parent 783d28d3 files · +174 −19Browse files

Showing the changes to include/uapi/linux (1 of 3 files). Show all

Unified · Split

include/uapi/linux/bpf.h+28−0
@@ -86,6 +86,7 @@ enum bpf_cmd { · 85 unmodified lines
8686 BPF_MAP_GET_NEXT_ID,
8787 BPF_PROG_GET_FD_BY_ID,
8888 BPF_MAP_GET_FD_BY_ID,
89+ BPF_OBJ_GET_INFO_BY_FD,
8990 };
9091
9192 enum bpf_map_type {
@@ -222,6 +223,12 @@ union bpf_attr { · 130 unmodified lines
222223 };
223224 __u32 next_id;
224225 };
226+
227+ struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
228+ __u32 bpf_fd;
229+ __u32 info_len;
230+ __aligned_u64 info;
231+ } info;
225232 } __attribute__((aligned(8)));
226233
227234 /* BPF helper function descriptions:
@@ -686,4 +693,25 @@ struct xdp_md { · 458 unmodified lines
686693 __u32 data_end;
687694 };
688695
696+#define BPF_TAG_SIZE 8
697+
698+struct bpf_prog_info {
699+ __u32 type;
700+ __u32 id;
701+ __u8 tag[BPF_TAG_SIZE];
702+ __u32 jited_prog_len;
703+ __u32 xlated_prog_len;
704+ __aligned_u64 jited_prog_insns;
705+ __aligned_u64 xlated_prog_insns;
706+} __attribute__((aligned(8)));
707+
708+struct bpf_map_info {
709+ __u32 type;
710+ __u32 id;
711+ __u32 key_size;
712+ __u32 value_size;
713+ __u32 max_entries;
714+ __u32 map_flags;
715+} __attribute__((aligned(8)));
716+
689717 #endif /* _UAPI__LINUX_BPF_H__ */