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
887 struct bpf_prog *prog;887 struct bpf_prog *prog;
888 struct user_struct *user;888 struct user_struct *user;
889 u64 load_time; /* ns since boottime */889 u64 load_time; /* ns since boottime */
890 u32 verified_insns;
890 struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE];891 struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE];
891 char name[BPF_OBJ_NAME_LEN];892 char name[BPF_OBJ_NAME_LEN];
892#ifdef CONFIG_SECURITY893#ifdef CONFIG_SECURITY
include/uapi/linux/bpf.h+1−0
@@ -5620,6 +5620,7 @@ struct bpf_prog_info { · 5619 unmodified lines
5620 __u64 run_time_ns;5620 __u64 run_time_ns;
5621 __u64 run_cnt;5621 __u64 run_cnt;
5622 __u64 recursion_misses;5622 __u64 recursion_misses;
5623 __u32 verified_insns;
5623} __attribute__((aligned(8)));5624} __attribute__((aligned(8)));
5624 5625
5625struct bpf_map_info {5626struct 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
1848 "prog_id:\t%u\n"1848 "prog_id:\t%u\n"
1849 "run_time_ns:\t%llu\n"1849 "run_time_ns:\t%llu\n"
1850 "run_cnt:\t%llu\n"1850 "run_cnt:\t%llu\n"
1851 "recursion_misses:\t%llu\n",1851 "recursion_misses:\t%llu\n"
1852 "verified_insns:\t%u\n",
1852 prog->type,1853 prog->type,
1853 prog->jited,1854 prog->jited,
1854 prog_tag,1855 prog_tag,
@@ -1856,7 +1857,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) · 1 unmodified line
1856 prog->aux->id,1857 prog->aux->id,
1857 stats.nsecs,1858 stats.nsecs,
1858 stats.cnt,1859 stats.cnt,
1859 stats.misses);1860 stats.misses,
1861 prog->aux->verified_insns);
1860}1862}
1861#endif1863#endif
1862 1864
@@ -3625,6 +3627,8 @@ static int bpf_prog_get_info_by_fd(struct file *file, · 1762 unmodified lines
3625 info.run_cnt = stats.cnt;3627 info.run_cnt = stats.cnt;
3626 info.recursion_misses = stats.misses;3628 info.recursion_misses = stats.misses;
3627 3629
3630 info.verified_insns = prog->aux->verified_insns;
3631
3628 if (!bpf_capable()) {3632 if (!bpf_capable()) {
3629 info.jited_prog_len = 0;3633 info.jited_prog_len = 0;
3630 info.xlated_prog_len = 0;3634 info.xlated_prog_len = 0;
kernel/bpf/verifier.c+1−0
@@ -14033,6 +14033,7 @@ skip_full_check: · 14032 unmodified lines
14033 14033
14034 env->verification_time = ktime_get_ns() - start_time;14034 env->verification_time = ktime_get_ns() - start_time;
14035 print_verification_stats(env);14035 print_verification_stats(env);
14036 env->prog->aux->verified_insns = env->insn_processed;
14036 14037
14037 if (log->level && bpf_verifier_log_full(log))14038 if (log->level && bpf_verifier_log_full(log))
14038 ret = -ENOSPC;14039 ret = -ENOSPC;
tools/include/uapi/linux/bpf.h+1−0
@@ -5620,6 +5620,7 @@ struct bpf_prog_info { · 5619 unmodified lines
5620 __u64 run_time_ns;5620 __u64 run_time_ns;
5621 __u64 run_cnt;5621 __u64 run_cnt;
5622 __u64 recursion_misses;5622 __u64 recursion_misses;
5623 __u32 verified_insns;
5623} __attribute__((aligned(8)));5624} __attribute__((aligned(8)));
5624 5625
5625struct bpf_map_info {5626struct 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