AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/12 17:58 flow patch-triage
6m Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "BPF_EVENTS"
  ],
  "FocusSymbols": [
    "bpf_tracing_multi_attach",
    "bpf_trampoline_multi_prog_attach",
    "bpf_trampoline_multi_prog_detach",
    "bpf_arch_text_poke_batch",
    "bpf_arch_text_poke"
  ],
  "KMSANReasoning": "The patch adds support for attaching tracing multi-links (fentry/fexit/fsession multi) to BPF programs using batch text poking and trampoline management.\n\nAnalysis of memory initialization and user-space exposure:\n1. User-space copies: In `bpf_link_get_info_by_fd`, the entire `struct bpf_link_info` is initialized with `memset(\u0026info, 0, sizeof(info))` before calling `link-\u003eops-\u003efill_link_info`. The newly added `flags` field in `info-\u003etracing_multi` is explicitly set, and array data exported to user pointers via `put_user` (including target BTF function IDs) uses initialized scalar values. No uninitialized struct padding or fields are leaked to userspace.\n2. Kernel structures and allocations: `struct bpf_tracing_multi_link` (including its flexible array member `nodes`) is allocated with `kvzalloc_flex()`, ensuring all fields are zero-initialized. Temporary arrays (`keys`, `progs`, `pokes`, `fds`, `cookies`, `ids`) are either fully populated (via `copy_from_user()`, `bpf_get_progs()`, or loops) before being read or sorted, or properly cleaned up on error.\n3. Text poke buffers: In `bpf_arch_text_poke_batch()` and `bpf_arch_text_poke_prepare_insns()`, instruction buffers `old_insn` and `new_insn` are initialized (with `x86_nops[5]`) before any `memcmp` or poking occurs.\n\nAny potential bugs introduced by this patch (such as reference counting leaks, use-after-free on rollback, out-of-bounds indexing, or locking issues with `text_mutex` / `trampoline_locks`) are covered by standard KASAN and LOCKDEP configurations. There are no uninitialized memory risks that would require a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch introduces multi-target tracing support for BPF programs, enabling fentry/fexit/fsession.multi links to attach to multiple target BPF programs simultaneously via the bpf() syscall. It adds batch text poking on x86 (bpf_arch_text_poke_batch), multi-program trampoline attachment and detach handling (bpf_trampoline_multi_prog_attach, bpf_trampoline_multi_prog_detach), and associated verifier and link lifecycle management. These changes reside in core reachable BPF subsystems and warrant fuzzing to uncover potential issues in state rollback, concurrency, or instruction patching.",
  "WorthFuzzing": true
}

1/1 2026/10/12 17:58 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 4f26995037887ee50c4e3d8ebbbe6dfdb4387288\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Mon Oct 12 17:58:07 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c\nindex 083fcd6cf15b7..b2040ae09273e 100644\n--- a/arch/x86/net/bpf_jit_comp.c\n+++ b/arch/x86/net/bpf_jit_comp.c\n@@ -646,13 +646,12 @@ static int emit_jump(u8 **pprog, void *func, void *ip)\n \treturn emit_patch(pprog, func, ip, 0xE9);\n }\n \n-static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n-\t\t\t\tenum bpf_text_poke_type new_t,\n-\t\t\t\tvoid *old_addr, void *new_addr)\n+static int bpf_arch_text_poke_prepare_insns(void *ip, enum bpf_text_poke_type old_t,\n+\t\t\t\t\t    enum bpf_text_poke_type new_t,\n+\t\t\t\t\t    void *old_addr, void *new_addr,\n+\t\t\t\t\t    u8 *old_insn, u8 *new_insn)\n {\n \tconst u8 *nop_insn = x86_nops[5];\n-\tu8 old_insn[X86_PATCH_SIZE];\n-\tu8 new_insn[X86_PATCH_SIZE];\n \tu8 *prog;\n \tint ret;\n \n@@ -676,24 +675,37 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n \t\t\treturn ret;\n \t}\n \n-\tret = -EBUSY;\n-\tmutex_lock(\u0026text_mutex);\n+\treturn 0;\n+}\n+\n+static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n+\t\t\t\tenum bpf_text_poke_type new_t,\n+\t\t\t\tvoid *old_addr, void *new_addr)\n+{\n+\tu8 old_insn[X86_PATCH_SIZE];\n+\tu8 new_insn[X86_PATCH_SIZE];\n+\tint ret;\n+\n+\tret = bpf_arch_text_poke_prepare_insns(ip, old_t, new_t, old_addr, new_addr, old_insn,\n+\t\t\t\t\t       new_insn);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tguard(mutex)(\u0026text_mutex);\n+\n \tif (memcmp(ip, old_insn, X86_PATCH_SIZE))\n-\t\tgoto out;\n-\tret = 1;\n+\t\treturn -EBUSY;\n \tif (memcmp(ip, new_insn, X86_PATCH_SIZE)) {\n \t\tsmp_text_poke_single(ip, new_insn, X86_PATCH_SIZE, NULL);\n-\t\tret = 0;\n+\t\treturn 0;\n \t}\n-out:\n-\tmutex_unlock(\u0026text_mutex);\n-\treturn ret;\n+\treturn 1;\n }\n \n-int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n-\t\t       enum bpf_text_poke_type new_t, void *old_addr,\n-\t\t       void *new_addr)\n+static int bpf_arch_text_poke_check_ip(void **ipp)\n {\n+\tvoid *ip = *ipp;\n+\n \tif (!is_kernel_text((long)ip) \u0026\u0026\n \t    !is_bpf_text_address((long)ip))\n \t\t/* BPF poking in modules is not supported */\n@@ -704,11 +716,65 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n \t * with an ENDBR instruction.\n \t */\n \tif (is_endbr(ip))\n-\t\tip += ENDBR_INSN_SIZE;\n+\t\t*ipp += ENDBR_INSN_SIZE;\n+\n+\treturn 0;\n+}\n+\n+int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n+\t\t       enum bpf_text_poke_type new_t, void *old_addr,\n+\t\t       void *new_addr)\n+{\n+\tint ret;\n+\n+\tret = bpf_arch_text_poke_check_ip(\u0026ip);\n+\tif (ret)\n+\t\treturn ret;\n \n \treturn __bpf_arch_text_poke(ip, old_t, new_t, old_addr, new_addr);\n }\n \n+int bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)\n+{\n+\tu8 old_insn[X86_PATCH_SIZE];\n+\tu8 new_insn[X86_PATCH_SIZE];\n+\tint err;\n+\tu32 i;\n+\n+\tfor (i = 0; i \u003c cnt; i++) {\n+\t\terr = bpf_arch_text_poke_check_ip(\u0026pokes[i]-\u003eip);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t}\n+\n+\tguard(mutex)(\u0026text_mutex);\n+\n+\tfor (i = 0; i \u003c cnt; i++) {\n+\t\tstruct bpf_text_poke *poke = pokes[i];\n+\n+\t\terr = bpf_arch_text_poke_prepare_insns(poke-\u003eip, poke-\u003eold_t, poke-\u003enew_t,\n+\t\t\t\t\t\t       poke-\u003eold_addr, poke-\u003enew_addr, old_insn,\n+\t\t\t\t\t\t       new_insn);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\tif (memcmp(poke-\u003eip, old_insn, X86_PATCH_SIZE))\n+\t\t\treturn -EBUSY;\n+\t}\n+\n+\tfor (i = 0; i \u003c cnt; i++) {\n+\t\tstruct bpf_text_poke *poke = pokes[i];\n+\n+\t\tbpf_arch_text_poke_prepare_insns(poke-\u003eip, poke-\u003eold_t, poke-\u003enew_t,\n+\t\t\t\t\t\t poke-\u003eold_addr, poke-\u003enew_addr, old_insn,\n+\t\t\t\t\t\t new_insn);\n+\t\tif (memcmp(poke-\u003eip, new_insn, X86_PATCH_SIZE))\n+\t\t\tsmp_text_poke_batch_add(poke-\u003eip, new_insn, X86_PATCH_SIZE, NULL);\n+\t}\n+\n+\tsmp_text_poke_batch_finish();\n+\treturn 0;\n+}\n+\n #define EMIT_LFENCE()\tEMIT3(0x0F, 0xAE, 0xE8)\n \n static void __emit_indirect_jump(u8 **pprog, int reg, bool ereg)\ndiff --git a/include/linux/bpf.h b/include/linux/bpf.h\nindex 54144372281cb..a37f926023fdf 100644\n--- a/include/linux/bpf.h\n+++ b/include/linux/bpf.h\n@@ -1496,9 +1496,10 @@ struct bpf_trampoline {\n \tstruct bpf_tramp_image *cur_image;\n \t/* Images not freed yet, cur_image and older ones still in use */\n \tstruct list_head images;\n-\t/* Used as temporary old image storage for multi_attach */\n+\t/* Used as temporary images storage for multi_attach */\n \tstruct {\n \t\tstruct bpf_tramp_image *old_image;\n+\t\tstruct bpf_tramp_image *new_image;\n \t\tu32 old_flags;\n \t} multi_attach;\n };\n@@ -1616,6 +1617,9 @@ int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,\n \t\t\t\tstruct bpf_tracing_multi_link *link);\n void bpf_trampoline_multi_detach(struct bpf_prog *prog,\n \t\t\t\t struct bpf_tracing_multi_link *link);\n+int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,\n+\t\t\t\t     struct bpf_tracing_multi_link *link);\n+void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link);\n void bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags);\n \n /*\n@@ -1739,6 +1743,14 @@ static inline void bpf_trampoline_multi_detach(struct bpf_prog *prog,\n \t\t\t\t\t       struct bpf_tracing_multi_link *link)\n {\n }\n+\n+static inline int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,\n+\t\t\t\t\t\t   struct bpf_tracing_multi_link *link)\n+{\n+\treturn -EOPNOTSUPP;\n+}\n+\n+static inline void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link) {}\n static inline void bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags) {}\n #endif\n \n@@ -2089,10 +2101,25 @@ struct bpf_tracing_link {\n \tstruct bpf_prog *tgt_prog;\n };\n \n+enum bpf_text_poke_type {\n+\tBPF_MOD_NOP,\n+\tBPF_MOD_CALL,\n+\tBPF_MOD_JUMP,\n+};\n+\n+struct bpf_text_poke {\n+\tvoid *ip;\n+\tvoid *old_addr;\n+\tvoid *new_addr;\n+\tenum bpf_text_poke_type old_t;\n+\tenum bpf_text_poke_type new_t;\n+};\n+\n struct bpf_tracing_multi_node {\n \tstruct bpf_tramp_node node;\n \tstruct bpf_trampoline *trampoline;\n \tstruct ftrace_func_entry entry;\n+\tstruct bpf_text_poke poke;\n };\n \n struct bpf_tracing_multi_data {\n@@ -2107,6 +2134,8 @@ struct bpf_tracing_multi_link {\n \tstruct bpf_tracing_multi_data data;\n \tu64 *cookies;\n \tstruct bpf_tramp_node *fexits;\n+\tstruct bpf_text_poke **pokes;\n+\tstruct bpf_prog **tgt_progs;\n \tint nodes_cnt;\n \tstruct bpf_tracing_multi_node nodes[] __counted_by(nodes_cnt);\n };\n@@ -4225,12 +4254,7 @@ static inline u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,\n }\n #endif /* CONFIG_INET */\n \n-enum bpf_text_poke_type {\n-\tBPF_MOD_NOP,\n-\tBPF_MOD_CALL,\n-\tBPF_MOD_JUMP,\n-};\n-\n+int bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt);\n int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n \t\t       enum bpf_text_poke_type new_t, void *old_addr,\n \t\t       void *new_addr);\ndiff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h\nindex 6f70db7515dd4..df66206af3cf9 100644\n--- a/include/uapi/linux/bpf.h\n+++ b/include/uapi/linux/bpf.h\n@@ -1927,6 +1927,8 @@ union bpf_attr {\n \t\t\t\t__aligned_u64\tids;\n \t\t\t\t__aligned_u64\tcookies;\n \t\t\t\t__u32\t\tcnt;\n+\t\t\t\t__u32\t\t:32;\n+\t\t\t\t__aligned_u64\tfds;\n \t\t\t} tracing_multi;\n \t\t};\n \t} link_create;\n@@ -6889,6 +6891,10 @@ struct bpf_btf_info {\n \t__u32 kernel_btf;\n } __attribute__((aligned(8)));\n \n+enum {\n+\tBPF_F_TRACING_MULTI_TGT_PROGS = (1U \u003c\u003c 0),\n+};\n+\n struct bpf_link_info {\n \t__u32 type;\n \t__u32 id;\n@@ -6974,10 +6980,11 @@ struct bpf_link_info {\n \t\t\t__u32 attach_type;\n \t\t\t__u32 count; /* in/out: tracing_multi target count */\n \t\t\t__u32 btf_obj_id;\n-\t\t\t__u32 :32;\n+\t\t\t__u32 flags;\n \t\t\t__aligned_u64 ids;\n \t\t\t__aligned_u64 addrs;\n \t\t\t__aligned_u64 cookies;\n+\t\t\t__aligned_u64 func_btf_ids;\n \t\t} tracing_multi;\n \t\tstruct {\n \t\t\t__u32 type; /* enum bpf_perf_event_type */\ndiff --git a/kernel/bpf/core.c b/kernel/bpf/core.c\nindex 05c89396119ad..49b794878c116 100644\n--- a/kernel/bpf/core.c\n+++ b/kernel/bpf/core.c\n@@ -3484,6 +3484,11 @@ int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,\n \treturn -EFAULT;\n }\n \n+int __weak bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)\n+{\n+\treturn -EOPNOTSUPP;\n+}\n+\n int __weak bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,\n \t\t\t      enum bpf_text_poke_type new_t, void *old_addr,\n \t\t\t      void *new_addr)\ndiff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c\nindex 24edb59238f34..6e18f69a63adf 100644\n--- a/kernel/bpf/trampoline.c\n+++ b/kernel/bpf/trampoline.c\n@@ -13,6 +13,7 @@\n #include \u003clinux/bpf_verifier.h\u003e\n #include \u003clinux/bpf_lsm.h\u003e\n #include \u003clinux/delay.h\u003e\n+#include \u003clinux/sort.h\u003e\n \n /* dummy _ops. The verifier will operate on target program's ops. */\n const struct bpf_verifier_ops bpf_extension_verifier_ops = {\n@@ -59,6 +60,33 @@ static void trampoline_unlock(struct bpf_trampoline *tr)\n \tmutex_unlock(select_trampoline_lock(tr));\n }\n \n+#ifdef CONFIG_BPF_SYSCALL\n+\n+static void trampoline_lock_all(void)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i \u003c TRAMPOLINE_LOCKS_TABLE_SIZE; i++)\n+\t\tmutex_lock(\u0026trampoline_locks[i].mutex);\n+}\n+\n+static void trampoline_unlock_all(void)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i \u003c TRAMPOLINE_LOCKS_TABLE_SIZE; i++)\n+\t\tmutex_unlock(\u0026trampoline_locks[i].mutex);\n+}\n+\n+static void bpf_trampoline_multi_attach_init(struct bpf_trampoline *tr)\n+{\n+\ttr-\u003emulti_attach.old_image = tr-\u003ecur_image;\n+\ttr-\u003emulti_attach.new_image = NULL;\n+\ttr-\u003emulti_attach.old_flags = tr-\u003eflags;\n+}\n+\n+#endif /* CONFIG_BPF_SYSCALL */\n+\n struct bpf_trampoline_ops {\n \tint (*register_fentry)(struct bpf_trampoline *tr, struct bpf_tramp_image *im, void *data);\n \tint (*unregister_fentry)(struct bpf_trampoline *tr, u32 orig_flags, void *data);\n@@ -475,18 +503,11 @@ static int register_fentry(struct bpf_trampoline *tr, struct bpf_tramp_image *im\n \t\t\t   void *data __maybe_unused)\n {\n \tvoid *new_addr = im-\u003eimage;\n-\tvoid *ip = tr-\u003efunc.addr;\n-\tunsigned long faddr;\n \tint ret;\n \n-\tfaddr = ftrace_location((unsigned long)ip);\n-\tif (faddr) {\n+\tif (tr-\u003efunc.ftrace_managed) {\n \t\tif (!tr-\u003efops)\n \t\t\treturn -ENOTSUPP;\n-\t\ttr-\u003efunc.ftrace_managed = true;\n-\t}\n-\n-\tif (tr-\u003efunc.ftrace_managed) {\n \t\tret = direct_ops_add(tr, new_addr);\n \t} else {\n \t\tret = bpf_trampoline_update_fentry(tr, 0, NULL, new_addr);\n@@ -1286,6 +1307,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key,\n \n \tmemcpy(\u0026tr-\u003efunc.model, \u0026tgt_info-\u003efmodel, sizeof(tgt_info-\u003efmodel));\n \ttr-\u003efunc.addr = (void *)tgt_info-\u003etgt_addr;\n+\ttr-\u003efunc.ftrace_managed = tr-\u003eip != 0;\n out:\n \ttrampoline_unlock(tr);\n \treturn tr;\n@@ -1579,22 +1601,6 @@ int __weak arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,\n     defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS) \u0026\u0026 \\\n     defined(CONFIG_BPF_SYSCALL)\n \n-static void trampoline_lock_all(void)\n-{\n-\tint i;\n-\n-\tfor (i = 0; i \u003c TRAMPOLINE_LOCKS_TABLE_SIZE; i++)\n-\t\tmutex_lock(\u0026trampoline_locks[i].mutex);\n-}\n-\n-static void trampoline_unlock_all(void)\n-{\n-\tint i;\n-\n-\tfor (i = 0; i \u003c TRAMPOLINE_LOCKS_TABLE_SIZE; i++)\n-\t\tmutex_unlock(\u0026trampoline_locks[i].mutex);\n-}\n-\n static void remove_tracing_multi_data(struct bpf_tracing_multi_data *data)\n {\n \tftrace_hash_remove(data-\u003ereg);\n@@ -1635,8 +1641,8 @@ static void ftrace_hash_add(struct ftrace_hash *hash, struct ftrace_func_entry *\n static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_image *im, void *ptr)\n {\n \tunsigned long addr = (unsigned long) im-\u003eimage;\n-\tunsigned long ip = ftrace_location(tr-\u003eip);\n \tstruct bpf_tracing_multi_data *data = ptr;\n+\tunsigned long ip = tr-\u003eip;\n \n \t/*\n \t * Different BTF ids get different trampolines, but they can still\n@@ -1649,7 +1655,6 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_ima\n \tif (bpf_trampoline_use_jmp(tr-\u003eflags))\n \t\taddr = ftrace_jmp_set(addr);\n \n-\ttr-\u003efunc.ftrace_managed = true;\n \tftrace_hash_add(data-\u003ereg, data-\u003eentry, ip, addr);\n \ttr-\u003ecur_image = im;\n \treturn 0;\n@@ -1658,13 +1663,12 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_ima\n static int unregister_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags, void *ptr)\n {\n \tunsigned long addr = (unsigned long) tr-\u003ecur_image-\u003eimage;\n-\tunsigned long ip = ftrace_location(tr-\u003eip);\n \tstruct bpf_tracing_multi_data *data = ptr;\n \n \tif (bpf_trampoline_use_jmp(tr-\u003eflags))\n \t\taddr = ftrace_jmp_set(addr);\n \n-\tftrace_hash_add(data-\u003eunreg, data-\u003eentry, ip, addr);\n+\tftrace_hash_add(data-\u003eunreg, data-\u003eentry, tr-\u003eip, addr);\n \ttr-\u003ecur_image = NULL;\n \treturn 0;\n }\n@@ -1673,13 +1677,12 @@ static int modify_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags, struct\n \t\t\t       bool lock_direct_mutex, void *ptr)\n {\n \tunsigned long addr = (unsigned long) im-\u003eimage;\n-\tunsigned long ip = ftrace_location(tr-\u003eip);\n \tstruct bpf_tracing_multi_data *data = ptr;\n \n \tif (bpf_trampoline_use_jmp(tr-\u003eflags))\n \t\taddr = ftrace_jmp_set(addr);\n \n-\tftrace_hash_add(data-\u003emodify, data-\u003eentry, ip, addr);\n+\tftrace_hash_add(data-\u003emodify, data-\u003eentry, tr-\u003eip, addr);\n \ttr-\u003ecur_image = im;\n \treturn 0;\n }\n@@ -1690,12 +1693,6 @@ static const struct bpf_trampoline_ops trampoline_multi_ops = {\n \t.modify_fentry     = modify_fentry_multi,\n };\n \n-static void bpf_trampoline_multi_attach_init(struct bpf_trampoline *tr)\n-{\n-\ttr-\u003emulti_attach.old_image = tr-\u003ecur_image;\n-\ttr-\u003emulti_attach.old_flags = tr-\u003eflags;\n-}\n-\n static void bpf_trampoline_multi_attach_free(struct bpf_trampoline *tr)\n {\n \t/*\n@@ -1712,6 +1709,7 @@ static void bpf_trampoline_multi_attach_free(struct bpf_trampoline *tr)\n \t\tbpf_tramp_image_put(tr-\u003emulti_attach.old_image);\n \n \ttr-\u003emulti_attach.old_image = NULL;\n+\ttr-\u003emulti_attach.new_image = NULL;\n \ttr-\u003emulti_attach.old_flags = 0;\n }\n \n@@ -1723,6 +1721,7 @@ static void bpf_trampoline_multi_attach_rollback(struct bpf_trampoline *tr)\n \ttr-\u003eflags = tr-\u003emulti_attach.old_flags;\n \n \ttr-\u003emulti_attach.old_image = NULL;\n+\ttr-\u003emulti_attach.new_image = NULL;\n \ttr-\u003emulti_attach.old_flags = 0;\n }\n \n@@ -1868,10 +1867,278 @@ void bpf_trampoline_multi_detach(struct bpf_prog *prog,\n #undef for_each_mnode_cnt\n #undef for_each_mnode\n \n+#else\n+\n+void bpf_trampoline_multi_detach(struct bpf_prog *prog,\n+\t\t\t\t struct bpf_tracing_multi_link *link) {}\n+\n #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS \u0026\u0026\n \t  CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS \u0026\u0026\n \t  CONFIG_BPF_SYSCALL */\n \n+#ifdef CONFIG_BPF_SYSCALL\n+\n+static int bpf_text_poke_cmp(const void *a, const void *b)\n+{\n+\tconst struct bpf_text_poke *pa = *(struct bpf_text_poke * const *)a;\n+\tconst struct bpf_text_poke *pb = *(struct bpf_text_poke * const *)b;\n+\tunsigned long ipa = (unsigned long) pa-\u003eip;\n+\tunsigned long ipb = (unsigned long) pb-\u003eip;\n+\n+\treturn (ipa \u003e ipb) - (ipa \u003c ipb);\n+}\n+\n+static int bpf_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)\n+{\n+\tint i, err;\n+\n+\t/*\n+\t * Sort pokes for two purposes:\n+\t * 1. Check duplicated poke target IPs.\n+\t * 2. Sorted poke target IPs would be friendly for poking them on x86,\n+\t *    see arch/x86/kernel/alternative.c::smp_text_poke_batch_add().\n+\t */\n+\tsort_nonatomic(pokes, cnt, sizeof(*pokes), bpf_text_poke_cmp, NULL);\n+\n+\tfor (i = 1; i \u003c cnt; i++)\n+\t\tif (pokes[i - 1]-\u003eip == pokes[i]-\u003eip)\n+\t\t\treturn -EINVAL;\n+\n+\terr = bpf_arch_text_poke_batch(pokes, cnt);\n+\tif (err != -EOPNOTSUPP)\n+\t\treturn err;\n+\n+\tfor (i = 0; i \u003c cnt; i++) {\n+\t\tstruct bpf_text_poke *p = pokes[i];\n+\n+\t\terr = bpf_arch_text_poke(p-\u003eip, p-\u003eold_t, p-\u003enew_t, p-\u003eold_addr, p-\u003enew_addr);\n+\t\tif (err)\n+\t\t\tgoto rollback;\n+\t}\n+\n+\treturn 0;\n+\n+rollback:\n+\tfor (i--; i \u003e= 0; i--) {\n+\t\tstruct bpf_text_poke *p = pokes[i];\n+\n+\t\tWARN_ON_ONCE(bpf_arch_text_poke(p-\u003eip, p-\u003enew_t, p-\u003eold_t, p-\u003enew_addr,\n+\t\t\t\t\t\tp-\u003eold_addr));\n+\t}\n+\treturn err;\n+}\n+\n+static enum bpf_text_poke_type bpf_trampoline_poke_type(const struct bpf_tramp_image *im, u32 flags)\n+{\n+\tif (!im)\n+\t\treturn BPF_MOD_NOP;\n+\n+\treturn bpf_trampoline_use_jmp(flags) ? BPF_MOD_JUMP : BPF_MOD_CALL;\n+}\n+\n+static void bpf_text_poke_init(struct bpf_text_poke *poke, struct bpf_trampoline *tr)\n+{\n+\tstruct bpf_tramp_image *old_image = tr-\u003emulti_attach.old_image;\n+\tstruct bpf_tramp_image *new_image = tr-\u003emulti_attach.new_image;\n+\n+\tpoke-\u003eip = tr-\u003efunc.addr;\n+\tpoke-\u003eold_addr = old_image ? old_image-\u003eimage : NULL;\n+\tpoke-\u003enew_addr = new_image ? new_image-\u003eimage : NULL;\n+\tpoke-\u003eold_t = bpf_trampoline_poke_type(old_image, tr-\u003emulti_attach.old_flags);\n+\tpoke-\u003enew_t = bpf_trampoline_poke_type(new_image, tr-\u003eflags);\n+}\n+\n+static int register_fentry_multi_prog(struct bpf_trampoline *tr,\n+\t\t\t\t      struct bpf_tramp_image *im,\n+\t\t\t\t      void *data __maybe_unused)\n+{\n+\ttr-\u003emulti_attach.new_image = im;\n+\treturn 0;\n+}\n+\n+static int unregister_fentry_multi_prog(struct bpf_trampoline *tr,\n+\t\t\t\t\tu32 orig_flags __maybe_unused,\n+\t\t\t\t\tvoid *data __maybe_unused)\n+{\n+\ttr-\u003emulti_attach.new_image = NULL;\n+\treturn 0;\n+}\n+\n+static int modify_fentry_multi_prog(struct bpf_trampoline *tr,\n+\t\t\t\t    u32 orig_flags __maybe_unused,\n+\t\t\t\t    struct bpf_tramp_image *im,\n+\t\t\t\t    bool lock_direct_mutex __maybe_unused,\n+\t\t\t\t    void *data __maybe_unused)\n+{\n+\ttr-\u003emulti_attach.new_image = im;\n+\treturn 0;\n+}\n+\n+static const struct bpf_trampoline_ops trampoline_multi_prog_ops = {\n+\t.register_fentry   = register_fentry_multi_prog,\n+\t.unregister_fentry = unregister_fentry_multi_prog,\n+\t.modify_fentry     = modify_fentry_multi_prog,\n+};\n+\n+static void bpf_trampoline_multi_prog_commit(struct bpf_trampoline *tr)\n+{\n+\tstruct bpf_tramp_image *old_image = tr-\u003emulti_attach.old_image;\n+\n+\ttr-\u003ecur_image = tr-\u003emulti_attach.new_image;\n+\ttr-\u003emulti_attach.old_image = NULL;\n+\ttr-\u003emulti_attach.new_image = NULL;\n+\ttr-\u003emulti_attach.old_flags = 0;\n+\n+\tif (old_image)\n+\t\tbpf_tramp_image_put(old_image);\n+}\n+\n+static void bpf_trampoline_multi_prog_rollback(struct bpf_trampoline *tr)\n+{\n+\tif (tr-\u003emulti_attach.new_image)\n+\t\tbpf_tramp_image_put(tr-\u003emulti_attach.new_image);\n+\n+\ttr-\u003eflags = tr-\u003emulti_attach.old_flags;\n+\ttr-\u003emulti_attach.old_image = NULL;\n+\ttr-\u003emulti_attach.new_image = NULL;\n+\ttr-\u003emulti_attach.old_flags = 0;\n+}\n+\n+#define for_each_mnode_cnt(mnode, link, cnt) \\\n+\tfor (i = 0, mnode = \u0026link-\u003enodes[i]; i \u003c cnt; i++, mnode = \u0026link-\u003enodes[i])\n+\n+#define for_each_mnode(mnode, link) \\\n+\tfor_each_mnode_cnt(mnode, link, link-\u003enodes_cnt)\n+\n+static int bpf_trampoline_multi_prog_prepare(struct bpf_prog *prog, u32 *ids, u64 *keys,\n+\t\t\t\t\t     struct bpf_tracing_multi_link *link)\n+{\n+\tstruct bpf_attach_target_info tgt_info = {};\n+\tstruct bpf_tracing_multi_node *mnode;\n+\tstruct bpf_trampoline *tr;\n+\tint i, cnt, err;\n+\n+\tfor_each_mnode(mnode, link) {\n+\t\terr = bpf_check_attach_target(NULL, prog, link-\u003etgt_progs[i], ids[i], \u0026tgt_info);\n+\t\tif (err)\n+\t\t\tgoto put_trampolines;\n+\n+\t\ttr = bpf_trampoline_get(keys[i], \u0026tgt_info);\n+\t\tif (!tr) {\n+\t\t\terr = -ENOMEM;\n+\t\t\tgoto put_trampolines;\n+\t\t}\n+\n+\t\tmnode-\u003etrampoline = tr;\n+\t\tmnode-\u003enode.link = \u0026link-\u003elink;\n+\t\tmnode-\u003enode.cookie = link-\u003ecookies ? link-\u003ecookies[i] : 0;\n+\n+\t\tif (prog-\u003eexpected_attach_type == BPF_TRACE_FSESSION_MULTI) {\n+\t\t\tlink-\u003efexits[i].link = \u0026link-\u003elink;\n+\t\t\tlink-\u003efexits[i].cookie = link-\u003ecookies ? link-\u003ecookies[i] : 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+\n+put_trampolines:\n+\tcnt = i;\n+\tfor_each_mnode_cnt(mnode, link, cnt)\n+\t\tbpf_trampoline_put(mnode-\u003etrampoline);\n+\treturn err;\n+}\n+\n+int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,\n+\t\t\t\t     struct bpf_tracing_multi_link *link)\n+{\n+\tstruct bpf_tracing_multi_node *mnode;\n+\tint i, err, linked_cnt = 0;\n+\n+\terr = bpf_trampoline_multi_prog_prepare(prog, ids, keys, link);\n+\tif (err)\n+\t\treturn err;\n+\n+\ttrampoline_lock_all();\n+\n+\tfor_each_mnode(mnode, link) {\n+\t\tbpf_trampoline_multi_attach_init(mnode-\u003etrampoline);\n+\n+\t\tif (link-\u003etgt_progs[i]-\u003eaux-\u003etail_call_reachable)\n+\t\t\tmnode-\u003etrampoline-\u003eflags |= BPF_TRAMP_F_TAIL_CALL_CTX;\n+\n+\t\terr = __bpf_trampoline_link_prog(\u0026mnode-\u003enode, mnode-\u003etrampoline, NULL,\n+\t\t\t\t\t\t \u0026trampoline_multi_prog_ops, NULL);\n+\t\tif (err) {\n+\t\t\tbpf_trampoline_multi_prog_rollback(mnode-\u003etrampoline);\n+\t\t\tgoto rollback;\n+\t\t}\n+\t\tlinked_cnt++;\n+\t}\n+\n+\tfor_each_mnode(mnode, link) {\n+\t\tlink-\u003epokes[i] = \u0026mnode-\u003epoke;\n+\t\tbpf_text_poke_init(link-\u003epokes[i], mnode-\u003etrampoline);\n+\t}\n+\n+\terr = bpf_text_poke_batch(link-\u003epokes, link-\u003enodes_cnt);\n+\tif (err)\n+\t\tgoto rollback;\n+\n+\tfor_each_mnode(mnode, link)\n+\t\tbpf_trampoline_multi_prog_commit(mnode-\u003etrampoline);\n+\n+\ttrampoline_unlock_all();\n+\treturn 0;\n+\n+rollback:\n+\tfor_each_mnode_cnt(mnode, link, linked_cnt) {\n+\t\tbpf_trampoline_remove_prog(mnode-\u003etrampoline, \u0026mnode-\u003enode);\n+\t\tbpf_trampoline_multi_prog_rollback(mnode-\u003etrampoline);\n+\t}\n+\n+\ttrampoline_unlock_all();\n+\n+\tfor_each_mnode(mnode, link)\n+\t\tbpf_trampoline_put(mnode-\u003etrampoline);\n+\treturn err;\n+}\n+\n+void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link)\n+{\n+\tstruct bpf_tracing_multi_node *mnode;\n+\tint i, err;\n+\n+\ttrampoline_lock_all();\n+\n+\tfor_each_mnode(mnode, link) {\n+\t\tbpf_trampoline_multi_attach_init(mnode-\u003etrampoline);\n+\t\terr = __bpf_trampoline_unlink_prog(\u0026mnode-\u003enode, mnode-\u003etrampoline, NULL,\n+\t\t\t\t\t\t   \u0026trampoline_multi_prog_ops, NULL);\n+\t\tif (WARN_ONCE(err, \"__bpf_trampoline_unlink_prog failed: %d\\n\", err))\n+\t\t\tbpf_trampoline_multi_prog_rollback(mnode-\u003etrampoline);\n+\t}\n+\n+\tfor_each_mnode(mnode, link) {\n+\t\tlink-\u003epokes[i] = \u0026mnode-\u003epoke;\n+\t\tbpf_text_poke_init(link-\u003epokes[i], mnode-\u003etrampoline);\n+\t}\n+\n+\tWARN_ON_ONCE(bpf_text_poke_batch(link-\u003epokes, link-\u003enodes_cnt));\n+\n+\tfor_each_mnode(mnode, link)\n+\t\tbpf_trampoline_multi_prog_commit(mnode-\u003etrampoline);\n+\n+\ttrampoline_unlock_all();\n+\n+\tfor_each_mnode(mnode, link)\n+\t\tbpf_trampoline_put(mnode-\u003etrampoline);\n+}\n+\n+#undef for_each_mnode_cnt\n+#undef for_each_mnode\n+\n+#endif /* CONFIG_BPF_SYSCALL */\n+\n static int __init init_trampolines(void)\n {\n \tint i;\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex 2f190abe34489..f2af2bbdd6fb5 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -22284,22 +22284,24 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,\n \t\t\treturn -EOPNOTSUPP;\n \t\t}\n \n-\t\t/*\n-\t\t * *.multi programs don't need an address during program\n-\t\t * verification, we just take the module ref if needed.\n-\t\t */\n-\t\tif (is_tracing_multi_id(prog, btf_id)) {\n+\t\tif (tgt_prog) {\n+\t\t\tif (subprog == 0)\n+\t\t\t\taddr = (long)tgt_prog-\u003ebpf_func;\n+\t\t\telse\n+\t\t\t\taddr = (long)tgt_prog-\u003eaux-\u003efunc[subprog]-\u003ebpf_func;\n+\t\t} else if (is_tracing_multi_id(prog, btf_id)) {\n+\t\t\t/*\n+\t\t\t * *.multi programs don't need an address during program\n+\t\t\t * verification, we just take the module ref if needed.\n+\t\t\t * *.multi programs don't have tgt_prog during program\n+\t\t\t * verification.\n+\t\t\t */\n \t\t\tif (btf_is_module(btf)) {\n \t\t\t\tmod = btf_try_get_module(btf);\n \t\t\t\tif (!mod)\n \t\t\t\t\treturn -ENOENT;\n \t\t\t}\n \t\t\taddr = 0;\n-\t\t} else if (tgt_prog) {\n-\t\t\tif (subprog == 0)\n-\t\t\t\taddr = (long) tgt_prog-\u003ebpf_func;\n-\t\t\telse\n-\t\t\t\taddr = (long) tgt_prog-\u003eaux-\u003efunc[subprog]-\u003ebpf_func;\n \t\t} else {\n \t\t\tif (btf_is_module(btf)) {\n \t\t\t\tmod = btf_try_get_module(btf);\ndiff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c\nindex 195f78db9bdaf..39c911917ae24 100644\n--- a/kernel/trace/bpf_trace.c\n+++ b/kernel/trace/bpf_trace.c\n@@ -3679,15 +3679,19 @@ __bpf_kfunc int bpf_copy_from_user_task_str_dynptr(const struct bpf_dynptr *dptr\n \n __bpf_kfunc_end_defs();\n \n-#if defined(CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS) \u0026\u0026 \\\n-    defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS)\n+static void bpf_put_progs(struct bpf_prog **progs, int cnt);\n \n static void bpf_tracing_multi_link_release(struct bpf_link *link)\n {\n \tstruct bpf_tracing_multi_link *tr_link =\n \t\tcontainer_of(link, struct bpf_tracing_multi_link, link);\n \n-\tbpf_trampoline_multi_detach(link-\u003eprog, tr_link);\n+\tif (tr_link-\u003etgt_progs) {\n+\t\tbpf_trampoline_multi_prog_detach(tr_link);\n+\t\tbpf_put_progs(tr_link-\u003etgt_progs, tr_link-\u003enodes_cnt);\n+\t} else {\n+\t\tbpf_trampoline_multi_detach(link-\u003eprog, tr_link);\n+\t}\n }\n \n static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)\n@@ -3695,6 +3699,8 @@ static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)\n \tstruct bpf_tracing_multi_link *tr_link =\n \t\tcontainer_of(link, struct bpf_tracing_multi_link, link);\n \n+\tkvfree(tr_link-\u003epokes);\n+\tkvfree(tr_link-\u003etgt_progs);\n \tkvfree(tr_link-\u003efexits);\n \tkvfree(tr_link-\u003ecookies);\n \tkvfree(tr_link);\n@@ -3703,15 +3709,16 @@ static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)\n static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,\n \t\t\t\t\t\t struct bpf_link_info *info)\n {\n+\tu32 __user *fids = u64_to_user_ptr(info-\u003etracing_multi.func_btf_ids);\n \tu64 __user *ucookies = u64_to_user_ptr(info-\u003etracing_multi.cookies);\n \tu64 __user *uaddrs = u64_to_user_ptr(info-\u003etracing_multi.addrs);\n \tu32 __user *uids = u64_to_user_ptr(info-\u003etracing_multi.ids);\n \tstruct bpf_tracing_multi_link *tr_link;\n \tu32 ucount = info-\u003etracing_multi.count;\n-\tbool has_cookies, show_addrs;\n+\tbool has_cookies, show_addrs, has_progs;\n \tint err = 0;\n \n-\tif ((uids || ucookies || uaddrs) \u0026\u0026 !ucount)\n+\tif ((uids || ucookies || uaddrs || fids) \u0026\u0026 !ucount)\n \t\treturn -EINVAL;\n \n \ttr_link = container_of(link, struct bpf_tracing_multi_link, link);\n@@ -3719,9 +3726,13 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,\n \tinfo-\u003etracing_multi.attach_type = tr_link-\u003elink.attach_type;\n \tinfo-\u003etracing_multi.count = tr_link-\u003enodes_cnt;\n \tinfo-\u003etracing_multi.btf_obj_id = btf_obj_id(tr_link-\u003elink.prog-\u003eaux-\u003eattach_btf);\n+\thas_progs = !!tr_link-\u003etgt_progs;\n+\tinfo-\u003etracing_multi.flags = has_progs ? BPF_F_TRACING_MULTI_TGT_PROGS : 0;\n \n-\tif (!uids \u0026\u0026 !ucookies \u0026\u0026 !uaddrs)\n+\tif (!uids \u0026\u0026 !ucookies \u0026\u0026 !uaddrs \u0026\u0026 !fids)\n \t\treturn 0;\n+\tif (has_progs != !!fids)\n+\t\treturn -EINVAL;\n \n \tif (ucount \u003c tr_link-\u003enodes_cnt)\n \t\terr = -ENOSPC;\n@@ -3733,20 +3744,27 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,\n \n \tfor (int i = 0; i \u003c ucount; i++) {\n \t\tstruct bpf_tracing_multi_node *mnode = \u0026tr_link-\u003enodes[i];\n+\t\tu32 prog_id, btf_id;\n \t\tu64 addr, cookie;\n-\t\tu32 id;\n \n-\t\tbpf_trampoline_unpack_key(mnode-\u003etrampoline-\u003ekey, NULL, \u0026id);\n+\t\tbpf_trampoline_unpack_key(mnode-\u003etrampoline-\u003ekey, \u0026prog_id, \u0026btf_id);\n \n-\t\taddr = show_addrs ? mnode-\u003etrampoline-\u003eip : 0;\n+\t\tif (!show_addrs)\n+\t\t\taddr = 0;\n+\t\telse if (has_progs)\n+\t\t\taddr = (u64) mnode-\u003etrampoline-\u003efunc.addr;\n+\t\telse\n+\t\t\taddr = mnode-\u003etrampoline-\u003eip;\n \t\tcookie = has_cookies ? tr_link-\u003ecookies[i] : 0;\n \n-\t\tif (uids \u0026\u0026 put_user(id, uids + i))\n+\t\tif (uids \u0026\u0026 put_user(has_progs ? prog_id : btf_id, uids + i))\n \t\t\treturn -EFAULT;\n \t\tif (uaddrs \u0026\u0026 put_user(addr, uaddrs + i))\n \t\t\treturn -EFAULT;\n \t\tif (ucookies \u0026\u0026 put_user(cookie, ucookies + i))\n \t\t\treturn -EFAULT;\n+\t\tif (has_progs \u0026\u0026 put_user((u32) mnode-\u003etrampoline-\u003ekey, fids + i))\n+\t\t\treturn -EFAULT;\n \n \t\tcond_resched();\n \t}\n@@ -3755,26 +3773,45 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,\n }\n \n #ifdef CONFIG_PROC_FS\n+static const char *bpf_prog_func_name(struct bpf_prog *prog, u32 btf_id)\n+{\n+\tconst struct btf *btf = prog-\u003eaux-\u003ebtf;\n+\tconst struct btf_type *t;\n+\n+\tt = btf_type_by_id(btf, btf_id);\n+\tif (!t || !btf_type_is_func(t))\n+\t\treturn \"\";\n+\n+\treturn btf_name_by_offset(btf, t-\u003ename_off);\n+}\n+\n static void bpf_tracing_multi_show_fdinfo(const struct bpf_link *link,\n \t\t\t\t\t  struct seq_file *seq)\n {\n \tstruct bpf_tracing_multi_link *tr_link =\n \t\tcontainer_of(link, struct bpf_tracing_multi_link, link);\n \tbool has_cookies = !!tr_link-\u003ecookies;\n+\tbool has_progs = !!tr_link-\u003etgt_progs;\n \n \tseq_printf(seq, \"attach_type:\\t%u\\n\", tr_link-\u003elink.attach_type);\n \tseq_printf(seq, \"cnt:\\t%u\\n\", tr_link-\u003enodes_cnt);\n \n-\tseq_printf(seq, \"%s\\t %s\\t %s\\t %s\\n\", \"obj-id\", \"btf-id\", \"cookie\", \"func\");\n+\tseq_printf(seq, \"%s\\t %s\\t %s\\t %s\\n\", has_progs ? \"prog-id\" : \"obj-id\", \"btf-id\", \"cookie\",\n+\t\t   \"func\");\n \tfor (int i = 0; i \u003c tr_link-\u003enodes_cnt; i++) {\n \t\tstruct bpf_tracing_multi_node *mnode = \u0026tr_link-\u003enodes[i];\n+\t\tu64 cookie = has_cookies ? tr_link-\u003ecookies[i] : 0;\n \t\tu32 btf_id, obj_id;\n \n \t\tbpf_trampoline_unpack_key(mnode-\u003etrampoline-\u003ekey, \u0026obj_id, \u0026btf_id);\n-\t\tseq_printf(seq, \"%u\\t %u\\t %llu\\t %pS\\n\",\n-\t\t\t   obj_id, btf_id,\n-\t\t\t   has_cookies ? tr_link-\u003ecookies[i] : 0,\n-\t\t\t   (void *) mnode-\u003etrampoline-\u003eip);\n+\t\tif (has_progs)\n+\t\t\tseq_printf(seq, \"%u\\t %u\\t %llu\\t %s\\n\",\n+\t\t\t\t   obj_id, btf_id, cookie,\n+\t\t\t\t   bpf_prog_func_name(tr_link-\u003etgt_progs[i], btf_id));\n+\t\telse\n+\t\t\tseq_printf(seq, \"%u\\t %u\\t %llu\\t %pS\\n\",\n+\t\t\t\t   obj_id, btf_id, cookie,\n+\t\t\t\t   (void *) mnode-\u003etrampoline-\u003eip);\n \n \t\tcond_resched();\n \t}\n@@ -3790,64 +3827,129 @@ static const struct bpf_link_ops bpf_tracing_multi_link_lops = {\n #endif\n };\n \n-static int ids_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)\n+struct tracing_multi_sort_data {\n+\tu64 *keys;\n+\tstruct bpf_prog **progs;\n+\tu32 *ids;\n+\tu64 *cookies;\n+};\n+\n+static int keys_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)\n {\n-\tu32 a = *(u32 *) pa;\n-\tu32 b = *(u32 *) pb;\n+\tconst u64 *key_a = pa, *key_b = pb;\n \n-\treturn (a \u003e b) - (a \u003c b);\n+\treturn (*key_a \u003e *key_b) - (*key_a \u003c *key_b);\n }\n \n-static void ids_swap_r(void *a, void *b, int size __maybe_unused,\n-\t\t       const void *priv __maybe_unused)\n+static void keys_swap_r(void *a, void *b, int size __maybe_unused,\n+\t\t\tconst void *priv __maybe_unused)\n {\n+\tconst struct tracing_multi_sort_data *data = priv;\n+\tstruct bpf_prog **prog_a, **prog_b;\n \tu64 *cookie_a, *cookie_b, *cookies;\n-\tu32 *id_a = a, *id_b = b, *ids;\n-\tvoid **data = (void **) priv;\n+\tu64 *key_a = a, *key_b = b, *keys;\n+\tu32 *id_a, *id_b, *ids;\n \n-\tids     = data[0];\n-\tcookies = data[1];\n+\tkeys    = data-\u003ekeys;\n+\tids     = data-\u003eids;\n+\tcookies = data-\u003ecookies;\n+\tid_a    = ids + (key_a - keys);\n+\tid_b    = ids + (key_b - keys);\n+\n+\tif (data-\u003eprogs) {\n+\t\tprog_a = data-\u003eprogs + (key_a - keys);\n+\t\tprog_b = data-\u003eprogs + (key_b - keys);\n+\t\tswap(*prog_a, *prog_b);\n+\t}\n \n \tif (cookies) {\n \t\tcookie_a = cookies + (id_a - ids);\n \t\tcookie_b = cookies + (id_b - ids);\n \t\tswap(*cookie_a, *cookie_b);\n \t}\n+\n \tswap(*id_a, *id_b);\n+\tswap(*key_a, *key_b);\n }\n \n-static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)\n+static int check_dup_keys(u64 *keys, struct bpf_prog **progs, u32 *ids,\n+\t\t\t  u64 *cookies, u32 cnt)\n {\n-\tvoid *data[2] = { ids, cookies };\n-\tint err = 0;\n+\tstruct tracing_multi_sort_data data = {\n+\t\t.keys = keys,\n+\t\t.progs = progs,\n+\t\t.ids = ids,\n+\t\t.cookies = cookies,\n+\t};\n \n \t/*\n-\t * Sort ids array (together with cookies array if defined)\n-\t * and check it for duplicates. The ids and cookies arrays\n-\t * are left sorted.\n+\t * Sort trampoline keys together with target programs, ids, and cookies,\n+\t * then check for duplicates. The arrays are left sorted.\n \t */\n-\tsort_r_nonatomic(ids, cnt, sizeof(ids[0]), ids_cmp_r, ids_swap_r, data);\n+\tsort_r_nonatomic(keys, cnt, sizeof(keys[0]), keys_cmp_r, keys_swap_r, \u0026data);\n \n-\tfor (int i = 1; i \u003c cnt; i++) {\n-\t\tif (ids[i] == ids[i - 1]) {\n+\tfor (int i = 1; i \u003c cnt; i++)\n+\t\tif (keys[i] == keys[i - 1])\n+\t\t\treturn -EINVAL;\n+\n+\treturn 0;\n+}\n+\n+static void bpf_put_progs(struct bpf_prog **progs, int cnt)\n+{\n+\tint i;\n+\n+\tif (!progs)\n+\t\treturn;\n+\n+\tfor (i = 0; i \u003c cnt; i++)\n+\t\tbpf_prog_put(progs[i]);\n+}\n+\n+static int bpf_get_progs(struct bpf_prog **progs, int *fds, int cnt)\n+{\n+\tint err, i, put_cnt = 0;\n+\tstruct bpf_prog *prog;\n+\n+\tfor (i = 0; i \u003c cnt; i++) {\n+\t\tprog = bpf_prog_get(fds[i]);\n+\t\tif (IS_ERR(prog)) {\n+\t\t\terr = PTR_ERR(prog);\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tprogs[i] = prog;\n+\t\tput_cnt++;\n+\n+\t\tif (prog-\u003etype == BPF_PROG_TYPE_TRACING) {\n \t\t\terr = -EINVAL;\n-\t\t\tbreak;\n+\t\t\tgoto error;\n \t\t}\n \t}\n+\treturn 0;\n+\n+error:\n+\tbpf_put_progs(progs, put_cnt);\n \treturn err;\n }\n \n int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n {\n \tstruct bpf_tracing_multi_link *link = NULL;\n+\tstruct btf *btf = prog-\u003eaux-\u003eattach_btf;\n \tstruct bpf_tramp_node *fexits = NULL;\n \tstruct bpf_link_primer link_primer;\n+\tstruct bpf_text_poke **pokes = NULL;\n+\tu64 *cookies = NULL, *keys = NULL;\n+\tstruct bpf_prog **progs = NULL;\n \tu32 cnt, *ids = NULL;\n \tu64 __user *ucookies;\n-\tu64 *cookies = NULL;\n \tu32 __user *uids;\n+\tint __user *ufds;\n+\tint *fds = NULL;\n \tint err;\n \n+\tufds = u64_to_user_ptr(attr-\u003elink_create.tracing_multi.fds);\n \tuids = u64_to_user_ptr(attr-\u003elink_create.tracing_multi.ids);\n \tcnt = attr-\u003elink_create.tracing_multi.cnt;\n \n@@ -3858,6 +3960,9 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n \tif (attr-\u003elink_create.flags || attr-\u003elink_create.target_fd)\n \t\treturn -EINVAL;\n \n+\tif (!ufds \u0026\u0026 !IS_ENABLED(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS))\n+\t\treturn -EOPNOTSUPP;\n+\n \tids = kvmalloc_objs(*ids, cnt);\n \tif (!ids)\n \t\treturn -ENOMEM;\n@@ -3867,6 +3972,37 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n \t\tgoto error;\n \t}\n \n+\tif (ufds) {\n+\t\tfds = kvmalloc_objs(*fds, cnt);\n+\t\tif (!fds) {\n+\t\t\terr = -ENOMEM;\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tif (copy_from_user(fds, ufds, cnt * sizeof(*fds))) {\n+\t\t\terr = -EFAULT;\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tprogs = kvmalloc_objs(*progs, cnt);\n+\t\tif (!progs) {\n+\t\t\terr = -ENOMEM;\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\terr = bpf_get_progs(progs, fds, cnt);\n+\t\tif (err) {\n+\t\t\tcnt = 0;\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tpokes = kvmalloc_objs(*pokes, cnt);\n+\t\tif (!pokes) {\n+\t\t\terr = -ENOMEM;\n+\t\t\tgoto error;\n+\t\t}\n+\t}\n+\n \tucookies = u64_to_user_ptr(attr-\u003elink_create.tracing_multi.cookies);\n \tif (ucookies) {\n \t\tcookies = kvmalloc_objs(*cookies, cnt);\n@@ -3880,7 +4016,16 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n \t\t}\n \t}\n \n-\terr = check_dup_ids(ids, cookies, cnt);\n+\tkeys = kvmalloc_objs(*keys, cnt);\n+\tif (!keys) {\n+\t\terr = -ENOMEM;\n+\t\tgoto error;\n+\t}\n+\n+\tfor (int i = 0; i \u003c cnt; i++)\n+\t\tkeys[i] = bpf_trampoline_compute_key(progs ? progs[i] : NULL, btf, ids[i]);\n+\n+\terr = check_dup_keys(keys, progs, ids, cookies, cnt);\n \tif (err)\n \t\tgoto error;\n \n@@ -3908,28 +4053,32 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n \tlink-\u003enodes_cnt = cnt;\n \tlink-\u003ecookies = cookies;\n \tlink-\u003efexits = fexits;\n+\tlink-\u003etgt_progs = progs;\n+\tlink-\u003epokes = pokes;\n \n-\terr = bpf_trampoline_multi_attach(prog, ids, link);\n+\tif (progs)\n+\t\terr = bpf_trampoline_multi_prog_attach(prog, ids, keys, link);\n+\telse\n+\t\terr = bpf_trampoline_multi_attach(prog, ids, link);\n \tkvfree(ids);\n+\tkvfree(keys);\n+\tkvfree(fds);\n \tif (err) {\n+\t\tbpf_put_progs(progs, cnt);\n \t\tbpf_link_cleanup(\u0026link_primer);\n \t\treturn err;\n \t}\n \treturn bpf_link_settle(\u0026link_primer);\n \n error:\n+\tbpf_put_progs(progs, cnt);\n \tkvfree(fexits);\n \tkvfree(cookies);\n \tkvfree(ids);\n+\tkvfree(keys);\n+\tkvfree(fds);\n+\tkvfree(progs);\n+\tkvfree(pokes);\n \tkvfree(link);\n \treturn err;\n }\n-\n-#else\n-\n-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n-{\n-\treturn -EOPNOTSUPP;\n-}\n-\n-#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS \u0026\u0026 CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS */\ndiff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c\nindex 5cffa2d283b47..da7e430b14c8a 100644\n--- a/tools/bpf/bpftool/link.c\n+++ b/tools/bpf/bpftool/link.c\n@@ -422,12 +422,31 @@ show_uprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)\n \tjsonw_end_array(json_wtr);\n }\n \n+#define BPF_PROG_PREFIX\t\t\"bpf_prog_\"\n+#define BPF_PROG_PREFIX_LEN\t(sizeof(BPF_PROG_PREFIX) - 1)\n+\n+static const char *\n+sym_name_trim_prefix(struct kernel_sym *sym, bool is_prog)\n+{\n+\tint prefix_len;\n+\n+\tif (!is_prog)\n+\t\treturn sym-\u003ename;\n+\n+\t/* Ref kernel/bpf/core.c::bpf_prog_ksym_set_name() */\n+\tprefix_len  = BPF_PROG_PREFIX_LEN;\n+\tprefix_len += BPF_TAG_SIZE * 2;\n+\tif (sym-\u003ename[prefix_len] != '\\0')\n+\t\tprefix_len += 1;\t\t/* skip the '_' */\n+\treturn sym-\u003ename + prefix_len;\n+}\n+\n static void\n show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)\n {\n-\tbool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;\n+\tbool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;\n \t__u64 *addrs, *cookies;\n-\t__u32 i, *ids;\n+\t__u32 i, *ids, *fids;\n \n \tif (!dd.sym_count)\n \t\tkernel_syms_load(\u0026dd);\n@@ -443,6 +462,8 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)\n \tids = u64_to_u32_arr(info-\u003etracing_multi.ids);\n \taddrs = u64_to_arr(info-\u003etracing_multi.addrs);\n \tcookies = u64_to_arr(info-\u003etracing_multi.cookies);\n+\tfids = u64_to_u32_arr(info-\u003etracing_multi.func_btf_ids);\n+\ttgt_progs = info-\u003etracing_multi.flags \u0026 BPF_F_TRACING_MULTI_TGT_PROGS;\n \n \tfor (i = 0; i \u003c info-\u003etracing_multi.count; i++) {\n \t\tstruct kernel_sym *sym;\n@@ -451,10 +472,12 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)\n \t\tsym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;\n \n \t\tjsonw_start_object(wtr);\n-\t\tjsonw_uint_field(wtr, \"id\", ids[i]);\n+\t\tjsonw_uint_field(wtr, tgt_progs ? \"prog_id\" : \"id\", ids[i]);\n+\t\tif (tgt_progs)\n+\t\t\tjsonw_uint_field(wtr, \"func_btf_id\", fids[i]);\n \t\tjsonw_uint_field(wtr, \"addr\", addr);\n \t\tif (sym) {\n-\t\t\tjsonw_string_field(wtr, \"func\", sym-\u003ename);\n+\t\t\tjsonw_string_field(wtr, \"func\", sym_name_trim_prefix(sym, tgt_progs));\n \t\t\tif (sym-\u003emodule[0] == '\\0') {\n \t\t\t\tjsonw_name(wtr, \"module\");\n \t\t\t\tjsonw_null(wtr);\n@@ -903,9 +926,9 @@ static void show_uprobe_multi_plain(struct bpf_link_info *info)\n \n static void show_tracing_multi_plain(struct bpf_link_info *info)\n {\n-\tbool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;\n+\tbool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;\n \t__u64 *addrs, *cookies;\n-\t__u32 i, *ids;\n+\t__u32 i, *ids, *fids;\n \n \tif (!info-\u003etracing_multi.count)\n \t\treturn;\n@@ -919,12 +942,18 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)\n \tprintf(\"btf_obj_id %u  \", info-\u003etracing_multi.btf_obj_id);\n \tprintf(\"count %u  \", info-\u003etracing_multi.count);\n \n-\tprintf(\"\\n\\t%-16s %-16s %-16s %s\",\n-\t       \"btf_id\", \"addr\", \"cookie\", \"func [module]\");\n+\ttgt_progs = info-\u003etracing_multi.flags \u0026 BPF_F_TRACING_MULTI_TGT_PROGS;\n+\tif (tgt_progs)\n+\t\tprintf(\"\\n\\t%-16s %-16s %-16s %-16s %s\",\n+\t\t       \"prog_id\", \"func_btf_id\", \"addr\", \"cookie\", \"func [module]\");\n+\telse\n+\t\tprintf(\"\\n\\t%-16s %-16s %-16s %s\",\n+\t\t       \"btf_id\", \"addr\", \"cookie\", \"func [module]\");\n \n \tids = u64_to_u32_arr(info-\u003etracing_multi.ids);\n \taddrs = u64_to_arr(info-\u003etracing_multi.addrs);\n \tcookies = u64_to_arr(info-\u003etracing_multi.cookies);\n+\tfids = u64_to_u32_arr(info-\u003etracing_multi.func_btf_ids);\n \n \tfor (i = 0; i \u003c info-\u003etracing_multi.count; i++) {\n \t\t__u64 addr = addrs[i];\n@@ -932,9 +961,13 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)\n \n \t\tsym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;\n \n-\t\tprintf(\"\\n\\t%-16u %016llx %-16llu\", ids[i], addr, cookies[i]);\n+\t\tif (tgt_progs)\n+\t\t\tprintf(\"\\n\\t%-16u %-16u %016llx %-16llu\",\n+\t\t\t       ids[i], fids[i], addr, cookies[i]);\n+\t\telse\n+\t\t\tprintf(\"\\n\\t%-16u %016llx %-16llu\", ids[i], addr, cookies[i]);\n \t\tif (sym) {\n-\t\t\tprintf(\" %s\", sym-\u003ename);\n+\t\t\tprintf(\" %s\", sym_name_trim_prefix(sym, tgt_progs));\n \t\t\tif (sym-\u003emodule[0] != '\\0')\n \t\t\t\tprintf(\" [%s]\", sym-\u003emodule);\n \t\t}\n@@ -1140,7 +1173,7 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)\n static int do_show_link(int fd)\n {\n \t__u64 *ref_ctr_offsets = NULL, *offsets = NULL, *cookies = NULL;\n-\t__u32 *ids = NULL;\n+\t__u32 *ids = NULL, *func_btf_ids = NULL;\n \tstruct bpf_link_info info;\n \t__u32 len = sizeof(info);\n \tchar path_buf[PATH_MAX];\n@@ -1229,12 +1262,16 @@ static int do_show_link(int fd)\n \tif (info.type == BPF_LINK_TYPE_TRACING_MULTI \u0026\u0026 !info.tracing_multi.ids) {\n \t\tcount = info.tracing_multi.count;\n \t\tif (count) {\n+\t\t\tbool tgt_progs = info.tracing_multi.flags \u0026 BPF_F_TRACING_MULTI_TGT_PROGS;\n+\n \t\t\tids = calloc(count, sizeof(__u32));\n \t\t\taddrs = calloc(count, sizeof(__u64));\n \t\t\tcookies = calloc(count, sizeof(__u64));\n-\t\t\tif (!ids || !addrs || !cookies) {\n+\t\t\tfunc_btf_ids = tgt_progs ? calloc(count, sizeof(__u32)) : NULL;\n+\t\t\tif (!ids || !addrs || !cookies || (tgt_progs \u0026\u0026 !func_btf_ids)) {\n \t\t\t\tp_err(\"mem alloc failed\");\n \t\t\t\tclose(fd);\n+\t\t\t\tfree(func_btf_ids);\n \t\t\t\tfree(cookies);\n \t\t\t\tfree(addrs);\n \t\t\t\tfree(ids);\n@@ -1243,6 +1280,7 @@ static int do_show_link(int fd)\n \t\t\tinfo.tracing_multi.ids = ptr_to_u64(ids);\n \t\t\tinfo.tracing_multi.addrs = ptr_to_u64(addrs);\n \t\t\tinfo.tracing_multi.cookies = ptr_to_u64(cookies);\n+\t\t\tinfo.tracing_multi.func_btf_ids = ptr_to_u64(func_btf_ids);\n \t\t\tgoto again;\n \t\t}\n \t}\n@@ -1282,6 +1320,7 @@ static int do_show_link(int fd)\n \t\tshow_link_close_plain(fd, \u0026info);\n \n \tfree(ref_ctr_offsets);\n+\tfree(func_btf_ids);\n \tfree(cookies);\n \tfree(offsets);\n \tfree(addrs);\ndiff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h\nindex 6f70db7515dd4..60998ea1381ce 100644\n--- a/tools/include/uapi/linux/bpf.h\n+++ b/tools/include/uapi/linux/bpf.h\n@@ -1927,6 +1927,8 @@ union bpf_attr {\n \t\t\t\t__aligned_u64\tids;\n \t\t\t\t__aligned_u64\tcookies;\n \t\t\t\t__u32\t\tcnt;\n+\t\t\t\t__u32\t\t:32;\n+\t\t\t\t__aligned_u64\tfds;\n \t\t\t} tracing_multi;\n \t\t};\n \t} link_create;\n@@ -6815,6 +6817,10 @@ struct sk_reuseport_md {\n \n #define BPF_TAG_SIZE\t8\n \n+enum {\n+\tBPF_F_TRACING_MULTI_TGT_PROGS = (1U \u003c\u003c 0),\n+};\n+\n struct bpf_prog_info {\n \t__u32 type;\n \t__u32 id;\n@@ -6974,10 +6980,11 @@ struct bpf_link_info {\n \t\t\t__u32 attach_type;\n \t\t\t__u32 count; /* in/out: tracing_multi target count */\n \t\t\t__u32 btf_obj_id;\n-\t\t\t__u32 :32;\n+\t\t\t__u32 flags;\n \t\t\t__aligned_u64 ids;\n \t\t\t__aligned_u64 addrs;\n \t\t\t__aligned_u64 cookies;\n+\t\t\t__aligned_u64 func_btf_ids;\n \t\t} tracing_multi;\n \t\tstruct {\n \t\t\t__u32 type; /* enum bpf_perf_event_type */\ndiff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c\nindex b49822d212aed..4a78ccba9df2d 100644\n--- a/tools/lib/bpf/bpf.c\n+++ b/tools/lib/bpf/bpf.c\n@@ -852,6 +852,7 @@ int bpf_link_create(int prog_fd, int target_fd,\n \t\tattr.link_create.tracing_multi.ids = ptr_to_u64(OPTS_GET(opts, tracing_multi.ids, 0));\n \t\tattr.link_create.tracing_multi.cookies = ptr_to_u64(OPTS_GET(opts, tracing_multi.cookies, 0));\n \t\tattr.link_create.tracing_multi.cnt = OPTS_GET(opts, tracing_multi.cnt, 0);\n+\t\tattr.link_create.tracing_multi.fds = ptr_to_u64(OPTS_GET(opts, tracing_multi.fds, 0));\n \t\tif (!OPTS_ZEROED(opts, tracing_multi))\n \t\t\treturn libbpf_err(-EINVAL);\n \t\tbreak;\ndiff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h\nindex 826d9cc9ab65d..cc37cf622dd85 100644\n--- a/tools/lib/bpf/bpf.h\n+++ b/tools/lib/bpf/bpf.h\n@@ -474,6 +474,8 @@ struct bpf_link_create_opts {\n \t\t\tconst __u32 *ids;\n \t\t\tconst __u64 *cookies;\n \t\t\t__u32 cnt;\n+\t\t\t__u32 :32;\n+\t\t\tconst int *fds;\n \t\t} tracing_multi;\n \t};\n \tsize_t :0;\ndiff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c\nindex cb09ded907732..72e2459e93399 100644\n--- a/tools/lib/bpf/libbpf.c\n+++ b/tools/lib/bpf/libbpf.c\n@@ -11604,7 +11604,7 @@ int libbpf_find_vmlinux_btf_id(const char *name,\n \treturn libbpf_err(err);\n }\n \n-static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd)\n+int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd)\n {\n \tstruct bpf_prog_info info;\n \t__u32 info_len = sizeof(info);\n@@ -13671,10 +13671,12 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa\n {\n \tLIBBPF_OPTS(bpf_link_create_opts, lopts);\n \tint prog_fd, link_fd, err, cnt;\n+\tstruct bpf_link *link = NULL;\n \t__u32 *free_ids = NULL;\n-\tstruct bpf_link *link;\n \tconst __u64 *cookies;\n+\tconst char **funcs;\n \tconst __u32 *ids;\n+\tconst int *fds;\n \n \tif (!OPTS_VALID(opts, bpf_tracing_multi_opts))\n \t\treturn libbpf_err_ptr(-EINVAL);\n@@ -13689,12 +13691,22 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa\n \tcnt = OPTS_GET(opts, cnt, 0);\n \tids = OPTS_GET(opts, ids, NULL);\n \tcookies = OPTS_GET(opts, cookies, NULL);\n+\tfds = OPTS_GET(opts, fds, NULL);\n+\tfuncs = OPTS_GET(opts, funcs, NULL);\n \n-\tif (!!ids != !!cnt)\n+\tif (ids \u0026\u0026 fds)\n+\t\treturn libbpf_err_ptr(-EINVAL);\n+\tif (!!fds != !!funcs)\n+\t\treturn libbpf_err_ptr(-EINVAL);\n+\tif (fds \u0026\u0026 !cnt)\n \t\treturn libbpf_err_ptr(-EINVAL);\n-\tif (pattern \u0026\u0026 (ids || cookies))\n+\tif (ids \u0026\u0026 !cnt)\n \t\treturn libbpf_err_ptr(-EINVAL);\n-\tif (!pattern \u0026\u0026 !ids)\n+\tif (!fds \u0026\u0026 !ids \u0026\u0026 cnt)\n+\t\treturn libbpf_err_ptr(-EINVAL);\n+\tif (pattern \u0026\u0026 (fds || ids || cookies))\n+\t\treturn libbpf_err_ptr(-EINVAL);\n+\tif (!pattern \u0026\u0026 !ids \u0026\u0026 !fds)\n \t\treturn libbpf_err_ptr(-EINVAL);\n \n \tif (pattern) {\n@@ -13704,11 +13716,32 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa\n \t\tif (cnt == 0)\n \t\t\treturn libbpf_err_ptr(-EINVAL);\n \t\tids = (const __u32 *) free_ids;\n+\t} else if (fds) {\n+\t\tsize_t cap = 0;\n+\t\tint i;\n+\n+\t\terr = libbpf_ensure_mem((void **) \u0026free_ids, \u0026cap, sizeof(*free_ids), cnt);\n+\t\tif (err)\n+\t\t\treturn libbpf_err_ptr(err);\n+\n+\t\tfor (i = 0; i \u003c cnt; i++) {\n+\t\t\tif (!funcs[i]) {\n+\t\t\t\terr = -EINVAL;\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\t\t\terr = libbpf_find_prog_btf_id(funcs[i], fds[i], prog-\u003eobj-\u003etoken_fd);\n+\t\t\tif (err \u003c 0)\n+\t\t\t\tgoto error;\n+\n+\t\t\tfree_ids[i] = err;\n+\t\t}\n+\t\tids = (const __u32 *) free_ids;\n \t}\n \n \tlopts.tracing_multi.ids = ids;\n \tlopts.tracing_multi.cookies = cookies;\n \tlopts.tracing_multi.cnt = cnt;\n+\tlopts.tracing_multi.fds = fds;\n \n \tlink = calloc(1, sizeof(*link));\n \tif (!link) {\ndiff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h\nindex 03f794f4adb03..612f3e17ebc25 100644\n--- a/tools/lib/bpf/libbpf.h\n+++ b/tools/lib/bpf/libbpf.h\n@@ -746,10 +746,12 @@ struct bpf_tracing_multi_opts {\n \tconst __u32 *ids;\n \tconst __u64 *cookies;\n \tsize_t cnt;\n+\tconst int *fds;\n+\tconst char **funcs;\n \tsize_t :0;\n };\n \n-#define bpf_tracing_multi_opts__last_field cnt\n+#define bpf_tracing_multi_opts__last_field funcs\n \n LIBBPF_API struct bpf_link *\n bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pattern,\ndiff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h\nindex 4e45dfacb548a..d4e899181bddc 100644\n--- a/tools/lib/bpf/libbpf_internal.h\n+++ b/tools/lib/bpf/libbpf_internal.h\n@@ -439,6 +439,7 @@ int btf_load_into_kernel(struct btf *btf,\n \t\t\t char *log_buf, size_t log_sz, __u32 log_level,\n \t\t\t int token_fd);\n struct btf *btf_load_from_kernel(__u32 id, struct btf *base_btf, int token_fd);\n+int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd);\n \n struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf);\n void btf_get_kernel_prefix_kind(enum bpf_attach_type attach_type,\ndiff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile\nindex 80d8bbbc3084a..23bed732d1bdd 100644\n--- a/tools/testing/selftests/bpf/Makefile\n+++ b/tools/testing/selftests/bpf/Makefile\n@@ -625,6 +625,7 @@ $(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/bloom_filter_bench.skel.h\n $(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop_bench.skel.h\n $(OUTPUT)/bench_bpf_for.o: $(OUTPUT)/bpf_for_bench.skel.h\n $(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_bench.skel.h\n+$(OUTPUT)/bench_tracing_multi_attach_progs.o: $(OUTPUT)/tracing_multi_attach_progs.skel.h\n $(OUTPUT)/bench_bpf_hashmap_full_update.o: $(OUTPUT)/bpf_hashmap_full_update_bench.skel.h\n $(OUTPUT)/bench_local_storage.o: $(OUTPUT)/local_storage_bench.skel.h\n $(OUTPUT)/bench_local_storage_rcu_tasks_trace.o: $(OUTPUT)/local_storage_rcu_tasks_trace_bench.skel.h\ndiff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c\nindex d5f494184f9d1..c7502187e6541 100644\n--- a/tools/testing/selftests/bpf/bench.c\n+++ b/tools/testing/selftests/bpf/bench.c\n@@ -529,6 +529,9 @@ extern const struct bench bench_trig_fmodret;\n extern const struct bench bench_trig_tp;\n extern const struct bench bench_trig_rawtp;\n \n+/* tracing_multi link attachment benchmark */\n+extern const struct bench bench_tracing_multi_attach_progs;\n+\n /* uprobe/uretprobe benchmarks */\n extern const struct bench bench_trig_uprobe_nop;\n extern const struct bench bench_trig_uretprobe_nop;\n@@ -615,6 +618,8 @@ static const struct bench *benchs[] = {\n \t\u0026bench_trig_fmodret,\n \t\u0026bench_trig_tp,\n \t\u0026bench_trig_rawtp,\n+\t/* tracing_multi */\n+\t\u0026bench_tracing_multi_attach_progs,\n \t/* uprobes */\n \t\u0026bench_trig_uprobe_nop,\n \t\u0026bench_trig_uretprobe_nop,\ndiff --git a/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c\nnew file mode 100644\nindex 0000000000000..6cc6851eb488e\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c\n@@ -0,0 +1,193 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#include \u003cstdio.h\u003e\n+#include \u003cstring.h\u003e\n+#include \"bench.h\"\n+#include \"testing_helpers.h\"\n+#include \"tracing_multi_attach_progs.skel.h\"\n+#include \"bpf/libbpf_internal.h\"\n+\n+#define TARGET_CNT 1000\n+\n+static struct ctx {\n+\tstruct tracing_multi_attach_progs *targets[TARGET_CNT];\n+\tstruct tracing_multi_attach_progs *fentries[TARGET_CNT];\n+\tstruct tracing_multi_attach_progs *fentry_multi;\n+\tint target_fds[TARGET_CNT];\n+\t__u32 target_btf_ids[TARGET_CNT];\n+\tint fentry_prog_fds[TARGET_CNT];\n+\tint fentry_multi_prog_fd;\n+} ctx;\n+\n+static void prepare(void)\n+{\n+\tint err, i;\n+\n+\tsetup_libbpf();\n+\n+\tfor (i = 0; i \u003c TARGET_CNT; i++) {\n+\t\tstruct tracing_multi_attach_progs *target;\n+\t\tint btf_id, fd, obj_token_fd;\n+\n+\t\ttarget = tracing_multi_attach_progs__open();\n+\t\tif (!target) {\n+\t\t\tfprintf(stderr, \"failed to open target program %d\\n\", i);\n+\t\t\texit(1);\n+\t\t}\n+\n+\t\tbpf_program__set_autoload(target-\u003eprogs.dummy_fentry, false);\n+\t\tbpf_program__set_autoload(target-\u003eprogs.dummy_fentry_multi, false);\n+\t\terr = tracing_multi_attach_progs__load(target);\n+\t\tif (err) {\n+\t\t\tfprintf(stderr, \"failed to load target program %d: %s\\n\",\n+\t\t\t\ti, strerror(-err));\n+\t\t\texit(1);\n+\t\t}\n+\n+\t\tfd = bpf_program__fd(target-\u003eprogs.target);\n+\t\tobj_token_fd = bpf_object__token_fd(target-\u003eobj);\n+\t\tobj_token_fd = obj_token_fd \u003c 0 ? 0 : obj_token_fd;\n+\t\tbtf_id = libbpf_find_prog_btf_id(\"target\", fd, obj_token_fd);\n+\t\tif (btf_id \u003c= 0) {\n+\t\t\tfprintf(stderr, \"failed to find target BTF ID: %s\\n\",\n+\t\t\t\tstrerror(-btf_id));\n+\t\t\texit(1);\n+\t\t}\n+\n+\t\tctx.targets[i] = target;\n+\t\tctx.target_fds[i] = fd;\n+\t\tctx.target_btf_ids[i] = btf_id;\n+\t}\n+}\n+\n+static long create_and_attach_fentry(void)\n+{\n+\tint link_fds[TARGET_CNT];\n+\tlong start_ns, end_ns;\n+\tint err, i, j;\n+\n+\tstart_ns = get_time_ns();\n+\n+\t/* An ordinary fentry program is bound to one target when it is loaded. */\n+\tfor (i = 0; i \u003c TARGET_CNT; i++) {\n+\t\tstruct tracing_multi_attach_progs *fentry;\n+\n+\t\tfentry = tracing_multi_attach_progs__open();\n+\t\tif (!fentry) {\n+\t\t\tfprintf(stderr, \"failed to open fentry program %d\\n\", i);\n+\t\t\texit(1);\n+\t\t}\n+\n+\t\tbpf_program__set_autoload(fentry-\u003eprogs.target, false);\n+\t\tbpf_program__set_autoload(fentry-\u003eprogs.dummy_fentry_multi, false);\n+\t\terr = bpf_program__set_attach_target(fentry-\u003eprogs.dummy_fentry, ctx.target_fds[i],\n+\t\t\t\t\t\t     \"target\");\n+\t\terr = err ?: tracing_multi_attach_progs__load(fentry);\n+\t\tif (err) {\n+\t\t\tfprintf(stderr, \"failed to load fentry program %d: %s\\n\",\n+\t\t\t\ti, strerror(-err));\n+\t\t\texit(1);\n+\t\t}\n+\n+\t\tctx.fentries[i] = fentry;\n+\t\tctx.fentry_prog_fds[i] = bpf_program__fd(fentry-\u003eprogs.dummy_fentry);\n+\t}\n+\n+\tfor (i = 0; i \u003c TARGET_CNT; i++) {\n+\t\tlink_fds[i] = bpf_link_create(ctx.fentry_prog_fds[i], 0, BPF_TRACE_FENTRY, NULL);\n+\t\tif (link_fds[i] \u003c 0) {\n+\t\t\terr = errno;\n+\t\t\tfor (j = 0; j \u003c i; j++)\n+\t\t\t\tclose(link_fds[j]);\n+\t\t\tfprintf(stderr, \"failed to create fentry link %d: %s\\n\",\n+\t\t\t\ti, strerror(err));\n+\t\t\texit(1);\n+\t\t}\n+\t}\n+\tend_ns = get_time_ns();\n+\n+\tfor (i = 0; i \u003c TARGET_CNT; i++)\n+\t\tclose(link_fds[i]);\n+\n+\treturn end_ns - start_ns;\n+}\n+\n+static long create_and_attach_fentry_multi(void)\n+{\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts);\n+\tlong start_ns, end_ns;\n+\tint err, link_fd;\n+\n+\topts.tracing_multi.ids = ctx.target_btf_ids;\n+\topts.tracing_multi.fds = ctx.target_fds;\n+\topts.tracing_multi.cnt = TARGET_CNT;\n+\n+\tstart_ns = get_time_ns();\n+\n+\tctx.fentry_multi = tracing_multi_attach_progs__open();\n+\tif (!ctx.fentry_multi) {\n+\t\tfprintf(stderr, \"failed to open fentry.multi program\\n\");\n+\t\texit(1);\n+\t}\n+\n+\tbpf_program__set_autoload(ctx.fentry_multi-\u003eprogs.target, false);\n+\tbpf_program__set_autoload(ctx.fentry_multi-\u003eprogs.dummy_fentry, false);\n+\terr = tracing_multi_attach_progs__load(ctx.fentry_multi);\n+\tif (err) {\n+\t\tfprintf(stderr, \"failed to load fentry.multi program: %s\\n\",\n+\t\t\tstrerror(-err));\n+\t\texit(1);\n+\t}\n+\n+\tctx.fentry_multi_prog_fd = bpf_program__fd(ctx.fentry_multi-\u003eprogs.dummy_fentry_multi);\n+\tlink_fd = bpf_link_create(ctx.fentry_multi_prog_fd, 0, BPF_TRACE_FENTRY_MULTI, \u0026opts);\n+\tend_ns = get_time_ns();\n+\tif (link_fd \u003c 0) {\n+\t\terr = errno;\n+\t\tfprintf(stderr, \"failed to create fentry.multi link: %s\\n\",\n+\t\t\tstrerror(err));\n+\t\texit(1);\n+\t}\n+\n+\tclose(link_fd);\n+\treturn end_ns - start_ns;\n+}\n+\n+static void cleanup(void)\n+{\n+\tint i;\n+\n+\ttracing_multi_attach_progs__destroy(ctx.fentry_multi);\n+\tfor (i = 0; i \u003c TARGET_CNT; i++) {\n+\t\ttracing_multi_attach_progs__destroy(ctx.fentries[i]);\n+\t\ttracing_multi_attach_progs__destroy(ctx.targets[i]);\n+\t}\n+}\n+\n+static void setup(void)\n+{\n+\tdouble fentry_multi_ms, fentry_ms;\n+\tlong fentry_multi_ns, fentry_ns;\n+\n+\tprepare();\n+\tfentry_ns = create_and_attach_fentry();\n+\tfentry_multi_ns = create_and_attach_fentry_multi();\n+\tfentry_ms = fentry_ns / 1000000.0;\n+\tfentry_multi_ms = fentry_multi_ns / 1000000.0;\n+\n+\tprintf(\"%s: prepared %d identical BPF program targets\\n\",\n+\t       bench-\u003ename, TARGET_CNT);\n+\tprintf(\"%s: fentry created and attached %d programs/links in %-.3lfms\\n\",\n+\t       bench-\u003ename, TARGET_CNT, fentry_ms);\n+\tprintf(\"%s: fentry.multi created one program and attached one %d-target link in %-.3lfms\\n\",\n+\t       bench-\u003ename, TARGET_CNT, fentry_multi_ms);\n+\tprintf(\"%s: fentry.multi creation/attachment speedup is %-.2lfx\\n\",\n+\t       bench-\u003ename, fentry_ms / fentry_multi_ms);\n+\n+\tcleanup();\n+\texit(0);\n+}\n+\n+const struct bench bench_tracing_multi_attach_progs = {\n+\t.name = \"tracing-multi-attach-progs\",\n+\t.setup = setup,\n+};\ndiff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c\nindex 0918321c8e63d..422e94f134094 100644\n--- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c\n+++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c\n@@ -3,11 +3,13 @@\n \n #include \u003cstring.h\u003e\n #include \u003clinux/bpf.h\u003e\n+#include \u003clinux/kallsyms.h\u003e\n #include \u003clinux/limits.h\u003e\n #include \u003cbpf/btf.h\u003e\n #include \u003ctest_progs.h\u003e\n #include \"trace_helpers.h\"\n #include \"test_fill_link_info.skel.h\"\n+#include \"tracing_multi_bpf.skel.h\"\n #include \"bpf/libbpf_internal.h\"\n \n #define TP_CAT \"sched\"\n@@ -39,8 +41,19 @@ struct tmulti_target {\n \t__u64 addr;\n \t__u64 cookie;\n \t__u32 id;\n+\t__u32 func_btf_id;\n };\n \n+static const char *tmulti_bpf_funcs[] = {\n+\t\"target_1\",\n+\t\"target_2\",\n+};\n+\n+static __u64 tmulti_bpf_fentry_cookies[] = { 0xfeed01, 0xfeed02 };\n+static __u64 tmulti_bpf_fexit_cookies[] = { 0xfeed11, 0xfeed12 };\n+static __u64 tmulti_bpf_fsession_cookies[] = { 0xfeed21, 0xfeed22 };\n+#define TRACING_MULTI_BPF_CNT ARRAY_SIZE(tmulti_bpf_funcs)\n+\n #define UPROBE_FILE \"/proc/self/exe\"\n static ssize_t uprobe_offset;\n /* uprobe attach point */\n@@ -421,14 +434,28 @@ static int tmulti_target_cmp(const void *a, const void *b)\n \treturn (ta-\u003eid \u003e tb-\u003eid) - (ta-\u003eid \u003c tb-\u003eid);\n }\n \n+static int setup_tmulti_btf_obj_id(const struct bpf_program *prog, __u32 *btf_obj_id)\n+{\n+\tstruct bpf_prog_info prog_info = {};\n+\t__u32 len = sizeof(prog_info);\n+\tint err;\n+\n+\terr = bpf_prog_get_info_by_fd(bpf_program__fd(prog), \u0026prog_info, \u0026len);\n+\tif (!ASSERT_OK(err, \"bpf_prog_get_info_by_fd\"))\n+\t\treturn -1;\n+\tif (!ASSERT_GT(prog_info.attach_btf_obj_id, 0, \"attach_btf_obj_id\"))\n+\t\treturn -1;\n+\n+\t*btf_obj_id = prog_info.attach_btf_obj_id;\n+\treturn 0;\n+}\n+\n static int setup_tmulti_targets(const struct bpf_program *prog,\n \t\t\t\tstruct tmulti_target *targets,\n \t\t\t\t__u32 *btf_obj_id)\n {\n-\tstruct bpf_prog_info prog_info;\n-\t__u32 len = sizeof(prog_info);\n \tstruct btf *btf;\n-\tint err, i;\n+\tint i;\n \t__s32 id;\n \n \tbtf = btf__load_vmlinux_btf();\n@@ -446,13 +473,8 @@ static int setup_tmulti_targets(const struct bpf_program *prog,\n \t\ttargets[i].id = id;\n \t}\n \n-\tmemset(\u0026prog_info, 0, len);\n-\terr = bpf_prog_get_info_by_fd(bpf_program__fd(prog), \u0026prog_info, \u0026len);\n-\tif (!ASSERT_OK(err, \"bpf_prog_get_info_by_fd\"))\n-\t\tgoto error;\n-\tif (!ASSERT_GT(prog_info.attach_btf_obj_id, 0, \"attach_btf_obj_id\"))\n+\tif (setup_tmulti_btf_obj_id(prog, btf_obj_id))\n \t\tgoto error;\n-\t*btf_obj_id = prog_info.attach_btf_obj_id;\n \n \t/*\n \t * The kernel tracing multi attach sorts ids. We sort as well,\n@@ -467,13 +489,49 @@ static int setup_tmulti_targets(const struct bpf_program *prog,\n \treturn -1;\n }\n \n+static int setup_tmulti_bpf_prog_targets(const struct bpf_program *prog, int token_fd,\n+\t\t\t\t\t const __u64 *cookies,\n+\t\t\t\t\t const struct bpf_program * const *target_progs,\n+\t\t\t\t\t struct tmulti_target *targets,\n+\t\t\t\t\t __u32 *btf_obj_id)\n+{\n+\tstruct bpf_prog_info prog_info = {};\n+\t__u32 len = sizeof(prog_info), func_btf_id;\n+\tint err, i, prog_fd;\n+\n+\tfor (i = 0; i \u003c TRACING_MULTI_BPF_CNT; i++) {\n+\t\tmemset(\u0026prog_info, 0, sizeof(prog_info));\n+\t\tlen = sizeof(prog_info);\n+\t\tprog_info.jited_ksyms = ptr_to_u64(\u0026targets[i].addr);\n+\t\tprog_info.nr_jited_ksyms = 1;\n+\t\tprog_fd = bpf_program__fd(target_progs[i]);\n+\t\terr = bpf_prog_get_info_by_fd(prog_fd, \u0026prog_info, \u0026len);\n+\t\tif (!ASSERT_OK(err, \"bpf_prog_get_info_by_fd\"))\n+\t\t\treturn -1;\n+\n+\t\tfunc_btf_id = libbpf_find_prog_btf_id(tmulti_bpf_funcs[i], prog_fd, token_fd);\n+\t\tif (!ASSERT_GT(func_btf_id, 0, \"libbpf_find_prog_btf_id\"))\n+\t\t\treturn -1;\n+\n+\t\ttargets[i].cookie = cookies[i];\n+\t\ttargets[i].id = prog_info.id;\n+\t\ttargets[i].func_btf_id = func_btf_id;\n+\t}\n+\n+\tqsort(targets, TRACING_MULTI_BPF_CNT, sizeof(targets[0]), tmulti_target_cmp);\n+\treturn setup_tmulti_btf_obj_id(prog, btf_obj_id);\n+}\n+\n static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog,\n \t\t\t\t\t  const struct tmulti_target *targets,\n-\t\t\t\t\t  __u32 btf_obj_id, bool has_cookies)\n+\t\t\t\t\t  __u32 btf_obj_id, __u32 count,\n+\t\t\t\t\t  bool has_cookies, bool tgt_progs)\n {\n+#define TMULTI_CNT (TRACING_MULTI_CNT \u003e TRACING_MULTI_BPF_CNT ? \\\n+\t\t    TRACING_MULTI_CNT : TRACING_MULTI_BPF_CNT)\n \tenum bpf_attach_type attach_type = bpf_program__expected_attach_type(prog);\n-\t__u64 addrs[TRACING_MULTI_CNT], cookies[TRACING_MULTI_CNT];\n-\t__u32 ids[TRACING_MULTI_CNT];\n+\t__u64 addrs[TMULTI_CNT], cookies[TMULTI_CNT];\n+\t__u32 ids[TMULTI_CNT], fids[TMULTI_CNT];\n \tstruct bpf_link_info info;\n \t__u32 len = sizeof(info);\n \tint err, i;\n@@ -487,16 +545,21 @@ static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog\n \t\treturn -1;\n \n \tASSERT_EQ(info.tracing_multi.attach_type, attach_type, \"info.tracing_multi.attach_type\");\n-\tASSERT_EQ(info.tracing_multi.count, TRACING_MULTI_CNT, \"info.tracing_multi.count\");\n+\tASSERT_EQ(info.tracing_multi.count, count, \"info.tracing_multi.count\");\n+\tif (tgt_progs)\n+\t\tASSERT_TRUE(info.tracing_multi.flags \u0026 BPF_F_TRACING_MULTI_TGT_PROGS,\n+\t\t\t    \"info.tracing_multi.flags\");\n \n \tmemset(ids, 0, sizeof(ids));\n+\tmemset(fids, 0, sizeof(fids));\n \tmemset(cookies, 0, sizeof(cookies));\n \tmemset(addrs, 0, sizeof(addrs));\n \n \tinfo.tracing_multi.ids = ptr_to_u64(ids);\n \tinfo.tracing_multi.addrs = ptr_to_u64(addrs);\n \tinfo.tracing_multi.cookies = has_cookies ? ptr_to_u64(cookies) : 0;\n-\tinfo.tracing_multi.count = TRACING_MULTI_CNT;\n+\tinfo.tracing_multi.func_btf_ids = tgt_progs ? ptr_to_u64(fids) : 0;\n+\tinfo.tracing_multi.count = count;\n \n \terr = bpf_link_get_info_by_fd(fd, \u0026info, \u0026len);\n \tif (!ASSERT_OK(err, \"bpf_link_get_info_by_fd\"))\n@@ -506,14 +569,20 @@ static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog\n \t\treturn -1;\n \n \tASSERT_EQ(info.tracing_multi.attach_type, attach_type, \"info.tracing_multi.attach_type\");\n-\tASSERT_EQ(info.tracing_multi.count, TRACING_MULTI_CNT, \"info.tracing_multi.count\");\n+\tASSERT_EQ(info.tracing_multi.count, count, \"info.tracing_multi.count\");\n \tASSERT_EQ(info.tracing_multi.btf_obj_id, btf_obj_id, \"tracing_multi.btf_obj_id\");\n+\tif (tgt_progs)\n+\t\tASSERT_TRUE(info.tracing_multi.flags \u0026 BPF_F_TRACING_MULTI_TGT_PROGS,\n+\t\t\t    \"info.tracing_multi.flags\");\n \n-\tfor (i = 0; i \u003c TRACING_MULTI_CNT; i++) {\n+\tfor (i = 0; i \u003c count; i++) {\n \t\tASSERT_EQ(ids[i], targets[i].id, \"tracing_multi.ids\");\n \t\tASSERT_EQ(cookies[i], has_cookies ? targets[i].cookie : 0, \"tracing_multi.cookies\");\n \n-\t\tif (targets[i].addr) {\n+\t\tif (tgt_progs) {\n+\t\t\tASSERT_EQ(addrs[i], targets[i].addr, \"tracing_multi.addrs\");\n+\t\t\tASSERT_EQ(fids[i], targets[i].func_btf_id, \"tracing_multi.func_btf_ids\");\n+\t\t} else if (targets[i].addr) {\n \t\t\tstruct ksym *ksym;\n \n \t\t\tif (!ASSERT_NEQ(addrs[i], 0, \"tracing_multi.addrs\"))\n@@ -624,13 +693,73 @@ static void test_tracing_multi_fill_link_info(struct test_fill_link_info *skel,\n \t\tverify_tracing_multi_invalid_user_buffer(link_fd, targets);\n \t} else {\n \t\terr = verify_tracing_multi_link_info(link_fd, skel-\u003eprogs.tmulti_run,\n-\t\t\t\t\t\t     targets, btf_obj_id, has_cookies);\n+\t\t\t\t\t\t     targets, btf_obj_id, TRACING_MULTI_CNT,\n+\t\t\t\t\t\t     has_cookies, false);\n \t\tASSERT_OK(err, \"verify_tracing_multi_link_info\");\n \t}\n \n \tbpf_link__destroy(link);\n }\n \n+static void test_tracing_multi_bpf_fill_link_info_one(struct tracing_multi_bpf *skel,\n+\t\t\t\t\t\t      struct bpf_program *prog,\n+\t\t\t\t\t\t      __u64 *cookies,\n+\t\t\t\t\t\t      bool has_cookies)\n+{\n+\tLIBBPF_OPTS(bpf_tracing_multi_opts, opts);\n+\tconst struct bpf_program *target_progs[] = {\n+\t\tskel-\u003eprogs.target_1,\n+\t\tskel-\u003eprogs.target_2,\n+\t};\n+\tstruct tmulti_target targets[TRACING_MULTI_BPF_CNT] = {};\n+\tint fds[TRACING_MULTI_BPF_CNT], token_fd, err, i;\n+\tstruct bpf_link *link;\n+\t__u32 btf_obj_id;\n+\n+\ttoken_fd = bpf_object__token_fd(skel-\u003eobj);\n+\ttoken_fd = token_fd \u003c 0 ? 0 : token_fd;\n+\n+\tif (setup_tmulti_bpf_prog_targets(prog, token_fd, cookies, target_progs, targets,\n+\t\t\t\t\t  \u0026btf_obj_id))\n+\t\treturn;\n+\n+\tfor (i = 0; i \u003c TRACING_MULTI_BPF_CNT; i++)\n+\t\tfds[i] = bpf_program__fd(target_progs[i]);\n+\n+\topts.fds = fds;\n+\topts.funcs = tmulti_bpf_funcs;\n+\topts.cnt = ARRAY_SIZE(fds);\n+\topts.cookies = has_cookies ? cookies : NULL;\n+\n+\tlink = bpf_program__attach_tracing_multi(prog, NULL, \u0026opts);\n+\tif (!ASSERT_OK_PTR(link, \"bpf_program__attach_tracing_multi\"))\n+\t\treturn;\n+\n+\terr = verify_tracing_multi_link_info(bpf_link__fd(link), prog, targets, btf_obj_id,\n+\t\t\t\t\t     TRACING_MULTI_BPF_CNT, has_cookies, true);\n+\tASSERT_OK(err, \"verify_tracing_multi_link_info\");\n+\n+\tbpf_link__destroy(link);\n+}\n+\n+static void test_tracing_multi_bpf_fill_link_info(bool has_cookies)\n+{\n+\tstruct tracing_multi_bpf *skel;\n+\n+\tskel = tracing_multi_bpf__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"tracing_multi_bpf__open_and_load\"))\n+\t\treturn;\n+\n+\ttest_tracing_multi_bpf_fill_link_info_one(skel, skel-\u003eprogs.test_fentry,\n+\t\t\t\t\t\t  tmulti_bpf_fentry_cookies, has_cookies);\n+\ttest_tracing_multi_bpf_fill_link_info_one(skel, skel-\u003eprogs.test_fexit,\n+\t\t\t\t\t\t  tmulti_bpf_fexit_cookies, has_cookies);\n+\ttest_tracing_multi_bpf_fill_link_info_one(skel, skel-\u003eprogs.test_fsession,\n+\t\t\t\t\t\t  tmulti_bpf_fsession_cookies, has_cookies);\n+\n+\ttracing_multi_bpf__destroy(skel);\n+}\n+\n #define SEC(name) __attribute__((section(name), used))\n \n static short uprobe_link_info_sema_1 SEC(\".probes\");\n@@ -879,6 +1008,10 @@ void test_fill_link_info(void)\n \t\ttest_tracing_multi_fill_link_info(skel, false, false);\n \t\ttest_tracing_multi_fill_link_info(skel, true, false);\n \t}\n+\tif (test__start_subtest(\"tracing_multi_bpf_link_info\")) {\n+\t\ttest_tracing_multi_bpf_fill_link_info(false);\n+\t\ttest_tracing_multi_bpf_fill_link_info(true);\n+\t}\n \tif (test__start_subtest(\"tracing_multi_invalid_ubuff\"))\n \t\ttest_tracing_multi_fill_link_info(skel, true, true);\n \ndiff --git a/tools/testing/selftests/bpf/prog_tests/tailcalls.c b/tools/testing/selftests/bpf/prog_tests/tailcalls.c\nindex 88d223110ecd5..3b122520711b0 100644\n--- a/tools/testing/selftests/bpf/prog_tests/tailcalls.c\n+++ b/tools/testing/selftests/bpf/prog_tests/tailcalls.c\n@@ -16,7 +16,9 @@\n #include \"tailcall_sleepable.skel.h\"\n #include \"tailcall_callback.skel.h\"\n #include \"tailcall_bpf2bpf2.skel.h\"\n+#include \"tailcall_bpf2bpf4.skel.h\"\n #include \"tailcall_bpf2bpf_fexit.skel.h\"\n+#include \"tracing_multi_bpf.skel.h\"\n \n /* test_tailcall_1 checks basic functionality by patching multiple locations\n  * in a single program for a single tail call slot with nop-\u003ejmp, jmp-\u003enop\n@@ -2065,6 +2067,66 @@ static void test_tailcall_large_stack(void)\n \ttailcall_large_stack__destroy(skel);\n }\n \n+/*\n+ * Verify that a tail call from a BPF subprog works when the subprog is\n+ * traced by fentry.multi.\n+ */\n+static void test_tailcall_bpf2bpf_fentry_multi(void)\n+{\n+\tstatic const char *funcs[] = { \"subprog_tail_2\" };\n+\tstruct tracing_multi_bpf *skel_tracing = NULL;\n+\tLIBBPF_OPTS(bpf_tracing_multi_opts, opts);\n+\tstruct tailcall_bpf2bpf4 *skel_tc;\n+\tstruct bpf_link *link = NULL;\n+\tint fds[ARRAY_SIZE(funcs)];\n+\tchar buff[128] = {};\n+\tint err, key;\n+\tLIBBPF_OPTS(bpf_test_run_opts, topts,\n+\t\t.data_in = buff,\n+\t\t.data_size_in = sizeof(buff),\n+\t\t.repeat = 1,\n+\t);\n+\n+\tskel_tc = tailcall_bpf2bpf4__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel_tc, \"tailcall_bpf2bpf4__open_and_load\"))\n+\t\treturn;\n+\n+\tskel_tracing = tracing_multi_bpf__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel_tracing, \"tracing_multi_bpf__open_and_load\"))\n+\t\tgoto out;\n+\n+\tkey = 0;\n+\tfds[0] = bpf_program__fd(skel_tc-\u003eprogs.classifier_2);\n+\terr = bpf_map_update_elem(bpf_map__fd(skel_tc-\u003emaps.jmp_table), \u0026key, \u0026fds[0], BPF_ANY);\n+\tif (!ASSERT_OK(err, \"bpf_map_update_elem\"))\n+\t\tgoto out;\n+\n+\tkey = 2;\n+\terr = bpf_map_update_elem(bpf_map__fd(skel_tc-\u003emaps.jmp_table), \u0026key, \u0026fds[0], BPF_ANY);\n+\tif (!ASSERT_OK(err, \"bpf_map_update_elem_loop\"))\n+\t\tgoto out;\n+\n+\topts.fds = fds;\n+\topts.funcs = funcs;\n+\topts.cnt = ARRAY_SIZE(fds);\n+\tlink = bpf_program__attach_tracing_multi(skel_tracing-\u003eprogs.test_fentry, NULL, \u0026opts);\n+\tif (!ASSERT_OK_PTR(link, \"bpf_program__attach_tracing_multi\"))\n+\t\tgoto out;\n+\n+\terr = bpf_prog_test_run_opts(bpf_program__fd(skel_tc-\u003eprogs.entry), \u0026topts);\n+\tif (!ASSERT_OK(err, \"bpf_prog_test_run_opts\"))\n+\t\tgoto out;\n+\n+\tASSERT_EQ(topts.retval, sizeof(buff) * 3, \"retval\");\n+\tASSERT_EQ(skel_tc-\u003ebss-\u003ecount, 33, \"count\");\n+\tASSERT_EQ(skel_tracing-\u003ebss-\u003etest_result_fentry, 33, \"fentry.multi count\");\n+\n+out:\n+\tbpf_link__destroy(link);\n+\ttracing_multi_bpf__destroy(skel_tracing);\n+\ttailcall_bpf2bpf4__destroy(skel_tc);\n+}\n+\n void test_tailcalls(void)\n {\n \tif (test__start_subtest(\"tailcall_1\"))\n@@ -2138,4 +2200,6 @@ void test_tailcalls(void)\n \t\ttest_tailcall_bpf2bpf_fexit_links();\n \tif (test__start_subtest(\"tailcall_large_stack\"))\n \t\ttest_tailcall_large_stack();\n+\tif (test__start_subtest(\"tailcall_bpf2bpf_fentry_multi\"))\n+\t\ttest_tailcall_bpf2bpf_fentry_multi();\n }\ndiff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c\nindex cc727011f3a2a..dfa24e229ff75 100644\n--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c\n+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c\n@@ -12,6 +12,7 @@\n #include \"tracing_multi_verifier.skel.h\"\n #include \"tracing_multi_bench.skel.h\"\n #include \"tracing_multi_rollback.skel.h\"\n+#include \"tracing_multi_bpf.skel.h\"\n #include \"trace_helpers.h\"\n \n static __u64 bpf_fentry_test_cookies[] = {\n@@ -1126,3 +1127,256 @@ void test_tracing_multi_test(void)\n \tif (test__start_subtest(\"fentry_after_multi\"))\n \t\ttest_fentry_after_multi();\n }\n+\n+static int run_bpf_target(struct bpf_program *prog, __u32 retval, const char *name)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, topts);\n+\tint err;\n+\n+\terr = bpf_prog_test_run_opts(bpf_program__fd(prog), \u0026topts);\n+\tif (!ASSERT_OK(err, name))\n+\t\treturn err;\n+\n+\tif (!ASSERT_EQ(topts.retval, retval, name))\n+\t\treturn -EINVAL;\n+\n+\treturn 0;\n+}\n+\n+static void test_link_api_bpf_prog(bool test_cookies)\n+{\n+\tconst char *funcs[] = { \"target_1\", \"target_2\" };\n+\t__u64 fentry_cookies[] = { 0xfeed01, 0xfeed02 };\n+\t__u64 fexit_cookies[] = { 0xfeed11, 0xfeed12 };\n+\t__u64 fsession_cookies[] = { 0xfeed21, 0xfeed22 };\n+\tLIBBPF_OPTS(bpf_tracing_multi_opts, opts);\n+\tstruct tracing_multi_bpf *skel = NULL;\n+\tint fds[ARRAY_SIZE(funcs)];\n+\tstruct bpf_link *link;\n+\n+\tskel = tracing_multi_bpf__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"tracing_multi_bpf__open_and_load\"))\n+\t\treturn;\n+\n+\tfds[0] = bpf_program__fd(skel-\u003eprogs.target_1);\n+\tfds[1] = bpf_program__fd(skel-\u003eprogs.target_2);\n+\n+\tskel-\u003ebss-\u003etest_cookies = test_cookies;\n+\n+\topts.fds = fds;\n+\topts.funcs = funcs;\n+\topts.cnt = ARRAY_SIZE(fds);\n+\n+\topts.cookies = test_cookies ? fentry_cookies : NULL;\n+\tlink = bpf_program__attach_tracing_multi(skel-\u003eprogs.test_fentry, NULL, \u0026opts);\n+\tif (!ASSERT_OK_PTR(link, \"attach_fentry\"))\n+\t\tgoto cleanup;\n+\tskel-\u003elinks.test_fentry = link;\n+\n+\topts.cookies = test_cookies ? fexit_cookies : NULL;\n+\tlink = bpf_program__attach_tracing_multi(skel-\u003eprogs.test_fexit, NULL, \u0026opts);\n+\tif (!ASSERT_OK_PTR(link, \"attach_fexit\"))\n+\t\tgoto cleanup;\n+\tskel-\u003elinks.test_fexit = link;\n+\n+\topts.cookies = test_cookies ? fsession_cookies : NULL;\n+\tlink = bpf_program__attach_tracing_multi(skel-\u003eprogs.test_fsession, NULL, \u0026opts);\n+\tif (!ASSERT_OK_PTR(link, \"attach_fsession\"))\n+\t\tgoto cleanup;\n+\tskel-\u003elinks.test_fsession = link;\n+\n+\tskel-\u003ebss-\u003efentry_cookie = fentry_cookies[0];\n+\tskel-\u003ebss-\u003efexit_cookie = fexit_cookies[0];\n+\tskel-\u003ebss-\u003efsession_cookie = fsession_cookies[0];\n+\tif (run_bpf_target(skel-\u003eprogs.target_1, 1, \"target_1\"))\n+\t\tgoto cleanup;\n+\n+\tskel-\u003ebss-\u003efentry_cookie = fentry_cookies[1];\n+\tskel-\u003ebss-\u003efexit_cookie = fexit_cookies[1];\n+\tskel-\u003ebss-\u003efsession_cookie = fsession_cookies[1];\n+\tif (run_bpf_target(skel-\u003eprogs.target_2, 2, \"target_2\"))\n+\t\tgoto cleanup;\n+\n+\tASSERT_EQ(skel-\u003ebss-\u003etarget_1_result, 1, \"target_1_result\");\n+\tASSERT_EQ(skel-\u003ebss-\u003etarget_2_result, 1, \"target_2_result\");\n+\tASSERT_EQ(skel-\u003ebss-\u003etest_result_fentry, ARRAY_SIZE(funcs), \"test_result_fentry\");\n+\tASSERT_EQ(skel-\u003ebss-\u003etest_result_fexit, ARRAY_SIZE(funcs), \"test_result_fexit\");\n+\tASSERT_EQ(skel-\u003ebss-\u003etest_result_fsession_entry, ARRAY_SIZE(funcs),\n+\t\t  \"test_result_fsession_entry\");\n+\tASSERT_EQ(skel-\u003ebss-\u003etest_result_fsession_exit, ARRAY_SIZE(funcs),\n+\t\t  \"test_result_fsession_exit\");\n+\n+cleanup:\n+\ttracing_multi_bpf__destroy(skel);\n+}\n+\n+static void test_attach_api_bpf_prog_fails(void)\n+{\n+\tstatic const char * const kfuncs[] = {\n+\t\t\"bpf_fentry_test1\",\n+\t};\n+\tconst char *bpf_funcs[] = { \"target_1\" };\n+\tLIBBPF_OPTS(bpf_tracing_multi_opts, opts);\n+\tLIBBPF_OPTS(bpf_link_create_opts, lopts);\n+\tstruct tracing_multi_bpf *skel = NULL;\n+\tint fd, target_id, token_fd;\n+\tint fds[2], dup_fd = -1;\n+\tstruct bpf_link *link;\n+\t__u32 target_ids[2];\n+\t__u32 *ids = NULL;\n+\tlong err;\n+\n+\tskel = tracing_multi_bpf__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"tracing_multi_bpf__open_and_load\"))\n+\t\treturn;\n+\n+\tids = get_ids(kfuncs, ARRAY_SIZE(kfuncs), NULL);\n+\tif (!ASSERT_OK_PTR(ids, \"get_ids\"))\n+\t\tgoto cleanup;\n+\n+\tfds[0] = bpf_program__fd(skel-\u003eprogs.target_1);\n+\n+\t/* fail#1 (libbpf) kernel ids and BPF prog fds */\n+\tLIBBPF_OPTS_RESET(opts,\n+\t\t.ids = ids,\n+\t\t.fds = fds,\n+\t\t.funcs = bpf_funcs,\n+\t\t.cnt = ARRAY_SIZE(bpf_funcs),\n+\t);\n+\n+\tlink = bpf_program__attach_tracing_multi(skel-\u003eprogs.test_fentry, NULL, \u0026opts);\n+\terr = libbpf_get_error(link);\n+\tif (!ASSERT_EQ(err, -EINVAL, \"libbpf_ids_fds\")) {\n+\t\tif (!err)\n+\t\t\tbpf_link__destroy(link);\n+\t\tgoto cleanup;\n+\t}\n+\n+\t/* fail#2 (libbpf) kernel pattern and BPF prog fds */\n+\tLIBBPF_OPTS_RESET(opts,\n+\t\t.fds = fds,\n+\t\t.funcs = bpf_funcs,\n+\t\t.cnt = ARRAY_SIZE(bpf_funcs),\n+\t);\n+\n+\tlink = bpf_program__attach_tracing_multi(skel-\u003eprogs.test_fentry,\n+\t\t\t\t\t\t\"bpf_fentry_test*\", \u0026opts);\n+\terr = libbpf_get_error(link);\n+\tif (!ASSERT_EQ(err, -EINVAL, \"libbpf_pattern_fds\")) {\n+\t\tif (!err)\n+\t\t\tbpf_link__destroy(link);\n+\t\tgoto cleanup;\n+\t}\n+\n+\t/* fail#3 (kernel) kernel id with BPF prog fd */\n+\tlopts.tracing_multi.ids = ids;\n+\tlopts.tracing_multi.fds = fds;\n+\tlopts.tracing_multi.cnt = ARRAY_SIZE(bpf_funcs);\n+\tfd = bpf_link_create(bpf_program__fd(skel-\u003eprogs.test_fentry), 0,\n+\t\t\t     BPF_TRACE_FENTRY_MULTI, \u0026lopts);\n+\tASSERT_EQ(fd, -EINVAL, \"kernel_id_bpf_fd\");\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\n+\t/* fail#4 (kernel) duplicate target through different fds */\n+\ttoken_fd = bpf_object__token_fd(skel-\u003eobj);\n+\ttoken_fd = token_fd \u003c 0 ? 0 : token_fd;\n+\ttarget_id = libbpf_find_prog_btf_id(\"target_1\", fds[0], token_fd);\n+\tif (!ASSERT_GT(target_id, 0, \"target_1_btf_id\"))\n+\t\tgoto cleanup;\n+\n+\tdup_fd = dup(fds[0]);\n+\tif (!ASSERT_GE(dup_fd, 0, \"dup_target_fd\"))\n+\t\tgoto cleanup;\n+\n+\tfds[1] = dup_fd;\n+\ttarget_ids[0] = target_id;\n+\ttarget_ids[1] = target_id;\n+\tlopts.tracing_multi.ids = target_ids;\n+\tlopts.tracing_multi.fds = fds;\n+\tlopts.tracing_multi.cnt = ARRAY_SIZE(fds);\n+\tfd = bpf_link_create(bpf_program__fd(skel-\u003eprogs.test_fentry), 0,\n+\t\t\t     BPF_TRACE_FENTRY_MULTI, \u0026lopts);\n+\tASSERT_EQ(fd, -EINVAL, \"duplicate_bpf_target\");\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\n+cleanup:\n+\tif (dup_fd \u003e= 0)\n+\t\tclose(dup_fd);\n+\ttracing_multi_bpf__destroy(skel);\n+\tfree(ids);\n+}\n+\n+static void test_rollback_bpf_prog(void)\n+{\n+\tint token_fd, prog_fd, fd = -1, pre_fd = -1;\n+\tLIBBPF_OPTS(bpf_link_create_opts, lopts);\n+\tstruct tracing_multi_bpf *skel = NULL;\n+\t__u32 target_ids[2], ids[2];\n+\tint target_fds[2], fds[2];\n+\tstruct bpf_program *prog;\n+\tint first, second;\n+\n+\tskel = tracing_multi_bpf__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"tracing_multi_bpf__open_and_load\"))\n+\t\treturn;\n+\n+\ttoken_fd = bpf_object__token_fd(skel-\u003eobj);\n+\ttoken_fd = token_fd \u003c 0 ? 0 : token_fd;\n+\ttarget_fds[0] = bpf_program__fd(skel-\u003eprogs.target_1);\n+\ttarget_fds[1] = bpf_program__fd(skel-\u003eprogs.target_2);\n+\ttarget_ids[0] = libbpf_find_prog_btf_id(\"target_1\", target_fds[0], token_fd);\n+\tif (!ASSERT_GT(target_ids[0], 0, \"target_1_btf_id\"))\n+\t\tgoto cleanup;\n+\ttarget_ids[1] = libbpf_find_prog_btf_id(\"target_2\", target_fds[1], token_fd);\n+\tif (!ASSERT_GT(target_ids[1], 0, \"target_2_btf_id\"))\n+\t\tgoto cleanup;\n+\n+\tfirst = target_fds[0] \u003c target_fds[1] ? 0 : 1;\n+\tsecond = 1 - first;\n+\tfds[0] = target_fds[first];\n+\tfds[1] = target_fds[second];\n+\tids[0] = target_ids[first];\n+\tids[1] = target_ids[second];\n+\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.test_fentry);\n+\tlopts.tracing_multi.ids = \u0026ids[1];\n+\tlopts.tracing_multi.fds = \u0026fds[1];\n+\tlopts.tracing_multi.cnt = 1;\n+\tpre_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, \u0026lopts);\n+\tif (!ASSERT_GE(pre_fd, 0, \"pre_attach\"))\n+\t\tgoto cleanup;\n+\n+\tlopts.tracing_multi.ids = ids;\n+\tlopts.tracing_multi.fds = fds;\n+\tlopts.tracing_multi.cnt = ARRAY_SIZE(ids);\n+\n+\tfd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, \u0026lopts);\n+\tif (!ASSERT_EQ(fd, -EBUSY, \"bpf_link_create\"))\n+\t\tgoto cleanup;\n+\n+\tprog = first == 0 ? skel-\u003eprogs.target_1 : skel-\u003eprogs.target_2;\n+\tif (run_bpf_target(prog, first + 1, \"rollback_target\"))\n+\t\tgoto cleanup;\n+\tASSERT_EQ(skel-\u003ebss-\u003etest_result_fentry, 0, \"test_result_fentry\");\n+\n+cleanup:\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\tif (pre_fd \u003e= 0)\n+\t\tclose(pre_fd);\n+\ttracing_multi_bpf__destroy(skel);\n+}\n+\n+void test_tracing_multi_prog_test(void)\n+{\n+\tif (test__start_subtest(\"link_api\"))\n+\t\ttest_link_api_bpf_prog(false);\n+\tif (test__start_subtest(\"attach_api_fails\"))\n+\t\ttest_attach_api_bpf_prog_fails();\n+\tif (test__start_subtest(\"cookies\"))\n+\t\ttest_link_api_bpf_prog(true);\n+\tif (test__start_subtest(\"rollback\"))\n+\t\ttest_rollback_bpf_prog();\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c b/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c\nnew file mode 100644\nindex 0000000000000..0ea4513904cd7\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c\n@@ -0,0 +1,24 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#include \u003cvmlinux.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \u003cbpf/bpf_tracing.h\u003e\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n+\n+SEC(\"syscall\")\n+int target(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"fentry\")\n+int BPF_PROG(dummy_fentry)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"fentry.multi\")\n+int BPF_PROG(dummy_fentry_multi)\n+{\n+\treturn 0;\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c b/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c\nnew file mode 100644\nindex 0000000000000..651b5d86203f3\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c\n@@ -0,0 +1,61 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#include \u003cvmlinux.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \u003cbpf/bpf_tracing.h\u003e\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n+\n+bool test_cookies;\n+__u64 fentry_cookie;\n+__u64 fexit_cookie;\n+__u64 fsession_cookie;\n+__u64 test_result_fentry;\n+__u64 test_result_fexit;\n+__u64 test_result_fsession_entry;\n+__u64 test_result_fsession_exit;\n+__u64 target_1_result;\n+__u64 target_2_result;\n+\n+SEC(\"syscall\")\n+int target_1(void *ctx)\n+{\n+\ttarget_1_result++;\n+\treturn 1;\n+}\n+\n+SEC(\"syscall\")\n+int target_2(void *ctx)\n+{\n+\ttarget_2_result++;\n+\treturn 2;\n+}\n+\n+SEC(\"fentry.multi\")\n+int BPF_PROG(test_fentry)\n+{\n+\tif (!test_cookies || bpf_get_attach_cookie(ctx) == fentry_cookie)\n+\t\ttest_result_fentry++;\n+\treturn 0;\n+}\n+\n+SEC(\"fexit.multi\")\n+int BPF_PROG(test_fexit)\n+{\n+\tif (!test_cookies || bpf_get_attach_cookie(ctx) == fexit_cookie)\n+\t\ttest_result_fexit++;\n+\treturn 0;\n+}\n+\n+SEC(\"fsession.multi\")\n+int BPF_PROG(test_fsession)\n+{\n+\tif (test_cookies \u0026\u0026 bpf_get_attach_cookie(ctx) != fsession_cookie)\n+\t\treturn 0;\n+\n+\tif (bpf_session_is_return(ctx))\n+\t\ttest_result_fsession_exit++;\n+\telse\n+\t\ttest_result_fsession_entry++;\n+\n+\treturn 0;\n+}\n"
}

2/1 2026/10/12 17:58 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "BPF_EVENTS"
  ],
  "FocusSymbols": [
    "bpf_tracing_multi_attach",
    "bpf_trampoline_multi_prog_attach",
    "bpf_trampoline_multi_prog_detach",
    "bpf_arch_text_poke_batch",
    "bpf_arch_text_poke"
  ],
  "Reasoning": "The patch introduces multi-target tracing support for BPF programs, enabling fentry/fexit/fsession.multi links to attach to multiple target BPF programs simultaneously via the bpf() syscall. It adds batch text poking on x86 (bpf_arch_text_poke_batch), multi-program trampoline attachment and detach handling (bpf_trampoline_multi_prog_attach, bpf_trampoline_multi_prog_detach), and associated verifier and link lifecycle management. These changes reside in core reachable BPF subsystems and warrant fuzzing to uncover potential issues in state rollback, concurrency, or instruction patching.",
  "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 4f26995037887ee50c4e3d8ebbbe6dfdb4387288
Author: syz-cluster <triage@syzkaller.com>
Date:   Mon Oct 12 17:58:07 2026 +0000

    syz-cluster: applied patch under review

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 083fcd6cf15b7..b2040ae09273e 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -646,13 +646,12 @@ static int emit_jump(u8 **pprog, void *func, void *ip)
 	return emit_patch(pprog, func, ip, 0xE9);
 }
 
-static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
-				enum bpf_text_poke_type new_t,
-				void *old_addr, void *new_addr)
+static int bpf_arch_text_poke_prepare_insns(void *ip, enum bpf_text_poke_type old_t,
+					    enum bpf_text_poke_type new_t,
+					    void *old_addr, void *new_addr,
+					    u8 *old_insn, u8 *new_insn)
 {
 	const u8 *nop_insn = x86_nops[5];
-	u8 old_insn[X86_PATCH_SIZE];
-	u8 new_insn[X86_PATCH_SIZE];
 	u8 *prog;
 	int ret;
 
@@ -676,24 +675,37 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 			return ret;
 	}
 
-	ret = -EBUSY;
-	mutex_lock(&text_mutex);
+	return 0;
+}
+
+static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
+				enum bpf_text_poke_type new_t,
+				void *old_addr, void *new_addr)
+{
+	u8 old_insn[X86_PATCH_SIZE];
+	u8 new_insn[X86_PATCH_SIZE];
+	int ret;
+
+	ret = bpf_arch_text_poke_prepare_insns(ip, old_t, new_t, old_addr, new_addr, old_insn,
+					       new_insn);
+	if (ret)
+		return ret;
+
+	guard(mutex)(&text_mutex);
+
 	if (memcmp(ip, old_insn, X86_PATCH_SIZE))
-		goto out;
-	ret = 1;
+		return -EBUSY;
 	if (memcmp(ip, new_insn, X86_PATCH_SIZE)) {
 		smp_text_poke_single(ip, new_insn, X86_PATCH_SIZE, NULL);
-		ret = 0;
+		return 0;
 	}
-out:
-	mutex_unlock(&text_mutex);
-	return ret;
+	return 1;
 }
 
-int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
-		       enum bpf_text_poke_type new_t, void *old_addr,
-		       void *new_addr)
+static int bpf_arch_text_poke_check_ip(void **ipp)
 {
+	void *ip = *ipp;
+
 	if (!is_kernel_text((long)ip) &&
 	    !is_bpf_text_address((long)ip))
 		/* BPF poking in modules is not supported */
@@ -704,11 +716,65 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 	 * with an ENDBR instruction.
 	 */
 	if (is_endbr(ip))
-		ip += ENDBR_INSN_SIZE;
+		*ipp += ENDBR_INSN_SIZE;
+
+	return 0;
+}
+
+int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
+		       enum bpf_text_poke_type new_t, void *old_addr,
+		       void *new_addr)
+{
+	int ret;
+
+	ret = bpf_arch_text_poke_check_ip(&ip);
+	if (ret)
+		return ret;
 
 	return __bpf_arch_text_poke(ip, old_t, new_t, old_addr, new_addr);
 }
 
+int bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)
+{
+	u8 old_insn[X86_PATCH_SIZE];
+	u8 new_insn[X86_PATCH_SIZE];
+	int err;
+	u32 i;
+
+	for (i = 0; i < cnt; i++) {
+		err = bpf_arch_text_poke_check_ip(&pokes[i]->ip);
+		if (err)
+			return err;
+	}
+
+	guard(mutex)(&text_mutex);
+
+	for (i = 0; i < cnt; i++) {
+		struct bpf_text_poke *poke = pokes[i];
+
+		err = bpf_arch_text_poke_prepare_insns(poke->ip, poke->old_t, poke->new_t,
+						       poke->old_addr, poke->new_addr, old_insn,
+						       new_insn);
+		if (err)
+			return err;
+		if (memcmp(poke->ip, old_insn, X86_PATCH_SIZE))
+			return -EBUSY;
+	}
+
+	for (i = 0; i < cnt; i++) {
+		struct bpf_text_poke *poke = pokes[i];
+
+		bpf_arch_text_poke_prepare_insns(poke->ip, poke->old_t, poke->new_t,
+						 poke->old_addr, poke->new_addr, old_insn,
+						 new_insn);
+		if (memcmp(poke->ip, new_insn, X86_PATCH_SIZE))
+			smp_text_poke_batch_add(poke->ip, new_insn, X86_PATCH_SIZE, NULL);
+	}
+
+	smp_text_poke_batch_finish();
+	return 0;
+}
+
 #define EMIT_LFENCE()	EMIT3(0x0F, 0xAE, 0xE8)
 
 static void __emit_indirect_jump(u8 **pprog, int reg, bool ereg)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 54144372281cb..a37f926023fdf 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1496,9 +1496,10 @@ struct bpf_trampoline {
 	struct bpf_tramp_image *cur_image;
 	/* Images not freed yet, cur_image and older ones still in use */
 	struct list_head images;
-	/* Used as temporary old image storage for multi_attach */
+	/* Used as temporary images storage for multi_attach */
 	struct {
 		struct bpf_tramp_image *old_image;
+		struct bpf_tramp_image *new_image;
 		u32 old_flags;
 	} multi_attach;
 };
@@ -1616,6 +1617,9 @@ int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
 				struct bpf_tracing_multi_link *link);
 void bpf_trampoline_multi_detach(struct bpf_prog *prog,
 				 struct bpf_tracing_multi_link *link);
+int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,
+				     struct bpf_tracing_multi_link *link);
+void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link);
 void bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags);
 
 /*
@@ -1739,6 +1743,14 @@ static inline void bpf_trampoline_multi_detach(struct bpf_prog *prog,
 					       struct bpf_tracing_multi_link *link)
 {
 }
+
+static inline int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,
+						   struct bpf_tracing_multi_link *link)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link) {}
 static inline void bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags) {}
 #endif
 
@@ -2089,10 +2101,25 @@ struct bpf_tracing_link {
 	struct bpf_prog *tgt_prog;
 };
 
+enum bpf_text_poke_type {
+	BPF_MOD_NOP,
+	BPF_MOD_CALL,
+	BPF_MOD_JUMP,
+};
+
+struct bpf_text_poke {
+	void *ip;
+	void *old_addr;
+	void *new_addr;
+	enum bpf_text_poke_type old_t;
+	enum bpf_text_poke_type new_t;
+};
+
 struct bpf_tracing_multi_node {
 	struct bpf_tramp_node node;
 	struct bpf_trampoline *trampoline;
 	struct ftrace_func_entry entry;
+	struct bpf_text_poke poke;
 };
 
 struct bpf_tracing_multi_data {
@@ -2107,6 +2134,8 @@ struct bpf_tracing_multi_link {
 	struct bpf_tracing_multi_data data;
 	u64 *cookies;
 	struct bpf_tramp_node *fexits;
+	struct bpf_text_poke **pokes;
+	struct bpf_prog **tgt_progs;
 	int nodes_cnt;
 	struct bpf_tracing_multi_node nodes[] __counted_by(nodes_cnt);
 };
@@ -4225,12 +4254,7 @@ static inline u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
 }
 #endif /* CONFIG_INET */
 
-enum bpf_text_poke_type {
-	BPF_MOD_NOP,
-	BPF_MOD_CALL,
-	BPF_MOD_JUMP,
-};
-
+int bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt);
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 		       enum bpf_text_poke_type new_t, void *old_addr,
 		       void *new_addr);
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 6f70db7515dd4..df66206af3cf9 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1927,6 +1927,8 @@ union bpf_attr {
 				__aligned_u64	ids;
 				__aligned_u64	cookies;
 				__u32		cnt;
+				__u32		:32;
+				__aligned_u64	fds;
 			} tracing_multi;
 		};
 	} link_create;
@@ -6889,6 +6891,10 @@ struct bpf_btf_info {
 	__u32 kernel_btf;
 } __attribute__((aligned(8)));
 
+enum {
+	BPF_F_TRACING_MULTI_TGT_PROGS = (1U << 0),
+};
+
 struct bpf_link_info {
 	__u32 type;
 	__u32 id;
@@ -6974,10 +6980,11 @@ struct bpf_link_info {
 			__u32 attach_type;
 			__u32 count; /* in/out: tracing_multi target count */
 			__u32 btf_obj_id;
-			__u32 :32;
+			__u32 flags;
 			__aligned_u64 ids;
 			__aligned_u64 addrs;
 			__aligned_u64 cookies;
+			__aligned_u64 func_btf_ids;
 		} tracing_multi;
 		struct {
 			__u32 type; /* enum bpf_perf_event_type */
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 05c89396119ad..49b794878c116 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -3484,6 +3484,11 @@ int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,
 	return -EFAULT;
 }
 
+int __weak bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)
+{
+	return -EOPNOTSUPP;
+}
+
 int __weak bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 			      enum bpf_text_poke_type new_t, void *old_addr,
 			      void *new_addr)
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index 24edb59238f34..6e18f69a63adf 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -13,6 +13,7 @@
 #include <linux/bpf_verifier.h>
 #include <linux/bpf_lsm.h>
 #include <linux/delay.h>
+#include <linux/sort.h>
 
 /* dummy _ops. The verifier will operate on target program's ops. */
 const struct bpf_verifier_ops bpf_extension_verifier_ops = {
@@ -59,6 +60,33 @@ static void trampoline_unlock(struct bpf_trampoline *tr)
 	mutex_unlock(select_trampoline_lock(tr));
 }
 
+#ifdef CONFIG_BPF_SYSCALL
+
+static void trampoline_lock_all(void)
+{
+	int i;
+
+	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
+		mutex_lock(&trampoline_locks[i].mutex);
+}
+
+static void trampoline_unlock_all(void)
+{
+	int i;
+
+	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
+		mutex_unlock(&trampoline_locks[i].mutex);
+}
+
+static void bpf_trampoline_multi_attach_init(struct bpf_trampoline *tr)
+{
+	tr->multi_attach.old_image = tr->cur_image;
+	tr->multi_attach.new_image = NULL;
+	tr->multi_attach.old_flags = tr->flags;
+}
+
+#endif /* CONFIG_BPF_SYSCALL */
+
 struct bpf_trampoline_ops {
 	int (*register_fentry)(struct bpf_trampoline *tr, struct bpf_tramp_image *im, void *data);
 	int (*unregister_fentry)(struct bpf_trampoline *tr, u32 orig_flags, void *data);
@@ -475,18 +503,11 @@ static int register_fentry(struct bpf_trampoline *tr, struct bpf_tramp_image *im
 			   void *data __maybe_unused)
 {
 	void *new_addr = im->image;
-	void *ip = tr->func.addr;
-	unsigned long faddr;
 	int ret;
 
-	faddr = ftrace_location((unsigned long)ip);
-	if (faddr) {
+	if (tr->func.ftrace_managed) {
 		if (!tr->fops)
 			return -ENOTSUPP;
-		tr->func.ftrace_managed = true;
-	}
-
-	if (tr->func.ftrace_managed) {
 		ret = direct_ops_add(tr, new_addr);
 	} else {
 		ret = bpf_trampoline_update_fentry(tr, 0, NULL, new_addr);
@@ -1286,6 +1307,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key,
 
 	memcpy(&tr->func.model, &tgt_info->fmodel, sizeof(tgt_info->fmodel));
 	tr->func.addr = (void *)tgt_info->tgt_addr;
+	tr->func.ftrace_managed = tr->ip != 0;
 out:
 	trampoline_unlock(tr);
 	return tr;
@@ -1579,22 +1601,6 @@ int __weak arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
     defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS) && \
     defined(CONFIG_BPF_SYSCALL)
 
-static void trampoline_lock_all(void)
-{
-	int i;
-
-	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
-		mutex_lock(&trampoline_locks[i].mutex);
-}
-
-static void trampoline_unlock_all(void)
-{
-	int i;
-
-	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
-		mutex_unlock(&trampoline_locks[i].mutex);
-}
-
 static void remove_tracing_multi_data(struct bpf_tracing_multi_data *data)
 {
 	ftrace_hash_remove(data->reg);
@@ -1635,8 +1641,8 @@ static void ftrace_hash_add(struct ftrace_hash *hash, struct ftrace_func_entry *
 static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_image *im, void *ptr)
 {
 	unsigned long addr = (unsigned long) im->image;
-	unsigned long ip = ftrace_location(tr->ip);
 	struct bpf_tracing_multi_data *data = ptr;
+	unsigned long ip = tr->ip;
 
 	/*
 	 * Different BTF ids get different trampolines, but they can still
@@ -1649,7 +1655,6 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_ima
 	if (bpf_trampoline_use_jmp(tr->flags))
 		addr = ftrace_jmp_set(addr);
 
-	tr->func.ftrace_managed = true;
 	ftrace_hash_add(data->reg, data->entry, ip, addr);
 	tr->cur_image = im;
 	return 0;
@@ -1658,13 +1663,12 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_ima
 static int unregister_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags, void *ptr)
 {
 	unsigned long addr = (unsigned long) tr->cur_image->image;
-	unsigned long ip = ftrace_location(tr->ip);
 	struct bpf_tracing_multi_data *data = ptr;
 
 	if (bpf_trampoline_use_jmp(tr->flags))
 		addr = ftrace_jmp_set(addr);
 
-	ftrace_hash_add(data->unreg, data->entry, ip, addr);
+	ftrace_hash_add(data->unreg, data->entry, tr->ip, addr);
 	tr->cur_image = NULL;
 	return 0;
 }
@@ -1673,13 +1677,12 @@ static int modify_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags, struct
 			       bool lock_direct_mutex, void *ptr)
 {
 	unsigned long addr = (unsigned long) im->image;
-	unsigned long ip = ftrace_location(tr->ip);
 	struct bpf_tracing_multi_data *data = ptr;
 
 	if (bpf_trampoline_use_jmp(tr->flags))
 		addr = ftrace_jmp_set(addr);
 
-	ftrace_hash_add(data->modify, data->entry, ip, addr);
+	ftrace_hash_add(data->modify, data->entry, tr->ip, addr);
 	tr->cur_image = im;
 	return 0;
 }
@@ -1690,12 +1693,6 @@ static const struct bpf_trampoline_ops trampoline_multi_ops = {
 	.modify_fentry     = modify_fentry_multi,
 };
 
-static void bpf_trampoline_multi_attach_init(struct bpf_trampoline *tr)
-{
-	tr->multi_attach.old_image = tr->cur_image;
-	tr->multi_attach.old_flags = tr->flags;
-}
-
 static void bpf_trampoline_multi_attach_free(struct bpf_trampoline *tr)
 {
 	/*
@@ -1712,6 +1709,7 @@ static void bpf_trampoline_multi_attach_free(struct bpf_trampoline *tr)
 		bpf_tramp_image_put(tr->multi_attach.old_image);
 
 	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
 	tr->multi_attach.old_flags = 0;
 }
 
@@ -1723,6 +1721,7 @@ static void bpf_trampoline_multi_attach_rollback(struct bpf_trampoline *tr)
 	tr->flags = tr->multi_attach.old_flags;
 
 	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
 	tr->multi_attach.old_flags = 0;
 }
 
@@ -1868,10 +1867,278 @@ void bpf_trampoline_multi_detach(struct bpf_prog *prog,
 #undef for_each_mnode_cnt
 #undef for_each_mnode
 
+#else
+
+void bpf_trampoline_multi_detach(struct bpf_prog *prog,
+				 struct bpf_tracing_multi_link *link) {}
+
 #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS &&
 	  CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS &&
 	  CONFIG_BPF_SYSCALL */
 
+#ifdef CONFIG_BPF_SYSCALL
+
+static int bpf_text_poke_cmp(const void *a, const void *b)
+{
+	const struct bpf_text_poke *pa = *(struct bpf_text_poke * const *)a;
+	const struct bpf_text_poke *pb = *(struct bpf_text_poke * const *)b;
+	unsigned long ipa = (unsigned long) pa->ip;
+	unsigned long ipb = (unsigned long) pb->ip;
+
+	return (ipa > ipb) - (ipa < ipb);
+}
+
+static int bpf_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)
+{
+	int i, err;
+
+	/*
+	 * Sort pokes for two purposes:
+	 * 1. Check duplicated poke target IPs.
+	 * 2. Sorted poke target IPs would be friendly for poking them on x86,
+	 *    see arch/x86/kernel/alternative.c::smp_text_poke_batch_add().
+	 */
+	sort_nonatomic(pokes, cnt, sizeof(*pokes), bpf_text_poke_cmp, NULL);
+
+	for (i = 1; i < cnt; i++)
+		if (pokes[i - 1]->ip == pokes[i]->ip)
+			return -EINVAL;
+
+	err = bpf_arch_text_poke_batch(pokes, cnt);
+	if (err != -EOPNOTSUPP)
+		return err;
+
+	for (i = 0; i < cnt; i++) {
+		struct bpf_text_poke *p = pokes[i];
+
+		err = bpf_arch_text_poke(p->ip, p->old_t, p->new_t, p->old_addr, p->new_addr);
+		if (err)
+			goto rollback;
+	}
+
+	return 0;
+
+rollback:
+	for (i--; i >= 0; i--) {
+		struct bpf_text_poke *p = pokes[i];
+
+		WARN_ON_ONCE(bpf_arch_text_poke(p->ip, p->new_t, p->old_t, p->new_addr,
+						p->old_addr));
+	}
+	return err;
+}
+
+static enum bpf_text_poke_type bpf_trampoline_poke_type(const struct bpf_tramp_image *im, u32 flags)
+{
+	if (!im)
+		return BPF_MOD_NOP;
+
+	return bpf_trampoline_use_jmp(flags) ? BPF_MOD_JUMP : BPF_MOD_CALL;
+}
+
+static void bpf_text_poke_init(struct bpf_text_poke *poke, struct bpf_trampoline *tr)
+{
+	struct bpf_tramp_image *old_image = tr->multi_attach.old_image;
+	struct bpf_tramp_image *new_image = tr->multi_attach.new_image;
+
+	poke->ip = tr->func.addr;
+	poke->old_addr = old_image ? old_image->image : NULL;
+	poke->new_addr = new_image ? new_image->image : NULL;
+	poke->old_t = bpf_trampoline_poke_type(old_image, tr->multi_attach.old_flags);
+	poke->new_t = bpf_trampoline_poke_type(new_image, tr->flags);
+}
+
+static int register_fentry_multi_prog(struct bpf_trampoline *tr,
+				      struct bpf_tramp_image *im,
+				      void *data __maybe_unused)
+{
+	tr->multi_attach.new_image = im;
+	return 0;
+}
+
+static int unregister_fentry_multi_prog(struct bpf_trampoline *tr,
+					u32 orig_flags __maybe_unused,
+					void *data __maybe_unused)
+{
+	tr->multi_attach.new_image = NULL;
+	return 0;
+}
+
+static int modify_fentry_multi_prog(struct bpf_trampoline *tr,
+				    u32 orig_flags __maybe_unused,
+				    struct bpf_tramp_image *im,
+				    bool lock_direct_mutex __maybe_unused,
+				    void *data __maybe_unused)
+{
+	tr->multi_attach.new_image = im;
+	return 0;
+}
+
+static const struct bpf_trampoline_ops trampoline_multi_prog_ops = {
+	.register_fentry   = register_fentry_multi_prog,
+	.unregister_fentry = unregister_fentry_multi_prog,
+	.modify_fentry     = modify_fentry_multi_prog,
+};
+
+static void bpf_trampoline_multi_prog_commit(struct bpf_trampoline *tr)
+{
+	struct bpf_tramp_image *old_image = tr->multi_attach.old_image;
+
+	tr->cur_image = tr->multi_attach.new_image;
+	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
+	tr->multi_attach.old_flags = 0;
+
+	if (old_image)
+		bpf_tramp_image_put(old_image);
+}
+
+static void bpf_trampoline_multi_prog_rollback(struct bpf_trampoline *tr)
+{
+	if (tr->multi_attach.new_image)
+		bpf_tramp_image_put(tr->multi_attach.new_image);
+
+	tr->flags = tr->multi_attach.old_flags;
+	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
+	tr->multi_attach.old_flags = 0;
+}
+
+#define for_each_mnode_cnt(mnode, link, cnt) \
+	for (i = 0, mnode = &link->nodes[i]; i < cnt; i++, mnode = &link->nodes[i])
+
+#define for_each_mnode(mnode, link) \
+	for_each_mnode_cnt(mnode, link, link->nodes_cnt)
+
+static int bpf_trampoline_multi_prog_prepare(struct bpf_prog *prog, u32 *ids, u64 *keys,
+					     struct bpf_tracing_multi_link *link)
+{
+	struct bpf_attach_target_info tgt_info = {};
+	struct bpf_tracing_multi_node *mnode;
+	struct bpf_trampoline *tr;
+	int i, cnt, err;
+
+	for_each_mnode(mnode, link) {
+		err = bpf_check_attach_target(NULL, prog, link->tgt_progs[i], ids[i], &tgt_info);
+		if (err)
+			goto put_trampolines;
+
+		tr = bpf_trampoline_get(keys[i], &tgt_info);
+		if (!tr) {
+			err = -ENOMEM;
+			goto put_trampolines;
+		}
+
+		mnode->trampoline = tr;
+		mnode->node.link = &link->link;
+		mnode->node.cookie = link->cookies ? link->cookies[i] : 0;
+
+		if (prog->expected_attach_type == BPF_TRACE_FSESSION_MULTI) {
+			link->fexits[i].link = &link->link;
+			link->fexits[i].cookie = link->cookies ? link->cookies[i] : 0;
+		}
+	}
+
+	return 0;
+
+put_trampolines:
+	cnt = i;
+	for_each_mnode_cnt(mnode, link, cnt)
+		bpf_trampoline_put(mnode->trampoline);
+	return err;
+}
+
+int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,
+				     struct bpf_tracing_multi_link *link)
+{
+	struct bpf_tracing_multi_node *mnode;
+	int i, err, linked_cnt = 0;
+
+	err = bpf_trampoline_multi_prog_prepare(prog, ids, keys, link);
+	if (err)
+		return err;
+
+	trampoline_lock_all();
+
+	for_each_mnode(mnode, link) {
+		bpf_trampoline_multi_attach_init(mnode->trampoline);
+
+		if (link->tgt_progs[i]->aux->tail_call_reachable)
+			mnode->trampoline->flags |= BPF_TRAMP_F_TAIL_CALL_CTX;
+
+		err = __bpf_trampoline_link_prog(&mnode->node, mnode->trampoline, NULL,
+						 &trampoline_multi_prog_ops, NULL);
+		if (err) {
+			bpf_trampoline_multi_prog_rollback(mnode->trampoline);
+			goto rollback;
+		}
+		linked_cnt++;
+	}
+
+	for_each_mnode(mnode, link) {
+		link->pokes[i] = &mnode->poke;
+		bpf_text_poke_init(link->pokes[i], mnode->trampoline);
+	}
+
+	err = bpf_text_poke_batch(link->pokes, link->nodes_cnt);
+	if (err)
+		goto rollback;
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_multi_prog_commit(mnode->trampoline);
+
+	trampoline_unlock_all();
+	return 0;
+
+rollback:
+	for_each_mnode_cnt(mnode, link, linked_cnt) {
+		bpf_trampoline_remove_prog(mnode->trampoline, &mnode->node);
+		bpf_trampoline_multi_prog_rollback(mnode->trampoline);
+	}
+
+	trampoline_unlock_all();
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_put(mnode->trampoline);
+	return err;
+}
+
+void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link)
+{
+	struct bpf_tracing_multi_node *mnode;
+	int i, err;
+
+	trampoline_lock_all();
+
+	for_each_mnode(mnode, link) {
+		bpf_trampoline_multi_attach_init(mnode->trampoline);
+		err = __bpf_trampoline_unlink_prog(&mnode->node, mnode->trampoline, NULL,
+						   &trampoline_multi_prog_ops, NULL);
+		if (WARN_ONCE(err, "__bpf_trampoline_unlink_prog failed: %d\n", err))
+			bpf_trampoline_multi_prog_rollback(mnode->trampoline);
+	}
+
+	for_each_mnode(mnode, link) {
+		link->pokes[i] = &mnode->poke;
+		bpf_text_poke_init(link->pokes[i], mnode->trampoline);
+	}
+
+	WARN_ON_ONCE(bpf_text_poke_batch(link->pokes, link->nodes_cnt));
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_multi_prog_commit(mnode->trampoline);
+
+	trampoline_unlock_all();
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_put(mnode->trampoline);
+}
+
+#undef for_each_mnode_cnt
+#undef for_each_mnode
+
+#endif /* CONFIG_BPF_SYSCALL */
+
 static int __init init_trampolines(void)
 {
 	int i;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 2f190abe34489..f2af2bbdd6fb5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -22284,22 +22284,24 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 			return -EOPNOTSUPP;
 		}
 
-		/*
-		 * *.multi programs don't need an address during program
-		 * verification, we just take the module ref if needed.
-		 */
-		if (is_tracing_multi_id(prog, btf_id)) {
+		if (tgt_prog) {
+			if (subprog == 0)
+				addr = (long)tgt_prog->bpf_func;
+			else
+				addr = (long)tgt_prog->aux->func[subprog]->bpf_func;
+		} else if (is_tracing_multi_id(prog, btf_id)) {
+			/*
+			 * *.multi programs don't need an address during program
+			 * verification, we just take the module ref if needed.
+			 * *.multi programs don't have tgt_prog during program
+			 * verification.
+			 */
 			if (btf_is_module(btf)) {
 				mod = btf_try_get_module(btf);
 				if (!mod)
 					return -ENOENT;
 			}
 			addr = 0;
-		} else if (tgt_prog) {
-			if (subprog == 0)
-				addr = (long) tgt_prog->bpf_func;
-			else
-				addr = (long) tgt_prog->aux->func[subprog]->bpf_func;
 		} else {
 			if (btf_is_module(btf)) {
 				mod = btf_try_get_module(btf);
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 195f78db9bdaf..39c911917ae24 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3679,15 +3679,19 @@ __bpf_kfunc int bpf_copy_from_user_task_str_dynptr(const struct bpf_dynptr *dptr
 
 __bpf_kfunc_end_defs();
 
-#if defined(CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS) && \
-    defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS)
+static void bpf_put_progs(struct bpf_prog **progs, int cnt);
 
 static void bpf_tracing_multi_link_release(struct bpf_link *link)
 {
 	struct bpf_tracing_multi_link *tr_link =
 		container_of(link, struct bpf_tracing_multi_link, link);
 
-	bpf_trampoline_multi_detach(link->prog, tr_link);
+	if (tr_link->tgt_progs) {
+		bpf_trampoline_multi_prog_detach(tr_link);
+		bpf_put_progs(tr_link->tgt_progs, tr_link->nodes_cnt);
+	} else {
+		bpf_trampoline_multi_detach(link->prog, tr_link);
+	}
 }
 
 static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
@@ -3695,6 +3699,8 @@ static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
 	struct bpf_tracing_multi_link *tr_link =
 		container_of(link, struct bpf_tracing_multi_link, link);
 
+	kvfree(tr_link->pokes);
+	kvfree(tr_link->tgt_progs);
 	kvfree(tr_link->fexits);
 	kvfree(tr_link->cookies);
 	kvfree(tr_link);
@@ -3703,15 +3709,16 @@ static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
 static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 						 struct bpf_link_info *info)
 {
+	u32 __user *fids = u64_to_user_ptr(info->tracing_multi.func_btf_ids);
 	u64 __user *ucookies = u64_to_user_ptr(info->tracing_multi.cookies);
 	u64 __user *uaddrs = u64_to_user_ptr(info->tracing_multi.addrs);
 	u32 __user *uids = u64_to_user_ptr(info->tracing_multi.ids);
 	struct bpf_tracing_multi_link *tr_link;
 	u32 ucount = info->tracing_multi.count;
-	bool has_cookies, show_addrs;
+	bool has_cookies, show_addrs, has_progs;
 	int err = 0;
 
-	if ((uids || ucookies || uaddrs) && !ucount)
+	if ((uids || ucookies || uaddrs || fids) && !ucount)
 		return -EINVAL;
 
 	tr_link = container_of(link, struct bpf_tracing_multi_link, link);
@@ -3719,9 +3726,13 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 	info->tracing_multi.attach_type = tr_link->link.attach_type;
 	info->tracing_multi.count = tr_link->nodes_cnt;
 	info->tracing_multi.btf_obj_id = btf_obj_id(tr_link->link.prog->aux->attach_btf);
+	has_progs = !!tr_link->tgt_progs;
+	info->tracing_multi.flags = has_progs ? BPF_F_TRACING_MULTI_TGT_PROGS : 0;
 
-	if (!uids && !ucookies && !uaddrs)
+	if (!uids && !ucookies && !uaddrs && !fids)
 		return 0;
+	if (has_progs != !!fids)
+		return -EINVAL;
 
 	if (ucount < tr_link->nodes_cnt)
 		err = -ENOSPC;
@@ -3733,20 +3744,27 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 
 	for (int i = 0; i < ucount; i++) {
 		struct bpf_tracing_multi_node *mnode = &tr_link->nodes[i];
+		u32 prog_id, btf_id;
 		u64 addr, cookie;
-		u32 id;
 
-		bpf_trampoline_unpack_key(mnode->trampoline->key, NULL, &id);
+		bpf_trampoline_unpack_key(mnode->trampoline->key, &prog_id, &btf_id);
 
-		addr = show_addrs ? mnode->trampoline->ip : 0;
+		if (!show_addrs)
+			addr = 0;
+		else if (has_progs)
+			addr = (u64) mnode->trampoline->func.addr;
+		else
+			addr = mnode->trampoline->ip;
 		cookie = has_cookies ? tr_link->cookies[i] : 0;
 
-		if (uids && put_user(id, uids + i))
+		if (uids && put_user(has_progs ? prog_id : btf_id, uids + i))
 			return -EFAULT;
 		if (uaddrs && put_user(addr, uaddrs + i))
 			return -EFAULT;
 		if (ucookies && put_user(cookie, ucookies + i))
 			return -EFAULT;
+		if (has_progs && put_user((u32) mnode->trampoline->key, fids + i))
+			return -EFAULT;
 
 		cond_resched();
 	}
@@ -3755,26 +3773,45 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 }
 
 #ifdef CONFIG_PROC_FS
+static const char *bpf_prog_func_name(struct bpf_prog *prog, u32 btf_id)
+{
+	const struct btf *btf = prog->aux->btf;
+	const struct btf_type *t;
+
+	t = btf_type_by_id(btf, btf_id);
+	if (!t || !btf_type_is_func(t))
+		return "";
+
+	return btf_name_by_offset(btf, t->name_off);
+}
+
 static void bpf_tracing_multi_show_fdinfo(const struct bpf_link *link,
 					  struct seq_file *seq)
 {
 	struct bpf_tracing_multi_link *tr_link =
 		container_of(link, struct bpf_tracing_multi_link, link);
 	bool has_cookies = !!tr_link->cookies;
+	bool has_progs = !!tr_link->tgt_progs;
 
 	seq_printf(seq, "attach_type:\t%u\n", tr_link->link.attach_type);
 	seq_printf(seq, "cnt:\t%u\n", tr_link->nodes_cnt);
 
-	seq_printf(seq, "%s\t %s\t %s\t %s\n", "obj-id", "btf-id", "cookie", "func");
+	seq_printf(seq, "%s\t %s\t %s\t %s\n", has_progs ? "prog-id" : "obj-id", "btf-id", "cookie",
+		   "func");
 	for (int i = 0; i < tr_link->nodes_cnt; i++) {
 		struct bpf_tracing_multi_node *mnode = &tr_link->nodes[i];
+		u64 cookie = has_cookies ? tr_link->cookies[i] : 0;
 		u32 btf_id, obj_id;
 
 		bpf_trampoline_unpack_key(mnode->trampoline->key, &obj_id, &btf_id);
-		seq_printf(seq, "%u\t %u\t %llu\t %pS\n",
-			   obj_id, btf_id,
-			   has_cookies ? tr_link->cookies[i] : 0,
-			   (void *) mnode->trampoline->ip);
+		if (has_progs)
+			seq_printf(seq, "%u\t %u\t %llu\t %s\n",
+				   obj_id, btf_id, cookie,
+				   bpf_prog_func_name(tr_link->tgt_progs[i], btf_id));
+		else
+			seq_printf(seq, "%u\t %u\t %llu\t %pS\n",
+				   obj_id, btf_id, cookie,
+				   (void *) mnode->trampoline->ip);
 
 		cond_resched();
 	}
@@ -3790,64 +3827,129 @@ static const struct bpf_link_ops bpf_tracing_multi_link_lops = {
 #endif
 };
 
-static int ids_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)
+struct tracing_multi_sort_data {
+	u64 *keys;
+	struct bpf_prog **progs;
+	u32 *ids;
+	u64 *cookies;
+};
+
+static int keys_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)
 {
-	u32 a = *(u32 *) pa;
-	u32 b = *(u32 *) pb;
+	const u64 *key_a = pa, *key_b = pb;
 
-	return (a > b) - (a < b);
+	return (*key_a > *key_b) - (*key_a < *key_b);
 }
 
-static void ids_swap_r(void *a, void *b, int size __maybe_unused,
-		       const void *priv __maybe_unused)
+static void keys_swap_r(void *a, void *b, int size __maybe_unused,
+			const void *priv __maybe_unused)
 {
+	const struct tracing_multi_sort_data *data = priv;
+	struct bpf_prog **prog_a, **prog_b;
 	u64 *cookie_a, *cookie_b, *cookies;
-	u32 *id_a = a, *id_b = b, *ids;
-	void **data = (void **) priv;
+	u64 *key_a = a, *key_b = b, *keys;
+	u32 *id_a, *id_b, *ids;
 
-	ids     = data[0];
-	cookies = data[1];
+	keys    = data->keys;
+	ids     = data->ids;
+	cookies = data->cookies;
+	id_a    = ids + (key_a - keys);
+	id_b    = ids + (key_b - keys);
+
+	if (data->progs) {
+		prog_a = data->progs + (key_a - keys);
+		prog_b = data->progs + (key_b - keys);
+		swap(*prog_a, *prog_b);
+	}
 
 	if (cookies) {
 		cookie_a = cookies + (id_a - ids);
 		cookie_b = cookies + (id_b - ids);
 		swap(*cookie_a, *cookie_b);
 	}
+
 	swap(*id_a, *id_b);
+	swap(*key_a, *key_b);
 }
 
-static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)
+static int check_dup_keys(u64 *keys, struct bpf_prog **progs, u32 *ids,
+			  u64 *cookies, u32 cnt)
 {
-	void *data[2] = { ids, cookies };
-	int err = 0;
+	struct tracing_multi_sort_data data = {
+		.keys = keys,
+		.progs = progs,
+		.ids = ids,
+		.cookies = cookies,
+	};
 
 	/*
-	 * Sort ids array (together with cookies array if defined)
-	 * and check it for duplicates. The ids and cookies arrays
-	 * are left sorted.
+	 * Sort trampoline keys together with target programs, ids, and cookies,
+	 * then check for duplicates. The arrays are left sorted.
 	 */
-	sort_r_nonatomic(ids, cnt, sizeof(ids[0]), ids_cmp_r, ids_swap_r, data);
+	sort_r_nonatomic(keys, cnt, sizeof(keys[0]), keys_cmp_r, keys_swap_r, &data);
 
-	for (int i = 1; i < cnt; i++) {
-		if (ids[i] == ids[i - 1]) {
+	for (int i = 1; i < cnt; i++)
+		if (keys[i] == keys[i - 1])
+			return -EINVAL;
+
+	return 0;
+}
+
+static void bpf_put_progs(struct bpf_prog **progs, int cnt)
+{
+	int i;
+
+	if (!progs)
+		return;
+
+	for (i = 0; i < cnt; i++)
+		bpf_prog_put(progs[i]);
+}
+
+static int bpf_get_progs(struct bpf_prog **progs, int *fds, int cnt)
+{
+	int err, i, put_cnt = 0;
+	struct bpf_prog *prog;
+
+	for (i = 0; i < cnt; i++) {
+		prog = bpf_prog_get(fds[i]);
+		if (IS_ERR(prog)) {
+			err = PTR_ERR(prog);
+			goto error;
+		}
+
+		progs[i] = prog;
+		put_cnt++;
+
+		if (prog->type == BPF_PROG_TYPE_TRACING) {
 			err = -EINVAL;
-			break;
+			goto error;
 		}
 	}
+	return 0;
+
+error:
+	bpf_put_progs(progs, put_cnt);
 	return err;
 }
 
 int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 {
 	struct bpf_tracing_multi_link *link = NULL;
+	struct btf *btf = prog->aux->attach_btf;
 	struct bpf_tramp_node *fexits = NULL;
 	struct bpf_link_primer link_primer;
+	struct bpf_text_poke **pokes = NULL;
+	u64 *cookies = NULL, *keys = NULL;
+	struct bpf_prog **progs = NULL;
 	u32 cnt, *ids = NULL;
 	u64 __user *ucookies;
-	u64 *cookies = NULL;
 	u32 __user *uids;
+	int __user *ufds;
+	int *fds = NULL;
 	int err;
 
+	ufds = u64_to_user_ptr(attr->link_create.tracing_multi.fds);
 	uids = u64_to_user_ptr(attr->link_create.tracing_multi.ids);
 	cnt = attr->link_create.tracing_multi.cnt;
 
@@ -3858,6 +3960,9 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 	if (attr->link_create.flags || attr->link_create.target_fd)
 		return -EINVAL;
 
+	if (!ufds && !IS_ENABLED(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS))
+		return -EOPNOTSUPP;
+
 	ids = kvmalloc_objs(*ids, cnt);
 	if (!ids)
 		return -ENOMEM;
@@ -3867,6 +3972,37 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 		goto error;
 	}
 
+	if (ufds) {
+		fds = kvmalloc_objs(*fds, cnt);
+		if (!fds) {
+			err = -ENOMEM;
+			goto error;
+		}
+
+		if (copy_from_user(fds, ufds, cnt * sizeof(*fds))) {
+			err = -EFAULT;
+			goto error;
+		}
+
+		progs = kvmalloc_objs(*progs, cnt);
+		if (!progs) {
+			err = -ENOMEM;
+			goto error;
+		}
+
+		err = bpf_get_progs(progs, fds, cnt);
+		if (err) {
+			cnt = 0;
+			goto error;
+		}
+
+		pokes = kvmalloc_objs(*pokes, cnt);
+		if (!pokes) {
+			err = -ENOMEM;
+			goto error;
+		}
+	}
+
 	ucookies = u64_to_user_ptr(attr->link_create.tracing_multi.cookies);
 	if (ucookies) {
 		cookies = kvmalloc_objs(*cookies, cnt);
@@ -3880,7 +4016,16 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 		}
 	}
 
-	err = check_dup_ids(ids, cookies, cnt);
+	keys = kvmalloc_objs(*keys, cnt);
+	if (!keys) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	for (int i = 0; i < cnt; i++)
+		keys[i] = bpf_trampoline_compute_key(progs ? progs[i] : NULL, btf, ids[i]);
+
+	err = check_dup_keys(keys, progs, ids, cookies, cnt);
 	if (err)
 		goto error;
 
@@ -3908,28 +4053,32 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 	link->nodes_cnt = cnt;
 	link->cookies = cookies;
 	link->fexits = fexits;
+	link->tgt_progs = progs;
+	link->pokes = pokes;
 
-	err = bpf_trampoline_multi_attach(prog, ids, link);
+	if (progs)
+		err = bpf_trampoline_multi_prog_attach(prog, ids, keys, link);
+	else
+		err = bpf_trampoline_multi_attach(prog, ids, link);
 	kvfree(ids);
+	kvfree(keys);
+	kvfree(fds);
 	if (err) {
+		bpf_put_progs(progs, cnt);
 		bpf_link_cleanup(&link_primer);
 		return err;
 	}
 	return bpf_link_settle(&link_primer);
 
 error:
+	bpf_put_progs(progs, cnt);
 	kvfree(fexits);
 	kvfree(cookies);
 	kvfree(ids);
+	kvfree(keys);
+	kvfree(fds);
+	kvfree(progs);
+	kvfree(pokes);
 	kvfree(link);
 	return err;
 }
-
-#else
-
-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
-{
-	return -EOPNOTSUPP;
-}
-
-#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS && CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS */
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 5cffa2d283b47..da7e430b14c8a 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -422,12 +422,31 @@ show_uprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 	jsonw_end_array(json_wtr);
 }
 
+#define BPF_PROG_PREFIX		"bpf_prog_"
+#define BPF_PROG_PREFIX_LEN	(sizeof(BPF_PROG_PREFIX) - 1)
+
+static const char *
+sym_name_trim_prefix(struct kernel_sym *sym, bool is_prog)
+{
+	int prefix_len;
+
+	if (!is_prog)
+		return sym->name;
+
+	/* Ref kernel/bpf/core.c::bpf_prog_ksym_set_name() */
+	prefix_len  = BPF_PROG_PREFIX_LEN;
+	prefix_len += BPF_TAG_SIZE * 2;
+	if (sym->name[prefix_len] != '\0')
+		prefix_len += 1;		/* skip the '_' */
+	return sym->name + prefix_len;
+}
+
 static void
 show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 {
-	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;
+	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;
 	__u64 *addrs, *cookies;
-	__u32 i, *ids;
+	__u32 i, *ids, *fids;
 
 	if (!dd.sym_count)
 		kernel_syms_load(&dd);
@@ -443,6 +462,8 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 	ids = u64_to_u32_arr(info->tracing_multi.ids);
 	addrs = u64_to_arr(info->tracing_multi.addrs);
 	cookies = u64_to_arr(info->tracing_multi.cookies);
+	fids = u64_to_u32_arr(info->tracing_multi.func_btf_ids);
+	tgt_progs = info->tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
 
 	for (i = 0; i < info->tracing_multi.count; i++) {
 		struct kernel_sym *sym;
@@ -451,10 +472,12 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 		sym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;
 
 		jsonw_start_object(wtr);
-		jsonw_uint_field(wtr, "id", ids[i]);
+		jsonw_uint_field(wtr, tgt_progs ? "prog_id" : "id", ids[i]);
+		if (tgt_progs)
+			jsonw_uint_field(wtr, "func_btf_id", fids[i]);
 		jsonw_uint_field(wtr, "addr", addr);
 		if (sym) {
-			jsonw_string_field(wtr, "func", sym->name);
+			jsonw_string_field(wtr, "func", sym_name_trim_prefix(sym, tgt_progs));
 			if (sym->module[0] == '\0') {
 				jsonw_name(wtr, "module");
 				jsonw_null(wtr);
@@ -903,9 +926,9 @@ static void show_uprobe_multi_plain(struct bpf_link_info *info)
 
 static void show_tracing_multi_plain(struct bpf_link_info *info)
 {
-	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;
+	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;
 	__u64 *addrs, *cookies;
-	__u32 i, *ids;
+	__u32 i, *ids, *fids;
 
 	if (!info->tracing_multi.count)
 		return;
@@ -919,12 +942,18 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)
 	printf("btf_obj_id %u  ", info->tracing_multi.btf_obj_id);
 	printf("count %u  ", info->tracing_multi.count);
 
-	printf("\n\t%-16s %-16s %-16s %s",
-	       "btf_id", "addr", "cookie", "func [module]");
+	tgt_progs = info->tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
+	if (tgt_progs)
+		printf("\n\t%-16s %-16s %-16s %-16s %s",
+		       "prog_id", "func_btf_id", "addr", "cookie", "func [module]");
+	else
+		printf("\n\t%-16s %-16s %-16s %s",
+		       "btf_id", "addr", "cookie", "func [module]");
 
 	ids = u64_to_u32_arr(info->tracing_multi.ids);
 	addrs = u64_to_arr(info->tracing_multi.addrs);
 	cookies = u64_to_arr(info->tracing_multi.cookies);
+	fids = u64_to_u32_arr(info->tracing_multi.func_btf_ids);
 
 	for (i = 0; i < info->tracing_multi.count; i++) {
 		__u64 addr = addrs[i];
@@ -932,9 +961,13 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)
 
 		sym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;
 
-		printf("\n\t%-16u %016llx %-16llu", ids[i], addr, cookies[i]);
+		if (tgt_progs)
+			printf("\n\t%-16u %-16u %016llx %-16llu",
+			       ids[i], fids[i], addr, cookies[i]);
+		else
+			printf("\n\t%-16u %016llx %-16llu", ids[i], addr, cookies[i]);
 		if (sym) {
-			printf(" %s", sym->name);
+			printf(" %s", sym_name_trim_prefix(sym, tgt_progs));
 			if (sym->module[0] != '\0')
 				printf(" [%s]", sym->module);
 		}
@@ -1140,7 +1173,7 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
 static int do_show_link(int fd)
 {
 	__u64 *ref_ctr_offsets = NULL, *offsets = NULL, *cookies = NULL;
-	__u32 *ids = NULL;
+	__u32 *ids = NULL, *func_btf_ids = NULL;
 	struct bpf_link_info info;
 	__u32 len = sizeof(info);
 	char path_buf[PATH_MAX];
@@ -1229,12 +1262,16 @@ static int do_show_link(int fd)
 	if (info.type == BPF_LINK_TYPE_TRACING_MULTI && !info.tracing_multi.ids) {
 		count = info.tracing_multi.count;
 		if (count) {
+			bool tgt_progs = info.tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
+
 			ids = calloc(count, sizeof(__u32));
 			addrs = calloc(count, sizeof(__u64));
 			cookies = calloc(count, sizeof(__u64));
-			if (!ids || !addrs || !cookies) {
+			func_btf_ids = tgt_progs ? calloc(count, sizeof(__u32)) : NULL;
+			if (!ids || !addrs || !cookies || (tgt_progs && !func_btf_ids)) {
 				p_err("mem alloc failed");
 				close(fd);
+				free(func_btf_ids);
 				free(cookies);
 				free(addrs);
 				free(ids);
@@ -1243,6 +1280,7 @@ static int do_show_link(int fd)
 			info.tracing_multi.ids = ptr_to_u64(ids);
 			info.tracing_multi.addrs = ptr_to_u64(addrs);
 			info.tracing_multi.cookies = ptr_to_u64(cookies);
+			info.tracing_multi.func_btf_ids = ptr_to_u64(func_btf_ids);
 			goto again;
 		}
 	}
@@ -1282,6 +1320,7 @@ static int do_show_link(int fd)
 		show_link_close_plain(fd, &info);
 
 	free(ref_ctr_offsets);
+	free(func_btf_ids);
 	free(cookies);
 	free(offsets);
 	free(addrs);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 6f70db7515dd4..60998ea1381ce 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1927,6 +1927,8 @@ union bpf_attr {
 				__aligned_u64	ids;
 				__aligned_u64	cookies;
 				__u32		cnt;
+				__u32		:32;
+				__aligned_u64	fds;
 			} tracing_multi;
 		};
 	} link_create;
@@ -6815,6 +6817,10 @@ struct sk_reuseport_md {
 
 #define BPF_TAG_SIZE	8
 
+enum {
+	BPF_F_TRACING_MULTI_TGT_PROGS = (1U << 0),
+};
+
 struct bpf_prog_info {
 	__u32 type;
 	__u32 id;
@@ -6974,10 +6980,11 @@ struct bpf_link_info {
 			__u32 attach_type;
 			__u32 count; /* in/out: tracing_multi target count */
 			__u32 btf_obj_id;
-			__u32 :32;
+			__u32 flags;
 			__aligned_u64 ids;
 			__aligned_u64 addrs;
 			__aligned_u64 cookies;
+			__aligned_u64 func_btf_ids;
 		} tracing_multi;
 		struct {
 			__u32 type; /* enum bpf_perf_event_type */
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index b49822d212aed..4a78ccba9df2d 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -852,6 +852,7 @@ int bpf_link_create(int prog_fd, int target_fd,
 		attr.link_create.tracing_multi.ids = ptr_to_u64(OPTS_GET(opts, tracing_multi.ids, 0));
 		attr.link_create.tracing_multi.cookies = ptr_to_u64(OPTS_GET(opts, tracing_multi.cookies, 0));
 		attr.link_create.tracing_multi.cnt = OPTS_GET(opts, tracing_multi.cnt, 0);
+		attr.link_create.tracing_multi.fds = ptr_to_u64(OPTS_GET(opts, tracing_multi.fds, 0));
 		if (!OPTS_ZEROED(opts, tracing_multi))
 			return libbpf_err(-EINVAL);
 		break;
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 826d9cc9ab65d..cc37cf622dd85 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -474,6 +474,8 @@ struct bpf_link_create_opts {
 			const __u32 *ids;
 			const __u64 *cookies;
 			__u32 cnt;
+			__u32 :32;
+			const int *fds;
 		} tracing_multi;
 	};
 	size_t :0;
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index cb09ded907732..72e2459e93399 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11604,7 +11604,7 @@ int libbpf_find_vmlinux_btf_id(const char *name,
 	return libbpf_err(err);
 }
 
-static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd)
+int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd)
 {
 	struct bpf_prog_info info;
 	__u32 info_len = sizeof(info);
@@ -13671,10 +13671,12 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa
 {
 	LIBBPF_OPTS(bpf_link_create_opts, lopts);
 	int prog_fd, link_fd, err, cnt;
+	struct bpf_link *link = NULL;
 	__u32 *free_ids = NULL;
-	struct bpf_link *link;
 	const __u64 *cookies;
+	const char **funcs;
 	const __u32 *ids;
+	const int *fds;
 
 	if (!OPTS_VALID(opts, bpf_tracing_multi_opts))
 		return libbpf_err_ptr(-EINVAL);
@@ -13689,12 +13691,22 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa
 	cnt = OPTS_GET(opts, cnt, 0);
 	ids = OPTS_GET(opts, ids, NULL);
 	cookies = OPTS_GET(opts, cookies, NULL);
+	fds = OPTS_GET(opts, fds, NULL);
+	funcs = OPTS_GET(opts, funcs, NULL);
 
-	if (!!ids != !!cnt)
+	if (ids && fds)
+		return libbpf_err_ptr(-EINVAL);
+	if (!!fds != !!funcs)
+		return libbpf_err_ptr(-EINVAL);
+	if (fds && !cnt)
 		return libbpf_err_ptr(-EINVAL);
-	if (pattern && (ids || cookies))
+	if (ids && !cnt)
 		return libbpf_err_ptr(-EINVAL);
-	if (!pattern && !ids)
+	if (!fds && !ids && cnt)
+		return libbpf_err_ptr(-EINVAL);
+	if (pattern && (fds || ids || cookies))
+		return libbpf_err_ptr(-EINVAL);
+	if (!pattern && !ids && !fds)
 		return libbpf_err_ptr(-EINVAL);
 
 	if (pattern) {
@@ -13704,11 +13716,32 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa
 		if (cnt == 0)
 			return libbpf_err_ptr(-EINVAL);
 		ids = (const __u32 *) free_ids;
+	} else if (fds) {
+		size_t cap = 0;
+		int i;
+
+		err = libbpf_ensure_mem((void **) &free_ids, &cap, sizeof(*free_ids), cnt);
+		if (err)
+			return libbpf_err_ptr(err);
+
+		for (i = 0; i < cnt; i++) {
+			if (!funcs[i]) {
+				err = -EINVAL;
+				goto error;
+			}
+			err = libbpf_find_prog_btf_id(funcs[i], fds[i], prog->obj->token_fd);
+			if (err < 0)
+				goto error;
+
+			free_ids[i] = err;
+		}
+		ids = (const __u32 *) free_ids;
 	}
 
 	lopts.tracing_multi.ids = ids;
 	lopts.tracing_multi.cookies = cookies;
 	lopts.tracing_multi.cnt = cnt;
+	lopts.tracing_multi.fds = fds;
 
 	link = calloc(1, sizeof(*link));
 	if (!link) {
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 03f794f4adb03..612f3e17ebc25 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -746,10 +746,12 @@ struct bpf_tracing_multi_opts {
 	const __u32 *ids;
 	const __u64 *cookies;
 	size_t cnt;
+	const int *fds;
+	const char **funcs;
 	size_t :0;
 };
 
-#define bpf_tracing_multi_opts__last_field cnt
+#define bpf_tracing_multi_opts__last_field funcs
 
 LIBBPF_API struct bpf_link *
 bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pattern,
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 4e45dfacb548a..d4e899181bddc 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -439,6 +439,7 @@ int btf_load_into_kernel(struct btf *btf,
 			 char *log_buf, size_t log_sz, __u32 log_level,
 			 int token_fd);
 struct btf *btf_load_from_kernel(__u32 id, struct btf *base_btf, int token_fd);
+int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd);
 
 struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf);
 void btf_get_kernel_prefix_kind(enum bpf_attach_type attach_type,
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 80d8bbbc3084a..23bed732d1bdd 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -625,6 +625,7 @@ $(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/bloom_filter_bench.skel.h
 $(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop_bench.skel.h
 $(OUTPUT)/bench_bpf_for.o: $(OUTPUT)/bpf_for_bench.skel.h
 $(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_bench.skel.h
+$(OUTPUT)/bench_tracing_multi_attach_progs.o: $(OUTPUT)/tracing_multi_attach_progs.skel.h
 $(OUTPUT)/bench_bpf_hashmap_full_update.o: $(OUTPUT)/bpf_hashmap_full_update_bench.skel.h
 $(OUTPUT)/bench_local_storage.o: $(OUTPUT)/local_storage_bench.skel.h
 $(OUTPUT)/bench_local_storage_rcu_tasks_trace.o: $(OUTPUT)/local_storage_rcu_tasks_trace_bench.skel.h
diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
index d5f494184f9d1..c7502187e6541 100644
--- a/tools/testing/selftests/bpf/bench.c
+++ b/tools/testing/selftests/bpf/bench.c
@@ -529,6 +529,9 @@ extern const struct bench bench_trig_fmodret;
 extern const struct bench bench_trig_tp;
 extern const struct bench bench_trig_rawtp;
 
+/* tracing_multi link attachment benchmark */
+extern const struct bench bench_tracing_multi_attach_progs;
+
 /* uprobe/uretprobe benchmarks */
 extern const struct bench bench_trig_uprobe_nop;
 extern const struct bench bench_trig_uretprobe_nop;
@@ -615,6 +618,8 @@ static const struct bench *benchs[] = {
 	&bench_trig_fmodret,
 	&bench_trig_tp,
 	&bench_trig_rawtp,
+	/* tracing_multi */
+	&bench_tracing_multi_attach_progs,
 	/* uprobes */
 	&bench_trig_uprobe_nop,
 	&bench_trig_uretprobe_nop,
diff --git a/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c
new file mode 100644
index 0000000000000..6cc6851eb488e
--- /dev/null
+++ b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <string.h>
+#include "bench.h"
+#include "testing_helpers.h"
+#include "tracing_multi_attach_progs.skel.h"
+#include "bpf/libbpf_internal.h"
+
+#define TARGET_CNT 1000
+
+static struct ctx {
+	struct tracing_multi_attach_progs *targets[TARGET_CNT];
+	struct tracing_multi_attach_progs *fentries[TARGET_CNT];
+	struct tracing_multi_attach_progs *fentry_multi;
+	int target_fds[TARGET_CNT];
+	__u32 target_btf_ids[TARGET_CNT];
+	int fentry_prog_fds[TARGET_CNT];
+	int fentry_multi_prog_fd;
+} ctx;
+
+static void prepare(void)
+{
+	int err, i;
+
+	setup_libbpf();
+
+	for (i = 0; i < TARGET_CNT; i++) {
+		struct tracing_multi_attach_progs *target;
+		int btf_id, fd, obj_token_fd;
+
+		target = tracing_multi_attach_progs__open();
+		if (!target) {
+			fprintf(stderr, "failed to open target program %d\n", i);
+			exit(1);
+		}
+
+		bpf_program__set_autoload(target->progs.dummy_fentry, false);
+		bpf_program__set_autoload(target->progs.dummy_fentry_multi, false);
+		err = tracing_multi_attach_progs__load(target);
+		if (err) {
+			fprintf(stderr, "failed to load target program %d: %s\n",
+				i, strerror(-err));
+			exit(1);
+		}
+
+		fd = bpf_program__fd(target->progs.target);
+		obj_token_fd = bpf_object__token_fd(target->obj);
+		obj_token_fd = obj_token_fd < 0 ? 0 : obj_token_fd;
+		btf_id = libbpf_find_prog_btf_id("target", fd, obj_token_fd);
+		if (btf_id <= 0) {
+			fprintf(stderr, "failed to find target BTF ID: %s\n",
+				strerror(-btf_id));
+			exit(1);
+		}
+
+		ctx.targets[i] = target;
+		ctx.target_fds[i] = fd;
+		ctx.target_btf_ids[i] = btf_id;
+	}
+}
+
+static long create_and_attach_fentry(void)
+{
+	int link_fds[TARGET_CNT];
+	long start_ns, end_ns;
+	int err, i, j;
+
+	start_ns = get_time_ns();
+
+	/* An ordinary fentry program is bound to one target when it is loaded. */
+	for (i = 0; i < TARGET_CNT; i++) {
+		struct tracing_multi_attach_progs *fentry;
+
+		fentry = tracing_multi_attach_progs__open();
+		if (!fentry) {
+			fprintf(stderr, "failed to open fentry program %d\n", i);
+			exit(1);
+		}
+
+		bpf_program__set_autoload(fentry->progs.target, false);
+		bpf_program__set_autoload(fentry->progs.dummy_fentry_multi, false);
+		err = bpf_program__set_attach_target(fentry->progs.dummy_fentry, ctx.target_fds[i],
+						     "target");
+		err = err ?: tracing_multi_attach_progs__load(fentry);
+		if (err) {
+			fprintf(stderr, "failed to load fentry program %d: %s\n",
+				i, strerror(-err));
+			exit(1);
+		}
+
+		ctx.fentries[i] = fentry;
+		ctx.fentry_prog_fds[i] = bpf_program__fd(fentry->progs.dummy_fentry);
+	}
+
+	for (i = 0; i < TARGET_CNT; i++) {
+		link_fds[i] = bpf_link_create(ctx.fentry_prog_fds[i], 0, BPF_TRACE_FENTRY, NULL);
+		if (link_fds[i] < 0) {
+			err = errno;
+			for (j = 0; j < i; j++)
+				close(link_fds[j]);
+			fprintf(stderr, "failed to create fentry link %d: %s\n",
+				i, strerror(err));
+			exit(1);
+		}
+	}
+	end_ns = get_time_ns();
+
+	for (i = 0; i < TARGET_CNT; i++)
+		close(link_fds[i]);
+
+	return end_ns - start_ns;
+}
+
+static long create_and_attach_fentry_multi(void)
+{
+	LIBBPF_OPTS(bpf_link_create_opts, opts);
+	long start_ns, end_ns;
+	int err, link_fd;
+
+	opts.tracing_multi.ids = ctx.target_btf_ids;
+	opts.tracing_multi.fds = ctx.target_fds;
+	opts.tracing_multi.cnt = TARGET_CNT;
+
+	start_ns = get_time_ns();
+
+	ctx.fentry_multi = tracing_multi_attach_progs__open();
+	if (!ctx.fentry_multi) {
+		fprintf(stderr, "failed to open fentry.multi program\n");
+		exit(1);
+	}
+
+	bpf_program__set_autoload(ctx.fentry_multi->progs.target, false);
+	bpf_program__set_autoload(ctx.fentry_multi->progs.dummy_fentry, false);
+	err = tracing_multi_attach_progs__load(ctx.fentry_multi);
+	if (err) {
+		fprintf(stderr, "failed to load fentry.multi program: %s\n",
+			strerror(-err));
+		exit(1);
+	}
+
+	ctx.fentry_multi_prog_fd = bpf_program__fd(ctx.fentry_multi->progs.dummy_fentry_multi);
+	link_fd = bpf_link_create(ctx.fentry_multi_prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &opts);
+	end_ns = get_time_ns();
+	if (link_fd < 0) {
+		err = errno;
+		fprintf(stderr, "failed to create fentry.multi link: %s\n",
+			strerror(err));
+		exit(1);
+	}
+
+	close(link_fd);
+	return end_ns - start_ns;
+}
+
+static void cleanup(void)
+{
+	int i;
+
+	tracing_multi_attach_progs__destroy(ctx.fentry_multi);
+	for (i = 0; i < TARGET_CNT; i++) {
+		tracing_multi_attach_progs__destroy(ctx.fentries[i]);
+		tracing_multi_attach_progs__destroy(ctx.targets[i]);
+	}
+}
+
+static void setup(void)
+{
+	double fentry_multi_ms, fentry_ms;
+	long fentry_multi_ns, fentry_ns;
+
+	prepare();
+	fentry_ns = create_and_attach_fentry();
+	fentry_multi_ns = create_and_attach_fentry_multi();
+	fentry_ms = fentry_ns / 1000000.0;
+	fentry_multi_ms = fentry_multi_ns / 1000000.0;
+
+	printf("%s: prepared %d identical BPF program targets\n",
+	       bench->name, TARGET_CNT);
+	printf("%s: fentry created and attached %d programs/links in %-.3lfms\n",
+	       bench->name, TARGET_CNT, fentry_ms);
+	printf("%s: fentry.multi created one program and attached one %d-target link in %-.3lfms\n",
+	       bench->name, TARGET_CNT, fentry_multi_ms);
+	printf("%s: fentry.multi creation/attachment speedup is %-.2lfx\n",
+	       bench->name, fentry_ms / fentry_multi_ms);
+
+	cleanup();
+	exit(0);
+}
+
+const struct bench bench_tracing_multi_attach_progs = {
+	.name = "tracing-multi-attach-progs",
+	.setup = setup,
+};
diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
index 0918321c8e63d..422e94f134094 100644
--- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
@@ -3,11 +3,13 @@
 
 #include <string.h>
 #include <linux/bpf.h>
+#include <linux/kallsyms.h>
 #include <linux/limits.h>
 #include <bpf/btf.h>
 #include <test_progs.h>
 #include "trace_helpers.h"
 #include "test_fill_link_info.skel.h"
+#include "tracing_multi_bpf.skel.h"
 #include "bpf/libbpf_internal.h"
 
 #define TP_CAT "sched"
@@ -39,8 +41,19 @@ struct tmulti_target {
 	__u64 addr;
 	__u64 cookie;
 	__u32 id;
+	__u32 func_btf_id;
 };
 
+static const char *tmulti_bpf_funcs[] = {
+	"target_1",
+	"target_2",
+};
+
+static __u64 tmulti_bpf_fentry_cookies[] = { 0xfeed01, 0xfeed02 };
+static __u64 tmulti_bpf_fexit_cookies[] = { 0xfeed11, 0xfeed12 };
+static __u64 tmulti_bpf_fsession_cookies[] = { 0xfeed21, 0xfeed22 };
+#define TRACING_MULTI_BPF_CNT ARRAY_SIZE(tmulti_bpf_funcs)
+
 #define UPROBE_FILE "/proc/self/exe"
 static ssize_t uprobe_offset;
 /* uprobe attach point */
@@ -421,14 +434,28 @@ static int tmulti_target_cmp(const void *a, const void *b)
 	return (ta->id > tb->id) - (ta->id < tb->id);
 }
 
+static int setup_tmulti_btf_obj_id(const struct bpf_program *prog, __u32 *btf_obj_id)
+{
+	struct bpf_prog_info prog_info = {};
+	__u32 len = sizeof(prog_info);
+	int err;
+
+	err = bpf_prog_get_info_by_fd(bpf_program__fd(prog), &prog_info, &len);
+	if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
+		return -1;
+	if (!ASSERT_GT(prog_info.attach_btf_obj_id, 0, "attach_btf_obj_id"))
+		return -1;
+
+	*btf_obj_id = prog_info.attach_btf_obj_id;
+	return 0;
+}
+
 static int setup_tmulti_targets(const struct bpf_program *prog,
 				struct tmulti_target *targets,
 				__u32 *btf_obj_id)
 {
-	struct bpf_prog_info prog_info;
-	__u32 len = sizeof(prog_info);
 	struct btf *btf;
-	int err, i;
+	int i;
 	__s32 id;
 
 	btf = btf__load_vmlinux_btf();
@@ -446,13 +473,8 @@ static int setup_tmulti_targets(const struct bpf_program *prog,
 		targets[i].id = id;
 	}
 
-	memset(&prog_info, 0, len);
-	err = bpf_prog_get_info_by_fd(bpf_program__fd(prog), &prog_info, &len);
-	if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
-		goto error;
-	if (!ASSERT_GT(prog_info.attach_btf_obj_id, 0, "attach_btf_obj_id"))
+	if (setup_tmulti_btf_obj_id(prog, btf_obj_id))
 		goto error;
-	*btf_obj_id = prog_info.attach_btf_obj_id;
 
 	/*
 	 * The kernel tracing multi attach sorts ids. We sort as well,
@@ -467,13 +489,49 @@ static int setup_tmulti_targets(const struct bpf_program *prog,
 	return -1;
 }
 
+static int setup_tmulti_bpf_prog_targets(const struct bpf_program *prog, int token_fd,
+					 const __u64 *cookies,
+					 const struct bpf_program * const *target_progs,
+					 struct tmulti_target *targets,
+					 __u32 *btf_obj_id)
+{
+	struct bpf_prog_info prog_info = {};
+	__u32 len = sizeof(prog_info), func_btf_id;
+	int err, i, prog_fd;
+
+	for (i = 0; i < TRACING_MULTI_BPF_CNT; i++) {
+		memset(&prog_info, 0, sizeof(prog_info));
+		len = sizeof(prog_info);
+		prog_info.jited_ksyms = ptr_to_u64(&targets[i].addr);
+		prog_info.nr_jited_ksyms = 1;
+		prog_fd = bpf_program__fd(target_progs[i]);
+		err = bpf_prog_get_info_by_fd(prog_fd, &prog_info, &len);
+		if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
+			return -1;
+
+		func_btf_id = libbpf_find_prog_btf_id(tmulti_bpf_funcs[i], prog_fd, token_fd);
+		if (!ASSERT_GT(func_btf_id, 0, "libbpf_find_prog_btf_id"))
+			return -1;
+
+		targets[i].cookie = cookies[i];
+		targets[i].id = prog_info.id;
+		targets[i].func_btf_id = func_btf_id;
+	}
+
+	qsort(targets, TRACING_MULTI_BPF_CNT, sizeof(targets[0]), tmulti_target_cmp);
+	return setup_tmulti_btf_obj_id(prog, btf_obj_id);
+}
+
 static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog,
 					  const struct tmulti_target *targets,
-					  __u32 btf_obj_id, bool has_cookies)
+					  __u32 btf_obj_id, __u32 count,
+					  bool has_cookies, bool tgt_progs)
 {
+#define TMULTI_CNT (TRACING_MULTI_CNT > TRACING_MULTI_BPF_CNT ? \
+		    TRACING_MULTI_CNT : TRACING_MULTI_BPF_CNT)
 	enum bpf_attach_type attach_type = bpf_program__expected_attach_type(prog);
-	__u64 addrs[TRACING_MULTI_CNT], cookies[TRACING_MULTI_CNT];
-	__u32 ids[TRACING_MULTI_CNT];
+	__u64 addrs[TMULTI_CNT], cookies[TMULTI_CNT];
+	__u32 ids[TMULTI_CNT], fids[TMULTI_CNT];
 	struct bpf_link_info info;
 	__u32 len = sizeof(info);
 	int err, i;
@@ -487,16 +545,21 @@ static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog
 		return -1;
 
 	ASSERT_EQ(info.tracing_multi.attach_type, attach_type, "info.tracing_multi.attach_type");
-	ASSERT_EQ(info.tracing_multi.count, TRACING_MULTI_CNT, "info.tracing_multi.count");
+	ASSERT_EQ(info.tracing_multi.count, count, "info.tracing_multi.count");
+	if (tgt_progs)
+		ASSERT_TRUE(info.tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS,
+			    "info.tracing_multi.flags");
 
 	memset(ids, 0, sizeof(ids));
+	memset(fids, 0, sizeof(fids));
 	memset(cookies, 0, sizeof(cookies));
 	memset(addrs, 0, sizeof(addrs));
 
 	info.tracing_multi.ids = ptr_to_u64(ids);
 	info.tracing_multi.addrs = ptr_to_u64(addrs);
 	info.tracing_multi.cookies = has_cookies ? ptr_to_u64(cookies) : 0;
-	info.tracing_multi.count = TRACING_MULTI_CNT;
+	info.tracing_multi.func_btf_ids = tgt_progs ? ptr_to_u64(fids) : 0;
+	info.tracing_multi.count = count;
 
 	err = bpf_link_get_info_by_fd(fd, &info, &len);
 	if (!ASSERT_OK(err, "bpf_link_get_info_by_fd"))
@@ -506,14 +569,20 @@ static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog
 		return -1;
 
 	ASSERT_EQ(info.tracing_multi.attach_type, attach_type, "info.tracing_multi.attach_type");
-	ASSERT_EQ(info.tracing_multi.count, TRACING_MULTI_CNT, "info.tracing_multi.count");
+	ASSERT_EQ(info.tracing_multi.count, count, "info.tracing_multi.count");
 	ASSERT_EQ(info.tracing_multi.btf_obj_id, btf_obj_id, "tracing_multi.btf_obj_id");
+	if (tgt_progs)
+		ASSERT_TRUE(info.tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS,
+			    "info.tracing_multi.flags");
 
-	for (i = 0; i < TRACING_MULTI_CNT; i++) {
+	for (i = 0; i < count; i++) {
 		ASSERT_EQ(ids[i], targets[i].id, "tracing_multi.ids");
 		ASSERT_EQ(cookies[i], has_cookies ? targets[i].cookie : 0, "tracing_multi.cookies");
 
-		if (targets[i].addr) {
+		if (tgt_progs) {
+			ASSERT_EQ(addrs[i], targets[i].addr, "tracing_multi.addrs");
+			ASSERT_EQ(fids[i], targets[i].func_btf_id, "tracing_multi.func_btf_ids");
+		} else if (targets[i].addr) {
 			struct ksym *ksym;
 
 			if (!ASSERT_NEQ(addrs[i], 0, "tracing_multi.addrs"))
@@ -624,13 +693,73 @@ static void test_tracing_multi_fill_link_info(struct test_fill_link_info *skel,
 		verify_tracing_multi_invalid_user_buffer(link_fd, targets);
 	} else {
 		err = verify_tracing_multi_link_info(link_fd, skel->progs.tmulti_run,
-						     targets, btf_obj_id, has_cookies);
+						     targets, btf_obj_id, TRACING_MULTI_CNT,
+						     has_cookies, false);
 		ASSERT_OK(err, "verify_tracing_multi_link_info");
 	}
 
 	bpf_link__destroy(link);
 }
 
+static void test_tracing_multi_bpf_fill_link_info_one(struct tracing_multi_bpf *skel,
+						      struct bpf_program *prog,
+						      __u64 *cookies,
+						      bool has_cookies)
+{
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	const struct bpf_program *target_progs[] = {
+		skel->progs.target_1,
+		skel->progs.target_2,
+	};
+	struct tmulti_target targets[TRACING_MULTI_BPF_CNT] = {};
+	int fds[TRACING_MULTI_BPF_CNT], token_fd, err, i;
+	struct bpf_link *link;
+	__u32 btf_obj_id;
+
+	token_fd = bpf_object__token_fd(skel->obj);
+	token_fd = token_fd < 0 ? 0 : token_fd;
+
+	if (setup_tmulti_bpf_prog_targets(prog, token_fd, cookies, target_progs, targets,
+					  &btf_obj_id))
+		return;
+
+	for (i = 0; i < TRACING_MULTI_BPF_CNT; i++)
+		fds[i] = bpf_program__fd(target_progs[i]);
+
+	opts.fds = fds;
+	opts.funcs = tmulti_bpf_funcs;
+	opts.cnt = ARRAY_SIZE(fds);
+	opts.cookies = has_cookies ? cookies : NULL;
+
+	link = bpf_program__attach_tracing_multi(prog, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "bpf_program__attach_tracing_multi"))
+		return;
+
+	err = verify_tracing_multi_link_info(bpf_link__fd(link), prog, targets, btf_obj_id,
+					     TRACING_MULTI_BPF_CNT, has_cookies, true);
+	ASSERT_OK(err, "verify_tracing_multi_link_info");
+
+	bpf_link__destroy(link);
+}
+
+static void test_tracing_multi_bpf_fill_link_info(bool has_cookies)
+{
+	struct tracing_multi_bpf *skel;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	test_tracing_multi_bpf_fill_link_info_one(skel, skel->progs.test_fentry,
+						  tmulti_bpf_fentry_cookies, has_cookies);
+	test_tracing_multi_bpf_fill_link_info_one(skel, skel->progs.test_fexit,
+						  tmulti_bpf_fexit_cookies, has_cookies);
+	test_tracing_multi_bpf_fill_link_info_one(skel, skel->progs.test_fsession,
+						  tmulti_bpf_fsession_cookies, has_cookies);
+
+	tracing_multi_bpf__destroy(skel);
+}
+
 #define SEC(name) __attribute__((section(name), used))
 
 static short uprobe_link_info_sema_1 SEC(".probes");
@@ -879,6 +1008,10 @@ void test_fill_link_info(void)
 		test_tracing_multi_fill_link_info(skel, false, false);
 		test_tracing_multi_fill_link_info(skel, true, false);
 	}
+	if (test__start_subtest("tracing_multi_bpf_link_info")) {
+		test_tracing_multi_bpf_fill_link_info(false);
+		test_tracing_multi_bpf_fill_link_info(true);
+	}
 	if (test__start_subtest("tracing_multi_invalid_ubuff"))
 		test_tracing_multi_fill_link_info(skel, true, true);
 
diff --git a/tools/testing/selftests/bpf/prog_tests/tailcalls.c b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
index 88d223110ecd5..3b122520711b0 100644
--- a/tools/testing/selftests/bpf/prog_tests/tailcalls.c
+++ b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
@@ -16,7 +16,9 @@
 #include "tailcall_sleepable.skel.h"
 #include "tailcall_callback.skel.h"
 #include "tailcall_bpf2bpf2.skel.h"
+#include "tailcall_bpf2bpf4.skel.h"
 #include "tailcall_bpf2bpf_fexit.skel.h"
+#include "tracing_multi_bpf.skel.h"
 
 /* test_tailcall_1 checks basic functionality by patching multiple locations
  * in a single program for a single tail call slot with nop->jmp, jmp->nop
@@ -2065,6 +2067,66 @@ static void test_tailcall_large_stack(void)
 	tailcall_large_stack__destroy(skel);
 }
 
+/*
+ * Verify that a tail call from a BPF subprog works when the subprog is
+ * traced by fentry.multi.
+ */
+static void test_tailcall_bpf2bpf_fentry_multi(void)
+{
+	static const char *funcs[] = { "subprog_tail_2" };
+	struct tracing_multi_bpf *skel_tracing = NULL;
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	struct tailcall_bpf2bpf4 *skel_tc;
+	struct bpf_link *link = NULL;
+	int fds[ARRAY_SIZE(funcs)];
+	char buff[128] = {};
+	int err, key;
+	LIBBPF_OPTS(bpf_test_run_opts, topts,
+		.data_in = buff,
+		.data_size_in = sizeof(buff),
+		.repeat = 1,
+	);
+
+	skel_tc = tailcall_bpf2bpf4__open_and_load();
+	if (!ASSERT_OK_PTR(skel_tc, "tailcall_bpf2bpf4__open_and_load"))
+		return;
+
+	skel_tracing = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel_tracing, "tracing_multi_bpf__open_and_load"))
+		goto out;
+
+	key = 0;
+	fds[0] = bpf_program__fd(skel_tc->progs.classifier_2);
+	err = bpf_map_update_elem(bpf_map__fd(skel_tc->maps.jmp_table), &key, &fds[0], BPF_ANY);
+	if (!ASSERT_OK(err, "bpf_map_update_elem"))
+		goto out;
+
+	key = 2;
+	err = bpf_map_update_elem(bpf_map__fd(skel_tc->maps.jmp_table), &key, &fds[0], BPF_ANY);
+	if (!ASSERT_OK(err, "bpf_map_update_elem_loop"))
+		goto out;
+
+	opts.fds = fds;
+	opts.funcs = funcs;
+	opts.cnt = ARRAY_SIZE(fds);
+	link = bpf_program__attach_tracing_multi(skel_tracing->progs.test_fentry, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "bpf_program__attach_tracing_multi"))
+		goto out;
+
+	err = bpf_prog_test_run_opts(bpf_program__fd(skel_tc->progs.entry), &topts);
+	if (!ASSERT_OK(err, "bpf_prog_test_run_opts"))
+		goto out;
+
+	ASSERT_EQ(topts.retval, sizeof(buff) * 3, "retval");
+	ASSERT_EQ(skel_tc->bss->count, 33, "count");
+	ASSERT_EQ(skel_tracing->bss->test_result_fentry, 33, "fentry.multi count");
+
+out:
+	bpf_link__destroy(link);
+	tracing_multi_bpf__destroy(skel_tracing);
+	tailcall_bpf2bpf4__destroy(skel_tc);
+}
+
 void test_tailcalls(void)
 {
 	if (test__start_subtest("tailcall_1"))
@@ -2138,4 +2200,6 @@ void test_tailcalls(void)
 		test_tailcall_bpf2bpf_fexit_links();
 	if (test__start_subtest("tailcall_large_stack"))
 		test_tailcall_large_stack();
+	if (test__start_subtest("tailcall_bpf2bpf_fentry_multi"))
+		test_tailcall_bpf2bpf_fentry_multi();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
index cc727011f3a2a..dfa24e229ff75 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -12,6 +12,7 @@
 #include "tracing_multi_verifier.skel.h"
 #include "tracing_multi_bench.skel.h"
 #include "tracing_multi_rollback.skel.h"
+#include "tracing_multi_bpf.skel.h"
 #include "trace_helpers.h"
 
 static __u64 bpf_fentry_test_cookies[] = {
@@ -1126,3 +1127,256 @@ void test_tracing_multi_test(void)
 	if (test__start_subtest("fentry_after_multi"))
 		test_fentry_after_multi();
 }
+
+static int run_bpf_target(struct bpf_program *prog, __u32 retval, const char *name)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, topts);
+	int err;
+
+	err = bpf_prog_test_run_opts(bpf_program__fd(prog), &topts);
+	if (!ASSERT_OK(err, name))
+		return err;
+
+	if (!ASSERT_EQ(topts.retval, retval, name))
+		return -EINVAL;
+
+	return 0;
+}
+
+static void test_link_api_bpf_prog(bool test_cookies)
+{
+	const char *funcs[] = { "target_1", "target_2" };
+	__u64 fentry_cookies[] = { 0xfeed01, 0xfeed02 };
+	__u64 fexit_cookies[] = { 0xfeed11, 0xfeed12 };
+	__u64 fsession_cookies[] = { 0xfeed21, 0xfeed22 };
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	struct tracing_multi_bpf *skel = NULL;
+	int fds[ARRAY_SIZE(funcs)];
+	struct bpf_link *link;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	fds[0] = bpf_program__fd(skel->progs.target_1);
+	fds[1] = bpf_program__fd(skel->progs.target_2);
+
+	skel->bss->test_cookies = test_cookies;
+
+	opts.fds = fds;
+	opts.funcs = funcs;
+	opts.cnt = ARRAY_SIZE(fds);
+
+	opts.cookies = test_cookies ? fentry_cookies : NULL;
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fentry, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "attach_fentry"))
+		goto cleanup;
+	skel->links.test_fentry = link;
+
+	opts.cookies = test_cookies ? fexit_cookies : NULL;
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fexit, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "attach_fexit"))
+		goto cleanup;
+	skel->links.test_fexit = link;
+
+	opts.cookies = test_cookies ? fsession_cookies : NULL;
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fsession, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "attach_fsession"))
+		goto cleanup;
+	skel->links.test_fsession = link;
+
+	skel->bss->fentry_cookie = fentry_cookies[0];
+	skel->bss->fexit_cookie = fexit_cookies[0];
+	skel->bss->fsession_cookie = fsession_cookies[0];
+	if (run_bpf_target(skel->progs.target_1, 1, "target_1"))
+		goto cleanup;
+
+	skel->bss->fentry_cookie = fentry_cookies[1];
+	skel->bss->fexit_cookie = fexit_cookies[1];
+	skel->bss->fsession_cookie = fsession_cookies[1];
+	if (run_bpf_target(skel->progs.target_2, 2, "target_2"))
+		goto cleanup;
+
+	ASSERT_EQ(skel->bss->target_1_result, 1, "target_1_result");
+	ASSERT_EQ(skel->bss->target_2_result, 1, "target_2_result");
+	ASSERT_EQ(skel->bss->test_result_fentry, ARRAY_SIZE(funcs), "test_result_fentry");
+	ASSERT_EQ(skel->bss->test_result_fexit, ARRAY_SIZE(funcs), "test_result_fexit");
+	ASSERT_EQ(skel->bss->test_result_fsession_entry, ARRAY_SIZE(funcs),
+		  "test_result_fsession_entry");
+	ASSERT_EQ(skel->bss->test_result_fsession_exit, ARRAY_SIZE(funcs),
+		  "test_result_fsession_exit");
+
+cleanup:
+	tracing_multi_bpf__destroy(skel);
+}
+
+static void test_attach_api_bpf_prog_fails(void)
+{
+	static const char * const kfuncs[] = {
+		"bpf_fentry_test1",
+	};
+	const char *bpf_funcs[] = { "target_1" };
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	LIBBPF_OPTS(bpf_link_create_opts, lopts);
+	struct tracing_multi_bpf *skel = NULL;
+	int fd, target_id, token_fd;
+	int fds[2], dup_fd = -1;
+	struct bpf_link *link;
+	__u32 target_ids[2];
+	__u32 *ids = NULL;
+	long err;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	ids = get_ids(kfuncs, ARRAY_SIZE(kfuncs), NULL);
+	if (!ASSERT_OK_PTR(ids, "get_ids"))
+		goto cleanup;
+
+	fds[0] = bpf_program__fd(skel->progs.target_1);
+
+	/* fail#1 (libbpf) kernel ids and BPF prog fds */
+	LIBBPF_OPTS_RESET(opts,
+		.ids = ids,
+		.fds = fds,
+		.funcs = bpf_funcs,
+		.cnt = ARRAY_SIZE(bpf_funcs),
+	);
+
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fentry, NULL, &opts);
+	err = libbpf_get_error(link);
+	if (!ASSERT_EQ(err, -EINVAL, "libbpf_ids_fds")) {
+		if (!err)
+			bpf_link__destroy(link);
+		goto cleanup;
+	}
+
+	/* fail#2 (libbpf) kernel pattern and BPF prog fds */
+	LIBBPF_OPTS_RESET(opts,
+		.fds = fds,
+		.funcs = bpf_funcs,
+		.cnt = ARRAY_SIZE(bpf_funcs),
+	);
+
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+						"bpf_fentry_test*", &opts);
+	err = libbpf_get_error(link);
+	if (!ASSERT_EQ(err, -EINVAL, "libbpf_pattern_fds")) {
+		if (!err)
+			bpf_link__destroy(link);
+		goto cleanup;
+	}
+
+	/* fail#3 (kernel) kernel id with BPF prog fd */
+	lopts.tracing_multi.ids = ids;
+	lopts.tracing_multi.fds = fds;
+	lopts.tracing_multi.cnt = ARRAY_SIZE(bpf_funcs);
+	fd = bpf_link_create(bpf_program__fd(skel->progs.test_fentry), 0,
+			     BPF_TRACE_FENTRY_MULTI, &lopts);
+	ASSERT_EQ(fd, -EINVAL, "kernel_id_bpf_fd");
+	if (fd >= 0)
+		close(fd);
+
+	/* fail#4 (kernel) duplicate target through different fds */
+	token_fd = bpf_object__token_fd(skel->obj);
+	token_fd = token_fd < 0 ? 0 : token_fd;
+	target_id = libbpf_find_prog_btf_id("target_1", fds[0], token_fd);
+	if (!ASSERT_GT(target_id, 0, "target_1_btf_id"))
+		goto cleanup;
+
+	dup_fd = dup(fds[0]);
+	if (!ASSERT_GE(dup_fd, 0, "dup_target_fd"))
+		goto cleanup;
+
+	fds[1] = dup_fd;
+	target_ids[0] = target_id;
+	target_ids[1] = target_id;
+	lopts.tracing_multi.ids = target_ids;
+	lopts.tracing_multi.fds = fds;
+	lopts.tracing_multi.cnt = ARRAY_SIZE(fds);
+	fd = bpf_link_create(bpf_program__fd(skel->progs.test_fentry), 0,
+			     BPF_TRACE_FENTRY_MULTI, &lopts);
+	ASSERT_EQ(fd, -EINVAL, "duplicate_bpf_target");
+	if (fd >= 0)
+		close(fd);
+
+cleanup:
+	if (dup_fd >= 0)
+		close(dup_fd);
+	tracing_multi_bpf__destroy(skel);
+	free(ids);
+}
+
+static void test_rollback_bpf_prog(void)
+{
+	int token_fd, prog_fd, fd = -1, pre_fd = -1;
+	LIBBPF_OPTS(bpf_link_create_opts, lopts);
+	struct tracing_multi_bpf *skel = NULL;
+	__u32 target_ids[2], ids[2];
+	int target_fds[2], fds[2];
+	struct bpf_program *prog;
+	int first, second;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	token_fd = bpf_object__token_fd(skel->obj);
+	token_fd = token_fd < 0 ? 0 : token_fd;
+	target_fds[0] = bpf_program__fd(skel->progs.target_1);
+	target_fds[1] = bpf_program__fd(skel->progs.target_2);
+	target_ids[0] = libbpf_find_prog_btf_id("target_1", target_fds[0], token_fd);
+	if (!ASSERT_GT(target_ids[0], 0, "target_1_btf_id"))
+		goto cleanup;
+	target_ids[1] = libbpf_find_prog_btf_id("target_2", target_fds[1], token_fd);
+	if (!ASSERT_GT(target_ids[1], 0, "target_2_btf_id"))
+		goto cleanup;
+
+	first = target_fds[0] < target_fds[1] ? 0 : 1;
+	second = 1 - first;
+	fds[0] = target_fds[first];
+	fds[1] = target_fds[second];
+	ids[0] = target_ids[first];
+	ids[1] = target_ids[second];
+
+	prog_fd = bpf_program__fd(skel->progs.test_fentry);
+	lopts.tracing_multi.ids = &ids[1];
+	lopts.tracing_multi.fds = &fds[1];
+	lopts.tracing_multi.cnt = 1;
+	pre_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &lopts);
+	if (!ASSERT_GE(pre_fd, 0, "pre_attach"))
+		goto cleanup;
+
+	lopts.tracing_multi.ids = ids;
+	lopts.tracing_multi.fds = fds;
+	lopts.tracing_multi.cnt = ARRAY_SIZE(ids);
+
+	fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &lopts);
+	if (!ASSERT_EQ(fd, -EBUSY, "bpf_link_create"))
+		goto cleanup;
+
+	prog = first == 0 ? skel->progs.target_1 : skel->progs.target_2;
+	if (run_bpf_target(prog, first + 1, "rollback_target"))
+		goto cleanup;
+	ASSERT_EQ(skel->bss->test_result_fentry, 0, "test_result_fentry");
+
+cleanup:
+	if (fd >= 0)
+		close(fd);
+	if (pre_fd >= 0)
+		close(pre_fd);
+	tracing_multi_bpf__destroy(skel);
+}
+
+void test_tracing_multi_prog_test(void)
+{
+	if (test__start_subtest("link_api"))
+		test_link_api_bpf_prog(false);
+	if (test__start_subtest("attach_api_fails"))
+		test_attach_api_bpf_prog_fails();
+	if (test__start_subtest("cookies"))
+		test_link_api_bpf_prog(true);
+	if (test__start_subtest("rollback"))
+		test_rollback_bpf_prog();
+}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c b/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c
new file mode 100644
index 0000000000000..0ea4513904cd7
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+SEC("syscall")
+int target(void *ctx)
+{
+	return 0;
+}
+
+SEC("fentry")
+int BPF_PROG(dummy_fentry)
+{
+	return 0;
+}
+
+SEC("fentry.multi")
+int BPF_PROG(dummy_fentry_multi)
+{
+	return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c b/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c
new file mode 100644
index 0000000000000..651b5d86203f3
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+bool test_cookies;
+__u64 fentry_cookie;
+__u64 fexit_cookie;
+__u64 fsession_cookie;
+__u64 test_result_fentry;
+__u64 test_result_fexit;
+__u64 test_result_fsession_entry;
+__u64 test_result_fsession_exit;
+__u64 target_1_result;
+__u64 target_2_result;
+
+SEC("syscall")
+int target_1(void *ctx)
+{
+	target_1_result++;
+	return 1;
+}
+
+SEC("syscall")
+int target_2(void *ctx)
+{
+	target_2_result++;
+	return 2;
+}
+
+SEC("fentry.multi")
+int BPF_PROG(test_fentry)
+{
+	if (!test_cookies || bpf_get_attach_cookie(ctx) == fentry_cookie)
+		test_result_fentry++;
+	return 0;
+}
+
+SEC("fexit.multi")
+int BPF_PROG(test_fexit)
+{
+	if (!test_cookies || bpf_get_attach_cookie(ctx) == fexit_cookie)
+		test_result_fexit++;
+	return 0;
+}
+
+SEC("fsession.multi")
+int BPF_PROG(test_fsession)
+{
+	if (test_cookies && bpf_get_attach_cookie(ctx) != fsession_cookie)
+		return 0;
+
+	if (bpf_session_is_return(ctx))
+		test_result_fsession_exit++;
+	else
+		test_result_fsession_entry++;
+
+	return 0;
+}

3/2 2026/10/12 17:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36833
							output: 36
							thoughts: 1092
						

Thoughts:
**Evaluation of the Provided Patch for Fuzzing with Syzkaller**

Alright, let's break this down. My initial assessment is that this patch *absolutely* warrants fuzzing. The changes are substantial and touch upon several critical BPF subsystems.

First, I examine the code changes. The patch modifies: `arch/x86/net/bpf_jit_comp.c`, which introduces `bpf_arch_text_poke_batch`; `include/linux/bpf.h`, with new structures and functions like `bpf_trampoline_multi_prog_attach` and `bpf_arch_text_poke_batch`; `include/uapi/linux/bpf.h`, with additions to `bpf_attr` and `bpf_link_info`; `kernel/bpf/core.c` with a weak `bpf_arch_text_poke_batch`; `kernel/bpf/trampoline.c` with multiple new functionalities; `kernel/bpf/verifier.c` updating `bpf_check_attach_target`, and `kernel/trace/bpf_trace.c` with changes to multi-link functions.

The target architecture is amd64. These modifications impact the core BPF components: the JIT compiler, BPF trampoline, BPF verifier, and `bpf_trace`. This code is directly reachable via the `bpf()` syscall, specifically with `BPF_LINK_CREATE` and the various `BPF_TRACE_*_MULTI` link types, which can use the FDs of other BPF programs as targets. This is standard software emulation-accessible.

I see several red flags: complex text poking with `bpf_text_poke_batch` and `bpf_arch_text_poke_batch` potentially, `bpf_trampoline_multi_prog_attach` and `bpf_trampoline_multi_prog_detach`, verifier changes, locking mechanisms, memory allocations, and error handling. The potential for subtle bugs is high in these areas.

Considering the following additions/modifications:
-   `bpf_text_poke_batch`
-   `bpf_trampoline_multi_prog_attach`
-   `bpf_trampoline_multi_prog_detach`
-   `bpf_arch_text_poke_batch`
-   `bpf_check_attach_target`
-   `bpf_tracing_multi_attach`

All of these indicate high potential for bugs, and thus fuzzing should be a priority.

Now, checking the rules, the patch clearly falls under the "Core Subsystems" category. Any modification in BPF, which it clearly is, necessitates a `WorthFuzzing` value of `true`.

We need to confirm the required configurations now. I'll need to check the Kconfig files and potentially use tools like `grepper` or check the `arch/x86/net/Makefile` to determine the exact compilation configurations.



4/2 2026/10/12 17:58 tool grepper
0m Args:
{
  "Expression": "bpf_jit_comp",
  "PathPrefixes": [
    "arch/x86/net/Makefile"
  ]
}

Results:
{
  "Output": "arch/x86/net/Makefile=6=ifeq ($(CONFIG_X86_32),y)\narch/x86/net/Makefile:7:        obj-$(CONFIG_BPF_JIT) += bpf_jit_comp32.o\narch/x86/net/Makefile-8-else\narch/x86/net/Makefile:9:        obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o\narch/x86/net/Makefile-10-endif\n"
}

5/2 2026/10/12 17:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38758
							output: 31
							thoughts: 39
						

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

**Investigating BPF JIT Configuration and Implementation**

Right, `CONFIG_BPF_JIT`. That flag always sets the stage. Now, to truly understand the implications and the current state of play, I need to dive into the core implementation. Let's see... the `kernel/bpf/trampoline.c` file is a prime candidate, as is `kernel/trace/bpf_trace.c`. I'll be looking for how the JIT is initialized, how it handles instruction translation, and any specific optimizations or tracing integration that relies on it. I need to understand the connection between these files and how they influence the behavior of BPF programs. I'm keen to find the nuances of how the JIT is used here. Time to get into the details of the code!



6/2 2026/10/12 17:58 tool grepper
0m Args:
{
  "Expression": "trampoline\\.o",
  "PathPrefixes": [
    "kernel/bpf/Makefile"
  ]
}

Results:
{
  "Output": "kernel/bpf/Makefile=16=obj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o\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\n"
}

7/2 2026/10/12 17:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39127
							output: 30
							thoughts: 20
						

Thoughts:
Here's a summary of my thought process, keeping in mind my expertise:

**Diving into the BPF Tracing Infrastructure**

Okay, so we need to understand how this tracing system works. My initial instinct, given that we're talking about BPF and tracing, is to zero in on the core implementation. Let's start with `bpf_trace.c`. That should be the main file, or at least a critical component, in the BPF tracing subsystem within the kernel. And since it's a kernel module, the best place to find how it's built and linked is likely the `Makefile`. Therefore, I'll start by checking its location in `kernel/trace/Makefile`, which should tell me how it's compiled, any dependencies it has, and perhaps even some relevant flags or options used in the build process. From the Makefile, I can easily navigate its dependencies and trace the build process. This will be my entry point to understanding the architecture.



8/2 2026/10/12 17:58 tool grepper
0m Args:
{
  "Expression": "bpf_trace",
  "PathPrefixes": [
    "kernel/trace/Makefile"
  ]
}

Results:
{
  "Output": "kernel/trace/Makefile=54=KCOV_INSTRUMENT_trace_irqsoff.o := n\nkernel/trace/Makefile-55-\nkernel/trace/Makefile:56:CFLAGS_bpf_trace.o := -I$(src)\nkernel/trace/Makefile-57-\n--\nkernel/trace/Makefile=109=obj-$(CONFIG_USER_EVENTS) += trace_events_user.o\nkernel/trace/Makefile:110:obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o\nkernel/trace/Makefile-111-obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o\n"
}

9/2 2026/10/12 17:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39552
							output: 32
							thoughts: 21
						

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

**Checking `CONFIG_BPF_EVENTS` in `kernel/trace/Kconfig`**

Alright, let's dive in. I need to quickly ascertain the configuration option for BPF events, specifically where it's defined and managed within the kernel's configuration hierarchy. My initial instinct is to look within the trace subsystem's Kconfig file, as that's the most logical place given the context. So, I'll go directly to `kernel/trace/Kconfig`. I'm expecting to find a clear definition there, or at the very least, an inclusion that points me towards the correct location. This will allow me to understand whether it's enabled by default, under what conditions it can be enabled, and what dependencies it might have. This is a crucial step in understanding the BPF event infrastructure's availability and configurability.



10/2 2026/10/12 17:58 tool grepper
0m Args:
{
  "Expression": "config BPF_EVENTS",
  "PathPrefixes": [
    "kernel/trace/Kconfig"
  ]
}

Results:
{
  "Output": "kernel/trace/Kconfig=851=config EPROBE_EVENTS\n--\nkernel/trace/Kconfig-864-\nkernel/trace/Kconfig:865:config BPF_EVENTS\nkernel/trace/Kconfig-866-\tdepends on BPF_SYSCALL\n"
}

11/2 2026/10/12 17:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39876
							output: 34
							thoughts: 28
						

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

**Diving into the BPF_EVENTS Configuration**

Okay, let's get down to brass tacks. I need to fully understand the definition of `BPF_EVENTS`, so I'm going to navigate directly to the source. Specifically, I'll be looking at `kernel/trace/Kconfig` and zeroing in around line 865. That's where I expect to find the definitive configuration details that I need to clarify. This is the best way to ensure I'm getting the complete picture for my work.



12/2 2026/10/12 17:58 tool read-file
0m Args:
{
  "File": "kernel/trace/Kconfig",
  "FirstLine": 860,
  "LineCount": 20
}

Results:
{
  "Contents": " 860:\t\t  events. It can be used to limit what fields are recorded in\n 861:\t\t  an event or even dereference a field of an event. It can\n 862:\t\t  convert the type of an event field. For example, turn an\n 863:\t\t  address into a string.\n 864:\t\n 865:\tconfig BPF_EVENTS\n 866:\t\tdepends on BPF_SYSCALL\n 867:\t\tdepends on (KPROBE_EVENTS || UPROBE_EVENTS) \u0026\u0026 PERF_EVENTS\n 868:\t\tbool\n 869:\t\tdefault y\n 870:\t\thelp\n 871:\t\t  This allows the user to attach BPF programs to kprobe, uprobe, and\n 872:\t\t  tracepoint events.\n 873:\t\n 874:\tconfig DYNAMIC_EVENTS\n 875:\t\tdef_bool n\n 876:\t\n 877:\tconfig PROBE_EVENTS\n 878:\t\tdef_bool n\n 879:\t\n"
}

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

Args:
null

Results:
null

Tokens:
							input: 40343
							output: 22
							thoughts: 77
						

Thoughts:
Here's my thought process, as it stands:

**Navigating the BPF Configuration Landscape**

Okay, so I need to figure out how these BPF options are set up. Let's start by digging into the configuration files. My gut says to check `init/Kconfig` and `kernel/bpf/Kconfig` for the `BPF_SYSCALL` option. That's likely where the fundamental BPF system call enablement is defined.

Then, I'm also thinking about `CONFIG_BPF_JIT`. I need to understand how the Just-In-Time compiler is handled. Where exactly is `BPF_JIT` defined? Are there any related configurations like `BPF_JIT_ALWAYS_ON` that might affect its behavior? I need to track down the dependency chain and any potential defaults or conditional settings for the JIT. That's where I should focus next.



14/2 2026/10/12 17:58 tool grepper
0m Args:
{
  "Expression": "config BPF_JIT\\b"
}

Results:
{
  "Output": "kernel/bpf/Kconfig=31=config BPF_SYSCALL\n--\nkernel/bpf/Kconfig-45-\nkernel/bpf/Kconfig:46:config BPF_JIT\nkernel/bpf/Kconfig-47-\tbool \"Enable BPF Just In Time compiler\"\n"
}

15/2 2026/10/12 17:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40724
							output: 34
							thoughts: 23
						

Thoughts:
Here's a summary of my thought process, tailored for an expert like yourself:

**Diving into the BPF Kernel Configuration**

Okay, time to get my hands dirty. I need to take a look at the BPF configuration within the kernel. I immediately think to check the `kernel/bpf/Kconfig` file. Given my familiarity with the kernel build system and BPF's structure, lines 30 to 70 seem like a likely spot to find the core definitions and dependencies I'm interested in. I'll zero in on that region to quickly grasp the relevant options and their conditions. This will likely give me a good overview of what's configurable regarding BPF at compile time.



16/2 2026/10/12 17:58 tool read-file
0m Args:
{
  "File": "kernel/bpf/Kconfig",
  "FirstLine": 30,
  "LineCount": 45
}

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  70:\t\t  is permanently set to 1 and setting any other value than that will\n  71:\t\t  return failure.\n  72:\t\n  73:\tconfig BPF_JIT_DEFAULT_ON\n  74:\t\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n"
}

17/2 2026/10/12 17:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41624
							output: 22
							thoughts: 29
						

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

**Diving into `bpf_tracing_multi_attach` Callers**

Alright, let's get down to brass tacks. I need to understand how `bpf_tracing_multi_attach` is being used within the kernel tracing system. My primary focus is on how this function is being called, particularly from within `kernel/trace/bpf_trace.c`. I need to review all the callers of this function to grasp the context of its usage and potential interactions. Specifically I'm interested in understanding the flow of execution and how the calls relate to the overall tracing architecture. This should reveal the control flow and highlight any potential areas of concern or opportunity.



18/2 2026/10/12 17:58 tool grepper
0m Args:
{
  "Expression": "bpf_tracing_multi_attach"
}

Results:
{
  "Output": "include/linux/trace_events.h=798=int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);\ninclude/linux/trace_events.h:799:int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr);\ninclude/linux/trace_events.h-800-#else\n--\ninclude/linux/trace_events.h=857=static inline int\ninclude/linux/trace_events.h:858:bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\ninclude/linux/trace_events.h-859-{\n--\nkernel/bpf/syscall.c=5838=static int link_create(union bpf_attr *attr, bpfptr_t uattr)\n--\nkernel/bpf/syscall.c-5888-\t\telse if (is_tracing_multi(prog-\u003eexpected_attach_type))\nkernel/bpf/syscall.c:5889:\t\t\tret = bpf_tracing_multi_attach(prog, attr);\nkernel/bpf/syscall.c-5890-\t\telse\n--\nkernel/trace/bpf_trace.c=3909=static int bpf_get_progs(struct bpf_prog **progs, int *fds, int cnt)\n--\nkernel/trace/bpf_trace.c-3935-\nkernel/trace/bpf_trace.c:3936:int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\nkernel/trace/bpf_trace.c-3937-{\n"
}

19/2 2026/10/12 17:59 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42268
							output: 37
							thoughts: 37
						

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

**Investigating `bpf_tracing_multi_attach` in `trace_events.h`**

Okay, so I need to understand the conditional compilation of `bpf_tracing_multi_attach`. I'll jump right into `include/linux/trace_events.h`. My immediate focus is around line 798. That's usually where these types of functions are defined or declared, especially for tracing-related features. I'm expecting to see a series of `#ifdef` statements, potentially nested, that determine whether the function's declaration or definition is included based on kernel configuration options or feature flags. I need to figure out what those conditions are, to understand when this multi-attach functionality is available and how it's controlled. This should give me insight into the dependencies, and any prerequisites required for using this feature within a broader BPF tracing context.



20/2 2026/10/12 17:59 tool read-file
0m Args:
{
  "File": "include/linux/trace_events.h",
  "FirstLine": 790,
  "LineCount": 25
}

Results:
{
  "Contents": " 790:\t\n 791:\tstruct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name);\n 792:\tvoid bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp);\n 793:\tint bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,\n 794:\t\t\t\t    u32 *fd_type, const char **buf,\n 795:\t\t\t\t    u64 *probe_offset, u64 *probe_addr,\n 796:\t\t\t\t    unsigned long *missed);\n 797:\tint bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);\n 798:\tint bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);\n 799:\tint bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr);\n 800:\t#else\n 801:\tstatic inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)\n 802:\t{\n 803:\t\treturn 1;\n 804:\t}\n 805:\t\n 806:\tstatic inline unsigned int trace_call_bpf_faultable(struct trace_event_call *call, void *ctx)\n 807:\t{\n 808:\t\treturn 1;\n 809:\t}\n 810:\t\n 811:\tstatic inline int\n 812:\tperf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie)\n 813:\t{\n 814:\t\treturn -EOPNOTSUPP;\n"
}

21/2 2026/10/12 17:59 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43041
							output: 37
							thoughts: 27
						

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

**Diving into `trace_events.h`**

Okay, time to get my hands dirty. I'm going to jump into the `include/linux/trace_events.h` header. I need to zero in on lines 780 through 790. This usually indicates a specific section where event definitions or possibly some crucial helper functions for tracing are defined. I expect there might be declarations related to tracepoint arguments, maybe some macros for event formatting, or potentially some of the core structures used by the tracing framework. I'm hoping to get a quick overview of what's handled in this section.



22/2 2026/10/12 17:59 tool read-file
0m Args:
{
  "File": "include/linux/trace_events.h",
  "FirstLine": 775,
  "LineCount": 20
}

Results:
{
  "Contents": " 775:\t\t\treturn false;\n 776:\t\n 777:\t\treturn __trace_trigger_soft_disabled(file);\n 778:\t}\n 779:\t\n 780:\t#ifdef CONFIG_BPF_EVENTS\n 781:\tunsigned int trace_call_bpf(struct trace_event_call *call, void *ctx);\n 782:\tunsigned int trace_call_bpf_faultable(struct trace_event_call *call, void *ctx);\n 783:\tint perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie);\n 784:\tvoid perf_event_detach_bpf_prog(struct perf_event *event);\n 785:\tint perf_event_query_prog_array(struct perf_event *event, void __user *info);\n 786:\t\n 787:\tstruct bpf_raw_tp_link;\n 788:\tint bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_raw_tp_link *link);\n 789:\tint bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_raw_tp_link *link);\n 790:\t\n 791:\tstruct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name);\n 792:\tvoid bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp);\n 793:\tint bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,\n 794:\t\t\t\t    u32 *fd_type, const char **buf,\n"
}

23/2 2026/10/12 17:59 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43723
							output: 40
							thoughts: 1235
						

Thoughts:
**Analyzing BPF Multi-Attach Requirements**

Okay, so I'm digging into this multi-attach BPF stuff. Line 780 confirms that `CONFIG_BPF_EVENTS` is in play. I see that `bpf_trace.c` has this check: `if (!ufds && !IS_ENABLED(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS)) return -EOPNOTSUPP;`. That's interesting; it seems like the `ufds` part is key here, and if it's set, this check is bypassed. Makes sense given the new functionality being added.

Now, `BPF_EVENTS` itself is dependent on `BPF_SYSCALL` and also requires either `KPROBE_EVENTS` or `UPROBE_EVENTS`, and `PERF_EVENTS`, which is straightforward. Let's look at what is in `bpf_trampoline.c`. I see a bunch of `bpf_text_poke` functions and `bpf_trampoline_multi_prog_attach/detach`, all protected by `#ifdef CONFIG_BPF_SYSCALL`.

And then, looking at the `Makefile`s, I see that `trampoline.o` is only compiled if `CONFIG_BPF_JIT` is enabled. That's a good clue. Similarly, `bpf_jit_comp.o` in `arch/x86/net` is also gated by `CONFIG_BPF_JIT`, and it implements `bpf_arch_text_poke_batch`. In `kernel/bpf/core.c`, the default `bpf_arch_text_poke_batch` returns `-EOPNOTSUPP`. On x86, it's provided in `bpf_jit_comp.c` if `CONFIG_BPF_JIT` is enabled, which is the expected JIT behavior. And of course, `BPF_JIT` depends on `BPF`.

So `CONFIG_BPF_SYSCALL` is a given, because we need the `bpf()` syscall. `CONFIG_BPF_EVENTS` enables `bpf_tracing_multi_attach` in `bpf_trace.c`. The Kconfig confirms that `BPF_EVENTS` requires `BPF_SYSCALL`, and either `KPROBE_EVENTS` or `UPROBE_EVENTS`, and also `PERF_EVENTS`.

Now, that `bpf_trace.c` check again... if `ufds` is set, `CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS` is NOT required! The code calls either `bpf_trampoline_multi_prog_attach` or `bpf_trampoline_multi_attach` based on whether `progs` is set or not. And, as we saw before, `bpf_trampoline_multi_prog_attach` is defined under `#ifdef CONFIG_BPF_SYSCALL`. In `include/linux/bpf.h`, it shows that both the attach and detach functions are conditionally defined by `CONFIG_BPF_JIT` and `CONFIG_BPF_SYSCALL`. So they need both to be present. I should verify line 1610-1750 in that file to be sure. That's the key thing: the new `ufds` path bypasses the single FTRACE requirement because of the trampoline logic being used, and it all works because of `CONFIG_BPF_SYSCALL` and `CONFIG_BPF_JIT`.



24/2 2026/10/12 17:59 tool grepper
0m Args:
{
  "Expression": "bpf_trampoline_multi_prog_attach",
  "PathPrefixes": [
    "include/linux/bpf.h"
  ]
}

Results:
{
  "Output": "include/linux/bpf.h=1618=void bpf_trampoline_multi_detach(struct bpf_prog *prog,\ninclude/linux/bpf.h-1619-\t\t\t\t struct bpf_tracing_multi_link *link);\ninclude/linux/bpf.h:1620:int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,\ninclude/linux/bpf.h-1621-\t\t\t\t     struct bpf_tracing_multi_link *link);\n--\ninclude/linux/bpf.h=1742=static inline void bpf_trampoline_multi_detach(struct bpf_prog *prog,\n--\ninclude/linux/bpf.h-1746-\ninclude/linux/bpf.h:1747:static inline int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,\ninclude/linux/bpf.h-1748-\t\t\t\t\t\t   struct bpf_tracing_multi_link *link)\n"
}

25/2 2026/10/12 17:59 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46058
							output: 37
							thoughts: 32
						

Thoughts:
Okay, here's my summary, considering my expertise:

**Checking BPF Header Preprocessor Directives**

Alright, let's dive into this. My initial thought is to zero in on the `#if` directives surrounding lines 1620 and 1747 in `include/linux/bpf.h`. I'm guessing this might be related to conditional compilation or feature gating within the BPF (Berkeley Packet Filter) subsystem. Given the line numbers, and my experience, this likely pertains to specific BPF instructions, helpers, or data structures that are conditionally enabled based on the kernel configuration or a specific BPF feature flag. I'll need to determine the conditions being checked. Are these related to kernel version support? Architecture-specific features? Perhaps some optional BPF security features that can be compiled out? Understanding these `#if` conditions is *crucial* for ensuring code portability and compatibility across different kernel builds and configurations. This is something I regularly deal with. The specifics will guide how I analyze any further code depending on that block, and possibly how to handle differences in BPF instruction sets if needed.



26/2 2026/10/12 17:59 tool read-file
0m Args:
{
  "File": "include/linux/bpf.h",
  "FirstLine": 1605,
  "LineCount": 20
}

Results:
{
  "Contents": "1605:\tint bpf_trampoline_link_prog(struct bpf_tramp_node *node,\n1606:\t\t\t\t     struct bpf_trampoline *tr,\n1607:\t\t\t\t     struct bpf_prog *tgt_prog);\n1608:\tint bpf_trampoline_unlink_prog(struct bpf_tramp_node *node,\n1609:\t\t\t\t       struct bpf_trampoline *tr,\n1610:\t\t\t\t       struct bpf_prog *tgt_prog);\n1611:\tstruct bpf_trampoline *bpf_trampoline_get(u64 key,\n1612:\t\t\t\t\t\t  struct bpf_attach_target_info *tgt_info);\n1613:\tvoid bpf_trampoline_put(struct bpf_trampoline *tr);\n1614:\tint arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int num_funcs);\n1615:\t\n1616:\tint bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,\n1617:\t\t\t\t\tstruct bpf_tracing_multi_link *link);\n1618:\tvoid bpf_trampoline_multi_detach(struct bpf_prog *prog,\n1619:\t\t\t\t\t struct bpf_tracing_multi_link *link);\n1620:\tint bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,\n1621:\t\t\t\t\t     struct bpf_tracing_multi_link *link);\n1622:\tvoid bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link);\n1623:\tvoid bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags);\n1624:\t\n"
}

27/2 2026/10/12 17:59 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46846
							output: 37
							thoughts: 26
						

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

**BPF Header Inspection**

Alright, I need to get a clear picture of how this works. I'm going to jump into the `include/linux/bpf.h` file, specifically examining lines 1590 through 1605. That's a specific area, so something interesting must be happening there. Let's see what core definitions or structures are laid out within that range. Are these related to helper functions? Error codes? Data structures? The line range suggests something significant is there, something that bears close scrutiny. I need to understand this snippet's implications within the larger BPF framework. Is this related to tracing, network filtering, or something else entirely? Time to dig in and clarify this!



28/2 2026/10/12 17:59 tool read-file
0m Args:
{
  "File": "include/linux/bpf.h",
  "FirstLine": 1585,
  "LineCount": 25
}

Results:
{
  "Contents": "1585:\tvoid *__bpf_dynptr_data_rw(const struct bpf_dynptr_kern *ptr, u64 len);\n1586:\tbool __bpf_dynptr_is_rdonly(const struct bpf_dynptr_kern *ptr);\n1587:\tint __bpf_dynptr_write(const struct bpf_dynptr_kern *dst, u64 offset,\n1588:\t\t\t       void *src, u64 len, u64 flags);\n1589:\tvoid *bpf_dynptr_slice_rdwr(const struct bpf_dynptr *p, u64 offset,\n1590:\t\t\t\t    void *buffer__nullable, u64 buffer__szk);\n1591:\t\n1592:\tstatic inline int bpf_dynptr_check_off_len(const struct bpf_dynptr_kern *ptr, u64 offset, u64 len)\n1593:\t{\n1594:\t\tu64 size = __bpf_dynptr_size(ptr);\n1595:\t\n1596:\t\tif (len \u003e size || offset \u003e size - len)\n1597:\t\t\treturn -E2BIG;\n1598:\t\n1599:\t\treturn 0;\n1600:\t}\n1601:\t\n1602:\tstruct bpf_tracing_multi_link;\n1603:\t\n1604:\t#ifdef CONFIG_BPF_JIT\n1605:\tint bpf_trampoline_link_prog(struct bpf_tramp_node *node,\n1606:\t\t\t\t     struct bpf_trampoline *tr,\n1607:\t\t\t\t     struct bpf_prog *tgt_prog);\n1608:\tint bpf_trampoline_unlink_prog(struct bpf_tramp_node *node,\n1609:\t\t\t\t       struct bpf_trampoline *tr,\n"
}

29/2 2026/10/12 17:59 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47581
							output: 247
							thoughts: 1921
						

Thoughts:
**Analysis of BPF Multi-Attach and Related Code for Fuzzing**

Alright, let's break this down. My initial observation is that `#ifdef CONFIG_BPF_JIT` guards `bpf_trampoline_multi_prog_attach`, which makes the compilation of related code conditional. Looking deeper, `trampoline.o` is only compiled when `CONFIG_BPF_JIT` is on, and within `trampoline.c`, we have further conditional compilation based on `CONFIG_BPF_SYSCALL`.  I see `bpf_arch_text_poke_batch` is in `arch/x86/net/bpf_jit_comp.c`, and it also hinges on `CONFIG_BPF_JIT`.  `bpf_trace.c` compiles when `CONFIG_BPF_EVENTS` is enabled, which in turn depends on `CONFIG_BPF_SYSCALL` and the presence of either `CONFIG_KPROBE_EVENTS` or `CONFIG_UPROBE_EVENTS`, along with `CONFIG_PERF_EVENTS`.

Now, the important part: what functions are being added or modified?  In `arch/x86/net/bpf_jit_comp.c`, we see additions like `bpf_arch_text_poke_batch`, and helpers `bpf_arch_text_poke_check_ip` and `bpf_arch_text_poke_prepare_insns`, alongside modifications to `bpf_arch_text_poke` and `__bpf_arch_text_poke`. `kernel/bpf/trampoline.c` brings in `bpf_trampoline_multi_prog_attach`, `bpf_trampoline_multi_prog_detach`, `bpf_trampoline_multi_prog_prepare`, `bpf_trampoline_multi_prog_commit`, `bpf_trampoline_multi_prog_rollback`, and `bpf_text_poke_batch`, with a modified `bpf_trampoline_multi_attach_init`.  `kernel/trace/bpf_trace.c` shows changes to `bpf_tracing_multi_attach`, `bpf_tracing_multi_link_release`, `bpf_tracing_multi_link_fill_link_info`, as well as a new `check_dup_keys` (renamed from `check_dup_ids`) and the helper `bpf_get_progs`. Finally, `kernel/bpf/verifier.c` has a modified `bpf_check_attach_target`.

Next, I need to check symbol visibility.  `bpf_arch_text_poke_batch`, `bpf_trampoline_multi_prog_attach`, `bpf_trampoline_multi_prog_detach`, `bpf_tracing_multi_attach`, and `bpf_check_attach_target` are all *non-static*, which is critical for fuzzing because we need to be able to reach them. `bpf_text_poke_batch` *is* static within `trampoline.c`, however. I see that `bpf_trampoline_multi_prog_attach`, `bpf_trampoline_multi_prog_detach`, `bpf_arch_text_poke_batch` and `bpf_tracing_multi_attach` are very specific to tracing multi attach on BPF programs.  `bpf_check_attach_target` is relevant to other attach points like fentry/fexit and tracing. The `bpf_arch_text_poke` and its batch variant, `bpf_arch_text_poke_batch`, are important for the JIT code patching.

Regarding dependencies, the key `CONFIG_` flags are: `BPF_SYSCALL` (enables the `bpf()` syscall and multi-attach logic), `BPF_JIT` (needed for `trampoline.c` and `bpf_jit_comp.c`), and `BPF_EVENTS` (which compiles `bpf_trace.c` that implements `bpf_tracing_multi_attach`).  `PERF_EVENTS` is needed for `BPF_EVENTS`, as are either `KPROBE_EVENTS` or `UPROBE_EVENTS`.  For x86_64, `HAVE_EBPF_JIT` is automatically selected and will also depend on the target `X86_64`.

The relevant `kconfig` snippet confirms that `BPF_EVENTS` depends on `BPF_SYSCALL` and  either `KPROBE_EVENTS` or `UPROBE_EVENTS` in combination with `PERF_EVENTS`.  So


30/2 2026/10/12 17:59 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "BPF_EVENTS"
  ],
  "FocusSymbols": [
    "bpf_tracing_multi_attach",
    "bpf_trampoline_multi_prog_attach",
    "bpf_trampoline_multi_prog_detach",
    "bpf_arch_text_poke_batch",
    "bpf_arch_text_poke"
  ],
  "Reasoning": "The patch introduces multi-target tracing support for BPF programs, enabling fentry/fexit/fsession.multi links to attach to multiple target BPF programs simultaneously via the bpf() syscall. It adds batch text poking on x86 (bpf_arch_text_poke_batch), multi-program trampoline attachment and detach handling (bpf_trampoline_multi_prog_attach, bpf_trampoline_multi_prog_detach), and associated verifier and link lifecycle management. These changes reside in core reachable BPF subsystems and warrant fuzzing to uncover potential issues in state rollback, concurrency, or instruction patching.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "BPF_EVENTS"
  ],
  "FocusSymbols": [
    "bpf_tracing_multi_attach",
    "bpf_trampoline_multi_prog_attach",
    "bpf_trampoline_multi_prog_detach",
    "bpf_arch_text_poke_batch",
    "bpf_arch_text_poke"
  ],
  "Reasoning": "The patch introduces multi-target tracing support for BPF programs, enabling fentry/fexit/fsession.multi links to attach to multiple target BPF programs simultaneously via the bpf() syscall. It adds batch text poking on x86 (bpf_arch_text_poke_batch), multi-program trampoline attachment and detach handling (bpf_trampoline_multi_prog_attach, bpf_trampoline_multi_prog_detach), and associated verifier and link lifecycle management. These changes reside in core reachable BPF subsystems and warrant fuzzing to uncover potential issues in state rollback, concurrency, or instruction patching.",
  "WorthFuzzing": true
}

31/1 2026/10/12 17:59 action If
4m Args:
{
  "WorthFuzzing": true
}

Results:
null

32/2 2026/10/12 17:59 agent kmsan-evaluator
4m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch adds support for attaching tracing multi-links (fentry/fexit/fsession multi) to BPF programs using batch text poking and trampoline management.\n\nAnalysis of memory initialization and user-space exposure:\n1. User-space copies: In `bpf_link_get_info_by_fd`, the entire `struct bpf_link_info` is initialized with `memset(\u0026info, 0, sizeof(info))` before calling `link-\u003eops-\u003efill_link_info`. The newly added `flags` field in `info-\u003etracing_multi` is explicitly set, and array data exported to user pointers via `put_user` (including target BTF function IDs) uses initialized scalar values. No uninitialized struct padding or fields are leaked to userspace.\n2. Kernel structures and allocations: `struct bpf_tracing_multi_link` (including its flexible array member `nodes`) is allocated with `kvzalloc_flex()`, ensuring all fields are zero-initialized. Temporary arrays (`keys`, `progs`, `pokes`, `fds`, `cookies`, `ids`) are either fully populated (via `copy_from_user()`, `bpf_get_progs()`, or loops) before being read or sorted, or properly cleaned up on error.\n3. Text poke buffers: In `bpf_arch_text_poke_batch()` and `bpf_arch_text_poke_prepare_insns()`, instruction buffers `old_insn` and `new_insn` are initialized (with `x86_nops[5]`) before any `memcmp` or poking occurs.\n\nAny potential bugs introduced by this patch (such as reference counting leaks, use-after-free on rollback, out-of-bounds indexing, or locking issues with `text_mutex` / `trampoline_locks`) are covered by standard KASAN and LOCKDEP configurations. There are no uninitialized memory risks that would require a dedicated KMSAN fuzzing session.",
  "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 4f26995037887ee50c4e3d8ebbbe6dfdb4387288
Author: syz-cluster <triage@syzkaller.com>
Date:   Mon Oct 12 17:58:07 2026 +0000

    syz-cluster: applied patch under review

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 083fcd6cf15b7..b2040ae09273e 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -646,13 +646,12 @@ static int emit_jump(u8 **pprog, void *func, void *ip)
 	return emit_patch(pprog, func, ip, 0xE9);
 }
 
-static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
-				enum bpf_text_poke_type new_t,
-				void *old_addr, void *new_addr)
+static int bpf_arch_text_poke_prepare_insns(void *ip, enum bpf_text_poke_type old_t,
+					    enum bpf_text_poke_type new_t,
+					    void *old_addr, void *new_addr,
+					    u8 *old_insn, u8 *new_insn)
 {
 	const u8 *nop_insn = x86_nops[5];
-	u8 old_insn[X86_PATCH_SIZE];
-	u8 new_insn[X86_PATCH_SIZE];
 	u8 *prog;
 	int ret;
 
@@ -676,24 +675,37 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 			return ret;
 	}
 
-	ret = -EBUSY;
-	mutex_lock(&text_mutex);
+	return 0;
+}
+
+static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
+				enum bpf_text_poke_type new_t,
+				void *old_addr, void *new_addr)
+{
+	u8 old_insn[X86_PATCH_SIZE];
+	u8 new_insn[X86_PATCH_SIZE];
+	int ret;
+
+	ret = bpf_arch_text_poke_prepare_insns(ip, old_t, new_t, old_addr, new_addr, old_insn,
+					       new_insn);
+	if (ret)
+		return ret;
+
+	guard(mutex)(&text_mutex);
+
 	if (memcmp(ip, old_insn, X86_PATCH_SIZE))
-		goto out;
-	ret = 1;
+		return -EBUSY;
 	if (memcmp(ip, new_insn, X86_PATCH_SIZE)) {
 		smp_text_poke_single(ip, new_insn, X86_PATCH_SIZE, NULL);
-		ret = 0;
+		return 0;
 	}
-out:
-	mutex_unlock(&text_mutex);
-	return ret;
+	return 1;
 }
 
-int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
-		       enum bpf_text_poke_type new_t, void *old_addr,
-		       void *new_addr)
+static int bpf_arch_text_poke_check_ip(void **ipp)
 {
+	void *ip = *ipp;
+
 	if (!is_kernel_text((long)ip) &&
 	    !is_bpf_text_address((long)ip))
 		/* BPF poking in modules is not supported */
@@ -704,11 +716,65 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 	 * with an ENDBR instruction.
 	 */
 	if (is_endbr(ip))
-		ip += ENDBR_INSN_SIZE;
+		*ipp += ENDBR_INSN_SIZE;
+
+	return 0;
+}
+
+int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
+		       enum bpf_text_poke_type new_t, void *old_addr,
+		       void *new_addr)
+{
+	int ret;
+
+	ret = bpf_arch_text_poke_check_ip(&ip);
+	if (ret)
+		return ret;
 
 	return __bpf_arch_text_poke(ip, old_t, new_t, old_addr, new_addr);
 }
 
+int bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)
+{
+	u8 old_insn[X86_PATCH_SIZE];
+	u8 new_insn[X86_PATCH_SIZE];
+	int err;
+	u32 i;
+
+	for (i = 0; i < cnt; i++) {
+		err = bpf_arch_text_poke_check_ip(&pokes[i]->ip);
+		if (err)
+			return err;
+	}
+
+	guard(mutex)(&text_mutex);
+
+	for (i = 0; i < cnt; i++) {
+		struct bpf_text_poke *poke = pokes[i];
+
+		err = bpf_arch_text_poke_prepare_insns(poke->ip, poke->old_t, poke->new_t,
+						       poke->old_addr, poke->new_addr, old_insn,
+						       new_insn);
+		if (err)
+			return err;
+		if (memcmp(poke->ip, old_insn, X86_PATCH_SIZE))
+			return -EBUSY;
+	}
+
+	for (i = 0; i < cnt; i++) {
+		struct bpf_text_poke *poke = pokes[i];
+
+		bpf_arch_text_poke_prepare_insns(poke->ip, poke->old_t, poke->new_t,
+						 poke->old_addr, poke->new_addr, old_insn,
+						 new_insn);
+		if (memcmp(poke->ip, new_insn, X86_PATCH_SIZE))
+			smp_text_poke_batch_add(poke->ip, new_insn, X86_PATCH_SIZE, NULL);
+	}
+
+	smp_text_poke_batch_finish();
+	return 0;
+}
+
 #define EMIT_LFENCE()	EMIT3(0x0F, 0xAE, 0xE8)
 
 static void __emit_indirect_jump(u8 **pprog, int reg, bool ereg)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 54144372281cb..a37f926023fdf 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1496,9 +1496,10 @@ struct bpf_trampoline {
 	struct bpf_tramp_image *cur_image;
 	/* Images not freed yet, cur_image and older ones still in use */
 	struct list_head images;
-	/* Used as temporary old image storage for multi_attach */
+	/* Used as temporary images storage for multi_attach */
 	struct {
 		struct bpf_tramp_image *old_image;
+		struct bpf_tramp_image *new_image;
 		u32 old_flags;
 	} multi_attach;
 };
@@ -1616,6 +1617,9 @@ int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
 				struct bpf_tracing_multi_link *link);
 void bpf_trampoline_multi_detach(struct bpf_prog *prog,
 				 struct bpf_tracing_multi_link *link);
+int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,
+				     struct bpf_tracing_multi_link *link);
+void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link);
 void bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags);
 
 /*
@@ -1739,6 +1743,14 @@ static inline void bpf_trampoline_multi_detach(struct bpf_prog *prog,
 					       struct bpf_tracing_multi_link *link)
 {
 }
+
+static inline int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,
+						   struct bpf_tracing_multi_link *link)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link) {}
 static inline void bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags) {}
 #endif
 
@@ -2089,10 +2101,25 @@ struct bpf_tracing_link {
 	struct bpf_prog *tgt_prog;
 };
 
+enum bpf_text_poke_type {
+	BPF_MOD_NOP,
+	BPF_MOD_CALL,
+	BPF_MOD_JUMP,
+};
+
+struct bpf_text_poke {
+	void *ip;
+	void *old_addr;
+	void *new_addr;
+	enum bpf_text_poke_type old_t;
+	enum bpf_text_poke_type new_t;
+};
+
 struct bpf_tracing_multi_node {
 	struct bpf_tramp_node node;
 	struct bpf_trampoline *trampoline;
 	struct ftrace_func_entry entry;
+	struct bpf_text_poke poke;
 };
 
 struct bpf_tracing_multi_data {
@@ -2107,6 +2134,8 @@ struct bpf_tracing_multi_link {
 	struct bpf_tracing_multi_data data;
 	u64 *cookies;
 	struct bpf_tramp_node *fexits;
+	struct bpf_text_poke **pokes;
+	struct bpf_prog **tgt_progs;
 	int nodes_cnt;
 	struct bpf_tracing_multi_node nodes[] __counted_by(nodes_cnt);
 };
@@ -4225,12 +4254,7 @@ static inline u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
 }
 #endif /* CONFIG_INET */
 
-enum bpf_text_poke_type {
-	BPF_MOD_NOP,
-	BPF_MOD_CALL,
-	BPF_MOD_JUMP,
-};
-
+int bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt);
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 		       enum bpf_text_poke_type new_t, void *old_addr,
 		       void *new_addr);
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 6f70db7515dd4..df66206af3cf9 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1927,6 +1927,8 @@ union bpf_attr {
 				__aligned_u64	ids;
 				__aligned_u64	cookies;
 				__u32		cnt;
+				__u32		:32;
+				__aligned_u64	fds;
 			} tracing_multi;
 		};
 	} link_create;
@@ -6889,6 +6891,10 @@ struct bpf_btf_info {
 	__u32 kernel_btf;
 } __attribute__((aligned(8)));
 
+enum {
+	BPF_F_TRACING_MULTI_TGT_PROGS = (1U << 0),
+};
+
 struct bpf_link_info {
 	__u32 type;
 	__u32 id;
@@ -6974,10 +6980,11 @@ struct bpf_link_info {
 			__u32 attach_type;
 			__u32 count; /* in/out: tracing_multi target count */
 			__u32 btf_obj_id;
-			__u32 :32;
+			__u32 flags;
 			__aligned_u64 ids;
 			__aligned_u64 addrs;
 			__aligned_u64 cookies;
+			__aligned_u64 func_btf_ids;
 		} tracing_multi;
 		struct {
 			__u32 type; /* enum bpf_perf_event_type */
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 05c89396119ad..49b794878c116 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -3484,6 +3484,11 @@ int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,
 	return -EFAULT;
 }
 
+int __weak bpf_arch_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)
+{
+	return -EOPNOTSUPP;
+}
+
 int __weak bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
 			      enum bpf_text_poke_type new_t, void *old_addr,
 			      void *new_addr)
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index 24edb59238f34..6e18f69a63adf 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -13,6 +13,7 @@
 #include <linux/bpf_verifier.h>
 #include <linux/bpf_lsm.h>
 #include <linux/delay.h>
+#include <linux/sort.h>
 
 /* dummy _ops. The verifier will operate on target program's ops. */
 const struct bpf_verifier_ops bpf_extension_verifier_ops = {
@@ -59,6 +60,33 @@ static void trampoline_unlock(struct bpf_trampoline *tr)
 	mutex_unlock(select_trampoline_lock(tr));
 }
 
+#ifdef CONFIG_BPF_SYSCALL
+
+static void trampoline_lock_all(void)
+{
+	int i;
+
+	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
+		mutex_lock(&trampoline_locks[i].mutex);
+}
+
+static void trampoline_unlock_all(void)
+{
+	int i;
+
+	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
+		mutex_unlock(&trampoline_locks[i].mutex);
+}
+
+static void bpf_trampoline_multi_attach_init(struct bpf_trampoline *tr)
+{
+	tr->multi_attach.old_image = tr->cur_image;
+	tr->multi_attach.new_image = NULL;
+	tr->multi_attach.old_flags = tr->flags;
+}
+
+#endif /* CONFIG_BPF_SYSCALL */
+
 struct bpf_trampoline_ops {
 	int (*register_fentry)(struct bpf_trampoline *tr, struct bpf_tramp_image *im, void *data);
 	int (*unregister_fentry)(struct bpf_trampoline *tr, u32 orig_flags, void *data);
@@ -475,18 +503,11 @@ static int register_fentry(struct bpf_trampoline *tr, struct bpf_tramp_image *im
 			   void *data __maybe_unused)
 {
 	void *new_addr = im->image;
-	void *ip = tr->func.addr;
-	unsigned long faddr;
 	int ret;
 
-	faddr = ftrace_location((unsigned long)ip);
-	if (faddr) {
+	if (tr->func.ftrace_managed) {
 		if (!tr->fops)
 			return -ENOTSUPP;
-		tr->func.ftrace_managed = true;
-	}
-
-	if (tr->func.ftrace_managed) {
 		ret = direct_ops_add(tr, new_addr);
 	} else {
 		ret = bpf_trampoline_update_fentry(tr, 0, NULL, new_addr);
@@ -1286,6 +1307,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key,
 
 	memcpy(&tr->func.model, &tgt_info->fmodel, sizeof(tgt_info->fmodel));
 	tr->func.addr = (void *)tgt_info->tgt_addr;
+	tr->func.ftrace_managed = tr->ip != 0;
 out:
 	trampoline_unlock(tr);
 	return tr;
@@ -1579,22 +1601,6 @@ int __weak arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
     defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS) && \
     defined(CONFIG_BPF_SYSCALL)
 
-static void trampoline_lock_all(void)
-{
-	int i;
-
-	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
-		mutex_lock(&trampoline_locks[i].mutex);
-}
-
-static void trampoline_unlock_all(void)
-{
-	int i;
-
-	for (i = 0; i < TRAMPOLINE_LOCKS_TABLE_SIZE; i++)
-		mutex_unlock(&trampoline_locks[i].mutex);
-}
-
 static void remove_tracing_multi_data(struct bpf_tracing_multi_data *data)
 {
 	ftrace_hash_remove(data->reg);
@@ -1635,8 +1641,8 @@ static void ftrace_hash_add(struct ftrace_hash *hash, struct ftrace_func_entry *
 static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_image *im, void *ptr)
 {
 	unsigned long addr = (unsigned long) im->image;
-	unsigned long ip = ftrace_location(tr->ip);
 	struct bpf_tracing_multi_data *data = ptr;
+	unsigned long ip = tr->ip;
 
 	/*
 	 * Different BTF ids get different trampolines, but they can still
@@ -1649,7 +1655,6 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_ima
 	if (bpf_trampoline_use_jmp(tr->flags))
 		addr = ftrace_jmp_set(addr);
 
-	tr->func.ftrace_managed = true;
 	ftrace_hash_add(data->reg, data->entry, ip, addr);
 	tr->cur_image = im;
 	return 0;
@@ -1658,13 +1663,12 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_ima
 static int unregister_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags, void *ptr)
 {
 	unsigned long addr = (unsigned long) tr->cur_image->image;
-	unsigned long ip = ftrace_location(tr->ip);
 	struct bpf_tracing_multi_data *data = ptr;
 
 	if (bpf_trampoline_use_jmp(tr->flags))
 		addr = ftrace_jmp_set(addr);
 
-	ftrace_hash_add(data->unreg, data->entry, ip, addr);
+	ftrace_hash_add(data->unreg, data->entry, tr->ip, addr);
 	tr->cur_image = NULL;
 	return 0;
 }
@@ -1673,13 +1677,12 @@ static int modify_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags, struct
 			       bool lock_direct_mutex, void *ptr)
 {
 	unsigned long addr = (unsigned long) im->image;
-	unsigned long ip = ftrace_location(tr->ip);
 	struct bpf_tracing_multi_data *data = ptr;
 
 	if (bpf_trampoline_use_jmp(tr->flags))
 		addr = ftrace_jmp_set(addr);
 
-	ftrace_hash_add(data->modify, data->entry, ip, addr);
+	ftrace_hash_add(data->modify, data->entry, tr->ip, addr);
 	tr->cur_image = im;
 	return 0;
 }
@@ -1690,12 +1693,6 @@ static const struct bpf_trampoline_ops trampoline_multi_ops = {
 	.modify_fentry     = modify_fentry_multi,
 };
 
-static void bpf_trampoline_multi_attach_init(struct bpf_trampoline *tr)
-{
-	tr->multi_attach.old_image = tr->cur_image;
-	tr->multi_attach.old_flags = tr->flags;
-}
-
 static void bpf_trampoline_multi_attach_free(struct bpf_trampoline *tr)
 {
 	/*
@@ -1712,6 +1709,7 @@ static void bpf_trampoline_multi_attach_free(struct bpf_trampoline *tr)
 		bpf_tramp_image_put(tr->multi_attach.old_image);
 
 	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
 	tr->multi_attach.old_flags = 0;
 }
 
@@ -1723,6 +1721,7 @@ static void bpf_trampoline_multi_attach_rollback(struct bpf_trampoline *tr)
 	tr->flags = tr->multi_attach.old_flags;
 
 	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
 	tr->multi_attach.old_flags = 0;
 }
 
@@ -1868,10 +1867,278 @@ void bpf_trampoline_multi_detach(struct bpf_prog *prog,
 #undef for_each_mnode_cnt
 #undef for_each_mnode
 
+#else
+
+void bpf_trampoline_multi_detach(struct bpf_prog *prog,
+				 struct bpf_tracing_multi_link *link) {}
+
 #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS &&
 	  CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS &&
 	  CONFIG_BPF_SYSCALL */
 
+#ifdef CONFIG_BPF_SYSCALL
+
+static int bpf_text_poke_cmp(const void *a, const void *b)
+{
+	const struct bpf_text_poke *pa = *(struct bpf_text_poke * const *)a;
+	const struct bpf_text_poke *pb = *(struct bpf_text_poke * const *)b;
+	unsigned long ipa = (unsigned long) pa->ip;
+	unsigned long ipb = (unsigned long) pb->ip;
+
+	return (ipa > ipb) - (ipa < ipb);
+}
+
+static int bpf_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)
+{
+	int i, err;
+
+	/*
+	 * Sort pokes for two purposes:
+	 * 1. Check duplicated poke target IPs.
+	 * 2. Sorted poke target IPs would be friendly for poking them on x86,
+	 *    see arch/x86/kernel/alternative.c::smp_text_poke_batch_add().
+	 */
+	sort_nonatomic(pokes, cnt, sizeof(*pokes), bpf_text_poke_cmp, NULL);
+
+	for (i = 1; i < cnt; i++)
+		if (pokes[i - 1]->ip == pokes[i]->ip)
+			return -EINVAL;
+
+	err = bpf_arch_text_poke_batch(pokes, cnt);
+	if (err != -EOPNOTSUPP)
+		return err;
+
+	for (i = 0; i < cnt; i++) {
+		struct bpf_text_poke *p = pokes[i];
+
+		err = bpf_arch_text_poke(p->ip, p->old_t, p->new_t, p->old_addr, p->new_addr);
+		if (err)
+			goto rollback;
+	}
+
+	return 0;
+
+rollback:
+	for (i--; i >= 0; i--) {
+		struct bpf_text_poke *p = pokes[i];
+
+		WARN_ON_ONCE(bpf_arch_text_poke(p->ip, p->new_t, p->old_t, p->new_addr,
+						p->old_addr));
+	}
+	return err;
+}
+
+static enum bpf_text_poke_type bpf_trampoline_poke_type(const struct bpf_tramp_image *im, u32 flags)
+{
+	if (!im)
+		return BPF_MOD_NOP;
+
+	return bpf_trampoline_use_jmp(flags) ? BPF_MOD_JUMP : BPF_MOD_CALL;
+}
+
+static void bpf_text_poke_init(struct bpf_text_poke *poke, struct bpf_trampoline *tr)
+{
+	struct bpf_tramp_image *old_image = tr->multi_attach.old_image;
+	struct bpf_tramp_image *new_image = tr->multi_attach.new_image;
+
+	poke->ip = tr->func.addr;
+	poke->old_addr = old_image ? old_image->image : NULL;
+	poke->new_addr = new_image ? new_image->image : NULL;
+	poke->old_t = bpf_trampoline_poke_type(old_image, tr->multi_attach.old_flags);
+	poke->new_t = bpf_trampoline_poke_type(new_image, tr->flags);
+}
+
+static int register_fentry_multi_prog(struct bpf_trampoline *tr,
+				      struct bpf_tramp_image *im,
+				      void *data __maybe_unused)
+{
+	tr->multi_attach.new_image = im;
+	return 0;
+}
+
+static int unregister_fentry_multi_prog(struct bpf_trampoline *tr,
+					u32 orig_flags __maybe_unused,
+					void *data __maybe_unused)
+{
+	tr->multi_attach.new_image = NULL;
+	return 0;
+}
+
+static int modify_fentry_multi_prog(struct bpf_trampoline *tr,
+				    u32 orig_flags __maybe_unused,
+				    struct bpf_tramp_image *im,
+				    bool lock_direct_mutex __maybe_unused,
+				    void *data __maybe_unused)
+{
+	tr->multi_attach.new_image = im;
+	return 0;
+}
+
+static const struct bpf_trampoline_ops trampoline_multi_prog_ops = {
+	.register_fentry   = register_fentry_multi_prog,
+	.unregister_fentry = unregister_fentry_multi_prog,
+	.modify_fentry     = modify_fentry_multi_prog,
+};
+
+static void bpf_trampoline_multi_prog_commit(struct bpf_trampoline *tr)
+{
+	struct bpf_tramp_image *old_image = tr->multi_attach.old_image;
+
+	tr->cur_image = tr->multi_attach.new_image;
+	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
+	tr->multi_attach.old_flags = 0;
+
+	if (old_image)
+		bpf_tramp_image_put(old_image);
+}
+
+static void bpf_trampoline_multi_prog_rollback(struct bpf_trampoline *tr)
+{
+	if (tr->multi_attach.new_image)
+		bpf_tramp_image_put(tr->multi_attach.new_image);
+
+	tr->flags = tr->multi_attach.old_flags;
+	tr->multi_attach.old_image = NULL;
+	tr->multi_attach.new_image = NULL;
+	tr->multi_attach.old_flags = 0;
+}
+
+#define for_each_mnode_cnt(mnode, link, cnt) \
+	for (i = 0, mnode = &link->nodes[i]; i < cnt; i++, mnode = &link->nodes[i])
+
+#define for_each_mnode(mnode, link) \
+	for_each_mnode_cnt(mnode, link, link->nodes_cnt)
+
+static int bpf_trampoline_multi_prog_prepare(struct bpf_prog *prog, u32 *ids, u64 *keys,
+					     struct bpf_tracing_multi_link *link)
+{
+	struct bpf_attach_target_info tgt_info = {};
+	struct bpf_tracing_multi_node *mnode;
+	struct bpf_trampoline *tr;
+	int i, cnt, err;
+
+	for_each_mnode(mnode, link) {
+		err = bpf_check_attach_target(NULL, prog, link->tgt_progs[i], ids[i], &tgt_info);
+		if (err)
+			goto put_trampolines;
+
+		tr = bpf_trampoline_get(keys[i], &tgt_info);
+		if (!tr) {
+			err = -ENOMEM;
+			goto put_trampolines;
+		}
+
+		mnode->trampoline = tr;
+		mnode->node.link = &link->link;
+		mnode->node.cookie = link->cookies ? link->cookies[i] : 0;
+
+		if (prog->expected_attach_type == BPF_TRACE_FSESSION_MULTI) {
+			link->fexits[i].link = &link->link;
+			link->fexits[i].cookie = link->cookies ? link->cookies[i] : 0;
+		}
+	}
+
+	return 0;
+
+put_trampolines:
+	cnt = i;
+	for_each_mnode_cnt(mnode, link, cnt)
+		bpf_trampoline_put(mnode->trampoline);
+	return err;
+}
+
+int bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,
+				     struct bpf_tracing_multi_link *link)
+{
+	struct bpf_tracing_multi_node *mnode;
+	int i, err, linked_cnt = 0;
+
+	err = bpf_trampoline_multi_prog_prepare(prog, ids, keys, link);
+	if (err)
+		return err;
+
+	trampoline_lock_all();
+
+	for_each_mnode(mnode, link) {
+		bpf_trampoline_multi_attach_init(mnode->trampoline);
+
+		if (link->tgt_progs[i]->aux->tail_call_reachable)
+			mnode->trampoline->flags |= BPF_TRAMP_F_TAIL_CALL_CTX;
+
+		err = __bpf_trampoline_link_prog(&mnode->node, mnode->trampoline, NULL,
+						 &trampoline_multi_prog_ops, NULL);
+		if (err) {
+			bpf_trampoline_multi_prog_rollback(mnode->trampoline);
+			goto rollback;
+		}
+		linked_cnt++;
+	}
+
+	for_each_mnode(mnode, link) {
+		link->pokes[i] = &mnode->poke;
+		bpf_text_poke_init(link->pokes[i], mnode->trampoline);
+	}
+
+	err = bpf_text_poke_batch(link->pokes, link->nodes_cnt);
+	if (err)
+		goto rollback;
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_multi_prog_commit(mnode->trampoline);
+
+	trampoline_unlock_all();
+	return 0;
+
+rollback:
+	for_each_mnode_cnt(mnode, link, linked_cnt) {
+		bpf_trampoline_remove_prog(mnode->trampoline, &mnode->node);
+		bpf_trampoline_multi_prog_rollback(mnode->trampoline);
+	}
+
+	trampoline_unlock_all();
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_put(mnode->trampoline);
+	return err;
+}
+
+void bpf_trampoline_multi_prog_detach(struct bpf_tracing_multi_link *link)
+{
+	struct bpf_tracing_multi_node *mnode;
+	int i, err;
+
+	trampoline_lock_all();
+
+	for_each_mnode(mnode, link) {
+		bpf_trampoline_multi_attach_init(mnode->trampoline);
+		err = __bpf_trampoline_unlink_prog(&mnode->node, mnode->trampoline, NULL,
+						   &trampoline_multi_prog_ops, NULL);
+		if (WARN_ONCE(err, "__bpf_trampoline_unlink_prog failed: %d\n", err))
+			bpf_trampoline_multi_prog_rollback(mnode->trampoline);
+	}
+
+	for_each_mnode(mnode, link) {
+		link->pokes[i] = &mnode->poke;
+		bpf_text_poke_init(link->pokes[i], mnode->trampoline);
+	}
+
+	WARN_ON_ONCE(bpf_text_poke_batch(link->pokes, link->nodes_cnt));
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_multi_prog_commit(mnode->trampoline);
+
+	trampoline_unlock_all();
+
+	for_each_mnode(mnode, link)
+		bpf_trampoline_put(mnode->trampoline);
+}
+
+#undef for_each_mnode_cnt
+#undef for_each_mnode
+
+#endif /* CONFIG_BPF_SYSCALL */
+
 static int __init init_trampolines(void)
 {
 	int i;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 2f190abe34489..f2af2bbdd6fb5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -22284,22 +22284,24 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 			return -EOPNOTSUPP;
 		}
 
-		/*
-		 * *.multi programs don't need an address during program
-		 * verification, we just take the module ref if needed.
-		 */
-		if (is_tracing_multi_id(prog, btf_id)) {
+		if (tgt_prog) {
+			if (subprog == 0)
+				addr = (long)tgt_prog->bpf_func;
+			else
+				addr = (long)tgt_prog->aux->func[subprog]->bpf_func;
+		} else if (is_tracing_multi_id(prog, btf_id)) {
+			/*
+			 * *.multi programs don't need an address during program
+			 * verification, we just take the module ref if needed.
+			 * *.multi programs don't have tgt_prog during program
+			 * verification.
+			 */
 			if (btf_is_module(btf)) {
 				mod = btf_try_get_module(btf);
 				if (!mod)
 					return -ENOENT;
 			}
 			addr = 0;
-		} else if (tgt_prog) {
-			if (subprog == 0)
-				addr = (long) tgt_prog->bpf_func;
-			else
-				addr = (long) tgt_prog->aux->func[subprog]->bpf_func;
 		} else {
 			if (btf_is_module(btf)) {
 				mod = btf_try_get_module(btf);
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 195f78db9bdaf..39c911917ae24 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3679,15 +3679,19 @@ __bpf_kfunc int bpf_copy_from_user_task_str_dynptr(const struct bpf_dynptr *dptr
 
 __bpf_kfunc_end_defs();
 
-#if defined(CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS) && \
-    defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS)
+static void bpf_put_progs(struct bpf_prog **progs, int cnt);
 
 static void bpf_tracing_multi_link_release(struct bpf_link *link)
 {
 	struct bpf_tracing_multi_link *tr_link =
 		container_of(link, struct bpf_tracing_multi_link, link);
 
-	bpf_trampoline_multi_detach(link->prog, tr_link);
+	if (tr_link->tgt_progs) {
+		bpf_trampoline_multi_prog_detach(tr_link);
+		bpf_put_progs(tr_link->tgt_progs, tr_link->nodes_cnt);
+	} else {
+		bpf_trampoline_multi_detach(link->prog, tr_link);
+	}
 }
 
 static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
@@ -3695,6 +3699,8 @@ static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
 	struct bpf_tracing_multi_link *tr_link =
 		container_of(link, struct bpf_tracing_multi_link, link);
 
+	kvfree(tr_link->pokes);
+	kvfree(tr_link->tgt_progs);
 	kvfree(tr_link->fexits);
 	kvfree(tr_link->cookies);
 	kvfree(tr_link);
@@ -3703,15 +3709,16 @@ static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
 static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 						 struct bpf_link_info *info)
 {
+	u32 __user *fids = u64_to_user_ptr(info->tracing_multi.func_btf_ids);
 	u64 __user *ucookies = u64_to_user_ptr(info->tracing_multi.cookies);
 	u64 __user *uaddrs = u64_to_user_ptr(info->tracing_multi.addrs);
 	u32 __user *uids = u64_to_user_ptr(info->tracing_multi.ids);
 	struct bpf_tracing_multi_link *tr_link;
 	u32 ucount = info->tracing_multi.count;
-	bool has_cookies, show_addrs;
+	bool has_cookies, show_addrs, has_progs;
 	int err = 0;
 
-	if ((uids || ucookies || uaddrs) && !ucount)
+	if ((uids || ucookies || uaddrs || fids) && !ucount)
 		return -EINVAL;
 
 	tr_link = container_of(link, struct bpf_tracing_multi_link, link);
@@ -3719,9 +3726,13 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 	info->tracing_multi.attach_type = tr_link->link.attach_type;
 	info->tracing_multi.count = tr_link->nodes_cnt;
 	info->tracing_multi.btf_obj_id = btf_obj_id(tr_link->link.prog->aux->attach_btf);
+	has_progs = !!tr_link->tgt_progs;
+	info->tracing_multi.flags = has_progs ? BPF_F_TRACING_MULTI_TGT_PROGS : 0;
 
-	if (!uids && !ucookies && !uaddrs)
+	if (!uids && !ucookies && !uaddrs && !fids)
 		return 0;
+	if (has_progs != !!fids)
+		return -EINVAL;
 
 	if (ucount < tr_link->nodes_cnt)
 		err = -ENOSPC;
@@ -3733,20 +3744,27 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 
 	for (int i = 0; i < ucount; i++) {
 		struct bpf_tracing_multi_node *mnode = &tr_link->nodes[i];
+		u32 prog_id, btf_id;
 		u64 addr, cookie;
-		u32 id;
 
-		bpf_trampoline_unpack_key(mnode->trampoline->key, NULL, &id);
+		bpf_trampoline_unpack_key(mnode->trampoline->key, &prog_id, &btf_id);
 
-		addr = show_addrs ? mnode->trampoline->ip : 0;
+		if (!show_addrs)
+			addr = 0;
+		else if (has_progs)
+			addr = (u64) mnode->trampoline->func.addr;
+		else
+			addr = mnode->trampoline->ip;
 		cookie = has_cookies ? tr_link->cookies[i] : 0;
 
-		if (uids && put_user(id, uids + i))
+		if (uids && put_user(has_progs ? prog_id : btf_id, uids + i))
 			return -EFAULT;
 		if (uaddrs && put_user(addr, uaddrs + i))
 			return -EFAULT;
 		if (ucookies && put_user(cookie, ucookies + i))
 			return -EFAULT;
+		if (has_progs && put_user((u32) mnode->trampoline->key, fids + i))
+			return -EFAULT;
 
 		cond_resched();
 	}
@@ -3755,26 +3773,45 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
 }
 
 #ifdef CONFIG_PROC_FS
+static const char *bpf_prog_func_name(struct bpf_prog *prog, u32 btf_id)
+{
+	const struct btf *btf = prog->aux->btf;
+	const struct btf_type *t;
+
+	t = btf_type_by_id(btf, btf_id);
+	if (!t || !btf_type_is_func(t))
+		return "";
+
+	return btf_name_by_offset(btf, t->name_off);
+}
+
 static void bpf_tracing_multi_show_fdinfo(const struct bpf_link *link,
 					  struct seq_file *seq)
 {
 	struct bpf_tracing_multi_link *tr_link =
 		container_of(link, struct bpf_tracing_multi_link, link);
 	bool has_cookies = !!tr_link->cookies;
+	bool has_progs = !!tr_link->tgt_progs;
 
 	seq_printf(seq, "attach_type:\t%u\n", tr_link->link.attach_type);
 	seq_printf(seq, "cnt:\t%u\n", tr_link->nodes_cnt);
 
-	seq_printf(seq, "%s\t %s\t %s\t %s\n", "obj-id", "btf-id", "cookie", "func");
+	seq_printf(seq, "%s\t %s\t %s\t %s\n", has_progs ? "prog-id" : "obj-id", "btf-id", "cookie",
+		   "func");
 	for (int i = 0; i < tr_link->nodes_cnt; i++) {
 		struct bpf_tracing_multi_node *mnode = &tr_link->nodes[i];
+		u64 cookie = has_cookies ? tr_link->cookies[i] : 0;
 		u32 btf_id, obj_id;
 
 		bpf_trampoline_unpack_key(mnode->trampoline->key, &obj_id, &btf_id);
-		seq_printf(seq, "%u\t %u\t %llu\t %pS\n",
-			   obj_id, btf_id,
-			   has_cookies ? tr_link->cookies[i] : 0,
-			   (void *) mnode->trampoline->ip);
+		if (has_progs)
+			seq_printf(seq, "%u\t %u\t %llu\t %s\n",
+				   obj_id, btf_id, cookie,
+				   bpf_prog_func_name(tr_link->tgt_progs[i], btf_id));
+		else
+			seq_printf(seq, "%u\t %u\t %llu\t %pS\n",
+				   obj_id, btf_id, cookie,
+				   (void *) mnode->trampoline->ip);
 
 		cond_resched();
 	}
@@ -3790,64 +3827,129 @@ static const struct bpf_link_ops bpf_tracing_multi_link_lops = {
 #endif
 };
 
-static int ids_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)
+struct tracing_multi_sort_data {
+	u64 *keys;
+	struct bpf_prog **progs;
+	u32 *ids;
+	u64 *cookies;
+};
+
+static int keys_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)
 {
-	u32 a = *(u32 *) pa;
-	u32 b = *(u32 *) pb;
+	const u64 *key_a = pa, *key_b = pb;
 
-	return (a > b) - (a < b);
+	return (*key_a > *key_b) - (*key_a < *key_b);
 }
 
-static void ids_swap_r(void *a, void *b, int size __maybe_unused,
-		       const void *priv __maybe_unused)
+static void keys_swap_r(void *a, void *b, int size __maybe_unused,
+			const void *priv __maybe_unused)
 {
+	const struct tracing_multi_sort_data *data = priv;
+	struct bpf_prog **prog_a, **prog_b;
 	u64 *cookie_a, *cookie_b, *cookies;
-	u32 *id_a = a, *id_b = b, *ids;
-	void **data = (void **) priv;
+	u64 *key_a = a, *key_b = b, *keys;
+	u32 *id_a, *id_b, *ids;
 
-	ids     = data[0];
-	cookies = data[1];
+	keys    = data->keys;
+	ids     = data->ids;
+	cookies = data->cookies;
+	id_a    = ids + (key_a - keys);
+	id_b    = ids + (key_b - keys);
+
+	if (data->progs) {
+		prog_a = data->progs + (key_a - keys);
+		prog_b = data->progs + (key_b - keys);
+		swap(*prog_a, *prog_b);
+	}
 
 	if (cookies) {
 		cookie_a = cookies + (id_a - ids);
 		cookie_b = cookies + (id_b - ids);
 		swap(*cookie_a, *cookie_b);
 	}
+
 	swap(*id_a, *id_b);
+	swap(*key_a, *key_b);
 }
 
-static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)
+static int check_dup_keys(u64 *keys, struct bpf_prog **progs, u32 *ids,
+			  u64 *cookies, u32 cnt)
 {
-	void *data[2] = { ids, cookies };
-	int err = 0;
+	struct tracing_multi_sort_data data = {
+		.keys = keys,
+		.progs = progs,
+		.ids = ids,
+		.cookies = cookies,
+	};
 
 	/*
-	 * Sort ids array (together with cookies array if defined)
-	 * and check it for duplicates. The ids and cookies arrays
-	 * are left sorted.
+	 * Sort trampoline keys together with target programs, ids, and cookies,
+	 * then check for duplicates. The arrays are left sorted.
 	 */
-	sort_r_nonatomic(ids, cnt, sizeof(ids[0]), ids_cmp_r, ids_swap_r, data);
+	sort_r_nonatomic(keys, cnt, sizeof(keys[0]), keys_cmp_r, keys_swap_r, &data);
 
-	for (int i = 1; i < cnt; i++) {
-		if (ids[i] == ids[i - 1]) {
+	for (int i = 1; i < cnt; i++)
+		if (keys[i] == keys[i - 1])
+			return -EINVAL;
+
+	return 0;
+}
+
+static void bpf_put_progs(struct bpf_prog **progs, int cnt)
+{
+	int i;
+
+	if (!progs)
+		return;
+
+	for (i = 0; i < cnt; i++)
+		bpf_prog_put(progs[i]);
+}
+
+static int bpf_get_progs(struct bpf_prog **progs, int *fds, int cnt)
+{
+	int err, i, put_cnt = 0;
+	struct bpf_prog *prog;
+
+	for (i = 0; i < cnt; i++) {
+		prog = bpf_prog_get(fds[i]);
+		if (IS_ERR(prog)) {
+			err = PTR_ERR(prog);
+			goto error;
+		}
+
+		progs[i] = prog;
+		put_cnt++;
+
+		if (prog->type == BPF_PROG_TYPE_TRACING) {
 			err = -EINVAL;
-			break;
+			goto error;
 		}
 	}
+	return 0;
+
+error:
+	bpf_put_progs(progs, put_cnt);
 	return err;
 }
 
 int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 {
 	struct bpf_tracing_multi_link *link = NULL;
+	struct btf *btf = prog->aux->attach_btf;
 	struct bpf_tramp_node *fexits = NULL;
 	struct bpf_link_primer link_primer;
+	struct bpf_text_poke **pokes = NULL;
+	u64 *cookies = NULL, *keys = NULL;
+	struct bpf_prog **progs = NULL;
 	u32 cnt, *ids = NULL;
 	u64 __user *ucookies;
-	u64 *cookies = NULL;
 	u32 __user *uids;
+	int __user *ufds;
+	int *fds = NULL;
 	int err;
 
+	ufds = u64_to_user_ptr(attr->link_create.tracing_multi.fds);
 	uids = u64_to_user_ptr(attr->link_create.tracing_multi.ids);
 	cnt = attr->link_create.tracing_multi.cnt;
 
@@ -3858,6 +3960,9 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 	if (attr->link_create.flags || attr->link_create.target_fd)
 		return -EINVAL;
 
+	if (!ufds && !IS_ENABLED(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS))
+		return -EOPNOTSUPP;
+
 	ids = kvmalloc_objs(*ids, cnt);
 	if (!ids)
 		return -ENOMEM;
@@ -3867,6 +3972,37 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 		goto error;
 	}
 
+	if (ufds) {
+		fds = kvmalloc_objs(*fds, cnt);
+		if (!fds) {
+			err = -ENOMEM;
+			goto error;
+		}
+
+		if (copy_from_user(fds, ufds, cnt * sizeof(*fds))) {
+			err = -EFAULT;
+			goto error;
+		}
+
+		progs = kvmalloc_objs(*progs, cnt);
+		if (!progs) {
+			err = -ENOMEM;
+			goto error;
+		}
+
+		err = bpf_get_progs(progs, fds, cnt);
+		if (err) {
+			cnt = 0;
+			goto error;
+		}
+
+		pokes = kvmalloc_objs(*pokes, cnt);
+		if (!pokes) {
+			err = -ENOMEM;
+			goto error;
+		}
+	}
+
 	ucookies = u64_to_user_ptr(attr->link_create.tracing_multi.cookies);
 	if (ucookies) {
 		cookies = kvmalloc_objs(*cookies, cnt);
@@ -3880,7 +4016,16 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 		}
 	}
 
-	err = check_dup_ids(ids, cookies, cnt);
+	keys = kvmalloc_objs(*keys, cnt);
+	if (!keys) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	for (int i = 0; i < cnt; i++)
+		keys[i] = bpf_trampoline_compute_key(progs ? progs[i] : NULL, btf, ids[i]);
+
+	err = check_dup_keys(keys, progs, ids, cookies, cnt);
 	if (err)
 		goto error;
 
@@ -3908,28 +4053,32 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
 	link->nodes_cnt = cnt;
 	link->cookies = cookies;
 	link->fexits = fexits;
+	link->tgt_progs = progs;
+	link->pokes = pokes;
 
-	err = bpf_trampoline_multi_attach(prog, ids, link);
+	if (progs)
+		err = bpf_trampoline_multi_prog_attach(prog, ids, keys, link);
+	else
+		err = bpf_trampoline_multi_attach(prog, ids, link);
 	kvfree(ids);
+	kvfree(keys);
+	kvfree(fds);
 	if (err) {
+		bpf_put_progs(progs, cnt);
 		bpf_link_cleanup(&link_primer);
 		return err;
 	}
 	return bpf_link_settle(&link_primer);
 
 error:
+	bpf_put_progs(progs, cnt);
 	kvfree(fexits);
 	kvfree(cookies);
 	kvfree(ids);
+	kvfree(keys);
+	kvfree(fds);
+	kvfree(progs);
+	kvfree(pokes);
 	kvfree(link);
 	return err;
 }
-
-#else
-
-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
-{
-	return -EOPNOTSUPP;
-}
-
-#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS && CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS */
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 5cffa2d283b47..da7e430b14c8a 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -422,12 +422,31 @@ show_uprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 	jsonw_end_array(json_wtr);
 }
 
+#define BPF_PROG_PREFIX		"bpf_prog_"
+#define BPF_PROG_PREFIX_LEN	(sizeof(BPF_PROG_PREFIX) - 1)
+
+static const char *
+sym_name_trim_prefix(struct kernel_sym *sym, bool is_prog)
+{
+	int prefix_len;
+
+	if (!is_prog)
+		return sym->name;
+
+	/* Ref kernel/bpf/core.c::bpf_prog_ksym_set_name() */
+	prefix_len  = BPF_PROG_PREFIX_LEN;
+	prefix_len += BPF_TAG_SIZE * 2;
+	if (sym->name[prefix_len] != '\0')
+		prefix_len += 1;		/* skip the '_' */
+	return sym->name + prefix_len;
+}
+
 static void
 show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 {
-	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;
+	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;
 	__u64 *addrs, *cookies;
-	__u32 i, *ids;
+	__u32 i, *ids, *fids;
 
 	if (!dd.sym_count)
 		kernel_syms_load(&dd);
@@ -443,6 +462,8 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 	ids = u64_to_u32_arr(info->tracing_multi.ids);
 	addrs = u64_to_arr(info->tracing_multi.addrs);
 	cookies = u64_to_arr(info->tracing_multi.cookies);
+	fids = u64_to_u32_arr(info->tracing_multi.func_btf_ids);
+	tgt_progs = info->tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
 
 	for (i = 0; i < info->tracing_multi.count; i++) {
 		struct kernel_sym *sym;
@@ -451,10 +472,12 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 		sym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;
 
 		jsonw_start_object(wtr);
-		jsonw_uint_field(wtr, "id", ids[i]);
+		jsonw_uint_field(wtr, tgt_progs ? "prog_id" : "id", ids[i]);
+		if (tgt_progs)
+			jsonw_uint_field(wtr, "func_btf_id", fids[i]);
 		jsonw_uint_field(wtr, "addr", addr);
 		if (sym) {
-			jsonw_string_field(wtr, "func", sym->name);
+			jsonw_string_field(wtr, "func", sym_name_trim_prefix(sym, tgt_progs));
 			if (sym->module[0] == '\0') {
 				jsonw_name(wtr, "module");
 				jsonw_null(wtr);
@@ -903,9 +926,9 @@ static void show_uprobe_multi_plain(struct bpf_link_info *info)
 
 static void show_tracing_multi_plain(struct bpf_link_info *info)
 {
-	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;
+	bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;
 	__u64 *addrs, *cookies;
-	__u32 i, *ids;
+	__u32 i, *ids, *fids;
 
 	if (!info->tracing_multi.count)
 		return;
@@ -919,12 +942,18 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)
 	printf("btf_obj_id %u  ", info->tracing_multi.btf_obj_id);
 	printf("count %u  ", info->tracing_multi.count);
 
-	printf("\n\t%-16s %-16s %-16s %s",
-	       "btf_id", "addr", "cookie", "func [module]");
+	tgt_progs = info->tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
+	if (tgt_progs)
+		printf("\n\t%-16s %-16s %-16s %-16s %s",
+		       "prog_id", "func_btf_id", "addr", "cookie", "func [module]");
+	else
+		printf("\n\t%-16s %-16s %-16s %s",
+		       "btf_id", "addr", "cookie", "func [module]");
 
 	ids = u64_to_u32_arr(info->tracing_multi.ids);
 	addrs = u64_to_arr(info->tracing_multi.addrs);
 	cookies = u64_to_arr(info->tracing_multi.cookies);
+	fids = u64_to_u32_arr(info->tracing_multi.func_btf_ids);
 
 	for (i = 0; i < info->tracing_multi.count; i++) {
 		__u64 addr = addrs[i];
@@ -932,9 +961,13 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)
 
 		sym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;
 
-		printf("\n\t%-16u %016llx %-16llu", ids[i], addr, cookies[i]);
+		if (tgt_progs)
+			printf("\n\t%-16u %-16u %016llx %-16llu",
+			       ids[i], fids[i], addr, cookies[i]);
+		else
+			printf("\n\t%-16u %016llx %-16llu", ids[i], addr, cookies[i]);
 		if (sym) {
-			printf(" %s", sym->name);
+			printf(" %s", sym_name_trim_prefix(sym, tgt_progs));
 			if (sym->module[0] != '\0')
 				printf(" [%s]", sym->module);
 		}
@@ -1140,7 +1173,7 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
 static int do_show_link(int fd)
 {
 	__u64 *ref_ctr_offsets = NULL, *offsets = NULL, *cookies = NULL;
-	__u32 *ids = NULL;
+	__u32 *ids = NULL, *func_btf_ids = NULL;
 	struct bpf_link_info info;
 	__u32 len = sizeof(info);
 	char path_buf[PATH_MAX];
@@ -1229,12 +1262,16 @@ static int do_show_link(int fd)
 	if (info.type == BPF_LINK_TYPE_TRACING_MULTI && !info.tracing_multi.ids) {
 		count = info.tracing_multi.count;
 		if (count) {
+			bool tgt_progs = info.tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
+
 			ids = calloc(count, sizeof(__u32));
 			addrs = calloc(count, sizeof(__u64));
 			cookies = calloc(count, sizeof(__u64));
-			if (!ids || !addrs || !cookies) {
+			func_btf_ids = tgt_progs ? calloc(count, sizeof(__u32)) : NULL;
+			if (!ids || !addrs || !cookies || (tgt_progs && !func_btf_ids)) {
 				p_err("mem alloc failed");
 				close(fd);
+				free(func_btf_ids);
 				free(cookies);
 				free(addrs);
 				free(ids);
@@ -1243,6 +1280,7 @@ static int do_show_link(int fd)
 			info.tracing_multi.ids = ptr_to_u64(ids);
 			info.tracing_multi.addrs = ptr_to_u64(addrs);
 			info.tracing_multi.cookies = ptr_to_u64(cookies);
+			info.tracing_multi.func_btf_ids = ptr_to_u64(func_btf_ids);
 			goto again;
 		}
 	}
@@ -1282,6 +1320,7 @@ static int do_show_link(int fd)
 		show_link_close_plain(fd, &info);
 
 	free(ref_ctr_offsets);
+	free(func_btf_ids);
 	free(cookies);
 	free(offsets);
 	free(addrs);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 6f70db7515dd4..60998ea1381ce 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1927,6 +1927,8 @@ union bpf_attr {
 				__aligned_u64	ids;
 				__aligned_u64	cookies;
 				__u32		cnt;
+				__u32		:32;
+				__aligned_u64	fds;
 			} tracing_multi;
 		};
 	} link_create;
@@ -6815,6 +6817,10 @@ struct sk_reuseport_md {
 
 #define BPF_TAG_SIZE	8
 
+enum {
+	BPF_F_TRACING_MULTI_TGT_PROGS = (1U << 0),
+};
+
 struct bpf_prog_info {
 	__u32 type;
 	__u32 id;
@@ -6974,10 +6980,11 @@ struct bpf_link_info {
 			__u32 attach_type;
 			__u32 count; /* in/out: tracing_multi target count */
 			__u32 btf_obj_id;
-			__u32 :32;
+			__u32 flags;
 			__aligned_u64 ids;
 			__aligned_u64 addrs;
 			__aligned_u64 cookies;
+			__aligned_u64 func_btf_ids;
 		} tracing_multi;
 		struct {
 			__u32 type; /* enum bpf_perf_event_type */
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index b49822d212aed..4a78ccba9df2d 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -852,6 +852,7 @@ int bpf_link_create(int prog_fd, int target_fd,
 		attr.link_create.tracing_multi.ids = ptr_to_u64(OPTS_GET(opts, tracing_multi.ids, 0));
 		attr.link_create.tracing_multi.cookies = ptr_to_u64(OPTS_GET(opts, tracing_multi.cookies, 0));
 		attr.link_create.tracing_multi.cnt = OPTS_GET(opts, tracing_multi.cnt, 0);
+		attr.link_create.tracing_multi.fds = ptr_to_u64(OPTS_GET(opts, tracing_multi.fds, 0));
 		if (!OPTS_ZEROED(opts, tracing_multi))
 			return libbpf_err(-EINVAL);
 		break;
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 826d9cc9ab65d..cc37cf622dd85 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -474,6 +474,8 @@ struct bpf_link_create_opts {
 			const __u32 *ids;
 			const __u64 *cookies;
 			__u32 cnt;
+			__u32 :32;
+			const int *fds;
 		} tracing_multi;
 	};
 	size_t :0;
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index cb09ded907732..72e2459e93399 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11604,7 +11604,7 @@ int libbpf_find_vmlinux_btf_id(const char *name,
 	return libbpf_err(err);
 }
 
-static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd)
+int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd)
 {
 	struct bpf_prog_info info;
 	__u32 info_len = sizeof(info);
@@ -13671,10 +13671,12 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa
 {
 	LIBBPF_OPTS(bpf_link_create_opts, lopts);
 	int prog_fd, link_fd, err, cnt;
+	struct bpf_link *link = NULL;
 	__u32 *free_ids = NULL;
-	struct bpf_link *link;
 	const __u64 *cookies;
+	const char **funcs;
 	const __u32 *ids;
+	const int *fds;
 
 	if (!OPTS_VALID(opts, bpf_tracing_multi_opts))
 		return libbpf_err_ptr(-EINVAL);
@@ -13689,12 +13691,22 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa
 	cnt = OPTS_GET(opts, cnt, 0);
 	ids = OPTS_GET(opts, ids, NULL);
 	cookies = OPTS_GET(opts, cookies, NULL);
+	fds = OPTS_GET(opts, fds, NULL);
+	funcs = OPTS_GET(opts, funcs, NULL);
 
-	if (!!ids != !!cnt)
+	if (ids && fds)
+		return libbpf_err_ptr(-EINVAL);
+	if (!!fds != !!funcs)
+		return libbpf_err_ptr(-EINVAL);
+	if (fds && !cnt)
 		return libbpf_err_ptr(-EINVAL);
-	if (pattern && (ids || cookies))
+	if (ids && !cnt)
 		return libbpf_err_ptr(-EINVAL);
-	if (!pattern && !ids)
+	if (!fds && !ids && cnt)
+		return libbpf_err_ptr(-EINVAL);
+	if (pattern && (fds || ids || cookies))
+		return libbpf_err_ptr(-EINVAL);
+	if (!pattern && !ids && !fds)
 		return libbpf_err_ptr(-EINVAL);
 
 	if (pattern) {
@@ -13704,11 +13716,32 @@ bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pa
 		if (cnt == 0)
 			return libbpf_err_ptr(-EINVAL);
 		ids = (const __u32 *) free_ids;
+	} else if (fds) {
+		size_t cap = 0;
+		int i;
+
+		err = libbpf_ensure_mem((void **) &free_ids, &cap, sizeof(*free_ids), cnt);
+		if (err)
+			return libbpf_err_ptr(err);
+
+		for (i = 0; i < cnt; i++) {
+			if (!funcs[i]) {
+				err = -EINVAL;
+				goto error;
+			}
+			err = libbpf_find_prog_btf_id(funcs[i], fds[i], prog->obj->token_fd);
+			if (err < 0)
+				goto error;
+
+			free_ids[i] = err;
+		}
+		ids = (const __u32 *) free_ids;
 	}
 
 	lopts.tracing_multi.ids = ids;
 	lopts.tracing_multi.cookies = cookies;
 	lopts.tracing_multi.cnt = cnt;
+	lopts.tracing_multi.fds = fds;
 
 	link = calloc(1, sizeof(*link));
 	if (!link) {
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 03f794f4adb03..612f3e17ebc25 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -746,10 +746,12 @@ struct bpf_tracing_multi_opts {
 	const __u32 *ids;
 	const __u64 *cookies;
 	size_t cnt;
+	const int *fds;
+	const char **funcs;
 	size_t :0;
 };
 
-#define bpf_tracing_multi_opts__last_field cnt
+#define bpf_tracing_multi_opts__last_field funcs
 
 LIBBPF_API struct bpf_link *
 bpf_program__attach_tracing_multi(const struct bpf_program *prog, const char *pattern,
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 4e45dfacb548a..d4e899181bddc 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -439,6 +439,7 @@ int btf_load_into_kernel(struct btf *btf,
 			 char *log_buf, size_t log_sz, __u32 log_level,
 			 int token_fd);
 struct btf *btf_load_from_kernel(__u32 id, struct btf *base_btf, int token_fd);
+int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int token_fd);
 
 struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf);
 void btf_get_kernel_prefix_kind(enum bpf_attach_type attach_type,
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 80d8bbbc3084a..23bed732d1bdd 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -625,6 +625,7 @@ $(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/bloom_filter_bench.skel.h
 $(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop_bench.skel.h
 $(OUTPUT)/bench_bpf_for.o: $(OUTPUT)/bpf_for_bench.skel.h
 $(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_bench.skel.h
+$(OUTPUT)/bench_tracing_multi_attach_progs.o: $(OUTPUT)/tracing_multi_attach_progs.skel.h
 $(OUTPUT)/bench_bpf_hashmap_full_update.o: $(OUTPUT)/bpf_hashmap_full_update_bench.skel.h
 $(OUTPUT)/bench_local_storage.o: $(OUTPUT)/local_storage_bench.skel.h
 $(OUTPUT)/bench_local_storage_rcu_tasks_trace.o: $(OUTPUT)/local_storage_rcu_tasks_trace_bench.skel.h
diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
index d5f494184f9d1..c7502187e6541 100644
--- a/tools/testing/selftests/bpf/bench.c
+++ b/tools/testing/selftests/bpf/bench.c
@@ -529,6 +529,9 @@ extern const struct bench bench_trig_fmodret;
 extern const struct bench bench_trig_tp;
 extern const struct bench bench_trig_rawtp;
 
+/* tracing_multi link attachment benchmark */
+extern const struct bench bench_tracing_multi_attach_progs;
+
 /* uprobe/uretprobe benchmarks */
 extern const struct bench bench_trig_uprobe_nop;
 extern const struct bench bench_trig_uretprobe_nop;
@@ -615,6 +618,8 @@ static const struct bench *benchs[] = {
 	&bench_trig_fmodret,
 	&bench_trig_tp,
 	&bench_trig_rawtp,
+	/* tracing_multi */
+	&bench_tracing_multi_attach_progs,
 	/* uprobes */
 	&bench_trig_uprobe_nop,
 	&bench_trig_uretprobe_nop,
diff --git a/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c
new file mode 100644
index 0000000000000..6cc6851eb488e
--- /dev/null
+++ b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <string.h>
+#include "bench.h"
+#include "testing_helpers.h"
+#include "tracing_multi_attach_progs.skel.h"
+#include "bpf/libbpf_internal.h"
+
+#define TARGET_CNT 1000
+
+static struct ctx {
+	struct tracing_multi_attach_progs *targets[TARGET_CNT];
+	struct tracing_multi_attach_progs *fentries[TARGET_CNT];
+	struct tracing_multi_attach_progs *fentry_multi;
+	int target_fds[TARGET_CNT];
+	__u32 target_btf_ids[TARGET_CNT];
+	int fentry_prog_fds[TARGET_CNT];
+	int fentry_multi_prog_fd;
+} ctx;
+
+static void prepare(void)
+{
+	int err, i;
+
+	setup_libbpf();
+
+	for (i = 0; i < TARGET_CNT; i++) {
+		struct tracing_multi_attach_progs *target;
+		int btf_id, fd, obj_token_fd;
+
+		target = tracing_multi_attach_progs__open();
+		if (!target) {
+			fprintf(stderr, "failed to open target program %d\n", i);
+			exit(1);
+		}
+
+		bpf_program__set_autoload(target->progs.dummy_fentry, false);
+		bpf_program__set_autoload(target->progs.dummy_fentry_multi, false);
+		err = tracing_multi_attach_progs__load(target);
+		if (err) {
+			fprintf(stderr, "failed to load target program %d: %s\n",
+				i, strerror(-err));
+			exit(1);
+		}
+
+		fd = bpf_program__fd(target->progs.target);
+		obj_token_fd = bpf_object__token_fd(target->obj);
+		obj_token_fd = obj_token_fd < 0 ? 0 : obj_token_fd;
+		btf_id = libbpf_find_prog_btf_id("target", fd, obj_token_fd);
+		if (btf_id <= 0) {
+			fprintf(stderr, "failed to find target BTF ID: %s\n",
+				strerror(-btf_id));
+			exit(1);
+		}
+
+		ctx.targets[i] = target;
+		ctx.target_fds[i] = fd;
+		ctx.target_btf_ids[i] = btf_id;
+	}
+}
+
+static long create_and_attach_fentry(void)
+{
+	int link_fds[TARGET_CNT];
+	long start_ns, end_ns;
+	int err, i, j;
+
+	start_ns = get_time_ns();
+
+	/* An ordinary fentry program is bound to one target when it is loaded. */
+	for (i = 0; i < TARGET_CNT; i++) {
+		struct tracing_multi_attach_progs *fentry;
+
+		fentry = tracing_multi_attach_progs__open();
+		if (!fentry) {
+			fprintf(stderr, "failed to open fentry program %d\n", i);
+			exit(1);
+		}
+
+		bpf_program__set_autoload(fentry->progs.target, false);
+		bpf_program__set_autoload(fentry->progs.dummy_fentry_multi, false);
+		err = bpf_program__set_attach_target(fentry->progs.dummy_fentry, ctx.target_fds[i],
+						     "target");
+		err = err ?: tracing_multi_attach_progs__load(fentry);
+		if (err) {
+			fprintf(stderr, "failed to load fentry program %d: %s\n",
+				i, strerror(-err));
+			exit(1);
+		}
+
+		ctx.fentries[i] = fentry;
+		ctx.fentry_prog_fds[i] = bpf_program__fd(fentry->progs.dummy_fentry);
+	}
+
+	for (i = 0; i < TARGET_CNT; i++) {
+		link_fds[i] = bpf_link_create(ctx.fentry_prog_fds[i], 0, BPF_TRACE_FENTRY, NULL);
+		if (link_fds[i] < 0) {
+			err = errno;
+			for (j = 0; j < i; j++)
+				close(link_fds[j]);
+			fprintf(stderr, "failed to create fentry link %d: %s\n",
+				i, strerror(err));
+			exit(1);
+		}
+	}
+	end_ns = get_time_ns();
+
+	for (i = 0; i < TARGET_CNT; i++)
+		close(link_fds[i]);
+
+	return end_ns - start_ns;
+}
+
+static long create_and_attach_fentry_multi(void)
+{
+	LIBBPF_OPTS(bpf_link_create_opts, opts);
+	long start_ns, end_ns;
+	int err, link_fd;
+
+	opts.tracing_multi.ids = ctx.target_btf_ids;
+	opts.tracing_multi.fds = ctx.target_fds;
+	opts.tracing_multi.cnt = TARGET_CNT;
+
+	start_ns = get_time_ns();
+
+	ctx.fentry_multi = tracing_multi_attach_progs__open();
+	if (!ctx.fentry_multi) {
+		fprintf(stderr, "failed to open fentry.multi program\n");
+		exit(1);
+	}
+
+	bpf_program__set_autoload(ctx.fentry_multi->progs.target, false);
+	bpf_program__set_autoload(ctx.fentry_multi->progs.dummy_fentry, false);
+	err = tracing_multi_attach_progs__load(ctx.fentry_multi);
+	if (err) {
+		fprintf(stderr, "failed to load fentry.multi program: %s\n",
+			strerror(-err));
+		exit(1);
+	}
+
+	ctx.fentry_multi_prog_fd = bpf_program__fd(ctx.fentry_multi->progs.dummy_fentry_multi);
+	link_fd = bpf_link_create(ctx.fentry_multi_prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &opts);
+	end_ns = get_time_ns();
+	if (link_fd < 0) {
+		err = errno;
+		fprintf(stderr, "failed to create fentry.multi link: %s\n",
+			strerror(err));
+		exit(1);
+	}
+
+	close(link_fd);
+	return end_ns - start_ns;
+}
+
+static void cleanup(void)
+{
+	int i;
+
+	tracing_multi_attach_progs__destroy(ctx.fentry_multi);
+	for (i = 0; i < TARGET_CNT; i++) {
+		tracing_multi_attach_progs__destroy(ctx.fentries[i]);
+		tracing_multi_attach_progs__destroy(ctx.targets[i]);
+	}
+}
+
+static void setup(void)
+{
+	double fentry_multi_ms, fentry_ms;
+	long fentry_multi_ns, fentry_ns;
+
+	prepare();
+	fentry_ns = create_and_attach_fentry();
+	fentry_multi_ns = create_and_attach_fentry_multi();
+	fentry_ms = fentry_ns / 1000000.0;
+	fentry_multi_ms = fentry_multi_ns / 1000000.0;
+
+	printf("%s: prepared %d identical BPF program targets\n",
+	       bench->name, TARGET_CNT);
+	printf("%s: fentry created and attached %d programs/links in %-.3lfms\n",
+	       bench->name, TARGET_CNT, fentry_ms);
+	printf("%s: fentry.multi created one program and attached one %d-target link in %-.3lfms\n",
+	       bench->name, TARGET_CNT, fentry_multi_ms);
+	printf("%s: fentry.multi creation/attachment speedup is %-.2lfx\n",
+	       bench->name, fentry_ms / fentry_multi_ms);
+
+	cleanup();
+	exit(0);
+}
+
+const struct bench bench_tracing_multi_attach_progs = {
+	.name = "tracing-multi-attach-progs",
+	.setup = setup,
+};
diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
index 0918321c8e63d..422e94f134094 100644
--- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
@@ -3,11 +3,13 @@
 
 #include <string.h>
 #include <linux/bpf.h>
+#include <linux/kallsyms.h>
 #include <linux/limits.h>
 #include <bpf/btf.h>
 #include <test_progs.h>
 #include "trace_helpers.h"
 #include "test_fill_link_info.skel.h"
+#include "tracing_multi_bpf.skel.h"
 #include "bpf/libbpf_internal.h"
 
 #define TP_CAT "sched"
@@ -39,8 +41,19 @@ struct tmulti_target {
 	__u64 addr;
 	__u64 cookie;
 	__u32 id;
+	__u32 func_btf_id;
 };
 
+static const char *tmulti_bpf_funcs[] = {
+	"target_1",
+	"target_2",
+};
+
+static __u64 tmulti_bpf_fentry_cookies[] = { 0xfeed01, 0xfeed02 };
+static __u64 tmulti_bpf_fexit_cookies[] = { 0xfeed11, 0xfeed12 };
+static __u64 tmulti_bpf_fsession_cookies[] = { 0xfeed21, 0xfeed22 };
+#define TRACING_MULTI_BPF_CNT ARRAY_SIZE(tmulti_bpf_funcs)
+
 #define UPROBE_FILE "/proc/self/exe"
 static ssize_t uprobe_offset;
 /* uprobe attach point */
@@ -421,14 +434,28 @@ static int tmulti_target_cmp(const void *a, const void *b)
 	return (ta->id > tb->id) - (ta->id < tb->id);
 }
 
+static int setup_tmulti_btf_obj_id(const struct bpf_program *prog, __u32 *btf_obj_id)
+{
+	struct bpf_prog_info prog_info = {};
+	__u32 len = sizeof(prog_info);
+	int err;
+
+	err = bpf_prog_get_info_by_fd(bpf_program__fd(prog), &prog_info, &len);
+	if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
+		return -1;
+	if (!ASSERT_GT(prog_info.attach_btf_obj_id, 0, "attach_btf_obj_id"))
+		return -1;
+
+	*btf_obj_id = prog_info.attach_btf_obj_id;
+	return 0;
+}
+
 static int setup_tmulti_targets(const struct bpf_program *prog,
 				struct tmulti_target *targets,
 				__u32 *btf_obj_id)
 {
-	struct bpf_prog_info prog_info;
-	__u32 len = sizeof(prog_info);
 	struct btf *btf;
-	int err, i;
+	int i;
 	__s32 id;
 
 	btf = btf__load_vmlinux_btf();
@@ -446,13 +473,8 @@ static int setup_tmulti_targets(const struct bpf_program *prog,
 		targets[i].id = id;
 	}
 
-	memset(&prog_info, 0, len);
-	err = bpf_prog_get_info_by_fd(bpf_program__fd(prog), &prog_info, &len);
-	if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
-		goto error;
-	if (!ASSERT_GT(prog_info.attach_btf_obj_id, 0, "attach_btf_obj_id"))
+	if (setup_tmulti_btf_obj_id(prog, btf_obj_id))
 		goto error;
-	*btf_obj_id = prog_info.attach_btf_obj_id;
 
 	/*
 	 * The kernel tracing multi attach sorts ids. We sort as well,
@@ -467,13 +489,49 @@ static int setup_tmulti_targets(const struct bpf_program *prog,
 	return -1;
 }
 
+static int setup_tmulti_bpf_prog_targets(const struct bpf_program *prog, int token_fd,
+					 const __u64 *cookies,
+					 const struct bpf_program * const *target_progs,
+					 struct tmulti_target *targets,
+					 __u32 *btf_obj_id)
+{
+	struct bpf_prog_info prog_info = {};
+	__u32 len = sizeof(prog_info), func_btf_id;
+	int err, i, prog_fd;
+
+	for (i = 0; i < TRACING_MULTI_BPF_CNT; i++) {
+		memset(&prog_info, 0, sizeof(prog_info));
+		len = sizeof(prog_info);
+		prog_info.jited_ksyms = ptr_to_u64(&targets[i].addr);
+		prog_info.nr_jited_ksyms = 1;
+		prog_fd = bpf_program__fd(target_progs[i]);
+		err = bpf_prog_get_info_by_fd(prog_fd, &prog_info, &len);
+		if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
+			return -1;
+
+		func_btf_id = libbpf_find_prog_btf_id(tmulti_bpf_funcs[i], prog_fd, token_fd);
+		if (!ASSERT_GT(func_btf_id, 0, "libbpf_find_prog_btf_id"))
+			return -1;
+
+		targets[i].cookie = cookies[i];
+		targets[i].id = prog_info.id;
+		targets[i].func_btf_id = func_btf_id;
+	}
+
+	qsort(targets, TRACING_MULTI_BPF_CNT, sizeof(targets[0]), tmulti_target_cmp);
+	return setup_tmulti_btf_obj_id(prog, btf_obj_id);
+}
+
 static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog,
 					  const struct tmulti_target *targets,
-					  __u32 btf_obj_id, bool has_cookies)
+					  __u32 btf_obj_id, __u32 count,
+					  bool has_cookies, bool tgt_progs)
 {
+#define TMULTI_CNT (TRACING_MULTI_CNT > TRACING_MULTI_BPF_CNT ? \
+		    TRACING_MULTI_CNT : TRACING_MULTI_BPF_CNT)
 	enum bpf_attach_type attach_type = bpf_program__expected_attach_type(prog);
-	__u64 addrs[TRACING_MULTI_CNT], cookies[TRACING_MULTI_CNT];
-	__u32 ids[TRACING_MULTI_CNT];
+	__u64 addrs[TMULTI_CNT], cookies[TMULTI_CNT];
+	__u32 ids[TMULTI_CNT], fids[TMULTI_CNT];
 	struct bpf_link_info info;
 	__u32 len = sizeof(info);
 	int err, i;
@@ -487,16 +545,21 @@ static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog
 		return -1;
 
 	ASSERT_EQ(info.tracing_multi.attach_type, attach_type, "info.tracing_multi.attach_type");
-	ASSERT_EQ(info.tracing_multi.count, TRACING_MULTI_CNT, "info.tracing_multi.count");
+	ASSERT_EQ(info.tracing_multi.count, count, "info.tracing_multi.count");
+	if (tgt_progs)
+		ASSERT_TRUE(info.tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS,
+			    "info.tracing_multi.flags");
 
 	memset(ids, 0, sizeof(ids));
+	memset(fids, 0, sizeof(fids));
 	memset(cookies, 0, sizeof(cookies));
 	memset(addrs, 0, sizeof(addrs));
 
 	info.tracing_multi.ids = ptr_to_u64(ids);
 	info.tracing_multi.addrs = ptr_to_u64(addrs);
 	info.tracing_multi.cookies = has_cookies ? ptr_to_u64(cookies) : 0;
-	info.tracing_multi.count = TRACING_MULTI_CNT;
+	info.tracing_multi.func_btf_ids = tgt_progs ? ptr_to_u64(fids) : 0;
+	info.tracing_multi.count = count;
 
 	err = bpf_link_get_info_by_fd(fd, &info, &len);
 	if (!ASSERT_OK(err, "bpf_link_get_info_by_fd"))
@@ -506,14 +569,20 @@ static int verify_tracing_multi_link_info(int fd, const struct bpf_program *prog
 		return -1;
 
 	ASSERT_EQ(info.tracing_multi.attach_type, attach_type, "info.tracing_multi.attach_type");
-	ASSERT_EQ(info.tracing_multi.count, TRACING_MULTI_CNT, "info.tracing_multi.count");
+	ASSERT_EQ(info.tracing_multi.count, count, "info.tracing_multi.count");
 	ASSERT_EQ(info.tracing_multi.btf_obj_id, btf_obj_id, "tracing_multi.btf_obj_id");
+	if (tgt_progs)
+		ASSERT_TRUE(info.tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS,
+			    "info.tracing_multi.flags");
 
-	for (i = 0; i < TRACING_MULTI_CNT; i++) {
+	for (i = 0; i < count; i++) {
 		ASSERT_EQ(ids[i], targets[i].id, "tracing_multi.ids");
 		ASSERT_EQ(cookies[i], has_cookies ? targets[i].cookie : 0, "tracing_multi.cookies");
 
-		if (targets[i].addr) {
+		if (tgt_progs) {
+			ASSERT_EQ(addrs[i], targets[i].addr, "tracing_multi.addrs");
+			ASSERT_EQ(fids[i], targets[i].func_btf_id, "tracing_multi.func_btf_ids");
+		} else if (targets[i].addr) {
 			struct ksym *ksym;
 
 			if (!ASSERT_NEQ(addrs[i], 0, "tracing_multi.addrs"))
@@ -624,13 +693,73 @@ static void test_tracing_multi_fill_link_info(struct test_fill_link_info *skel,
 		verify_tracing_multi_invalid_user_buffer(link_fd, targets);
 	} else {
 		err = verify_tracing_multi_link_info(link_fd, skel->progs.tmulti_run,
-						     targets, btf_obj_id, has_cookies);
+						     targets, btf_obj_id, TRACING_MULTI_CNT,
+						     has_cookies, false);
 		ASSERT_OK(err, "verify_tracing_multi_link_info");
 	}
 
 	bpf_link__destroy(link);
 }
 
+static void test_tracing_multi_bpf_fill_link_info_one(struct tracing_multi_bpf *skel,
+						      struct bpf_program *prog,
+						      __u64 *cookies,
+						      bool has_cookies)
+{
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	const struct bpf_program *target_progs[] = {
+		skel->progs.target_1,
+		skel->progs.target_2,
+	};
+	struct tmulti_target targets[TRACING_MULTI_BPF_CNT] = {};
+	int fds[TRACING_MULTI_BPF_CNT], token_fd, err, i;
+	struct bpf_link *link;
+	__u32 btf_obj_id;
+
+	token_fd = bpf_object__token_fd(skel->obj);
+	token_fd = token_fd < 0 ? 0 : token_fd;
+
+	if (setup_tmulti_bpf_prog_targets(prog, token_fd, cookies, target_progs, targets,
+					  &btf_obj_id))
+		return;
+
+	for (i = 0; i < TRACING_MULTI_BPF_CNT; i++)
+		fds[i] = bpf_program__fd(target_progs[i]);
+
+	opts.fds = fds;
+	opts.funcs = tmulti_bpf_funcs;
+	opts.cnt = ARRAY_SIZE(fds);
+	opts.cookies = has_cookies ? cookies : NULL;
+
+	link = bpf_program__attach_tracing_multi(prog, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "bpf_program__attach_tracing_multi"))
+		return;
+
+	err = verify_tracing_multi_link_info(bpf_link__fd(link), prog, targets, btf_obj_id,
+					     TRACING_MULTI_BPF_CNT, has_cookies, true);
+	ASSERT_OK(err, "verify_tracing_multi_link_info");
+
+	bpf_link__destroy(link);
+}
+
+static void test_tracing_multi_bpf_fill_link_info(bool has_cookies)
+{
+	struct tracing_multi_bpf *skel;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	test_tracing_multi_bpf_fill_link_info_one(skel, skel->progs.test_fentry,
+						  tmulti_bpf_fentry_cookies, has_cookies);
+	test_tracing_multi_bpf_fill_link_info_one(skel, skel->progs.test_fexit,
+						  tmulti_bpf_fexit_cookies, has_cookies);
+	test_tracing_multi_bpf_fill_link_info_one(skel, skel->progs.test_fsession,
+						  tmulti_bpf_fsession_cookies, has_cookies);
+
+	tracing_multi_bpf__destroy(skel);
+}
+
 #define SEC(name) __attribute__((section(name), used))
 
 static short uprobe_link_info_sema_1 SEC(".probes");
@@ -879,6 +1008,10 @@ void test_fill_link_info(void)
 		test_tracing_multi_fill_link_info(skel, false, false);
 		test_tracing_multi_fill_link_info(skel, true, false);
 	}
+	if (test__start_subtest("tracing_multi_bpf_link_info")) {
+		test_tracing_multi_bpf_fill_link_info(false);
+		test_tracing_multi_bpf_fill_link_info(true);
+	}
 	if (test__start_subtest("tracing_multi_invalid_ubuff"))
 		test_tracing_multi_fill_link_info(skel, true, true);
 
diff --git a/tools/testing/selftests/bpf/prog_tests/tailcalls.c b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
index 88d223110ecd5..3b122520711b0 100644
--- a/tools/testing/selftests/bpf/prog_tests/tailcalls.c
+++ b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
@@ -16,7 +16,9 @@
 #include "tailcall_sleepable.skel.h"
 #include "tailcall_callback.skel.h"
 #include "tailcall_bpf2bpf2.skel.h"
+#include "tailcall_bpf2bpf4.skel.h"
 #include "tailcall_bpf2bpf_fexit.skel.h"
+#include "tracing_multi_bpf.skel.h"
 
 /* test_tailcall_1 checks basic functionality by patching multiple locations
  * in a single program for a single tail call slot with nop->jmp, jmp->nop
@@ -2065,6 +2067,66 @@ static void test_tailcall_large_stack(void)
 	tailcall_large_stack__destroy(skel);
 }
 
+/*
+ * Verify that a tail call from a BPF subprog works when the subprog is
+ * traced by fentry.multi.
+ */
+static void test_tailcall_bpf2bpf_fentry_multi(void)
+{
+	static const char *funcs[] = { "subprog_tail_2" };
+	struct tracing_multi_bpf *skel_tracing = NULL;
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	struct tailcall_bpf2bpf4 *skel_tc;
+	struct bpf_link *link = NULL;
+	int fds[ARRAY_SIZE(funcs)];
+	char buff[128] = {};
+	int err, key;
+	LIBBPF_OPTS(bpf_test_run_opts, topts,
+		.data_in = buff,
+		.data_size_in = sizeof(buff),
+		.repeat = 1,
+	);
+
+	skel_tc = tailcall_bpf2bpf4__open_and_load();
+	if (!ASSERT_OK_PTR(skel_tc, "tailcall_bpf2bpf4__open_and_load"))
+		return;
+
+	skel_tracing = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel_tracing, "tracing_multi_bpf__open_and_load"))
+		goto out;
+
+	key = 0;
+	fds[0] = bpf_program__fd(skel_tc->progs.classifier_2);
+	err = bpf_map_update_elem(bpf_map__fd(skel_tc->maps.jmp_table), &key, &fds[0], BPF_ANY);
+	if (!ASSERT_OK(err, "bpf_map_update_elem"))
+		goto out;
+
+	key = 2;
+	err = bpf_map_update_elem(bpf_map__fd(skel_tc->maps.jmp_table), &key, &fds[0], BPF_ANY);
+	if (!ASSERT_OK(err, "bpf_map_update_elem_loop"))
+		goto out;
+
+	opts.fds = fds;
+	opts.funcs = funcs;
+	opts.cnt = ARRAY_SIZE(fds);
+	link = bpf_program__attach_tracing_multi(skel_tracing->progs.test_fentry, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "bpf_program__attach_tracing_multi"))
+		goto out;
+
+	err = bpf_prog_test_run_opts(bpf_program__fd(skel_tc->progs.entry), &topts);
+	if (!ASSERT_OK(err, "bpf_prog_test_run_opts"))
+		goto out;
+
+	ASSERT_EQ(topts.retval, sizeof(buff) * 3, "retval");
+	ASSERT_EQ(skel_tc->bss->count, 33, "count");
+	ASSERT_EQ(skel_tracing->bss->test_result_fentry, 33, "fentry.multi count");
+
+out:
+	bpf_link__destroy(link);
+	tracing_multi_bpf__destroy(skel_tracing);
+	tailcall_bpf2bpf4__destroy(skel_tc);
+}
+
 void test_tailcalls(void)
 {
 	if (test__start_subtest("tailcall_1"))
@@ -2138,4 +2200,6 @@ void test_tailcalls(void)
 		test_tailcall_bpf2bpf_fexit_links();
 	if (test__start_subtest("tailcall_large_stack"))
 		test_tailcall_large_stack();
+	if (test__start_subtest("tailcall_bpf2bpf_fentry_multi"))
+		test_tailcall_bpf2bpf_fentry_multi();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
index cc727011f3a2a..dfa24e229ff75 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
@@ -12,6 +12,7 @@
 #include "tracing_multi_verifier.skel.h"
 #include "tracing_multi_bench.skel.h"
 #include "tracing_multi_rollback.skel.h"
+#include "tracing_multi_bpf.skel.h"
 #include "trace_helpers.h"
 
 static __u64 bpf_fentry_test_cookies[] = {
@@ -1126,3 +1127,256 @@ void test_tracing_multi_test(void)
 	if (test__start_subtest("fentry_after_multi"))
 		test_fentry_after_multi();
 }
+
+static int run_bpf_target(struct bpf_program *prog, __u32 retval, const char *name)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, topts);
+	int err;
+
+	err = bpf_prog_test_run_opts(bpf_program__fd(prog), &topts);
+	if (!ASSERT_OK(err, name))
+		return err;
+
+	if (!ASSERT_EQ(topts.retval, retval, name))
+		return -EINVAL;
+
+	return 0;
+}
+
+static void test_link_api_bpf_prog(bool test_cookies)
+{
+	const char *funcs[] = { "target_1", "target_2" };
+	__u64 fentry_cookies[] = { 0xfeed01, 0xfeed02 };
+	__u64 fexit_cookies[] = { 0xfeed11, 0xfeed12 };
+	__u64 fsession_cookies[] = { 0xfeed21, 0xfeed22 };
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	struct tracing_multi_bpf *skel = NULL;
+	int fds[ARRAY_SIZE(funcs)];
+	struct bpf_link *link;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	fds[0] = bpf_program__fd(skel->progs.target_1);
+	fds[1] = bpf_program__fd(skel->progs.target_2);
+
+	skel->bss->test_cookies = test_cookies;
+
+	opts.fds = fds;
+	opts.funcs = funcs;
+	opts.cnt = ARRAY_SIZE(fds);
+
+	opts.cookies = test_cookies ? fentry_cookies : NULL;
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fentry, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "attach_fentry"))
+		goto cleanup;
+	skel->links.test_fentry = link;
+
+	opts.cookies = test_cookies ? fexit_cookies : NULL;
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fexit, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "attach_fexit"))
+		goto cleanup;
+	skel->links.test_fexit = link;
+
+	opts.cookies = test_cookies ? fsession_cookies : NULL;
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fsession, NULL, &opts);
+	if (!ASSERT_OK_PTR(link, "attach_fsession"))
+		goto cleanup;
+	skel->links.test_fsession = link;
+
+	skel->bss->fentry_cookie = fentry_cookies[0];
+	skel->bss->fexit_cookie = fexit_cookies[0];
+	skel->bss->fsession_cookie = fsession_cookies[0];
+	if (run_bpf_target(skel->progs.target_1, 1, "target_1"))
+		goto cleanup;
+
+	skel->bss->fentry_cookie = fentry_cookies[1];
+	skel->bss->fexit_cookie = fexit_cookies[1];
+	skel->bss->fsession_cookie = fsession_cookies[1];
+	if (run_bpf_target(skel->progs.target_2, 2, "target_2"))
+		goto cleanup;
+
+	ASSERT_EQ(skel->bss->target_1_result, 1, "target_1_result");
+	ASSERT_EQ(skel->bss->target_2_result, 1, "target_2_result");
+	ASSERT_EQ(skel->bss->test_result_fentry, ARRAY_SIZE(funcs), "test_result_fentry");
+	ASSERT_EQ(skel->bss->test_result_fexit, ARRAY_SIZE(funcs), "test_result_fexit");
+	ASSERT_EQ(skel->bss->test_result_fsession_entry, ARRAY_SIZE(funcs),
+		  "test_result_fsession_entry");
+	ASSERT_EQ(skel->bss->test_result_fsession_exit, ARRAY_SIZE(funcs),
+		  "test_result_fsession_exit");
+
+cleanup:
+	tracing_multi_bpf__destroy(skel);
+}
+
+static void test_attach_api_bpf_prog_fails(void)
+{
+	static const char * const kfuncs[] = {
+		"bpf_fentry_test1",
+	};
+	const char *bpf_funcs[] = { "target_1" };
+	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+	LIBBPF_OPTS(bpf_link_create_opts, lopts);
+	struct tracing_multi_bpf *skel = NULL;
+	int fd, target_id, token_fd;
+	int fds[2], dup_fd = -1;
+	struct bpf_link *link;
+	__u32 target_ids[2];
+	__u32 *ids = NULL;
+	long err;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	ids = get_ids(kfuncs, ARRAY_SIZE(kfuncs), NULL);
+	if (!ASSERT_OK_PTR(ids, "get_ids"))
+		goto cleanup;
+
+	fds[0] = bpf_program__fd(skel->progs.target_1);
+
+	/* fail#1 (libbpf) kernel ids and BPF prog fds */
+	LIBBPF_OPTS_RESET(opts,
+		.ids = ids,
+		.fds = fds,
+		.funcs = bpf_funcs,
+		.cnt = ARRAY_SIZE(bpf_funcs),
+	);
+
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fentry, NULL, &opts);
+	err = libbpf_get_error(link);
+	if (!ASSERT_EQ(err, -EINVAL, "libbpf_ids_fds")) {
+		if (!err)
+			bpf_link__destroy(link);
+		goto cleanup;
+	}
+
+	/* fail#2 (libbpf) kernel pattern and BPF prog fds */
+	LIBBPF_OPTS_RESET(opts,
+		.fds = fds,
+		.funcs = bpf_funcs,
+		.cnt = ARRAY_SIZE(bpf_funcs),
+	);
+
+	link = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+						"bpf_fentry_test*", &opts);
+	err = libbpf_get_error(link);
+	if (!ASSERT_EQ(err, -EINVAL, "libbpf_pattern_fds")) {
+		if (!err)
+			bpf_link__destroy(link);
+		goto cleanup;
+	}
+
+	/* fail#3 (kernel) kernel id with BPF prog fd */
+	lopts.tracing_multi.ids = ids;
+	lopts.tracing_multi.fds = fds;
+	lopts.tracing_multi.cnt = ARRAY_SIZE(bpf_funcs);
+	fd = bpf_link_create(bpf_program__fd(skel->progs.test_fentry), 0,
+			     BPF_TRACE_FENTRY_MULTI, &lopts);
+	ASSERT_EQ(fd, -EINVAL, "kernel_id_bpf_fd");
+	if (fd >= 0)
+		close(fd);
+
+	/* fail#4 (kernel) duplicate target through different fds */
+	token_fd = bpf_object__token_fd(skel->obj);
+	token_fd = token_fd < 0 ? 0 : token_fd;
+	target_id = libbpf_find_prog_btf_id("target_1", fds[0], token_fd);
+	if (!ASSERT_GT(target_id, 0, "target_1_btf_id"))
+		goto cleanup;
+
+	dup_fd = dup(fds[0]);
+	if (!ASSERT_GE(dup_fd, 0, "dup_target_fd"))
+		goto cleanup;
+
+	fds[1] = dup_fd;
+	target_ids[0] = target_id;
+	target_ids[1] = target_id;
+	lopts.tracing_multi.ids = target_ids;
+	lopts.tracing_multi.fds = fds;
+	lopts.tracing_multi.cnt = ARRAY_SIZE(fds);
+	fd = bpf_link_create(bpf_program__fd(skel->progs.test_fentry), 0,
+			     BPF_TRACE_FENTRY_MULTI, &lopts);
+	ASSERT_EQ(fd, -EINVAL, "duplicate_bpf_target");
+	if (fd >= 0)
+		close(fd);
+
+cleanup:
+	if (dup_fd >= 0)
+		close(dup_fd);
+	tracing_multi_bpf__destroy(skel);
+	free(ids);
+}
+
+static void test_rollback_bpf_prog(void)
+{
+	int token_fd, prog_fd, fd = -1, pre_fd = -1;
+	LIBBPF_OPTS(bpf_link_create_opts, lopts);
+	struct tracing_multi_bpf *skel = NULL;
+	__u32 target_ids[2], ids[2];
+	int target_fds[2], fds[2];
+	struct bpf_program *prog;
+	int first, second;
+
+	skel = tracing_multi_bpf__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "tracing_multi_bpf__open_and_load"))
+		return;
+
+	token_fd = bpf_object__token_fd(skel->obj);
+	token_fd = token_fd < 0 ? 0 : token_fd;
+	target_fds[0] = bpf_program__fd(skel->progs.target_1);
+	target_fds[1] = bpf_program__fd(skel->progs.target_2);
+	target_ids[0] = libbpf_find_prog_btf_id("target_1", target_fds[0], token_fd);
+	if (!ASSERT_GT(target_ids[0], 0, "target_1_btf_id"))
+		goto cleanup;
+	target_ids[1] = libbpf_find_prog_btf_id("target_2", target_fds[1], token_fd);
+	if (!ASSERT_GT(target_ids[1], 0, "target_2_btf_id"))
+		goto cleanup;
+
+	first = target_fds[0] < target_fds[1] ? 0 : 1;
+	second = 1 - first;
+	fds[0] = target_fds[first];
+	fds[1] = target_fds[second];
+	ids[0] = target_ids[first];
+	ids[1] = target_ids[second];
+
+	prog_fd = bpf_program__fd(skel->progs.test_fentry);
+	lopts.tracing_multi.ids = &ids[1];
+	lopts.tracing_multi.fds = &fds[1];
+	lopts.tracing_multi.cnt = 1;
+	pre_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &lopts);
+	if (!ASSERT_GE(pre_fd, 0, "pre_attach"))
+		goto cleanup;
+
+	lopts.tracing_multi.ids = ids;
+	lopts.tracing_multi.fds = fds;
+	lopts.tracing_multi.cnt = ARRAY_SIZE(ids);
+
+	fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &lopts);
+	if (!ASSERT_EQ(fd, -EBUSY, "bpf_link_create"))
+		goto cleanup;
+
+	prog = first == 0 ? skel->progs.target_1 : skel->progs.target_2;
+	if (run_bpf_target(prog, first + 1, "rollback_target"))
+		goto cleanup;
+	ASSERT_EQ(skel->bss->test_result_fentry, 0, "test_result_fentry");
+
+cleanup:
+	if (fd >= 0)
+		close(fd);
+	if (pre_fd >= 0)
+		close(pre_fd);
+	tracing_multi_bpf__destroy(skel);
+}
+
+void test_tracing_multi_prog_test(void)
+{
+	if (test__start_subtest("link_api"))
+		test_link_api_bpf_prog(false);
+	if (test__start_subtest("attach_api_fails"))
+		test_attach_api_bpf_prog_fails();
+	if (test__start_subtest("cookies"))
+		test_link_api_bpf_prog(true);
+	if (test__start_subtest("rollback"))
+		test_rollback_bpf_prog();
+}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c b/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c
new file mode 100644
index 0000000000000..0ea4513904cd7
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_attach_progs.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+SEC("syscall")
+int target(void *ctx)
+{
+	return 0;
+}
+
+SEC("fentry")
+int BPF_PROG(dummy_fentry)
+{
+	return 0;
+}
+
+SEC("fentry.multi")
+int BPF_PROG(dummy_fentry_multi)
+{
+	return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c b/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c
new file mode 100644
index 0000000000000..651b5d86203f3
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tracing_multi_bpf.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+bool test_cookies;
+__u64 fentry_cookie;
+__u64 fexit_cookie;
+__u64 fsession_cookie;
+__u64 test_result_fentry;
+__u64 test_result_fexit;
+__u64 test_result_fsession_entry;
+__u64 test_result_fsession_exit;
+__u64 target_1_result;
+__u64 target_2_result;
+
+SEC("syscall")
+int target_1(void *ctx)
+{
+	target_1_result++;
+	return 1;
+}
+
+SEC("syscall")
+int target_2(void *ctx)
+{
+	target_2_result++;
+	return 2;
+}
+
+SEC("fentry.multi")
+int BPF_PROG(test_fentry)
+{
+	if (!test_cookies || bpf_get_attach_cookie(ctx) == fentry_cookie)
+		test_result_fentry++;
+	return 0;
+}
+
+SEC("fexit.multi")
+int BPF_PROG(test_fexit)
+{
+	if (!test_cookies || bpf_get_attach_cookie(ctx) == fexit_cookie)
+		test_result_fexit++;
+	return 0;
+}
+
+SEC("fsession.multi")
+int BPF_PROG(test_fsession)
+{
+	if (test_cookies && bpf_get_attach_cookie(ctx) != fsession_cookie)
+		return 0;
+
+	if (bpf_session_is_return(ctx))
+		test_result_fsession_exit++;
+	else
+		test_result_fsession_entry++;
+
+	return 0;
+}

33/3 2026/10/12 17:59 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36045
							output: 37
							thoughts: 1178
						

Thoughts:
**KMSAN Evaluation for BPF Tracing Multi Patch**

Okay, so I need to decide if this patch warrants a dedicated KMSAN fuzzing session. Let's dig in. First, I need to understand what this patch actually *does*. It looks like it's adding support to attach tracing features (fentry.multi, fexit.multi, fsession.multi) to BPF programs, not just kernel functions. This is a significant change, so I need to be thorough.

First, I need to meticulously go through the file changes.

*   `arch/x86/net/bpf_jit_comp.c`: Looks like some refactoring and batching of `bpf_arch_text_poke` functions. Mostly internal, but I'll keep an eye on how these new batching functions are used.
*   `include/linux/bpf.h`: Adds and modifies structures related to multi-program attachment (like `bpf_trampoline::multi_attach`, `bpf_text_poke`, and `bpf_tracing_multi_link`). Definitely important. Introduces `bpf_arch_text_poke_batch` here too.
*   `include/uapi/linux/bpf.h`: Important changes to the user-space API (`bpf_attr`, `bpf_link_info`). Adds the `fds` field, and modifies the `tracing_multi` struct. Adds `BPF_F_TRACING_MULTI_TGT_PROGS`. These are potential areas for KMSAN concerns, especially around uninitialized fields passed to userspace. I'll need to scrutinize how these `fds` and flags are handled.
*   `kernel/bpf/core.c`: A weak definition for that batching function. Nothing immediately worrying here.
*   `kernel/bpf/trampoline.c`: Moves and adds code related to multi-prog attachment, including batching and comparison logic. This is definitely where things could get interesting, so I need to pay close attention.
*   `kernel/bpf/verifier.c`: Adjustments to target handling, good to know, but likely not a primary KMSAN target.
*   `kernel/trace/bpf_trace.c`: This is the most interesting part. `bpf_tracing_multi_link_fill_link_info` looks like where the user-space data is constructed and returned. In particular, that code snippet there using `put_user` and the `fids` pointer is a big red flag for potentially uninitialized memory. I need to trace this function's call path to ensure there are no uninitialized values leaking to user space. The `bpf_tracing_multi_attach` function, with its allocation of `fds`, `progs`, etc., also needs a close look.

Now, let's focus on the KMSAN angle. My primary concern is if any kernel structures are being sent to user space where fields or structure padding might not be fully initialized or zeroed. I need to focus on how information is populated into the `bpf_link_info` structure and how it is transmitted to user space via things like `copy_to_user`, `put_user`, or Netlink.

Specifically, that `bpf_tracing_multi_link_fill_link_info` function and its caller(s) are my main target. I need to understand exactly how the `bpf_link_info` struct is filled. I will track down where `bpf_tracing_multi_link_fill_link_info` is called to understand the context and how the data is passed to user space. I need to check the call path from `bpf_tracing_multi_link_fill_link_info` in `kernel/trace/bpf_trace.c` to understand where `bpf_link_get_info_by_fd` or `link_get_info` are involved. After this analysis, I will determine if the patch needs a dedicated KMSAN session.



34/3 2026/10/12 17:59 tool grepper
0m Args:
{
  "Expression": "bpf_tracing_multi_link_fill_link_info",
  "PathPrefixes": [
    "kernel/"
  ]
}

Results:
{
  "Output": "kernel/trace/bpf_trace.c=3697=static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)\n--\nkernel/trace/bpf_trace.c-3708-\nkernel/trace/bpf_trace.c:3709:static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,\nkernel/trace/bpf_trace.c-3710-\t\t\t\t\t\t struct bpf_link_info *info)\n--\nkernel/trace/bpf_trace.c=3821=static const struct bpf_link_ops bpf_tracing_multi_link_lops = {\n--\nkernel/trace/bpf_trace.c-3823-\t.dealloc_deferred = bpf_tracing_multi_link_dealloc,\nkernel/trace/bpf_trace.c:3824:\t.fill_link_info = bpf_tracing_multi_link_fill_link_info,\nkernel/trace/bpf_trace.c-3825-#ifdef CONFIG_PROC_FS\n"
}

35/3 2026/10/12 17:59 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38409
							output: 34
							thoughts: 37
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience, and written as if they are my own:

**Analyzing `bpf_link_info` in `kernel/bpf/syscall.c`**

Alright, I need to zero in on how `bpf_link_info` is being managed within the `kernel/bpf/syscall.c` file, specifically when `fill_link_info` is invoked. I want to understand the control flow, error handling, and data population. My immediate concern is with the structure, especially considering recent changes and potential issues related to memory access and race conditions. I need to make sure the data is being populated correctly, that any necessary locking is in place (or absent for good reason), and that the information presented is consistent. I'm also looking for any subtle performance bottlenecks that might be introduced by excessive copying or inefficient data structures within that particular function. I'm particularly interested in how it handles different link types and, of course, the implications for security and stability within the whole eBPF framework. This goes without saying, but it is super important.



36/3 2026/10/12 18:00 tool grepper
0m Args:
{
  "Expression": "fill_link_info",
  "PathPrefixes": [
    "kernel/bpf/syscall.c"
  ]
}

Results:
{
  "Output": "kernel/bpf/syscall.c=3637=static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link,\n--\nkernel/bpf/syscall.c-3656-\nkernel/bpf/syscall.c:3657:static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,\nkernel/bpf/syscall.c-3658-\t\t\t\t\t   struct bpf_link_info *info)\n--\nkernel/bpf/syscall.c=3671=static const struct bpf_link_ops bpf_tracing_link_lops = {\n--\nkernel/bpf/syscall.c-3674-\t.show_fdinfo = bpf_tracing_link_show_fdinfo,\nkernel/bpf/syscall.c:3675:\t.fill_link_info = bpf_tracing_link_fill_link_info,\nkernel/bpf/syscall.c-3676-};\n--\nkernel/bpf/syscall.c=3927=static int bpf_copy_to_user(char __user *ubuf, const char *buf, u32 ulen,\n--\nkernel/bpf/syscall.c-3945-\nkernel/bpf/syscall.c:3946:static int bpf_raw_tp_link_fill_link_info(const struct bpf_link *link,\nkernel/bpf/syscall.c-3947-\t\t\t\t\t  struct bpf_link_info *info)\n--\nkernel/bpf/syscall.c=3968=static const struct bpf_link_ops bpf_raw_tp_link_lops = {\n--\nkernel/bpf/syscall.c-3971-\t.show_fdinfo = bpf_raw_tp_link_show_fdinfo,\nkernel/bpf/syscall.c:3972:\t.fill_link_info = bpf_raw_tp_link_fill_link_info,\nkernel/bpf/syscall.c-3973-};\n--\nkernel/bpf/syscall.c=4181=static int bpf_perf_link_fill_perf_event(const struct perf_event *event,\n--\nkernel/bpf/syscall.c-4190-\nkernel/bpf/syscall.c:4191:static int bpf_perf_link_fill_link_info(const struct bpf_link *link,\nkernel/bpf/syscall.c-4192-\t\t\t\t\tstruct bpf_link_info *info)\n--\nkernel/bpf/syscall.c=4282=static const struct bpf_link_ops bpf_perf_link_lops = {\n--\nkernel/bpf/syscall.c-4284-\t.dealloc = bpf_perf_link_dealloc,\nkernel/bpf/syscall.c:4285:\t.fill_link_info = bpf_perf_link_fill_link_info,\nkernel/bpf/syscall.c-4286-\t.show_fdinfo = bpf_perf_link_show_fdinfo,\n--\nkernel/bpf/syscall.c=5521=static int bpf_link_get_info_by_fd(struct file *file,\n--\nkernel/bpf/syscall.c-5549-\nkernel/bpf/syscall.c:5550:\tif (link-\u003eops-\u003efill_link_info) {\nkernel/bpf/syscall.c:5551:\t\terr = link-\u003eops-\u003efill_link_info(link, \u0026info);\nkernel/bpf/syscall.c-5552-\t\tif (err)\n"
}

37/3 2026/10/12 18:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39634
							output: 37
							thoughts: 29
						

Thoughts:
Okay, let's dive into this. Here's my take on understanding this code:

**Analyzing `bpf_link_get_info_by_fd` in `kernel/bpf/syscall.c`**

Alright, time to crack open `bpf_link_get_info_by_fd` within `kernel/bpf/syscall.c`. This is where the magic happens when someone wants to get information about a BPF link using its file descriptor. I need to understand how the kernel handles this request. My immediate focus will be on the data structures it uses, the locking mechanisms employed to ensure thread safety, and any error handling that's baked in. I expect to see checks for valid file descriptors, and some sort of translation from the file descriptor to the underlying BPF link object. I'm going to look for how it handles various link types and the information it exposes based on those types. Let's see if it deals with reference counting correctly to prevent memory leaks and potentially exposes a lot of data, and what mechanisms are there to prevent denial of service. I want to see how this function retrieves and prepares the information, perhaps packing it into a user-accessible buffer. This will likely involve iterating through some data structure or using an accessor function specific to the link to provide the specific details being queried. I'll need to pay close attention to the potential for races and ensure that the retrieved information remains consistent, even under concurrent operations. Finally, I'll be looking for any hints about performance considerations and potential bottlenecks within the function itself, especially if it involves any costly operations.



38/3 2026/10/12 18:00 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 5520,
  "LineCount": 50
}

Results:
{
  "Contents": "5520:\t\n5521:\tstatic int bpf_link_get_info_by_fd(struct file *file,\n5522:\t\t\t\t\t  struct bpf_link *link,\n5523:\t\t\t\t\t  const union bpf_attr *attr,\n5524:\t\t\t\t\t  union bpf_attr __user *uattr)\n5525:\t{\n5526:\t\tstruct bpf_link_info __user *uinfo = u64_to_user_ptr(attr-\u003einfo.info);\n5527:\t\tstruct bpf_link_info info;\n5528:\t\tconst struct bpf_prog *prog;\n5529:\t\tu32 info_len = attr-\u003einfo.info_len;\n5530:\t\tint err;\n5531:\t\n5532:\t\terr = bpf_check_uarg_tail_zero(USER_BPFPTR(uinfo), sizeof(info), info_len);\n5533:\t\tif (err)\n5534:\t\t\treturn err;\n5535:\t\tinfo_len = min_t(u32, sizeof(info), info_len);\n5536:\t\n5537:\t\tmemset(\u0026info, 0, sizeof(info));\n5538:\t\tif (copy_from_user(\u0026info, uinfo, info_len))\n5539:\t\t\treturn -EFAULT;\n5540:\t\n5541:\t\tinfo.type = link-\u003etype;\n5542:\t\tinfo.id = link-\u003eid;\n5543:\t\n5544:\t\trcu_read_lock();\n5545:\t\tprog = READ_ONCE(link-\u003eprog);\n5546:\t\tif (prog)\n5547:\t\t\tinfo.prog_id = prog-\u003eaux-\u003eid;\n5548:\t\trcu_read_unlock();\n5549:\t\n5550:\t\tif (link-\u003eops-\u003efill_link_info) {\n5551:\t\t\terr = link-\u003eops-\u003efill_link_info(link, \u0026info);\n5552:\t\t\tif (err)\n5553:\t\t\t\treturn err;\n5554:\t\t}\n5555:\t\n5556:\t\tif (copy_to_user(uinfo, \u0026info, info_len) ||\n5557:\t\t    put_user(info_len, \u0026uattr-\u003einfo.info_len))\n5558:\t\t\treturn -EFAULT;\n5559:\t\n5560:\t\treturn 0;\n5561:\t}\n5562:\t\n5563:\tstatic int token_get_info_by_fd(struct file *file,\n5564:\t\t\t\t\tstruct bpf_token *token,\n5565:\t\t\t\t\tconst union bpf_attr *attr,\n5566:\t\t\t\t\tunion bpf_attr __user *uattr)\n5567:\t{\n5568:\t\tstruct bpf_token_info __user *uinfo = u64_to_user_ptr(attr-\u003einfo.info);\n5569:\t\tu32 info_len = attr-\u003einfo.info_len;\n"
}

39/3 2026/10/12 18:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40838
							output: 37
							thoughts: 1378
						

Thoughts:
**Analyzing BPF Link Info Retrieval for Tracing Multi Links**

Okay, so I'm diving into the kernel code for retrieving information about BPF tracing multi links, specifically the `bpf_link_get_info_by_fd` function. The first thing that jumps out is the structure initialization: `memset(&info, 0, sizeof(info))`. This zeros out the entire `info` structure, which is important because it sets all the fields to a known state before data is copied in from user space and also has implications with regards to padding and any uninitialized fields.

Then, there's `copy_from_user` to populate the `info` structure from user-provided data. Afterward, `link->ops->fill_link_info(link, &info)` is called, which is where the relevant information for the specific link type is populated. Finally, the filled `info` is copied back to user space.

Looking at `struct bpf_link_info`, it's clear the `tracing_multi` member is what we are interested in. Because of the `memset`, all of its fields are initially zeroed. However, there's a crucial initialization of `info->tracing_multi.flags` with `BPF_F_TRACING_MULTI_TGT_PROGS` based on whether there are programs attached.

Now, let's turn our attention to `bpf_tracing_multi_link_fill_link_info`. This function is responsible for populating the `tracing_multi` part of the `bpf_link_info` structure for multi-target tracing links. The code carefully handles user-space pointers for several arrays: `func_btf_ids`, `cookies`, `addrs`, and `ids`. An important check is in place to ensure a valid `ucount` value.

The code retrieves and populates several fields: `attach_type`, `count`, `btf_obj_id`, and `flags`. The loop then iterates through the link nodes. Inside the loop, it uses `bpf_trampoline_unpack_key` to get `prog_id` and `btf_id`. It determines the address and cookie for each node based on the presence of programs and cookies and then, crucially, updates user-space arrays through `put_user`.

Here's the problem: I see this line: `if (has_progs && put_user((u32) mnode->trampoline->key, fids + i))`. It looks like the kernel is writing the `mnode->trampoline->key` to `fids`, but how is `mnode->trampoline->key` computed and what does it represent? I need to understand what's packed into this key. Therefore, I need to check the implementations of `bpf_trampoline_compute_key` and `bpf_trampoline_unpack_key`. This is likely the crucial point where program/BTF IDs are actually encoded and retrieved from the key.



40/3 2026/10/12 18:00 tool grepper
0m Args:
{
  "Expression": "bpf_trampoline_(compute|unpack)_key",
  "PathPrefixes": [
    "kernel/bpf/"
  ]
}

Results:
{
  "Output": "kernel/bpf/syscall.c=3637=static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link,\n--\nkernel/bpf/syscall.c-3643-\nkernel/bpf/syscall.c:3644:\tbpf_trampoline_unpack_key(tr_link-\u003etrampoline-\u003ekey,\nkernel/bpf/syscall.c-3645-\t\t\t\t  \u0026target_obj_id, \u0026target_btf_id);\n--\nkernel/bpf/syscall.c=3657=static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,\n--\nkernel/bpf/syscall.c-3663-\tinfo-\u003etracing.cookie = tr_link-\u003elink.node.cookie;\nkernel/bpf/syscall.c:3664:\tbpf_trampoline_unpack_key(tr_link-\u003etrampoline-\u003ekey,\nkernel/bpf/syscall.c-3665-\t\t\t\t  \u0026info-\u003etracing.target_obj_id,\n--\nkernel/bpf/syscall.c=3678=static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n--\nkernel/bpf/syscall.c-3741-\nkernel/bpf/syscall.c:3742:\t\tkey = bpf_trampoline_compute_key(tgt_prog, NULL, btf_id);\nkernel/bpf/syscall.c-3743-\t}\n--\nkernel/bpf/syscall.c-3799-\t\tbtf_id = prog-\u003eaux-\u003eattach_btf_id;\nkernel/bpf/syscall.c:3800:\t\tkey = bpf_trampoline_compute_key(NULL, prog-\u003eaux-\u003eattach_btf, btf_id);\nkernel/bpf/syscall.c-3801-\t}\n--\nkernel/bpf/trampoline.c=1204=int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,\n--\nkernel/bpf/trampoline.c-1220-\nkernel/bpf/trampoline.c:1221:\tkey = bpf_trampoline_compute_key(NULL, prog-\u003eaux-\u003eattach_btf,\nkernel/bpf/trampoline.c-1222-\t\t\t\t\t prog-\u003eaux-\u003eattach_btf_id);\n--\nkernel/bpf/trampoline.c=1269=void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog)\n--\nkernel/bpf/trampoline.c-1275-\nkernel/bpf/trampoline.c:1276:\tkey = bpf_trampoline_compute_key(NULL, prog-\u003eaux-\u003eattach_btf,\nkernel/bpf/trampoline.c-1277-\t\t\t\t\t prog-\u003eaux-\u003eattach_btf_id);\n--\nkernel/bpf/trampoline.c=1734=int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,\n--\nkernel/bpf/trampoline.c-1751-\nkernel/bpf/trampoline.c:1752:\t\tkey = bpf_trampoline_compute_key(NULL, btf, ids[i]);\nkernel/bpf/trampoline.c-1753-\n--\nkernel/bpf/verifier.c=22430=static int check_attach_btf_id(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-22517-\nkernel/bpf/verifier.c:22518:\tkey = bpf_trampoline_compute_key(tgt_prog, prog-\u003eaux-\u003eattach_btf, btf_id);\nkernel/bpf/verifier.c-22519-\ttr = bpf_trampoline_get(key, \u0026tgt_info);\n"
}

41/3 2026/10/12 18:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43877
							output: 32
							thoughts: 28
						

Thoughts:
Okay, here's my take on those functions, thinking through it as you asked:

**Diving into the BPF Trampoline Key Generation**

Alright, let's break down the mechanics of `bpf_trampoline_compute_key` and `bpf_trampoline_unpack_key`. My initial thought is to understand how these functions fit into the larger BPF trampoline puzzle. Clearly, we're dealing with key manipulation, which is crucial for efficient lookup and retrieval of data associated with these trampolines. Knowing this, my focus will be on the specifics of how the key is constructed and deconstructed, which is fundamental to the underlying system.

`bpf_trampoline_compute_key` has to do the heavy lifting: I need to understand what it's taking as input, what kind of key it generates, and, crucially, the rationale behind the key's format. Is it a composite key incorporating multiple fields, and if so, what are those fields? Is there an inherent ordering? The goal here would be to figure out if it's optimized for certain types of lookups or data patterns. Does it factor in information about the trampoline itself, or is it solely dependent on the context being passed? Understanding the "why" behind the key's construction will provide insight into the data model.

Then, there's `bpf_trampoline_unpack_key`. This is essentially the inverse function. It's the decoder ring! The interesting questions here relate to how robust the unpacking is. Is there any error checking? Does it have any implications for security? What would happen if the key is corrupted? Is there any redundancy or checksumming built in? Is the key format designed to be backwards compatible? Again, it must extract meaningful information, so I need to see what information is being extracted from the key.

My ultimate goal is to understand the complete cycle of the key. How is it generated, and how is it used, and how is it unpacked? This will give me an understanding of the efficiency and potential design constraints of the BPF trampoline mechanism.



42/3 2026/10/12 18:00 tool grepper
0m Args:
{
  "Expression": "bpf_trampoline_compute_key",
  "PathPrefixes": [
    "include/"
  ]
}

Results:
{
  "Output": "include/linux/bpf_verifier.h=1346=bpf_prog_offload_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt);\n--\ninclude/linux/bpf_verifier.h-1348-/* this lives here instead of in bpf.h because it needs to dereference tgt_prog */\ninclude/linux/bpf_verifier.h:1349:static inline u64 bpf_trampoline_compute_key(const struct bpf_prog *tgt_prog,\ninclude/linux/bpf_verifier.h-1350-\t\t\t\t\t     struct btf *btf, u32 btf_id)\n"
}

43/3 2026/10/12 18:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44551
							output: 39
							thoughts: 24
						

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

**Dissecting the BPF Verifier Header File**

Alright, I need to get my head around this BPF verification process. I'm going to jump straight into `include/linux/bpf_verifier.h` – specifically, around line 1349. I know this file intimately, but I want to refresh my understanding of *that* section, as it's been a bit fuzzy lately. I'm hoping to clarify something regarding [insert specific issue the user would be interested in regarding the BPF verifier or the surrounding code]. I suspect something related to [insert suspected area of code] might be key to what I'm looking for. Let's see if this jump into this section helps. I'm expecting to find the key pieces of logic that drive [specific aspect of BPF verification]. Time to get to it.



44/3 2026/10/12 18:00 tool read-file
0m Args:
{
  "File": "include/linux/bpf_verifier.h",
  "FirstLine": 1348,
  "LineCount": 40
}

Results:
{
  "Contents": "1348:\t/* this lives here instead of in bpf.h because it needs to dereference tgt_prog */\n1349:\tstatic inline u64 bpf_trampoline_compute_key(const struct bpf_prog *tgt_prog,\n1350:\t\t\t\t\t\t     struct btf *btf, u32 btf_id)\n1351:\t{\n1352:\t\tif (tgt_prog)\n1353:\t\t\treturn ((u64)tgt_prog-\u003eaux-\u003eid \u003c\u003c 32) | btf_id;\n1354:\t\telse\n1355:\t\t\treturn ((u64)btf_obj_id(btf) \u003c\u003c 32) | 0x80000000 | btf_id;\n1356:\t}\n1357:\t\n1358:\t/* unpack the IDs from the key as constructed above */\n1359:\tstatic inline void bpf_trampoline_unpack_key(u64 key, u32 *obj_id, u32 *btf_id)\n1360:\t{\n1361:\t\tif (obj_id)\n1362:\t\t\t*obj_id = key \u003e\u003e 32;\n1363:\t\tif (btf_id)\n1364:\t\t\t*btf_id = key \u0026 0x7FFFFFFF;\n1365:\t}\n1366:\t\n1367:\tint bpf_prepare_btf_info(struct bpf_verifier_env *env,\n1368:\t\t\t\t const union bpf_attr *attr, bpfptr_t uattr);\n1369:\tint bpf_check_core_relo(struct bpf_verifier_env *env,\n1370:\t\t\t\tconst union bpf_attr *attr, bpfptr_t uattr);\n1371:\tint bpf_check_btf_info(struct bpf_verifier_env *env,\n1372:\t\t\t       const union bpf_attr *attr, bpfptr_t uattr);\n1373:\t\n1374:\tint bpf_check_attach_target(struct bpf_verifier_log *log,\n1375:\t\t\t\t    const struct bpf_prog *prog,\n1376:\t\t\t\t    const struct bpf_prog *tgt_prog,\n1377:\t\t\t\t    u32 btf_id,\n1378:\t\t\t\t    struct bpf_attach_target_info *tgt_info);\n1379:\tvoid bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab);\n1380:\t\n1381:\tint mark_chain_precision(struct bpf_verifier_env *env, int regno);\n1382:\t\n1383:\tint bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx);\n1384:\tint bpf_split_cur_state(struct bpf_verifier_env *env);\n1385:\tint bpf_update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st);\n1386:\t\n1387:\tvoid bpf_clear_jmp_history(struct bpf_verifier_state *state);\n"
}

45/3 2026/10/12 18:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 45654
							output: 39
							thoughts: 166
						

Thoughts:
**Deconstructing the Key and Understanding BPF Multi-Linkage**

Okay, so I'm looking at this `key` value, and it's built as an integer. I'm seeing it's a combination of a program ID (`tgt_prog->aux->id`) shifted left 32 bits, and then OR'd with a BTF ID (`btf_id`). So, when `bpf_trampoline_unpack_key` comes into play, it correctly separates them; `prog_id` is the upper 32 bits, and `btf_id` is the lower 31 bits, since we're masking with `0x7FFFFFFF`.  And yes, confirmed, casting `mnode->trampoline->key` to `u32` just gives us that lower 32 bits, which is the `btf_id`.  Both of these are ultimately simple scalar integers.

Now, I need to understand how `bpf_tracing_multi_link` is allocated and initialized. The structure and initialization logic is important here. Time to dive into the code. Let's start with `bpf_tracing_multi_attach` in `kernel/trace/bpf_trace.c`.



46/3 2026/10/12 18:00 tool grepper
0m Args:
{
  "Expression": "bpf_tracing_multi_attach",
  "PathPrefixes": [
    "kernel/trace/bpf_trace.c"
  ]
}

Results:
{
  "Output": "kernel/trace/bpf_trace.c=3909=static int bpf_get_progs(struct bpf_prog **progs, int *fds, int cnt)\n--\nkernel/trace/bpf_trace.c-3935-\nkernel/trace/bpf_trace.c:3936:int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\nkernel/trace/bpf_trace.c-3937-{\n"
}

47/3 2026/10/12 18:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46260
							output: 40
							thoughts: 35
						

Thoughts:
Okay, let's dive into this. Here's my take on those lines of code...

**Dissecting `bpf_tracing_multi_attach`**

Alright, time to get my hands dirty. I'm focusing on `bpf_tracing_multi_attach`, specifically around line 3936 in `kernel/trace/bpf_trace.c`. I need to understand how multiple eBPF programs are attached to a single tracepoint or kprobe. This function is the heart of that mechanism. I'm probably looking for how the system handles the complexities of multiple programs vying for the same trace information. I suspect this will involve some form of program enumeration and possibly a chain of execution, though I am curious about the specifics. I'm also anticipating some careful handling of resource allocation and deallocation to ensure stability when multiple programs are active. I'll be looking for any potential race conditions and performance bottlenecks related to multiple program execution in a single context. Let's see how they've addressed that.



48/3 2026/10/12 18:00 tool read-file
0m Args:
{
  "File": "kernel/trace/bpf_trace.c",
  "FirstLine": 3936,
  "LineCount": 100
}

Results:
{
  "Contents": "3936:\tint bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n3937:\t{\n3938:\t\tstruct bpf_tracing_multi_link *link = NULL;\n3939:\t\tstruct btf *btf = prog-\u003eaux-\u003eattach_btf;\n3940:\t\tstruct bpf_tramp_node *fexits = NULL;\n3941:\t\tstruct bpf_link_primer link_primer;\n3942:\t\tstruct bpf_text_poke **pokes = NULL;\n3943:\t\tu64 *cookies = NULL, *keys = NULL;\n3944:\t\tstruct bpf_prog **progs = NULL;\n3945:\t\tu32 cnt, *ids = NULL;\n3946:\t\tu64 __user *ucookies;\n3947:\t\tu32 __user *uids;\n3948:\t\tint __user *ufds;\n3949:\t\tint *fds = NULL;\n3950:\t\tint err;\n3951:\t\n3952:\t\tufds = u64_to_user_ptr(attr-\u003elink_create.tracing_multi.fds);\n3953:\t\tuids = u64_to_user_ptr(attr-\u003elink_create.tracing_multi.ids);\n3954:\t\tcnt = attr-\u003elink_create.tracing_multi.cnt;\n3955:\t\n3956:\t\tif (!cnt || !uids)\n3957:\t\t\treturn -EINVAL;\n3958:\t\tif (cnt \u003e MAX_TRACING_MULTI_CNT)\n3959:\t\t\treturn -E2BIG;\n3960:\t\tif (attr-\u003elink_create.flags || attr-\u003elink_create.target_fd)\n3961:\t\t\treturn -EINVAL;\n3962:\t\n3963:\t\tif (!ufds \u0026\u0026 !IS_ENABLED(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS))\n3964:\t\t\treturn -EOPNOTSUPP;\n3965:\t\n3966:\t\tids = kvmalloc_objs(*ids, cnt);\n3967:\t\tif (!ids)\n3968:\t\t\treturn -ENOMEM;\n3969:\t\n3970:\t\tif (copy_from_user(ids, uids, cnt * sizeof(*ids))) {\n3971:\t\t\terr = -EFAULT;\n3972:\t\t\tgoto error;\n3973:\t\t}\n3974:\t\n3975:\t\tif (ufds) {\n3976:\t\t\tfds = kvmalloc_objs(*fds, cnt);\n3977:\t\t\tif (!fds) {\n3978:\t\t\t\terr = -ENOMEM;\n3979:\t\t\t\tgoto error;\n3980:\t\t\t}\n3981:\t\n3982:\t\t\tif (copy_from_user(fds, ufds, cnt * sizeof(*fds))) {\n3983:\t\t\t\terr = -EFAULT;\n3984:\t\t\t\tgoto error;\n3985:\t\t\t}\n3986:\t\n3987:\t\t\tprogs = kvmalloc_objs(*progs, cnt);\n3988:\t\t\tif (!progs) {\n3989:\t\t\t\terr = -ENOMEM;\n3990:\t\t\t\tgoto error;\n3991:\t\t\t}\n3992:\t\n3993:\t\t\terr = bpf_get_progs(progs, fds, cnt);\n3994:\t\t\tif (err) {\n3995:\t\t\t\tcnt = 0;\n3996:\t\t\t\tgoto error;\n3997:\t\t\t}\n3998:\t\n3999:\t\t\tpokes = kvmalloc_objs(*pokes, cnt);\n4000:\t\t\tif (!pokes) {\n4001:\t\t\t\terr = -ENOMEM;\n4002:\t\t\t\tgoto error;\n4003:\t\t\t}\n4004:\t\t}\n4005:\t\n4006:\t\tucookies = u64_to_user_ptr(attr-\u003elink_create.tracing_multi.cookies);\n4007:\t\tif (ucookies) {\n4008:\t\t\tcookies = kvmalloc_objs(*cookies, cnt);\n4009:\t\t\tif (!cookies) {\n4010:\t\t\t\terr = -ENOMEM;\n4011:\t\t\t\tgoto error;\n4012:\t\t\t}\n4013:\t\t\tif (copy_from_user(cookies, ucookies, cnt * sizeof(*cookies))) {\n4014:\t\t\t\terr = -EFAULT;\n4015:\t\t\t\tgoto error;\n4016:\t\t\t}\n4017:\t\t}\n4018:\t\n4019:\t\tkeys = kvmalloc_objs(*keys, cnt);\n4020:\t\tif (!keys) {\n4021:\t\t\terr = -ENOMEM;\n4022:\t\t\tgoto error;\n4023:\t\t}\n4024:\t\n4025:\t\tfor (int i = 0; i \u003c cnt; i++)\n4026:\t\t\tkeys[i] = bpf_trampoline_compute_key(progs ? progs[i] : NULL, btf, ids[i]);\n4027:\t\n4028:\t\terr = check_dup_keys(keys, progs, ids, cookies, cnt);\n4029:\t\tif (err)\n4030:\t\t\tgoto error;\n4031:\t\n4032:\t\tif (prog-\u003eexpected_attach_type == BPF_TRACE_FSESSION_MULTI) {\n4033:\t\t\tfexits = kvmalloc_objs(*fexits, cnt);\n4034:\t\t\tif (!fexits) {\n4035:\t\t\t\terr = -ENOMEM;\n"
}

49/3 2026/10/12 18:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48032
							output: 39
							thoughts: 29
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, as requested, geared toward an expert audience, and in the first person:

**Diving into `bpf_trace.c`**

Alright, let's keep going. We're at lines 4036 through 4090 within `kernel/trace/bpf_trace.c`. I need to figure out how this specific segment of the code is handling BPF tracepoints. My immediate goal is to understand the control flow here, particularly how events are being attached and detached. Given the function context, I'm expecting to encounter some details around how BPF programs are associated with tracepoints, possibly including reference counting, error handling, and perhaps some optimization strategies for managing program lifetimes.

I'll be looking specifically for any calls to functions like `bpf_attach_tracepoint`, `bpf_detach_tracepoint`, or similar variants. I'll need to see how the kernel deals with multiple BPF programs attached to the same tracepoint, and how the program state transitions are handled here, with any relevant locking mechanisms involved. I'll need to look closely at memory management within this region of the code as well. I'm expecting some interaction with structures like `tracepoint_probe`, `bpf_prog_aux`, or their equivalents. I'll pay attention to any error checking and recovery; any place where a BPF program might be rejected or unloaded. Essentially, I'm trying to map out this section's contribution to BPF program lifecycle management within the tracepoint framework.



50/3 2026/10/12 18:00 tool read-file
0m Args:
{
  "File": "kernel/trace/bpf_trace.c",
  "FirstLine": 4036,
  "LineCount": 60
}

Results:
{
  "Contents": "4036:\t\t\t\tgoto error;\n4037:\t\t\t}\n4038:\t\t}\n4039:\t\n4040:\t\tlink = kvzalloc_flex(*link, nodes, cnt);\n4041:\t\tif (!link) {\n4042:\t\t\terr = -ENOMEM;\n4043:\t\t\tgoto error;\n4044:\t\t}\n4045:\t\n4046:\t\tbpf_link_init(\u0026link-\u003elink, BPF_LINK_TYPE_TRACING_MULTI,\n4047:\t\t\t      \u0026bpf_tracing_multi_link_lops, prog, prog-\u003eexpected_attach_type);\n4048:\t\n4049:\t\terr = bpf_link_prime(\u0026link-\u003elink, \u0026link_primer);\n4050:\t\tif (err)\n4051:\t\t\tgoto error;\n4052:\t\n4053:\t\tlink-\u003enodes_cnt = cnt;\n4054:\t\tlink-\u003ecookies = cookies;\n4055:\t\tlink-\u003efexits = fexits;\n4056:\t\tlink-\u003etgt_progs = progs;\n4057:\t\tlink-\u003epokes = pokes;\n4058:\t\n4059:\t\tif (progs)\n4060:\t\t\terr = bpf_trampoline_multi_prog_attach(prog, ids, keys, link);\n4061:\t\telse\n4062:\t\t\terr = bpf_trampoline_multi_attach(prog, ids, link);\n4063:\t\tkvfree(ids);\n4064:\t\tkvfree(keys);\n4065:\t\tkvfree(fds);\n4066:\t\tif (err) {\n4067:\t\t\tbpf_put_progs(progs, cnt);\n4068:\t\t\tbpf_link_cleanup(\u0026link_primer);\n4069:\t\t\treturn err;\n4070:\t\t}\n4071:\t\treturn bpf_link_settle(\u0026link_primer);\n4072:\t\n4073:\terror:\n4074:\t\tbpf_put_progs(progs, cnt);\n4075:\t\tkvfree(fexits);\n4076:\t\tkvfree(cookies);\n4077:\t\tkvfree(ids);\n4078:\t\tkvfree(keys);\n4079:\t\tkvfree(fds);\n4080:\t\tkvfree(progs);\n4081:\t\tkvfree(pokes);\n4082:\t\tkvfree(link);\n4083:\t\treturn err;\n4084:\t}\n"
}

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

Args:
null

Results:
null

Tokens:
							input: 49108
							output: 40
							thoughts: 783
						

Thoughts:
**Analyzing Zero-Initialization and Potential Vulnerabilities in BPF Tracing**

Okay, let's break this down. That `kvzalloc_flex` call with `link = kvzalloc_flex(*link, nodes, cnt);` is really interesting. It means the entire `link` structure, including all the `nodes`, gets zero-allocated. This is a common pattern in the kernel, but it's important to keep in mind, and the context matters.

Looking at the `bpf_tracing_multi_link` struct:

```c
struct bpf_tracing_multi_link {
	struct bpf_link link;
	struct bpf_tracing_multi_data data;
	u64 *cookies;
	struct bpf_tramp_node *fexits;
	struct bpf_text_poke **pokes;
	struct bpf_prog **tgt_progs;
	int nodes_cnt;
	struct bpf_tracing_multi_node nodes[] __counted_by(nodes_cnt);
};
```

Everything in there, by default, will be initialized to zero. That's a good starting point, but let's dig deeper. The zero-initialization is something to keep in mind, I need to understand how the system relies on it.

Now, my mind goes to those text poking functions: `bpf_arch_text_poke_batch`, `__bpf_arch_text_poke`, and `bpf_arch_text_poke_prepare_insns`. Let's examine what's going on in `arch/x86/net/bpf_jit_comp.c`:

```c
static int bpf_arch_text_poke_prepare_insns(void *ip, enum bpf_text_poke_type old_t,
					    enum bpf_text_poke_type new_t,
					    void *old_addr, void *new_addr,
					    u8 *old_insn, u8 *new_insn)
{
	const u8 *nop_insn = x86_nops[5];
	u8 *prog;
	int ret;

	switch (old_t) {
	case BPF_MOD_NOP:
		memcpy(old_insn, nop_insn, X86_PATCH_SIZE);
		break;
	case BPF_MOD_CALL:
		prog = old_insn;
		ret = emit_call(&prog, old_addr, ip);
		if (ret)
			return ret;
		break;
	case BPF_MOD_JUMP:
		prog = old_insn;
		ret = emit_jump(&prog, old_addr, ip);
		if (ret)
			return ret;
		break;
	}

	switch (new_t) {
	case BPF_MOD_NOP:
		memcpy(new_insn, nop_insn, X86_PATCH_SIZE);
		break;
	case BPF_MOD_CALL:
		prog = new_insn;
		ret = emit_call(&prog, new_addr, ip);
		if (ret)
			return ret;
		break;
	case BPF_MOD_JUMP:
		prog = new_insn;
		ret = emit_jump(&prog, new_addr, ip);
		if (ret)
			return ret;
		break;
	}

	return 0;
}
```

Okay, the `bpf_arch_text_poke_prepare_insns` function uses a `switch` statement on `old_t` and `new_t`, which are enums representing modification types. My concern is: what happens if `old_t` or `new_t` has an *invalid* enum value?  If that's the case, we could have a security issue if we hit a case that's not explicitly handled. Let's trace back where those `old_t` and `new_t` values come from. Need to check what possible values these variables could hold. I'll need to review `emit_call` and `emit_jump` which I see are called here. Let's make sure these functions have proper validation.



52/3 2026/10/12 18:00 tool grepper
0m Args:
{
  "Expression": "emit_call",
  "PathPrefixes": [
    "arch/x86/net/bpf_jit_comp.c"
  ]
}

Results:
{
  "Output": "arch/x86/net/bpf_jit_comp.c=451=static void emit_nops(u8 **pprog, int len)\n--\narch/x86/net/bpf_jit_comp.c-473- */\narch/x86/net/bpf_jit_comp.c:474:static int emit_call(u8 **prog, void *func, void *ip);\narch/x86/net/bpf_jit_comp.c-475-\narch/x86/net/bpf_jit_comp.c=476=static void emit_fineibt(u8 **pprog, u8 *ip, u32 hash, int arity)\n--\narch/x86/net/bpf_jit_comp.c-483-\t\tEMIT2(0x2e, 0x2e);\t\t\t/* cs cs */\narch/x86/net/bpf_jit_comp.c:484:\t\temit_call(\u0026prog, __bhi_args[arity], ip + 11);\narch/x86/net/bpf_jit_comp.c-485-\t} else {\n--\narch/x86/net/bpf_jit_comp.c=617=static int emit_patch(u8 **pprog, void *func, void *ip, u8 opcode)\n--\narch/x86/net/bpf_jit_comp.c-631-\narch/x86/net/bpf_jit_comp.c:632:static int emit_call(u8 **pprog, void *func, void *ip)\narch/x86/net/bpf_jit_comp.c-633-{\n--\narch/x86/net/bpf_jit_comp.c=649=static int bpf_arch_text_poke_prepare_insns(void *ip, enum bpf_text_poke_type old_t,\n--\narch/x86/net/bpf_jit_comp.c-661-\t\tret = old_t == BPF_MOD_CALL ?\narch/x86/net/bpf_jit_comp.c:662:\t\t      emit_call(\u0026prog, old_addr, ip) :\narch/x86/net/bpf_jit_comp.c-663-\t\t      emit_jump(\u0026prog, old_addr, ip);\n--\narch/x86/net/bpf_jit_comp.c-671-\t\tret = new_t == BPF_MOD_CALL ?\narch/x86/net/bpf_jit_comp.c:672:\t\t      emit_call(\u0026prog, new_addr, ip) :\narch/x86/net/bpf_jit_comp.c-673-\t\t      emit_jump(\u0026prog, new_addr, ip);\n--\narch/x86/net/bpf_jit_comp.c=832=static int emit_indirect_call(u8 **pprog, int bpf_reg, u8 *ip)\n--\narch/x86/net/bpf_jit_comp.c-840-\t\tOPTIMIZER_HIDE_VAR(reg);\narch/x86/net/bpf_jit_comp.c:841:\t\terr = emit_call(\u0026prog, its_static_thunk(reg + 8*ereg), ip);\narch/x86/net/bpf_jit_comp.c-842-\t} else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {\n--\narch/x86/net/bpf_jit_comp.c-847-\t\tif (cpu_feature_enabled(X86_FEATURE_CALL_DEPTH))\narch/x86/net/bpf_jit_comp.c:848:\t\t\terr = emit_call(\u0026prog, \u0026__x86_indirect_call_thunk_array[reg + 8*ereg], ip);\narch/x86/net/bpf_jit_comp.c-849-\t\telse\narch/x86/net/bpf_jit_comp.c:850:\t\t\terr = emit_call(\u0026prog, \u0026__x86_indirect_thunk_array[reg + 8*ereg], ip);\narch/x86/net/bpf_jit_comp.c-851-\t} else {\n--\narch/x86/net/bpf_jit_comp.c=1248=static int emit_kasan_check(struct bpf_verifier_env *env, u8 **pprog,\n--\narch/x86/net/bpf_jit_comp.c-1316-\t/* call kasan_func */\narch/x86/net/bpf_jit_comp.c:1317:\tif (emit_call(\u0026prog, kasan_func, ip))\narch/x86/net/bpf_jit_comp.c-1318-\t\treturn -ERANGE;\n--\narch/x86/net/bpf_jit_comp.c=1923=static int emit_spectre_bhb_barrier(u8 **pprog, u8 *ip,\n--\narch/x86/net/bpf_jit_comp.c-1937-\narch/x86/net/bpf_jit_comp.c:1938:\t\tif (emit_call(\u0026prog, func, ip))\narch/x86/net/bpf_jit_comp.c-1939-\t\t\treturn -EINVAL;\n--\narch/x86/net/bpf_jit_comp.c=2069=static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\n--\narch/x86/net/bpf_jit_comp.c-3047-\t\t\tip += x86_call_depth_emit_accounting(\u0026prog, func, ip);\narch/x86/net/bpf_jit_comp.c:3048:\t\t\tif (emit_call(\u0026prog, func, ip))\narch/x86/net/bpf_jit_comp.c-3049-\t\t\t\treturn -EINVAL;\n"
}

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

Args:
null

Results:
null

Tokens:
							input: 52446
							output: 44
							thoughts: 57
						

Thoughts:
Okay, let's dive into the core of how this works.

**Deep Dive into `bpf_arch_text_poke_prepare_insns` Implementation**

Alright, I need to get a clear picture of how this `bpf_arch_text_poke_prepare_insns` function is implemented in the context of the x86 architecture. I'm going to consult the source code, specifically `arch/x86/net/bpf_jit_comp.c`, and I'll focus on lines 615 through 680. That chunk should give me a solid understanding of its operational details. I need to refresh my memory on the specifics of the JIT compilation process and the interaction with the x86 instruction set. By understanding this function, I hope to have a good feel for how the BPF code is being prepared for modification. I'm especially interested in how it handles instruction patching, and any special considerations for x86. I need to see how the code handles memory alignment, any pre-processing, and, importantly, what it means for the JIT engine. Once I've reviewed the code, I'll have a good grasp on the mechanics in this crucial function.



54/3 2026/10/12 18:00 tool read-file
0m Args:
{
  "File": "arch/x86/net/bpf_jit_comp.c",
  "FirstLine": 615,
  "LineCount": 65
}

Results:
{
  "Contents": " 615:\t}\n 616:\t\n 617:\tstatic int emit_patch(u8 **pprog, void *func, void *ip, u8 opcode)\n 618:\t{\n 619:\t\tu8 *prog = *pprog;\n 620:\t\ts64 offset;\n 621:\t\n 622:\t\toffset = func - (ip + X86_PATCH_SIZE);\n 623:\t\tif (!is_simm32(offset)) {\n 624:\t\t\tpr_err(\"Target call %p is out of range\\n\", func);\n 625:\t\t\treturn -ERANGE;\n 626:\t\t}\n 627:\t\tEMIT1_off32(opcode, offset);\n 628:\t\t*pprog = prog;\n 629:\t\treturn 0;\n 630:\t}\n 631:\t\n 632:\tstatic int emit_call(u8 **pprog, void *func, void *ip)\n 633:\t{\n 634:\t\treturn emit_patch(pprog, func, ip, 0xE8);\n 635:\t}\n 636:\t\n 637:\tstatic int emit_rsb_call(u8 **pprog, void *func, void *ip)\n 638:\t{\n 639:\t\tOPTIMIZER_HIDE_VAR(func);\n 640:\t\tip += x86_call_depth_emit_accounting(pprog, func, ip);\n 641:\t\treturn emit_patch(pprog, func, ip, 0xE8);\n 642:\t}\n 643:\t\n 644:\tstatic int emit_jump(u8 **pprog, void *func, void *ip)\n 645:\t{\n 646:\t\treturn emit_patch(pprog, func, ip, 0xE9);\n 647:\t}\n 648:\t\n 649:\tstatic int bpf_arch_text_poke_prepare_insns(void *ip, enum bpf_text_poke_type old_t,\n 650:\t\t\t\t\t\t    enum bpf_text_poke_type new_t,\n 651:\t\t\t\t\t\t    void *old_addr, void *new_addr,\n 652:\t\t\t\t\t\t    u8 *old_insn, u8 *new_insn)\n 653:\t{\n 654:\t\tconst u8 *nop_insn = x86_nops[5];\n 655:\t\tu8 *prog;\n 656:\t\tint ret;\n 657:\t\n 658:\t\tmemcpy(old_insn, nop_insn, X86_PATCH_SIZE);\n 659:\t\tif (old_t != BPF_MOD_NOP \u0026\u0026 old_addr) {\n 660:\t\t\tprog = old_insn;\n 661:\t\t\tret = old_t == BPF_MOD_CALL ?\n 662:\t\t\t      emit_call(\u0026prog, old_addr, ip) :\n 663:\t\t\t      emit_jump(\u0026prog, old_addr, ip);\n 664:\t\t\tif (ret)\n 665:\t\t\t\treturn ret;\n 666:\t\t}\n 667:\t\n 668:\t\tmemcpy(new_insn, nop_insn, X86_PATCH_SIZE);\n 669:\t\tif (new_t != BPF_MOD_NOP \u0026\u0026 new_addr) {\n 670:\t\t\tprog = new_insn;\n 671:\t\t\tret = new_t == BPF_MOD_CALL ?\n 672:\t\t\t      emit_call(\u0026prog, new_addr, ip) :\n 673:\t\t\t      emit_jump(\u0026prog, new_addr, ip);\n 674:\t\t\tif (ret)\n 675:\t\t\t\treturn ret;\n 676:\t\t}\n 677:\t\n 678:\t\treturn 0;\n 679:\t}\n"
}

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

Args:
null

Results:
null

Tokens:
							input: 53833
							output: 39
							thoughts: 788
						

Thoughts:
**Analyzing the BPF Text Poke Batch Implementation**

Okay, so I'm looking at this `memcpy` call here: `memcpy(old_insn, nop_insn, X86_PATCH_SIZE);` and its counterpart with `new_insn`. I can see that `old_insn` and `new_insn` are definitely fully initialized before they're used. They are being set up on the stack, which is good to know, and the code clearly ensures all bytes are populated.

Now, let's dive deeper into `bpf_arch_text_poke_batch` within `arch/x86/net/bpf_jit_comp.c`. I need to understand this process. I see those stack arrays, `old_insn` and `new_insn`, each of size `X86_PATCH_SIZE`, which I know is 5 bytes. In each loop iteration, the function `bpf_arch_text_poke_prepare_insns` is called with both of those arrays. It looks like `bpf_arch_text_poke_prepare_insns` is responsible for preparing the instructions, and it starts with a `memcpy` from `nop_insn`. I'm going to assume that `nop_insn` is initialized somewhere else, but I can see the code copies all `X86_PATCH_SIZE` bytes into those local buffers. Then, the function optionally overwrites some of the bytes with `EMIT1_off32`. So, I'm confident that all 5 bytes are fully initialized before `memcmp` or `smp_text_poke_batch_add` are called.

Next, I need to understand the larger context. Let me check `bpf_text_poke_batch` and `bpf_trampoline_multi_prog_attach` within `kernel/bpf/trampoline.c`. I'll go through the code around lines 1880-2100 in `kernel/bpf/trampoline.c` to understand where this fits into the picture.



56/3 2026/10/12 18:01 tool read-file
0m Args:
{
  "File": "kernel/bpf/trampoline.c",
  "FirstLine": 1880,
  "LineCount": 100
}

Results:
{
  "Contents": "1880:\t\n1881:\tstatic int bpf_text_poke_cmp(const void *a, const void *b)\n1882:\t{\n1883:\t\tconst struct bpf_text_poke *pa = *(struct bpf_text_poke * const *)a;\n1884:\t\tconst struct bpf_text_poke *pb = *(struct bpf_text_poke * const *)b;\n1885:\t\tunsigned long ipa = (unsigned long) pa-\u003eip;\n1886:\t\tunsigned long ipb = (unsigned long) pb-\u003eip;\n1887:\t\n1888:\t\treturn (ipa \u003e ipb) - (ipa \u003c ipb);\n1889:\t}\n1890:\t\n1891:\tstatic int bpf_text_poke_batch(struct bpf_text_poke **pokes, u32 cnt)\n1892:\t{\n1893:\t\tint i, err;\n1894:\t\n1895:\t\t/*\n1896:\t\t * Sort pokes for two purposes:\n1897:\t\t * 1. Check duplicated poke target IPs.\n1898:\t\t * 2. Sorted poke target IPs would be friendly for poking them on x86,\n1899:\t\t *    see arch/x86/kernel/alternative.c::smp_text_poke_batch_add().\n1900:\t\t */\n1901:\t\tsort_nonatomic(pokes, cnt, sizeof(*pokes), bpf_text_poke_cmp, NULL);\n1902:\t\n1903:\t\tfor (i = 1; i \u003c cnt; i++)\n1904:\t\t\tif (pokes[i - 1]-\u003eip == pokes[i]-\u003eip)\n1905:\t\t\t\treturn -EINVAL;\n1906:\t\n1907:\t\terr = bpf_arch_text_poke_batch(pokes, cnt);\n1908:\t\tif (err != -EOPNOTSUPP)\n1909:\t\t\treturn err;\n1910:\t\n1911:\t\tfor (i = 0; i \u003c cnt; i++) {\n1912:\t\t\tstruct bpf_text_poke *p = pokes[i];\n1913:\t\n1914:\t\t\terr = bpf_arch_text_poke(p-\u003eip, p-\u003eold_t, p-\u003enew_t, p-\u003eold_addr, p-\u003enew_addr);\n1915:\t\t\tif (err)\n1916:\t\t\t\tgoto rollback;\n1917:\t\t}\n1918:\t\n1919:\t\treturn 0;\n1920:\t\n1921:\trollback:\n1922:\t\tfor (i--; i \u003e= 0; i--) {\n1923:\t\t\tstruct bpf_text_poke *p = pokes[i];\n1924:\t\n1925:\t\t\tWARN_ON_ONCE(bpf_arch_text_poke(p-\u003eip, p-\u003enew_t, p-\u003eold_t, p-\u003enew_addr,\n1926:\t\t\t\t\t\t\tp-\u003eold_addr));\n1927:\t\t}\n1928:\t\treturn err;\n1929:\t}\n1930:\t\n1931:\tstatic enum bpf_text_poke_type bpf_trampoline_poke_type(const struct bpf_tramp_image *im, u32 flags)\n1932:\t{\n1933:\t\tif (!im)\n1934:\t\t\treturn BPF_MOD_NOP;\n1935:\t\n1936:\t\treturn bpf_trampoline_use_jmp(flags) ? BPF_MOD_JUMP : BPF_MOD_CALL;\n1937:\t}\n1938:\t\n1939:\tstatic void bpf_text_poke_init(struct bpf_text_poke *poke, struct bpf_trampoline *tr)\n1940:\t{\n1941:\t\tstruct bpf_tramp_image *old_image = tr-\u003emulti_attach.old_image;\n1942:\t\tstruct bpf_tramp_image *new_image = tr-\u003emulti_attach.new_image;\n1943:\t\n1944:\t\tpoke-\u003eip = tr-\u003efunc.addr;\n1945:\t\tpoke-\u003eold_addr = old_image ? old_image-\u003eimage : NULL;\n1946:\t\tpoke-\u003enew_addr = new_image ? new_image-\u003eimage : NULL;\n1947:\t\tpoke-\u003eold_t = bpf_trampoline_poke_type(old_image, tr-\u003emulti_attach.old_flags);\n1948:\t\tpoke-\u003enew_t = bpf_trampoline_poke_type(new_image, tr-\u003eflags);\n1949:\t}\n1950:\t\n1951:\tstatic int register_fentry_multi_prog(struct bpf_trampoline *tr,\n1952:\t\t\t\t\t      struct bpf_tramp_image *im,\n1953:\t\t\t\t\t      void *data __maybe_unused)\n1954:\t{\n1955:\t\ttr-\u003emulti_attach.new_image = im;\n1956:\t\treturn 0;\n1957:\t}\n1958:\t\n1959:\tstatic int unregister_fentry_multi_prog(struct bpf_trampoline *tr,\n1960:\t\t\t\t\t\tu32 orig_flags __maybe_unused,\n1961:\t\t\t\t\t\tvoid *data __maybe_unused)\n1962:\t{\n1963:\t\ttr-\u003emulti_attach.new_image = NULL;\n1964:\t\treturn 0;\n1965:\t}\n1966:\t\n1967:\tstatic int modify_fentry_multi_prog(struct bpf_trampoline *tr,\n1968:\t\t\t\t\t    u32 orig_flags __maybe_unused,\n1969:\t\t\t\t\t    struct bpf_tramp_image *im,\n1970:\t\t\t\t\t    bool lock_direct_mutex __maybe_unused,\n1971:\t\t\t\t\t    void *data __maybe_unused)\n1972:\t{\n1973:\t\ttr-\u003emulti_attach.new_image = im;\n1974:\t\treturn 0;\n1975:\t}\n1976:\t\n1977:\tstatic const struct bpf_trampoline_ops trampoline_multi_prog_ops = {\n1978:\t\t.register_fentry   = register_fentry_multi_prog,\n1979:\t\t.unregister_fentry = unregister_fentry_multi_prog,\n"
}

57/3 2026/10/12 18:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 56797
							output: 38
							thoughts: 32
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm already deep in kernel BPF work:

**Deep Dive into Trampoline Implementation**

Alright, time to dig deeper into this `kernel/bpf/trampoline.c` file. Specifically, I need to focus on lines 1980 through 2070. I know this section likely deals with a core aspect of the BPF trampoline mechanism, so I expect to find some critical low-level details there. I'm probably looking for how the trampoline is set up or executed, and how it interacts with the underlying system. Given the line range, I'm expecting to get into the nitty gritty, potentially the data structures, the precise sequence of operations, or maybe even some edge case handling. I'm mentally preparing to scrutinize the code for any potential vulnerabilities or optimizations that jump out at me.



58/3 2026/10/12 18:01 tool read-file
0m Args:
{
  "File": "kernel/bpf/trampoline.c",
  "FirstLine": 1980,
  "LineCount": 90
}

Results:
{
  "Contents": "1980:\t\t.modify_fentry     = modify_fentry_multi_prog,\n1981:\t};\n1982:\t\n1983:\tstatic void bpf_trampoline_multi_prog_commit(struct bpf_trampoline *tr)\n1984:\t{\n1985:\t\tstruct bpf_tramp_image *old_image = tr-\u003emulti_attach.old_image;\n1986:\t\n1987:\t\ttr-\u003ecur_image = tr-\u003emulti_attach.new_image;\n1988:\t\ttr-\u003emulti_attach.old_image = NULL;\n1989:\t\ttr-\u003emulti_attach.new_image = NULL;\n1990:\t\ttr-\u003emulti_attach.old_flags = 0;\n1991:\t\n1992:\t\tif (old_image)\n1993:\t\t\tbpf_tramp_image_put(old_image);\n1994:\t}\n1995:\t\n1996:\tstatic void bpf_trampoline_multi_prog_rollback(struct bpf_trampoline *tr)\n1997:\t{\n1998:\t\tif (tr-\u003emulti_attach.new_image)\n1999:\t\t\tbpf_tramp_image_put(tr-\u003emulti_attach.new_image);\n2000:\t\n2001:\t\ttr-\u003eflags = tr-\u003emulti_attach.old_flags;\n2002:\t\ttr-\u003emulti_attach.old_image = NULL;\n2003:\t\ttr-\u003emulti_attach.new_image = NULL;\n2004:\t\ttr-\u003emulti_attach.old_flags = 0;\n2005:\t}\n2006:\t\n2007:\t#define for_each_mnode_cnt(mnode, link, cnt) \\\n2008:\t\tfor (i = 0, mnode = \u0026link-\u003enodes[i]; i \u003c cnt; i++, mnode = \u0026link-\u003enodes[i])\n2009:\t\n2010:\t#define for_each_mnode(mnode, link) \\\n2011:\t\tfor_each_mnode_cnt(mnode, link, link-\u003enodes_cnt)\n2012:\t\n2013:\tstatic int bpf_trampoline_multi_prog_prepare(struct bpf_prog *prog, u32 *ids, u64 *keys,\n2014:\t\t\t\t\t\t     struct bpf_tracing_multi_link *link)\n2015:\t{\n2016:\t\tstruct bpf_attach_target_info tgt_info = {};\n2017:\t\tstruct bpf_tracing_multi_node *mnode;\n2018:\t\tstruct bpf_trampoline *tr;\n2019:\t\tint i, cnt, err;\n2020:\t\n2021:\t\tfor_each_mnode(mnode, link) {\n2022:\t\t\terr = bpf_check_attach_target(NULL, prog, link-\u003etgt_progs[i], ids[i], \u0026tgt_info);\n2023:\t\t\tif (err)\n2024:\t\t\t\tgoto put_trampolines;\n2025:\t\n2026:\t\t\ttr = bpf_trampoline_get(keys[i], \u0026tgt_info);\n2027:\t\t\tif (!tr) {\n2028:\t\t\t\terr = -ENOMEM;\n2029:\t\t\t\tgoto put_trampolines;\n2030:\t\t\t}\n2031:\t\n2032:\t\t\tmnode-\u003etrampoline = tr;\n2033:\t\t\tmnode-\u003enode.link = \u0026link-\u003elink;\n2034:\t\t\tmnode-\u003enode.cookie = link-\u003ecookies ? link-\u003ecookies[i] : 0;\n2035:\t\n2036:\t\t\tif (prog-\u003eexpected_attach_type == BPF_TRACE_FSESSION_MULTI) {\n2037:\t\t\t\tlink-\u003efexits[i].link = \u0026link-\u003elink;\n2038:\t\t\t\tlink-\u003efexits[i].cookie = link-\u003ecookies ? link-\u003ecookies[i] : 0;\n2039:\t\t\t}\n2040:\t\t}\n2041:\t\n2042:\t\treturn 0;\n2043:\t\n2044:\tput_trampolines:\n2045:\t\tcnt = i;\n2046:\t\tfor_each_mnode_cnt(mnode, link, cnt)\n2047:\t\t\tbpf_trampoline_put(mnode-\u003etrampoline);\n2048:\t\treturn err;\n2049:\t}\n2050:\t\n2051:\tint bpf_trampoline_multi_prog_attach(struct bpf_prog *prog, u32 *ids, u64 *keys,\n2052:\t\t\t\t\t     struct bpf_tracing_multi_link *link)\n2053:\t{\n2054:\t\tstruct bpf_tracing_multi_node *mnode;\n2055:\t\tint i, err, linked_cnt = 0;\n2056:\t\n2057:\t\terr = bpf_trampoline_multi_prog_prepare(prog, ids, keys, link);\n2058:\t\tif (err)\n2059:\t\t\treturn err;\n2060:\t\n2061:\t\ttrampoline_lock_all();\n2062:\t\n2063:\t\tfor_each_mnode(mnode, link) {\n2064:\t\t\tbpf_trampoline_multi_attach_init(mnode-\u003etrampoline);\n2065:\t\n2066:\t\t\tif (link-\u003etgt_progs[i]-\u003eaux-\u003etail_call_reachable)\n2067:\t\t\t\tmnode-\u003etrampoline-\u003eflags |= BPF_TRAMP_F_TAIL_CALL_CTX;\n2068:\t\n2069:\t\t\terr = __bpf_trampoline_link_prog(\u0026mnode-\u003enode, mnode-\u003etrampoline, NULL,\n"
}

59/3 2026/10/12 18:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58577
							output: 37
							thoughts: 216
						

Thoughts:
**Analyzing `bpf_trampoline_multi_prog_prepare` and `bpf_check_attach_target`**

Okay, let's dive into this `tgt_info` structure within `bpf_trampoline_multi_prog_prepare`. I see it's initialized with `{}` which means zero-initialized right off the bat: `struct bpf_attach_target_info tgt_info = {};` That's a good starting point. Now, looking at the loop, I see `bpf_check_attach_target` is called repeatedly: `err = bpf_check_attach_target(NULL, prog, link->tgt_progs[i], ids[i], &tgt_info);`. My immediate question is: does `bpf_check_attach_target` fully populate `tgt_info` each time, or is it smart enough to only update the relevant fields and potentially reuse previous values? That could have implications for how information is shared or, more importantly, *not* shared between iterations. I need to be sure about that.

Hang on... I'm noticing something crucial here: The `tgt_info` structure is declared *outside* the `for_each_mnode` loop. That means it's persistent across iterations: `struct bpf_attach_target_info tgt_info = {};`. Hmm, the question shifts: is `tgt_info` being cleared or reset *inside* the `bpf_check_attach_target` function? I suspect the function is designed to fill this structure, but I need to confirm if it completely overwrites its values or if it might leave some fields untouched.

Alright, time to crack open the implementation of `bpf_check_attach_target` and figure this out definitively!



60/3 2026/10/12 18:01 tool grepper
0m Args:
{
  "Expression": "bpf_check_attach_target",
  "PathPrefixes": [
    "kernel/bpf/verifier.c"
  ]
}

Results:
{
  "Output": "kernel/bpf/verifier.c=14541=static int process_kf_arg_ptr_to_rbtree_node(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-14552- * LSM hooks and iters (both sleepable and non-sleepable) are safe.\nkernel/bpf/verifier.c:14553: * Any sleepable progs are also safe since bpf_check_attach_target() enforce\nkernel/bpf/verifier.c-14554- * them can only be attached to some specific hook points.\n--\nkernel/bpf/verifier.c=21991=static bool attach_uses_trampoline_retval(enum bpf_attach_type type)\n--\nkernel/bpf/verifier.c-22004-\nkernel/bpf/verifier.c:22005:int bpf_check_attach_target(struct bpf_verifier_log *log,\nkernel/bpf/verifier.c-22006-\t\t\t    const struct bpf_prog *prog,\n--\nkernel/bpf/verifier.c=22430=static int check_attach_btf_id(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-22460-\nkernel/bpf/verifier.c:22461:\tret = bpf_check_attach_target(\u0026env-\u003elog, prog, tgt_prog, btf_id, \u0026tgt_info);\nkernel/bpf/verifier.c-22462-\tif (ret)\n"
}

61/3 2026/10/12 18:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 59611
							output: 38
							thoughts: 25
						

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

**Diving into `bpf_check_attach_target` for a Refresher**

Alright, time to refresh my memory on the intricacies of BPF program attachment. I need to revisit `bpf_check_attach_target` in `kernel/bpf/verifier.c`. Specifically, I want to understand the logic flow here. The function is critical for enforcing security and ensuring that BPF programs are attached to valid targets in a safe manner, it's the gatekeeper. I'll focus on how it handles different program types and potential attach points. Let's see what the latest version has to say, as the requirements around attaching have evolved. I'll look for potential vulnerabilities, interesting design choices, and of course, any improvements from the last time I dug into it. Should be interesting.



62/3 2026/10/12 18:01 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 22005,
  "LineCount": 40
}

Results:
{
  "Contents": "22005:\tint bpf_check_attach_target(struct bpf_verifier_log *log,\n22006:\t\t\t\t    const struct bpf_prog *prog,\n22007:\t\t\t\t    const struct bpf_prog *tgt_prog,\n22008:\t\t\t\t    u32 btf_id,\n22009:\t\t\t\t    struct bpf_attach_target_info *tgt_info)\n22010:\t{\n22011:\t\tbool prog_extension = prog-\u003etype == BPF_PROG_TYPE_EXT;\n22012:\t\tbool prog_tracing = prog-\u003etype == BPF_PROG_TYPE_TRACING;\n22013:\t\tchar trace_symbol[KSYM_SYMBOL_LEN];\n22014:\t\tconst char prefix[] = \"btf_trace_\";\n22015:\t\tstruct bpf_raw_event_map *btp;\n22016:\t\tint ret = 0, subprog = -1, i;\n22017:\t\tconst struct btf_type *t;\n22018:\t\tbool conservative = true;\n22019:\t\tconst char *tname, *fname;\n22020:\t\tstruct btf *btf;\n22021:\t\tlong addr = 0;\n22022:\t\tstruct module *mod = NULL;\n22023:\t\n22024:\t\tif (!btf_id) {\n22025:\t\t\tbpf_log(log, \"Tracing programs must provide btf_id\\n\");\n22026:\t\t\treturn -EINVAL;\n22027:\t\t}\n22028:\t\tbtf = tgt_prog ? tgt_prog-\u003eaux-\u003ebtf : prog-\u003eaux-\u003eattach_btf;\n22029:\t\tif (!btf) {\n22030:\t\t\tbpf_log(log,\n22031:\t\t\t\t\"Tracing program can only be attached to another program annotated with BTF\\n\");\n22032:\t\t\treturn -EINVAL;\n22033:\t\t}\n22034:\t\tt = btf_type_by_id(btf, btf_id);\n22035:\t\tif (!t) {\n22036:\t\t\tbpf_log(log, \"attach_btf_id %u is invalid\\n\", btf_id);\n22037:\t\t\treturn -EINVAL;\n22038:\t\t}\n22039:\t\ttname = btf_name_by_offset(btf, t-\u003ename_off);\n22040:\t\tif (!tname) {\n22041:\t\t\tbpf_log(log, \"attach_btf_id %u doesn't have a name\\n\", btf_id);\n22042:\t\t\treturn -EINVAL;\n22043:\t\t}\n22044:\t\tif (tgt_prog) {\n"
}

63/3 2026/10/12 18:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60615
							output: 38
							thoughts: 20
						

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

**Deconstructing bpf_check_attach_target**

Alright, let's zero in on the culmination of `bpf_check_attach_target`. I'm going to carefully consider the function's last operations to see where the rubber meets the road. I'll need to remember the different scenarios that might lead to a final result or decision. Is it returning a success or failure, and what are the reasons for each of those final conditions? Specifically, I am looking to assess the very last action performed and try to understand what the function's purpose is. By considering the end, I can clarify the overall mission of the function and how it fits into the broader picture of eBPF program attachment.



64/3 2026/10/12 18:01 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 22310,
  "LineCount": 40
}

Results:
{
  "Contents": "22310:\t\t\t\t\telse\n22311:\t\t\t\t\t\taddr = 0;\n22312:\t\t\t\t} else {\n22313:\t\t\t\t\taddr = kallsyms_lookup_name(tname);\n22314:\t\t\t\t}\n22315:\t\t\t\tif (!addr) {\n22316:\t\t\t\t\tmodule_put(mod);\n22317:\t\t\t\t\tbpf_log(log,\n22318:\t\t\t\t\t\t\"The address of function %s cannot be found\\n\",\n22319:\t\t\t\t\t\ttname);\n22320:\t\t\t\t\treturn -ENOENT;\n22321:\t\t\t\t}\n22322:\t\t\t}\n22323:\t\n22324:\t\t\tif (prog-\u003esleepable) {\n22325:\t\t\t\tret = btf_id_allow_sleepable(btf_id, addr, prog, btf);\n22326:\t\t\t\tif (ret) {\n22327:\t\t\t\t\tmodule_put(mod);\n22328:\t\t\t\t\tbpf_log(log, \"%s is not sleepable\\n\", tname);\n22329:\t\t\t\t\treturn ret;\n22330:\t\t\t\t}\n22331:\t\t\t} else if (prog-\u003eexpected_attach_type == BPF_MODIFY_RETURN) {\n22332:\t\t\t\tif (tgt_prog) {\n22333:\t\t\t\t\tmodule_put(mod);\n22334:\t\t\t\t\tbpf_log(log, \"can't modify return codes of BPF programs\\n\");\n22335:\t\t\t\t\treturn -EINVAL;\n22336:\t\t\t\t}\n22337:\t\t\t\tret = -EINVAL;\n22338:\t\t\t\tif (btf_kfunc_is_modify_return(btf, btf_id, prog) ||\n22339:\t\t\t\t    !check_attach_modify_return(addr, tname))\n22340:\t\t\t\t\tret = 0;\n22341:\t\t\t\tif (ret) {\n22342:\t\t\t\t\tmodule_put(mod);\n22343:\t\t\t\t\tbpf_log(log, \"%s() is not modifiable\\n\", tname);\n22344:\t\t\t\t\treturn ret;\n22345:\t\t\t\t}\n22346:\t\t\t}\n22347:\t\n22348:\t\t\tbreak;\n22349:\t\t}\n"
}

65/3 2026/10/12 18:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 61450
							output: 38
							thoughts: 32
						

Thoughts:
Okay, let's dive into this. Here's my take on those lines in `kernel/bpf/verifier.c`:

**Analyzing `tgt_info` within the BPF Verifier**

Alright, I need to get into the details of the BPF verifier and, specifically, what's going on around line 22350 in `kernel/bpf/verifier.c`. My initial thought is to figure out exactly what the code does with `tgt_info` at that point. I'm already anticipating I'll be looking for memory access patterns, data validation checks, or perhaps even control flow manipulations that use or alter the information held within `tgt_info`. Given the complexity of BPF verification, there's a strong likelihood I'll need to trace the usage of `tgt_info` both before and after that specific line to understand the full context. What kind of data is `tgt_info` holding? Is it a structure? An array? What are its fields? Answering these questions will be key to deciphering the verification logic in this area. It's time to fire up the debugger and dig in!



66/3 2026/10/12 18:01 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 22350,
  "LineCount": 40
}

Results:
{
  "Contents": "22350:\t\ttgt_info-\u003etgt_addr = addr;\n22351:\t\ttgt_info-\u003etgt_name = tname;\n22352:\t\ttgt_info-\u003etgt_type = t;\n22353:\t\ttgt_info-\u003etgt_mod = mod;\n22354:\t\treturn 0;\n22355:\t}\n22356:\t\n22357:\tBTF_SET_START(btf_id_deny)\n22358:\tBTF_ID_UNUSED\n22359:\t#ifdef CONFIG_SMP\n22360:\tBTF_ID(func, ___migrate_enable)\n22361:\tBTF_ID(func, migrate_disable)\n22362:\tBTF_ID(func, migrate_enable)\n22363:\t#endif\n22364:\t#if !defined CONFIG_PREEMPT_RCU \u0026\u0026 !defined CONFIG_TINY_RCU\n22365:\tBTF_ID(func, rcu_read_unlock_strict)\n22366:\t#endif\n22367:\t#if defined(CONFIG_DEBUG_PREEMPT) || defined(CONFIG_TRACE_PREEMPT_TOGGLE)\n22368:\tBTF_ID(func, preempt_count_add)\n22369:\tBTF_ID(func, preempt_count_sub)\n22370:\t#endif\n22371:\t#ifdef CONFIG_PREEMPT_RCU\n22372:\tBTF_ID(func, __rcu_read_lock)\n22373:\tBTF_ID(func, __rcu_read_unlock)\n22374:\t#endif\n22375:\tBTF_SET_END(btf_id_deny)\n22376:\t\n22377:\t/* fexit and fmod_ret can't be used to attach to __noreturn functions.\n22378:\t * Currently, we must manually list all __noreturn functions here. Once a more\n22379:\t * robust solution is implemented, this workaround can be removed.\n22380:\t */\n22381:\tBTF_SET_START(noreturn_deny)\n22382:\t#ifdef CONFIG_IA32_EMULATION\n22383:\tBTF_ID(func, __ia32_sys_exit)\n22384:\tBTF_ID(func, __ia32_sys_exit_group)\n22385:\t#endif\n22386:\t#ifdef CONFIG_KUNIT\n22387:\tBTF_ID(func, __kunit_abort)\n22388:\tBTF_ID(func, kunit_try_catch_throw)\n22389:\t#endif\n"
}

67/3 2026/10/12 18:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62496
							output: 35
							thoughts: 15
						

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

**Analyzing the Target Feature Model**

Okay, so I'm diving into this code, and the first thing I need to understand is what's going on with `tgt_info->fmodel`. I know `tgt_info` is likely a struct containing target-specific information, and `fmodel` probably represents the feature model for that target. My brain is immediately running through the possible data structures this could be. Is it a simple struct? A pointer to a more complex object? A handle to something managed elsewhere? Is it a lookup table, a tree structure, or something entirely more exotic? I need to know the specific type to continue. Does the code provide type information, or do I need to look it up in the definitions to understand its structure? What can it tell me about the target's capabilities and limitations? Does the `fmodel` encapsulate any hardware-specific details, or is it more of a high-level representation of supported features? Understanding this `fmodel` is critical to understanding the code's behavior for this specific target. I need to get a handle on this before I can proceed any further.



68/3 2026/10/12 18:02 tool grepper
0m Args:
{
  "Expression": "tgt_info-\u003efmodel",
  "PathPrefixes": [
    "kernel/bpf/verifier.c"
  ]
}

Results:
{
  "Output": "kernel/bpf/verifier.c=22005=int bpf_check_attach_target(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-22231-\t\t\treturn -EINVAL;\nkernel/bpf/verifier.c:22232:\t\tret = btf_distill_func_proto(log, btf, t, tname, \u0026tgt_info-\u003efmodel);\nkernel/bpf/verifier.c-22233-\t\tif (ret)\n--\nkernel/bpf/verifier.c-22274-\nkernel/bpf/verifier.c:22275:\t\tret = btf_distill_func_proto(log, btf, t, tname, \u0026tgt_info-\u003efmodel);\nkernel/bpf/verifier.c-22276-\t\tif (ret \u003c 0)\n--\nkernel/bpf/verifier.c-22278-\nkernel/bpf/verifier.c:22279:\t\tif (tgt_info-\u003efmodel.ret_size \u003e 8 \u0026\u0026\nkernel/bpf/verifier.c-22280-\t\t    attach_uses_trampoline_retval(prog-\u003eexpected_attach_type)) {\n--\nkernel/bpf/verifier.c=22530=int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 btf_id,\n--\nkernel/bpf/verifier.c-22559-\t\treturn -EINVAL;\nkernel/bpf/verifier.c:22560:\terr = btf_distill_func_proto(NULL, btf, t, tname, \u0026tgt_info-\u003efmodel);\nkernel/bpf/verifier.c-22561-\tif (err \u003c 0)\nkernel/bpf/verifier.c-22562-\t\treturn err;\nkernel/bpf/verifier.c:22563:\tif (tgt_info-\u003efmodel.ret_size \u003e 8 \u0026\u0026\nkernel/bpf/verifier.c-22564-\t    attach_uses_trampoline_retval(prog-\u003eexpected_attach_type))\n"
}

69/3 2026/10/12 18:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63353
							output: 32
							thoughts: 1064
						

Thoughts:
**Analyzing BPF Trampoline Multi-Program Attachment**

Okay, so I'm digging into this multi-program attachment code and trying to get a handle on how the target addresses are determined and passed around. I see `btf_distill_func_proto` populating `tgt_info->fmodel`, and then `bpf_trampoline_get` uses that information. I know `bpf_trampoline_get` does a simple copy of `tgt_info->fmodel` and sets the address `tr->func.addr` from `tgt_info->tgt_addr`, and also the `ftrace_managed` flag based on `tr->ip`.  That seems straightforward enough, but I have a nagging feeling.

Now, I'm thinking about `bpf_check_attach_target` in `verifier.c`.  I see this patch that's changed things. Before, if we had a multi-ID tracing program, the address `addr` would be set to 0. Now, if `tgt_prog` exists, which it does in the multi-prog case, the code assigns `addr` from `tgt_prog->bpf_func` or its sub-function, and `tgt_info->tgt_addr` gets set. That makes sense: we now correctly retrieve the target address.

But what really has me thinking is the use of `tgt_info` within `bpf_trampoline_multi_prog_prepare`.  I see it being used in a loop: `bpf_check_attach_target` is called in each iteration, and then `bpf_trampoline_get` is called using `tgt_info`. My concern is whether `tgt_info` is being properly handled in the loop. Is `bpf_check_attach_target` overwriting all the fields of `tgt_info` in each iteration, or could there be a problem with how it's being used? I need to check the definition of the `tgt_info` struct to ensure there's no unintended carry-over or unexpected behavior. This is crucial for multi-program scenarios, because multiple programs will likely interact and modify data that can be used by others.



70/3 2026/10/12 18:02 tool grepper
0m Args:
{
  "Expression": "struct bpf_attach_target_info",
  "PathPrefixes": [
    "include/"
  ]
}

Results:
{
  "Output": "include/linux/bpf.h=1471=struct bpf_trampoline {\n--\ninclude/linux/bpf.h-1506-\ninclude/linux/bpf.h:1507:struct bpf_attach_target_info {\ninclude/linux/bpf.h-1508-\tstruct btf_func_model fmodel;\n--\ninclude/linux/bpf.h=1611=struct bpf_trampoline *bpf_trampoline_get(u64 key,\ninclude/linux/bpf.h:1612:\t\t\t\t\t  struct bpf_attach_target_info *tgt_info);\ninclude/linux/bpf.h-1613-void bpf_trampoline_put(struct bpf_trampoline *tr);\n--\ninclude/linux/bpf.h=1716=static inline struct bpf_trampoline *bpf_trampoline_get(u64 key,\ninclude/linux/bpf.h:1717:\t\t\t\t\t\t\tstruct bpf_attach_target_info *tgt_info)\ninclude/linux/bpf.h-1718-{\n--\ninclude/linux/bpf_verifier.h=1374=int bpf_check_attach_target(struct bpf_verifier_log *log,\n--\ninclude/linux/bpf_verifier.h-1377-\t\t\t    u32 btf_id,\ninclude/linux/bpf_verifier.h:1378:\t\t\t    struct bpf_attach_target_info *tgt_info);\ninclude/linux/bpf_verifier.h-1379-void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab);\n--\ninclude/linux/bpf_verifier.h=1981=int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 btf_id,\ninclude/linux/bpf_verifier.h:1982:\t\t\t\t  struct bpf_attach_target_info *tgt_info);\ninclude/linux/bpf_verifier.h-1983-\n"
}

71/3 2026/10/12 18:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65457
							output: 37
							thoughts: 18
						

Thoughts:
Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:

**Inspecting the `struct bpf_attach_target_info`**

Right, let's get down to brass tacks. I need to understand this `struct bpf_attach_target_info` thoroughly. Time to roll up my sleeves and see what the developers have deemed important enough to include in this structure. I already have a pretty good mental model of how the BPF infrastructure operates, but a detailed inspection of this struct is crucial. I want to build a clear picture of exactly *how* targets are identified, how the kernel tracks relevant information about them, and what attributes are available for programs when they're attached. It's time to parse the documentation, look at the source if I need to, and see what the data structure is telling me. I'll mentally map the fields, understand their purpose, and what implications they have on attach behavior. No stone unturned. I need this core data structure etched in my brain to make this work.



72/3 2026/10/12 18:02 tool read-file
0m Args:
{
  "File": "include/linux/bpf.h",
  "FirstLine": 1506,
  "LineCount": 15
}

Results:
{
  "Contents": "1506:\t\n1507:\tstruct bpf_attach_target_info {\n1508:\t\tstruct btf_func_model fmodel;\n1509:\t\tlong tgt_addr;\n1510:\t\tstruct module *tgt_mod;\n1511:\t\tconst char *tgt_name;\n1512:\t\tconst struct btf_type *tgt_type;\n1513:\t};\n1514:\t\n1515:\t#define BPF_DISPATCHER_MAX 48 /* Fits in 2048B */\n1516:\t\n1517:\tstruct bpf_dispatcher_prog {\n1518:\t\tstruct bpf_prog *prog;\n1519:\t\trefcount_t users;\n1520:\t};\n"
}

73/3 2026/10/12 18:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65956
							output: 37
							thoughts: 274
						

Thoughts:
**My Analysis of the `bpf_link_create` Process**

Okay, so I'm tracking how `btf_func_model` gets populated. It looks like `btf_distill_func_proto` handles that, writing to `tgt_addr`, `tgt_name`, `tgt_type`, and `tgt_mod`. Excellent, and the `tgt_info = {};` initialization at the beginning ensures we avoid any uninitialized memory issues, which is always a good practice.

Now, let's look closely at that `union bpf_attr`, specifically the `tracing_multi` section. I see `ids`, `cookies`, `cnt`, a 32-bit padding field (nice to see the architect kept alignment in mind) and then `fds`.

The user's `attr` data, passed into the `bpf_link_create` syscall, is, as I suspected, copied, likely through `bpf_check_uarg_tail_zero` or a similar function within `sys_bpf`. I need to ensure the data is properly sanitized.

Hang on, before I dive into `kernel/bpf/syscall.c`, let's see how `bpf_tracing_multi_attach` uses this `attr` data. Ah, good, it seems `attr` is *already* copied from user space by `__sys_bpf` or `CHECK_ATTR`. That simplifies things, so now the most obvious place to find the link is in the `kernel/bpf/syscall.c` file where `link_create` is defined.



74/3 2026/10/12 18:02 tool grepper
0m Args:
{
  "Expression": "bpf_tracing_multi_attach",
  "PathPrefixes": [
    "kernel/bpf/syscall.c"
  ]
}

Results:
{
  "Output": "kernel/bpf/syscall.c=5838=static int link_create(union bpf_attr *attr, bpfptr_t uattr)\n--\nkernel/bpf/syscall.c-5888-\t\telse if (is_tracing_multi(prog-\u003eexpected_attach_type))\nkernel/bpf/syscall.c:5889:\t\t\tret = bpf_tracing_multi_attach(prog, attr);\nkernel/bpf/syscall.c-5890-\t\telse\n"
}

75/3 2026/10/12 18:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66742
							output: 37
							thoughts: 41
						

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

**Digging into eBPF Link Creation**

Alright, let's dive into the `link_create` function. I'm specifically interested in how the `attr` argument is validated, so I'm heading directly to `kernel/bpf/syscall.c` and zeroing in on lines 5880-5910. I know this is where the core logic for eBPF link creation will reside, and where I expect to find the checks on the supplied attributes. I want to understand exactly what kind of sanitization or validity tests are being performed on those `attr` values before the link itself is actually created. This'll give me a good handle on potential vulnerabilities or even just subtle behavioral differences in how these links are formed.



76/3 2026/10/12 18:02 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 5880,
  "LineCount": 35
}

Results:
{
  "Contents": "5880:\t\t\t}\n5881:\t\t\tif (prog-\u003eexpected_attach_type == BPF_TRACE_RAW_TP)\n5882:\t\t\t\tret = bpf_raw_tp_link_attach(prog, NULL, attr-\u003elink_create.tracing.cookie,\n5883:\t\t\t\t\t\t\t     attr-\u003elink_create.attach_type);\n5884:\t\t\telse if (prog-\u003eexpected_attach_type == BPF_TRACE_ITER)\n5885:\t\t\t\tret = bpf_iter_link_attach(attr, uattr, prog);\n5886:\t\t\telse if (prog-\u003eexpected_attach_type == BPF_LSM_CGROUP)\n5887:\t\t\t\tret = cgroup_bpf_link_attach(attr, prog);\n5888:\t\t\telse if (is_tracing_multi(prog-\u003eexpected_attach_type))\n5889:\t\t\t\tret = bpf_tracing_multi_attach(prog, attr);\n5890:\t\t\telse\n5891:\t\t\t\tret = bpf_tracing_prog_attach(prog,\n5892:\t\t\t\t\t\t\t      attr-\u003elink_create.target_fd,\n5893:\t\t\t\t\t\t\t      attr-\u003elink_create.target_btf_id,\n5894:\t\t\t\t\t\t\t      attr-\u003elink_create.tracing.cookie,\n5895:\t\t\t\t\t\t\t      attr-\u003elink_create.attach_type);\n5896:\t\t\tbreak;\n5897:\t\tcase BPF_PROG_TYPE_FLOW_DISSECTOR:\n5898:\t\tcase BPF_PROG_TYPE_SK_LOOKUP:\n5899:\t\t\tret = netns_bpf_link_create(attr, prog);\n5900:\t\t\tbreak;\n5901:\t\tcase BPF_PROG_TYPE_SK_MSG:\n5902:\t\tcase BPF_PROG_TYPE_SK_SKB:\n5903:\t\t\tret = sock_map_link_create(attr, prog);\n5904:\t\t\tbreak;\n5905:\t#ifdef CONFIG_NET\n5906:\t\tcase BPF_PROG_TYPE_XDP:\n5907:\t\t\tret = bpf_xdp_link_attach(attr, prog);\n5908:\t\t\tbreak;\n5909:\t\tcase BPF_PROG_TYPE_SCHED_CLS:\n5910:\t\t\tif (attr-\u003elink_create.attach_type == BPF_TCX_INGRESS ||\n5911:\t\t\t    attr-\u003elink_create.attach_type == BPF_TCX_EGRESS)\n5912:\t\t\t\tret = tcx_link_attach(attr, prog);\n5913:\t\t\telse\n5914:\t\t\t\tret = netkit_link_attach(attr, prog);\n"
}

77/3 2026/10/12 18:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 67685
							output: 29
							thoughts: 2638
						

Thoughts:
**Uncovering Potential Uninitialized Data in `bpf_tracing_multi_link_fill_link_info`**

Okay, so I'm digging into this `bpf_tracing_multi_link_fill_link_info` function and I'm a bit concerned about whether there's a possibility of uninitialized data leaking into userspace via the `bpf_link_info` structure and its associated arrays: `uids`, `uaddrs`, `ucookies`, and `fids`.  I've seen the `copy_from_bpfptr` with `CHECK_ATTR` and zeroing, which is good, in `__sys_bpf` and `sys_bpf`, but now need to verify this for this function.

First, I examine the data assignments.  The variables `prog_id` and `btf_id`, derived from `mnode->trampoline->key`, look safe because they are fully initialized local `u32` variables. `addr`, depending on `show_addrs` and `has_progs`, is assigned either zero,  `mnode->trampoline->func.addr`, or `mnode->trampoline->ip`. I trace it to `bpf_trampoline_get`, and its source, `tgt_info->tgt_addr`, ensuring that it is initialized.

Then, the critical path seems to be with `cookie`. If `has_cookies` is true, it uses `tr_link->cookies[i]`.  This triggers an immediate check to confirm the initialization of `tr_link->cookies`.  I trace `tr_link->cookies` back to `bpf_tracing_multi_attach` where `ucookies` (from user space) are copied into `cookies`. Then, it's sorted with `keys_swap_r`. I'm going through the `keys_swap_r` function with its swapping, focusing on the calculation of `cookie_a`, to ensure that the swapping process maintains the correct indices. The calculation `cookie_a = cookies + (id_a - ids);` looks a bit tricky, but with the checks `id_a = ids + (key_a - keys);`, it's clear that all offsets are consistent and swapping is done correctly.

Similarly, I confirm that the `(u32) mnode->trampoline->key` is initialized since it's a cast of a `u64`.  The `info->tracing_multi.flags` is initialized using a ternary operation.

Next, I check `struct bpf_link_info` for padding which could cause uninitialized data leakage. I review the layout of the `tracing_multi` section within `struct bpf_link_info` and confirm there is no padding between the members. Crucially, the entire `bpf_link_info` struct is zeroed out using `memset` in `bpf_link_get_info_by_fd` before any of these fields are populated, which is a key safety net.

Finally, I remember `pokes`. In `bpf_tracing_multi_attach`, `pokes = kvmalloc_objs(*pokes, cnt)` is performed, and now I need to check what is `kvmalloc_objs` and to ensure that `pokes` are properly initialized.



78/3 2026/10/12 18:02 tool grepper
0m Args:
{
  "Expression": "#define kvmalloc_objs",
  "PathPrefixes": [
    "include/"
  ]
}

Results:
{
  "Output": "include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);\n--\ninclude/linux/slab.h-1164-\t__alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), 1)\ninclude/linux/slab.h:1165:#define kvmalloc_objs(P, COUNT, ...) \\\ninclude/linux/slab.h-1166-\t__alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)\n"
}

79/3 2026/10/12 18:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 71226
							output: 32
							thoughts: 1340
						

Thoughts:
**Analyzing `pokes` Initialization and Usage in BPF Trampoline Multi-Program Attachment/Detachment**

Okay, so I'm digging into this `kvmalloc_objs` thing, and it's calling plain `kvmalloc`, which, as we know, doesn't zero-initialize memory.  My immediate concern is how `pokes` is handled, specifically within the `bpf_trampoline_multi_prog_attach` and `bpf_trampoline_multi_prog_detach` functions. I need to be sure the memory associated with `pokes` is getting properly initialized before it's used.

First, I see the loop in `bpf_trampoline_multi_prog_attach`: the code iterates through `mnode`s and assigns the address of `mnode->poke` to `link->pokes[i]`.  That seems straightforward, but crucially, *every* element of `link->pokes` is assigned, from `0` up to `link->nodes_cnt - 1`. Excellent. Then, each element gets passed to `bpf_text_poke_init`.

Now, the important part: what does `bpf_text_poke_init` do?  Looking at the function, it initializes all the fields of the `struct bpf_text_poke`! `ip`, `old_addr`, `new_addr`, `old_t`, and `new_t` are all set.  Okay, that's what I want to see. Each field is clearly initialized with valid values. This gives me confidence in the initial setup of `link->pokes`.

Then, I have to check `bpf_trampoline_multi_prog_detach` also initializes `link->pokes[i]` in the same manner. This must also be done to assure all information that should be set, is set.

Now, a critical question: what happens if `bpf_trampoline_multi_prog_attach` fails during the attachment process? I saw that a call to `bpf_link_cleanup` is used to recover from the failure.

Therefore, I need to check what `bpf_link_cleanup` does.



80/3 2026/10/12 18:02 tool grepper
0m Args:
{
  "Expression": "bpf_link_cleanup",
  "PathPrefixes": [
    "kernel/bpf/"
  ]
}

Results:
{
  "Output": "kernel/bpf/bpf_iter.c=504=int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/bpf_iter.c-567-\t\tif (err) {\nkernel/bpf/bpf_iter.c:568:\t\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/bpf_iter.c-569-\t\t\treturn err;\n--\nkernel/bpf/bpf_struct_ops.c=1471=int bpf_struct_ops_link_create(union bpf_attr *attr)\n--\nkernel/bpf/bpf_struct_ops.c-1524-\t\tmutex_unlock(\u0026update_mutex);\nkernel/bpf/bpf_struct_ops.c:1525:\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/bpf_struct_ops.c-1526-\t\tlink = NULL;\n--\nkernel/bpf/cgroup.c=1700=int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)\n--\nkernel/bpf/cgroup.c-1733-\tif (err) {\nkernel/bpf/cgroup.c:1734:\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/cgroup.c-1735-\t\tgoto out_put_cgroup;\n--\nkernel/bpf/cgroup.c=3097=int cgroup_bpf_struct_ops_attach(struct bpf_map *map, const union bpf_attr *attr)\n--\nkernel/bpf/cgroup.c-3198-\t}\nkernel/bpf/cgroup.c:3199:\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/cgroup.c-3200-\treturn err;\n--\nkernel/bpf/net_namespace.c=471=int netns_bpf_link_create(const union bpf_attr *attr, struct bpf_prog *prog)\n--\nkernel/bpf/net_namespace.c-509-\tif (err) {\nkernel/bpf/net_namespace.c:510:\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/net_namespace.c-511-\t\tgoto out_put_net;\n--\nkernel/bpf/syscall.c=3303=static void bpf_link_free_id(int id)\n--\nkernel/bpf/syscall.c-3321- */\nkernel/bpf/syscall.c:3322:void bpf_link_cleanup(struct bpf_link_primer *primer)\nkernel/bpf/syscall.c-3323-{\n--\nkernel/bpf/syscall.c=3678=static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n--\nkernel/bpf/syscall.c-3860-\tif (err) {\nkernel/bpf/syscall.c:3861:\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/syscall.c-3862-\t\tlink = NULL;\n--\nkernel/bpf/syscall.c=4289=static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)\n--\nkernel/bpf/syscall.c-4321-\tif (err) {\nkernel/bpf/syscall.c:4322:\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/syscall.c-4323-\t\tgoto out_put_file;\n--\nkernel/bpf/syscall.c=4341=static int bpf_raw_tp_link_attach(struct bpf_prog *prog,\n--\nkernel/bpf/syscall.c-4405-\tif (err) {\nkernel/bpf/syscall.c:4406:\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/syscall.c-4407-\t\tgoto out_put_btp;\n--\nkernel/bpf/tcx.c=310=int tcx_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)\n--\nkernel/bpf/tcx.c-338-\t\ttcx-\u003edev = NULL;\nkernel/bpf/tcx.c:339:\t\tbpf_link_cleanup(\u0026link_primer);\nkernel/bpf/tcx.c-340-\t\tgoto out;\n"
}

81/3 2026/10/12 18:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 74236
							output: 37
							thoughts: 23
						

Thoughts:
Here's a first-person summary, tailored for an expert audience, of the thought process described:

**Diving into BPF Link Cleanup**

Alright, let's get down to brass tacks. I need to understand the lifecycle of a BPF link's resources, and the cleanup process is critical. Let's head straight to the source. I'm going to start with `bpf_link_cleanup` in `kernel/bpf/syscall.c`. This is where the rubber meets the road, where the kernel actually untangles the BPF link's connections. I expect to see the release of various resources - the detachment from their target, the freeing of link-specific data structures, and the handling of any associated reference counts. My focus will be on the edge cases, how it handles errors, concurrent access, and what happens during different link states (active, inactive, in the process of detachment). I'll be looking for any potential memory leaks or race conditions within the cleanup routine. This is where the code becomes particularly vulnerable, so understanding the locking strategies and how they are implemented is essential. I'll probably cross-reference this with the linking infrastructure and the attach/detach functions. I want to see how these elements interact. It's time to dig in and determine what's actually happening!



82/3 2026/10/12 18:03 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 3320,
  "LineCount": 25
}

Results:
{
  "Contents": "3320:\t * link's release callback.\n3321:\t */\n3322:\tvoid bpf_link_cleanup(struct bpf_link_primer *primer)\n3323:\t{\n3324:\t\tprimer-\u003elink-\u003eprog = NULL;\n3325:\t\tbpf_link_free_id(primer-\u003eid);\n3326:\t\tfput(primer-\u003efile);\n3327:\t\tput_unused_fd(primer-\u003efd);\n3328:\t}\n3329:\t\n3330:\tvoid bpf_link_inc(struct bpf_link *link)\n3331:\t{\n3332:\t\tatomic64_inc(\u0026link-\u003erefcnt);\n3333:\t}\n3334:\t\n3335:\tstatic void bpf_link_dealloc(struct bpf_link *link)\n3336:\t{\n3337:\t\t/* now that we know that bpf_link itself can't be reached, put underlying BPF program */\n3338:\t\tif (link-\u003eprog)\n3339:\t\t\tbpf_prog_put(link-\u003eprog);\n3340:\t\n3341:\t\t/* free bpf_link and its containing memory */\n3342:\t\tif (link-\u003eops-\u003edealloc_deferred)\n3343:\t\t\tlink-\u003eops-\u003edealloc_deferred(link);\n3344:\t\telse\n"
}

83/3 2026/10/12 18:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 74949
							output: 32
							thoughts: 4538
						

Thoughts:
**Comprehensive Analysis of BPF Tracing Multi-Link Initialization and Cleanup**

Okay, I've thoroughly reviewed the code surrounding the `bpf_tracing_multi_link` functionality, paying close attention to potential uninitialized memory reads and other safety concerns. Here's a breakdown of my findings and thought process:

My initial concern was around the `fput(primer->file)` call, which triggers the file release callback. However, after careful examination, I determined the subsequent memory deallocation in `bpf_tracing_multi_link_dealloc` uses `kvfree` on arrays like `pokes`, `tgt_progs`, `fexits`, and `cookies`. `kvfree` itself doesn't cause uninitialized memory reads, but I needed to ensure that the contents of these arrays were properly initialized *before* deallocation.

I then scrutinized the initialization of the `link->pokes` array, particularly within `bpf_trampoline_multi_prog_attach` and `bpf_text_poke_batch`. The loop that assigns and initializes the array entries, combined with the subsequent use of `bpf_text_poke_batch` (and the `sort_nonatomic` function), made me realize that all entries in `link->pokes` should be initialized to valid `&mnode->poke` pointers. The `bpf_text_poke_cmp` function compares the `ip` addresses, and `ip` addresses are intialized. This process appeared sound.

The `sort_r_nonatomic` function in `check_dup_keys` sparked another line of inquiry. Were all the arrays, especially `keys`, `progs`, `ids`, and `cookies`, fully initialized before being passed to `check_dup_keys`? The code in `bpf_tracing_multi_attach` answered this question.

-   `ids` are initialized by a `copy_from_user` call, meaning the user provides the values.
-   `fds` are also initialized by a `copy_from_user` call.
-   `progs` go through `bpf_get_progs`, and the `bpf_get_progs` initializes all elements if it succeeds, and properly cleans up when it fails. If `bpf_get_progs` fails, `cnt` is set to 0 to avoid double frees, ensuring that we don't attempt to deallocate uninitialized program pointers.
-   `cookies` can be initialized from `copy_from_user` or set to `NULL` (if no cookies were given), meaning we don't have uninitialized reads.
-   `keys` are computed and initialized in a loop with `bpf_trampoline_compute_key`.

So, the arrays passed into `check_dup_keys` are indeed fully initialized, addressing my concern about potential uninitialized data.

I then examined the `error` handling in `bpf_tracing_multi_attach` in detail, considering the scenario where `bpf_get_progs` might return an error *after* some program pointers had already been retrieved. The code correctly sets `cnt = 0` to prevent issues with partially filled arrays during the cleanup phase using `bpf_put_progs`. I checked the entire `error` block and made sure that all potential memory leaks and double-frees were prevented using the `kvfree` and initial null assignments.

I then moved on to the `bpf_tracing_multi_show_fdinfo` function, to confirm that no uninitialized values were being printed to the sequence file. The function dereferences fields like `tr_link->cookies` and `tr_link->tgt_progs` in a safe manner that I validated, with `seq_printf` formatting data and avoiding potential issues.

I investigated `bpf_arch_text_poke_check_ip` and `bpf_arch_text_poke_batch` because it modifies `pokes[i]->ip` in place, which means an uninitialized read *could* happen, but the code does so safely, after sorting, and the comparison of `pokes[i]->ip` occurs on a valid memory address.

I then carefully looked at the `struct bpf_text_poke`, and how `poke->ip` which is kernel text, and `old_insn` which is initialized. There are no uninitialized reads in the patch.

I then looked at the state of `tr->func.ftrace_managed`, `bpf_trampoline_multi_attach_init`, `bpf_trampoline_multi_attach_free`, `bpf_trampoline_multi_attach_rollback`, and `struct bpf_text_poke` and determined there are no possible uninitialized reads, nor possible leaks


84/3 2026/10/12 18:03 tool grepper
0m Args:
{
  "Expression": "CHECK_ATTR",
  "PathPrefixes": [
    "kernel/bpf/syscall.c"
  ]
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 208 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (1 files in total):\nkernel/bpf/syscall.c:35\n\nkernel/bpf/syscall.c=1216=int bpf_get_file_flag(int flags)\n--\nkernel/bpf/syscall.c-1227-/* helper macro to check that unused fields 'union bpf_attr' are zero */\nkernel/bpf/syscall.c:1228:#define CHECK_ATTR(CMD) \\\nkernel/bpf/syscall.c-1229-\tmemchr_inv((void *) \u0026attr-\u003eCMD##_LAST_FIELD + \\\n--\nkernel/bpf/syscall.c=1401=static int map_create_alloc(union bpf_attr *attr, bpfptr_t uattr, struct bpf_verifier_log *log,\n--\nkernel/bpf/syscall.c-1411-\nkernel/bpf/syscall.c:1412:\terr = CHECK_ATTR(BPF_MAP_CREATE);\nkernel/bpf/syscall.c-1413-\tif (err) {\n--\nkernel/bpf/syscall.c=1805=static int map_lookup_elem(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-1813-\nkernel/bpf/syscall.c:1814:\tif (CHECK_ATTR(BPF_MAP_LOOKUP_ELEM))\nkernel/bpf/syscall.c-1815-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=1866=static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)\n--\nkernel/bpf/syscall.c-1874-\nkernel/bpf/syscall.c:1875:\tif (CHECK_ATTR(BPF_MAP_UPDATE_ELEM))\nkernel/bpf/syscall.c-1876-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=1919=static int map_delete_elem(union bpf_attr *attr, bpfptr_t uattr)\n--\nkernel/bpf/syscall.c-1925-\nkernel/bpf/syscall.c:1926:\tif (CHECK_ATTR(BPF_MAP_DELETE_ELEM))\nkernel/bpf/syscall.c-1927-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=1972=static int map_get_next_key(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-1979-\nkernel/bpf/syscall.c:1980:\tif (CHECK_ATTR(BPF_MAP_GET_NEXT_KEY))\nkernel/bpf/syscall.c-1981-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=2235=static int map_lookup_and_delete_elem(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-2243-\nkernel/bpf/syscall.c:2244:\tif (CHECK_ATTR(BPF_MAP_LOOKUP_AND_DELETE_ELEM))\nkernel/bpf/syscall.c-2245-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=2327=static int map_freeze(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-2331-\nkernel/bpf/syscall.c:2332:\tif (CHECK_ATTR(BPF_MAP_FREEZE))\nkernel/bpf/syscall.c-2333-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=2953=static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\n--\nkernel/bpf/syscall.c-2963-\nkernel/bpf/syscall.c:2964:\tif (CHECK_ATTR(BPF_PROG_LOAD))\nkernel/bpf/syscall.c-2965-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=3232=static int bpf_obj_pin(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-3235-\nkernel/bpf/syscall.c:3236:\tif (CHECK_ATTR(BPF_OBJ) || attr-\u003efile_flags \u0026 ~BPF_F_PATH_FD)\nkernel/bpf/syscall.c-3237-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=3248=static int bpf_obj_get(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-3251-\nkernel/bpf/syscall.c:3252:\tif (CHECK_ATTR(BPF_OBJ) || attr-\u003ebpf_fd != 0 ||\nkernel/bpf/syscall.c-3253-\t    attr-\u003efile_flags \u0026 ~(BPF_OBJ_FLAG_MASK | BPF_F_PATH_FD))\n--\nkernel/bpf/syscall.c=4419=static int bpf_raw_tracepoint_open(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-4425-\nkernel/bpf/syscall.c:4426:\tif (CHECK_ATTR(BPF_RAW_TRACEPOINT_OPEN))\nkernel/bpf/syscall.c-4427-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=4623=static int bpf_prog_attach(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-4628-\nkernel/bpf/syscall.c:4629:\tif (CHECK_ATTR(BPF_PROG_ATTACH))\nkernel/bpf/syscall.c-4630-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=4692=static int bpf_prog_detach(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-4697-\nkernel/bpf/syscall.c:4698:\tif (CHECK_ATTR(BPF_PROG_DETACH))\nkernel/bpf/syscall.c-4699-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=4762=static int bpf_prog_query(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-4766-\t\treturn -EPERM;\nkernel/bpf/syscall.c:4767:\tif (CHECK_ATTR(BPF_PROG_QUERY))\nkernel/bpf/syscall.c-4768-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=4827=static int bpf_prog_test_run(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-4832-\nkernel/bpf/syscall.c:4833:\tif (CHECK_ATTR(BPF_PROG_TEST_RUN))\nkernel/bpf/syscall.c-4834-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=4857=static int bpf_obj_get_next_id(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-4864-\nkernel/bpf/syscall.c:4865:\tif (CHECK_ATTR(BPF_OBJ_GET_NEXT_ID) || next_id \u003e= INT_MAX)\nkernel/bpf/syscall.c-4866-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=4940=static int bpf_prog_get_fd_by_id(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-4945-\nkernel/bpf/syscall.c:4946:\tif (CHECK_ATTR(BPF_PROG_GET_FD_BY_ID))\nkernel/bpf/syscall.c-4947-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=4965=static int bpf_map_get_fd_by_id(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-4971-\nkernel/bpf/syscall.c:4972:\tif (CHECK_ATTR(BPF_MAP_GET_FD_BY_ID) ||\nkernel/bpf/syscall.c-4973-\t    attr-\u003eopen_flags \u0026 ~BPF_OBJ_FLAG_MASK)\n--\nkernel/bpf/syscall.c=5580=static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-5582-{\nkernel/bpf/syscall.c:5583:\tif (CHECK_ATTR(BPF_OBJ_GET_INFO_BY_FD))\nkernel/bpf/syscall.c-5584-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=5609=static int bpf_btf_load(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\n--\nkernel/bpf/syscall.c-5612-\nkernel/bpf/syscall.c:5613:\tif (CHECK_ATTR(BPF_BTF_LOAD))\nkernel/bpf/syscall.c-5614-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=5641=static int bpf_btf_get_fd_by_id(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-5644-\nkernel/bpf/syscall.c:5645:\tif (CHECK_ATTR(BPF_BTF_GET_FD_BY_ID))\nkernel/bpf/syscall.c-5646-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=5709=static int bpf_task_fd_query(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-5718-\nkernel/bpf/syscall.c:5719:\tif (CHECK_ATTR(BPF_TASK_FD_QUERY))\nkernel/bpf/syscall.c-5720-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=5792=static int bpf_map_do_batch(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-5801-\nkernel/bpf/syscall.c:5802:\tif (CHECK_ATTR(BPF_MAP_BATCH))\nkernel/bpf/syscall.c-5803-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=5838=static int link_create(union bpf_attr *attr, bpfptr_t uattr)\n--\nkernel/bpf/syscall.c-5842-\nkernel/bpf/syscall.c:5843:\tif (CHECK_ATTR(BPF_LINK_CREATE))\nkernel/bpf/syscall.c-5844-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=5975=static int link_update(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-5981-\nkernel/bpf/syscall.c:5982:\tif (CHECK_ATTR(BPF_LINK_UPDATE))\nkernel/bpf/syscall.c-5983-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6033=static int link_detach(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-6037-\nkernel/bpf/syscall.c:6038:\tif (CHECK_ATTR(BPF_LINK_DETACH))\nkernel/bpf/syscall.c-6039-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6106=static int bpf_link_get_fd_by_id(const union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-6111-\nkernel/bpf/syscall.c:6112:\tif (CHECK_ATTR(BPF_LINK_GET_FD_BY_ID))\nkernel/bpf/syscall.c-6113-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6165=static int bpf_enable_stats(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-6167-\nkernel/bpf/syscall.c:6168:\tif (CHECK_ATTR(BPF_ENABLE_STATS))\nkernel/bpf/syscall.c-6169-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6185=static int bpf_iter_create(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-6189-\nkernel/bpf/syscall.c:6190:\tif (CHECK_ATTR(BPF_ITER_CREATE))\nkernel/bpf/syscall.c-6191-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6208=static int bpf_prog_bind_map(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-6214-\nkernel/bpf/syscall.c:6215:\tif (CHECK_ATTR(BPF_PROG_BIND_MAP))\nkernel/bpf/syscall.c-6216-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6274=static int token_create(union bpf_attr *attr)\nkernel/bpf/syscall.c-6275-{\nkernel/bpf/syscall.c:6276:\tif (CHECK_ATTR(BPF_TOKEN_CREATE))\nkernel/bpf/syscall.c-6277-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6288=static int prog_stream_read(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-6294-\nkernel/bpf/syscall.c:6295:\tif (CHECK_ATTR(BPF_PROG_STREAM_READ_BY_FD))\nkernel/bpf/syscall.c-6296-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=6310=static int prog_assoc_struct_ops(union bpf_attr *attr)\n--\nkernel/bpf/syscall.c-6315-\n\n"
}

85/3 2026/10/12 18:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 84304
							output: 38
							thoughts: 16
						

Thoughts:
Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:

**Checking `BPF_LINK_CREATE_LAST_FIELD`**

Alright, let's take a quick look at `BPF_LINK_CREATE_LAST_FIELD`. It's a key element in managing BPF links, especially when dealing with the intricacies of link creation and ordering. I need to make sure I have a solid grasp on how this field interacts with the overall link structure, and ensure the code handling this field aligns with expected link behavior. There might be some subtle interplay with the various link flags and types – particularly regarding the insertion order of BPF programs or maps. I need to verify that it's correctly used in conjunction with different link types to account for the last field during link creation, and that there are no discrepancies. Any potential issues here could lead to unexpected program loading or execution behavior. A careful check will ensure consistent operation across link configurations.



86/3 2026/10/12 18:03 tool grepper
0m Args:
{
  "Expression": "BPF_LINK_CREATE_LAST_FIELD",
  "PathPrefixes": [
    "include/",
    "kernel/"
  ]
}

Results:
{
  "Output": "kernel/bpf/syscall.c=5792=static int bpf_map_do_batch(const union bpf_attr *attr,\n--\nkernel/bpf/syscall.c-5836-\nkernel/bpf/syscall.c:5837:#define BPF_LINK_CREATE_LAST_FIELD link_create.uprobe_multi.path_fd\nkernel/bpf/syscall.c-5838-static int link_create(union bpf_attr *attr, bpfptr_t uattr)\n"
}

87/3 2026/10/12 18:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 84698
							output: 452
							thoughts: 1475
						

Thoughts:
**KMSAN Assessment: No Uninitialized Memory Risks**

Okay, let's break this down. My primary concern here is determining if this patch introduces any uninitialized memory vulnerabilities that would warrant the use of KMSAN. First, I note that `link_create.uprobe_multi.path_fd` is the final field, following `tracing_multi`, and the `bpf_check_uarg_tail_zero` function verifies that any extra bytes beyond `uattr`'s size are zeroed, which is a good starting point.

Now, let's systematically evaluate against the four KMSAN criteria:

1.  **Kernel structures to userspace:** In `bpf_link_get_info_by_fd`, the `info` structure is meticulously zeroed with `memset` *before* the `fill_link_info` function is called. The `copy_to_user` call then sends this zeroed and populated structure to userspace. Inside `bpf_tracing_multi_link_fill_link_info`, `put_user` is used for scalar values (u32, u64) which are initialized before being passed. No concerns here.

2.  **Conditional logic on uninitialized variables:** I carefully examined the variables in the patch. The x86 text poking (in `arch/x86/net/bpf_jit_comp.c`) uses `memcpy` to fully initialize `old_insn` and `new_insn` before they are used. In `kernel/bpf/trampoline.c`, `bpf_attach_target_info` is zero-initialized and  `bpf_text_poke_init` explicitly writes to all the fields of `struct bpf_text_poke`. In `kernel/trace/bpf_trace.c`, `tracing_multi_sort_data` is explicitly initialized, and the `bpf_tracing_multi_link` structure is allocated and zeroed using `kvzalloc_flex`. All arrays are either populated from user space or freed. No uninitialized memory is used in any conditional branches.

3.  **Complex data structure initialization:** The `bpf_tracing_multi_link` is allocated and zeroed by `kvzalloc_flex`, including the flexible array. The `bpf_trampoline` structure's fields related to multi-attach are initialized and cleared correctly in all relevant paths (init, rollback, commit, free).

4.  **Bounds checks and length/logic vulnerabilities:** The code correctly checks the `cnt` value against `MAX_TRACING_MULTI_CNT` and `0`. All loops iterate up to either `cnt` or `ucount`, which in turn is capped. In `bpf_arch_text_poke_batch`, the loop iterates up to `cnt`. No issues with potential out-of-bounds access due to uninitialized length variables.

Next, I considered alternative bug detectors, which brings us to:

*   **Other Potential Issues:** I considered other memory-safety issues, such as out-of-bounds access due to `cnt` mismatches (KASAN would catch these), memory leaks/use-after-free in rollback/refcounting (KASAN), locking deadlocks (LOCKDEP), and text poking concurrency (standard kernel checks and KASAN). But these are not related to uninitialized memory.

After thorough examination, it is clear that all memory allocated for structs is either zero-allocated or entirely overwritten before being read. The structure (`bpf_link_info`) sent to user space is zeroed and populated with initialized scalars.

**Final Verdict:** Therefore, this patch does *not* introduce or expose uninitialized memory risks. KMSAN is unnecessary. KASAN and LOCKDEP are sufficient for the detected potential problems.

To ensure nothing was missed, I reviewed the key fields:

*   `info->tracing_multi.flags`: set correctly.
*   `info->tracing_multi.func_btf_ids`: Userspace pointers.
*   `link->pokes`, `link->tgt_progs`: allocated with `kvmalloc_objs` and completely written.
*   `nodes`: flex array zero-initialized by `kvzalloc_flex`.
*   `keys`: filled in a loop.
*   `fds`: filled via `copy_from_user`.

Everything is consistent. It's safe to say there are no KMSAN-relevant vulnerabilities here, so I'll respond accordingly.



88/3 2026/10/12 18:04 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch adds support for attaching tracing multi-links (fentry/fexit/fsession multi) to BPF programs using batch text poking and trampoline management.\n\nAnalysis of memory initialization and user-space exposure:\n1. User-space copies: In `bpf_link_get_info_by_fd`, the entire `struct bpf_link_info` is initialized with `memset(\u0026info, 0, sizeof(info))` before calling `link-\u003eops-\u003efill_link_info`. The newly added `flags` field in `info-\u003etracing_multi` is explicitly set, and array data exported to user pointers via `put_user` (including target BTF function IDs) uses initialized scalar values. No uninitialized struct padding or fields are leaked to userspace.\n2. Kernel structures and allocations: `struct bpf_tracing_multi_link` (including its flexible array member `nodes`) is allocated with `kvzalloc_flex()`, ensuring all fields are zero-initialized. Temporary arrays (`keys`, `progs`, `pokes`, `fds`, `cookies`, `ids`) are either fully populated (via `copy_from_user()`, `bpf_get_progs()`, or loops) before being read or sorted, or properly cleaned up on error.\n3. Text poke buffers: In `bpf_arch_text_poke_batch()` and `bpf_arch_text_poke_prepare_insns()`, instruction buffers `old_insn` and `new_insn` are initialized (with `x86_nops[5]`) before any `memcmp` or poking occurs.\n\nAny potential bugs introduced by this patch (such as reference counting leaks, use-after-free on rollback, out-of-bounds indexing, or locking issues with `text_mutex` / `trampoline_locks`) are covered by standard KASAN and LOCKDEP configurations. There are no uninitialized memory risks that would require a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch adds support for attaching tracing multi-links (fentry/fexit/fsession multi) to BPF programs using batch text poking and trampoline management.\n\nAnalysis of memory initialization and user-space exposure:\n1. User-space copies: In `bpf_link_get_info_by_fd`, the entire `struct bpf_link_info` is initialized with `memset(\u0026info, 0, sizeof(info))` before calling `link-\u003eops-\u003efill_link_info`. The newly added `flags` field in `info-\u003etracing_multi` is explicitly set, and array data exported to user pointers via `put_user` (including target BTF function IDs) uses initialized scalar values. No uninitialized struct padding or fields are leaked to userspace.\n2. Kernel structures and allocations: `struct bpf_tracing_multi_link` (including its flexible array member `nodes`) is allocated with `kvzalloc_flex()`, ensuring all fields are zero-initialized. Temporary arrays (`keys`, `progs`, `pokes`, `fds`, `cookies`, `ids`) are either fully populated (via `copy_from_user()`, `bpf_get_progs()`, or loops) before being read or sorted, or properly cleaned up on error.\n3. Text poke buffers: In `bpf_arch_text_poke_batch()` and `bpf_arch_text_poke_prepare_insns()`, instruction buffers `old_insn` and `new_insn` are initialized (with `x86_nops[5]`) before any `memcmp` or poking occurs.\n\nAny potential bugs introduced by this patch (such as reference counting leaks, use-after-free on rollback, out-of-bounds indexing, or locking issues with `text_mutex` / `trampoline_locks`) are covered by standard KASAN and LOCKDEP configurations. There are no uninitialized memory risks that would require a dedicated KMSAN fuzzing session.",
  "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)