History

bpf: Add name, load_time, uid and map_ids to bpf_prog_info

The patch adds name and load_time to struct bpf_prog_aux. They are also exported to bpf_prog_info. The bpf_prog's name is passed by userspace during BPF_PROG_LOAD. The kernel only stores the first (BPF_PROG_NAME_LEN - 1) bytes and the name stored in the kernel is always \0 terminated. The kernel will reject name that contains characters other than isalnum() and '_'. It will also reject name that is not null terminated. The existing 'user->uid' of the bpf_prog_aux is also exported to the bpf_prog_info as created_by_uid. The existing 'used_maps' of the bpf_prog_aux is exported to the newly added members 'nr_map_ids' and 'map_ids' of the bpf_prog_info. On the input, nr_map_ids tells how big the userspace's map_ids buffer is. On the output, nr_map_ids tells the exact user_map_cnt and it will only copy up to the userspace's map_ids buffer is allowed.

Martin KaFai Lau committed 9 years ago

Commit cb4d2b31 parent cf5d74b3 files · +60 −1Browse files

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

Unified · Split

include/uapi/linux/bpf.h+8−0
@@ -175,6 +175,8 @@ enum bpf_attach_type { · 174 unmodified lines
175/* Specify numa node during map creation */175/* Specify numa node during map creation */
176#define BPF_F_NUMA_NODE (1U << 2)176#define BPF_F_NUMA_NODE (1U << 2)
177 177
178#define BPF_OBJ_NAME_LEN 16U
179
178union bpf_attr {180union bpf_attr {
179 struct { /* anonymous struct used by BPF_MAP_CREATE command */181 struct { /* anonymous struct used by BPF_MAP_CREATE command */
180 __u32 map_type; /* one of enum bpf_map_type */182 __u32 map_type; /* one of enum bpf_map_type */
@@ -210,6 +212,7 @@ union bpf_attr { · 29 unmodified lines
210 __aligned_u64 log_buf; /* user supplied buffer */212 __aligned_u64 log_buf; /* user supplied buffer */
211 __u32 kern_version; /* checked when prog_type=kprobe */213 __u32 kern_version; /* checked when prog_type=kprobe */
212 __u32 prog_flags;214 __u32 prog_flags;
215 __u8 prog_name[BPF_OBJ_NAME_LEN];
213 };216 };
214 217
215 struct { /* anonymous struct used by BPF_OBJ_* commands */218 struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -812,6 +815,11 @@ struct bpf_prog_info { · 596 unmodified lines
812 __u32 xlated_prog_len;815 __u32 xlated_prog_len;
813 __aligned_u64 jited_prog_insns;816 __aligned_u64 jited_prog_insns;
814 __aligned_u64 xlated_prog_insns;817 __aligned_u64 xlated_prog_insns;
818 __u64 load_time; /* ns since boottime */
819 __u32 created_by_uid;
820 __u32 nr_map_ids;
821 __aligned_u64 map_ids;
822 __u8 name[BPF_OBJ_NAME_LEN];
815} __attribute__((aligned(8)));823} __attribute__((aligned(8)));
816 824
817struct bpf_map_info {825struct bpf_map_info {