History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Daniel Borkmann says: ==================== pull-request: bpf-next 2019-10-27 The following pull-request contains BPF updates for your *net-next* tree. We've added 52 non-merge commits during the last 11 day(s) which contain a total of 65 files changed, 2604 insertions(+), 1100 deletions(-). The main changes are: 1) Revolutionize BPF tracing by using in-kernel BTF to type check BPF assembly code. The work here teaches BPF verifier to recognize kfree_skb()'s first argument as 'struct sk_buff *' in tracepoints such that verifier allows direct use of bpf_skb_event_output() helper used in tc BPF et al (w/o probing memory access) that dumps skb data into perf ring buffer. Also add direct loads to probe memory in order to speed up/replace bpf_probe_read() calls, from Alexei Starovoitov. 2) Big batch of changes to improve libbpf and BPF kselftests. Besides others: generalization of libbpf's CO-RE relocation support to now also include field existence relocations, revamp the BPF kselftest Makefile to add test runner concept allowing to exercise various ways to build BPF programs, and teach bpf_object__open() and friends to automatically derive BPF program type/expected attach type from section names to ease their use, from Andrii Nakryiko. 3) Fix deadlock in stackmap's build-id lookup on rq_lock(), from Song Liu. 4) Allow to read BTF as raw data from bpftool. Most notable use case is to dump /sys/kernel/btf/vmlinux through this, from Jiri Olsa. 5) Use bpf_redirect_map() helper in libbpf's AF_XDP helper prog which manages to improve "rx_drop" performance by ~4%., from Björn Töpel. 6) Fix to restore the flow dissector after reattach BPF test and also fix error handling in bpf_helper_defs.h generation, from Jakub Sitnicki. 7) Improve verifier's BTF ctx access for use outside of raw_tp, from Martin KaFai Lau. 8) Improve documentation for AF_XDP with new sections and to reflect latest features, from Magnus Karlsson. 9) Add back 'version' section parsing to libbpf for old kernels, from John Fastabend. 10) Fix strncat bounds error in libbpf's libbpf_prog_type_by_name(), from KP Singh. 11) Turn on -mattr=+alu32 in LLVM by default for BPF kselftests in order to improve insn coverage for built BPF progs, from Yonghong Song. 12) Misc minor cleanups and fixes, from various others. ====================

David S. Miller committed 7 years ago

Commit 5b7fe932 parents b951248 027cbaa65 files · +2604 −1100Browse files

Showing the changes to include/linux (5 of 65 files). Show all

Unified · Split

5 files
  1. include/linux/bpf.h +38 −6
  2. include/linux/bpf_verifier.h +7 −1
  3. include/linux/btf.h +32 −0
  4. include/linux/extable.h +10 −0
  5. include/linux/filter.h +5 −1
include/linux/bpf.h+38−6
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 #include <linux/u64_stats_sync.h>
1717
1818 struct bpf_verifier_env;
19+struct bpf_verifier_log;
1920 struct perf_event;
2021 struct bpf_prog;
2122 struct bpf_map;
@@ -23,6 +24,7 @@ struct sock; · 1 unmodified line
2324 struct seq_file;
2425 struct btf;
2526 struct btf_type;
27+struct exception_table_entry;
2628
2729 extern struct idr btf_idr;
2830 extern spinlock_t btf_idr_lock;
@@ -211,6 +213,7 @@ enum bpf_arg_type { · 182 unmodified lines
211213 ARG_PTR_TO_INT, /* pointer to int */
212214 ARG_PTR_TO_LONG, /* pointer to long */
213215 ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */
216+ ARG_PTR_TO_BTF_ID, /* pointer to in-kernel struct */
214217 };
215218
216219 /* type of values returned from helper functions */
@@ -233,11 +236,17 @@ struct bpf_func_proto { · 16 unmodified lines
233236 bool gpl_only;
234237 bool pkt_access;
235238 enum bpf_return_type ret_type;
236− enum bpf_arg_type arg1_type;
237− enum bpf_arg_type arg2_type;
238− enum bpf_arg_type arg3_type;
239− enum bpf_arg_type arg4_type;
240− enum bpf_arg_type arg5_type;
239+ union {
240+ struct {
241+ enum bpf_arg_type arg1_type;
242+ enum bpf_arg_type arg2_type;
243+ enum bpf_arg_type arg3_type;
244+ enum bpf_arg_type arg4_type;
245+ enum bpf_arg_type arg5_type;
246+ };
247+ enum bpf_arg_type arg_type[5];
248+ };
249+ u32 *btf_id; /* BTF ids of arguments */
241250 };
242251
243252 /* bpf_context is intentionally undefined structure. Pointer to bpf_context is
@@ -281,6 +290,7 @@ enum bpf_reg_type { · 37 unmodified lines
281290 PTR_TO_TCP_SOCK_OR_NULL, /* reg points to struct tcp_sock or NULL */
282291 PTR_TO_TP_BUFFER, /* reg points to a writable raw tp's buffer */
283292 PTR_TO_XDP_SOCK, /* reg points to struct xdp_sock */
293+ PTR_TO_BTF_ID, /* reg points to kernel struct */
284294 };
285295
286296 /* The information passed from prog-specific *_is_valid_access
@@ -288,7 +298,11 @@ enum bpf_reg_type { · 1 unmodified line
288298 */
289299 struct bpf_insn_access_aux {
290300 enum bpf_reg_type reg_type;
291− int ctx_field_size;
301+ union {
302+ int ctx_field_size;
303+ u32 btf_id;
304+ };
305+ struct bpf_verifier_log *log; /* for verbose logs */
292306 };
293307
294308 static inline void
@@ -375,8 +389,14 @@ struct bpf_prog_aux { · 80 unmodified lines
375389 u32 id;
376390 u32 func_cnt; /* used by non-func prog as the number of func progs */
377391 u32 func_idx; /* 0 for non-func prog, the index in func array for func prog */
392+ u32 attach_btf_id; /* in-kernel BTF type id to attach to */
378393 bool verifier_zext; /* Zero extensions has been inserted by verifier. */
379394 bool offload_requested;
395+ bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */
396+ /* BTF_KIND_FUNC_PROTO for valid attach_btf_id */
397+ const struct btf_type *attach_func_proto;
398+ /* function name for valid attach_btf_id */
399+ const char *attach_func_name;
380400 struct bpf_prog **func;
381401 void *jit_data; /* JIT specific data. arch dependent */
382402 struct latch_tree_node ksym_tnode;
@@ -416,6 +436,8 @@ struct bpf_prog_aux { · 33 unmodified lines
416436 * main prog always has linfo_idx == 0
417437 */
418438 u32 linfo_idx;
439+ u32 num_exentries;
440+ struct exception_table_entry *extable;
419441 struct bpf_prog_stats __percpu *stats;
420442 union {
421443 struct work_struct work;
@@ -482,6 +504,7 @@ struct bpf_event_entry { · 60 unmodified lines
482504
483505 bool bpf_prog_array_compatible(struct bpf_array *array, const struct bpf_prog *fp);
484506 int bpf_prog_calc_tag(struct bpf_prog *fp);
507+const char *kernel_type_name(u32 btf_type_id);
485508
486509 const struct bpf_func_proto *bpf_get_trace_printk_proto(void);
487510
@@ -747,6 +770,15 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, · 259 unmodified lines
747770 int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
748771 const union bpf_attr *kattr,
749772 union bpf_attr __user *uattr);
773+bool btf_ctx_access(int off, int size, enum bpf_access_type type,
774+ const struct bpf_prog *prog,
775+ struct bpf_insn_access_aux *info);
776+int btf_struct_access(struct bpf_verifier_log *log,
777+ const struct btf_type *t, int off, int size,
778+ enum bpf_access_type atype,
779+ u32 *next_btf_id);
780+u32 btf_resolve_helper_id(struct bpf_verifier_log *log, void *, int);
781+
750782 #else /* !CONFIG_BPF_SYSCALL */
751783 static inline struct bpf_prog *bpf_prog_get(u32 ufd)
752784 {
include/linux/bpf_verifier.h+7−1
@@ -52,6 +52,8 @@ struct bpf_reg_state { · 51 unmodified lines
5252 */
5353 struct bpf_map *map_ptr;
5454
55+ u32 btf_id; /* for PTR_TO_BTF_ID */
56+
5557 /* Max size from any of the above. */
5658 unsigned long raw;
5759 };
@@ -330,10 +332,12 @@ static inline bool bpf_verifier_log_full(const struct bpf_verifier_log *log) · 272 unmodified lines
330332 #define BPF_LOG_STATS 4
331333 #define BPF_LOG_LEVEL (BPF_LOG_LEVEL1 | BPF_LOG_LEVEL2)
332334 #define BPF_LOG_MASK (BPF_LOG_LEVEL | BPF_LOG_STATS)
335+#define BPF_LOG_KERNEL (BPF_LOG_MASK + 1) /* kernel internal flag */
333336
334337 static inline bool bpf_verifier_log_needed(const struct bpf_verifier_log *log)
335338 {
336− return log->level && log->ubuf && !bpf_verifier_log_full(log);
339+ return (log->level && log->ubuf && !bpf_verifier_log_full(log)) ||
340+ log->level == BPF_LOG_KERNEL;
337341 }
338342
339343 #define BPF_MAX_SUBPROGS 256
@@ -397,6 +401,8 @@ __printf(2, 0) void bpf_verifier_vlog(struct bpf_verifier_log *log, · 57 unmodified lines
397401 const char *fmt, va_list args);
398402 __printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,
399403 const char *fmt, ...);
404+__printf(2, 3) void bpf_log(struct bpf_verifier_log *log,
405+ const char *fmt, ...);
400406
401407 static inline struct bpf_func_state *cur_func(struct bpf_verifier_env *env)
402408 {
include/linux/btf.h+32−0
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 #define _LINUX_BTF_H 1
66
77 #include <linux/types.h>
8+#include <uapi/linux/btf.h>
89
910 struct btf;
1011 struct btf_member;
@@ -53,9 +54,40 @@ bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s, · 42 unmodified lines
5354 int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t);
5455 bool btf_type_is_void(const struct btf_type *t);
5556
57+static inline bool btf_type_is_ptr(const struct btf_type *t)
58+{
59+ return BTF_INFO_KIND(t->info) == BTF_KIND_PTR;
60+}
61+
62+static inline bool btf_type_is_int(const struct btf_type *t)
63+{
64+ return BTF_INFO_KIND(t->info) == BTF_KIND_INT;
65+}
66+
67+static inline bool btf_type_is_enum(const struct btf_type *t)
68+{
69+ return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM;
70+}
71+
72+static inline bool btf_type_is_typedef(const struct btf_type *t)
73+{
74+ return BTF_INFO_KIND(t->info) == BTF_KIND_TYPEDEF;
75+}
76+
77+static inline bool btf_type_is_func(const struct btf_type *t)
78+{
79+ return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC;
80+}
81+
82+static inline bool btf_type_is_func_proto(const struct btf_type *t)
83+{
84+ return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC_PROTO;
85+}
86+
5687 #ifdef CONFIG_BPF_SYSCALL
5788 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
5889 const char *btf_name_by_offset(const struct btf *btf, u32 offset);
90+struct btf *btf_parse_vmlinux(void);
5991 #else
6092 static inline const struct btf_type *btf_type_by_id(const struct btf *btf,
6193 u32 type_id)
include/linux/extable.h+10−0
@@ -33,4 +33,14 @@ search_module_extables(unsigned long addr) · 32 unmodified lines
3333 }
3434 #endif /*CONFIG_MODULES*/
3535
36+#ifdef CONFIG_BPF_JIT
37+const struct exception_table_entry *search_bpf_extables(unsigned long addr);
38+#else
39+static inline const struct exception_table_entry *
40+search_bpf_extables(unsigned long addr)
41+{
42+ return NULL;
43+}
44+#endif
45+
3646 #endif /* _LINUX_EXTABLE_H */
include/linux/filter.h+5−1
@@ -65,6 +65,9 @@ struct ctl_table_header; · 64 unmodified lines
6565 /* unused opcode to mark special call to bpf_tail_call() helper */
6666 #define BPF_TAIL_CALL 0xf0
6767
68+/* unused opcode to mark special load instruction. Same as BPF_ABS */
69+#define BPF_PROBE_MEM 0x20
70+
6871 /* unused opcode to mark call to interpreter with arguments */
6972 #define BPF_CALL_ARGS 0xe0
7073
@@ -464,10 +467,11 @@ static inline bool insn_is_zext(const struct bpf_insn *insn) · 393 unmodified lines
464467 #define BPF_CALL_x(x, name, ...) \
465468 static __always_inline \
466469 u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
470+ typedef u64 (*btf_##name)(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
467471 u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
468472 u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
469473 { \
470− return ____##name(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
474+ return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
471475 } \
472476 static __always_inline \
473477 u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t