History

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

Daniel Borkmann says: ==================== pull-request: bpf-next 2018-12-21 The following pull-request contains BPF updates for your *net-next* tree. There is a merge conflict in test_verifier.c. Result looks as follows: [...] }, { "calls: cross frame pruning", .insns = { [...] .prog_type = BPF_PROG_TYPE_SOCKET_FILTER, .errstr_unpriv = "function calls to other bpf functions are allowed for root only", .result_unpriv = REJECT, .errstr = "!read_ok", .result = REJECT, }, { "jset: functional", .insns = { [...] { "jset: unknown const compare not taken", .insns = { BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32), BPF_JMP_IMM(BPF_JSET, BPF_REG_0, 1, 1), BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0), BPF_EXIT_INSN(), }, .prog_type = BPF_PROG_TYPE_SOCKET_FILTER, .errstr_unpriv = "!read_ok", .result_unpriv = REJECT, .errstr = "!read_ok", .result = REJECT, }, [...] { "jset: range", .insns = { [...] }, .prog_type = BPF_PROG_TYPE_SOCKET_FILTER, .result_unpriv = ACCEPT, .result = ACCEPT, }, The main changes are: 1) Various BTF related improvements in order to get line info working. Meaning, verifier will now annotate the corresponding BPF C code to the error log, from Martin and Yonghong. 2) Implement support for raw BPF tracepoints in modules, from Matt. 3) Add several improvements to verifier state logic, namely speeding up stacksafe check, optimizations for stack state equivalence test and safety checks for liveness analysis, from Alexei. 4) Teach verifier to make use of BPF_JSET instruction, add several test cases to kselftests and remove nfp specific JSET optimization now that verifier has awareness, from Jakub. 5) Improve BPF verifier's slot_type marking logic in order to allow more stack slot sharing, from Jiong. 6) Add sk_msg->size member for context access and add set of fixes and improvements to make sock_map with kTLS usable with openssl based applications, from John. 7) Several cleanups and documentation updates in bpftool as well as auto-mount of tracefs for "bpftool prog tracelog" command, from Quentin. 8) Include sub-program tags from now on in bpf_prog_info in order to have a reliable way for user space to get all tags of the program e.g. needed for kallsyms correlation, from Song. 9) Add BTF annotations for cgroup_local_storage BPF maps and implement bpf fs pretty print support, from Roman. 10) Fix bpftool in order to allow for cross-compilation, from Ivan. 11) Update of bpftool license to GPLv2-only + BSD-2-Clause in order to be compatible with libbfd and allow for Debian packaging, from Jakub. 12) Remove an obsolete prog->aux sanitation in dump and get rid of version check for prog load, from Daniel. 13) Fix a memory leak in libbpf's line info handling, from Prashant. 14) Fix cpumap's frame alignment for build_skb() so that skb_shared_info does not get unaligned, from Jesper. 15) Fix test_progs kselftest to work with older compilers which are less smart in optimizing (and thus throwing build error), from Stanislav. 16) Cleanup and simplify AF_XDP socket teardown, from Björn. 17) Fix sk lookup in BPF kselftest's test_sock_addr with regards to netns_id argument, from Andrey. ====================

David S. Miller committed 7 years ago

Commit 339bbff2 parents e770454 1cf4a0c64 files · +2331 −680Browse files

Showing the changes to kernel/trace (1 of 64 files). Show all

Unified · Split

kernel/trace/bpf_trace.c+97−2
@@ -17,6 +17,43 @@ · 16 unmodified lines
17#include "trace_probe.h"17#include "trace_probe.h"
18#include "trace.h"18#include "trace.h"
19 19
20#ifdef CONFIG_MODULES
21struct bpf_trace_module {
22 struct module *module;
23 struct list_head list;
24};
25
26static LIST_HEAD(bpf_trace_modules);
27static DEFINE_MUTEX(bpf_module_mutex);
28
29static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name)
30{
31 struct bpf_raw_event_map *btp, *ret = NULL;
32 struct bpf_trace_module *btm;
33 unsigned int i;
34
35 mutex_lock(&bpf_module_mutex);
36 list_for_each_entry(btm, &bpf_trace_modules, list) {
37 for (i = 0; i < btm->module->num_bpf_raw_events; ++i) {
38 btp = &btm->module->bpf_raw_events[i];
39 if (!strcmp(btp->tp->name, name)) {
40 if (try_module_get(btm->module))
41 ret = btp;
42 goto out;
43 }
44 }
45 }
46out:
47 mutex_unlock(&bpf_module_mutex);
48 return ret;
49}
50#else
51static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name)
52{
53 return NULL;
54}
55#endif /* CONFIG_MODULES */
56
20u64 bpf_get_stackid(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);57u64 bpf_get_stackid(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
21u64 bpf_get_stack(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);58u64 bpf_get_stack(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
22 59
@@ -1076,7 +1113,7 @@ int perf_event_query_prog_array(struct perf_event *event, void __user *info) · 1053 unmodified lines
1076extern struct bpf_raw_event_map __start__bpf_raw_tp[];1113extern struct bpf_raw_event_map __start__bpf_raw_tp[];
1077extern struct bpf_raw_event_map __stop__bpf_raw_tp[];1114extern struct bpf_raw_event_map __stop__bpf_raw_tp[];
1078 1115
1079struct bpf_raw_event_map *bpf_find_raw_tracepoint(const char *name)1116struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name)
1080{1117{
1081 struct bpf_raw_event_map *btp = __start__bpf_raw_tp;1118 struct bpf_raw_event_map *btp = __start__bpf_raw_tp;
1082 1119
@@ -1084,7 +1121,16 @@ struct bpf_raw_event_map *bpf_find_raw_tracepoint(const char *name) · 1 unmodified line
1084 if (!strcmp(btp->tp->name, name))1121 if (!strcmp(btp->tp->name, name))
1085 return btp;1122 return btp;
1086 }1123 }
1087 return NULL;1124
1125 return bpf_get_raw_tracepoint_module(name);
1126}
1127
1128void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp)
1129{
1130 struct module *mod = __module_address((unsigned long)btp);
1131
1132 if (mod)
1133 module_put(mod);
1088}1134}
1089 1135
1090static __always_inline1136static __always_inline
@@ -1222,3 +1268,52 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id, · 131 unmodified lines
1222 1268
1223 return err;1269 return err;
1224}1270}
1271
1272#ifdef CONFIG_MODULES
1273int bpf_event_notify(struct notifier_block *nb, unsigned long op, void *module)
1274{
1275 struct bpf_trace_module *btm, *tmp;
1276 struct module *mod = module;
1277
1278 if (mod->num_bpf_raw_events == 0 ||
1279 (op != MODULE_STATE_COMING && op != MODULE_STATE_GOING))
1280 return 0;
1281
1282 mutex_lock(&bpf_module_mutex);
1283
1284 switch (op) {
1285 case MODULE_STATE_COMING:
1286 btm = kzalloc(sizeof(*btm), GFP_KERNEL);
1287 if (btm) {
1288 btm->module = module;
1289 list_add(&btm->list, &bpf_trace_modules);
1290 }
1291 break;
1292 case MODULE_STATE_GOING:
1293 list_for_each_entry_safe(btm, tmp, &bpf_trace_modules, list) {
1294 if (btm->module == module) {
1295 list_del(&btm->list);
1296 kfree(btm);
1297 break;
1298 }
1299 }
1300 break;
1301 }
1302
1303 mutex_unlock(&bpf_module_mutex);
1304
1305 return 0;
1306}
1307
1308static struct notifier_block bpf_module_nb = {
1309 .notifier_call = bpf_event_notify,
1310};
1311
1312int __init bpf_event_init(void)
1313{
1314 register_module_notifier(&bpf_module_nb);
1315 return 0;
1316}
1317
1318fs_initcall(bpf_event_init);
1319#endif /* CONFIG_MODULES */