History

bpf: Add bpf_line_info support

This patch adds bpf_line_info support. It accepts an array of bpf_line_info objects during BPF_PROG_LOAD. The "line_info", "line_info_cnt" and "line_info_rec_size" are added to the "union bpf_attr". The "line_info_rec_size" makes bpf_line_info extensible in the future. The new "check_btf_line()" ensures the userspace line_info is valid for the kernel to use. When the verifier is translating/patching the bpf_prog (through "bpf_patch_insn_single()"), the line_infos' insn_off is also adjusted by the newly added "bpf_adj_linfo()". If the bpf_prog is jited, this patch also provides the jited addrs (in aux->jited_linfo) for the corresponding line_info.insn_off. "bpf_prog_fill_jited_linfo()" is added to fill the aux->jited_linfo. It is currently called by the x86 jit. Other jits can also use "bpf_prog_fill_jited_linfo()" and it will be done in the followup patches. In the future, if it deemed necessary, a particular jit could also provide its own "bpf_prog_fill_jited_linfo()" implementation. A few "*line_info*" fields are added to the bpf_prog_info such that the user can get the xlated line_info back (i.e. the line_info with its insn_off reflecting the translated prog). The jited_line_info is available if the prog is jited. It is an array of __u64. If the prog is not jited, jited_line_info_cnt is 0. The verifier's verbose log with line_info will be done in a follow up patch.

Martin KaFai Lau committed 7 years ago

Commit c454a461 parent 6baefa110 files · +419 −33Browse files

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

Unified · Split

include/uapi/linux/bpf.h+19−0
@@ -356,6 +356,9 @@ union bpf_attr { · 355 unmodified lines
356356 __u32 func_info_rec_size; /* userspace bpf_func_info size */
357357 __aligned_u64 func_info; /* func info */
358358 __u32 func_info_cnt; /* number of bpf_func_info records */
359+ __u32 line_info_rec_size; /* userspace bpf_line_info size */
360+ __aligned_u64 line_info; /* line info */
361+ __u32 line_info_cnt; /* number of bpf_line_info records */
359362 };
360363
361364 struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -2679,6 +2682,12 @@ struct bpf_prog_info { · 2317 unmodified lines
26792682 __u32 func_info_rec_size;
26802683 __aligned_u64 func_info;
26812684 __u32 func_info_cnt;
2685+ __u32 line_info_cnt;
2686+ __aligned_u64 line_info;
2687+ __aligned_u64 jited_line_info;
2688+ __u32 jited_line_info_cnt;
2689+ __u32 line_info_rec_size;
2690+ __u32 jited_line_info_rec_size;
26822691 } __attribute__((aligned(8)));
26832692
26842693 struct bpf_map_info {
@@ -2995,4 +3004,14 @@ struct bpf_func_info { · 310 unmodified lines
29953004 __u32 type_id;
29963005 };
29973006
3007+#define BPF_LINE_INFO_LINE_NUM(line_col) ((line_col) >> 10)
3008+#define BPF_LINE_INFO_LINE_COL(line_col) ((line_col) & 0x3ff)
3009+
3010+struct bpf_line_info {
3011+ __u32 insn_off;
3012+ __u32 file_name_off;
3013+ __u32 line_off;
3014+ __u32 line_col;
3015+};
3016+
29983017 #endif /* _UAPI__LINUX_BPF_H__ */