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=1796214735; b=m7bnRa8tDotlReRCChOJeD7kU2s/7ad9kng+w6XJTEnycoyXJwoEiyOmzWXx8eVi3MA6 BUtxNYgVPLyy7YySwehzNLZpZo+JuVZU3crEWzFt30ytfqcLHpfRqmJ+ju1ki0BL+cVpE VwmfW7ktEh6UoXp/3wz9Y4ixYB8IzXmNb46W0wsfKQ3coIgdzQqe+A7+o40DSt1hSprSf QV45LbAYmfu6sPNLTJAz5OwTC8FLoHUGQ1xmUf6MtNvOmJ9rDGTjLKUyOmsa30WiwdG/3 HjgbPdCXoUcxJttPigPKN1xbmO93Jy0zPyyGBWs/349rB+Wq+HeR49dWiWVXw/etohw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214735; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ivK5jrV4abFYC5RZKi+pYhtZpFwc0VnfusN1iICWEmg=; b=4pCTWOiKZUEmGJ1VCRwttosYuZZSeIvUSGTYuNeAUZGEpIOAtVaGRzPqUVdrgqLBgDK7 5UumE6RVgIDtzadgx1chdhvPNum1xOO6ETWeTyEkc6dac0QkxEprVx7VuNTxPcisZl6+b FNFiD6Wr7JXjVaNm/xYX91aRaZ2k49yMXjYfQQNGmOZbpk+pmUwGyq2oqeT8cGwZiLPgW HDyqaoLeJwteSZccf9EXMIx0Cj/jCVus8EQdD/3POEHXj8qfHPTJ802BsvBACKAVM4SqE QokP2qzWm0vUuCwI6wnuQOpcNAAQ+vgwa/9Wh6y3RtfYffli2+uxnxWXU33ULr1dViQ== 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=Oz4ZFGYR; 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 9910A606A322; Wed, 2 Dec 2026 12:32:15 +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=Oz4ZFGYR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 349841F00896; Wed, 2 Dec 2026 12:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214735; bh=ivK5jrV4abFYC5RZKi+pYhtZpFwc0VnfusN1iICWEmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Oz4ZFGYRU3/cAlUQfVy6FEN9HknoawrETpQ8mGl2Co8lY3JHvHHOClIzl6GSBp0Eb ntwOmlRXD4YTNql6IRueTc+DCisHbuRt4Ig1mamMIuRBbAHUm3D2al3LuZyJSQGdIu /HP9fXRCnazzyj71VeiYNuvkOfJwQD5rgJ56vRZguc7QELCsvDUOIsMNLPCCKb9xP5 5of4UIjXFFqV65Ui1VRA5iVN0ZnfuKuXdgjnwDHLUJrfnGKzz2Iil0qa2jyvJnebqV MVpUutOQyM2P00jBxKFiMapRv47uKPxlUedeUX6uBw30DXJNDFaXhob+j8aiO0iAZU UoIk2edWqOLcw== 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 09/31] bpf: Add link info support for kprobe multi inlined functions Date: Wed, 2 Dec 2026 13:30:13 +0100 Message-ID: <20261202123035.10335-10-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-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 info shows just the functions attached with fprobe, the inlined instances are not visible. Adding new fields to struct bpf_link_info for the attached inlined instances: inline_addrs - addresses of the inlined instances inline_cookies - cookies of the inlined instances inline_ids - BTF ids of the inlined functions inline_count - number of the inlined instances inline_skipped - number of instances that could not be attached The BTF id is needed to get the function name, because instances of two functions can share the same address. The arrays have the same semantics as the addrs/cookies arrays, with inline_count as in/out value. Also adding the missed count of the inlined instances to the missed value in the link info. Signed-off-by: Jiri Olsa --- include/uapi/linux/bpf.h | 5 +++ kernel/trace/bpf_trace.c | 70 ++++++++++++++++++++++++++++++++-- tools/include/uapi/linux/bpf.h | 5 +++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 96e6a629f0c0..eee02f62f98b 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -6979,6 +6979,11 @@ struct bpf_link_info { __u32 flags; __u64 missed; __aligned_u64 cookies; + __aligned_u64 inline_addrs; + __aligned_u64 inline_cookies; + __aligned_u64 inline_ids; + __u32 inline_count; /* in/out: kprobe_multi inlined instances count */ + __u32 inline_skipped; } kprobe_multi; struct { __aligned_u64 path; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 15430d72c2a0..2151ae84b18f 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2373,6 +2373,7 @@ struct inline_site { struct bpf_kprobe_multi_link *link; u64 cookie; u32 sym_idx; + u32 func_id; bool has_entry; bool traceable; }; @@ -2494,6 +2495,60 @@ static void bpf_kprobe_multi_link_release(struct bpf_link *link) kprobe_multi_put_modules(kmulti_link->mods, kmulti_link->mods_cnt); } +static unsigned long inline_sites_missed(const struct inline_sites *inlines) +{ + unsigned long missed = 0; + u32 i; + + for (i = 0; i < inlines->cnt; i++) + missed += inlines->kps[i]->nmissed; + return missed; +} + +/* + * Fill addresses, cookies and function BTF ids of attached inlined + * instances, with the same semantics as for the link functions. + */ +static int inline_sites_fill_link_info(const struct inline_sites *inlines, + struct bpf_link_info *info) +{ + u64 __user *ucookies = u64_to_user_ptr(info->kprobe_multi.inline_cookies); + u64 __user *uaddrs = u64_to_user_ptr(info->kprobe_multi.inline_addrs); + u32 __user *uids = u64_to_user_ptr(info->kprobe_multi.inline_ids); + bool show = kallsyms_show_value(current_cred()); + u32 ucount = info->kprobe_multi.inline_count; + const struct inline_site *site; + int err = 0; + u32 i; + + if (!uaddrs ^ !ucount) + return -EINVAL; + if ((ucookies || uids) && !ucount) + return -EINVAL; + + info->kprobe_multi.inline_count = inlines->cnt; + info->kprobe_multi.inline_skipped = inlines->sites_cnt - inlines->cnt; + + if (!uaddrs) + return 0; + if (ucount < inlines->cnt) + err = -ENOSPC; + else + ucount = inlines->cnt; + + for (i = 0; i < ucount; i++) { + site = container_of(inlines->kps[i], struct inline_site, kp); + + if (put_user(show ? (unsigned long)site->kp.addr : 0, uaddrs + i)) + return -EFAULT; + if (ucookies && put_user(site->cookie, ucookies + i)) + return -EFAULT; + if (uids && put_user(site->func_id, uids + i)) + return -EFAULT; + } + return err; +} + static void bpf_kprobe_multi_link_dealloc(struct bpf_link *link) { struct bpf_kprobe_multi_link *kmulti_link; @@ -2524,10 +2579,15 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link, kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link); info->kprobe_multi.count = kmulti_link->cnt; info->kprobe_multi.flags = kmulti_link->link.flags; - info->kprobe_multi.missed = kmulti_link->fp.nmissed; + info->kprobe_multi.missed = kmulti_link->fp.nmissed + + inline_sites_missed(&kmulti_link->inlines); + + err = inline_sites_fill_link_info(&kmulti_link->inlines, info); + if (err && err != -ENOSPC) + return err; if (!uaddrs) - return 0; + return err; if (ucount < kmulti_link->cnt) err = -ENOSPC; else @@ -2904,7 +2964,8 @@ struct inline_lookup { u32 cap; }; -static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr, u32 sym_idx) +static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr, + u32 sym_idx, u32 func_id) { struct inline_site *sites; u32 cap; @@ -2924,6 +2985,7 @@ static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr, u lookup->sites[lookup->cnt++] = (struct inline_site) { .kp.addr = (kprobe_opcode_t *)addr, .sym_idx = sym_idx, + .func_id = func_id, }; return 0; } @@ -2943,7 +3005,7 @@ static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf * idx = inline_sym_idx(btf, loc, lookup->syms, lookup->syms_cnt); if (idx < 0) continue; - err = inline_lookup_add(lookup, base + loc->offset, idx); + err = inline_lookup_add(lookup, base + loc->offset, idx, loc->func); if (err) return err; } diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 96e6a629f0c0..eee02f62f98b 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -6979,6 +6979,11 @@ struct bpf_link_info { __u32 flags; __u64 missed; __aligned_u64 cookies; + __aligned_u64 inline_addrs; + __aligned_u64 inline_cookies; + __aligned_u64 inline_ids; + __u32 inline_count; /* in/out: kprobe_multi inlined instances count */ + __u32 inline_skipped; } kprobe_multi; struct { __aligned_u64 path; -- 2.56.1