Skip to content

Commit 815581c

Browse files
sandip4nborkmann
authored andcommitted
bpf: get JITed image lengths of functions via syscall
This adds new two new fields to struct bpf_prog_info. For multi-function programs, these fields can be used to pass a list of the JITed image lengths of each function for a given program to userspace using the bpf system call with the BPF_OBJ_GET_INFO_BY_FD command. This can be used by userspace applications like bpftool to split up the contiguous JITed dump, also obtained via the system call, into more relatable chunks corresponding to each function. Signed-off-by: Sandipan Das <sandipan@linux.vnet.ibm.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 4d56a76 commit 815581c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,9 @@ struct bpf_prog_info {
22062206
__u64 netns_dev;
22072207
__u64 netns_ino;
22082208
__u32 nr_jited_ksyms;
2209+
__u32 nr_jited_func_lens;
22092210
__aligned_u64 jited_ksyms;
2211+
__aligned_u64 jited_func_lens;
22102212
} __attribute__((aligned(8)));
22112213

22122214
struct bpf_map_info {

kernel/bpf/syscall.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,26 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
20372037
}
20382038
}
20392039

2040+
ulen = info.nr_jited_func_lens;
2041+
info.nr_jited_func_lens = prog->aux->func_cnt;
2042+
if (info.nr_jited_func_lens && ulen) {
2043+
if (bpf_dump_raw_ok()) {
2044+
u32 __user *user_lens;
2045+
u32 func_len, i;
2046+
2047+
/* copy the JITed image lengths for each function */
2048+
ulen = min_t(u32, info.nr_jited_func_lens, ulen);
2049+
user_lens = u64_to_user_ptr(info.jited_func_lens);
2050+
for (i = 0; i < ulen; i++) {
2051+
func_len = prog->aux->func[i]->jited_len;
2052+
if (put_user(func_len, &user_lens[i]))
2053+
return -EFAULT;
2054+
}
2055+
} else {
2056+
info.jited_func_lens = 0;
2057+
}
2058+
}
2059+
20402060
done:
20412061
if (copy_to_user(uinfo, &info, info_len) ||
20422062
put_user(info_len, &uattr->info.info_len))

0 commit comments

Comments
 (0)