AI Trajectory


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

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "btf_loc_param_check_meta",
    "btf_loc_proto_check_meta",
    "btf_loc_proto_resolve",
    "btf_locsec_check_meta",
    "btf_locsec_resolve",
    "btf_new_fd"
  ],
  "KMSANReasoning": "The patch series adds support for three new BTF kinds (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, BTF_KIND_LOCSEC) across documentation, UAPI, bpftool, libbpf, selftests, and the kernel BTF verifier (kernel/bpf/btf.c).\n\nKMSAN vs KASAN applicability analysis:\n1. Kernel memory allocation \u0026 initialization:\n   - When user space loads a BTF object via bpf(BPF_BTF_LOAD), the kernel allocates memory for the BTF object using kzalloc() and copies user-provided bytes directly into kvmalloc'd memory with copy_from_bpfptr().\n   - The validation routines added for the new BTF kinds (btf_loc_param_check_meta, btf_loc_proto_check_meta, btf_locsec_check_meta, and their resolution functions) strictly parse and inspect the already populated buffer.\n   - Verification checks size and boundary constraints (meta_left \u003e= meta_needed) before accessing any elements, protecting against out-of-bounds reads (which fall squarely under KASAN's domain).\n\n2. Kernel-to-user space information exposure:\n   - When retrieving BTF info via BPF_OBJ_GET_INFO_BY_FD, struct bpf_btf_info is cleared with memset(\u0026info, 0, sizeof(info)), and the BTF payload copied back to user space is simply the user-supplied (or module/vmlinux) BTF data buffer. No uninitialized struct padding or uninitialized heap/stack memory is copied to user space.\n\n3. Control flow and branching:\n   - All branching decisions in the new code evaluate well-defined struct fields populated from user data or verification state.\n   - The expanded struct btf_field_desc (m_offs[2]) and btf_field_iter in tools/lib/bpf/btf_iter.c (included in kernel/bpf/btf_iter.c for module BTF relocation) explicitly initialize all iterator fields upon btf_field_iter_init().\n\n4. Bug surface:\n   - Any bugs in metadata validation, index calculations, or type resolution are memory boundary/indexing or logic errors, which are either rejected cleanly by the BTF verifier or caught by standard bug detectors (KASAN for OOB reads/writes).\n   - There are no uninitialized memory reads or information leaks introduced or exposed by these changes.\n\nTherefore, dedicated KMSAN fuzzing is not warranted (NeedsKMSAN=false).",
  "NeedsKMSAN": false,
  "Reasoning": "The patch introduces support for new BTF types (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, and BTF_KIND_LOCSEC) in the BPF subsystem, adding metadata validation, logging, and type resolution logic in kernel/bpf/btf.c. This code is directly reachable by user space via the BPF_BTF_LOAD command of the bpf() system call. Fuzzing is warranted to test bounds checking, type resolution, and validation of malformed BTF data.",
  "WorthFuzzing": true
}

1/1 2026/09/17 18:48 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 63a3bf6e1b250d9153a70283b74731c455e0fbc1\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Thu Sep 17 18:48:12 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst\nindex 004aa1058d857..70ab6ad608ae5 100644\n--- a/Documentation/bpf/btf.rst\n+++ b/Documentation/bpf/btf.rst\n@@ -88,6 +88,9 @@ sequentially and type id is assigned to each recognized type starting from id\n     #define BTF_KIND_DECL_TAG       17      /* Decl Tag     */\n     #define BTF_KIND_TYPE_TAG       18      /* Type Tag     */\n     #define BTF_KIND_ENUM64         19      /* Enumeration up to 64-bit values */\n+    #define BTF_KIND_LOC_PARAM      20      /* Location description (register, const etc) */\n+    #define BTF_KIND_LOC_PROTO      21      /* Set of location parameters for site */\n+    #define BTF_KIND_LOCSEC         22      /* Section with site descriptions */\n \n Note that the type section encodes debug info, not just pure types.\n ``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram.\n@@ -104,11 +107,13 @@ Each type contains the following common data::\n          *             decl_tag and type_tag\n          */\n         __u32 info;\n-        /* \"size\" is used by INT, ENUM, STRUCT, UNION and ENUM64.\n+        /* \"size\" is used by INT, ENUM, STRUCT, UNION, ENUM64 and\n+         * LOC_PARAM.\n          * \"size\" tells the size of the type it is describing.\n          *\n          * \"type\" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,\n-         * FUNC, FUNC_PROTO, DECL_TAG and TYPE_TAG.\n+         * FUNC, FUNC_PROTO, DECL_TAG and TYPE_TAG. It is unused by\n+         * LOC_PROTO and LOCSEC.\n          * \"type\" is a type_id referring to another type.\n          */\n         union {\n@@ -563,6 +568,77 @@ The ``btf_enum64`` encoding:\n If the original enum value is signed and the size is less than 8,\n that value will be sign extended into 8 bytes.\n \n+2.2.20 BTF_KIND_LOC_PARAM\n+~~~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+``struct btf_type`` encoding requirement:\n+  * ``name_off``: 0\n+  * ``info.kind_flag``: 0\n+  * ``info.kind``: BTF_KIND_LOC_PARAM\n+  * ``info.vlen``: number of 32-bit location value words\n+  * ``size``: size in bytes of the represented parameter: 1, 2, 4, 8 or 16\n+\n+``btf_type`` is followed by a ``struct btf_loc_param`` and ``info.vlen``\n+number of 32-bit value words.::\n+\n+    struct btf_loc_param {\n+        __u32 flags;\n+        __u32 values[];\n+    };\n+\n+The ``flags`` field describes how to interpret ``values``:\n+\n+  * ``BTF_LOC_PARAM_CONST`` describes a constant; the value is stored in\n+    low-word, high-word order when it requires 64 bits.\n+  * ``BTF_LOC_PARAM_ADDR | BTF_LOC_PARAM_CONST`` describes an address to be\n+    normalized relative to the kernel or module base address.\n+  * ``BTF_LOC_PARAM_REG`` with one word describes a register number; with two\n+    words it describes a multi-register parameter.\n+  * ``BTF_LOC_PARAM_REG | BTF_LOC_PARAM_OFFSET`` describes an address held in\n+    a register plus an offset. Adding ``BTF_LOC_PARAM_DEREF`` dereferences\n+    that address. ``BTF_LOC_PARAM_REG | BTF_LOC_PARAM_DEREF`` with one word\n+    dereferences the value held in the register.\n+  * ``BTF_LOC_PARAM_SIGNED`` makes a constant or offset signed.\n+\n+2.2.21 BTF_KIND_LOC_PROTO\n+~~~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+``struct btf_type`` encoding requirement:\n+  * ``name_off``: 0\n+  * ``info.kind_flag``: 0\n+  * ``info.kind``: BTF_KIND_LOC_PROTO\n+  * ``info.vlen``: number of function parameter locations\n+  * ``type``: 0\n+\n+``btf_type`` is followed by ``info.vlen`` number of ``__u32`` BTF type IDs.\n+Each entry corresponds to a function parameter at an inline site. An entry is\n+either 0, meaning that no location information is available, or the type ID\n+of a ``BTF_KIND_LOC_PARAM``.\n+\n+2.2.22 BTF_KIND_LOCSEC\n+~~~~~~~~~~~~~~~~~~~~~~\n+\n+``struct btf_type`` encoding requirement:\n+  * ``name_off``: offset to a valid ELF section name\n+  * ``info.kind_flag``: 0\n+  * ``info.kind``: BTF_KIND_LOCSEC\n+  * ``info.vlen``: number of inline sites in the section\n+  * ``type``: 0\n+\n+``btf_type`` is followed by ``info.vlen`` number of ``struct btf_loc``.::\n+\n+    struct btf_loc {\n+        __u32 func;\n+        __u32 loc_proto;\n+        __u32 offset;\n+    };\n+\n+The ``func`` field is the non-zero type ID of the ``BTF_KIND_FUNC`` being\n+described. ``loc_proto`` is the non-zero type ID of the associated\n+``BTF_KIND_LOC_PROTO``. ``offset`` is the location address offset relative to\n+the kernel or module base address. A LOCSEC named ``inline.text``, for example,\n+contains inline-site records for the ``.text`` section.\n+\n 2.3 Constant Values\n -------------------\n \ndiff --git a/include/linux/btf.h b/include/linux/btf.h\nindex ddd0f4f32d24b..f29ed358b7a8c 100644\n--- a/include/linux/btf.h\n+++ b/include/linux/btf.h\n@@ -261,6 +261,11 @@ const char *btf_type_str(const struct btf_type *t);\n \t     i \u003c btf_type_vlen(datasec_type);\t\t\t\\\n \t     i++, member++)\n \n+#define for_each_loc(i, locsec_type, member)\t\t\t\\\n+\tfor (i = 0, member = btf_type_loc_secinfo(locsec_type);\t\\\n+\t     i \u003c btf_type_vlen(locsec_type);\t\t\t\\\n+\t     i++, member++)\n+\n static inline bool btf_type_is_ptr(const struct btf_type *t)\n {\n \treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_PTR;\n@@ -329,6 +334,21 @@ static inline u64 btf_enum64_value(const struct btf_enum64 *e)\n \treturn ((u64)e-\u003eval_hi32 \u003c\u003c 32) | e-\u003eval_lo32;\n }\n \n+static inline struct btf_loc_param *btf_loc_param(const struct btf_type *t)\n+{\n+\treturn (struct btf_loc_param *)(t + 1);\n+}\n+\n+static inline __u32 *btf_loc_proto_params(const struct btf_type *t)\n+{\n+\treturn (__u32 *)(t + 1);\n+}\n+\n+static inline struct btf_loc *btf_type_loc_secinfo(const struct btf_type *t)\n+{\n+\treturn (struct btf_loc *)(t + 1);\n+}\n+\n static inline bool btf_is_composite(const struct btf_type *t)\n {\n \tu16 kind = btf_kind(t);\n@@ -559,7 +579,7 @@ struct btf_field_desc {\n \t/* member struct size, or zero, if no members */\n \tint m_sz;\n \t/* repeated per-member offsets */\n-\tint m_off_cnt, m_offs[1];\n+\tint m_off_cnt, m_offs[2];\n };\n \n struct btf_field_iter {\ndiff --git a/include/uapi/linux/btf.h b/include/uapi/linux/btf.h\nindex 618167cab4e61..a85d293f4127f 100644\n--- a/include/uapi/linux/btf.h\n+++ b/include/uapi/linux/btf.h\n@@ -92,7 +92,9 @@ enum {\n \tBTF_KIND_DECL_TAG\t= 17,\t/* Decl Tag */\n \tBTF_KIND_TYPE_TAG\t= 18,\t/* Type Tag */\n \tBTF_KIND_ENUM64\t\t= 19,\t/* Enumeration up to 64-bit values */\n-\n+\tBTF_KIND_LOC_PARAM\t= 20,\t/* Location parameter information */\n+\tBTF_KIND_LOC_PROTO\t= 21,\t/* Location prototype for site */\n+\tBTF_KIND_LOCSEC\t\t= 22,\t/* Location section */\n \tNR_BTF_KINDS,\n \tBTF_KIND_MAX\t\t= NR_BTF_KINDS - 1,\n };\n@@ -212,4 +214,65 @@ struct btf_enum64 {\n \t__u32\tval_hi32;\n };\n \n+/*\n+ * BTF_KIND_LOC_PARAM is followed by a single \"struct btf_loc_param\"\n+ * that contains flags specifying the contents of the vlen-specified\n+ * number of 4-byte values that follow.\n+ */\n+struct btf_loc_param {\n+\t__u32 flags;\n+\t__u32 values[];\n+};\n+\n+/*\n+ * The combination of size, vlen and flags gives us the means to interpret\n+ * the following vlen-specified set of 4-byte values:\n+ *\n+ * - a BTF_LOC_PARAM_CONST is a constant value; combination\n+ *   of size, vlen and _SIGNED flag determines it. If the value requires\n+ *   64 bits it is stored in {lo,hi} order.\n+ * - a BTF_LOC_PARAM_ADDR|BTF_LOC_PARAM_CONST is an address that should be\n+ *   normalized with respect to kernel/module base address.\n+ * - a BTF_LOC_PARAM_REG with vlen 1 is a simple register number;\n+ *   with vlen 2 it is a multi-register parameter.\n+ * - a _REG | OFFSET describes an address without dereferencing it.\n+ * - a _REG | DEREF with vlen 1 dereferences the value in the register\n+ *   number specified.\n+ * - a REG | DEREF | OFFSET with vlen specifies the register value in\n+ *   the first 4-byte value and the offset in the remainder.\n+ */\n+enum btf_loc_param_flags {\n+\tBTF_LOC_PARAM_SIGNED\t\t=\t0x1,\n+\tBTF_LOC_PARAM_CONST\t\t=\t0x2,\n+\tBTF_LOC_PARAM_ADDR\t\t=\t0x4,\n+\tBTF_LOC_PARAM_REG\t\t=\t0x8,\n+\tBTF_LOC_PARAM_DEREF\t\t=\t0x10,\n+\tBTF_LOC_PARAM_OFFSET\t\t=\t0x20,\n+};\n+\n+/*\n+ * BTF_KIND_LOC_PROTO specifies location prototypes; i.e. how locations relate\n+ * to parameters; a struct btf_type of BTF_KIND_LOC_PROTO is followed by a\n+ * vlen-specified number of __u32 BTF type ids which specify the associated\n+ * BTF_KIND_LOC_PARAM for each function parameter associated with the\n+ * location.  The type should either be 0 (no location info) or point at\n+ * a BTF_KIND_LOC_PARAM.\n+ */\n+\n+/*\n+ * BTF_KIND_LOCSEC consists of vlen-specified number of \"struct btf_loc\"\n+ * containing location site-specific information for a specific ELF section;\n+ * for example locations in \".text\" are in a LOCSEC named \"inline.text\".\n+ *\n+ * - function (func)\n+ * - location prototype type id (loc_proto)\n+ * - address offset (offset) relative to kernel base address\n+ */\n+\n+struct btf_loc {\n+\t__u32 func;\n+\t__u32 loc_proto;\n+\t__u32 offset;\n+};\n+\n #endif /* _UAPI__LINUX_BTF_H__ */\ndiff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c\nindex 7daf4c286c9b2..af5f161b5bddc 100644\n--- a/kernel/bpf/btf.c\n+++ b/kernel/bpf/btf.c\n@@ -345,6 +345,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {\n \t[BTF_KIND_DECL_TAG]\t= \"DECL_TAG\",\n \t[BTF_KIND_TYPE_TAG]\t= \"TYPE_TAG\",\n \t[BTF_KIND_ENUM64]\t= \"ENUM64\",\n+\t[BTF_KIND_LOC_PARAM]\t= \"LOC_PARAM\",\n+\t[BTF_KIND_LOC_PROTO]\t= \"LOC_PROTO\",\n+\t[BTF_KIND_LOCSEC]\t= \"LOCSEC\",\n };\n \n const char *btf_type_str(const struct btf_type *t)\n@@ -517,11 +520,27 @@ static bool btf_type_is_decl_tag(const struct btf_type *t)\n \treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_DECL_TAG;\n }\n \n+static bool btf_type_is_loc_param(const struct btf_type *t)\n+{\n+\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_LOC_PARAM;\n+}\n+\n+static bool btf_type_is_loc_proto(const struct btf_type *t)\n+{\n+\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_LOC_PROTO;\n+}\n+\n+static bool btf_type_is_locsec(const struct btf_type *t)\n+{\n+\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_LOCSEC;\n+}\n+\n static bool btf_type_nosize(const struct btf_type *t)\n {\n \treturn btf_type_is_void(t) || btf_type_is_fwd(t) ||\n \t       btf_type_is_func(t) || btf_type_is_func_proto(t) ||\n-\t       btf_type_is_decl_tag(t);\n+\t       btf_type_is_decl_tag(t) || btf_type_is_loc_param(t) ||\n+\t       btf_type_is_loc_proto(t) || btf_type_is_locsec(t);\n }\n \n static bool btf_type_nosize_or_null(const struct btf_type *t)\n@@ -796,7 +815,9 @@ static bool btf_type_needs_resolve(const struct btf_type *t)\n \t       btf_type_is_var(t) ||\n \t       btf_type_is_func(t) ||\n \t       btf_type_is_decl_tag(t) ||\n-\t       btf_type_is_datasec(t);\n+\t       btf_type_is_datasec(t) ||\n+\t       btf_type_is_loc_proto(t) ||\n+\t       btf_type_is_locsec(t);\n }\n \n /* t-\u003esize can be used */\n@@ -4729,6 +4750,279 @@ static const struct btf_kind_operations enum64_ops = {\n \t.show = btf_enum64_show,\n };\n \n+static s32 btf_loc_param_check_meta(struct btf_verifier_env *env,\n+\t\t\t\t    const struct btf_type *t,\n+\t\t\t\t    u32 meta_left)\n+{\n+\tconst struct btf_loc_param *p = btf_loc_param(t);\n+\tu32 size, meta_needed, vlen = btf_vlen(t);\n+\n+\tmeta_needed = sizeof(*p) + sizeof(__u32) * vlen;\n+\tif (meta_left \u003c meta_needed) {\n+\t\tbtf_verifier_log_basic(env, t,\n+\t\t\t\t       \"meta_left:%u meta_needed:%u\",\n+\t\t\t\t      meta_left, meta_needed);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (t-\u003ename_off) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid name\");\n+\t\treturn -EINVAL;\n+\t}\n+\tsize = t-\u003esize;\n+\tif (size \u003e 16 || !is_power_of_2(size)) {\n+\t\tbtf_verifier_log_type(env, t, \"Unexpected size\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (btf_type_kflag(t)) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid btf_info kind_flag\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tbtf_verifier_log_type(env, t, NULL);\n+\n+\treturn meta_needed;\n+}\n+\n+static void btf_loc_param_log(struct btf_verifier_env *env,\n+\t\t\t const struct btf_type *t)\n+{\n+\tconst struct btf_loc_param *p = btf_loc_param(t);\n+\tu32 i, vlen = btf_vlen(t);\n+\n+\tbtf_verifier_log(env, \"size=%u vlen=%u flags=0x%x\", t-\u003esize, vlen, p-\u003eflags);\n+\tfor (i = 0; i \u003c vlen; i++)\n+\t\tbtf_verifier_log(env, \", %u\", p-\u003evalues[i]);\n+}\n+\n+static const struct btf_kind_operations loc_param_ops = {\n+\t.check_meta = btf_loc_param_check_meta,\n+\t.resolve = btf_df_resolve,\n+\t.check_member = btf_df_check_member,\n+\t.check_kflag_member = btf_df_check_kflag_member,\n+\t.log_details = btf_loc_param_log,\n+\t.show = btf_df_show,\n+};\n+\n+static s32 btf_loc_proto_check_meta(struct btf_verifier_env *env,\n+\t\t\t\t    const struct btf_type *t,\n+\t\t\t\t    u32 meta_left)\n+{\n+\tu32 meta_needed;\n+\n+\tmeta_needed = sizeof(__u32) * btf_type_vlen(t);\n+\n+\tif (meta_left \u003c meta_needed) {\n+\t\tbtf_verifier_log_basic(env, t,\n+\t\t\t\t       \"meta_left:%u meta_needed:%u\",\n+\t\t\t\t      meta_left, meta_needed);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (t-\u003ename_off) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid name\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (btf_type_kflag(t)) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid btf_info kind_flag\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tbtf_verifier_log_type(env, t, NULL);\n+\n+\treturn meta_needed;\n+}\n+\n+static void btf_loc_proto_log(struct btf_verifier_env *env,\n+\t\t\t      const struct btf_type *t)\n+{\n+\tconst __u32 *params = btf_loc_proto_params(t);\n+\tu32 i, nr_params = btf_type_vlen(t);\n+\n+\tbtf_verifier_log(env, \"vlen=%u\", nr_params);\n+\tfor (i = 0; i \u003c nr_params; i++, params++)\n+\t\tbtf_verifier_log(env, \", %u\", *params);\n+}\n+\n+static int btf_loc_proto_resolve(struct btf_verifier_env *env,\n+\t\t\t\t const struct resolve_vertex *v)\n+{\n+\tconst struct btf_type *t = v-\u003et;\n+\tconst __u32 *params = btf_loc_proto_params(t);\n+\tu32 i, nr_params = btf_type_vlen(t);\n+\tstruct btf *btf = env-\u003ebtf;\n+\n+\tif (t-\u003etype) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid loc_proto type\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tfor (i = 0; i \u003c nr_params; i++) {\n+\t\tconst struct btf_type *param_type;\n+\t\tu32 param_type_id = params[i];\n+\n+\t\tif (!param_type_id)\n+\t\t\tcontinue;\n+\n+\t\tparam_type = btf_type_by_id(btf, param_type_id);\n+\t\tif (!param_type || !btf_type_is_loc_param(param_type)) {\n+\t\t\tbtf_verifier_log_type(env, t,\n+\t\t\t\t\t      \"Invalid loc_param#%u\", i + 1);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t}\n+\n+\tenv_stack_pop_resolved(env, 0, 0);\n+\treturn 0;\n+}\n+\n+static const struct btf_kind_operations loc_proto_ops = {\n+\t.check_meta = btf_loc_proto_check_meta,\n+\t.resolve = btf_loc_proto_resolve,\n+\t.check_member = btf_df_check_member,\n+\t.check_kflag_member = btf_df_check_kflag_member,\n+\t.log_details = btf_loc_proto_log,\n+\t.show = btf_df_show,\n+};\n+\n+__printf(4, 5)\n+static void btf_verifier_log_loc(struct btf_verifier_env *env,\n+\t\t\t\t const struct btf_type *locsec_type,\n+\t\t\t\t const struct btf_loc *loc,\n+\t\t\t\t const char *fmt, ...)\n+{\n+\tstruct bpf_verifier_log *log = \u0026env-\u003elog;\n+\tva_list args;\n+\n+\tif (!bpf_verifier_log_needed(log))\n+\t\treturn;\n+\tif (log-\u003elevel == BPF_LOG_KERNEL \u0026\u0026 !fmt)\n+\t\treturn;\n+\tif (env-\u003ephase != CHECK_META)\n+\t\tbtf_verifier_log_type(env, locsec_type, NULL);\n+\n+\t__btf_verifier_log(log, \"\\t func=%u loc_proto=%u offset=%u\",\n+\t\t\t   loc-\u003efunc, loc-\u003eloc_proto, loc-\u003eoffset);\n+\tif (fmt \u0026\u0026 *fmt) {\n+\t\t__btf_verifier_log(log, \" \");\n+\t\tva_start(args, fmt);\n+\t\tbpf_verifier_vlog(log, fmt, args);\n+\t\tva_end(args);\n+\t}\n+\n+\t__btf_verifier_log(log, \"\\n\");\n+}\n+\n+static s32 btf_locsec_check_meta(struct btf_verifier_env *env,\n+\t\t\t\t const struct btf_type *t,\n+\t\t\t\t u32 meta_left)\n+{\n+\tu32 i, meta_needed, vlen = btf_type_vlen(t);\n+\tconst struct btf_loc *loc;\n+\n+\tmeta_needed = sizeof(struct btf_loc) * vlen;\n+\n+\tif (meta_left \u003c meta_needed) {\n+\t\tbtf_verifier_log_basic(env, t,\n+\t\t\t\t       \"meta_left:%u meta_needed:%u\",\n+\t\t\t\t       meta_left, meta_needed);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (btf_type_kflag(t)) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid btf_info kind_flag\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!t-\u003ename_off ||\n+\t    !btf_name_valid_section(env-\u003ebtf, t-\u003ename_off)) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid name\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tfor_each_loc(i, t, loc) {\n+\t\t/* A loc func, loc proto cannot be in type void */\n+\t\tif (!loc-\u003efunc || !BTF_TYPE_ID_VALID(loc-\u003efunc)) {\n+\t\t\tbtf_verifier_log_loc(env, t, loc, \"Invalid func\");\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t\tif (!loc-\u003eloc_proto || !BTF_TYPE_ID_VALID(loc-\u003eloc_proto)) {\n+\t\t\tbtf_verifier_log_loc(env, t, loc, \"Invalid loc_proto\");\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t\tbtf_verifier_log_loc(env, t, loc, NULL);\n+\t}\n+\n+\treturn meta_needed;\n+}\n+\n+static void btf_locsec_log(struct btf_verifier_env *env,\n+\t\t\t   const struct btf_type *t)\n+{\n+\tbtf_verifier_log(env, \"vlen=%u\", btf_type_vlen(t));\n+}\n+\n+static int btf_locsec_resolve(struct btf_verifier_env *env,\n+\t\t\t      const struct resolve_vertex *v)\n+{\n+\tconst struct btf_type *t = v-\u003et;\n+\tconst struct btf_loc *loc;\n+\tstruct btf *btf = env-\u003ebtf;\n+\tu32 i;\n+\n+\tif (t-\u003etype) {\n+\t\tbtf_verifier_log_type(env, t, \"Invalid locsec type\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tenv-\u003eresolve_mode = RESOLVE_TBD;\n+\tfor (i = v-\u003enext_member, loc = btf_type_loc_secinfo(t) + i;\n+\t     i \u003c btf_type_vlen(t); i++, loc++) {\n+\t\tconst struct btf_type *func_type, *loc_proto_type;\n+\t\tu32 func_type_id = loc-\u003efunc;\n+\t\tu32 loc_proto_type_id = loc-\u003eloc_proto;\n+\n+\t\tfunc_type = btf_type_by_id(btf, func_type_id);\n+\t\tif (!func_type || !btf_type_is_func(func_type)) {\n+\t\t\tbtf_verifier_log_type(env, t,\n+\t\t\t\t\t      \"Invalid func#%u\", i + 1);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (!env_type_is_resolved(env, func_type_id)) {\n+\t\t\tenv_stack_set_next_member(env, i);\n+\t\t\treturn env_stack_push(env, func_type, func_type_id);\n+\t\t}\n+\n+\t\tloc_proto_type = btf_type_by_id(btf, loc_proto_type_id);\n+\t\tif (!loc_proto_type || !btf_type_is_loc_proto(loc_proto_type)) {\n+\t\t\tbtf_verifier_log_type(env, t,\n+\t\t\t\t\t      \"Invalid loc_proto#%u\", i + 1);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (!env_type_is_resolved(env, loc_proto_type_id)) {\n+\t\t\tenv_stack_set_next_member(env, i + 1);\n+\t\t\treturn env_stack_push(env, loc_proto_type,\n+\t\t\t\t\t      loc_proto_type_id);\n+\t\t}\n+\t}\n+\n+\tenv_stack_pop_resolved(env, 0, 0);\n+\treturn 0;\n+}\n+\n+static const struct btf_kind_operations locsec_ops = {\n+\t.check_meta = btf_locsec_check_meta,\n+\t.resolve = btf_locsec_resolve,\n+\t.check_member = btf_df_check_member,\n+\t.check_kflag_member = btf_df_check_kflag_member,\n+\t.log_details = btf_locsec_log,\n+\t.show = btf_df_show,\n+};\n+\n static s32 btf_func_proto_check_meta(struct btf_verifier_env *env,\n \t\t\t\t     const struct btf_type *t,\n \t\t\t\t     u32 meta_left)\n@@ -5398,6 +5692,9 @@ static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {\n \t[BTF_KIND_DECL_TAG] = \u0026decl_tag_ops,\n \t[BTF_KIND_TYPE_TAG] = \u0026modifier_ops,\n \t[BTF_KIND_ENUM64] = \u0026enum64_ops,\n+\t[BTF_KIND_LOC_PARAM] = \u0026loc_param_ops,\n+\t[BTF_KIND_LOC_PROTO] = \u0026loc_proto_ops,\n+\t[BTF_KIND_LOCSEC] = \u0026locsec_ops,\n };\n \n static s32 btf_check_meta(struct btf_verifier_env *env,\n@@ -5472,7 +5769,8 @@ static bool btf_resolve_valid(struct btf_verifier_env *env,\n \tif (!env_type_is_resolved(env, type_id))\n \t\treturn false;\n \n-\tif (btf_type_is_struct(t) || btf_type_is_datasec(t))\n+\tif (btf_type_is_struct(t) || btf_type_is_datasec(t) ||\n+\t    btf_type_is_loc_proto(t) || btf_type_is_locsec(t))\n \t\treturn !btf_resolved_type_id(btf, type_id) \u0026\u0026\n \t\t       !btf_resolved_type_size(btf, type_id);\n \ndiff --git a/tools/bpf/bpftool/Documentation/bpftool-btf.rst b/tools/bpf/bpftool/Documentation/bpftool-btf.rst\nindex cf75a7fa2d6bc..c6dc445cd4a19 100644\n--- a/tools/bpf/bpftool/Documentation/bpftool-btf.rst\n+++ b/tools/bpf/bpftool/Documentation/bpftool-btf.rst\n@@ -16,7 +16,7 @@ SYNOPSIS\n \n **bpftool** [*OPTIONS*] **btf** *COMMAND*\n \n-*OPTIONS* := { |COMMON_OPTIONS| | { **-B** | **--base-btf** } }\n+*OPTIONS* := { |COMMON_OPTIONS| | [{ **-B** | **--base-btf**} *FILE*]...  }\n \n *COMMANDS* := { **dump** | **help** }\n \n@@ -87,7 +87,10 @@ OPTIONS\n     objects for kernel modules. To avoid duplicating all kernel symbols\n     required by modules, BTF objects for modules are \"split\", they are\n     built incrementally on top of the kernel (vmlinux) BTF object. So the\n-    base BTF reference should usually point to the kernel BTF.\n+    base BTF reference should usually point to the kernel BTF.  Multiple\n+    base BTF objects can be passed, where the first is assumed to be the\n+    root BTF, followed by split BTF based upon it, followed by split\n+    BTF based upon the first split BTF and so on.\n \n     When the main BTF object to process (for example, the module BTF to\n     dump) is passed as a *FILE*, bpftool attempts to autodetect the path\ndiff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c\nindex bca0a3982f09b..5e0cb58628117 100644\n--- a/tools/bpf/bpftool/btf.c\n+++ b/tools/bpf/bpftool/btf.c\n@@ -51,6 +51,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {\n \t[BTF_KIND_DECL_TAG]\t= \"DECL_TAG\",\n \t[BTF_KIND_TYPE_TAG]\t= \"TYPE_TAG\",\n \t[BTF_KIND_ENUM64]\t= \"ENUM64\",\n+\t[BTF_KIND_LOC_PARAM]\t= \"LOC_PARAM\",\n+\t[BTF_KIND_LOC_PROTO]\t= \"LOC_PROTO\",\n+\t[BTF_KIND_LOCSEC]\t= \"LOCSEC\",\n };\n \n struct sort_datum {\n@@ -117,6 +120,83 @@ static int btf_kind_safe(int kind)\n \treturn kind \u003c= BTF_KIND_MAX ? kind : BTF_KIND_UNKN;\n }\n \n+static void btf_loc_param_str(const struct btf_type *t, char *str, size_t sz)\n+{\n+\tconst struct btf_loc_param *p;\n+\t__u32 i = 0, vlen;\n+\t__u64 value;\n+\tbool negative = false;\n+\tchar regs[32] = {};\n+\tchar num[32] = {};\n+\tconst char *op = \"\";\n+\n+\tif (!t || !btf_is_loc_param(t)) {\n+\t\tsnprintf(str, sz, \"\u003cinvalid\u003e\");\n+\t\treturn;\n+\t}\n+\n+\tp = btf_loc_param(t);\n+\tvlen = btf_vlen(t);\n+\n+\tif (p-\u003eflags \u0026 BTF_LOC_PARAM_REG) {\n+\t\t__u32 nregs = (p-\u003eflags == BTF_LOC_PARAM_REG) ? vlen : 1;\n+\n+\t\tif (nregs \u003e vlen) {\n+\t\t\tsnprintf(str, sz, \"?\");\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tswitch (nregs) {\n+\t\tcase 2:\n+\t\t\tsnprintf(regs, sizeof(regs), \"r%u, r%u\",\n+\t\t\t\t p-\u003evalues[0], p-\u003evalues[1]);\n+\t\t\tbreak;\n+\t\tcase 1:\n+\t\t\tsnprintf(regs, sizeof(regs), \"r%u\", p-\u003evalues[0]);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tsnprintf(regs, sizeof(regs), \"?\");\n+\t\t\tbreak;\n+\t\t}\n+\t\ti += nregs;\n+\t}\n+\tif (p-\u003eflags \u0026 (BTF_LOC_PARAM_CONST|BTF_LOC_PARAM_OFFSET)) {\n+\t\tswitch (vlen - i) {\n+\t\tcase 1:\n+\t\t\tvalue = p-\u003evalues[i];\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\tvalue = ((__u64)p-\u003evalues[i + 1] \u003c\u003c 32) | p-\u003evalues[i];\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tsnprintf(num, sizeof(num), \"?\");\n+\t\t\tgoto done;\n+\t\t}\n+\t\tif ((p-\u003eflags \u0026 BTF_LOC_PARAM_SIGNED) \u0026\u0026 t-\u003esize \u0026\u0026\n+\t\t    t-\u003esize \u003c= sizeof(value)) {\n+\t\t\t__u32 bits = t-\u003esize * 8;\n+\n+\t\t\tif (t-\u003esize \u003c sizeof(value))\n+\t\t\t\tvalue \u0026= (1ULL \u003c\u003c bits) - 1;\n+\t\t\tnegative = value \u0026 (1ULL \u003c\u003c (bits - 1));\n+\t\t\tif (negative)\n+\t\t\t\tvalue = t-\u003esize == sizeof(value) ? -value :\n+\t\t\t\t\t(1ULL \u003c\u003c bits) - value;\n+\t\t}\n+\t\tsnprintf(num, sizeof(num), \"0x%llx\", (unsigned long long)value);\n+\t}\n+\tif (num[0])\n+\t\top = regs[0] ? (negative ? \" - \" : \" + \") : negative ? \"-\" : \"\";\n+\n+done:\n+\tsnprintf(str, sz, \"%s%s%s%s%s\",\n+\t\t p-\u003eflags \u0026 BTF_LOC_PARAM_DEREF ? \"*(\" : \"\",\n+\t\t regs,\n+\t\t op,\n+\t\t num,\n+\t\t p-\u003eflags \u0026 BTF_LOC_PARAM_DEREF ? \")\" : \"\");\n+}\n+\n static int dump_btf_type(const struct btf *btf, __u32 id,\n \t\t\t const struct btf_type *t)\n {\n@@ -415,6 +495,95 @@ static int dump_btf_type(const struct btf *btf, __u32 id,\n \t\t}\n \t\tbreak;\n \t}\n+\tcase BTF_KIND_LOC_PARAM: {\n+\t\tconst struct btf_loc_param *p = btf_loc_param(t);\n+\t\t__u32 vlen = btf_vlen(t);\n+\t\tchar param_str[256] = {};\n+\n+\t\tbtf_loc_param_str(t, param_str, sizeof(param_str));\n+\n+\t\tif (json_output) {\n+\t\t\tjsonw_uint_field(w, \"size\", t-\u003esize);\n+\t\t\tjsonw_uint_field(w, \"flags\", p-\u003eflags);\n+\t\t\tjsonw_uint_field(w, \"vlen\", vlen);\n+\t\t\tjsonw_string_field(w, \"values\", param_str);\n+\t\t} else {\n+\t\t\tprintf(\" size=%u flags=0x%x vlen=%u values='%s'\", t-\u003esize, p-\u003eflags, vlen, param_str);\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tcase BTF_KIND_LOC_PROTO: {\n+\t\t__u32 *params = btf_loc_proto_params(t);\n+\t\t__u16 vlen = btf_vlen(t);\n+\t\tint i;\n+\n+\t\tif (json_output) {\n+\t\t\tjsonw_uint_field(w, \"vlen\", vlen);\n+\t\t\tjsonw_name(w, \"params\");\n+\t\t\tjsonw_start_array(w);\n+\t\t} else {\n+\t\t\tprintf(\" vlen=%u\", vlen);\n+\t\t}\n+\n+\t\tfor (i = 0; i \u003c vlen; i++, params++) {\n+\t\t\tconst struct btf_type *p;\n+\t\t\tchar param_str[256] = {};\n+\n+\t\t\tif (*params) {\n+\t\t\t\tp = btf__type_by_id(btf, *params);\n+\t\t\t\tbtf_loc_param_str(p, param_str, sizeof(param_str));\n+\t\t\t} else {\n+\t\t\t\tsnprintf(param_str, sizeof(param_str), \"\u003cunavailable\u003e\");\n+\t\t\t}\n+\t\t\tif (json_output) {\n+\t\t\t\tjsonw_start_object(w);\n+\t\t\t\tjsonw_uint_field(w, \"type_id\", *params);\n+\t\t\t\tjsonw_string_field(w, \"value\", param_str);\n+\t\t\t\tjsonw_end_object(w);\n+\t\t\t} else {\n+\t\t\t\tprintf(\"\\n\\ttype_id=%u value='%s'\", *params, param_str);\n+\t\t\t}\n+\t\t}\n+\t\tif (json_output)\n+\t\t\tjsonw_end_array(w);\n+\t\tbreak;\n+\t}\n+\n+\tcase BTF_KIND_LOCSEC: {\n+\t\tstruct btf_loc *locs = btf_locsec_locs(t);\n+\t\t__u32 i, vlen = btf_vlen(t);\n+\n+\t\tif (json_output) {\n+\t\t\tjsonw_uint_field(w, \"vlen\", vlen);\n+\t\t\tjsonw_name(w, \"locs\");\n+\t\t\tjsonw_start_array(w);\n+\t\t} else {\n+\t\t\tprintf(\" vlen=%u\", vlen);\n+\t\t}\n+\n+\t\tfor (i = 0; i \u003c vlen; i++, locs++) {\n+\t\t\tconst struct btf_type *f = btf__type_by_id(btf, locs-\u003efunc);\n+\t\t\tconst char *name = \"\u003cinvalid\u003e\";\n+\n+\t\t\tif (f \u0026\u0026 btf_is_func(f))\n+\t\t\t\tname = btf_str(btf, f-\u003ename_off);\n+\n+\t\t\tif (json_output) {\n+\t\t\t\tjsonw_start_object(w);\n+\t\t\t\tjsonw_uint_field(w, \"func_type_id\", locs-\u003efunc);\n+\t\t\t\tjsonw_string_field(w, \"name\", name);\n+\t\t\t\tjsonw_uint_field(w, \"loc_proto_type_id\", locs-\u003eloc_proto);\n+\t\t\t\tjsonw_uint_field(w, \"offset\", locs-\u003eoffset);\n+\t\t\t\tjsonw_end_object(w);\n+\t\t\t} else {\n+\t\t\t\tprintf(\"\\n\\tname='%s' func_type_id=%u loc_proto_type_id=%u offset=%u\",\n+\t\t\t\t       name, locs-\u003efunc, locs-\u003eloc_proto, locs-\u003eoffset);\n+\t\t\t}\n+\t\t}\n+\t\tif (json_output)\n+\t\t\tjsonw_end_array(w);\n+\t\tbreak;\n+\t}\n \tdefault:\n \t\tbreak;\n \t}\n@@ -1545,7 +1714,7 @@ static int do_help(int argc, char **argv)\n \t\t\"       \" HELP_SPEC_MAP \"\\n\"\n \t\t\"       \" HELP_SPEC_PROGRAM \"\\n\"\n \t\t\"       \" HELP_SPEC_OPTIONS \" |\\n\"\n-\t\t\"                    {-B|--base-btf} }\\n\"\n+\t\t\"                    {[{-B|--base-btf} FILE]... }\\n\"\n \t\t\"\",\n \t\tbin_name, \"btf\");\n \ndiff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c\nindex 5ababd8f7d0a0..cff76be7d2e86 100644\n--- a/tools/bpf/bpftool/main.c\n+++ b/tools/bpf/bpftool/main.c\n@@ -466,6 +466,7 @@ int main(int argc, char **argv)\n \t\t{ \"base-btf\",\trequired_argument, NULL, 'B' },\n \t\t{ 0 }\n \t};\n+\tstruct btf *new_base_btf = NULL, *root_base_btf = NULL;\n \tbool version_requested = false;\n \tint opt, ret;\n \n@@ -515,12 +516,16 @@ int main(int argc, char **argv)\n \t\t\tverifier_logs = true;\n \t\t\tbreak;\n \t\tcase 'B':\n-\t\t\tbase_btf = btf__parse(optarg, NULL);\n-\t\t\tif (!base_btf) {\n+\t\t\t/* handle multi-split BTF */\n+\t\t\tnew_base_btf = btf__parse_split(optarg, base_btf);\n+\t\t\tif (!new_base_btf) {\n \t\t\t\tp_err(\"failed to parse base BTF at '%s': %d\\n\",\n \t\t\t\t      optarg, -errno);\n \t\t\t\treturn -1;\n \t\t\t}\n+\t\t\tbase_btf = new_base_btf;\n+\t\t\tif (!root_base_btf)\n+\t\t\t\troot_base_btf = base_btf;\n \t\t\tbreak;\n \t\tcase 'L':\n \t\t\tuse_loader = true;\n@@ -567,7 +572,18 @@ int main(int argc, char **argv)\n \tif (json_output)\n \t\tjsonw_destroy(\u0026json_wtr);\n \n-\tbtf__free(base_btf);\n+\twhile (base_btf) {\n+\t\tnew_base_btf = (struct btf *)btf__base_btf(base_btf);\n+\t\tbtf__free(base_btf);\n+\t\t/*\n+\t\t * Do not free base BTF that is an owned .BTF.base ; leads\n+\t\t * to a double-free, so only free as far as the root base\n+\t\t * we explicitly read with -B above.\n+\t\t */\n+\t\tif (base_btf == root_base_btf)\n+\t\t\tbreak;\n+\t\tbase_btf = new_base_btf;\n+\t}\n \n \treturn ret;\n }\ndiff --git a/tools/include/uapi/linux/btf.h b/tools/include/uapi/linux/btf.h\nindex 618167cab4e61..a85d293f4127f 100644\n--- a/tools/include/uapi/linux/btf.h\n+++ b/tools/include/uapi/linux/btf.h\n@@ -92,7 +92,9 @@ enum {\n \tBTF_KIND_DECL_TAG\t= 17,\t/* Decl Tag */\n \tBTF_KIND_TYPE_TAG\t= 18,\t/* Type Tag */\n \tBTF_KIND_ENUM64\t\t= 19,\t/* Enumeration up to 64-bit values */\n-\n+\tBTF_KIND_LOC_PARAM\t= 20,\t/* Location parameter information */\n+\tBTF_KIND_LOC_PROTO\t= 21,\t/* Location prototype for site */\n+\tBTF_KIND_LOCSEC\t\t= 22,\t/* Location section */\n \tNR_BTF_KINDS,\n \tBTF_KIND_MAX\t\t= NR_BTF_KINDS - 1,\n };\n@@ -212,4 +214,65 @@ struct btf_enum64 {\n \t__u32\tval_hi32;\n };\n \n+/*\n+ * BTF_KIND_LOC_PARAM is followed by a single \"struct btf_loc_param\"\n+ * that contains flags specifying the contents of the vlen-specified\n+ * number of 4-byte values that follow.\n+ */\n+struct btf_loc_param {\n+\t__u32 flags;\n+\t__u32 values[];\n+};\n+\n+/*\n+ * The combination of size, vlen and flags gives us the means to interpret\n+ * the following vlen-specified set of 4-byte values:\n+ *\n+ * - a BTF_LOC_PARAM_CONST is a constant value; combination\n+ *   of size, vlen and _SIGNED flag determines it. If the value requires\n+ *   64 bits it is stored in {lo,hi} order.\n+ * - a BTF_LOC_PARAM_ADDR|BTF_LOC_PARAM_CONST is an address that should be\n+ *   normalized with respect to kernel/module base address.\n+ * - a BTF_LOC_PARAM_REG with vlen 1 is a simple register number;\n+ *   with vlen 2 it is a multi-register parameter.\n+ * - a _REG | OFFSET describes an address without dereferencing it.\n+ * - a _REG | DEREF with vlen 1 dereferences the value in the register\n+ *   number specified.\n+ * - a REG | DEREF | OFFSET with vlen specifies the register value in\n+ *   the first 4-byte value and the offset in the remainder.\n+ */\n+enum btf_loc_param_flags {\n+\tBTF_LOC_PARAM_SIGNED\t\t=\t0x1,\n+\tBTF_LOC_PARAM_CONST\t\t=\t0x2,\n+\tBTF_LOC_PARAM_ADDR\t\t=\t0x4,\n+\tBTF_LOC_PARAM_REG\t\t=\t0x8,\n+\tBTF_LOC_PARAM_DEREF\t\t=\t0x10,\n+\tBTF_LOC_PARAM_OFFSET\t\t=\t0x20,\n+};\n+\n+/*\n+ * BTF_KIND_LOC_PROTO specifies location prototypes; i.e. how locations relate\n+ * to parameters; a struct btf_type of BTF_KIND_LOC_PROTO is followed by a\n+ * vlen-specified number of __u32 BTF type ids which specify the associated\n+ * BTF_KIND_LOC_PARAM for each function parameter associated with the\n+ * location.  The type should either be 0 (no location info) or point at\n+ * a BTF_KIND_LOC_PARAM.\n+ */\n+\n+/*\n+ * BTF_KIND_LOCSEC consists of vlen-specified number of \"struct btf_loc\"\n+ * containing location site-specific information for a specific ELF section;\n+ * for example locations in \".text\" are in a LOCSEC named \"inline.text\".\n+ *\n+ * - function (func)\n+ * - location prototype type id (loc_proto)\n+ * - address offset (offset) relative to kernel base address\n+ */\n+\n+struct btf_loc {\n+\t__u32 func;\n+\t__u32 loc_proto;\n+\t__u32 offset;\n+};\n+\n #endif /* _UAPI__LINUX_BTF_H__ */\ndiff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c\nindex 908bd344229d5..332a8388fcc41 100644\n--- a/tools/lib/bpf/btf.c\n+++ b/tools/lib/bpf/btf.c\n@@ -57,6 +57,9 @@ static struct btf_layout layouts[NR_BTF_KINDS] = {\n [BTF_KIND_DECL_TAG] =\t{\tsizeof(struct btf_decl_tag),\t0,\t\t\t\t0 },\n [BTF_KIND_TYPE_TAG] =\t{\t0,\t\t\t\t0,\t\t\t\t0 },\n [BTF_KIND_ENUM64] =\t{\t0,\t\t\t\tsizeof(struct btf_enum64),\t0 },\n+[BTF_KIND_LOC_PARAM] =\t{\tsizeof(struct btf_loc_param),\tsizeof(__u32),\t\t\t0 },\n+[BTF_KIND_LOC_PROTO] =\t{\t0,\t\t\t\tsizeof(__u32),\t\t\t0 },\n+[BTF_KIND_LOCSEC] =\t{\t0,\t\t\t\tsizeof(struct btf_loc),\t\t0 },\n };\n \n struct btf {\n@@ -486,6 +489,12 @@ static int btf_type_size(const struct btf *btf, const struct btf_type *t)\n \t\treturn base_size + vlen * sizeof(struct btf_var_secinfo);\n \tcase BTF_KIND_DECL_TAG:\n \t\treturn base_size + sizeof(struct btf_decl_tag);\n+\tcase BTF_KIND_LOC_PARAM:\n+\t\treturn base_size + sizeof(struct btf_loc_param) + vlen * sizeof(__u32);\n+\tcase BTF_KIND_LOC_PROTO:\n+\t\treturn base_size + vlen * sizeof(__u32);\n+\tcase BTF_KIND_LOCSEC:\n+\t\treturn base_size + vlen * sizeof(struct btf_loc);\n \tdefault:\n \t\treturn btf_type_size_unknown(btf, t);\n \t}\n@@ -501,12 +510,15 @@ static void btf_bswap_type_base(struct btf_type *t)\n static int btf_bswap_type_rest(struct btf_type *t)\n {\n \tstruct btf_var_secinfo *v;\n+\tstruct btf_loc_param *lp;\n \tstruct btf_enum64 *e64;\n \tstruct btf_member *m;\n \tstruct btf_array *a;\n \tstruct btf_param *p;\n \tstruct btf_enum *e;\n+\tstruct btf_loc *l;\n \t__u32 vlen = btf_vlen(t);\n+\t__u32 *d;\n \tint i;\n \n \tswitch (btf_kind(t)) {\n@@ -569,6 +581,23 @@ static int btf_bswap_type_rest(struct btf_type *t)\n \tcase BTF_KIND_DECL_TAG:\n \t\tbtf_decl_tag(t)-\u003ecomponent_idx = bswap_32(btf_decl_tag(t)-\u003ecomponent_idx);\n \t\treturn 0;\n+\tcase BTF_KIND_LOC_PARAM:\n+\t\tlp = btf_loc_param(t);\n+\t\tlp-\u003eflags = bswap_32(lp-\u003eflags);\n+\t\tfor (i = 0, d = (__u32 *)(lp + 1); i \u003c vlen; i++, d++)\n+\t\t\t*d = bswap_32(*d);\n+\t\treturn 0;\n+\tcase BTF_KIND_LOC_PROTO:\n+\t\tfor (i = 0, d = btf_loc_proto_params(t); i \u003c vlen; i++, d++)\n+\t\t\t*d = bswap_32(*d);\n+\t\treturn 0;\n+\tcase BTF_KIND_LOCSEC:\n+\t\tfor (i = 0, l = btf_locsec_locs(t); i \u003c vlen; i++, l++) {\n+\t\t\tl-\u003efunc = bswap_32(l-\u003efunc);\n+\t\t\tl-\u003eloc_proto = bswap_32(l-\u003eloc_proto);\n+\t\t\tl-\u003eoffset = bswap_32(l-\u003eoffset);\n+\t\t}\n+\t\treturn 0;\n \tdefault:\n \t\tpr_debug(\"Unsupported BTF_KIND:%u\\n\", btf_kind(t));\n \t\treturn -EINVAL;\n@@ -745,6 +774,33 @@ static int btf_validate_type(const struct btf *btf, const struct btf_type *t, __\n \t\t}\n \t\tbreak;\n \t}\n+\tcase BTF_KIND_LOC_PARAM:\n+\t\tbreak;\n+\tcase BTF_KIND_LOC_PROTO: {\n+\t\t__u32 *p = btf_loc_proto_params(t);\n+\n+\t\tn = btf_vlen(t);\n+\t\tfor (i = 0; i \u003c n; i++, p++) {\n+\t\t\terr = btf_validate_id(btf, *p, id);\n+\t\t\tif (err)\n+\t\t\t\treturn err;\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tcase BTF_KIND_LOCSEC: {\n+\t\tconst struct btf_loc *l = btf_locsec_locs(t);\n+\n+\t\tn = btf_vlen(t);\n+\t\tfor (i = 0; i \u003c n; i++, l++) {\n+\t\t\tif (!err)\n+\t\t\t\terr = btf_validate_id(btf, l-\u003efunc, id);\n+\t\t\tif (!err)\n+\t\t\t\terr = btf_validate_id(btf, l-\u003eloc_proto, id);\n+\t\t\tif (err)\n+\t\t\t\treturn err;\n+\t\t}\n+\t\tbreak;\n+\t}\n \tdefault:\n \t\t/* Kind may be represented in kind layout information. */\n \t\tif (btf_type_size_unknown(btf, t) \u003c 0) {\n@@ -3344,6 +3400,208 @@ int btf__add_decl_attr(struct btf *btf, const char *value, int ref_type_id,\n \treturn btf_add_decl_tag(btf, value, ref_type_id, component_idx, 1);\n }\n \n+/*\n+ * Append new BTF_KIND_LOC_PARAM with specified size and flags.  Values are\n+ * added via btf__add_loc_param_value().\n+ *\n+ * Returns:\n+ *   -  \u003e0, type ID of newly added BTF type;\n+ *   - \u003c0, on error.\n+ */\n+int btf__add_loc_param(struct btf *btf, __u32 size, __u32 flags)\n+{\n+\tstruct btf_loc_param *p;\n+\tstruct btf_type *t;\n+\tint sz, err;\n+\n+\terr = btf_ensure_modifiable(btf);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tsz = sizeof(struct btf_type) + sizeof(*p);\n+\tt = btf_add_type_mem(btf, sz);\n+\tif (!t)\n+\t\treturn libbpf_err(-ENOMEM);\n+\n+\tt-\u003ename_off = 0;\n+\tt-\u003einfo = btf_type_info(BTF_KIND_LOC_PARAM, 0, 0);\n+\tt-\u003esize = size;\n+\n+\tp = btf_loc_param(t);\n+\tp-\u003eflags = flags;\n+\n+\treturn btf_commit_type(btf, sz);\n+}\n+\n+int btf__add_loc_param_value(struct btf *btf, __u32 value)\n+{\n+\tstruct btf_type *t;\n+\tint sz, err;\n+\t__u32 *v;\n+\n+\t/* last type should be BTF_KIND_LOC_PARAM */\n+\tif (btf-\u003enr_types == 0)\n+\t\treturn libbpf_err(-EINVAL);\n+\tt = btf_last_type(btf);\n+\tif (!btf_is_loc_param(t))\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\t/* decompose and invalidate raw data */\n+\terr = btf_ensure_modifiable(btf);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tsz = sizeof(value);\n+\tv = btf_add_type_mem(btf, sz);\n+\tif (!v)\n+\t\treturn libbpf_err(-ENOMEM);\n+\t*v = value;\n+\n+\t/* update parent type's vlen */\n+\tt = btf_last_type(btf);\n+\terr = btf_type_inc_vlen(t);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tbtf_hdr_update_type_len(btf, btf-\u003ehdr.type_len + sz);\n+\treturn 0;\n+}\n+\n+/*\n+ * Append new BTF_KIND_LOC_PROTO\n+ *\n+ * The prototype is then populated with 0 or more BTF_KIND_LOC_PARAMs via\n+ * btf__add_loc_proto_param(); similar to how btf__add_func_param() adds\n+ * parameters to a FUNC_PROTO.\n+ *\n+ * Returns:\n+ *   -  \u003e0, type ID of newly added BTF type;\n+ *   - \u003c0, on error.\n+ */\n+int btf__add_loc_proto(struct btf *btf)\n+{\n+\tstruct btf_type *t;\n+\tint err;\n+\n+\terr = btf_ensure_modifiable(btf);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tt = btf_add_type_mem(btf, sizeof(struct btf_type));\n+\tif (!t)\n+\t\treturn libbpf_err(-ENOMEM);\n+\n+\tt-\u003ename_off = 0;\n+\tt-\u003einfo = btf_type_info(BTF_KIND_LOC_PROTO, 0, 0);\n+\tt-\u003esize = 0;\n+\n+\treturn btf_commit_type(btf, sizeof(struct btf_type));\n+}\n+\n+int btf__add_loc_proto_param(struct btf *btf, __u32 id)\n+{\n+\tstruct btf_type *t;\n+\tint sz, err;\n+\t__u32 *p;\n+\n+\tif (validate_type_id(id))\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\t/* last type should be BTF_KIND_LOC_PROTO */\n+\tif (btf-\u003enr_types == 0)\n+\t\treturn libbpf_err(-EINVAL);\n+\tt = btf_last_type(btf);\n+\tif (!btf_is_loc_proto(t))\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\t/* decompose and invalidate raw data */\n+\terr = btf_ensure_modifiable(btf);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tsz = sizeof(__u32);\n+\tp = btf_add_type_mem(btf, sz);\n+\tif (!p)\n+\t\treturn libbpf_err(-ENOMEM);\n+\t*p = id;\n+\n+\t/* update parent type's vlen */\n+\tt = btf_last_type(btf);\n+\terr = btf_type_inc_vlen(t);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tbtf_hdr_update_type_len(btf, btf-\u003ehdr.type_len + sz);\n+\treturn 0;\n+}\n+\n+int btf__add_locsec(struct btf *btf, const char *name)\n+{\n+\tstruct btf_type *t;\n+\tint name_off = 0;\n+\tint err;\n+\n+\terr = btf_ensure_modifiable(btf);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tt = btf_add_type_mem(btf, sizeof(struct btf_type));\n+\tif (!t)\n+\t\treturn libbpf_err(-ENOMEM);\n+\n+\tif (!str_is_empty(name)) {\n+\t\tname_off = btf__add_str(btf, name);\n+\t\tif (name_off \u003c 0)\n+\t\t\treturn libbpf_err(name_off);\n+\t}\n+\tt-\u003ename_off = name_off;\n+\tt-\u003einfo = btf_type_info(BTF_KIND_LOCSEC, 0, 0);\n+\tt-\u003esize = 0;\n+\n+\treturn btf_commit_type(btf, sizeof(struct btf_type));\n+}\n+\n+int btf__add_locsec_loc(struct btf *btf, __u32 func, __u32 loc_proto,\n+\t\t\t__u32 offset)\n+{\n+\tstruct btf_type *t;\n+\tstruct btf_loc *l;\n+\tint sz, err;\n+\n+\tif (validate_type_id(func) || validate_type_id(loc_proto))\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\t/* last type should be BTF_KIND_LOCSEC */\n+\tif (btf-\u003enr_types == 0)\n+\t\treturn libbpf_err(-EINVAL);\n+\tt = btf_last_type(btf);\n+\tif (!btf_is_locsec(t))\n+\t\treturn libbpf_err(-EINVAL);\n+\n+\t/* decompose and invalidate raw data */\n+\terr = btf_ensure_modifiable(btf);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tsz = sizeof(*l);\n+\tl = btf_add_type_mem(btf, sz);\n+\tif (!l)\n+\t\treturn libbpf_err(-ENOMEM);\n+\n+\tl-\u003efunc = func;\n+\tl-\u003eloc_proto = loc_proto;\n+\tl-\u003eoffset = offset;\n+\n+\t/* update parent type's vlen */\n+\tt = btf_last_type(btf);\n+\terr = btf_type_inc_vlen(t);\n+\tif (err)\n+\t\treturn libbpf_err(err);\n+\n+\tbtf_hdr_update_type_len(btf, btf-\u003ehdr.type_len + sz);\n+\treturn 0;\n+}\n+\n struct btf_ext_sec_info_param {\n \t__u32 off;\n \t__u32 len;\n@@ -4114,8 +4372,8 @@ static struct btf_dedup *btf_dedup_new(struct btf *btf, const struct btf_dedup_o\n \tfor (i = 1; i \u003c type_cnt; i++) {\n \t\tstruct btf_type *t = btf_type_by_id(d-\u003ebtf, i);\n \n-\t\t/* VAR and DATASEC are never deduped and are self-canonical */\n-\t\tif (btf_is_var(t) || btf_is_datasec(t))\n+\t\t/* VAR, DATASEC and LOCSEC are never deduped and are self-canonical */\n+\t\tif (btf_is_var(t) || btf_is_datasec(t) || btf_is_locsec(t))\n \t\t\td-\u003emap[i] = i;\n \t\telse\n \t\t\td-\u003emap[i] = BTF_UNPROCESSED_ID;\n@@ -4395,6 +4653,47 @@ static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2)\n \t       btf_is_any_enum(t1) \u0026\u0026 btf_is_any_enum(t2);\n }\n \n+static long btf_hash_loc_param(struct btf_type *t)\n+{\n+\tstruct btf_loc_param *p = btf_loc_param(t);\n+\tlong h = btf_hash_common(t);\n+\tint i, vlen = btf_vlen(t);\n+\n+\th = hash_combine(h, p-\u003eflags);\n+\n+\tfor (i = 0; i \u003c vlen; i++)\n+\t\th = hash_combine(h, p-\u003evalues[i]);\n+\treturn h;\n+}\n+\n+static long btf_hash_loc_proto(struct btf_type *t)\n+{\n+\t__u32 *p = btf_loc_proto_params(t);\n+\tlong h = btf_hash_common(t);\n+\tint i, vlen = btf_vlen(t);\n+\n+\tfor (i = 0; i \u003c vlen; i++, p++)\n+\t\th = hash_combine(h, *p);\n+\treturn h;\n+}\n+\n+static bool btf_equal_loc_param(struct btf_type *t1, struct btf_type *t2)\n+{\n+\tstruct btf_loc_param *p1 = btf_loc_param(t1);\n+\tstruct btf_loc_param *p2 = btf_loc_param(t2);\n+\tint i, vlen = btf_vlen(t1);\n+\n+\tif (!btf_equal_common(t1, t2))\n+\t\treturn false;\n+\tif (p1-\u003eflags != p2-\u003eflags)\n+\t\treturn false;\n+\tfor (i = 0; i \u003c vlen; i++) {\n+\t\tif (p1-\u003evalues[i] != p2-\u003evalues[i])\n+\t\t\treturn false;\n+\t}\n+\treturn true;\n+}\n+\n /*\n  * Calculate type signature hash of STRUCT/UNION, ignoring referenced type IDs,\n  * as referenced type IDs equivalence is established separately during type\n@@ -4589,7 +4888,8 @@ static int btf_dedup_prep(struct btf_dedup *d)\n \t\tswitch (btf_kind(t)) {\n \t\tcase BTF_KIND_VAR:\n \t\tcase BTF_KIND_DATASEC:\n-\t\t\t/* VAR and DATASEC are never hash/deduplicated */\n+\t\tcase BTF_KIND_LOCSEC:\n+\t\t\t/* VAR DATASEC and LOCSEC are never hash/deduplicated */\n \t\t\tcontinue;\n \t\tcase BTF_KIND_CONST:\n \t\tcase BTF_KIND_VOLATILE:\n@@ -4622,6 +4922,12 @@ static int btf_dedup_prep(struct btf_dedup *d)\n \t\tcase BTF_KIND_FUNC_PROTO:\n \t\t\th = btf_hash_fnproto(t);\n \t\t\tbreak;\n+\t\tcase BTF_KIND_LOC_PARAM:\n+\t\t\th = btf_hash_loc_param(t);\n+\t\t\tbreak;\n+\t\tcase BTF_KIND_LOC_PROTO:\n+\t\t\th = btf_hash_loc_proto(t);\n+\t\t\tbreak;\n \t\tdefault:\n \t\t\tpr_debug(\"unknown kind %d for type [%d]\\n\", btf_kind(t), type_id);\n \t\t\treturn -EINVAL;\n@@ -4664,6 +4970,8 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)\n \tcase BTF_KIND_DATASEC:\n \tcase BTF_KIND_DECL_TAG:\n \tcase BTF_KIND_TYPE_TAG:\n+\tcase BTF_KIND_LOC_PROTO:\n+\tcase BTF_KIND_LOCSEC:\n \t\treturn 0;\n \n \tcase BTF_KIND_INT:\n@@ -4713,6 +5021,18 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)\n \t\t}\n \t\tbreak;\n \n+\tcase BTF_KIND_LOC_PARAM:\n+\t\th = btf_hash_loc_param(t);\n+\t\tfor_each_dedup_cand(d, hash_entry, h) {\n+\t\t\tcand_id = hash_entry-\u003evalue;\n+\t\t\tcand = btf_type_by_id(d-\u003ebtf, cand_id);\n+\t\t\tif (btf_equal_loc_param(t, cand)) {\n+\t\t\t\tnew_id = cand_id;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tbreak;\n+\n \tdefault:\n \t\treturn -EINVAL;\n \t}\n@@ -5145,6 +5465,13 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,\n \t\treturn 1;\n \t}\n \n+\tcase BTF_KIND_LOC_PARAM:\n+\t\treturn btf_equal_loc_param(cand_type, canon_type);\n+\n+\tcase BTF_KIND_LOC_PROTO:\n+\tcase BTF_KIND_LOCSEC:\n+\t\treturn 0;\n+\n \tdefault:\n \t\treturn -EINVAL;\n \t}\n@@ -5489,6 +5816,37 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)\n \t\tbreak;\n \t}\n \n+\tcase BTF_KIND_LOC_PROTO: {\n+\t\t__u32 *p1, *p2;\n+\t\t__u32 i, vlen;\n+\n+\t\tp1 = btf_loc_proto_params(t);\n+\t\tvlen = btf_vlen(t);\n+\n+\t\tfor (i = 0; i \u003c vlen; i++, p1++) {\n+\t\t\tref_type_id = btf_dedup_ref_type(d, *p1);\n+\t\t\tif (ref_type_id \u003c 0)\n+\t\t\t\treturn ref_type_id;\n+\t\t\t*p1 = ref_type_id;\n+\t\t}\n+\n+\t\th = btf_hash_loc_proto(t);\n+\t\tfor_each_dedup_cand(d, hash_entry, h) {\n+\t\t\tcand_id = hash_entry-\u003evalue;\n+\t\t\tcand = btf_type_by_id(d-\u003ebtf, cand_id);\n+\t\t\tif (!btf_equal_common(t, cand))\n+\t\t\t\tcontinue;\n+\t\t\tvlen = btf_vlen(cand);\n+\t\t\tp1 = btf_loc_proto_params(t);\n+\t\t\tp2 = btf_loc_proto_params(cand);\n+\t\t\tif (memcmp(p1, p2, vlen * sizeof(__u32)) == 0) {\n+\t\t\t\tnew_id = cand_id;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tbreak;\n+\t}\n+\n \tdefault:\n \t\treturn -EINVAL;\n \t}\n@@ -5970,8 +6328,11 @@ static int btf_add_distilled_type_ids(struct btf_distill *dist, __u32 i)\n \t\tcase BTF_KIND_CONST:\n \t\tcase BTF_KIND_RESTRICT:\n \t\tcase BTF_KIND_VOLATILE:\n+\t\tcase BTF_KIND_FUNC:\n \t\tcase BTF_KIND_FUNC_PROTO:\n \t\tcase BTF_KIND_TYPE_TAG:\n+\t\tcase BTF_KIND_LOC_PARAM:\n+\t\tcase BTF_KIND_LOC_PROTO:\n \t\t\tdist-\u003eid_map[*id] = *id;\n \t\t\tbreak;\n \t\tdefault:\n@@ -5997,7 +6358,7 @@ static int btf_add_distilled_type_ids(struct btf_distill *dist, __u32 i)\n \n static int btf_add_distilled_types(struct btf_distill *dist)\n {\n-\tbool adding_to_base = dist-\u003epipe.dst-\u003estart_id == 1;\n+\tbool adding_to_base = dist-\u003epipe.dst-\u003ebase_btf == NULL;\n \tint id = btf__type_cnt(dist-\u003epipe.dst);\n \tstruct btf_type *t;\n \tint i, err = 0;\n@@ -6065,8 +6426,12 @@ static int btf_add_distilled_types(struct btf_distill *dist)\n \t\tcase BTF_KIND_CONST:\n \t\tcase BTF_KIND_RESTRICT:\n \t\tcase BTF_KIND_VOLATILE:\n+\t\tcase BTF_KIND_FUNC:\n \t\tcase BTF_KIND_FUNC_PROTO:\n \t\tcase BTF_KIND_TYPE_TAG:\n+\t\tcase BTF_KIND_LOC_PARAM:\n+\t\tcase BTF_KIND_LOC_PROTO:\n+\t\tcase BTF_KIND_LOCSEC:\n \t\t\t/* All other types are added to split BTF. */\n \t\t\tif (adding_to_base)\n \t\t\t\tcontinue;\ndiff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h\nindex 587172c0de089..57f12630c5d15 100644\n--- a/tools/lib/bpf/btf.h\n+++ b/tools/lib/bpf/btf.h\n@@ -274,6 +274,20 @@ LIBBPF_API int btf__add_decl_tag(struct btf *btf, const char *value, int ref_typ\n LIBBPF_API int btf__add_decl_attr(struct btf *btf, const char *value, int ref_type_id,\n \t\t\t\t  int component_idx);\n \n+/* location construction APIs */\n+LIBBPF_API int btf__add_loc_param(struct btf *btf, __u32 size, __u32 flags);\n+\n+LIBBPF_API int btf__add_loc_param_value(struct btf *btf, __u32 value);\n+\n+LIBBPF_API int btf__add_loc_proto(struct btf *btf);\n+\n+LIBBPF_API int btf__add_loc_proto_param(struct btf *btf, __u32 id);\n+\n+LIBBPF_API int btf__add_locsec(struct btf *btf, const char *name);\n+\n+LIBBPF_API int btf__add_locsec_loc(struct btf *btf, __u32 func, __u32 loc_proto,\n+\t\t\t\t   __u32 offset);\n+\n struct btf_dedup_opts {\n \tsize_t sz;\n \t/* optional .BTF.ext info to dedup along the main BTF info */\n@@ -431,6 +445,12 @@ btf_dump__dump_type_data(struct btf_dump *d, __u32 id,\n #define BTF_KIND_DECL_TAG\t17\t/* Decl Tag */\n #define BTF_KIND_TYPE_TAG\t18\t/* Type Tag */\n #define BTF_KIND_ENUM64\t\t19\t/* Enum for up-to 64bit values */\n+#define BTF_KIND_LOC_PARAM\t20\t/* Parameter at location */\n+#define BTF_KIND_LOC_PROTO\t21\t/* Parameter set at location */\n+#define BTF_KIND_LOCSEC\t\t22\t/* Section containing location info */\n+\n+struct btf_loc_param;\n+struct btf_loc;\n \n static inline __u16 btf_kind(const struct btf_type *t)\n {\n@@ -569,6 +589,21 @@ static inline bool btf_is_any_enum(const struct btf_type *t)\n \treturn btf_is_enum(t) || btf_is_enum64(t);\n }\n \n+static inline bool btf_is_loc_param(const struct btf_type *t)\n+{\n+\treturn btf_kind(t) == BTF_KIND_LOC_PARAM;\n+}\n+\n+static inline bool btf_is_loc_proto(const struct btf_type *t)\n+{\n+\treturn btf_kind(t) == BTF_KIND_LOC_PROTO;\n+}\n+\n+static inline bool btf_is_locsec(const struct btf_type *t)\n+{\n+\treturn btf_kind(t) == BTF_KIND_LOCSEC;\n+}\n+\n static inline bool btf_kind_core_compat(const struct btf_type *t1,\n \t\t\t\t\tconst struct btf_type *t2)\n {\n@@ -683,6 +718,21 @@ static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)\n \treturn (struct btf_decl_tag *)(t + 1);\n }\n \n+static inline struct btf_loc_param *btf_loc_param(const struct btf_type *t)\n+{\n+\treturn (struct btf_loc_param *)(t + 1);\n+}\n+\n+static inline __u32 *btf_loc_proto_params(const struct btf_type *t)\n+{\n+\treturn (__u32 *)(t + 1);\n+}\n+\n+static inline struct btf_loc *btf_locsec_locs(const struct btf_type *t)\n+{\n+\treturn (struct btf_loc *)(t + 1);\n+}\n+\n #ifdef __cplusplus\n } /* extern \"C\" */\n #endif\ndiff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c\nindex 123c448f20c74..fa995c02a1705 100644\n--- a/tools/lib/bpf/btf_dump.c\n+++ b/tools/lib/bpf/btf_dump.c\n@@ -328,6 +328,9 @@ static int btf_dump_mark_referenced(struct btf_dump *d)\n \t\tcase BTF_KIND_ENUM64:\n \t\tcase BTF_KIND_FWD:\n \t\tcase BTF_KIND_FLOAT:\n+\t\tcase BTF_KIND_LOC_PARAM:\n+\t\tcase BTF_KIND_LOC_PROTO:\n+\t\tcase BTF_KIND_LOCSEC:\n \t\t\tbreak;\n \n \t\tcase BTF_KIND_VOLATILE:\n@@ -609,6 +612,9 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)\n \tcase BTF_KIND_VAR:\n \tcase BTF_KIND_DATASEC:\n \tcase BTF_KIND_DECL_TAG:\n+\tcase BTF_KIND_LOC_PARAM:\n+\tcase BTF_KIND_LOC_PROTO:\n+\tcase BTF_KIND_LOCSEC:\n \t\td-\u003etype_states[id].order_state = ORDERED;\n \t\treturn 0;\n \n@@ -2525,6 +2531,9 @@ static int btf_dump_dump_type_data(struct btf_dump *d,\n \tcase BTF_KIND_FUNC:\n \tcase BTF_KIND_FUNC_PROTO:\n \tcase BTF_KIND_DECL_TAG:\n+\tcase BTF_KIND_LOC_PARAM:\n+\tcase BTF_KIND_LOC_PROTO:\n+\tcase BTF_KIND_LOCSEC:\n \t\terr = btf_dump_unsupported_data(d, t, id);\n \t\tbreak;\n \tcase BTF_KIND_INT:\ndiff --git a/tools/lib/bpf/btf_iter.c b/tools/lib/bpf/btf_iter.c\nindex 9a6c822c22944..199063b55ebe6 100644\n--- a/tools/lib/bpf/btf_iter.c\n+++ b/tools/lib/bpf/btf_iter.c\n@@ -29,6 +29,7 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n \t\tcase BTF_KIND_FLOAT:\n \t\tcase BTF_KIND_ENUM:\n \t\tcase BTF_KIND_ENUM64:\n+\t\tcase BTF_KIND_LOC_PARAM:\n \t\t\tit-\u003edesc = (struct btf_field_desc) {};\n \t\t\tbreak;\n \t\tcase BTF_KIND_FWD:\n@@ -71,6 +72,20 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n \t\t\t\t1, {offsetof(struct btf_var_secinfo, type)}\n \t\t\t};\n \t\t\tbreak;\n+\t\tcase BTF_KIND_LOC_PROTO:\n+\t\t\tit-\u003edesc = (struct btf_field_desc) {\n+\t\t\t\t0, {},\n+\t\t\t\tsizeof(__u32),\n+\t\t\t\t1, {0}};\n+\t\t\tbreak;\n+\t\tcase BTF_KIND_LOCSEC:\n+\t\t\tit-\u003edesc = (struct btf_field_desc) {\n+\t\t\t\t0, {},\n+\t\t\t\tsizeof(struct btf_loc),\n+\t\t\t\t2, {offsetof(struct btf_loc, func),\n+\t\t\t\t    offsetof(struct btf_loc, loc_proto)}};\n+\t\t\tbreak;\n+\n \t\tdefault:\n \t\t\treturn -EINVAL;\n \t\t}\n@@ -94,6 +109,9 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n \t\tcase BTF_KIND_DECL_TAG:\n \t\tcase BTF_KIND_TYPE_TAG:\n \t\tcase BTF_KIND_DATASEC:\n+\t\tcase BTF_KIND_LOC_PARAM:\n+\t\tcase BTF_KIND_LOC_PROTO:\n+\t\tcase BTF_KIND_LOCSEC:\n \t\t\tit-\u003edesc = (struct btf_field_desc) {\n \t\t\t\t1, {offsetof(struct btf_type, name_off)}\n \t\t\t};\ndiff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map\nindex 08ab2ea881fb6..7f51783df129a 100644\n--- a/tools/lib/bpf/libbpf.map\n+++ b/tools/lib/bpf/libbpf.map\n@@ -460,6 +460,12 @@ LIBBPF_1.8.0 {\n \tglobal:\n \t\tbpf_program__attach_tracing_multi;\n \t\tbpf_program__clone;\n+\t\tbtf__add_loc_param;\n+\t\tbtf__add_loc_param_value;\n+\t\tbtf__add_loc_proto;\n+\t\tbtf__add_loc_proto_param;\n+\t\tbtf__add_locsec;\n+\t\tbtf__add_locsec_loc;\n \t\tbtf__find_by_name_kind_own;\n \t\tbtf__new_empty_opts;\n } LIBBPF_1.7.0;\ndiff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h\nindex cb4d962338441..546f65b95cf4d 100644\n--- a/tools/lib/bpf/libbpf_internal.h\n+++ b/tools/lib/bpf/libbpf_internal.h\n@@ -580,7 +580,7 @@ struct btf_field_desc {\n \t/* member struct size, or zero, if no members */\n \tint m_sz;\n \t/* repeated per-member offsets */\n-\tint m_off_cnt, m_offs[1];\n+\tint m_off_cnt, m_offs[2];\n };\n \n struct btf_field_iter {\ndiff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c\nindex 1c1c2c26690a7..972403f6a7438 100644\n--- a/tools/testing/selftests/bpf/btf_helpers.c\n+++ b/tools/testing/selftests/bpf/btf_helpers.c\n@@ -27,11 +27,14 @@ static const char * const btf_kind_str_mapping[] = {\n \t[BTF_KIND_DECL_TAG]\t= \"DECL_TAG\",\n \t[BTF_KIND_TYPE_TAG]\t= \"TYPE_TAG\",\n \t[BTF_KIND_ENUM64]\t= \"ENUM64\",\n+\t[BTF_KIND_LOC_PARAM]\t= \"LOC_PARAM\",\n+\t[BTF_KIND_LOC_PROTO]\t= \"LOC_PROTO\",\n+\t[BTF_KIND_LOCSEC]\t= \"LOCSEC\",\n };\n \n static const char *btf_kind_str(__u16 kind)\n {\n-\tif (kind \u003e BTF_KIND_ENUM64)\n+\tif (kind \u003e BTF_KIND_LOCSEC)\n \t\treturn \"UNKNOWN\";\n \treturn btf_kind_str_mapping[kind];\n }\n@@ -203,6 +206,37 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)\n \t\tfprintf(out, \" type_id=%u component_idx=%d\",\n \t\t\tt-\u003etype, btf_decl_tag(t)-\u003ecomponent_idx);\n \t\tbreak;\n+\tcase BTF_KIND_LOC_PARAM: {\n+\t\tstruct btf_loc_param *p = btf_loc_param(t);\n+\t\t__u32 *v = (__u32 *)(p + 1);\n+\n+\t\tfprintf(out, \" size=%u flags=0x%x vlen=%u\", t-\u003esize, p-\u003eflags, vlen);\n+\t\tfor (i = 0; i \u003c vlen; i++, v++) {\n+\t\t\tif (p-\u003eflags \u0026 BTF_LOC_PARAM_SIGNED)\n+\t\t\t\tfprintf(out, \"\\n\\tvalue=%d\", (__s32)*v);\n+\t\t\telse\n+\t\t\t\tfprintf(out, \"\\n\\tvalue=%u\", *v);\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tcase BTF_KIND_LOC_PROTO: {\n+\t\tconst __u32 *p = btf_loc_proto_params(t);\n+\n+\t\tfprintf(out, \" vlen=%u\", vlen);\n+\t\tfor (i = 0; i \u003c vlen; i++, p++)\n+\t\t\tfprintf(out, \"\\n\\ttype_id=%u\", *p);\n+\t\tbreak;\n+\t}\n+\tcase BTF_KIND_LOCSEC: {\n+\t\tconst struct btf_loc *l = btf_locsec_locs(t);\n+\n+\t\tfprintf(out, \" vlen=%u\", vlen);\n+\t\tfor (i = 0; i \u003c vlen; i++, l++) {\n+\t\t\tfprintf(out, \"\\n\\tfunc_type_id=%u loc_proto_type_id=%u offset=%u\",\n+\t\t\t\tl-\u003efunc, l-\u003eloc_proto, l-\u003eoffset);\n+\t\t}\n+\t\tbreak;\n+\t}\n \tdefault:\n \t\tbreak;\n \t}\ndiff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c\nindex d5b25302b0c89..f8ea9dfd0780b 100644\n--- a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c\n+++ b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c\n@@ -57,6 +57,35 @@ static struct btf *mk_btf(void)\n \treturn btf;\n }\n \n+static struct btf *mk_loc_btf(void)\n+{\n+\tstruct btf *btf;\n+\n+\tbtf = btf__new_empty();\n+\tif (!ASSERT_OK_PTR(btf, \"new_empty\"))\n+\t\treturn NULL;\n+\n+\tbtf__add_int(btf, \"int\", 4, BTF_INT_SIGNED);\n+\tbtf__add_func_proto(btf, 1);\n+\tbtf__add_func_param(btf, \"arg1\", 1);\n+\tbtf__add_func_param(btf, \"arg2\", 1);\n+\tbtf__add_func(btf, \"foo\", BTF_FUNC_STATIC, 2);\n+\n+\tbtf__add_loc_param(btf, 4, BTF_LOC_PARAM_REG);\n+\tbtf__add_loc_param_value(btf, 1);\n+\tbtf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG |\n+\t\t\t    BTF_LOC_PARAM_DEREF | BTF_LOC_PARAM_OFFSET);\n+\tbtf__add_loc_param_value(btf, 2);\n+\tbtf__add_loc_param_value(btf, 0x10);\n+\tbtf__add_loc_proto(btf);\n+\tbtf__add_loc_proto_param(btf, 4);\n+\tbtf__add_loc_proto_param(btf, 5);\n+\tbtf__add_locsec(btf, \"inline.text\");\n+\tbtf__add_locsec_loc(btf, 3, 6, 64);\n+\n+\treturn btf;\n+}\n+\n static int btf_to_tmpfile(const struct btf *btf, char *path)\n {\n \tssize_t written;\n@@ -105,6 +134,26 @@ static char *dump_c(const char *btf_path, bool sorted)\n \treturn buf;\n }\n \n+static char *dump_raw(const char *btf_path)\n+{\n+\tchar args[MAX_BPFTOOL_CMD_LEN];\n+\tchar *buf;\n+\tint err;\n+\n+\tbuf = malloc(DUMP_BUF_SZ);\n+\tif (!ASSERT_OK_PTR(buf, \"alloc_dump\"))\n+\t\treturn NULL;\n+\n+\tsnprintf(args, sizeof(args), \"btf dump file %s\", btf_path);\n+\terr = get_bpftool_command_output(args, buf, DUMP_BUF_SZ);\n+\tif (!ASSERT_OK(err, \"btf_dump_raw\")) {\n+\t\tfree(buf);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn buf;\n+}\n+\n static char *read_expected(const char *path)\n {\n \tchar *buf = NULL;\n@@ -155,6 +204,31 @@ static void test_dump(const char *btf_path, bool sorted)\n \tfree(dump);\n }\n \n+static void test_loc_dump(const char *btf_path)\n+{\n+\tconst char expected[] =\n+\t\t\"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\\n\"\n+\t\t\"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\\n\"\n+\t\t\"\\t'arg1' type_id=1\\n\"\n+\t\t\"\\t'arg2' type_id=1\\n\"\n+\t\t\"[3] FUNC 'foo' type_id=2 linkage=static\\n\"\n+\t\t\"[4] LOC_PARAM '(anon)' size=4 flags=0x8 vlen=1 values='r1'\\n\"\n+\t\t\"[5] LOC_PARAM '(anon)' size=8 flags=0x38 vlen=2 values='*(r2 + 0x10)'\\n\"\n+\t\t\"[6] LOC_PROTO '(anon)' vlen=2\\n\"\n+\t\t\"\\ttype_id=4 value='r1'\\n\"\n+\t\t\"\\ttype_id=5 value='*(r2 + 0x10)'\\n\"\n+\t\t\"[7] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tname='foo' func_type_id=3 loc_proto_type_id=6 offset=64\\n\";\n+\tchar *dump;\n+\n+\tdump = dump_raw(btf_path);\n+\tif (!dump)\n+\t\treturn;\n+\n+\tASSERT_OK(compare_text_to_expected(dump, expected), \"cmp_loc_dump\");\n+\tfree(dump);\n+}\n+\n void test_bpftool_btf_dump(void)\n {\n \tchar path[PATH_MAX];\n@@ -175,4 +249,14 @@ void test_bpftool_btf_dump(void)\n \tunlink(path);\n out_btf:\n \tbtf__free(btf);\n+\n+\tbtf = mk_loc_btf();\n+\tif (!btf)\n+\t\treturn;\n+\n+\tif (!btf_to_tmpfile(btf, path) \u0026\u0026 test__start_subtest(\"loc_dump\"))\n+\t\ttest_loc_dump(path);\n+\n+\tunlink(path);\n+\tbtf__free(btf);\n }\ndiff --git a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c\nindex 9d61611515938..5c15a6b7f4fb9 100644\n--- a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c\n+++ b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c\n@@ -554,6 +554,120 @@ static void test_split_module(void)\n \tbtf__free(vmlinux_btf);\n }\n \n+static void test_split_loc(void)\n+{\n+\tstruct btf *btf1, *btf2;\n+\tint err;\n+\n+\tbtf1 = btf__new_empty();\n+\tif (!ASSERT_OK_PTR(btf1, \"empty_main_btf\"))\n+\t\treturn;\n+\n+\tbtf__set_pointer_size(btf1, 8); /* enforce 64-bit arch */\n+\n+\n+\tbtf__add_int(btf1, \"long\", 8, BTF_INT_SIGNED);  /* [1] long */\n+\tbtf__add_ptr(btf1, 1);                          /* [2] ptr to long */\n+\tbtf__add_func_proto(btf1, 1);\t\t\t/* [3] long (*)(long, long *); */\n+\tbtf__add_func_param(btf1, \"p1\", 1);\n+\tbtf__add_func_param(btf1, \"p2\", 2);\n+\tbtf__add_func(btf1, \"foo\", BTF_FUNC_STATIC, 3);\t/* [4] long foo(long, long *); */\n+\tbtf__add_loc_param(btf1, 8, BTF_LOC_PARAM_CONST);\n+\tbtf__add_loc_param_value(btf1, 3735928559);\n+\tbtf__add_loc_param_value(btf1, 4277009102);\t/* [5] loc value */\n+\tbtf__add_loc_param(btf1, 8, BTF_LOC_PARAM_REG);\t/* [6] loc reg 1 */\n+\tbtf__add_loc_param_value(btf1, 1);\n+\tbtf__add_loc_proto(btf1);\t\t\t/* [7] loc proto */\n+\tbtf__add_loc_proto_param(btf1, 5);\t\t/*  param value */\n+\tbtf__add_loc_proto_param(btf1, 6);\t\t/*  param reg 1 */\n+\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf1,\n+\t\t\"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED\",\n+\t\t\"[2] PTR '(anon)' type_id=1\",\n+\t\t\"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\\n\"\n+\t\t\"\\t'p1' type_id=1\\n\"\n+\t\t\"\\t'p2' type_id=2\",\n+\t\t\"[4] FUNC 'foo' type_id=3 linkage=static\",\n+\t\t\"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\\n\"\n+\t\t\"\\tvalue=3735928559\\n\"\n+\t\t\"\\tvalue=4277009102\",\n+\t\t\"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\\n\"\n+\t\t\"\\tvalue=1\",\n+\t\t\"[7] LOC_PROTO '(anon)' vlen=2\\n\"\n+\t\t\"\\ttype_id=5\\n\"\n+\t\t\"\\ttype_id=6\");\n+\n+\tbtf2 = btf__new_empty_split(btf1);\n+\tif (!ASSERT_OK_PTR(btf2, \"empty_split_btf\"))\n+\t\tgoto cleanup;\n+\tbtf__add_loc_param(btf2, 8, BTF_LOC_PARAM_REG);\n+\tbtf__add_loc_param_value(btf2, 1);\t\t/* [8] loc reg 1 */\n+\tbtf__add_loc_proto(btf2);\t\t\t/* [9] loc proto */\n+\tbtf__add_loc_proto_param(btf2, 5);\t\t/* param value */\n+\tbtf__add_loc_proto_param(btf2, 8);\t\t/* param reg 1 */\n+\tbtf__add_locsec(btf2, \"inline.text\");\t\t/* [10] locsec \"inline.text\" */\n+\t/* add duplicate locsec */\n+\tbtf__add_locsec_loc(btf2, 4, 9, 128);\n+\tbtf__add_locsec(btf2, \"inline.text\");\t\t/* [11] locsec \"inline.text\" */\n+\tbtf__add_locsec_loc(btf2, 4, 9, 128);\n+\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf2,\n+\t\t\"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED\",\n+\t\t\"[2] PTR '(anon)' type_id=1\",\n+\t\t\"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\\n\"\n+\t\t\"\\t'p1' type_id=1\\n\"\n+\t\t\"\\t'p2' type_id=2\",\n+\t\t\"[4] FUNC 'foo' type_id=3 linkage=static\",\n+\t\t\"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\\n\"\n+\t\t\"\\tvalue=3735928559\\n\"\n+\t\t\"\\tvalue=4277009102\",\n+\t\t\"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\\n\"\n+\t\t\"\\tvalue=1\",\n+\t\t\"[7] LOC_PROTO '(anon)' vlen=2\\n\"\n+\t\t\"\\ttype_id=5\\n\"\n+\t\t\"\\ttype_id=6\",\n+\t\t\"[8] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\\n\"\n+\t\t\"\\tvalue=1\",\n+\t\t\"[9] LOC_PROTO '(anon)' vlen=2\\n\"\n+\t\t\"\\ttype_id=5\\n\"\n+\t\t\"\\ttype_id=8\",\n+\t\t\"[10] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=4 loc_proto_type_id=9 offset=128\",\n+\t\t\"[11] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=4 loc_proto_type_id=9 offset=128\");\n+\n+\terr = btf__dedup(btf2, NULL);\n+\tif (!ASSERT_OK(err, \"btf_dedup\"))\n+\t\tgoto cleanup;\n+\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf2,\n+\t\t\"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED\",\n+\t\t\"[2] PTR '(anon)' type_id=1\",\n+\t\t\"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\\n\"\n+\t\t\"\\t'p1' type_id=1\\n\"\n+\t\t\"\\t'p2' type_id=2\",\n+\t\t\"[4] FUNC 'foo' type_id=3 linkage=static\",\n+\t\t\"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\\n\"\n+\t\t\"\\tvalue=3735928559\\n\"\n+\t\t\"\\tvalue=4277009102\",\n+\t\t\"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\\n\"\n+\t\t\"\\tvalue=1\",\n+\t\t\"[7] LOC_PROTO '(anon)' vlen=2\\n\"\n+\t\t\"\\ttype_id=5\\n\"\n+\t\t\"\\ttype_id=6\",\n+\t\t\"[8] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=4 loc_proto_type_id=7 offset=128\",\n+\t\t\"[9] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=4 loc_proto_type_id=7 offset=128\");\n+\n+cleanup:\n+\tbtf__free(btf2);\n+\tbtf__free(btf1);\n+}\n+\n void test_btf_dedup_split()\n {\n \tif (test__start_subtest(\"split_simple\"))\n@@ -566,4 +680,6 @@ void test_btf_dedup_split()\n \t\ttest_split_dup_struct_in_cu();\n \tif (test__start_subtest(\"split_module\"))\n \t\ttest_split_module();\n+\tif (test__start_subtest(\"split_loc\"))\n+\t\ttest_split_loc();\n }\ndiff --git a/tools/testing/selftests/bpf/prog_tests/btf_distill.c b/tools/testing/selftests/bpf/prog_tests/btf_distill.c\nindex fb67ae195a738..141a4cb1f4054 100644\n--- a/tools/testing/selftests/bpf/prog_tests/btf_distill.c\n+++ b/tools/testing/selftests/bpf/prog_tests/btf_distill.c\n@@ -671,6 +671,105 @@ static void test_distilled_base_embedded_err(void)\n \tbtf__free(btf1);\n }\n \n+/* LOC_PARAM, LOC_PROTO should be added to split BTF. */\n+static void test_distilled_loc(void)\n+{\n+\tstruct btf *btf1 = NULL, *btf2 = NULL, *btf3 = NULL;\n+\tstruct btf *btf4 = NULL, *btf5 = NULL;\n+\n+\tbtf1 = btf__new_empty();\n+\tif (!ASSERT_OK_PTR(btf1, \"empty_main_btf\"))\n+\t\treturn;\n+\n+\tbtf__add_int(btf1, \"int\", 4, BTF_INT_SIGNED);\t/* [1] int */\n+\tbtf__add_func_proto(btf1, 1);                   /* [2] int (*)(int); */\n+\tbtf__add_func_param(btf1, \"p1\", 1);\n+\tbtf__add_func(btf1, \"foo\", BTF_FUNC_STATIC, 2);\t/* [3] int foo(int); */\n+\tbtf__add_loc_param(btf1, 4, BTF_LOC_PARAM_SIGNED | BTF_LOC_PARAM_CONST);\n+\tbtf__add_loc_param_value(btf1, -1);\t\t/* [4] loc value */\n+\tbtf__add_loc_proto(btf1);\t\t\t/* [5] loc proto */\n+\tbtf__add_loc_proto_param(btf1, 4);\t\t/*  param value */\n+\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf1,\n+\t\t\"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\",\n+\t\t\"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\\n\"\n+\t\t\"\\t'p1' type_id=1\",\n+\t\t\"[3] FUNC 'foo' type_id=2 linkage=static\",\n+\t\t\"[4] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\\n\"\n+\t\t\"\\tvalue=-1\",\n+\t\t\"[5] LOC_PROTO '(anon)' vlen=1\\n\"\n+\t\t\"\\ttype_id=4\");\n+\n+\tbtf2 = btf__new_empty_split(btf1);\n+\tif (!ASSERT_OK_PTR(btf2, \"empty_split_btf\"))\n+\t\tgoto cleanup;\n+\n+\tbtf__add_locsec(btf2, \"inline.text\");\t\t/* [6] locsec */\n+\tbtf__add_locsec_loc(btf2, 3, 5, 256);\t\t/* \"foo\" offset 256 */\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf2,\n+\t\t\"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\",\n+\t\t\"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\\n\"\n+\t\t\"\\t'p1' type_id=1\",\n+\t\t\"[3] FUNC 'foo' type_id=2 linkage=static\",\n+\t\t\"[4] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\\n\"\n+\t\t\"\\tvalue=-1\",\n+\t\t\"[5] LOC_PROTO '(anon)' vlen=1\\n\"\n+\t\t\"\\ttype_id=4\",\n+\t\t\"[6] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=3 loc_proto_type_id=5 offset=256\");\n+\n+\tif (!ASSERT_EQ(0, btf__distill_base(btf2, \u0026btf3, \u0026btf4),\n+\t\t       \"distilled_base\") ||\n+\t    !ASSERT_OK_PTR(btf3, \"distilled_base\") ||\n+\t    !ASSERT_OK_PTR(btf4, \"distilled_split\") ||\n+\t    !ASSERT_EQ(2, btf__type_cnt(btf3), \"distilled_base_type_cnt\"))\n+\t\tgoto cleanup;\n+\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf4,\n+\t\t\"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\",\n+\t\t/* remainder is split BTF */\n+\t\t\"[2] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=4 loc_proto_type_id=6 offset=256\",\n+\t\t\"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\\n\"\n+\t\t\"\\t'p1' type_id=1\",\n+\t\t\"[4] FUNC 'foo' type_id=3 linkage=static\",\n+\t\t\"[5] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\\n\"\n+\t\t\"\\tvalue=-1\",\n+\t\t\"[6] LOC_PROTO '(anon)' vlen=1\\n\"\n+\t\t\"\\ttype_id=5\");\n+\n+\tbtf5 = btf__new_empty();\n+\tif (!ASSERT_OK_PTR(btf5, \"empty_reloc_btf\"))\n+\t\tgoto cleanup;\n+\tbtf__add_int(btf5, \"int\", 4, BTF_INT_SIGNED);\t/* [1] int */\n+\n+\tif (!ASSERT_EQ(btf__relocate(btf4, btf5), 0, \"relocate_split\"))\n+\t\tgoto cleanup;\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf4,\n+\t\t\"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\",\n+\t\t/* remainder is split BTF */\n+\t\t\"[2] LOCSEC 'inline.text' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=4 loc_proto_type_id=6 offset=256\",\n+\t\t\"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\\n\"\n+\t\t\"\\t'p1' type_id=1\",\n+\t\t\"[4] FUNC 'foo' type_id=3 linkage=static\",\n+\t\t\"[5] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\\n\"\n+\t\t\"\\tvalue=-1\",\n+\t\t\"[6] LOC_PROTO '(anon)' vlen=1\\n\"\n+\t\t\"\\ttype_id=5\");\n+\n+cleanup:\n+\tbtf__free(btf5);\n+\tbtf__free(btf4);\n+\tbtf__free(btf3);\n+\tbtf__free(btf2);\n+\tbtf__free(btf1);\n+}\n+\n void test_btf_distill(void)\n {\n \tif (test__start_subtest(\"distilled_base\"))\n@@ -689,4 +788,6 @@ void test_btf_distill(void)\n \t\ttest_distilled_base_vmlinux();\n \tif (test__start_subtest(\"distilled_endianness\"))\n \t\ttest_distilled_endianness();\n+\tif (test__start_subtest(\"distilled_loc\"))\n+\t\ttest_distilled_loc();\n }\ndiff --git a/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c b/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c\nindex 32159d3eb281b..dcb5429d141df 100644\n--- a/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c\n+++ b/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c\n@@ -31,8 +31,11 @@ struct field_data {\n \t{ .ids = { 11 },\t.strs = { \"decltag\" } },\n \t{ .ids = { 6 },\t\t.strs = { \"typetag\" } },\n \t{ .ids = {},\t\t.strs = { \"e64\", \"eval1\", \"eval2\", \"eval3\" } },\n-\t{ .ids = { 15, 16 },\t.strs = { \"datasec1\" } }\n-\n+\t{ .ids = { 15, 16 },\t.strs = { \"datasec1\" } },\n+\t{ .ids = {},\t\t.strs = { \"\" } },\n+\t{ .ids = {},\t\t.strs = { \"\" } },\n+\t{ .ids = { 22, 23 },\t.strs = { \"\" } },\n+\t{ .ids = { 14, 24 },\t.strs = { \".loc\" } }\n };\n \n /* Fabricate BTF with various types and check BTF field iteration finds types,\n@@ -88,6 +91,19 @@ void test_btf_field_iter(void)\n \tbtf__add_datasec_var_info(btf, 15, 0, 4);\n \tbtf__add_datasec_var_info(btf, 16, 4, 8);\n \n+\tbtf__add_loc_param(btf, 4, BTF_LOC_PARAM_CONST | BTF_LOC_PARAM_SIGNED);\n+\t\t\t\t\t\t\t/* [22] loc value -1 */\n+\tbtf__add_loc_param_value(btf, -1);\n+\tbtf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG);\t/* [23] loc reg 1 */\n+\tbtf__add_loc_param_value(btf, 1);\n+\n+\tbtf__add_loc_proto(btf);\t\t\t/* [24] loc proto */\n+\tbtf__add_loc_proto_param(btf, 22);\t\t/*  param value -1, */\n+\tbtf__add_loc_proto_param(btf, 23);\t\t/*  param reg 1 */\n+\n+\tbtf__add_locsec(btf, \".loc\");\t\t\t/* [25] locsec \".loc\" */\n+\tbtf__add_locsec_loc(btf, 14, 24, 128);\t\t/* \"func\" */\n+\n \tVALIDATE_RAW_BTF(\n \t\tbtf,\n \t\t\"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\",\n@@ -123,7 +139,16 @@ void test_btf_field_iter(void)\n \t\t\"\\t'eval3' val=3000\",\n \t\t\"[21] DATASEC 'datasec1' size=12 vlen=2\\n\"\n \t\t\"\\ttype_id=15 offset=0 size=4\\n\"\n-\t\t\"\\ttype_id=16 offset=4 size=8\");\n+\t\t\"\\ttype_id=16 offset=4 size=8\",\n+\t\t\"[22] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\\n\"\n+\t\t\"\\tvalue=-1\",\n+\t\t\"[23] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\\n\"\n+\t\t\"\\tvalue=1\",\n+\t\t\"[24] LOC_PROTO '(anon)' vlen=2\\n\"\n+\t\t\"\\ttype_id=22\\n\"\n+\t\t\"\\ttype_id=23\",\n+\t\t\"[25] LOCSEC '.loc' vlen=1\\n\"\n+\t\t\"\\tfunc_type_id=14 loc_proto_type_id=24 offset=128\");\n \n \tfor (id = 1; id \u003c btf__type_cnt(btf); id++) {\n \t\tstruct btf_type *t = btf_type_by_id(btf, id);\ndiff --git a/tools/testing/selftests/bpf/test_btf.h b/tools/testing/selftests/bpf/test_btf.h\nindex e7bc781083745..b99c04b4d26bb 100644\n--- a/tools/testing/selftests/bpf/test_btf.h\n+++ b/tools/testing/selftests/bpf/test_btf.h\n@@ -84,4 +84,20 @@\n #define BTF_TYPE_TAG_ENC(value, type)\t\\\n \tBTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)\n \n+#define BTF_LOC_PARAM_ENC(nvals, sz, flags) \\\n+\tBTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_LOC_PARAM, 0, nvals), sz), (flags)\n+\n+#define BTF_LOC_PARAM_VAL_ENCODE(val)\t(val)\n+\n+#define BTF_LOC_PROTO_ENC(nargs) \\\n+\tBTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_LOC_PROTO, 0, nargs), 0)\n+\n+#define BTF_LOC_PROTO_PARAM_ENCODE(param) (param)\n+\n+#define BTF_LOCSEC_ENC(name, nlocs) \\\n+\tBTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_LOCSEC, 0, nlocs), 0)\n+\n+#define BTF_LOCSEC_LOC_ENCODE(func, loc_proto, offset) \\\n+\t(func), (loc_proto), (offset)\n+\n #endif /* _TEST_BTF_H */\n"
}

2/1 2026/09/17 18:48 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "btf_loc_param_check_meta",
    "btf_loc_proto_check_meta",
    "btf_loc_proto_resolve",
    "btf_locsec_check_meta",
    "btf_locsec_resolve",
    "btf_new_fd"
  ],
  "Reasoning": "The patch introduces support for new BTF types (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, and BTF_KIND_LOCSEC) in the BPF subsystem, adding metadata validation, logging, and type resolution logic in kernel/bpf/btf.c. This code is directly reachable by user space via the BPF_BTF_LOAD command of the bpf() system call. Fuzzing is warranted to test bounds checking, type resolution, and validation of malformed BTF data.",
  "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 63a3bf6e1b250d9153a70283b74731c455e0fbc1
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Sep 17 18:48:12 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
index 004aa1058d857..70ab6ad608ae5 100644
--- a/Documentation/bpf/btf.rst
+++ b/Documentation/bpf/btf.rst
@@ -88,6 +88,9 @@ sequentially and type id is assigned to each recognized type starting from id
     #define BTF_KIND_DECL_TAG       17      /* Decl Tag     */
     #define BTF_KIND_TYPE_TAG       18      /* Type Tag     */
     #define BTF_KIND_ENUM64         19      /* Enumeration up to 64-bit values */
+    #define BTF_KIND_LOC_PARAM      20      /* Location description (register, const etc) */
+    #define BTF_KIND_LOC_PROTO      21      /* Set of location parameters for site */
+    #define BTF_KIND_LOCSEC         22      /* Section with site descriptions */
 
 Note that the type section encodes debug info, not just pure types.
 ``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram.
@@ -104,11 +107,13 @@ Each type contains the following common data::
          *             decl_tag and type_tag
          */
         __u32 info;
-        /* "size" is used by INT, ENUM, STRUCT, UNION and ENUM64.
+        /* "size" is used by INT, ENUM, STRUCT, UNION, ENUM64 and
+         * LOC_PARAM.
          * "size" tells the size of the type it is describing.
          *
          * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
-         * FUNC, FUNC_PROTO, DECL_TAG and TYPE_TAG.
+         * FUNC, FUNC_PROTO, DECL_TAG and TYPE_TAG. It is unused by
+         * LOC_PROTO and LOCSEC.
          * "type" is a type_id referring to another type.
          */
         union {
@@ -563,6 +568,77 @@ The ``btf_enum64`` encoding:
 If the original enum value is signed and the size is less than 8,
 that value will be sign extended into 8 bytes.
 
+2.2.20 BTF_KIND_LOC_PARAM
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``struct btf_type`` encoding requirement:
+  * ``name_off``: 0
+  * ``info.kind_flag``: 0
+  * ``info.kind``: BTF_KIND_LOC_PARAM
+  * ``info.vlen``: number of 32-bit location value words
+  * ``size``: size in bytes of the represented parameter: 1, 2, 4, 8 or 16
+
+``btf_type`` is followed by a ``struct btf_loc_param`` and ``info.vlen``
+number of 32-bit value words.::
+
+    struct btf_loc_param {
+        __u32 flags;
+        __u32 values[];
+    };
+
+The ``flags`` field describes how to interpret ``values``:
+
+  * ``BTF_LOC_PARAM_CONST`` describes a constant; the value is stored in
+    low-word, high-word order when it requires 64 bits.
+  * ``BTF_LOC_PARAM_ADDR | BTF_LOC_PARAM_CONST`` describes an address to be
+    normalized relative to the kernel or module base address.
+  * ``BTF_LOC_PARAM_REG`` with one word describes a register number; with two
+    words it describes a multi-register parameter.
+  * ``BTF_LOC_PARAM_REG | BTF_LOC_PARAM_OFFSET`` describes an address held in
+    a register plus an offset. Adding ``BTF_LOC_PARAM_DEREF`` dereferences
+    that address. ``BTF_LOC_PARAM_REG | BTF_LOC_PARAM_DEREF`` with one word
+    dereferences the value held in the register.
+  * ``BTF_LOC_PARAM_SIGNED`` makes a constant or offset signed.
+
+2.2.21 BTF_KIND_LOC_PROTO
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``struct btf_type`` encoding requirement:
+  * ``name_off``: 0
+  * ``info.kind_flag``: 0
+  * ``info.kind``: BTF_KIND_LOC_PROTO
+  * ``info.vlen``: number of function parameter locations
+  * ``type``: 0
+
+``btf_type`` is followed by ``info.vlen`` number of ``__u32`` BTF type IDs.
+Each entry corresponds to a function parameter at an inline site. An entry is
+either 0, meaning that no location information is available, or the type ID
+of a ``BTF_KIND_LOC_PARAM``.
+
+2.2.22 BTF_KIND_LOCSEC
+~~~~~~~~~~~~~~~~~~~~~~
+
+``struct btf_type`` encoding requirement:
+  * ``name_off``: offset to a valid ELF section name
+  * ``info.kind_flag``: 0
+  * ``info.kind``: BTF_KIND_LOCSEC
+  * ``info.vlen``: number of inline sites in the section
+  * ``type``: 0
+
+``btf_type`` is followed by ``info.vlen`` number of ``struct btf_loc``.::
+
+    struct btf_loc {
+        __u32 func;
+        __u32 loc_proto;
+        __u32 offset;
+    };
+
+The ``func`` field is the non-zero type ID of the ``BTF_KIND_FUNC`` being
+described. ``loc_proto`` is the non-zero type ID of the associated
+``BTF_KIND_LOC_PROTO``. ``offset`` is the location address offset relative to
+the kernel or module base address. A LOCSEC named ``inline.text``, for example,
+contains inline-site records for the ``.text`` section.
+
 2.3 Constant Values
 -------------------
 
diff --git a/include/linux/btf.h b/include/linux/btf.h
index ddd0f4f32d24b..f29ed358b7a8c 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -261,6 +261,11 @@ const char *btf_type_str(const struct btf_type *t);
 	     i < btf_type_vlen(datasec_type);			\
 	     i++, member++)
 
+#define for_each_loc(i, locsec_type, member)			\
+	for (i = 0, member = btf_type_loc_secinfo(locsec_type);	\
+	     i < btf_type_vlen(locsec_type);			\
+	     i++, member++)
+
 static inline bool btf_type_is_ptr(const struct btf_type *t)
 {
 	return BTF_INFO_KIND(t->info) == BTF_KIND_PTR;
@@ -329,6 +334,21 @@ static inline u64 btf_enum64_value(const struct btf_enum64 *e)
 	return ((u64)e->val_hi32 << 32) | e->val_lo32;
 }
 
+static inline struct btf_loc_param *btf_loc_param(const struct btf_type *t)
+{
+	return (struct btf_loc_param *)(t + 1);
+}
+
+static inline __u32 *btf_loc_proto_params(const struct btf_type *t)
+{
+	return (__u32 *)(t + 1);
+}
+
+static inline struct btf_loc *btf_type_loc_secinfo(const struct btf_type *t)
+{
+	return (struct btf_loc *)(t + 1);
+}
+
 static inline bool btf_is_composite(const struct btf_type *t)
 {
 	u16 kind = btf_kind(t);
@@ -559,7 +579,7 @@ struct btf_field_desc {
 	/* member struct size, or zero, if no members */
 	int m_sz;
 	/* repeated per-member offsets */
-	int m_off_cnt, m_offs[1];
+	int m_off_cnt, m_offs[2];
 };
 
 struct btf_field_iter {
diff --git a/include/uapi/linux/btf.h b/include/uapi/linux/btf.h
index 618167cab4e61..a85d293f4127f 100644
--- a/include/uapi/linux/btf.h
+++ b/include/uapi/linux/btf.h
@@ -92,7 +92,9 @@ enum {
 	BTF_KIND_DECL_TAG	= 17,	/* Decl Tag */
 	BTF_KIND_TYPE_TAG	= 18,	/* Type Tag */
 	BTF_KIND_ENUM64		= 19,	/* Enumeration up to 64-bit values */
-
+	BTF_KIND_LOC_PARAM	= 20,	/* Location parameter information */
+	BTF_KIND_LOC_PROTO	= 21,	/* Location prototype for site */
+	BTF_KIND_LOCSEC		= 22,	/* Location section */
 	NR_BTF_KINDS,
 	BTF_KIND_MAX		= NR_BTF_KINDS - 1,
 };
@@ -212,4 +214,65 @@ struct btf_enum64 {
 	__u32	val_hi32;
 };
 
+/*
+ * BTF_KIND_LOC_PARAM is followed by a single "struct btf_loc_param"
+ * that contains flags specifying the contents of the vlen-specified
+ * number of 4-byte values that follow.
+ */
+struct btf_loc_param {
+	__u32 flags;
+	__u32 values[];
+};
+
+/*
+ * The combination of size, vlen and flags gives us the means to interpret
+ * the following vlen-specified set of 4-byte values:
+ *
+ * - a BTF_LOC_PARAM_CONST is a constant value; combination
+ *   of size, vlen and _SIGNED flag determines it. If the value requires
+ *   64 bits it is stored in {lo,hi} order.
+ * - a BTF_LOC_PARAM_ADDR|BTF_LOC_PARAM_CONST is an address that should be
+ *   normalized with respect to kernel/module base address.
+ * - a BTF_LOC_PARAM_REG with vlen 1 is a simple register number;
+ *   with vlen 2 it is a multi-register parameter.
+ * - a _REG | OFFSET describes an address without dereferencing it.
+ * - a _REG | DEREF with vlen 1 dereferences the value in the register
+ *   number specified.
+ * - a REG | DEREF | OFFSET with vlen specifies the register value in
+ *   the first 4-byte value and the offset in the remainder.
+ */
+enum btf_loc_param_flags {
+	BTF_LOC_PARAM_SIGNED		=	0x1,
+	BTF_LOC_PARAM_CONST		=	0x2,
+	BTF_LOC_PARAM_ADDR		=	0x4,
+	BTF_LOC_PARAM_REG		=	0x8,
+	BTF_LOC_PARAM_DEREF		=	0x10,
+	BTF_LOC_PARAM_OFFSET		=	0x20,
+};
+
+/*
+ * BTF_KIND_LOC_PROTO specifies location prototypes; i.e. how locations relate
+ * to parameters; a struct btf_type of BTF_KIND_LOC_PROTO is followed by a
+ * vlen-specified number of __u32 BTF type ids which specify the associated
+ * BTF_KIND_LOC_PARAM for each function parameter associated with the
+ * location.  The type should either be 0 (no location info) or point at
+ * a BTF_KIND_LOC_PARAM.
+ */
+
+/*
+ * BTF_KIND_LOCSEC consists of vlen-specified number of "struct btf_loc"
+ * containing location site-specific information for a specific ELF section;
+ * for example locations in ".text" are in a LOCSEC named "inline.text".
+ *
+ * - function (func)
+ * - location prototype type id (loc_proto)
+ * - address offset (offset) relative to kernel base address
+ */
+
+struct btf_loc {
+	__u32 func;
+	__u32 loc_proto;
+	__u32 offset;
+};
+
 #endif /* _UAPI__LINUX_BTF_H__ */
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 7daf4c286c9b2..af5f161b5bddc 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -345,6 +345,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
 	[BTF_KIND_DECL_TAG]	= "DECL_TAG",
 	[BTF_KIND_TYPE_TAG]	= "TYPE_TAG",
 	[BTF_KIND_ENUM64]	= "ENUM64",
+	[BTF_KIND_LOC_PARAM]	= "LOC_PARAM",
+	[BTF_KIND_LOC_PROTO]	= "LOC_PROTO",
+	[BTF_KIND_LOCSEC]	= "LOCSEC",
 };
 
 const char *btf_type_str(const struct btf_type *t)
@@ -517,11 +520,27 @@ static bool btf_type_is_decl_tag(const struct btf_type *t)
 	return BTF_INFO_KIND(t->info) == BTF_KIND_DECL_TAG;
 }
 
+static bool btf_type_is_loc_param(const struct btf_type *t)
+{
+	return BTF_INFO_KIND(t->info) == BTF_KIND_LOC_PARAM;
+}
+
+static bool btf_type_is_loc_proto(const struct btf_type *t)
+{
+	return BTF_INFO_KIND(t->info) == BTF_KIND_LOC_PROTO;
+}
+
+static bool btf_type_is_locsec(const struct btf_type *t)
+{
+	return BTF_INFO_KIND(t->info) == BTF_KIND_LOCSEC;
+}
+
 static bool btf_type_nosize(const struct btf_type *t)
 {
 	return btf_type_is_void(t) || btf_type_is_fwd(t) ||
 	       btf_type_is_func(t) || btf_type_is_func_proto(t) ||
-	       btf_type_is_decl_tag(t);
+	       btf_type_is_decl_tag(t) || btf_type_is_loc_param(t) ||
+	       btf_type_is_loc_proto(t) || btf_type_is_locsec(t);
 }
 
 static bool btf_type_nosize_or_null(const struct btf_type *t)
@@ -796,7 +815,9 @@ static bool btf_type_needs_resolve(const struct btf_type *t)
 	       btf_type_is_var(t) ||
 	       btf_type_is_func(t) ||
 	       btf_type_is_decl_tag(t) ||
-	       btf_type_is_datasec(t);
+	       btf_type_is_datasec(t) ||
+	       btf_type_is_loc_proto(t) ||
+	       btf_type_is_locsec(t);
 }
 
 /* t->size can be used */
@@ -4729,6 +4750,279 @@ static const struct btf_kind_operations enum64_ops = {
 	.show = btf_enum64_show,
 };
 
+static s32 btf_loc_param_check_meta(struct btf_verifier_env *env,
+				    const struct btf_type *t,
+				    u32 meta_left)
+{
+	const struct btf_loc_param *p = btf_loc_param(t);
+	u32 size, meta_needed, vlen = btf_vlen(t);
+
+	meta_needed = sizeof(*p) + sizeof(__u32) * vlen;
+	if (meta_left < meta_needed) {
+		btf_verifier_log_basic(env, t,
+				       "meta_left:%u meta_needed:%u",
+				      meta_left, meta_needed);
+		return -EINVAL;
+	}
+
+	if (t->name_off) {
+		btf_verifier_log_type(env, t, "Invalid name");
+		return -EINVAL;
+	}
+	size = t->size;
+	if (size > 16 || !is_power_of_2(size)) {
+		btf_verifier_log_type(env, t, "Unexpected size");
+		return -EINVAL;
+	}
+
+	if (btf_type_kflag(t)) {
+		btf_verifier_log_type(env, t, "Invalid btf_info kind_flag");
+		return -EINVAL;
+	}
+
+	btf_verifier_log_type(env, t, NULL);
+
+	return meta_needed;
+}
+
+static void btf_loc_param_log(struct btf_verifier_env *env,
+			 const struct btf_type *t)
+{
+	const struct btf_loc_param *p = btf_loc_param(t);
+	u32 i, vlen = btf_vlen(t);
+
+	btf_verifier_log(env, "size=%u vlen=%u flags=0x%x", t->size, vlen, p->flags);
+	for (i = 0; i < vlen; i++)
+		btf_verifier_log(env, ", %u", p->values[i]);
+}
+
+static const struct btf_kind_operations loc_param_ops = {
+	.check_meta = btf_loc_param_check_meta,
+	.resolve = btf_df_resolve,
+	.check_member = btf_df_check_member,
+	.check_kflag_member = btf_df_check_kflag_member,
+	.log_details = btf_loc_param_log,
+	.show = btf_df_show,
+};
+
+static s32 btf_loc_proto_check_meta(struct btf_verifier_env *env,
+				    const struct btf_type *t,
+				    u32 meta_left)
+{
+	u32 meta_needed;
+
+	meta_needed = sizeof(__u32) * btf_type_vlen(t);
+
+	if (meta_left < meta_needed) {
+		btf_verifier_log_basic(env, t,
+				       "meta_left:%u meta_needed:%u",
+				      meta_left, meta_needed);
+		return -EINVAL;
+	}
+
+	if (t->name_off) {
+		btf_verifier_log_type(env, t, "Invalid name");
+		return -EINVAL;
+	}
+
+	if (btf_type_kflag(t)) {
+		btf_verifier_log_type(env, t, "Invalid btf_info kind_flag");
+		return -EINVAL;
+	}
+
+	btf_verifier_log_type(env, t, NULL);
+
+	return meta_needed;
+}
+
+static void btf_loc_proto_log(struct btf_verifier_env *env,
+			      const struct btf_type *t)
+{
+	const __u32 *params = btf_loc_proto_params(t);
+	u32 i, nr_params = btf_type_vlen(t);
+
+	btf_verifier_log(env, "vlen=%u", nr_params);
+	for (i = 0; i < nr_params; i++, params++)
+		btf_verifier_log(env, ", %u", *params);
+}
+
+static int btf_loc_proto_resolve(struct btf_verifier_env *env,
+				 const struct resolve_vertex *v)
+{
+	const struct btf_type *t = v->t;
+	const __u32 *params = btf_loc_proto_params(t);
+	u32 i, nr_params = btf_type_vlen(t);
+	struct btf *btf = env->btf;
+
+	if (t->type) {
+		btf_verifier_log_type(env, t, "Invalid loc_proto type");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < nr_params; i++) {
+		const struct btf_type *param_type;
+		u32 param_type_id = params[i];
+
+		if (!param_type_id)
+			continue;
+
+		param_type = btf_type_by_id(btf, param_type_id);
+		if (!param_type || !btf_type_is_loc_param(param_type)) {
+			btf_verifier_log_type(env, t,
+					      "Invalid loc_param#%u", i + 1);
+			return -EINVAL;
+		}
+	}
+
+	env_stack_pop_resolved(env, 0, 0);
+	return 0;
+}
+
+static const struct btf_kind_operations loc_proto_ops = {
+	.check_meta = btf_loc_proto_check_meta,
+	.resolve = btf_loc_proto_resolve,
+	.check_member = btf_df_check_member,
+	.check_kflag_member = btf_df_check_kflag_member,
+	.log_details = btf_loc_proto_log,
+	.show = btf_df_show,
+};
+
+__printf(4, 5)
+static void btf_verifier_log_loc(struct btf_verifier_env *env,
+				 const struct btf_type *locsec_type,
+				 const struct btf_loc *loc,
+				 const char *fmt, ...)
+{
+	struct bpf_verifier_log *log = &env->log;
+	va_list args;
+
+	if (!bpf_verifier_log_needed(log))
+		return;
+	if (log->level == BPF_LOG_KERNEL && !fmt)
+		return;
+	if (env->phase != CHECK_META)
+		btf_verifier_log_type(env, locsec_type, NULL);
+
+	__btf_verifier_log(log, "\t func=%u loc_proto=%u offset=%u",
+			   loc->func, loc->loc_proto, loc->offset);
+	if (fmt && *fmt) {
+		__btf_verifier_log(log, " ");
+		va_start(args, fmt);
+		bpf_verifier_vlog(log, fmt, args);
+		va_end(args);
+	}
+
+	__btf_verifier_log(log, "\n");
+}
+
+static s32 btf_locsec_check_meta(struct btf_verifier_env *env,
+				 const struct btf_type *t,
+				 u32 meta_left)
+{
+	u32 i, meta_needed, vlen = btf_type_vlen(t);
+	const struct btf_loc *loc;
+
+	meta_needed = sizeof(struct btf_loc) * vlen;
+
+	if (meta_left < meta_needed) {
+		btf_verifier_log_basic(env, t,
+				       "meta_left:%u meta_needed:%u",
+				       meta_left, meta_needed);
+		return -EINVAL;
+	}
+
+	if (btf_type_kflag(t)) {
+		btf_verifier_log_type(env, t, "Invalid btf_info kind_flag");
+		return -EINVAL;
+	}
+
+	if (!t->name_off ||
+	    !btf_name_valid_section(env->btf, t->name_off)) {
+		btf_verifier_log_type(env, t, "Invalid name");
+		return -EINVAL;
+	}
+
+	for_each_loc(i, t, loc) {
+		/* A loc func, loc proto cannot be in type void */
+		if (!loc->func || !BTF_TYPE_ID_VALID(loc->func)) {
+			btf_verifier_log_loc(env, t, loc, "Invalid func");
+			return -EINVAL;
+		}
+		if (!loc->loc_proto || !BTF_TYPE_ID_VALID(loc->loc_proto)) {
+			btf_verifier_log_loc(env, t, loc, "Invalid loc_proto");
+			return -EINVAL;
+		}
+		btf_verifier_log_loc(env, t, loc, NULL);
+	}
+
+	return meta_needed;
+}
+
+static void btf_locsec_log(struct btf_verifier_env *env,
+			   const struct btf_type *t)
+{
+	btf_verifier_log(env, "vlen=%u", btf_type_vlen(t));
+}
+
+static int btf_locsec_resolve(struct btf_verifier_env *env,
+			      const struct resolve_vertex *v)
+{
+	const struct btf_type *t = v->t;
+	const struct btf_loc *loc;
+	struct btf *btf = env->btf;
+	u32 i;
+
+	if (t->type) {
+		btf_verifier_log_type(env, t, "Invalid locsec type");
+		return -EINVAL;
+	}
+
+	env->resolve_mode = RESOLVE_TBD;
+	for (i = v->next_member, loc = btf_type_loc_secinfo(t) + i;
+	     i < btf_type_vlen(t); i++, loc++) {
+		const struct btf_type *func_type, *loc_proto_type;
+		u32 func_type_id = loc->func;
+		u32 loc_proto_type_id = loc->loc_proto;
+
+		func_type = btf_type_by_id(btf, func_type_id);
+		if (!func_type || !btf_type_is_func(func_type)) {
+			btf_verifier_log_type(env, t,
+					      "Invalid func#%u", i + 1);
+			return -EINVAL;
+		}
+
+		if (!env_type_is_resolved(env, func_type_id)) {
+			env_stack_set_next_member(env, i);
+			return env_stack_push(env, func_type, func_type_id);
+		}
+
+		loc_proto_type = btf_type_by_id(btf, loc_proto_type_id);
+		if (!loc_proto_type || !btf_type_is_loc_proto(loc_proto_type)) {
+			btf_verifier_log_type(env, t,
+					      "Invalid loc_proto#%u", i + 1);
+			return -EINVAL;
+		}
+
+		if (!env_type_is_resolved(env, loc_proto_type_id)) {
+			env_stack_set_next_member(env, i + 1);
+			return env_stack_push(env, loc_proto_type,
+					      loc_proto_type_id);
+		}
+	}
+
+	env_stack_pop_resolved(env, 0, 0);
+	return 0;
+}
+
+static const struct btf_kind_operations locsec_ops = {
+	.check_meta = btf_locsec_check_meta,
+	.resolve = btf_locsec_resolve,
+	.check_member = btf_df_check_member,
+	.check_kflag_member = btf_df_check_kflag_member,
+	.log_details = btf_locsec_log,
+	.show = btf_df_show,
+};
+
 static s32 btf_func_proto_check_meta(struct btf_verifier_env *env,
 				     const struct btf_type *t,
 				     u32 meta_left)
@@ -5398,6 +5692,9 @@ static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {
 	[BTF_KIND_DECL_TAG] = &decl_tag_ops,
 	[BTF_KIND_TYPE_TAG] = &modifier_ops,
 	[BTF_KIND_ENUM64] = &enum64_ops,
+	[BTF_KIND_LOC_PARAM] = &loc_param_ops,
+	[BTF_KIND_LOC_PROTO] = &loc_proto_ops,
+	[BTF_KIND_LOCSEC] = &locsec_ops,
 };
 
 static s32 btf_check_meta(struct btf_verifier_env *env,
@@ -5472,7 +5769,8 @@ static bool btf_resolve_valid(struct btf_verifier_env *env,
 	if (!env_type_is_resolved(env, type_id))
 		return false;
 
-	if (btf_type_is_struct(t) || btf_type_is_datasec(t))
+	if (btf_type_is_struct(t) || btf_type_is_datasec(t) ||
+	    btf_type_is_loc_proto(t) || btf_type_is_locsec(t))
 		return !btf_resolved_type_id(btf, type_id) &&
 		       !btf_resolved_type_size(btf, type_id);
 
diff --git a/tools/bpf/bpftool/Documentation/bpftool-btf.rst b/tools/bpf/bpftool/Documentation/bpftool-btf.rst
index cf75a7fa2d6bc..c6dc445cd4a19 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-btf.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-btf.rst
@@ -16,7 +16,7 @@ SYNOPSIS
 
 **bpftool** [*OPTIONS*] **btf** *COMMAND*
 
-*OPTIONS* := { |COMMON_OPTIONS| | { **-B** | **--base-btf** } }
+*OPTIONS* := { |COMMON_OPTIONS| | [{ **-B** | **--base-btf**} *FILE*]...  }
 
 *COMMANDS* := { **dump** | **help** }
 
@@ -87,7 +87,10 @@ OPTIONS
     objects for kernel modules. To avoid duplicating all kernel symbols
     required by modules, BTF objects for modules are "split", they are
     built incrementally on top of the kernel (vmlinux) BTF object. So the
-    base BTF reference should usually point to the kernel BTF.
+    base BTF reference should usually point to the kernel BTF.  Multiple
+    base BTF objects can be passed, where the first is assumed to be the
+    root BTF, followed by split BTF based upon it, followed by split
+    BTF based upon the first split BTF and so on.
 
     When the main BTF object to process (for example, the module BTF to
     dump) is passed as a *FILE*, bpftool attempts to autodetect the path
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index bca0a3982f09b..5e0cb58628117 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -51,6 +51,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
 	[BTF_KIND_DECL_TAG]	= "DECL_TAG",
 	[BTF_KIND_TYPE_TAG]	= "TYPE_TAG",
 	[BTF_KIND_ENUM64]	= "ENUM64",
+	[BTF_KIND_LOC_PARAM]	= "LOC_PARAM",
+	[BTF_KIND_LOC_PROTO]	= "LOC_PROTO",
+	[BTF_KIND_LOCSEC]	= "LOCSEC",
 };
 
 struct sort_datum {
@@ -117,6 +120,83 @@ static int btf_kind_safe(int kind)
 	return kind <= BTF_KIND_MAX ? kind : BTF_KIND_UNKN;
 }
 
+static void btf_loc_param_str(const struct btf_type *t, char *str, size_t sz)
+{
+	const struct btf_loc_param *p;
+	__u32 i = 0, vlen;
+	__u64 value;
+	bool negative = false;
+	char regs[32] = {};
+	char num[32] = {};
+	const char *op = "";
+
+	if (!t || !btf_is_loc_param(t)) {
+		snprintf(str, sz, "<invalid>");
+		return;
+	}
+
+	p = btf_loc_param(t);
+	vlen = btf_vlen(t);
+
+	if (p->flags & BTF_LOC_PARAM_REG) {
+		__u32 nregs = (p->flags == BTF_LOC_PARAM_REG) ? vlen : 1;
+
+		if (nregs > vlen) {
+			snprintf(str, sz, "?");
+			return;
+		}
+
+		switch (nregs) {
+		case 2:
+			snprintf(regs, sizeof(regs), "r%u, r%u",
+				 p->values[0], p->values[1]);
+			break;
+		case 1:
+			snprintf(regs, sizeof(regs), "r%u", p->values[0]);
+			break;
+		default:
+			snprintf(regs, sizeof(regs), "?");
+			break;
+		}
+		i += nregs;
+	}
+	if (p->flags & (BTF_LOC_PARAM_CONST|BTF_LOC_PARAM_OFFSET)) {
+		switch (vlen - i) {
+		case 1:
+			value = p->values[i];
+			break;
+		case 2:
+			value = ((__u64)p->values[i + 1] << 32) | p->values[i];
+			break;
+		default:
+			snprintf(num, sizeof(num), "?");
+			goto done;
+		}
+		if ((p->flags & BTF_LOC_PARAM_SIGNED) && t->size &&
+		    t->size <= sizeof(value)) {
+			__u32 bits = t->size * 8;
+
+			if (t->size < sizeof(value))
+				value &= (1ULL << bits) - 1;
+			negative = value & (1ULL << (bits - 1));
+			if (negative)
+				value = t->size == sizeof(value) ? -value :
+					(1ULL << bits) - value;
+		}
+		snprintf(num, sizeof(num), "0x%llx", (unsigned long long)value);
+	}
+	if (num[0])
+		op = regs[0] ? (negative ? " - " : " + ") : negative ? "-" : "";
+
+done:
+	snprintf(str, sz, "%s%s%s%s%s",
+		 p->flags & BTF_LOC_PARAM_DEREF ? "*(" : "",
+		 regs,
+		 op,
+		 num,
+		 p->flags & BTF_LOC_PARAM_DEREF ? ")" : "");
+}
+
 static int dump_btf_type(const struct btf *btf, __u32 id,
 			 const struct btf_type *t)
 {
@@ -415,6 +495,95 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 		}
 		break;
 	}
+	case BTF_KIND_LOC_PARAM: {
+		const struct btf_loc_param *p = btf_loc_param(t);
+		__u32 vlen = btf_vlen(t);
+		char param_str[256] = {};
+
+		btf_loc_param_str(t, param_str, sizeof(param_str));
+
+		if (json_output) {
+			jsonw_uint_field(w, "size", t->size);
+			jsonw_uint_field(w, "flags", p->flags);
+			jsonw_uint_field(w, "vlen", vlen);
+			jsonw_string_field(w, "values", param_str);
+		} else {
+			printf(" size=%u flags=0x%x vlen=%u values='%s'", t->size, p->flags, vlen, param_str);
+		}
+		break;
+	}
+	case BTF_KIND_LOC_PROTO: {
+		__u32 *params = btf_loc_proto_params(t);
+		__u16 vlen = btf_vlen(t);
+		int i;
+
+		if (json_output) {
+			jsonw_uint_field(w, "vlen", vlen);
+			jsonw_name(w, "params");
+			jsonw_start_array(w);
+		} else {
+			printf(" vlen=%u", vlen);
+		}
+
+		for (i = 0; i < vlen; i++, params++) {
+			const struct btf_type *p;
+			char param_str[256] = {};
+
+			if (*params) {
+				p = btf__type_by_id(btf, *params);
+				btf_loc_param_str(p, param_str, sizeof(param_str));
+			} else {
+				snprintf(param_str, sizeof(param_str), "<unavailable>");
+			}
+			if (json_output) {
+				jsonw_start_object(w);
+				jsonw_uint_field(w, "type_id", *params);
+				jsonw_string_field(w, "value", param_str);
+				jsonw_end_object(w);
+			} else {
+				printf("\n\ttype_id=%u value='%s'", *params, param_str);
+			}
+		}
+		if (json_output)
+			jsonw_end_array(w);
+		break;
+	}
+
+	case BTF_KIND_LOCSEC: {
+		struct btf_loc *locs = btf_locsec_locs(t);
+		__u32 i, vlen = btf_vlen(t);
+
+		if (json_output) {
+			jsonw_uint_field(w, "vlen", vlen);
+			jsonw_name(w, "locs");
+			jsonw_start_array(w);
+		} else {
+			printf(" vlen=%u", vlen);
+		}
+
+		for (i = 0; i < vlen; i++, locs++) {
+			const struct btf_type *f = btf__type_by_id(btf, locs->func);
+			const char *name = "<invalid>";
+
+			if (f && btf_is_func(f))
+				name = btf_str(btf, f->name_off);
+
+			if (json_output) {
+				jsonw_start_object(w);
+				jsonw_uint_field(w, "func_type_id", locs->func);
+				jsonw_string_field(w, "name", name);
+				jsonw_uint_field(w, "loc_proto_type_id", locs->loc_proto);
+				jsonw_uint_field(w, "offset", locs->offset);
+				jsonw_end_object(w);
+			} else {
+				printf("\n\tname='%s' func_type_id=%u loc_proto_type_id=%u offset=%u",
+				       name, locs->func, locs->loc_proto, locs->offset);
+			}
+		}
+		if (json_output)
+			jsonw_end_array(w);
+		break;
+	}
 	default:
 		break;
 	}
@@ -1545,7 +1714,7 @@ static int do_help(int argc, char **argv)
 		"       " HELP_SPEC_MAP "\n"
 		"       " HELP_SPEC_PROGRAM "\n"
 		"       " HELP_SPEC_OPTIONS " |\n"
-		"                    {-B|--base-btf} }\n"
+		"                    {[{-B|--base-btf} FILE]... }\n"
 		"",
 		bin_name, "btf");
 
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 5ababd8f7d0a0..cff76be7d2e86 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -466,6 +466,7 @@ int main(int argc, char **argv)
 		{ "base-btf",	required_argument, NULL, 'B' },
 		{ 0 }
 	};
+	struct btf *new_base_btf = NULL, *root_base_btf = NULL;
 	bool version_requested = false;
 	int opt, ret;
 
@@ -515,12 +516,16 @@ int main(int argc, char **argv)
 			verifier_logs = true;
 			break;
 		case 'B':
-			base_btf = btf__parse(optarg, NULL);
-			if (!base_btf) {
+			/* handle multi-split BTF */
+			new_base_btf = btf__parse_split(optarg, base_btf);
+			if (!new_base_btf) {
 				p_err("failed to parse base BTF at '%s': %d\n",
 				      optarg, -errno);
 				return -1;
 			}
+			base_btf = new_base_btf;
+			if (!root_base_btf)
+				root_base_btf = base_btf;
 			break;
 		case 'L':
 			use_loader = true;
@@ -567,7 +572,18 @@ int main(int argc, char **argv)
 	if (json_output)
 		jsonw_destroy(&json_wtr);
 
-	btf__free(base_btf);
+	while (base_btf) {
+		new_base_btf = (struct btf *)btf__base_btf(base_btf);
+		btf__free(base_btf);
+		/*
+		 * Do not free base BTF that is an owned .BTF.base ; leads
+		 * to a double-free, so only free as far as the root base
+		 * we explicitly read with -B above.
+		 */
+		if (base_btf == root_base_btf)
+			break;
+		base_btf = new_base_btf;
+	}
 
 	return ret;
 }
diff --git a/tools/include/uapi/linux/btf.h b/tools/include/uapi/linux/btf.h
index 618167cab4e61..a85d293f4127f 100644
--- a/tools/include/uapi/linux/btf.h
+++ b/tools/include/uapi/linux/btf.h
@@ -92,7 +92,9 @@ enum {
 	BTF_KIND_DECL_TAG	= 17,	/* Decl Tag */
 	BTF_KIND_TYPE_TAG	= 18,	/* Type Tag */
 	BTF_KIND_ENUM64		= 19,	/* Enumeration up to 64-bit values */
-
+	BTF_KIND_LOC_PARAM	= 20,	/* Location parameter information */
+	BTF_KIND_LOC_PROTO	= 21,	/* Location prototype for site */
+	BTF_KIND_LOCSEC		= 22,	/* Location section */
 	NR_BTF_KINDS,
 	BTF_KIND_MAX		= NR_BTF_KINDS - 1,
 };
@@ -212,4 +214,65 @@ struct btf_enum64 {
 	__u32	val_hi32;
 };
 
+/*
+ * BTF_KIND_LOC_PARAM is followed by a single "struct btf_loc_param"
+ * that contains flags specifying the contents of the vlen-specified
+ * number of 4-byte values that follow.
+ */
+struct btf_loc_param {
+	__u32 flags;
+	__u32 values[];
+};
+
+/*
+ * The combination of size, vlen and flags gives us the means to interpret
+ * the following vlen-specified set of 4-byte values:
+ *
+ * - a BTF_LOC_PARAM_CONST is a constant value; combination
+ *   of size, vlen and _SIGNED flag determines it. If the value requires
+ *   64 bits it is stored in {lo,hi} order.
+ * - a BTF_LOC_PARAM_ADDR|BTF_LOC_PARAM_CONST is an address that should be
+ *   normalized with respect to kernel/module base address.
+ * - a BTF_LOC_PARAM_REG with vlen 1 is a simple register number;
+ *   with vlen 2 it is a multi-register parameter.
+ * - a _REG | OFFSET describes an address without dereferencing it.
+ * - a _REG | DEREF with vlen 1 dereferences the value in the register
+ *   number specified.
+ * - a REG | DEREF | OFFSET with vlen specifies the register value in
+ *   the first 4-byte value and the offset in the remainder.
+ */
+enum btf_loc_param_flags {
+	BTF_LOC_PARAM_SIGNED		=	0x1,
+	BTF_LOC_PARAM_CONST		=	0x2,
+	BTF_LOC_PARAM_ADDR		=	0x4,
+	BTF_LOC_PARAM_REG		=	0x8,
+	BTF_LOC_PARAM_DEREF		=	0x10,
+	BTF_LOC_PARAM_OFFSET		=	0x20,
+};
+
+/*
+ * BTF_KIND_LOC_PROTO specifies location prototypes; i.e. how locations relate
+ * to parameters; a struct btf_type of BTF_KIND_LOC_PROTO is followed by a
+ * vlen-specified number of __u32 BTF type ids which specify the associated
+ * BTF_KIND_LOC_PARAM for each function parameter associated with the
+ * location.  The type should either be 0 (no location info) or point at
+ * a BTF_KIND_LOC_PARAM.
+ */
+
+/*
+ * BTF_KIND_LOCSEC consists of vlen-specified number of "struct btf_loc"
+ * containing location site-specific information for a specific ELF section;
+ * for example locations in ".text" are in a LOCSEC named "inline.text".
+ *
+ * - function (func)
+ * - location prototype type id (loc_proto)
+ * - address offset (offset) relative to kernel base address
+ */
+
+struct btf_loc {
+	__u32 func;
+	__u32 loc_proto;
+	__u32 offset;
+};
+
 #endif /* _UAPI__LINUX_BTF_H__ */
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 908bd344229d5..332a8388fcc41 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -57,6 +57,9 @@ static struct btf_layout layouts[NR_BTF_KINDS] = {
 [BTF_KIND_DECL_TAG] =	{	sizeof(struct btf_decl_tag),	0,				0 },
 [BTF_KIND_TYPE_TAG] =	{	0,				0,				0 },
 [BTF_KIND_ENUM64] =	{	0,				sizeof(struct btf_enum64),	0 },
+[BTF_KIND_LOC_PARAM] =	{	sizeof(struct btf_loc_param),	sizeof(__u32),			0 },
+[BTF_KIND_LOC_PROTO] =	{	0,				sizeof(__u32),			0 },
+[BTF_KIND_LOCSEC] =	{	0,				sizeof(struct btf_loc),		0 },
 };
 
 struct btf {
@@ -486,6 +489,12 @@ static int btf_type_size(const struct btf *btf, const struct btf_type *t)
 		return base_size + vlen * sizeof(struct btf_var_secinfo);
 	case BTF_KIND_DECL_TAG:
 		return base_size + sizeof(struct btf_decl_tag);
+	case BTF_KIND_LOC_PARAM:
+		return base_size + sizeof(struct btf_loc_param) + vlen * sizeof(__u32);
+	case BTF_KIND_LOC_PROTO:
+		return base_size + vlen * sizeof(__u32);
+	case BTF_KIND_LOCSEC:
+		return base_size + vlen * sizeof(struct btf_loc);
 	default:
 		return btf_type_size_unknown(btf, t);
 	}
@@ -501,12 +510,15 @@ static void btf_bswap_type_base(struct btf_type *t)
 static int btf_bswap_type_rest(struct btf_type *t)
 {
 	struct btf_var_secinfo *v;
+	struct btf_loc_param *lp;
 	struct btf_enum64 *e64;
 	struct btf_member *m;
 	struct btf_array *a;
 	struct btf_param *p;
 	struct btf_enum *e;
+	struct btf_loc *l;
 	__u32 vlen = btf_vlen(t);
+	__u32 *d;
 	int i;
 
 	switch (btf_kind(t)) {
@@ -569,6 +581,23 @@ static int btf_bswap_type_rest(struct btf_type *t)
 	case BTF_KIND_DECL_TAG:
 		btf_decl_tag(t)->component_idx = bswap_32(btf_decl_tag(t)->component_idx);
 		return 0;
+	case BTF_KIND_LOC_PARAM:
+		lp = btf_loc_param(t);
+		lp->flags = bswap_32(lp->flags);
+		for (i = 0, d = (__u32 *)(lp + 1); i < vlen; i++, d++)
+			*d = bswap_32(*d);
+		return 0;
+	case BTF_KIND_LOC_PROTO:
+		for (i = 0, d = btf_loc_proto_params(t); i < vlen; i++, d++)
+			*d = bswap_32(*d);
+		return 0;
+	case BTF_KIND_LOCSEC:
+		for (i = 0, l = btf_locsec_locs(t); i < vlen; i++, l++) {
+			l->func = bswap_32(l->func);
+			l->loc_proto = bswap_32(l->loc_proto);
+			l->offset = bswap_32(l->offset);
+		}
+		return 0;
 	default:
 		pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t));
 		return -EINVAL;
@@ -745,6 +774,33 @@ static int btf_validate_type(const struct btf *btf, const struct btf_type *t, __
 		}
 		break;
 	}
+	case BTF_KIND_LOC_PARAM:
+		break;
+	case BTF_KIND_LOC_PROTO: {
+		__u32 *p = btf_loc_proto_params(t);
+
+		n = btf_vlen(t);
+		for (i = 0; i < n; i++, p++) {
+			err = btf_validate_id(btf, *p, id);
+			if (err)
+				return err;
+		}
+		break;
+	}
+	case BTF_KIND_LOCSEC: {
+		const struct btf_loc *l = btf_locsec_locs(t);
+
+		n = btf_vlen(t);
+		for (i = 0; i < n; i++, l++) {
+			if (!err)
+				err = btf_validate_id(btf, l->func, id);
+			if (!err)
+				err = btf_validate_id(btf, l->loc_proto, id);
+			if (err)
+				return err;
+		}
+		break;
+	}
 	default:
 		/* Kind may be represented in kind layout information. */
 		if (btf_type_size_unknown(btf, t) < 0) {
@@ -3344,6 +3400,208 @@ int btf__add_decl_attr(struct btf *btf, const char *value, int ref_type_id,
 	return btf_add_decl_tag(btf, value, ref_type_id, component_idx, 1);
 }
 
+/*
+ * Append new BTF_KIND_LOC_PARAM with specified size and flags.  Values are
+ * added via btf__add_loc_param_value().
+ *
+ * Returns:
+ *   -  >0, type ID of newly added BTF type;
+ *   - <0, on error.
+ */
+int btf__add_loc_param(struct btf *btf, __u32 size, __u32 flags)
+{
+	struct btf_loc_param *p;
+	struct btf_type *t;
+	int sz, err;
+
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(struct btf_type) + sizeof(*p);
+	t = btf_add_type_mem(btf, sz);
+	if (!t)
+		return libbpf_err(-ENOMEM);
+
+	t->name_off = 0;
+	t->info = btf_type_info(BTF_KIND_LOC_PARAM, 0, 0);
+	t->size = size;
+
+	p = btf_loc_param(t);
+	p->flags = flags;
+
+	return btf_commit_type(btf, sz);
+}
+
+int btf__add_loc_param_value(struct btf *btf, __u32 value)
+{
+	struct btf_type *t;
+	int sz, err;
+	__u32 *v;
+
+	/* last type should be BTF_KIND_LOC_PARAM */
+	if (btf->nr_types == 0)
+		return libbpf_err(-EINVAL);
+	t = btf_last_type(btf);
+	if (!btf_is_loc_param(t))
+		return libbpf_err(-EINVAL);
+
+	/* decompose and invalidate raw data */
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(value);
+	v = btf_add_type_mem(btf, sz);
+	if (!v)
+		return libbpf_err(-ENOMEM);
+	*v = value;
+
+	/* update parent type's vlen */
+	t = btf_last_type(btf);
+	err = btf_type_inc_vlen(t);
+	if (err)
+		return libbpf_err(err);
+
+	btf_hdr_update_type_len(btf, btf->hdr.type_len + sz);
+	return 0;
+}
+
+/*
+ * Append new BTF_KIND_LOC_PROTO
+ *
+ * The prototype is then populated with 0 or more BTF_KIND_LOC_PARAMs via
+ * btf__add_loc_proto_param(); similar to how btf__add_func_param() adds
+ * parameters to a FUNC_PROTO.
+ *
+ * Returns:
+ *   -  >0, type ID of newly added BTF type;
+ *   - <0, on error.
+ */
+int btf__add_loc_proto(struct btf *btf)
+{
+	struct btf_type *t;
+	int err;
+
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	t = btf_add_type_mem(btf, sizeof(struct btf_type));
+	if (!t)
+		return libbpf_err(-ENOMEM);
+
+	t->name_off = 0;
+	t->info = btf_type_info(BTF_KIND_LOC_PROTO, 0, 0);
+	t->size = 0;
+
+	return btf_commit_type(btf, sizeof(struct btf_type));
+}
+
+int btf__add_loc_proto_param(struct btf *btf, __u32 id)
+{
+	struct btf_type *t;
+	int sz, err;
+	__u32 *p;
+
+	if (validate_type_id(id))
+		return libbpf_err(-EINVAL);
+
+	/* last type should be BTF_KIND_LOC_PROTO */
+	if (btf->nr_types == 0)
+		return libbpf_err(-EINVAL);
+	t = btf_last_type(btf);
+	if (!btf_is_loc_proto(t))
+		return libbpf_err(-EINVAL);
+
+	/* decompose and invalidate raw data */
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(__u32);
+	p = btf_add_type_mem(btf, sz);
+	if (!p)
+		return libbpf_err(-ENOMEM);
+	*p = id;
+
+	/* update parent type's vlen */
+	t = btf_last_type(btf);
+	err = btf_type_inc_vlen(t);
+	if (err)
+		return libbpf_err(err);
+
+	btf_hdr_update_type_len(btf, btf->hdr.type_len + sz);
+	return 0;
+}
+
+int btf__add_locsec(struct btf *btf, const char *name)
+{
+	struct btf_type *t;
+	int name_off = 0;
+	int err;
+
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	t = btf_add_type_mem(btf, sizeof(struct btf_type));
+	if (!t)
+		return libbpf_err(-ENOMEM);
+
+	if (!str_is_empty(name)) {
+		name_off = btf__add_str(btf, name);
+		if (name_off < 0)
+			return libbpf_err(name_off);
+	}
+	t->name_off = name_off;
+	t->info = btf_type_info(BTF_KIND_LOCSEC, 0, 0);
+	t->size = 0;
+
+	return btf_commit_type(btf, sizeof(struct btf_type));
+}
+
+int btf__add_locsec_loc(struct btf *btf, __u32 func, __u32 loc_proto,
+			__u32 offset)
+{
+	struct btf_type *t;
+	struct btf_loc *l;
+	int sz, err;
+
+	if (validate_type_id(func) || validate_type_id(loc_proto))
+		return libbpf_err(-EINVAL);
+
+	/* last type should be BTF_KIND_LOCSEC */
+	if (btf->nr_types == 0)
+		return libbpf_err(-EINVAL);
+	t = btf_last_type(btf);
+	if (!btf_is_locsec(t))
+		return libbpf_err(-EINVAL);
+
+	/* decompose and invalidate raw data */
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(*l);
+	l = btf_add_type_mem(btf, sz);
+	if (!l)
+		return libbpf_err(-ENOMEM);
+
+	l->func = func;
+	l->loc_proto = loc_proto;
+	l->offset = offset;
+
+	/* update parent type's vlen */
+	t = btf_last_type(btf);
+	err = btf_type_inc_vlen(t);
+	if (err)
+		return libbpf_err(err);
+
+	btf_hdr_update_type_len(btf, btf->hdr.type_len + sz);
+	return 0;
+}
+
 struct btf_ext_sec_info_param {
 	__u32 off;
 	__u32 len;
@@ -4114,8 +4372,8 @@ static struct btf_dedup *btf_dedup_new(struct btf *btf, const struct btf_dedup_o
 	for (i = 1; i < type_cnt; i++) {
 		struct btf_type *t = btf_type_by_id(d->btf, i);
 
-		/* VAR and DATASEC are never deduped and are self-canonical */
-		if (btf_is_var(t) || btf_is_datasec(t))
+		/* VAR, DATASEC and LOCSEC are never deduped and are self-canonical */
+		if (btf_is_var(t) || btf_is_datasec(t) || btf_is_locsec(t))
 			d->map[i] = i;
 		else
 			d->map[i] = BTF_UNPROCESSED_ID;
@@ -4395,6 +4653,47 @@ static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2)
 	       btf_is_any_enum(t1) && btf_is_any_enum(t2);
 }
 
+static long btf_hash_loc_param(struct btf_type *t)
+{
+	struct btf_loc_param *p = btf_loc_param(t);
+	long h = btf_hash_common(t);
+	int i, vlen = btf_vlen(t);
+
+	h = hash_combine(h, p->flags);
+
+	for (i = 0; i < vlen; i++)
+		h = hash_combine(h, p->values[i]);
+	return h;
+}
+
+static long btf_hash_loc_proto(struct btf_type *t)
+{
+	__u32 *p = btf_loc_proto_params(t);
+	long h = btf_hash_common(t);
+	int i, vlen = btf_vlen(t);
+
+	for (i = 0; i < vlen; i++, p++)
+		h = hash_combine(h, *p);
+	return h;
+}
+
+static bool btf_equal_loc_param(struct btf_type *t1, struct btf_type *t2)
+{
+	struct btf_loc_param *p1 = btf_loc_param(t1);
+	struct btf_loc_param *p2 = btf_loc_param(t2);
+	int i, vlen = btf_vlen(t1);
+
+	if (!btf_equal_common(t1, t2))
+		return false;
+	if (p1->flags != p2->flags)
+		return false;
+	for (i = 0; i < vlen; i++) {
+		if (p1->values[i] != p2->values[i])
+			return false;
+	}
+	return true;
+}
+
 /*
  * Calculate type signature hash of STRUCT/UNION, ignoring referenced type IDs,
  * as referenced type IDs equivalence is established separately during type
@@ -4589,7 +4888,8 @@ static int btf_dedup_prep(struct btf_dedup *d)
 		switch (btf_kind(t)) {
 		case BTF_KIND_VAR:
 		case BTF_KIND_DATASEC:
-			/* VAR and DATASEC are never hash/deduplicated */
+		case BTF_KIND_LOCSEC:
+			/* VAR DATASEC and LOCSEC are never hash/deduplicated */
 			continue;
 		case BTF_KIND_CONST:
 		case BTF_KIND_VOLATILE:
@@ -4622,6 +4922,12 @@ static int btf_dedup_prep(struct btf_dedup *d)
 		case BTF_KIND_FUNC_PROTO:
 			h = btf_hash_fnproto(t);
 			break;
+		case BTF_KIND_LOC_PARAM:
+			h = btf_hash_loc_param(t);
+			break;
+		case BTF_KIND_LOC_PROTO:
+			h = btf_hash_loc_proto(t);
+			break;
 		default:
 			pr_debug("unknown kind %d for type [%d]\n", btf_kind(t), type_id);
 			return -EINVAL;
@@ -4664,6 +4970,8 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
 	case BTF_KIND_DATASEC:
 	case BTF_KIND_DECL_TAG:
 	case BTF_KIND_TYPE_TAG:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
 		return 0;
 
 	case BTF_KIND_INT:
@@ -4713,6 +5021,18 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
 		}
 		break;
 
+	case BTF_KIND_LOC_PARAM:
+		h = btf_hash_loc_param(t);
+		for_each_dedup_cand(d, hash_entry, h) {
+			cand_id = hash_entry->value;
+			cand = btf_type_by_id(d->btf, cand_id);
+			if (btf_equal_loc_param(t, cand)) {
+				new_id = cand_id;
+				break;
+			}
+		}
+		break;
+
 	default:
 		return -EINVAL;
 	}
@@ -5145,6 +5465,13 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
 		return 1;
 	}
 
+	case BTF_KIND_LOC_PARAM:
+		return btf_equal_loc_param(cand_type, canon_type);
+
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -5489,6 +5816,37 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 		break;
 	}
 
+	case BTF_KIND_LOC_PROTO: {
+		__u32 *p1, *p2;
+		__u32 i, vlen;
+
+		p1 = btf_loc_proto_params(t);
+		vlen = btf_vlen(t);
+
+		for (i = 0; i < vlen; i++, p1++) {
+			ref_type_id = btf_dedup_ref_type(d, *p1);
+			if (ref_type_id < 0)
+				return ref_type_id;
+			*p1 = ref_type_id;
+		}
+
+		h = btf_hash_loc_proto(t);
+		for_each_dedup_cand(d, hash_entry, h) {
+			cand_id = hash_entry->value;
+			cand = btf_type_by_id(d->btf, cand_id);
+			if (!btf_equal_common(t, cand))
+				continue;
+			vlen = btf_vlen(cand);
+			p1 = btf_loc_proto_params(t);
+			p2 = btf_loc_proto_params(cand);
+			if (memcmp(p1, p2, vlen * sizeof(__u32)) == 0) {
+				new_id = cand_id;
+				break;
+			}
+		}
+		break;
+	}
+
 	default:
 		return -EINVAL;
 	}
@@ -5970,8 +6328,11 @@ static int btf_add_distilled_type_ids(struct btf_distill *dist, __u32 i)
 		case BTF_KIND_CONST:
 		case BTF_KIND_RESTRICT:
 		case BTF_KIND_VOLATILE:
+		case BTF_KIND_FUNC:
 		case BTF_KIND_FUNC_PROTO:
 		case BTF_KIND_TYPE_TAG:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
 			dist->id_map[*id] = *id;
 			break;
 		default:
@@ -5997,7 +6358,7 @@ static int btf_add_distilled_type_ids(struct btf_distill *dist, __u32 i)
 
 static int btf_add_distilled_types(struct btf_distill *dist)
 {
-	bool adding_to_base = dist->pipe.dst->start_id == 1;
+	bool adding_to_base = dist->pipe.dst->base_btf == NULL;
 	int id = btf__type_cnt(dist->pipe.dst);
 	struct btf_type *t;
 	int i, err = 0;
@@ -6065,8 +6426,12 @@ static int btf_add_distilled_types(struct btf_distill *dist)
 		case BTF_KIND_CONST:
 		case BTF_KIND_RESTRICT:
 		case BTF_KIND_VOLATILE:
+		case BTF_KIND_FUNC:
 		case BTF_KIND_FUNC_PROTO:
 		case BTF_KIND_TYPE_TAG:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
+		case BTF_KIND_LOCSEC:
 			/* All other types are added to split BTF. */
 			if (adding_to_base)
 				continue;
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 587172c0de089..57f12630c5d15 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -274,6 +274,20 @@ LIBBPF_API int btf__add_decl_tag(struct btf *btf, const char *value, int ref_typ
 LIBBPF_API int btf__add_decl_attr(struct btf *btf, const char *value, int ref_type_id,
 				  int component_idx);
 
+/* location construction APIs */
+LIBBPF_API int btf__add_loc_param(struct btf *btf, __u32 size, __u32 flags);
+
+LIBBPF_API int btf__add_loc_param_value(struct btf *btf, __u32 value);
+
+LIBBPF_API int btf__add_loc_proto(struct btf *btf);
+
+LIBBPF_API int btf__add_loc_proto_param(struct btf *btf, __u32 id);
+
+LIBBPF_API int btf__add_locsec(struct btf *btf, const char *name);
+
+LIBBPF_API int btf__add_locsec_loc(struct btf *btf, __u32 func, __u32 loc_proto,
+				   __u32 offset);
+
 struct btf_dedup_opts {
 	size_t sz;
 	/* optional .BTF.ext info to dedup along the main BTF info */
@@ -431,6 +445,12 @@ btf_dump__dump_type_data(struct btf_dump *d, __u32 id,
 #define BTF_KIND_DECL_TAG	17	/* Decl Tag */
 #define BTF_KIND_TYPE_TAG	18	/* Type Tag */
 #define BTF_KIND_ENUM64		19	/* Enum for up-to 64bit values */
+#define BTF_KIND_LOC_PARAM	20	/* Parameter at location */
+#define BTF_KIND_LOC_PROTO	21	/* Parameter set at location */
+#define BTF_KIND_LOCSEC		22	/* Section containing location info */
+
+struct btf_loc_param;
+struct btf_loc;
 
 static inline __u16 btf_kind(const struct btf_type *t)
 {
@@ -569,6 +589,21 @@ static inline bool btf_is_any_enum(const struct btf_type *t)
 	return btf_is_enum(t) || btf_is_enum64(t);
 }
 
+static inline bool btf_is_loc_param(const struct btf_type *t)
+{
+	return btf_kind(t) == BTF_KIND_LOC_PARAM;
+}
+
+static inline bool btf_is_loc_proto(const struct btf_type *t)
+{
+	return btf_kind(t) == BTF_KIND_LOC_PROTO;
+}
+
+static inline bool btf_is_locsec(const struct btf_type *t)
+{
+	return btf_kind(t) == BTF_KIND_LOCSEC;
+}
+
 static inline bool btf_kind_core_compat(const struct btf_type *t1,
 					const struct btf_type *t2)
 {
@@ -683,6 +718,21 @@ static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
 	return (struct btf_decl_tag *)(t + 1);
 }
 
+static inline struct btf_loc_param *btf_loc_param(const struct btf_type *t)
+{
+	return (struct btf_loc_param *)(t + 1);
+}
+
+static inline __u32 *btf_loc_proto_params(const struct btf_type *t)
+{
+	return (__u32 *)(t + 1);
+}
+
+static inline struct btf_loc *btf_locsec_locs(const struct btf_type *t)
+{
+	return (struct btf_loc *)(t + 1);
+}
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 123c448f20c74..fa995c02a1705 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -328,6 +328,9 @@ static int btf_dump_mark_referenced(struct btf_dump *d)
 		case BTF_KIND_ENUM64:
 		case BTF_KIND_FWD:
 		case BTF_KIND_FLOAT:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
+		case BTF_KIND_LOCSEC:
 			break;
 
 		case BTF_KIND_VOLATILE:
@@ -609,6 +612,9 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
 	case BTF_KIND_VAR:
 	case BTF_KIND_DATASEC:
 	case BTF_KIND_DECL_TAG:
+	case BTF_KIND_LOC_PARAM:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
 		d->type_states[id].order_state = ORDERED;
 		return 0;
 
@@ -2525,6 +2531,9 @@ static int btf_dump_dump_type_data(struct btf_dump *d,
 	case BTF_KIND_FUNC:
 	case BTF_KIND_FUNC_PROTO:
 	case BTF_KIND_DECL_TAG:
+	case BTF_KIND_LOC_PARAM:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
 		err = btf_dump_unsupported_data(d, t, id);
 		break;
 	case BTF_KIND_INT:
diff --git a/tools/lib/bpf/btf_iter.c b/tools/lib/bpf/btf_iter.c
index 9a6c822c22944..199063b55ebe6 100644
--- a/tools/lib/bpf/btf_iter.c
+++ b/tools/lib/bpf/btf_iter.c
@@ -29,6 +29,7 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 		case BTF_KIND_FLOAT:
 		case BTF_KIND_ENUM:
 		case BTF_KIND_ENUM64:
+		case BTF_KIND_LOC_PARAM:
 			it->desc = (struct btf_field_desc) {};
 			break;
 		case BTF_KIND_FWD:
@@ -71,6 +72,20 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 				1, {offsetof(struct btf_var_secinfo, type)}
 			};
 			break;
+		case BTF_KIND_LOC_PROTO:
+			it->desc = (struct btf_field_desc) {
+				0, {},
+				sizeof(__u32),
+				1, {0}};
+			break;
+		case BTF_KIND_LOCSEC:
+			it->desc = (struct btf_field_desc) {
+				0, {},
+				sizeof(struct btf_loc),
+				2, {offsetof(struct btf_loc, func),
+				    offsetof(struct btf_loc, loc_proto)}};
+			break;
+
 		default:
 			return -EINVAL;
 		}
@@ -94,6 +109,9 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 		case BTF_KIND_DECL_TAG:
 		case BTF_KIND_TYPE_TAG:
 		case BTF_KIND_DATASEC:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
+		case BTF_KIND_LOCSEC:
 			it->desc = (struct btf_field_desc) {
 				1, {offsetof(struct btf_type, name_off)}
 			};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 08ab2ea881fb6..7f51783df129a 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -460,6 +460,12 @@ LIBBPF_1.8.0 {
 	global:
 		bpf_program__attach_tracing_multi;
 		bpf_program__clone;
+		btf__add_loc_param;
+		btf__add_loc_param_value;
+		btf__add_loc_proto;
+		btf__add_loc_proto_param;
+		btf__add_locsec;
+		btf__add_locsec_loc;
 		btf__find_by_name_kind_own;
 		btf__new_empty_opts;
 } LIBBPF_1.7.0;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index cb4d962338441..546f65b95cf4d 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -580,7 +580,7 @@ struct btf_field_desc {
 	/* member struct size, or zero, if no members */
 	int m_sz;
 	/* repeated per-member offsets */
-	int m_off_cnt, m_offs[1];
+	int m_off_cnt, m_offs[2];
 };
 
 struct btf_field_iter {
diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index 1c1c2c26690a7..972403f6a7438 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
@@ -27,11 +27,14 @@ static const char * const btf_kind_str_mapping[] = {
 	[BTF_KIND_DECL_TAG]	= "DECL_TAG",
 	[BTF_KIND_TYPE_TAG]	= "TYPE_TAG",
 	[BTF_KIND_ENUM64]	= "ENUM64",
+	[BTF_KIND_LOC_PARAM]	= "LOC_PARAM",
+	[BTF_KIND_LOC_PROTO]	= "LOC_PROTO",
+	[BTF_KIND_LOCSEC]	= "LOCSEC",
 };
 
 static const char *btf_kind_str(__u16 kind)
 {
-	if (kind > BTF_KIND_ENUM64)
+	if (kind > BTF_KIND_LOCSEC)
 		return "UNKNOWN";
 	return btf_kind_str_mapping[kind];
 }
@@ -203,6 +206,37 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
 		fprintf(out, " type_id=%u component_idx=%d",
 			t->type, btf_decl_tag(t)->component_idx);
 		break;
+	case BTF_KIND_LOC_PARAM: {
+		struct btf_loc_param *p = btf_loc_param(t);
+		__u32 *v = (__u32 *)(p + 1);
+
+		fprintf(out, " size=%u flags=0x%x vlen=%u", t->size, p->flags, vlen);
+		for (i = 0; i < vlen; i++, v++) {
+			if (p->flags & BTF_LOC_PARAM_SIGNED)
+				fprintf(out, "\n\tvalue=%d", (__s32)*v);
+			else
+				fprintf(out, "\n\tvalue=%u", *v);
+		}
+		break;
+	}
+	case BTF_KIND_LOC_PROTO: {
+		const __u32 *p = btf_loc_proto_params(t);
+
+		fprintf(out, " vlen=%u", vlen);
+		for (i = 0; i < vlen; i++, p++)
+			fprintf(out, "\n\ttype_id=%u", *p);
+		break;
+	}
+	case BTF_KIND_LOCSEC: {
+		const struct btf_loc *l = btf_locsec_locs(t);
+
+		fprintf(out, " vlen=%u", vlen);
+		for (i = 0; i < vlen; i++, l++) {
+			fprintf(out, "\n\tfunc_type_id=%u loc_proto_type_id=%u offset=%u",
+				l->func, l->loc_proto, l->offset);
+		}
+		break;
+	}
 	default:
 		break;
 	}
diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
index d5b25302b0c89..f8ea9dfd0780b 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
@@ -57,6 +57,35 @@ static struct btf *mk_btf(void)
 	return btf;
 }
 
+static struct btf *mk_loc_btf(void)
+{
+	struct btf *btf;
+
+	btf = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf, "new_empty"))
+		return NULL;
+
+	btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+	btf__add_func_proto(btf, 1);
+	btf__add_func_param(btf, "arg1", 1);
+	btf__add_func_param(btf, "arg2", 1);
+	btf__add_func(btf, "foo", BTF_FUNC_STATIC, 2);
+
+	btf__add_loc_param(btf, 4, BTF_LOC_PARAM_REG);
+	btf__add_loc_param_value(btf, 1);
+	btf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG |
+			    BTF_LOC_PARAM_DEREF | BTF_LOC_PARAM_OFFSET);
+	btf__add_loc_param_value(btf, 2);
+	btf__add_loc_param_value(btf, 0x10);
+	btf__add_loc_proto(btf);
+	btf__add_loc_proto_param(btf, 4);
+	btf__add_loc_proto_param(btf, 5);
+	btf__add_locsec(btf, "inline.text");
+	btf__add_locsec_loc(btf, 3, 6, 64);
+
+	return btf;
+}
+
 static int btf_to_tmpfile(const struct btf *btf, char *path)
 {
 	ssize_t written;
@@ -105,6 +134,26 @@ static char *dump_c(const char *btf_path, bool sorted)
 	return buf;
 }
 
+static char *dump_raw(const char *btf_path)
+{
+	char args[MAX_BPFTOOL_CMD_LEN];
+	char *buf;
+	int err;
+
+	buf = malloc(DUMP_BUF_SZ);
+	if (!ASSERT_OK_PTR(buf, "alloc_dump"))
+		return NULL;
+
+	snprintf(args, sizeof(args), "btf dump file %s", btf_path);
+	err = get_bpftool_command_output(args, buf, DUMP_BUF_SZ);
+	if (!ASSERT_OK(err, "btf_dump_raw")) {
+		free(buf);
+		return NULL;
+	}
+
+	return buf;
+}
+
 static char *read_expected(const char *path)
 {
 	char *buf = NULL;
@@ -155,6 +204,31 @@ static void test_dump(const char *btf_path, bool sorted)
 	free(dump);
 }
 
+static void test_loc_dump(const char *btf_path)
+{
+	const char expected[] =
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\n"
+		"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'arg1' type_id=1\n"
+		"\t'arg2' type_id=1\n"
+		"[3] FUNC 'foo' type_id=2 linkage=static\n"
+		"[4] LOC_PARAM '(anon)' size=4 flags=0x8 vlen=1 values='r1'\n"
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x38 vlen=2 values='*(r2 + 0x10)'\n"
+		"[6] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=4 value='r1'\n"
+		"\ttype_id=5 value='*(r2 + 0x10)'\n"
+		"[7] LOCSEC 'inline.text' vlen=1\n"
+		"\tname='foo' func_type_id=3 loc_proto_type_id=6 offset=64\n";
+	char *dump;
+
+	dump = dump_raw(btf_path);
+	if (!dump)
+		return;
+
+	ASSERT_OK(compare_text_to_expected(dump, expected), "cmp_loc_dump");
+	free(dump);
+}
+
 void test_bpftool_btf_dump(void)
 {
 	char path[PATH_MAX];
@@ -175,4 +249,14 @@ void test_bpftool_btf_dump(void)
 	unlink(path);
 out_btf:
 	btf__free(btf);
+
+	btf = mk_loc_btf();
+	if (!btf)
+		return;
+
+	if (!btf_to_tmpfile(btf, path) && test__start_subtest("loc_dump"))
+		test_loc_dump(path);
+
+	unlink(path);
+	btf__free(btf);
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
index 9d61611515938..5c15a6b7f4fb9 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
@@ -554,6 +554,120 @@ static void test_split_module(void)
 	btf__free(vmlinux_btf);
 }
 
+static void test_split_loc(void)
+{
+	struct btf *btf1, *btf2;
+	int err;
+
+	btf1 = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf1, "empty_main_btf"))
+		return;
+
+	btf__set_pointer_size(btf1, 8); /* enforce 64-bit arch */
+
+
+	btf__add_int(btf1, "long", 8, BTF_INT_SIGNED);  /* [1] long */
+	btf__add_ptr(btf1, 1);                          /* [2] ptr to long */
+	btf__add_func_proto(btf1, 1);			/* [3] long (*)(long, long *); */
+	btf__add_func_param(btf1, "p1", 1);
+	btf__add_func_param(btf1, "p2", 2);
+	btf__add_func(btf1, "foo", BTF_FUNC_STATIC, 3);	/* [4] long foo(long, long *); */
+	btf__add_loc_param(btf1, 8, BTF_LOC_PARAM_CONST);
+	btf__add_loc_param_value(btf1, 3735928559);
+	btf__add_loc_param_value(btf1, 4277009102);	/* [5] loc value */
+	btf__add_loc_param(btf1, 8, BTF_LOC_PARAM_REG);	/* [6] loc reg 1 */
+	btf__add_loc_param_value(btf1, 1);
+	btf__add_loc_proto(btf1);			/* [7] loc proto */
+	btf__add_loc_proto_param(btf1, 5);		/*  param value */
+	btf__add_loc_proto_param(btf1, 6);		/*  param reg 1 */
+
+	VALIDATE_RAW_BTF(
+		btf1,
+		"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'p1' type_id=1\n"
+		"\t'p2' type_id=2",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\n"
+		"\tvalue=3735928559\n"
+		"\tvalue=4277009102",
+		"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[7] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=6");
+
+	btf2 = btf__new_empty_split(btf1);
+	if (!ASSERT_OK_PTR(btf2, "empty_split_btf"))
+		goto cleanup;
+	btf__add_loc_param(btf2, 8, BTF_LOC_PARAM_REG);
+	btf__add_loc_param_value(btf2, 1);		/* [8] loc reg 1 */
+	btf__add_loc_proto(btf2);			/* [9] loc proto */
+	btf__add_loc_proto_param(btf2, 5);		/* param value */
+	btf__add_loc_proto_param(btf2, 8);		/* param reg 1 */
+	btf__add_locsec(btf2, "inline.text");		/* [10] locsec "inline.text" */
+	/* add duplicate locsec */
+	btf__add_locsec_loc(btf2, 4, 9, 128);
+	btf__add_locsec(btf2, "inline.text");		/* [11] locsec "inline.text" */
+	btf__add_locsec_loc(btf2, 4, 9, 128);
+
+	VALIDATE_RAW_BTF(
+		btf2,
+		"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'p1' type_id=1\n"
+		"\t'p2' type_id=2",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\n"
+		"\tvalue=3735928559\n"
+		"\tvalue=4277009102",
+		"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[7] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=6",
+		"[8] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[9] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=8",
+		"[10] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=9 offset=128",
+		"[11] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=9 offset=128");
+
+	err = btf__dedup(btf2, NULL);
+	if (!ASSERT_OK(err, "btf_dedup"))
+		goto cleanup;
+
+	VALIDATE_RAW_BTF(
+		btf2,
+		"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'p1' type_id=1\n"
+		"\t'p2' type_id=2",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\n"
+		"\tvalue=3735928559\n"
+		"\tvalue=4277009102",
+		"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[7] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=6",
+		"[8] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=7 offset=128",
+		"[9] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=7 offset=128");
+
+cleanup:
+	btf__free(btf2);
+	btf__free(btf1);
+}
+
 void test_btf_dedup_split()
 {
 	if (test__start_subtest("split_simple"))
@@ -566,4 +680,6 @@ void test_btf_dedup_split()
 		test_split_dup_struct_in_cu();
 	if (test__start_subtest("split_module"))
 		test_split_module();
+	if (test__start_subtest("split_loc"))
+		test_split_loc();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_distill.c b/tools/testing/selftests/bpf/prog_tests/btf_distill.c
index fb67ae195a738..141a4cb1f4054 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_distill.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_distill.c
@@ -671,6 +671,105 @@ static void test_distilled_base_embedded_err(void)
 	btf__free(btf1);
 }
 
+/* LOC_PARAM, LOC_PROTO should be added to split BTF. */
+static void test_distilled_loc(void)
+{
+	struct btf *btf1 = NULL, *btf2 = NULL, *btf3 = NULL;
+	struct btf *btf4 = NULL, *btf5 = NULL;
+
+	btf1 = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf1, "empty_main_btf"))
+		return;
+
+	btf__add_int(btf1, "int", 4, BTF_INT_SIGNED);	/* [1] int */
+	btf__add_func_proto(btf1, 1);                   /* [2] int (*)(int); */
+	btf__add_func_param(btf1, "p1", 1);
+	btf__add_func(btf1, "foo", BTF_FUNC_STATIC, 2);	/* [3] int foo(int); */
+	btf__add_loc_param(btf1, 4, BTF_LOC_PARAM_SIGNED | BTF_LOC_PARAM_CONST);
+	btf__add_loc_param_value(btf1, -1);		/* [4] loc value */
+	btf__add_loc_proto(btf1);			/* [5] loc proto */
+	btf__add_loc_proto_param(btf1, 4);		/*  param value */
+
+	VALIDATE_RAW_BTF(
+		btf1,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[3] FUNC 'foo' type_id=2 linkage=static",
+		"[4] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[5] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=4");
+
+	btf2 = btf__new_empty_split(btf1);
+	if (!ASSERT_OK_PTR(btf2, "empty_split_btf"))
+		goto cleanup;
+
+	btf__add_locsec(btf2, "inline.text");		/* [6] locsec */
+	btf__add_locsec_loc(btf2, 3, 5, 256);		/* "foo" offset 256 */
+	VALIDATE_RAW_BTF(
+		btf2,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[3] FUNC 'foo' type_id=2 linkage=static",
+		"[4] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[5] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=4",
+		"[6] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=3 loc_proto_type_id=5 offset=256");
+
+	if (!ASSERT_EQ(0, btf__distill_base(btf2, &btf3, &btf4),
+		       "distilled_base") ||
+	    !ASSERT_OK_PTR(btf3, "distilled_base") ||
+	    !ASSERT_OK_PTR(btf4, "distilled_split") ||
+	    !ASSERT_EQ(2, btf__type_cnt(btf3), "distilled_base_type_cnt"))
+		goto cleanup;
+
+	VALIDATE_RAW_BTF(
+		btf4,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		/* remainder is split BTF */
+		"[2] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=6 offset=256",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[6] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=5");
+
+	btf5 = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf5, "empty_reloc_btf"))
+		goto cleanup;
+	btf__add_int(btf5, "int", 4, BTF_INT_SIGNED);	/* [1] int */
+
+	if (!ASSERT_EQ(btf__relocate(btf4, btf5), 0, "relocate_split"))
+		goto cleanup;
+	VALIDATE_RAW_BTF(
+		btf4,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		/* remainder is split BTF */
+		"[2] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=6 offset=256",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[6] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=5");
+
+cleanup:
+	btf__free(btf5);
+	btf__free(btf4);
+	btf__free(btf3);
+	btf__free(btf2);
+	btf__free(btf1);
+}
+
 void test_btf_distill(void)
 {
 	if (test__start_subtest("distilled_base"))
@@ -689,4 +788,6 @@ void test_btf_distill(void)
 		test_distilled_base_vmlinux();
 	if (test__start_subtest("distilled_endianness"))
 		test_distilled_endianness();
+	if (test__start_subtest("distilled_loc"))
+		test_distilled_loc();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c b/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c
index 32159d3eb281b..dcb5429d141df 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c
@@ -31,8 +31,11 @@ struct field_data {
 	{ .ids = { 11 },	.strs = { "decltag" } },
 	{ .ids = { 6 },		.strs = { "typetag" } },
 	{ .ids = {},		.strs = { "e64", "eval1", "eval2", "eval3" } },
-	{ .ids = { 15, 16 },	.strs = { "datasec1" } }
-
+	{ .ids = { 15, 16 },	.strs = { "datasec1" } },
+	{ .ids = {},		.strs = { "" } },
+	{ .ids = {},		.strs = { "" } },
+	{ .ids = { 22, 23 },	.strs = { "" } },
+	{ .ids = { 14, 24 },	.strs = { ".loc" } }
 };
 
 /* Fabricate BTF with various types and check BTF field iteration finds types,
@@ -88,6 +91,19 @@ void test_btf_field_iter(void)
 	btf__add_datasec_var_info(btf, 15, 0, 4);
 	btf__add_datasec_var_info(btf, 16, 4, 8);
 
+	btf__add_loc_param(btf, 4, BTF_LOC_PARAM_CONST | BTF_LOC_PARAM_SIGNED);
+							/* [22] loc value -1 */
+	btf__add_loc_param_value(btf, -1);
+	btf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG);	/* [23] loc reg 1 */
+	btf__add_loc_param_value(btf, 1);
+
+	btf__add_loc_proto(btf);			/* [24] loc proto */
+	btf__add_loc_proto_param(btf, 22);		/*  param value -1, */
+	btf__add_loc_proto_param(btf, 23);		/*  param reg 1 */
+
+	btf__add_locsec(btf, ".loc");			/* [25] locsec ".loc" */
+	btf__add_locsec_loc(btf, 14, 24, 128);		/* "func" */
+
 	VALIDATE_RAW_BTF(
 		btf,
 		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
@@ -123,7 +139,16 @@ void test_btf_field_iter(void)
 		"\t'eval3' val=3000",
 		"[21] DATASEC 'datasec1' size=12 vlen=2\n"
 		"\ttype_id=15 offset=0 size=4\n"
-		"\ttype_id=16 offset=4 size=8");
+		"\ttype_id=16 offset=4 size=8",
+		"[22] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[23] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[24] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=22\n"
+		"\ttype_id=23",
+		"[25] LOCSEC '.loc' vlen=1\n"
+		"\tfunc_type_id=14 loc_proto_type_id=24 offset=128");
 
 	for (id = 1; id < btf__type_cnt(btf); id++) {
 		struct btf_type *t = btf_type_by_id(btf, id);
diff --git a/tools/testing/selftests/bpf/test_btf.h b/tools/testing/selftests/bpf/test_btf.h
index e7bc781083745..b99c04b4d26bb 100644
--- a/tools/testing/selftests/bpf/test_btf.h
+++ b/tools/testing/selftests/bpf/test_btf.h
@@ -84,4 +84,20 @@
 #define BTF_TYPE_TAG_ENC(value, type)	\
 	BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)
 
+#define BTF_LOC_PARAM_ENC(nvals, sz, flags) \
+	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_LOC_PARAM, 0, nvals), sz), (flags)
+
+#define BTF_LOC_PARAM_VAL_ENCODE(val)	(val)
+
+#define BTF_LOC_PROTO_ENC(nargs) \
+	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_LOC_PROTO, 0, nargs), 0)
+
+#define BTF_LOC_PROTO_PARAM_ENCODE(param) (param)
+
+#define BTF_LOCSEC_ENC(name, nlocs) \
+	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_LOCSEC, 0, nlocs), 0)
+
+#define BTF_LOCSEC_LOC_ENCODE(func, loc_proto, offset) \
+	(func), (loc_proto), (offset)
+
 #endif /* _TEST_BTF_H */

3/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32944
							output: 32
							thoughts: 914
						

Thoughts:
**Fuzzing Evaluation: This Patch is a Prime Target!**

Okay, let's break this down. My initial assessment is that this patch introduces significant changes to BPF BTF handling, and immediately, my spidey-sense is tingling – it *screams* "fuzz me!"

First, I see the scope of the modifications: `Documentation/bpf/btf.rst`, `include/linux/btf.h`, `include/uapi/linux/btf.h`, `kernel/bpf/btf.c`, and the `tools` directory. That's a good chunk of code, and it's all centered on BTF, which is already a known attack surface.

Specifically, diving into `kernel/bpf/btf.c`, I notice the addition of three brand new BTF kinds: `BTF_KIND_LOC_PARAM`, `BTF_KIND_LOC_PROTO`, and `BTF_KIND_LOCSEC`. Each new kind comes with its own verification and resolution logic: `btf_loc_param_check_meta`, `btf_loc_proto_check_meta`, `btf_loc_proto_resolve`, and `btf_locsec_check_meta`, `btf_locsec_resolve`. These are all prime fuzzing candidates. The changes to `btf_resolve_valid`, `struct btf_field_desc`, and new macros/structs add further depth to this.

The crucial point here is that this is *reachable code*. Anyone with or without privileges (depending on the configurations) can load BTF data into the kernel via `bpf(BPF_BTF_LOAD, ...)`! Syzkaller is known to fuzz this interface heavily, so we're talking about a direct user-space interface. This means we're dealing with parsing, verification, and resolution of user-supplied binary data *entirely* within the kernel. Parsing, bounds checking, resolution loops, type ID lookups... the usual suspects for memory corruption bugs.

Given the existing BPF fuzzing capabilities of Syzkaller and the introduction of new BTF kinds, this patch clearly hits all the right notes: it touches a core subsystem, has a user-space interface (the `bpf()` syscall) that we can readily target, and is dealing with parsing arbitrary binary input. In my expert opinion, this is *definitely* worth fuzzing. I'll need to check the Kconfig options next to ensure the code is compiled, but I'm pretty confident in giving this a green light.



4/2 2026/09/17 18:48 tool grepper
0m Args:
{
  "Expression": "config BPF_SYSCALL",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Kconfig=29=menu \"BPF subsystem\"\nkernel/bpf/Kconfig-30-\nkernel/bpf/Kconfig:31:config BPF_SYSCALL\nkernel/bpf/Kconfig-32-\tbool \"Enable bpf() system call\"\n"
}

5/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34526
							output: 29
							thoughts: 25
						

Thoughts:
Here's my take on the thought process, as if I were the one thinking it:

**Diving into the BPF BTF Compilation**

Okay, so I need to understand how `btf.c` is compiled within the BPF kernel module. Time to get down to brass tacks. The `Makefile` in `kernel/bpf/` is the obvious place to start. It's the central configuration and compilation script for that directory. That's where I should be able to trace how this specific file, `btf.c`, gets handled. Let's see what's what. I'm expecting to find the relevant compilation flags, dependencies, and ultimately, the object file generation rule. I want to see exactly how the BTF-related code is linked into the broader BPF ecosystem. Hopefully, it is well documented! I am eager to begin.



6/2 2026/09/17 18:48 tool grepper
0m Args:
{
  "Expression": "btf\\.o",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Makefile=13=obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o\nkernel/bpf/Makefile:14:obj-$(CONFIG_BPF_SYSCALL) += fixups.o cfg.o states.o backtrack.o check_btf.o\nkernel/bpf/Makefile-15-obj-${CONFIG_BPF_LSM}\t  += bpf_inode_storage.o\n--\nkernel/bpf/Makefile=17=obj-$(CONFIG_BPF_JIT) += trampoline.o\nkernel/bpf/Makefile:18:obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o\nkernel/bpf/Makefile-19-ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)\n--\nkernel/bpf/Makefile=43=ifeq ($(CONFIG_SYSFS),y)\nkernel/bpf/Makefile:44:obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o\nkernel/bpf/Makefile-45-endif\n"
}

7/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35054
							output: 34
							thoughts: 61
						

Thoughts:
**My Analysis of BTF Compilation**

Okay, so looking at this makefile logic, it's clear that `btf.o` is only built when `CONFIG_BPF_SYSCALL` is enabled. That's straightforward enough: `obj-$(CONFIG_BPF_SYSCALL) += btf.o` directly links the object file to the configuration. But, like any good engineer, I need to understand the dependencies. I should double-check *how* `CONFIG_BPF_SYSCALL` itself is defined and if it depends on any other configuration options. Understanding those dependencies will give me a better handle on when `btf.o` will actually appear in the final build. This is critical, especially when working with something as complex as BPF and its syscall interface. Knowing the prerequisites to ensure `btf.o` is built is the key.



8/2 2026/09/17 18:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/Kconfig",
  "FirstLine": 30,
  "LineCount": 40
}

Results:
{
  "Contents": "  30:\t\n  31:\tconfig BPF_SYSCALL\n  32:\t\tbool \"Enable bpf() system call\"\n  33:\t\tselect BPF\n  34:\t\tselect IRQ_WORK\n  35:\t\tselect NEED_TASKS_RCU\n  36:\t\tselect TASKS_TRACE_RCU\n  37:\t\tselect BINARY_PRINTF\n  38:\t\tselect NET_SOCK_MSG if NET\n  39:\t\tselect NET_XGRESS if NET\n  40:\t\tselect PAGE_POOL if NET\n  41:\t\tdefault n\n  42:\t\thelp\n  43:\t\t  Enable the bpf() system call that allows to manipulate BPF programs\n  44:\t\t  and maps via file descriptors.\n  45:\t\n  46:\tconfig BPF_JIT\n  47:\t\tbool \"Enable BPF Just In Time compiler\"\n  48:\t\tdepends on BPF\n  49:\t\tdepends on HAVE_CBPF_JIT || HAVE_EBPF_JIT\n  50:\t\tselect EXECMEM\n  51:\t\thelp\n  52:\t\t  BPF programs are normally handled by a BPF interpreter. This option\n  53:\t\t  allows the kernel to generate native code when a program is loaded\n  54:\t\t  into the kernel. This will significantly speed-up processing of BPF\n  55:\t\t  programs.\n  56:\t\n  57:\t\t  Note, an admin should enable this feature changing:\n  58:\t\t  /proc/sys/net/core/bpf_jit_enable\n  59:\t\t  /proc/sys/net/core/bpf_jit_harden   (optional)\n  60:\t\t  /proc/sys/net/core/bpf_jit_kallsyms (optional)\n  61:\t\n  62:\tconfig BPF_JIT_ALWAYS_ON\n  63:\t\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n  64:\t\tdepends on BPF_SYSCALL \u0026\u0026 HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n  65:\t\thelp\n  66:\t\t  Enables BPF JIT and removes BPF interpreter to avoid speculative\n  67:\t\t  execution of BPF instructions by the interpreter.\n  68:\t\n  69:\t\t  When CONFIG_BPF_JIT_ALWAYS_ON is enabled, /proc/sys/net/core/bpf_jit_enable\n"
}

9/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35946
							output: 31
							thoughts: 121
						

Thoughts:
**My BPF Compilation Thoughts**

Okay, so I'm working with `BPF_SYSCALL`, and as I understand it, that's pretty standard. No major red flags there – it shouldn't require anything exotic, just whatever's selected or depended upon. Let me just quickly confirm that though.

Wait, hold on, I should make sure that `DEBUG_INFO_BTF` isn't lurking around and relevant here, even if it doesn't immediately seem necessary. Let's see... does `btf.o` depend on `DEBUG_INFO_BTF` in any way? No, the line `obj-$(CONFIG_BPF_SYSCALL) += btf.o` only means that it needs `CONFIG_BPF_SYSCALL` to be configured. So no dependency there.

Alright, one last thing, to be safe. It’s always good practice to check for any conditional compilation. Let me just glance at the source for `kernel/bpf/btf.c` and make sure there are no surprise `#ifdef`s related to `DEBUG_INFO_BTF`. Just a quick sanity check to be thorough.



10/2 2026/09/17 18:48 tool grepper
0m Args:
{
  "Expression": "#ifdef",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=2468=static void btf_int128_print(struct btf_show *show, void *data)\n--\nkernel/bpf/btf.c-2478-\nkernel/bpf/btf.c:2479:#ifdef __BIG_ENDIAN_BITFIELD\nkernel/bpf/btf.c-2480-\tupper_num = *(u64 *)data;\n--\nkernel/bpf/btf.c=2493=static void btf_int128_shift(u64 *print_num, u16 left_shift_bits,\n--\nkernel/bpf/btf.c-2497-\nkernel/bpf/btf.c:2498:#ifdef __BIG_ENDIAN_BITFIELD\nkernel/bpf/btf.c-2499-\tupper_num = print_num[0];\n--\nkernel/bpf/btf.c-2524-\nkernel/bpf/btf.c:2525:#ifdef __BIG_ENDIAN_BITFIELD\nkernel/bpf/btf.c-2526-\tprint_num[0] = upper_num;\n--\nkernel/bpf/btf.c=2534=static void btf_bitfield_show(void *data, u8 bits_offset,\n--\nkernel/bpf/btf.c-2546-\nkernel/bpf/btf.c:2547:#ifdef __BIG_ENDIAN_BITFIELD\nkernel/bpf/btf.c-2548-\tleft_shift_bits = bits_offset;\n--\nkernel/bpf/btf.c=6460=bool btf_is_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf,\n--\nkernel/bpf/btf.c-6537-/* forward declarations for arch-specific underlying types of\nkernel/bpf/btf.c:6538: * bpf_user_pt_regs_t; this avoids the need for arch-specific #ifdef\nkernel/bpf/btf.c-6539- * compilation guards below for BPF_PROG_TYPE_PERF_EVENT checks, but still\n--\nkernel/bpf/btf.c=6800=__u32 btf_relocate_id(const struct btf *btf, __u32 id)\n--\nkernel/bpf/btf.c-6806-\nkernel/bpf/btf.c:6807:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-6808-\n--\nkernel/bpf/btf.c=8709=int btf_type_name_to_buf(const struct btf *btf, u32 type_id, char *buf, int len)\n--\nkernel/bpf/btf.c-8718-\nkernel/bpf/btf.c:8719:#ifdef CONFIG_PROC_FS\nkernel/bpf/btf.c-8720-static void bpf_btf_show_fdinfo(struct seq_file *m, struct file *filp)\n--\nkernel/bpf/btf.c=8734=const struct file_operations btf_fops = {\nkernel/bpf/btf.c:8735:#ifdef CONFIG_PROC_FS\nkernel/bpf/btf.c-8736-\t.show_fdinfo\t= bpf_btf_show_fdinfo,\n--\nkernel/bpf/btf.c=8882=enum {\n--\nkernel/bpf/btf.c-8885-\nkernel/bpf/btf.c:8886:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8887-struct btf_module {\n--\nkernel/bpf/btf.c=9027=struct module *btf_try_get_module(const struct btf *btf)\n--\nkernel/bpf/btf.c-9029-\tstruct module *res = NULL;\nkernel/bpf/btf.c:9030:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9031-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c=9057=struct btf *btf_get_module_btf(const struct module *module)\nkernel/bpf/btf.c-9058-{\nkernel/bpf/btf.c:9059:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9060-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-9070-\nkernel/bpf/btf.c:9071:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9072-\tmutex_lock(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=9235=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\nkernel/bpf/btf.c-9236-{\nkernel/bpf/btf.c:9237:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9238-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-9251-\nkernel/bpf/btf.c:9252:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9253-\tguard(mutex)(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=9900=static struct bpf_cand_cache *populate_cand_cache(struct bpf_cand_cache *cands,\n--\nkernel/bpf/btf.c-9927-\nkernel/bpf/btf.c:9928:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9929-static void __purge_cand_cache(struct btf *btf, struct bpf_cand_cache **cache,\n--\nkernel/bpf/btf.c=10232=bool btf_type_ids_nocast_alias(struct bpf_verifier_log *log,\n--\nkernel/bpf/btf.c-10286-\nkernel/bpf/btf.c:10287:#ifdef CONFIG_BPF_JIT\nkernel/bpf/btf.c-10288-static int\n"
}

11/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38080
							output: 32
							thoughts: 262
						

Thoughts:
**My Initial Assessment of the BTF Function Additions**

Alright, let's break down these new functions in `kernel/bpf/btf.c`. I see we've added a suite of functions dealing with 'loc' (location) parameters and protocols, along with some logging utilities and metadata checks: `btf_loc_param_check_meta`, `btf_loc_param_log`, `btf_loc_proto_check_meta`, `btf_loc_proto_log`, `btf_loc_proto_resolve`, `btf_verifier_log_loc`, `btf_locsec_check_meta`, `btf_locsec_log`, and `btf_locsec_resolve`. Clearly, there's a significant focus on runtime inspection and verification.

My next step is understanding the call paths. When BTF data is loaded through `bpf(BPF_BTF_LOAD, ...)` the path seems to be either `btf_load_from_raw()` or `btf_new_fd()` which then goes to `btf_check_all_metas()`. From there, `kind_ops[kind]->check_meta` is called. We then see `btf_check_all_types()` which calls `kind_ops[kind]->resolve` through `btf_resolve()`.

So, the critical entry points are `check_meta` and `resolve`. I need to dig into the calls to these functions within `btf.c` itself. Knowing the specific contexts where these functions are invoked is essential to grasp the implications of these changes.



12/2 2026/09/17 18:48 tool grepper
0m Args:
{
  "Expression": "check_meta",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=449=struct btf_kind_operations {\nkernel/bpf/btf.c:450:\ts32 (*check_meta)(struct btf_verifier_env *env,\nkernel/bpf/btf.c-451-\t\t\t  const struct btf_type *t,\n--\nkernel/bpf/btf.c=2336=static int btf_int_check_kflag_member(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-2391-\nkernel/bpf/btf.c:2392:static s32 btf_int_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-2393-\t\t\t      const struct btf_type *t,\n--\nkernel/bpf/btf.c=2647=static const struct btf_kind_operations int_ops = {\nkernel/bpf/btf.c:2648:\t.check_meta = btf_int_check_meta,\nkernel/bpf/btf.c-2649-\t.resolve = btf_df_resolve,\n--\nkernel/bpf/btf.c=2706=static int btf_ptr_check_member(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-2731-\nkernel/bpf/btf.c:2732:static int btf_ref_type_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-2733-\t\t\t\t   const struct btf_type *t,\n--\nkernel/bpf/btf.c=2986=static const struct btf_kind_operations modifier_ops = {\nkernel/bpf/btf.c:2987:\t.check_meta = btf_ref_type_check_meta,\nkernel/bpf/btf.c-2988-\t.resolve = btf_modifier_resolve,\n--\nkernel/bpf/btf.c=2995=static const struct btf_kind_operations ptr_ops = {\nkernel/bpf/btf.c:2996:\t.check_meta = btf_ref_type_check_meta,\nkernel/bpf/btf.c-2997-\t.resolve = btf_ptr_resolve,\n--\nkernel/bpf/btf.c-3003-\nkernel/bpf/btf.c:3004:static s32 btf_fwd_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-3005-\t\t\t      const struct btf_type *t,\n--\nkernel/bpf/btf.c=3036=static const struct btf_kind_operations fwd_ops = {\nkernel/bpf/btf.c:3037:\t.check_meta = btf_fwd_check_meta,\nkernel/bpf/btf.c-3038-\t.resolve = btf_df_resolve,\n--\nkernel/bpf/btf.c=3045=static int btf_array_check_member(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-3073-\nkernel/bpf/btf.c:3074:static s32 btf_array_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-3075-\t\t\t\tconst struct btf_type *t,\n--\nkernel/bpf/btf.c=3287=static const struct btf_kind_operations array_ops = {\nkernel/bpf/btf.c:3288:\t.check_meta = btf_array_check_meta,\nkernel/bpf/btf.c-3289-\t.resolve = btf_array_resolve,\n--\nkernel/bpf/btf.c=3296=static int btf_struct_check_member(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-3320-\nkernel/bpf/btf.c:3321:static s32 btf_struct_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-3322-\t\t\t\t const struct btf_type *t,\n--\nkernel/bpf/btf.c=4473=static const struct btf_kind_operations struct_ops = {\nkernel/bpf/btf.c:4474:\t.check_meta = btf_struct_check_meta,\nkernel/bpf/btf.c-4475-\t.resolve = btf_struct_resolve,\n--\nkernel/bpf/btf.c=4507=static int btf_enum_check_kflag_member(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-4541-\nkernel/bpf/btf.c:4542:static s32 btf_enum_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-4543-\t\t\t       const struct btf_type *t,\n--\nkernel/bpf/btf.c=4641=static const struct btf_kind_operations enum_ops = {\nkernel/bpf/btf.c:4642:\t.check_meta = btf_enum_check_meta,\nkernel/bpf/btf.c-4643-\t.resolve = btf_df_resolve,\n--\nkernel/bpf/btf.c-4649-\nkernel/bpf/btf.c:4650:static s32 btf_enum64_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-4651-\t\t\t\t const struct btf_type *t,\n--\nkernel/bpf/btf.c=4744=static const struct btf_kind_operations enum64_ops = {\nkernel/bpf/btf.c:4745:\t.check_meta = btf_enum64_check_meta,\nkernel/bpf/btf.c-4746-\t.resolve = btf_df_resolve,\n--\nkernel/bpf/btf.c-4752-\nkernel/bpf/btf.c:4753:static s32 btf_loc_param_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-4754-\t\t\t\t    const struct btf_type *t,\n--\nkernel/bpf/btf.c=4799=static const struct btf_kind_operations loc_param_ops = {\nkernel/bpf/btf.c:4800:\t.check_meta = btf_loc_param_check_meta,\nkernel/bpf/btf.c-4801-\t.resolve = btf_df_resolve,\n--\nkernel/bpf/btf.c-4807-\nkernel/bpf/btf.c:4808:static s32 btf_loc_proto_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-4809-\t\t\t\t    const struct btf_type *t,\n--\nkernel/bpf/btf.c=4881=static const struct btf_kind_operations loc_proto_ops = {\nkernel/bpf/btf.c:4882:\t.check_meta = btf_loc_proto_check_meta,\nkernel/bpf/btf.c-4883-\t.resolve = btf_loc_proto_resolve,\n--\nkernel/bpf/btf.c=4891=static void btf_verifier_log_loc(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-4917-\nkernel/bpf/btf.c:4918:static s32 btf_locsec_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-4919-\t\t\t\t const struct btf_type *t,\n--\nkernel/bpf/btf.c=5017=static const struct btf_kind_operations locsec_ops = {\nkernel/bpf/btf.c:5018:\t.check_meta = btf_locsec_check_meta,\nkernel/bpf/btf.c-5019-\t.resolve = btf_locsec_resolve,\n--\nkernel/bpf/btf.c-5025-\nkernel/bpf/btf.c:5026:static s32 btf_func_proto_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-5027-\t\t\t\t     const struct btf_type *t,\n--\nkernel/bpf/btf.c=5095=static const struct btf_kind_operations func_proto_ops = {\nkernel/bpf/btf.c:5096:\t.check_meta = btf_func_proto_check_meta,\nkernel/bpf/btf.c-5097-\t.resolve = btf_df_resolve,\n--\nkernel/bpf/btf.c-5112-\nkernel/bpf/btf.c:5113:static s32 btf_func_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-5114-\t\t\t       const struct btf_type *t,\n--\nkernel/bpf/btf.c=5153=static const struct btf_kind_operations func_ops = {\nkernel/bpf/btf.c:5154:\t.check_meta = btf_func_check_meta,\nkernel/bpf/btf.c-5155-\t.resolve = btf_func_resolve,\n--\nkernel/bpf/btf.c-5161-\nkernel/bpf/btf.c:5162:static s32 btf_var_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-5163-\t\t\t      const struct btf_type *t,\n--\nkernel/bpf/btf.c=5217=static const struct btf_kind_operations var_ops = {\nkernel/bpf/btf.c:5218:\t.check_meta\t\t= btf_var_check_meta,\nkernel/bpf/btf.c-5219-\t.resolve\t\t= btf_var_resolve,\n--\nkernel/bpf/btf.c-5225-\nkernel/bpf/btf.c:5226:static s32 btf_datasec_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-5227-\t\t\t\t  const struct btf_type *t,\n--\nkernel/bpf/btf.c=5369=static const struct btf_kind_operations datasec_ops = {\nkernel/bpf/btf.c:5370:\t.check_meta\t\t= btf_datasec_check_meta,\nkernel/bpf/btf.c-5371-\t.resolve\t\t= btf_datasec_resolve,\n--\nkernel/bpf/btf.c-5377-\nkernel/bpf/btf.c:5378:static s32 btf_float_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-5379-\t\t\t\tconst struct btf_type *t,\n--\nkernel/bpf/btf.c=5444=static const struct btf_kind_operations float_ops = {\nkernel/bpf/btf.c:5445:\t.check_meta = btf_float_check_meta,\nkernel/bpf/btf.c-5446-\t.resolve = btf_df_resolve,\n--\nkernel/bpf/btf.c-5452-\nkernel/bpf/btf.c:5453:static s32 btf_decl_tag_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-5454-\t\t\t      const struct btf_type *t,\n--\nkernel/bpf/btf.c=5543=static const struct btf_kind_operations decl_tag_ops = {\nkernel/bpf/btf.c:5544:\t.check_meta = btf_decl_tag_check_meta,\nkernel/bpf/btf.c-5545-\t.resolve = btf_decl_tag_resolve,\n--\nkernel/bpf/btf.c=5675=static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {\n--\nkernel/bpf/btf.c-5699-\nkernel/bpf/btf.c:5700:static s32 btf_check_meta(struct btf_verifier_env *env,\nkernel/bpf/btf.c-5701-\t\t\t  const struct btf_type *t,\n--\nkernel/bpf/btf.c-5726-\nkernel/bpf/btf.c:5727:\tvar_meta_size = btf_type_ops(t)-\u003echeck_meta(env, t, meta_left);\nkernel/bpf/btf.c-5728-\tif (var_meta_size \u003c 0)\n--\nkernel/bpf/btf.c=5736=static int btf_check_all_metas(struct btf_verifier_env *env)\n--\nkernel/bpf/btf.c-5750-\nkernel/bpf/btf.c:5751:\t\tmeta_size = btf_check_meta(env, t, end - cur);\nkernel/bpf/btf.c-5752-\t\tif (meta_size \u003c 0)\n"
}

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

Args:
null

Results:
null

Tokens:
							input: 42321
							output: 32
							thoughts: 432
						

Thoughts:
**My Analysis of BTF Function Inlining and Symbol Visibility**

Okay, let's break this down. I'm focusing on these functions: `btf_check_all_metas`, `btf_check_all_types`, and `btf_resolve`. I need to understand how they interact with the BTF loading process.

Specifically, I'm concerned about the inlining of several static functions: `btf_loc_param_check_meta`, `btf_loc_proto_check_meta`, `btf_loc_proto_resolve`, `btf_locsec_check_meta`, `btf_locsec_resolve`, `btf_verifier_log_loc`, `btf_loc_param_log`, `btf_loc_proto_log`, and `btf_locsec_log`. These are all called via function pointers through `kind_ops`, which is crucial.

The question is, *can* the compiler inline them when invoked through `kind_ops[kind]->check_meta` or `kind_ops[kind]->resolve`? My initial intuition is no, and the reason is this: the addresses of these static functions are explicitly taken and stored in structures like `static const struct btf_kind_operations loc_param_ops = { ... };`. These structures are then placed into `kind_ops[]`. Taking the address is a barrier to inlining. Because the address is taken and used in a function pointer assignment, they will *not* be inlined.

Therefore, these functions *must* exist as symbols in vmlinux. Now, I need to verify that these are, indeed, symbols within the kernel image. I need to make sure I am correct, and I will verify that they are symbols.

On a related note, I should check the non-static entry points for BTF loading as well. I need to know the full picture of the loading process. I need to look at what functions in `kernel/bpf/btf.c` handle BTF loading. Functions like `btf_load_into_kernel`, `btf_new_fd`, `btf_parse`, and `bpf_btf_load` are the relevant functions to investigate. I'll need to examine `kernel/bpf/btf.c` around the `BPF_BTF_LOAD` area. This should give me a complete understanding.



14/2 2026/09/17 18:48 tool grepper
0m Args:
{
  "Expression": "bpf_btf_load",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/syscall.c=5535=static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-5563-\nkernel/bpf/syscall.c:5564:static int bpf_btf_load(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\nkernel/bpf/syscall.c-5565-{\n--\nkernel/bpf/syscall.c=6303=static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size,\n--\nkernel/bpf/syscall.c-6416-\t\t\t\t\t\u0026attr_common, uattr_common, size_common);\nkernel/bpf/syscall.c:6417:\t\terr = err ?: bpf_btf_load(\u0026attr, uattr, \u0026attr_log);\nkernel/bpf/syscall.c-6418-\t\tbreak;\n"
}

15/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43573
							output: 37
							thoughts: 22
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:

**Diving into bpf_btf_load**

Alright, time to get my hands dirty. Let's trace this `bpf_btf_load` function within `btf.c`. I need to understand exactly what's happening under the hood when a BTF object gets loaded. Specifically, what other functions does this pivotal entry point invoke? I'm hoping to get a clearer picture of the data structures involved, the validation steps, and how the BTF data finally gets integrated into the kernel's BPF infrastructure. I suspect there'll be calls related to symbol parsing, type definition handling, perhaps some checks for BTF version compatibility... and of course, memory allocation and object initialization. My goal is to map out the call graph from `bpf_btf_load` so I can understand any potential performance bottlenecks or subtle behavior that might impact more complex BPF programs. This will help me be prepared for edge cases and debugging when things get out of control.



16/2 2026/09/17 18:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 5564,
  "LineCount": 40
}

Results:
{
  "Contents": "5564:\tstatic int bpf_btf_load(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\n5565:\t{\n5566:\t\tstruct bpf_token *token = NULL;\n5567:\t\n5568:\t\tif (CHECK_ATTR(BPF_BTF_LOAD))\n5569:\t\t\treturn -EINVAL;\n5570:\t\n5571:\t\tif (attr-\u003ebtf_flags \u0026 ~BPF_F_TOKEN_FD)\n5572:\t\t\treturn -EINVAL;\n5573:\t\n5574:\t\tif (attr-\u003ebtf_flags \u0026 BPF_F_TOKEN_FD) {\n5575:\t\t\ttoken = bpf_token_get_from_fd(attr-\u003ebtf_token_fd);\n5576:\t\t\tif (IS_ERR(token))\n5577:\t\t\t\treturn PTR_ERR(token);\n5578:\t\t\tif (!bpf_token_allow_cmd(token, BPF_BTF_LOAD)) {\n5579:\t\t\t\tbpf_token_put(token);\n5580:\t\t\t\ttoken = NULL;\n5581:\t\t\t}\n5582:\t\t}\n5583:\t\n5584:\t\tif (!bpf_token_capable(token, CAP_BPF)) {\n5585:\t\t\tbpf_token_put(token);\n5586:\t\t\treturn -EPERM;\n5587:\t\t}\n5588:\t\n5589:\t\tbpf_token_put(token);\n5590:\t\n5591:\t\treturn btf_new_fd(attr, uattr, attr_log);\n5592:\t}\n5593:\t\n5594:\t#define BPF_BTF_GET_FD_BY_ID_LAST_FIELD fd_by_id_token_fd\n5595:\t\n5596:\tstatic int bpf_btf_get_fd_by_id(const union bpf_attr *attr)\n5597:\t{\n5598:\t\tstruct bpf_token *token = NULL;\n5599:\t\n5600:\t\tif (CHECK_ATTR(BPF_BTF_GET_FD_BY_ID))\n5601:\t\t\treturn -EINVAL;\n5602:\t\n5603:\t\tif (attr-\u003eopen_flags \u0026 ~BPF_F_TOKEN_FD)\n"
}

17/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44508
							output: 36
							thoughts: 53
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Diving into BTF Loading**

Okay, so `bpf_btf_load` is the entry point, and it calls `btf_new_fd`. That function name rings a bell... I'm guessing that's where the heavy lifting of BTF object creation happens. Let's trace into that `btf_new_fd` function in `kernel/bpf/btf.c`. I need to understand how it's processing the attributes that are passed in. Looks like the `attr`, `uattr` and `attr_log` variables will be key to understanding the BTF creation process. I expect to find the actual BTF data structures being built or populated in that function. It's time to dig in and see what's happening.



18/2 2026/09/17 18:48 tool grepper
0m Args:
{
  "Expression": "int btf_new_fd",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=8741=static int __btf_new_fd(struct btf *btf)\n--\nkernel/bpf/btf.c-8745-\nkernel/bpf/btf.c:8746:int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\nkernel/bpf/btf.c-8747-{\n"
}

19/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44912
							output: 38
							thoughts: 15
						

Thoughts:
Here's a breakdown of the process, from my perspective, as an expert in this field.

**Deconstructing `btf_new_fd` Flow**

Okay, so I'm looking at the `btf_new_fd` function, and my mental checklist is already running. The objective, as I recall, is to handle BTF data provided via a file descriptor. So, first, I want to understand how it's getting *into* that function. What are the preconditions? Is it coming from a user-space program? Is this related to a kernel module loading? I need the context. What's the role of that file descriptor? Is it representing a file on disk, a memory mapping, or something else entirely?

Then, I'm thinking about the implications. What kind of validation is happening? There has to be robust checking, to make sure this BTF data is well-formed, complete, and doesn't contain any malicious code or corrupt structures that could crash the system. I'm especially interested in how it handles size limitations and potential overflow problems. Security, in this area, is paramount. I'm mentally parsing where the actual data gets read, whether it's through a system call like `read` or a memory mapping interface. I’m thinking about how the system handles the size or length of the incoming BTF data, and how that gets handled during reading.

Next, I need to know how the data is *processed* and *integrated*. How is the BTF information structured internally? Are we creating new BTF objects within the kernel, or updating existing ones? What are the implications if this BTF information is replacing existing data? I need to understand how the new BTF data is linked to the appropriate structures within the kernel, and the implications of this linking.

And finally, I'm thinking about error handling and cleanup. What happens if something goes wrong during the process? Are we gracefully releasing resources like memory allocations? Are there any potential memory leaks? Is there robust error checking at *every* stage? If the data is corrupt, or some other error occurs, how do we back out without compromising the system's stability? And most importantly, how do we notify the caller of the failure with a meaningful return code? I need to trace the return values and error conditions, how those errors are propagated up the call stack, and what the potential impact is of failure. I see `btf_new_fd`, it’s the entry point, so I’m mentally walking all the possible return paths. I want to see how these errors are handled at the caller level.



20/2 2026/09/17 18:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 8746,
  "LineCount": 40
}

Results:
{
  "Contents": "8746:\tint btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\n8747:\t{\n8748:\t\tstruct btf *btf;\n8749:\t\tint ret;\n8750:\t\n8751:\t\tbtf = btf_parse(attr, uattr, attr_log);\n8752:\t\tif (IS_ERR(btf))\n8753:\t\t\treturn PTR_ERR(btf);\n8754:\t\n8755:\t\tret = btf_alloc_id(btf);\n8756:\t\tif (ret) {\n8757:\t\t\tbtf_free(btf);\n8758:\t\t\treturn ret;\n8759:\t\t}\n8760:\t\n8761:\t\t/*\n8762:\t\t * The BTF ID is published to the userspace.\n8763:\t\t * All BTF free must go through call_rcu() from\n8764:\t\t * now on (i.e. free by calling btf_put()).\n8765:\t\t */\n8766:\t\n8767:\t\tret = __btf_new_fd(btf);\n8768:\t\tif (ret \u003c 0)\n8769:\t\t\tbtf_put(btf);\n8770:\t\n8771:\t\treturn ret;\n8772:\t}\n8773:\t\n8774:\tstruct btf *btf_get_by_fd(int fd)\n8775:\t{\n8776:\t\tstruct btf *btf;\n8777:\t\tCLASS(fd, f)(fd);\n8778:\t\n8779:\t\tbtf = __btf_get_by_fd(f);\n8780:\t\tif (!IS_ERR(btf))\n8781:\t\t\trefcount_inc(\u0026btf-\u003erefcnt);\n8782:\t\n8783:\t\treturn btf;\n8784:\t}\n8785:\t\n"
}

21/2 2026/09/17 18:48 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46065
							output: 38
							thoughts: 7
						

Thoughts:
Okay, here's my attempt at summarizing the provided thought process, tailored for an expert in their field, and written in the first person:

**My Perspective on `btf_parse`**

Alright, let's break down this `btf_parse` process. I see this as a critical piece, a foundational step in any BPF-centric system. It's essentially the interpreter, right? The mechanism that takes the raw BTF (BPF Type Format) data, that crucial metadata that describes all the types used in our BPF programs and maps, and translates it into something usable and understandable within our environment. I'm thinking about the implications here – how efficiently this is done directly impacts the performance of BPF program loading, verification, and ultimately, runtime execution.

My mind immediately goes to the potential bottlenecks. Is the parsing optimized for various BTF structures? Large, complex BTF blobs can be quite challenging, especially when we're dealing with nested structures, unions, and the complexities of function signatures. I'm wondering about the strategies employed for error handling; how robust is this implementation against malformed or unexpected BTF data? A single flaw here can propagate and cause catastrophic failures, so I’m keen to see the approach to validation and graceful degradation.

Furthermore, how does it handle different BTF versions, if any? Backward compatibility is always a consideration. Are there any clever techniques used for caching or pre-computing frequently accessed type information to speed things up? I assume there's some sort of internal representation or a symbol table-like structure that makes querying and navigating the parsed BTF data efficient. This internal representation is critical: I hope it provides a well-defined abstraction layer for the rest of the BPF toolchain to easily access the necessary information. I want to see the performance profile of the parse, especially if a large BTF is loaded. It is a key step, it must be fast!

Finally, how does it interact with the verifier? Is it providing the necessary type information directly to the verifier, or is there an intermediate step? This connection is paramount for the verifier to perform its static analysis and ensure the safety and correctness of our BPF programs. I need a tight coupling here, to ensure all is well.

Essentially, I see this `btf_parse` functionality as the gateway to unlocking the true potential of BPF. Done well, it unlocks enormous capabilities; done poorly, it is a limiting factor in both power and performance. I need a robust and fast parsing phase.



22/2 2026/09/17 18:49 tool grepper
0m Args:
{
  "Expression": "struct btf \\*btf_parse\\(",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=6240=static int btf_check_modifier_chain_length(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-6277-\nkernel/bpf/btf.c:6278:static struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr,\nkernel/bpf/btf.c-6279-\t\t\t     struct bpf_log_attr *attr_log)\n"
}

23/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46779
							output: 38
							thoughts: 26
						

Thoughts:
Here's my summary, as if I were the one thinking these thoughts, targeting an expert audience:

**Analyzing BTF Handling in `kernel/bpf/btf.c`**

Alright, let's dive into the core of how the BTF machinery works within the kernel. I'm focusing on lines 6278 through 6330 in `kernel/bpf/btf.c`. This section likely deals with a crucial aspect of BTF (Berkeley Packet Filter Type Format) handling. I'm expecting to see operations related to either type resolution, data structure manipulation, or maybe even error handling during the BTF parsing/processing phase. Given the range, it could be a specific function responsible for a critical check or data conversion. I'm hoping to see how the code gracefully handles any edge cases, particularly those involving complex nested types or potentially malicious BTF metadata. I'm also anticipating that I might spot some optimizations or tricks the developers have put in place to boost the efficiency of BTF operations. My expert understanding of eBPF means I'm looking for any clues that would impact the performance or security characteristics of the underlying system.



24/2 2026/09/17 18:49 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 6278,
  "LineCount": 45
}

Results:
{
  "Contents": "6278:\tstatic struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr,\n6279:\t\t\t\t     struct bpf_log_attr *attr_log)\n6280:\t{\n6281:\t\tbpfptr_t btf_data = make_bpfptr(attr-\u003ebtf, uattr.is_kernel);\n6282:\t\tstruct btf_struct_metas *struct_meta_tab;\n6283:\t\tstruct btf_verifier_env *env = NULL;\n6284:\t\tstruct btf *btf = NULL;\n6285:\t\tu8 *data;\n6286:\t\tint err, ret;\n6287:\t\n6288:\t\tif (attr-\u003ebtf_size \u003e BTF_MAX_SIZE)\n6289:\t\t\treturn ERR_PTR(-E2BIG);\n6290:\t\n6291:\t\tenv = kzalloc_obj(*env, GFP_KERNEL | __GFP_NOWARN);\n6292:\t\tif (!env)\n6293:\t\t\treturn ERR_PTR(-ENOMEM);\n6294:\t\n6295:\t\t/* user could have requested verbose verifier output\n6296:\t\t * and supplied buffer to store the verification trace\n6297:\t\t */\n6298:\t\terr = bpf_vlog_init(\u0026env-\u003elog, attr_log-\u003elevel, attr_log-\u003eubuf, attr_log-\u003esize);\n6299:\t\tif (err)\n6300:\t\t\tgoto errout_free;\n6301:\t\n6302:\t\tbtf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);\n6303:\t\tif (!btf) {\n6304:\t\t\terr = -ENOMEM;\n6305:\t\t\tgoto errout;\n6306:\t\t}\n6307:\t\tenv-\u003ebtf = btf;\n6308:\t\tbtf-\u003enamed_start_id = 0;\n6309:\t\n6310:\t\tdata = kvmalloc(attr-\u003ebtf_size, GFP_KERNEL | __GFP_NOWARN);\n6311:\t\tif (!data) {\n6312:\t\t\terr = -ENOMEM;\n6313:\t\t\tgoto errout;\n6314:\t\t}\n6315:\t\n6316:\t\tbtf-\u003edata = data;\n6317:\t\tbtf-\u003edata_size = attr-\u003ebtf_size;\n6318:\t\n6319:\t\tif (copy_from_bpfptr(data, btf_data, attr-\u003ebtf_size)) {\n6320:\t\t\terr = -EFAULT;\n6321:\t\t\tgoto errout;\n6322:\t\t}\n"
}

25/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47806
							output: 38
							thoughts: 13
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Analyzing the Data Flow**

Alright, line 6322… Let's pause and consider what's happening after that. Given my understanding of this system's architecture, this specific point is crucial because it often indicates [insert relevant technical implication – e.g., the termination of a major loop, the beginning of a data transformation, a call to a critical module, etc.]. I need to determine if there are any potential bottlenecks or areas of vulnerability that could arise, particularly related to [mention a relevant concern – e.g., memory allocation, race conditions, incorrect data formatting, etc.]. My focus is to quickly recognize the key function call or process that immediately follows this line. This helps me to get a better overview of the dataflow as well as where my focus should be as I move forward. A solid grasp of the logical continuation beyond this point will inform my review of the preceding section. This approach allows me to identify any logic errors and ensure the integrity of the solution.



26/2 2026/09/17 18:49 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 6323,
  "LineCount": 45
}

Results:
{
  "Contents": "6323:\t\n6324:\t\terr = btf_parse_hdr(env);\n6325:\t\tif (err)\n6326:\t\t\tgoto errout;\n6327:\t\n6328:\t\tbtf-\u003enohdr_data = btf-\u003edata + btf-\u003ehdr.hdr_len;\n6329:\t\n6330:\t\terr = btf_parse_str_sec(env);\n6331:\t\tif (err)\n6332:\t\t\tgoto errout;\n6333:\t\n6334:\t\terr = btf_parse_layout_sec(env);\n6335:\t\tif (err)\n6336:\t\t\tgoto errout;\n6337:\t\n6338:\t\terr = btf_parse_type_sec(env);\n6339:\t\tif (err)\n6340:\t\t\tgoto errout;\n6341:\t\n6342:\t\terr = btf_check_modifier_chain_length(env, btf, 1);\n6343:\t\tif (err)\n6344:\t\t\tgoto errout;\n6345:\t\n6346:\t\tstruct_meta_tab = btf_parse_struct_metas(\u0026env-\u003elog, btf);\n6347:\t\tif (IS_ERR(struct_meta_tab)) {\n6348:\t\t\terr = PTR_ERR(struct_meta_tab);\n6349:\t\t\tgoto errout;\n6350:\t\t}\n6351:\t\tbtf-\u003estruct_meta_tab = struct_meta_tab;\n6352:\t\n6353:\t\tif (struct_meta_tab) {\n6354:\t\t\tint i;\n6355:\t\n6356:\t\t\tfor (i = 0; i \u003c struct_meta_tab-\u003ecnt; i++) {\n6357:\t\t\t\terr = btf_check_and_fixup_fields(btf, struct_meta_tab-\u003etypes[i].record);\n6358:\t\t\t\tif (err \u003c 0)\n6359:\t\t\t\t\tgoto errout_meta;\n6360:\t\t\t}\n6361:\t\t}\n6362:\t\n6363:\t\terr = bpf_log_attr_finalize(attr_log, \u0026env-\u003elog);\n6364:\t\tif (err)\n6365:\t\t\tgoto errout_free;\n6366:\t\n6367:\t\tbtf_verifier_env_free(env);\n"
}

27/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48733
							output: 38
							thoughts: 59
						

Thoughts:
Here's my summary, as if I were thinking it:

**Deep Dive into BTF Type Section Parsing**

Okay, so we're in the thick of it – time to dissect the BTF type section parsing. I'm seeing `btf_parse_type_sec(env)` being called, which is the expected entry point for processing the type section, and that's kicking off a cascade of checks! Good to see it's well-structured. It immediately calls `btf_check_all_metas(env)` and `btf_check_all_types(env)`. That makes perfect sense; metadata and type integrity should be verified early on. This indicates a robust approach to error detection, which is critical in BTF to ensure the validity of the data. Now, let's zoom in on `btf_parse_type_sec` itself and see how it handles things... let's see what’s under the hood.



28/2 2026/09/17 18:49 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 5850,
  "LineCount": 40
}

Results:
{
  "Contents": "5850:\t\tfor (i = btf-\u003ebase_btf ? 0 : 1; i \u003c btf-\u003enr_types; i++) {\n5851:\t\t\ttype_id = btf-\u003estart_id + i;\n5852:\t\t\tt = btf_type_by_id(btf, type_id);\n5853:\t\n5854:\t\t\tenv-\u003elog_type_id = type_id;\n5855:\t\t\tif (btf_type_needs_resolve(t) \u0026\u0026\n5856:\t\t\t    !env_type_is_resolved(env, type_id)) {\n5857:\t\t\t\terr = btf_resolve(env, t, type_id);\n5858:\t\t\t\tif (err)\n5859:\t\t\t\t\treturn err;\n5860:\t\t\t}\n5861:\t\n5862:\t\t\tif (btf_type_is_func_proto(t)) {\n5863:\t\t\t\terr = btf_func_proto_check(env, t);\n5864:\t\t\t\tif (err)\n5865:\t\t\t\t\treturn err;\n5866:\t\t\t}\n5867:\t\t}\n5868:\t\n5869:\t\treturn 0;\n5870:\t}\n5871:\t\n5872:\tstatic int btf_parse_type_sec(struct btf_verifier_env *env)\n5873:\t{\n5874:\t\tconst struct btf_header *hdr = \u0026env-\u003ebtf-\u003ehdr;\n5875:\t\tint err;\n5876:\t\n5877:\t\t/* Type section must align to 4 bytes */\n5878:\t\tif (hdr-\u003etype_off \u0026 (sizeof(u32) - 1)) {\n5879:\t\t\tbtf_verifier_log(env, \"Unaligned type_off\");\n5880:\t\t\treturn -EINVAL;\n5881:\t\t}\n5882:\t\n5883:\t\tif (!env-\u003ebtf-\u003ebase_btf \u0026\u0026 !hdr-\u003etype_len) {\n5884:\t\t\tbtf_verifier_log(env, \"No type found\");\n5885:\t\t\treturn -EINVAL;\n5886:\t\t}\n5887:\t\n5888:\t\terr = btf_check_all_metas(env);\n5889:\t\tif (err)\n"
}

29/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49653
							output: 34
							thoughts: 1069
						

Thoughts:
**Analyzing BTF Metadata Handling for Fuzzing**

Okay, so I'm digging into this BTF code, specifically the verification and resolution process. `btf_parse_type_sec` calls `btf_check_all_metas`, which then dispatches to `kind_ops[kind]->check_meta`. Similarly, `btf_check_all_types` calls `btf_resolve`, which, again, dispatches to `kind_ops[kind]->resolve`. That's the core flow.

Now, I need to focus on the key functions introduced in `kernel/bpf/btf.c`. Let's see... I've got `btf_loc_param_check_meta`, `btf_loc_proto_check_meta`, `btf_loc_proto_resolve`, `btf_locsec_check_meta`, and `btf_locsec_resolve`. Then there are logging helpers like `btf_verifier_log_loc`, `btf_loc_param_log`, `btf_loc_proto_log`, and `btf_locsec_log`. And crucially, the API entrypoint, `btf_new_fd`, which is likely also known as `bpf_btf_load`.

Right, let's confirm whether these are static or non-static within `btf.c` to see if they're directly targetable. Okay, it looks like they *are* static: `static s32 btf_loc_param_check_meta`, and so on. But they're being assigned to `ops` tables like `loc_param_ops`, meaning the compiler will treat them as distinct functions with their own symbols. That's good, that's what I want!

Now, according to the fuzzing guidelines, I need to pick targeted functions. It states: "AVOID UBIQUITOUS LIFECYCLE HOT-PATHS," and "TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS." The functions I've identified, these `btf_loc_*` functions, look *perfect*. They handle specific logic and are directly called by the kernel's BTF loader. And `btf_new_fd`, while an entrypoint, isn't *ubiquitous*. It's specific to the BTF load functionality. Plus `btf_parse_type_sec` is the parser for the BTF type section. So including `btf_loc_param_check_meta`, `btf_loc_proto_check_meta`, `btf_loc_proto_resolve`, `btf_locsec_check_meta`, `btf_locsec_resolve`, and `btf_new_fd` should be very targeted and precise for fuzzing.

Okay, let's do a double-check on those functions now. Specifically in `btf_loc_param_check_meta`, the following code is present:

```c
	meta_needed = sizeof(*p) + sizeof(__u32) * vlen;
	if (meta_left < meta_needed) {
```

Hold on... What about integer overflow in that `meta_needed` calculation? `vlen` is a `u32`, and `meta_needed` is also a `u32`. If `vlen` is, say, `0x40000000`, then `4 * 0x40000000` could result in zero due to overflow! That could lead to a heap overflow. Wait, what is `btf_vlen(t)`? I need to check how `vlen` is determined.



30/2 2026/09/17 18:49 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "define btf_vlen",
  "PathPrefix": "include/linux/btf.h"
}

Results:
{
  "error": "no matches"
}

31/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 51566
							output: 35
							thoughts: 21
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Hunting Down BTF Vector Length Information**

Okay, so I need to get my hands on the vector length information within the BTF (BPF Type Format) data. I'm thinking, based on past experience and the common naming conventions, that the key I'm after is probably going to be named something along the lines of `btf_vlen` or perhaps `btf_type_vlen`. It’s highly probable it’s under one of those, right? These names are usually pretty consistent within the BTF structure itself. I’ll start digging for those right away and verify what the struct is using within the code to expose this information.



32/2 2026/09/17 18:49 tool grepper
0m Args:
{
  "Expression": "btf_type_vlen",
  "PathPrefix": "include/linux/btf.h"
}

Results:
{
  "Output": "include/linux/btf.h=252=const char *btf_type_str(const struct btf_type *t);\n--\ninclude/linux/btf.h-255-\tfor (i = 0, member = btf_type_member(struct_type);\t\\\ninclude/linux/btf.h:256:\t     i \u003c btf_type_vlen(struct_type);\t\t\t\\\ninclude/linux/btf.h-257-\t     i++, member++)\n--\ninclude/linux/btf.h-260-\tfor (i = 0, member = btf_type_var_secinfo(datasec_type);\t\\\ninclude/linux/btf.h:261:\t     i \u003c btf_type_vlen(datasec_type);\t\t\t\\\ninclude/linux/btf.h-262-\t     i++, member++)\n--\ninclude/linux/btf.h-265-\tfor (i = 0, member = btf_type_loc_secinfo(locsec_type);\t\\\ninclude/linux/btf.h:266:\t     i \u003c btf_type_vlen(locsec_type);\t\t\t\\\ninclude/linux/btf.h-267-\t     i++, member++)\n--\ninclude/linux/btf.h=439=static inline bool btf_type_is_array(const struct btf_type *t)\n--\ninclude/linux/btf.h-443-\ninclude/linux/btf.h:444:static inline u32 btf_type_vlen(const struct btf_type *t)\ninclude/linux/btf.h-445-{\n--\ninclude/linux/btf.h=449=static inline u32 btf_vlen(const struct btf_type *t)\ninclude/linux/btf.h-450-{\ninclude/linux/btf.h:451:\treturn btf_type_vlen(t);\ninclude/linux/btf.h-452-}\n"
}

33/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52303
							output: 36
							thoughts: 24
						

Thoughts:
Here's a summary of my thought process, as requested:

**BTF Header Analysis: A Quick Scan**

Alright, let's dive in. My initial thought is to zero in on lines 440-455 within `include/linux/btf.h`. I'm going to quickly skim this section, expecting it to contain crucial details regarding BTF (BPF Type Format) internals. Depending on what it is, I will have the following questions and more:

*   **Data Structures:** What key data structures are defined or declared in this section? BTF's effectiveness hinges on efficient type representation, so I anticipate structures for handling type information, potentially including function prototypes, enums, structs, and typedefs.
*   **Encoding/Decoding:** Are there any hints about the encoding or decoding of BTF data? I'm looking for clues about how type information is serialized and deserialized for use within BPF programs and the kernel. Is this related to `btf_type` and other related structures?
*   **Versioning:** Any references to BTF versioning? Proper BPF usage means being sure the BTF data is compatible with the version of the kernel and the eBPF program, so that's something to look for.
*   **Utilities**: Any functions or macros that provide utility functions for processing the BTF data? Are there any functions to look up types, validate the data, or perform conversions?
*   **Complexity**: Are there any red flags for particularly complex aspects of BTF that could introduce challenges in understanding or implementation?

I'll be paying close attention to any comments or variable names that hint at the purpose and behavior of the code. My goal is to quickly grasp the core functionality of this segment and how it fits into the broader BTF architecture. I'm hoping this is a relatively self-contained section, so I can grasp it fast. I'll need this information in order to understand how BTF works.



34/2 2026/09/17 18:49 tool read-file
0m Args:
{
  "File": "include/linux/btf.h",
  "FirstLine": 440,
  "LineCount": 20
}

Results:
{
  "Contents": " 440:\t{\n 441:\t\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_ARRAY;\n 442:\t}\n 443:\t\n 444:\tstatic inline u32 btf_type_vlen(const struct btf_type *t)\n 445:\t{\n 446:\t\treturn BTF_INFO_VLEN(t-\u003einfo);\n 447:\t}\n 448:\t\n 449:\tstatic inline u32 btf_vlen(const struct btf_type *t)\n 450:\t{\n 451:\t\treturn btf_type_vlen(t);\n 452:\t}\n 453:\t\n 454:\tstatic inline u16 btf_func_linkage(const struct btf_type *t)\n 455:\t{\n 456:\t\treturn BTF_INFO_VLEN(t-\u003einfo);\n 457:\t}\n 458:\t\n 459:\tstatic inline bool btf_type_kflag(const struct btf_type *t)\n"
}

35/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53083
							output: 28
							thoughts: 1596
						

Thoughts:
**Analyzing BTF Type Resolution Logic**

Okay, so I'm diving into this BTF type resolution code. First thing, I'm noting that `BTF_INFO_VLEN` is 16 bits, so the maximum `vlen` is 65535, which means 32-bit math won't overflow – that's good.

Now, I'm focusing on `btf_locsec_resolve`. I see this loop iterating through members, and I'm following the logic carefully, trying to keep track of the `next_member` index. It seems like the critical part is when it checks `env_type_is_resolved` for `func_type_id` and `loc_proto_type_id`.  When `loc_proto_type` is unresolved, the code does a `env_stack_set_next_member(env, i + 1);` which sets the loop to continue from the next member after the currently unresolved member. Then I started to think about various possible paths and the `next_member` variable, especially the case where `func_type` is resolved but `loc_proto_type` isn't. When `loc_proto_type` isn't resolved, it should push to the stack and then pick up the loop from `i + 1`!

But what if, both types are not resolved? The stack will handle that case with setting `env_stack_set_next_member(env, i);` so that when `func_type` is resolved, it goes back and picks up from the same index.

I'm starting to think about recursion and invalid type IDs – those are potential gotchas. The code does include checks for invalid function and location protocol types, and it returns `-EINVAL` if something is wrong. I think this handles the case of loops and self references.

Now, I'm imagining a `locsec` referencing `loc_proto`, which then references `loc_param`. Let's see what happens with `btf_loc_proto_resolve`. Ah, so it doesn't push `param_type` onto the stack! That's because `loc_param` is a "no-resolve" type. I need to make sure I understand why those are handled differently.

Let me also check `btf_resolve_valid`. This function seems to check whether certain types are resolved. It is checking that `struct`, `datasec`, `loc_proto` and `locsec` are not resolved. So those need resolving.

And finally, something caught my eye in `include/linux/btf.h`: the change to `struct btf_field_desc` from `m_offs[1]` to `m_offs[2]`. I need to figure out where that's used in the kernel to understand the impact of that change. Let me grep for `btf_field_desc`.



36/2 2026/09/17 18:49 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "btf_field_desc",
  "PathPrefix": "kernel/"
}

Results:
{
  "error": "no matches"
}

37/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55351
							output: 20
							thoughts: 18
						

Thoughts:
Here's my take on those thoughts:

**Investigating the `btf_field_desc` Structure**

Okay, so I need to get a handle on the `btf_field_desc` structure within the codebase. My gut feeling is that it's going to be central to something I'm currently working on, and I need to quickly refresh my understanding of where it's used and how it fits into the larger architecture. The most efficient way to do that, of course, is a deep dive with `grep`. I'm going to run a full tree search using `grep` specifically for the string "btf_field_desc". This should give me a concise list of every instance of that structure being referenced, which I can then cross-reference to quickly understand its scope, use cases, and interactions with other parts of the system. This quick and focused search will allow me to jump-start my analysis and get a clearer picture of its role.



38/2 2026/09/17 18:49 tool grepper
0m Args:
{
  "Expression": "btf_field_desc"
}

Results:
{
  "Output": "include/linux/btf.h=571=enum btf_field_iter_kind {\n--\ninclude/linux/btf.h-575-\ninclude/linux/btf.h:576:struct btf_field_desc {\ninclude/linux/btf.h-577-\t/* once-per-type offsets */\n--\ninclude/linux/btf.h=585=struct btf_field_iter {\ninclude/linux/btf.h:586:\tstruct btf_field_desc desc;\ninclude/linux/btf.h-587-\tvoid *p;\n--\ntools/lib/bpf/btf_iter.c=16=int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n--\ntools/lib/bpf/btf_iter.c-32-\t\tcase BTF_KIND_LOC_PARAM:\ntools/lib/bpf/btf_iter.c:33:\t\t\tit-\u003edesc = (struct btf_field_desc) {};\ntools/lib/bpf/btf_iter.c-34-\t\t\tbreak;\n--\ntools/lib/bpf/btf_iter.c-44-\t\tcase BTF_KIND_TYPE_TAG:\ntools/lib/bpf/btf_iter.c:45:\t\t\tit-\u003edesc = (struct btf_field_desc) { 1, {offsetof(struct btf_type, type)} };\ntools/lib/bpf/btf_iter.c-46-\t\t\tbreak;\ntools/lib/bpf/btf_iter.c-47-\t\tcase BTF_KIND_ARRAY:\ntools/lib/bpf/btf_iter.c:48:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-49-\t\t\t\t2, {sizeof(struct btf_type) + offsetof(struct btf_array, type),\n--\ntools/lib/bpf/btf_iter.c-54-\t\tcase BTF_KIND_UNION:\ntools/lib/bpf/btf_iter.c:55:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-56-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-61-\t\tcase BTF_KIND_FUNC_PROTO:\ntools/lib/bpf/btf_iter.c:62:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-63-\t\t\t\t1, {offsetof(struct btf_type, type)},\n--\ntools/lib/bpf/btf_iter.c-68-\t\tcase BTF_KIND_DATASEC:\ntools/lib/bpf/btf_iter.c:69:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-70-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-75-\t\tcase BTF_KIND_LOC_PROTO:\ntools/lib/bpf/btf_iter.c:76:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-77-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-81-\t\tcase BTF_KIND_LOCSEC:\ntools/lib/bpf/btf_iter.c:82:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-83-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-95-\t\tcase BTF_KIND_UNKN:\ntools/lib/bpf/btf_iter.c:96:\t\t\tit-\u003edesc = (struct btf_field_desc) {};\ntools/lib/bpf/btf_iter.c-97-\t\t\tbreak;\n--\ntools/lib/bpf/btf_iter.c-114-\t\tcase BTF_KIND_LOCSEC:\ntools/lib/bpf/btf_iter.c:115:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-116-\t\t\t\t1, {offsetof(struct btf_type, name_off)}\n--\ntools/lib/bpf/btf_iter.c-119-\t\tcase BTF_KIND_ENUM:\ntools/lib/bpf/btf_iter.c:120:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-121-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/btf_iter.c-126-\t\tcase BTF_KIND_ENUM64:\ntools/lib/bpf/btf_iter.c:127:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-128-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/btf_iter.c-134-\t\tcase BTF_KIND_UNION:\ntools/lib/bpf/btf_iter.c:135:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-136-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/btf_iter.c-141-\t\tcase BTF_KIND_FUNC_PROTO:\ntools/lib/bpf/btf_iter.c:142:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-143-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/libbpf_internal.h=572=enum btf_field_iter_kind {\n--\ntools/lib/bpf/libbpf_internal.h-576-\ntools/lib/bpf/libbpf_internal.h:577:struct btf_field_desc {\ntools/lib/bpf/libbpf_internal.h-578-\t/* once-per-type offsets */\n--\ntools/lib/bpf/libbpf_internal.h=586=struct btf_field_iter {\ntools/lib/bpf/libbpf_internal.h:587:\tstruct btf_field_desc desc;\ntools/lib/bpf/libbpf_internal.h-588-\tvoid *p;\n"
}

39/2 2026/09/17 18:49 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57321
							output: 221
							thoughts: 758
						

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

Okay, here's the breakdown. This patch introduces new BTF kinds: `BTF_KIND_LOC_PARAM`, `BTF_KIND_LOC_PROTO`, and `BTF_KIND_LOCSEC`. I see they've updated `include/linux/btf.h` to stay in sync with `tools/lib/bpf/libbpf_internal.h`, which is good. The implementation in `kernel/bpf/btf.c` includes the metadata verification functions (`btf_loc_param_check_meta`, etc.), resolution functions (`btf_loc_proto_resolve`, etc.), and verifier logging functions. All this new functionality is triggered through the `bpf(BPF_BTF_LOAD, ...)` system call when userspace provides BTF data containing these new types.

Now, let's nail down the details. It looks like fuzzing is definitely warranted - `WorthFuzzing: true`.  We need `BPF_SYSCALL` enabled, which is the key config here. I initially wondered about `DEBUG_INFO_BTF`, but that's for generating `vmlinux.btf` at build time, not loading BTF via the syscall. So, `BPF_SYSCALL` is *the* requirement since it selects `BPF`.

The core functions to focus on are:
*   `btf_loc_param_check_meta`
*   `btf_loc_proto_check_meta`
*   `btf_loc_proto_resolve`
*   `btf_locsec_check_meta`
*   `btf_locsec_resolve`
*   `btf_new_fd`

I double-checked; the `btf_verifier_log_loc`, `btf_loc_param_log`, etc., are just logging helpers. Those first six functions are where the real logic resides.

These are all *new* functions specifically tied to this patch – not ubiquitous at all! `btf_new_fd` is only called when BTF is loaded through `BPF_BTF_LOAD`.

Alright, let's summarize it for the record:

*   **WorthFuzzing:** true
*   **Reasoning:** New BTF kinds, implemented through the `BPF_BTF_LOAD` syscall, introducing new verification and resolution functions.
*   **FocusSymbols:** `btf_loc_param_check_meta`, `btf_loc_proto_check_meta`, `btf_loc_proto_resolve`, `btf_locsec_check_meta`, `btf_locsec_resolve`, `btf_new_fd`
*   **EnableConfigs:** `BPF_SYSCALL`

That's it. It's time to call `set-results`.



40/2 2026/09/17 18:49 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "btf_loc_param_check_meta",
    "btf_loc_proto_check_meta",
    "btf_loc_proto_resolve",
    "btf_locsec_check_meta",
    "btf_locsec_resolve",
    "btf_new_fd"
  ],
  "Reasoning": "The patch introduces support for new BTF types (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, and BTF_KIND_LOCSEC) in the BPF subsystem, adding metadata validation, logging, and type resolution logic in kernel/bpf/btf.c. This code is directly reachable by user space via the BPF_BTF_LOAD command of the bpf() system call. Fuzzing is warranted to test bounds checking, type resolution, and validation of malformed BTF data.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "btf_loc_param_check_meta",
    "btf_loc_proto_check_meta",
    "btf_loc_proto_resolve",
    "btf_locsec_check_meta",
    "btf_locsec_resolve",
    "btf_new_fd"
  ],
  "Reasoning": "The patch introduces support for new BTF types (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, and BTF_KIND_LOCSEC) in the BPF subsystem, adding metadata validation, logging, and type resolution logic in kernel/bpf/btf.c. This code is directly reachable by user space via the BPF_BTF_LOAD command of the bpf() system call. Fuzzing is warranted to test bounds checking, type resolution, and validation of malformed BTF data.",
  "WorthFuzzing": true
}

41/1 2026/09/17 18:49 action If
6m Args:
{
  "WorthFuzzing": true
}

Results:
null

42/2 2026/09/17 18:49 agent kmsan-evaluator
6m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series adds support for three new BTF kinds (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, BTF_KIND_LOCSEC) across documentation, UAPI, bpftool, libbpf, selftests, and the kernel BTF verifier (kernel/bpf/btf.c).\n\nKMSAN vs KASAN applicability analysis:\n1. Kernel memory allocation \u0026 initialization:\n   - When user space loads a BTF object via bpf(BPF_BTF_LOAD), the kernel allocates memory for the BTF object using kzalloc() and copies user-provided bytes directly into kvmalloc'd memory with copy_from_bpfptr().\n   - The validation routines added for the new BTF kinds (btf_loc_param_check_meta, btf_loc_proto_check_meta, btf_locsec_check_meta, and their resolution functions) strictly parse and inspect the already populated buffer.\n   - Verification checks size and boundary constraints (meta_left \u003e= meta_needed) before accessing any elements, protecting against out-of-bounds reads (which fall squarely under KASAN's domain).\n\n2. Kernel-to-user space information exposure:\n   - When retrieving BTF info via BPF_OBJ_GET_INFO_BY_FD, struct bpf_btf_info is cleared with memset(\u0026info, 0, sizeof(info)), and the BTF payload copied back to user space is simply the user-supplied (or module/vmlinux) BTF data buffer. No uninitialized struct padding or uninitialized heap/stack memory is copied to user space.\n\n3. Control flow and branching:\n   - All branching decisions in the new code evaluate well-defined struct fields populated from user data or verification state.\n   - The expanded struct btf_field_desc (m_offs[2]) and btf_field_iter in tools/lib/bpf/btf_iter.c (included in kernel/bpf/btf_iter.c for module BTF relocation) explicitly initialize all iterator fields upon btf_field_iter_init().\n\n4. Bug surface:\n   - Any bugs in metadata validation, index calculations, or type resolution are memory boundary/indexing or logic errors, which are either rejected cleanly by the BTF verifier or caught by standard bug detectors (KASAN for OOB reads/writes).\n   - There are no uninitialized memory reads or information leaks introduced or exposed by these changes.\n\nTherefore, dedicated KMSAN fuzzing is not warranted (NeedsKMSAN=false).",
  "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 63a3bf6e1b250d9153a70283b74731c455e0fbc1
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Sep 17 18:48:12 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
index 004aa1058d857..70ab6ad608ae5 100644
--- a/Documentation/bpf/btf.rst
+++ b/Documentation/bpf/btf.rst
@@ -88,6 +88,9 @@ sequentially and type id is assigned to each recognized type starting from id
     #define BTF_KIND_DECL_TAG       17      /* Decl Tag     */
     #define BTF_KIND_TYPE_TAG       18      /* Type Tag     */
     #define BTF_KIND_ENUM64         19      /* Enumeration up to 64-bit values */
+    #define BTF_KIND_LOC_PARAM      20      /* Location description (register, const etc) */
+    #define BTF_KIND_LOC_PROTO      21      /* Set of location parameters for site */
+    #define BTF_KIND_LOCSEC         22      /* Section with site descriptions */
 
 Note that the type section encodes debug info, not just pure types.
 ``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram.
@@ -104,11 +107,13 @@ Each type contains the following common data::
          *             decl_tag and type_tag
          */
         __u32 info;
-        /* "size" is used by INT, ENUM, STRUCT, UNION and ENUM64.
+        /* "size" is used by INT, ENUM, STRUCT, UNION, ENUM64 and
+         * LOC_PARAM.
          * "size" tells the size of the type it is describing.
          *
          * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
-         * FUNC, FUNC_PROTO, DECL_TAG and TYPE_TAG.
+         * FUNC, FUNC_PROTO, DECL_TAG and TYPE_TAG. It is unused by
+         * LOC_PROTO and LOCSEC.
          * "type" is a type_id referring to another type.
          */
         union {
@@ -563,6 +568,77 @@ The ``btf_enum64`` encoding:
 If the original enum value is signed and the size is less than 8,
 that value will be sign extended into 8 bytes.
 
+2.2.20 BTF_KIND_LOC_PARAM
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``struct btf_type`` encoding requirement:
+  * ``name_off``: 0
+  * ``info.kind_flag``: 0
+  * ``info.kind``: BTF_KIND_LOC_PARAM
+  * ``info.vlen``: number of 32-bit location value words
+  * ``size``: size in bytes of the represented parameter: 1, 2, 4, 8 or 16
+
+``btf_type`` is followed by a ``struct btf_loc_param`` and ``info.vlen``
+number of 32-bit value words.::
+
+    struct btf_loc_param {
+        __u32 flags;
+        __u32 values[];
+    };
+
+The ``flags`` field describes how to interpret ``values``:
+
+  * ``BTF_LOC_PARAM_CONST`` describes a constant; the value is stored in
+    low-word, high-word order when it requires 64 bits.
+  * ``BTF_LOC_PARAM_ADDR | BTF_LOC_PARAM_CONST`` describes an address to be
+    normalized relative to the kernel or module base address.
+  * ``BTF_LOC_PARAM_REG`` with one word describes a register number; with two
+    words it describes a multi-register parameter.
+  * ``BTF_LOC_PARAM_REG | BTF_LOC_PARAM_OFFSET`` describes an address held in
+    a register plus an offset. Adding ``BTF_LOC_PARAM_DEREF`` dereferences
+    that address. ``BTF_LOC_PARAM_REG | BTF_LOC_PARAM_DEREF`` with one word
+    dereferences the value held in the register.
+  * ``BTF_LOC_PARAM_SIGNED`` makes a constant or offset signed.
+
+2.2.21 BTF_KIND_LOC_PROTO
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``struct btf_type`` encoding requirement:
+  * ``name_off``: 0
+  * ``info.kind_flag``: 0
+  * ``info.kind``: BTF_KIND_LOC_PROTO
+  * ``info.vlen``: number of function parameter locations
+  * ``type``: 0
+
+``btf_type`` is followed by ``info.vlen`` number of ``__u32`` BTF type IDs.
+Each entry corresponds to a function parameter at an inline site. An entry is
+either 0, meaning that no location information is available, or the type ID
+of a ``BTF_KIND_LOC_PARAM``.
+
+2.2.22 BTF_KIND_LOCSEC
+~~~~~~~~~~~~~~~~~~~~~~
+
+``struct btf_type`` encoding requirement:
+  * ``name_off``: offset to a valid ELF section name
+  * ``info.kind_flag``: 0
+  * ``info.kind``: BTF_KIND_LOCSEC
+  * ``info.vlen``: number of inline sites in the section
+  * ``type``: 0
+
+``btf_type`` is followed by ``info.vlen`` number of ``struct btf_loc``.::
+
+    struct btf_loc {
+        __u32 func;
+        __u32 loc_proto;
+        __u32 offset;
+    };
+
+The ``func`` field is the non-zero type ID of the ``BTF_KIND_FUNC`` being
+described. ``loc_proto`` is the non-zero type ID of the associated
+``BTF_KIND_LOC_PROTO``. ``offset`` is the location address offset relative to
+the kernel or module base address. A LOCSEC named ``inline.text``, for example,
+contains inline-site records for the ``.text`` section.
+
 2.3 Constant Values
 -------------------
 
diff --git a/include/linux/btf.h b/include/linux/btf.h
index ddd0f4f32d24b..f29ed358b7a8c 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -261,6 +261,11 @@ const char *btf_type_str(const struct btf_type *t);
 	     i < btf_type_vlen(datasec_type);			\
 	     i++, member++)
 
+#define for_each_loc(i, locsec_type, member)			\
+	for (i = 0, member = btf_type_loc_secinfo(locsec_type);	\
+	     i < btf_type_vlen(locsec_type);			\
+	     i++, member++)
+
 static inline bool btf_type_is_ptr(const struct btf_type *t)
 {
 	return BTF_INFO_KIND(t->info) == BTF_KIND_PTR;
@@ -329,6 +334,21 @@ static inline u64 btf_enum64_value(const struct btf_enum64 *e)
 	return ((u64)e->val_hi32 << 32) | e->val_lo32;
 }
 
+static inline struct btf_loc_param *btf_loc_param(const struct btf_type *t)
+{
+	return (struct btf_loc_param *)(t + 1);
+}
+
+static inline __u32 *btf_loc_proto_params(const struct btf_type *t)
+{
+	return (__u32 *)(t + 1);
+}
+
+static inline struct btf_loc *btf_type_loc_secinfo(const struct btf_type *t)
+{
+	return (struct btf_loc *)(t + 1);
+}
+
 static inline bool btf_is_composite(const struct btf_type *t)
 {
 	u16 kind = btf_kind(t);
@@ -559,7 +579,7 @@ struct btf_field_desc {
 	/* member struct size, or zero, if no members */
 	int m_sz;
 	/* repeated per-member offsets */
-	int m_off_cnt, m_offs[1];
+	int m_off_cnt, m_offs[2];
 };
 
 struct btf_field_iter {
diff --git a/include/uapi/linux/btf.h b/include/uapi/linux/btf.h
index 618167cab4e61..a85d293f4127f 100644
--- a/include/uapi/linux/btf.h
+++ b/include/uapi/linux/btf.h
@@ -92,7 +92,9 @@ enum {
 	BTF_KIND_DECL_TAG	= 17,	/* Decl Tag */
 	BTF_KIND_TYPE_TAG	= 18,	/* Type Tag */
 	BTF_KIND_ENUM64		= 19,	/* Enumeration up to 64-bit values */
-
+	BTF_KIND_LOC_PARAM	= 20,	/* Location parameter information */
+	BTF_KIND_LOC_PROTO	= 21,	/* Location prototype for site */
+	BTF_KIND_LOCSEC		= 22,	/* Location section */
 	NR_BTF_KINDS,
 	BTF_KIND_MAX		= NR_BTF_KINDS - 1,
 };
@@ -212,4 +214,65 @@ struct btf_enum64 {
 	__u32	val_hi32;
 };
 
+/*
+ * BTF_KIND_LOC_PARAM is followed by a single "struct btf_loc_param"
+ * that contains flags specifying the contents of the vlen-specified
+ * number of 4-byte values that follow.
+ */
+struct btf_loc_param {
+	__u32 flags;
+	__u32 values[];
+};
+
+/*
+ * The combination of size, vlen and flags gives us the means to interpret
+ * the following vlen-specified set of 4-byte values:
+ *
+ * - a BTF_LOC_PARAM_CONST is a constant value; combination
+ *   of size, vlen and _SIGNED flag determines it. If the value requires
+ *   64 bits it is stored in {lo,hi} order.
+ * - a BTF_LOC_PARAM_ADDR|BTF_LOC_PARAM_CONST is an address that should be
+ *   normalized with respect to kernel/module base address.
+ * - a BTF_LOC_PARAM_REG with vlen 1 is a simple register number;
+ *   with vlen 2 it is a multi-register parameter.
+ * - a _REG | OFFSET describes an address without dereferencing it.
+ * - a _REG | DEREF with vlen 1 dereferences the value in the register
+ *   number specified.
+ * - a REG | DEREF | OFFSET with vlen specifies the register value in
+ *   the first 4-byte value and the offset in the remainder.
+ */
+enum btf_loc_param_flags {
+	BTF_LOC_PARAM_SIGNED		=	0x1,
+	BTF_LOC_PARAM_CONST		=	0x2,
+	BTF_LOC_PARAM_ADDR		=	0x4,
+	BTF_LOC_PARAM_REG		=	0x8,
+	BTF_LOC_PARAM_DEREF		=	0x10,
+	BTF_LOC_PARAM_OFFSET		=	0x20,
+};
+
+/*
+ * BTF_KIND_LOC_PROTO specifies location prototypes; i.e. how locations relate
+ * to parameters; a struct btf_type of BTF_KIND_LOC_PROTO is followed by a
+ * vlen-specified number of __u32 BTF type ids which specify the associated
+ * BTF_KIND_LOC_PARAM for each function parameter associated with the
+ * location.  The type should either be 0 (no location info) or point at
+ * a BTF_KIND_LOC_PARAM.
+ */
+
+/*
+ * BTF_KIND_LOCSEC consists of vlen-specified number of "struct btf_loc"
+ * containing location site-specific information for a specific ELF section;
+ * for example locations in ".text" are in a LOCSEC named "inline.text".
+ *
+ * - function (func)
+ * - location prototype type id (loc_proto)
+ * - address offset (offset) relative to kernel base address
+ */
+
+struct btf_loc {
+	__u32 func;
+	__u32 loc_proto;
+	__u32 offset;
+};
+
 #endif /* _UAPI__LINUX_BTF_H__ */
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 7daf4c286c9b2..af5f161b5bddc 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -345,6 +345,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
 	[BTF_KIND_DECL_TAG]	= "DECL_TAG",
 	[BTF_KIND_TYPE_TAG]	= "TYPE_TAG",
 	[BTF_KIND_ENUM64]	= "ENUM64",
+	[BTF_KIND_LOC_PARAM]	= "LOC_PARAM",
+	[BTF_KIND_LOC_PROTO]	= "LOC_PROTO",
+	[BTF_KIND_LOCSEC]	= "LOCSEC",
 };
 
 const char *btf_type_str(const struct btf_type *t)
@@ -517,11 +520,27 @@ static bool btf_type_is_decl_tag(const struct btf_type *t)
 	return BTF_INFO_KIND(t->info) == BTF_KIND_DECL_TAG;
 }
 
+static bool btf_type_is_loc_param(const struct btf_type *t)
+{
+	return BTF_INFO_KIND(t->info) == BTF_KIND_LOC_PARAM;
+}
+
+static bool btf_type_is_loc_proto(const struct btf_type *t)
+{
+	return BTF_INFO_KIND(t->info) == BTF_KIND_LOC_PROTO;
+}
+
+static bool btf_type_is_locsec(const struct btf_type *t)
+{
+	return BTF_INFO_KIND(t->info) == BTF_KIND_LOCSEC;
+}
+
 static bool btf_type_nosize(const struct btf_type *t)
 {
 	return btf_type_is_void(t) || btf_type_is_fwd(t) ||
 	       btf_type_is_func(t) || btf_type_is_func_proto(t) ||
-	       btf_type_is_decl_tag(t);
+	       btf_type_is_decl_tag(t) || btf_type_is_loc_param(t) ||
+	       btf_type_is_loc_proto(t) || btf_type_is_locsec(t);
 }
 
 static bool btf_type_nosize_or_null(const struct btf_type *t)
@@ -796,7 +815,9 @@ static bool btf_type_needs_resolve(const struct btf_type *t)
 	       btf_type_is_var(t) ||
 	       btf_type_is_func(t) ||
 	       btf_type_is_decl_tag(t) ||
-	       btf_type_is_datasec(t);
+	       btf_type_is_datasec(t) ||
+	       btf_type_is_loc_proto(t) ||
+	       btf_type_is_locsec(t);
 }
 
 /* t->size can be used */
@@ -4729,6 +4750,279 @@ static const struct btf_kind_operations enum64_ops = {
 	.show = btf_enum64_show,
 };
 
+static s32 btf_loc_param_check_meta(struct btf_verifier_env *env,
+				    const struct btf_type *t,
+				    u32 meta_left)
+{
+	const struct btf_loc_param *p = btf_loc_param(t);
+	u32 size, meta_needed, vlen = btf_vlen(t);
+
+	meta_needed = sizeof(*p) + sizeof(__u32) * vlen;
+	if (meta_left < meta_needed) {
+		btf_verifier_log_basic(env, t,
+				       "meta_left:%u meta_needed:%u",
+				      meta_left, meta_needed);
+		return -EINVAL;
+	}
+
+	if (t->name_off) {
+		btf_verifier_log_type(env, t, "Invalid name");
+		return -EINVAL;
+	}
+	size = t->size;
+	if (size > 16 || !is_power_of_2(size)) {
+		btf_verifier_log_type(env, t, "Unexpected size");
+		return -EINVAL;
+	}
+
+	if (btf_type_kflag(t)) {
+		btf_verifier_log_type(env, t, "Invalid btf_info kind_flag");
+		return -EINVAL;
+	}
+
+	btf_verifier_log_type(env, t, NULL);
+
+	return meta_needed;
+}
+
+static void btf_loc_param_log(struct btf_verifier_env *env,
+			 const struct btf_type *t)
+{
+	const struct btf_loc_param *p = btf_loc_param(t);
+	u32 i, vlen = btf_vlen(t);
+
+	btf_verifier_log(env, "size=%u vlen=%u flags=0x%x", t->size, vlen, p->flags);
+	for (i = 0; i < vlen; i++)
+		btf_verifier_log(env, ", %u", p->values[i]);
+}
+
+static const struct btf_kind_operations loc_param_ops = {
+	.check_meta = btf_loc_param_check_meta,
+	.resolve = btf_df_resolve,
+	.check_member = btf_df_check_member,
+	.check_kflag_member = btf_df_check_kflag_member,
+	.log_details = btf_loc_param_log,
+	.show = btf_df_show,
+};
+
+static s32 btf_loc_proto_check_meta(struct btf_verifier_env *env,
+				    const struct btf_type *t,
+				    u32 meta_left)
+{
+	u32 meta_needed;
+
+	meta_needed = sizeof(__u32) * btf_type_vlen(t);
+
+	if (meta_left < meta_needed) {
+		btf_verifier_log_basic(env, t,
+				       "meta_left:%u meta_needed:%u",
+				      meta_left, meta_needed);
+		return -EINVAL;
+	}
+
+	if (t->name_off) {
+		btf_verifier_log_type(env, t, "Invalid name");
+		return -EINVAL;
+	}
+
+	if (btf_type_kflag(t)) {
+		btf_verifier_log_type(env, t, "Invalid btf_info kind_flag");
+		return -EINVAL;
+	}
+
+	btf_verifier_log_type(env, t, NULL);
+
+	return meta_needed;
+}
+
+static void btf_loc_proto_log(struct btf_verifier_env *env,
+			      const struct btf_type *t)
+{
+	const __u32 *params = btf_loc_proto_params(t);
+	u32 i, nr_params = btf_type_vlen(t);
+
+	btf_verifier_log(env, "vlen=%u", nr_params);
+	for (i = 0; i < nr_params; i++, params++)
+		btf_verifier_log(env, ", %u", *params);
+}
+
+static int btf_loc_proto_resolve(struct btf_verifier_env *env,
+				 const struct resolve_vertex *v)
+{
+	const struct btf_type *t = v->t;
+	const __u32 *params = btf_loc_proto_params(t);
+	u32 i, nr_params = btf_type_vlen(t);
+	struct btf *btf = env->btf;
+
+	if (t->type) {
+		btf_verifier_log_type(env, t, "Invalid loc_proto type");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < nr_params; i++) {
+		const struct btf_type *param_type;
+		u32 param_type_id = params[i];
+
+		if (!param_type_id)
+			continue;
+
+		param_type = btf_type_by_id(btf, param_type_id);
+		if (!param_type || !btf_type_is_loc_param(param_type)) {
+			btf_verifier_log_type(env, t,
+					      "Invalid loc_param#%u", i + 1);
+			return -EINVAL;
+		}
+	}
+
+	env_stack_pop_resolved(env, 0, 0);
+	return 0;
+}
+
+static const struct btf_kind_operations loc_proto_ops = {
+	.check_meta = btf_loc_proto_check_meta,
+	.resolve = btf_loc_proto_resolve,
+	.check_member = btf_df_check_member,
+	.check_kflag_member = btf_df_check_kflag_member,
+	.log_details = btf_loc_proto_log,
+	.show = btf_df_show,
+};
+
+__printf(4, 5)
+static void btf_verifier_log_loc(struct btf_verifier_env *env,
+				 const struct btf_type *locsec_type,
+				 const struct btf_loc *loc,
+				 const char *fmt, ...)
+{
+	struct bpf_verifier_log *log = &env->log;
+	va_list args;
+
+	if (!bpf_verifier_log_needed(log))
+		return;
+	if (log->level == BPF_LOG_KERNEL && !fmt)
+		return;
+	if (env->phase != CHECK_META)
+		btf_verifier_log_type(env, locsec_type, NULL);
+
+	__btf_verifier_log(log, "\t func=%u loc_proto=%u offset=%u",
+			   loc->func, loc->loc_proto, loc->offset);
+	if (fmt && *fmt) {
+		__btf_verifier_log(log, " ");
+		va_start(args, fmt);
+		bpf_verifier_vlog(log, fmt, args);
+		va_end(args);
+	}
+
+	__btf_verifier_log(log, "\n");
+}
+
+static s32 btf_locsec_check_meta(struct btf_verifier_env *env,
+				 const struct btf_type *t,
+				 u32 meta_left)
+{
+	u32 i, meta_needed, vlen = btf_type_vlen(t);
+	const struct btf_loc *loc;
+
+	meta_needed = sizeof(struct btf_loc) * vlen;
+
+	if (meta_left < meta_needed) {
+		btf_verifier_log_basic(env, t,
+				       "meta_left:%u meta_needed:%u",
+				       meta_left, meta_needed);
+		return -EINVAL;
+	}
+
+	if (btf_type_kflag(t)) {
+		btf_verifier_log_type(env, t, "Invalid btf_info kind_flag");
+		return -EINVAL;
+	}
+
+	if (!t->name_off ||
+	    !btf_name_valid_section(env->btf, t->name_off)) {
+		btf_verifier_log_type(env, t, "Invalid name");
+		return -EINVAL;
+	}
+
+	for_each_loc(i, t, loc) {
+		/* A loc func, loc proto cannot be in type void */
+		if (!loc->func || !BTF_TYPE_ID_VALID(loc->func)) {
+			btf_verifier_log_loc(env, t, loc, "Invalid func");
+			return -EINVAL;
+		}
+		if (!loc->loc_proto || !BTF_TYPE_ID_VALID(loc->loc_proto)) {
+			btf_verifier_log_loc(env, t, loc, "Invalid loc_proto");
+			return -EINVAL;
+		}
+		btf_verifier_log_loc(env, t, loc, NULL);
+	}
+
+	return meta_needed;
+}
+
+static void btf_locsec_log(struct btf_verifier_env *env,
+			   const struct btf_type *t)
+{
+	btf_verifier_log(env, "vlen=%u", btf_type_vlen(t));
+}
+
+static int btf_locsec_resolve(struct btf_verifier_env *env,
+			      const struct resolve_vertex *v)
+{
+	const struct btf_type *t = v->t;
+	const struct btf_loc *loc;
+	struct btf *btf = env->btf;
+	u32 i;
+
+	if (t->type) {
+		btf_verifier_log_type(env, t, "Invalid locsec type");
+		return -EINVAL;
+	}
+
+	env->resolve_mode = RESOLVE_TBD;
+	for (i = v->next_member, loc = btf_type_loc_secinfo(t) + i;
+	     i < btf_type_vlen(t); i++, loc++) {
+		const struct btf_type *func_type, *loc_proto_type;
+		u32 func_type_id = loc->func;
+		u32 loc_proto_type_id = loc->loc_proto;
+
+		func_type = btf_type_by_id(btf, func_type_id);
+		if (!func_type || !btf_type_is_func(func_type)) {
+			btf_verifier_log_type(env, t,
+					      "Invalid func#%u", i + 1);
+			return -EINVAL;
+		}
+
+		if (!env_type_is_resolved(env, func_type_id)) {
+			env_stack_set_next_member(env, i);
+			return env_stack_push(env, func_type, func_type_id);
+		}
+
+		loc_proto_type = btf_type_by_id(btf, loc_proto_type_id);
+		if (!loc_proto_type || !btf_type_is_loc_proto(loc_proto_type)) {
+			btf_verifier_log_type(env, t,
+					      "Invalid loc_proto#%u", i + 1);
+			return -EINVAL;
+		}
+
+		if (!env_type_is_resolved(env, loc_proto_type_id)) {
+			env_stack_set_next_member(env, i + 1);
+			return env_stack_push(env, loc_proto_type,
+					      loc_proto_type_id);
+		}
+	}
+
+	env_stack_pop_resolved(env, 0, 0);
+	return 0;
+}
+
+static const struct btf_kind_operations locsec_ops = {
+	.check_meta = btf_locsec_check_meta,
+	.resolve = btf_locsec_resolve,
+	.check_member = btf_df_check_member,
+	.check_kflag_member = btf_df_check_kflag_member,
+	.log_details = btf_locsec_log,
+	.show = btf_df_show,
+};
+
 static s32 btf_func_proto_check_meta(struct btf_verifier_env *env,
 				     const struct btf_type *t,
 				     u32 meta_left)
@@ -5398,6 +5692,9 @@ static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {
 	[BTF_KIND_DECL_TAG] = &decl_tag_ops,
 	[BTF_KIND_TYPE_TAG] = &modifier_ops,
 	[BTF_KIND_ENUM64] = &enum64_ops,
+	[BTF_KIND_LOC_PARAM] = &loc_param_ops,
+	[BTF_KIND_LOC_PROTO] = &loc_proto_ops,
+	[BTF_KIND_LOCSEC] = &locsec_ops,
 };
 
 static s32 btf_check_meta(struct btf_verifier_env *env,
@@ -5472,7 +5769,8 @@ static bool btf_resolve_valid(struct btf_verifier_env *env,
 	if (!env_type_is_resolved(env, type_id))
 		return false;
 
-	if (btf_type_is_struct(t) || btf_type_is_datasec(t))
+	if (btf_type_is_struct(t) || btf_type_is_datasec(t) ||
+	    btf_type_is_loc_proto(t) || btf_type_is_locsec(t))
 		return !btf_resolved_type_id(btf, type_id) &&
 		       !btf_resolved_type_size(btf, type_id);
 
diff --git a/tools/bpf/bpftool/Documentation/bpftool-btf.rst b/tools/bpf/bpftool/Documentation/bpftool-btf.rst
index cf75a7fa2d6bc..c6dc445cd4a19 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-btf.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-btf.rst
@@ -16,7 +16,7 @@ SYNOPSIS
 
 **bpftool** [*OPTIONS*] **btf** *COMMAND*
 
-*OPTIONS* := { |COMMON_OPTIONS| | { **-B** | **--base-btf** } }
+*OPTIONS* := { |COMMON_OPTIONS| | [{ **-B** | **--base-btf**} *FILE*]...  }
 
 *COMMANDS* := { **dump** | **help** }
 
@@ -87,7 +87,10 @@ OPTIONS
     objects for kernel modules. To avoid duplicating all kernel symbols
     required by modules, BTF objects for modules are "split", they are
     built incrementally on top of the kernel (vmlinux) BTF object. So the
-    base BTF reference should usually point to the kernel BTF.
+    base BTF reference should usually point to the kernel BTF.  Multiple
+    base BTF objects can be passed, where the first is assumed to be the
+    root BTF, followed by split BTF based upon it, followed by split
+    BTF based upon the first split BTF and so on.
 
     When the main BTF object to process (for example, the module BTF to
     dump) is passed as a *FILE*, bpftool attempts to autodetect the path
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index bca0a3982f09b..5e0cb58628117 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -51,6 +51,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
 	[BTF_KIND_DECL_TAG]	= "DECL_TAG",
 	[BTF_KIND_TYPE_TAG]	= "TYPE_TAG",
 	[BTF_KIND_ENUM64]	= "ENUM64",
+	[BTF_KIND_LOC_PARAM]	= "LOC_PARAM",
+	[BTF_KIND_LOC_PROTO]	= "LOC_PROTO",
+	[BTF_KIND_LOCSEC]	= "LOCSEC",
 };
 
 struct sort_datum {
@@ -117,6 +120,83 @@ static int btf_kind_safe(int kind)
 	return kind <= BTF_KIND_MAX ? kind : BTF_KIND_UNKN;
 }
 
+static void btf_loc_param_str(const struct btf_type *t, char *str, size_t sz)
+{
+	const struct btf_loc_param *p;
+	__u32 i = 0, vlen;
+	__u64 value;
+	bool negative = false;
+	char regs[32] = {};
+	char num[32] = {};
+	const char *op = "";
+
+	if (!t || !btf_is_loc_param(t)) {
+		snprintf(str, sz, "<invalid>");
+		return;
+	}
+
+	p = btf_loc_param(t);
+	vlen = btf_vlen(t);
+
+	if (p->flags & BTF_LOC_PARAM_REG) {
+		__u32 nregs = (p->flags == BTF_LOC_PARAM_REG) ? vlen : 1;
+
+		if (nregs > vlen) {
+			snprintf(str, sz, "?");
+			return;
+		}
+
+		switch (nregs) {
+		case 2:
+			snprintf(regs, sizeof(regs), "r%u, r%u",
+				 p->values[0], p->values[1]);
+			break;
+		case 1:
+			snprintf(regs, sizeof(regs), "r%u", p->values[0]);
+			break;
+		default:
+			snprintf(regs, sizeof(regs), "?");
+			break;
+		}
+		i += nregs;
+	}
+	if (p->flags & (BTF_LOC_PARAM_CONST|BTF_LOC_PARAM_OFFSET)) {
+		switch (vlen - i) {
+		case 1:
+			value = p->values[i];
+			break;
+		case 2:
+			value = ((__u64)p->values[i + 1] << 32) | p->values[i];
+			break;
+		default:
+			snprintf(num, sizeof(num), "?");
+			goto done;
+		}
+		if ((p->flags & BTF_LOC_PARAM_SIGNED) && t->size &&
+		    t->size <= sizeof(value)) {
+			__u32 bits = t->size * 8;
+
+			if (t->size < sizeof(value))
+				value &= (1ULL << bits) - 1;
+			negative = value & (1ULL << (bits - 1));
+			if (negative)
+				value = t->size == sizeof(value) ? -value :
+					(1ULL << bits) - value;
+		}
+		snprintf(num, sizeof(num), "0x%llx", (unsigned long long)value);
+	}
+	if (num[0])
+		op = regs[0] ? (negative ? " - " : " + ") : negative ? "-" : "";
+
+done:
+	snprintf(str, sz, "%s%s%s%s%s",
+		 p->flags & BTF_LOC_PARAM_DEREF ? "*(" : "",
+		 regs,
+		 op,
+		 num,
+		 p->flags & BTF_LOC_PARAM_DEREF ? ")" : "");
+}
+
 static int dump_btf_type(const struct btf *btf, __u32 id,
 			 const struct btf_type *t)
 {
@@ -415,6 +495,95 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 		}
 		break;
 	}
+	case BTF_KIND_LOC_PARAM: {
+		const struct btf_loc_param *p = btf_loc_param(t);
+		__u32 vlen = btf_vlen(t);
+		char param_str[256] = {};
+
+		btf_loc_param_str(t, param_str, sizeof(param_str));
+
+		if (json_output) {
+			jsonw_uint_field(w, "size", t->size);
+			jsonw_uint_field(w, "flags", p->flags);
+			jsonw_uint_field(w, "vlen", vlen);
+			jsonw_string_field(w, "values", param_str);
+		} else {
+			printf(" size=%u flags=0x%x vlen=%u values='%s'", t->size, p->flags, vlen, param_str);
+		}
+		break;
+	}
+	case BTF_KIND_LOC_PROTO: {
+		__u32 *params = btf_loc_proto_params(t);
+		__u16 vlen = btf_vlen(t);
+		int i;
+
+		if (json_output) {
+			jsonw_uint_field(w, "vlen", vlen);
+			jsonw_name(w, "params");
+			jsonw_start_array(w);
+		} else {
+			printf(" vlen=%u", vlen);
+		}
+
+		for (i = 0; i < vlen; i++, params++) {
+			const struct btf_type *p;
+			char param_str[256] = {};
+
+			if (*params) {
+				p = btf__type_by_id(btf, *params);
+				btf_loc_param_str(p, param_str, sizeof(param_str));
+			} else {
+				snprintf(param_str, sizeof(param_str), "<unavailable>");
+			}
+			if (json_output) {
+				jsonw_start_object(w);
+				jsonw_uint_field(w, "type_id", *params);
+				jsonw_string_field(w, "value", param_str);
+				jsonw_end_object(w);
+			} else {
+				printf("\n\ttype_id=%u value='%s'", *params, param_str);
+			}
+		}
+		if (json_output)
+			jsonw_end_array(w);
+		break;
+	}
+
+	case BTF_KIND_LOCSEC: {
+		struct btf_loc *locs = btf_locsec_locs(t);
+		__u32 i, vlen = btf_vlen(t);
+
+		if (json_output) {
+			jsonw_uint_field(w, "vlen", vlen);
+			jsonw_name(w, "locs");
+			jsonw_start_array(w);
+		} else {
+			printf(" vlen=%u", vlen);
+		}
+
+		for (i = 0; i < vlen; i++, locs++) {
+			const struct btf_type *f = btf__type_by_id(btf, locs->func);
+			const char *name = "<invalid>";
+
+			if (f && btf_is_func(f))
+				name = btf_str(btf, f->name_off);
+
+			if (json_output) {
+				jsonw_start_object(w);
+				jsonw_uint_field(w, "func_type_id", locs->func);
+				jsonw_string_field(w, "name", name);
+				jsonw_uint_field(w, "loc_proto_type_id", locs->loc_proto);
+				jsonw_uint_field(w, "offset", locs->offset);
+				jsonw_end_object(w);
+			} else {
+				printf("\n\tname='%s' func_type_id=%u loc_proto_type_id=%u offset=%u",
+				       name, locs->func, locs->loc_proto, locs->offset);
+			}
+		}
+		if (json_output)
+			jsonw_end_array(w);
+		break;
+	}
 	default:
 		break;
 	}
@@ -1545,7 +1714,7 @@ static int do_help(int argc, char **argv)
 		"       " HELP_SPEC_MAP "\n"
 		"       " HELP_SPEC_PROGRAM "\n"
 		"       " HELP_SPEC_OPTIONS " |\n"
-		"                    {-B|--base-btf} }\n"
+		"                    {[{-B|--base-btf} FILE]... }\n"
 		"",
 		bin_name, "btf");
 
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 5ababd8f7d0a0..cff76be7d2e86 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -466,6 +466,7 @@ int main(int argc, char **argv)
 		{ "base-btf",	required_argument, NULL, 'B' },
 		{ 0 }
 	};
+	struct btf *new_base_btf = NULL, *root_base_btf = NULL;
 	bool version_requested = false;
 	int opt, ret;
 
@@ -515,12 +516,16 @@ int main(int argc, char **argv)
 			verifier_logs = true;
 			break;
 		case 'B':
-			base_btf = btf__parse(optarg, NULL);
-			if (!base_btf) {
+			/* handle multi-split BTF */
+			new_base_btf = btf__parse_split(optarg, base_btf);
+			if (!new_base_btf) {
 				p_err("failed to parse base BTF at '%s': %d\n",
 				      optarg, -errno);
 				return -1;
 			}
+			base_btf = new_base_btf;
+			if (!root_base_btf)
+				root_base_btf = base_btf;
 			break;
 		case 'L':
 			use_loader = true;
@@ -567,7 +572,18 @@ int main(int argc, char **argv)
 	if (json_output)
 		jsonw_destroy(&json_wtr);
 
-	btf__free(base_btf);
+	while (base_btf) {
+		new_base_btf = (struct btf *)btf__base_btf(base_btf);
+		btf__free(base_btf);
+		/*
+		 * Do not free base BTF that is an owned .BTF.base ; leads
+		 * to a double-free, so only free as far as the root base
+		 * we explicitly read with -B above.
+		 */
+		if (base_btf == root_base_btf)
+			break;
+		base_btf = new_base_btf;
+	}
 
 	return ret;
 }
diff --git a/tools/include/uapi/linux/btf.h b/tools/include/uapi/linux/btf.h
index 618167cab4e61..a85d293f4127f 100644
--- a/tools/include/uapi/linux/btf.h
+++ b/tools/include/uapi/linux/btf.h
@@ -92,7 +92,9 @@ enum {
 	BTF_KIND_DECL_TAG	= 17,	/* Decl Tag */
 	BTF_KIND_TYPE_TAG	= 18,	/* Type Tag */
 	BTF_KIND_ENUM64		= 19,	/* Enumeration up to 64-bit values */
-
+	BTF_KIND_LOC_PARAM	= 20,	/* Location parameter information */
+	BTF_KIND_LOC_PROTO	= 21,	/* Location prototype for site */
+	BTF_KIND_LOCSEC		= 22,	/* Location section */
 	NR_BTF_KINDS,
 	BTF_KIND_MAX		= NR_BTF_KINDS - 1,
 };
@@ -212,4 +214,65 @@ struct btf_enum64 {
 	__u32	val_hi32;
 };
 
+/*
+ * BTF_KIND_LOC_PARAM is followed by a single "struct btf_loc_param"
+ * that contains flags specifying the contents of the vlen-specified
+ * number of 4-byte values that follow.
+ */
+struct btf_loc_param {
+	__u32 flags;
+	__u32 values[];
+};
+
+/*
+ * The combination of size, vlen and flags gives us the means to interpret
+ * the following vlen-specified set of 4-byte values:
+ *
+ * - a BTF_LOC_PARAM_CONST is a constant value; combination
+ *   of size, vlen and _SIGNED flag determines it. If the value requires
+ *   64 bits it is stored in {lo,hi} order.
+ * - a BTF_LOC_PARAM_ADDR|BTF_LOC_PARAM_CONST is an address that should be
+ *   normalized with respect to kernel/module base address.
+ * - a BTF_LOC_PARAM_REG with vlen 1 is a simple register number;
+ *   with vlen 2 it is a multi-register parameter.
+ * - a _REG | OFFSET describes an address without dereferencing it.
+ * - a _REG | DEREF with vlen 1 dereferences the value in the register
+ *   number specified.
+ * - a REG | DEREF | OFFSET with vlen specifies the register value in
+ *   the first 4-byte value and the offset in the remainder.
+ */
+enum btf_loc_param_flags {
+	BTF_LOC_PARAM_SIGNED		=	0x1,
+	BTF_LOC_PARAM_CONST		=	0x2,
+	BTF_LOC_PARAM_ADDR		=	0x4,
+	BTF_LOC_PARAM_REG		=	0x8,
+	BTF_LOC_PARAM_DEREF		=	0x10,
+	BTF_LOC_PARAM_OFFSET		=	0x20,
+};
+
+/*
+ * BTF_KIND_LOC_PROTO specifies location prototypes; i.e. how locations relate
+ * to parameters; a struct btf_type of BTF_KIND_LOC_PROTO is followed by a
+ * vlen-specified number of __u32 BTF type ids which specify the associated
+ * BTF_KIND_LOC_PARAM for each function parameter associated with the
+ * location.  The type should either be 0 (no location info) or point at
+ * a BTF_KIND_LOC_PARAM.
+ */
+
+/*
+ * BTF_KIND_LOCSEC consists of vlen-specified number of "struct btf_loc"
+ * containing location site-specific information for a specific ELF section;
+ * for example locations in ".text" are in a LOCSEC named "inline.text".
+ *
+ * - function (func)
+ * - location prototype type id (loc_proto)
+ * - address offset (offset) relative to kernel base address
+ */
+
+struct btf_loc {
+	__u32 func;
+	__u32 loc_proto;
+	__u32 offset;
+};
+
 #endif /* _UAPI__LINUX_BTF_H__ */
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 908bd344229d5..332a8388fcc41 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -57,6 +57,9 @@ static struct btf_layout layouts[NR_BTF_KINDS] = {
 [BTF_KIND_DECL_TAG] =	{	sizeof(struct btf_decl_tag),	0,				0 },
 [BTF_KIND_TYPE_TAG] =	{	0,				0,				0 },
 [BTF_KIND_ENUM64] =	{	0,				sizeof(struct btf_enum64),	0 },
+[BTF_KIND_LOC_PARAM] =	{	sizeof(struct btf_loc_param),	sizeof(__u32),			0 },
+[BTF_KIND_LOC_PROTO] =	{	0,				sizeof(__u32),			0 },
+[BTF_KIND_LOCSEC] =	{	0,				sizeof(struct btf_loc),		0 },
 };
 
 struct btf {
@@ -486,6 +489,12 @@ static int btf_type_size(const struct btf *btf, const struct btf_type *t)
 		return base_size + vlen * sizeof(struct btf_var_secinfo);
 	case BTF_KIND_DECL_TAG:
 		return base_size + sizeof(struct btf_decl_tag);
+	case BTF_KIND_LOC_PARAM:
+		return base_size + sizeof(struct btf_loc_param) + vlen * sizeof(__u32);
+	case BTF_KIND_LOC_PROTO:
+		return base_size + vlen * sizeof(__u32);
+	case BTF_KIND_LOCSEC:
+		return base_size + vlen * sizeof(struct btf_loc);
 	default:
 		return btf_type_size_unknown(btf, t);
 	}
@@ -501,12 +510,15 @@ static void btf_bswap_type_base(struct btf_type *t)
 static int btf_bswap_type_rest(struct btf_type *t)
 {
 	struct btf_var_secinfo *v;
+	struct btf_loc_param *lp;
 	struct btf_enum64 *e64;
 	struct btf_member *m;
 	struct btf_array *a;
 	struct btf_param *p;
 	struct btf_enum *e;
+	struct btf_loc *l;
 	__u32 vlen = btf_vlen(t);
+	__u32 *d;
 	int i;
 
 	switch (btf_kind(t)) {
@@ -569,6 +581,23 @@ static int btf_bswap_type_rest(struct btf_type *t)
 	case BTF_KIND_DECL_TAG:
 		btf_decl_tag(t)->component_idx = bswap_32(btf_decl_tag(t)->component_idx);
 		return 0;
+	case BTF_KIND_LOC_PARAM:
+		lp = btf_loc_param(t);
+		lp->flags = bswap_32(lp->flags);
+		for (i = 0, d = (__u32 *)(lp + 1); i < vlen; i++, d++)
+			*d = bswap_32(*d);
+		return 0;
+	case BTF_KIND_LOC_PROTO:
+		for (i = 0, d = btf_loc_proto_params(t); i < vlen; i++, d++)
+			*d = bswap_32(*d);
+		return 0;
+	case BTF_KIND_LOCSEC:
+		for (i = 0, l = btf_locsec_locs(t); i < vlen; i++, l++) {
+			l->func = bswap_32(l->func);
+			l->loc_proto = bswap_32(l->loc_proto);
+			l->offset = bswap_32(l->offset);
+		}
+		return 0;
 	default:
 		pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t));
 		return -EINVAL;
@@ -745,6 +774,33 @@ static int btf_validate_type(const struct btf *btf, const struct btf_type *t, __
 		}
 		break;
 	}
+	case BTF_KIND_LOC_PARAM:
+		break;
+	case BTF_KIND_LOC_PROTO: {
+		__u32 *p = btf_loc_proto_params(t);
+
+		n = btf_vlen(t);
+		for (i = 0; i < n; i++, p++) {
+			err = btf_validate_id(btf, *p, id);
+			if (err)
+				return err;
+		}
+		break;
+	}
+	case BTF_KIND_LOCSEC: {
+		const struct btf_loc *l = btf_locsec_locs(t);
+
+		n = btf_vlen(t);
+		for (i = 0; i < n; i++, l++) {
+			if (!err)
+				err = btf_validate_id(btf, l->func, id);
+			if (!err)
+				err = btf_validate_id(btf, l->loc_proto, id);
+			if (err)
+				return err;
+		}
+		break;
+	}
 	default:
 		/* Kind may be represented in kind layout information. */
 		if (btf_type_size_unknown(btf, t) < 0) {
@@ -3344,6 +3400,208 @@ int btf__add_decl_attr(struct btf *btf, const char *value, int ref_type_id,
 	return btf_add_decl_tag(btf, value, ref_type_id, component_idx, 1);
 }
 
+/*
+ * Append new BTF_KIND_LOC_PARAM with specified size and flags.  Values are
+ * added via btf__add_loc_param_value().
+ *
+ * Returns:
+ *   -  >0, type ID of newly added BTF type;
+ *   - <0, on error.
+ */
+int btf__add_loc_param(struct btf *btf, __u32 size, __u32 flags)
+{
+	struct btf_loc_param *p;
+	struct btf_type *t;
+	int sz, err;
+
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(struct btf_type) + sizeof(*p);
+	t = btf_add_type_mem(btf, sz);
+	if (!t)
+		return libbpf_err(-ENOMEM);
+
+	t->name_off = 0;
+	t->info = btf_type_info(BTF_KIND_LOC_PARAM, 0, 0);
+	t->size = size;
+
+	p = btf_loc_param(t);
+	p->flags = flags;
+
+	return btf_commit_type(btf, sz);
+}
+
+int btf__add_loc_param_value(struct btf *btf, __u32 value)
+{
+	struct btf_type *t;
+	int sz, err;
+	__u32 *v;
+
+	/* last type should be BTF_KIND_LOC_PARAM */
+	if (btf->nr_types == 0)
+		return libbpf_err(-EINVAL);
+	t = btf_last_type(btf);
+	if (!btf_is_loc_param(t))
+		return libbpf_err(-EINVAL);
+
+	/* decompose and invalidate raw data */
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(value);
+	v = btf_add_type_mem(btf, sz);
+	if (!v)
+		return libbpf_err(-ENOMEM);
+	*v = value;
+
+	/* update parent type's vlen */
+	t = btf_last_type(btf);
+	err = btf_type_inc_vlen(t);
+	if (err)
+		return libbpf_err(err);
+
+	btf_hdr_update_type_len(btf, btf->hdr.type_len + sz);
+	return 0;
+}
+
+/*
+ * Append new BTF_KIND_LOC_PROTO
+ *
+ * The prototype is then populated with 0 or more BTF_KIND_LOC_PARAMs via
+ * btf__add_loc_proto_param(); similar to how btf__add_func_param() adds
+ * parameters to a FUNC_PROTO.
+ *
+ * Returns:
+ *   -  >0, type ID of newly added BTF type;
+ *   - <0, on error.
+ */
+int btf__add_loc_proto(struct btf *btf)
+{
+	struct btf_type *t;
+	int err;
+
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	t = btf_add_type_mem(btf, sizeof(struct btf_type));
+	if (!t)
+		return libbpf_err(-ENOMEM);
+
+	t->name_off = 0;
+	t->info = btf_type_info(BTF_KIND_LOC_PROTO, 0, 0);
+	t->size = 0;
+
+	return btf_commit_type(btf, sizeof(struct btf_type));
+}
+
+int btf__add_loc_proto_param(struct btf *btf, __u32 id)
+{
+	struct btf_type *t;
+	int sz, err;
+	__u32 *p;
+
+	if (validate_type_id(id))
+		return libbpf_err(-EINVAL);
+
+	/* last type should be BTF_KIND_LOC_PROTO */
+	if (btf->nr_types == 0)
+		return libbpf_err(-EINVAL);
+	t = btf_last_type(btf);
+	if (!btf_is_loc_proto(t))
+		return libbpf_err(-EINVAL);
+
+	/* decompose and invalidate raw data */
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(__u32);
+	p = btf_add_type_mem(btf, sz);
+	if (!p)
+		return libbpf_err(-ENOMEM);
+	*p = id;
+
+	/* update parent type's vlen */
+	t = btf_last_type(btf);
+	err = btf_type_inc_vlen(t);
+	if (err)
+		return libbpf_err(err);
+
+	btf_hdr_update_type_len(btf, btf->hdr.type_len + sz);
+	return 0;
+}
+
+int btf__add_locsec(struct btf *btf, const char *name)
+{
+	struct btf_type *t;
+	int name_off = 0;
+	int err;
+
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	t = btf_add_type_mem(btf, sizeof(struct btf_type));
+	if (!t)
+		return libbpf_err(-ENOMEM);
+
+	if (!str_is_empty(name)) {
+		name_off = btf__add_str(btf, name);
+		if (name_off < 0)
+			return libbpf_err(name_off);
+	}
+	t->name_off = name_off;
+	t->info = btf_type_info(BTF_KIND_LOCSEC, 0, 0);
+	t->size = 0;
+
+	return btf_commit_type(btf, sizeof(struct btf_type));
+}
+
+int btf__add_locsec_loc(struct btf *btf, __u32 func, __u32 loc_proto,
+			__u32 offset)
+{
+	struct btf_type *t;
+	struct btf_loc *l;
+	int sz, err;
+
+	if (validate_type_id(func) || validate_type_id(loc_proto))
+		return libbpf_err(-EINVAL);
+
+	/* last type should be BTF_KIND_LOCSEC */
+	if (btf->nr_types == 0)
+		return libbpf_err(-EINVAL);
+	t = btf_last_type(btf);
+	if (!btf_is_locsec(t))
+		return libbpf_err(-EINVAL);
+
+	/* decompose and invalidate raw data */
+	err = btf_ensure_modifiable(btf);
+	if (err)
+		return libbpf_err(err);
+
+	sz = sizeof(*l);
+	l = btf_add_type_mem(btf, sz);
+	if (!l)
+		return libbpf_err(-ENOMEM);
+
+	l->func = func;
+	l->loc_proto = loc_proto;
+	l->offset = offset;
+
+	/* update parent type's vlen */
+	t = btf_last_type(btf);
+	err = btf_type_inc_vlen(t);
+	if (err)
+		return libbpf_err(err);
+
+	btf_hdr_update_type_len(btf, btf->hdr.type_len + sz);
+	return 0;
+}
+
 struct btf_ext_sec_info_param {
 	__u32 off;
 	__u32 len;
@@ -4114,8 +4372,8 @@ static struct btf_dedup *btf_dedup_new(struct btf *btf, const struct btf_dedup_o
 	for (i = 1; i < type_cnt; i++) {
 		struct btf_type *t = btf_type_by_id(d->btf, i);
 
-		/* VAR and DATASEC are never deduped and are self-canonical */
-		if (btf_is_var(t) || btf_is_datasec(t))
+		/* VAR, DATASEC and LOCSEC are never deduped and are self-canonical */
+		if (btf_is_var(t) || btf_is_datasec(t) || btf_is_locsec(t))
 			d->map[i] = i;
 		else
 			d->map[i] = BTF_UNPROCESSED_ID;
@@ -4395,6 +4653,47 @@ static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2)
 	       btf_is_any_enum(t1) && btf_is_any_enum(t2);
 }
 
+static long btf_hash_loc_param(struct btf_type *t)
+{
+	struct btf_loc_param *p = btf_loc_param(t);
+	long h = btf_hash_common(t);
+	int i, vlen = btf_vlen(t);
+
+	h = hash_combine(h, p->flags);
+
+	for (i = 0; i < vlen; i++)
+		h = hash_combine(h, p->values[i]);
+	return h;
+}
+
+static long btf_hash_loc_proto(struct btf_type *t)
+{
+	__u32 *p = btf_loc_proto_params(t);
+	long h = btf_hash_common(t);
+	int i, vlen = btf_vlen(t);
+
+	for (i = 0; i < vlen; i++, p++)
+		h = hash_combine(h, *p);
+	return h;
+}
+
+static bool btf_equal_loc_param(struct btf_type *t1, struct btf_type *t2)
+{
+	struct btf_loc_param *p1 = btf_loc_param(t1);
+	struct btf_loc_param *p2 = btf_loc_param(t2);
+	int i, vlen = btf_vlen(t1);
+
+	if (!btf_equal_common(t1, t2))
+		return false;
+	if (p1->flags != p2->flags)
+		return false;
+	for (i = 0; i < vlen; i++) {
+		if (p1->values[i] != p2->values[i])
+			return false;
+	}
+	return true;
+}
+
 /*
  * Calculate type signature hash of STRUCT/UNION, ignoring referenced type IDs,
  * as referenced type IDs equivalence is established separately during type
@@ -4589,7 +4888,8 @@ static int btf_dedup_prep(struct btf_dedup *d)
 		switch (btf_kind(t)) {
 		case BTF_KIND_VAR:
 		case BTF_KIND_DATASEC:
-			/* VAR and DATASEC are never hash/deduplicated */
+		case BTF_KIND_LOCSEC:
+			/* VAR DATASEC and LOCSEC are never hash/deduplicated */
 			continue;
 		case BTF_KIND_CONST:
 		case BTF_KIND_VOLATILE:
@@ -4622,6 +4922,12 @@ static int btf_dedup_prep(struct btf_dedup *d)
 		case BTF_KIND_FUNC_PROTO:
 			h = btf_hash_fnproto(t);
 			break;
+		case BTF_KIND_LOC_PARAM:
+			h = btf_hash_loc_param(t);
+			break;
+		case BTF_KIND_LOC_PROTO:
+			h = btf_hash_loc_proto(t);
+			break;
 		default:
 			pr_debug("unknown kind %d for type [%d]\n", btf_kind(t), type_id);
 			return -EINVAL;
@@ -4664,6 +4970,8 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
 	case BTF_KIND_DATASEC:
 	case BTF_KIND_DECL_TAG:
 	case BTF_KIND_TYPE_TAG:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
 		return 0;
 
 	case BTF_KIND_INT:
@@ -4713,6 +5021,18 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
 		}
 		break;
 
+	case BTF_KIND_LOC_PARAM:
+		h = btf_hash_loc_param(t);
+		for_each_dedup_cand(d, hash_entry, h) {
+			cand_id = hash_entry->value;
+			cand = btf_type_by_id(d->btf, cand_id);
+			if (btf_equal_loc_param(t, cand)) {
+				new_id = cand_id;
+				break;
+			}
+		}
+		break;
+
 	default:
 		return -EINVAL;
 	}
@@ -5145,6 +5465,13 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
 		return 1;
 	}
 
+	case BTF_KIND_LOC_PARAM:
+		return btf_equal_loc_param(cand_type, canon_type);
+
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -5489,6 +5816,37 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 		break;
 	}
 
+	case BTF_KIND_LOC_PROTO: {
+		__u32 *p1, *p2;
+		__u32 i, vlen;
+
+		p1 = btf_loc_proto_params(t);
+		vlen = btf_vlen(t);
+
+		for (i = 0; i < vlen; i++, p1++) {
+			ref_type_id = btf_dedup_ref_type(d, *p1);
+			if (ref_type_id < 0)
+				return ref_type_id;
+			*p1 = ref_type_id;
+		}
+
+		h = btf_hash_loc_proto(t);
+		for_each_dedup_cand(d, hash_entry, h) {
+			cand_id = hash_entry->value;
+			cand = btf_type_by_id(d->btf, cand_id);
+			if (!btf_equal_common(t, cand))
+				continue;
+			vlen = btf_vlen(cand);
+			p1 = btf_loc_proto_params(t);
+			p2 = btf_loc_proto_params(cand);
+			if (memcmp(p1, p2, vlen * sizeof(__u32)) == 0) {
+				new_id = cand_id;
+				break;
+			}
+		}
+		break;
+	}
+
 	default:
 		return -EINVAL;
 	}
@@ -5970,8 +6328,11 @@ static int btf_add_distilled_type_ids(struct btf_distill *dist, __u32 i)
 		case BTF_KIND_CONST:
 		case BTF_KIND_RESTRICT:
 		case BTF_KIND_VOLATILE:
+		case BTF_KIND_FUNC:
 		case BTF_KIND_FUNC_PROTO:
 		case BTF_KIND_TYPE_TAG:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
 			dist->id_map[*id] = *id;
 			break;
 		default:
@@ -5997,7 +6358,7 @@ static int btf_add_distilled_type_ids(struct btf_distill *dist, __u32 i)
 
 static int btf_add_distilled_types(struct btf_distill *dist)
 {
-	bool adding_to_base = dist->pipe.dst->start_id == 1;
+	bool adding_to_base = dist->pipe.dst->base_btf == NULL;
 	int id = btf__type_cnt(dist->pipe.dst);
 	struct btf_type *t;
 	int i, err = 0;
@@ -6065,8 +6426,12 @@ static int btf_add_distilled_types(struct btf_distill *dist)
 		case BTF_KIND_CONST:
 		case BTF_KIND_RESTRICT:
 		case BTF_KIND_VOLATILE:
+		case BTF_KIND_FUNC:
 		case BTF_KIND_FUNC_PROTO:
 		case BTF_KIND_TYPE_TAG:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
+		case BTF_KIND_LOCSEC:
 			/* All other types are added to split BTF. */
 			if (adding_to_base)
 				continue;
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 587172c0de089..57f12630c5d15 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -274,6 +274,20 @@ LIBBPF_API int btf__add_decl_tag(struct btf *btf, const char *value, int ref_typ
 LIBBPF_API int btf__add_decl_attr(struct btf *btf, const char *value, int ref_type_id,
 				  int component_idx);
 
+/* location construction APIs */
+LIBBPF_API int btf__add_loc_param(struct btf *btf, __u32 size, __u32 flags);
+
+LIBBPF_API int btf__add_loc_param_value(struct btf *btf, __u32 value);
+
+LIBBPF_API int btf__add_loc_proto(struct btf *btf);
+
+LIBBPF_API int btf__add_loc_proto_param(struct btf *btf, __u32 id);
+
+LIBBPF_API int btf__add_locsec(struct btf *btf, const char *name);
+
+LIBBPF_API int btf__add_locsec_loc(struct btf *btf, __u32 func, __u32 loc_proto,
+				   __u32 offset);
+
 struct btf_dedup_opts {
 	size_t sz;
 	/* optional .BTF.ext info to dedup along the main BTF info */
@@ -431,6 +445,12 @@ btf_dump__dump_type_data(struct btf_dump *d, __u32 id,
 #define BTF_KIND_DECL_TAG	17	/* Decl Tag */
 #define BTF_KIND_TYPE_TAG	18	/* Type Tag */
 #define BTF_KIND_ENUM64		19	/* Enum for up-to 64bit values */
+#define BTF_KIND_LOC_PARAM	20	/* Parameter at location */
+#define BTF_KIND_LOC_PROTO	21	/* Parameter set at location */
+#define BTF_KIND_LOCSEC		22	/* Section containing location info */
+
+struct btf_loc_param;
+struct btf_loc;
 
 static inline __u16 btf_kind(const struct btf_type *t)
 {
@@ -569,6 +589,21 @@ static inline bool btf_is_any_enum(const struct btf_type *t)
 	return btf_is_enum(t) || btf_is_enum64(t);
 }
 
+static inline bool btf_is_loc_param(const struct btf_type *t)
+{
+	return btf_kind(t) == BTF_KIND_LOC_PARAM;
+}
+
+static inline bool btf_is_loc_proto(const struct btf_type *t)
+{
+	return btf_kind(t) == BTF_KIND_LOC_PROTO;
+}
+
+static inline bool btf_is_locsec(const struct btf_type *t)
+{
+	return btf_kind(t) == BTF_KIND_LOCSEC;
+}
+
 static inline bool btf_kind_core_compat(const struct btf_type *t1,
 					const struct btf_type *t2)
 {
@@ -683,6 +718,21 @@ static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
 	return (struct btf_decl_tag *)(t + 1);
 }
 
+static inline struct btf_loc_param *btf_loc_param(const struct btf_type *t)
+{
+	return (struct btf_loc_param *)(t + 1);
+}
+
+static inline __u32 *btf_loc_proto_params(const struct btf_type *t)
+{
+	return (__u32 *)(t + 1);
+}
+
+static inline struct btf_loc *btf_locsec_locs(const struct btf_type *t)
+{
+	return (struct btf_loc *)(t + 1);
+}
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 123c448f20c74..fa995c02a1705 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -328,6 +328,9 @@ static int btf_dump_mark_referenced(struct btf_dump *d)
 		case BTF_KIND_ENUM64:
 		case BTF_KIND_FWD:
 		case BTF_KIND_FLOAT:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
+		case BTF_KIND_LOCSEC:
 			break;
 
 		case BTF_KIND_VOLATILE:
@@ -609,6 +612,9 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
 	case BTF_KIND_VAR:
 	case BTF_KIND_DATASEC:
 	case BTF_KIND_DECL_TAG:
+	case BTF_KIND_LOC_PARAM:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
 		d->type_states[id].order_state = ORDERED;
 		return 0;
 
@@ -2525,6 +2531,9 @@ static int btf_dump_dump_type_data(struct btf_dump *d,
 	case BTF_KIND_FUNC:
 	case BTF_KIND_FUNC_PROTO:
 	case BTF_KIND_DECL_TAG:
+	case BTF_KIND_LOC_PARAM:
+	case BTF_KIND_LOC_PROTO:
+	case BTF_KIND_LOCSEC:
 		err = btf_dump_unsupported_data(d, t, id);
 		break;
 	case BTF_KIND_INT:
diff --git a/tools/lib/bpf/btf_iter.c b/tools/lib/bpf/btf_iter.c
index 9a6c822c22944..199063b55ebe6 100644
--- a/tools/lib/bpf/btf_iter.c
+++ b/tools/lib/bpf/btf_iter.c
@@ -29,6 +29,7 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 		case BTF_KIND_FLOAT:
 		case BTF_KIND_ENUM:
 		case BTF_KIND_ENUM64:
+		case BTF_KIND_LOC_PARAM:
 			it->desc = (struct btf_field_desc) {};
 			break;
 		case BTF_KIND_FWD:
@@ -71,6 +72,20 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 				1, {offsetof(struct btf_var_secinfo, type)}
 			};
 			break;
+		case BTF_KIND_LOC_PROTO:
+			it->desc = (struct btf_field_desc) {
+				0, {},
+				sizeof(__u32),
+				1, {0}};
+			break;
+		case BTF_KIND_LOCSEC:
+			it->desc = (struct btf_field_desc) {
+				0, {},
+				sizeof(struct btf_loc),
+				2, {offsetof(struct btf_loc, func),
+				    offsetof(struct btf_loc, loc_proto)}};
+			break;
+
 		default:
 			return -EINVAL;
 		}
@@ -94,6 +109,9 @@ int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
 		case BTF_KIND_DECL_TAG:
 		case BTF_KIND_TYPE_TAG:
 		case BTF_KIND_DATASEC:
+		case BTF_KIND_LOC_PARAM:
+		case BTF_KIND_LOC_PROTO:
+		case BTF_KIND_LOCSEC:
 			it->desc = (struct btf_field_desc) {
 				1, {offsetof(struct btf_type, name_off)}
 			};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 08ab2ea881fb6..7f51783df129a 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -460,6 +460,12 @@ LIBBPF_1.8.0 {
 	global:
 		bpf_program__attach_tracing_multi;
 		bpf_program__clone;
+		btf__add_loc_param;
+		btf__add_loc_param_value;
+		btf__add_loc_proto;
+		btf__add_loc_proto_param;
+		btf__add_locsec;
+		btf__add_locsec_loc;
 		btf__find_by_name_kind_own;
 		btf__new_empty_opts;
 } LIBBPF_1.7.0;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index cb4d962338441..546f65b95cf4d 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -580,7 +580,7 @@ struct btf_field_desc {
 	/* member struct size, or zero, if no members */
 	int m_sz;
 	/* repeated per-member offsets */
-	int m_off_cnt, m_offs[1];
+	int m_off_cnt, m_offs[2];
 };
 
 struct btf_field_iter {
diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index 1c1c2c26690a7..972403f6a7438 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
@@ -27,11 +27,14 @@ static const char * const btf_kind_str_mapping[] = {
 	[BTF_KIND_DECL_TAG]	= "DECL_TAG",
 	[BTF_KIND_TYPE_TAG]	= "TYPE_TAG",
 	[BTF_KIND_ENUM64]	= "ENUM64",
+	[BTF_KIND_LOC_PARAM]	= "LOC_PARAM",
+	[BTF_KIND_LOC_PROTO]	= "LOC_PROTO",
+	[BTF_KIND_LOCSEC]	= "LOCSEC",
 };
 
 static const char *btf_kind_str(__u16 kind)
 {
-	if (kind > BTF_KIND_ENUM64)
+	if (kind > BTF_KIND_LOCSEC)
 		return "UNKNOWN";
 	return btf_kind_str_mapping[kind];
 }
@@ -203,6 +206,37 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
 		fprintf(out, " type_id=%u component_idx=%d",
 			t->type, btf_decl_tag(t)->component_idx);
 		break;
+	case BTF_KIND_LOC_PARAM: {
+		struct btf_loc_param *p = btf_loc_param(t);
+		__u32 *v = (__u32 *)(p + 1);
+
+		fprintf(out, " size=%u flags=0x%x vlen=%u", t->size, p->flags, vlen);
+		for (i = 0; i < vlen; i++, v++) {
+			if (p->flags & BTF_LOC_PARAM_SIGNED)
+				fprintf(out, "\n\tvalue=%d", (__s32)*v);
+			else
+				fprintf(out, "\n\tvalue=%u", *v);
+		}
+		break;
+	}
+	case BTF_KIND_LOC_PROTO: {
+		const __u32 *p = btf_loc_proto_params(t);
+
+		fprintf(out, " vlen=%u", vlen);
+		for (i = 0; i < vlen; i++, p++)
+			fprintf(out, "\n\ttype_id=%u", *p);
+		break;
+	}
+	case BTF_KIND_LOCSEC: {
+		const struct btf_loc *l = btf_locsec_locs(t);
+
+		fprintf(out, " vlen=%u", vlen);
+		for (i = 0; i < vlen; i++, l++) {
+			fprintf(out, "\n\tfunc_type_id=%u loc_proto_type_id=%u offset=%u",
+				l->func, l->loc_proto, l->offset);
+		}
+		break;
+	}
 	default:
 		break;
 	}
diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
index d5b25302b0c89..f8ea9dfd0780b 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
@@ -57,6 +57,35 @@ static struct btf *mk_btf(void)
 	return btf;
 }
 
+static struct btf *mk_loc_btf(void)
+{
+	struct btf *btf;
+
+	btf = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf, "new_empty"))
+		return NULL;
+
+	btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+	btf__add_func_proto(btf, 1);
+	btf__add_func_param(btf, "arg1", 1);
+	btf__add_func_param(btf, "arg2", 1);
+	btf__add_func(btf, "foo", BTF_FUNC_STATIC, 2);
+
+	btf__add_loc_param(btf, 4, BTF_LOC_PARAM_REG);
+	btf__add_loc_param_value(btf, 1);
+	btf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG |
+			    BTF_LOC_PARAM_DEREF | BTF_LOC_PARAM_OFFSET);
+	btf__add_loc_param_value(btf, 2);
+	btf__add_loc_param_value(btf, 0x10);
+	btf__add_loc_proto(btf);
+	btf__add_loc_proto_param(btf, 4);
+	btf__add_loc_proto_param(btf, 5);
+	btf__add_locsec(btf, "inline.text");
+	btf__add_locsec_loc(btf, 3, 6, 64);
+
+	return btf;
+}
+
 static int btf_to_tmpfile(const struct btf *btf, char *path)
 {
 	ssize_t written;
@@ -105,6 +134,26 @@ static char *dump_c(const char *btf_path, bool sorted)
 	return buf;
 }
 
+static char *dump_raw(const char *btf_path)
+{
+	char args[MAX_BPFTOOL_CMD_LEN];
+	char *buf;
+	int err;
+
+	buf = malloc(DUMP_BUF_SZ);
+	if (!ASSERT_OK_PTR(buf, "alloc_dump"))
+		return NULL;
+
+	snprintf(args, sizeof(args), "btf dump file %s", btf_path);
+	err = get_bpftool_command_output(args, buf, DUMP_BUF_SZ);
+	if (!ASSERT_OK(err, "btf_dump_raw")) {
+		free(buf);
+		return NULL;
+	}
+
+	return buf;
+}
+
 static char *read_expected(const char *path)
 {
 	char *buf = NULL;
@@ -155,6 +204,31 @@ static void test_dump(const char *btf_path, bool sorted)
 	free(dump);
 }
 
+static void test_loc_dump(const char *btf_path)
+{
+	const char expected[] =
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\n"
+		"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'arg1' type_id=1\n"
+		"\t'arg2' type_id=1\n"
+		"[3] FUNC 'foo' type_id=2 linkage=static\n"
+		"[4] LOC_PARAM '(anon)' size=4 flags=0x8 vlen=1 values='r1'\n"
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x38 vlen=2 values='*(r2 + 0x10)'\n"
+		"[6] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=4 value='r1'\n"
+		"\ttype_id=5 value='*(r2 + 0x10)'\n"
+		"[7] LOCSEC 'inline.text' vlen=1\n"
+		"\tname='foo' func_type_id=3 loc_proto_type_id=6 offset=64\n";
+	char *dump;
+
+	dump = dump_raw(btf_path);
+	if (!dump)
+		return;
+
+	ASSERT_OK(compare_text_to_expected(dump, expected), "cmp_loc_dump");
+	free(dump);
+}
+
 void test_bpftool_btf_dump(void)
 {
 	char path[PATH_MAX];
@@ -175,4 +249,14 @@ void test_bpftool_btf_dump(void)
 	unlink(path);
 out_btf:
 	btf__free(btf);
+
+	btf = mk_loc_btf();
+	if (!btf)
+		return;
+
+	if (!btf_to_tmpfile(btf, path) && test__start_subtest("loc_dump"))
+		test_loc_dump(path);
+
+	unlink(path);
+	btf__free(btf);
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
index 9d61611515938..5c15a6b7f4fb9 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
@@ -554,6 +554,120 @@ static void test_split_module(void)
 	btf__free(vmlinux_btf);
 }
 
+static void test_split_loc(void)
+{
+	struct btf *btf1, *btf2;
+	int err;
+
+	btf1 = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf1, "empty_main_btf"))
+		return;
+
+	btf__set_pointer_size(btf1, 8); /* enforce 64-bit arch */
+
+
+	btf__add_int(btf1, "long", 8, BTF_INT_SIGNED);  /* [1] long */
+	btf__add_ptr(btf1, 1);                          /* [2] ptr to long */
+	btf__add_func_proto(btf1, 1);			/* [3] long (*)(long, long *); */
+	btf__add_func_param(btf1, "p1", 1);
+	btf__add_func_param(btf1, "p2", 2);
+	btf__add_func(btf1, "foo", BTF_FUNC_STATIC, 3);	/* [4] long foo(long, long *); */
+	btf__add_loc_param(btf1, 8, BTF_LOC_PARAM_CONST);
+	btf__add_loc_param_value(btf1, 3735928559);
+	btf__add_loc_param_value(btf1, 4277009102);	/* [5] loc value */
+	btf__add_loc_param(btf1, 8, BTF_LOC_PARAM_REG);	/* [6] loc reg 1 */
+	btf__add_loc_param_value(btf1, 1);
+	btf__add_loc_proto(btf1);			/* [7] loc proto */
+	btf__add_loc_proto_param(btf1, 5);		/*  param value */
+	btf__add_loc_proto_param(btf1, 6);		/*  param reg 1 */
+
+	VALIDATE_RAW_BTF(
+		btf1,
+		"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'p1' type_id=1\n"
+		"\t'p2' type_id=2",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\n"
+		"\tvalue=3735928559\n"
+		"\tvalue=4277009102",
+		"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[7] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=6");
+
+	btf2 = btf__new_empty_split(btf1);
+	if (!ASSERT_OK_PTR(btf2, "empty_split_btf"))
+		goto cleanup;
+	btf__add_loc_param(btf2, 8, BTF_LOC_PARAM_REG);
+	btf__add_loc_param_value(btf2, 1);		/* [8] loc reg 1 */
+	btf__add_loc_proto(btf2);			/* [9] loc proto */
+	btf__add_loc_proto_param(btf2, 5);		/* param value */
+	btf__add_loc_proto_param(btf2, 8);		/* param reg 1 */
+	btf__add_locsec(btf2, "inline.text");		/* [10] locsec "inline.text" */
+	/* add duplicate locsec */
+	btf__add_locsec_loc(btf2, 4, 9, 128);
+	btf__add_locsec(btf2, "inline.text");		/* [11] locsec "inline.text" */
+	btf__add_locsec_loc(btf2, 4, 9, 128);
+
+	VALIDATE_RAW_BTF(
+		btf2,
+		"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'p1' type_id=1\n"
+		"\t'p2' type_id=2",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\n"
+		"\tvalue=3735928559\n"
+		"\tvalue=4277009102",
+		"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[7] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=6",
+		"[8] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[9] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=8",
+		"[10] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=9 offset=128",
+		"[11] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=9 offset=128");
+
+	err = btf__dedup(btf2, NULL);
+	if (!ASSERT_OK(err, "btf_dedup"))
+		goto cleanup;
+
+	VALIDATE_RAW_BTF(
+		btf2,
+		"[1] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=2\n"
+		"\t'p1' type_id=1\n"
+		"\t'p2' type_id=2",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2\n"
+		"\tvalue=3735928559\n"
+		"\tvalue=4277009102",
+		"[6] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[7] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=5\n"
+		"\ttype_id=6",
+		"[8] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=7 offset=128",
+		"[9] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=7 offset=128");
+
+cleanup:
+	btf__free(btf2);
+	btf__free(btf1);
+}
+
 void test_btf_dedup_split()
 {
 	if (test__start_subtest("split_simple"))
@@ -566,4 +680,6 @@ void test_btf_dedup_split()
 		test_split_dup_struct_in_cu();
 	if (test__start_subtest("split_module"))
 		test_split_module();
+	if (test__start_subtest("split_loc"))
+		test_split_loc();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_distill.c b/tools/testing/selftests/bpf/prog_tests/btf_distill.c
index fb67ae195a738..141a4cb1f4054 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_distill.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_distill.c
@@ -671,6 +671,105 @@ static void test_distilled_base_embedded_err(void)
 	btf__free(btf1);
 }
 
+/* LOC_PARAM, LOC_PROTO should be added to split BTF. */
+static void test_distilled_loc(void)
+{
+	struct btf *btf1 = NULL, *btf2 = NULL, *btf3 = NULL;
+	struct btf *btf4 = NULL, *btf5 = NULL;
+
+	btf1 = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf1, "empty_main_btf"))
+		return;
+
+	btf__add_int(btf1, "int", 4, BTF_INT_SIGNED);	/* [1] int */
+	btf__add_func_proto(btf1, 1);                   /* [2] int (*)(int); */
+	btf__add_func_param(btf1, "p1", 1);
+	btf__add_func(btf1, "foo", BTF_FUNC_STATIC, 2);	/* [3] int foo(int); */
+	btf__add_loc_param(btf1, 4, BTF_LOC_PARAM_SIGNED | BTF_LOC_PARAM_CONST);
+	btf__add_loc_param_value(btf1, -1);		/* [4] loc value */
+	btf__add_loc_proto(btf1);			/* [5] loc proto */
+	btf__add_loc_proto_param(btf1, 4);		/*  param value */
+
+	VALIDATE_RAW_BTF(
+		btf1,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[3] FUNC 'foo' type_id=2 linkage=static",
+		"[4] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[5] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=4");
+
+	btf2 = btf__new_empty_split(btf1);
+	if (!ASSERT_OK_PTR(btf2, "empty_split_btf"))
+		goto cleanup;
+
+	btf__add_locsec(btf2, "inline.text");		/* [6] locsec */
+	btf__add_locsec_loc(btf2, 3, 5, 256);		/* "foo" offset 256 */
+	VALIDATE_RAW_BTF(
+		btf2,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		"[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[3] FUNC 'foo' type_id=2 linkage=static",
+		"[4] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[5] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=4",
+		"[6] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=3 loc_proto_type_id=5 offset=256");
+
+	if (!ASSERT_EQ(0, btf__distill_base(btf2, &btf3, &btf4),
+		       "distilled_base") ||
+	    !ASSERT_OK_PTR(btf3, "distilled_base") ||
+	    !ASSERT_OK_PTR(btf4, "distilled_split") ||
+	    !ASSERT_EQ(2, btf__type_cnt(btf3), "distilled_base_type_cnt"))
+		goto cleanup;
+
+	VALIDATE_RAW_BTF(
+		btf4,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		/* remainder is split BTF */
+		"[2] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=6 offset=256",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[6] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=5");
+
+	btf5 = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf5, "empty_reloc_btf"))
+		goto cleanup;
+	btf__add_int(btf5, "int", 4, BTF_INT_SIGNED);	/* [1] int */
+
+	if (!ASSERT_EQ(btf__relocate(btf4, btf5), 0, "relocate_split"))
+		goto cleanup;
+	VALIDATE_RAW_BTF(
+		btf4,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		/* remainder is split BTF */
+		"[2] LOCSEC 'inline.text' vlen=1\n"
+		"\tfunc_type_id=4 loc_proto_type_id=6 offset=256",
+		"[3] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
+		"\t'p1' type_id=1",
+		"[4] FUNC 'foo' type_id=3 linkage=static",
+		"[5] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[6] LOC_PROTO '(anon)' vlen=1\n"
+		"\ttype_id=5");
+
+cleanup:
+	btf__free(btf5);
+	btf__free(btf4);
+	btf__free(btf3);
+	btf__free(btf2);
+	btf__free(btf1);
+}
+
 void test_btf_distill(void)
 {
 	if (test__start_subtest("distilled_base"))
@@ -689,4 +788,6 @@ void test_btf_distill(void)
 		test_distilled_base_vmlinux();
 	if (test__start_subtest("distilled_endianness"))
 		test_distilled_endianness();
+	if (test__start_subtest("distilled_loc"))
+		test_distilled_loc();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c b/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c
index 32159d3eb281b..dcb5429d141df 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_field_iter.c
@@ -31,8 +31,11 @@ struct field_data {
 	{ .ids = { 11 },	.strs = { "decltag" } },
 	{ .ids = { 6 },		.strs = { "typetag" } },
 	{ .ids = {},		.strs = { "e64", "eval1", "eval2", "eval3" } },
-	{ .ids = { 15, 16 },	.strs = { "datasec1" } }
-
+	{ .ids = { 15, 16 },	.strs = { "datasec1" } },
+	{ .ids = {},		.strs = { "" } },
+	{ .ids = {},		.strs = { "" } },
+	{ .ids = { 22, 23 },	.strs = { "" } },
+	{ .ids = { 14, 24 },	.strs = { ".loc" } }
 };
 
 /* Fabricate BTF with various types and check BTF field iteration finds types,
@@ -88,6 +91,19 @@ void test_btf_field_iter(void)
 	btf__add_datasec_var_info(btf, 15, 0, 4);
 	btf__add_datasec_var_info(btf, 16, 4, 8);
 
+	btf__add_loc_param(btf, 4, BTF_LOC_PARAM_CONST | BTF_LOC_PARAM_SIGNED);
+							/* [22] loc value -1 */
+	btf__add_loc_param_value(btf, -1);
+	btf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG);	/* [23] loc reg 1 */
+	btf__add_loc_param_value(btf, 1);
+
+	btf__add_loc_proto(btf);			/* [24] loc proto */
+	btf__add_loc_proto_param(btf, 22);		/*  param value -1, */
+	btf__add_loc_proto_param(btf, 23);		/*  param reg 1 */
+
+	btf__add_locsec(btf, ".loc");			/* [25] locsec ".loc" */
+	btf__add_locsec_loc(btf, 14, 24, 128);		/* "func" */
+
 	VALIDATE_RAW_BTF(
 		btf,
 		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
@@ -123,7 +139,16 @@ void test_btf_field_iter(void)
 		"\t'eval3' val=3000",
 		"[21] DATASEC 'datasec1' size=12 vlen=2\n"
 		"\ttype_id=15 offset=0 size=4\n"
-		"\ttype_id=16 offset=4 size=8");
+		"\ttype_id=16 offset=4 size=8",
+		"[22] LOC_PARAM '(anon)' size=4 flags=0x3 vlen=1\n"
+		"\tvalue=-1",
+		"[23] LOC_PARAM '(anon)' size=8 flags=0x8 vlen=1\n"
+		"\tvalue=1",
+		"[24] LOC_PROTO '(anon)' vlen=2\n"
+		"\ttype_id=22\n"
+		"\ttype_id=23",
+		"[25] LOCSEC '.loc' vlen=1\n"
+		"\tfunc_type_id=14 loc_proto_type_id=24 offset=128");
 
 	for (id = 1; id < btf__type_cnt(btf); id++) {
 		struct btf_type *t = btf_type_by_id(btf, id);
diff --git a/tools/testing/selftests/bpf/test_btf.h b/tools/testing/selftests/bpf/test_btf.h
index e7bc781083745..b99c04b4d26bb 100644
--- a/tools/testing/selftests/bpf/test_btf.h
+++ b/tools/testing/selftests/bpf/test_btf.h
@@ -84,4 +84,20 @@
 #define BTF_TYPE_TAG_ENC(value, type)	\
 	BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)
 
+#define BTF_LOC_PARAM_ENC(nvals, sz, flags) \
+	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_LOC_PARAM, 0, nvals), sz), (flags)
+
+#define BTF_LOC_PARAM_VAL_ENCODE(val)	(val)
+
+#define BTF_LOC_PROTO_ENC(nargs) \
+	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_LOC_PROTO, 0, nargs), 0)
+
+#define BTF_LOC_PROTO_PARAM_ENCODE(param) (param)
+
+#define BTF_LOCSEC_ENC(name, nlocs) \
+	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_LOCSEC, 0, nlocs), 0)
+
+#define BTF_LOCSEC_LOC_ENCODE(func, loc_proto, offset) \
+	(func), (loc_proto), (offset)
+
 #endif /* _TEST_BTF_H */

43/3 2026/09/17 18:49 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32156
							output: 37
							thoughts: 2202
						

Thoughts:
**KMSAN Fuzzing Evaluation for BTF New Kinds**

Okay, let's break this down. My task is to determine if this kernel patch introducing new BTF kinds (LOC_PARAM, LOC_PROTO, LOCSEC) warrants a dedicated KMSAN fuzzing session. The rules are clear: KMSAN is expensive, so it's *only* justified if this patch exposes uninitialized memory risks that other detectors (KASAN, LOCKDEP) won't catch.

First, I need to understand what this patch actually *does*. It's adding support for these new BTF kinds, which suggests it is adding new data structures to BPF Type Format (BTF) definitions. The affected files are a good indicator of the scope: kernel-space code in `kernel/bpf/btf.c`, along with supporting header files (`include/linux/btf.h`, `include/uapi/linux/btf.h`) and user-space tools (`tools/bpf/bpftool` and relevant includes).  That tells me that changes involve both kernel-internal BTF structures and how they are exposed to user space.

Now, I'm diving into the kernel code changes in detail. The patch introduces new structures like `btf_loc_param`, `btf_loc_proto`, and `btf_loc`.  It looks like these structures are related to location information within the BTF data. The core concern here is how these new structures are *handled*. Are they initialized properly before use? Are they copied to/from user space in a safe manner?  The `btf_type_nosize` function catches my eye. Is a zero-size type really appropriate for new structures? This needs further investigation.

Specifically, I see a potential area for concern in the `btf_loc_param` structure, which has a `values[]` array. The documentation notes that `btf_loc_param`'s size is specified in `t->size`, and checks are performed on `size` within `btf_loc_param_check_meta`. How is `size` determined and set?

The critical questions are about data flow and initialization:

1.  **User-space exposure:** Does the patch modify any structures being *sent to user space* that now include these new BTF kinds? This includes any functions that might use `copy_to_user`, `put_user`, netlink skb attributes, ioctl output arguments, socket options, or BPF buffers.  If these new structures are passed to user space *without* proper initialization, KMSAN is definitely needed.
2.  **Conditional Logic/Branching:** Does the introduction of these new kinds involve any new logic that relies on potentially uninitialized variables? This could introduce a vulnerability.
3.  **Complex Data Structures:** Are new complex data structures involved or used where uninitialized fields could be read later in reachable code paths? If the answer is yes, then there is a risk.
4.  **Bounds Checks:** Does the code introduce any new ways to manipulate pointers or index into data structures related to BTF which *could* permit access to uninitialized data.

To answer those questions, I need to investigate the BTF parsing code in `kernel/bpf/btf.c`.  Specifically, I need to look closely at how BTF data is:
*   Parsed from user space (e.g. through the `bpf()` syscall or similar mechanisms).
*   Handled within the kernel (including type resolution and size calculations).
*   Potentially *returned* to user space (e.g., through `bpf_btf_get_info_by_fd` or BTF dumping).

I am not going to guess.  I am going to *find* the answers in the code using grepping or reading the code directly. I need to trace the data flow to ensure there are no uninitialized memory leaks. Based on the analysis of these flows, I will make the final decision.



44/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "btf_parse_type_sec",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=5838=static int btf_check_all_types(struct btf_verifier_env *env)\n--\nkernel/bpf/btf.c-5871-\nkernel/bpf/btf.c:5872:static int btf_parse_type_sec(struct btf_verifier_env *env)\nkernel/bpf/btf.c-5873-{\n--\nkernel/bpf/btf.c=6278=static struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/btf.c-6337-\nkernel/bpf/btf.c:6338:\terr = btf_parse_type_sec(env);\nkernel/bpf/btf.c-6339-\tif (err)\n"
}

45/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35484
							output: 38
							thoughts: 36
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Diving into BTF Parsing in the Kernel**

Alright, time to refresh my memory on the nitty-gritty of BTF handling, specifically focusing on `kernel/bpf/btf.c`. I'm especially interested in the `btf_parse` function and how it orchestrates the loading and movement of BTF data between the kernel and userspace. I need to understand the data flow, and potential bottlenecks, and any security implications related to this crucial process. I'll need to pay close attention to the memory copying routines and how they handle user-provided data. Are there any checks for size, alignment, and other constraints to prevent exploitable vulnerabilities? I want to make sure the data marshaling and validation are robust. Essentially, I need to know how resilient this whole process is to malicious or malformed BTF data. Let's see how they've handled potential injection attacks and buffer overflows. It's time to dig in and remind myself of the details.



46/3 2026/09/17 18:50 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 6280,
  "LineCount": 80
}

Results:
{
  "Contents": "6280:\t{\n6281:\t\tbpfptr_t btf_data = make_bpfptr(attr-\u003ebtf, uattr.is_kernel);\n6282:\t\tstruct btf_struct_metas *struct_meta_tab;\n6283:\t\tstruct btf_verifier_env *env = NULL;\n6284:\t\tstruct btf *btf = NULL;\n6285:\t\tu8 *data;\n6286:\t\tint err, ret;\n6287:\t\n6288:\t\tif (attr-\u003ebtf_size \u003e BTF_MAX_SIZE)\n6289:\t\t\treturn ERR_PTR(-E2BIG);\n6290:\t\n6291:\t\tenv = kzalloc_obj(*env, GFP_KERNEL | __GFP_NOWARN);\n6292:\t\tif (!env)\n6293:\t\t\treturn ERR_PTR(-ENOMEM);\n6294:\t\n6295:\t\t/* user could have requested verbose verifier output\n6296:\t\t * and supplied buffer to store the verification trace\n6297:\t\t */\n6298:\t\terr = bpf_vlog_init(\u0026env-\u003elog, attr_log-\u003elevel, attr_log-\u003eubuf, attr_log-\u003esize);\n6299:\t\tif (err)\n6300:\t\t\tgoto errout_free;\n6301:\t\n6302:\t\tbtf = kzalloc_obj(*btf, GFP_KERNEL | __GFP_NOWARN);\n6303:\t\tif (!btf) {\n6304:\t\t\terr = -ENOMEM;\n6305:\t\t\tgoto errout;\n6306:\t\t}\n6307:\t\tenv-\u003ebtf = btf;\n6308:\t\tbtf-\u003enamed_start_id = 0;\n6309:\t\n6310:\t\tdata = kvmalloc(attr-\u003ebtf_size, GFP_KERNEL | __GFP_NOWARN);\n6311:\t\tif (!data) {\n6312:\t\t\terr = -ENOMEM;\n6313:\t\t\tgoto errout;\n6314:\t\t}\n6315:\t\n6316:\t\tbtf-\u003edata = data;\n6317:\t\tbtf-\u003edata_size = attr-\u003ebtf_size;\n6318:\t\n6319:\t\tif (copy_from_bpfptr(data, btf_data, attr-\u003ebtf_size)) {\n6320:\t\t\terr = -EFAULT;\n6321:\t\t\tgoto errout;\n6322:\t\t}\n6323:\t\n6324:\t\terr = btf_parse_hdr(env);\n6325:\t\tif (err)\n6326:\t\t\tgoto errout;\n6327:\t\n6328:\t\tbtf-\u003enohdr_data = btf-\u003edata + btf-\u003ehdr.hdr_len;\n6329:\t\n6330:\t\terr = btf_parse_str_sec(env);\n6331:\t\tif (err)\n6332:\t\t\tgoto errout;\n6333:\t\n6334:\t\terr = btf_parse_layout_sec(env);\n6335:\t\tif (err)\n6336:\t\t\tgoto errout;\n6337:\t\n6338:\t\terr = btf_parse_type_sec(env);\n6339:\t\tif (err)\n6340:\t\t\tgoto errout;\n6341:\t\n6342:\t\terr = btf_check_modifier_chain_length(env, btf, 1);\n6343:\t\tif (err)\n6344:\t\t\tgoto errout;\n6345:\t\n6346:\t\tstruct_meta_tab = btf_parse_struct_metas(\u0026env-\u003elog, btf);\n6347:\t\tif (IS_ERR(struct_meta_tab)) {\n6348:\t\t\terr = PTR_ERR(struct_meta_tab);\n6349:\t\t\tgoto errout;\n6350:\t\t}\n6351:\t\tbtf-\u003estruct_meta_tab = struct_meta_tab;\n6352:\t\n6353:\t\tif (struct_meta_tab) {\n6354:\t\t\tint i;\n6355:\t\n6356:\t\t\tfor (i = 0; i \u003c struct_meta_tab-\u003ecnt; i++) {\n6357:\t\t\t\terr = btf_check_and_fixup_fields(btf, struct_meta_tab-\u003etypes[i].record);\n6358:\t\t\t\tif (err \u003c 0)\n6359:\t\t\t\t\tgoto errout_meta;\n"
}

47/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36983
							output: 38
							thoughts: 116
						

Thoughts:
**My Analysis of BTF Loading and Retrieval**

Okay, so I'm tracing this BTF loading process. It looks like user space initiates the whole thing by using `bpf(BPF_BTF_LOAD, ...)` to send BTF data. That makes sense. The kernel then allocates memory with `kvmalloc(...)` to hold the data, and `copy_from_bpfptr(data, btf_data, attr->btf_size)` handles the actual copy from the user-space buffer, `btf_data`, into this kernel-side buffer, `data`. Standard stuff, but I need to make sure I understand the complete picture.

Now, my key question is, *how* is the BTF information actually pulled back out from the kernel for a user-space inspection? Like when you use something like `BPF_OBJ_GET_INFO_BY_FD` to inspect an eBPF object. I need to understand this part. I need to know how user space gets it. I'll search for `bpf_btf_get_info_by_fd` in the source code to see how it's handled. That should be the right place to start looking.



48/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "bpf_btf_get_info_by_fd",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/syscall.c=5389=static int bpf_map_get_info_by_fd(struct file *file,\n--\nkernel/bpf/syscall.c-5459-\nkernel/bpf/syscall.c:5460:static int bpf_btf_get_info_by_fd(struct file *file,\nkernel/bpf/syscall.c-5461-\t\t\t\t  struct btf *btf,\n--\nkernel/bpf/syscall.c=5535=static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-5551-\telse if (fd_file(f)-\u003ef_op == \u0026btf_fops)\nkernel/bpf/syscall.c:5552:\t\treturn bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)-\u003eprivate_data, attr, uattr);\nkernel/bpf/syscall.c-5553-\telse if (fd_file(f)-\u003ef_op == \u0026bpf_link_fops || fd_file(f)-\u003ef_op == \u0026bpf_link_fops_poll)\n"
}

49/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37710
							output: 37
							thoughts: 30
						

Thoughts:
Here's my summary, as though I'm reading and thinking about the code:

**Diving into `bpf_btf_get_info_by_fd`**

Okay, time to dissect `bpf_btf_get_info_by_fd` within `kernel/bpf/syscall.c`. Let's see what's going on here. I'm already anticipating this will be a critical part of the BTF (BPF Type Format) introspection mechanism. This function is likely the gateway for user-space programs to access and interrogate BTF data associated with a BPF object, identified by its file descriptor. I need to understand how it handles file descriptor validation, any necessary security checks, the extraction of the BTF information itself, and how that information is then presented back to the calling user-space program. I expect to see nuances in how it deals with different BTF versions, potential error scenarios, and memory management. Hopefully, the code is reasonably well-commented because I'll need to rapidly grasp the architecture to understand where to modify it for whatever project I'm working on. Let's see if this function lives up to its name.



50/3 2026/09/17 18:50 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 5460,
  "LineCount": 75
}

Results:
{
  "Contents": "5460:\tstatic int bpf_btf_get_info_by_fd(struct file *file,\n5461:\t\t\t\t\t  struct btf *btf,\n5462:\t\t\t\t\t  const union bpf_attr *attr,\n5463:\t\t\t\t\t  union bpf_attr __user *uattr)\n5464:\t{\n5465:\t\tstruct bpf_btf_info __user *uinfo = u64_to_user_ptr(attr-\u003einfo.info);\n5466:\t\tu32 info_len = attr-\u003einfo.info_len;\n5467:\t\tint err;\n5468:\t\n5469:\t\terr = bpf_check_uarg_tail_zero(USER_BPFPTR(uinfo), sizeof(*uinfo), info_len);\n5470:\t\tif (err)\n5471:\t\t\treturn err;\n5472:\t\n5473:\t\treturn btf_get_info_by_fd(btf, attr, uattr);\n5474:\t}\n5475:\t\n5476:\tstatic int bpf_link_get_info_by_fd(struct file *file,\n5477:\t\t\t\t\t  struct bpf_link *link,\n5478:\t\t\t\t\t  const union bpf_attr *attr,\n5479:\t\t\t\t\t  union bpf_attr __user *uattr)\n5480:\t{\n5481:\t\tstruct bpf_link_info __user *uinfo = u64_to_user_ptr(attr-\u003einfo.info);\n5482:\t\tstruct bpf_link_info info;\n5483:\t\tconst struct bpf_prog *prog;\n5484:\t\tu32 info_len = attr-\u003einfo.info_len;\n5485:\t\tint err;\n5486:\t\n5487:\t\terr = bpf_check_uarg_tail_zero(USER_BPFPTR(uinfo), sizeof(info), info_len);\n5488:\t\tif (err)\n5489:\t\t\treturn err;\n5490:\t\tinfo_len = min_t(u32, sizeof(info), info_len);\n5491:\t\n5492:\t\tmemset(\u0026info, 0, sizeof(info));\n5493:\t\tif (copy_from_user(\u0026info, uinfo, info_len))\n5494:\t\t\treturn -EFAULT;\n5495:\t\n5496:\t\tinfo.type = link-\u003etype;\n5497:\t\tinfo.id = link-\u003eid;\n5498:\t\n5499:\t\trcu_read_lock();\n5500:\t\tprog = READ_ONCE(link-\u003eprog);\n5501:\t\tif (prog)\n5502:\t\t\tinfo.prog_id = prog-\u003eaux-\u003eid;\n5503:\t\trcu_read_unlock();\n5504:\t\n5505:\t\tif (link-\u003eops-\u003efill_link_info) {\n5506:\t\t\terr = link-\u003eops-\u003efill_link_info(link, \u0026info);\n5507:\t\t\tif (err)\n5508:\t\t\t\treturn err;\n5509:\t\t}\n5510:\t\n5511:\t\tif (copy_to_user(uinfo, \u0026info, info_len) ||\n5512:\t\t    put_user(info_len, \u0026uattr-\u003einfo.info_len))\n5513:\t\t\treturn -EFAULT;\n5514:\t\n5515:\t\treturn 0;\n5516:\t}\n5517:\t\n5518:\tstatic int token_get_info_by_fd(struct file *file,\n5519:\t\t\t\t\tstruct bpf_token *token,\n5520:\t\t\t\t\tconst union bpf_attr *attr,\n5521:\t\t\t\t\tunion bpf_attr __user *uattr)\n5522:\t{\n5523:\t\tstruct bpf_token_info __user *uinfo = u64_to_user_ptr(attr-\u003einfo.info);\n5524:\t\tu32 info_len = attr-\u003einfo.info_len;\n5525:\t\tint err;\n5526:\t\n5527:\t\terr = bpf_check_uarg_tail_zero(USER_BPFPTR(uinfo), sizeof(*uinfo), info_len);\n5528:\t\tif (err)\n5529:\t\t\treturn err;\n5530:\t\treturn bpf_token_get_info_by_fd(token, attr, uattr);\n5531:\t}\n5532:\t\n5533:\t#define BPF_OBJ_GET_INFO_BY_FD_LAST_FIELD info.info\n5534:\t\n"
}

51/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39251
							output: 35
							thoughts: 28
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm deeply familiar with BPF and the kernel:

**Examining btf_get_info_by_fd**

Right, let's dive into `btf_get_info_by_fd` within `kernel/bpf/btf.c`. I need to understand how we're retrieving BTF information from a file descriptor. I'm likely interested in how this function facilitates the interaction between BPF programs and the BTF data they depend on. Specifically, I want to understand: how is the file descriptor validated, what data is extracted from the FD, how is this data parsed or interpreted, and how are potential errors handled? Are there any optimizations in place for frequent lookups? Are there implications for security or resource management related to that FD? This function probably serves a crucial role in enabling BPF programs to introspect and leverage type information, so I'll want to grasp its mechanics thoroughly. I suspect this will be the heart of how the BPF system loads and uses BTF data.



52/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "btf_get_info_by_fd",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/btf.c=8774=struct btf *btf_get_by_fd(int fd)\n--\nkernel/bpf/btf.c-8785-\nkernel/bpf/btf.c:8786:int btf_get_info_by_fd(const struct btf *btf,\nkernel/bpf/btf.c-8787-\t\t       const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c=5389=static int bpf_map_get_info_by_fd(struct file *file,\n--\nkernel/bpf/syscall.c-5459-\nkernel/bpf/syscall.c:5460:static int bpf_btf_get_info_by_fd(struct file *file,\nkernel/bpf/syscall.c-5461-\t\t\t\t  struct btf *btf,\n--\nkernel/bpf/syscall.c-5472-\nkernel/bpf/syscall.c:5473:\treturn btf_get_info_by_fd(btf, attr, uattr);\nkernel/bpf/syscall.c-5474-}\n--\nkernel/bpf/syscall.c=5535=static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-5551-\telse if (fd_file(f)-\u003ef_op == \u0026btf_fops)\nkernel/bpf/syscall.c:5552:\t\treturn bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)-\u003eprivate_data, attr, uattr);\nkernel/bpf/syscall.c-5553-\telse if (fd_file(f)-\u003ef_op == \u0026bpf_link_fops || fd_file(f)-\u003ef_op == \u0026bpf_link_fops_poll)\n"
}

53/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40038
							output: 38
							thoughts: 28
						

Thoughts:
Here's my take on those thoughts, assuming I'm deep in kernel internals:

**Diving into BTF Info Retrieval**

Alright, time to crack open `kernel/bpf/btf.c`. Specifically, I want to refresh my memory on how `btf_get_info_by_fd` works. I'm guessing I'll be revisiting how it handles the file descriptor and then parses the BTF data. I'm keen to see if I can get a clearer picture of any recent changes in how we look up and provide BTF information, potentially to trace a bug report. There’s always the chance I can glean some optimization ideas in passing. Let's see how efficiently it handles the different error conditions and if there are any obvious bottlenecks related to the file system operations. Time to get my hands dirty.



54/3 2026/09/17 18:50 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 8786,
  "LineCount": 55
}

Results:
{
  "Contents": "8786:\tint btf_get_info_by_fd(const struct btf *btf,\n8787:\t\t\t       const union bpf_attr *attr,\n8788:\t\t\t       union bpf_attr __user *uattr)\n8789:\t{\n8790:\t\tstruct bpf_btf_info __user *uinfo;\n8791:\t\tstruct bpf_btf_info info;\n8792:\t\tu32 info_copy, btf_copy;\n8793:\t\tvoid __user *ubtf;\n8794:\t\tchar __user *uname;\n8795:\t\tu32 uinfo_len, uname_len, name_len;\n8796:\t\tint ret = 0;\n8797:\t\n8798:\t\tuinfo = u64_to_user_ptr(attr-\u003einfo.info);\n8799:\t\tuinfo_len = attr-\u003einfo.info_len;\n8800:\t\n8801:\t\tinfo_copy = min_t(u32, uinfo_len, sizeof(info));\n8802:\t\tmemset(\u0026info, 0, sizeof(info));\n8803:\t\tif (copy_from_user(\u0026info, uinfo, info_copy))\n8804:\t\t\treturn -EFAULT;\n8805:\t\n8806:\t\tinfo.id = READ_ONCE(btf-\u003eid);\n8807:\t\tubtf = u64_to_user_ptr(info.btf);\n8808:\t\tbtf_copy = min_t(u32, btf-\u003edata_size, info.btf_size);\n8809:\t\tif (copy_to_user(ubtf, btf-\u003edata, btf_copy))\n8810:\t\t\treturn -EFAULT;\n8811:\t\tinfo.btf_size = btf-\u003edata_size;\n8812:\t\n8813:\t\tinfo.kernel_btf = btf-\u003ekernel_btf;\n8814:\t\n8815:\t\tuname = u64_to_user_ptr(info.name);\n8816:\t\tuname_len = info.name_len;\n8817:\t\tif (!uname ^ !uname_len)\n8818:\t\t\treturn -EINVAL;\n8819:\t\n8820:\t\tname_len = strlen(btf-\u003ename);\n8821:\t\tinfo.name_len = name_len;\n8822:\t\n8823:\t\tif (uname) {\n8824:\t\t\tif (uname_len \u003e= name_len + 1) {\n8825:\t\t\t\tif (copy_to_user(uname, btf-\u003ename, name_len + 1))\n8826:\t\t\t\t\treturn -EFAULT;\n8827:\t\t\t} else {\n8828:\t\t\t\tchar zero = '\\0';\n8829:\t\n8830:\t\t\t\tif (copy_to_user(uname, btf-\u003ename, uname_len - 1))\n8831:\t\t\t\t\treturn -EFAULT;\n8832:\t\t\t\tif (put_user(zero, uname + uname_len - 1))\n8833:\t\t\t\t\treturn -EFAULT;\n8834:\t\t\t\t/* let user-space know about too short buffer */\n8835:\t\t\t\tret = -ENOSPC;\n8836:\t\t\t}\n8837:\t\t}\n8838:\t\n8839:\t\tif (copy_to_user(uinfo, \u0026info, info_copy) ||\n8840:\t\t    put_user(info_copy, \u0026uattr-\u003einfo.info_len))\n"
}

55/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41217
							output: 38
							thoughts: 652
						

Thoughts:
**Analyzing `btf_loc_param_check_meta` for Vulnerabilities**

Alright, let's break this down. `btf_get_info_by_fd` just copies the BTF data back to the user, after it's been copied from user space or loaded from the kernel/module. The `info` struct is zeroed out. Now, let's dive into the kernel/bpf/btf.c file and see what's new.

Specifically, I'm focusing on `btf_loc_param_check_meta`. The logic seems straightforward, but I need to make sure I don't miss something. I see that `meta_needed` is calculated as `sizeof(*p) + sizeof(__u32) * vlen`. I immediately hone in on the potential for an overflow or an uninitialized memory read here. Could `sizeof(__u32) * vlen` overflow? Let's see... `vlen` is determined by `btf_vlen(t)`, which is essentially the lower 16 bits of `t->info`—`t->info & 0xffff`. That's a 16-bit number, so the maximum value is 65535. Now, 65535 multiplied by 4 (size of `__u32`) equals 262140. Okay, that won't overflow a 32-bit `meta_needed`. Good. The check of `meta_left` also seems reasonable. The pointer `p` is calculated as `(struct btf_loc_param *)(t + 1)`.

Now, I'm curious about the derivation of `meta_left`. Where is that coming from? I need to look at `btf_parse_type_sec` to see how it's computed. I need the full context to feel confident.



56/3 2026/09/17 18:50 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 5870,
  "LineCount": 70
}

Results:
{
  "Contents": "5870:\t}\n5871:\t\n5872:\tstatic int btf_parse_type_sec(struct btf_verifier_env *env)\n5873:\t{\n5874:\t\tconst struct btf_header *hdr = \u0026env-\u003ebtf-\u003ehdr;\n5875:\t\tint err;\n5876:\t\n5877:\t\t/* Type section must align to 4 bytes */\n5878:\t\tif (hdr-\u003etype_off \u0026 (sizeof(u32) - 1)) {\n5879:\t\t\tbtf_verifier_log(env, \"Unaligned type_off\");\n5880:\t\t\treturn -EINVAL;\n5881:\t\t}\n5882:\t\n5883:\t\tif (!env-\u003ebtf-\u003ebase_btf \u0026\u0026 !hdr-\u003etype_len) {\n5884:\t\t\tbtf_verifier_log(env, \"No type found\");\n5885:\t\t\treturn -EINVAL;\n5886:\t\t}\n5887:\t\n5888:\t\terr = btf_check_all_metas(env);\n5889:\t\tif (err)\n5890:\t\t\treturn err;\n5891:\t\n5892:\t\treturn btf_check_all_types(env);\n5893:\t}\n5894:\t\n5895:\tstatic int btf_parse_str_sec(struct btf_verifier_env *env)\n5896:\t{\n5897:\t\tconst struct btf_header *hdr;\n5898:\t\tstruct btf *btf = env-\u003ebtf;\n5899:\t\tconst char *start, *end;\n5900:\t\n5901:\t\thdr = \u0026btf-\u003ehdr;\n5902:\t\tstart = btf-\u003enohdr_data + hdr-\u003estr_off;\n5903:\t\tend = start + hdr-\u003estr_len;\n5904:\t\n5905:\t\tif (hdr-\u003ehdr_len \u003c sizeof(struct btf_header) \u0026\u0026\n5906:\t\t    end != btf-\u003edata + btf-\u003edata_size) {\n5907:\t\t\tbtf_verifier_log(env, \"String section is not at the end\");\n5908:\t\t\treturn -EINVAL;\n5909:\t\t}\n5910:\t\n5911:\t\tbtf-\u003estrings = start;\n5912:\t\n5913:\t\tif (btf-\u003ebase_btf \u0026\u0026 !hdr-\u003estr_len)\n5914:\t\t\treturn 0;\n5915:\t\tif (!hdr-\u003estr_len || hdr-\u003estr_len - 1 \u003e BTF_MAX_NAME_OFFSET || end[-1]) {\n5916:\t\t\tbtf_verifier_log(env, \"Invalid string section\");\n5917:\t\t\treturn -EINVAL;\n5918:\t\t}\n5919:\t\tif (!btf-\u003ebase_btf \u0026\u0026 start[0]) {\n5920:\t\t\tbtf_verifier_log(env, \"Invalid string section\");\n5921:\t\t\treturn -EINVAL;\n5922:\t\t}\n5923:\t\n5924:\t\treturn 0;\n5925:\t}\n5926:\t\n5927:\tstatic int btf_parse_layout_sec(struct btf_verifier_env *env)\n5928:\t{\n5929:\t\tconst struct btf_header *hdr = \u0026env-\u003ebtf-\u003ehdr;\n5930:\t\tstruct btf *btf = env-\u003ebtf;\n5931:\t\tvoid *start, *end;\n5932:\t\n5933:\t\tif (hdr-\u003ehdr_len \u003c sizeof(struct btf_header) ||\n5934:\t\t    hdr-\u003elayout_len == 0)\n5935:\t\t\treturn 0;\n5936:\t\n5937:\t\t/* Layout section must align to 4 bytes */\n5938:\t\tif (hdr-\u003elayout_off \u0026 (sizeof(u32) - 1)) {\n5939:\t\t\tbtf_verifier_log(env, \"Unaligned layout_off\");\n"
}

57/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43387
							output: 38
							thoughts: 39
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Diving into BTF Metadata Validation**

Right, so I need to check something in the kernel's BTF handling. Let's start with `kernel/bpf/btf.c`. Specifically, I'm going to focus on lines 5800 through 5870 because that's usually where they do the BTF metadata checks, namely `btf_check_all_metas`. This suggests they're likely validating the type information itself for consistency and integrity within the BTF section. I'm guessing I'll find the logic for things like checking the sizes, offsets, and types against known constraints, and for ensuring that the metadata accurately reflects the underlying data structures. I'll need to pay close attention to the error handling within that section, and how they report any inconsistencies. Probably I will find there the calls to the helpers responsible to do the actual verification. Let's hope the code is well-commented; this section can be tricky, depending on what the issue ends up being.



58/3 2026/09/17 18:50 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 5800,
  "LineCount": 70
}

Results:
{
  "Contents": "5800:\t\t}\n5801:\t\n5802:\t\treturn false;\n5803:\t}\n5804:\t\n5805:\tstatic int btf_resolve(struct btf_verifier_env *env,\n5806:\t\t\t       const struct btf_type *t, u32 type_id)\n5807:\t{\n5808:\t\tu32 save_log_type_id = env-\u003elog_type_id;\n5809:\t\tconst struct resolve_vertex *v;\n5810:\t\tint err = 0;\n5811:\t\n5812:\t\tenv-\u003eresolve_mode = RESOLVE_TBD;\n5813:\t\tenv_stack_push(env, t, type_id);\n5814:\t\twhile (!err \u0026\u0026 (v = env_stack_peak(env))) {\n5815:\t\t\tenv-\u003elog_type_id = v-\u003etype_id;\n5816:\t\t\terr = btf_type_ops(v-\u003et)-\u003eresolve(env, v);\n5817:\t\t}\n5818:\t\n5819:\t\tenv-\u003elog_type_id = type_id;\n5820:\t\tif (err == -E2BIG) {\n5821:\t\t\tbtf_verifier_log_type(env, t,\n5822:\t\t\t\t\t      \"Exceeded max resolving depth:%u\",\n5823:\t\t\t\t\t      MAX_RESOLVE_DEPTH);\n5824:\t\t} else if (err == -EEXIST) {\n5825:\t\t\tbtf_verifier_log_type(env, t, \"Loop detected\");\n5826:\t\t}\n5827:\t\n5828:\t\t/* Final sanity check */\n5829:\t\tif (!err \u0026\u0026 !btf_resolve_valid(env, t, type_id)) {\n5830:\t\t\tbtf_verifier_log_type(env, t, \"Invalid resolve state\");\n5831:\t\t\terr = -EINVAL;\n5832:\t\t}\n5833:\t\n5834:\t\tenv-\u003elog_type_id = save_log_type_id;\n5835:\t\treturn err;\n5836:\t}\n5837:\t\n5838:\tstatic int btf_check_all_types(struct btf_verifier_env *env)\n5839:\t{\n5840:\t\tstruct btf *btf = env-\u003ebtf;\n5841:\t\tconst struct btf_type *t;\n5842:\t\tu32 type_id, i;\n5843:\t\tint err;\n5844:\t\n5845:\t\terr = env_resolve_init(env);\n5846:\t\tif (err)\n5847:\t\t\treturn err;\n5848:\t\n5849:\t\tenv-\u003ephase++;\n5850:\t\tfor (i = btf-\u003ebase_btf ? 0 : 1; i \u003c btf-\u003enr_types; i++) {\n5851:\t\t\ttype_id = btf-\u003estart_id + i;\n5852:\t\t\tt = btf_type_by_id(btf, type_id);\n5853:\t\n5854:\t\t\tenv-\u003elog_type_id = type_id;\n5855:\t\t\tif (btf_type_needs_resolve(t) \u0026\u0026\n5856:\t\t\t    !env_type_is_resolved(env, type_id)) {\n5857:\t\t\t\terr = btf_resolve(env, t, type_id);\n5858:\t\t\t\tif (err)\n5859:\t\t\t\t\treturn err;\n5860:\t\t\t}\n5861:\t\n5862:\t\t\tif (btf_type_is_func_proto(t)) {\n5863:\t\t\t\terr = btf_func_proto_check(env, t);\n5864:\t\t\t\tif (err)\n5865:\t\t\t\t\treturn err;\n5866:\t\t\t}\n5867:\t\t}\n5868:\t\n5869:\t\treturn 0;\n"
}

59/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44755
							output: 39
							thoughts: 28
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Analyzing `btf_check_all_metas` (Lines 5700-5800)**

Okay, time to dive into that specific function. I need to take a look at `btf_check_all_metas` – lines 5700 to 5800 should be the relevant section. I’m expecting this to be where the core validation of the BTF metadata occurs, probably iterating through the defined types and performing checks on their consistency and coherence. It's likely checking for things like valid offsets within structures, correct sizes, and potentially cross-references between different BTF type definitions. I imagine there are several levels of checks, perhaps starting with simple structural sanity and then moving into deeper semantic analysis, depending on the BPF program's intended usage of BTF. I'll be looking specifically for how it handles different BTF type kinds, and how it deals with potential errors or inconsistencies that could lead to runtime issues when the BPF program is loaded and executed. Specifically, how it handles things like recursive data structures and any optimizations to improve performance. I need to understand the logic flow, the error handling, and the overall strategy for ensuring BTF metadata integrity.



60/3 2026/09/17 18:50 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 5700,
  "LineCount": 100
}

Results:
{
  "Contents": "5700:\tstatic s32 btf_check_meta(struct btf_verifier_env *env,\n5701:\t\t\t\t  const struct btf_type *t,\n5702:\t\t\t\t  u32 meta_left)\n5703:\t{\n5704:\t\tu32 saved_meta_left = meta_left;\n5705:\t\ts32 var_meta_size;\n5706:\t\n5707:\t\tif (meta_left \u003c sizeof(*t)) {\n5708:\t\t\tbtf_verifier_log(env, \"[%u] meta_left:%u meta_needed:%zu\",\n5709:\t\t\t\t\t env-\u003elog_type_id, meta_left, sizeof(*t));\n5710:\t\t\treturn -EINVAL;\n5711:\t\t}\n5712:\t\tmeta_left -= sizeof(*t);\n5713:\t\n5714:\t\tif (BTF_INFO_KIND(t-\u003einfo) \u003e BTF_KIND_MAX ||\n5715:\t\t    BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_UNKN) {\n5716:\t\t\tbtf_verifier_log(env, \"[%u] Invalid kind:%u\",\n5717:\t\t\t\t\t env-\u003elog_type_id, BTF_INFO_KIND(t-\u003einfo));\n5718:\t\t\treturn -EINVAL;\n5719:\t\t}\n5720:\t\n5721:\t\tif (!btf_name_offset_valid(env-\u003ebtf, t-\u003ename_off)) {\n5722:\t\t\tbtf_verifier_log(env, \"[%u] Invalid name_offset:%u\",\n5723:\t\t\t\t\t env-\u003elog_type_id, t-\u003ename_off);\n5724:\t\t\treturn -EINVAL;\n5725:\t\t}\n5726:\t\n5727:\t\tvar_meta_size = btf_type_ops(t)-\u003echeck_meta(env, t, meta_left);\n5728:\t\tif (var_meta_size \u003c 0)\n5729:\t\t\treturn var_meta_size;\n5730:\t\n5731:\t\tmeta_left -= var_meta_size;\n5732:\t\n5733:\t\treturn saved_meta_left - meta_left;\n5734:\t}\n5735:\t\n5736:\tstatic int btf_check_all_metas(struct btf_verifier_env *env)\n5737:\t{\n5738:\t\tstruct btf *btf = env-\u003ebtf;\n5739:\t\tstruct btf_header *hdr;\n5740:\t\tvoid *cur, *end;\n5741:\t\n5742:\t\thdr = \u0026btf-\u003ehdr;\n5743:\t\tcur = btf-\u003enohdr_data + hdr-\u003etype_off;\n5744:\t\tend = cur + hdr-\u003etype_len;\n5745:\t\n5746:\t\tenv-\u003elog_type_id = btf-\u003ebase_btf ? btf-\u003estart_id : 1;\n5747:\t\twhile (cur \u003c end) {\n5748:\t\t\tstruct btf_type *t = cur;\n5749:\t\t\ts32 meta_size;\n5750:\t\n5751:\t\t\tmeta_size = btf_check_meta(env, t, end - cur);\n5752:\t\t\tif (meta_size \u003c 0)\n5753:\t\t\t\treturn meta_size;\n5754:\t\n5755:\t\t\tbtf_add_type(env, t);\n5756:\t\t\tcur += meta_size;\n5757:\t\t\tenv-\u003elog_type_id++;\n5758:\t\t}\n5759:\t\n5760:\t\treturn 0;\n5761:\t}\n5762:\t\n5763:\tstatic bool btf_resolve_valid(struct btf_verifier_env *env,\n5764:\t\t\t\t      const struct btf_type *t,\n5765:\t\t\t\t      u32 type_id)\n5766:\t{\n5767:\t\tstruct btf *btf = env-\u003ebtf;\n5768:\t\n5769:\t\tif (!env_type_is_resolved(env, type_id))\n5770:\t\t\treturn false;\n5771:\t\n5772:\t\tif (btf_type_is_struct(t) || btf_type_is_datasec(t) ||\n5773:\t\t    btf_type_is_loc_proto(t) || btf_type_is_locsec(t))\n5774:\t\t\treturn !btf_resolved_type_id(btf, type_id) \u0026\u0026\n5775:\t\t\t       !btf_resolved_type_size(btf, type_id);\n5776:\t\n5777:\t\tif (btf_type_is_decl_tag(t) || btf_type_is_func(t))\n5778:\t\t\treturn btf_resolved_type_id(btf, type_id) \u0026\u0026\n5779:\t\t\t       !btf_resolved_type_size(btf, type_id);\n5780:\t\n5781:\t\tif (btf_type_is_modifier(t) || btf_type_is_ptr(t) ||\n5782:\t\t    btf_type_is_var(t)) {\n5783:\t\t\tt = btf_type_id_resolve(btf, \u0026type_id);\n5784:\t\t\treturn t \u0026\u0026\n5785:\t\t\t       !btf_type_is_modifier(t) \u0026\u0026\n5786:\t\t\t       !btf_type_is_var(t) \u0026\u0026\n5787:\t\t\t       !btf_type_is_datasec(t);\n5788:\t\t}\n5789:\t\n5790:\t\tif (btf_type_is_array(t)) {\n5791:\t\t\tconst struct btf_array *array = btf_type_array(t);\n5792:\t\t\tconst struct btf_type *elem_type;\n5793:\t\t\tu32 elem_type_id = array-\u003etype;\n5794:\t\t\tu32 elem_size;\n5795:\t\n5796:\t\t\telem_type = btf_type_id_size(btf, \u0026elem_type_id, \u0026elem_size);\n5797:\t\t\treturn elem_type \u0026\u0026 !btf_type_is_modifier(elem_type) \u0026\u0026\n5798:\t\t\t\t(array-\u003enelems * elem_size ==\n5799:\t\t\t\t btf_resolved_type_size(btf, type_id));\n"
}

61/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46819
							output: 35
							thoughts: 763
						

Thoughts:
**Analyzing the btf.c Code: Locating Parameter Meta Data Verification**

Okay, let's dive into these new functions added in `btf.c`, specifically the `check_meta` and `resolve` functions. I'm focusing on how they handle metadata verification for the local parameter type.

First, I examine `btf_loc_param_check_meta`. It seems pretty straightforward: it calculates how much metadata is needed based on `btf_vlen(t)` and the size of `btf_loc_param` itself. Then, it checks if enough metadata is actually *available* (`meta_left`). Any issue there and it returns `-EINVAL`, logging the details for debugging. It also validates a few other things: it rejects the type if `name_off` is set, likely because it shouldn't have a name. It also makes sure `t->size` falls within some constraints (between 1 and 16 bytes, and a power of 2, it would seem). It also enforces that no kind flags are set.

*Hang on a sec.* I'm missing something, in the logic for `btf_loc_param_check_meta` it reads `size = t->size;` - but isn't there something about checking the `p->flags` or `p->values`? Is that missing from here?

Moving on, `btf_loc_param_log` just dumps out some information for debugging, namely the size, vlen, and the flags of the local parameter.

Then, there's `loc_param_ops`. It defines the operations for the local parameter kind and looks fine - but there's this `btf_df_resolve` function. I don't immediately recognize it and the code doesn't explain much. So, my next step is to grep for it. Gotta see what that function *actually does*.



62/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "btf_df_resolve",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=2265=static int btf_generic_check_kflag_member(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-2283-\nkernel/bpf/btf.c:2284:static int btf_df_resolve(struct btf_verifier_env *env,\nkernel/bpf/btf.c-2285-\t\t\t  const struct resolve_vertex *v)\n--\nkernel/bpf/btf.c=2647=static const struct btf_kind_operations int_ops = {\nkernel/bpf/btf.c-2648-\t.check_meta = btf_int_check_meta,\nkernel/bpf/btf.c:2649:\t.resolve = btf_df_resolve,\nkernel/bpf/btf.c-2650-\t.check_member = btf_int_check_member,\n--\nkernel/bpf/btf.c=3036=static const struct btf_kind_operations fwd_ops = {\nkernel/bpf/btf.c-3037-\t.check_meta = btf_fwd_check_meta,\nkernel/bpf/btf.c:3038:\t.resolve = btf_df_resolve,\nkernel/bpf/btf.c-3039-\t.check_member = btf_df_check_member,\n--\nkernel/bpf/btf.c=4641=static const struct btf_kind_operations enum_ops = {\nkernel/bpf/btf.c-4642-\t.check_meta = btf_enum_check_meta,\nkernel/bpf/btf.c:4643:\t.resolve = btf_df_resolve,\nkernel/bpf/btf.c-4644-\t.check_member = btf_enum_check_member,\n--\nkernel/bpf/btf.c=4744=static const struct btf_kind_operations enum64_ops = {\nkernel/bpf/btf.c-4745-\t.check_meta = btf_enum64_check_meta,\nkernel/bpf/btf.c:4746:\t.resolve = btf_df_resolve,\nkernel/bpf/btf.c-4747-\t.check_member = btf_enum_check_member,\n--\nkernel/bpf/btf.c=4799=static const struct btf_kind_operations loc_param_ops = {\nkernel/bpf/btf.c-4800-\t.check_meta = btf_loc_param_check_meta,\nkernel/bpf/btf.c:4801:\t.resolve = btf_df_resolve,\nkernel/bpf/btf.c-4802-\t.check_member = btf_df_check_member,\n--\nkernel/bpf/btf.c=5095=static const struct btf_kind_operations func_proto_ops = {\nkernel/bpf/btf.c-5096-\t.check_meta = btf_func_proto_check_meta,\nkernel/bpf/btf.c:5097:\t.resolve = btf_df_resolve,\nkernel/bpf/btf.c-5098-\t/*\n--\nkernel/bpf/btf.c=5444=static const struct btf_kind_operations float_ops = {\nkernel/bpf/btf.c-5445-\t.check_meta = btf_float_check_meta,\nkernel/bpf/btf.c:5446:\t.resolve = btf_df_resolve,\nkernel/bpf/btf.c-5447-\t.check_member = btf_float_check_member,\n"
}

63/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49004
							output: 36
							thoughts: 241
						

Thoughts:
**Analyzing BTF Type Resolution**

Okay, let's break this down. It seems like `btf_df_resolve` is the default resolver, and by design, it just returns -EINVAL if it's called. But I'm seeing that `btf_type_needs_resolve` is false for `LOC_PARAM` types. Intriguing. It looks like it's a special case we aren't handling correctly.

Now, what's this `btf_type_nosize` function? I don't recall seeing it explicitly before, so I'll need to double check that I know what it means. Let me look at the code:

```c
static bool btf_type_nosize(const struct btf_type *t)
{
	return btf_type_is_void(t) || btf_type_is_fwd(t) ||
	       btf_type_is_func(t) || btf_type_is_func_proto(t) ||
	       btf_type_is_decl_tag(t) || btf_type_is_loc_param(t) ||
	       btf_type_is_loc_proto(t) || btf_type_is_locsec(t);
}
```

Okay, so it identifies types that don't have a size associated with them - void, forward declarations, functions, function prototypes, declaration tags, local parameters, local function prototypes, and local sections. That makes sense.

But wait! I'm still not quite grasping the context. Where is `btf_type_nosize` actually used? I should run a quick `grep` for `btf_type_nosize` in the codebase to understand its interactions. That'll give me a clearer picture.



64/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "btf_type_nosize",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=533=static bool btf_type_is_locsec(const struct btf_type *t)\n--\nkernel/bpf/btf.c-537-\nkernel/bpf/btf.c:538:static bool btf_type_nosize(const struct btf_type *t)\nkernel/bpf/btf.c-539-{\n--\nkernel/bpf/btf.c-545-\nkernel/bpf/btf.c:546:static bool btf_type_nosize_or_null(const struct btf_type *t)\nkernel/bpf/btf.c-547-{\nkernel/bpf/btf.c:548:\treturn !t || btf_type_nosize(t);\nkernel/bpf/btf.c-549-}\n--\nkernel/bpf/btf.c=2199=const struct btf_type *btf_type_id_size(const struct btf *btf,\n--\nkernel/bpf/btf.c-2206-\tsize_type = btf_type_by_id(btf, size_type_id);\nkernel/bpf/btf.c:2207:\tif (btf_type_nosize_or_null(size_type))\nkernel/bpf/btf.c-2208-\t\treturn NULL;\n--\nkernel/bpf/btf.c-2222-\t\tsize_type = btf_type_by_id(btf, size_type_id);\nkernel/bpf/btf.c:2223:\t\tif (btf_type_nosize_or_null(size_type))\nkernel/bpf/btf.c-2224-\t\t\treturn NULL;\n--\nkernel/bpf/btf.c=3127=static int btf_array_resolve(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-3138-\tindex_type = btf_type_by_id(btf, index_type_id);\nkernel/bpf/btf.c:3139:\tif (btf_type_nosize_or_null(index_type) ||\nkernel/bpf/btf.c-3140-\t    btf_type_is_resolve_source_only(index_type)) {\n--\nkernel/bpf/btf.c-3158-\telem_type = btf_type_by_id(btf, elem_type_id);\nkernel/bpf/btf.c:3159:\tif (btf_type_nosize_or_null(elem_type) ||\nkernel/bpf/btf.c-3160-\t    btf_type_is_resolve_source_only(elem_type)) {\n--\nkernel/bpf/btf.c=3402=static int btf_struct_resolve(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-3442-\nkernel/bpf/btf.c:3443:\t\tif (btf_type_nosize_or_null(member_type) ||\nkernel/bpf/btf.c-3444-\t\t    btf_type_is_resolve_source_only(member_type)) {\n"
}

65/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50534
							output: 38
							thoughts: 2381
						

Thoughts:
**Analyzing BTF Type Resolution for LOC_PROTO and LOCSEC**

Okay, so I'm diving into how the BTF verifier handles `LOC_PROTO` and `LOCSEC` types, specifically focusing on how they are resolved and validated. The initial assumption about `btf_type_nosize` not being suitable for arrays or structs makes perfect sense; `LOC_PARAM`, `LOC_PROTO`, and `LOCSEC` aren't data types meant for that.

Now, let's dissect the code. With `btf_loc_proto_resolve` and `btf_locsec_resolve`, the first step is always checking if there is enough metadata. For `LOC_PROTO`, that involves verifying if `meta_left` (remaining buffer space) is sufficient to store `vlen` (variable length) number of `__u32` type IDs. The documentation explicitly states that a `btf_type` of type `btf_loc_proto` is followed by a variable-length array of `__u32` type IDs.

In the `btf_loc_proto_resolve` function, the check `t->type` seems to be used to ensure that the given type is not a forward declaration, before iterating over the variable-length array of parameter type IDs. Each ID is looked up and needs to be a valid `LOC_PARAM` type.

Moving on to `btf_locsec`, the `check_meta` function's role is similar, it checks for sufficient `meta_left` for storing `vlen` number of `btf_loc` structs, where each `btf_loc` contains information about a section and a location. The code also validates the name offset and `kind_flag`. Iterating over the locs in `btf_locsec_check_meta` ensures that `func` and `loc_proto` are valid, and `BTF_TYPE_ID_VALID` checks are performed.

Now, the interesting part is the `btf_locsec_resolve` function, and here's where the resolve stack comes into play. I need to understand how the resolution process unfolds: The code iterates through each `btf_loc`. For each `loc`, it checks if `func_type` is resolved using `env_type_is_resolved`. If not, it pushes `func_type` onto the stack using `env_stack_push`. This also calls `env_stack_set_next_member`, but I am still not completely sure about the meaning of `next_member`, and if it's the index `i` or index `i + 1`. This would mean it needs to go back to the previous function after `func_type` is resolved and then check the `loc_proto_type`. If `loc_proto_type` is not resolved, it's also pushed onto the stack. When both the `func_type` and `loc_proto_type` are resolved, the verifier knows it has successfully resolved everything related to a `btf_loc`. Then, the verifier pops resolved data from the stack, and it repeats the same process for other `btf_loc` until the end of the `btf_locsec`. I'll need to check the other resolve functions such as `btf_datasec_resolve` or `btf_struct_resolve` to understand how `env_stack_set_next_member` is used in a broader context to see if I can get a clearer understanding of what `next_member` actually represents in the stack.



66/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "env_stack_set_next_member",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=2024=static int env_stack_push(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-2053-\nkernel/bpf/btf.c:2054:static void env_stack_set_next_member(struct btf_verifier_env *env,\nkernel/bpf/btf.c-2055-\t\t\t\t      u32 next_member)\n--\nkernel/bpf/btf.c=3402=static int btf_struct_resolve(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-3451-\t\t    !env_type_is_resolved(env, member_type_id)) {\nkernel/bpf/btf.c:3452:\t\t\tenv_stack_set_next_member(env, i + 1);\nkernel/bpf/btf.c-3453-\t\t\treturn env_stack_push(env, member_type, member_type_id);\n--\nkernel/bpf/btf.c=4967=static int btf_locsec_resolve(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-4994-\t\tif (!env_type_is_resolved(env, func_type_id)) {\nkernel/bpf/btf.c:4995:\t\t\tenv_stack_set_next_member(env, i);\nkernel/bpf/btf.c-4996-\t\t\treturn env_stack_push(env, func_type, func_type_id);\n--\nkernel/bpf/btf.c-5006-\t\tif (!env_type_is_resolved(env, loc_proto_type_id)) {\nkernel/bpf/btf.c:5007:\t\t\tenv_stack_set_next_member(env, i + 1);\nkernel/bpf/btf.c-5008-\t\t\treturn env_stack_push(env, loc_proto_type,\n--\nkernel/bpf/btf.c=5299=static int btf_datasec_resolve(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-5318-\t\t    !env_type_is_resolved(env, var_type_id)) {\nkernel/bpf/btf.c:5319:\t\t\tenv_stack_set_next_member(env, i + 1);\nkernel/bpf/btf.c-5320-\t\t\treturn env_stack_push(env, var_type, var_type_id);\n"
}

67/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54389
							output: 34
							thoughts: 209
						

Thoughts:
**My Analysis of the BTF Resolver Logic**

Okay, so here's how I'm understanding this resolver's control flow. It's essentially managing a stack for resolving dependencies within BTF members. When a `func_type` needs resolution, we mark the current member index `i` with `next_member`. Once `func_type` is resolved and popped from the stack, we resume the `btf_locsec_resolve` function precisely at that saved member index `i`. At this point, `func_type` is guaranteed to be resolved, and we move on to checking `loc_proto_type`. If *that* requires resolution, `next_member` is incremented to `i + 1`, `loc_proto_type` is pushed, and the process repeats. This is all standard logic for handling multiple recursive references in a BTF member.

My primary focus here, and what I really need to drill down into, is what resolution *actually* entails. It's not just about retrieving some data; it's about validating types, checking their existence, and then recording them correctly on the resolve stack. A central concern is always around memory safety: are we reading or writing uninitialized memory during this process?

Therefore, I need to confirm that `btf_verifier_env` has no undefined behavior. I need to investigate the allocations and initializations. Everything inside `btf_verifier_env` is supposedly handled with `kzalloc_obj` or initialized, but I need to confirm this assumption. To do this, I will turn my attention to `env_resolve_init` and scrutinize the function.



68/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "env_resolve_init",
  "PathPrefix": "kernel/bpf/btf.c"
}

Results:
{
  "Output": "kernel/bpf/btf.c=1940=void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)\n--\nkernel/bpf/btf.c-1946-\nkernel/bpf/btf.c:1947:static int env_resolve_init(struct btf_verifier_env *env)\nkernel/bpf/btf.c-1948-{\n--\nkernel/bpf/btf.c=5838=static int btf_check_all_types(struct btf_verifier_env *env)\n--\nkernel/bpf/btf.c-5844-\nkernel/bpf/btf.c:5845:\terr = env_resolve_init(env);\nkernel/bpf/btf.c-5846-\tif (err)\n"
}

69/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55209
							output: 39
							thoughts: 80
						

Thoughts:
Okay, let's get down to brass tacks.

**Digging Deeper into BTF Kind Handling**

Alright, I've got a good grasp on the initial changes, but I need to make sure we've covered all the bases. My primary concern now is ensuring we haven't introduced any subtle bugs or oversights with these new BTF kinds. The critical questions are: what's the broader impact within the kernel? Are there any other areas within the kernel that actively leverage or depend on the old set of BTF kinds where these new ones haven't been accounted for? I need to meticulously verify that any code that makes decisions based on BTF kind or iterates through BTF types is correctly handling these additions. A comprehensive search is the only way to be sure. My next step is to cast a wide net, looking for instances of `BTF_KIND_MAX` and `NR_BTF_KINDS` in the kernel source. Those are the key indicators of potential issues if they are not updated.



70/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "(NR_BTF_KINDS|BTF_KIND_MAX)",
  "PathPrefix": "kernel/"
}

Results:
{
  "Output": "kernel/bpf/btf.c=316=struct btf_verifier_env {\n--\nkernel/bpf/btf.c-326-\nkernel/bpf/btf.c:327:static const char * const btf_kind_str[NR_BTF_KINDS] = {\nkernel/bpf/btf.c-328-\t[BTF_KIND_UNKN]\t\t= \"UNKNOWN\",\n--\nkernel/bpf/btf.c=449=struct btf_kind_operations {\n--\nkernel/bpf/btf.c-469-\nkernel/bpf/btf.c:470:static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS];\nkernel/bpf/btf.c-471-static struct btf_type btf_void;\n--\nkernel/bpf/btf.c=5647=static int btf_func_check(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-5674-\nkernel/bpf/btf.c:5675:static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {\nkernel/bpf/btf.c-5676-\t[BTF_KIND_INT] = \u0026int_ops,\n--\nkernel/bpf/btf.c=5700=static s32 btf_check_meta(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-5713-\nkernel/bpf/btf.c:5714:\tif (BTF_INFO_KIND(t-\u003einfo) \u003e BTF_KIND_MAX ||\nkernel/bpf/btf.c-5715-\t    BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_UNKN) {\n"
}

71/3 2026/09/17 18:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 56036
							output: 28
							thoughts: 26
						

Thoughts:
Here's my thought process, as if I were considering this myself:

**Investigating BTF Kind Handling in the Kernel**

Okay, so I want to get a broader understanding of how BTF kinds are managed throughout the kernel. My initial instinct is to perform a comprehensive search. I'll need to look across the entire kernel source tree, and I figure the most direct way to get started is to use a specific identifier. The keyword I'm looking for is `BTF_KIND_`. That should be a unique enough prefix to narrow down my results and give me a good overview of the relevant code locations. I'm expecting this search to reveal all the places where different BTF kinds are defined, checked, and processed. This should allow me to formulate a mental map of how this entire system works.



72/3 2026/09/17 18:50 tool grepper
0m Args:
{
  "Expression": "BTF_KIND_",
  "PathPrefix": "kernel/"
}

Results:
{
  "Output": "kernel/bpf/arraymap.c=581=static int array_map_check_btf(struct bpf_map *map,\n--\nkernel/bpf/arraymap.c-592-\nkernel/bpf/arraymap.c:593:\t\tif (BTF_INFO_KIND(value_type-\u003einfo) != BTF_KIND_DATASEC)\nkernel/bpf/arraymap.c-594-\t\t\treturn -EINVAL;\n--\nkernel/bpf/bpf_struct_ops.c=173=static int prepare_arg_info(struct btf *btf,\n--\nkernel/bpf/bpf_struct_ops.c-199-\nkernel/bpf/bpf_struct_ops.c:200:\tstub_func_id = btf_find_by_name_kind(btf, stub_fname, BTF_KIND_FUNC);\nkernel/bpf/bpf_struct_ops.c-201-\tif (stub_func_id \u003c 0) {\n--\nkernel/bpf/bpf_struct_ops.c=358=int bpf_struct_ops_desc_init(struct bpf_struct_ops_desc *st_ops_desc,\n--\nkernel/bpf/bpf_struct_ops.c-384-\ttype_id = btf_find_by_name_kind(btf, st_ops-\u003ename,\nkernel/bpf/bpf_struct_ops.c:385:\t\t\t\t\tBTF_KIND_STRUCT);\nkernel/bpf/bpf_struct_ops.c-386-\tif (type_id \u003c 0) {\n--\nkernel/bpf/bpf_struct_ops.c-398-\tvalue_id = btf_find_by_name_kind(btf, value_name,\nkernel/bpf/bpf_struct_ops.c:399:\t\t\t\t\t BTF_KIND_STRUCT);\nkernel/bpf/bpf_struct_ops.c-400-\tif (value_id \u003c 0) {\n--\nkernel/bpf/btf.c-91- *   - [?] is the type_id of the btf_type object.\nkernel/bpf/btf.c:92: *   - CONST/PTR is the BTF_KIND_XXX\nkernel/bpf/btf.c-93- *   - \"(anon)\" is the name of the type.  It just\n--\nkernel/bpf/btf.c-158- *\nkernel/bpf/btf.c:159: * When resolving a BTF_KIND_STRUCT, we need to resolve all its\nkernel/bpf/btf.c-160- * members because a member is always referring to another\nkernel/bpf/btf.c-161- * type.  A struct's member can be treated as \"RESOLVED\" if\nkernel/bpf/btf.c:162: * it is referring to a BTF_KIND_PTR.  Otherwise, the\nkernel/bpf/btf.c-163- * following valid C struct would be rejected:\n--\nkernel/bpf/btf.c-169- *\nkernel/bpf/btf.c:170: * When resolving a BTF_KIND_PTR, it needs to keep resolving if\nkernel/bpf/btf.c:171: * it is referring to another BTF_KIND_PTR.  Otherwise, we cannot\nkernel/bpf/btf.c-172- * detect a pointer loop, e.g.:\nkernel/bpf/btf.c:173: * BTF_KIND_CONST -\u003e BTF_KIND_PTR -\u003e BTF_KIND_CONST -\u003e BTF_KIND_PTR +\nkernel/bpf/btf.c-174- *                        ^                                         |\n--\nkernel/bpf/btf.c=327=static const char * const btf_kind_str[NR_BTF_KINDS] = {\nkernel/bpf/btf.c:328:\t[BTF_KIND_UNKN]\t\t= \"UNKNOWN\",\nkernel/bpf/btf.c:329:\t[BTF_KIND_INT]\t\t= \"INT\",\nkernel/bpf/btf.c:330:\t[BTF_KIND_PTR]\t\t= \"PTR\",\nkernel/bpf/btf.c:331:\t[BTF_KIND_ARRAY]\t= \"ARRAY\",\nkernel/bpf/btf.c:332:\t[BTF_KIND_STRUCT]\t= \"STRUCT\",\nkernel/bpf/btf.c:333:\t[BTF_KIND_UNION]\t= \"UNION\",\nkernel/bpf/btf.c:334:\t[BTF_KIND_ENUM]\t\t= \"ENUM\",\nkernel/bpf/btf.c:335:\t[BTF_KIND_FWD]\t\t= \"FWD\",\nkernel/bpf/btf.c:336:\t[BTF_KIND_TYPEDEF]\t= \"TYPEDEF\",\nkernel/bpf/btf.c:337:\t[BTF_KIND_VOLATILE]\t= \"VOLATILE\",\nkernel/bpf/btf.c:338:\t[BTF_KIND_CONST]\t= \"CONST\",\nkernel/bpf/btf.c:339:\t[BTF_KIND_RESTRICT]\t= \"RESTRICT\",\nkernel/bpf/btf.c:340:\t[BTF_KIND_FUNC]\t\t= \"FUNC\",\nkernel/bpf/btf.c:341:\t[BTF_KIND_FUNC_PROTO]\t= \"FUNC_PROTO\",\nkernel/bpf/btf.c:342:\t[BTF_KIND_VAR]\t\t= \"VAR\",\nkernel/bpf/btf.c:343:\t[BTF_KIND_DATASEC]\t= \"DATASEC\",\nkernel/bpf/btf.c:344:\t[BTF_KIND_FLOAT]\t= \"FLOAT\",\nkernel/bpf/btf.c:345:\t[BTF_KIND_DECL_TAG]\t= \"DECL_TAG\",\nkernel/bpf/btf.c:346:\t[BTF_KIND_TYPE_TAG]\t= \"TYPE_TAG\",\nkernel/bpf/btf.c:347:\t[BTF_KIND_ENUM64]\t= \"ENUM64\",\nkernel/bpf/btf.c:348:\t[BTF_KIND_LOC_PARAM]\t= \"LOC_PARAM\",\nkernel/bpf/btf.c:349:\t[BTF_KIND_LOC_PROTO]\t= \"LOC_PROTO\",\nkernel/bpf/btf.c:350:\t[BTF_KIND_LOCSEC]\t= \"LOCSEC\",\nkernel/bpf/btf.c-351-};\n--\nkernel/bpf/btf.c=479=static bool btf_type_is_modifier(const struct btf_type *t)\n--\nkernel/bpf/btf.c-491-\tswitch (BTF_INFO_KIND(t-\u003einfo)) {\nkernel/bpf/btf.c:492:\tcase BTF_KIND_TYPEDEF:\nkernel/bpf/btf.c:493:\tcase BTF_KIND_VOLATILE:\nkernel/bpf/btf.c:494:\tcase BTF_KIND_CONST:\nkernel/bpf/btf.c:495:\tcase BTF_KIND_RESTRICT:\nkernel/bpf/btf.c:496:\tcase BTF_KIND_TYPE_TAG:\nkernel/bpf/btf.c-497-\t\treturn true;\n--\nkernel/bpf/btf.c=513=static bool btf_type_is_datasec(const struct btf_type *t)\nkernel/bpf/btf.c-514-{\nkernel/bpf/btf.c:515:\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_DATASEC;\nkernel/bpf/btf.c-516-}\n--\nkernel/bpf/btf.c=518=static bool btf_type_is_decl_tag(const struct btf_type *t)\nkernel/bpf/btf.c-519-{\nkernel/bpf/btf.c:520:\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_DECL_TAG;\nkernel/bpf/btf.c-521-}\n--\nkernel/bpf/btf.c=523=static bool btf_type_is_loc_param(const struct btf_type *t)\nkernel/bpf/btf.c-524-{\nkernel/bpf/btf.c:525:\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_LOC_PARAM;\nkernel/bpf/btf.c-526-}\n--\nkernel/bpf/btf.c=528=static bool btf_type_is_loc_proto(const struct btf_type *t)\nkernel/bpf/btf.c-529-{\nkernel/bpf/btf.c:530:\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_LOC_PROTO;\nkernel/bpf/btf.c-531-}\n--\nkernel/bpf/btf.c=533=static bool btf_type_is_locsec(const struct btf_type *t)\nkernel/bpf/btf.c-534-{\nkernel/bpf/btf.c:535:\treturn BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_LOCSEC;\nkernel/bpf/btf.c-536-}\n--\nkernel/bpf/btf.c=824=static bool btf_type_has_size(const struct btf_type *t)\n--\nkernel/bpf/btf.c-826-\tswitch (BTF_INFO_KIND(t-\u003einfo)) {\nkernel/bpf/btf.c:827:\tcase BTF_KIND_INT:\nkernel/bpf/btf.c:828:\tcase BTF_KIND_STRUCT:\nkernel/bpf/btf.c:829:\tcase BTF_KIND_UNION:\nkernel/bpf/btf.c:830:\tcase BTF_KIND_ENUM:\nkernel/bpf/btf.c:831:\tcase BTF_KIND_DATASEC:\nkernel/bpf/btf.c:832:\tcase BTF_KIND_FLOAT:\nkernel/bpf/btf.c:833:\tcase BTF_KIND_ENUM64:\nkernel/bpf/btf.c-834-\t\treturn true;\n--\nkernel/bpf/btf.c=1075=static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf,\n--\nkernel/bpf/btf.c-1080-\twhile (btf_type_is_modifier(t) \u0026\u0026\nkernel/bpf/btf.c:1081:\t       BTF_INFO_KIND(t-\u003einfo) != BTF_KIND_TYPEDEF) {\nkernel/bpf/btf.c-1082-\t\tt = btf_type_by_id(btf, t-\u003etype);\n--\nkernel/bpf/btf.c-1089-\nkernel/bpf/btf.c:1090:#define BTF_KIND_BIT(kind)\t(1ULL \u003c\u003c kind)\nkernel/bpf/btf.c-1091-\n--\nkernel/bpf/btf.c=1098=static const char *btf_show_name(struct btf_show *show)\n--\nkernel/bpf/btf.c-1168-\t\tswitch (BTF_INFO_KIND(t-\u003einfo)) {\nkernel/bpf/btf.c:1169:\t\tcase BTF_KIND_TYPEDEF:\nkernel/bpf/btf.c-1170-\t\t\tif (!name)\n--\nkernel/bpf/btf.c-1172-\t\t\t\t\t\t\t       t-\u003ename_off);\nkernel/bpf/btf.c:1173:\t\t\tkinds |= BTF_KIND_BIT(BTF_KIND_TYPEDEF);\nkernel/bpf/btf.c-1174-\t\t\tid = t-\u003etype;\nkernel/bpf/btf.c-1175-\t\t\tbreak;\nkernel/bpf/btf.c:1176:\t\tcase BTF_KIND_ARRAY:\nkernel/bpf/btf.c:1177:\t\t\tkinds |= BTF_KIND_BIT(BTF_KIND_ARRAY);\nkernel/bpf/btf.c-1178-\t\t\tparens = \"[\";\n--\nkernel/bpf/btf.c-1185-\t\t\tbreak;\nkernel/bpf/btf.c:1186:\t\tcase BTF_KIND_PTR:\nkernel/bpf/btf.c:1187:\t\t\tkinds |= BTF_KIND_BIT(BTF_KIND_PTR);\nkernel/bpf/btf.c-1188-\t\t\tif (ptr_suffix \u003e ptr_suffixes)\n--\nkernel/bpf/btf.c-1207-\tswitch (BTF_INFO_KIND(t-\u003einfo)) {\nkernel/bpf/btf.c:1208:\tcase BTF_KIND_STRUCT:\nkernel/bpf/btf.c:1209:\tcase BTF_KIND_UNION:\nkernel/bpf/btf.c:1210:\t\tprefix = BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_STRUCT ?\nkernel/bpf/btf.c-1211-\t\t\t \"struct\" : \"union\";\nkernel/bpf/btf.c-1212-\t\t/* if it's an array of struct/union, parens is already set */\nkernel/bpf/btf.c:1213:\t\tif (!(kinds \u0026 (BTF_KIND_BIT(BTF_KIND_ARRAY))))\nkernel/bpf/btf.c-1214-\t\t\tparens = \"{\";\nkernel/bpf/btf.c-1215-\t\tbreak;\nkernel/bpf/btf.c:1216:\tcase BTF_KIND_ENUM:\nkernel/bpf/btf.c:1217:\tcase BTF_KIND_ENUM64:\nkernel/bpf/btf.c-1218-\t\tprefix = \"enum\";\n--\nkernel/bpf/btf.c-1224-\t/* pointer does not require parens */\nkernel/bpf/btf.c:1225:\tif (kinds \u0026 BTF_KIND_BIT(BTF_KIND_PTR))\nkernel/bpf/btf.c-1226-\t\tparens = \"\";\nkernel/bpf/btf.c-1227-\t/* typedef does not require struct/union/enum prefix */\nkernel/bpf/btf.c:1228:\tif (kinds \u0026 BTF_KIND_BIT(BTF_KIND_TYPEDEF))\nkernel/bpf/btf.c-1229-\t\tprefix = \"\";\n--\nkernel/bpf/btf.c=1277=static const char *btf_show_delim(struct btf_show *show)\n--\nkernel/bpf/btf.c-1282-\tif ((show-\u003eflags \u0026 BTF_SHOW_COMPACT) \u0026\u0026 show-\u003estate.type \u0026\u0026\nkernel/bpf/btf.c:1283:\t\tBTF_INFO_KIND(show-\u003estate.type-\u003einfo) == BTF_KIND_UNION)\nkernel/bpf/btf.c-1284-\t\treturn \"|\";\n--\nkernel/bpf/btf.c=2073=static const struct resolve_vertex *env_stack_peak(struct btf_verifier_env *env)\n--\nkernel/bpf/btf.c-2080- * type: is an array (e.g. u32 array[x][y])\nkernel/bpf/btf.c:2081: * return type: type \"u32[x][y]\", i.e. BTF_KIND_ARRAY,\nkernel/bpf/btf.c-2082- * *type_size: (x * y * sizeof(u32)).  Hence, *type_size always\n--\nkernel/bpf/btf.c=2099=__btf_resolve_size(const struct btf *btf, const struct btf_type *type,\n--\nkernel/bpf/btf.c-2109-\t\t/* type-\u003esize can be used */\nkernel/bpf/btf.c:2110:\t\tcase BTF_KIND_INT:\nkernel/bpf/btf.c:2111:\t\tcase BTF_KIND_STRUCT:\nkernel/bpf/btf.c:2112:\t\tcase BTF_KIND_UNION:\nkernel/bpf/btf.c:2113:\t\tcase BTF_KIND_ENUM:\nkernel/bpf/btf.c:2114:\t\tcase BTF_KIND_FLOAT:\nkernel/bpf/btf.c:2115:\t\tcase BTF_KIND_ENUM64:\nkernel/bpf/btf.c-2116-\t\t\tsize = type-\u003esize;\n--\nkernel/bpf/btf.c-2118-\nkernel/bpf/btf.c:2119:\t\tcase BTF_KIND_PTR:\nkernel/bpf/btf.c-2120-\t\t\tsize = sizeof(void *);\n--\nkernel/bpf/btf.c-2123-\t\t/* Modifiers */\nkernel/bpf/btf.c:2124:\t\tcase BTF_KIND_TYPEDEF:\nkernel/bpf/btf.c:2125:\t\tcase BTF_KIND_VOLATILE:\nkernel/bpf/btf.c:2126:\t\tcase BTF_KIND_CONST:\nkernel/bpf/btf.c:2127:\t\tcase BTF_KIND_RESTRICT:\nkernel/bpf/btf.c:2128:\t\tcase BTF_KIND_TYPE_TAG:\nkernel/bpf/btf.c-2129-\t\t\tid = type-\u003etype;\n--\nkernel/bpf/btf.c-2132-\nkernel/bpf/btf.c:2133:\t\tcase BTF_KIND_ARRAY:\nkernel/bpf/btf.c-2134-\t\t\tif (!array_type)\n--\nkernel/bpf/btf.c=2732=static int btf_ref_type_check_meta(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-2755-\t */\nkernel/bpf/btf.c:2756:\tif (BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_TYPEDEF) {\nkernel/bpf/btf.c-2757-\t\tif (!t-\u003ename_off ||\n--\nkernel/bpf/btf.c-2761-\t\t}\nkernel/bpf/btf.c:2762:\t} else if (BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_TYPE_TAG) {\nkernel/bpf/btf.c-2763-\t\tvalue = btf_name_by_offset(env-\u003ebtf, t-\u003ename_off);\n--\nkernel/bpf/btf.c=3321=static s32 btf_struct_check_meta(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-3324-{\nkernel/bpf/btf.c:3325:\tbool is_union = BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_UNION;\nkernel/bpf/btf.c-3326-\tconst struct btf_member *member;\n--\nkernel/bpf/btf.c=3669=btf_find_graph_root(const struct btf *btf, const struct btf_type *pt,\n--\nkernel/bpf/btf.c-3691-\t\treturn -ENOMEM;\nkernel/bpf/btf.c:3692:\tid = btf_find_by_name_kind(btf, value_type, BTF_KIND_STRUCT);\nkernel/bpf/btf.c-3693-\tkfree(value_type);\n--\nkernel/bpf/btf.c=5095=static const struct btf_kind_operations func_proto_ops = {\n--\nkernel/bpf/btf.c-5098-\t/*\nkernel/bpf/btf.c:5099:\t * BTF_KIND_FUNC_PROTO cannot be directly referred by\nkernel/bpf/btf.c-5100-\t * a struct's member.\n--\nkernel/bpf/btf.c-5102-\t * It should be a function pointer instead.\nkernel/bpf/btf.c:5103:\t * (i.e. struct's member -\u003e BTF_KIND_PTR -\u003e BTF_KIND_FUNC_PROTO)\nkernel/bpf/btf.c-5104-\t *\n--\nkernel/bpf/btf.c=5675=static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {\nkernel/bpf/btf.c:5676:\t[BTF_KIND_INT] = \u0026int_ops,\nkernel/bpf/btf.c:5677:\t[BTF_KIND_PTR] = \u0026ptr_ops,\nkernel/bpf/btf.c:5678:\t[BTF_KIND_ARRAY] = \u0026array_ops,\nkernel/bpf/btf.c:5679:\t[BTF_KIND_STRUCT] = \u0026struct_ops,\nkernel/bpf/btf.c:5680:\t[BTF_KIND_UNION] = \u0026struct_ops,\nkernel/bpf/btf.c:5681:\t[BTF_KIND_ENUM] = \u0026enum_ops,\nkernel/bpf/btf.c:5682:\t[BTF_KIND_FWD] = \u0026fwd_ops,\nkernel/bpf/btf.c:5683:\t[BTF_KIND_TYPEDEF] = \u0026modifier_ops,\nkernel/bpf/btf.c:5684:\t[BTF_KIND_VOLATILE] = \u0026modifier_ops,\nkernel/bpf/btf.c:5685:\t[BTF_KIND_CONST] = \u0026modifier_ops,\nkernel/bpf/btf.c:5686:\t[BTF_KIND_RESTRICT] = \u0026modifier_ops,\nkernel/bpf/btf.c:5687:\t[BTF_KIND_FUNC] = \u0026func_ops,\nkernel/bpf/btf.c:5688:\t[BTF_KIND_FUNC_PROTO] = \u0026func_proto_ops,\nkernel/bpf/btf.c:5689:\t[BTF_KIND_VAR] = \u0026var_ops,\nkernel/bpf/btf.c:5690:\t[BTF_KIND_DATASEC] = \u0026datasec_ops,\nkernel/bpf/btf.c:5691:\t[BTF_KIND_FLOAT] = \u0026float_ops,\nkernel/bpf/btf.c:5692:\t[BTF_KIND_DECL_TAG] = \u0026decl_tag_ops,\nkernel/bpf/btf.c:5693:\t[BTF_KIND_TYPE_TAG] = \u0026modifier_ops,\nkernel/bpf/btf.c:5694:\t[BTF_KIND_ENUM64] = \u0026enum64_ops,\nkernel/bpf/btf.c:5695:\t[BTF_KIND_LOC_PARAM] = \u0026loc_param_ops,\nkernel/bpf/btf.c:5696:\t[BTF_KIND_LOC_PROTO] = \u0026loc_proto_ops,\nkernel/bpf/btf.c:5697:\t[BTF_KIND_LOCSEC] = \u0026locsec_ops,\nkernel/bpf/btf.c-5698-};\n--\nkernel/bpf/btf.c=5700=static s32 btf_check_meta(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-5713-\nkernel/bpf/btf.c:5714:\tif (BTF_INFO_KIND(t-\u003einfo) \u003e BTF_KIND_MAX ||\nkernel/bpf/btf.c:5715:\t    BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_UNKN) {\nkernel/bpf/btf.c-5716-\t\tbtf_verifier_log(env, \"[%u] Invalid kind:%u\",\n--\nkernel/bpf/btf.c=6108=btf_parse_struct_metas(struct bpf_verifier_log *log, struct btf *btf)\n--\nkernel/bpf/btf.c-6128-\nkernel/bpf/btf.c:6129:\t\tid = btf_find_by_name_kind(btf, alloc_obj_fields[i], BTF_KIND_STRUCT);\nkernel/bpf/btf.c-6130-\t\tif (id \u003c 0)\n--\nkernel/bpf/btf.c=7442=static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,\n--\nkernel/bpf/btf.c-7462-\tvlen = btf_type_vlen(t);\nkernel/bpf/btf.c:7463:\tif (BTF_INFO_KIND(t-\u003einfo) == BTF_KIND_UNION \u0026\u0026 vlen != 1 \u0026\u0026 !(*flag \u0026 PTR_UNTRUSTED))\nkernel/bpf/btf.c-7464-\t\t/*\n--\nkernel/bpf/btf.c=7893=int btf_distill_func_proto(struct bpf_verifier_log *log,\n--\nkernel/bpf/btf.c-7964-/* Compare BTFs of two functions assuming only scalars and pointers to context.\nkernel/bpf/btf.c:7965: * t1 points to BTF_KIND_FUNC in btf1\nkernel/bpf/btf.c:7966: * t2 points to BTF_KIND_FUNC in btf2\nkernel/bpf/btf.c-7967- * Returns:\n--\nkernel/bpf/inode.c=661=static int find_bpffs_btf_enums(struct bpffs_btf_enums *info)\n--\nkernel/bpf/inode.c-686-\t\tid = btf_find_by_name_kind(btf, btf_enums[i].name,\nkernel/bpf/inode.c:687:\t\t\t\t\t   BTF_KIND_ENUM);\nkernel/bpf/inode.c-688-\t\tif (id \u003c 0)\n--\nkernel/bpf/local_storage.c=368=static int cgroup_storage_check_btf(struct bpf_map *map,\n--\nkernel/bpf/local_storage.c-387-\t\t */\nkernel/bpf/local_storage.c:388:\t\tif (BTF_INFO_KIND(key_type-\u003einfo) != BTF_KIND_STRUCT ||\nkernel/bpf/local_storage.c-389-\t\t    BTF_INFO_VLEN(key_type-\u003einfo) != 2)\n--\nkernel/bpf/lpm_trie.c=754=static int trie_check_btf(struct bpf_map *map,\n--\nkernel/bpf/lpm_trie.c-759-\t/* Keys must have struct bpf_lpm_trie_key_u8 embedded. */\nkernel/bpf/lpm_trie.c:760:\treturn BTF_INFO_KIND(key_type-\u003einfo) != BTF_KIND_STRUCT ?\nkernel/bpf/lpm_trie.c-761-\t       -EINVAL : 0;\n--\nkernel/bpf/verifier.c=2460=static int bpf_find_exception_callback_insn_off(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-2490-\nkernel/bpf/verifier.c:2491:\tret = btf_find_by_name_kind(btf, name, BTF_KIND_FUNC);\nkernel/bpf/verifier.c-2492-\tif (ret \u003c 0) {\n--\nkernel/bpf/verifier.c=2756=static const struct btf_type *find_kfunc_impl_proto(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-2771-\nkernel/bpf/verifier.c:2772:\timpl_id = btf_find_by_name_kind(btf, buf, BTF_KIND_FUNC);\nkernel/bpf/verifier.c-2773-\tif (impl_id \u003c= 0) {\n--\nkernel/bpf/verifier.c=18908=static int find_btf_percpu_datasec(struct btf *btf)\n--\nkernel/bpf/verifier.c-18921-\t\tt = btf_type_by_id(btf, i);\nkernel/bpf/verifier.c:18922:\t\tif (BTF_INFO_KIND(t-\u003einfo) != BTF_KIND_DATASEC)\nkernel/bpf/verifier.c-18923-\t\t\tcontinue;\n--\nkernel/bpf/verifier.c=20399=int bpf_check_attach_target(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-20594-\t\tif (fname)\nkernel/bpf/verifier.c:20595:\t\t\tret = btf_find_by_name_kind(btf, fname, BTF_KIND_FUNC);\nkernel/bpf/verifier.c-20596-\n--\nkernel/trace/trace_btf.c=13=const struct btf_type *btf_find_func_proto(const char *func_name, struct btf **btf_p)\n--\nkernel/trace/trace_btf.c-17-\nkernel/trace/trace_btf.c:18:\tid = bpf_find_btf_id(func_name, BTF_KIND_FUNC, btf_p);\nkernel/trace/trace_btf.c-19-\tif (id \u003c 0)\n--\nkernel/trace/trace_btf.c-21-\nkernel/trace/trace_btf.c:22:\t/* Get BTF_KIND_FUNC type */\nkernel/trace/trace_btf.c-23-\tt = btf_type_by_id(*btf_p, id);\n--\nkernel/trace/trace_btf.c-26-\nkernel/trace/trace_btf.c:27:\t/* The type of BTF_KIND_FUNC is BTF_KIND_FUNC_PROTO */\nkernel/trace/trace_btf.c-28-\tt = btf_type_by_id(*btf_p, t-\u003etype);\n--\nkernel/trace/trace_output.c=721=void print_function_args(struct trace_seq *s, unsigned long *args,\n--\nkernel/trace/trace_output.c-767-\nkernel/trace/trace_output.c:768:\t\tswitch (t ? BTF_INFO_KIND(t-\u003einfo) : BTF_KIND_UNKN) {\nkernel/trace/trace_output.c:769:\t\tcase BTF_KIND_UNKN:\nkernel/trace/trace_output.c-770-\t\t\ttrace_seq_putc(s, '?');\n--\nkernel/trace/trace_output.c-772-\t\t\tfallthrough;\nkernel/trace/trace_output.c:773:\t\tcase BTF_KIND_PTR:\nkernel/trace/trace_output.c-774-\t\t\ttrace_seq_printf(s, \"0x%lx\", arg);\nkernel/trace/trace_output.c-775-\t\t\tbreak;\nkernel/trace/trace_output.c:776:\t\tcase BTF_KIND_INT:\nkernel/trace/trace_output.c-777-\t\t\tencode = btf_int_encoding(t);\n--\nkernel/trace/trace_output.c-783-\t\t\tbreak;\nkernel/trace/trace_output.c:784:\t\tcase BTF_KIND_ENUM:\nkernel/trace/trace_output.c-785-\t\t\ttrace_seq_printf(s, \"%ld\", arg);\n--\nkernel/trace/trace_probe.c=409=static bool btf_type_is_char_ptr(struct btf *btf, const struct btf_type *type)\n--\nkernel/trace/trace_probe.c-417-\nkernel/trace/trace_probe.c:418:\tif (BTF_INFO_KIND(real_type-\u003einfo) != BTF_KIND_INT)\nkernel/trace/trace_probe.c-419-\t\treturn false;\n--\nkernel/trace/trace_probe.c=426=static bool btf_type_is_char_array(struct btf *btf, const struct btf_type *type)\n--\nkernel/trace/trace_probe.c-431-\nkernel/trace/trace_probe.c:432:\tif (BTF_INFO_KIND(type-\u003einfo) != BTF_KIND_ARRAY)\nkernel/trace/trace_probe.c-433-\t\treturn false;\n--\nkernel/trace/trace_probe.c=483=static const char *fetch_type_from_btf_type(struct btf *btf,\n--\nkernel/trace/trace_probe.c-490-\tswitch (BTF_INFO_KIND(type-\u003einfo)) {\nkernel/trace/trace_probe.c:491:\tcase BTF_KIND_ENUM:\nkernel/trace/trace_probe.c-492-\t\t/* enum is \"int\", so convert to \"s32\" */\nkernel/trace/trace_probe.c-493-\t\treturn \"s32\";\nkernel/trace/trace_probe.c:494:\tcase BTF_KIND_ENUM64:\nkernel/trace/trace_probe.c-495-\t\treturn \"s64\";\nkernel/trace/trace_probe.c:496:\tcase BTF_KIND_PTR:\nkernel/trace/trace_probe.c-497-\t\t/* pointer will be converted to \"x??\" */\nkernel/trace/trace_probe.c-498-\t\treturn IS_ENABLED(CONFIG_64BIT) ? \"x64\" : \"x32\";\nkernel/trace/trace_probe.c:499:\tcase BTF_KIND_INT:\nkernel/trace/trace_probe.c-500-\t\tintdata = btf_type_int(type);\n--\nkernel/trace/trace_probe.c=685=static int parse_btf_field(char *fieldname, const struct btf_type *type,\n--\nkernel/trace/trace_probe.c-697-\t\t\t/* Outer loop for solving arrow operator ('-\u003e') */\nkernel/trace/trace_probe.c:698:\t\t\tif (BTF_INFO_KIND(type-\u003einfo) != BTF_KIND_PTR) {\nkernel/trace/trace_probe.c-699-\t\t\t\ttrace_probe_log_err(ctx-\u003eoffset, NO_PTR_STRCT);\n--\nkernel/trace/trace_probe.c=736=static int parse_btf_arg(char *varname,\n--\nkernel/trace/trace_probe.c-764-\t\t/* If no typecast is specified for $current, use task_struct by default */\nkernel/trace/trace_probe.c:765:\t\tret = bpf_find_btf_id(\"task_struct\", BTF_KIND_STRUCT, \u0026ctx-\u003estruct_btf);\nkernel/trace/trace_probe.c-766-\t\tif (ret \u003c 0) {\n--\nkernel/trace/trace_probe.c=882=static int query_btf_struct(const char *sname, struct traceprobe_parse_context *ctx)\n--\nkernel/trace/trace_probe.c-892-\nkernel/trace/trace_probe.c:893:\tid = bpf_find_btf_id(sname, BTF_KIND_STRUCT, \u0026btf);\nkernel/trace/trace_probe.c-894-\tif (id \u003c 0)\n"
}

73/3 2026/09/17 18:50 llm kmsan-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65765
							output: 20
							thoughts: 1285
						

Thoughts:
**Analyzing BTF Handling for LOC Types**

Okay, let's break down how the kernel handles BTF (Berkeley Trace Format) types specifically when user space is loading them, focusing on the `BTF_KIND_LOC_PARAM`, `BTF_KIND_LOC_PROTO`, and `BTF_KIND_LOCSEC` kinds. My initial thought process involves tracing the execution through the `btf_parse` function.

First, memory is allocated using `kvmalloc` based on the provided size (`attr->btf_size`), then copied from user space with `copy_from_bpfptr`. This, of course, is a critical step for security and validation. Then, the process dives into the parsing phase: `btf_parse_hdr`, `btf_parse_str_sec`, `btf_parse_layout_sec`, and finally the core, `btf_parse_type_sec`. Within `btf_parse_type_sec`, the code iterates through type checks: `btf_check_all_metas` and `btf_check_all_types`.

In `btf_check_all_metas`, a specific function, `btf_type_ops(t)->check_meta` is called for each type, and within that, checks are performed depending on the specific `BTF_KIND`. For `BTF_KIND_LOC_PARAM`, I see these constraints: the metadata size (`meta_left`) must be reasonable; the name offset (`t->name_off`) must be zero; the size (`t->size`) must be <= 16 and a power of 2; and it cannot be a kernel-specific flag (`!btf_type_kflag(t)`). `BTF_KIND_LOC_PROTO` also imposes similar checks, related to `vlen` (variable length) and, importantly, the name offset being zero and no kernel flags. For `BTF_KIND_LOCSEC`, validation of the metadata size, lack of kernel flags, a valid name, and validation of `loc->func` and `loc->loc_proto` are crucial.

Moving into `btf_check_all_types`, I note that `btf_type_needs_resolve(t)` triggers specific resolutions for `loc_proto` and `locsec` types. `btf_loc_proto_resolve` is called when `btf_type_is_loc_proto(t)` is true, it checks that the type's type is zero and then makes sure the `param_type` is valid and refers to a `loc_param`. Similarly,  `btf_locsec_resolve` verifies the zero type, and checks if the function and the location proto are valid with their corresponding types.

Then there is `btf_resolve_valid`. It appears to be an overall validation that's related to the resolving of types that have not been resolved, such as structs, data sections, and `loc` types.

Now, my thoughts turn to broader usage. Where else in the kernel are these `loc` types actually *used*? I remember seeing them in `include/linux/btf.h` and the inline functions `btf_loc_param`, `btf_loc_proto_params` and `btf_type_loc_secinfo`. I'm also now thinking that `struct btf_field_desc` is likely related, it contains information about member offsets and size within types. The next step is a search to confirm any kernel-wide uses of `btf_field_desc`.



74/3 2026/09/17 18:52 tool grepper
0m Args:
{
  "Expression": "btf_field_desc"
}

Results:
{
  "Output": "include/linux/btf.h=571=enum btf_field_iter_kind {\n--\ninclude/linux/btf.h-575-\ninclude/linux/btf.h:576:struct btf_field_desc {\ninclude/linux/btf.h-577-\t/* once-per-type offsets */\n--\ninclude/linux/btf.h=585=struct btf_field_iter {\ninclude/linux/btf.h:586:\tstruct btf_field_desc desc;\ninclude/linux/btf.h-587-\tvoid *p;\n--\ntools/lib/bpf/btf_iter.c=16=int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n--\ntools/lib/bpf/btf_iter.c-32-\t\tcase BTF_KIND_LOC_PARAM:\ntools/lib/bpf/btf_iter.c:33:\t\t\tit-\u003edesc = (struct btf_field_desc) {};\ntools/lib/bpf/btf_iter.c-34-\t\t\tbreak;\n--\ntools/lib/bpf/btf_iter.c-44-\t\tcase BTF_KIND_TYPE_TAG:\ntools/lib/bpf/btf_iter.c:45:\t\t\tit-\u003edesc = (struct btf_field_desc) { 1, {offsetof(struct btf_type, type)} };\ntools/lib/bpf/btf_iter.c-46-\t\t\tbreak;\ntools/lib/bpf/btf_iter.c-47-\t\tcase BTF_KIND_ARRAY:\ntools/lib/bpf/btf_iter.c:48:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-49-\t\t\t\t2, {sizeof(struct btf_type) + offsetof(struct btf_array, type),\n--\ntools/lib/bpf/btf_iter.c-54-\t\tcase BTF_KIND_UNION:\ntools/lib/bpf/btf_iter.c:55:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-56-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-61-\t\tcase BTF_KIND_FUNC_PROTO:\ntools/lib/bpf/btf_iter.c:62:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-63-\t\t\t\t1, {offsetof(struct btf_type, type)},\n--\ntools/lib/bpf/btf_iter.c-68-\t\tcase BTF_KIND_DATASEC:\ntools/lib/bpf/btf_iter.c:69:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-70-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-75-\t\tcase BTF_KIND_LOC_PROTO:\ntools/lib/bpf/btf_iter.c:76:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-77-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-81-\t\tcase BTF_KIND_LOCSEC:\ntools/lib/bpf/btf_iter.c:82:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-83-\t\t\t\t0, {},\n--\ntools/lib/bpf/btf_iter.c-95-\t\tcase BTF_KIND_UNKN:\ntools/lib/bpf/btf_iter.c:96:\t\t\tit-\u003edesc = (struct btf_field_desc) {};\ntools/lib/bpf/btf_iter.c-97-\t\t\tbreak;\n--\ntools/lib/bpf/btf_iter.c-114-\t\tcase BTF_KIND_LOCSEC:\ntools/lib/bpf/btf_iter.c:115:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-116-\t\t\t\t1, {offsetof(struct btf_type, name_off)}\n--\ntools/lib/bpf/btf_iter.c-119-\t\tcase BTF_KIND_ENUM:\ntools/lib/bpf/btf_iter.c:120:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-121-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/btf_iter.c-126-\t\tcase BTF_KIND_ENUM64:\ntools/lib/bpf/btf_iter.c:127:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-128-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/btf_iter.c-134-\t\tcase BTF_KIND_UNION:\ntools/lib/bpf/btf_iter.c:135:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-136-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/btf_iter.c-141-\t\tcase BTF_KIND_FUNC_PROTO:\ntools/lib/bpf/btf_iter.c:142:\t\t\tit-\u003edesc = (struct btf_field_desc) {\ntools/lib/bpf/btf_iter.c-143-\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n--\ntools/lib/bpf/libbpf_internal.h=572=enum btf_field_iter_kind {\n--\ntools/lib/bpf/libbpf_internal.h-576-\ntools/lib/bpf/libbpf_internal.h:577:struct btf_field_desc {\ntools/lib/bpf/libbpf_internal.h-578-\t/* once-per-type offsets */\n--\ntools/lib/bpf/libbpf_internal.h=586=struct btf_field_iter {\ntools/lib/bpf/libbpf_internal.h:587:\tstruct btf_field_desc desc;\ntools/lib/bpf/libbpf_internal.h-588-\tvoid *p;\n"
}

75/3 2026/09/17 18:52 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 69577
							output: 36
							thoughts: 65
						

Thoughts:
**BTF Field Description Analysis**

Okay, so I'm looking into this `btf_field_desc` structure, defined in `include/linux/btf.h`. The first question that pops into my head, given my familiarity with the kernel and BTF, is *why* it's situated in the `include/linux/btf.h` directory. Logically, it should relate directly to the BTF (BPF Type Format) infrastructure, making it fundamental to describing data structures used in BPF programs.

Right, let's get into the specifics. I'll take a quick scan, specifically lines 555-595 of `include/linux/btf.h`, to refresh my memory of its composition. I need to understand its structure, member by member, and how it is used to describe fields of a particular type.



76/3 2026/09/17 18:52 tool read-file
0m Args:
{
  "File": "include/linux/btf.h",
  "FirstLine": 555,
  "LineCount": 45
}

Results:
{
  "Contents": " 555:\tu32 btf_ctx_arg_idx(struct btf *btf, const struct btf_type *func_proto, int off);\n 556:\t\n 557:\tstruct bpf_verifier_log;\n 558:\t\n 559:\t#if defined(CONFIG_BPF_JIT) \u0026\u0026 defined(CONFIG_BPF_SYSCALL)\n 560:\tstruct bpf_struct_ops;\n 561:\tint __register_bpf_struct_ops(struct bpf_struct_ops *st_ops);\n 562:\tconst struct bpf_struct_ops_desc *bpf_struct_ops_find_value(struct btf *btf, u32 value_id);\n 563:\tconst struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id);\n 564:\t#else\n 565:\tstatic inline const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id)\n 566:\t{\n 567:\t\treturn NULL;\n 568:\t}\n 569:\t#endif\n 570:\t\n 571:\tenum btf_field_iter_kind {\n 572:\t\tBTF_FIELD_ITER_IDS,\n 573:\t\tBTF_FIELD_ITER_STRS,\n 574:\t};\n 575:\t\n 576:\tstruct btf_field_desc {\n 577:\t\t/* once-per-type offsets */\n 578:\t\tint t_off_cnt, t_offs[2];\n 579:\t\t/* member struct size, or zero, if no members */\n 580:\t\tint m_sz;\n 581:\t\t/* repeated per-member offsets */\n 582:\t\tint m_off_cnt, m_offs[2];\n 583:\t};\n 584:\t\n 585:\tstruct btf_field_iter {\n 586:\t\tstruct btf_field_desc desc;\n 587:\t\tvoid *p;\n 588:\t\tint m_idx;\n 589:\t\tint off_idx;\n 590:\t\tint vlen;\n 591:\t};\n 592:\t\n 593:\t#ifdef CONFIG_BPF_SYSCALL\n 594:\tconst struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);\n 595:\tvoid btf_set_base_btf(struct btf *btf, const struct btf *base_btf);\n 596:\tint btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids);\n 597:\tint btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n 598:\t\t\t\tenum btf_field_iter_kind iter_kind);\n 599:\t__u32 *btf_field_iter_next(struct btf_field_iter *it);\n"
}

77/3 2026/09/17 18:52 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 70702
							output: 33
							thoughts: 68
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**BTF Iteration Exploration**

Hold on a second! I need to take a closer look at something in the kernel's BPF implementation. Specifically, I should be examining the functions `btf_relocate`, `btf_field_iter_init`, and `btf_field_iter_next`. These are located within `kernel/bpf/btf.c`. I'm starting to suspect there's something interesting here related to how BTF field information is handled.

Okay, my next step is clear: let's fire up `grep` and search for every instance of `btf_field_iter_init` within the `kernel/bpf/` directory. That should give me a good picture of how and where this iterator is being used. That'll provide useful context for understanding the relocation logic. I'm hoping to understand the relationship between the field iterator and the relocation process.



78/3 2026/09/17 18:52 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "btf_field_iter_init",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "error": "no matches"
}

79/3 2026/09/17 18:52 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 71029
							output: 22
							thoughts: 44
						

Thoughts:
Here's my attempt at summarizing the thought process, as if I were having them:

**Navigating the BTF Codebase**

Okay, hold on a second... I was sure `btf_field_iter_init` was part of the core BTF implementation, specifically in `kernel/bpf/`. But it's not popping up where I expected. That's a little unsettling. Where the heck did they put it? Right, time to dig. Let's fire up the search tools and trace down where the heck `btf_field_iter_init` actually resides in the kernel source. I need to understand the location before I proceed, because I might be using an old source tree. This could be important!



80/3 2026/09/17 18:52 tool grepper
0m Args:
{
  "Expression": "btf_field_iter_init"
}

Results:
{
  "Output": "include/linux/btf.h=596=int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids);\ninclude/linux/btf.h:597:int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\ninclude/linux/btf.h-598-\t\t\tenum btf_field_iter_kind iter_kind);\n--\ninclude/linux/btf.h=646=static inline int btf_relocate(void *log, struct btf *btf, const struct btf *base_btf,\n--\ninclude/linux/btf.h-651-\ninclude/linux/btf.h:652:static inline int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\ninclude/linux/btf.h-653-\t\t\t\t      enum btf_field_iter_kind iter_kind)\n--\ntools/bpf/bpftool/gen.c=2524=static struct btf *btfgen_get_btf(struct btfgen_info *info)\n--\ntools/bpf/bpftool/gen.c-2604-\ntools/bpf/bpftool/gen.c:2605:\t\terr = btf_field_iter_init(\u0026it, btf_type, BTF_FIELD_ITER_IDS);\ntools/bpf/bpftool/gen.c-2606-\t\tif (err)\n--\ntools/lib/bpf/btf.c=2254=static int btf_add_type(struct btf_pipe *p, const struct btf_type *src_type)\n--\ntools/lib/bpf/btf.c-2275-\ntools/lib/bpf/btf.c:2276:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\ntools/lib/bpf/btf.c-2277-\tif (err)\n--\ntools/lib/bpf/btf.c=2299=int btf__add_btf(struct btf *btf, const struct btf *src_btf)\n--\ntools/lib/bpf/btf.c-2361-\t\t/* add, dedup, and remap strings referenced by this BTF type */\ntools/lib/bpf/btf.c:2362:\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\ntools/lib/bpf/btf.c-2363-\t\tif (err)\n--\ntools/lib/bpf/btf.c-2374-\t\t/* remap all type IDs referenced from this BTF type */\ntools/lib/bpf/btf.c:2375:\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf.c-2376-\t\tif (err)\n--\ntools/lib/bpf/btf.c=4403=static int btf_for_each_str_off(struct btf_dedup *d, str_off_visit_fn fn, void *ctx)\n--\ntools/lib/bpf/btf.c-4411-\ntools/lib/bpf/btf.c:4412:\t\tr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\ntools/lib/bpf/btf.c-4413-\t\tif (r)\n--\ntools/lib/bpf/btf.c=6096=static int btf_dedup_remap_types(struct btf_dedup *d)\n--\ntools/lib/bpf/btf.c-6104-\ntools/lib/bpf/btf.c:6105:\t\tr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf.c-6106-\t\tif (r)\n--\ntools/lib/bpf/btf.c=6291=static int btf_add_distilled_type_ids(struct btf_distill *dist, __u32 i)\n--\ntools/lib/bpf/btf.c-6297-\ntools/lib/bpf/btf.c:6298:\terr = btf_field_iter_init(\u0026it, split_t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf.c-6299-\tif (err)\n--\ntools/lib/bpf/btf.c=6458=static int btf_update_distilled_type_ids(struct btf_distill *dist, __u32 i)\n--\ntools/lib/bpf/btf.c-6464-\ntools/lib/bpf/btf.c:6465:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf.c-6466-\tif (err)\n--\ntools/lib/bpf/btf.c=6638=int btf__permute(struct btf *btf, __u32 *id_map, __u32 id_map_cnt,\n--\ntools/lib/bpf/btf.c-6710-\t\t/* fix up referenced IDs for BTF */\ntools/lib/bpf/btf.c:6711:\t\terr = btf_field_iter_init(\u0026it, nt, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf.c-6712-\t\tif (err)\n--\ntools/lib/bpf/btf_iter.c-15-\ntools/lib/bpf/btf_iter.c:16:int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\ntools/lib/bpf/btf_iter.c-17-\t\t\tenum btf_field_iter_kind iter_kind)\n--\ntools/lib/bpf/btf_relocate.c=66=static int btf_relocate_rewrite_type_id(struct btf_relocate *r, __u32 i)\n--\ntools/lib/bpf/btf_relocate.c-72-\ntools/lib/bpf/btf_relocate.c:73:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf_relocate.c-74-\tif (err)\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-141-\ntools/lib/bpf/btf_relocate.c:142:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf_relocate.c-143-\tif (err)\n--\ntools/lib/bpf/btf_relocate.c=412=static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i)\n--\ntools/lib/bpf/btf_relocate.c-418-\ntools/lib/bpf/btf_relocate.c:419:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\ntools/lib/bpf/btf_relocate.c-420-\tif (err)\n--\ntools/lib/bpf/libbpf_internal.h=586=struct btf_field_iter {\n--\ntools/lib/bpf/libbpf_internal.h-593-\ntools/lib/bpf/libbpf_internal.h:594:int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t, enum btf_field_iter_kind iter_kind);\ntools/lib/bpf/libbpf_internal.h-595-__u32 *btf_field_iter_next(struct btf_field_iter *it);\n--\ntools/lib/bpf/linker.c=1086=static int linker_sanity_check_btf(struct src_obj *obj)\n--\ntools/lib/bpf/linker.c-1100-\ntools/lib/bpf/linker.c:1101:\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/linker.c-1102-\t\tif (err)\n--\ntools/lib/bpf/linker.c-1108-\ntools/lib/bpf/linker.c:1109:\t\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\ntools/lib/bpf/linker.c-1110-\t\tif (err)\n--\ntools/lib/bpf/linker.c=2412=static int linker_append_btf(struct bpf_linker *linker, struct src_obj *obj)\n--\ntools/lib/bpf/linker.c-2488-\ntools/lib/bpf/linker.c:2489:\t\terr = btf_field_iter_init(\u0026it, dst_t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/linker.c-2490-\t\tif (err)\n--\ntools/testing/selftests/bpf/prog_tests/btf_field_iter.c=44=void test_btf_field_iter(void)\n--\ntools/testing/selftests/bpf/prog_tests/btf_field_iter.c-160-\t\t\tbreak;\ntools/testing/selftests/bpf/prog_tests/btf_field_iter.c:161:\t\tif (!ASSERT_OK(btf_field_iter_init(\u0026it_strs, t, BTF_FIELD_ITER_STRS),\ntools/testing/selftests/bpf/prog_tests/btf_field_iter.c-162-\t\t\t       \"iter_init_strs\"))\ntools/testing/selftests/bpf/prog_tests/btf_field_iter.c-163-\t\t\tbreak;\ntools/testing/selftests/bpf/prog_tests/btf_field_iter.c:164:\t\tif (!ASSERT_OK(btf_field_iter_init(\u0026it_ids, t, BTF_FIELD_ITER_IDS),\ntools/testing/selftests/bpf/prog_tests/btf_field_iter.c-165-\t\t\t       \"iter_init_ids\"))\n"
}

81/3 2026/09/17 18:52 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 74044
							output: 22
							thoughts: 237
						

Thoughts:
**Investigating the Implementation of `btf_field_iter_init`**

Okay, so I'm looking at `include/linux/btf.h` and I see this stub for `btf_field_iter_init`.  The comment here tells me it's not supported unless `CONFIG_BPF_SYSCALL` is enabled, which makes sense.  But now, the question is, where is this actually *implemented* when that configuration option *is* enabled? I have to figure out where the real definition lives.

Alright, let's fire up a grep across the kernel source. I need to find all instances of `\bbtf_field_iter_init\b` within the `.c` files to locate the full implementation. Let's see what the previous grep query output returns. Okay, it looks like it's defined in `tools/lib/bpf/btf_iter.c`.

Aha, hold on. Is it *only* in the tools directory? My experience tells me that bpf functions often have kernel-side implementations as well as user-space tool implementations. Let's make sure there isn't a kernel-side version of this function. Let's check. I'll need to list all the files in `kernel/bpf/`. Maybe it's called `kernel/bpf/btf_iter.c` or something similar, or perhaps it's in a slightly different location. I need to ensure I've found all possible implementations.



82/3 2026/09/17 18:52 tool codesearch-dir-index
0m Args:
{
  "Dir": "kernel/bpf"
}

Results:
{
  "Files": [
    "arena.c",
    "arraymap.c",
    "backtrack.c",
    "bloom_filter.c",
    "bpf_cgrp_storage.c",
    "bpf_inode_storage.c",
    "bpf_insn_array.c",
    "bpf_iter.c",
    "bpf_local_storage.c",
    "bpf_lru_list.c",
    "bpf_lru_list.h",
    "bpf_lsm.c",
    "bpf_lsm_proto.c",
    "bpf_struct_ops.c",
    "bpf_task_storage.c",
    "btf.c",
    "btf_iter.c",
    "btf_relocate.c",
    "cfg.c",
    "cgroup.c",
    "cgroup_iter.c",
    "check_btf.c",
    "cnum.c",
    "cnum_defs.h",
    "const_fold.c",
    "core.c",
    "cpumap.c",
    "cpumask.c",
    "crypto.c",
    "devmap.c",
    "diagnostics.c",
    "diagnostics.h",
    "disasm.c",
    "disasm.h",
    "dispatcher.c",
    "dmabuf_iter.c",
    "fixups.c",
    "hashtab.c",
    "helpers.c",
    "inode.c",
    "keys.c",
    "kmem_cache_iter.c",
    "link_iter.c",
    "liveness.c",
    "local_storage.c",
    "log.c",
    "lpm_trie.c",
    "map_in_map.c",
    "map_in_map.h",
    "map_iter.c",
    "memalloc.c",
    "mmap_unlock_work.h",
    "mprog.c",
    "net_namespace.c",
    "offload.c",
    "percpu_freelist.c",
    "percpu_freelist.h",
    "prog_iter.c",
    "queue_stack_maps.c",
    "range_tree.c",
    "range_tree.h",
    "relo_core.c",
    "reuseport_array.c",
    "ringbuf.c",
    "rqspinlock.c",
    "rqspinlock.h",
    "stackmap.c",
    "states.c",
    "stream.c",
    "syscall.c",
    "sysfs_btf.c",
    "task_iter.c",
    "tcx.c",
    "tnum.c",
    "token.c",
    "trampoline.c",
    "verifier.c"
  ],
  "Subdirs": [
    "preload"
  ]
}

83/3 2026/09/17 18:52 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 75279
							output: 37
							thoughts: 59
						

Thoughts:
**A Quick Debug Dive**

Okay, so I see `kernel/bpf/btf_iter.c`! Wait a minute... why didn't the grep command I ran pick this up? That's unusual, and definitely worth a quick investigation. Alright, let's just go ahead and examine `kernel/bpf/btf_iter.c` directly and figure out what's happening. Probably something straightforward that I'm overlooking... need to just take a look.



84/3 2026/09/17 18:52 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf_iter.c",
  "FirstLine": 1,
  "LineCount": 80
}

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

85/3 2026/09/17 18:52 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 75540
							output: 38
							thoughts: 71
						

Thoughts:
Here's my summary, as the expert:

**BTF Iteration and Relocation: A Quick Check**

Okay, so I'm diving into the kernel's BPF implementation, specifically focusing on BTF (BPF Type Format) handling. I immediately notice something interesting: `kernel/bpf/btf_iter.c` just does a direct `#include` of a file from the `tools` directory, specifically `../../tools/lib/bpf/btf_iter.c`. That's not *necessarily* bad, but it makes me pause. It's a bit unusual to reach into the toolchain like that in the core kernel. I'd need to consider why they've chosen this approach versus a more traditional build system inclusion.

My immediate next thought is, how is `btf_relocate.c` handled? Let me go take a look at `kernel/bpf/btf_relocate.c` to understand that part of the code. This is likely related, and the connection (or lack thereof) will be important to grasp the overall structure. I want to see how relocation is done within the context of BTF and the interaction between the kernel and the tools. I'm keen to understand if it also uses the include from `tools`.



86/3 2026/09/17 18:52 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf_relocate.c",
  "FirstLine": 1,
  "LineCount": 80
}

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"
}

87/3 2026/09/17 18:52 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 75985
							output: 27
							thoughts: 121
						

Thoughts:
**Kernel BPF File Inclusion Insight**

Okay, so I'm diving into this kernel code, specifically `kernel/bpf/btf_iter.c` and `kernel/bpf/btf_relocate.c`, and something immediately jumps out at me. These files are *literally* `#include`-ing files from `tools/lib/bpf/`! That's a crucial detail. Think about it: any changes I make in `tools/lib/bpf/btf_iter.c`, for instance, will actually affect what compiles into the kernel itself. This is really significant. It means the tools codebase is directly influencing core kernel functionality in this specific area.

Now, I need to understand the full scope of this. I should investigate if this inclusion practice is isolated to those two files or if it's more pervasive within `kernel/bpf/`. Time to grep the `kernel/` directory for any other instances of `#include ".*tools` to check. I need to get a better sense of how widespread this dependency is.



88/3 2026/09/17 18:52 tool grepper
0m Args:
{
  "Expression": "#include \".*tools",
  "PathPrefix": "kernel/"
}

Results:
{
  "Output": "kernel/bpf/btf.c-36-#include \u003cnet/xdp.h\u003e\nkernel/bpf/btf.c:37:#include \"../tools/lib/bpf/relo_core.h\"\nkernel/bpf/btf.c-38-\n--\nkernel/bpf/btf_iter.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/btf_iter.c:2:#include \"../../tools/lib/bpf/btf_iter.c\"\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/bpf/relo_core.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/relo_core.c:2:#include \"../../tools/lib/bpf/relo_core.c\"\n"
}

89/3 2026/09/17 18:52 llm kmsan-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 76643
							output: 40
							thoughts: 878
						

Thoughts:
**Analyzing BTF Iteration in the Kernel and Libbpf**

Okay, so I see that `kernel/bpf/btf_iter.c`, `kernel/bpf/btf_relocate.c`, and `kernel/bpf/relo_core.c` are including files from `tools/lib/bpf`. Right, let's figure out what changed in that userspace library that the kernel is now using.

First, I checked `tools/lib/bpf/btf.c` – that's just libbpf, user space, and not directly included in the kernel. `tools/lib/bpf/btf.h` is just the header file for libbpf, so no surprises there. Similarly, `tools/lib/bpf/btf_dump.c` is userspace only. But hold on... `tools/lib/bpf/btf_iter.c` IS included by `kernel/bpf/btf_iter.c`! Now we're getting somewhere.

Let me carefully review the changes within `tools/lib/bpf/btf_iter.c`. There's also some interesting changes in `include/linux/btf.h` and `tools/lib/bpf/libbpf_internal.h`.  It looks like there's a modification to `struct btf_field_desc`, where `m_offs` array size has been increased from `[1]` to `[2]`.

In `tools/lib/bpf/btf_iter.c` I can see within `btf_field_iter_init` there are new cases for `BTF_KIND_LOC_PARAM`, `BTF_KIND_LOC_PROTO`, and `BTF_KIND_LOCSEC`. Specifically, for the new `BTF_KIND_LOC_PROTO` and `BTF_KIND_LOCSEC` types, a `btf_field_desc` is being initialized with specific member offsets. This suggests a change in how we're iterating through fields, especially related to these new location-specific BTF kinds.  For the `BTF_KIND_LOC_PARAM`, `BTF_KIND_LOC_PROTO`, and `BTF_KIND_LOCSEC` cases, the `btf_field_desc` is populated. These have different settings for `m_sz`, and the offsets array `m_offs`.

I should probably read through `tools/lib/bpf/btf_iter.c` more thoroughly to understand exactly how `btf_field_iter_init` and `btf_field_iter_next` handle these kinds of BTF data.



90/3 2026/09/17 18:53 tool read-file
0m Args:
{
  "File": "tools/lib/bpf/btf_iter.c",
  "FirstLine": 1,
  "LineCount": 100
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\n   2:\t/* Copyright (c) 2021 Facebook */\n   3:\t/* Copyright (c) 2024, Oracle and/or its affiliates. */\n   4:\t\n   5:\t#ifdef __KERNEL__\n   6:\t#include \u003clinux/bpf.h\u003e\n   7:\t#include \u003clinux/btf.h\u003e\n   8:\t\n   9:\t#define btf_var_secinfos(t)\t(struct btf_var_secinfo *)btf_type_var_secinfo(t)\n  10:\t\n  11:\t#else\n  12:\t#include \"btf.h\"\n  13:\t#include \"libbpf_internal.h\"\n  14:\t#endif\n  15:\t\n  16:\tint btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,\n  17:\t\t\t\tenum btf_field_iter_kind iter_kind)\n  18:\t{\n  19:\t\tit-\u003ep = NULL;\n  20:\t\tit-\u003em_idx = -1;\n  21:\t\tit-\u003eoff_idx = 0;\n  22:\t\tit-\u003evlen = 0;\n  23:\t\n  24:\t\tswitch (iter_kind) {\n  25:\t\tcase BTF_FIELD_ITER_IDS:\n  26:\t\t\tswitch (btf_kind(t)) {\n  27:\t\t\tcase BTF_KIND_UNKN:\n  28:\t\t\tcase BTF_KIND_INT:\n  29:\t\t\tcase BTF_KIND_FLOAT:\n  30:\t\t\tcase BTF_KIND_ENUM:\n  31:\t\t\tcase BTF_KIND_ENUM64:\n  32:\t\t\tcase BTF_KIND_LOC_PARAM:\n  33:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {};\n  34:\t\t\t\tbreak;\n  35:\t\t\tcase BTF_KIND_FWD:\n  36:\t\t\tcase BTF_KIND_CONST:\n  37:\t\t\tcase BTF_KIND_VOLATILE:\n  38:\t\t\tcase BTF_KIND_RESTRICT:\n  39:\t\t\tcase BTF_KIND_PTR:\n  40:\t\t\tcase BTF_KIND_TYPEDEF:\n  41:\t\t\tcase BTF_KIND_FUNC:\n  42:\t\t\tcase BTF_KIND_VAR:\n  43:\t\t\tcase BTF_KIND_DECL_TAG:\n  44:\t\t\tcase BTF_KIND_TYPE_TAG:\n  45:\t\t\t\tit-\u003edesc = (struct btf_field_desc) { 1, {offsetof(struct btf_type, type)} };\n  46:\t\t\t\tbreak;\n  47:\t\t\tcase BTF_KIND_ARRAY:\n  48:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n  49:\t\t\t\t\t2, {sizeof(struct btf_type) + offsetof(struct btf_array, type),\n  50:\t\t\t\t\tsizeof(struct btf_type) + offsetof(struct btf_array, index_type)}\n  51:\t\t\t\t};\n  52:\t\t\t\tbreak;\n  53:\t\t\tcase BTF_KIND_STRUCT:\n  54:\t\t\tcase BTF_KIND_UNION:\n  55:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n  56:\t\t\t\t\t0, {},\n  57:\t\t\t\t\tsizeof(struct btf_member),\n  58:\t\t\t\t\t1, {offsetof(struct btf_member, type)}\n  59:\t\t\t\t};\n  60:\t\t\t\tbreak;\n  61:\t\t\tcase BTF_KIND_FUNC_PROTO:\n  62:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n  63:\t\t\t\t\t1, {offsetof(struct btf_type, type)},\n  64:\t\t\t\t\tsizeof(struct btf_param),\n  65:\t\t\t\t\t1, {offsetof(struct btf_param, type)}\n  66:\t\t\t\t};\n  67:\t\t\t\tbreak;\n  68:\t\t\tcase BTF_KIND_DATASEC:\n  69:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n  70:\t\t\t\t\t0, {},\n  71:\t\t\t\t\tsizeof(struct btf_var_secinfo),\n  72:\t\t\t\t\t1, {offsetof(struct btf_var_secinfo, type)}\n  73:\t\t\t\t};\n  74:\t\t\t\tbreak;\n  75:\t\t\tcase BTF_KIND_LOC_PROTO:\n  76:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n  77:\t\t\t\t\t0, {},\n  78:\t\t\t\t\tsizeof(__u32),\n  79:\t\t\t\t\t1, {0}};\n  80:\t\t\t\tbreak;\n  81:\t\t\tcase BTF_KIND_LOCSEC:\n  82:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n  83:\t\t\t\t\t0, {},\n  84:\t\t\t\t\tsizeof(struct btf_loc),\n  85:\t\t\t\t\t2, {offsetof(struct btf_loc, func),\n  86:\t\t\t\t\t    offsetof(struct btf_loc, loc_proto)}};\n  87:\t\t\t\tbreak;\n  88:\t\n  89:\t\t\tdefault:\n  90:\t\t\t\treturn -EINVAL;\n  91:\t\t\t}\n  92:\t\t\tbreak;\n  93:\t\tcase BTF_FIELD_ITER_STRS:\n  94:\t\t\tswitch (btf_kind(t)) {\n  95:\t\t\tcase BTF_KIND_UNKN:\n  96:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {};\n  97:\t\t\t\tbreak;\n  98:\t\t\tcase BTF_KIND_INT:\n  99:\t\t\tcase BTF_KIND_FLOAT:\n 100:\t\t\tcase BTF_KIND_FWD:\n"
}

91/3 2026/09/17 18:53 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 79638
							output: 41
							thoughts: 22
						

Thoughts:
Here's my take on the thoughts, rendered as though they are mine, assuming my expertise:

**Diving into `btf_iter.c`**

Alright, time to dig into the guts of `btf_iter.c` within the BPF tools library. I need to get a clear picture of how this iterator is implemented, because understanding this is crucial for efficient BPF program inspection and manipulation. I'm especially interested in how it handles traversing BTF (BPF Type Format) data structures. I need to refresh my understanding of the data layout and how the iteration logic accounts for the potentially complex nested types. Are they using a stack or recursion, or some other clever approach for handling those nested structures? I need to analyze how they handle errors and edge cases. I hope the code is well-commented and clean; I don't want to spend too much time deciphering cryptic code. Let's see if this iteration implementation is optimized. Any obvious bottlenecks? Time to get reading.



92/3 2026/09/17 18:53 tool read-file
0m Args:
{
  "File": "tools/lib/bpf/btf_iter.c",
  "FirstLine": 101,
  "LineCount": 80
}

Results:
{
  "Contents": " 101:\t\t\tcase BTF_KIND_ARRAY:\n 102:\t\t\tcase BTF_KIND_CONST:\n 103:\t\t\tcase BTF_KIND_VOLATILE:\n 104:\t\t\tcase BTF_KIND_RESTRICT:\n 105:\t\t\tcase BTF_KIND_PTR:\n 106:\t\t\tcase BTF_KIND_TYPEDEF:\n 107:\t\t\tcase BTF_KIND_FUNC:\n 108:\t\t\tcase BTF_KIND_VAR:\n 109:\t\t\tcase BTF_KIND_DECL_TAG:\n 110:\t\t\tcase BTF_KIND_TYPE_TAG:\n 111:\t\t\tcase BTF_KIND_DATASEC:\n 112:\t\t\tcase BTF_KIND_LOC_PARAM:\n 113:\t\t\tcase BTF_KIND_LOC_PROTO:\n 114:\t\t\tcase BTF_KIND_LOCSEC:\n 115:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n 116:\t\t\t\t\t1, {offsetof(struct btf_type, name_off)}\n 117:\t\t\t\t};\n 118:\t\t\t\tbreak;\n 119:\t\t\tcase BTF_KIND_ENUM:\n 120:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n 121:\t\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n 122:\t\t\t\t\tsizeof(struct btf_enum),\n 123:\t\t\t\t\t1, {offsetof(struct btf_enum, name_off)}\n 124:\t\t\t\t};\n 125:\t\t\t\tbreak;\n 126:\t\t\tcase BTF_KIND_ENUM64:\n 127:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n 128:\t\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n 129:\t\t\t\t\tsizeof(struct btf_enum64),\n 130:\t\t\t\t\t1, {offsetof(struct btf_enum64, name_off)}\n 131:\t\t\t\t};\n 132:\t\t\t\tbreak;\n 133:\t\t\tcase BTF_KIND_STRUCT:\n 134:\t\t\tcase BTF_KIND_UNION:\n 135:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n 136:\t\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n 137:\t\t\t\t\tsizeof(struct btf_member),\n 138:\t\t\t\t\t1, {offsetof(struct btf_member, name_off)}\n 139:\t\t\t\t};\n 140:\t\t\t\tbreak;\n 141:\t\t\tcase BTF_KIND_FUNC_PROTO:\n 142:\t\t\t\tit-\u003edesc = (struct btf_field_desc) {\n 143:\t\t\t\t\t1, {offsetof(struct btf_type, name_off)},\n 144:\t\t\t\t\tsizeof(struct btf_param),\n 145:\t\t\t\t\t1, {offsetof(struct btf_param, name_off)}\n 146:\t\t\t\t};\n 147:\t\t\t\tbreak;\n 148:\t\t\tdefault:\n 149:\t\t\t\treturn -EINVAL;\n 150:\t\t\t}\n 151:\t\t\tbreak;\n 152:\t\tdefault:\n 153:\t\t\treturn -EINVAL;\n 154:\t\t}\n 155:\t\n 156:\t\tif (it-\u003edesc.m_sz)\n 157:\t\t\tit-\u003evlen = btf_vlen(t);\n 158:\t\n 159:\t\tit-\u003ep = t;\n 160:\t\treturn 0;\n 161:\t}\n 162:\t\n 163:\t__u32 *btf_field_iter_next(struct btf_field_iter *it)\n 164:\t{\n 165:\t\tif (!it-\u003ep)\n 166:\t\t\treturn NULL;\n 167:\t\n 168:\t\tif (it-\u003em_idx \u003c 0) {\n 169:\t\t\tif (it-\u003eoff_idx \u003c it-\u003edesc.t_off_cnt)\n 170:\t\t\t\treturn it-\u003ep + it-\u003edesc.t_offs[it-\u003eoff_idx++];\n 171:\t\t\t/* move to per-member iteration */\n 172:\t\t\tit-\u003em_idx = 0;\n 173:\t\t\tit-\u003ep += sizeof(struct btf_type);\n 174:\t\t\tit-\u003eoff_idx = 0;\n 175:\t\t}\n 176:\t\n 177:\t\t/* if type doesn't have members, stop */\n 178:\t\tif (it-\u003edesc.m_sz == 0) {\n 179:\t\t\tit-\u003ep = NULL;\n 180:\t\t\treturn NULL;\n"
}

93/3 2026/09/17 18:53 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 81138
							output: 27
							thoughts: 442
						

Thoughts:
**Analyzing the BTF Field Iterator Update**

Okay, let's dive into this BTF field iterator change. I need to understand why they expanded `m_offs` in `struct btf_field_desc` from `[1]` to `[2]`. Looking at `tools/lib/bpf/btf_iter.c`, the structure definition itself is the key:

```c
struct btf_field_desc {
	/* once-per-type offsets */
	int t_off_cnt, t_offs[2];
	/* member struct size, or zero, if no members */
	int m_sz;
	/* repeated per-member offsets */
	int m_off_cnt, m_offs[2];
};
```

Previously, `m_offs` was only an array of size 1. Now it is an array of size 2. The code comment notes that this change is specifically to accommodate `LOCSEC`, which now has two member offsets: `offsetof(struct btf_loc, func)` and `offsetof(struct btf_loc, loc_proto)`. This makes sense; more offsets require more storage.

The `it->desc = (struct btf_field_desc) { ... };` initialization deserves a closer look. Because this is a C designated/compound literal, any fields *not* explicitly mentioned in the initialization are implicitly zeroed.

Now, checking `btf_field_iter_next`:

```c
	while (it->m_idx < it->vlen) {
		if (it->off_idx < it->desc.m_off_cnt)
			return it->p + it->desc.m_offs[it->off_idx++];
		/* move to next member */
		it->m_idx++;
		it->p += it->desc.m_sz;
		it->off_idx = 0;
	}
```

This iterator uses the `m_offs` array to step through member offsets.  Before the change, it would only have been able to handle a single offset, now it can handle up to two.  The logic iterates through members (`it->m_idx`), and within each member, iterates through the offsets (`it->off_idx`) using `desc.m_offs[]`.

Next, I'll trace usage of this iterator within the kernel to understand the impact of this change more fully. A quick grep for `btf_field_iter` and `btf_relocate` within `kernel/` will provide the necessary context.



94/3 2026/09/17 18:53 tool grepper
0m Args:
{
  "Expression": "btf_relocate",
  "PathPrefix": "kernel/"
}

Results:
{
  "Output": "kernel/bpf/Makefile=67=obj-$(CONFIG_BPF_SYSCALL) += btf_iter.o\nkernel/bpf/Makefile:68:obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o\nkernel/bpf/Makefile-69-obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o\n--\nkernel/bpf/btf.c=6767=struct btf *btf_parse_vmlinux(void)\n--\nkernel/bpf/btf.c-6799- */\nkernel/bpf/btf.c:6800:__u32 btf_relocate_id(const struct btf *btf, __u32 id)\nkernel/bpf/btf.c-6801-{\n--\nkernel/bpf/btf.c=6809=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-6880-\tif (base_btf != vmlinux_btf) {\nkernel/bpf/btf.c:6881:\t\terr = btf_relocate(btf, vmlinux_btf, \u0026btf-\u003ebase_id_map);\nkernel/bpf/btf.c-6882-\t\tif (err)\n--\nkernel/bpf/btf.c=9300=static int btf_populate_kfunc_set(struct btf *btf, enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-9394-\tfor (i = set-\u003ecnt; i \u003c set-\u003ecnt + add_set-\u003ecnt; i++)\nkernel/bpf/btf.c:9395:\t\tset-\u003epairs[i].id = btf_relocate_id(btf, set-\u003epairs[i].id);\nkernel/bpf/btf.c-9396-\n--\nkernel/bpf/btf.c=9580=static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-9592-\tfor (i = 0; i \u003c kset-\u003eset-\u003ecnt; i++) {\nkernel/bpf/btf.c:9593:\t\tret = btf_check_kfunc_protos(btf, btf_relocate_id(btf, kset-\u003eset-\u003epairs[i].id),\nkernel/bpf/btf.c-9594-\t\t\t\t\t     kset-\u003eset-\u003epairs[i].flags);\n--\nkernel/bpf/btf.c=9649=static int btf_check_dtor_kfuncs(struct btf *btf, const struct btf_id_dtor_kfunc *dtors, u32 cnt)\n--\nkernel/bpf/btf.c-9656-\tfor (i = 0; i \u003c cnt; i++) {\nkernel/bpf/btf.c:9657:\t\tdtor_btf_id = btf_relocate_id(btf, dtors[i].kfunc_btf_id);\nkernel/bpf/btf.c-9658-\n--\nkernel/bpf/btf.c=9694=int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt,\n--\nkernel/bpf/btf.c-9752-\tfor (i = tab_cnt; i \u003c tab_cnt + add_cnt; i++) {\nkernel/bpf/btf.c:9753:\t\ttab-\u003edtors[i].btf_id = btf_relocate_id(btf, tab-\u003edtors[i].btf_id);\nkernel/bpf/btf.c:9754:\t\ttab-\u003edtors[i].kfunc_btf_id = btf_relocate_id(btf, tab-\u003edtors[i].kfunc_btf_id);\nkernel/bpf/btf.c-9755-\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=2234=event_btf_ids_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)\n--\nkernel/trace/trace_events.c-2263-\t\t/* Module-local ids in ids[] need base+local relocation. */\nkernel/trace/trace_events.c:2264:\t\ttp_id = btf_relocate_id(btf, ids[1]);\nkernel/trace/trace_events.c-2265-\n--\nkernel/trace/trace_events.c-2271-\t\tif (call-\u003eflags \u0026 TRACE_EVENT_FL_TRACEPOINT) {\nkernel/trace/trace_events.c:2272:\t\t\tt = btf_type_by_id(btf, btf_relocate_id(btf, ids[0]));\nkernel/trace/trace_events.c-2273-\t\t\traw_id = t ? t-\u003etype : 0;\n"
}

95/3 2026/09/17 18:53 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 83538
							output: 40
							thoughts: 4593
						

Thoughts:
**Analysis of BTF Patch for Potential Vulnerabilities**

Okay, so I've been digging into this BTF patch, specifically focusing on potential vulnerabilities related to uninitialized memory or integer overflows. My initial thought was to see if the patch touched `btf_relocate`, but it didn't directly modify `tools/lib/bpf/btf_relocate.c`. This means my initial concern about potential relocation issues is likely unwarranted.

Instead, the patch introduces new BTF kinds: `LOC_PARAM`, `LOC_PROTO`, and `LOCSEC`. This is where my focus shifted. I need to understand how these new kinds are handled, especially concerning data validation and potential information leaks or overflows.

I've examined the changes in both the kernel and the `tools/lib/bpf` side. Key areas of concern were in the verifier's logging and metadata checks (`btf_verifier_log_loc`, `btf_locsec_check_meta`, `btf_loc_param_check_meta`, `btf_loc_proto_check_meta`). I specifically looked at:

1.  **Format String Vulnerabilities**: I checked for potential uninitialized values used in format strings for verifier logs, but concluded that `va_start` / `va_end` usage in `btf_verifier_log_loc` is safe because `va_start` is conditionally invoked.
2.  **Integer Overflows:** I confirmed that the calculations involving `sizeof(struct btf_loc) * vlen` in `btf_locsec_check_meta` and the similar ones in the other check functions are safe, because `vlen` is bounded.
3.  **Data Validation:** I noted that data is copied from userspace in `btf_parse` and validated in `btf_check_meta` and associated functions. Integer overflow and uninitialized memory concerns are avoided because data copied from userspace is fully initialized before use and all accesses are range-checked.
4.  **Meta Size**: I verified that `meta_left` is derived from `attr->btf_size` and not user-controlled and that accesses through it are valid.
5.  **`struct btf_field_desc` Initialization**: I investigated the usage of `struct btf_field_desc` within `btf_field_iter` and how it is initialized. I'm satisfied that initialization, including the new `m_offs` array, is done correctly using compound literals, which ensures all members are initialized, even the new second offset.

The conclusion is that the code looks pretty good.



96/3 2026/09/17 18:54 tool grepper
0m Args:
{
  "Expression": "btf_field_iter",
  "PathPrefix": "tools/lib/bpf/btf_relocate.c"
}

Results:
{
  "Output": "tools/lib/bpf/btf_relocate.c=66=static int btf_relocate_rewrite_type_id(struct btf_relocate *r, __u32 i)\n--\ntools/lib/bpf/btf_relocate.c-68-\tstruct btf_type *t = btf_type_by_id(r-\u003ebtf, i);\ntools/lib/bpf/btf_relocate.c:69:\tstruct btf_field_iter it;\ntools/lib/bpf/btf_relocate.c-70-\t__u32 *id;\n--\ntools/lib/bpf/btf_relocate.c-72-\ntools/lib/bpf/btf_relocate.c:73:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf_relocate.c-74-\tif (err)\n--\ntools/lib/bpf/btf_relocate.c-76-\ntools/lib/bpf/btf_relocate.c:77:\twhile ((id = btf_field_iter_next(\u0026it)))\ntools/lib/bpf/btf_relocate.c-78-\t\t*id = r-\u003eid_map[*id];\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-134-\tstruct btf_type *t = btf_type_by_id(r-\u003ebtf, i);\ntools/lib/bpf/btf_relocate.c:135:\tstruct btf_field_iter it;\ntools/lib/bpf/btf_relocate.c-136-\t__u32 *id;\n--\ntools/lib/bpf/btf_relocate.c-141-\ntools/lib/bpf/btf_relocate.c:142:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_IDS);\ntools/lib/bpf/btf_relocate.c-143-\tif (err)\n--\ntools/lib/bpf/btf_relocate.c-145-\ntools/lib/bpf/btf_relocate.c:146:\twhile ((id = btf_field_iter_next(\u0026it))) {\ntools/lib/bpf/btf_relocate.c-147-\t\t__u32 next_id = *id;\n--\ntools/lib/bpf/btf_relocate.c=412=static int btf_relocate_rewrite_strs(struct btf_relocate *r, __u32 i)\n--\ntools/lib/bpf/btf_relocate.c-414-\tstruct btf_type *t = btf_type_by_id(r-\u003ebtf, i);\ntools/lib/bpf/btf_relocate.c:415:\tstruct btf_field_iter it;\ntools/lib/bpf/btf_relocate.c-416-\t__u32 *str_off;\n--\ntools/lib/bpf/btf_relocate.c-418-\ntools/lib/bpf/btf_relocate.c:419:\terr = btf_field_iter_init(\u0026it, t, BTF_FIELD_ITER_STRS);\ntools/lib/bpf/btf_relocate.c-420-\tif (err)\n--\ntools/lib/bpf/btf_relocate.c-422-\ntools/lib/bpf/btf_relocate.c:423:\twhile ((str_off = btf_field_iter_next(\u0026it))) {\ntools/lib/bpf/btf_relocate.c-424-\t\tif (!*str_off)\n"
}

97/3 2026/09/17 18:54 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 89748
							output: 37
							thoughts: 263
						

Thoughts:
**My Initial Assessment and Concerns**

Okay, here's what I'm seeing: `btf_relocate_rewrite_type_id`, `btf_mark_embedded_composite_type_ids`, and `btf_relocate_rewrite_strs` all share a very similar pattern. They're all just iterating through IDs or string offsets within the BTF types. Nothing groundbreaking there, but it begs the question of whether this is the only place we need to be concerned with these values.

My immediate thought is, are there *other* parts of the kernel that interact with BTF data and, specifically, with those location kinds: `BTF_KIND_LOC_PARAM`, `BTF_KIND_LOC_PROTO`, `BTF_KIND_LOCSEC`? We really need to make sure we've accounted for every dependency.

I should check the core BTF implementation in `kernel/bpf/btf.c` and make sure there are no other places that need these types.

Now, wait...what about core relocation in the kernel? Specifically, is `bpf_core_apply_relo_insn` impacted by those relocation kinds? I need to look for `relo_core` in the `kernel/bpf/` directory or even search for those `BTF_KIND_` definitions in `relo_core.c` or any related files. We can't let relocation slip through the cracks here. This could get very complex, very quickly if we aren't careful.



98/3 2026/09/17 18:54 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "BTF_KIND_",
  "PathPrefix": "kernel/bpf/relo_core.c"
}

Results:
{
  "error": "no matches"
}

99/3 2026/09/17 18:54 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 90393
							output: 39
							thoughts: 23
						

Thoughts:
Here's my take on the thought process:

**Reviewing Potential Relocation Issues**

Okay, I need to make sure I haven't missed anything, especially related to relocation handling. The `tools/lib/bpf/relo_core.c` file is a prime suspect for anything funky in that area, so let me quickly scan that source. I know it handles the core logic, so a quick verification there is the sensible move to ensure everything is operating as expected. I'm looking for anything that might have slipped through initial reviews or testing. Gotta be thorough.



100/3 2026/09/17 18:54 tool grepper
0m Args:
{
  "Expression": "BTF_KIND_",
  "PathPrefix": "tools/lib/bpf/relo_core.c"
}

Results:
{
  "Output": "tools/lib/bpf/relo_core.c=145=int __bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id,\n--\ntools/lib/bpf/relo_core.c-170-\tswitch (btf_kind(local_type)) {\ntools/lib/bpf/relo_core.c:171:\tcase BTF_KIND_UNKN:\ntools/lib/bpf/relo_core.c:172:\tcase BTF_KIND_STRUCT:\ntools/lib/bpf/relo_core.c:173:\tcase BTF_KIND_UNION:\ntools/lib/bpf/relo_core.c:174:\tcase BTF_KIND_ENUM:\ntools/lib/bpf/relo_core.c:175:\tcase BTF_KIND_FWD:\ntools/lib/bpf/relo_core.c:176:\tcase BTF_KIND_ENUM64:\ntools/lib/bpf/relo_core.c-177-\t\treturn 1;\ntools/lib/bpf/relo_core.c:178:\tcase BTF_KIND_INT:\ntools/lib/bpf/relo_core.c-179-\t\t/* just reject deprecated bitfield-like integers; all other\n--\ntools/lib/bpf/relo_core.c-182-\t\treturn btf_int_offset(local_type) == 0 \u0026\u0026 btf_int_offset(targ_type) == 0;\ntools/lib/bpf/relo_core.c:183:\tcase BTF_KIND_PTR:\ntools/lib/bpf/relo_core.c-184-\t\tlocal_id = local_type-\u003etype;\n--\ntools/lib/bpf/relo_core.c-186-\t\tgoto recur;\ntools/lib/bpf/relo_core.c:187:\tcase BTF_KIND_ARRAY:\ntools/lib/bpf/relo_core.c-188-\t\tlocal_id = btf_array(local_type)-\u003etype;\n--\ntools/lib/bpf/relo_core.c-190-\t\tgoto recur;\ntools/lib/bpf/relo_core.c:191:\tcase BTF_KIND_FUNC_PROTO: {\ntools/lib/bpf/relo_core.c-192-\t\tstruct btf_param *local_p = btf_params(local_type);\n--\ntools/lib/bpf/relo_core.c=413=static int bpf_core_fields_are_compat(const struct btf *local_btf,\n--\ntools/lib/bpf/relo_core.c-431-\tswitch (btf_kind(local_type)) {\ntools/lib/bpf/relo_core.c:432:\tcase BTF_KIND_PTR:\ntools/lib/bpf/relo_core.c:433:\tcase BTF_KIND_FLOAT:\ntools/lib/bpf/relo_core.c-434-\t\treturn 1;\ntools/lib/bpf/relo_core.c:435:\tcase BTF_KIND_FWD:\ntools/lib/bpf/relo_core.c:436:\tcase BTF_KIND_ENUM64:\ntools/lib/bpf/relo_core.c:437:\tcase BTF_KIND_ENUM: {\ntools/lib/bpf/relo_core.c-438-\t\tconst char *local_name, *targ_name;\n--\ntools/lib/bpf/relo_core.c-450-\t}\ntools/lib/bpf/relo_core.c:451:\tcase BTF_KIND_INT:\ntools/lib/bpf/relo_core.c-452-\t\t/* just reject deprecated bitfield-like integers; all other\n--\ntools/lib/bpf/relo_core.c-456-\t\t       btf_int_offset(targ_type) == 0;\ntools/lib/bpf/relo_core.c:457:\tcase BTF_KIND_ARRAY:\ntools/lib/bpf/relo_core.c-458-\t\tlocal_id = btf_array(local_type)-\u003etype;\n--\ntools/lib/bpf/relo_core.c=1561=int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const struct btf *targ_btf,\n--\ntools/lib/bpf/relo_core.c-1591-\tswitch (local_k) {\ntools/lib/bpf/relo_core.c:1592:\tcase BTF_KIND_UNKN:\ntools/lib/bpf/relo_core.c-1593-\t\treturn local_k == targ_k;\ntools/lib/bpf/relo_core.c:1594:\tcase BTF_KIND_FWD: {\ntools/lib/bpf/relo_core.c-1595-\t\tbool local_f = BTF_INFO_KFLAG(local_t-\u003einfo);\n--\ntools/lib/bpf/relo_core.c-1603-\t\t\t */\ntools/lib/bpf/relo_core.c:1604:\t\t\treturn (targ_k == BTF_KIND_STRUCT \u0026\u0026 !local_f) ||\ntools/lib/bpf/relo_core.c:1605:\t\t\t       (targ_k == BTF_KIND_UNION \u0026\u0026 local_f);\ntools/lib/bpf/relo_core.c-1606-\t\t} else {\n--\ntools/lib/bpf/relo_core.c-1613-\t}\ntools/lib/bpf/relo_core.c:1614:\tcase BTF_KIND_ENUM:\ntools/lib/bpf/relo_core.c:1615:\tcase BTF_KIND_ENUM64:\ntools/lib/bpf/relo_core.c-1616-\t\tif (!btf_is_any_enum(targ_t))\n--\ntools/lib/bpf/relo_core.c-1619-\t\treturn bpf_core_enums_match(local_btf, local_t, targ_btf, targ_t);\ntools/lib/bpf/relo_core.c:1620:\tcase BTF_KIND_STRUCT:\ntools/lib/bpf/relo_core.c:1621:\tcase BTF_KIND_UNION:\ntools/lib/bpf/relo_core.c-1622-\t\tif (behind_ptr) {\n--\ntools/lib/bpf/relo_core.c-1627-\ntools/lib/bpf/relo_core.c:1628:\t\t\tif (targ_k != BTF_KIND_FWD)\ntools/lib/bpf/relo_core.c-1629-\t\t\t\treturn 0;\ntools/lib/bpf/relo_core.c-1630-\ntools/lib/bpf/relo_core.c:1631:\t\t\treturn (local_k == BTF_KIND_UNION) == targ_f;\ntools/lib/bpf/relo_core.c-1632-\t\t} else {\n--\ntools/lib/bpf/relo_core.c-1638-\t\t}\ntools/lib/bpf/relo_core.c:1639:\tcase BTF_KIND_INT: {\ntools/lib/bpf/relo_core.c-1640-\t\t__u8 local_sgn;\n--\ntools/lib/bpf/relo_core.c-1650-\t}\ntools/lib/bpf/relo_core.c:1651:\tcase BTF_KIND_PTR:\ntools/lib/bpf/relo_core.c-1652-\t\tif (local_k != targ_k)\n--\ntools/lib/bpf/relo_core.c-1659-\t\tgoto recur;\ntools/lib/bpf/relo_core.c:1660:\tcase BTF_KIND_ARRAY: {\ntools/lib/bpf/relo_core.c-1661-\t\tconst struct btf_array *local_array = btf_array(local_t);\n--\ntools/lib/bpf/relo_core.c-1673-\t}\ntools/lib/bpf/relo_core.c:1674:\tcase BTF_KIND_FUNC_PROTO: {\ntools/lib/bpf/relo_core.c-1675-\t\tstruct btf_param *local_p = btf_params(local_t);\n"
}

101/3 2026/09/17 18:54 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 92853
							output: 27
							thoughts: 128
						

Thoughts:
**Kernel BTF Deduplication - A Quick Check**

Okay, so I'm thinking I should really refresh my memory on the `btf_dedup` function. Let's start by looking at `tools/lib/bpf/btf.c`. Hang on... a slight pause. I'm immediately thinking, "Wait, `bpftool` and `libbpf` are *user space* tools. Kernel BTF parsing is what syzkaller's fuzzing, right?" That's the `bpf(BPF_BTF_LOAD)` and `bpf(BPF_OBJ_GET_INFO_BY_FD)` stuff - those are the system calls we're interested in. So, the question really becomes: can `btf_dedup` even *run* inside the kernel? That's the important piece. Right, better search in the `kernel/` directory and see if I can find it there. I need to zero in on the relevant code.



102/3 2026/09/17 18:54 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "btf_dedup",
  "PathPrefix": "kernel/"
}

Results:
{
  "error": "no matches"
}

103/3 2026/09/17 18:54 llm kmsan-evaluator-compressor
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Reply:
### SUMMARY OF INVESTIGATION

#### 1. Goal & Context
- Determine whether patch series adding BTF kinds `BTF_KIND_LOC_PARAM` (20), `BTF_KIND_LOC_PROTO` (21), and `BTF_KIND_LOCSEC` (22) requires a dedicated KMSAN fuzzing session (`NeedsKMSAN=true` vs `false`).
- Evaluation criterion: KMSAN is justified only if uninitialized memory risks exist (reads of uninitialized memory in control flow, leaking uninitialized heap/stack memory or structure padding to user space via syscalls/copies, uninitialized variables used in branching) that KASAN/LOCKDEP cannot catch.

#### 2. Patch Overview & Code Changes
- **Diff summary:**
  - `Documentation/bpf/btf.rst`: Docs for `BTF_KIND_LOC_PARAM`, `BTF_KIND_LOC_PROTO`, `BTF_KIND_LOCSEC`.
  - `include/uapi/linux/btf.h` & `tools/include/uapi/linux/btf.h`:
    - Defines `BTF_KIND_LOC_PARAM = 20`, `BTF_KIND_LOC_PROTO = 21`, `BTF_KIND_LOCSEC = 22`.
    - Defines `struct btf_loc_param { __u32 flags; __u32 values[]; };`.
    - Defines `enum btf_loc_param_flags` (`SIGNED`, `CONST`, `ADDR`, `REG`, `DEREF`, `OFFSET`).
    - Defines `struct btf_loc { __u32 func; __u32 loc_proto; __u32 offset; };`.
  - `include/linux/btf.h`:
    - Macro `for_each_loc(i, locsec_type, member)`.
    - Helper accessors: `btf_loc_param()`, `btf_loc_proto_params()`, `btf_type_loc_secinfo()`.
    - Modified `struct btf_field_desc`: `m_offs[1]` expanded to `m_offs[2]`.
  - `kernel/bpf/btf.c`:
    - Added string representations to `btf_kind_str[]`.
    - Added helper predicates: `btf_type_is_loc_param()`, `btf_type_is_loc_proto()`, `btf_type_is_locsec()`.
    - Updated `btf_type_nosize()` to include the three new kinds.
    - Updated `btf_type_needs_resolve()` to include `LOC_PROTO` and `LOCSEC`.
    - Implemented `btf_loc_param_check_meta()`, `btf_loc_param_log()`, `loc_param_ops`.
    - Implemented `btf_loc_proto_check_meta()`, `btf_loc_proto_log()`, `btf_loc_proto_resolve()`, `loc_proto_ops`.
    - Implemented `btf_verifier_log_loc()`, `btf_locsec_check_meta()`, `btf_locsec_log()`, `btf_locsec_resolve()`, `locsec_ops`.
    - Added ops to `kind_ops[NR_BTF_KINDS]`.
    - Updated `btf_resolve_valid()`.
  - Tools / libbpf / bpftool / selftests:
    - `bpftool`: CLI option `-B/--base-btf` multi-file parsing; display format for loc kinds in `dump_btf_type()` and `btf_loc_param_str()`.
    - `libbpf`: Type validation, endian bswap (`btf_bswap_type_rest`), dedup, distillation, new builder APIs (`btf__add_loc_param`, etc.).
    - `selftests/bpf`: Corresponding test cases (`btf_field_iter`, `bpftool_btf_dump`, `btf_dedup_split`, `btf_distill`).

#### 3. Investigation & Analysis of Kernel Paths

##### A. Memory Loading and Verifier Paths (`kernel/bpf/btf.c`)
1. **BTF Object Ingestion (`btf_parse` in `kernel/bpf/btf.c`)**:
   - `env = kzalloc_obj(*env, ...)`: environment zeroed.
   - `btf = kzalloc_obj(*btf, ...)`: `struct btf` zeroed.
   - `data = kvmalloc(attr->btf_size, ...)`: allocated and filled immediately via `copy_from_bpfptr(data, btf_data, attr->btf_size)`.
   - Parsing reads exclusively from this user-provided buffer.
2. **Metadata verification (`btf_loc_*_check_meta`)**:
   - Checks `meta_left < meta_needed` where `meta_needed` is calculated from `sizeof(header) + vlen * elem_size`.
   - `vlen` is extracted from `btf_vlen(t)` (16 bits), preventing 32-bit overflow when multiplied by 4 or 12 (`sizeof(struct btf_loc)`).
   - Bounds checks ensure all accesses stay strictly within the allocated user data section.
3. **Type resolution (`btf_loc_proto_resolve`, `btf_locsec_resolve`)**:
   - References look up types in `env->btf` via `btf_type_by_id()`.
   - Checks that types exist and match expected kinds (`LOC_PARAM` for `LOC_PROTO`; `FUNC` and `LOC_PROTO` for `LOCSEC`).
   - Resolution bookkeeping uses stack vertices and resolve arrays initialized in `env_resolve_init()`.
   - No uninitialized struct fields or pointers allocated or read.

##### B. Kernel-to-User Space Exposure
1. **`btf_get_info_by_fd()` / `bpf_btf_get_info_by_fd()`**:
   - Copies `struct bpf_btf_info` out to user space:
     - `memset(&info, 0, sizeof(info))` before populating fields.
     - `btf_copy = min_t(u32, btf->data_size, info.btf_size)`.
     - `copy_to_user(ubtf, btf->data, btf_copy)` copies raw BTF bytes previously loaded or generated.
     - Name string copy uses null terminator or length checks.
   - No new kernel structures containing uninitialized padding or uninitialized memory are sent to user space.
2. **Kernel usage of BTF LOC kinds**:
   - Searched entire `kernel/`:
     - LOC kinds are only used within `kernel/bpf/btf.c` for validation/verification when BTF is parsed.
     - They are not used in tracing output, probe arg fetching, BPF verifier core, struct ops, or map definitions.
     - No kernel subsystem consumes `btf_loc` or `btf_loc_param` in execution paths that could branch on uninitialized fields.

##### C. `struct btf_field_desc` alteration (`include/linux/btf.h`)
- `int m_offs[1]` changed to `int m_offs[2]`.
- Inspected in kernel: `btf_field_iter_init` and `btf_field_desc` are only declared in `include/linux/btf.h` with an inline stub, used in `tools/lib/bpf` and `tools/bpf/bpftool`.
- No kernel stack/heap buffers allocate `btf_field_desc` with uninitialized trailing entries that are copied to user space.

#### 4. Active Line of Investigation / Status
- The analysis indicates:
  - All kernel memory structures touched are either zero-allocated (`kzalloc`, `memset`) or populated directly from user input.
  - The new BTF kinds are purely data formats parsed and validated during BTF loading.
  - Parsing validates metadata size against boundaries before accessing fields.
  - No info leaks or uninitialized memory reads are introduced.
  - Any out-of-bounds access or memory corruption risks in parser/verifier are covered by KASAN.
- Ready to conclude whether `NeedsKMSAN=false` or `true` (pointing to `false`).

#### 5. Potential Repetitive Loops / Tool Calls Warning
- Tool searching across `kernel/` for `BTF_KIND_` and `btf_field_iter_init` is complete. No further searches or file inspections are needed.
- Next step is to invoke `set-results` with `NeedsKMSAN=false` and provide the detailed technical rationale.

Tokens:
							input: 68879
							output: 2011
							thoughts: 0
						

104/3 2026/09/17 18:54 llm kmsan-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46534
							output: 591
							thoughts: 0
						

105/3 2026/09/17 18:55 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series adds support for three new BTF kinds (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, BTF_KIND_LOCSEC) across documentation, UAPI, bpftool, libbpf, selftests, and the kernel BTF verifier (kernel/bpf/btf.c).\n\nKMSAN vs KASAN applicability analysis:\n1. Kernel memory allocation \u0026 initialization:\n   - When user space loads a BTF object via bpf(BPF_BTF_LOAD), the kernel allocates memory for the BTF object using kzalloc() and copies user-provided bytes directly into kvmalloc'd memory with copy_from_bpfptr().\n   - The validation routines added for the new BTF kinds (btf_loc_param_check_meta, btf_loc_proto_check_meta, btf_locsec_check_meta, and their resolution functions) strictly parse and inspect the already populated buffer.\n   - Verification checks size and boundary constraints (meta_left \u003e= meta_needed) before accessing any elements, protecting against out-of-bounds reads (which fall squarely under KASAN's domain).\n\n2. Kernel-to-user space information exposure:\n   - When retrieving BTF info via BPF_OBJ_GET_INFO_BY_FD, struct bpf_btf_info is cleared with memset(\u0026info, 0, sizeof(info)), and the BTF payload copied back to user space is simply the user-supplied (or module/vmlinux) BTF data buffer. No uninitialized struct padding or uninitialized heap/stack memory is copied to user space.\n\n3. Control flow and branching:\n   - All branching decisions in the new code evaluate well-defined struct fields populated from user data or verification state.\n   - The expanded struct btf_field_desc (m_offs[2]) and btf_field_iter in tools/lib/bpf/btf_iter.c (included in kernel/bpf/btf_iter.c for module BTF relocation) explicitly initialize all iterator fields upon btf_field_iter_init().\n\n4. Bug surface:\n   - Any bugs in metadata validation, index calculations, or type resolution are memory boundary/indexing or logic errors, which are either rejected cleanly by the BTF verifier or caught by standard bug detectors (KASAN for OOB reads/writes).\n   - There are no uninitialized memory reads or information leaks introduced or exposed by these changes.\n\nTherefore, dedicated KMSAN fuzzing is not warranted (NeedsKMSAN=false).",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series adds support for three new BTF kinds (BTF_KIND_LOC_PARAM, BTF_KIND_LOC_PROTO, BTF_KIND_LOCSEC) across documentation, UAPI, bpftool, libbpf, selftests, and the kernel BTF verifier (kernel/bpf/btf.c).\n\nKMSAN vs KASAN applicability analysis:\n1. Kernel memory allocation \u0026 initialization:\n   - When user space loads a BTF object via bpf(BPF_BTF_LOAD), the kernel allocates memory for the BTF object using kzalloc() and copies user-provided bytes directly into kvmalloc'd memory with copy_from_bpfptr().\n   - The validation routines added for the new BTF kinds (btf_loc_param_check_meta, btf_loc_proto_check_meta, btf_locsec_check_meta, and their resolution functions) strictly parse and inspect the already populated buffer.\n   - Verification checks size and boundary constraints (meta_left \u003e= meta_needed) before accessing any elements, protecting against out-of-bounds reads (which fall squarely under KASAN's domain).\n\n2. Kernel-to-user space information exposure:\n   - When retrieving BTF info via BPF_OBJ_GET_INFO_BY_FD, struct bpf_btf_info is cleared with memset(\u0026info, 0, sizeof(info)), and the BTF payload copied back to user space is simply the user-supplied (or module/vmlinux) BTF data buffer. No uninitialized struct padding or uninitialized heap/stack memory is copied to user space.\n\n3. Control flow and branching:\n   - All branching decisions in the new code evaluate well-defined struct fields populated from user data or verification state.\n   - The expanded struct btf_field_desc (m_offs[2]) and btf_field_iter in tools/lib/bpf/btf_iter.c (included in kernel/bpf/btf_iter.c for module BTF relocation) explicitly initialize all iterator fields upon btf_field_iter_init().\n\n4. Bug surface:\n   - Any bugs in metadata validation, index calculations, or type resolution are memory boundary/indexing or logic errors, which are either rejected cleanly by the BTF verifier or caught by standard bug detectors (KASAN for OOB reads/writes).\n   - There are no uninitialized memory reads or information leaks introduced or exposed by these changes.\n\nTherefore, dedicated KMSAN fuzzing is not warranted (NeedsKMSAN=false).",
  "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)