From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214714; b=pQH+PoWcDy8GOvcklx2wSuH/UE87iW/ghc0LtKJiRVF27sWxH2v4qarfrbJoJaP32Kj4 0eftCiCZRoWLTkfhXno1BCyYfah24JqD3TqA9BdwtFUDuOA02Gh2ni16vRfyi1eTW7BuD tUDjj2UT1JfVhfk3yPDWPAdAeEs0laB/zENRfOO8pE7w2irHjHDuxi3idfjm84wBp7gLC EKEJlSIIC7WcMGDZ83FFk21BMyQ60p8R9yJE3kkIRHQcdDPtBN582bbAH8HuxOAGXZPl1 +dwXdoptc46OoJ7NMNsOlj71mCUA1ndarczigSrInzxvGleqfvk1BPzPakwj2jwIYdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214714; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Zvv/JSn55jrS0PlRc8wbo5YiGKTZKI+6ak7aNRXRQ2g=; b=OnYvnzE+/zYEpIqlsENH8CNLDFfpswIS7J0V7hBV2KjPWhMGD7zRRJwiaGMK5Qow0WsJ uqnuIah2gKJFF8UuPcgVQ/OsUAsf7yG+/1RqUTU24wbuZvB3FMwrgqtkv6ZjoukvExXJI RLkdv7K4C2N6bNkeERfStDNzJfe7tLsb/zfnxeLBShjHMYLn1+oeON0XH4VNYAyIE2lEP gTpiHdQIYmE7819ql3aVIiUj+8hmXguFs2t/oBtHSvd+55oNnPw75QsRKa9XHTO7ZdUEH wfAe5ibb28E7CTiM8Dcjv4zsidZ91qlX+IgDcCSBpDG5EDFKLCKBQsc+EVow0L6M6ug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B2XZNjGC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD399606A31A; Wed, 2 Dec 2026 12:31:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B2XZNjGC Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D2BA1F00899; Wed, 2 Dec 2026 12:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214714; bh=Zvv/JSn55jrS0PlRc8wbo5YiGKTZKI+6ak7aNRXRQ2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=B2XZNjGC2yMfkpQJweO4pVFnSUKGIA0LyMl6X/djOprdmFu7p68sTjnDAw62oA7bj RbRGFsbcaD3U58s9fvznzmf2tKLHHTntT1+Wq2IWdVdK0hq+o+HQbN4BcCH+mEGLHb EK7RcukEbE0ZkGcqek1B00wCUF41cTrVuL8jCgnrIGkUqzLbUpTVLglA/dhlW7PZQ8 +E/XOrWO4g4kfcxU8LkWnkKADQP/+mkSrOFKkmduiqGZibma3UpSjXulkmXSrCqhjU IyTOfWLXcBKUaYIaJsadSgf5i0gDiGznKa/Hn7PuxFanBj/pJzXNBrO4MFRC6vu7Dm Wi03aU1y/9IZw== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Song Liu , Yonghong Song , Quentin Monnet , Alan Maguire Subject: [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link Date: Wed, 2 Dec 2026 13:30:11 +0100 Message-ID: <20261202123035.10335-8-jolsa@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org> References: <20261202123035.10335-1-jolsa@kernel.org> X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The kprobe multi link attaches functions through fprobe, so it gets only to the out-of-line copy of the function. The inlined instances are not traced, and a function that is inlined in all its callers can't be attached at all. Adding BPF_F_KPROBE_MULTI_INLINE flag that makes the link attach also the inlined instances of the functions provided in the syms array. The instances are resolved by function name from the vmlinux inline BTF (inline.text LOCSEC). Each of them gets its own kprobe and the kprobes are enabled all at once with enable_kprobes. Instances of two functions can share the same address, the program is executed for both. Each function needs to have either entry or at least one inlined instance, otherwise the attach fails with -ESRCH. Instances that kprobes refuse (jump label or static call site, bug table entry, NOKPROBE_SYMBOL or noinstr caller) are skipped, and so are instances inlined in functions without ftrace location (notrace), which are likely not safe to probe. With all the attachable functions in vmlinux that's 748 instances out of 20688. The attach fails if a function has no entry and all its instances are skipped. The program attached to inlined instance gets pt_regs of the probed instruction, so the function arguments are not available in the argument registers. The bpf_get_func_ip helper returns the address of the inlined instance. The flag can't be combined with BPF_F_KPROBE_MULTI_RETURN flag, session program, the addrs array or program that uses bpf_override_return. The number of inlined instances is limited to MAX_KPROBE_MULTI_CNT, the attach fails with -E2BIG above that. The support is x86_64 only for now, selected with the new HAVE_KPROBE_MULTI_INLINE config option. The attach with the flag fails with -EOPNOTSUPP on other architectures, on kernel without inline BTF and without CONFIG_KPROBES. The support for cookies and for inlined instances in modules is added in following changes. Signed-off-by: Jiri Olsa --- arch/Kconfig | 6 + arch/x86/Kconfig | 1 + include/uapi/linux/bpf.h | 8 +- kernel/trace/bpf_trace.c | 379 +++++++++++++++++++++++++++++++-- tools/include/uapi/linux/bpf.h | 8 +- 5 files changed, 384 insertions(+), 18 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 350144df6863..1824719263db 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -308,6 +308,12 @@ config HAVE_OPTPROBES config HAVE_KPROBES_ON_FTRACE bool +config HAVE_KPROBE_MULTI_INLINE + bool + help + The architecture supports kprobe multi link attach to inlined + functions (BPF_F_KPROBE_MULTI_INLINE). + config ARCH_CORRECT_STACKTRACE_ON_KRETPROBE bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 23889c2261e4..992756c0672d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -262,6 +262,7 @@ config X86 select HAVE_KERNEL_ZSTD select HAVE_KPROBES select HAVE_KPROBES_ON_FTRACE + select HAVE_KPROBE_MULTI_INLINE if X86_64 select HAVE_FUNCTION_ERROR_INJECTION select HAVE_KRETPROBES select HAVE_RETHOOK diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 28904c6f0787..96e6a629f0c0 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1365,10 +1365,14 @@ enum bpf_perf_event_type { #define BPF_F_TEST_REG_INVARIANTS (1U << 7) /* link_create.kprobe_multi.flags used in LINK_CREATE command for - * BPF_TRACE_KPROBE_MULTI attach type to create return probe. + * BPF_TRACE_KPROBE_MULTI attach type. */ enum { - BPF_F_KPROBE_MULTI_RETURN = (1U << 0) + /* Create return probe. */ + BPF_F_KPROBE_MULTI_RETURN = (1U << 0), + + /* Attach also to inlined function instances, skip those that fail. */ + BPF_F_KPROBE_MULTI_INLINE = (1U << 1), }; /* link_create.uprobe_multi.flags used in LINK_CREATE command for diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index c546e1d41be0..89388a140b48 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -30,6 +30,7 @@ #include #include +#include #include #include "trace_probe.h" @@ -2365,6 +2366,27 @@ struct bpf_session_run_ctx { }; #ifdef CONFIG_FPROBE +struct bpf_kprobe_multi_link; + +struct inline_site { + struct kprobe kp; + struct bpf_kprobe_multi_link *link; + u32 sym_idx; + bool has_entry; + bool traceable; +}; + +/* + * @sites has @sites_cnt inlined instances found for the link, the ones + * that got registered are stored in @kps (@cnt), the rest was skipped. + */ +struct inline_sites { + struct inline_site *sites; + struct kprobe **kps; + u32 sites_cnt; + u32 cnt; +}; + struct bpf_kprobe_multi_link { struct bpf_link link; struct fprobe fp; @@ -2373,6 +2395,7 @@ struct bpf_kprobe_multi_link { u32 cnt; u32 mods_cnt; struct module **mods; + struct inline_sites inlines; }; struct bpf_kprobe_multi_run_ctx { @@ -2463,7 +2486,9 @@ static void bpf_kprobe_multi_link_release(struct bpf_link *link) kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link); /* Don't wait for RCU GP here. */ - unregister_fprobe_async(&kmulti_link->fp); + if (kmulti_link->cnt) + unregister_fprobe_async(&kmulti_link->fp); + unregister_kprobes(kmulti_link->inlines.kps, kmulti_link->inlines.cnt); kprobe_multi_put_modules(kmulti_link->mods, kmulti_link->mods_cnt); } @@ -2472,6 +2497,8 @@ static void bpf_kprobe_multi_link_dealloc(struct bpf_link *link) struct bpf_kprobe_multi_link *kmulti_link; kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link); + kvfree(kmulti_link->inlines.sites); + kvfree(kmulti_link->inlines.kps); kvfree(kmulti_link->addrs); kvfree(kmulti_link->cookies); kfree(kmulti_link->mods); @@ -2626,7 +2653,7 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx) static __always_inline int kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, unsigned long entry_ip, struct ftrace_regs *fregs, - bool is_return, void *data) + struct pt_regs *regs, bool is_return, void *data) { struct bpf_kprobe_multi_run_ctx run_ctx = { .session_ctx = { @@ -2637,13 +2664,12 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, .entry_ip = entry_ip, }; struct bpf_run_ctx *old_run_ctx; - struct pt_regs *regs; int err; /* - * graph tracer framework ensures we won't migrate, so there is no need - * to use migrate_disable for bpf_prog_run again. The check here just for - * __this_cpu_inc_return. + * Both fprobe and kprobe handlers ensure we won't migrate, so there + * is no need to use migrate_disable for bpf_prog_run again. The check + * here just for __this_cpu_inc_return. */ cant_sleep(); @@ -2654,11 +2680,14 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, } rcu_read_lock(); - regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr()); + /* The caller provides either ftrace_regs or pt_regs. */ + if (fregs) + regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr()); old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx); err = bpf_prog_run(link->link.prog, regs); bpf_reset_run_ctx(old_run_ctx); - ftrace_partial_regs_update(fregs, bpf_kprobe_multi_pt_regs_ptr()); + if (fregs) + ftrace_partial_regs_update(fregs, bpf_kprobe_multi_pt_regs_ptr()); rcu_read_unlock(); out: @@ -2676,7 +2705,7 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip, link = container_of(fp, struct bpf_kprobe_multi_link, fp); err = kprobe_multi_link_prog_run(link, ftrace_get_entry_ip(fentry_ip), - fregs, false, data); + fregs, NULL, false, data); return is_kprobe_session(link->link.prog) ? err : 0; } @@ -2689,9 +2718,21 @@ kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip, link = container_of(fp, struct bpf_kprobe_multi_link, fp); kprobe_multi_link_prog_run(link, ftrace_get_entry_ip(fentry_ip), - fregs, true, data); + fregs, NULL, true, data); } +static int +kprobe_multi_inline_handler(struct kprobe *kp, struct pt_regs *regs) +{ + struct inline_site *site; + + site = container_of(kp, struct inline_site, kp); + kprobe_multi_link_prog_run(site->link, (unsigned long)kp->addr, + NULL, regs, false, NULL); + return 0; +} +NOKPROBE_SYMBOL(kprobe_multi_inline_handler); + static int symbols_cmp_r(const void *a, const void *b, const void *priv) { const char **str_a = (const char **) a; @@ -2700,6 +2741,11 @@ static int symbols_cmp_r(const void *a, const void *b, const void *priv) return strcmp(*str_a, *str_b); } +static int symbols_cmp(const void *a, const void *b) +{ + return symbols_cmp_r(a, b, NULL); +} + struct multi_symbols_sort { const char **funcs; u64 *cookies; @@ -2809,8 +2855,262 @@ static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt) return 0; } +static int inline_sym_idx(const struct btf *btf, const struct btf_loc *loc, + const char **syms, u32 cnt) +{ + const struct btf_type *t = btf_type_by_id(btf, loc->func); + const char *name, **sym; + + if (!t) + return -1; + name = btf_name_by_offset(btf, t->name_off); + if (!name) + return -1; + sym = bsearch(&name, syms, cnt, sizeof(*syms), symbols_cmp); + return sym ? sym - syms : -1; +} + +static int inlines_cmp(const void *a, const void *b) +{ + const struct inline_site *site_a = a, *site_b = b; + + if (site_a->sym_idx != site_b->sym_idx) + return site_a->sym_idx < site_b->sym_idx ? -1 : 1; + if (site_a->kp.addr != site_b->kp.addr) + return site_a->kp.addr < site_b->kp.addr ? -1 : 1; + return 0; +} + +struct inline_lookup { + /* Input: functions to look for, @syms is alphabetically sorted. */ + const char **syms; + unsigned long *addrs; + u32 syms_cnt; + + /* Output */ + struct inline_sites *inlines; + u32 addrs_cnt; + + /* Lookup state */ + struct inline_site *sites; + u32 cnt; + u32 cap; +}; + +static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr, u32 sym_idx) +{ + struct inline_site *sites; + u32 cap; + + if (lookup->cnt == MAX_KPROBE_MULTI_CNT) + return -E2BIG; + + if (lookup->cnt == lookup->cap) { + cap = max(16, lookup->cap * 2); + sites = kvrealloc(lookup->sites, array_size(cap, sizeof(*sites)), GFP_KERNEL); + if (!sites) + return -ENOMEM; + lookup->sites = sites; + lookup->cap = cap; + } + + lookup->sites[lookup->cnt++] = (struct inline_site) { + .kp.addr = (kprobe_opcode_t *)addr, + .sym_idx = sym_idx, + }; + return 0; +} + +/* + * Add inlined instances of the functions we look for from @locsec, + * the offsets of its locations are relative to @base address. + */ +static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf *btf, + const struct btf_type *locsec, unsigned long base) +{ + struct btf_loc *loc; + int idx, err; + u32 i; + + for_each_loc(i, locsec, loc) { + idx = inline_sym_idx(btf, loc, lookup->syms, lookup->syms_cnt); + if (idx < 0) + continue; + err = inline_lookup_add(lookup, base + loc->offset, idx); + if (err) + return err; + } + return 0; +} + +/* + * Sort instances by symbol name and address, so instances of each + * symbol are next to each other, and get rid of duplicates. + */ +static void inline_lookup_sort(struct inline_lookup *lookup) +{ + struct inline_site *sites = lookup->sites; + u32 i, j; + + sort(sites, lookup->cnt, sizeof(*sites), inlines_cmp, NULL); + + for (i = 0, j = 0; i < lookup->cnt; i++) { + if (i && !inlines_cmp(&sites[i], &sites[i - 1])) + continue; + if (i != j) + sites[j] = sites[i]; + j++; + } + lookup->cnt = j; +} + +/* + * The inlined instance is attached inside the function it's inlined in, + * make sure that function is traceable (not notrace) and safe to probe. + */ +static bool inline_site_traceable(unsigned long addr) +{ + unsigned long size, offset; + + if (!kallsyms_lookup_size_offset(addr, &size, &offset)) + return false; + addr -= offset; + return ftrace_location_range(addr, addr + size - 1); +} + +/* + * Find inlined instances for functions in @lookup->syms. Each function + * must have an entry address or at least one inlined instance, functions + * without an entry address are dropped from @lookup->addrs. + */ +static int inline_lookup_symbols(struct inline_lookup *lookup) +{ + struct inline_sites *inlines = lookup->inlines; + unsigned long *addrs = lookup->addrs; + u32 i, j, k, n, cnt = lookup->syms_cnt; + struct inline_site *sites; + struct btf *btf; + int err; + s32 id; + + btf = bpf_get_btf_vmlinux_inline(); + if (IS_ERR_OR_NULL(btf)) + return -EOPNOTSUPP; + + /* The offsets of inline.text locations are relative to .text section. */ + id = btf_find_by_name_kind(btf, "inline.text", BTF_KIND_LOCSEC); + if (id < 0) + return -EOPNOTSUPP; + + err = inline_lookup_locsec(lookup, btf, btf_type_by_id(btf, id), (unsigned long)_stext); + if (err) + goto error; + + inline_lookup_sort(lookup); + + sites = lookup->sites; + n = lookup->cnt; + + for (i = 0; i < n; i++) { + sites[i].kp.pre_handler = kprobe_multi_inline_handler; + /* Registered disabled and enabled all at once. */ + sites[i].kp.flags = KPROBE_FLAG_DISABLED; + sites[i].has_entry = !!addrs[sites[i].sym_idx]; + sites[i].traceable = inline_site_traceable((unsigned long)sites[i].kp.addr); + } + + /* + * Each symbol needs to have either entry or inlined instance, + * keep only symbols with entry in @addrs array. + * The instances are sorted by symbol name, so we walk them together. + */ + for (i = 0, j = 0, k = 0; i < cnt; i++) { + while (k < n && sites[k].sym_idx < i) + k++; + if (!addrs[i]) { + if (k < n && sites[k].sym_idx == i) + continue; + err = -ESRCH; + goto error; + } + addrs[j] = addrs[i]; + j++; + } + + inlines->sites = sites; + inlines->sites_cnt = n; + lookup->addrs_cnt = j; + return 0; + +error: + kvfree(lookup->sites); + return err; +} + +/* + * Register inlined instances of the @link and skip the ones that fail. + * Fail if function has no entry and none of its instances registered. + */ +static int inline_sites_register(struct bpf_kprobe_multi_link *link) +{ + struct inline_sites *inlines = &link->inlines; + struct inline_site *site, *first = NULL; + int err, first_err = 0; + bool attached = false; + u32 i, cnt = 0; + + inlines->kps = kvmalloc_array(inlines->sites_cnt, sizeof(*inlines->kps), GFP_KERNEL); + if (!inlines->kps) + return -ENOMEM; + + for (i = 0; i < inlines->sites_cnt; i++) { + site = &inlines->sites[i]; + site->link = link; + + /* First inlined instance of the function. */ + if (!i || site->sym_idx != first->sym_idx) { + first = site; + first_err = 0; + attached = site->has_entry; + } + + err = site->traceable ? register_kprobe(&site->kp) : -EINVAL; + if (err == -ENOMEM) + goto error; + if (err) { + first_err = first_err ?: err; + } else { + inlines->kps[cnt++] = &site->kp; + attached = true; + } + + /* Last inlined instance of the function. */ + if (i + 1 < inlines->sites_cnt && site[1].sym_idx == site->sym_idx) + continue; + if (!attached) { + err = first_err; + goto error; + } + } + + /* Arm all the registered instances with single sync. */ + if (cnt) { + err = enable_kprobes(inlines->kps, cnt); + if (err) + goto error; + } + + inlines->cnt = cnt; + return 0; + +error: + unregister_kprobes(inlines->kps, cnt); + return err; +} + int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) { + struct inline_sites inlines = {}; struct bpf_kprobe_multi_link *link = NULL; struct bpf_link_primer link_primer; void __user *ucookies; @@ -2840,7 +3140,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr return -EINVAL; flags = attr->link_create.kprobe_multi.flags; - if (flags & ~BPF_F_KPROBE_MULTI_RETURN) + if (flags & ~(BPF_F_KPROBE_MULTI_RETURN | BPF_F_KPROBE_MULTI_INLINE)) return -EINVAL; uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs); @@ -2848,6 +3148,24 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if (!!uaddrs == !!usyms) return -EINVAL; + if (flags & BPF_F_KPROBE_MULTI_INLINE) { + /* + * Inlined instances are resolved from function names and + * have just entry probe, so there's no return probe, session + * or override support. + */ + if (flags & BPF_F_KPROBE_MULTI_RETURN) + return -EINVAL; + if (is_kprobe_session(prog) || prog->kprobe_override) + return -EINVAL; + if (uaddrs) + return -EINVAL; + if (!IS_ENABLED(CONFIG_KPROBES)) + return -EOPNOTSUPP; + if (!IS_ENABLED(CONFIG_HAVE_KPROBE_MULTI_INLINE)) + return -EOPNOTSUPP; + } + cnt = attr->link_create.kprobe_multi.cnt; if (!cnt) return -EINVAL; @@ -2894,6 +3212,26 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr symbols_swap_r, &data); err = ftrace_lookup_symbols(us.syms, cnt, addrs); + + /* + * With inline flag it's ok if the function is not found, + * as long as it has inlined instance. Unresolved functions + * have zero in addrs. + */ + if ((flags & BPF_F_KPROBE_MULTI_INLINE) && (!err || err == -ESRCH)) { + struct inline_lookup lookup = { + .inlines = &inlines, + .syms = us.syms, + .syms_cnt = cnt, + .addrs = addrs, + }; + + err = inline_lookup_symbols(&lookup); + /* The cnt is changed to number of functions with entry. */ + if (!err) + cnt = lookup.addrs_cnt; + } + free_user_syms(&us); if (err) goto error; @@ -2928,6 +3266,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr link->cookies = cookies; link->cnt = cnt; link->link.flags = flags; + link->inlines = inlines; if (cookies) { /* @@ -2947,12 +3286,23 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr goto error_cleanup; link->mods_cnt = err; - err = register_fprobe_ips(&link->fp, addrs, cnt); - if (err) - goto error_modules; + if (inlines.sites_cnt) { + err = inline_sites_register(link); + if (err) + goto error_modules; + } + + /* All the functions might have just inlined instances. */ + if (cnt) { + err = register_fprobe_ips(&link->fp, addrs, cnt); + if (err) + goto error_inlines; + } return bpf_link_settle(&link_primer); +error_inlines: + unregister_kprobes(link->inlines.kps, link->inlines.cnt); error_modules: kprobe_multi_put_modules(link->mods, link->mods_cnt); error_cleanup: @@ -2963,6 +3313,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr kfree(link); kvfree(addrs); kvfree(cookies); + kvfree(inlines.sites); return err; } #else /* !CONFIG_FPROBE */ diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 28904c6f0787..96e6a629f0c0 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1365,10 +1365,14 @@ enum bpf_perf_event_type { #define BPF_F_TEST_REG_INVARIANTS (1U << 7) /* link_create.kprobe_multi.flags used in LINK_CREATE command for - * BPF_TRACE_KPROBE_MULTI attach type to create return probe. + * BPF_TRACE_KPROBE_MULTI attach type. */ enum { - BPF_F_KPROBE_MULTI_RETURN = (1U << 0) + /* Create return probe. */ + BPF_F_KPROBE_MULTI_RETURN = (1U << 0), + + /* Attach also to inlined function instances, skip those that fail. */ + BPF_F_KPROBE_MULTI_INLINE = (1U << 1), }; /* link_create.uprobe_multi.flags used in LINK_CREATE command for -- 2.56.1