Skip to content

Commit a7c19db

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
bpf: add bpffs pretty print for program array map
Added bpffs pretty print for program array map. For a particular array index, if the program array points to a valid program, the "<index>: <prog_id>" will be printed out like 0: 6 which means bpf program with id "6" is installed at index "0". Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent f6f3bac commit a7c19db

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

kernel/bpf/arraymap.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,29 @@ static void bpf_fd_array_map_clear(struct bpf_map *map)
553553
fd_array_map_delete_elem(map, &i);
554554
}
555555

556+
static void prog_array_map_seq_show_elem(struct bpf_map *map, void *key,
557+
struct seq_file *m)
558+
{
559+
void **elem, *ptr;
560+
u32 prog_id;
561+
562+
rcu_read_lock();
563+
564+
elem = array_map_lookup_elem(map, key);
565+
if (elem) {
566+
ptr = READ_ONCE(*elem);
567+
if (ptr) {
568+
seq_printf(m, "%u: ", *(u32 *)key);
569+
prog_id = prog_fd_array_sys_lookup_elem(ptr);
570+
btf_type_seq_show(map->btf, map->btf_value_type_id,
571+
&prog_id, m);
572+
seq_puts(m, "\n");
573+
}
574+
}
575+
576+
rcu_read_unlock();
577+
}
578+
556579
const struct bpf_map_ops prog_array_map_ops = {
557580
.map_alloc_check = fd_array_map_alloc_check,
558581
.map_alloc = array_map_alloc,
@@ -564,7 +587,7 @@ const struct bpf_map_ops prog_array_map_ops = {
564587
.map_fd_put_ptr = prog_fd_array_put_ptr,
565588
.map_fd_sys_lookup_elem = prog_fd_array_sys_lookup_elem,
566589
.map_release_uref = bpf_fd_array_map_clear,
567-
.map_check_btf = map_check_no_btf,
590+
.map_seq_show_elem = prog_array_map_seq_show_elem,
568591
};
569592

570593
static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file,

0 commit comments

Comments
 (0)