]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - kernel/bpf/sysfs_btf.c
Merge tag 'pci-v5.15-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[mirror_ubuntu-jammy-kernel.git] / kernel / bpf / sysfs_btf.c
CommitLineData
341dfcf8
AN
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Provide kernel BTF information for introspection and use by eBPF tools.
4 */
5#include <linux/kernel.h>
6#include <linux/module.h>
7#include <linux/kobject.h>
8#include <linux/init.h>
9#include <linux/sysfs.h>
10
11/* See scripts/link-vmlinux.sh, gen_btf() func for details */
90ceddcb
FS
12extern char __weak __start_BTF[];
13extern char __weak __stop_BTF[];
341dfcf8
AN
14
15static ssize_t
7fd78568
AN
16btf_vmlinux_read(struct file *file, struct kobject *kobj,
17 struct bin_attribute *bin_attr,
18 char *buf, loff_t off, size_t len)
341dfcf8 19{
90ceddcb 20 memcpy(buf, __start_BTF + off, len);
341dfcf8
AN
21 return len;
22}
23
7fd78568
AN
24static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {
25 .attr = { .name = "vmlinux", .mode = 0444, },
26 .read = btf_vmlinux_read,
341dfcf8
AN
27};
28
36e68442 29struct kobject *btf_kobj;
341dfcf8 30
7fd78568 31static int __init btf_vmlinux_init(void)
341dfcf8 32{
e23bb04b
TA
33 bin_attr_btf_vmlinux.size = __stop_BTF - __start_BTF;
34
35 if (!__start_BTF || bin_attr_btf_vmlinux.size == 0)
341dfcf8
AN
36 return 0;
37
38 btf_kobj = kobject_create_and_add("btf", kernel_kobj);
e0325006
WY
39 if (!btf_kobj)
40 return -ENOMEM;
341dfcf8 41
7fd78568 42 return sysfs_create_bin_file(btf_kobj, &bin_attr_btf_vmlinux);
341dfcf8
AN
43}
44
7fd78568 45subsys_initcall(btf_vmlinux_init);