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
86 BPF_MAP_GET_NEXT_ID,86 BPF_MAP_GET_NEXT_ID,
87 BPF_PROG_GET_FD_BY_ID,87 BPF_PROG_GET_FD_BY_ID,
88 BPF_MAP_GET_FD_BY_ID,88 BPF_MAP_GET_FD_BY_ID,
89 BPF_OBJ_GET_INFO_BY_FD,
89};90};
90 91
91enum bpf_map_type {92enum bpf_map_type {
@@ -222,6 +223,12 @@ union bpf_attr { · 130 unmodified lines
222 };223 };
223 __u32 next_id;224 __u32 next_id;
224 };225 };
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;
225} __attribute__((aligned(8)));232} __attribute__((aligned(8)));
226 233
227/* BPF helper function descriptions:234/* BPF helper function descriptions:
@@ -686,4 +693,25 @@ struct xdp_md { · 458 unmodified lines
686 __u32 data_end;693 __u32 data_end;
687};694};
688 695
696#define BPF_TAG_SIZE 8
697
698struct 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
708struct 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
689#endif /* _UAPI__LINUX_BPF_H__ */717#endif /* _UAPI__LINUX_BPF_H__ */