summaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2019-03-04 13:14:31 -0500
committerDavid S. Miller <davem@davemloft.net>2019-03-04 13:14:31 -0500
commitf7fb7c1a1c8f86005d34f28278524213c521f761 (patch)
tree05a3b21c5e0b1667b106153fc0f0eb88cd980ab2 /kernel/bpf/syscall.c
parent8c4238df4d0cc3420c5ee14b54d200d74267cfe5 (diff)
parent87dab7c3d54ce0f1ff6b54840bf7279d0944bc6a (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2019-03-04 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add AF_XDP support to libbpf. Rationale is to facilitate writing AF_XDP applications by offering higher-level APIs that hide many of the details of the AF_XDP uapi. Sample programs are converted over to this new interface as well, from Magnus. 2) Introduce a new cant_sleep() macro for annotation of functions that cannot sleep and use it in BPF_PROG_RUN() to assert that BPF programs run under preemption disabled context, from Peter. 3) Introduce per BPF prog stats in order to monitor the usage of BPF; this is controlled by kernel.bpf_stats_enabled sysctl knob where monitoring tools can make use of this to efficiently determine the average cost of programs, from Alexei. 4) Split up BPF selftest's test_progs similarly as we already did with test_verifier. This allows to further reduce merge conflicts in future and to get more structure into our quickly growing BPF selftest suite, from Stanislav. 5) Fix a bug in BTF's dedup algorithm which can cause an infinite loop in some circumstances; also various BPF doc fixes and improvements, from Andrii. 6) Various BPF sample cleanups and migration to libbpf in order to further isolate the old sample loader code (so we can get rid of it at some point), from Jakub. 7) Add a new BPF helper for BPF cgroup skb progs that allows to set ECN CE code point and a Host Bandwidth Manager (HBM) sample program for limiting the bandwidth used by v2 cgroups, from Lawrence. 8) Enable write access to skb->queue_mapping from tc BPF egress programs in order to let BPF pick TX queue, from Jesper. 9) Fix a bug in BPF spinlock handling for map-in-map which did not propagate spin_lock_off to the meta map, from Yonghong. 10) Fix a bug in the new per-CPU BPF prog counters to properly initialize stats for each CPU, from Eric. 11) Add various BPF helper prototypes to selftest's bpf_helpers.h, from Willem. 12) Fix various BPF samples bugs in XDP and tracing progs, from Toke, Daniel and Yonghong. 13) Silence preemption splat in test_bpf after BPF_PROG_RUN() enforces it now everywhere, from Anders. 14) Fix a signedness bug in libbpf's btf_dedup_ref_type() to get error handling working, from Dan. 15) Fix bpftool documentation and auto-completion with regards to stream_{verdict,parser} attach types, from Alban. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 797a99c7493e..bc34cf9fe9ee 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1283,24 +1283,54 @@ static int bpf_prog_release(struct inode *inode, struct file *filp)
1283 return 0; 1283 return 0;
1284} 1284}
1285 1285
1286static void bpf_prog_get_stats(const struct bpf_prog *prog,
1287 struct bpf_prog_stats *stats)
1288{
1289 u64 nsecs = 0, cnt = 0;
1290 int cpu;
1291
1292 for_each_possible_cpu(cpu) {
1293 const struct bpf_prog_stats *st;
1294 unsigned int start;
1295 u64 tnsecs, tcnt;
1296
1297 st = per_cpu_ptr(prog->aux->stats, cpu);
1298 do {
1299 start = u64_stats_fetch_begin_irq(&st->syncp);
1300 tnsecs = st->nsecs;
1301 tcnt = st->cnt;
1302 } while (u64_stats_fetch_retry_irq(&st->syncp, start));
1303 nsecs += tnsecs;
1304 cnt += tcnt;
1305 }
1306 stats->nsecs = nsecs;
1307 stats->cnt = cnt;
1308}
1309
1286#ifdef CONFIG_PROC_FS 1310#ifdef CONFIG_PROC_FS
1287static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) 1311static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)
1288{ 1312{
1289 const struct bpf_prog *prog = filp->private_data; 1313 const struct bpf_prog *prog = filp->private_data;
1290 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; 1314 char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
1315 struct bpf_prog_stats stats;
1291 1316
1317 bpf_prog_get_stats(prog, &stats);
1292 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); 1318 bin2hex(prog_tag, prog->tag, sizeof(prog->tag));
1293 seq_printf(m, 1319 seq_printf(m,
1294 "prog_type:\t%u\n" 1320 "prog_type:\t%u\n"
1295 "prog_jited:\t%u\n" 1321 "prog_jited:\t%u\n"
1296 "prog_tag:\t%s\n" 1322 "prog_tag:\t%s\n"
1297 "memlock:\t%llu\n" 1323 "memlock:\t%llu\n"
1298 "prog_id:\t%u\n", 1324 "prog_id:\t%u\n"
1325 "run_time_ns:\t%llu\n"
1326 "run_cnt:\t%llu\n",
1299 prog->type, 1327 prog->type,
1300 prog->jited, 1328 prog->jited,
1301 prog_tag, 1329 prog_tag,
1302 prog->pages * 1ULL << PAGE_SHIFT, 1330 prog->pages * 1ULL << PAGE_SHIFT,
1303 prog->aux->id); 1331 prog->aux->id,
1332 stats.nsecs,
1333 stats.cnt);
1304} 1334}
1305#endif 1335#endif
1306 1336
@@ -2122,6 +2152,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
2122 struct bpf_prog_info __user *uinfo = u64_to_user_ptr(attr->info.info); 2152 struct bpf_prog_info __user *uinfo = u64_to_user_ptr(attr->info.info);
2123 struct bpf_prog_info info = {}; 2153 struct bpf_prog_info info = {};
2124 u32 info_len = attr->info.info_len; 2154 u32 info_len = attr->info.info_len;
2155 struct bpf_prog_stats stats;
2125 char __user *uinsns; 2156 char __user *uinsns;
2126 u32 ulen; 2157 u32 ulen;
2127 int err; 2158 int err;
@@ -2161,6 +2192,10 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
2161 if (err) 2192 if (err)
2162 return err; 2193 return err;
2163 2194
2195 bpf_prog_get_stats(prog, &stats);
2196 info.run_time_ns = stats.nsecs;
2197 info.run_cnt = stats.cnt;
2198
2164 if (!capable(CAP_SYS_ADMIN)) { 2199 if (!capable(CAP_SYS_ADMIN)) {
2165 info.jited_prog_len = 0; 2200 info.jited_prog_len = 0;
2166 info.xlated_prog_len = 0; 2201 info.xlated_prog_len = 0;