History

bpf: Add PTR_TO_BTF_ID_OR_NULL support

Add bpf_reg_type PTR_TO_BTF_ID_OR_NULL support. For tracing/iter program, the bpf program context definition, e.g., for previous bpf_map target, looks like struct bpf_iter__bpf_map { struct bpf_iter_meta *meta; struct bpf_map *map; }; The kernel guarantees that meta is not NULL, but map pointer maybe NULL. The NULL map indicates that all objects have been traversed, so bpf program can take proper action, e.g., do final aggregation and/or send final report to user space. Add btf_id_or_null_non0_off to prog->aux structure, to indicate that if the context access offset is not 0, set to PTR_TO_BTF_ID_OR_NULL instead of PTR_TO_BTF_ID. This bit is set for tracing/iter program.

Yonghong Song committed 6 years ago

Commit b121b341 parent eaaacd23 files · +18 −5Browse files

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

Unified · Split

include/linux/bpf.h+2−0
@@ -320,6 +320,7 @@ enum bpf_reg_type { · 319 unmodified lines
320 PTR_TO_TP_BUFFER, /* reg points to a writable raw tp's buffer */320 PTR_TO_TP_BUFFER, /* reg points to a writable raw tp's buffer */
321 PTR_TO_XDP_SOCK, /* reg points to struct xdp_sock */321 PTR_TO_XDP_SOCK, /* reg points to struct xdp_sock */
322 PTR_TO_BTF_ID, /* reg points to kernel struct */322 PTR_TO_BTF_ID, /* reg points to kernel struct */
323 PTR_TO_BTF_ID_OR_NULL, /* reg points to kernel struct or NULL */
323};324};
324 325
325/* The information passed from prog-specific *_is_valid_access326/* The information passed from prog-specific *_is_valid_access
@@ -658,6 +659,7 @@ struct bpf_prog_aux { · 332 unmodified lines
658 bool offload_requested;659 bool offload_requested;
659 bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */660 bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */
660 bool func_proto_unreliable;661 bool func_proto_unreliable;
662 bool btf_id_or_null_non0_off;
661 enum bpf_tramp_prog_type trampoline_prog_type;663 enum bpf_tramp_prog_type trampoline_prog_type;
662 struct bpf_trampoline *trampoline;664 struct bpf_trampoline *trampoline;
663 struct hlist_node tramp_hlist;665 struct hlist_node tramp_hlist;