AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/09 13:48 flow patch-triage
25m Args:
null

Results:
{
  "EnableConfigs": [
    "DEBUG_INFO_BTF_INLINE",
    "DEBUG_INFO_BTF",
    "DEBUG_INFO_BTF_MODULES",
    "BPF_SYSCALL",
    "SYSFS",
    "MODULES"
  ],
  "FocusSymbols": [
    "btf_set_base_btf",
    "btf_rebase_inline",
    "btf_parse_split",
    "btf_parse_module",
    "btf_module_handle_vmlinux_inline",
    "btf_module_notify",
    "btf_sysfs_read_lazy",
    "btf_sysfs_mmap_lazy",
    "btf_sysfs_mmap_image",
    "sysfs_btf_add",
    "btf_relocate"
  ],
  "KMSANReasoning": "The patch series introduces support for inline BTF generation and sysfs exposure (/sys/kernel/btf/*.inline), adding parsing, relocation, and sysfs handling for .BTF.inline sections in vmlinux and loadable modules.\n\nHolistic analysis of memory initialization and user-space transfers shows:\n1. Memory Allocations:\n   - In `btf_parse_split()`, `struct btf` is allocated with `kzalloc_obj()`, ensuring all fields are zeroed, and `btf-\u003edata` is copied with `kvmemdup()`.\n   - In `sysfs_btf_add()`, `struct btf_sysfs_entry` is allocated with `kzalloc_obj()`.\n   - In `btf_relocate()`, the relocation maps (`id_map` and `str_map`) are allocated with `calloc()`, which maps to `kvcalloc()` in the kernel build, ensuring zero-initialization.\n   - In `btf_module_handle_vmlinux_inline()`, the buffer exposed to sysfs is allocated with `vmalloc_user()`, which explicitly zero-initializes all pages (`GFP_KERNEL | __GFP_ZERO`), preventing uninitialized slack bytes across page boundaries when mmapped.\n\n2. User-Space Exposure:\n   - Data is exposed only via sysfs binary attributes (`/sys/kernel/btf/*`). Reads use `sysfs_bin_attr_simple_read()` or `btf_sysfs_read_lazy()` using bounded copies from fully populated buffers.\n   - Mmaps use `remap_vmalloc_range()` on `vmalloc_user()` memory or `remap_pfn_range()` on dedicated, page-aligned image sections. No kernel struct padding or uninitialized memory is copied to user space.\n\n3. KASAN vs. KMSAN:\n   - Potential risks in the new relocation logic (such as buffer bounds or indexing into `module_str_map` / `module_id_map`) or lifecycle management of sysfs attributes during module unloading represent out-of-bounds accesses or use-after-free/double-free conditions, which are detectable by KASAN.\n   - No uninitialized memory reads or information leak hazards are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch introduces inline BTF support (.BTF.inline sections) along with kernel infrastructure to parse, rebase, and relocate inline BTF upon module loading, and exposes it through sysfs entries supporting lazy loading, reading, and mmap operations. These changes modify reachable core BPF, sysfs, and module loader execution paths accessible via syscalls like init_module/finit_module, read, and mmap.",
  "WorthFuzzing": true
}

1/1 2026/10/09 13:48 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit f2fd4fe68b2b0fd38f8b379496a376e8764bd384\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Oct 9 13:48:00 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/.gitignore b/.gitignore\nindex 9875120ea7bde..d54bdaac99813 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -72,6 +72,7 @@ modules.order\n /vmlinux.symvers\n /vmlinux.thinlto-index\n /vmlinux.unstripped\n+/vmlinux.BTF.inline\n /vmlinux-gdb.py\n /vmlinuz\n /System.map\ndiff --git a/Makefile b/Makefile\nindex 6b8b812f23b92..b3053dd3c1059 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1769,6 +1769,7 @@ endif # CONFIG_MODULES\n CLEAN_FILES += vmlinux.symvers modules-only.symvers \\\n \t       modules.builtin modules.builtin.modinfo modules.nsdeps \\\n \t       modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \\\n+\t       vmlinux.BTF.inline \\\n \t       vmlinux.thinlto-index builtin.order \\\n \t       compile_commands.json rust/test \\\n \t       rust-project.json .vmlinux.objs .vmlinux.export.c \\\ndiff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h\nindex b2988aa12f664..b17251bc63f5d 100644\n--- a/include/asm-generic/vmlinux.lds.h\n+++ b/include/asm-generic/vmlinux.lds.h\n@@ -675,12 +675,43 @@\n /*\n  * .BTF\n  */\n+#ifdef CONFIG_DEBUG_INFO_BTF_INLINE\n+#define BTF_INLINE\t\t\t\t\t\t\t\\\n+\t. = ALIGN(PAGE_SIZE);\t\t\t\t\t\t\\\n+\t.BTF.inline : AT(ADDR(.BTF.inline) - LOAD_OFFSET) {\t\t\\\n+\t\tBOUNDED_SECTION_BY(.BTF.inline, _BTF_inline)\t\t\\\n+\t}\n+#else\n+#define BTF_INLINE\n+#endif\n+\n+#ifdef CONFIG_DEBUG_INFO_BTF_INLINE_MODULE\n+/* __MODULE_NAME_LEN + SHA-256 digest + u32 BTF size */\n+#ifdef CONFIG_64BIT\n+#define BTF_LINK_SIZE\t(64 - 8 + 32 + 4)\n+#else\n+#define BTF_LINK_SIZE\t(64 - 4 + 32 + 4)\n+#endif\n+#define BTF_INLINE_LINK\t\t\t\t\t\t\\\n+\t. = ALIGN(PAGE_SIZE);\t\t\t\t\t\\\n+\t.BTF.inline.link : AT(ADDR(.BTF.inline.link) - LOAD_OFFSET) { \\\n+\t\t__start_BTF_inline_link = .;\t\t\t\t\\\n+\t\tBYTE(0)\t\t\t\t\t\t\\\n+\t\t. += BTF_LINK_SIZE - 1;\t\t\t\t\t\\\n+\t\t__stop_BTF_inline_link = .;\t\t\t\t\\\n+\t}\n+#else\n+#define BTF_INLINE_LINK\n+#endif\n+\n #ifdef CONFIG_DEBUG_INFO_BTF\n #define BTF\t\t\t\t\t\t\t\t\\\n \t. = ALIGN(PAGE_SIZE);\t\t\t\t\t\t\\\n \t.BTF : AT(ADDR(.BTF) - LOAD_OFFSET) {\t\t\t\t\\\n \t\tBOUNDED_SECTION_BY(.BTF, _BTF)\t\t\t\t\\\n \t}\t\t\t\t\t\t\t\t\\\n+\tBTF_INLINE\t\t\t\t\t\t\t\\\n+\tBTF_INLINE_LINK\t\t\t\t\t\t\\\n \t. = ALIGN(PAGE_SIZE);\t\t\t\t\t\t\\\n \t.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) {\t\t\t\\\n \t\t*(.BTF_ids)\t\t\t\t\t\t\\\ndiff --git a/include/linux/btf.h b/include/linux/btf.h\nindex 4b63bb91550a1..b66e20a18c54f 100644\n--- a/include/linux/btf.h\n+++ b/include/linux/btf.h\n@@ -5,6 +5,7 @@\n #define _LINUX_BTF_H 1\n \n #include \u003clinux/types.h\u003e\n+#include \u003clinux/module.h\u003e\n #include \u003clinux/bpfptr.h\u003e\n #include \u003clinux/bsearch.h\u003e\n #include \u003clinux/btf_ids.h\u003e\n@@ -118,6 +119,19 @@ struct btf_show;\n struct btf_id_set;\n struct bpf_prog;\n \n+#define BTF_LINK_SHA256_LEN\t32\n+\n+/*\n+ * A .BTF.link or .BTF.inline.link section identifies the module which\n+ * carries a vmlinux BTF section.  The module name is NUL terminated and the\n+ * field is padded to __MODULE_NAME_LEN.\n+ */\n+struct btf_link {\n+\tchar module_name[__MODULE_NAME_LEN];\n+\tu8 sha256[BTF_LINK_SHA256_LEN];\n+\tu32 btf_size;\n+} __packed;\n+\n typedef int (*btf_kfunc_filter_t)(const struct bpf_prog *prog, u32 kfunc_id);\n \n struct btf_kfunc_id_set {\n@@ -594,7 +608,8 @@ struct btf_field_iter {\n #ifdef CONFIG_BPF_SYSCALL\n const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);\n void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\n-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids);\n+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids,\n+\t\t __u32 **map_strs);\n int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n \t\t\tenum btf_field_iter_kind iter_kind);\n __u32 *btf_field_iter_next(struct btf_field_iter *it);\n@@ -624,6 +639,29 @@ bool btf_types_are_same(const struct btf *btf1, u32 id1,\n \t\t\tconst struct btf *btf2, u32 id2);\n int btf_check_iter_arg(struct btf *btf, const struct btf_type *func, int arg_idx);\n \n+#if IS_ENABLED(CONFIG_SYSFS)\n+struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,\n+\t\t\t\t    bool mmap, const char *lazy_module_name);\n+bool sysfs_btf_update(struct bin_attribute *attr, void *data);\n+void sysfs_btf_remove(struct bin_attribute *attr);\n+#else\n+static inline struct bin_attribute *\n+sysfs_btf_add(const char *name, void *data, size_t data_size, bool mmap,\n+\t      const char *lazy_module_name)\n+{\n+\treturn NULL;\n+}\n+\n+static inline bool sysfs_btf_update(struct bin_attribute *attr, void *data)\n+{\n+\treturn false;\n+}\n+\n+static inline void sysfs_btf_remove(struct bin_attribute *attr)\n+{\n+}\n+#endif\n+\n static inline bool btf_type_is_struct_ptr(struct btf *btf, const struct btf_type *t)\n {\n \tif (!btf_type_is_ptr(t))\n@@ -645,7 +683,7 @@ static inline void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\n }\n \n static inline int btf_relocate(void *log, struct btf *btf, const struct btf *base_btf,\n-\t\t\t       __u32 **map_ids)\n+\t\t\t       __u32 **map_ids, __u32 **map_strs)\n {\n \treturn -EOPNOTSUPP;\n }\ndiff --git a/include/linux/module.h b/include/linux/module.h\nindex 96cc98568eea5..a6abde12a458f 100644\n--- a/include/linux/module.h\n+++ b/include/linux/module.h\n@@ -503,6 +503,10 @@ struct module {\n \tvoid *btf_data;\n \tvoid *btf_base_data;\n #endif\n+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)\n+\tunsigned int btf_inline_data_size;\n+\tvoid *btf_inline_data;\n+#endif\n #ifdef CONFIG_JUMP_LABEL\n \tstruct jump_entry *jump_entries;\n \tunsigned int num_jump_entries;\ndiff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile\nindex c1f9b0d3468d3..37e62ef450791 100644\n--- a/kernel/bpf/Makefile\n+++ b/kernel/bpf/Makefile\n@@ -42,6 +42,7 @@ obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o\n endif\n ifeq ($(CONFIG_SYSFS),y)\n obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o\n+obj-$(CONFIG_DEBUG_INFO_BTF_INLINE) += btf_vmlinux_inline.o\n endif\n ifeq ($(CONFIG_BPF_JIT),y)\n obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o\ndiff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c\nindex 0630675377aaa..29599ab7449ed 100644\n--- a/kernel/bpf/btf.c\n+++ b/kernel/bpf/btf.c\n@@ -25,11 +25,12 @@\n #include \u003clinux/skmsg.h\u003e\n #include \u003clinux/perf_event.h\u003e\n #include \u003clinux/bsearch.h\u003e\n-#include \u003clinux/kobject.h\u003e\n #include \u003clinux/string.h\u003e\n-#include \u003clinux/sysfs.h\u003e\n #include \u003clinux/overflow.h\u003e\n #include \u003clinux/bitops.h\u003e\n+#include \u003clinux/unaligned.h\u003e\n+#include \u003clinux/vmalloc.h\u003e\n+#include \u003ccrypto/sha2.h\u003e\n \n #include \u003cnet/netfilter/nf_bpf_link.h\u003e\n \n@@ -1935,7 +1936,7 @@ void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\n {\n \tbtf-\u003ebase_btf = (struct btf *)base_btf;\n \tbtf-\u003estart_id = btf_nr_types(base_btf);\n-\tbtf-\u003estart_str_off = base_btf-\u003ehdr.str_len;\n+\tbtf-\u003estart_str_off = base_btf-\u003estart_str_off + base_btf-\u003ehdr.str_len;\n }\n \n static int env_resolve_init(struct btf_verifier_env *env)\n@@ -6921,15 +6922,137 @@ __u32 btf_relocate_id(const struct btf *btf, __u32 id)\n \n #ifdef CONFIG_DEBUG_INFO_BTF_MODULES\n \n+static struct btf *btf_parse_split(struct btf_verifier_env *env,\n+\t\t\t\t   const char *name, const void *data,\n+\t\t\t\t   unsigned int data_size, struct btf *base_btf)\n+{\n+\tstruct btf *btf;\n+\tint err;\n+\n+\tbtf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);\n+\tif (!btf)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\tenv-\u003ebtf = btf;\n+\n+\tbtf_set_base_btf(btf, base_btf);\n+\tbtf-\u003ekernel_btf = true;\n+\tbtf-\u003enamed_start_id = 0;\n+\tstrscpy(btf-\u003ename, name);\n+\n+\tbtf-\u003edata = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);\n+\tif (!btf-\u003edata) {\n+\t\terr = -ENOMEM;\n+\t\tgoto errout;\n+\t}\n+\tbtf-\u003edata_size = data_size;\n+\n+\terr = btf_parse_hdr(env);\n+\tif (err)\n+\t\tgoto errout;\n+\n+\tbtf-\u003enohdr_data = btf-\u003edata + btf-\u003ehdr.hdr_len;\n+\n+\terr = btf_parse_str_sec(env);\n+\tif (err)\n+\t\tgoto errout;\n+\n+\terr = btf_check_all_metas(env);\n+\tif (err)\n+\t\tgoto errout;\n+\n+\terr = btf_check_modifier_chain_length(env, btf, btf_nr_types(base_btf));\n+\tif (err)\n+\t\tgoto errout;\n+\n+\treturn btf;\n+\n+errout:\n+\tbtf_free(btf);\n+\treturn ERR_PTR(err);\n+}\n+\n+static int btf_rebase_inline(struct btf *inline_btf,\n+\t\t\t     const struct btf *module_btf,\n+\t\t\t     const u32 *module_id_map,\n+\t\t\t     const u32 *module_str_map,\n+\t\t\t     u32 old_module_type_cnt)\n+{\n+\tu32 old_start_id = inline_btf-\u003estart_id;\n+\tu32 old_start_str_off = inline_btf-\u003estart_str_off;\n+\tu32 old_module_start_str_off = old_start_str_off - module_btf-\u003ehdr.str_len;\n+\tu32 new_start_id = btf_nr_types(module_btf);\n+\tu32 new_start_str_off = module_btf-\u003estart_str_off + module_btf-\u003ehdr.str_len;\n+\ts64 id_delta = (s64)new_start_id - old_start_id;\n+\ts64 str_delta = (s64)new_start_str_off - old_start_str_off;\n+\tu32 i;\n+\n+\t/*\n+\t * The inline BTF was parsed relative to the original module BTF. Its\n+\t * base IDs must therefore use the map generated when that BTF was\n+\t * relocated, while IDs for inline-local types only move by the change\n+\t * in the module BTF's starting ID.\n+\t */\n+\tfor (i = 0; i \u003c inline_btf-\u003enr_types; i++) {\n+\t\tstruct btf_field_iter it;\n+\t\tstruct btf_type *t = inline_btf-\u003etypes[i];\n+\t\tu32 *id, *str_off;\n+\t\tint err;\n+\n+\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\twhile ((id = btf_field_iter_next(\u0026it))) {\n+\t\t\tif (!*id)\n+\t\t\t\tcontinue;\n+\t\t\tif (*id \u003c old_module_type_cnt) {\n+\t\t\t\tif (module_id_map)\n+\t\t\t\t\t*id = module_id_map[*id];\n+\t\t\t} else if (*id \u003e= old_start_id) {\n+\t\t\t\t*id += id_delta;\n+\t\t\t} else {\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\t\t}\n+\n+\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\twhile ((str_off = btf_field_iter_next(\u0026it))) {\n+\t\t\tif (!*str_off)\n+\t\t\t\tcontinue;\n+\t\t\tif (*str_off \u003c old_module_start_str_off) {\n+\t\t\t\t/* Vmlinux strings retain their offsets for in-tree modules. */\n+\t\t\t\tif (!module_id_map)\n+\t\t\t\t\tcontinue;\n+\t\t\t\tif (!module_str_map || !module_str_map[*str_off])\n+\t\t\t\t\treturn -EINVAL;\n+\t\t\t\t*str_off = module_str_map[*str_off];\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\t*str_off += str_delta;\n+\t\t}\n+\t}\n+\n+\tbtf_set_base_btf(inline_btf, module_btf);\n+\tbtf_check_sorted(inline_btf);\n+\treturn 0;\n+}\n+\n static struct btf *btf_parse_module(const char *module_name, const void *data,\n \t\t\t\t    unsigned int data_size, void *base_data,\n-\t\t\t\t    unsigned int base_data_size)\n+\t\t\t\t    unsigned int base_data_size,\n+\t\t\t\t    const void *inline_data,\n+\t\t\t\t    unsigned int inline_data_size,\n+\t\t\t\t    void **relocated_inline_data)\n {\n-\tstruct btf *btf = NULL, *vmlinux_btf, *base_btf = NULL;\n+\tstruct btf *btf = NULL, *inline_btf = NULL, *vmlinux_btf, *base_btf = NULL;\n \tstruct btf_verifier_env *env = NULL;\n \tstruct bpf_verifier_log *log;\n+\tu32 *module_str_map = NULL;\n+\tu32 old_module_type_cnt;\n \tint err = 0;\n \n+\t*relocated_inline_data = NULL;\n \tvmlinux_btf = bpf_get_btf_vmlinux();\n \tif (IS_ERR(vmlinux_btf))\n \t\treturn vmlinux_btf;\n@@ -6953,67 +7076,68 @@ static struct btf *btf_parse_module(const char *module_name, const void *data,\n \t\tbase_btf = vmlinux_btf;\n \t}\n \n-\tbtf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);\n-\tif (!btf) {\n-\t\terr = -ENOMEM;\n+\tbtf = btf_parse_split(env, module_name, data, data_size, base_btf);\n+\tif (IS_ERR(btf)) {\n+\t\terr = PTR_ERR(btf);\n+\t\tbtf = NULL;\n \t\tgoto errout;\n \t}\n-\tenv-\u003ebtf = btf;\n-\n-\tbtf-\u003ebase_btf = base_btf;\n-\tbtf-\u003estart_id = base_btf-\u003enr_types;\n-\tbtf-\u003estart_str_off = base_btf-\u003ehdr.str_len;\n-\tbtf-\u003ekernel_btf = true;\n-\tbtf-\u003enamed_start_id = 0;\n-\tstrscpy(btf-\u003ename, module_name);\n+\told_module_type_cnt = btf_nr_types(btf);\n \n-\tbtf-\u003edata = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);\n-\tif (!btf-\u003edata) {\n-\t\terr = -ENOMEM;\n-\t\tgoto errout;\n+\tif (inline_data_size) {\n+\t\tinline_btf = btf_parse_split(env, module_name, inline_data,\n+\t\t\t\t\t     inline_data_size, btf);\n+\t\tif (IS_ERR(inline_btf)) {\n+\t\t\tpr_warn(\"failed to validate module [%s] inline BTF: %ld\\n\",\n+\t\t\t\tmodule_name, PTR_ERR(inline_btf));\n+\t\t\tinline_btf = NULL;\n+\t\t}\n \t}\n-\tbtf-\u003edata_size = data_size;\n-\n-\terr = btf_parse_hdr(env);\n-\tif (err)\n-\t\tgoto errout;\n-\n-\tbtf-\u003enohdr_data = btf-\u003edata + btf-\u003ehdr.hdr_len;\n-\n-\terr = btf_parse_str_sec(env);\n-\tif (err)\n-\t\tgoto errout;\n-\n-\terr = btf_check_all_metas(env);\n-\tif (err)\n-\t\tgoto errout;\n-\n-\terr = btf_check_modifier_chain_length(env, btf, btf_nr_types(base_btf));\n-\tif (err)\n-\t\tgoto errout;\n \n \tif (base_btf != vmlinux_btf) {\n-\t\terr = btf_relocate(btf, vmlinux_btf, \u0026btf-\u003ebase_id_map);\n+\t\terr = btf_relocate(btf, vmlinux_btf, \u0026btf-\u003ebase_id_map,\n+\t\t\t\t   \u0026module_str_map);\n \t\tif (err)\n \t\t\tgoto errout;\n \t\tbtf_free(base_btf);\n \t\tbase_btf = vmlinux_btf;\n \t}\n \n-\tbtf_verifier_env_free(env);\n+\tif (inline_btf) {\n+\t\terr = btf_rebase_inline(inline_btf, btf, btf-\u003ebase_id_map,\n+\t\t\t\t\tmodule_str_map, old_module_type_cnt);\n+\t\tif (err) {\n+\t\t\tpr_warn(\"failed to relocate module [%s] inline BTF: %d\\n\",\n+\t\t\t\tmodule_name, err);\n+\t\t\tbtf_free(inline_btf);\n+\t\t} else {\n+\t\t\t*relocated_inline_data = inline_btf-\u003edata;\n+\t\t\tinline_btf-\u003edata = NULL;\n+\t\t\tbtf_free(inline_btf);\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * With a distilled base, btf_relocate() replaces the base BTF and\n+\t * rewrites string offsets. Check ordering only after that final BTF\n+\t * view has been established, so named_start_id describes the BTF used\n+\t * by name lookups.\n+\t */\n \tbtf_check_sorted(btf);\n+\tbtf_verifier_env_free(env);\n+\tkvfree(module_str_map);\n \trefcount_set(\u0026btf-\u003erefcnt, 1);\n \treturn btf;\n \n errout:\n+\tkvfree(module_str_map);\n \tbtf_verifier_env_free(env);\n+\tif (inline_btf)\n+\t\tbtf_free(inline_btf);\n \tif (!IS_ERR(base_btf) \u0026\u0026 base_btf != vmlinux_btf)\n \t\tbtf_free(base_btf);\n-\tif (btf) {\n-\t\tkvfree(btf-\u003edata);\n-\t\tkvfree(btf-\u003etypes);\n-\t\tkfree(btf);\n-\t}\n+\tif (btf)\n+\t\tbtf_free(btf);\n \treturn ERR_PTR(err);\n }\n \n@@ -9007,6 +9131,8 @@ struct btf_module {\n \tstruct module *module;\n \tstruct btf *btf;\n \tstruct bin_attribute *sysfs_attr;\n+\tstruct bin_attribute *sysfs_inline_attr;\n+\tvoid *btf_inline_data;\n \tint flags;\n };\n \n@@ -9015,28 +9141,149 @@ static DEFINE_MUTEX(btf_module_mutex);\n \n static void purge_cand_cache(struct btf *btf);\n \n+#if IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE)\n+extern char __start_BTF_inline_link[];\n+extern char __stop_BTF_inline_link[];\n+\n+static struct bin_attribute *vmlinux_inline_attr;\n+static const struct btf_link *vmlinux_inline_link;\n+\n+static const struct btf_link *btf_parse_link(void *start, unsigned int size)\n+{\n+\tconst struct btf_link *link = start;\n+\tunsigned int module_name_len;\n+\n+\tif (!link || size != sizeof(*link) || link-\u003ebtf_size == 0)\n+\t\treturn NULL;\n+\n+\tmodule_name_len = strnlen(link-\u003emodule_name, sizeof(link-\u003emodule_name));\n+\tif (!module_name_len || module_name_len == sizeof(link-\u003emodule_name) ||\n+\t    memchr_inv(link-\u003emodule_name + module_name_len + 1, 0,\n+\t\t       sizeof(link-\u003emodule_name) - module_name_len - 1))\n+\t\treturn NULL;\n+\treturn link;\n+}\n+\n+static bool btf_verify_link(const struct btf_link *link, const struct module *mod,\n+\t\t\t    const void *data, size_t data_size)\n+{\n+\tu8 actual_digest[BTF_LINK_SHA256_LEN];\n+\n+\tif (!link || data_size != link-\u003ebtf_size) {\n+\t\tpr_warn(\" BTF link from module [%s] missing or has unexpected size\\n\", mod-\u003ename);\n+\t\treturn false;\n+\t}\n+\tsha256(data, data_size, actual_digest);\n+\tif (memcmp(actual_digest, link-\u003esha256, sizeof(actual_digest))) {\n+\t\tpr_warn(\"BTF link from module [%s] has unexpected digest\\n\", mod-\u003ename);\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+static void btf_vmlinux_inline_lazy_init(void)\n+{\n+\tvmlinux_inline_link = btf_parse_link(__start_BTF_inline_link,\n+\t\t\t\t\t     __stop_BTF_inline_link -\n+\t\t\t\t\t     __start_BTF_inline_link);\n+\tif (!vmlinux_inline_link) {\n+\t\tpr_warn(\"invalid vmlinux inline BTF link\\n\");\n+\t\treturn;\n+\t}\n+\tvmlinux_inline_attr = sysfs_btf_add(\"vmlinux.inline\", NULL,\n+\t\t\t\t\t    vmlinux_inline_link-\u003ebtf_size, true,\n+\t\t\t\t\t    vmlinux_inline_link-\u003emodule_name);\n+\tif (IS_ERR(vmlinux_inline_attr)) {\n+\t\tpr_warn(\"failed to register vmlinux inline BTF in sysfs: %ld\\n\",\n+\t\t\tPTR_ERR(vmlinux_inline_attr));\n+\t\tvmlinux_inline_attr = NULL;\n+\t}\n+}\n+\n+static bool btf_module_is_vmlinux_inline(const struct module *mod)\n+{\n+\treturn vmlinux_inline_link \u0026\u0026 !strcmp(mod-\u003ename, vmlinux_inline_link-\u003emodule_name);\n+}\n+\n+static int btf_module_handle_vmlinux_inline(const struct module *mod)\n+{\n+\tvoid *data;\n+\n+\tif (!mod-\u003ebtf_inline_data ||\n+\t    mod-\u003ebtf_inline_data_size != vmlinux_inline_link-\u003ebtf_size)\n+\t\treturn -EINVAL;\n+\n+\tdata = vmalloc_user(mod-\u003ebtf_inline_data_size);\n+\tif (!data)\n+\t\treturn -ENOMEM;\n+\tmemcpy(data, mod-\u003ebtf_inline_data, mod-\u003ebtf_inline_data_size);\n+\n+\tif (!btf_verify_link(vmlinux_inline_link, mod, data, mod-\u003ebtf_inline_data_size) ||\n+\t    !sysfs_btf_update(vmlinux_inline_attr, data)) {\n+\t\tkvfree(data);\n+\t\treturn -EINVAL;\n+\t}\n+\treturn 0;\n+}\n+\n+#else\n+\n+static bool btf_module_is_vmlinux_inline(const struct module *mod)\n+{\n+\treturn false;\n+}\n+\n+static int btf_module_handle_vmlinux_inline(const struct module *mod)\n+{\n+\treturn 0;\n+}\n+\n+static void btf_vmlinux_inline_lazy_init(void)\n+{\n+}\n+\n+#endif /* IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE) */\n+\n static int btf_module_notify(struct notifier_block *nb, unsigned long op,\n \t\t\t     void *module)\n {\n \tstruct btf_module *btf_mod, *tmp;\n \tstruct module *mod = module;\n+\tstruct bin_attribute *attr;\n \tstruct btf *btf;\n+\tvoid *inline_data = NULL, *relocated_inline_data = NULL;\n+\tunsigned int inline_data_size = 0;\n \tint err = 0;\n \n-\tif (mod-\u003ebtf_data_size == 0 ||\n-\t    (op != MODULE_STATE_COMING \u0026\u0026 op != MODULE_STATE_LIVE \u0026\u0026\n-\t     op != MODULE_STATE_GOING))\n+\tif (op != MODULE_STATE_COMING \u0026\u0026 op != MODULE_STATE_LIVE \u0026\u0026\n+\t    op != MODULE_STATE_GOING)\n \t\tgoto out;\n \n \tswitch (op) {\n \tcase MODULE_STATE_COMING:\n+\t\tif (btf_module_is_vmlinux_inline(mod)) {\n+\t\t\terr = btf_module_handle_vmlinux_inline(mod);\n+\t\t\tbreak;\n+\t\t}\n+\n+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)\n+\t\tif (mod-\u003ebtf_inline_data_size) {\n+\t\t\tinline_data = mod-\u003ebtf_inline_data;\n+\t\t\tinline_data_size = mod-\u003ebtf_inline_data_size;\n+\t\t}\n+#endif\n+\t\tif (!mod-\u003ebtf_data_size)\n+\t\t\tbreak;\n \t\tbtf_mod = kzalloc_obj(*btf_mod);\n \t\tif (!btf_mod) {\n \t\t\terr = -ENOMEM;\n \t\t\tgoto out;\n \t\t}\n \t\tbtf = btf_parse_module(mod-\u003ename, mod-\u003ebtf_data, mod-\u003ebtf_data_size,\n-\t\t\t\t       mod-\u003ebtf_base_data, mod-\u003ebtf_base_data_size);\n+\t\t\t\t       mod-\u003ebtf_base_data, mod-\u003ebtf_base_data_size,\n+\t\t\t\t       inline_data, inline_data_size,\n+\t\t\t\t       \u0026relocated_inline_data);\n \t\tif (IS_ERR(btf)) {\n \t\t\tkfree(btf_mod);\n \t\t\tif (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) {\n@@ -9051,6 +9298,7 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,\n \t\terr = btf_alloc_id(btf);\n \t\tif (err) {\n \t\t\tbtf_free(btf);\n+\t\t\tkvfree(relocated_inline_data);\n \t\t\tkfree(btf_mod);\n \t\t\tgoto out;\n \t\t}\n@@ -9059,37 +9307,35 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,\n \t\tmutex_lock(\u0026btf_module_mutex);\n \t\tbtf_mod-\u003emodule = module;\n \t\tbtf_mod-\u003ebtf = btf;\n+\t\tbtf_mod-\u003ebtf_inline_data = relocated_inline_data;\n \t\tlist_add(\u0026btf_mod-\u003elist, \u0026btf_modules);\n \t\tmutex_unlock(\u0026btf_module_mutex);\n \n-\t\tif (IS_ENABLED(CONFIG_SYSFS)) {\n-\t\t\tstruct bin_attribute *attr;\n-\n-\t\t\tattr = kzalloc_obj(*attr);\n-\t\t\tif (!attr)\n-\t\t\t\tgoto out;\n+\t\tattr = sysfs_btf_add(btf-\u003ename, btf-\u003edata, btf-\u003edata_size, false, NULL);\n+\t\tif (IS_ERR(attr)) {\n+\t\t\terr = 0;\n+\t\t\tgoto out;\n+\t\t}\n+\t\tbtf_mod-\u003esysfs_attr = attr;\n \n-\t\t\tsysfs_bin_attr_init(attr);\n-\t\t\tattr-\u003eattr.name = btf-\u003ename;\n-\t\t\tattr-\u003eattr.mode = 0444;\n-\t\t\tattr-\u003esize = btf-\u003edata_size;\n-\t\t\tattr-\u003eprivate = btf-\u003edata;\n-\t\t\tattr-\u003eread = sysfs_bin_attr_simple_read;\n+\t\tif (relocated_inline_data) {\n+\t\t\tchar name[MODULE_NAME_LEN + sizeof(\".inline\")];\n \n-\t\t\terr = sysfs_create_bin_file(btf_kobj, attr);\n-\t\t\tif (err) {\n-\t\t\t\tpr_warn(\"failed to register module [%s] BTF in sysfs: %d\\n\",\n-\t\t\t\t\tmod-\u003ename, err);\n-\t\t\t\tkfree(attr);\n+\t\t\tsnprintf(name, sizeof(name), \"%s.inline\", mod-\u003ename);\n+\t\t\tattr = sysfs_btf_add(name, relocated_inline_data,\n+\t\t\t\t\t     inline_data_size, false, NULL);\n+\t\t\tif (IS_ERR(attr)) {\n+\t\t\t\tkvfree(relocated_inline_data);\n+\t\t\t\tbtf_mod-\u003ebtf_inline_data = NULL;\n \t\t\t\terr = 0;\n-\t\t\t\tgoto out;\n+\t\t\t\tbreak;\n \t\t\t}\n-\n-\t\t\tbtf_mod-\u003esysfs_attr = attr;\n+\t\t\tbtf_mod-\u003esysfs_inline_attr = attr;\n \t\t}\n-\n \t\tbreak;\n \tcase MODULE_STATE_LIVE:\n+\t\tif (!mod-\u003ebtf_data_size)\n+\t\t\tbreak;\n \t\tmutex_lock(\u0026btf_module_mutex);\n \t\tlist_for_each_entry_safe(btf_mod, tmp, \u0026btf_modules, list) {\n \t\t\tif (btf_mod-\u003emodule != module)\n@@ -9101,6 +9347,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,\n \t\tmutex_unlock(\u0026btf_module_mutex);\n \t\tbreak;\n \tcase MODULE_STATE_GOING:\n+\t\tif (!mod-\u003ebtf_data_size)\n+\t\t\tbreak;\n \t\tmutex_lock(\u0026btf_module_mutex);\n \t\tlist_for_each_entry_safe(btf_mod, tmp, \u0026btf_modules, list) {\n \t\t\tif (btf_mod-\u003emodule != module)\n@@ -9115,10 +9363,12 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,\n \t\t\tbtf_free_id(btf_mod-\u003ebtf);\n \t\t\tlist_del(\u0026btf_mod-\u003elist);\n \t\t\tif (btf_mod-\u003esysfs_attr)\n-\t\t\t\tsysfs_remove_bin_file(btf_kobj, btf_mod-\u003esysfs_attr);\n+\t\t\t\tsysfs_btf_remove(btf_mod-\u003esysfs_attr);\n+\t\t\tif (btf_mod-\u003esysfs_inline_attr)\n+\t\t\t\tsysfs_btf_remove(btf_mod-\u003esysfs_inline_attr);\n+\t\t\tkvfree(btf_mod-\u003ebtf_inline_data);\n \t\t\tpurge_cand_cache(btf_mod-\u003ebtf);\n \t\t\tbtf_put(btf_mod-\u003ebtf);\n-\t\t\tkfree(btf_mod-\u003esysfs_attr);\n \t\t\tkfree(btf_mod);\n \t\t\tbreak;\n \t\t}\n@@ -9135,6 +9385,7 @@ static struct notifier_block btf_module_nb = {\n \n static int __init btf_module_init(void)\n {\n+\tbtf_vmlinux_inline_lazy_init();\n \tregister_module_notifier(\u0026btf_module_nb);\n \treturn 0;\n }\ndiff --git a/kernel/bpf/btf_vmlinux_inline.c b/kernel/bpf/btf_vmlinux_inline.c\nnew file mode 100644\nindex 0000000000000..d5c599d9f7295\n--- /dev/null\n+++ b/kernel/bpf/btf_vmlinux_inline.c\n@@ -0,0 +1,29 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026, Oracle and/or its affiliates. */\n+/*\n+ * Provide kernel BTF inline function information for use by BPF tools.\n+ */\n+#include \u003clinux/btf.h\u003e\n+#include \u003clinux/init.h\u003e\n+#include \u003clinux/kernel.h\u003e\n+#include \u003clinux/module.h\u003e\n+\n+#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)\n+extern char __start_BTF_inline[];\n+extern char __stop_BTF_inline[];\n+#endif\n+\n+static int __init btf_vmlinux_inline_init(void)\n+{\n+#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)\n+\tsize_t data_size = __stop_BTF_inline - __start_BTF_inline;\n+\n+\tif (data_size)\n+\t\tsysfs_btf_add(\"vmlinux.inline\", __start_BTF_inline, data_size, true, NULL);\n+#endif\n+\treturn 0;\n+}\n+subsys_initcall(btf_vmlinux_inline_init);\n+\n+MODULE_DESCRIPTION(\"BTF inline information for vmlinux\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c\nindex 9cbe15ce3540c..556fe92c36495 100644\n--- a/kernel/bpf/sysfs_btf.c\n+++ b/kernel/bpf/sysfs_btf.c\n@@ -6,8 +6,10 @@\n #include \u003clinux/module.h\u003e\n #include \u003clinux/kobject.h\u003e\n #include \u003clinux/init.h\u003e\n+#include \u003clinux/slab.h\u003e\n #include \u003clinux/sysfs.h\u003e\n #include \u003clinux/mm.h\u003e\n+#include \u003clinux/vmalloc.h\u003e\n #include \u003clinux/io.h\u003e\n #include \u003clinux/btf.h\u003e\n \n@@ -15,16 +17,12 @@\n extern char __start_BTF[];\n extern char __stop_BTF[];\n \n-static int btf_sysfs_vmlinux_mmap(struct file *filp, struct kobject *kobj,\n-\t\t\t\t  const struct bin_attribute *attr,\n-\t\t\t\t  struct vm_area_struct *vma)\n+static int btf_sysfs_mmap_check(void *data, size_t size, struct vm_area_struct *vma)\n {\n-\tunsigned long pages = PAGE_ALIGN(attr-\u003esize) \u003e\u003e PAGE_SHIFT;\n+\tunsigned long pages = PAGE_ALIGN(size) \u003e\u003e PAGE_SHIFT;\n \tsize_t vm_size = vma-\u003evm_end - vma-\u003evm_start;\n-\tphys_addr_t addr = __pa_symbol(__start_BTF);\n-\tunsigned long pfn = addr \u003e\u003e PAGE_SHIFT;\n \n-\tif (attr-\u003eprivate != __start_BTF || !PAGE_ALIGNED(addr))\n+\tif (!data || !PAGE_ALIGNED((unsigned long)data))\n \t\treturn -EINVAL;\n \n \tif (vma-\u003evm_pgoff)\n@@ -33,24 +31,153 @@ static int btf_sysfs_vmlinux_mmap(struct file *filp, struct kobject *kobj,\n \tif (vma-\u003evm_flags \u0026 (VM_WRITE | VM_EXEC | VM_MAYSHARE))\n \t\treturn -EACCES;\n \n-\tif (pfn + pages \u003c pfn)\n-\t\treturn -EINVAL;\n-\n \tif ((vm_size \u003e\u003e PAGE_SHIFT) \u003e pages)\n \t\treturn -EINVAL;\n \n \tvm_flags_mod(vma, VM_DONTDUMP, VM_MAYEXEC | VM_MAYWRITE);\n+\treturn 0;\n+}\n+\n+static int btf_sysfs_mmap_image(struct file *filp, struct kobject *kobj,\n+\t\t\t\tconst struct bin_attribute *attr,\n+\t\t\t\tstruct vm_area_struct *vma)\n+{\n+\tvoid *data = READ_ONCE(attr-\u003eprivate);\n+\tphys_addr_t addr;\n+\tunsigned long pfn;\n+\tsize_t vm_size = vma-\u003evm_end - vma-\u003evm_start;\n+\tint err;\n+\n+\terr = btf_sysfs_mmap_check(data, attr-\u003esize, vma);\n+\tif (err)\n+\t\treturn err;\n+\n+\t/* Kernel image addresses can lie inside the vmalloc range on arm64. */\n+\taddr = __pa_symbol(data);\n+\tpfn = addr \u003e\u003e PAGE_SHIFT;\n+\tif (pfn + (PAGE_ALIGN(attr-\u003esize) \u003e\u003e PAGE_SHIFT) \u003c pfn)\n+\t\treturn -EINVAL;\n+\n \treturn remap_pfn_range(vma, vma-\u003evm_start, pfn, vm_size, vma-\u003evm_page_prot);\n }\n \n static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {\n \t.attr = { .name = \"vmlinux\", .mode = 0444, },\n \t.read = sysfs_bin_attr_simple_read,\n-\t.mmap = btf_sysfs_vmlinux_mmap,\n+\t.mmap = btf_sysfs_mmap_image,\n };\n \n struct kobject *btf_kobj;\n \n+struct btf_sysfs_entry {\n+\tstruct bin_attribute attr;\n+\tchar *module_name;\n+};\n+\n+static void *btf_sysfs_lazy_data(const struct bin_attribute *attr)\n+{\n+\tstruct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);\n+\tvoid *data;\n+\n+\tdata = smp_load_acquire(\u0026attr-\u003eprivate);\n+\tif (!data) {\n+\t\trequest_module(\"%s\", entry-\u003emodule_name);\n+\t\tdata = smp_load_acquire(\u0026attr-\u003eprivate);\n+\t}\n+\treturn data;\n+}\n+\n+static ssize_t btf_sysfs_read_lazy(struct file *filp, struct kobject *kobj,\n+\t\t\t\t   const struct bin_attribute *attr, char *buf,\n+\t\t\t\t   loff_t off, size_t count)\n+{\n+\tvoid *data = btf_sysfs_lazy_data(attr);\n+\n+\tif (!data)\n+\t\treturn -ENODEV;\n+\n+\treturn memory_read_from_buffer(buf, count, \u0026off, data, attr-\u003esize);\n+}\n+\n+static int btf_sysfs_mmap_lazy(struct file *filp, struct kobject *kobj,\n+\t\t\t       const struct bin_attribute *attr,\n+\t\t\t       struct vm_area_struct *vma)\n+{\n+\tvoid *data = btf_sysfs_lazy_data(attr);\n+\tint err;\n+\n+\tif (!data)\n+\t\treturn -ENODEV;\n+\n+\terr = btf_sysfs_mmap_check(data, attr-\u003esize, vma);\n+\tif (err)\n+\t\treturn err;\n+\n+\treturn remap_vmalloc_range(vma, data, 0);\n+}\n+\n+struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,\n+\t\t\t\t    bool mmap, const char *lazy_module_name)\n+{\n+\tstruct btf_sysfs_entry *entry;\n+\tstruct bin_attribute *attr;\n+\tint err;\n+\n+\tentry = kzalloc_obj(*entry);\n+\tif (!entry)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tattr = \u0026entry-\u003eattr;\n+\tsysfs_bin_attr_init(attr);\n+\tattr-\u003eattr.mode = 0444;\n+\tattr-\u003esize = data_size;\n+\tattr-\u003eprivate = data;\n+\tattr-\u003eread = lazy_module_name ? btf_sysfs_read_lazy : sysfs_bin_attr_simple_read;\n+\tif (mmap)\n+\t\tattr-\u003emmap = lazy_module_name ? btf_sysfs_mmap_lazy : btf_sysfs_mmap_image;\n+\tattr-\u003eattr.name = kstrdup(name, GFP_KERNEL);\n+\tif (!attr-\u003eattr.name) {\n+\t\terr = -ENOMEM;\n+\t\tgoto err_free;\n+\t}\n+\tif (lazy_module_name) {\n+\t\tentry-\u003emodule_name = kstrdup(lazy_module_name, GFP_KERNEL);\n+\t\tif (!entry-\u003emodule_name) {\n+\t\t\terr = -ENOMEM;\n+\t\t\tgoto err_free;\n+\t\t}\n+\t}\n+\n+\terr = sysfs_create_bin_file(btf_kobj, attr);\n+\tif (err) {\n+\t\tpr_warn(\"failed to register [%s] BTF in sysfs: %d\\n\", name, err);\n+\t\tgoto err_free;\n+\t}\n+\n+\treturn attr;\n+\n+err_free:\n+\tkfree(entry-\u003emodule_name);\n+\tkfree(attr-\u003eattr.name);\n+\tkfree(entry);\n+\treturn ERR_PTR(err);\n+}\n+\n+bool sysfs_btf_update(struct bin_attribute *attr, void *data)\n+{\n+\treturn attr \u0026\u0026 !cmpxchg(\u0026attr-\u003eprivate, NULL, data);\n+}\n+\n+void sysfs_btf_remove(struct bin_attribute *attr)\n+{\n+\tstruct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);\n+\n+\tsysfs_remove_bin_file(btf_kobj, attr);\n+\tkfree(entry-\u003emodule_name);\n+\tkfree(attr-\u003eattr.name);\n+\tkfree(entry);\n+}\n+\n static int __init btf_vmlinux_init(void)\n {\n \tbin_attr_btf_vmlinux.private = __start_BTF;\ndiff --git a/kernel/module/main.c b/kernel/module/main.c\nindex c1b34dc1e89ac..5b9eb56164b29 100644\n--- a/kernel/module/main.c\n+++ b/kernel/module/main.c\n@@ -2723,6 +2723,10 @@ static int find_module_sections(struct module *mod, struct load_info *info)\n \tmod-\u003ebtf_base_data = any_section_objs(info, \".BTF.base\", 1,\n \t\t\t\t\t      \u0026mod-\u003ebtf_base_data_size);\n #endif\n+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)\n+\tmod-\u003ebtf_inline_data = any_section_objs(info, \".BTF.inline\", 1,\n+\t\t\t\t\t\t\u0026mod-\u003ebtf_inline_data_size);\n+#endif\n #ifdef CONFIG_JUMP_LABEL\n \tmod-\u003ejump_entries = section_objs(info, \"__jump_table\",\n \t\t\t\t\tsizeof(*mod-\u003ejump_entries),\n@@ -3176,6 +3180,9 @@ static noinline int do_init_module(struct module *mod)\n \t/* .BTF is not SHF_ALLOC and will get removed, so sanitize pointers */\n \tmod-\u003ebtf_data = NULL;\n \tmod-\u003ebtf_base_data = NULL;\n+#endif\n+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)\n+\tmod-\u003ebtf_inline_data = NULL;\n #endif\n \t/*\n \t * We want to free module_init, but be aware that kallsyms may be\ndiff --git a/lib/Kconfig.debug b/lib/Kconfig.debug\nindex 134b15a44625e..2f34619905b60 100644\n--- a/lib/Kconfig.debug\n+++ b/lib/Kconfig.debug\n@@ -425,6 +425,12 @@ config PAHOLE_HAS_LANG_EXCLUDE\n \t  otherwise it would emit malformed kernel and module binaries when\n \t  using DEBUG_INFO_BTF_MODULES.\n \n+config PAHOLE_HAS_INLINE\n+\tdef_bool PAHOLE_VERSION \u003e= 132\n+\thelp\n+\t  Support for the \"inline\" BTF feature is available. It encodes\n+\t  information about inline sites and how to retrieve their parameters.\n+\n config DEBUG_INFO_BTF_MODULES\n \tbool \"Generate BTF type information for kernel modules\"\n \tdefault y\n@@ -432,6 +438,18 @@ config DEBUG_INFO_BTF_MODULES\n \thelp\n \t  Generate compact split BTF type information for kernel modules.\n \n+config DEBUG_INFO_BTF_INLINE\n+\ttristate \"Provide information about inline sites in BTF\"\n+\tdefault n\n+\tdepends on DEBUG_INFO_BTF \u0026\u0026 PAHOLE_HAS_INLINE \u0026\u0026 SYSFS\n+\tselect DEBUG_INFO_BTF_MODULES if MODULES\n+\thelp\n+\t  Generate information about inline sites in .BTF.inline sections.\n+\t  These sections contain split BTF relative to the kernel or module BTF\n+\t  and are made available in /sys/kernel/btf with a \".inline\" suffix.\n+\t  The information describes inline locations and how to retrieve their\n+\t  associated parameters.\n+\n config MODULE_ALLOW_BTF_MISMATCH\n \tbool \"Allow loading modules with non-matching BTF type info\"\n \tdepends on DEBUG_INFO_BTF_MODULES\ndiff --git a/scripts/Makefile.btf b/scripts/Makefile.btf\nindex a1812985a61aa..98012344a81ec 100644\n--- a/scripts/Makefile.btf\n+++ b/scripts/Makefile.btf\n@@ -22,7 +22,14 @@ endif\n \n pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE)\t\t+= --lang_exclude=rust\n \n+btf-inline := $(CONFIG_DEBUG_INFO_BTF_INLINE)\n+ifneq ($(btf-inline),)\n+btf-inline-feat := inline\n+pahole-flags-$(call test-ge, $(pahole-ver), 132) += --btf_features=$(btf-inline-feat)\n+endif\n+\n export PAHOLE_FLAGS := $(pahole-flags-y)\n+export BTF_INLINE := $(btf-inline)\n \n resolve-btfids-flags-y :=\n resolve-btfids-flags-$(CONFIG_WERROR) += --fatal_warnings\ndiff --git a/scripts/gen-btf.sh b/scripts/gen-btf.sh\nindex 8ca96eb10a69e..b17f1189298a5 100755\n--- a/scripts/gen-btf.sh\n+++ b/scripts/gen-btf.sh\n@@ -68,6 +68,7 @@ esac\n \n gen_btf_data()\n {\n+\tinline=${BTF_INLINE:+--inline}\n \tbtf1=\"${ELF_FILE}.BTF.1\"\n \t${PAHOLE} -J ${PAHOLE_FLAGS}\t\t\t\\\n \t\t${BTF_BASE:+--btf_base ${BTF_BASE}}\t\\\n@@ -76,6 +77,7 @@ gen_btf_data()\n \n \t${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_FLAGS}\t\\\n \t\t${BTF_BASE:+--btf_base ${BTF_BASE}}\t\\\n+\t\t${inline}\t\t\t\t\\\n \t\t--btf ${btf1} \"${ELF_FILE}\"\n }\n \n@@ -83,14 +85,28 @@ gen_btf_o()\n {\n \tbtf_data=${ELF_FILE}.btf.o\n \n-\t# Create ${btf_data} which contains just .BTF section but no symbols. Add\n+\t# Create ${btf_data} which contains just BTF sections but no symbols. Add\n \t# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all\n \t# deletes all symbols including __start_BTF and __stop_BTF, which will\n \t# be redefined in the linker script.\n \techo \"\" | ${CC} ${CLANG_FLAGS} ${KBUILD_CPPFLAGS} ${KBUILD_CFLAGS} -fno-lto -c -x c -o ${btf_data} -\n \t${OBJCOPY} --add-section .BTF=${ELF_FILE}.BTF \\\n \t\t--set-section-flags .BTF=alloc,readonly ${btf_data}\n-\t${OBJCOPY} --only-section=.BTF --strip-all ${btf_data}\n+\tONLY_SEC=\"--only-section=.BTF\"\n+\tbtf_inline=${ELF_FILE}.BTF.inline\n+\tif [ \"${BTF_INLINE}\" = \"m\" ]; then\n+\t\tif [ -f \"${btf_inline}\" ]; then\n+\t\t\tcp \"${btf_inline}\" \"${objtree}/vmlinux.BTF.inline\"\n+\t\telse\n+\t\t\trm -f \"${objtree}/vmlinux.BTF.inline\"\n+\t\tfi\n+\tfi\n+\tif [ \"${BTF_INLINE}\" = \"y\" ] \u0026\u0026 [ -f \"${btf_inline}\" ]; then\n+\t\t${OBJCOPY} --add-section .BTF.inline=${btf_inline} \\\n+\t\t\t--set-section-flags .BTF.inline=alloc,readonly ${btf_data}\n+\t\tONLY_SEC=\"${ONLY_SEC} --only-section=.BTF.inline\"\n+\tfi\n+\t${OBJCOPY} ${ONLY_SEC} --strip-all ${btf_data}\n \n \t# Change e_type to ET_REL so that it can be used to link final vmlinux.\n \t# GNU ld 2.35+ and lld do not allow an ET_EXEC input.\n@@ -111,6 +127,15 @@ embed_btf_data()\n \tif [ -f \"${btf_base}\" ]; then\n \t\t${OBJCOPY} --add-section .BTF.base=${btf_base} ${ELF_FILE}\n \tfi\n+\tbtf_inline=${ELF_FILE}.BTF.inline\n+\tcase \"${ELF_FILE}\" in\n+\t*/btf_vmlinux_inline.ko)\n+\t\tbtf_inline=${BTF_BASE}.BTF.inline\n+\t\t;;\n+\tesac\n+\tif [ -n \"${BTF_INLINE}\" ] \u0026\u0026 [ -f \"${btf_inline}\" ]; then\n+\t\t${OBJCOPY} --add-section .BTF.inline=${btf_inline} ${ELF_FILE}\n+\tfi\n \tbtf_ids=\"${ELF_FILE}.BTF_ids\"\n \tif [ -f \"${btf_ids}\" ]; then\n \t\t${RESOLVE_BTFIDS} --patch_btfids ${btf_ids} ${ELF_FILE}\n@@ -121,6 +146,8 @@ cleanup()\n {\n \trm -f \"${ELF_FILE}.BTF.1\"\n \trm -f \"${ELF_FILE}.BTF\"\n+\trm -f \"${ELF_FILE}.BTF.inline\"\n+\trm -f \"${ELF_FILE}.BTF.inline.link\"\n \tif [ \"${BTFGEN_MODE}\" = \"module\" ]; then\n \t\trm -f \"${ELF_FILE}.BTF.base\"\n \t\trm -f \"${ELF_FILE}.BTF_ids\"\ndiff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh\nindex ab0b8125c8cbc..5424caf5135bc 100755\n--- a/scripts/link-vmlinux.sh\n+++ b/scripts/link-vmlinux.sh\n@@ -289,7 +289,13 @@ vmlinux_link \"${VMLINUX}\"\n \n if is_enabled CONFIG_DEBUG_INFO_BTF; then\n \tinfo BTFIDS ${VMLINUX}\n-\t${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}\n+\tif [ \"${BTF_INLINE}\" = \"m\" ]; then\n+\t\t${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} \\\n+\t\t\t--btf_link .BTF.inline:btf_vmlinux_inline:vmlinux.BTF.inline \\\n+\t\t\t${VMLINUX}\n+\telse\n+\t\t${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}\n+\tfi\n fi\n \n mksysmap \"${VMLINUX}\" System.map\ndiff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec\nindex 46e80970f7239..8f0933cbbe452 100644\n--- a/scripts/package/kernel.spec\n+++ b/scripts/package/kernel.spec\n@@ -68,13 +68,13 @@ This package provides debug information for the kernel image and modules from th\n %undefine _debugsource_packages\n %undefine _debuginfo_subpackages\n \n-# Preserve .BTF and .BTF.base sections in kernel modules during debuginfo\n-# stripping. find-debuginfo.sh uses eu-strip which removes non-allocated ELF\n-# sections like .BTF by default. .BTF.base is required for BTF distillation\n-# support; without it, module BTF validation fails.\n+# Preserve .BTF,  .BTF.base and .BTF.inline sections in kernel modules during\n+# debuginfo stripping. find-debuginfo.sh uses eu-strip which removes\n+# non-allocated ELF sections like .BTF by default. .BTF.base is required for\n+# BTF distillation support; without it, module BTF validation fails.\n %global with_keep_section %(%{__find_debuginfo} --help 2\u003e\u00261 | grep -c keep-section)\n %if %{with_keep_section}\n-%global _find_debuginfo_opts -r --keep-section .BTF --keep-section .BTF.base\n+%global _find_debuginfo_opts -r --keep-section .BTF --keep-section .BTF.base --keep-section .BTF.inline\n %else\n %global _find_debuginfo_opts -r\n %endif\ndiff --git a/tools/bpf/resolve_btfids/Build b/tools/bpf/resolve_btfids/Build\nindex 077de3829c722..602e1508bf092 100644\n--- a/tools/bpf/resolve_btfids/Build\n+++ b/tools/bpf/resolve_btfids/Build\n@@ -1,6 +1,7 @@\n hostprogs := resolve_btfids\n \n resolve_btfids-y += main.o\n+resolve_btfids-y += btf_colors.o\n resolve_btfids-y += rbtree.o\n resolve_btfids-y += zalloc.o\n resolve_btfids-y += string.o\ndiff --git a/tools/bpf/resolve_btfids/btf_colors.c b/tools/bpf/resolve_btfids/btf_colors.c\nnew file mode 100644\nindex 0000000000000..5d307d70e7f22\n--- /dev/null\n+++ b/tools/bpf/resolve_btfids/btf_colors.c\n@@ -0,0 +1,145 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+#include \u003cbpf/libbpf_internal.h\u003e\n+#include \"btf_colors.h\"\n+\n+/*\n+ * Functions in this file mainly exist to refer to functions from libbpf_internal.h,\n+ * which can't be included in main.c because of the u32 poison and pr_warn macro conflicts.\n+ */\n+\n+void btf_sha256(const void *data, size_t len,\n+\t\t__u8 out[BTF_SHA256_DIGEST_LENGTH])\n+{\n+\tlibbpf_sha256(data, len, out);\n+}\n+\n+/*\n+ * Marks `root_id` and local types reachable from it with `color`.\n+ * `colors` is indexed by source ID; worklist has room for every local type.\n+ */\n+void btf_mark_reachable(struct btf *btf, __u32 root_id, enum btf_color color,\n+\t\t\t__u8 *colors, __u32 *worklist)\n+{\n+\tconst struct btf *base = btf__base_btf(btf);\n+\t__u32 start_id = base ? btf__type_cnt(base) : 1;\n+\t__u32 pending = 0;\n+\n+\tif (root_id \u003c start_id || (colors[root_id] \u0026 color) == color)\n+\t\treturn;\n+\tcolors[root_id] |= color;\n+\tworklist[pending++] = root_id;\n+\twhile (pending) {\n+\t\tconst struct btf_type *t = btf__type_by_id(btf, worklist[--pending]);\n+\t\tstruct btf_field_iter it;\n+\t\t__u32 *id;\n+\n+\t\tbtf_field_iter_init(\u0026it, (struct btf_type *)t, BTF_FIELD_ITER_IDS);\n+\t\twhile ((id = btf_field_iter_next(\u0026it))) {\n+\t\t\tif (*id \u003c start_id || (colors[*id] \u0026 color) == color)\n+\t\t\t\tcontinue;\n+\t\t\tcolors[*id] |= color;\n+\t\t\tworklist[pending++] = *id;\n+\t\t}\n+\t}\n+}\n+\n+static int cmp_loc(const void *a, const void *b)\n+{\n+\tconst struct btf_loc *la = a, *lb = b;\n+\n+\tif (la-\u003efunc != lb-\u003efunc)\n+\t\treturn la-\u003efunc \u003c lb-\u003efunc ? -1 : 1;\n+\tif (la-\u003eoffset != lb-\u003eoffset)\n+\t\treturn la-\u003eoffset \u003c lb-\u003eoffset ? -1 : 1;\n+\tif (la-\u003eloc_proto != lb-\u003eloc_proto)\n+\t\treturn la-\u003eloc_proto \u003c lb-\u003eloc_proto ? -1 : 1;\n+\treturn 0;\n+}\n+\n+static void remap(struct btf *btf, const __u32 *id_map, __u32 src_start_id)\n+{\n+\tconst struct btf *base = btf__base_btf(btf);\n+\t__u32 start_id = base ? btf__type_cnt(base) : 1;\n+\t__u32 i, type_cnt = btf__type_cnt(btf);\n+\n+\tfor (i = start_id; i \u003c type_cnt; i++) {\n+\t\tstruct btf_type *t = (struct btf_type *)btf__type_by_id(btf, i);\n+\t\tstruct btf_field_iter it;\n+\t\t__u32 *id;\n+\n+\t\tbtf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\n+\t\twhile ((id = btf_field_iter_next(\u0026it))) {\n+\t\t\t/* Void and types in the original ancestor are unchanged. */\n+\t\t\tif (*id \u003e= src_start_id)\n+\t\t\t\t*id = id_map[*id - src_start_id];\n+\t\t}\n+\t\tif (btf_is_locsec(t))\n+\t\t\tqsort(btf_locsec_locs(t), btf_vlen(t), sizeof(struct btf_loc), cmp_loc);\n+\t}\n+}\n+\n+/*\n+ * Split the `src` into `main_out` base and `inline_out`,\n+ * according to `colors` array. Relative ordering remains\n+ * the same as in `src`.\n+ */\n+int btf_split_by_color(struct btf *src, const __u8 *colors,\n+\t\t       struct btf **main_out, struct btf **inline_out)\n+{\n+\tLIBBPF_OPTS(btf_new_opts, opts,\n+\t\t    .base_btf = (struct btf *)btf__base_btf(src),\n+\t\t    .add_layout = btf_header(src)-\u003elayout_len != 0,\n+\t);\n+\tstruct btf *main_btf, *inline_btf = NULL;\n+\t__u32 start_id = opts.base_btf ? btf__type_cnt(opts.base_btf) : 1;\n+\t__u32 type_cnt = btf__type_cnt(src);\n+\t__u32 *id_map, i;\n+\tint err = -ENOMEM;\n+\n+\t*main_out = NULL;\n+\t*inline_out = NULL;\n+\tid_map = malloc((type_cnt - start_id ?: 1) * sizeof(*id_map));\n+\tif (!id_map)\n+\t\treturn -ENOMEM;\n+\tmain_btf = btf__new_empty_opts(\u0026opts);\n+\tif (!main_btf)\n+\t\tgoto out;\n+\tbtf__set_endianness(main_btf, btf__endianness(src));\n+\t/* Copy MAIN and SHARED marked types to `main_out`. */\n+\tfor (i = start_id; i \u003c type_cnt; i++) {\n+\t\tif (colors[i] == BTF_COLOR_LOC)\n+\t\t\tcontinue;\n+\t\terr = btf__add_type(main_btf, src, btf__type_by_id(src, i));\n+\t\tif (err \u003c 0)\n+\t\t\tgoto out;\n+\t\tid_map[i - start_id] = err;\n+\t}\n+\t/*\n+\t * Copy LOC marked types to `inline_out`.\n+\t * `main_btf` types count is stable at this point.\n+\t */\n+\tinline_btf = btf__new_empty_split(main_btf);\n+\tif (!inline_btf) {\n+\t\terr = -ENOMEM;\n+\t\tgoto out;\n+\t}\n+\tfor (i = start_id; i \u003c type_cnt; i++) {\n+\t\tif (colors[i] != BTF_COLOR_LOC)\n+\t\t\tcontinue;\n+\t\terr = btf__add_type(inline_btf, src, btf__type_by_id(src, i));\n+\t\tif (err \u003c 0)\n+\t\t\tgoto out;\n+\t\tid_map[i - start_id] = err;\n+\t}\n+\tremap(main_btf, id_map, start_id);\n+\tremap(inline_btf, id_map, start_id);\n+\t*main_out = main_btf;\n+\t*inline_out = inline_btf;\n+\tfree(id_map);\n+\treturn 0;\n+out:\n+\tbtf__free(inline_btf);\n+\tbtf__free(main_btf);\n+\tfree(id_map);\n+\treturn err;\n+}\ndiff --git a/tools/bpf/resolve_btfids/btf_colors.h b/tools/bpf/resolve_btfids/btf_colors.h\nnew file mode 100644\nindex 0000000000000..56a85a242d6bd\n--- /dev/null\n+++ b/tools/bpf/resolve_btfids/btf_colors.h\n@@ -0,0 +1,24 @@\n+/* SPDX-License-Identifier: GPL-2.0-only */\n+#ifndef __RESOLVE_BTFIDS_BTF_COLORS_H\n+#define __RESOLVE_BTFIDS_BTF_COLORS_H\n+\n+#include \u003cbpf/btf.h\u003e\n+\n+enum btf_color {\n+\tBTF_COLOR_NONE = 0,\n+\tBTF_COLOR_MAIN = 1,\n+\tBTF_COLOR_LOC = 2,\n+\tBTF_COLOR_SHARED = BTF_COLOR_MAIN | BTF_COLOR_LOC,\n+};\n+\n+#define BTF_SHA256_DIGEST_LENGTH\t32\n+\n+void btf_sha256(const void *data, size_t len,\n+\t\t__u8 out[BTF_SHA256_DIGEST_LENGTH]);\n+void btf_mark_reachable(struct btf *btf, __u32 root, enum btf_color color,\n+\t\t\t__u8 *colors, __u32 *worklist);\n+\n+int btf_split_by_color(struct btf *src, const __u8 *colors,\n+\t\t       struct btf **main_out, struct btf **inline_out);\n+\n+#endif\ndiff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c\nindex 37d7e7224207d..f737fac60fa24 100644\n--- a/tools/bpf/resolve_btfids/main.c\n+++ b/tools/bpf/resolve_btfids/main.c\n@@ -89,9 +89,11 @@\n #include \u003clinux/limits.h\u003e\n #include \u003cbpf/btf.h\u003e\n #include \u003cbpf/libbpf.h\u003e\n+#include \"btf_colors.h\"\n #include \u003csubcmd/parse-options.h\u003e\n \n #define BTF_IDS_SECTION\t\".BTF_ids\"\n+#define BTF_LINK_MODULE_NAME_MAX\t64\n #define BTF_ID_PREFIX\t\"__BTF_ID__\"\n \n #define BTF_STRUCT\t\"struct\"\n@@ -142,7 +144,10 @@ struct object {\n \n \tstruct btf *btf;\n \tstruct btf *base_btf;\n+\tstruct btf *inline_btf;\n+\tstruct btf *orig_btf;\n \tbool distill_base;\n+\tbool extract_inline;\n \n \tstruct {\n \t\tint\t\t fd;\n@@ -154,6 +159,11 @@ struct object {\n \t\tsize_t\t\t strtabidx;\n \t\tunsigned long\t idlist_addr;\n \t\tint\t\t encoding;\n+\t\tint\t\t elf_class;\n+\t\tconst char\t**func_symbols;\n+\t\tu32\t\t func_symbols_cnt;\n+\t\tu32\t\t func_symbols_cap;\n+\t\tbool\t\t func_symbols_collected;\n \t} efile;\n \n \tstruct rb_root\tsets;\n@@ -172,6 +182,19 @@ struct object {\n \tu32 addr_syms_cap;\n };\n \n+struct btf_link {\n+\tchar *value;\n+\tchar *section;\n+\tchar *module;\n+\tchar *btf_path;\n+};\n+\n+struct btf_links {\n+\tstruct btf_link *links;\n+\tu32 cnt;\n+\tu32 cap;\n+};\n+\n #define DECL_TAG_FASTCALL \"bpf_fastcall\"\n #define DECL_TAG_KFUNC \"bpf_kfunc\"\n \n@@ -259,6 +282,49 @@ static int __ensure_mem(void **data, u32 *cap, u32 cnt, size_t elem_sz)\n #define ensure_mem(arr_ptr, cap_ptr, cnt) \\\n \t__ensure_mem((void **)(arr_ptr), (cap_ptr), (cnt), sizeof(**(arr_ptr)))\n \n+static int parse_btf_link(const struct option *opt, const char *arg, int unset)\n+{\n+\tstruct btf_links *links = opt-\u003evalue;\n+\tstruct btf_link *link;\n+\tchar *separator;\n+\n+\tif (unset)\n+\t\treturn -EINVAL;\n+\tif (__ensure_mem((void **)\u0026links-\u003elinks, \u0026links-\u003ecap, links-\u003ecnt + 1,\n+\t\t\t sizeof(*links-\u003elinks)))\n+\t\treturn -ENOMEM;\n+\tlink = \u0026links-\u003elinks[links-\u003ecnt];\n+\tmemset(link, 0, sizeof(*link));\n+\tlink-\u003evalue = strdup(arg);\n+\tif (!link-\u003evalue)\n+\t\treturn -ENOMEM;\n+\tlink-\u003esection = link-\u003evalue;\n+\tseparator = strchr(link-\u003esection, ':');\n+\tif (!separator || separator == link-\u003esection)\n+\t\tgoto err_value;\n+\t*separator++ = '\\0';\n+\tlink-\u003emodule = separator;\n+\tseparator = strchr(link-\u003emodule, ':');\n+\tif (!separator || separator == link-\u003emodule || !separator[1])\n+\t\tgoto err_value;\n+\t*separator++ = '\\0';\n+\tlink-\u003ebtf_path = separator;\n+\tlinks-\u003ecnt++;\n+\treturn 0;\n+err_value:\n+\tfree(link-\u003evalue);\n+\treturn -EINVAL;\n+}\n+\n+static void free_btf_links(struct btf_links *links)\n+{\n+\tu32 i;\n+\n+\tfor (i = 0; i \u003c links-\u003ecnt; i++)\n+\t\tfree(links-\u003elinks[i].value);\n+\tfree(links-\u003elinks);\n+}\n+\n static bool is_btf_id(const char *name)\n {\n \treturn name \u0026\u0026 !strncmp(name, BTF_ID_PREFIX, sizeof(BTF_ID_PREFIX) - 1);\n@@ -480,6 +546,7 @@ static int elf_collect(struct object *obj)\n \t\treturn -1;\n \t}\n \tobj-\u003eefile.encoding = ehdr.e_ident[EI_DATA];\n+\tobj-\u003eefile.elf_class = ehdr.e_ident[EI_CLASS];\n \n \t/*\n \t * Scan all the elf sections and look for save data\n@@ -572,6 +639,58 @@ static const char *find_name_by_addr(struct object *obj, Elf64_Addr addr)\n \treturn res ? res-\u003ename : NULL;\n }\n \n+static int cmp_func_symbol(const void *a, const void *b)\n+{\n+\tconst char * const *name = a;\n+\tconst char * const *other = b;\n+\n+\treturn strcmp(*name, *other);\n+}\n+\n+static int collect_func_symbols(struct object *obj)\n+{\n+\tElf_Scn *scn;\n+\tGElf_Shdr sh;\n+\tint n, i;\n+\n+\tif (obj-\u003eefile.symbols_shndx == -1)\n+\t\treturn 0;\n+\n+\tscn = elf_getscn(obj-\u003eefile.elf, obj-\u003eefile.symbols_shndx);\n+\tif (!scn || gelf_getshdr(scn, \u0026sh) != \u0026sh || !sh.sh_entsize)\n+\t\treturn -EINVAL;\n+\tn = sh.sh_size / sh.sh_entsize;\n+\n+\tfor (i = 0; i \u003c n; i++) {\n+\t\tGElf_Sym sym;\n+\t\tconst char *name;\n+\n+\t\tif (!gelf_getsym(obj-\u003eefile.symbols, i, \u0026sym))\n+\t\t\treturn -EINVAL;\n+\t\tif (GELF_ST_TYPE(sym.st_info) != STT_FUNC ||\n+\t\t    sym.st_shndx == SHN_UNDEF || !sym.st_name)\n+\t\t\tcontinue;\n+\t\tname = elf_strptr(obj-\u003eefile.elf, obj-\u003eefile.strtabidx, sym.st_name);\n+\t\tif (!name)\n+\t\t\treturn -EINVAL;\n+\t\tif (ensure_mem(\u0026obj-\u003eefile.func_symbols, \u0026obj-\u003eefile.func_symbols_cap,\n+\t\t\t       obj-\u003eefile.func_symbols_cnt + 1))\n+\t\t\treturn -ENOMEM;\n+\t\tobj-\u003eefile.func_symbols[obj-\u003eefile.func_symbols_cnt++] = name;\n+\t}\n+\n+\tqsort(obj-\u003eefile.func_symbols, obj-\u003eefile.func_symbols_cnt,\n+\t      sizeof(*obj-\u003eefile.func_symbols), cmp_func_symbol);\n+\tobj-\u003eefile.func_symbols_collected = true;\n+\treturn 0;\n+}\n+\n+static bool has_func_symbol(const struct object *obj, const char *name)\n+{\n+\treturn bsearch(\u0026name, obj-\u003eefile.func_symbols, obj-\u003eefile.func_symbols_cnt,\n+\t\t       sizeof(*obj-\u003eefile.func_symbols), cmp_func_symbol) != NULL;\n+}\n+\n static int symbols_collect(struct object *obj)\n {\n \tElf_Scn *scn = NULL;\n@@ -688,8 +807,9 @@ static int load_btf(struct object *obj)\n \t\tif (err) {\n \t\t\tpr_err(\"FAILED: load base BTF from %s: %s\\n\",\n \t\t\t       obj-\u003ebase_btf_path, strerror(-err));\n-\t\t\tgoto out_err;\n+\t\t\treturn err;\n \t\t}\n+\t\tobj-\u003ebase_btf = base_btf;\n \t}\n \n \tbtf = btf__parse_split(obj-\u003ebtf_path ?: obj-\u003epath, base_btf);\n@@ -697,20 +817,12 @@ static int load_btf(struct object *obj)\n \tif (err) {\n \t\tpr_err(\"FAILED: load BTF from %s: %s\\n\",\n \t\t\tobj-\u003ebtf_path ?: obj-\u003epath, strerror(-err));\n-\t\tgoto out_err;\n+\t\treturn err;\n \t}\n \n-\tobj-\u003ebase_btf = base_btf;\n \tobj-\u003ebtf = btf;\n \n \treturn 0;\n-\n-out_err:\n-\tbtf__free(base_btf);\n-\tbtf__free(btf);\n-\tobj-\u003ebase_btf = NULL;\n-\tobj-\u003ebtf = NULL;\n-\treturn err;\n }\n \n static int symbols_resolve(struct object *obj)\n@@ -977,6 +1089,153 @@ static int dump_raw_btf(struct btf *btf, const char *out_path)\n \treturn 0;\n }\n \n+static int patch_btf_link(struct object *obj, const struct btf_link *link)\n+{\n+\tchar section[128];\n+\tvoid *raw_btf_data = NULL;\n+\tsize_t shdrstrndx, module_name_len;\n+\tint fd = -1, len, err = -1;\n+\tFILE *btf_file = NULL;\n+\tElf_Scn *scn = NULL;\n+\tu32 raw_btf_size;\n+\tstruct stat st;\n+\tElf_Data *data;\n+\tGElf_Shdr sh;\n+\tchar *name;\n+\tElf *elf = NULL;\n+\tu8 *size;\n+\n+\tif (stat(link-\u003ebtf_path, \u0026st)) {\n+\t\terr = -errno;\n+\t\tpr_err(\"FAILED to stat BTF file %s: %s\\n\",\n+\t\t       link-\u003ebtf_path, strerror(errno));\n+\t\treturn err;\n+\t}\n+\tif (!S_ISREG(st.st_mode) || st.st_size \u003c= 0 || st.st_size \u003e UINT_MAX) {\n+\t\tpr_err(\"FAILED: invalid BTF file size or type: %s\\n\", link-\u003ebtf_path);\n+\t\treturn -EINVAL;\n+\t}\n+\traw_btf_size = st.st_size;\n+\traw_btf_data = malloc(raw_btf_size);\n+\tif (!raw_btf_data) {\n+\t\tpr_err(\"FAILED to allocate %u bytes for BTF file %s\\n\",\n+\t\t       raw_btf_size, link-\u003ebtf_path);\n+\t\treturn -ENOMEM;\n+\t}\n+\tbtf_file = fopen(link-\u003ebtf_path, \"rb\");\n+\tif (!btf_file) {\n+\t\terr = -errno;\n+\t\tpr_err(\"FAILED to open BTF file %s: %s\\n\",\n+\t\t       link-\u003ebtf_path, strerror(errno));\n+\t\tgoto out;\n+\t}\n+\tif (fread(raw_btf_data, raw_btf_size, 1, btf_file) != 1) {\n+\t\terr = -EIO;\n+\t\tpr_err(\"FAILED to read BTF file %s\\n\", link-\u003ebtf_path);\n+\t\tgoto out;\n+\t}\n+\tfclose(btf_file);\n+\tbtf_file = NULL;\n+\tif (obj-\u003eefile.elf_class == ELFCLASS32) {\n+\t\tmodule_name_len = BTF_LINK_MODULE_NAME_MAX - 4;\n+\t} else if (obj-\u003eefile.elf_class == ELFCLASS64) {\n+\t\tmodule_name_len = BTF_LINK_MODULE_NAME_MAX - 8;\n+\t} else {\n+\t\terr = -EINVAL;\n+\t\tpr_err(\"FAILED: unsupported ELF class %u in %s\\n\",\n+\t\t       obj-\u003eefile.elf_class, obj-\u003epath);\n+\t\tgoto out;\n+\t}\n+\tif (strlen(link-\u003emodule) \u003e= module_name_len) {\n+\t\terr = -EINVAL;\n+\t\tpr_err(\"FAILED: module name too long for BTF link: %s\\n\", link-\u003emodule);\n+\t\tgoto out;\n+\t}\n+\tlen = snprintf(section, sizeof(section), \"%s.link\", link-\u003esection);\n+\tif (len \u003c 0 || len \u003e= sizeof(section)) {\n+\t\terr = -ENAMETOOLONG;\n+\t\tpr_err(\"FAILED: BTF link section name too long: %s.link\\n\", link-\u003esection);\n+\t\tgoto out;\n+\t}\n+\n+\tfd = open(obj-\u003epath, O_RDWR);\n+\tif (fd \u003c 0) {\n+\t\terr = -errno;\n+\t\tpr_err(\"FAILED to open %s: %s\\n\", obj-\u003epath, strerror(errno));\n+\t\tgoto out;\n+\t}\n+\telf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);\n+\tif (!elf) {\n+\t\terr = -EINVAL;\n+\t\tpr_err(\"FAILED to create ELF descriptor for %s: %s\\n\",\n+\t\t       obj-\u003epath, elf_errmsg(-1));\n+\t\tgoto out;\n+\t}\n+\telf_flagelf(elf, ELF_C_SET, ELF_F_LAYOUT);\n+\tif (elf_getshdrstrndx(elf, \u0026shdrstrndx)) {\n+\t\tpr_err(\"FAILED to get section name index from %s: %s\\n\",\n+\t\t       obj-\u003epath, elf_errmsg(-1));\n+\t\tgoto out;\n+\t}\n+\twhile ((scn = elf_nextscn(elf, scn))) {\n+\t\tif (gelf_getshdr(scn, \u0026sh) != \u0026sh) {\n+\t\t\tpr_err(\"FAILED to get section header from %s: %s\\n\",\n+\t\t\t       obj-\u003epath, elf_errmsg(-1));\n+\t\t\tgoto out;\n+\t\t}\n+\t\tname = elf_strptr(elf, shdrstrndx, sh.sh_name);\n+\t\tif (name \u0026\u0026 !strcmp(name, section))\n+\t\t\tbreak;\n+\t}\n+\tif (!scn) {\n+\t\tpr_err(\"FAILED: section %s not found in %s\\n\", section, obj-\u003epath);\n+\t\tgoto out;\n+\t}\n+\tdata = elf_getdata(scn, NULL);\n+\tif (sh.sh_type != SHT_PROGBITS || !data || !data-\u003ed_buf ||\n+\t    data-\u003ed_size != module_name_len +\n+\t\tBTF_SHA256_DIGEST_LENGTH + sizeof(u32)) {\n+\t\tpr_err(\"FAILED: section %s is not a writable BTF link\\n\", section);\n+\t\tgoto out;\n+\t}\n+\tmemset(data-\u003ed_buf, 0, data-\u003ed_size);\n+\tmemcpy(data-\u003ed_buf, link-\u003emodule, strlen(link-\u003emodule) + 1);\n+\tbtf_sha256(raw_btf_data, raw_btf_size,\n+\t\t   (u8 *)data-\u003ed_buf + module_name_len);\n+\tsize = (u8 *)data-\u003ed_buf + module_name_len + BTF_SHA256_DIGEST_LENGTH;\n+\tif (obj-\u003eefile.encoding == ELFDATA2LSB) {\n+\t\tsize[0] = raw_btf_size;\n+\t\tsize[1] = raw_btf_size \u003e\u003e 8;\n+\t\tsize[2] = raw_btf_size \u003e\u003e 16;\n+\t\tsize[3] = raw_btf_size \u003e\u003e 24;\n+\t} else if (obj-\u003eefile.encoding == ELFDATA2MSB) {\n+\t\tsize[0] = raw_btf_size \u003e\u003e 24;\n+\t\tsize[1] = raw_btf_size \u003e\u003e 16;\n+\t\tsize[2] = raw_btf_size \u003e\u003e 8;\n+\t\tsize[3] = raw_btf_size;\n+\t} else {\n+\t\tpr_err(\"FAILED: unsupported ELF data encoding %u in %s\\n\",\n+\t\t       obj-\u003eefile.encoding, obj-\u003epath);\n+\t\tgoto out;\n+\t}\n+\telf_flagdata(data, ELF_C_SET, ELF_F_DIRTY);\n+\tif (elf_update(elf, ELF_C_WRITE) \u003c 0) {\n+\t\tpr_err(\"FAILED to update ELF file %s: %s\\n\",\n+\t\t       obj-\u003epath, elf_errmsg(-1));\n+\t\tgoto out;\n+\t}\n+\terr = 0;\n+out:\n+\tif (elf)\n+\t\telf_end(elf);\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\tif (btf_file)\n+\t\tfclose(btf_file);\n+\tfree(raw_btf_data);\n+\treturn err;\n+}\n+\n static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, s32 type_id)\n {\n \tconst struct btf_type *t = btf__type_by_id(btf, type_id);\n@@ -1510,6 +1769,84 @@ static int btf2btf(struct object *obj)\n \treturn err;\n }\n \n+static bool keep_in_base_btf(struct object *obj, const struct btf_type *t)\n+{\n+\tconst char *name;\n+\n+\tswitch (btf_kind(t)) {\n+\tcase BTF_KIND_FUNC:\n+\t\tname = btf__name_by_offset(obj-\u003ebtf, t-\u003ename_off);\n+\t\treturn !obj-\u003eefile.func_symbols_collected || has_func_symbol(obj, name) ||\n+\t\t       btf_id__find(\u0026obj-\u003efuncs, name);\n+\tcase BTF_KIND_FUNC_PROTO:\n+\tcase BTF_KIND_LOC_PARAM:\n+\tcase BTF_KIND_LOC_PROTO:\n+\tcase BTF_KIND_LOCSEC:\n+\t\treturn false;\n+\tdefault:\n+\t\t/*\n+\t\t * Ordinary types stay in base btf even if only inline records use them.\n+\t\t * Should we relax this?\n+\t\t */\n+\t\treturn true;\n+\t}\n+}\n+\n+/* Mark which types should go to .BTF.inline */\n+static int color_btf(struct object *obj, __u8 *colors)\n+{\n+\tstruct btf *btf = obj-\u003ebtf;\n+\tconst struct btf *base = btf__base_btf(btf);\n+\t__u32 start_id = base ? btf__type_cnt(base) : 1;\n+\t__u32 type_cnt = btf__type_cnt(btf), i;\n+\t__u32 *worklist;\n+\n+\tworklist = malloc((type_cnt - start_id ?: 1) * sizeof(*worklist));\n+\tif (!worklist)\n+\t\treturn -ENOMEM;\n+\t/* First, mark all types reachable from LOC BTF entries. */\n+\tfor (i = start_id; i \u003c type_cnt; i++) {\n+\t\tconst struct btf_type *t = btf__type_by_id(btf, i);\n+\n+\t\tif (!btf_is_locsec(t) \u0026\u0026 !btf_is_loc_proto(t) \u0026\u0026 !btf_is_loc_param(t))\n+\t\t\tcontinue;\n+\t\tbtf_mark_reachable(btf, i, BTF_COLOR_LOC, colors, worklist);\n+\t}\n+\t/* Next, traverse non-marked types converting some LOC markings to SHARED. */\n+\tfor (i = start_id; i \u003c type_cnt; i++) {\n+\t\tconst struct btf_type *t = btf__type_by_id(btf, i);\n+\n+\t\tif (colors[i] == BTF_COLOR_LOC \u0026\u0026 !keep_in_base_btf(obj, t))\n+\t\t\tcontinue;\n+\t\tbtf_mark_reachable(btf, i, BTF_COLOR_MAIN, colors, worklist);\n+\t}\n+\tfree(worklist);\n+\treturn 0;\n+}\n+\n+static int extract_inline_btf(struct object *obj)\n+{\n+\tstruct btf *btf = obj-\u003ebtf, *main_btf, *inline_btf;\n+\t__u8 *colors;\n+\tint err;\n+\n+\tcolors = calloc(btf__type_cnt(btf), sizeof(*colors));\n+\tif (!colors)\n+\t\treturn -ENOMEM;\n+\terr = color_btf(obj, colors);\n+\tif (err)\n+\t\tgoto out;\n+\terr = btf_split_by_color(btf, colors, \u0026main_btf, \u0026inline_btf);\n+\tif (!err) {\n+\t\tobj-\u003eorig_btf = btf;\n+\t\tobj-\u003ebtf = main_btf;\n+\t\tobj-\u003einline_btf = inline_btf;\n+\t}\n+out:\n+\tfree(colors);\n+\treturn err;\n+}\n+\n /*\n  * Sort types by name in ascending order resulting in all\n  * anonymous types being placed before named types.\n@@ -1583,14 +1920,14 @@ static int finalize_btf(struct object *obj)\n \terr = btf__dedup(obj-\u003ebtf, NULL);\n \tif (err) {\n \t\tpr_err(\"FAILED to dedup BTF: %s\\n\", strerror(errno));\n-\t\tgoto out_err;\n+\t\treturn err;\n \t}\n \n \tif (obj-\u003ebase_btf \u0026\u0026 obj-\u003edistill_base) {\n \t\terr = btf__distill_base(obj-\u003ebtf, \u0026base_btf, \u0026btf);\n \t\tif (err) {\n \t\t\tpr_err(\"FAILED to distill base BTF: %s\\n\", strerror(errno));\n-\t\t\tgoto out_err;\n+\t\t\treturn err;\n \t\t}\n \n \t\tbtf__free(obj-\u003ebase_btf);\n@@ -1602,18 +1939,18 @@ static int finalize_btf(struct object *obj)\n \terr = sort_btf_by_name(obj-\u003ebtf);\n \tif (err) {\n \t\tpr_err(\"FAILED to sort BTF: %s\\n\", strerror(errno));\n-\t\tgoto out_err;\n+\t\treturn err;\n \t}\n \n-\treturn 0;\n-\n-out_err:\n-\tbtf__free(base_btf);\n-\tbtf__free(btf);\n-\tobj-\u003ebase_btf = NULL;\n-\tobj-\u003ebtf = NULL;\n+\tif (obj-\u003eextract_inline) {\n+\t\terr = extract_inline_btf(obj);\n+\t\tif (err) {\n+\t\t\tpr_err(\"FAILED to extract inline BTF: %s\\n\", strerror(-err));\n+\t\t\treturn err;\n+\t\t}\n+\t}\n \n-\treturn err;\n+\treturn 0;\n }\n \n static inline int make_out_path(char *buf, u32 buf_sz, const char *in_path, const char *suffix)\n@@ -1740,7 +2077,7 @@ static int patch_btfids(const char *btfids_path, const char *elf_path)\n \n static const char * const resolve_btfids_usage[] = {\n \t\"resolve_btfids [\u003coptions\u003e] \u003cELF object\u003e\",\n-\t\"resolve_btfids --patch_btfids \u003c.BTF_ids file\u003e \u003cELF object\u003e\",\n+\t\"resolve_btfids --patch_btfids \u003c.BTF_ids file\u003e [--btf_link \u003csection:module:btf-file\u003e] \u003cELF object\u003e\",\n \tNULL\n };\n \n@@ -1758,6 +2095,7 @@ int main(int argc, const char **argv)\n \t\t.sets     = RB_ROOT,\n \t};\n \tconst char *btfids_path = NULL;\n+\tstruct btf_links btf_links = {};\n \tbool fatal_warnings = false;\n \tbool resolve_btfids = true;\n \tchar out_path[PATH_MAX];\n@@ -1773,6 +2111,10 @@ int main(int argc, const char **argv)\n \t\t\t    \"turn warnings into errors\"),\n \t\tOPT_BOOLEAN(0, \"distill_base\", \u0026obj.distill_base,\n \t\t\t    \"distill --btf_base and emit .BTF.base section data\"),\n+\t\tOPT_BOOLEAN(0, \"inline\", \u0026obj.extract_inline,\n+\t\t\t    \"extract location BTF into a .BTF.inline file\"),\n+\t\tOPT_CALLBACK(0, \"btf_link\", \u0026btf_links, \"section:module:btf-file\",\n+\t\t\t     \"patch a BTF link with --patch_btfids\", parse_btf_link),\n \t\tOPT_STRING(0, \"patch_btfids\", \u0026btfids_path, \"file\",\n \t\t\t   \"path to .BTF_ids section data blob to patch into ELF file\"),\n \t\tOPT_END()\n@@ -1783,14 +2125,34 @@ int main(int argc, const char **argv)\n \t\t\t     PARSE_OPT_STOP_AT_NON_OPTION);\n \tif (argc != 1)\n \t\tusage_with_options(resolve_btfids_usage, btfid_options);\n+\tif (btf_links.cnt \u0026\u0026 !btfids_path) {\n+\t\tpr_err(\"--btf_link requires --patch_btfids\\n\");\n+\t\tgoto out;\n+\t}\n \n \tobj.path = argv[0];\n \n-\tif (btfids_path)\n-\t\treturn patch_btfids(btfids_path, obj.path);\n+\tif (btfids_path) {\n+\t\terr = patch_btfids(btfids_path, obj.path);\n+\t\tif (err || !btf_links.cnt)\n+\t\t\tgoto out;\n+\t\tif (elf_collect(\u0026obj)) {\n+\t\t\terr = -EINVAL;\n+\t\t\tgoto out;\n+\t\t}\n+\t\tfor (u32 i = 0; i \u003c btf_links.cnt; i++) {\n+\t\t\tstruct btf_link *link = \u0026btf_links.links[i];\n \n+\t\t\terr = patch_btf_link(\u0026obj, link);\n+\t\t\tif (err)\n+\t\t\t\tbreak;\n+\t\t}\n+\t\tgoto out;\n+\t}\n \tif (elf_collect(\u0026obj))\n \t\tgoto out;\n+\tif (obj.extract_inline \u0026\u0026 collect_func_symbols(\u0026obj))\n+\t\tgoto out;\n \n \t/*\n \t * We did not find .BTF_ids section or symbols section,\n@@ -1841,18 +2203,33 @@ int main(int argc, const char **argv)\n \t\tif (err)\n \t\t\tgoto out;\n \t}\n+\tif (obj.inline_btf) {\n+\t\terr = make_out_path(out_path, sizeof(out_path), obj.path, BTF_ELF_SEC \".inline\");\n+\t\terr = err ?: dump_raw_btf(obj.inline_btf, out_path);\n+\t\tif (err)\n+\t\t\tgoto out;\n+\t}\n \n \tif (!(fatal_warnings \u0026\u0026 warnings))\n \t\terr = 0;\n out:\n-\tbtf__free(obj.base_btf);\n+\tfree_btf_links(\u0026btf_links);\n+\t/*\n+\t * Free BTFs in reverse dependency order.  inline_btf borrows obj.btf;\n+\t * obj.btf can borrow a base owned by orig_btf or obj.base_btf, and\n+\t * orig_btf can also borrow obj.base_btf.\n+\t */\n+\tbtf__free(obj.inline_btf);\n \tbtf__free(obj.btf);\n+\tbtf__free(obj.orig_btf);\n+\tbtf__free(obj.base_btf);\n \tbtf_id__free_all(\u0026obj.structs);\n \tbtf_id__free_all(\u0026obj.unions);\n \tbtf_id__free_all(\u0026obj.typedefs);\n \tbtf_id__free_all(\u0026obj.funcs);\n \tbtf_id__free_all(\u0026obj.sets);\n \tfree(obj.addr_syms);\n+\tfree(obj.efile.func_symbols);\n \tif (obj.efile.elf) {\n \t\telf_end(obj.efile.elf);\n \t\tclose(obj.efile.fd);\ndiff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c\nindex 512b3962f75f8..d2ff6f5d6d5b6 100644\n--- a/tools/lib/bpf/btf.c\n+++ b/tools/lib/bpf/btf.c\n@@ -6640,7 +6640,7 @@ void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\n \n int btf__relocate(struct btf *btf, const struct btf *base_btf)\n {\n-\tint err = btf_relocate(btf, base_btf, NULL);\n+\tint err = btf_relocate(btf, base_btf, NULL, NULL);\n \n \tif (!err)\n \t\tbtf-\u003eowns_base = false;\ndiff --git a/tools/lib/bpf/btf_relocate.c b/tools/lib/bpf/btf_relocate.c\nindex df5fa4bd87d69..e55dd75f6c950 100644\n--- a/tools/lib/bpf/btf_relocate.c\n+++ b/tools/lib/bpf/btf_relocate.c\n@@ -441,7 +441,8 @@ static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i)\n /* If successful, output of relocation is updated BTF with base BTF pointing\n  * at base_btf, and type ids, strings adjusted accordingly.\n  */\n-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map)\n+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\n+\t\t __u32 **str_map)\n {\n \tunsigned int nr_types = btf__type_cnt(btf);\n \tconst struct btf_header *dist_base_hdr;\n@@ -512,6 +513,10 @@ int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map)\n \t\t*id_map = r.id_map;\n \t\tr.id_map = NULL;\n \t}\n+\tif (str_map) {\n+\t\t*str_map = r.str_map;\n+\t\tr.str_map = NULL;\n+\t}\n err_out:\n \tfree(r.id_map);\n \tfree(r.str_map);\ndiff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h\nindex 546f65b95cf4d..4e45dfacb548a 100644\n--- a/tools/lib/bpf/libbpf_internal.h\n+++ b/tools/lib/bpf/libbpf_internal.h\n@@ -249,7 +249,8 @@ const char *btf_kind_str(const struct btf_type *t);\n const struct btf_type *skip_mods_and_typedefs(const struct btf *btf, __u32 id, __u32 *res_id);\n const struct btf_header *btf_header(const struct btf *btf);\n void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\n-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map);\n+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\n+\t\t __u32 **str_map);\n bool btf_type_is_traceable_func(const struct btf *btf, const struct btf_type *t);\n \n static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t)\ndiff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile\nindex a22be7efd1fa2..80d8bbbc3084a 100644\n--- a/tools/testing/selftests/bpf/Makefile\n+++ b/tools/testing/selftests/bpf/Makefile\n@@ -343,7 +343,9 @@ else\n endif\n \n $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids\t\\\n-\t\t       $(TOOLSDIR)/bpf/resolve_btfids/main.c\t\\\n+\t\t       $(TOOLSDIR)/bpf/resolve_btfids/main.c\t\t\\\n+\t\t       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.c\t\\\n+\t\t       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.h\t\\\n \t\t       $(TOOLSDIR)/lib/rbtree.c\t\t\t\\\n \t\t       $(TOOLSDIR)/lib/zalloc.c\t\t\t\\\n \t\t       $(TOOLSDIR)/lib/string.c\t\t\t\\\ndiff --git a/tools/testing/selftests/bpf/prog_tests/btf_inline.c b/tools/testing/selftests/bpf/prog_tests/btf_inline.c\nnew file mode 100644\nindex 0000000000000..d88fab6429b1b\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/btf_inline.c\n@@ -0,0 +1,113 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026, Oracle and/or its affiliates. */\n+\n+#include \u003ctest_progs.h\u003e\n+#include \u003cbpf/btf.h\u003e\n+#include \u003cbpf/libbpf.h\u003e\n+\n+#define BTF_SYSFS_DIR\t\t\"/sys/kernel/btf\"\n+#define BTF_INLINE_SUFFIX\t\".inline\"\n+\n+/*\n+ * For a specific inline site, verify we have the right function,\n+ * loc proto and loc param representation and that the offset is\n+ * reasonable given the caller where it was inlined.\n+ */\n+void test_btf_inline(void)\n+{\n+\tstruct btf *inline_btf = NULL, *btf = NULL, *vmlinux_btf = NULL;\n+\tconst char *inline_caller = \"bpf_testmod_test_write\";\n+\tconst char *inline_func = \"testmod_inline_len\";\n+\tunsigned long long caller_addr, base_addr;\n+\tbool skip = false, found_loc = false;\n+\tconst struct btf_loc_param *lp;\n+\tint locsec_id, func_id, n, i;\n+\tconst struct btf_type *t;\n+\tstruct btf_loc *l;\n+\tconst __u32 *p;\n+\tint err = 0;\n+\n+\tif (!env.has_testmod) {\n+\t\ttest__skip();\n+\t\treturn;\n+\t}\n+\n+\tbase_addr = module_get_base_addr(\"bpf_testmod\");\n+\tif (!ASSERT_NEQ(base_addr, 0, \"base_addr_nonzero\"))\n+\t\treturn;\n+\n+\tif (!ASSERT_OK(kallsyms_find(inline_caller, \u0026caller_addr),\n+\t\t       \"find_inline_caller\"))\n+\t\treturn;\n+\tif (!ASSERT_NEQ(caller_addr, 0, \"caller_addr_nonzero\"))\n+\t\treturn;\n+\tif (!ASSERT_GT(caller_addr, base_addr, \"caller_addr_gt_base_addr\"))\n+\t\treturn;\n+\tcaller_addr -= base_addr;\n+\n+\tvmlinux_btf = btf__load_vmlinux_btf();\n+\tif (!ASSERT_OK_PTR(vmlinux_btf, \"vmlinux_btf\"))\n+\t\treturn;\n+\n+\tbtf = btf__parse_split(BTF_SYSFS_DIR \"/bpf_testmod\", vmlinux_btf);\n+\tif (!ASSERT_OK_PTR(btf, \"bpf_testmod_btf\"))\n+\t\tgoto out;\n+\n+\tinline_btf = btf__parse_split(BTF_SYSFS_DIR \"/bpf_testmod\" BTF_INLINE_SUFFIX,\n+\t\t\t\t      btf);\n+\terr = libbpf_get_error(inline_btf);\n+\t/* pahole may not have inline BTF feature support. */\n+\tif (err == -ENOENT) {\n+\t\tskip = true;\n+\t\tgoto out;\n+\t}\n+\tif (!ASSERT_OK(err, \"parse_inline_btf\"))\n+\t\tgoto out;\n+\tlocsec_id = btf__find_by_name_kind(inline_btf, \"inline.text\", BTF_KIND_LOCSEC);\n+\tif (locsec_id \u003c 0) {\n+\t\tskip = true;\n+\t\tgoto out;\n+\t}\n+\tfunc_id = btf__find_by_name_kind(inline_btf, inline_func, BTF_KIND_FUNC);\n+\tif (!ASSERT_GT(func_id, 0, \"inline_caller_func\"))\n+\t\tgoto out;\n+\tt = btf__type_by_id(inline_btf, locsec_id);\n+\tn = btf_vlen(t);\n+\tfor (i = 0, l = btf_locsec_locs(t); i \u003c n; i++, l++) {\n+\t\tif (l-\u003efunc == func_id) {\n+\t\t\tfound_loc = true;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (!ASSERT_TRUE(found_loc, \"found_loc\"))\n+\t\tgoto out;\n+\tif (!ASSERT_GT(l-\u003eloc_proto, 0, \"loc_proto_id\"))\n+\t\tgoto out;\n+\tif (!ASSERT_GT(l-\u003eoffset, 0, \"loc_offset\"))\n+\t\tgoto out;\n+\tt = btf__type_by_id(inline_btf, l-\u003eloc_proto);\n+\tif (!ASSERT_OK_PTR(t, \"loc_proto_ptr\"))\n+\t\tgoto out;\n+\tif (!ASSERT_EQ(btf_vlen(t), 1, \"loc_proto_one_param\"))\n+\t\tgoto out;\n+\tp = btf_loc_proto_params(t);\n+\tif (!ASSERT_GT(*p, 0, \"loc_proto_has_loc_param\"))\n+\t\tgoto out;\n+\tt = btf__type_by_id(inline_btf, *p);\n+\tif (!ASSERT_OK_PTR(t, \"loc_param_ptr\"))\n+\t\tgoto out;\n+\tlp = btf_loc_param(t);\n+\tif (!ASSERT_TRUE(lp-\u003eflags \u0026 BTF_LOC_PARAM_REG, \"param_has_reg\"))\n+\t\tgoto out;\n+\tif (!ASSERT_GT(l-\u003eoffset, caller_addr, \"inline_gt_caller\"))\n+\t\tgoto out;\n+\t/* simple sanity test to roughly ensure inline site still in function */\n+\tif (!ASSERT_LT(l-\u003eoffset, caller_addr + 512, \"inline_in_caller\"))\n+\t\tgoto out;\n+out:\n+\tbtf__free(inline_btf);\n+\tbtf__free(btf);\n+\tbtf__free(vmlinux_btf);\n+\tif (skip)\n+\t\ttest__skip();\n+}\ndiff --git a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c\nindex 3923e64c4c1d0..3fde8598189f4 100644\n--- a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c\n+++ b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c\n@@ -3,15 +3,21 @@\n \n #include \u003ctest_progs.h\u003e\n #include \u003cbpf/btf.h\u003e\n+#include \u003cdirent.h\u003e\n+#include \u003climits.h\u003e\n #include \u003csys/stat.h\u003e\n #include \u003csys/mman.h\u003e\n #include \u003cfcntl.h\u003e\n #include \u003cunistd.h\u003e\n \n+#define BTF_SYSFS_DIR\t\t\"/sys/kernel/btf\"\n+#define BTF_INLINE_SUFFIX\t\".inline\"\n+\n static void test_btf_mmap_sysfs(const char *path, struct btf *base)\n {\n \tstruct stat st;\n \t__u64 btf_size, end;\n+\tsize_t mmap_len = 0;\n \tvoid *raw_data = NULL;\n \tint fd = -1;\n \tlong page_size;\n@@ -26,6 +32,7 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)\n \n \tbtf_size = st.st_size;\n \tend = (btf_size + page_size - 1) / page_size * page_size;\n+\tmmap_len = btf_size;\n \n \tfd = open(path, O_RDONLY);\n \tif (!ASSERT_GE(fd, 0, \"open_btf\"))\n@@ -39,11 +46,13 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)\n \tif (!ASSERT_EQ(raw_data, MAP_FAILED, \"mmap_btf_shared\"))\n \t\tgoto cleanup;\n \n-\traw_data = mmap(NULL, end + 1, PROT_READ, MAP_PRIVATE, fd, 0);\n+\tmmap_len = end + 1;\n+\traw_data = mmap(NULL, mmap_len, PROT_READ, MAP_PRIVATE, fd, 0);\n \tif (!ASSERT_EQ(raw_data, MAP_FAILED, \"mmap_btf_invalid_size\"))\n \t\tgoto cleanup;\n \n-\traw_data = mmap(NULL, end, PROT_READ, MAP_PRIVATE, fd, 0);\n+\tmmap_len = end;\n+\traw_data = mmap(NULL, mmap_len, PROT_READ, MAP_PRIVATE, fd, 0);\n \tif (!ASSERT_OK_PTR(raw_data, \"mmap_btf\"))\n \t\tgoto cleanup;\n \n@@ -70,12 +79,84 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)\n cleanup:\n \tbtf__free(btf);\n \tif (raw_data \u0026\u0026 raw_data != MAP_FAILED)\n-\t\tmunmap(raw_data, btf_size);\n+\t\tmunmap(raw_data, mmap_len);\n \tif (fd \u003e= 0)\n \t\tclose(fd);\n }\n \n+static void test_btf_inline_sysfs_all(void)\n+{\n+\tstruct btf *vmlinux_btf;\n+\tstruct dirent *dentry;\n+\tDIR *dir;\n+\tint err = 0;\n+\n+\tdir = opendir(BTF_SYSFS_DIR);\n+\tif (!ASSERT_OK_PTR(dir, \"open_btf_sysfs\"))\n+\t\treturn;\n+\n+\tvmlinux_btf = btf__parse(BTF_SYSFS_DIR \"/vmlinux\", NULL);\n+\tif (!ASSERT_OK_PTR(vmlinux_btf, \"parse_vmlinux_btf\")) {\n+\t\tclosedir(dir);\n+\t\treturn;\n+\t}\n+\n+\twhile ((dentry = readdir(dir)) != NULL) {\n+\t\tstruct btf *base_btf = NULL, *module_btf = NULL, *inline_btf = NULL;\n+\t\tchar btf_path[PATH_MAX], inline_path[PATH_MAX];\n+\t\tstruct stat st;\n+\n+\t\t/* Skip \".\", \"..\" and \"foo.inline\" */\n+\t\tif (strstr(dentry-\u003ed_name, \".\"))\n+\t\t\tcontinue;\n+\n+\t\tif (strcmp(dentry-\u003ed_name, \"vmlinux\") == 0)\n+\t\t\tbase_btf = vmlinux_btf;\n+\n+\t\tif (snprintf(btf_path, sizeof(btf_path), \"%s/%s\",\n+\t\t\t     BTF_SYSFS_DIR, dentry-\u003ed_name) \u003e= sizeof(btf_path) ||\n+\t\t    snprintf(inline_path, sizeof(inline_path), \"%s/%s%s\",\n+\t\t\t     BTF_SYSFS_DIR, dentry-\u003ed_name, BTF_INLINE_SUFFIX) \u003e=\n+\t\t\t     sizeof(inline_path)) {\n+\t\t\tASSERT_FAIL(\"BTF sysfs path is too long\\n\");\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (!base_btf) {\n+\t\t\tmodule_btf = btf__parse_split(btf_path, vmlinux_btf);\n+\t\t\terr = libbpf_get_error(module_btf);\n+\t\t\tif (err) {\n+\t\t\t\t/* A module can be unloaded while its sysfs entry is iterated. */\n+\t\t\t\tif (err == -ENOENT)\n+\t\t\t\t\tcontinue;\n+\t\t\t\tASSERT_OK(err, \"parse_module_btf\");\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tbase_btf = module_btf;\n+\t\t}\n+\t\tif (stat(inline_path, \u0026st)) {\n+\t\t\terr = errno;\n+\t\t\tif (err != ENOENT)\n+\t\t\t\tASSERT_OK(err, \"stat_inline_btf\");\n+\t\t\tbtf__free(module_btf);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (base_btf == vmlinux_btf)\n+\t\t\ttest_btf_mmap_sysfs(inline_path, base_btf);\n+\t\tinline_btf = btf__parse_split(inline_path, base_btf);\n+\t\terr = libbpf_get_error(inline_btf);\n+\t\tif (!err)\n+\t\t\tbtf__free(inline_btf);\n+\t\tASSERT_OK(err, \"parse_inline_btf\");\n+\t\tbtf__free(module_btf);\n+\t}\n+\tclosedir(dir);\n+\n+\tbtf__free(vmlinux_btf);\n+}\n+\n void test_btf_sysfs(void)\n {\n \ttest_btf_mmap_sysfs(\"/sys/kernel/btf/vmlinux\", NULL);\n+\ttest_btf_inline_sysfs_all();\n }\ndiff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\nindex 93847ca6293b4..b4f0af2aeca45 100644\n--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\n+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\n@@ -735,6 +735,13 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,\n EXPORT_SYMBOL(bpf_testmod_test_read);\n ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO);\n \n+static __always_inline size_t testmod_inline_len(size_t len)\n+{\n+\t/* Keep an instruction in the inline site without changing len. */\n+\tasm volatile(\"\" : \"+m\"(len));\n+\treturn len;\n+}\n+\n noinline ssize_t\n bpf_testmod_test_write(struct file *file, struct kobject *kobj,\n \t\t      const struct bin_attribute *bin_attr,\n@@ -743,7 +750,7 @@ bpf_testmod_test_write(struct file *file, struct kobject *kobj,\n \tstruct bpf_testmod_test_write_ctx ctx = {\n \t\t.buf = buf,\n \t\t.off = off,\n-\t\t.len = len,\n+\t\t.len = testmod_inline_len(len),\n \t};\n \n \ttrace_bpf_testmod_test_write_bare_tp(current, \u0026ctx);\n@@ -802,7 +809,7 @@ static struct testmod_uprobe uprobe = {\n \t.consumer.ret_handler = uprobe_ret_handler,\n };\n \n-static int testmod_register_uprobe(loff_t offset)\n+static __always_inline int testmod_register_uprobe(loff_t offset)\n {\n \tint err = -EBUSY;\n \ndiff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c\nindex 679008b310d9a..f3a1d627699da 100644\n--- a/tools/testing/selftests/bpf/trace_helpers.c\n+++ b/tools/testing/selftests/bpf/trace_helpers.c\n@@ -244,6 +244,26 @@ int kallsyms_find(const char *sym, unsigned long long *addr)\n \treturn err;\n }\n \n+unsigned long long module_get_base_addr(const char *module)\n+{\n+\tunsigned long long addr, base_addr = 0;\n+\tchar name[500];\n+\tFILE *f;\n+\n+\tf = fopen(\"/proc/modules\", \"r\");\n+\tif (!f)\n+\t\treturn 0;\n+\n+\twhile (fscanf(f, \"%499s %*s %*s %*s %*s 0x%llx\", name, \u0026addr) == 2) {\n+\t\tif (strcmp(module, name) == 0) {\n+\t\t\tbase_addr = addr;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tfclose(f);\n+\treturn base_addr;\n+}\n+\n #ifdef PROCMAP_QUERY\n int env_verbosity __weak = 0;\n \ndiff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h\nindex 01c8ecc456270..eb0d0d9804d6e 100644\n--- a/tools/testing/selftests/bpf/trace_helpers.h\n+++ b/tools/testing/selftests/bpf/trace_helpers.h\n@@ -38,6 +38,7 @@ typedef int (*ksym_search_cmp_t)(const void *p1, const struct ksym *p2);\n int load_kallsyms(void);\n struct ksym *ksym_search(long key);\n long ksym_get_addr(const char *name);\n+unsigned long long module_get_base_addr(const char *module);\n \n struct ksyms *load_kallsyms_local(void);\n struct ksym *ksym_search_local(struct ksyms *ksyms, long key);\ndiff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile\nindex 2f423de831473..d1b65fd379118 100644\n--- a/tools/testing/selftests/hid/Makefile\n+++ b/tools/testing/selftests/hid/Makefile\n@@ -148,6 +148,8 @@ endif\n \n $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids\t\\\n \t\t       $(TOOLSDIR)/bpf/resolve_btfids/main.c\t\\\n+\t\t       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.c\t\\\n+\t\t       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.h\t\\\n \t\t       $(TOOLSDIR)/lib/rbtree.c\t\t\t\\\n \t\t       $(TOOLSDIR)/lib/zalloc.c\t\t\t\\\n \t\t       $(TOOLSDIR)/lib/string.c\t\t\t\\\n"
}

2/1 2026/10/09 13:48 agent patch-evaluator
22m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "DEBUG_INFO_BTF_INLINE",
    "DEBUG_INFO_BTF",
    "DEBUG_INFO_BTF_MODULES",
    "BPF_SYSCALL",
    "SYSFS",
    "MODULES"
  ],
  "FocusSymbols": [
    "btf_set_base_btf",
    "btf_rebase_inline",
    "btf_parse_split",
    "btf_parse_module",
    "btf_module_handle_vmlinux_inline",
    "btf_module_notify",
    "btf_sysfs_read_lazy",
    "btf_sysfs_mmap_lazy",
    "btf_sysfs_mmap_image",
    "sysfs_btf_add",
    "btf_relocate"
  ],
  "Reasoning": "The patch introduces inline BTF support (.BTF.inline sections) along with kernel infrastructure to parse, rebase, and relocate inline BTF upon module loading, and exposes it through sysfs entries supporting lazy loading, reading, and mmap operations. These changes modify reachable core BPF, sysfs, and module loader execution paths accessible via syscalls like init_module/finit_module, read, and mmap.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit f2fd4fe68b2b0fd38f8b379496a376e8764bd384
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Oct 9 13:48:00 2026 +0000

    syz-cluster: applied patch under review

diff --git a/.gitignore b/.gitignore
index 9875120ea7bde..d54bdaac99813 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,6 +72,7 @@ modules.order
 /vmlinux.symvers
 /vmlinux.thinlto-index
 /vmlinux.unstripped
+/vmlinux.BTF.inline
 /vmlinux-gdb.py
 /vmlinuz
 /System.map
diff --git a/Makefile b/Makefile
index 6b8b812f23b92..b3053dd3c1059 100644
--- a/Makefile
+++ b/Makefile
@@ -1769,6 +1769,7 @@ endif # CONFIG_MODULES
 CLEAN_FILES += vmlinux.symvers modules-only.symvers \
 	       modules.builtin modules.builtin.modinfo modules.nsdeps \
 	       modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \
+	       vmlinux.BTF.inline \
 	       vmlinux.thinlto-index builtin.order \
 	       compile_commands.json rust/test \
 	       rust-project.json .vmlinux.objs .vmlinux.export.c \
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b2988aa12f664..b17251bc63f5d 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -675,12 +675,43 @@
 /*
  * .BTF
  */
+#ifdef CONFIG_DEBUG_INFO_BTF_INLINE
+#define BTF_INLINE							\
+	. = ALIGN(PAGE_SIZE);						\
+	.BTF.inline : AT(ADDR(.BTF.inline) - LOAD_OFFSET) {		\
+		BOUNDED_SECTION_BY(.BTF.inline, _BTF_inline)		\
+	}
+#else
+#define BTF_INLINE
+#endif
+
+#ifdef CONFIG_DEBUG_INFO_BTF_INLINE_MODULE
+/* __MODULE_NAME_LEN + SHA-256 digest + u32 BTF size */
+#ifdef CONFIG_64BIT
+#define BTF_LINK_SIZE	(64 - 8 + 32 + 4)
+#else
+#define BTF_LINK_SIZE	(64 - 4 + 32 + 4)
+#endif
+#define BTF_INLINE_LINK						\
+	. = ALIGN(PAGE_SIZE);					\
+	.BTF.inline.link : AT(ADDR(.BTF.inline.link) - LOAD_OFFSET) { \
+		__start_BTF_inline_link = .;				\
+		BYTE(0)						\
+		. += BTF_LINK_SIZE - 1;					\
+		__stop_BTF_inline_link = .;				\
+	}
+#else
+#define BTF_INLINE_LINK
+#endif
+
 #ifdef CONFIG_DEBUG_INFO_BTF
 #define BTF								\
 	. = ALIGN(PAGE_SIZE);						\
 	.BTF : AT(ADDR(.BTF) - LOAD_OFFSET) {				\
 		BOUNDED_SECTION_BY(.BTF, _BTF)				\
 	}								\
+	BTF_INLINE							\
+	BTF_INLINE_LINK						\
 	. = ALIGN(PAGE_SIZE);						\
 	.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) {			\
 		*(.BTF_ids)						\
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 4b63bb91550a1..b66e20a18c54f 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -5,6 +5,7 @@
 #define _LINUX_BTF_H 1
 
 #include <linux/types.h>
+#include <linux/module.h>
 #include <linux/bpfptr.h>
 #include <linux/bsearch.h>
 #include <linux/btf_ids.h>
@@ -118,6 +119,19 @@ struct btf_show;
 struct btf_id_set;
 struct bpf_prog;
 
+#define BTF_LINK_SHA256_LEN	32
+
+/*
+ * A .BTF.link or .BTF.inline.link section identifies the module which
+ * carries a vmlinux BTF section.  The module name is NUL terminated and the
+ * field is padded to __MODULE_NAME_LEN.
+ */
+struct btf_link {
+	char module_name[__MODULE_NAME_LEN];
+	u8 sha256[BTF_LINK_SHA256_LEN];
+	u32 btf_size;
+} __packed;
+
 typedef int (*btf_kfunc_filter_t)(const struct bpf_prog *prog, u32 kfunc_id);
 
 struct btf_kfunc_id_set {
@@ -594,7 +608,8 @@ struct btf_field_iter {
 #ifdef CONFIG_BPF_SYSCALL
 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
 void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);
-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids);
+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids,
+		 __u32 **map_strs);
 int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 			enum btf_field_iter_kind iter_kind);
 __u32 *btf_field_iter_next(struct btf_field_iter *it);
@@ -624,6 +639,29 @@ bool btf_types_are_same(const struct btf *btf1, u32 id1,
 			const struct btf *btf2, u32 id2);
 int btf_check_iter_arg(struct btf *btf, const struct btf_type *func, int arg_idx);
 
+#if IS_ENABLED(CONFIG_SYSFS)
+struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,
+				    bool mmap, const char *lazy_module_name);
+bool sysfs_btf_update(struct bin_attribute *attr, void *data);
+void sysfs_btf_remove(struct bin_attribute *attr);
+#else
+static inline struct bin_attribute *
+sysfs_btf_add(const char *name, void *data, size_t data_size, bool mmap,
+	      const char *lazy_module_name)
+{
+	return NULL;
+}
+
+static inline bool sysfs_btf_update(struct bin_attribute *attr, void *data)
+{
+	return false;
+}
+
+static inline void sysfs_btf_remove(struct bin_attribute *attr)
+{
+}
+#endif
+
 static inline bool btf_type_is_struct_ptr(struct btf *btf, const struct btf_type *t)
 {
 	if (!btf_type_is_ptr(t))
@@ -645,7 +683,7 @@ static inline void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)
 }
 
 static inline int btf_relocate(void *log, struct btf *btf, const struct btf *base_btf,
-			       __u32 **map_ids)
+			       __u32 **map_ids, __u32 **map_strs)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/include/linux/module.h b/include/linux/module.h
index 96cc98568eea5..a6abde12a458f 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -503,6 +503,10 @@ struct module {
 	void *btf_data;
 	void *btf_base_data;
 #endif
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+	unsigned int btf_inline_data_size;
+	void *btf_inline_data;
+#endif
 #ifdef CONFIG_JUMP_LABEL
 	struct jump_entry *jump_entries;
 	unsigned int num_jump_entries;
diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index c1f9b0d3468d3..37e62ef450791 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o
 endif
 ifeq ($(CONFIG_SYSFS),y)
 obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o
+obj-$(CONFIG_DEBUG_INFO_BTF_INLINE) += btf_vmlinux_inline.o
 endif
 ifeq ($(CONFIG_BPF_JIT),y)
 obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 0630675377aaa..29599ab7449ed 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -25,11 +25,12 @@
 #include <linux/skmsg.h>
 #include <linux/perf_event.h>
 #include <linux/bsearch.h>
-#include <linux/kobject.h>
 #include <linux/string.h>
-#include <linux/sysfs.h>
 #include <linux/overflow.h>
 #include <linux/bitops.h>
+#include <linux/unaligned.h>
+#include <linux/vmalloc.h>
+#include <crypto/sha2.h>
 
 #include <net/netfilter/nf_bpf_link.h>
 
@@ -1935,7 +1936,7 @@ void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)
 {
 	btf->base_btf = (struct btf *)base_btf;
 	btf->start_id = btf_nr_types(base_btf);
-	btf->start_str_off = base_btf->hdr.str_len;
+	btf->start_str_off = base_btf->start_str_off + base_btf->hdr.str_len;
 }
 
 static int env_resolve_init(struct btf_verifier_env *env)
@@ -6921,15 +6922,137 @@ __u32 btf_relocate_id(const struct btf *btf, __u32 id)
 
 #ifdef CONFIG_DEBUG_INFO_BTF_MODULES
 
+static struct btf *btf_parse_split(struct btf_verifier_env *env,
+				   const char *name, const void *data,
+				   unsigned int data_size, struct btf *base_btf)
+{
+	struct btf *btf;
+	int err;
+
+	btf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);
+	if (!btf)
+		return ERR_PTR(-ENOMEM);
+	env->btf = btf;
+
+	btf_set_base_btf(btf, base_btf);
+	btf->kernel_btf = true;
+	btf->named_start_id = 0;
+	strscpy(btf->name, name);
+
+	btf->data = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);
+	if (!btf->data) {
+		err = -ENOMEM;
+		goto errout;
+	}
+	btf->data_size = data_size;
+
+	err = btf_parse_hdr(env);
+	if (err)
+		goto errout;
+
+	btf->nohdr_data = btf->data + btf->hdr.hdr_len;
+
+	err = btf_parse_str_sec(env);
+	if (err)
+		goto errout;
+
+	err = btf_check_all_metas(env);
+	if (err)
+		goto errout;
+
+	err = btf_check_modifier_chain_length(env, btf, btf_nr_types(base_btf));
+	if (err)
+		goto errout;
+
+	return btf;
+
+errout:
+	btf_free(btf);
+	return ERR_PTR(err);
+}
+
+static int btf_rebase_inline(struct btf *inline_btf,
+			     const struct btf *module_btf,
+			     const u32 *module_id_map,
+			     const u32 *module_str_map,
+			     u32 old_module_type_cnt)
+{
+	u32 old_start_id = inline_btf->start_id;
+	u32 old_start_str_off = inline_btf->start_str_off;
+	u32 old_module_start_str_off = old_start_str_off - module_btf->hdr.str_len;
+	u32 new_start_id = btf_nr_types(module_btf);
+	u32 new_start_str_off = module_btf->start_str_off + module_btf->hdr.str_len;
+	s64 id_delta = (s64)new_start_id - old_start_id;
+	s64 str_delta = (s64)new_start_str_off - old_start_str_off;
+	u32 i;
+
+	/*
+	 * The inline BTF was parsed relative to the original module BTF. Its
+	 * base IDs must therefore use the map generated when that BTF was
+	 * relocated, while IDs for inline-local types only move by the change
+	 * in the module BTF's starting ID.
+	 */
+	for (i = 0; i < inline_btf->nr_types; i++) {
+		struct btf_field_iter it;
+		struct btf_type *t = inline_btf->types[i];
+		u32 *id, *str_off;
+		int err;
+
+		err = btf_field_iter_init(&it, t, BTF_FIELD_ITER_IDS);
+		if (err)
+			return err;
+		while ((id = btf_field_iter_next(&it))) {
+			if (!*id)
+				continue;
+			if (*id < old_module_type_cnt) {
+				if (module_id_map)
+					*id = module_id_map[*id];
+			} else if (*id >= old_start_id) {
+				*id += id_delta;
+			} else {
+				return -EINVAL;
+			}
+		}
+
+		err = btf_field_iter_init(&it, t, BTF_FIELD_ITER_STRS);
+		if (err)
+			return err;
+		while ((str_off = btf_field_iter_next(&it))) {
+			if (!*str_off)
+				continue;
+			if (*str_off < old_module_start_str_off) {
+				/* Vmlinux strings retain their offsets for in-tree modules. */
+				if (!module_id_map)
+					continue;
+				if (!module_str_map || !module_str_map[*str_off])
+					return -EINVAL;
+				*str_off = module_str_map[*str_off];
+				continue;
+			}
+			*str_off += str_delta;
+		}
+	}
+
+	btf_set_base_btf(inline_btf, module_btf);
+	btf_check_sorted(inline_btf);
+	return 0;
+}
+
 static struct btf *btf_parse_module(const char *module_name, const void *data,
 				    unsigned int data_size, void *base_data,
-				    unsigned int base_data_size)
+				    unsigned int base_data_size,
+				    const void *inline_data,
+				    unsigned int inline_data_size,
+				    void **relocated_inline_data)
 {
-	struct btf *btf = NULL, *vmlinux_btf, *base_btf = NULL;
+	struct btf *btf = NULL, *inline_btf = NULL, *vmlinux_btf, *base_btf = NULL;
 	struct btf_verifier_env *env = NULL;
 	struct bpf_verifier_log *log;
+	u32 *module_str_map = NULL;
+	u32 old_module_type_cnt;
 	int err = 0;
 
+	*relocated_inline_data = NULL;
 	vmlinux_btf = bpf_get_btf_vmlinux();
 	if (IS_ERR(vmlinux_btf))
 		return vmlinux_btf;
@@ -6953,67 +7076,68 @@ static struct btf *btf_parse_module(const char *module_name, const void *data,
 		base_btf = vmlinux_btf;
 	}
 
-	btf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);
-	if (!btf) {
-		err = -ENOMEM;
+	btf = btf_parse_split(env, module_name, data, data_size, base_btf);
+	if (IS_ERR(btf)) {
+		err = PTR_ERR(btf);
+		btf = NULL;
 		goto errout;
 	}
-	env->btf = btf;
-
-	btf->base_btf = base_btf;
-	btf->start_id = base_btf->nr_types;
-	btf->start_str_off = base_btf->hdr.str_len;
-	btf->kernel_btf = true;
-	btf->named_start_id = 0;
-	strscpy(btf->name, module_name);
+	old_module_type_cnt = btf_nr_types(btf);
 
-	btf->data = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);
-	if (!btf->data) {
-		err = -ENOMEM;
-		goto errout;
+	if (inline_data_size) {
+		inline_btf = btf_parse_split(env, module_name, inline_data,
+					     inline_data_size, btf);
+		if (IS_ERR(inline_btf)) {
+			pr_warn("failed to validate module [%s] inline BTF: %ld\n",
+				module_name, PTR_ERR(inline_btf));
+			inline_btf = NULL;
+		}
 	}
-	btf->data_size = data_size;
-
-	err = btf_parse_hdr(env);
-	if (err)
-		goto errout;
-
-	btf->nohdr_data = btf->data + btf->hdr.hdr_len;
-
-	err = btf_parse_str_sec(env);
-	if (err)
-		goto errout;
-
-	err = btf_check_all_metas(env);
-	if (err)
-		goto errout;
-
-	err = btf_check_modifier_chain_length(env, btf, btf_nr_types(base_btf));
-	if (err)
-		goto errout;
 
 	if (base_btf != vmlinux_btf) {
-		err = btf_relocate(btf, vmlinux_btf, &btf->base_id_map);
+		err = btf_relocate(btf, vmlinux_btf, &btf->base_id_map,
+				   &module_str_map);
 		if (err)
 			goto errout;
 		btf_free(base_btf);
 		base_btf = vmlinux_btf;
 	}
 
-	btf_verifier_env_free(env);
+	if (inline_btf) {
+		err = btf_rebase_inline(inline_btf, btf, btf->base_id_map,
+					module_str_map, old_module_type_cnt);
+		if (err) {
+			pr_warn("failed to relocate module [%s] inline BTF: %d\n",
+				module_name, err);
+			btf_free(inline_btf);
+		} else {
+			*relocated_inline_data = inline_btf->data;
+			inline_btf->data = NULL;
+			btf_free(inline_btf);
+		}
+	}
+
+	/*
+	 * With a distilled base, btf_relocate() replaces the base BTF and
+	 * rewrites string offsets. Check ordering only after that final BTF
+	 * view has been established, so named_start_id describes the BTF used
+	 * by name lookups.
+	 */
 	btf_check_sorted(btf);
+	btf_verifier_env_free(env);
+	kvfree(module_str_map);
 	refcount_set(&btf->refcnt, 1);
 	return btf;
 
 errout:
+	kvfree(module_str_map);
 	btf_verifier_env_free(env);
+	if (inline_btf)
+		btf_free(inline_btf);
 	if (!IS_ERR(base_btf) && base_btf != vmlinux_btf)
 		btf_free(base_btf);
-	if (btf) {
-		kvfree(btf->data);
-		kvfree(btf->types);
-		kfree(btf);
-	}
+	if (btf)
+		btf_free(btf);
 	return ERR_PTR(err);
 }
 
@@ -9007,6 +9131,8 @@ struct btf_module {
 	struct module *module;
 	struct btf *btf;
 	struct bin_attribute *sysfs_attr;
+	struct bin_attribute *sysfs_inline_attr;
+	void *btf_inline_data;
 	int flags;
 };
 
@@ -9015,28 +9141,149 @@ static DEFINE_MUTEX(btf_module_mutex);
 
 static void purge_cand_cache(struct btf *btf);
 
+#if IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE)
+extern char __start_BTF_inline_link[];
+extern char __stop_BTF_inline_link[];
+
+static struct bin_attribute *vmlinux_inline_attr;
+static const struct btf_link *vmlinux_inline_link;
+
+static const struct btf_link *btf_parse_link(void *start, unsigned int size)
+{
+	const struct btf_link *link = start;
+	unsigned int module_name_len;
+
+	if (!link || size != sizeof(*link) || link->btf_size == 0)
+		return NULL;
+
+	module_name_len = strnlen(link->module_name, sizeof(link->module_name));
+	if (!module_name_len || module_name_len == sizeof(link->module_name) ||
+	    memchr_inv(link->module_name + module_name_len + 1, 0,
+		       sizeof(link->module_name) - module_name_len - 1))
+		return NULL;
+	return link;
+}
+
+static bool btf_verify_link(const struct btf_link *link, const struct module *mod,
+			    const void *data, size_t data_size)
+{
+	u8 actual_digest[BTF_LINK_SHA256_LEN];
+
+	if (!link || data_size != link->btf_size) {
+		pr_warn(" BTF link from module [%s] missing or has unexpected size\n", mod->name);
+		return false;
+	}
+	sha256(data, data_size, actual_digest);
+	if (memcmp(actual_digest, link->sha256, sizeof(actual_digest))) {
+		pr_warn("BTF link from module [%s] has unexpected digest\n", mod->name);
+		return false;
+	}
+
+	return true;
+}
+
+static void btf_vmlinux_inline_lazy_init(void)
+{
+	vmlinux_inline_link = btf_parse_link(__start_BTF_inline_link,
+					     __stop_BTF_inline_link -
+					     __start_BTF_inline_link);
+	if (!vmlinux_inline_link) {
+		pr_warn("invalid vmlinux inline BTF link\n");
+		return;
+	}
+	vmlinux_inline_attr = sysfs_btf_add("vmlinux.inline", NULL,
+					    vmlinux_inline_link->btf_size, true,
+					    vmlinux_inline_link->module_name);
+	if (IS_ERR(vmlinux_inline_attr)) {
+		pr_warn("failed to register vmlinux inline BTF in sysfs: %ld\n",
+			PTR_ERR(vmlinux_inline_attr));
+		vmlinux_inline_attr = NULL;
+	}
+}
+
+static bool btf_module_is_vmlinux_inline(const struct module *mod)
+{
+	return vmlinux_inline_link && !strcmp(mod->name, vmlinux_inline_link->module_name);
+}
+
+static int btf_module_handle_vmlinux_inline(const struct module *mod)
+{
+	void *data;
+
+	if (!mod->btf_inline_data ||
+	    mod->btf_inline_data_size != vmlinux_inline_link->btf_size)
+		return -EINVAL;
+
+	data = vmalloc_user(mod->btf_inline_data_size);
+	if (!data)
+		return -ENOMEM;
+	memcpy(data, mod->btf_inline_data, mod->btf_inline_data_size);
+
+	if (!btf_verify_link(vmlinux_inline_link, mod, data, mod->btf_inline_data_size) ||
+	    !sysfs_btf_update(vmlinux_inline_attr, data)) {
+		kvfree(data);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+#else
+
+static bool btf_module_is_vmlinux_inline(const struct module *mod)
+{
+	return false;
+}
+
+static int btf_module_handle_vmlinux_inline(const struct module *mod)
+{
+	return 0;
+}
+
+static void btf_vmlinux_inline_lazy_init(void)
+{
+}
+
+#endif /* IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE) */
+
 static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 			     void *module)
 {
 	struct btf_module *btf_mod, *tmp;
 	struct module *mod = module;
+	struct bin_attribute *attr;
 	struct btf *btf;
+	void *inline_data = NULL, *relocated_inline_data = NULL;
+	unsigned int inline_data_size = 0;
 	int err = 0;
 
-	if (mod->btf_data_size == 0 ||
-	    (op != MODULE_STATE_COMING && op != MODULE_STATE_LIVE &&
-	     op != MODULE_STATE_GOING))
+	if (op != MODULE_STATE_COMING && op != MODULE_STATE_LIVE &&
+	    op != MODULE_STATE_GOING)
 		goto out;
 
 	switch (op) {
 	case MODULE_STATE_COMING:
+		if (btf_module_is_vmlinux_inline(mod)) {
+			err = btf_module_handle_vmlinux_inline(mod);
+			break;
+		}
+
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+		if (mod->btf_inline_data_size) {
+			inline_data = mod->btf_inline_data;
+			inline_data_size = mod->btf_inline_data_size;
+		}
+#endif
+		if (!mod->btf_data_size)
+			break;
 		btf_mod = kzalloc_obj(*btf_mod);
 		if (!btf_mod) {
 			err = -ENOMEM;
 			goto out;
 		}
 		btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size,
-				       mod->btf_base_data, mod->btf_base_data_size);
+				       mod->btf_base_data, mod->btf_base_data_size,
+				       inline_data, inline_data_size,
+				       &relocated_inline_data);
 		if (IS_ERR(btf)) {
 			kfree(btf_mod);
 			if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) {
@@ -9051,6 +9298,7 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 		err = btf_alloc_id(btf);
 		if (err) {
 			btf_free(btf);
+			kvfree(relocated_inline_data);
 			kfree(btf_mod);
 			goto out;
 		}
@@ -9059,37 +9307,35 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 		mutex_lock(&btf_module_mutex);
 		btf_mod->module = module;
 		btf_mod->btf = btf;
+		btf_mod->btf_inline_data = relocated_inline_data;
 		list_add(&btf_mod->list, &btf_modules);
 		mutex_unlock(&btf_module_mutex);
 
-		if (IS_ENABLED(CONFIG_SYSFS)) {
-			struct bin_attribute *attr;
-
-			attr = kzalloc_obj(*attr);
-			if (!attr)
-				goto out;
+		attr = sysfs_btf_add(btf->name, btf->data, btf->data_size, false, NULL);
+		if (IS_ERR(attr)) {
+			err = 0;
+			goto out;
+		}
+		btf_mod->sysfs_attr = attr;
 
-			sysfs_bin_attr_init(attr);
-			attr->attr.name = btf->name;
-			attr->attr.mode = 0444;
-			attr->size = btf->data_size;
-			attr->private = btf->data;
-			attr->read = sysfs_bin_attr_simple_read;
+		if (relocated_inline_data) {
+			char name[MODULE_NAME_LEN + sizeof(".inline")];
 
-			err = sysfs_create_bin_file(btf_kobj, attr);
-			if (err) {
-				pr_warn("failed to register module [%s] BTF in sysfs: %d\n",
-					mod->name, err);
-				kfree(attr);
+			snprintf(name, sizeof(name), "%s.inline", mod->name);
+			attr = sysfs_btf_add(name, relocated_inline_data,
+					     inline_data_size, false, NULL);
+			if (IS_ERR(attr)) {
+				kvfree(relocated_inline_data);
+				btf_mod->btf_inline_data = NULL;
 				err = 0;
-				goto out;
+				break;
 			}
-
-			btf_mod->sysfs_attr = attr;
+			btf_mod->sysfs_inline_attr = attr;
 		}
-
 		break;
 	case MODULE_STATE_LIVE:
+		if (!mod->btf_data_size)
+			break;
 		mutex_lock(&btf_module_mutex);
 		list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) {
 			if (btf_mod->module != module)
@@ -9101,6 +9347,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 		mutex_unlock(&btf_module_mutex);
 		break;
 	case MODULE_STATE_GOING:
+		if (!mod->btf_data_size)
+			break;
 		mutex_lock(&btf_module_mutex);
 		list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) {
 			if (btf_mod->module != module)
@@ -9115,10 +9363,12 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 			btf_free_id(btf_mod->btf);
 			list_del(&btf_mod->list);
 			if (btf_mod->sysfs_attr)
-				sysfs_remove_bin_file(btf_kobj, btf_mod->sysfs_attr);
+				sysfs_btf_remove(btf_mod->sysfs_attr);
+			if (btf_mod->sysfs_inline_attr)
+				sysfs_btf_remove(btf_mod->sysfs_inline_attr);
+			kvfree(btf_mod->btf_inline_data);
 			purge_cand_cache(btf_mod->btf);
 			btf_put(btf_mod->btf);
-			kfree(btf_mod->sysfs_attr);
 			kfree(btf_mod);
 			break;
 		}
@@ -9135,6 +9385,7 @@ static struct notifier_block btf_module_nb = {
 
 static int __init btf_module_init(void)
 {
+	btf_vmlinux_inline_lazy_init();
 	register_module_notifier(&btf_module_nb);
 	return 0;
 }
diff --git a/kernel/bpf/btf_vmlinux_inline.c b/kernel/bpf/btf_vmlinux_inline.c
new file mode 100644
index 0000000000000..d5c599d9f7295
--- /dev/null
+++ b/kernel/bpf/btf_vmlinux_inline.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026, Oracle and/or its affiliates. */
+/*
+ * Provide kernel BTF inline function information for use by BPF tools.
+ */
+#include <linux/btf.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)
+extern char __start_BTF_inline[];
+extern char __stop_BTF_inline[];
+#endif
+
+static int __init btf_vmlinux_inline_init(void)
+{
+#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)
+	size_t data_size = __stop_BTF_inline - __start_BTF_inline;
+
+	if (data_size)
+		sysfs_btf_add("vmlinux.inline", __start_BTF_inline, data_size, true, NULL);
+#endif
+	return 0;
+}
+subsys_initcall(btf_vmlinux_inline_init);
+
+MODULE_DESCRIPTION("BTF inline information for vmlinux");
+MODULE_LICENSE("GPL");
diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c
index 9cbe15ce3540c..556fe92c36495 100644
--- a/kernel/bpf/sysfs_btf.c
+++ b/kernel/bpf/sysfs_btf.c
@@ -6,8 +6,10 @@
 #include <linux/module.h>
 #include <linux/kobject.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/sysfs.h>
 #include <linux/mm.h>
+#include <linux/vmalloc.h>
 #include <linux/io.h>
 #include <linux/btf.h>
 
@@ -15,16 +17,12 @@
 extern char __start_BTF[];
 extern char __stop_BTF[];
 
-static int btf_sysfs_vmlinux_mmap(struct file *filp, struct kobject *kobj,
-				  const struct bin_attribute *attr,
-				  struct vm_area_struct *vma)
+static int btf_sysfs_mmap_check(void *data, size_t size, struct vm_area_struct *vma)
 {
-	unsigned long pages = PAGE_ALIGN(attr->size) >> PAGE_SHIFT;
+	unsigned long pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
 	size_t vm_size = vma->vm_end - vma->vm_start;
-	phys_addr_t addr = __pa_symbol(__start_BTF);
-	unsigned long pfn = addr >> PAGE_SHIFT;
 
-	if (attr->private != __start_BTF || !PAGE_ALIGNED(addr))
+	if (!data || !PAGE_ALIGNED((unsigned long)data))
 		return -EINVAL;
 
 	if (vma->vm_pgoff)
@@ -33,24 +31,153 @@ static int btf_sysfs_vmlinux_mmap(struct file *filp, struct kobject *kobj,
 	if (vma->vm_flags & (VM_WRITE | VM_EXEC | VM_MAYSHARE))
 		return -EACCES;
 
-	if (pfn + pages < pfn)
-		return -EINVAL;
-
 	if ((vm_size >> PAGE_SHIFT) > pages)
 		return -EINVAL;
 
 	vm_flags_mod(vma, VM_DONTDUMP, VM_MAYEXEC | VM_MAYWRITE);
+	return 0;
+}
+
+static int btf_sysfs_mmap_image(struct file *filp, struct kobject *kobj,
+				const struct bin_attribute *attr,
+				struct vm_area_struct *vma)
+{
+	void *data = READ_ONCE(attr->private);
+	phys_addr_t addr;
+	unsigned long pfn;
+	size_t vm_size = vma->vm_end - vma->vm_start;
+	int err;
+
+	err = btf_sysfs_mmap_check(data, attr->size, vma);
+	if (err)
+		return err;
+
+	/* Kernel image addresses can lie inside the vmalloc range on arm64. */
+	addr = __pa_symbol(data);
+	pfn = addr >> PAGE_SHIFT;
+	if (pfn + (PAGE_ALIGN(attr->size) >> PAGE_SHIFT) < pfn)
+		return -EINVAL;
+
 	return remap_pfn_range(vma, vma->vm_start, pfn, vm_size, vma->vm_page_prot);
 }
 
 static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {
 	.attr = { .name = "vmlinux", .mode = 0444, },
 	.read = sysfs_bin_attr_simple_read,
-	.mmap = btf_sysfs_vmlinux_mmap,
+	.mmap = btf_sysfs_mmap_image,
 };
 
 struct kobject *btf_kobj;
 
+struct btf_sysfs_entry {
+	struct bin_attribute attr;
+	char *module_name;
+};
+
+static void *btf_sysfs_lazy_data(const struct bin_attribute *attr)
+{
+	struct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);
+	void *data;
+
+	data = smp_load_acquire(&attr->private);
+	if (!data) {
+		request_module("%s", entry->module_name);
+		data = smp_load_acquire(&attr->private);
+	}
+	return data;
+}
+
+static ssize_t btf_sysfs_read_lazy(struct file *filp, struct kobject *kobj,
+				   const struct bin_attribute *attr, char *buf,
+				   loff_t off, size_t count)
+{
+	void *data = btf_sysfs_lazy_data(attr);
+
+	if (!data)
+		return -ENODEV;
+
+	return memory_read_from_buffer(buf, count, &off, data, attr->size);
+}
+
+static int btf_sysfs_mmap_lazy(struct file *filp, struct kobject *kobj,
+			       const struct bin_attribute *attr,
+			       struct vm_area_struct *vma)
+{
+	void *data = btf_sysfs_lazy_data(attr);
+	int err;
+
+	if (!data)
+		return -ENODEV;
+
+	err = btf_sysfs_mmap_check(data, attr->size, vma);
+	if (err)
+		return err;
+
+	return remap_vmalloc_range(vma, data, 0);
+}
+
+struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,
+				    bool mmap, const char *lazy_module_name)
+{
+	struct btf_sysfs_entry *entry;
+	struct bin_attribute *attr;
+	int err;
+
+	entry = kzalloc_obj(*entry);
+	if (!entry)
+		return ERR_PTR(-ENOMEM);
+
+	attr = &entry->attr;
+	sysfs_bin_attr_init(attr);
+	attr->attr.mode = 0444;
+	attr->size = data_size;
+	attr->private = data;
+	attr->read = lazy_module_name ? btf_sysfs_read_lazy : sysfs_bin_attr_simple_read;
+	if (mmap)
+		attr->mmap = lazy_module_name ? btf_sysfs_mmap_lazy : btf_sysfs_mmap_image;
+	attr->attr.name = kstrdup(name, GFP_KERNEL);
+	if (!attr->attr.name) {
+		err = -ENOMEM;
+		goto err_free;
+	}
+	if (lazy_module_name) {
+		entry->module_name = kstrdup(lazy_module_name, GFP_KERNEL);
+		if (!entry->module_name) {
+			err = -ENOMEM;
+			goto err_free;
+		}
+	}
+
+	err = sysfs_create_bin_file(btf_kobj, attr);
+	if (err) {
+		pr_warn("failed to register [%s] BTF in sysfs: %d\n", name, err);
+		goto err_free;
+	}
+
+	return attr;
+
+err_free:
+	kfree(entry->module_name);
+	kfree(attr->attr.name);
+	kfree(entry);
+	return ERR_PTR(err);
+}
+
+bool sysfs_btf_update(struct bin_attribute *attr, void *data)
+{
+	return attr && !cmpxchg(&attr->private, NULL, data);
+}
+
+void sysfs_btf_remove(struct bin_attribute *attr)
+{
+	struct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);
+
+	sysfs_remove_bin_file(btf_kobj, attr);
+	kfree(entry->module_name);
+	kfree(attr->attr.name);
+	kfree(entry);
+}
+
 static int __init btf_vmlinux_init(void)
 {
 	bin_attr_btf_vmlinux.private = __start_BTF;
diff --git a/kernel/module/main.c b/kernel/module/main.c
index c1b34dc1e89ac..5b9eb56164b29 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2723,6 +2723,10 @@ static int find_module_sections(struct module *mod, struct load_info *info)
 	mod->btf_base_data = any_section_objs(info, ".BTF.base", 1,
 					      &mod->btf_base_data_size);
 #endif
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+	mod->btf_inline_data = any_section_objs(info, ".BTF.inline", 1,
+						&mod->btf_inline_data_size);
+#endif
 #ifdef CONFIG_JUMP_LABEL
 	mod->jump_entries = section_objs(info, "__jump_table",
 					sizeof(*mod->jump_entries),
@@ -3176,6 +3180,9 @@ static noinline int do_init_module(struct module *mod)
 	/* .BTF is not SHF_ALLOC and will get removed, so sanitize pointers */
 	mod->btf_data = NULL;
 	mod->btf_base_data = NULL;
+#endif
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+	mod->btf_inline_data = NULL;
 #endif
 	/*
 	 * We want to free module_init, but be aware that kallsyms may be
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 134b15a44625e..2f34619905b60 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -425,6 +425,12 @@ config PAHOLE_HAS_LANG_EXCLUDE
 	  otherwise it would emit malformed kernel and module binaries when
 	  using DEBUG_INFO_BTF_MODULES.
 
+config PAHOLE_HAS_INLINE
+	def_bool PAHOLE_VERSION >= 132
+	help
+	  Support for the "inline" BTF feature is available. It encodes
+	  information about inline sites and how to retrieve their parameters.
+
 config DEBUG_INFO_BTF_MODULES
 	bool "Generate BTF type information for kernel modules"
 	default y
@@ -432,6 +438,18 @@ config DEBUG_INFO_BTF_MODULES
 	help
 	  Generate compact split BTF type information for kernel modules.
 
+config DEBUG_INFO_BTF_INLINE
+	tristate "Provide information about inline sites in BTF"
+	default n
+	depends on DEBUG_INFO_BTF && PAHOLE_HAS_INLINE && SYSFS
+	select DEBUG_INFO_BTF_MODULES if MODULES
+	help
+	  Generate information about inline sites in .BTF.inline sections.
+	  These sections contain split BTF relative to the kernel or module BTF
+	  and are made available in /sys/kernel/btf with a ".inline" suffix.
+	  The information describes inline locations and how to retrieve their
+	  associated parameters.
+
 config MODULE_ALLOW_BTF_MISMATCH
 	bool "Allow loading modules with non-matching BTF type info"
 	depends on DEBUG_INFO_BTF_MODULES
diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
index a1812985a61aa..98012344a81ec 100644
--- a/scripts/Makefile.btf
+++ b/scripts/Makefile.btf
@@ -22,7 +22,14 @@ endif
 
 pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE)		+= --lang_exclude=rust
 
+btf-inline := $(CONFIG_DEBUG_INFO_BTF_INLINE)
+ifneq ($(btf-inline),)
+btf-inline-feat := inline
+pahole-flags-$(call test-ge, $(pahole-ver), 132) += --btf_features=$(btf-inline-feat)
+endif
+
 export PAHOLE_FLAGS := $(pahole-flags-y)
+export BTF_INLINE := $(btf-inline)
 
 resolve-btfids-flags-y :=
 resolve-btfids-flags-$(CONFIG_WERROR) += --fatal_warnings
diff --git a/scripts/gen-btf.sh b/scripts/gen-btf.sh
index 8ca96eb10a69e..b17f1189298a5 100755
--- a/scripts/gen-btf.sh
+++ b/scripts/gen-btf.sh
@@ -68,6 +68,7 @@ esac
 
 gen_btf_data()
 {
+	inline=${BTF_INLINE:+--inline}
 	btf1="${ELF_FILE}.BTF.1"
 	${PAHOLE} -J ${PAHOLE_FLAGS}			\
 		${BTF_BASE:+--btf_base ${BTF_BASE}}	\
@@ -76,6 +77,7 @@ gen_btf_data()
 
 	${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_FLAGS}	\
 		${BTF_BASE:+--btf_base ${BTF_BASE}}	\
+		${inline}				\
 		--btf ${btf1} "${ELF_FILE}"
 }
 
@@ -83,14 +85,28 @@ gen_btf_o()
 {
 	btf_data=${ELF_FILE}.btf.o
 
-	# Create ${btf_data} which contains just .BTF section but no symbols. Add
+	# Create ${btf_data} which contains just BTF sections but no symbols. Add
 	# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all
 	# deletes all symbols including __start_BTF and __stop_BTF, which will
 	# be redefined in the linker script.
 	echo "" | ${CC} ${CLANG_FLAGS} ${KBUILD_CPPFLAGS} ${KBUILD_CFLAGS} -fno-lto -c -x c -o ${btf_data} -
 	${OBJCOPY} --add-section .BTF=${ELF_FILE}.BTF \
 		--set-section-flags .BTF=alloc,readonly ${btf_data}
-	${OBJCOPY} --only-section=.BTF --strip-all ${btf_data}
+	ONLY_SEC="--only-section=.BTF"
+	btf_inline=${ELF_FILE}.BTF.inline
+	if [ "${BTF_INLINE}" = "m" ]; then
+		if [ -f "${btf_inline}" ]; then
+			cp "${btf_inline}" "${objtree}/vmlinux.BTF.inline"
+		else
+			rm -f "${objtree}/vmlinux.BTF.inline"
+		fi
+	fi
+	if [ "${BTF_INLINE}" = "y" ] && [ -f "${btf_inline}" ]; then
+		${OBJCOPY} --add-section .BTF.inline=${btf_inline} \
+			--set-section-flags .BTF.inline=alloc,readonly ${btf_data}
+		ONLY_SEC="${ONLY_SEC} --only-section=.BTF.inline"
+	fi
+	${OBJCOPY} ${ONLY_SEC} --strip-all ${btf_data}
 
 	# Change e_type to ET_REL so that it can be used to link final vmlinux.
 	# GNU ld 2.35+ and lld do not allow an ET_EXEC input.
@@ -111,6 +127,15 @@ embed_btf_data()
 	if [ -f "${btf_base}" ]; then
 		${OBJCOPY} --add-section .BTF.base=${btf_base} ${ELF_FILE}
 	fi
+	btf_inline=${ELF_FILE}.BTF.inline
+	case "${ELF_FILE}" in
+	*/btf_vmlinux_inline.ko)
+		btf_inline=${BTF_BASE}.BTF.inline
+		;;
+	esac
+	if [ -n "${BTF_INLINE}" ] && [ -f "${btf_inline}" ]; then
+		${OBJCOPY} --add-section .BTF.inline=${btf_inline} ${ELF_FILE}
+	fi
 	btf_ids="${ELF_FILE}.BTF_ids"
 	if [ -f "${btf_ids}" ]; then
 		${RESOLVE_BTFIDS} --patch_btfids ${btf_ids} ${ELF_FILE}
@@ -121,6 +146,8 @@ cleanup()
 {
 	rm -f "${ELF_FILE}.BTF.1"
 	rm -f "${ELF_FILE}.BTF"
+	rm -f "${ELF_FILE}.BTF.inline"
+	rm -f "${ELF_FILE}.BTF.inline.link"
 	if [ "${BTFGEN_MODE}" = "module" ]; then
 		rm -f "${ELF_FILE}.BTF.base"
 		rm -f "${ELF_FILE}.BTF_ids"
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index ab0b8125c8cbc..5424caf5135bc 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -289,7 +289,13 @@ vmlinux_link "${VMLINUX}"
 
 if is_enabled CONFIG_DEBUG_INFO_BTF; then
 	info BTFIDS ${VMLINUX}
-	${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}
+	if [ "${BTF_INLINE}" = "m" ]; then
+		${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} \
+			--btf_link .BTF.inline:btf_vmlinux_inline:vmlinux.BTF.inline \
+			${VMLINUX}
+	else
+		${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}
+	fi
 fi
 
 mksysmap "${VMLINUX}" System.map
diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec
index 46e80970f7239..8f0933cbbe452 100644
--- a/scripts/package/kernel.spec
+++ b/scripts/package/kernel.spec
@@ -68,13 +68,13 @@ This package provides debug information for the kernel image and modules from th
 %undefine _debugsource_packages
 %undefine _debuginfo_subpackages
 
-# Preserve .BTF and .BTF.base sections in kernel modules during debuginfo
-# stripping. find-debuginfo.sh uses eu-strip which removes non-allocated ELF
-# sections like .BTF by default. .BTF.base is required for BTF distillation
-# support; without it, module BTF validation fails.
+# Preserve .BTF,  .BTF.base and .BTF.inline sections in kernel modules during
+# debuginfo stripping. find-debuginfo.sh uses eu-strip which removes
+# non-allocated ELF sections like .BTF by default. .BTF.base is required for
+# BTF distillation support; without it, module BTF validation fails.
 %global with_keep_section %(%{__find_debuginfo} --help 2>&1 | grep -c keep-section)
 %if %{with_keep_section}
-%global _find_debuginfo_opts -r --keep-section .BTF --keep-section .BTF.base
+%global _find_debuginfo_opts -r --keep-section .BTF --keep-section .BTF.base --keep-section .BTF.inline
 %else
 %global _find_debuginfo_opts -r
 %endif
diff --git a/tools/bpf/resolve_btfids/Build b/tools/bpf/resolve_btfids/Build
index 077de3829c722..602e1508bf092 100644
--- a/tools/bpf/resolve_btfids/Build
+++ b/tools/bpf/resolve_btfids/Build
@@ -1,6 +1,7 @@
 hostprogs := resolve_btfids
 
 resolve_btfids-y += main.o
+resolve_btfids-y += btf_colors.o
 resolve_btfids-y += rbtree.o
 resolve_btfids-y += zalloc.o
 resolve_btfids-y += string.o
diff --git a/tools/bpf/resolve_btfids/btf_colors.c b/tools/bpf/resolve_btfids/btf_colors.c
new file mode 100644
index 0000000000000..5d307d70e7f22
--- /dev/null
+++ b/tools/bpf/resolve_btfids/btf_colors.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <bpf/libbpf_internal.h>
+#include "btf_colors.h"
+
+/*
+ * Functions in this file mainly exist to refer to functions from libbpf_internal.h,
+ * which can't be included in main.c because of the u32 poison and pr_warn macro conflicts.
+ */
+
+void btf_sha256(const void *data, size_t len,
+		__u8 out[BTF_SHA256_DIGEST_LENGTH])
+{
+	libbpf_sha256(data, len, out);
+}
+
+/*
+ * Marks `root_id` and local types reachable from it with `color`.
+ * `colors` is indexed by source ID; worklist has room for every local type.
+ */
+void btf_mark_reachable(struct btf *btf, __u32 root_id, enum btf_color color,
+			__u8 *colors, __u32 *worklist)
+{
+	const struct btf *base = btf__base_btf(btf);
+	__u32 start_id = base ? btf__type_cnt(base) : 1;
+	__u32 pending = 0;
+
+	if (root_id < start_id || (colors[root_id] & color) == color)
+		return;
+	colors[root_id] |= color;
+	worklist[pending++] = root_id;
+	while (pending) {
+		const struct btf_type *t = btf__type_by_id(btf, worklist[--pending]);
+		struct btf_field_iter it;
+		__u32 *id;
+
+		btf_field_iter_init(&it, (struct btf_type *)t, BTF_FIELD_ITER_IDS);
+		while ((id = btf_field_iter_next(&it))) {
+			if (*id < start_id || (colors[*id] & color) == color)
+				continue;
+			colors[*id] |= color;
+			worklist[pending++] = *id;
+		}
+	}
+}
+
+static int cmp_loc(const void *a, const void *b)
+{
+	const struct btf_loc *la = a, *lb = b;
+
+	if (la->func != lb->func)
+		return la->func < lb->func ? -1 : 1;
+	if (la->offset != lb->offset)
+		return la->offset < lb->offset ? -1 : 1;
+	if (la->loc_proto != lb->loc_proto)
+		return la->loc_proto < lb->loc_proto ? -1 : 1;
+	return 0;
+}
+
+static void remap(struct btf *btf, const __u32 *id_map, __u32 src_start_id)
+{
+	const struct btf *base = btf__base_btf(btf);
+	__u32 start_id = base ? btf__type_cnt(base) : 1;
+	__u32 i, type_cnt = btf__type_cnt(btf);
+
+	for (i = start_id; i < type_cnt; i++) {
+		struct btf_type *t = (struct btf_type *)btf__type_by_id(btf, i);
+		struct btf_field_iter it;
+		__u32 *id;
+
+		btf_field_iter_init(&it, t, BTF_FIELD_ITER_IDS);
+		while ((id = btf_field_iter_next(&it))) {
+			/* Void and types in the original ancestor are unchanged. */
+			if (*id >= src_start_id)
+				*id = id_map[*id - src_start_id];
+		}
+		if (btf_is_locsec(t))
+			qsort(btf_locsec_locs(t), btf_vlen(t), sizeof(struct btf_loc), cmp_loc);
+	}
+}
+
+/*
+ * Split the `src` into `main_out` base and `inline_out`,
+ * according to `colors` array. Relative ordering remains
+ * the same as in `src`.
+ */
+int btf_split_by_color(struct btf *src, const __u8 *colors,
+		       struct btf **main_out, struct btf **inline_out)
+{
+	LIBBPF_OPTS(btf_new_opts, opts,
+		    .base_btf = (struct btf *)btf__base_btf(src),
+		    .add_layout = btf_header(src)->layout_len != 0,
+	);
+	struct btf *main_btf, *inline_btf = NULL;
+	__u32 start_id = opts.base_btf ? btf__type_cnt(opts.base_btf) : 1;
+	__u32 type_cnt = btf__type_cnt(src);
+	__u32 *id_map, i;
+	int err = -ENOMEM;
+
+	*main_out = NULL;
+	*inline_out = NULL;
+	id_map = malloc((type_cnt - start_id ?: 1) * sizeof(*id_map));
+	if (!id_map)
+		return -ENOMEM;
+	main_btf = btf__new_empty_opts(&opts);
+	if (!main_btf)
+		goto out;
+	btf__set_endianness(main_btf, btf__endianness(src));
+	/* Copy MAIN and SHARED marked types to `main_out`. */
+	for (i = start_id; i < type_cnt; i++) {
+		if (colors[i] == BTF_COLOR_LOC)
+			continue;
+		err = btf__add_type(main_btf, src, btf__type_by_id(src, i));
+		if (err < 0)
+			goto out;
+		id_map[i - start_id] = err;
+	}
+	/*
+	 * Copy LOC marked types to `inline_out`.
+	 * `main_btf` types count is stable at this point.
+	 */
+	inline_btf = btf__new_empty_split(main_btf);
+	if (!inline_btf) {
+		err = -ENOMEM;
+		goto out;
+	}
+	for (i = start_id; i < type_cnt; i++) {
+		if (colors[i] != BTF_COLOR_LOC)
+			continue;
+		err = btf__add_type(inline_btf, src, btf__type_by_id(src, i));
+		if (err < 0)
+			goto out;
+		id_map[i - start_id] = err;
+	}
+	remap(main_btf, id_map, start_id);
+	remap(inline_btf, id_map, start_id);
+	*main_out = main_btf;
+	*inline_out = inline_btf;
+	free(id_map);
+	return 0;
+out:
+	btf__free(inline_btf);
+	btf__free(main_btf);
+	free(id_map);
+	return err;
+}
diff --git a/tools/bpf/resolve_btfids/btf_colors.h b/tools/bpf/resolve_btfids/btf_colors.h
new file mode 100644
index 0000000000000..56a85a242d6bd
--- /dev/null
+++ b/tools/bpf/resolve_btfids/btf_colors.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __RESOLVE_BTFIDS_BTF_COLORS_H
+#define __RESOLVE_BTFIDS_BTF_COLORS_H
+
+#include <bpf/btf.h>
+
+enum btf_color {
+	BTF_COLOR_NONE = 0,
+	BTF_COLOR_MAIN = 1,
+	BTF_COLOR_LOC = 2,
+	BTF_COLOR_SHARED = BTF_COLOR_MAIN | BTF_COLOR_LOC,
+};
+
+#define BTF_SHA256_DIGEST_LENGTH	32
+
+void btf_sha256(const void *data, size_t len,
+		__u8 out[BTF_SHA256_DIGEST_LENGTH]);
+void btf_mark_reachable(struct btf *btf, __u32 root, enum btf_color color,
+			__u8 *colors, __u32 *worklist);
+
+int btf_split_by_color(struct btf *src, const __u8 *colors,
+		       struct btf **main_out, struct btf **inline_out);
+
+#endif
diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 37d7e7224207d..f737fac60fa24 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -89,9 +89,11 @@
 #include <linux/limits.h>
 #include <bpf/btf.h>
 #include <bpf/libbpf.h>
+#include "btf_colors.h"
 #include <subcmd/parse-options.h>
 
 #define BTF_IDS_SECTION	".BTF_ids"
+#define BTF_LINK_MODULE_NAME_MAX	64
 #define BTF_ID_PREFIX	"__BTF_ID__"
 
 #define BTF_STRUCT	"struct"
@@ -142,7 +144,10 @@ struct object {
 
 	struct btf *btf;
 	struct btf *base_btf;
+	struct btf *inline_btf;
+	struct btf *orig_btf;
 	bool distill_base;
+	bool extract_inline;
 
 	struct {
 		int		 fd;
@@ -154,6 +159,11 @@ struct object {
 		size_t		 strtabidx;
 		unsigned long	 idlist_addr;
 		int		 encoding;
+		int		 elf_class;
+		const char	**func_symbols;
+		u32		 func_symbols_cnt;
+		u32		 func_symbols_cap;
+		bool		 func_symbols_collected;
 	} efile;
 
 	struct rb_root	sets;
@@ -172,6 +182,19 @@ struct object {
 	u32 addr_syms_cap;
 };
 
+struct btf_link {
+	char *value;
+	char *section;
+	char *module;
+	char *btf_path;
+};
+
+struct btf_links {
+	struct btf_link *links;
+	u32 cnt;
+	u32 cap;
+};
+
 #define DECL_TAG_FASTCALL "bpf_fastcall"
 #define DECL_TAG_KFUNC "bpf_kfunc"
 
@@ -259,6 +282,49 @@ static int __ensure_mem(void **data, u32 *cap, u32 cnt, size_t elem_sz)
 #define ensure_mem(arr_ptr, cap_ptr, cnt) \
 	__ensure_mem((void **)(arr_ptr), (cap_ptr), (cnt), sizeof(**(arr_ptr)))
 
+static int parse_btf_link(const struct option *opt, const char *arg, int unset)
+{
+	struct btf_links *links = opt->value;
+	struct btf_link *link;
+	char *separator;
+
+	if (unset)
+		return -EINVAL;
+	if (__ensure_mem((void **)&links->links, &links->cap, links->cnt + 1,
+			 sizeof(*links->links)))
+		return -ENOMEM;
+	link = &links->links[links->cnt];
+	memset(link, 0, sizeof(*link));
+	link->value = strdup(arg);
+	if (!link->value)
+		return -ENOMEM;
+	link->section = link->value;
+	separator = strchr(link->section, ':');
+	if (!separator || separator == link->section)
+		goto err_value;
+	*separator++ = '\0';
+	link->module = separator;
+	separator = strchr(link->module, ':');
+	if (!separator || separator == link->module || !separator[1])
+		goto err_value;
+	*separator++ = '\0';
+	link->btf_path = separator;
+	links->cnt++;
+	return 0;
+err_value:
+	free(link->value);
+	return -EINVAL;
+}
+
+static void free_btf_links(struct btf_links *links)
+{
+	u32 i;
+
+	for (i = 0; i < links->cnt; i++)
+		free(links->links[i].value);
+	free(links->links);
+}
+
 static bool is_btf_id(const char *name)
 {
 	return name && !strncmp(name, BTF_ID_PREFIX, sizeof(BTF_ID_PREFIX) - 1);
@@ -480,6 +546,7 @@ static int elf_collect(struct object *obj)
 		return -1;
 	}
 	obj->efile.encoding = ehdr.e_ident[EI_DATA];
+	obj->efile.elf_class = ehdr.e_ident[EI_CLASS];
 
 	/*
 	 * Scan all the elf sections and look for save data
@@ -572,6 +639,58 @@ static const char *find_name_by_addr(struct object *obj, Elf64_Addr addr)
 	return res ? res->name : NULL;
 }
 
+static int cmp_func_symbol(const void *a, const void *b)
+{
+	const char * const *name = a;
+	const char * const *other = b;
+
+	return strcmp(*name, *other);
+}
+
+static int collect_func_symbols(struct object *obj)
+{
+	Elf_Scn *scn;
+	GElf_Shdr sh;
+	int n, i;
+
+	if (obj->efile.symbols_shndx == -1)
+		return 0;
+
+	scn = elf_getscn(obj->efile.elf, obj->efile.symbols_shndx);
+	if (!scn || gelf_getshdr(scn, &sh) != &sh || !sh.sh_entsize)
+		return -EINVAL;
+	n = sh.sh_size / sh.sh_entsize;
+
+	for (i = 0; i < n; i++) {
+		GElf_Sym sym;
+		const char *name;
+
+		if (!gelf_getsym(obj->efile.symbols, i, &sym))
+			return -EINVAL;
+		if (GELF_ST_TYPE(sym.st_info) != STT_FUNC ||
+		    sym.st_shndx == SHN_UNDEF || !sym.st_name)
+			continue;
+		name = elf_strptr(obj->efile.elf, obj->efile.strtabidx, sym.st_name);
+		if (!name)
+			return -EINVAL;
+		if (ensure_mem(&obj->efile.func_symbols, &obj->efile.func_symbols_cap,
+			       obj->efile.func_symbols_cnt + 1))
+			return -ENOMEM;
+		obj->efile.func_symbols[obj->efile.func_symbols_cnt++] = name;
+	}
+
+	qsort(obj->efile.func_symbols, obj->efile.func_symbols_cnt,
+	      sizeof(*obj->efile.func_symbols), cmp_func_symbol);
+	obj->efile.func_symbols_collected = true;
+	return 0;
+}
+
+static bool has_func_symbol(const struct object *obj, const char *name)
+{
+	return bsearch(&name, obj->efile.func_symbols, obj->efile.func_symbols_cnt,
+		       sizeof(*obj->efile.func_symbols), cmp_func_symbol) != NULL;
+}
+
 static int symbols_collect(struct object *obj)
 {
 	Elf_Scn *scn = NULL;
@@ -688,8 +807,9 @@ static int load_btf(struct object *obj)
 		if (err) {
 			pr_err("FAILED: load base BTF from %s: %s\n",
 			       obj->base_btf_path, strerror(-err));
-			goto out_err;
+			return err;
 		}
+		obj->base_btf = base_btf;
 	}
 
 	btf = btf__parse_split(obj->btf_path ?: obj->path, base_btf);
@@ -697,20 +817,12 @@ static int load_btf(struct object *obj)
 	if (err) {
 		pr_err("FAILED: load BTF from %s: %s\n",
 			obj->btf_path ?: obj->path, strerror(-err));
-		goto out_err;
+		return err;
 	}
 
-	obj->base_btf = base_btf;
 	obj->btf = btf;
 
 	return 0;
-
-out_err:
-	btf__free(base_btf);
-	btf__free(btf);
-	obj->base_btf = NULL;
-	obj->btf = NULL;
-	return err;
 }
 
 static int symbols_resolve(struct object *obj)
@@ -977,6 +1089,153 @@ static int dump_raw_btf(struct btf *btf, const char *out_path)
 	return 0;
 }
 
+static int patch_btf_link(struct object *obj, const struct btf_link *link)
+{
+	char section[128];
+	void *raw_btf_data = NULL;
+	size_t shdrstrndx, module_name_len;
+	int fd = -1, len, err = -1;
+	FILE *btf_file = NULL;
+	Elf_Scn *scn = NULL;
+	u32 raw_btf_size;
+	struct stat st;
+	Elf_Data *data;
+	GElf_Shdr sh;
+	char *name;
+	Elf *elf = NULL;
+	u8 *size;
+
+	if (stat(link->btf_path, &st)) {
+		err = -errno;
+		pr_err("FAILED to stat BTF file %s: %s\n",
+		       link->btf_path, strerror(errno));
+		return err;
+	}
+	if (!S_ISREG(st.st_mode) || st.st_size <= 0 || st.st_size > UINT_MAX) {
+		pr_err("FAILED: invalid BTF file size or type: %s\n", link->btf_path);
+		return -EINVAL;
+	}
+	raw_btf_size = st.st_size;
+	raw_btf_data = malloc(raw_btf_size);
+	if (!raw_btf_data) {
+		pr_err("FAILED to allocate %u bytes for BTF file %s\n",
+		       raw_btf_size, link->btf_path);
+		return -ENOMEM;
+	}
+	btf_file = fopen(link->btf_path, "rb");
+	if (!btf_file) {
+		err = -errno;
+		pr_err("FAILED to open BTF file %s: %s\n",
+		       link->btf_path, strerror(errno));
+		goto out;
+	}
+	if (fread(raw_btf_data, raw_btf_size, 1, btf_file) != 1) {
+		err = -EIO;
+		pr_err("FAILED to read BTF file %s\n", link->btf_path);
+		goto out;
+	}
+	fclose(btf_file);
+	btf_file = NULL;
+	if (obj->efile.elf_class == ELFCLASS32) {
+		module_name_len = BTF_LINK_MODULE_NAME_MAX - 4;
+	} else if (obj->efile.elf_class == ELFCLASS64) {
+		module_name_len = BTF_LINK_MODULE_NAME_MAX - 8;
+	} else {
+		err = -EINVAL;
+		pr_err("FAILED: unsupported ELF class %u in %s\n",
+		       obj->efile.elf_class, obj->path);
+		goto out;
+	}
+	if (strlen(link->module) >= module_name_len) {
+		err = -EINVAL;
+		pr_err("FAILED: module name too long for BTF link: %s\n", link->module);
+		goto out;
+	}
+	len = snprintf(section, sizeof(section), "%s.link", link->section);
+	if (len < 0 || len >= sizeof(section)) {
+		err = -ENAMETOOLONG;
+		pr_err("FAILED: BTF link section name too long: %s.link\n", link->section);
+		goto out;
+	}
+
+	fd = open(obj->path, O_RDWR);
+	if (fd < 0) {
+		err = -errno;
+		pr_err("FAILED to open %s: %s\n", obj->path, strerror(errno));
+		goto out;
+	}
+	elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
+	if (!elf) {
+		err = -EINVAL;
+		pr_err("FAILED to create ELF descriptor for %s: %s\n",
+		       obj->path, elf_errmsg(-1));
+		goto out;
+	}
+	elf_flagelf(elf, ELF_C_SET, ELF_F_LAYOUT);
+	if (elf_getshdrstrndx(elf, &shdrstrndx)) {
+		pr_err("FAILED to get section name index from %s: %s\n",
+		       obj->path, elf_errmsg(-1));
+		goto out;
+	}
+	while ((scn = elf_nextscn(elf, scn))) {
+		if (gelf_getshdr(scn, &sh) != &sh) {
+			pr_err("FAILED to get section header from %s: %s\n",
+			       obj->path, elf_errmsg(-1));
+			goto out;
+		}
+		name = elf_strptr(elf, shdrstrndx, sh.sh_name);
+		if (name && !strcmp(name, section))
+			break;
+	}
+	if (!scn) {
+		pr_err("FAILED: section %s not found in %s\n", section, obj->path);
+		goto out;
+	}
+	data = elf_getdata(scn, NULL);
+	if (sh.sh_type != SHT_PROGBITS || !data || !data->d_buf ||
+	    data->d_size != module_name_len +
+		BTF_SHA256_DIGEST_LENGTH + sizeof(u32)) {
+		pr_err("FAILED: section %s is not a writable BTF link\n", section);
+		goto out;
+	}
+	memset(data->d_buf, 0, data->d_size);
+	memcpy(data->d_buf, link->module, strlen(link->module) + 1);
+	btf_sha256(raw_btf_data, raw_btf_size,
+		   (u8 *)data->d_buf + module_name_len);
+	size = (u8 *)data->d_buf + module_name_len + BTF_SHA256_DIGEST_LENGTH;
+	if (obj->efile.encoding == ELFDATA2LSB) {
+		size[0] = raw_btf_size;
+		size[1] = raw_btf_size >> 8;
+		size[2] = raw_btf_size >> 16;
+		size[3] = raw_btf_size >> 24;
+	} else if (obj->efile.encoding == ELFDATA2MSB) {
+		size[0] = raw_btf_size >> 24;
+		size[1] = raw_btf_size >> 16;
+		size[2] = raw_btf_size >> 8;
+		size[3] = raw_btf_size;
+	} else {
+		pr_err("FAILED: unsupported ELF data encoding %u in %s\n",
+		       obj->efile.encoding, obj->path);
+		goto out;
+	}
+	elf_flagdata(data, ELF_C_SET, ELF_F_DIRTY);
+	if (elf_update(elf, ELF_C_WRITE) < 0) {
+		pr_err("FAILED to update ELF file %s: %s\n",
+		       obj->path, elf_errmsg(-1));
+		goto out;
+	}
+	err = 0;
+out:
+	if (elf)
+		elf_end(elf);
+	if (fd >= 0)
+		close(fd);
+	if (btf_file)
+		fclose(btf_file);
+	free(raw_btf_data);
+	return err;
+}
+
 static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, s32 type_id)
 {
 	const struct btf_type *t = btf__type_by_id(btf, type_id);
@@ -1510,6 +1769,84 @@ static int btf2btf(struct object *obj)
 	return err;
 }
 
+static bool keep_in_base_btf(struct object *obj, const struct btf_type *t)
+{
+	const char *name;
+
+	switch (btf_kind(t)) {
+	case BTF_KIND_FUNC:
+		name = btf__name_by_offset(obj->btf, t->name_off);
+		return !obj->efile.func_symbols_collected || has_func_symbol(obj, name) ||
+		       btf_id__find(&obj->funcs, name);
+	case BTF_KIND_FUNC_PROTO:
+	case BTF_KIND_LOC_PARAM:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
+		return false;
+	default:
+		/*
+		 * Ordinary types stay in base btf even if only inline records use them.
+		 * Should we relax this?
+		 */
+		return true;
+	}
+}
+
+/* Mark which types should go to .BTF.inline */
+static int color_btf(struct object *obj, __u8 *colors)
+{
+	struct btf *btf = obj->btf;
+	const struct btf *base = btf__base_btf(btf);
+	__u32 start_id = base ? btf__type_cnt(base) : 1;
+	__u32 type_cnt = btf__type_cnt(btf), i;
+	__u32 *worklist;
+
+	worklist = malloc((type_cnt - start_id ?: 1) * sizeof(*worklist));
+	if (!worklist)
+		return -ENOMEM;
+	/* First, mark all types reachable from LOC BTF entries. */
+	for (i = start_id; i < type_cnt; i++) {
+		const struct btf_type *t = btf__type_by_id(btf, i);
+
+		if (!btf_is_locsec(t) && !btf_is_loc_proto(t) && !btf_is_loc_param(t))
+			continue;
+		btf_mark_reachable(btf, i, BTF_COLOR_LOC, colors, worklist);
+	}
+	/* Next, traverse non-marked types converting some LOC markings to SHARED. */
+	for (i = start_id; i < type_cnt; i++) {
+		const struct btf_type *t = btf__type_by_id(btf, i);
+
+		if (colors[i] == BTF_COLOR_LOC && !keep_in_base_btf(obj, t))
+			continue;
+		btf_mark_reachable(btf, i, BTF_COLOR_MAIN, colors, worklist);
+	}
+	free(worklist);
+	return 0;
+}
+
+static int extract_inline_btf(struct object *obj)
+{
+	struct btf *btf = obj->btf, *main_btf, *inline_btf;
+	__u8 *colors;
+	int err;
+
+	colors = calloc(btf__type_cnt(btf), sizeof(*colors));
+	if (!colors)
+		return -ENOMEM;
+	err = color_btf(obj, colors);
+	if (err)
+		goto out;
+	err = btf_split_by_color(btf, colors, &main_btf, &inline_btf);
+	if (!err) {
+		obj->orig_btf = btf;
+		obj->btf = main_btf;
+		obj->inline_btf = inline_btf;
+	}
+out:
+	free(colors);
+	return err;
+}
+
 /*
  * Sort types by name in ascending order resulting in all
  * anonymous types being placed before named types.
@@ -1583,14 +1920,14 @@ static int finalize_btf(struct object *obj)
 	err = btf__dedup(obj->btf, NULL);
 	if (err) {
 		pr_err("FAILED to dedup BTF: %s\n", strerror(errno));
-		goto out_err;
+		return err;
 	}
 
 	if (obj->base_btf && obj->distill_base) {
 		err = btf__distill_base(obj->btf, &base_btf, &btf);
 		if (err) {
 			pr_err("FAILED to distill base BTF: %s\n", strerror(errno));
-			goto out_err;
+			return err;
 		}
 
 		btf__free(obj->base_btf);
@@ -1602,18 +1939,18 @@ static int finalize_btf(struct object *obj)
 	err = sort_btf_by_name(obj->btf);
 	if (err) {
 		pr_err("FAILED to sort BTF: %s\n", strerror(errno));
-		goto out_err;
+		return err;
 	}
 
-	return 0;
-
-out_err:
-	btf__free(base_btf);
-	btf__free(btf);
-	obj->base_btf = NULL;
-	obj->btf = NULL;
+	if (obj->extract_inline) {
+		err = extract_inline_btf(obj);
+		if (err) {
+			pr_err("FAILED to extract inline BTF: %s\n", strerror(-err));
+			return err;
+		}
+	}
 
-	return err;
+	return 0;
 }
 
 static inline int make_out_path(char *buf, u32 buf_sz, const char *in_path, const char *suffix)
@@ -1740,7 +2077,7 @@ static int patch_btfids(const char *btfids_path, const char *elf_path)
 
 static const char * const resolve_btfids_usage[] = {
 	"resolve_btfids [<options>] <ELF object>",
-	"resolve_btfids --patch_btfids <.BTF_ids file> <ELF object>",
+	"resolve_btfids --patch_btfids <.BTF_ids file> [--btf_link <section:module:btf-file>] <ELF object>",
 	NULL
 };
 
@@ -1758,6 +2095,7 @@ int main(int argc, const char **argv)
 		.sets     = RB_ROOT,
 	};
 	const char *btfids_path = NULL;
+	struct btf_links btf_links = {};
 	bool fatal_warnings = false;
 	bool resolve_btfids = true;
 	char out_path[PATH_MAX];
@@ -1773,6 +2111,10 @@ int main(int argc, const char **argv)
 			    "turn warnings into errors"),
 		OPT_BOOLEAN(0, "distill_base", &obj.distill_base,
 			    "distill --btf_base and emit .BTF.base section data"),
+		OPT_BOOLEAN(0, "inline", &obj.extract_inline,
+			    "extract location BTF into a .BTF.inline file"),
+		OPT_CALLBACK(0, "btf_link", &btf_links, "section:module:btf-file",
+			     "patch a BTF link with --patch_btfids", parse_btf_link),
 		OPT_STRING(0, "patch_btfids", &btfids_path, "file",
 			   "path to .BTF_ids section data blob to patch into ELF file"),
 		OPT_END()
@@ -1783,14 +2125,34 @@ int main(int argc, const char **argv)
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	if (argc != 1)
 		usage_with_options(resolve_btfids_usage, btfid_options);
+	if (btf_links.cnt && !btfids_path) {
+		pr_err("--btf_link requires --patch_btfids\n");
+		goto out;
+	}
 
 	obj.path = argv[0];
 
-	if (btfids_path)
-		return patch_btfids(btfids_path, obj.path);
+	if (btfids_path) {
+		err = patch_btfids(btfids_path, obj.path);
+		if (err || !btf_links.cnt)
+			goto out;
+		if (elf_collect(&obj)) {
+			err = -EINVAL;
+			goto out;
+		}
+		for (u32 i = 0; i < btf_links.cnt; i++) {
+			struct btf_link *link = &btf_links.links[i];
 
+			err = patch_btf_link(&obj, link);
+			if (err)
+				break;
+		}
+		goto out;
+	}
 	if (elf_collect(&obj))
 		goto out;
+	if (obj.extract_inline && collect_func_symbols(&obj))
+		goto out;
 
 	/*
 	 * We did not find .BTF_ids section or symbols section,
@@ -1841,18 +2203,33 @@ int main(int argc, const char **argv)
 		if (err)
 			goto out;
 	}
+	if (obj.inline_btf) {
+		err = make_out_path(out_path, sizeof(out_path), obj.path, BTF_ELF_SEC ".inline");
+		err = err ?: dump_raw_btf(obj.inline_btf, out_path);
+		if (err)
+			goto out;
+	}
 
 	if (!(fatal_warnings && warnings))
 		err = 0;
 out:
-	btf__free(obj.base_btf);
+	free_btf_links(&btf_links);
+	/*
+	 * Free BTFs in reverse dependency order.  inline_btf borrows obj.btf;
+	 * obj.btf can borrow a base owned by orig_btf or obj.base_btf, and
+	 * orig_btf can also borrow obj.base_btf.
+	 */
+	btf__free(obj.inline_btf);
 	btf__free(obj.btf);
+	btf__free(obj.orig_btf);
+	btf__free(obj.base_btf);
 	btf_id__free_all(&obj.structs);
 	btf_id__free_all(&obj.unions);
 	btf_id__free_all(&obj.typedefs);
 	btf_id__free_all(&obj.funcs);
 	btf_id__free_all(&obj.sets);
 	free(obj.addr_syms);
+	free(obj.efile.func_symbols);
 	if (obj.efile.elf) {
 		elf_end(obj.efile.elf);
 		close(obj.efile.fd);
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 512b3962f75f8..d2ff6f5d6d5b6 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -6640,7 +6640,7 @@ void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)
 
 int btf__relocate(struct btf *btf, const struct btf *base_btf)
 {
-	int err = btf_relocate(btf, base_btf, NULL);
+	int err = btf_relocate(btf, base_btf, NULL, NULL);
 
 	if (!err)
 		btf->owns_base = false;
diff --git a/tools/lib/bpf/btf_relocate.c b/tools/lib/bpf/btf_relocate.c
index df5fa4bd87d69..e55dd75f6c950 100644
--- a/tools/lib/bpf/btf_relocate.c
+++ b/tools/lib/bpf/btf_relocate.c
@@ -441,7 +441,8 @@ static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i)
 /* If successful, output of relocation is updated BTF with base BTF pointing
  * at base_btf, and type ids, strings adjusted accordingly.
  */
-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map)
+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,
+		 __u32 **str_map)
 {
 	unsigned int nr_types = btf__type_cnt(btf);
 	const struct btf_header *dist_base_hdr;
@@ -512,6 +513,10 @@ int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map)
 		*id_map = r.id_map;
 		r.id_map = NULL;
 	}
+	if (str_map) {
+		*str_map = r.str_map;
+		r.str_map = NULL;
+	}
 err_out:
 	free(r.id_map);
 	free(r.str_map);
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 546f65b95cf4d..4e45dfacb548a 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -249,7 +249,8 @@ const char *btf_kind_str(const struct btf_type *t);
 const struct btf_type *skip_mods_and_typedefs(const struct btf *btf, __u32 id, __u32 *res_id);
 const struct btf_header *btf_header(const struct btf *btf);
 void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);
-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map);
+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,
+		 __u32 **str_map);
 bool btf_type_is_traceable_func(const struct btf *btf, const struct btf_type *t);
 
 static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index a22be7efd1fa2..80d8bbbc3084a 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -343,7 +343,9 @@ else
 endif
 
 $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids	\
-		       $(TOOLSDIR)/bpf/resolve_btfids/main.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/main.c		\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.h	\
 		       $(TOOLSDIR)/lib/rbtree.c			\
 		       $(TOOLSDIR)/lib/zalloc.c			\
 		       $(TOOLSDIR)/lib/string.c			\
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_inline.c b/tools/testing/selftests/bpf/prog_tests/btf_inline.c
new file mode 100644
index 0000000000000..d88fab6429b1b
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/btf_inline.c
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026, Oracle and/or its affiliates. */
+
+#include <test_progs.h>
+#include <bpf/btf.h>
+#include <bpf/libbpf.h>
+
+#define BTF_SYSFS_DIR		"/sys/kernel/btf"
+#define BTF_INLINE_SUFFIX	".inline"
+
+/*
+ * For a specific inline site, verify we have the right function,
+ * loc proto and loc param representation and that the offset is
+ * reasonable given the caller where it was inlined.
+ */
+void test_btf_inline(void)
+{
+	struct btf *inline_btf = NULL, *btf = NULL, *vmlinux_btf = NULL;
+	const char *inline_caller = "bpf_testmod_test_write";
+	const char *inline_func = "testmod_inline_len";
+	unsigned long long caller_addr, base_addr;
+	bool skip = false, found_loc = false;
+	const struct btf_loc_param *lp;
+	int locsec_id, func_id, n, i;
+	const struct btf_type *t;
+	struct btf_loc *l;
+	const __u32 *p;
+	int err = 0;
+
+	if (!env.has_testmod) {
+		test__skip();
+		return;
+	}
+
+	base_addr = module_get_base_addr("bpf_testmod");
+	if (!ASSERT_NEQ(base_addr, 0, "base_addr_nonzero"))
+		return;
+
+	if (!ASSERT_OK(kallsyms_find(inline_caller, &caller_addr),
+		       "find_inline_caller"))
+		return;
+	if (!ASSERT_NEQ(caller_addr, 0, "caller_addr_nonzero"))
+		return;
+	if (!ASSERT_GT(caller_addr, base_addr, "caller_addr_gt_base_addr"))
+		return;
+	caller_addr -= base_addr;
+
+	vmlinux_btf = btf__load_vmlinux_btf();
+	if (!ASSERT_OK_PTR(vmlinux_btf, "vmlinux_btf"))
+		return;
+
+	btf = btf__parse_split(BTF_SYSFS_DIR "/bpf_testmod", vmlinux_btf);
+	if (!ASSERT_OK_PTR(btf, "bpf_testmod_btf"))
+		goto out;
+
+	inline_btf = btf__parse_split(BTF_SYSFS_DIR "/bpf_testmod" BTF_INLINE_SUFFIX,
+				      btf);
+	err = libbpf_get_error(inline_btf);
+	/* pahole may not have inline BTF feature support. */
+	if (err == -ENOENT) {
+		skip = true;
+		goto out;
+	}
+	if (!ASSERT_OK(err, "parse_inline_btf"))
+		goto out;
+	locsec_id = btf__find_by_name_kind(inline_btf, "inline.text", BTF_KIND_LOCSEC);
+	if (locsec_id < 0) {
+		skip = true;
+		goto out;
+	}
+	func_id = btf__find_by_name_kind(inline_btf, inline_func, BTF_KIND_FUNC);
+	if (!ASSERT_GT(func_id, 0, "inline_caller_func"))
+		goto out;
+	t = btf__type_by_id(inline_btf, locsec_id);
+	n = btf_vlen(t);
+	for (i = 0, l = btf_locsec_locs(t); i < n; i++, l++) {
+		if (l->func == func_id) {
+			found_loc = true;
+			break;
+		}
+	}
+	if (!ASSERT_TRUE(found_loc, "found_loc"))
+		goto out;
+	if (!ASSERT_GT(l->loc_proto, 0, "loc_proto_id"))
+		goto out;
+	if (!ASSERT_GT(l->offset, 0, "loc_offset"))
+		goto out;
+	t = btf__type_by_id(inline_btf, l->loc_proto);
+	if (!ASSERT_OK_PTR(t, "loc_proto_ptr"))
+		goto out;
+	if (!ASSERT_EQ(btf_vlen(t), 1, "loc_proto_one_param"))
+		goto out;
+	p = btf_loc_proto_params(t);
+	if (!ASSERT_GT(*p, 0, "loc_proto_has_loc_param"))
+		goto out;
+	t = btf__type_by_id(inline_btf, *p);
+	if (!ASSERT_OK_PTR(t, "loc_param_ptr"))
+		goto out;
+	lp = btf_loc_param(t);
+	if (!ASSERT_TRUE(lp->flags & BTF_LOC_PARAM_REG, "param_has_reg"))
+		goto out;
+	if (!ASSERT_GT(l->offset, caller_addr, "inline_gt_caller"))
+		goto out;
+	/* simple sanity test to roughly ensure inline site still in function */
+	if (!ASSERT_LT(l->offset, caller_addr + 512, "inline_in_caller"))
+		goto out;
+out:
+	btf__free(inline_btf);
+	btf__free(btf);
+	btf__free(vmlinux_btf);
+	if (skip)
+		test__skip();
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
index 3923e64c4c1d0..3fde8598189f4 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
@@ -3,15 +3,21 @@
 
 #include <test_progs.h>
 #include <bpf/btf.h>
+#include <dirent.h>
+#include <limits.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <unistd.h>
 
+#define BTF_SYSFS_DIR		"/sys/kernel/btf"
+#define BTF_INLINE_SUFFIX	".inline"
+
 static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 {
 	struct stat st;
 	__u64 btf_size, end;
+	size_t mmap_len = 0;
 	void *raw_data = NULL;
 	int fd = -1;
 	long page_size;
@@ -26,6 +32,7 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 
 	btf_size = st.st_size;
 	end = (btf_size + page_size - 1) / page_size * page_size;
+	mmap_len = btf_size;
 
 	fd = open(path, O_RDONLY);
 	if (!ASSERT_GE(fd, 0, "open_btf"))
@@ -39,11 +46,13 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 	if (!ASSERT_EQ(raw_data, MAP_FAILED, "mmap_btf_shared"))
 		goto cleanup;
 
-	raw_data = mmap(NULL, end + 1, PROT_READ, MAP_PRIVATE, fd, 0);
+	mmap_len = end + 1;
+	raw_data = mmap(NULL, mmap_len, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (!ASSERT_EQ(raw_data, MAP_FAILED, "mmap_btf_invalid_size"))
 		goto cleanup;
 
-	raw_data = mmap(NULL, end, PROT_READ, MAP_PRIVATE, fd, 0);
+	mmap_len = end;
+	raw_data = mmap(NULL, mmap_len, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (!ASSERT_OK_PTR(raw_data, "mmap_btf"))
 		goto cleanup;
 
@@ -70,12 +79,84 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 cleanup:
 	btf__free(btf);
 	if (raw_data && raw_data != MAP_FAILED)
-		munmap(raw_data, btf_size);
+		munmap(raw_data, mmap_len);
 	if (fd >= 0)
 		close(fd);
 }
 
+static void test_btf_inline_sysfs_all(void)
+{
+	struct btf *vmlinux_btf;
+	struct dirent *dentry;
+	DIR *dir;
+	int err = 0;
+
+	dir = opendir(BTF_SYSFS_DIR);
+	if (!ASSERT_OK_PTR(dir, "open_btf_sysfs"))
+		return;
+
+	vmlinux_btf = btf__parse(BTF_SYSFS_DIR "/vmlinux", NULL);
+	if (!ASSERT_OK_PTR(vmlinux_btf, "parse_vmlinux_btf")) {
+		closedir(dir);
+		return;
+	}
+
+	while ((dentry = readdir(dir)) != NULL) {
+		struct btf *base_btf = NULL, *module_btf = NULL, *inline_btf = NULL;
+		char btf_path[PATH_MAX], inline_path[PATH_MAX];
+		struct stat st;
+
+		/* Skip ".", ".." and "foo.inline" */
+		if (strstr(dentry->d_name, "."))
+			continue;
+
+		if (strcmp(dentry->d_name, "vmlinux") == 0)
+			base_btf = vmlinux_btf;
+
+		if (snprintf(btf_path, sizeof(btf_path), "%s/%s",
+			     BTF_SYSFS_DIR, dentry->d_name) >= sizeof(btf_path) ||
+		    snprintf(inline_path, sizeof(inline_path), "%s/%s%s",
+			     BTF_SYSFS_DIR, dentry->d_name, BTF_INLINE_SUFFIX) >=
+			     sizeof(inline_path)) {
+			ASSERT_FAIL("BTF sysfs path is too long\n");
+			break;
+		}
+
+		if (!base_btf) {
+			module_btf = btf__parse_split(btf_path, vmlinux_btf);
+			err = libbpf_get_error(module_btf);
+			if (err) {
+				/* A module can be unloaded while its sysfs entry is iterated. */
+				if (err == -ENOENT)
+					continue;
+				ASSERT_OK(err, "parse_module_btf");
+				continue;
+			}
+			base_btf = module_btf;
+		}
+		if (stat(inline_path, &st)) {
+			err = errno;
+			if (err != ENOENT)
+				ASSERT_OK(err, "stat_inline_btf");
+			btf__free(module_btf);
+			continue;
+		}
+		if (base_btf == vmlinux_btf)
+			test_btf_mmap_sysfs(inline_path, base_btf);
+		inline_btf = btf__parse_split(inline_path, base_btf);
+		err = libbpf_get_error(inline_btf);
+		if (!err)
+			btf__free(inline_btf);
+		ASSERT_OK(err, "parse_inline_btf");
+		btf__free(module_btf);
+	}
+	closedir(dir);
+
+	btf__free(vmlinux_btf);
+}
+
 void test_btf_sysfs(void)
 {
 	test_btf_mmap_sysfs("/sys/kernel/btf/vmlinux", NULL);
+	test_btf_inline_sysfs_all();
 }
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 93847ca6293b4..b4f0af2aeca45 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -735,6 +735,13 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
 EXPORT_SYMBOL(bpf_testmod_test_read);
 ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO);
 
+static __always_inline size_t testmod_inline_len(size_t len)
+{
+	/* Keep an instruction in the inline site without changing len. */
+	asm volatile("" : "+m"(len));
+	return len;
+}
+
 noinline ssize_t
 bpf_testmod_test_write(struct file *file, struct kobject *kobj,
 		      const struct bin_attribute *bin_attr,
@@ -743,7 +750,7 @@ bpf_testmod_test_write(struct file *file, struct kobject *kobj,
 	struct bpf_testmod_test_write_ctx ctx = {
 		.buf = buf,
 		.off = off,
-		.len = len,
+		.len = testmod_inline_len(len),
 	};
 
 	trace_bpf_testmod_test_write_bare_tp(current, &ctx);
@@ -802,7 +809,7 @@ static struct testmod_uprobe uprobe = {
 	.consumer.ret_handler = uprobe_ret_handler,
 };
 
-static int testmod_register_uprobe(loff_t offset)
+static __always_inline int testmod_register_uprobe(loff_t offset)
 {
 	int err = -EBUSY;
 
diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 679008b310d9a..f3a1d627699da 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -244,6 +244,26 @@ int kallsyms_find(const char *sym, unsigned long long *addr)
 	return err;
 }
 
+unsigned long long module_get_base_addr(const char *module)
+{
+	unsigned long long addr, base_addr = 0;
+	char name[500];
+	FILE *f;
+
+	f = fopen("/proc/modules", "r");
+	if (!f)
+		return 0;
+
+	while (fscanf(f, "%499s %*s %*s %*s %*s 0x%llx", name, &addr) == 2) {
+		if (strcmp(module, name) == 0) {
+			base_addr = addr;
+			break;
+		}
+	}
+	fclose(f);
+	return base_addr;
+}
+
 #ifdef PROCMAP_QUERY
 int env_verbosity __weak = 0;
 
diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
index 01c8ecc456270..eb0d0d9804d6e 100644
--- a/tools/testing/selftests/bpf/trace_helpers.h
+++ b/tools/testing/selftests/bpf/trace_helpers.h
@@ -38,6 +38,7 @@ typedef int (*ksym_search_cmp_t)(const void *p1, const struct ksym *p2);
 int load_kallsyms(void);
 struct ksym *ksym_search(long key);
 long ksym_get_addr(const char *name);
+unsigned long long module_get_base_addr(const char *module);
 
 struct ksyms *load_kallsyms_local(void);
 struct ksym *ksym_search_local(struct ksyms *ksyms, long key);
diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile
index 2f423de831473..d1b65fd379118 100644
--- a/tools/testing/selftests/hid/Makefile
+++ b/tools/testing/selftests/hid/Makefile
@@ -148,6 +148,8 @@ endif
 
 $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids	\
 		       $(TOOLSDIR)/bpf/resolve_btfids/main.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.h	\
 		       $(TOOLSDIR)/lib/rbtree.c			\
 		       $(TOOLSDIR)/lib/zalloc.c			\
 		       $(TOOLSDIR)/lib/string.c			\

3/2 2026/10/09 13:48 llm patch-evaluator
2m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33955
							output: 19
							thoughts: 1139
						

Thoughts:
**Analyzing the Potential Impact of a BTF Inline Patch**

Okay, so I need to evaluate this patch series that's been applied as HEAD in the kernel repo. My initial thought is to get a solid grasp of what's going on, so let's start by inspecting the `git log` or the diff directly.  I'll run some quick tools to help; perhaps `git log`, `git show`, or even just a glance at the provided diff is enough to understand the series. Let's see... looking at the tools I have available, looks like `grepper`, `codesearch-dir-index`, `read-file` and `set-results` are present.

Now, let's look at this patch. The commit message mentions "syz-cluster: applied patch under review," which immediately raises a flag. We're talking about a fuzzing-related patch.

From the file list – `.gitignore`, `Makefile`, and the `include` and `kernel` directories – I can already see this is related to BTF and BPF.  Specifically, it seems to add support for "inline" BTF, which is controlled by `CONFIG_DEBUG_INFO_BTF_INLINE`.  That's a key clue.

I need to dive into the core changes: `kernel/bpf/btf.c`, `kernel/bpf/sysfs_btf.c`, `kernel/module/main.c`, and `kernel/bpf/btf_vmlinux_inline.c`.  Let's see...

Now, let's pinpoint the kernel code being modified. From what I see in `kernel/bpf/btf.c`: there are new functions being added: `btf_parse_split()`, and `btf_rebase_inline()`. Existing functions are modified, namely `btf_parse_module()`, `btf_parse_link()`, `btf_verify_link()`, and some initialization and module handling functions.  Crucially, there's `btf_module_notify()`, which handles module loading and unloading via `MODULE_STATE_COMING`, `MODULE_STATE_LIVE`, and `MODULE_STATE_GOING`. And the `init_module` and `finit_module` syscalls call this.

Okay, this is getting interesting. This has direct implications for syzkaller. Does syzkaller even execute module loading? Well, it definitely fuzzes syscalls, including `init_module` and `finit_module`.  And that means BTF parsing is reachable through these syscalls! This is a potential attack vector if there's a vulnerability in that code.

Then, there's also the sysfs exposure in `kernel/bpf/sysfs_btf.c`:  I see attributes like `/sys/kernel/btf/vmlinux.inline` and `/sys/kernel/btf/<module>.inline`.  Sysfs read/mmap is available via `btf_sysfs_read_lazy` and `btf_sysfs_mmap_lazy`!  If `CONFIG_DEBUG_INFO_BTF_INLINE=m`, it's lazy loading, meaning it *requests a module*! That means `request_module("%s", entry->module_name);` is called and, with `remap_vmalloc_range(vma, data, 0)` being called when sysfs files are mmaped. This directly opens up a potential fuzzing target. Sysfs read / mmap on `/sys/kernel/btf/*` is accessible to userspace!

Now, the potential exploit is becoming clearer. So, I see that module loading is very much involved, and BTF parsing is triggered during module loading via `init_module`/`finit_module` syscalls. Since syzkaller fuzzes these syscalls, including sysfs reads/mmap, that makes this a prime target for exploitation. Even BPF syscalls and `btf_relocate` are potential attack vectors. I need to be sure by grepping for `btf_relocate` throughout the kernel.



4/2 2026/10/09 13:50 tool grepper
0m Args:
{
  "Expression": "btf_relocate"
}

Results:
{
  "Output": "include/linux/btf.h=256=struct btf *btf_get_module_btf(const struct module *module);\ninclude/linux/btf.h:257:__u32 btf_relocate_id(const struct btf *btf, __u32 id);\ninclude/linux/btf.h-258-const struct btf_type *btf_type_skip_modifiers(const struct btf *btf,\n--\ninclude/linux/btf.h=610=void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\ninclude/linux/btf.h:611:int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids,\ninclude/linux/btf.h-612-\t\t __u32 **map_strs);\n--\ninclude/linux/btf.h=681=static inline void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\n--\ninclude/linux/btf.h-684-\ninclude/linux/btf.h:685:static inline int btf_relocate(void *log, struct btf *btf, const struct btf *base_btf,\ninclude/linux/btf.h-686-\t\t\t       __u32 **map_ids, __u32 **map_strs)\n--\nkernel/bpf/Makefile=66=obj-$(CONFIG_BPF_SYSCALL) += btf_iter.o\nkernel/bpf/Makefile:67:obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o\nkernel/bpf/Makefile-68-obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o\n--\nkernel/bpf/btf.c=6883=struct btf *btf_parse_vmlinux(void)\n--\nkernel/bpf/btf.c-6915- */\nkernel/bpf/btf.c:6916:__u32 btf_relocate_id(const struct btf *btf, __u32 id)\nkernel/bpf/btf.c-6917-{\n--\nkernel/bpf/btf.c=7041=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-7097-\tif (base_btf != vmlinux_btf) {\nkernel/bpf/btf.c:7098:\t\terr = btf_relocate(btf, vmlinux_btf, \u0026btf-\u003ebase_id_map,\nkernel/bpf/btf.c-7099-\t\t\t\t   \u0026module_str_map);\n--\nkernel/bpf/btf.c-7120-\t/*\nkernel/bpf/btf.c:7121:\t * With a distilled base, btf_relocate() replaces the base BTF and\nkernel/bpf/btf.c-7122-\t * rewrites string offsets. Check ordering only after that final BTF\n--\nkernel/bpf/btf.c=9669=static int btf_populate_kfunc_set(struct btf *btf, enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-9763-\tfor (i = set-\u003ecnt; i \u003c set-\u003ecnt + add_set-\u003ecnt; i++)\nkernel/bpf/btf.c:9764:\t\tset-\u003epairs[i].id = btf_relocate_id(btf, set-\u003epairs[i].id);\nkernel/bpf/btf.c-9765-\n--\nkernel/bpf/btf.c=9949=static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-9961-\tfor (i = 0; i \u003c kset-\u003eset-\u003ecnt; i++) {\nkernel/bpf/btf.c:9962:\t\tret = btf_check_kfunc_protos(btf, btf_relocate_id(btf, kset-\u003eset-\u003epairs[i].id),\nkernel/bpf/btf.c-9963-\t\t\t\t\t     kset-\u003eset-\u003epairs[i].flags);\n--\nkernel/bpf/btf.c=10018=static int btf_check_dtor_kfuncs(struct btf *btf, const struct btf_id_dtor_kfunc *dtors, u32 cnt)\n--\nkernel/bpf/btf.c-10025-\tfor (i = 0; i \u003c cnt; i++) {\nkernel/bpf/btf.c:10026:\t\tdtor_btf_id = btf_relocate_id(btf, dtors[i].kfunc_btf_id);\nkernel/bpf/btf.c-10027-\n--\nkernel/bpf/btf.c=10063=int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt,\n--\nkernel/bpf/btf.c-10121-\tfor (i = tab_cnt; i \u003c tab_cnt + add_cnt; i++) {\nkernel/bpf/btf.c:10122:\t\ttab-\u003edtors[i].btf_id = btf_relocate_id(btf, tab-\u003edtors[i].btf_id);\nkernel/bpf/btf.c:10123:\t\ttab-\u003edtors[i].kfunc_btf_id = btf_relocate_id(btf, tab-\u003edtors[i].kfunc_btf_id);\nkernel/bpf/btf.c-10124-\t}\n--\nkernel/bpf/btf_relocate.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/btf_relocate.c:2:#include \"../../tools/lib/bpf/btf_relocate.c\"\n--\nkernel/trace/trace_events.c=2236=event_btf_ids_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)\n--\nkernel/trace/trace_events.c-2265-\t\t/* Module-local ids in ids[] need base+local relocation. */\nkernel/trace/trace_events.c:2266:\t\ttp_id = btf_relocate_id(btf, ids[1]);\nkernel/trace/trace_events.c-2267-\n--\nkernel/trace/trace_events.c-2273-\t\tif (call-\u003eflags \u0026 TRACE_EVENT_FL_TRACEPOINT) {\nkernel/trace/trace_events.c:2274:\t\t\tt = btf_type_by_id(btf, btf_relocate_id(btf, ids[0]));\nkernel/trace/trace_events.c-2275-\t\t\traw_id = t ? t-\u003etype : 0;\n--\ntools/lib/bpf/Build=1=libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_utils.o \\\n--\ntools/lib/bpf/Build-3-\t    btf_dump.o ringbuf.o strset.o linker.o gen_loader.o relo_core.o \\\ntools/lib/bpf/Build:4:\t    usdt.o zip.o elf.o features.o btf_iter.o btf_relocate.o\n--\ntools/lib/bpf/btf.c=6641=int btf__relocate(struct btf *btf, const struct btf *base_btf)\ntools/lib/bpf/btf.c-6642-{\ntools/lib/bpf/btf.c:6643:\tint err = btf_relocate(btf, base_btf, NULL, NULL);\ntools/lib/bpf/btf.c-6644-\n--\ntools/lib/bpf/btf_relocate.c=36=struct btf;\ntools/lib/bpf/btf_relocate.c-37-\ntools/lib/bpf/btf_relocate.c:38:struct btf_relocate {\ntools/lib/bpf/btf_relocate.c-39-\tstruct btf *btf;\n--\ntools/lib/bpf/btf_relocate.c=58=struct btf_name_info {\n--\ntools/lib/bpf/btf_relocate.c-65-\ntools/lib/bpf/btf_relocate.c:66:static int btf_relocate_rewrite_type_id(struct btf_relocate *r, __u32 i)\ntools/lib/bpf/btf_relocate.c-67-{\n--\ntools/lib/bpf/btf_relocate.c=102=static struct btf_name_info *search_btf_name_size(struct btf_name_info *key,\n--\ntools/lib/bpf/btf_relocate.c-131- */\ntools/lib/bpf/btf_relocate.c:132:static int btf_mark_embedded_composite_type_ids(struct btf_relocate *r, __u32 i)\ntools/lib/bpf/btf_relocate.c-133-{\n--\ntools/lib/bpf/btf_relocate.c-183- */\ntools/lib/bpf/btf_relocate.c:184:static int btf_relocate_map_distilled_base(struct btf_relocate *r)\ntools/lib/bpf/btf_relocate.c-185-{\n--\ntools/lib/bpf/btf_relocate.c-382-/* distilled base should only have named int/float/enum/fwd/struct/union types. */\ntools/lib/bpf/btf_relocate.c:383:static int btf_relocate_validate_distilled_base(struct btf_relocate *r)\ntools/lib/bpf/btf_relocate.c-384-{\n--\ntools/lib/bpf/btf_relocate.c-411-\ntools/lib/bpf/btf_relocate.c:412:static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i)\ntools/lib/bpf/btf_relocate.c-413-{\n--\ntools/lib/bpf/btf_relocate.c-443- */\ntools/lib/bpf/btf_relocate.c:444:int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\ntools/lib/bpf/btf_relocate.c-445-\t\t __u32 **str_map)\n--\ntools/lib/bpf/btf_relocate.c-449-\tconst struct btf_header *base_hdr;\ntools/lib/bpf/btf_relocate.c:450:\tstruct btf_relocate r = {};\ntools/lib/bpf/btf_relocate.c-451-\tint err = 0;\n--\ntools/lib/bpf/btf_relocate.c-474-\ntools/lib/bpf/btf_relocate.c:475:\terr = btf_relocate_validate_distilled_base(\u0026r);\ntools/lib/bpf/btf_relocate.c-476-\tif (err)\n--\ntools/lib/bpf/btf_relocate.c-489-\t */\ntools/lib/bpf/btf_relocate.c:490:\terr = btf_relocate_map_distilled_base(\u0026r);\ntools/lib/bpf/btf_relocate.c-491-\tif (err)\n--\ntools/lib/bpf/btf_relocate.c-498-\tfor (i = 0, id = r.nr_dist_base_types; i \u003c r.nr_split_types; i++, id++) {\ntools/lib/bpf/btf_relocate.c:499:\t\terr = btf_relocate_rewrite_type_id(\u0026r, id);\ntools/lib/bpf/btf_relocate.c-500-\t\tif (err)\n--\ntools/lib/bpf/btf_relocate.c-504-\tfor (i = 0; i \u003c r.nr_split_types; i++) {\ntools/lib/bpf/btf_relocate.c:505:\t\terr = btf_relocate_rewrite_strs(\u0026r, i + r.nr_dist_base_types);\ntools/lib/bpf/btf_relocate.c-506-\t\tif (err)\n--\ntools/lib/bpf/libbpf_internal.h=251=void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\ntools/lib/bpf/libbpf_internal.h:252:int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\ntools/lib/bpf/libbpf_internal.h-253-\t\t __u32 **str_map);\n"
}

5/2 2026/10/09 13:50 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39470
							output: 24
							thoughts: 161
						

Thoughts:
**Kernel BTF Relocation: A Curious Inclusion**

Okay, let's dive into this `kernel/bpf/btf_relocate.c` file. Hmm, interesting. It's directly including `../../tools/lib/bpf/btf_relocate.c`. Hold on a second... that's unusual. My immediate thought is, this is not just a dependency, it is also bringing the user-space tools code directly into the kernel build.

Wait, I think I see what's happening. Looking closer, `kernel/bpf/btf_relocate.c` is being compiled into the kernel itself – the `obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o` line confirms it. And, as suspected, that file includes the `tools/lib/bpf/btf_relocate.c` file. This means, *that* specific user-space library is also now getting baked into the kernel image. I need to verify this assumption.

I'll quickly use `read-file` or `grepper` to double-check the contents of `kernel/bpf/btf_relocate.c`. Let's see what's actually getting linked.



6/2 2026/10/09 13:50 tool grepper
0m Args:
{
  "Expression": "#include.*btf_relocate\\.c"
}

Results:
{
  "Output": "kernel/bpf/btf_relocate.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/btf_relocate.c:2:#include \"../../tools/lib/bpf/btf_relocate.c\"\n"
}

7/2 2026/10/09 13:50 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40004
							output: 34
							thoughts: 195
						

Thoughts:
**Analyzing the Recent Kernel Patch**

Okay, so I see that `kernel/bpf/btf_relocate.c` includes a file from the tools directory, specifically `../../tools/lib/bpf/btf_relocate.c`. That's the starting point. Now, let's dive into the specifics of this patch. My immediate thought is, *what exactly is this doing*? Time to check the commit message. I'll use `git show` or `git log` to get the context. Ideally, I'd grep `git log` if possible, but I know grepper searches file contents, not Git logs, so that's out.

Let's quickly check the following files for the details: `kernel/bpf/btf.c`, `kernel/bpf/sysfs_btf.c`, `kernel/module/main.c`, `kernel/bpf/btf_vmlinux_inline.c`, and `lib/Kconfig.debug`. The changes in these areas will give me the information I require to fully understand what is being changed and why.

I'll specifically look at `lib/Kconfig.debug` and pay attention to around line 430. Hopefully, that will give me some key insights.



8/2 2026/10/09 13:50 tool read-file
0m Args:
{
  "File": "lib/Kconfig.debug",
  "FirstLine": 425,
  "LineCount": 40
}

Results:
{
  "Contents": " 425:\t\t  otherwise it would emit malformed kernel and module binaries when\n 426:\t\t  using DEBUG_INFO_BTF_MODULES.\n 427:\t\n 428:\tconfig PAHOLE_HAS_INLINE\n 429:\t\tdef_bool PAHOLE_VERSION \u003e= 132\n 430:\t\thelp\n 431:\t\t  Support for the \"inline\" BTF feature is available. It encodes\n 432:\t\t  information about inline sites and how to retrieve their parameters.\n 433:\t\n 434:\tconfig DEBUG_INFO_BTF_MODULES\n 435:\t\tbool \"Generate BTF type information for kernel modules\"\n 436:\t\tdefault y\n 437:\t\tdepends on DEBUG_INFO_BTF \u0026\u0026 MODULES\n 438:\t\thelp\n 439:\t\t  Generate compact split BTF type information for kernel modules.\n 440:\t\n 441:\tconfig DEBUG_INFO_BTF_INLINE\n 442:\t\ttristate \"Provide information about inline sites in BTF\"\n 443:\t\tdefault n\n 444:\t\tdepends on DEBUG_INFO_BTF \u0026\u0026 PAHOLE_HAS_INLINE \u0026\u0026 SYSFS\n 445:\t\tselect DEBUG_INFO_BTF_MODULES if MODULES\n 446:\t\thelp\n 447:\t\t  Generate information about inline sites in .BTF.inline sections.\n 448:\t\t  These sections contain split BTF relative to the kernel or module BTF\n 449:\t\t  and are made available in /sys/kernel/btf with a \".inline\" suffix.\n 450:\t\t  The information describes inline locations and how to retrieve their\n 451:\t\t  associated parameters.\n 452:\t\n 453:\tconfig MODULE_ALLOW_BTF_MISMATCH\n 454:\t\tbool \"Allow loading modules with non-matching BTF type info\"\n 455:\t\tdepends on DEBUG_INFO_BTF_MODULES\n 456:\t\thelp\n 457:\t\t  For modules whose split BTF does not match vmlinux, load without\n 458:\t\t  BTF rather than refusing to load. The default behavior with\n 459:\t\t  module BTF enabled is to reject modules with such mismatches;\n 460:\t\t  this option will still load module BTF where possible but ignore\n 461:\t\t  it when a mismatch is found.\n 462:\t\n 463:\tconfig GDB_SCRIPTS\n 464:\t\tbool \"Provide GDB scripts for kernel debugging\"\n"
}

9/2 2026/10/09 13:50 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41162
							output: 19
							thoughts: 140
						

Thoughts:
Here's my thought process, as if I were analyzing that configuration entry:

**Analyzing `CONFIG_DEBUG_INFO_BTF_INLINE` for Syzkaller Integration**

Okay, let's break this down. I'm looking at `CONFIG_DEBUG_INFO_BTF_INLINE`. Right off the bat, I see it's dependent on `DEBUG_INFO_BTF`, `PAHOLE_HAS_INLINE`, and `SYSFS`. Fine, understandable dependencies, but let's drill down on that `PAHOLE_HAS_INLINE` condition. It seems we need `PAHOLE_VERSION >= 132`.

Now the crucial question for syzkaller arises: Is that version of `pahole` actually available in this environment? I need to know if the build environment has `pahole` version 132 or greater. And more generally: Can we even realistically enable `CONFIG_DEBUG_INFO_BTF_INLINE` for syzkaller's purposes? This is a key requirement for using this config for fuzzing.

I should check the `Kconfig` files directly to locate the definition of `PAHOLE_VERSION` since it's used in the environment, and confirm what it's set to. I need to be sure before I go further.



10/2 2026/10/09 13:51 tool grepper
0m Args:
{
  "Expression": "PAHOLE_VERSION"
}

Results:
{
  "Output": "Makefile=730=endif\n--\nMakefile-733-# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.\nMakefile:734:# CC_VERSION_TEXT, RUSTC_VERSION_TEXT and PAHOLE_VERSION are referenced from\nMakefile-735-# Kconfig (so they need export), and from include/config/auto.conf.cmd to\n--\nMakefile=738=RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2\u003e/dev/null))\nMakefile:739:PAHOLE_VERSION = $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE))\nMakefile-740-\n--\nMakefile=759=include $(srctree)/arch/$(SRCARCH)/Makefile\nMakefile:760:export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT PAHOLE_VERSION\nMakefile-761-\n--\nMakefile=2093=prepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT)\nMakefile:2094:prepare: PAHOLE_VERSION := $(PAHOLE_VERSION)\nMakefile-2095-prepare:\n--\nMakefile-2100-\tfi\nMakefile:2101:\t@if [ \"$(PAHOLE_VERSION)\" != \"$(CONFIG_PAHOLE_VERSION)\" ]; then \\\nMakefile-2102-\t\techo \u003e\u00262 \"warning: pahole version differs from the one used to build the kernel\"; \\\nMakefile:2103:\t\techo \u003e\u00262 \"  The kernel was built with: $(CONFIG_PAHOLE_VERSION)\"; \\\nMakefile:2104:\t\techo \u003e\u00262 \"  You are using:             $(PAHOLE_VERSION)\"; \\\nMakefile-2105-\tfi\n--\ninit/Kconfig=198=config RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS\n--\ninit/Kconfig-200-\ninit/Kconfig:201:config PAHOLE_VERSION\ninit/Kconfig-202-\tint\ninit/Kconfig:203:\tdefault \"$(PAHOLE_VERSION)\"\ninit/Kconfig-204-\n--\nkernel/module/Kconfig=189=config GENDWARFKSYMS\n--\nkernel/module/Kconfig-199-\t# Verify 0 address DWARF variables are in ELF section\").\nkernel/module/Kconfig:200:\tdepends on !X86 || !DEBUG_INFO_BTF || PAHOLE_VERSION \u003c 128 || PAHOLE_VERSION \u003e 129\nkernel/module/Kconfig-201-\thelp\n--\nlib/Kconfig.debug=398=config DEBUG_INFO_BTF\n--\nlib/Kconfig.debug-402-\tdepends on BPF_SYSCALL\nlib/Kconfig.debug:403:\tdepends on PAHOLE_VERSION \u003e= 122\nlib/Kconfig.debug-404-\t# pahole uses elfutils, which does not have support for Hexagon relocations\n--\nlib/Kconfig.debug=411=config PAHOLE_HAS_BTF_TAG\nlib/Kconfig.debug:412:\tdef_bool PAHOLE_VERSION \u003e= 123\nlib/Kconfig.debug-413-\tdepends on CC_IS_CLANG\n--\nlib/Kconfig.debug=419=config PAHOLE_HAS_LANG_EXCLUDE\nlib/Kconfig.debug:420:\tdef_bool PAHOLE_VERSION \u003e= 124\nlib/Kconfig.debug-421-\thelp\n--\nlib/Kconfig.debug=428=config PAHOLE_HAS_INLINE\nlib/Kconfig.debug:429:\tdef_bool PAHOLE_VERSION \u003e= 132\nlib/Kconfig.debug-430-\thelp\n--\nscripts/Makefile.btf-2-\nscripts/Makefile.btf:3:pahole-ver := $(CONFIG_PAHOLE_VERSION)\nscripts/Makefile.btf-4-pahole-flags-y :=\n"
}

11/2 2026/10/09 13:51 llm patch-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42609
							output: 39
							thoughts: 46
						

Thoughts:
Okay, let's dive into this. I need to get a handle on what's been changed within the kernel. My first step is to focus on this `sysfs_btf.c` file. I'm going to carefully read the contents of `kernel/bpf/sysfs_btf.c`. I need to understand its role and how it's been impacted.



12/2 2026/10/09 13:52 tool read-file
0m Args:
{
  "File": "kernel/bpf/sysfs_btf.c",
  "FirstLine": 1,
  "LineCount": 100
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: GPL-2.0\n   2:\t/*\n   3:\t * Provide kernel BTF information for introspection and use by eBPF tools.\n   4:\t */\n   5:\t#include \u003clinux/kernel.h\u003e\n   6:\t#include \u003clinux/module.h\u003e\n   7:\t#include \u003clinux/kobject.h\u003e\n   8:\t#include \u003clinux/init.h\u003e\n   9:\t#include \u003clinux/slab.h\u003e\n  10:\t#include \u003clinux/sysfs.h\u003e\n  11:\t#include \u003clinux/mm.h\u003e\n  12:\t#include \u003clinux/vmalloc.h\u003e\n  13:\t#include \u003clinux/io.h\u003e\n  14:\t#include \u003clinux/btf.h\u003e\n  15:\t\n  16:\t/* See scripts/link-vmlinux.sh, gen_btf() func for details */\n  17:\textern char __start_BTF[];\n  18:\textern char __stop_BTF[];\n  19:\t\n  20:\tstatic int btf_sysfs_mmap_check(void *data, size_t size, struct vm_area_struct *vma)\n  21:\t{\n  22:\t\tunsigned long pages = PAGE_ALIGN(size) \u003e\u003e PAGE_SHIFT;\n  23:\t\tsize_t vm_size = vma-\u003evm_end - vma-\u003evm_start;\n  24:\t\n  25:\t\tif (!data || !PAGE_ALIGNED((unsigned long)data))\n  26:\t\t\treturn -EINVAL;\n  27:\t\n  28:\t\tif (vma-\u003evm_pgoff)\n  29:\t\t\treturn -EINVAL;\n  30:\t\n  31:\t\tif (vma-\u003evm_flags \u0026 (VM_WRITE | VM_EXEC | VM_MAYSHARE))\n  32:\t\t\treturn -EACCES;\n  33:\t\n  34:\t\tif ((vm_size \u003e\u003e PAGE_SHIFT) \u003e pages)\n  35:\t\t\treturn -EINVAL;\n  36:\t\n  37:\t\tvm_flags_mod(vma, VM_DONTDUMP, VM_MAYEXEC | VM_MAYWRITE);\n  38:\t\treturn 0;\n  39:\t}\n  40:\t\n  41:\tstatic int btf_sysfs_mmap_image(struct file *filp, struct kobject *kobj,\n  42:\t\t\t\t\tconst struct bin_attribute *attr,\n  43:\t\t\t\t\tstruct vm_area_struct *vma)\n  44:\t{\n  45:\t\tvoid *data = READ_ONCE(attr-\u003eprivate);\n  46:\t\tphys_addr_t addr;\n  47:\t\tunsigned long pfn;\n  48:\t\tsize_t vm_size = vma-\u003evm_end - vma-\u003evm_start;\n  49:\t\tint err;\n  50:\t\n  51:\t\terr = btf_sysfs_mmap_check(data, attr-\u003esize, vma);\n  52:\t\tif (err)\n  53:\t\t\treturn err;\n  54:\t\n  55:\t\t/* Kernel image addresses can lie inside the vmalloc range on arm64. */\n  56:\t\taddr = __pa_symbol(data);\n  57:\t\tpfn = addr \u003e\u003e PAGE_SHIFT;\n  58:\t\tif (pfn + (PAGE_ALIGN(attr-\u003esize) \u003e\u003e PAGE_SHIFT) \u003c pfn)\n  59:\t\t\treturn -EINVAL;\n  60:\t\n  61:\t\treturn remap_pfn_range(vma, vma-\u003evm_start, pfn, vm_size, vma-\u003evm_page_prot);\n  62:\t}\n  63:\t\n  64:\tstatic struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {\n  65:\t\t.attr = { .name = \"vmlinux\", .mode = 0444, },\n  66:\t\t.read = sysfs_bin_attr_simple_read,\n  67:\t\t.mmap = btf_sysfs_mmap_image,\n  68:\t};\n  69:\t\n  70:\tstruct kobject *btf_kobj;\n  71:\t\n  72:\tstruct btf_sysfs_entry {\n  73:\t\tstruct bin_attribute attr;\n  74:\t\tchar *module_name;\n  75:\t};\n  76:\t\n  77:\tstatic void *btf_sysfs_lazy_data(const struct bin_attribute *attr)\n  78:\t{\n  79:\t\tstruct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);\n  80:\t\tvoid *data;\n  81:\t\n  82:\t\tdata = smp_load_acquire(\u0026attr-\u003eprivate);\n  83:\t\tif (!data) {\n  84:\t\t\trequest_module(\"%s\", entry-\u003emodule_name);\n  85:\t\t\tdata = smp_load_acquire(\u0026attr-\u003eprivate);\n  86:\t\t}\n  87:\t\treturn data;\n  88:\t}\n  89:\t\n  90:\tstatic ssize_t btf_sysfs_read_lazy(struct file *filp, struct kobject *kobj,\n  91:\t\t\t\t\t   const struct bin_attribute *attr, char *buf,\n  92:\t\t\t\t\t   loff_t off, size_t count)\n  93:\t{\n  94:\t\tvoid *data = btf_sysfs_lazy_data(attr);\n  95:\t\n  96:\t\tif (!data)\n  97:\t\t\treturn -ENODEV;\n  98:\t\n  99:\t\treturn memory_read_from_buffer(buf, count, \u0026off, data, attr-\u003esize);\n 100:\t}\n"
}

13/2 2026/10/09 13:52 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44257
							output: 40
							thoughts: 21
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `kernel/bpf/sysfs_btf.c`**

Alright, let's get down to brass tacks and dig into the code. Time to scrutinize the remaining sections of `kernel/bpf/sysfs_btf.c`. I need a solid understanding of how this particular module interacts with the sysfs filesystem and how it handles BTF (BPF Type Format) data. I'll be looking for nuances regarding the interfaces offered, error handling, data structures used, and any potential performance bottlenecks or security considerations. Specifically, I'm hoping to discover the intricacies of how BTF data is exposed, loaded, and managed through this interface. Given my level of expertise, I need to know how this integration affects overall BPF programmability and debugging capabilities. I'm keen to anticipate and prepare for issues.



14/2 2026/10/09 13:52 tool read-file
0m Args:
{
  "File": "kernel/bpf/sysfs_btf.c",
  "FirstLine": 101,
  "LineCount": 80
}

Results:
{
  "Contents": " 101:\t\n 102:\tstatic int btf_sysfs_mmap_lazy(struct file *filp, struct kobject *kobj,\n 103:\t\t\t\t       const struct bin_attribute *attr,\n 104:\t\t\t\t       struct vm_area_struct *vma)\n 105:\t{\n 106:\t\tvoid *data = btf_sysfs_lazy_data(attr);\n 107:\t\tint err;\n 108:\t\n 109:\t\tif (!data)\n 110:\t\t\treturn -ENODEV;\n 111:\t\n 112:\t\terr = btf_sysfs_mmap_check(data, attr-\u003esize, vma);\n 113:\t\tif (err)\n 114:\t\t\treturn err;\n 115:\t\n 116:\t\treturn remap_vmalloc_range(vma, data, 0);\n 117:\t}\n 118:\t\n 119:\tstruct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,\n 120:\t\t\t\t\t    bool mmap, const char *lazy_module_name)\n 121:\t{\n 122:\t\tstruct btf_sysfs_entry *entry;\n 123:\t\tstruct bin_attribute *attr;\n 124:\t\tint err;\n 125:\t\n 126:\t\tentry = kzalloc_obj(*entry);\n 127:\t\tif (!entry)\n 128:\t\t\treturn ERR_PTR(-ENOMEM);\n 129:\t\n 130:\t\tattr = \u0026entry-\u003eattr;\n 131:\t\tsysfs_bin_attr_init(attr);\n 132:\t\tattr-\u003eattr.mode = 0444;\n 133:\t\tattr-\u003esize = data_size;\n 134:\t\tattr-\u003eprivate = data;\n 135:\t\tattr-\u003eread = lazy_module_name ? btf_sysfs_read_lazy : sysfs_bin_attr_simple_read;\n 136:\t\tif (mmap)\n 137:\t\t\tattr-\u003emmap = lazy_module_name ? btf_sysfs_mmap_lazy : btf_sysfs_mmap_image;\n 138:\t\tattr-\u003eattr.name = kstrdup(name, GFP_KERNEL);\n 139:\t\tif (!attr-\u003eattr.name) {\n 140:\t\t\terr = -ENOMEM;\n 141:\t\t\tgoto err_free;\n 142:\t\t}\n 143:\t\tif (lazy_module_name) {\n 144:\t\t\tentry-\u003emodule_name = kstrdup(lazy_module_name, GFP_KERNEL);\n 145:\t\t\tif (!entry-\u003emodule_name) {\n 146:\t\t\t\terr = -ENOMEM;\n 147:\t\t\t\tgoto err_free;\n 148:\t\t\t}\n 149:\t\t}\n 150:\t\n 151:\t\terr = sysfs_create_bin_file(btf_kobj, attr);\n 152:\t\tif (err) {\n 153:\t\t\tpr_warn(\"failed to register [%s] BTF in sysfs: %d\\n\", name, err);\n 154:\t\t\tgoto err_free;\n 155:\t\t}\n 156:\t\n 157:\t\treturn attr;\n 158:\t\n 159:\terr_free:\n 160:\t\tkfree(entry-\u003emodule_name);\n 161:\t\tkfree(attr-\u003eattr.name);\n 162:\t\tkfree(entry);\n 163:\t\treturn ERR_PTR(err);\n 164:\t}\n 165:\t\n 166:\tbool sysfs_btf_update(struct bin_attribute *attr, void *data)\n 167:\t{\n 168:\t\treturn attr \u0026\u0026 !cmpxchg(\u0026attr-\u003eprivate, NULL, data);\n 169:\t}\n 170:\t\n 171:\tvoid sysfs_btf_remove(struct bin_attribute *attr)\n 172:\t{\n 173:\t\tstruct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);\n 174:\t\n 175:\t\tsysfs_remove_bin_file(btf_kobj, attr);\n 176:\t\tkfree(entry-\u003emodule_name);\n 177:\t\tkfree(attr-\u003eattr.name);\n 178:\t\tkfree(entry);\n 179:\t}\n 180:\t\n"
}

15/2 2026/10/09 13:52 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 45716
							output: 39
							thoughts: 1629
						

Thoughts:
**Analyzing BTF Sysfs Registration and Lazy Loading**

Okay, so I'm looking at how BTF (BPF Type Format) data is exposed through sysfs. It seems `sysfs_btf_add` is the key function called for every BTF registration via sysfs, and I need to understand the nuances of how this works, especially with the `CONFIG_DEBUG_INFO_BTF_INLINE` option.

Before the patch, sysfs registration was handled directly by allocating `bin_attribute` structures and populating them. Now, it looks like `sysfs_btf_add` is the central point. I see that on module unload, `sysfs_btf_remove` is used to clean up the `bin_attribute` and `btf_sysfs_entry`.

I'm focusing in on the statically defined `bin_attr_btf_vmlinux` as it is not allocated with `sysfs_btf_add` which suggests a different handling of the vmlinux BTF data, and the interaction with modules. The key question is around how the inline BTF data for `vmlinux` is handled.

Now, if `CONFIG_DEBUG_INFO_BTF_INLINE` is enabled, things get interesting. The code in `btf_vmlinux_inline.c` adds the `vmlinux.inline` BTF entry. If it's compiled as a module, there's a lazy initialization (`btf_vmlinux_inline_lazy_init`) which I need to investigate in detail. If the module is loaded it calls `btf_module_handle_vmlinux_inline`. This function copies module BTF data into kernel memory and updates the `vmlinux.inline` attribute.

What happens when someone reads `/sys/kernel/btf/vmlinux.inline`? `btf_sysfs_lazy_data()` is called, which calls `request_module("%s", entry->module_name);` to load a module (likely `btf_vmlinux_inline`). When the module loads, `btf_module_notify()` with `MODULE_STATE_COMING` calls `btf_module_handle_vmlinux_inline()`. This is where the actual copying and verification of the inline BTF data happens, and ultimately, memory is remapped for access.

Here's the critical question: Does the lazy loading mechanism allow *any* module to be loaded by an unprivileged user just by trying to read the `vmlinux.inline` file? This could potentially be a security vulnerability.  I need to drill down into the loading and parsing logic within `btf_parse_module`, `btf_parse_split`, and `btf_rebase_inline`, specifically within the large chunk of code between lines 6920 and 7150 of `kernel/bpf/btf.c`. I need to understand if there are any checks or restrictions on which modules can be requested.



16/2 2026/10/09 13:53 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 6920,
  "LineCount": 100
}

Results:
{
  "Contents": "6920:\t\treturn btf-\u003ebase_id_map[id];\n6921:\t}\n6922:\t\n6923:\t#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\n6924:\t\n6925:\tstatic struct btf *btf_parse_split(struct btf_verifier_env *env,\n6926:\t\t\t\t\t   const char *name, const void *data,\n6927:\t\t\t\t\t   unsigned int data_size, struct btf *base_btf)\n6928:\t{\n6929:\t\tstruct btf *btf;\n6930:\t\tint err;\n6931:\t\n6932:\t\tbtf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);\n6933:\t\tif (!btf)\n6934:\t\t\treturn ERR_PTR(-ENOMEM);\n6935:\t\tenv-\u003ebtf = btf;\n6936:\t\n6937:\t\tbtf_set_base_btf(btf, base_btf);\n6938:\t\tbtf-\u003ekernel_btf = true;\n6939:\t\tbtf-\u003enamed_start_id = 0;\n6940:\t\tstrscpy(btf-\u003ename, name);\n6941:\t\n6942:\t\tbtf-\u003edata = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);\n6943:\t\tif (!btf-\u003edata) {\n6944:\t\t\terr = -ENOMEM;\n6945:\t\t\tgoto errout;\n6946:\t\t}\n6947:\t\tbtf-\u003edata_size = data_size;\n6948:\t\n6949:\t\terr = btf_parse_hdr(env);\n6950:\t\tif (err)\n6951:\t\t\tgoto errout;\n6952:\t\n6953:\t\tbtf-\u003enohdr_data = btf-\u003edata + btf-\u003ehdr.hdr_len;\n6954:\t\n6955:\t\terr = btf_parse_str_sec(env);\n6956:\t\tif (err)\n6957:\t\t\tgoto errout;\n6958:\t\n6959:\t\terr = btf_check_all_metas(env);\n6960:\t\tif (err)\n6961:\t\t\tgoto errout;\n6962:\t\n6963:\t\terr = btf_check_modifier_chain_length(env, btf, btf_nr_types(base_btf));\n6964:\t\tif (err)\n6965:\t\t\tgoto errout;\n6966:\t\n6967:\t\treturn btf;\n6968:\t\n6969:\terrout:\n6970:\t\tbtf_free(btf);\n6971:\t\treturn ERR_PTR(err);\n6972:\t}\n6973:\t\n6974:\tstatic int btf_rebase_inline(struct btf *inline_btf,\n6975:\t\t\t\t     const struct btf *module_btf,\n6976:\t\t\t\t     const u32 *module_id_map,\n6977:\t\t\t\t     const u32 *module_str_map,\n6978:\t\t\t\t     u32 old_module_type_cnt)\n6979:\t{\n6980:\t\tu32 old_start_id = inline_btf-\u003estart_id;\n6981:\t\tu32 old_start_str_off = inline_btf-\u003estart_str_off;\n6982:\t\tu32 old_module_start_str_off = old_start_str_off - module_btf-\u003ehdr.str_len;\n6983:\t\tu32 new_start_id = btf_nr_types(module_btf);\n6984:\t\tu32 new_start_str_off = module_btf-\u003estart_str_off + module_btf-\u003ehdr.str_len;\n6985:\t\ts64 id_delta = (s64)new_start_id - old_start_id;\n6986:\t\ts64 str_delta = (s64)new_start_str_off - old_start_str_off;\n6987:\t\tu32 i;\n6988:\t\n6989:\t\t/*\n6990:\t\t * The inline BTF was parsed relative to the original module BTF. Its\n6991:\t\t * base IDs must therefore use the map generated when that BTF was\n6992:\t\t * relocated, while IDs for inline-local types only move by the change\n6993:\t\t * in the module BTF's starting ID.\n6994:\t\t */\n6995:\t\tfor (i = 0; i \u003c inline_btf-\u003enr_types; i++) {\n6996:\t\t\tstruct btf_field_iter it;\n6997:\t\t\tstruct btf_type *t = inline_btf-\u003etypes[i];\n6998:\t\t\tu32 *id, *str_off;\n6999:\t\t\tint err;\n7000:\t\n7001:\t\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\n7002:\t\t\tif (err)\n7003:\t\t\t\treturn err;\n7004:\t\t\twhile ((id = btf_field_iter_next(\u0026it))) {\n7005:\t\t\t\tif (!*id)\n7006:\t\t\t\t\tcontinue;\n7007:\t\t\t\tif (*id \u003c old_module_type_cnt) {\n7008:\t\t\t\t\tif (module_id_map)\n7009:\t\t\t\t\t\t*id = module_id_map[*id];\n7010:\t\t\t\t} else if (*id \u003e= old_start_id) {\n7011:\t\t\t\t\t*id += id_delta;\n7012:\t\t\t\t} else {\n7013:\t\t\t\t\treturn -EINVAL;\n7014:\t\t\t\t}\n7015:\t\t\t}\n7016:\t\n7017:\t\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\n7018:\t\t\tif (err)\n7019:\t\t\t\treturn err;\n"
}

17/2 2026/10/09 13:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49644
							output: 38
							thoughts: 25
						

Thoughts:
Okay, let's dive into this. Here's my take on those lines from `btf.c`:

**Deep Dive into btf.c: Lines 7020-7130**

Alright, time to get my hands dirty. I'm going to focus on lines 7020 to 7130 of `btf.c`. Given what I already know about BTF, I expect to see... well, a lot. This likely involves some critical function or data structure definition, or maybe a core loop within one of the BTF processing stages. Based on my experience with the codebase, I'm anticipating interactions with type information handling, perhaps related to relocation, verification, or even printing of BTF data. The length of the section suggests it's more than just a simple utility function. We're probably dealing with a significant chunk of the BTF processing pipeline here. I'll need to pay close attention to the variable names and control flow; those will be the keys to understanding the logic. It's time to parse the details of how this section handles type definitions and interactions with the larger BTF structure. Let's see what gems are buried within.



18/2 2026/10/09 13:53 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 7020,
  "LineCount": 80
}

Results:
{
  "Contents": "7020:\t\t\twhile ((str_off = btf_field_iter_next(\u0026it))) {\n7021:\t\t\t\tif (!*str_off)\n7022:\t\t\t\t\tcontinue;\n7023:\t\t\t\tif (*str_off \u003c old_module_start_str_off) {\n7024:\t\t\t\t\t/* Vmlinux strings retain their offsets for in-tree modules. */\n7025:\t\t\t\t\tif (!module_id_map)\n7026:\t\t\t\t\t\tcontinue;\n7027:\t\t\t\t\tif (!module_str_map || !module_str_map[*str_off])\n7028:\t\t\t\t\t\treturn -EINVAL;\n7029:\t\t\t\t\t*str_off = module_str_map[*str_off];\n7030:\t\t\t\t\tcontinue;\n7031:\t\t\t\t}\n7032:\t\t\t\t*str_off += str_delta;\n7033:\t\t\t}\n7034:\t\t}\n7035:\t\n7036:\t\tbtf_set_base_btf(inline_btf, module_btf);\n7037:\t\tbtf_check_sorted(inline_btf);\n7038:\t\treturn 0;\n7039:\t}\n7040:\t\n7041:\tstatic struct btf *btf_parse_module(const char *module_name, const void *data,\n7042:\t\t\t\t\t    unsigned int data_size, void *base_data,\n7043:\t\t\t\t\t    unsigned int base_data_size,\n7044:\t\t\t\t\t    const void *inline_data,\n7045:\t\t\t\t\t    unsigned int inline_data_size,\n7046:\t\t\t\t\t    void **relocated_inline_data)\n7047:\t{\n7048:\t\tstruct btf *btf = NULL, *inline_btf = NULL, *vmlinux_btf, *base_btf = NULL;\n7049:\t\tstruct btf_verifier_env *env = NULL;\n7050:\t\tstruct bpf_verifier_log *log;\n7051:\t\tu32 *module_str_map = NULL;\n7052:\t\tu32 old_module_type_cnt;\n7053:\t\tint err = 0;\n7054:\t\n7055:\t\t*relocated_inline_data = NULL;\n7056:\t\tvmlinux_btf = bpf_get_btf_vmlinux();\n7057:\t\tif (IS_ERR(vmlinux_btf))\n7058:\t\t\treturn vmlinux_btf;\n7059:\t\tif (!vmlinux_btf)\n7060:\t\t\treturn ERR_PTR(-EINVAL);\n7061:\t\n7062:\t\tenv = kzalloc_obj(*env, GFP_KERNEL | __GFP_NOWARN);\n7063:\t\tif (!env)\n7064:\t\t\treturn ERR_PTR(-ENOMEM);\n7065:\t\n7066:\t\tlog = \u0026env-\u003elog;\n7067:\t\tlog-\u003elevel = BPF_LOG_KERNEL;\n7068:\t\n7069:\t\tif (base_data) {\n7070:\t\t\tbase_btf = btf_parse_base(env, \".BTF.base\", base_data, base_data_size);\n7071:\t\t\tif (IS_ERR(base_btf)) {\n7072:\t\t\t\terr = PTR_ERR(base_btf);\n7073:\t\t\t\tgoto errout;\n7074:\t\t\t}\n7075:\t\t} else {\n7076:\t\t\tbase_btf = vmlinux_btf;\n7077:\t\t}\n7078:\t\n7079:\t\tbtf = btf_parse_split(env, module_name, data, data_size, base_btf);\n7080:\t\tif (IS_ERR(btf)) {\n7081:\t\t\terr = PTR_ERR(btf);\n7082:\t\t\tbtf = NULL;\n7083:\t\t\tgoto errout;\n7084:\t\t}\n7085:\t\told_module_type_cnt = btf_nr_types(btf);\n7086:\t\n7087:\t\tif (inline_data_size) {\n7088:\t\t\tinline_btf = btf_parse_split(env, module_name, inline_data,\n7089:\t\t\t\t\t\t     inline_data_size, btf);\n7090:\t\t\tif (IS_ERR(inline_btf)) {\n7091:\t\t\t\tpr_warn(\"failed to validate module [%s] inline BTF: %ld\\n\",\n7092:\t\t\t\t\tmodule_name, PTR_ERR(inline_btf));\n7093:\t\t\t\tinline_btf = NULL;\n7094:\t\t\t}\n7095:\t\t}\n7096:\t\n7097:\t\tif (base_btf != vmlinux_btf) {\n7098:\t\t\terr = btf_relocate(btf, vmlinux_btf, \u0026btf-\u003ebase_id_map,\n7099:\t\t\t\t\t   \u0026module_str_map);\n"
}

19/2 2026/10/09 13:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 51271
							output: 38
							thoughts: 23
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach that snippet from `btf.c`:

**Analyzing Lines 7100-7150 of btf.c**

Alright, I need to get a handle on what's happening within lines 7100 to 7150 of `btf.c`. *Why* was I directed to this specific section? Is it a suspected bug, an area flagged for optimization, or maybe part of a larger debugging session? Knowing the context would definitely inform my approach. My initial scan will be to understand the high-level purpose of this block of code within the BTF (BPF Type Format) context. I'm going to look for function calls, control structures (if/else, loops), and any variable declarations that might give me a clue about the code's function. Are we dealing with type parsing, symbol table manipulation, or perhaps some form of BTF validation?

Next, I'll pay close attention to the data structures involved, the specific variables that are being used and modified, and the operations being performed on them. I expect a BTF implementation to be handling complex type information, so I'll be looking for references to BTF type descriptors, names, sizes, and any potential interactions with the BPF VM itself.

I'll be mindful of potential error handling as well. BTF parsing, particularly from untrusted sources, is a minefield for vulnerabilities. Are there any checks for malformed data, unexpected input sizes, or potential out-of-bounds reads or writes? Any robust BTF implementation would need to have solid validation.

I'll pay attention to any comments. It's common to find comments that explain the purpose of a block or function. I'm hoping that there will be some notes on why this code is important.

After I've got a grasp of the code's *what*, I'll try to understand the *why*. What is this code accomplishing within the larger BTF ecosystem? What are its dependencies, and what does it contribute to the overall process? Are there any obvious bottlenecks or areas where performance could be improved?



20/2 2026/10/09 13:53 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 7100,
  "LineCount": 50
}

Results:
{
  "Contents": "7100:\t\t\tif (err)\n7101:\t\t\t\tgoto errout;\n7102:\t\t\tbtf_free(base_btf);\n7103:\t\t\tbase_btf = vmlinux_btf;\n7104:\t\t}\n7105:\t\n7106:\t\tif (inline_btf) {\n7107:\t\t\terr = btf_rebase_inline(inline_btf, btf, btf-\u003ebase_id_map,\n7108:\t\t\t\t\t\tmodule_str_map, old_module_type_cnt);\n7109:\t\t\tif (err) {\n7110:\t\t\t\tpr_warn(\"failed to relocate module [%s] inline BTF: %d\\n\",\n7111:\t\t\t\t\tmodule_name, err);\n7112:\t\t\t\tbtf_free(inline_btf);\n7113:\t\t\t} else {\n7114:\t\t\t\t*relocated_inline_data = inline_btf-\u003edata;\n7115:\t\t\t\tinline_btf-\u003edata = NULL;\n7116:\t\t\t\tbtf_free(inline_btf);\n7117:\t\t\t}\n7118:\t\t}\n7119:\t\n7120:\t\t/*\n7121:\t\t * With a distilled base, btf_relocate() replaces the base BTF and\n7122:\t\t * rewrites string offsets. Check ordering only after that final BTF\n7123:\t\t * view has been established, so named_start_id describes the BTF used\n7124:\t\t * by name lookups.\n7125:\t\t */\n7126:\t\tbtf_check_sorted(btf);\n7127:\t\tbtf_verifier_env_free(env);\n7128:\t\tkvfree(module_str_map);\n7129:\t\trefcount_set(\u0026btf-\u003erefcnt, 1);\n7130:\t\treturn btf;\n7131:\t\n7132:\terrout:\n7133:\t\tkvfree(module_str_map);\n7134:\t\tbtf_verifier_env_free(env);\n7135:\t\tif (inline_btf)\n7136:\t\t\tbtf_free(inline_btf);\n7137:\t\tif (!IS_ERR(base_btf) \u0026\u0026 base_btf != vmlinux_btf)\n7138:\t\t\tbtf_free(base_btf);\n7139:\t\tif (btf)\n7140:\t\t\tbtf_free(btf);\n7141:\t\treturn ERR_PTR(err);\n7142:\t}\n7143:\t\n7144:\t#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\n7145:\t\n7146:\tstruct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog)\n7147:\t{\n7148:\t\tstruct bpf_prog *tgt_prog = prog-\u003eaux-\u003edst_prog;\n7149:\t\n"
}

21/2 2026/10/09 13:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52573
							output: 42
							thoughts: 146
						

Thoughts:
Okay, let's dive into this.

**Examining the BTF Relocation Process**

Alright, I need to get a clear picture of how this BTF relocation works, specifically in the context of the tools used. My immediate focus is on the `btf_relocate` function. It looks like the main entry point is defined in `tools/lib/bpf/btf_relocate.c`, which gets compiled into the kernel. Right, so I need to check how things have evolved in this area and understand the mechanics.

I'm particularly interested in how the string map (`str_map`) is handled within the `btf_relocate` function. I'll need to closely examine the surrounding code in `tools/lib/bpf/btf_relocate.c` to see the details of where and how that `str_map` parameter is used and how the string table is managed during the relocation process. This should give me insight into how string offsets are adjusted or remapped when BTF data is moved or combined.



22/2 2026/10/09 13:53 tool read-file
0m Args:
{
  "File": "tools/lib/bpf/btf_relocate.c",
  "FirstLine": 440,
  "LineCount": 80
}

Results:
{
  "Contents": " 440:\t\n 441:\t/* If successful, output of relocation is updated BTF with base BTF pointing\n 442:\t * at base_btf, and type ids, strings adjusted accordingly.\n 443:\t */\n 444:\tint btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\n 445:\t\t\t __u32 **str_map)\n 446:\t{\n 447:\t\tunsigned int nr_types = btf__type_cnt(btf);\n 448:\t\tconst struct btf_header *dist_base_hdr;\n 449:\t\tconst struct btf_header *base_hdr;\n 450:\t\tstruct btf_relocate r = {};\n 451:\t\tint err = 0;\n 452:\t\t__u32 id, i;\n 453:\t\n 454:\t\tr.dist_base_btf = btf__base_btf(btf);\n 455:\t\tif (!base_btf || r.dist_base_btf == base_btf)\n 456:\t\t\treturn -EINVAL;\n 457:\t\n 458:\t\tr.nr_dist_base_types = btf__type_cnt(r.dist_base_btf);\n 459:\t\tr.nr_base_types = btf__type_cnt(base_btf);\n 460:\t\tr.nr_split_types = nr_types - r.nr_dist_base_types;\n 461:\t\tr.btf = btf;\n 462:\t\tr.base_btf = base_btf;\n 463:\t\n 464:\t\tr.id_map = calloc(nr_types, sizeof(*r.id_map));\n 465:\t\tr.str_map = calloc(btf_header(r.dist_base_btf)-\u003estr_len, sizeof(*r.str_map));\n 466:\t\tdist_base_hdr = btf_header(r.dist_base_btf);\n 467:\t\tbase_hdr = btf_header(r.base_btf);\n 468:\t\tr.dist_str_len = dist_base_hdr-\u003estr_len;\n 469:\t\tr.base_str_len = base_hdr-\u003estr_len;\n 470:\t\tif (!r.id_map || !r.str_map) {\n 471:\t\t\terr = -ENOMEM;\n 472:\t\t\tgoto err_out;\n 473:\t\t}\n 474:\t\n 475:\t\terr = btf_relocate_validate_distilled_base(\u0026r);\n 476:\t\tif (err)\n 477:\t\t\tgoto err_out;\n 478:\t\n 479:\t\t/* Split BTF ids need to be adjusted as base and distilled base\n 480:\t\t * have different numbers of types, changing the start id of split\n 481:\t\t * BTF.\n 482:\t\t */\n 483:\t\tfor (id = r.nr_dist_base_types; id \u003c nr_types; id++)\n 484:\t\t\tr.id_map[id] = id + r.nr_base_types - r.nr_dist_base_types;\n 485:\t\n 486:\t\t/* Build a map from distilled base ids to actual base BTF ids; it is used\n 487:\t\t * to update split BTF id references.  Also build a str_map mapping from\n 488:\t\t * distilled base BTF names to base BTF names.\n 489:\t\t */\n 490:\t\terr = btf_relocate_map_distilled_base(\u0026r);\n 491:\t\tif (err)\n 492:\t\t\tgoto err_out;\n 493:\t\n 494:\t\t/* Next, rewrite type ids in split BTF, replacing split ids with updated\n 495:\t\t * ids based on number of types in base BTF, and base ids with\n 496:\t\t * relocated ids from base_btf.\n 497:\t\t */\n 498:\t\tfor (i = 0, id = r.nr_dist_base_types; i \u003c r.nr_split_types; i++, id++) {\n 499:\t\t\terr = btf_relocate_rewrite_type_id(\u0026r, id);\n 500:\t\t\tif (err)\n 501:\t\t\t\tgoto err_out;\n 502:\t\t}\n 503:\t\t/* String offsets now need to be updated using the str_map. */\n 504:\t\tfor (i = 0; i \u003c r.nr_split_types; i++) {\n 505:\t\t\terr = btf_relocate_rewrite_strs(\u0026r, i + r.nr_dist_base_types);\n 506:\t\t\tif (err)\n 507:\t\t\t\tgoto err_out;\n 508:\t\t}\n 509:\t\t/* Finally reset base BTF to be base_btf */\n 510:\t\tbtf_set_base_btf(btf, base_btf);\n 511:\t\n 512:\t\tif (id_map) {\n 513:\t\t\t*id_map = r.id_map;\n 514:\t\t\tr.id_map = NULL;\n 515:\t\t}\n 516:\t\tif (str_map) {\n 517:\t\t\t*str_map = r.str_map;\n 518:\t\t\tr.str_map = NULL;\n 519:\t\t}\n"
}

23/2 2026/10/09 13:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54428
							output: 34
							thoughts: 2291
						

Thoughts:
**WorthFuzzing Analysis: BTF Chaining and sysfs Exposure**

Okay, let's break this down. First, I see a crucial modification in `btf_set_base_btf` within `kernel/bpf/btf.c`. The change, `btf->start_str_off = base_btf->start_str_off + base_btf->hdr.str_len;`, is a big deal. It enables the chaining of base BTFs, allowing for nested structures like inline BTFs relying on module BTFs, which in turn rely on the vmlinux BTF. This is a significant architectural improvement.

Now, the million-dollar question: is this fuzzable? I have to go through the patch fuzzing guidelines. First, reachability is key. Am I looking at code that can actually run in a standard environment?

Well, let's see. The guidelines make it very clear that any modification in BPF, sysfs, module loading, and memory mapping should be fuzzed, as all these are core subsystems. The patch touches the following core BPF files: `kernel/bpf/btf.c`, `kernel/bpf/sysfs_btf.c`, and `kernel/bpf/btf_vmlinux_inline.c`. It also hits the module loading code (`kernel/module/main.c`) and `tools/lib/bpf/btf_relocate.c` which gets compiled into the kernel. It seems like the modifications are in multiple places, not just a single, isolated function.

Let's go deeper. The code paths are clearly reachable: Module loading triggers the `.BTF.inline` parsing via `find_module_sections`. `btf_module_notify` handles `MODULE_STATE_COMING`.  Then, `btf_parse_module`, `btf_rebase_inline`, `sysfs_btf_add` are all involved. Moreover, userspace interactions with `/sys/kernel/btf/*` also play a role. Reading or mmapping these files triggers `btf_sysfs_read_lazy`, `btf_sysfs_mmap_lazy`, etc., leading to `btf_sysfs_lazy_data()`, and potentially `request_module()`, `remap_vmalloc_range()`, or `memory_read_from_buffer()`. Notably, `btf_sysfs_mmap_image()` now handles the `mmap()` of `/sys/kernel/btf/vmlinux`, replacing the previous `btf_sysfs_vmlinux_mmap` function. This sysfs exposure makes the code very accessible.

Given that this affects BPF core subsystems, I must conclude that `WorthFuzzing = true`. The code is clearly reachable, executable, and involves core functionalities.

Now, configuration. What config options do I need? A careful analysis of the Kconfig files is required. I need to figure out what triggers the code path I've identified. The crucial option appears to be `DEBUG_INFO_BTF_INLINE`. It's tristate (y, m, or n). The dependencies are:

-   `DEBUG_INFO_BTF`
-   `SYSFS`
-   `PAHOLE_HAS_INLINE`, which is dependent on a `PAHOLE_VERSION` of at least 132.

The next step is to analyze what `DEBUG_INFO_BTF` depends on, but that's a different rabbit hole for now.



24/2 2026/10/09 13:54 tool read-file
0m Args:
{
  "File": "lib/Kconfig.debug",
  "FirstLine": 398,
  "LineCount": 20
}

Results:
{
  "Contents": " 398:\tconfig DEBUG_INFO_BTF\n 399:\t\tbool \"Generate BTF type information\"\n 400:\t\tdepends on !DEBUG_INFO_SPLIT \u0026\u0026 !DEBUG_INFO_REDUCED\n 401:\t\tdepends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST\n 402:\t\tdepends on BPF_SYSCALL\n 403:\t\tdepends on PAHOLE_VERSION \u003e= 122\n 404:\t\t# pahole uses elfutils, which does not have support for Hexagon relocations\n 405:\t\tdepends on !HEXAGON\n 406:\t\thelp\n 407:\t\t  Generate deduplicated BTF type information from DWARF debug info.\n 408:\t\t  Turning this on requires pahole v1.22 or later, which will convert\n 409:\t\t  DWARF type info into equivalent deduplicated BTF type info.\n 410:\t\n 411:\tconfig PAHOLE_HAS_BTF_TAG\n 412:\t\tdef_bool PAHOLE_VERSION \u003e= 123\n 413:\t\tdepends on CC_IS_CLANG\n 414:\t\thelp\n 415:\t\t  Decide whether pahole emits btf_tag attributes (btf_type_tag and\n 416:\t\t  btf_decl_tag) or not. Currently only clang compiler implements\n 417:\t\t  these attributes, so make the config depend on CC_IS_CLANG.\n"
}

25/2 2026/10/09 13:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57895
							output: 25
							thoughts: 213
						

Thoughts:
Here's my thought process, as requested:

**Configuration Considerations for BTF and BPF**

Okay, time to make sure this kernel configuration is rock solid for our needs. First, I need to double-check the essentials: `BPF_SYSCALL`, `DEBUG_INFO_BTF`, `DEBUG_INFO_BTF_MODULES`, and `DEBUG_INFO_BTF_INLINE`. That seems like a good starting point. Hold on, though... don't forget the obvious! We're dealing with modules, so `CONFIG_MODULES` is definitely relevant. Actually, we should be using `MODULES` for the generic kernel modules, and then `DEBUG_INFO_BTF_MODULES` alongside it.

Right, so what specific flags do we need to *specify* in our config? Oh, that's right, the instructions said "without CONFIG_ prefix." So, that boils down to:

*   `DEBUG_INFO_BTF`
*   `DEBUG_INFO_BTF_MODULES`
*   `DEBUG_INFO_BTF_INLINE`
*   `BPF_SYSCALL`
*   `SYSFS`
*   `MODULES`

That covers everything, right? Well, let's just make *absolutely* sure. Hmm, I have a nagging feeling about `CONFIG_DEBUG_INFO_BTF_INLINE_MODULE`. Does that exist? Better be safe than sorry, let's grep for `CONFIG_DEBUG_INFO_BTF_INLINE_MODULE` and `DEBUG_INFO_BTF_INLINE_MODULE`. I'll run this check to make sure it's defined and/or used anywhere. Gotta be thorough.



26/2 2026/10/09 13:54 tool grepper
0m Args:
{
  "Expression": "DEBUG_INFO_BTF_INLINE_MODULE"
}

Results:
{
  "Output": "include/asm-generic/vmlinux.lds.h-687-\ninclude/asm-generic/vmlinux.lds.h:688:#ifdef CONFIG_DEBUG_INFO_BTF_INLINE_MODULE\ninclude/asm-generic/vmlinux.lds.h-689-/* __MODULE_NAME_LEN + SHA-256 digest + u32 BTF size */\n"
}

27/2 2026/10/09 13:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58611
							output: 25
							thoughts: 49
						

Thoughts:
Okay, here's my summary, taking on the persona you requested:

**Chasing Down the BTF_INLINE_MODULE Source**

Alright, hang on a second. I need to figure out where `CONFIG_DEBUG_INFO_BTF_INLINE_MODULE` is actually defined, or, if it's generated somehow, what's generating it. My immediate thought is to check the configuration files, naturally. That's usually the first place to look when dealing with Kconfig options. So, let's fire up `grep`. I'll run it against the Kconfig files and scripts to search for variations on that theme. I'll search for `BTF_INLINE_MODULE` directly, and also the broader term `_MODULE`, just to be thorough and catch any related definitions that might illuminate this option's origin or influence. It's a bit of a breadcrumb hunt, but that's how you dig into these things. Let's see what turns up.



28/2 2026/10/09 13:54 tool grepper
0m Args:
{
  "Expression": "DEBUG_INFO_BTF_INLINE_MODULE"
}

Results:
{
  "Output": "include/asm-generic/vmlinux.lds.h-687-\ninclude/asm-generic/vmlinux.lds.h:688:#ifdef CONFIG_DEBUG_INFO_BTF_INLINE_MODULE\ninclude/asm-generic/vmlinux.lds.h-689-/* __MODULE_NAME_LEN + SHA-256 digest + u32 BTF size */\n"
}

29/2 2026/10/09 13:54 llm patch-evaluator
15m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 59002
							output: 23
							thoughts: 1510
						

Thoughts:
**Focus Symbol Selection for BTF Fuzzing**

Okay, so I'm thinking about how to effectively focus fuzzing efforts for BTF changes in the kernel. The Kconfig behavior of automatically defining a `_MODULE` symbol when a tristate config is set to 'm' is standard behavior, meaning `CONFIG_DEBUG_INFO_BTF_INLINE=m` sets `CONFIG_DEBUG_INFO_BTF_INLINE_MODULE`. This is good to keep in mind, but not immediately relevant to picking fuzzing targets.

Now, the instructions on FocusSymbols are pretty clear. I need to avoid ubiquitous lifecycle functions – things like allocators, deallocators, or core synchronization primitives. Instead, I need to pinpoint functions that *specifically* implement the added or altered logic, or API entrypoints for the subsystem in question. Compiler-inlined static functions present a challenge, so if the changes are mainly in these inline helpers, I need to find non-static caller functions that exercise them, again avoiding those ubiquitous wrappers.

So, let's look at the candidate symbols added or modified in the kernel:

In `kernel/bpf/btf.c`, I've got: `btf_set_base_btf` (a non-static function), `btf_parse_split`, `btf_rebase_inline`, `btf_parse_module`, `btf_parse_link`, `btf_verify_link`, `btf_vmlinux_inline_lazy_init`, `btf_module_is_vmlinux_inline`, `btf_module_handle_vmlinux_inline` and `btf_module_notify` (all static). Remember, static functions *can* still have symbols in vmlinux if not inlined. Non-static entrypoints / API functions are great.

In `kernel/bpf/sysfs_btf.c`, there's: `btf_sysfs_mmap_check`, `btf_sysfs_mmap_image`, `btf_sysfs_lazy_data`, `btf_sysfs_read_lazy`, `btf_sysfs_mmap_lazy` (all static), and then the non-static functions `sysfs_btf_add`, `sysfs_btf_update`, and `sysfs_btf_remove`.

Then, in `kernel/bpf/btf_vmlinux_inline.c` there is `btf_vmlinux_inline_init` (an initcall).

Finally, `btf_relocate` (non-static function) is in `kernel/bpf/btf_relocate.c`, which is compiled as `obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o`. I've confirmed that `btf_relocate` is called by `btf_parse_module` in `kernel/bpf/btf.c`.

Now, I need to evaluate these candidates. I need to check whether to choose a static or non-static symbol. I want to check `btf_rebase_inline`, `btf_parse_split`, `btf_parse_module`, `btf_module_notify`, `sysfs_btf_add`, `btf_sysfs_read_lazy`, `btf_sysfs_mmap_lazy`, `btf_sysfs_mmap_image`, `btf_relocate`, `btf_set_base_btf`, and `btf_module_handle_vmlinux_inline`.

Okay, let's assess their size/complexity: `btf_rebase_inline` is 60+ lines with loops and `btf_field_iter`, and `btf_parse_split` is 45 lines. `btf_parse_module` is also in `btf.c`.  `btf_module_notify` is the module notifier callback.

Important: None of these functions seem ubiquitous. They are specific to BTF parsing, relocation, and sysfs BTF introspection, so that's good! Now, before I settle on these, I should do a quick check to see if functions like `btf_set_base_btf` or `btf_relocate` have other callers or uses. I'll grep for `btf_set_base_btf` to be sure.



30/2 2026/10/09 14:09 tool grepper
0m Args:
{
  "Expression": "btf_set_base_btf"
}

Results:
{
  "Output": "include/linux/btf.h=609=const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);\ninclude/linux/btf.h:610:void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\ninclude/linux/btf.h-611-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids,\n--\ninclude/linux/btf.h=675=static inline const struct btf_type *btf_type_by_id(const struct btf *btf,\n--\ninclude/linux/btf.h-680-\ninclude/linux/btf.h:681:static inline void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\ninclude/linux/btf.h-682-{\n--\nkernel/bpf/btf.c=1930=const struct btf_header *btf_header(const struct btf *btf)\n--\nkernel/bpf/btf.c-1934-\nkernel/bpf/btf.c:1935:void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\nkernel/bpf/btf.c-1936-{\n--\nkernel/bpf/btf.c=6925=static struct btf *btf_parse_split(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-6936-\nkernel/bpf/btf.c:6937:\tbtf_set_base_btf(btf, base_btf);\nkernel/bpf/btf.c-6938-\tbtf-\u003ekernel_btf = true;\n--\nkernel/bpf/btf.c=6974=static int btf_rebase_inline(struct btf *inline_btf,\n--\nkernel/bpf/btf.c-7035-\nkernel/bpf/btf.c:7036:\tbtf_set_base_btf(inline_btf, module_btf);\nkernel/bpf/btf.c-7037-\tbtf_check_sorted(inline_btf);\n--\ntools/lib/bpf/btf.c=6629=const struct btf_header *btf_header(const struct btf *btf)\n--\ntools/lib/bpf/btf.c-6633-\ntools/lib/bpf/btf.c:6634:void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\ntools/lib/bpf/btf.c-6635-{\n--\ntools/lib/bpf/btf_relocate.c=444=int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\n--\ntools/lib/bpf/btf_relocate.c-509-\t/* Finally reset base BTF to be base_btf */\ntools/lib/bpf/btf_relocate.c:510:\tbtf_set_base_btf(btf, base_btf);\ntools/lib/bpf/btf_relocate.c-511-\n--\ntools/lib/bpf/libbpf_internal.h=250=const struct btf_header *btf_header(const struct btf *btf);\ntools/lib/bpf/libbpf_internal.h:251:void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\ntools/lib/bpf/libbpf_internal.h-252-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\n"
}

31/2 2026/10/09 14:09 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62538
							output: 288
							thoughts: 886
						

Thoughts:
**My Assessment of the BTF Patch**

Okay, so I've been digging into this patch. The key symbol that clearly has a changed implementation is `btf_set_base_btf`. Right, let's trace this back, I need to check how it's used. Based on the code, `btf_module_notify` and `btf_parse_module` are definitely relevant. Let's see... looking at `btf.c`, `btf_module_notify` handles module loading and unloading, and `btf_parse_module` is called during module loading to parse the BTF, including the inline BTF data. Inside `btf_parse_module`, there are calls to `btf_rebase_inline` and `btf_parse_split`, too. I see `btf_module_handle_vmlinux_inline` is called when the `vmlinux_inline` module loads as well, which is an interesting edge case to note.

Then there's the `sysfs_btf.c` stuff: `btf_sysfs_read_lazy`, `btf_sysfs_mmap_lazy`, and `btf_sysfs_mmap_image`. And don't forget the sysfs operations: `sysfs_btf_add`, `sysfs_btf_update`, and `sysfs_btf_remove`. Finally, we have `btf_relocate` from `btf_relocate.c`.

Now, before I commit to anything, let's review the requirements and guidelines. First, the core triage philosophy. The main question is reachability, is it reachable? Yes, definitely. Module loading, sysfs read and mmap, and BTF operations are all reachable. No need to blindly trust NFCI or refactoring – I'll remain skeptical and ensure I've gone over the code. This doesn't seem to introduce any new or modified assertions or runtime logic that I can see.

Worth fuzzing? Yes, absolutely. And for the `FocusSymbols`, I'll prioritize these specific kernel functions: `btf_set_base_btf`, `btf_rebase_inline`, `btf_parse_split`, `btf_parse_module`, `btf_module_handle_vmlinux_inline`, `btf_module_notify`, `btf_sysfs_read_lazy`, `btf_sysfs_mmap_lazy`, `btf_sysfs_mmap_image`, `sysfs_btf_add`, and `btf_relocate`.

Just to be thorough, I'm checking for any other symbols, and I see `btf_vmlinux_inline_init`, but that's just an initcall so it runs only at boot. Not really a fuzzing target here.

Alright, what about the `EnableConfigs`? We need: `DEBUG_INFO_BTF_INLINE`, `DEBUG_INFO_BTF`, `DEBUG_INFO_BTF_MODULES`, `BPF_SYSCALL`, `SYSFS`, and `MODULES`. Now, let me check the dependencies for `DEBUG_INFO_BTF_INLINE`: it depends on `DEBUG_INFO_BTF && PAHOLE_HAS_INLINE && SYSFS`. Good, `DEBUG_INFO_BTF` depends on `BPF_SYSCALL`. And `DEBUG_INFO_BTF_MODULES` needs `DEBUG_INFO_BTF && MODULES`. `MODULES` just enables module support.

Okay, let's put it all together. This patch clearly introduces support for inline BTF (`CONFIG_DEBUG_INFO_BTF_INLINE`), and adds logic to parse, relocate, and rebase them during module loading. (`btf_parse_split`, `btf_rebase_inline`, `btf_relocate`), along with sysfs handlers for read and mmap (`btf_sysfs_read_lazy`, `btf_sysfs_mmap_lazy`, `btf_sysfs_mmap_image`). These changes affect core, reachable subsystems: BPF, sysfs, and kernel module management. Userspace can trigger this through syscalls like `init_module`/`finit_module`, sysfs read, and mmap.

Yep, that's solid. Time to call `set-results`.



32/2 2026/10/09 14:10 tool set-results
0m Args:
{
  "EnableConfigs": [
    "DEBUG_INFO_BTF_INLINE",
    "DEBUG_INFO_BTF",
    "DEBUG_INFO_BTF_MODULES",
    "BPF_SYSCALL",
    "SYSFS",
    "MODULES"
  ],
  "FocusSymbols": [
    "btf_set_base_btf",
    "btf_rebase_inline",
    "btf_parse_split",
    "btf_parse_module",
    "btf_module_handle_vmlinux_inline",
    "btf_module_notify",
    "btf_sysfs_read_lazy",
    "btf_sysfs_mmap_lazy",
    "btf_sysfs_mmap_image",
    "sysfs_btf_add",
    "btf_relocate"
  ],
  "Reasoning": "The patch introduces inline BTF support (.BTF.inline sections) along with kernel infrastructure to parse, rebase, and relocate inline BTF upon module loading, and exposes it through sysfs entries supporting lazy loading, reading, and mmap operations. These changes modify reachable core BPF, sysfs, and module loader execution paths accessible via syscalls like init_module/finit_module, read, and mmap.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "DEBUG_INFO_BTF_INLINE",
    "DEBUG_INFO_BTF",
    "DEBUG_INFO_BTF_MODULES",
    "BPF_SYSCALL",
    "SYSFS",
    "MODULES"
  ],
  "FocusSymbols": [
    "btf_set_base_btf",
    "btf_rebase_inline",
    "btf_parse_split",
    "btf_parse_module",
    "btf_module_handle_vmlinux_inline",
    "btf_module_notify",
    "btf_sysfs_read_lazy",
    "btf_sysfs_mmap_lazy",
    "btf_sysfs_mmap_image",
    "sysfs_btf_add",
    "btf_relocate"
  ],
  "Reasoning": "The patch introduces inline BTF support (.BTF.inline sections) along with kernel infrastructure to parse, rebase, and relocate inline BTF upon module loading, and exposes it through sysfs entries supporting lazy loading, reading, and mmap operations. These changes modify reachable core BPF, sysfs, and module loader execution paths accessible via syscalls like init_module/finit_module, read, and mmap.",
  "WorthFuzzing": true
}

33/1 2026/10/09 14:10 action If
3m Args:
{
  "WorthFuzzing": true
}

Results:
null

34/2 2026/10/09 14:10 agent kmsan-evaluator
3m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series introduces support for inline BTF generation and sysfs exposure (/sys/kernel/btf/*.inline), adding parsing, relocation, and sysfs handling for .BTF.inline sections in vmlinux and loadable modules.\n\nHolistic analysis of memory initialization and user-space transfers shows:\n1. Memory Allocations:\n   - In `btf_parse_split()`, `struct btf` is allocated with `kzalloc_obj()`, ensuring all fields are zeroed, and `btf-\u003edata` is copied with `kvmemdup()`.\n   - In `sysfs_btf_add()`, `struct btf_sysfs_entry` is allocated with `kzalloc_obj()`.\n   - In `btf_relocate()`, the relocation maps (`id_map` and `str_map`) are allocated with `calloc()`, which maps to `kvcalloc()` in the kernel build, ensuring zero-initialization.\n   - In `btf_module_handle_vmlinux_inline()`, the buffer exposed to sysfs is allocated with `vmalloc_user()`, which explicitly zero-initializes all pages (`GFP_KERNEL | __GFP_ZERO`), preventing uninitialized slack bytes across page boundaries when mmapped.\n\n2. User-Space Exposure:\n   - Data is exposed only via sysfs binary attributes (`/sys/kernel/btf/*`). Reads use `sysfs_bin_attr_simple_read()` or `btf_sysfs_read_lazy()` using bounded copies from fully populated buffers.\n   - Mmaps use `remap_vmalloc_range()` on `vmalloc_user()` memory or `remap_pfn_range()` on dedicated, page-aligned image sections. No kernel struct padding or uninitialized memory is copied to user space.\n\n3. KASAN vs. KMSAN:\n   - Potential risks in the new relocation logic (such as buffer bounds or indexing into `module_str_map` / `module_id_map`) or lifecycle management of sysfs attributes during module unloading represent out-of-bounds accesses or use-after-free/double-free conditions, which are detectable by KASAN.\n   - No uninitialized memory reads or information leak hazards are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit f2fd4fe68b2b0fd38f8b379496a376e8764bd384
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Oct 9 13:48:00 2026 +0000

    syz-cluster: applied patch under review

diff --git a/.gitignore b/.gitignore
index 9875120ea7bde..d54bdaac99813 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,6 +72,7 @@ modules.order
 /vmlinux.symvers
 /vmlinux.thinlto-index
 /vmlinux.unstripped
+/vmlinux.BTF.inline
 /vmlinux-gdb.py
 /vmlinuz
 /System.map
diff --git a/Makefile b/Makefile
index 6b8b812f23b92..b3053dd3c1059 100644
--- a/Makefile
+++ b/Makefile
@@ -1769,6 +1769,7 @@ endif # CONFIG_MODULES
 CLEAN_FILES += vmlinux.symvers modules-only.symvers \
 	       modules.builtin modules.builtin.modinfo modules.nsdeps \
 	       modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \
+	       vmlinux.BTF.inline \
 	       vmlinux.thinlto-index builtin.order \
 	       compile_commands.json rust/test \
 	       rust-project.json .vmlinux.objs .vmlinux.export.c \
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b2988aa12f664..b17251bc63f5d 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -675,12 +675,43 @@
 /*
  * .BTF
  */
+#ifdef CONFIG_DEBUG_INFO_BTF_INLINE
+#define BTF_INLINE							\
+	. = ALIGN(PAGE_SIZE);						\
+	.BTF.inline : AT(ADDR(.BTF.inline) - LOAD_OFFSET) {		\
+		BOUNDED_SECTION_BY(.BTF.inline, _BTF_inline)		\
+	}
+#else
+#define BTF_INLINE
+#endif
+
+#ifdef CONFIG_DEBUG_INFO_BTF_INLINE_MODULE
+/* __MODULE_NAME_LEN + SHA-256 digest + u32 BTF size */
+#ifdef CONFIG_64BIT
+#define BTF_LINK_SIZE	(64 - 8 + 32 + 4)
+#else
+#define BTF_LINK_SIZE	(64 - 4 + 32 + 4)
+#endif
+#define BTF_INLINE_LINK						\
+	. = ALIGN(PAGE_SIZE);					\
+	.BTF.inline.link : AT(ADDR(.BTF.inline.link) - LOAD_OFFSET) { \
+		__start_BTF_inline_link = .;				\
+		BYTE(0)						\
+		. += BTF_LINK_SIZE - 1;					\
+		__stop_BTF_inline_link = .;				\
+	}
+#else
+#define BTF_INLINE_LINK
+#endif
+
 #ifdef CONFIG_DEBUG_INFO_BTF
 #define BTF								\
 	. = ALIGN(PAGE_SIZE);						\
 	.BTF : AT(ADDR(.BTF) - LOAD_OFFSET) {				\
 		BOUNDED_SECTION_BY(.BTF, _BTF)				\
 	}								\
+	BTF_INLINE							\
+	BTF_INLINE_LINK						\
 	. = ALIGN(PAGE_SIZE);						\
 	.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) {			\
 		*(.BTF_ids)						\
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 4b63bb91550a1..b66e20a18c54f 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -5,6 +5,7 @@
 #define _LINUX_BTF_H 1
 
 #include <linux/types.h>
+#include <linux/module.h>
 #include <linux/bpfptr.h>
 #include <linux/bsearch.h>
 #include <linux/btf_ids.h>
@@ -118,6 +119,19 @@ struct btf_show;
 struct btf_id_set;
 struct bpf_prog;
 
+#define BTF_LINK_SHA256_LEN	32
+
+/*
+ * A .BTF.link or .BTF.inline.link section identifies the module which
+ * carries a vmlinux BTF section.  The module name is NUL terminated and the
+ * field is padded to __MODULE_NAME_LEN.
+ */
+struct btf_link {
+	char module_name[__MODULE_NAME_LEN];
+	u8 sha256[BTF_LINK_SHA256_LEN];
+	u32 btf_size;
+} __packed;
+
 typedef int (*btf_kfunc_filter_t)(const struct bpf_prog *prog, u32 kfunc_id);
 
 struct btf_kfunc_id_set {
@@ -594,7 +608,8 @@ struct btf_field_iter {
 #ifdef CONFIG_BPF_SYSCALL
 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
 void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);
-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids);
+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids,
+		 __u32 **map_strs);
 int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 			enum btf_field_iter_kind iter_kind);
 __u32 *btf_field_iter_next(struct btf_field_iter *it);
@@ -624,6 +639,29 @@ bool btf_types_are_same(const struct btf *btf1, u32 id1,
 			const struct btf *btf2, u32 id2);
 int btf_check_iter_arg(struct btf *btf, const struct btf_type *func, int arg_idx);
 
+#if IS_ENABLED(CONFIG_SYSFS)
+struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,
+				    bool mmap, const char *lazy_module_name);
+bool sysfs_btf_update(struct bin_attribute *attr, void *data);
+void sysfs_btf_remove(struct bin_attribute *attr);
+#else
+static inline struct bin_attribute *
+sysfs_btf_add(const char *name, void *data, size_t data_size, bool mmap,
+	      const char *lazy_module_name)
+{
+	return NULL;
+}
+
+static inline bool sysfs_btf_update(struct bin_attribute *attr, void *data)
+{
+	return false;
+}
+
+static inline void sysfs_btf_remove(struct bin_attribute *attr)
+{
+}
+#endif
+
 static inline bool btf_type_is_struct_ptr(struct btf *btf, const struct btf_type *t)
 {
 	if (!btf_type_is_ptr(t))
@@ -645,7 +683,7 @@ static inline void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)
 }
 
 static inline int btf_relocate(void *log, struct btf *btf, const struct btf *base_btf,
-			       __u32 **map_ids)
+			       __u32 **map_ids, __u32 **map_strs)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/include/linux/module.h b/include/linux/module.h
index 96cc98568eea5..a6abde12a458f 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -503,6 +503,10 @@ struct module {
 	void *btf_data;
 	void *btf_base_data;
 #endif
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+	unsigned int btf_inline_data_size;
+	void *btf_inline_data;
+#endif
 #ifdef CONFIG_JUMP_LABEL
 	struct jump_entry *jump_entries;
 	unsigned int num_jump_entries;
diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index c1f9b0d3468d3..37e62ef450791 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o
 endif
 ifeq ($(CONFIG_SYSFS),y)
 obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o
+obj-$(CONFIG_DEBUG_INFO_BTF_INLINE) += btf_vmlinux_inline.o
 endif
 ifeq ($(CONFIG_BPF_JIT),y)
 obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 0630675377aaa..29599ab7449ed 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -25,11 +25,12 @@
 #include <linux/skmsg.h>
 #include <linux/perf_event.h>
 #include <linux/bsearch.h>
-#include <linux/kobject.h>
 #include <linux/string.h>
-#include <linux/sysfs.h>
 #include <linux/overflow.h>
 #include <linux/bitops.h>
+#include <linux/unaligned.h>
+#include <linux/vmalloc.h>
+#include <crypto/sha2.h>
 
 #include <net/netfilter/nf_bpf_link.h>
 
@@ -1935,7 +1936,7 @@ void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)
 {
 	btf->base_btf = (struct btf *)base_btf;
 	btf->start_id = btf_nr_types(base_btf);
-	btf->start_str_off = base_btf->hdr.str_len;
+	btf->start_str_off = base_btf->start_str_off + base_btf->hdr.str_len;
 }
 
 static int env_resolve_init(struct btf_verifier_env *env)
@@ -6921,15 +6922,137 @@ __u32 btf_relocate_id(const struct btf *btf, __u32 id)
 
 #ifdef CONFIG_DEBUG_INFO_BTF_MODULES
 
+static struct btf *btf_parse_split(struct btf_verifier_env *env,
+				   const char *name, const void *data,
+				   unsigned int data_size, struct btf *base_btf)
+{
+	struct btf *btf;
+	int err;
+
+	btf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);
+	if (!btf)
+		return ERR_PTR(-ENOMEM);
+	env->btf = btf;
+
+	btf_set_base_btf(btf, base_btf);
+	btf->kernel_btf = true;
+	btf->named_start_id = 0;
+	strscpy(btf->name, name);
+
+	btf->data = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);
+	if (!btf->data) {
+		err = -ENOMEM;
+		goto errout;
+	}
+	btf->data_size = data_size;
+
+	err = btf_parse_hdr(env);
+	if (err)
+		goto errout;
+
+	btf->nohdr_data = btf->data + btf->hdr.hdr_len;
+
+	err = btf_parse_str_sec(env);
+	if (err)
+		goto errout;
+
+	err = btf_check_all_metas(env);
+	if (err)
+		goto errout;
+
+	err = btf_check_modifier_chain_length(env, btf, btf_nr_types(base_btf));
+	if (err)
+		goto errout;
+
+	return btf;
+
+errout:
+	btf_free(btf);
+	return ERR_PTR(err);
+}
+
+static int btf_rebase_inline(struct btf *inline_btf,
+			     const struct btf *module_btf,
+			     const u32 *module_id_map,
+			     const u32 *module_str_map,
+			     u32 old_module_type_cnt)
+{
+	u32 old_start_id = inline_btf->start_id;
+	u32 old_start_str_off = inline_btf->start_str_off;
+	u32 old_module_start_str_off = old_start_str_off - module_btf->hdr.str_len;
+	u32 new_start_id = btf_nr_types(module_btf);
+	u32 new_start_str_off = module_btf->start_str_off + module_btf->hdr.str_len;
+	s64 id_delta = (s64)new_start_id - old_start_id;
+	s64 str_delta = (s64)new_start_str_off - old_start_str_off;
+	u32 i;
+
+	/*
+	 * The inline BTF was parsed relative to the original module BTF. Its
+	 * base IDs must therefore use the map generated when that BTF was
+	 * relocated, while IDs for inline-local types only move by the change
+	 * in the module BTF's starting ID.
+	 */
+	for (i = 0; i < inline_btf->nr_types; i++) {
+		struct btf_field_iter it;
+		struct btf_type *t = inline_btf->types[i];
+		u32 *id, *str_off;
+		int err;
+
+		err = btf_field_iter_init(&it, t, BTF_FIELD_ITER_IDS);
+		if (err)
+			return err;
+		while ((id = btf_field_iter_next(&it))) {
+			if (!*id)
+				continue;
+			if (*id < old_module_type_cnt) {
+				if (module_id_map)
+					*id = module_id_map[*id];
+			} else if (*id >= old_start_id) {
+				*id += id_delta;
+			} else {
+				return -EINVAL;
+			}
+		}
+
+		err = btf_field_iter_init(&it, t, BTF_FIELD_ITER_STRS);
+		if (err)
+			return err;
+		while ((str_off = btf_field_iter_next(&it))) {
+			if (!*str_off)
+				continue;
+			if (*str_off < old_module_start_str_off) {
+				/* Vmlinux strings retain their offsets for in-tree modules. */
+				if (!module_id_map)
+					continue;
+				if (!module_str_map || !module_str_map[*str_off])
+					return -EINVAL;
+				*str_off = module_str_map[*str_off];
+				continue;
+			}
+			*str_off += str_delta;
+		}
+	}
+
+	btf_set_base_btf(inline_btf, module_btf);
+	btf_check_sorted(inline_btf);
+	return 0;
+}
+
 static struct btf *btf_parse_module(const char *module_name, const void *data,
 				    unsigned int data_size, void *base_data,
-				    unsigned int base_data_size)
+				    unsigned int base_data_size,
+				    const void *inline_data,
+				    unsigned int inline_data_size,
+				    void **relocated_inline_data)
 {
-	struct btf *btf = NULL, *vmlinux_btf, *base_btf = NULL;
+	struct btf *btf = NULL, *inline_btf = NULL, *vmlinux_btf, *base_btf = NULL;
 	struct btf_verifier_env *env = NULL;
 	struct bpf_verifier_log *log;
+	u32 *module_str_map = NULL;
+	u32 old_module_type_cnt;
 	int err = 0;
 
+	*relocated_inline_data = NULL;
 	vmlinux_btf = bpf_get_btf_vmlinux();
 	if (IS_ERR(vmlinux_btf))
 		return vmlinux_btf;
@@ -6953,67 +7076,68 @@ static struct btf *btf_parse_module(const char *module_name, const void *data,
 		base_btf = vmlinux_btf;
 	}
 
-	btf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);
-	if (!btf) {
-		err = -ENOMEM;
+	btf = btf_parse_split(env, module_name, data, data_size, base_btf);
+	if (IS_ERR(btf)) {
+		err = PTR_ERR(btf);
+		btf = NULL;
 		goto errout;
 	}
-	env->btf = btf;
-
-	btf->base_btf = base_btf;
-	btf->start_id = base_btf->nr_types;
-	btf->start_str_off = base_btf->hdr.str_len;
-	btf->kernel_btf = true;
-	btf->named_start_id = 0;
-	strscpy(btf->name, module_name);
+	old_module_type_cnt = btf_nr_types(btf);
 
-	btf->data = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);
-	if (!btf->data) {
-		err = -ENOMEM;
-		goto errout;
+	if (inline_data_size) {
+		inline_btf = btf_parse_split(env, module_name, inline_data,
+					     inline_data_size, btf);
+		if (IS_ERR(inline_btf)) {
+			pr_warn("failed to validate module [%s] inline BTF: %ld\n",
+				module_name, PTR_ERR(inline_btf));
+			inline_btf = NULL;
+		}
 	}
-	btf->data_size = data_size;
-
-	err = btf_parse_hdr(env);
-	if (err)
-		goto errout;
-
-	btf->nohdr_data = btf->data + btf->hdr.hdr_len;
-
-	err = btf_parse_str_sec(env);
-	if (err)
-		goto errout;
-
-	err = btf_check_all_metas(env);
-	if (err)
-		goto errout;
-
-	err = btf_check_modifier_chain_length(env, btf, btf_nr_types(base_btf));
-	if (err)
-		goto errout;
 
 	if (base_btf != vmlinux_btf) {
-		err = btf_relocate(btf, vmlinux_btf, &btf->base_id_map);
+		err = btf_relocate(btf, vmlinux_btf, &btf->base_id_map,
+				   &module_str_map);
 		if (err)
 			goto errout;
 		btf_free(base_btf);
 		base_btf = vmlinux_btf;
 	}
 
-	btf_verifier_env_free(env);
+	if (inline_btf) {
+		err = btf_rebase_inline(inline_btf, btf, btf->base_id_map,
+					module_str_map, old_module_type_cnt);
+		if (err) {
+			pr_warn("failed to relocate module [%s] inline BTF: %d\n",
+				module_name, err);
+			btf_free(inline_btf);
+		} else {
+			*relocated_inline_data = inline_btf->data;
+			inline_btf->data = NULL;
+			btf_free(inline_btf);
+		}
+	}
+
+	/*
+	 * With a distilled base, btf_relocate() replaces the base BTF and
+	 * rewrites string offsets. Check ordering only after that final BTF
+	 * view has been established, so named_start_id describes the BTF used
+	 * by name lookups.
+	 */
 	btf_check_sorted(btf);
+	btf_verifier_env_free(env);
+	kvfree(module_str_map);
 	refcount_set(&btf->refcnt, 1);
 	return btf;
 
 errout:
+	kvfree(module_str_map);
 	btf_verifier_env_free(env);
+	if (inline_btf)
+		btf_free(inline_btf);
 	if (!IS_ERR(base_btf) && base_btf != vmlinux_btf)
 		btf_free(base_btf);
-	if (btf) {
-		kvfree(btf->data);
-		kvfree(btf->types);
-		kfree(btf);
-	}
+	if (btf)
+		btf_free(btf);
 	return ERR_PTR(err);
 }
 
@@ -9007,6 +9131,8 @@ struct btf_module {
 	struct module *module;
 	struct btf *btf;
 	struct bin_attribute *sysfs_attr;
+	struct bin_attribute *sysfs_inline_attr;
+	void *btf_inline_data;
 	int flags;
 };
 
@@ -9015,28 +9141,149 @@ static DEFINE_MUTEX(btf_module_mutex);
 
 static void purge_cand_cache(struct btf *btf);
 
+#if IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE)
+extern char __start_BTF_inline_link[];
+extern char __stop_BTF_inline_link[];
+
+static struct bin_attribute *vmlinux_inline_attr;
+static const struct btf_link *vmlinux_inline_link;
+
+static const struct btf_link *btf_parse_link(void *start, unsigned int size)
+{
+	const struct btf_link *link = start;
+	unsigned int module_name_len;
+
+	if (!link || size != sizeof(*link) || link->btf_size == 0)
+		return NULL;
+
+	module_name_len = strnlen(link->module_name, sizeof(link->module_name));
+	if (!module_name_len || module_name_len == sizeof(link->module_name) ||
+	    memchr_inv(link->module_name + module_name_len + 1, 0,
+		       sizeof(link->module_name) - module_name_len - 1))
+		return NULL;
+	return link;
+}
+
+static bool btf_verify_link(const struct btf_link *link, const struct module *mod,
+			    const void *data, size_t data_size)
+{
+	u8 actual_digest[BTF_LINK_SHA256_LEN];
+
+	if (!link || data_size != link->btf_size) {
+		pr_warn(" BTF link from module [%s] missing or has unexpected size\n", mod->name);
+		return false;
+	}
+	sha256(data, data_size, actual_digest);
+	if (memcmp(actual_digest, link->sha256, sizeof(actual_digest))) {
+		pr_warn("BTF link from module [%s] has unexpected digest\n", mod->name);
+		return false;
+	}
+
+	return true;
+}
+
+static void btf_vmlinux_inline_lazy_init(void)
+{
+	vmlinux_inline_link = btf_parse_link(__start_BTF_inline_link,
+					     __stop_BTF_inline_link -
+					     __start_BTF_inline_link);
+	if (!vmlinux_inline_link) {
+		pr_warn("invalid vmlinux inline BTF link\n");
+		return;
+	}
+	vmlinux_inline_attr = sysfs_btf_add("vmlinux.inline", NULL,
+					    vmlinux_inline_link->btf_size, true,
+					    vmlinux_inline_link->module_name);
+	if (IS_ERR(vmlinux_inline_attr)) {
+		pr_warn("failed to register vmlinux inline BTF in sysfs: %ld\n",
+			PTR_ERR(vmlinux_inline_attr));
+		vmlinux_inline_attr = NULL;
+	}
+}
+
+static bool btf_module_is_vmlinux_inline(const struct module *mod)
+{
+	return vmlinux_inline_link && !strcmp(mod->name, vmlinux_inline_link->module_name);
+}
+
+static int btf_module_handle_vmlinux_inline(const struct module *mod)
+{
+	void *data;
+
+	if (!mod->btf_inline_data ||
+	    mod->btf_inline_data_size != vmlinux_inline_link->btf_size)
+		return -EINVAL;
+
+	data = vmalloc_user(mod->btf_inline_data_size);
+	if (!data)
+		return -ENOMEM;
+	memcpy(data, mod->btf_inline_data, mod->btf_inline_data_size);
+
+	if (!btf_verify_link(vmlinux_inline_link, mod, data, mod->btf_inline_data_size) ||
+	    !sysfs_btf_update(vmlinux_inline_attr, data)) {
+		kvfree(data);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+#else
+
+static bool btf_module_is_vmlinux_inline(const struct module *mod)
+{
+	return false;
+}
+
+static int btf_module_handle_vmlinux_inline(const struct module *mod)
+{
+	return 0;
+}
+
+static void btf_vmlinux_inline_lazy_init(void)
+{
+}
+
+#endif /* IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE) */
+
 static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 			     void *module)
 {
 	struct btf_module *btf_mod, *tmp;
 	struct module *mod = module;
+	struct bin_attribute *attr;
 	struct btf *btf;
+	void *inline_data = NULL, *relocated_inline_data = NULL;
+	unsigned int inline_data_size = 0;
 	int err = 0;
 
-	if (mod->btf_data_size == 0 ||
-	    (op != MODULE_STATE_COMING && op != MODULE_STATE_LIVE &&
-	     op != MODULE_STATE_GOING))
+	if (op != MODULE_STATE_COMING && op != MODULE_STATE_LIVE &&
+	    op != MODULE_STATE_GOING)
 		goto out;
 
 	switch (op) {
 	case MODULE_STATE_COMING:
+		if (btf_module_is_vmlinux_inline(mod)) {
+			err = btf_module_handle_vmlinux_inline(mod);
+			break;
+		}
+
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+		if (mod->btf_inline_data_size) {
+			inline_data = mod->btf_inline_data;
+			inline_data_size = mod->btf_inline_data_size;
+		}
+#endif
+		if (!mod->btf_data_size)
+			break;
 		btf_mod = kzalloc_obj(*btf_mod);
 		if (!btf_mod) {
 			err = -ENOMEM;
 			goto out;
 		}
 		btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size,
-				       mod->btf_base_data, mod->btf_base_data_size);
+				       mod->btf_base_data, mod->btf_base_data_size,
+				       inline_data, inline_data_size,
+				       &relocated_inline_data);
 		if (IS_ERR(btf)) {
 			kfree(btf_mod);
 			if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) {
@@ -9051,6 +9298,7 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 		err = btf_alloc_id(btf);
 		if (err) {
 			btf_free(btf);
+			kvfree(relocated_inline_data);
 			kfree(btf_mod);
 			goto out;
 		}
@@ -9059,37 +9307,35 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 		mutex_lock(&btf_module_mutex);
 		btf_mod->module = module;
 		btf_mod->btf = btf;
+		btf_mod->btf_inline_data = relocated_inline_data;
 		list_add(&btf_mod->list, &btf_modules);
 		mutex_unlock(&btf_module_mutex);
 
-		if (IS_ENABLED(CONFIG_SYSFS)) {
-			struct bin_attribute *attr;
-
-			attr = kzalloc_obj(*attr);
-			if (!attr)
-				goto out;
+		attr = sysfs_btf_add(btf->name, btf->data, btf->data_size, false, NULL);
+		if (IS_ERR(attr)) {
+			err = 0;
+			goto out;
+		}
+		btf_mod->sysfs_attr = attr;
 
-			sysfs_bin_attr_init(attr);
-			attr->attr.name = btf->name;
-			attr->attr.mode = 0444;
-			attr->size = btf->data_size;
-			attr->private = btf->data;
-			attr->read = sysfs_bin_attr_simple_read;
+		if (relocated_inline_data) {
+			char name[MODULE_NAME_LEN + sizeof(".inline")];
 
-			err = sysfs_create_bin_file(btf_kobj, attr);
-			if (err) {
-				pr_warn("failed to register module [%s] BTF in sysfs: %d\n",
-					mod->name, err);
-				kfree(attr);
+			snprintf(name, sizeof(name), "%s.inline", mod->name);
+			attr = sysfs_btf_add(name, relocated_inline_data,
+					     inline_data_size, false, NULL);
+			if (IS_ERR(attr)) {
+				kvfree(relocated_inline_data);
+				btf_mod->btf_inline_data = NULL;
 				err = 0;
-				goto out;
+				break;
 			}
-
-			btf_mod->sysfs_attr = attr;
+			btf_mod->sysfs_inline_attr = attr;
 		}
-
 		break;
 	case MODULE_STATE_LIVE:
+		if (!mod->btf_data_size)
+			break;
 		mutex_lock(&btf_module_mutex);
 		list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) {
 			if (btf_mod->module != module)
@@ -9101,6 +9347,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 		mutex_unlock(&btf_module_mutex);
 		break;
 	case MODULE_STATE_GOING:
+		if (!mod->btf_data_size)
+			break;
 		mutex_lock(&btf_module_mutex);
 		list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) {
 			if (btf_mod->module != module)
@@ -9115,10 +9363,12 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
 			btf_free_id(btf_mod->btf);
 			list_del(&btf_mod->list);
 			if (btf_mod->sysfs_attr)
-				sysfs_remove_bin_file(btf_kobj, btf_mod->sysfs_attr);
+				sysfs_btf_remove(btf_mod->sysfs_attr);
+			if (btf_mod->sysfs_inline_attr)
+				sysfs_btf_remove(btf_mod->sysfs_inline_attr);
+			kvfree(btf_mod->btf_inline_data);
 			purge_cand_cache(btf_mod->btf);
 			btf_put(btf_mod->btf);
-			kfree(btf_mod->sysfs_attr);
 			kfree(btf_mod);
 			break;
 		}
@@ -9135,6 +9385,7 @@ static struct notifier_block btf_module_nb = {
 
 static int __init btf_module_init(void)
 {
+	btf_vmlinux_inline_lazy_init();
 	register_module_notifier(&btf_module_nb);
 	return 0;
 }
diff --git a/kernel/bpf/btf_vmlinux_inline.c b/kernel/bpf/btf_vmlinux_inline.c
new file mode 100644
index 0000000000000..d5c599d9f7295
--- /dev/null
+++ b/kernel/bpf/btf_vmlinux_inline.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026, Oracle and/or its affiliates. */
+/*
+ * Provide kernel BTF inline function information for use by BPF tools.
+ */
+#include <linux/btf.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)
+extern char __start_BTF_inline[];
+extern char __stop_BTF_inline[];
+#endif
+
+static int __init btf_vmlinux_inline_init(void)
+{
+#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)
+	size_t data_size = __stop_BTF_inline - __start_BTF_inline;
+
+	if (data_size)
+		sysfs_btf_add("vmlinux.inline", __start_BTF_inline, data_size, true, NULL);
+#endif
+	return 0;
+}
+subsys_initcall(btf_vmlinux_inline_init);
+
+MODULE_DESCRIPTION("BTF inline information for vmlinux");
+MODULE_LICENSE("GPL");
diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c
index 9cbe15ce3540c..556fe92c36495 100644
--- a/kernel/bpf/sysfs_btf.c
+++ b/kernel/bpf/sysfs_btf.c
@@ -6,8 +6,10 @@
 #include <linux/module.h>
 #include <linux/kobject.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/sysfs.h>
 #include <linux/mm.h>
+#include <linux/vmalloc.h>
 #include <linux/io.h>
 #include <linux/btf.h>
 
@@ -15,16 +17,12 @@
 extern char __start_BTF[];
 extern char __stop_BTF[];
 
-static int btf_sysfs_vmlinux_mmap(struct file *filp, struct kobject *kobj,
-				  const struct bin_attribute *attr,
-				  struct vm_area_struct *vma)
+static int btf_sysfs_mmap_check(void *data, size_t size, struct vm_area_struct *vma)
 {
-	unsigned long pages = PAGE_ALIGN(attr->size) >> PAGE_SHIFT;
+	unsigned long pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
 	size_t vm_size = vma->vm_end - vma->vm_start;
-	phys_addr_t addr = __pa_symbol(__start_BTF);
-	unsigned long pfn = addr >> PAGE_SHIFT;
 
-	if (attr->private != __start_BTF || !PAGE_ALIGNED(addr))
+	if (!data || !PAGE_ALIGNED((unsigned long)data))
 		return -EINVAL;
 
 	if (vma->vm_pgoff)
@@ -33,24 +31,153 @@ static int btf_sysfs_vmlinux_mmap(struct file *filp, struct kobject *kobj,
 	if (vma->vm_flags & (VM_WRITE | VM_EXEC | VM_MAYSHARE))
 		return -EACCES;
 
-	if (pfn + pages < pfn)
-		return -EINVAL;
-
 	if ((vm_size >> PAGE_SHIFT) > pages)
 		return -EINVAL;
 
 	vm_flags_mod(vma, VM_DONTDUMP, VM_MAYEXEC | VM_MAYWRITE);
+	return 0;
+}
+
+static int btf_sysfs_mmap_image(struct file *filp, struct kobject *kobj,
+				const struct bin_attribute *attr,
+				struct vm_area_struct *vma)
+{
+	void *data = READ_ONCE(attr->private);
+	phys_addr_t addr;
+	unsigned long pfn;
+	size_t vm_size = vma->vm_end - vma->vm_start;
+	int err;
+
+	err = btf_sysfs_mmap_check(data, attr->size, vma);
+	if (err)
+		return err;
+
+	/* Kernel image addresses can lie inside the vmalloc range on arm64. */
+	addr = __pa_symbol(data);
+	pfn = addr >> PAGE_SHIFT;
+	if (pfn + (PAGE_ALIGN(attr->size) >> PAGE_SHIFT) < pfn)
+		return -EINVAL;
+
 	return remap_pfn_range(vma, vma->vm_start, pfn, vm_size, vma->vm_page_prot);
 }
 
 static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {
 	.attr = { .name = "vmlinux", .mode = 0444, },
 	.read = sysfs_bin_attr_simple_read,
-	.mmap = btf_sysfs_vmlinux_mmap,
+	.mmap = btf_sysfs_mmap_image,
 };
 
 struct kobject *btf_kobj;
 
+struct btf_sysfs_entry {
+	struct bin_attribute attr;
+	char *module_name;
+};
+
+static void *btf_sysfs_lazy_data(const struct bin_attribute *attr)
+{
+	struct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);
+	void *data;
+
+	data = smp_load_acquire(&attr->private);
+	if (!data) {
+		request_module("%s", entry->module_name);
+		data = smp_load_acquire(&attr->private);
+	}
+	return data;
+}
+
+static ssize_t btf_sysfs_read_lazy(struct file *filp, struct kobject *kobj,
+				   const struct bin_attribute *attr, char *buf,
+				   loff_t off, size_t count)
+{
+	void *data = btf_sysfs_lazy_data(attr);
+
+	if (!data)
+		return -ENODEV;
+
+	return memory_read_from_buffer(buf, count, &off, data, attr->size);
+}
+
+static int btf_sysfs_mmap_lazy(struct file *filp, struct kobject *kobj,
+			       const struct bin_attribute *attr,
+			       struct vm_area_struct *vma)
+{
+	void *data = btf_sysfs_lazy_data(attr);
+	int err;
+
+	if (!data)
+		return -ENODEV;
+
+	err = btf_sysfs_mmap_check(data, attr->size, vma);
+	if (err)
+		return err;
+
+	return remap_vmalloc_range(vma, data, 0);
+}
+
+struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,
+				    bool mmap, const char *lazy_module_name)
+{
+	struct btf_sysfs_entry *entry;
+	struct bin_attribute *attr;
+	int err;
+
+	entry = kzalloc_obj(*entry);
+	if (!entry)
+		return ERR_PTR(-ENOMEM);
+
+	attr = &entry->attr;
+	sysfs_bin_attr_init(attr);
+	attr->attr.mode = 0444;
+	attr->size = data_size;
+	attr->private = data;
+	attr->read = lazy_module_name ? btf_sysfs_read_lazy : sysfs_bin_attr_simple_read;
+	if (mmap)
+		attr->mmap = lazy_module_name ? btf_sysfs_mmap_lazy : btf_sysfs_mmap_image;
+	attr->attr.name = kstrdup(name, GFP_KERNEL);
+	if (!attr->attr.name) {
+		err = -ENOMEM;
+		goto err_free;
+	}
+	if (lazy_module_name) {
+		entry->module_name = kstrdup(lazy_module_name, GFP_KERNEL);
+		if (!entry->module_name) {
+			err = -ENOMEM;
+			goto err_free;
+		}
+	}
+
+	err = sysfs_create_bin_file(btf_kobj, attr);
+	if (err) {
+		pr_warn("failed to register [%s] BTF in sysfs: %d\n", name, err);
+		goto err_free;
+	}
+
+	return attr;
+
+err_free:
+	kfree(entry->module_name);
+	kfree(attr->attr.name);
+	kfree(entry);
+	return ERR_PTR(err);
+}
+
+bool sysfs_btf_update(struct bin_attribute *attr, void *data)
+{
+	return attr && !cmpxchg(&attr->private, NULL, data);
+}
+
+void sysfs_btf_remove(struct bin_attribute *attr)
+{
+	struct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);
+
+	sysfs_remove_bin_file(btf_kobj, attr);
+	kfree(entry->module_name);
+	kfree(attr->attr.name);
+	kfree(entry);
+}
+
 static int __init btf_vmlinux_init(void)
 {
 	bin_attr_btf_vmlinux.private = __start_BTF;
diff --git a/kernel/module/main.c b/kernel/module/main.c
index c1b34dc1e89ac..5b9eb56164b29 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2723,6 +2723,10 @@ static int find_module_sections(struct module *mod, struct load_info *info)
 	mod->btf_base_data = any_section_objs(info, ".BTF.base", 1,
 					      &mod->btf_base_data_size);
 #endif
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+	mod->btf_inline_data = any_section_objs(info, ".BTF.inline", 1,
+						&mod->btf_inline_data_size);
+#endif
 #ifdef CONFIG_JUMP_LABEL
 	mod->jump_entries = section_objs(info, "__jump_table",
 					sizeof(*mod->jump_entries),
@@ -3176,6 +3180,9 @@ static noinline int do_init_module(struct module *mod)
 	/* .BTF is not SHF_ALLOC and will get removed, so sanitize pointers */
 	mod->btf_data = NULL;
 	mod->btf_base_data = NULL;
+#endif
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+	mod->btf_inline_data = NULL;
 #endif
 	/*
 	 * We want to free module_init, but be aware that kallsyms may be
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 134b15a44625e..2f34619905b60 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -425,6 +425,12 @@ config PAHOLE_HAS_LANG_EXCLUDE
 	  otherwise it would emit malformed kernel and module binaries when
 	  using DEBUG_INFO_BTF_MODULES.
 
+config PAHOLE_HAS_INLINE
+	def_bool PAHOLE_VERSION >= 132
+	help
+	  Support for the "inline" BTF feature is available. It encodes
+	  information about inline sites and how to retrieve their parameters.
+
 config DEBUG_INFO_BTF_MODULES
 	bool "Generate BTF type information for kernel modules"
 	default y
@@ -432,6 +438,18 @@ config DEBUG_INFO_BTF_MODULES
 	help
 	  Generate compact split BTF type information for kernel modules.
 
+config DEBUG_INFO_BTF_INLINE
+	tristate "Provide information about inline sites in BTF"
+	default n
+	depends on DEBUG_INFO_BTF && PAHOLE_HAS_INLINE && SYSFS
+	select DEBUG_INFO_BTF_MODULES if MODULES
+	help
+	  Generate information about inline sites in .BTF.inline sections.
+	  These sections contain split BTF relative to the kernel or module BTF
+	  and are made available in /sys/kernel/btf with a ".inline" suffix.
+	  The information describes inline locations and how to retrieve their
+	  associated parameters.
+
 config MODULE_ALLOW_BTF_MISMATCH
 	bool "Allow loading modules with non-matching BTF type info"
 	depends on DEBUG_INFO_BTF_MODULES
diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
index a1812985a61aa..98012344a81ec 100644
--- a/scripts/Makefile.btf
+++ b/scripts/Makefile.btf
@@ -22,7 +22,14 @@ endif
 
 pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE)		+= --lang_exclude=rust
 
+btf-inline := $(CONFIG_DEBUG_INFO_BTF_INLINE)
+ifneq ($(btf-inline),)
+btf-inline-feat := inline
+pahole-flags-$(call test-ge, $(pahole-ver), 132) += --btf_features=$(btf-inline-feat)
+endif
+
 export PAHOLE_FLAGS := $(pahole-flags-y)
+export BTF_INLINE := $(btf-inline)
 
 resolve-btfids-flags-y :=
 resolve-btfids-flags-$(CONFIG_WERROR) += --fatal_warnings
diff --git a/scripts/gen-btf.sh b/scripts/gen-btf.sh
index 8ca96eb10a69e..b17f1189298a5 100755
--- a/scripts/gen-btf.sh
+++ b/scripts/gen-btf.sh
@@ -68,6 +68,7 @@ esac
 
 gen_btf_data()
 {
+	inline=${BTF_INLINE:+--inline}
 	btf1="${ELF_FILE}.BTF.1"
 	${PAHOLE} -J ${PAHOLE_FLAGS}			\
 		${BTF_BASE:+--btf_base ${BTF_BASE}}	\
@@ -76,6 +77,7 @@ gen_btf_data()
 
 	${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_FLAGS}	\
 		${BTF_BASE:+--btf_base ${BTF_BASE}}	\
+		${inline}				\
 		--btf ${btf1} "${ELF_FILE}"
 }
 
@@ -83,14 +85,28 @@ gen_btf_o()
 {
 	btf_data=${ELF_FILE}.btf.o
 
-	# Create ${btf_data} which contains just .BTF section but no symbols. Add
+	# Create ${btf_data} which contains just BTF sections but no symbols. Add
 	# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all
 	# deletes all symbols including __start_BTF and __stop_BTF, which will
 	# be redefined in the linker script.
 	echo "" | ${CC} ${CLANG_FLAGS} ${KBUILD_CPPFLAGS} ${KBUILD_CFLAGS} -fno-lto -c -x c -o ${btf_data} -
 	${OBJCOPY} --add-section .BTF=${ELF_FILE}.BTF \
 		--set-section-flags .BTF=alloc,readonly ${btf_data}
-	${OBJCOPY} --only-section=.BTF --strip-all ${btf_data}
+	ONLY_SEC="--only-section=.BTF"
+	btf_inline=${ELF_FILE}.BTF.inline
+	if [ "${BTF_INLINE}" = "m" ]; then
+		if [ -f "${btf_inline}" ]; then
+			cp "${btf_inline}" "${objtree}/vmlinux.BTF.inline"
+		else
+			rm -f "${objtree}/vmlinux.BTF.inline"
+		fi
+	fi
+	if [ "${BTF_INLINE}" = "y" ] && [ -f "${btf_inline}" ]; then
+		${OBJCOPY} --add-section .BTF.inline=${btf_inline} \
+			--set-section-flags .BTF.inline=alloc,readonly ${btf_data}
+		ONLY_SEC="${ONLY_SEC} --only-section=.BTF.inline"
+	fi
+	${OBJCOPY} ${ONLY_SEC} --strip-all ${btf_data}
 
 	# Change e_type to ET_REL so that it can be used to link final vmlinux.
 	# GNU ld 2.35+ and lld do not allow an ET_EXEC input.
@@ -111,6 +127,15 @@ embed_btf_data()
 	if [ -f "${btf_base}" ]; then
 		${OBJCOPY} --add-section .BTF.base=${btf_base} ${ELF_FILE}
 	fi
+	btf_inline=${ELF_FILE}.BTF.inline
+	case "${ELF_FILE}" in
+	*/btf_vmlinux_inline.ko)
+		btf_inline=${BTF_BASE}.BTF.inline
+		;;
+	esac
+	if [ -n "${BTF_INLINE}" ] && [ -f "${btf_inline}" ]; then
+		${OBJCOPY} --add-section .BTF.inline=${btf_inline} ${ELF_FILE}
+	fi
 	btf_ids="${ELF_FILE}.BTF_ids"
 	if [ -f "${btf_ids}" ]; then
 		${RESOLVE_BTFIDS} --patch_btfids ${btf_ids} ${ELF_FILE}
@@ -121,6 +146,8 @@ cleanup()
 {
 	rm -f "${ELF_FILE}.BTF.1"
 	rm -f "${ELF_FILE}.BTF"
+	rm -f "${ELF_FILE}.BTF.inline"
+	rm -f "${ELF_FILE}.BTF.inline.link"
 	if [ "${BTFGEN_MODE}" = "module" ]; then
 		rm -f "${ELF_FILE}.BTF.base"
 		rm -f "${ELF_FILE}.BTF_ids"
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index ab0b8125c8cbc..5424caf5135bc 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -289,7 +289,13 @@ vmlinux_link "${VMLINUX}"
 
 if is_enabled CONFIG_DEBUG_INFO_BTF; then
 	info BTFIDS ${VMLINUX}
-	${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}
+	if [ "${BTF_INLINE}" = "m" ]; then
+		${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} \
+			--btf_link .BTF.inline:btf_vmlinux_inline:vmlinux.BTF.inline \
+			${VMLINUX}
+	else
+		${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}
+	fi
 fi
 
 mksysmap "${VMLINUX}" System.map
diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec
index 46e80970f7239..8f0933cbbe452 100644
--- a/scripts/package/kernel.spec
+++ b/scripts/package/kernel.spec
@@ -68,13 +68,13 @@ This package provides debug information for the kernel image and modules from th
 %undefine _debugsource_packages
 %undefine _debuginfo_subpackages
 
-# Preserve .BTF and .BTF.base sections in kernel modules during debuginfo
-# stripping. find-debuginfo.sh uses eu-strip which removes non-allocated ELF
-# sections like .BTF by default. .BTF.base is required for BTF distillation
-# support; without it, module BTF validation fails.
+# Preserve .BTF,  .BTF.base and .BTF.inline sections in kernel modules during
+# debuginfo stripping. find-debuginfo.sh uses eu-strip which removes
+# non-allocated ELF sections like .BTF by default. .BTF.base is required for
+# BTF distillation support; without it, module BTF validation fails.
 %global with_keep_section %(%{__find_debuginfo} --help 2>&1 | grep -c keep-section)
 %if %{with_keep_section}
-%global _find_debuginfo_opts -r --keep-section .BTF --keep-section .BTF.base
+%global _find_debuginfo_opts -r --keep-section .BTF --keep-section .BTF.base --keep-section .BTF.inline
 %else
 %global _find_debuginfo_opts -r
 %endif
diff --git a/tools/bpf/resolve_btfids/Build b/tools/bpf/resolve_btfids/Build
index 077de3829c722..602e1508bf092 100644
--- a/tools/bpf/resolve_btfids/Build
+++ b/tools/bpf/resolve_btfids/Build
@@ -1,6 +1,7 @@
 hostprogs := resolve_btfids
 
 resolve_btfids-y += main.o
+resolve_btfids-y += btf_colors.o
 resolve_btfids-y += rbtree.o
 resolve_btfids-y += zalloc.o
 resolve_btfids-y += string.o
diff --git a/tools/bpf/resolve_btfids/btf_colors.c b/tools/bpf/resolve_btfids/btf_colors.c
new file mode 100644
index 0000000000000..5d307d70e7f22
--- /dev/null
+++ b/tools/bpf/resolve_btfids/btf_colors.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <bpf/libbpf_internal.h>
+#include "btf_colors.h"
+
+/*
+ * Functions in this file mainly exist to refer to functions from libbpf_internal.h,
+ * which can't be included in main.c because of the u32 poison and pr_warn macro conflicts.
+ */
+
+void btf_sha256(const void *data, size_t len,
+		__u8 out[BTF_SHA256_DIGEST_LENGTH])
+{
+	libbpf_sha256(data, len, out);
+}
+
+/*
+ * Marks `root_id` and local types reachable from it with `color`.
+ * `colors` is indexed by source ID; worklist has room for every local type.
+ */
+void btf_mark_reachable(struct btf *btf, __u32 root_id, enum btf_color color,
+			__u8 *colors, __u32 *worklist)
+{
+	const struct btf *base = btf__base_btf(btf);
+	__u32 start_id = base ? btf__type_cnt(base) : 1;
+	__u32 pending = 0;
+
+	if (root_id < start_id || (colors[root_id] & color) == color)
+		return;
+	colors[root_id] |= color;
+	worklist[pending++] = root_id;
+	while (pending) {
+		const struct btf_type *t = btf__type_by_id(btf, worklist[--pending]);
+		struct btf_field_iter it;
+		__u32 *id;
+
+		btf_field_iter_init(&it, (struct btf_type *)t, BTF_FIELD_ITER_IDS);
+		while ((id = btf_field_iter_next(&it))) {
+			if (*id < start_id || (colors[*id] & color) == color)
+				continue;
+			colors[*id] |= color;
+			worklist[pending++] = *id;
+		}
+	}
+}
+
+static int cmp_loc(const void *a, const void *b)
+{
+	const struct btf_loc *la = a, *lb = b;
+
+	if (la->func != lb->func)
+		return la->func < lb->func ? -1 : 1;
+	if (la->offset != lb->offset)
+		return la->offset < lb->offset ? -1 : 1;
+	if (la->loc_proto != lb->loc_proto)
+		return la->loc_proto < lb->loc_proto ? -1 : 1;
+	return 0;
+}
+
+static void remap(struct btf *btf, const __u32 *id_map, __u32 src_start_id)
+{
+	const struct btf *base = btf__base_btf(btf);
+	__u32 start_id = base ? btf__type_cnt(base) : 1;
+	__u32 i, type_cnt = btf__type_cnt(btf);
+
+	for (i = start_id; i < type_cnt; i++) {
+		struct btf_type *t = (struct btf_type *)btf__type_by_id(btf, i);
+		struct btf_field_iter it;
+		__u32 *id;
+
+		btf_field_iter_init(&it, t, BTF_FIELD_ITER_IDS);
+		while ((id = btf_field_iter_next(&it))) {
+			/* Void and types in the original ancestor are unchanged. */
+			if (*id >= src_start_id)
+				*id = id_map[*id - src_start_id];
+		}
+		if (btf_is_locsec(t))
+			qsort(btf_locsec_locs(t), btf_vlen(t), sizeof(struct btf_loc), cmp_loc);
+	}
+}
+
+/*
+ * Split the `src` into `main_out` base and `inline_out`,
+ * according to `colors` array. Relative ordering remains
+ * the same as in `src`.
+ */
+int btf_split_by_color(struct btf *src, const __u8 *colors,
+		       struct btf **main_out, struct btf **inline_out)
+{
+	LIBBPF_OPTS(btf_new_opts, opts,
+		    .base_btf = (struct btf *)btf__base_btf(src),
+		    .add_layout = btf_header(src)->layout_len != 0,
+	);
+	struct btf *main_btf, *inline_btf = NULL;
+	__u32 start_id = opts.base_btf ? btf__type_cnt(opts.base_btf) : 1;
+	__u32 type_cnt = btf__type_cnt(src);
+	__u32 *id_map, i;
+	int err = -ENOMEM;
+
+	*main_out = NULL;
+	*inline_out = NULL;
+	id_map = malloc((type_cnt - start_id ?: 1) * sizeof(*id_map));
+	if (!id_map)
+		return -ENOMEM;
+	main_btf = btf__new_empty_opts(&opts);
+	if (!main_btf)
+		goto out;
+	btf__set_endianness(main_btf, btf__endianness(src));
+	/* Copy MAIN and SHARED marked types to `main_out`. */
+	for (i = start_id; i < type_cnt; i++) {
+		if (colors[i] == BTF_COLOR_LOC)
+			continue;
+		err = btf__add_type(main_btf, src, btf__type_by_id(src, i));
+		if (err < 0)
+			goto out;
+		id_map[i - start_id] = err;
+	}
+	/*
+	 * Copy LOC marked types to `inline_out`.
+	 * `main_btf` types count is stable at this point.
+	 */
+	inline_btf = btf__new_empty_split(main_btf);
+	if (!inline_btf) {
+		err = -ENOMEM;
+		goto out;
+	}
+	for (i = start_id; i < type_cnt; i++) {
+		if (colors[i] != BTF_COLOR_LOC)
+			continue;
+		err = btf__add_type(inline_btf, src, btf__type_by_id(src, i));
+		if (err < 0)
+			goto out;
+		id_map[i - start_id] = err;
+	}
+	remap(main_btf, id_map, start_id);
+	remap(inline_btf, id_map, start_id);
+	*main_out = main_btf;
+	*inline_out = inline_btf;
+	free(id_map);
+	return 0;
+out:
+	btf__free(inline_btf);
+	btf__free(main_btf);
+	free(id_map);
+	return err;
+}
diff --git a/tools/bpf/resolve_btfids/btf_colors.h b/tools/bpf/resolve_btfids/btf_colors.h
new file mode 100644
index 0000000000000..56a85a242d6bd
--- /dev/null
+++ b/tools/bpf/resolve_btfids/btf_colors.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __RESOLVE_BTFIDS_BTF_COLORS_H
+#define __RESOLVE_BTFIDS_BTF_COLORS_H
+
+#include <bpf/btf.h>
+
+enum btf_color {
+	BTF_COLOR_NONE = 0,
+	BTF_COLOR_MAIN = 1,
+	BTF_COLOR_LOC = 2,
+	BTF_COLOR_SHARED = BTF_COLOR_MAIN | BTF_COLOR_LOC,
+};
+
+#define BTF_SHA256_DIGEST_LENGTH	32
+
+void btf_sha256(const void *data, size_t len,
+		__u8 out[BTF_SHA256_DIGEST_LENGTH]);
+void btf_mark_reachable(struct btf *btf, __u32 root, enum btf_color color,
+			__u8 *colors, __u32 *worklist);
+
+int btf_split_by_color(struct btf *src, const __u8 *colors,
+		       struct btf **main_out, struct btf **inline_out);
+
+#endif
diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 37d7e7224207d..f737fac60fa24 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -89,9 +89,11 @@
 #include <linux/limits.h>
 #include <bpf/btf.h>
 #include <bpf/libbpf.h>
+#include "btf_colors.h"
 #include <subcmd/parse-options.h>
 
 #define BTF_IDS_SECTION	".BTF_ids"
+#define BTF_LINK_MODULE_NAME_MAX	64
 #define BTF_ID_PREFIX	"__BTF_ID__"
 
 #define BTF_STRUCT	"struct"
@@ -142,7 +144,10 @@ struct object {
 
 	struct btf *btf;
 	struct btf *base_btf;
+	struct btf *inline_btf;
+	struct btf *orig_btf;
 	bool distill_base;
+	bool extract_inline;
 
 	struct {
 		int		 fd;
@@ -154,6 +159,11 @@ struct object {
 		size_t		 strtabidx;
 		unsigned long	 idlist_addr;
 		int		 encoding;
+		int		 elf_class;
+		const char	**func_symbols;
+		u32		 func_symbols_cnt;
+		u32		 func_symbols_cap;
+		bool		 func_symbols_collected;
 	} efile;
 
 	struct rb_root	sets;
@@ -172,6 +182,19 @@ struct object {
 	u32 addr_syms_cap;
 };
 
+struct btf_link {
+	char *value;
+	char *section;
+	char *module;
+	char *btf_path;
+};
+
+struct btf_links {
+	struct btf_link *links;
+	u32 cnt;
+	u32 cap;
+};
+
 #define DECL_TAG_FASTCALL "bpf_fastcall"
 #define DECL_TAG_KFUNC "bpf_kfunc"
 
@@ -259,6 +282,49 @@ static int __ensure_mem(void **data, u32 *cap, u32 cnt, size_t elem_sz)
 #define ensure_mem(arr_ptr, cap_ptr, cnt) \
 	__ensure_mem((void **)(arr_ptr), (cap_ptr), (cnt), sizeof(**(arr_ptr)))
 
+static int parse_btf_link(const struct option *opt, const char *arg, int unset)
+{
+	struct btf_links *links = opt->value;
+	struct btf_link *link;
+	char *separator;
+
+	if (unset)
+		return -EINVAL;
+	if (__ensure_mem((void **)&links->links, &links->cap, links->cnt + 1,
+			 sizeof(*links->links)))
+		return -ENOMEM;
+	link = &links->links[links->cnt];
+	memset(link, 0, sizeof(*link));
+	link->value = strdup(arg);
+	if (!link->value)
+		return -ENOMEM;
+	link->section = link->value;
+	separator = strchr(link->section, ':');
+	if (!separator || separator == link->section)
+		goto err_value;
+	*separator++ = '\0';
+	link->module = separator;
+	separator = strchr(link->module, ':');
+	if (!separator || separator == link->module || !separator[1])
+		goto err_value;
+	*separator++ = '\0';
+	link->btf_path = separator;
+	links->cnt++;
+	return 0;
+err_value:
+	free(link->value);
+	return -EINVAL;
+}
+
+static void free_btf_links(struct btf_links *links)
+{
+	u32 i;
+
+	for (i = 0; i < links->cnt; i++)
+		free(links->links[i].value);
+	free(links->links);
+}
+
 static bool is_btf_id(const char *name)
 {
 	return name && !strncmp(name, BTF_ID_PREFIX, sizeof(BTF_ID_PREFIX) - 1);
@@ -480,6 +546,7 @@ static int elf_collect(struct object *obj)
 		return -1;
 	}
 	obj->efile.encoding = ehdr.e_ident[EI_DATA];
+	obj->efile.elf_class = ehdr.e_ident[EI_CLASS];
 
 	/*
 	 * Scan all the elf sections and look for save data
@@ -572,6 +639,58 @@ static const char *find_name_by_addr(struct object *obj, Elf64_Addr addr)
 	return res ? res->name : NULL;
 }
 
+static int cmp_func_symbol(const void *a, const void *b)
+{
+	const char * const *name = a;
+	const char * const *other = b;
+
+	return strcmp(*name, *other);
+}
+
+static int collect_func_symbols(struct object *obj)
+{
+	Elf_Scn *scn;
+	GElf_Shdr sh;
+	int n, i;
+
+	if (obj->efile.symbols_shndx == -1)
+		return 0;
+
+	scn = elf_getscn(obj->efile.elf, obj->efile.symbols_shndx);
+	if (!scn || gelf_getshdr(scn, &sh) != &sh || !sh.sh_entsize)
+		return -EINVAL;
+	n = sh.sh_size / sh.sh_entsize;
+
+	for (i = 0; i < n; i++) {
+		GElf_Sym sym;
+		const char *name;
+
+		if (!gelf_getsym(obj->efile.symbols, i, &sym))
+			return -EINVAL;
+		if (GELF_ST_TYPE(sym.st_info) != STT_FUNC ||
+		    sym.st_shndx == SHN_UNDEF || !sym.st_name)
+			continue;
+		name = elf_strptr(obj->efile.elf, obj->efile.strtabidx, sym.st_name);
+		if (!name)
+			return -EINVAL;
+		if (ensure_mem(&obj->efile.func_symbols, &obj->efile.func_symbols_cap,
+			       obj->efile.func_symbols_cnt + 1))
+			return -ENOMEM;
+		obj->efile.func_symbols[obj->efile.func_symbols_cnt++] = name;
+	}
+
+	qsort(obj->efile.func_symbols, obj->efile.func_symbols_cnt,
+	      sizeof(*obj->efile.func_symbols), cmp_func_symbol);
+	obj->efile.func_symbols_collected = true;
+	return 0;
+}
+
+static bool has_func_symbol(const struct object *obj, const char *name)
+{
+	return bsearch(&name, obj->efile.func_symbols, obj->efile.func_symbols_cnt,
+		       sizeof(*obj->efile.func_symbols), cmp_func_symbol) != NULL;
+}
+
 static int symbols_collect(struct object *obj)
 {
 	Elf_Scn *scn = NULL;
@@ -688,8 +807,9 @@ static int load_btf(struct object *obj)
 		if (err) {
 			pr_err("FAILED: load base BTF from %s: %s\n",
 			       obj->base_btf_path, strerror(-err));
-			goto out_err;
+			return err;
 		}
+		obj->base_btf = base_btf;
 	}
 
 	btf = btf__parse_split(obj->btf_path ?: obj->path, base_btf);
@@ -697,20 +817,12 @@ static int load_btf(struct object *obj)
 	if (err) {
 		pr_err("FAILED: load BTF from %s: %s\n",
 			obj->btf_path ?: obj->path, strerror(-err));
-		goto out_err;
+		return err;
 	}
 
-	obj->base_btf = base_btf;
 	obj->btf = btf;
 
 	return 0;
-
-out_err:
-	btf__free(base_btf);
-	btf__free(btf);
-	obj->base_btf = NULL;
-	obj->btf = NULL;
-	return err;
 }
 
 static int symbols_resolve(struct object *obj)
@@ -977,6 +1089,153 @@ static int dump_raw_btf(struct btf *btf, const char *out_path)
 	return 0;
 }
 
+static int patch_btf_link(struct object *obj, const struct btf_link *link)
+{
+	char section[128];
+	void *raw_btf_data = NULL;
+	size_t shdrstrndx, module_name_len;
+	int fd = -1, len, err = -1;
+	FILE *btf_file = NULL;
+	Elf_Scn *scn = NULL;
+	u32 raw_btf_size;
+	struct stat st;
+	Elf_Data *data;
+	GElf_Shdr sh;
+	char *name;
+	Elf *elf = NULL;
+	u8 *size;
+
+	if (stat(link->btf_path, &st)) {
+		err = -errno;
+		pr_err("FAILED to stat BTF file %s: %s\n",
+		       link->btf_path, strerror(errno));
+		return err;
+	}
+	if (!S_ISREG(st.st_mode) || st.st_size <= 0 || st.st_size > UINT_MAX) {
+		pr_err("FAILED: invalid BTF file size or type: %s\n", link->btf_path);
+		return -EINVAL;
+	}
+	raw_btf_size = st.st_size;
+	raw_btf_data = malloc(raw_btf_size);
+	if (!raw_btf_data) {
+		pr_err("FAILED to allocate %u bytes for BTF file %s\n",
+		       raw_btf_size, link->btf_path);
+		return -ENOMEM;
+	}
+	btf_file = fopen(link->btf_path, "rb");
+	if (!btf_file) {
+		err = -errno;
+		pr_err("FAILED to open BTF file %s: %s\n",
+		       link->btf_path, strerror(errno));
+		goto out;
+	}
+	if (fread(raw_btf_data, raw_btf_size, 1, btf_file) != 1) {
+		err = -EIO;
+		pr_err("FAILED to read BTF file %s\n", link->btf_path);
+		goto out;
+	}
+	fclose(btf_file);
+	btf_file = NULL;
+	if (obj->efile.elf_class == ELFCLASS32) {
+		module_name_len = BTF_LINK_MODULE_NAME_MAX - 4;
+	} else if (obj->efile.elf_class == ELFCLASS64) {
+		module_name_len = BTF_LINK_MODULE_NAME_MAX - 8;
+	} else {
+		err = -EINVAL;
+		pr_err("FAILED: unsupported ELF class %u in %s\n",
+		       obj->efile.elf_class, obj->path);
+		goto out;
+	}
+	if (strlen(link->module) >= module_name_len) {
+		err = -EINVAL;
+		pr_err("FAILED: module name too long for BTF link: %s\n", link->module);
+		goto out;
+	}
+	len = snprintf(section, sizeof(section), "%s.link", link->section);
+	if (len < 0 || len >= sizeof(section)) {
+		err = -ENAMETOOLONG;
+		pr_err("FAILED: BTF link section name too long: %s.link\n", link->section);
+		goto out;
+	}
+
+	fd = open(obj->path, O_RDWR);
+	if (fd < 0) {
+		err = -errno;
+		pr_err("FAILED to open %s: %s\n", obj->path, strerror(errno));
+		goto out;
+	}
+	elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
+	if (!elf) {
+		err = -EINVAL;
+		pr_err("FAILED to create ELF descriptor for %s: %s\n",
+		       obj->path, elf_errmsg(-1));
+		goto out;
+	}
+	elf_flagelf(elf, ELF_C_SET, ELF_F_LAYOUT);
+	if (elf_getshdrstrndx(elf, &shdrstrndx)) {
+		pr_err("FAILED to get section name index from %s: %s\n",
+		       obj->path, elf_errmsg(-1));
+		goto out;
+	}
+	while ((scn = elf_nextscn(elf, scn))) {
+		if (gelf_getshdr(scn, &sh) != &sh) {
+			pr_err("FAILED to get section header from %s: %s\n",
+			       obj->path, elf_errmsg(-1));
+			goto out;
+		}
+		name = elf_strptr(elf, shdrstrndx, sh.sh_name);
+		if (name && !strcmp(name, section))
+			break;
+	}
+	if (!scn) {
+		pr_err("FAILED: section %s not found in %s\n", section, obj->path);
+		goto out;
+	}
+	data = elf_getdata(scn, NULL);
+	if (sh.sh_type != SHT_PROGBITS || !data || !data->d_buf ||
+	    data->d_size != module_name_len +
+		BTF_SHA256_DIGEST_LENGTH + sizeof(u32)) {
+		pr_err("FAILED: section %s is not a writable BTF link\n", section);
+		goto out;
+	}
+	memset(data->d_buf, 0, data->d_size);
+	memcpy(data->d_buf, link->module, strlen(link->module) + 1);
+	btf_sha256(raw_btf_data, raw_btf_size,
+		   (u8 *)data->d_buf + module_name_len);
+	size = (u8 *)data->d_buf + module_name_len + BTF_SHA256_DIGEST_LENGTH;
+	if (obj->efile.encoding == ELFDATA2LSB) {
+		size[0] = raw_btf_size;
+		size[1] = raw_btf_size >> 8;
+		size[2] = raw_btf_size >> 16;
+		size[3] = raw_btf_size >> 24;
+	} else if (obj->efile.encoding == ELFDATA2MSB) {
+		size[0] = raw_btf_size >> 24;
+		size[1] = raw_btf_size >> 16;
+		size[2] = raw_btf_size >> 8;
+		size[3] = raw_btf_size;
+	} else {
+		pr_err("FAILED: unsupported ELF data encoding %u in %s\n",
+		       obj->efile.encoding, obj->path);
+		goto out;
+	}
+	elf_flagdata(data, ELF_C_SET, ELF_F_DIRTY);
+	if (elf_update(elf, ELF_C_WRITE) < 0) {
+		pr_err("FAILED to update ELF file %s: %s\n",
+		       obj->path, elf_errmsg(-1));
+		goto out;
+	}
+	err = 0;
+out:
+	if (elf)
+		elf_end(elf);
+	if (fd >= 0)
+		close(fd);
+	if (btf_file)
+		fclose(btf_file);
+	free(raw_btf_data);
+	return err;
+}
+
 static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, s32 type_id)
 {
 	const struct btf_type *t = btf__type_by_id(btf, type_id);
@@ -1510,6 +1769,84 @@ static int btf2btf(struct object *obj)
 	return err;
 }
 
+static bool keep_in_base_btf(struct object *obj, const struct btf_type *t)
+{
+	const char *name;
+
+	switch (btf_kind(t)) {
+	case BTF_KIND_FUNC:
+		name = btf__name_by_offset(obj->btf, t->name_off);
+		return !obj->efile.func_symbols_collected || has_func_symbol(obj, name) ||
+		       btf_id__find(&obj->funcs, name);
+	case BTF_KIND_FUNC_PROTO:
+	case BTF_KIND_LOC_PARAM:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
+		return false;
+	default:
+		/*
+		 * Ordinary types stay in base btf even if only inline records use them.
+		 * Should we relax this?
+		 */
+		return true;
+	}
+}
+
+/* Mark which types should go to .BTF.inline */
+static int color_btf(struct object *obj, __u8 *colors)
+{
+	struct btf *btf = obj->btf;
+	const struct btf *base = btf__base_btf(btf);
+	__u32 start_id = base ? btf__type_cnt(base) : 1;
+	__u32 type_cnt = btf__type_cnt(btf), i;
+	__u32 *worklist;
+
+	worklist = malloc((type_cnt - start_id ?: 1) * sizeof(*worklist));
+	if (!worklist)
+		return -ENOMEM;
+	/* First, mark all types reachable from LOC BTF entries. */
+	for (i = start_id; i < type_cnt; i++) {
+		const struct btf_type *t = btf__type_by_id(btf, i);
+
+		if (!btf_is_locsec(t) && !btf_is_loc_proto(t) && !btf_is_loc_param(t))
+			continue;
+		btf_mark_reachable(btf, i, BTF_COLOR_LOC, colors, worklist);
+	}
+	/* Next, traverse non-marked types converting some LOC markings to SHARED. */
+	for (i = start_id; i < type_cnt; i++) {
+		const struct btf_type *t = btf__type_by_id(btf, i);
+
+		if (colors[i] == BTF_COLOR_LOC && !keep_in_base_btf(obj, t))
+			continue;
+		btf_mark_reachable(btf, i, BTF_COLOR_MAIN, colors, worklist);
+	}
+	free(worklist);
+	return 0;
+}
+
+static int extract_inline_btf(struct object *obj)
+{
+	struct btf *btf = obj->btf, *main_btf, *inline_btf;
+	__u8 *colors;
+	int err;
+
+	colors = calloc(btf__type_cnt(btf), sizeof(*colors));
+	if (!colors)
+		return -ENOMEM;
+	err = color_btf(obj, colors);
+	if (err)
+		goto out;
+	err = btf_split_by_color(btf, colors, &main_btf, &inline_btf);
+	if (!err) {
+		obj->orig_btf = btf;
+		obj->btf = main_btf;
+		obj->inline_btf = inline_btf;
+	}
+out:
+	free(colors);
+	return err;
+}
+
 /*
  * Sort types by name in ascending order resulting in all
  * anonymous types being placed before named types.
@@ -1583,14 +1920,14 @@ static int finalize_btf(struct object *obj)
 	err = btf__dedup(obj->btf, NULL);
 	if (err) {
 		pr_err("FAILED to dedup BTF: %s\n", strerror(errno));
-		goto out_err;
+		return err;
 	}
 
 	if (obj->base_btf && obj->distill_base) {
 		err = btf__distill_base(obj->btf, &base_btf, &btf);
 		if (err) {
 			pr_err("FAILED to distill base BTF: %s\n", strerror(errno));
-			goto out_err;
+			return err;
 		}
 
 		btf__free(obj->base_btf);
@@ -1602,18 +1939,18 @@ static int finalize_btf(struct object *obj)
 	err = sort_btf_by_name(obj->btf);
 	if (err) {
 		pr_err("FAILED to sort BTF: %s\n", strerror(errno));
-		goto out_err;
+		return err;
 	}
 
-	return 0;
-
-out_err:
-	btf__free(base_btf);
-	btf__free(btf);
-	obj->base_btf = NULL;
-	obj->btf = NULL;
+	if (obj->extract_inline) {
+		err = extract_inline_btf(obj);
+		if (err) {
+			pr_err("FAILED to extract inline BTF: %s\n", strerror(-err));
+			return err;
+		}
+	}
 
-	return err;
+	return 0;
 }
 
 static inline int make_out_path(char *buf, u32 buf_sz, const char *in_path, const char *suffix)
@@ -1740,7 +2077,7 @@ static int patch_btfids(const char *btfids_path, const char *elf_path)
 
 static const char * const resolve_btfids_usage[] = {
 	"resolve_btfids [<options>] <ELF object>",
-	"resolve_btfids --patch_btfids <.BTF_ids file> <ELF object>",
+	"resolve_btfids --patch_btfids <.BTF_ids file> [--btf_link <section:module:btf-file>] <ELF object>",
 	NULL
 };
 
@@ -1758,6 +2095,7 @@ int main(int argc, const char **argv)
 		.sets     = RB_ROOT,
 	};
 	const char *btfids_path = NULL;
+	struct btf_links btf_links = {};
 	bool fatal_warnings = false;
 	bool resolve_btfids = true;
 	char out_path[PATH_MAX];
@@ -1773,6 +2111,10 @@ int main(int argc, const char **argv)
 			    "turn warnings into errors"),
 		OPT_BOOLEAN(0, "distill_base", &obj.distill_base,
 			    "distill --btf_base and emit .BTF.base section data"),
+		OPT_BOOLEAN(0, "inline", &obj.extract_inline,
+			    "extract location BTF into a .BTF.inline file"),
+		OPT_CALLBACK(0, "btf_link", &btf_links, "section:module:btf-file",
+			     "patch a BTF link with --patch_btfids", parse_btf_link),
 		OPT_STRING(0, "patch_btfids", &btfids_path, "file",
 			   "path to .BTF_ids section data blob to patch into ELF file"),
 		OPT_END()
@@ -1783,14 +2125,34 @@ int main(int argc, const char **argv)
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	if (argc != 1)
 		usage_with_options(resolve_btfids_usage, btfid_options);
+	if (btf_links.cnt && !btfids_path) {
+		pr_err("--btf_link requires --patch_btfids\n");
+		goto out;
+	}
 
 	obj.path = argv[0];
 
-	if (btfids_path)
-		return patch_btfids(btfids_path, obj.path);
+	if (btfids_path) {
+		err = patch_btfids(btfids_path, obj.path);
+		if (err || !btf_links.cnt)
+			goto out;
+		if (elf_collect(&obj)) {
+			err = -EINVAL;
+			goto out;
+		}
+		for (u32 i = 0; i < btf_links.cnt; i++) {
+			struct btf_link *link = &btf_links.links[i];
 
+			err = patch_btf_link(&obj, link);
+			if (err)
+				break;
+		}
+		goto out;
+	}
 	if (elf_collect(&obj))
 		goto out;
+	if (obj.extract_inline && collect_func_symbols(&obj))
+		goto out;
 
 	/*
 	 * We did not find .BTF_ids section or symbols section,
@@ -1841,18 +2203,33 @@ int main(int argc, const char **argv)
 		if (err)
 			goto out;
 	}
+	if (obj.inline_btf) {
+		err = make_out_path(out_path, sizeof(out_path), obj.path, BTF_ELF_SEC ".inline");
+		err = err ?: dump_raw_btf(obj.inline_btf, out_path);
+		if (err)
+			goto out;
+	}
 
 	if (!(fatal_warnings && warnings))
 		err = 0;
 out:
-	btf__free(obj.base_btf);
+	free_btf_links(&btf_links);
+	/*
+	 * Free BTFs in reverse dependency order.  inline_btf borrows obj.btf;
+	 * obj.btf can borrow a base owned by orig_btf or obj.base_btf, and
+	 * orig_btf can also borrow obj.base_btf.
+	 */
+	btf__free(obj.inline_btf);
 	btf__free(obj.btf);
+	btf__free(obj.orig_btf);
+	btf__free(obj.base_btf);
 	btf_id__free_all(&obj.structs);
 	btf_id__free_all(&obj.unions);
 	btf_id__free_all(&obj.typedefs);
 	btf_id__free_all(&obj.funcs);
 	btf_id__free_all(&obj.sets);
 	free(obj.addr_syms);
+	free(obj.efile.func_symbols);
 	if (obj.efile.elf) {
 		elf_end(obj.efile.elf);
 		close(obj.efile.fd);
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 512b3962f75f8..d2ff6f5d6d5b6 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -6640,7 +6640,7 @@ void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)
 
 int btf__relocate(struct btf *btf, const struct btf *base_btf)
 {
-	int err = btf_relocate(btf, base_btf, NULL);
+	int err = btf_relocate(btf, base_btf, NULL, NULL);
 
 	if (!err)
 		btf->owns_base = false;
diff --git a/tools/lib/bpf/btf_relocate.c b/tools/lib/bpf/btf_relocate.c
index df5fa4bd87d69..e55dd75f6c950 100644
--- a/tools/lib/bpf/btf_relocate.c
+++ b/tools/lib/bpf/btf_relocate.c
@@ -441,7 +441,8 @@ static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i)
 /* If successful, output of relocation is updated BTF with base BTF pointing
  * at base_btf, and type ids, strings adjusted accordingly.
  */
-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map)
+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,
+		 __u32 **str_map)
 {
 	unsigned int nr_types = btf__type_cnt(btf);
 	const struct btf_header *dist_base_hdr;
@@ -512,6 +513,10 @@ int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map)
 		*id_map = r.id_map;
 		r.id_map = NULL;
 	}
+	if (str_map) {
+		*str_map = r.str_map;
+		r.str_map = NULL;
+	}
 err_out:
 	free(r.id_map);
 	free(r.str_map);
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 546f65b95cf4d..4e45dfacb548a 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -249,7 +249,8 @@ const char *btf_kind_str(const struct btf_type *t);
 const struct btf_type *skip_mods_and_typedefs(const struct btf *btf, __u32 id, __u32 *res_id);
 const struct btf_header *btf_header(const struct btf *btf);
 void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);
-int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map);
+int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,
+		 __u32 **str_map);
 bool btf_type_is_traceable_func(const struct btf *btf, const struct btf_type *t);
 
 static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index a22be7efd1fa2..80d8bbbc3084a 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -343,7 +343,9 @@ else
 endif
 
 $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids	\
-		       $(TOOLSDIR)/bpf/resolve_btfids/main.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/main.c		\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.h	\
 		       $(TOOLSDIR)/lib/rbtree.c			\
 		       $(TOOLSDIR)/lib/zalloc.c			\
 		       $(TOOLSDIR)/lib/string.c			\
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_inline.c b/tools/testing/selftests/bpf/prog_tests/btf_inline.c
new file mode 100644
index 0000000000000..d88fab6429b1b
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/btf_inline.c
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026, Oracle and/or its affiliates. */
+
+#include <test_progs.h>
+#include <bpf/btf.h>
+#include <bpf/libbpf.h>
+
+#define BTF_SYSFS_DIR		"/sys/kernel/btf"
+#define BTF_INLINE_SUFFIX	".inline"
+
+/*
+ * For a specific inline site, verify we have the right function,
+ * loc proto and loc param representation and that the offset is
+ * reasonable given the caller where it was inlined.
+ */
+void test_btf_inline(void)
+{
+	struct btf *inline_btf = NULL, *btf = NULL, *vmlinux_btf = NULL;
+	const char *inline_caller = "bpf_testmod_test_write";
+	const char *inline_func = "testmod_inline_len";
+	unsigned long long caller_addr, base_addr;
+	bool skip = false, found_loc = false;
+	const struct btf_loc_param *lp;
+	int locsec_id, func_id, n, i;
+	const struct btf_type *t;
+	struct btf_loc *l;
+	const __u32 *p;
+	int err = 0;
+
+	if (!env.has_testmod) {
+		test__skip();
+		return;
+	}
+
+	base_addr = module_get_base_addr("bpf_testmod");
+	if (!ASSERT_NEQ(base_addr, 0, "base_addr_nonzero"))
+		return;
+
+	if (!ASSERT_OK(kallsyms_find(inline_caller, &caller_addr),
+		       "find_inline_caller"))
+		return;
+	if (!ASSERT_NEQ(caller_addr, 0, "caller_addr_nonzero"))
+		return;
+	if (!ASSERT_GT(caller_addr, base_addr, "caller_addr_gt_base_addr"))
+		return;
+	caller_addr -= base_addr;
+
+	vmlinux_btf = btf__load_vmlinux_btf();
+	if (!ASSERT_OK_PTR(vmlinux_btf, "vmlinux_btf"))
+		return;
+
+	btf = btf__parse_split(BTF_SYSFS_DIR "/bpf_testmod", vmlinux_btf);
+	if (!ASSERT_OK_PTR(btf, "bpf_testmod_btf"))
+		goto out;
+
+	inline_btf = btf__parse_split(BTF_SYSFS_DIR "/bpf_testmod" BTF_INLINE_SUFFIX,
+				      btf);
+	err = libbpf_get_error(inline_btf);
+	/* pahole may not have inline BTF feature support. */
+	if (err == -ENOENT) {
+		skip = true;
+		goto out;
+	}
+	if (!ASSERT_OK(err, "parse_inline_btf"))
+		goto out;
+	locsec_id = btf__find_by_name_kind(inline_btf, "inline.text", BTF_KIND_LOCSEC);
+	if (locsec_id < 0) {
+		skip = true;
+		goto out;
+	}
+	func_id = btf__find_by_name_kind(inline_btf, inline_func, BTF_KIND_FUNC);
+	if (!ASSERT_GT(func_id, 0, "inline_caller_func"))
+		goto out;
+	t = btf__type_by_id(inline_btf, locsec_id);
+	n = btf_vlen(t);
+	for (i = 0, l = btf_locsec_locs(t); i < n; i++, l++) {
+		if (l->func == func_id) {
+			found_loc = true;
+			break;
+		}
+	}
+	if (!ASSERT_TRUE(found_loc, "found_loc"))
+		goto out;
+	if (!ASSERT_GT(l->loc_proto, 0, "loc_proto_id"))
+		goto out;
+	if (!ASSERT_GT(l->offset, 0, "loc_offset"))
+		goto out;
+	t = btf__type_by_id(inline_btf, l->loc_proto);
+	if (!ASSERT_OK_PTR(t, "loc_proto_ptr"))
+		goto out;
+	if (!ASSERT_EQ(btf_vlen(t), 1, "loc_proto_one_param"))
+		goto out;
+	p = btf_loc_proto_params(t);
+	if (!ASSERT_GT(*p, 0, "loc_proto_has_loc_param"))
+		goto out;
+	t = btf__type_by_id(inline_btf, *p);
+	if (!ASSERT_OK_PTR(t, "loc_param_ptr"))
+		goto out;
+	lp = btf_loc_param(t);
+	if (!ASSERT_TRUE(lp->flags & BTF_LOC_PARAM_REG, "param_has_reg"))
+		goto out;
+	if (!ASSERT_GT(l->offset, caller_addr, "inline_gt_caller"))
+		goto out;
+	/* simple sanity test to roughly ensure inline site still in function */
+	if (!ASSERT_LT(l->offset, caller_addr + 512, "inline_in_caller"))
+		goto out;
+out:
+	btf__free(inline_btf);
+	btf__free(btf);
+	btf__free(vmlinux_btf);
+	if (skip)
+		test__skip();
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
index 3923e64c4c1d0..3fde8598189f4 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
@@ -3,15 +3,21 @@
 
 #include <test_progs.h>
 #include <bpf/btf.h>
+#include <dirent.h>
+#include <limits.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <unistd.h>
 
+#define BTF_SYSFS_DIR		"/sys/kernel/btf"
+#define BTF_INLINE_SUFFIX	".inline"
+
 static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 {
 	struct stat st;
 	__u64 btf_size, end;
+	size_t mmap_len = 0;
 	void *raw_data = NULL;
 	int fd = -1;
 	long page_size;
@@ -26,6 +32,7 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 
 	btf_size = st.st_size;
 	end = (btf_size + page_size - 1) / page_size * page_size;
+	mmap_len = btf_size;
 
 	fd = open(path, O_RDONLY);
 	if (!ASSERT_GE(fd, 0, "open_btf"))
@@ -39,11 +46,13 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 	if (!ASSERT_EQ(raw_data, MAP_FAILED, "mmap_btf_shared"))
 		goto cleanup;
 
-	raw_data = mmap(NULL, end + 1, PROT_READ, MAP_PRIVATE, fd, 0);
+	mmap_len = end + 1;
+	raw_data = mmap(NULL, mmap_len, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (!ASSERT_EQ(raw_data, MAP_FAILED, "mmap_btf_invalid_size"))
 		goto cleanup;
 
-	raw_data = mmap(NULL, end, PROT_READ, MAP_PRIVATE, fd, 0);
+	mmap_len = end;
+	raw_data = mmap(NULL, mmap_len, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (!ASSERT_OK_PTR(raw_data, "mmap_btf"))
 		goto cleanup;
 
@@ -70,12 +79,84 @@ static void test_btf_mmap_sysfs(const char *path, struct btf *base)
 cleanup:
 	btf__free(btf);
 	if (raw_data && raw_data != MAP_FAILED)
-		munmap(raw_data, btf_size);
+		munmap(raw_data, mmap_len);
 	if (fd >= 0)
 		close(fd);
 }
 
+static void test_btf_inline_sysfs_all(void)
+{
+	struct btf *vmlinux_btf;
+	struct dirent *dentry;
+	DIR *dir;
+	int err = 0;
+
+	dir = opendir(BTF_SYSFS_DIR);
+	if (!ASSERT_OK_PTR(dir, "open_btf_sysfs"))
+		return;
+
+	vmlinux_btf = btf__parse(BTF_SYSFS_DIR "/vmlinux", NULL);
+	if (!ASSERT_OK_PTR(vmlinux_btf, "parse_vmlinux_btf")) {
+		closedir(dir);
+		return;
+	}
+
+	while ((dentry = readdir(dir)) != NULL) {
+		struct btf *base_btf = NULL, *module_btf = NULL, *inline_btf = NULL;
+		char btf_path[PATH_MAX], inline_path[PATH_MAX];
+		struct stat st;
+
+		/* Skip ".", ".." and "foo.inline" */
+		if (strstr(dentry->d_name, "."))
+			continue;
+
+		if (strcmp(dentry->d_name, "vmlinux") == 0)
+			base_btf = vmlinux_btf;
+
+		if (snprintf(btf_path, sizeof(btf_path), "%s/%s",
+			     BTF_SYSFS_DIR, dentry->d_name) >= sizeof(btf_path) ||
+		    snprintf(inline_path, sizeof(inline_path), "%s/%s%s",
+			     BTF_SYSFS_DIR, dentry->d_name, BTF_INLINE_SUFFIX) >=
+			     sizeof(inline_path)) {
+			ASSERT_FAIL("BTF sysfs path is too long\n");
+			break;
+		}
+
+		if (!base_btf) {
+			module_btf = btf__parse_split(btf_path, vmlinux_btf);
+			err = libbpf_get_error(module_btf);
+			if (err) {
+				/* A module can be unloaded while its sysfs entry is iterated. */
+				if (err == -ENOENT)
+					continue;
+				ASSERT_OK(err, "parse_module_btf");
+				continue;
+			}
+			base_btf = module_btf;
+		}
+		if (stat(inline_path, &st)) {
+			err = errno;
+			if (err != ENOENT)
+				ASSERT_OK(err, "stat_inline_btf");
+			btf__free(module_btf);
+			continue;
+		}
+		if (base_btf == vmlinux_btf)
+			test_btf_mmap_sysfs(inline_path, base_btf);
+		inline_btf = btf__parse_split(inline_path, base_btf);
+		err = libbpf_get_error(inline_btf);
+		if (!err)
+			btf__free(inline_btf);
+		ASSERT_OK(err, "parse_inline_btf");
+		btf__free(module_btf);
+	}
+	closedir(dir);
+
+	btf__free(vmlinux_btf);
+}
+
 void test_btf_sysfs(void)
 {
 	test_btf_mmap_sysfs("/sys/kernel/btf/vmlinux", NULL);
+	test_btf_inline_sysfs_all();
 }
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 93847ca6293b4..b4f0af2aeca45 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -735,6 +735,13 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
 EXPORT_SYMBOL(bpf_testmod_test_read);
 ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO);
 
+static __always_inline size_t testmod_inline_len(size_t len)
+{
+	/* Keep an instruction in the inline site without changing len. */
+	asm volatile("" : "+m"(len));
+	return len;
+}
+
 noinline ssize_t
 bpf_testmod_test_write(struct file *file, struct kobject *kobj,
 		      const struct bin_attribute *bin_attr,
@@ -743,7 +750,7 @@ bpf_testmod_test_write(struct file *file, struct kobject *kobj,
 	struct bpf_testmod_test_write_ctx ctx = {
 		.buf = buf,
 		.off = off,
-		.len = len,
+		.len = testmod_inline_len(len),
 	};
 
 	trace_bpf_testmod_test_write_bare_tp(current, &ctx);
@@ -802,7 +809,7 @@ static struct testmod_uprobe uprobe = {
 	.consumer.ret_handler = uprobe_ret_handler,
 };
 
-static int testmod_register_uprobe(loff_t offset)
+static __always_inline int testmod_register_uprobe(loff_t offset)
 {
 	int err = -EBUSY;
 
diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 679008b310d9a..f3a1d627699da 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -244,6 +244,26 @@ int kallsyms_find(const char *sym, unsigned long long *addr)
 	return err;
 }
 
+unsigned long long module_get_base_addr(const char *module)
+{
+	unsigned long long addr, base_addr = 0;
+	char name[500];
+	FILE *f;
+
+	f = fopen("/proc/modules", "r");
+	if (!f)
+		return 0;
+
+	while (fscanf(f, "%499s %*s %*s %*s %*s 0x%llx", name, &addr) == 2) {
+		if (strcmp(module, name) == 0) {
+			base_addr = addr;
+			break;
+		}
+	}
+	fclose(f);
+	return base_addr;
+}
+
 #ifdef PROCMAP_QUERY
 int env_verbosity __weak = 0;
 
diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
index 01c8ecc456270..eb0d0d9804d6e 100644
--- a/tools/testing/selftests/bpf/trace_helpers.h
+++ b/tools/testing/selftests/bpf/trace_helpers.h
@@ -38,6 +38,7 @@ typedef int (*ksym_search_cmp_t)(const void *p1, const struct ksym *p2);
 int load_kallsyms(void);
 struct ksym *ksym_search(long key);
 long ksym_get_addr(const char *name);
+unsigned long long module_get_base_addr(const char *module);
 
 struct ksyms *load_kallsyms_local(void);
 struct ksym *ksym_search_local(struct ksyms *ksyms, long key);
diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile
index 2f423de831473..d1b65fd379118 100644
--- a/tools/testing/selftests/hid/Makefile
+++ b/tools/testing/selftests/hid/Makefile
@@ -148,6 +148,8 @@ endif
 
 $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids	\
 		       $(TOOLSDIR)/bpf/resolve_btfids/main.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.c	\
+		       $(TOOLSDIR)/bpf/resolve_btfids/btf_colors.h	\
 		       $(TOOLSDIR)/lib/rbtree.c			\
 		       $(TOOLSDIR)/lib/zalloc.c			\
 		       $(TOOLSDIR)/lib/string.c			\

35/3 2026/10/09 14:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33167
							output: 20
							thoughts: 3701
						

Thoughts:
**KMSAN Fuzzing Evaluation: Inline BTF Patch Series**

Okay, let's break down this patch series and determine if it warrants a dedicated KMSAN fuzzing session. My focus is on potential memory safety issues, specifically uninitialized memory reads or writes, that could be exploited. I'll need to scrutinize how this new "inline BTF" data is handled, especially when it interacts with user space and other kernel components.

First, I need to understand the data flow. This patch series introduces inline BTF (BTF - BPF Type Format) data, apparently for faster module loading and potentially better debugging information. The core changes involve:

*   Adding new sections (.BTF.inline, .BTF.inline.link) to the kernel image.
*   Introducing a new `btf_link` structure to manage inline BTF data.
*   New sysfs interfaces (`sysfs_btf_add`, `sysfs_btf_update`, `sysfs_btf_remove`) to expose and manage this data.
*   Changes in `module.h` and `main.c` to integrate inline BTF data into module loading/unloading.

My primary concern is around any data passed to user space. Specifically, my thought process will revolve around these things:

1.  **User-space exposure:** Where does this new `BTF` data get copied or mapped into user space? I need to track `copy_to_user`, `put_user`, netlink skb attributes, ioctl output arguments, socket options, or BPF buffers. Are all fields fully initialized? Any padding?
2.  **Conditional logic:** Does any conditional logic depend on the state of newly introduced structures or variables, especially before they're fully initialized?
3.  **Data structure initialization:** Are complex data structures initialized properly? Any chance of uninitialized memory being read later in reachable code paths?
4.  **Bounds and lengths:** Are there any bounds checks, lengths, or logic that could lead to reading beyond the allocated buffer when handling the inline BTF data?

Let's dive into the code. `kernel/bpf/sysfs_btf.c` seems like a good starting point since it's introducing sysfs interfaces.

Okay, here I see `btf_sysfs_read_lazy` and `btf_sysfs_mmap_lazy` which reads the data from sysfs. I need to understand the `data` pointer. It looks like `btf_sysfs_lazy_data` is used to get the data. It might be lazy-loaded by `request_module`, which might be a good thing, unless the module loading itself introduces issues. In the happy path, it gets the data from `attr->private`. Where is this `attr->private` populated?

Aha! `btf_module_handle_vmlinux_inline` in `btf.c` handles `vmlinux.inline` BTF. Here, the `data` comes from `mod->btf_inline_data`, which seems to be populated from the `.BTF.inline` section of a module. The `data` is allocated by `vmalloc_user`, and the data is copied by `memcpy`.

Crucially, `vmalloc_user` either zero-fills memory or it uses `GFP_ZERO` which means the entire allocated area is zeroed on allocation. This is good as it prevents uninitialized memory reads for the allocated pages. However, I need to check the bounds and sizes. `vmalloc_user` will allocate pages. But what if the data itself is smaller than a page?

`btf_sysfs_mmap_check` is called by `btf_sysfs_mmap_lazy`, and it does some checks. It verifies that `data` is page-aligned (which is good) and that the requested `vma` size is not larger than the allocated memory. It also checks for the `VM_WRITE | VM_EXEC | VM_MAYSHARE` flags, which is a good protection against misuse. The checks seem reasonable. The `remap_vmalloc_range` maps the allocated pages into user space, but this should be safe since the allocated memory is zeroed. `memory_read_from_buffer` reads up to `attr->size`.

Alright, I don't see any immediately obvious issues in `sysfs_btf.c`. But I need to continue to check the data origin.

Let's check `btf.c`, especially the `btf_parse_split` and `btf_rebase_inline`. `btf_parse_split` allocates memory by `kzalloc_obj` and `kvmemdup`. `kvmemdup` allocates memory by `


36/3 2026/10/09 14:11 tool grepper
0m Args:
{
  "Expression": "int btf_relocate"
}

Results:
{
  "Output": "include/linux/btf.h=610=void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\ninclude/linux/btf.h:611:int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids,\ninclude/linux/btf.h-612-\t\t __u32 **map_strs);\n--\ninclude/linux/btf.h=681=static inline void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\n--\ninclude/linux/btf.h-684-\ninclude/linux/btf.h:685:static inline int btf_relocate(void *log, struct btf *btf, const struct btf *base_btf,\ninclude/linux/btf.h-686-\t\t\t       __u32 **map_ids, __u32 **map_strs)\n--\ntools/lib/bpf/btf_relocate.c=58=struct btf_name_info {\n--\ntools/lib/bpf/btf_relocate.c-65-\ntools/lib/bpf/btf_relocate.c:66:static int btf_relocate_rewrite_type_id(struct btf_relocate *r, __u32 i)\ntools/lib/bpf/btf_relocate.c-67-{\n--\ntools/lib/bpf/btf_relocate.c=132=static int btf_mark_embedded_composite_type_ids(struct btf_relocate *r, __u32 i)\n--\ntools/lib/bpf/btf_relocate.c-183- */\ntools/lib/bpf/btf_relocate.c:184:static int btf_relocate_map_distilled_base(struct btf_relocate *r)\ntools/lib/bpf/btf_relocate.c-185-{\n--\ntools/lib/bpf/btf_relocate.c-382-/* distilled base should only have named int/float/enum/fwd/struct/union types. */\ntools/lib/bpf/btf_relocate.c:383:static int btf_relocate_validate_distilled_base(struct btf_relocate *r)\ntools/lib/bpf/btf_relocate.c-384-{\n--\ntools/lib/bpf/btf_relocate.c-411-\ntools/lib/bpf/btf_relocate.c:412:static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i)\ntools/lib/bpf/btf_relocate.c-413-{\n--\ntools/lib/bpf/btf_relocate.c-443- */\ntools/lib/bpf/btf_relocate.c:444:int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\ntools/lib/bpf/btf_relocate.c-445-\t\t __u32 **str_map)\n--\ntools/lib/bpf/libbpf_internal.h=251=void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\ntools/lib/bpf/libbpf_internal.h:252:int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\ntools/lib/bpf/libbpf_internal.h-253-\t\t __u32 **str_map);\n"
}

37/3 2026/10/09 14:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38870
							output: 30
							thoughts: 60
						

Thoughts:
Okay, let's dive into this.

**Tracing the Kernel's BTF Relocation**

Alright, my immediate thought is to pinpoint where the magic of `btf_relocate` is actually implemented within the kernel. My intuition leans toward the BPF subsystem, so let's check. Ah, it seems like `kernel/bpf/btf.c` holds the key – specifically, it calls `btf_relocate`. That's a good starting point. Now, to get a handle on all the relevant contexts, let's quickly grep for that function name within the `kernel/bpf/` directory. That should reveal all the call sites and related code within that area. This should give me a good lay of the land for where and how the relocation is actually happening.



38/3 2026/10/09 14:11 tool grepper
0m Args:
{
  "Expression": "btf_relocate",
  "PathPrefixes": [
    "kernel/bpf"
  ]
}

Results:
{
  "Output": "kernel/bpf/Makefile=66=obj-$(CONFIG_BPF_SYSCALL) += btf_iter.o\nkernel/bpf/Makefile:67:obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o\nkernel/bpf/Makefile-68-obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o\n--\nkernel/bpf/btf.c=6883=struct btf *btf_parse_vmlinux(void)\n--\nkernel/bpf/btf.c-6915- */\nkernel/bpf/btf.c:6916:__u32 btf_relocate_id(const struct btf *btf, __u32 id)\nkernel/bpf/btf.c-6917-{\n--\nkernel/bpf/btf.c=7041=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-7097-\tif (base_btf != vmlinux_btf) {\nkernel/bpf/btf.c:7098:\t\terr = btf_relocate(btf, vmlinux_btf, \u0026btf-\u003ebase_id_map,\nkernel/bpf/btf.c-7099-\t\t\t\t   \u0026module_str_map);\n--\nkernel/bpf/btf.c-7120-\t/*\nkernel/bpf/btf.c:7121:\t * With a distilled base, btf_relocate() replaces the base BTF and\nkernel/bpf/btf.c-7122-\t * rewrites string offsets. Check ordering only after that final BTF\n--\nkernel/bpf/btf.c=9669=static int btf_populate_kfunc_set(struct btf *btf, enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-9763-\tfor (i = set-\u003ecnt; i \u003c set-\u003ecnt + add_set-\u003ecnt; i++)\nkernel/bpf/btf.c:9764:\t\tset-\u003epairs[i].id = btf_relocate_id(btf, set-\u003epairs[i].id);\nkernel/bpf/btf.c-9765-\n--\nkernel/bpf/btf.c=9949=static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-9961-\tfor (i = 0; i \u003c kset-\u003eset-\u003ecnt; i++) {\nkernel/bpf/btf.c:9962:\t\tret = btf_check_kfunc_protos(btf, btf_relocate_id(btf, kset-\u003eset-\u003epairs[i].id),\nkernel/bpf/btf.c-9963-\t\t\t\t\t     kset-\u003eset-\u003epairs[i].flags);\n--\nkernel/bpf/btf.c=10018=static int btf_check_dtor_kfuncs(struct btf *btf, const struct btf_id_dtor_kfunc *dtors, u32 cnt)\n--\nkernel/bpf/btf.c-10025-\tfor (i = 0; i \u003c cnt; i++) {\nkernel/bpf/btf.c:10026:\t\tdtor_btf_id = btf_relocate_id(btf, dtors[i].kfunc_btf_id);\nkernel/bpf/btf.c-10027-\n--\nkernel/bpf/btf.c=10063=int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt,\n--\nkernel/bpf/btf.c-10121-\tfor (i = tab_cnt; i \u003c tab_cnt + add_cnt; i++) {\nkernel/bpf/btf.c:10122:\t\ttab-\u003edtors[i].btf_id = btf_relocate_id(btf, tab-\u003edtors[i].btf_id);\nkernel/bpf/btf.c:10123:\t\ttab-\u003edtors[i].kfunc_btf_id = btf_relocate_id(btf, tab-\u003edtors[i].kfunc_btf_id);\nkernel/bpf/btf.c-10124-\t}\n--\nkernel/bpf/btf_relocate.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/btf_relocate.c:2:#include \"../../tools/lib/bpf/btf_relocate.c\"\n"
}

39/3 2026/10/09 14:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40348
							output: 42
							thoughts: 434
						

Thoughts:
**Analyzing the BTF Relocation Logic**

Okay, so I'm looking at `kernel/bpf/btf_relocate.c`, and it's pulling in the relocation logic from `../../tools/lib/bpf/btf_relocate.c`. That's standard practice, nothing unexpected there. Now, the interesting part is this patch to `tools/lib/bpf/btf_relocate.c`. It's a fairly straightforward modification to the `btf_relocate` function.

I see they've added an `__u32 **str_map` parameter to `btf_relocate`. This is significant. It seems this `str_map` is intended to handle string offset adjustments during the BTF relocation process. The return of the `id_map` for remapping type IDs is already established; this addition points to a string table remapping, too, which is a key concept.

The code now also includes the following:
```c
	if (str_map) {
		*str_map = r.str_map;
		r.str_map = NULL;
	}
```
This strongly implies that `r.str_map` is being allocated somewhere within `btf_relocate` and that it will contain the string offset mappings, and is now being provided to the caller. Then it's cleared so it's not freed more than once.

My next step is to dive into the rest of the `btf_relocate.c` file to trace the allocation and initialization of `r.str_map`, understanding the how the string offset mapping is created. This will give me a complete understanding of how string offsets are handled during BTF relocation.



40/3 2026/10/09 14:11 tool read-file
0m Args:
{
  "File": "tools/lib/bpf/btf_relocate.c",
  "FirstLine": 440,
  "LineCount": 80
}

Results:
{
  "Contents": " 440:\t\n 441:\t/* If successful, output of relocation is updated BTF with base BTF pointing\n 442:\t * at base_btf, and type ids, strings adjusted accordingly.\n 443:\t */\n 444:\tint btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map,\n 445:\t\t\t __u32 **str_map)\n 446:\t{\n 447:\t\tunsigned int nr_types = btf__type_cnt(btf);\n 448:\t\tconst struct btf_header *dist_base_hdr;\n 449:\t\tconst struct btf_header *base_hdr;\n 450:\t\tstruct btf_relocate r = {};\n 451:\t\tint err = 0;\n 452:\t\t__u32 id, i;\n 453:\t\n 454:\t\tr.dist_base_btf = btf__base_btf(btf);\n 455:\t\tif (!base_btf || r.dist_base_btf == base_btf)\n 456:\t\t\treturn -EINVAL;\n 457:\t\n 458:\t\tr.nr_dist_base_types = btf__type_cnt(r.dist_base_btf);\n 459:\t\tr.nr_base_types = btf__type_cnt(base_btf);\n 460:\t\tr.nr_split_types = nr_types - r.nr_dist_base_types;\n 461:\t\tr.btf = btf;\n 462:\t\tr.base_btf = base_btf;\n 463:\t\n 464:\t\tr.id_map = calloc(nr_types, sizeof(*r.id_map));\n 465:\t\tr.str_map = calloc(btf_header(r.dist_base_btf)-\u003estr_len, sizeof(*r.str_map));\n 466:\t\tdist_base_hdr = btf_header(r.dist_base_btf);\n 467:\t\tbase_hdr = btf_header(r.base_btf);\n 468:\t\tr.dist_str_len = dist_base_hdr-\u003estr_len;\n 469:\t\tr.base_str_len = base_hdr-\u003estr_len;\n 470:\t\tif (!r.id_map || !r.str_map) {\n 471:\t\t\terr = -ENOMEM;\n 472:\t\t\tgoto err_out;\n 473:\t\t}\n 474:\t\n 475:\t\terr = btf_relocate_validate_distilled_base(\u0026r);\n 476:\t\tif (err)\n 477:\t\t\tgoto err_out;\n 478:\t\n 479:\t\t/* Split BTF ids need to be adjusted as base and distilled base\n 480:\t\t * have different numbers of types, changing the start id of split\n 481:\t\t * BTF.\n 482:\t\t */\n 483:\t\tfor (id = r.nr_dist_base_types; id \u003c nr_types; id++)\n 484:\t\t\tr.id_map[id] = id + r.nr_base_types - r.nr_dist_base_types;\n 485:\t\n 486:\t\t/* Build a map from distilled base ids to actual base BTF ids; it is used\n 487:\t\t * to update split BTF id references.  Also build a str_map mapping from\n 488:\t\t * distilled base BTF names to base BTF names.\n 489:\t\t */\n 490:\t\terr = btf_relocate_map_distilled_base(\u0026r);\n 491:\t\tif (err)\n 492:\t\t\tgoto err_out;\n 493:\t\n 494:\t\t/* Next, rewrite type ids in split BTF, replacing split ids with updated\n 495:\t\t * ids based on number of types in base BTF, and base ids with\n 496:\t\t * relocated ids from base_btf.\n 497:\t\t */\n 498:\t\tfor (i = 0, id = r.nr_dist_base_types; i \u003c r.nr_split_types; i++, id++) {\n 499:\t\t\terr = btf_relocate_rewrite_type_id(\u0026r, id);\n 500:\t\t\tif (err)\n 501:\t\t\t\tgoto err_out;\n 502:\t\t}\n 503:\t\t/* String offsets now need to be updated using the str_map. */\n 504:\t\tfor (i = 0; i \u003c r.nr_split_types; i++) {\n 505:\t\t\terr = btf_relocate_rewrite_strs(\u0026r, i + r.nr_dist_base_types);\n 506:\t\t\tif (err)\n 507:\t\t\t\tgoto err_out;\n 508:\t\t}\n 509:\t\t/* Finally reset base BTF to be base_btf */\n 510:\t\tbtf_set_base_btf(btf, base_btf);\n 511:\t\n 512:\t\tif (id_map) {\n 513:\t\t\t*id_map = r.id_map;\n 514:\t\t\tr.id_map = NULL;\n 515:\t\t}\n 516:\t\tif (str_map) {\n 517:\t\t\t*str_map = r.str_map;\n 518:\t\t\tr.str_map = NULL;\n 519:\t\t}\n"
}

41/3 2026/10/09 14:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42641
							output: 38
							thoughts: 75
						

Thoughts:
**Examining the Memory Allocation in Kernel BTF Relocation**

Okay, so I've spotted this interesting line: `r.str_map = calloc(...)`. In this kernel context, that's likely `calloc` or one of its kernel-specific equivalents like `kvcalloc` or `kzalloc`. That's the key. Now, as a follow up, I need to check exactly how `calloc` is defined and used within this specific module. Let's delve into `kernel/bpf/btf_relocate.c` to see how they've set it up, in this instance.



42/3 2026/10/09 14:11 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf_relocate.c",
  "FirstLine": 1,
  "LineCount": 40
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\n   2:\t#include \"../../tools/lib/bpf/btf_relocate.c\"\n"
}

43/3 2026/10/09 14:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42950
							output: 40
							thoughts: 51
						

Thoughts:
Okay, here's my thought process on this, presented as a first-person expert summary:

**Digging into a `calloc` Mystery in BTF Relocation**

Alright, I'm hitting a snag here. I see a `calloc` call during the compilation of `kernel/bpf/btf_relocate.c`, and that's immediately raising a red flag. I want to understand *exactly* where this function is being pulled from – specifically, when compiling code related to BTF relocation. I'm not seeing it at a high level.

My first instinct is to dig into the include files for `tools/lib/bpf/btf_relocate.c`. That's where I need to start, before I start looking in the deeper places. I need to trace this dependency and figure out which header is implicitly or explicitly declaring it, and which library it might be linking against. This includes looking for things that might be macro defined to `calloc`. That's the most likely source of the problem. Time to start tracing this path.



44/3 2026/10/09 14:11 tool read-file
0m Args:
{
  "File": "tools/lib/bpf/btf_relocate.c",
  "FirstLine": 1,
  "LineCount": 40
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\n   2:\t/* Copyright (c) 2024, Oracle and/or its affiliates. */\n   3:\t\n   4:\t#ifndef _GNU_SOURCE\n   5:\t#define _GNU_SOURCE\n   6:\t#endif\n   7:\t\n   8:\t#ifdef __KERNEL__\n   9:\t#include \u003clinux/bpf.h\u003e\n  10:\t#include \u003clinux/bsearch.h\u003e\n  11:\t#include \u003clinux/btf.h\u003e\n  12:\t#include \u003clinux/sort.h\u003e\n  13:\t#include \u003clinux/string.h\u003e\n  14:\t#include \u003clinux/bpf_verifier.h\u003e\n  15:\t\n  16:\t#define btf_type_by_id\t\t\t\t(struct btf_type *)btf_type_by_id\n  17:\t#define btf__type_cnt\t\t\t\tbtf_nr_types\n  18:\t#define btf__base_btf\t\t\t\tbtf_base_btf\n  19:\t#define btf__name_by_offset\t\t\tbtf_name_by_offset\n  20:\t#define btf__str_by_offset\t\t\tbtf_str_by_offset\n  21:\t#define btf_kflag\t\t\t\tbtf_type_kflag\n  22:\t\n  23:\t#define calloc(nmemb, sz)\t\t\tkvcalloc(nmemb, sz, GFP_KERNEL | __GFP_NOWARN)\n  24:\t#define free(ptr)\t\t\t\tkvfree(ptr)\n  25:\t#define qsort(base, num, sz, cmp)\t\tsort(base, num, sz, cmp, NULL)\n  26:\t\n  27:\t#else\n  28:\t\n  29:\t#include \"btf.h\"\n  30:\t#include \"bpf.h\"\n  31:\t#include \"libbpf.h\"\n  32:\t#include \"libbpf_internal.h\"\n  33:\t\n  34:\t#endif /* __KERNEL__ */\n  35:\t\n  36:\tstruct btf;\n  37:\t\n  38:\tstruct btf_relocate {\n  39:\t\tstruct btf *btf;\n  40:\t\tconst struct btf *base_btf;\n"
}

45/3 2026/10/09 14:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43884
							output: 24
							thoughts: 2242
						

Thoughts:
**Deep Dive into BTF Memory Management and Sysfs Interaction**

Okay, so I've been tracing through the BTF (BPF Type Format) code, specifically focusing on memory allocation and interaction with the sysfs filesystem. The initial observation is that `kvcalloc`, which is used throughout the kernel for zeroed memory allocation, is the counterpart to user space `calloc`, which is a neat detail.

In `btf_parse_module`, I see that `module_str_map` is allocated with `kvcalloc` and subsequently freed with `kvfree`, which makes sense for memory allocated within the kernel context.

The most interesting part is the `btf_link` structure which is seemingly patched by `resolve_btfids`. The presence of `__start_BTF_inline_link` and `__stop_BTF_inline_link` is intriguing, indicating that this is a section within the vmlinux ELF that's populated at build time, presumably with information needed to link BTF data, specifically about inline BTF data from modules. I can see this definition in `include/asm-generic/vmlinux.lds.h`.

Switching gears, I'm examining how BTF data is exposed via sysfs using `sysfs_btf_add`. The use of `kzalloc_obj` to allocate a `btf_sysfs_entry` is clear; all fields of this struct are either zeroed or initialized, ensuring that there are no uninitialized variables. This struct contains a `bin_attribute`, which is what gets registered in sysfs. And, based on whether the data is from a module, it is assigned a lazy or non-lazy version of reading/mmapping using `btf_sysfs_read_lazy` and `btf_sysfs_mmap_lazy`, and simple versions of `sysfs_bin_attr_simple_read` and `btf_sysfs_mmap_image`.

The `sysfs_btf_remove` function mirrors the allocation process by freeing `entry->module_name` and `attr->attr.name`, followed by freeing the `entry` itself, indicating a correct cleanup sequence. This function, in particular, leverages `container_of` to get a pointer to the enclosing `btf_sysfs_entry` from the `bin_attribute`.

Now, I've noticed a significant change in how things used to work in the code before a patch. Previously, the `sysfs_attr` field of `btf_mod` was a `bin_attribute` allocated with `kzalloc`. This now points to a `struct btf_sysfs_entry`. This `sysfs_btf_add` function now returns `&entry->attr`. This change seems to be clean, given the `sysfs_btf_remove` usage of the `container_of` macro.

Finally, `bin_attr_btf_vmlinux` is created at boot, so it's not being passed to `sysfs_btf_remove`.

My concern is the `buf` parameter in the sysfs bin_attribute read handler. Is that user space or kernel space? It's essential to know the contract and context of `bin_attribute.read` to ensure correct and safe data access. It needs to be carefully scrutinized for potential security vulnerabilities like buffer overflows or information leaks.



46/3 2026/10/09 14:11 tool grepper
0m Args:
{
  "Expression": "sysfs_bin_attr_simple_read"
}

Results:
{
  "Output": "arch/powerpc/platforms/powernv/opal.c=792=static int opal_add_one_export(struct kobject *parent, const char *export_name,\n--\narch/powerpc/platforms/powernv/opal.c-817-\tattr-\u003eattr.mode = 0400;\narch/powerpc/platforms/powernv/opal.c:818:\tattr-\u003eread = sysfs_bin_attr_simple_read;\narch/powerpc/platforms/powernv/opal.c-819-\tattr-\u003eprivate = __va(vals[0]);\n--\ndrivers/acpi/acpi_fpdt.c=139=static const struct attribute_group boot_attr_group = {\n--\ndrivers/acpi/acpi_fpdt.c-143-\ndrivers/acpi/acpi_fpdt.c:144:static BIN_ATTR(FBPT, 0400, sysfs_bin_attr_simple_read, NULL, 0);\ndrivers/acpi/acpi_fpdt.c:145:static BIN_ATTR(S3PT, 0400, sysfs_bin_attr_simple_read, NULL, 0);\ndrivers/acpi/acpi_fpdt.c-146-\n--\nfs/sysfs/file.c=794=EXPORT_SYMBOL_GPL(sysfs_emit_at);\n--\nfs/sysfs/file.c-796-/**\nfs/sysfs/file.c:797: *\tsysfs_bin_attr_simple_read - read callback to simply copy from memory.\nfs/sysfs/file.c-798- *\t@file:\tattribute file which is being read.\n--\nfs/sysfs/file.c-813- */\nfs/sysfs/file.c:814:ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj,\nfs/sysfs/file.c-815-\t\t\t\t   const struct bin_attribute *attr, char *buf,\n--\nfs/sysfs/file.c-820-}\nfs/sysfs/file.c:821:EXPORT_SYMBOL_GPL(sysfs_bin_attr_simple_read);\n--\ninclude/linux/sysfs.h=381=struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size)\n--\ninclude/linux/sysfs.h-383-#define __BIN_ATTR_SIMPLE_RO(_name, _mode)\t\t\t\t\\\ninclude/linux/sysfs.h:384:\t__BIN_ATTR(_name, _mode, sysfs_bin_attr_simple_read, NULL, 0)\ninclude/linux/sysfs.h-385-\n--\ninclude/linux/sysfs.h=497=int sysfs_emit_at(char *buf, int at, const char *fmt, ...);\ninclude/linux/sysfs.h-498-\ninclude/linux/sysfs.h:499:ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj,\ninclude/linux/sysfs.h-500-\t\t\t\t   const struct bin_attribute *attr, char *buf,\n--\ninclude/linux/sysfs.h=756=static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...)\n--\ninclude/linux/sysfs.h-760-\ninclude/linux/sysfs.h:761:static inline ssize_t sysfs_bin_attr_simple_read(struct file *file,\ninclude/linux/sysfs.h-762-\t\t\t\t\t\t struct kobject *kobj,\n--\ninit/initramfs.c=611=extern unsigned long __initramfs_size;\n--\ninit/initramfs.c-614-\ninit/initramfs.c:615:static BIN_ATTR(initrd, 0440, sysfs_bin_attr_simple_read, NULL, 0);\ninit/initramfs.c-616-\n--\nkernel/bpf/sysfs_btf.c=64=static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = {\nkernel/bpf/sysfs_btf.c-65-\t.attr = { .name = \"vmlinux\", .mode = 0444, },\nkernel/bpf/sysfs_btf.c:66:\t.read = sysfs_bin_attr_simple_read,\nkernel/bpf/sysfs_btf.c-67-\t.mmap = btf_sysfs_mmap_image,\n--\nkernel/bpf/sysfs_btf.c=119=struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,\n--\nkernel/bpf/sysfs_btf.c-134-\tattr-\u003eprivate = data;\nkernel/bpf/sysfs_btf.c:135:\tattr-\u003eread = lazy_module_name ? btf_sysfs_read_lazy : sysfs_bin_attr_simple_read;\nkernel/bpf/sysfs_btf.c-136-\tif (mmap)\n--\nkernel/module/sysfs.c=151=static int add_notes_attrs(struct module *mod, const struct load_info *info)\n--\nkernel/module/sysfs.c-191-\t\t\tnattr-\u003eprivate = (void *)info-\u003esechdrs[i].sh_addr;\nkernel/module/sysfs.c:192:\t\t\tnattr-\u003eread = sysfs_bin_attr_simple_read;\nkernel/module/sysfs.c-193-\t\t\t*(gattr++) = nattr++;\n"
}

47/3 2026/10/09 14:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48325
							output: 36
							thoughts: 27
						

Thoughts:
Okay, let's dive into this. Here's my thought process on the matter:

**Analyzing `sysfs_bin_attr_simple_read`**

Alright, my first step is to zero in on `sysfs_bin_attr_simple_read`. That's where I need to start. Specifically, I'm going to locate it within `fs/sysfs/file.c`. I need to get a clear picture of how this function operates within the SysFS file system. I'm looking for the nitty-gritty details. It’s important to see how it's implemented. Then, I can start to reason about its usage, potential issues, and optimization possibilities. Time to dig in.



48/3 2026/10/09 14:11 tool read-file
0m Args:
{
  "File": "fs/sysfs/file.c",
  "FirstLine": 813,
  "LineCount": 15
}

Results:
{
  "Contents": " 813:\t */\n 814:\tssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj,\n 815:\t\t\t\t\t   const struct bin_attribute *attr, char *buf,\n 816:\t\t\t\t\t   loff_t off, size_t count)\n 817:\t{\n 818:\t\tmemcpy(buf, attr-\u003eprivate + off, count);\n 819:\t\treturn count;\n 820:\t}\n 821:\tEXPORT_SYMBOL_GPL(sysfs_bin_attr_simple_read);\n"
}

49/3 2026/10/09 14:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48706
							output: 32
							thoughts: 1272
						

Thoughts:
**Analyzing BTF Lazy Loading in Sysfs**

Okay, so I'm looking at how the kernel handles reading BTF data through sysfs. I see that there are two primary methods, `sysfs_bin_attr_simple_read` and `btf_sysfs_read_lazy`, both of which are copying data into the `buf` provided by the sysfs read subsystem, which ultimately gets sent to userspace. The key difference here is the source of the data. `sysfs_bin_attr_simple_read` uses `attr->private`, while `btf_sysfs_read_lazy` uses `data` obtained through lazy loading.

My focus is on understanding the `data` source in `btf_sysfs_read_lazy` and its counterpart, `btf_sysfs_mmap_lazy`, especially in the context of lazy initialization. Let's trace it.

I see that `btf_vmlinux_inline_lazy_init` sets up the `vmlinux.inline` attribute. When a user reads from `/sys/kernel/btf/vmlinux.inline`, `btf_sysfs_read_lazy` is called, and that in turn calls `btf_sysfs_lazy_data`. Inside `btf_sysfs_lazy_data`, we find the critical bit: the module is requested if `attr->private` is null. So it's lazy-loaded.

So, if `data` is NULL, the kernel calls `request_module` with the module name. When that module loads, `btf_module_notify` gets involved. Crucially, I see that the function `btf_module_is_vmlinux_inline` checks if the module matches the expected name. If it's a match, `btf_module_handle_vmlinux_inline` is called.

Inside `btf_module_handle_vmlinux_inline`, a new buffer `data` is allocated using `vmalloc_user`. It then copies data using `memcpy`, but the data comes from `mod->btf_inline_data`. Importantly, after verification, `sysfs_btf_update` is called, which then sets `attr->private` to point to the new allocated `data`.

Back in `btf_sysfs_lazy_data`, the `data` is returned. So that makes sense. The key is in how `mod->btf_inline_data` is initialized.

Now, I need to check where `mod->btf_inline_data` comes from, the source of data that is copied. I see that in `kernel/module/main.c`, `mod->btf_inline_data` is set by reading the `.BTF.inline` section from the module's ELF file using `any_section_objs`. That seems critical. So `any_section_objs` reads the ELF section `.BTF.inline` from the loaded module. I should probably check how other BTF sections are handled too, to make sure this is consistent with the general pattern.



50/3 2026/10/09 14:12 tool grepper
0m Args:
{
  "Expression": "any_section_objs.*BTF",
  "PathPrefixes": [
    "kernel/module"
  ]
}

Results:
{
  "Output": "kernel/module/main.c=2670=static int find_module_sections(struct module *mod, struct load_info *info)\n--\nkernel/module/main.c-2721-#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/module/main.c:2722:\tmod-\u003ebtf_data = any_section_objs(info, \".BTF\", 1, \u0026mod-\u003ebtf_data_size);\nkernel/module/main.c:2723:\tmod-\u003ebtf_base_data = any_section_objs(info, \".BTF.base\", 1,\nkernel/module/main.c-2724-\t\t\t\t\t      \u0026mod-\u003ebtf_base_data_size);\n--\nkernel/module/main.c-2726-#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)\nkernel/module/main.c:2727:\tmod-\u003ebtf_inline_data = any_section_objs(info, \".BTF.inline\", 1,\nkernel/module/main.c-2728-\t\t\t\t\t\t\u0026mod-\u003ebtf_inline_data_size);\n"
}

51/3 2026/10/09 14:12 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50970
							output: 20
							thoughts: 2366
						

Thoughts:
**Analyzing BTF Inline Data and Potential Vulnerabilities**

Okay, so I'm digging into this BTF inline data stuff. It seems like it's handled pretty much the same way as `.BTF` and `.BTF.base` sections, which is expected. But the key question here is, what's going on with `vmlinux_inline_link`? I'm looking at `btf_parse_link`, making sure it's validated properly, especially given the `__start_BTF_inline_link` symbol defined in the linker script. Is there a potential for it to be uninitialized? It's crucial this section is properly populated by `resolve_btfids --btf_link`.

Now, the `btf_module_notify` function... This is where things get interesting.  Specifically, `relocated_inline_data` is used here and added to sysfs.  But I need to confirm the unloading flow to make sure there are no leaks or double-frees, because that screams use-after-free or a double-free issue, especially when dealing with kernel modules.  The code in `MODULE_STATE_GOING` looks like it *should* free the `btf_inline_data`.  However, is the `btf_mod` properly found?

Then there's `sysfs_btf_update`. If `vmlinux_inline_attr` has already been updated, the `cmpxchg` will fail. `btf_module_handle_vmlinux_inline` should handle the error correctly by freeing `data`, and return -EINVAL. But what happens if the module providing the `vmlinux` inline BTF unloads? Looking at `btf_module_is_vmlinux_inline`, it's clear the system does not create a `btf_mod` entry for the vmlinux inline data when a module is loaded. Thus, on unload, the data remains.  The `vmalloc_user` copy does not point to module memory.

Let's look more closely at `sysfs_btf_mmap_image`, and the `btf_sysfs_mmap_image` function.  It uses `__pa_symbol(data)`, which is the physical address of a symbol. This seems fine for built-in, statically linked data, as in the `.BTF` inline section (`btf_vmlinux_inline.c`), and it is PAGE_ALIGNED.

Finally, `btf_sysfs_mmap_lazy` is used for non-built-in modules, and `vmalloc_user` is used to allocate the memory. But here is the critical point: could uninitialized memory get exposed to user space when mmapped? I need to check the exact `vmalloc_user` implementation to confirm. However, `vmalloc_user` zero-fills the memory. This should be okay.

So, in summary, I've identified some potential issues related to memory management and module unloading, especially with the use of `vmalloc_user` and the handling of the inline BTF data, and will investigate how `btf_module_handle_vmlinux_inline` is executed when a module unloads, to be sure this is safe.



52/3 2026/10/09 14:12 tool grepper
0m Args:
{
  "Expression": "void \\*vmalloc_user"
}

Results:
{
  "Output": "include/linux/vmalloc.h=153=extern void *vzalloc_noprof(unsigned long size) __alloc_size(1);\n--\ninclude/linux/vmalloc.h-155-\ninclude/linux/vmalloc.h:156:extern void *vmalloc_user_noprof(unsigned long size) __alloc_size(1);\ninclude/linux/vmalloc.h-157-#define vmalloc_user(...)\talloc_hooks(vmalloc_user_noprof(__VA_ARGS__))\n--\nmm/nommu.c=142=static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)\n--\nmm/nommu.c-159-\nmm/nommu.c:160:void *vmalloc_user_noprof(unsigned long size)\nmm/nommu.c-161-{\n--\nmm/vmalloc.c=4246=EXPORT_SYMBOL(vzalloc_noprof);\n--\nmm/vmalloc.c-4256- */\nmm/vmalloc.c:4257:void *vmalloc_user_noprof(unsigned long size)\nmm/vmalloc.c-4258-{\n"
}

53/3 2026/10/09 14:12 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54372
							output: 35
							thoughts: 17
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `mm/vmalloc.c:4257`**

Alright, that's where we need to start. My immediate thought is, based on previous investigations, that's likely the hot spot related to some recent allocation issue we've been tracking. It's often the root of the vmalloc complexities. I'm mentally parsing that line number – 4257 in `vmalloc.c` – and bracing myself to encounter... well, it could be a number of things. Memory fragmentation? Perhaps an issue with the bookkeeping structures during large allocation requests? Maybe a subtle race condition in the slab allocator's interaction with vmalloc? Could be related to the architecture's page size. I'm expecting something in the realm of an edge case, a subtle interaction between different memory management subsystems, or possibly a poorly handled corner case in the error handling. Let's see what the code actually *says*. I'm going in with a critical eye, ready to cross-reference with the relevant kernel documentation and my mental model of the vmalloc region layout and allocation algorithms. Let's get to the bottom of this.



54/3 2026/10/09 14:12 tool read-file
0m Args:
{
  "File": "mm/vmalloc.c",
  "FirstLine": 4255,
  "LineCount": 15
}

Results:
{
  "Contents": "4255:\t * Return: pointer to the allocated memory or %NULL on error\n4256:\t */\n4257:\tvoid *vmalloc_user_noprof(unsigned long size)\n4258:\t{\n4259:\t\treturn __vmalloc_node_range_noprof(size, SHMLBA,  VMALLOC_START, VMALLOC_END,\n4260:\t\t\t\t\t    GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL,\n4261:\t\t\t\t\t    VM_USERMAP, NUMA_NO_NODE,\n4262:\t\t\t\t\t    __builtin_return_address(0));\n4263:\t}\n4264:\tEXPORT_SYMBOL(vmalloc_user_noprof);\n4265:\t\n4266:\t/**\n4267:\t * vmalloc_node - allocate memory on a specific node\n4268:\t * @size:\t  allocation size\n4269:\t * @node:\t  numa node\n"
}

55/3 2026/10/09 14:12 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54942
							output: 29
							thoughts: 7361
						

Thoughts:
**Deep Dive into BTF Data Handling and Potential Uninitialized Memory Issues**

Okay, I've thoroughly analyzed the code related to BTF (BPF Type Format) data, specifically focusing on potential vulnerabilities related to uninitialized memory or out-of-bounds reads. My primary concern was ensuring data integrity, especially given how BTF data can be accessed through sysfs and used in BPF operations.

Initially, I was worried about the padding and unused space in `vmalloc_user` potentially leading to uninitialized memory being exposed. However, `__GFP_ZERO` guarantees zeroed memory, eliminating that concern. The `btf_sysfs_mmap_image` function, which handles memory mapping for the BTF data, seemed like a crucial area. Examining `btf_sysfs_mmap_image` alongside the older `btf_sysfs_vmlinux_mmap` revealed that the relevant check is now done by `btf_sysfs_mmap_check`. This checks that the mapped data is valid before mapping the memory via `remap_pfn_range`.

The various callers of `sysfs_btf_add` need close scrutiny. I carefully traced how the `attr->private` field is populated, which is the data exposed through sysfs. It can be either the `.BTF` section (`__start_BTF`) or the `.BTF.inline` section (`__start_BTF_inline`).  The `.BTF.inline` section is particularly interesting because it contains BTF data that is relocated for each module.

I then followed the data flow through `btf_parse_split`, `btf_rebase_inline`, and `btf_module_notify`.  `btf_parse_split` allocates a `btf` structure with `kzalloc_obj`, which guarantees zero initialization, and then copies the BTF data using `kvmemdup`. This eliminates any concerns about uninitialized memory in the BTF data itself. In `btf_rebase_inline`, I reviewed how string offsets and type IDs are adjusted during relocation. There was a potential for an out-of-bounds access in string maps during rebase. I traced the allocation size of `module_str_map` which prevents out-of-bounds access, because a string offset is compared with the size of the allocated memory.

The `btf_verify_link` function was analyzed to confirm that it correctly uses the SHA256 digest, which has a size of 32 bytes, thus ensuring data integrity. I also examined the `struct btf_link`, which contains the SHA256 digest, and confirmed that it isn't copied to user space, eliminating a potential information leak.

I then thoroughly investigated the use of sysfs attributes, particularly in `sysfs_btf_add` and `sysfs_bin_attr_simple_read`. The data exposed to userspace is either the raw BTF data copied from the module ELF file or the relocated BTF data. The code uses `kzalloc_obj` and `kstrdup` to allocate zero-initialized memory and safely copies the data, preventing uninitialized memory from being exposed. I also verified that the name buffer used in `btf_module_notify` and `snprintf` is safe, thanks to the use of `snprintf` with `sizeof` and `kstrdup`.

I also focused on the `btf_set_base_btf` function, and validated that there were no integer overflows on the offsets that are being calculated.

Finally, I exhaustively analyzed `btf_parse_split` to ensure that it initializes the `btf` structure properly. I verified that this function, which replaces `btf_parse_module` as a helper function for both module and inline BTF, correctly handles resource allocation and deallocation to prevent memory leaks. I checked the error paths and ensure all resources are freed on error paths, and I also inspected the return value handling of `relocated_inline_data` to ensure that the BTF data is handled safely.

I also did a search of BPF syscall in `kernel/bpf/` to verify the inline BTF does not interact with BPF syscall, which would potentially create an exposure.

In summary, my analysis reveals a robust and careful handling of BTF data, with safeguards against uninitialized memory and out-of-bounds accesses. The use of zero-initialized allocations, data copying with explicit size checks, and secure sysfs attribute creation methods all contribute to this conclusion.



56/3 2026/10/09 14:13 tool grepper
0m Args:
{
  "Expression": "btf_inline",
  "PathPrefixes": [
    "kernel/bpf"
  ]
}

Results:
{
  "Output": "kernel/bpf/btf.c=9129=struct btf_module {\n--\nkernel/bpf/btf.c-9134-\tstruct bin_attribute *sysfs_inline_attr;\nkernel/bpf/btf.c:9135:\tvoid *btf_inline_data;\nkernel/bpf/btf.c-9136-\tint flags;\n--\nkernel/bpf/btf.c=9209=static int btf_module_handle_vmlinux_inline(const struct module *mod)\n--\nkernel/bpf/btf.c-9212-\nkernel/bpf/btf.c:9213:\tif (!mod-\u003ebtf_inline_data ||\nkernel/bpf/btf.c:9214:\t    mod-\u003ebtf_inline_data_size != vmlinux_inline_link-\u003ebtf_size)\nkernel/bpf/btf.c-9215-\t\treturn -EINVAL;\nkernel/bpf/btf.c-9216-\nkernel/bpf/btf.c:9217:\tdata = vmalloc_user(mod-\u003ebtf_inline_data_size);\nkernel/bpf/btf.c-9218-\tif (!data)\nkernel/bpf/btf.c-9219-\t\treturn -ENOMEM;\nkernel/bpf/btf.c:9220:\tmemcpy(data, mod-\u003ebtf_inline_data, mod-\u003ebtf_inline_data_size);\nkernel/bpf/btf.c-9221-\nkernel/bpf/btf.c:9222:\tif (!btf_verify_link(vmlinux_inline_link, mod, data, mod-\u003ebtf_inline_data_size) ||\nkernel/bpf/btf.c-9223-\t    !sysfs_btf_update(vmlinux_inline_attr, data)) {\n--\nkernel/bpf/btf.c=9248=static int btf_module_notify(struct notifier_block *nb, unsigned long op,\n--\nkernel/bpf/btf.c-9270-#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)\nkernel/bpf/btf.c:9271:\t\tif (mod-\u003ebtf_inline_data_size) {\nkernel/bpf/btf.c:9272:\t\t\tinline_data = mod-\u003ebtf_inline_data;\nkernel/bpf/btf.c:9273:\t\t\tinline_data_size = mod-\u003ebtf_inline_data_size;\nkernel/bpf/btf.c-9274-\t\t}\n--\nkernel/bpf/btf.c-9309-\t\tbtf_mod-\u003ebtf = btf;\nkernel/bpf/btf.c:9310:\t\tbtf_mod-\u003ebtf_inline_data = relocated_inline_data;\nkernel/bpf/btf.c-9311-\t\tlist_add(\u0026btf_mod-\u003elist, \u0026btf_modules);\n--\nkernel/bpf/btf.c-9328-\t\t\t\tkvfree(relocated_inline_data);\nkernel/bpf/btf.c:9329:\t\t\t\tbtf_mod-\u003ebtf_inline_data = NULL;\nkernel/bpf/btf.c-9330-\t\t\t\terr = 0;\n--\nkernel/bpf/btf.c-9368-\t\t\t\tsysfs_btf_remove(btf_mod-\u003esysfs_inline_attr);\nkernel/bpf/btf.c:9369:\t\t\tkvfree(btf_mod-\u003ebtf_inline_data);\nkernel/bpf/btf.c-9370-\t\t\tpurge_cand_cache(btf_mod-\u003ebtf);\n"
}

57/3 2026/10/09 14:13 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 64266
							output: 529
							thoughts: 1569
						

Thoughts:
**KMSAN Assessment: Inline BTF Sysfs Exposure**

Okay, let's break this down. My goal is to determine if these changes, specifically the inline BTF sysfs exposure, introduce any uninitialized memory risks that necessitate KMSAN testing.  From my understanding, inline BTF is only surfaced through sysfs files under `/sys/kernel/btf/` with the `.inline` suffix. It's not part of the standard BTF ID table, which is key to its isolation. The documentation itself emphasizes that this is about providing information.

First, let's clarify the purpose: This patch introduces the ability to generate information about inlined sites within the kernel's BTF data. These .BTF.inline sections are relative to the kernel or modules BTF data and are made accessible via sysfs with the ".inline" suffix. This includes linker section definitions, module notification handling for `.BTF.inline` sections, relocation of inline BTF IDs/strings, and lazy loading via sysfs for vmlinux inline BTF.

The critical distinction is between what KASAN and KMSAN catch. KASAN is my go-to for out-of-bounds accesses, use-after-free, double-free, and invalid frees. LOCKDEP is my buddy for locking bugs, and UBSAN for undefined behavior. KMSAN is specifically for reads of *uninitialized* memory, whether that's stack, heap, or page allocations, and kernel-to-user memory leaks. The rule is clear: KMSAN is expensive, and should only be used if there are risks KMSAN uniquely detects.

Now, let's systematically address potential issues:

1.  **Kernel to User Space:** The only exposure to userspace is through reading/mmaping the sysfs binary files.  I've checked the read operations:  `btf_sysfs_read_lazy` uses `memory_read_from_buffer` to copy data from a `vmalloc_user` allocated buffer (filled with `memcpy`).  For mmap, `btf_sysfs_mmap_lazy` uses `remap_vmalloc_range` on `vmalloc_user` memory (which is zeroed), and for the direct image mapping, `btf_sysfs_mmap_image` maps read-only page-aligned rodata. For module sysfs entries, `sysfs_bin_attr_simple_read` reads from `kvmemdup` data. The entry itself, `struct btf_sysfs_entry`, is allocated with `kzalloc_obj`, which *zeroes* all the fields. Thus, no uninitialized values are exposed to the user.

2.  **Conditional Logic/Branching:** There's no evidence of conditional logic or branching that relies on potentially uninitialized variables or struct fields.  All local variables and structure fields I've encountered are explicitly initialized.

3.  **Data Structure Allocation:** The `btf` structure in `btf_parse_split` and the `btf_sysfs_entry` structure in `sysfs_btf_add` are allocated with `kzalloc_obj`, which is a zeroed allocation. The `btf->data` field is allocated via `kvmemdup`. In the `btf_relocate` function, the maps are allocated by using calloc, which maps to `kvcalloc`, zeroing all the elements. The `data` in `btf_module_handle_vmlinux_inline` is allocated with `vmalloc_user` using `GFP_KERNEL | __GFP_ZERO`.

4.  **Bounds Checks:** There are bounds checks in `btf_rebase_inline`. These ensure that the indexing does not go out of bounds on `old_module_type_cnt`, `*id`, and `*str_off`. If there were a problem with the bounds checking, that would be an out-of-bounds access. The existing checks seem sound.

I've also quickly reviewed the related userspace tools (`tools/bpf/resolve_btfids/*`, `tools/testing/selftests/*`, and `scripts/*`) to confirm that they do not introduce risks.

**Conclusion:**  Based on this meticulous analysis, I'm confident there are no uninitialized memory risks here.  KASAN and other standard kernel bug detectors can catch any memory safety issues (out-of-bounds, use-after-free, etc.). Therefore, `NeedsKMSAN=false`. My reasoning is structured: explain the patch, data structure allocations/initialization, kernel-to-userspace transfers, and why KASAN versus KMSAN applies. Time to `set-results`.



58/3 2026/10/09 14:13 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series introduces support for inline BTF generation and sysfs exposure (/sys/kernel/btf/*.inline), adding parsing, relocation, and sysfs handling for .BTF.inline sections in vmlinux and loadable modules.\n\nHolistic analysis of memory initialization and user-space transfers shows:\n1. Memory Allocations:\n   - In `btf_parse_split()`, `struct btf` is allocated with `kzalloc_obj()`, ensuring all fields are zeroed, and `btf-\u003edata` is copied with `kvmemdup()`.\n   - In `sysfs_btf_add()`, `struct btf_sysfs_entry` is allocated with `kzalloc_obj()`.\n   - In `btf_relocate()`, the relocation maps (`id_map` and `str_map`) are allocated with `calloc()`, which maps to `kvcalloc()` in the kernel build, ensuring zero-initialization.\n   - In `btf_module_handle_vmlinux_inline()`, the buffer exposed to sysfs is allocated with `vmalloc_user()`, which explicitly zero-initializes all pages (`GFP_KERNEL | __GFP_ZERO`), preventing uninitialized slack bytes across page boundaries when mmapped.\n\n2. User-Space Exposure:\n   - Data is exposed only via sysfs binary attributes (`/sys/kernel/btf/*`). Reads use `sysfs_bin_attr_simple_read()` or `btf_sysfs_read_lazy()` using bounded copies from fully populated buffers.\n   - Mmaps use `remap_vmalloc_range()` on `vmalloc_user()` memory or `remap_pfn_range()` on dedicated, page-aligned image sections. No kernel struct padding or uninitialized memory is copied to user space.\n\n3. KASAN vs. KMSAN:\n   - Potential risks in the new relocation logic (such as buffer bounds or indexing into `module_str_map` / `module_id_map`) or lifecycle management of sysfs attributes during module unloading represent out-of-bounds accesses or use-after-free/double-free conditions, which are detectable by KASAN.\n   - No uninitialized memory reads or information leak hazards are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series introduces support for inline BTF generation and sysfs exposure (/sys/kernel/btf/*.inline), adding parsing, relocation, and sysfs handling for .BTF.inline sections in vmlinux and loadable modules.\n\nHolistic analysis of memory initialization and user-space transfers shows:\n1. Memory Allocations:\n   - In `btf_parse_split()`, `struct btf` is allocated with `kzalloc_obj()`, ensuring all fields are zeroed, and `btf-\u003edata` is copied with `kvmemdup()`.\n   - In `sysfs_btf_add()`, `struct btf_sysfs_entry` is allocated with `kzalloc_obj()`.\n   - In `btf_relocate()`, the relocation maps (`id_map` and `str_map`) are allocated with `calloc()`, which maps to `kvcalloc()` in the kernel build, ensuring zero-initialization.\n   - In `btf_module_handle_vmlinux_inline()`, the buffer exposed to sysfs is allocated with `vmalloc_user()`, which explicitly zero-initializes all pages (`GFP_KERNEL | __GFP_ZERO`), preventing uninitialized slack bytes across page boundaries when mmapped.\n\n2. User-Space Exposure:\n   - Data is exposed only via sysfs binary attributes (`/sys/kernel/btf/*`). Reads use `sysfs_bin_attr_simple_read()` or `btf_sysfs_read_lazy()` using bounded copies from fully populated buffers.\n   - Mmaps use `remap_vmalloc_range()` on `vmalloc_user()` memory or `remap_pfn_range()` on dedicated, page-aligned image sections. No kernel struct padding or uninitialized memory is copied to user space.\n\n3. KASAN vs. KMSAN:\n   - Potential risks in the new relocation logic (such as buffer bounds or indexing into `module_str_map` / `module_id_map`) or lifecycle management of sysfs attributes during module unloading represent out-of-bounds accesses or use-after-free/double-free conditions, which are detectable by KASAN.\n   - No uninitialized memory reads or information leak hazards are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)