Skip to content

Commit 0e6f601

Browse files
author
Alexei Starovoitov
committed
Merge branch 'Integrate kernel module BTF support'
Andrii Nakryiko says: ==================== This patch set adds BTF generation for kernel modules using a compact split BTF approach. Respective patches have all the details. Kernel module BTFs rely on pahole's split BTF support, which is added in [0] and will be available starting from v1.19. Support for it is detected automatically during kernel build time. This patch set implements in-kernel support for split BTF loading and validation. It also extends GET_OBJ_INFO API for BTFs to return BTF's module name and a flag whether BTF itself is in-kernel or user-provided. vmlinux BTF is also exposed to user-space through the same BTF object iteration APIs. Follow up patch set will utilize the fact that vmlinux and module BTFs now have associated ID to provide ability to attach BPF fentry/fexit/etc programs to functions defined in kernel modules. bpftool is also extended to show module/vmlinux BTF's name. [0] https://patchwork.kernel.org/project/netdevbpf/list/?series=378699&state=* v3->v4: - copy_to_user() on ENOSPC in btf_get_info_by_fd() (Martin); v2->v3: - get rid of unnecessary gotos (Song); v2->v1: - drop WARNs, add fewer pr_warn()'s instead (Greg); - properly initialize sysfs binary attribute structure (Greg); - add __maybe_unused to any_section_objs, used conditionally by module BTF; rfc->v1: - CONFIG_DEBUG_INFO_BTF_MODULES is derived automatically (Alexei); - vmlinux BTF now has explicit "vmlinux" name (Alexei); - added sysfs ABI documentation for /sys/kernel/btf/<module> (Greg). Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> ==================== Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents f52b8fd + cecaf4a commit 0e6f601

File tree

11 files changed

+459
-58
lines changed

11 files changed

+459
-58
lines changed

Documentation/ABI/testing/sysfs-kernel-btf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ Description:
1515
information with description of all internal kernel types. See
1616
Documentation/bpf/btf.rst for detailed description of format
1717
itself.
18+
19+
What: /sys/kernel/btf/<module-name>
20+
Date: Nov 2020
21+
KernelVersion: 5.11
22+
23+
Description:
24+
Read-only binary attribute exposing kernel module's BTF type
25+
information as an add-on to the kernel's BTF (/sys/kernel/btf/vmlinux).

include/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ struct seq_operations;
3636
struct bpf_iter_aux_info;
3737
struct bpf_local_storage;
3838
struct bpf_local_storage_map;
39+
struct kobject;
3940

4041
extern struct idr btf_idr;
4142
extern spinlock_t btf_idr_lock;
43+
extern struct kobject *btf_kobj;
4244

4345
typedef int (*bpf_iter_init_seq_priv_t)(void *private_data,
4446
struct bpf_iter_aux_info *aux);

include/linux/module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ struct module {
475475
unsigned int num_bpf_raw_events;
476476
struct bpf_raw_event_map *bpf_raw_events;
477477
#endif
478+
#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
479+
unsigned int btf_data_size;
480+
void *btf_data;
481+
#endif
478482
#ifdef CONFIG_JUMP_LABEL
479483
struct jump_entry *jump_entries;
480484
unsigned int num_jump_entries;

include/uapi/linux/bpf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4466,6 +4466,9 @@ struct bpf_btf_info {
44664466
__aligned_u64 btf;
44674467
__u32 btf_size;
44684468
__u32 id;
4469+
__aligned_u64 name;
4470+
__u32 name_len;
4471+
__u32 kernel_btf;
44694472
} __attribute__((aligned(8)));
44704473

44714474
struct bpf_link_info {

0 commit comments

Comments
 (0)