Skip to content

Commit aba64c7

Browse files
davemarchevskyanakryiko
authored andcommitted
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. Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20211020074818.1017682-2-davemarchevsky@fb.com
1 parent 632f96d commit aba64c7

5 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎include/linux/bpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ struct bpf_prog_aux {
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5620,6 +5620,7 @@ struct bpf_prog_info {
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‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,15 +1848,17 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)
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,
18551856
prog->pages * 1ULL << PAGE_SHIFT,
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,
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14033,6 +14033,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr)
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5620,6 +5620,7 @@ struct bpf_prog_info {
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 {

0 commit comments

Comments
 (0)