History

bpf: Add verified_insns to bpf_prog_info and fdinfo

This stat is currently printed in the verifier log and not stored anywhere. To ease consumption of this data, add a field to bpf_prog_aux so it can be exposed via BPF_OBJ_GET_INFO_BY_FD and fdinfo.

Dave Marchevsky committed 5 years ago

Commit aba64c71 parent 632f96d5 files · +10 −2Browse files

Unified · Split

5 files
  1. include/linux/bpf.h +1 −0
  2. include/uapi/linux/bpf.h +1 −0
  3. kernel/bpf/syscall.c +6 −2
  4. kernel/bpf/verifier.c +1 −0
  5. tools/include/uapi/linux/bpf.h +1 −0
include/linux/bpf.h+1−0
@@ -887,6 +887,7 @@ struct bpf_prog_aux { · 886 unmodified lines
887887 struct bpf_prog *prog;
888888 struct user_struct *user;
889889 u64 load_time; /* ns since boottime */
890+ u32 verified_insns;
890891 struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE];
891892 char name[BPF_OBJ_NAME_LEN];
892893 #ifdef CONFIG_SECURITY
include/uapi/linux/bpf.h+1−0
@@ -5620,6 +5620,7 @@ struct bpf_prog_info { · 5619 unmodified lines
56205620 __u64 run_time_ns;
56215621 __u64 run_cnt;
56225622 __u64 recursion_misses;
5623+ __u32 verified_insns;
56235624 } __attribute__((aligned(8)));
56245625
56255626 struct bpf_map_info {
kernel/bpf/syscall.c+6−2
@@ -1848,7 +1848,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) · 1847 unmodified lines
18481848 "prog_id:\t%u\n"
18491849 "run_time_ns:\t%llu\n"
18501850 "run_cnt:\t%llu\n"
1851− "recursion_misses:\t%llu\n",
1851+ "recursion_misses:\t%llu\n"
1852+ "verified_insns:\t%u\n",
18521853 prog->type,
18531854 prog->jited,
18541855 prog_tag,
@@ -1856,7 +1857,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) · 1 unmodified line
18561857 prog->aux->id,
18571858 stats.nsecs,
18581859 stats.cnt,
1859− stats.misses);
1860+ stats.misses,
1861+ prog->aux->verified_insns);
18601862 }
18611863 #endif
18621864
@@ -3625,6 +3627,8 @@ static int bpf_prog_get_info_by_fd(struct file *file, · 1762 unmodified lines
36253627 info.run_cnt = stats.cnt;
36263628 info.recursion_misses = stats.misses;
36273629
3630+ info.verified_insns = prog->aux->verified_insns;
3631+
36283632 if (!bpf_capable()) {
36293633 info.jited_prog_len = 0;
36303634 info.xlated_prog_len = 0;
kernel/bpf/verifier.c+1−0
@@ -14033,6 +14033,7 @@ skip_full_check: · 14032 unmodified lines
1403314033
1403414034 env->verification_time = ktime_get_ns() - start_time;
1403514035 print_verification_stats(env);
14036+ env->prog->aux->verified_insns = env->insn_processed;
1403614037
1403714038 if (log->level && bpf_verifier_log_full(log))
1403814039 ret = -ENOSPC;
tools/include/uapi/linux/bpf.h+1−0
@@ -5620,6 +5620,7 @@ struct bpf_prog_info { · 5619 unmodified lines
56205620 __u64 run_time_ns;
56215621 __u64 run_cnt;
56225622 __u64 recursion_misses;
5623+ __u32 verified_insns;
56235624 } __attribute__((aligned(8)));
56245625
56255626 struct bpf_map_info {

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