From nobody Fri Feb 13 17:30:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D54F132D452; Wed, 11 Feb 2026 08:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799757; cv=none; b=OogBKQXKd3HGgSaiuY0KJuT5pFv9Cc7Rfmft6FFwoprdbpEyDvHZWGE3vKhjSwWKH600KUAsIPFv1yEr8vlDFfrDls0W1VuTHzMDlIhgX4XC9vD8uTmlhZ6MmKAXV4APjdt3kowqNyB7NeSFPThQU0+/jKXfKibjDwOpBw9R6+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799757; c=relaxed/simple; bh=DQxx4sQpSRlmKFD8OqooGbohxZ8Wbb2yF5Xw1ruqRyM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dYqe0r7XZsw0YEtrJK5sa5l0MorAmJB+dIy+i7XDnBcphNWH9IX6h/o5aBaMGknTs6y6W22ISFSMJlKjzanRNIIL8VjlJZpx1fM5NWzPSCbzTTfVwa/pZThG7SZnQrqQ5QPQk2PmAgqMAsKHoZWyQ2lbu0AGd8AjRGuQ+rJH+GU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CtEoCmEu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CtEoCmEu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33168C19424; Wed, 11 Feb 2026 08:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770799757; bh=DQxx4sQpSRlmKFD8OqooGbohxZ8Wbb2yF5Xw1ruqRyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CtEoCmEuIQYkf44CTRIYkvvBx+oRL9t4k8OhMF0fiZQ2ZrtJIoaQO79zQVL2yzl7d YRpPNBf4NEJlNkaEJI5CHzHxVEEiqXDuwPjsD78GBozOBkeWq6J09Pop2UnAAgylxd kOGh8OGo5i1KvYHHyZ3ipVAyZfH6Y8k6nudQEoj9Tari74h0sKVMJ2fx97MAVMfJXN FXWtgt7LCZfQD/21QgAdRGZnQYbEFzRCNkIfzEvVjpHnODFXzk2Fgn5fgJo9R1IgUa T0ypFr7osDA20BKtEaZzLMs9Lbp0U3pncTIEfpTG+g60YPvqrM5nSnYL95apiab/hx ++6Y+WUDAkMRQ== From: Jiri Olsa To: Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend Subject: [PATCHv3 bpf-next 1/5] selftests/bpf: Emit nop,nop5 instructions combo for x86_64 arch Date: Wed, 11 Feb 2026 09:48:54 +0100 Message-ID: <20260211084858.750950-2-jolsa@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260211084858.750950-1-jolsa@kernel.org> References: <20260211084858.750950-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Syncing latest usdt.h change [1]. Now that we have nop5 optimization support in kernel, let's emit nop,nop5 for usdt probe. We leave it up to the library to use desirable nop instruction. [1] https://github.com/libbpf/usdt/commit/c9865d158984fb2b73e3cbbdcdfb4f583= ad36a73 Signed-off-by: Jiri Olsa --- tools/testing/selftests/bpf/usdt.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/bpf/usdt.h b/tools/testing/selftests/b= pf/usdt.h index 549d1f774810..c71e21df38b3 100644 --- a/tools/testing/selftests/bpf/usdt.h +++ b/tools/testing/selftests/bpf/usdt.h @@ -312,6 +312,8 @@ struct usdt_sema { volatile unsigned short active; }; #ifndef USDT_NOP #if defined(__ia64__) || defined(__s390__) || defined(__s390x__) #define USDT_NOP nop 0 +#elif defined(__x86_64__) +#define USDT_NOP .byte 0x90, 0x0f, 0x1f, 0x44, 0x00,= 0x0 /* nop, nop5 */ #else #define USDT_NOP nop #endif --=20 2.53.0 From nobody Fri Feb 13 17:30:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE53D23BD1B; Wed, 11 Feb 2026 08:49:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799766; cv=none; b=Vsf9kiQj6tp1OZBd0wcYhU2pHFI8NvWNKBSfwJCLXXdj8IK12F5AtbJI1k8LVxq/nNinKXE9NN4suD6Lbg8GtJTpu8cac7usaDVCTdHKWdWeBF6Cp29wH5ALen+AD+YJKnq22eiE19ylKA0BPy4rtLSwhEr/Dd9BV0R03DxXvNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799766; c=relaxed/simple; bh=S29y+uuqZrMgOo1hWvanWYe+TzfNJHT+V3QfZUY1MX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fRFZm4190oIAd8aDMFLUXsg0oKltq1gESWYdm59cpi0QJm0fZgd2cEGq+EmZY0agCrRiP7sw4lkJHOmzhN4otfbzNVJ9n2Z+C/JYO9mvbabMHNrKVf9IHK0VaubqMl1pSDrcUbXN3ezfQNJUf6mPG+F7xtlFeKkJUOuSGJzKf4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c31jckCQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c31jckCQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5AA1C4CEF7; Wed, 11 Feb 2026 08:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770799766; bh=S29y+uuqZrMgOo1hWvanWYe+TzfNJHT+V3QfZUY1MX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c31jckCQ9RypyXjw7tNKjmdji0Iey4BEfNNq3qHJjEE7ZIzUoYrjeDvKH1cOpWR3a nZkqfxStXBogU5AlvjDu+wsqrSDfrziTkf84T4bZ3iq2Kv78jAv+yvKDDNXyob5ifX GME5p9WkNZe5JQC/8k5PvUi94dBvp8F6k18I+mCQfzS/nGueoQ4LI/9XcMV9qNyEoA qrIRxf7HHWsc9XYxA+AdRWi9aHQSI1HounUStWZwLUafRjbmXyeXu+9Z0++tHlr2n7 8aR4/XHMO5QZXLJT6Sb0FQ9itCUlnQyzE8419RzQis35brm92sECWxyS5QhAbYvzqR ykgkG7cxYNloA== From: Jiri Olsa To: Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend Subject: [PATCHv3 bpf-next 2/5] libbpf: Add uprobe syscall feature detection Date: Wed, 11 Feb 2026 09:48:55 +0100 Message-ID: <20260211084858.750950-3-jolsa@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260211084858.750950-1-jolsa@kernel.org> References: <20260211084858.750950-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adding uprobe syscall feature detection that will be used in following changes. Signed-off-by: Jiri Olsa --- tools/lib/bpf/features.c | 24 ++++++++++++++++++++++++ tools/lib/bpf/libbpf_internal.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c index b842b83e2480..04a225c7f2c0 100644 --- a/tools/lib/bpf/features.c +++ b/tools/lib/bpf/features.c @@ -506,6 +506,27 @@ static int probe_kern_arg_ctx_tag(int token_fd) return probe_fd(prog_fd); } =20 +#ifdef __x86_64__ + +#ifndef __NR_uprobe +#define __NR_uprobe 336 +#endif + +static int probe_uprobe_syscall(int token_fd) +{ + /* + * If kernel supports uprobe() syscall, it will return -ENXIO when called + * from the outside of a kernel-generated uprobe trampoline. + */ + return syscall(__NR_uprobe) < 0 && errno =3D=3D ENXIO; +} +#else +static int probe_uprobe_syscall(int token_fd) +{ + return 0; +} +#endif + typedef int (*feature_probe_fn)(int /* token_fd */); =20 static struct kern_feature_cache feature_cache; @@ -581,6 +602,9 @@ static struct kern_feature_desc { [FEAT_BTF_QMARK_DATASEC] =3D { "BTF DATASEC names starting from '?'", probe_kern_btf_qmark_datasec, }, + [FEAT_UPROBE_SYSCALL] =3D { + "Kernel supports uprobe syscall", probe_uprobe_syscall, + }, }; =20 bool feat_supported(struct kern_feature_cache *cache, enum kern_feature_id= feat_id) diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_interna= l.h index fc59b21b51b5..69aa61c038a9 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -392,6 +392,8 @@ enum kern_feature_id { FEAT_ARG_CTX_TAG, /* Kernel supports '?' at the front of datasec names */ FEAT_BTF_QMARK_DATASEC, + /* Kernel supports uprobe syscall */ + FEAT_UPROBE_SYSCALL, __FEAT_CNT, }; =20 --=20 2.53.0 From nobody Fri Feb 13 17:30:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFEA323BD1B; Wed, 11 Feb 2026 08:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799775; cv=none; b=cG6nH572utHyRNtdQ4saMEd6NVDM2oiJQeXm1PBw+5Z1RAo1utsDmJ5/C3gaLTGuMhu3qukUovHdAU69icWA5aNE1xFzqtslqwxO1l2UbzN3fJ41sYsKxkLVXn5uOa5J6BaavQvVAs7dtnEzCNmx4sjGvuFjh0K+zIB2NuQVQZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799775; c=relaxed/simple; bh=/e5FLaITB6aTJI/Ft1Jn5QjDQwpwtZrhk8oW4a8Zxes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eHBl2hh3iEJ9lBRQ+X0B3opAG/7HF4Mf64XnxrNzXTTNKidUYEsj0R2rHOPVlcfJNU8VldZQ0YeSCTjLrHpaG6BetSJxeshQuCRjyTTC2/HwlsS++iO3QTzLDRjEpDNecndT8BURgpjmdXfb71+T0eSM5+X7/NIEfgI0JDq4TnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jYCU4cGC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jYCU4cGC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3D4EC4CEF7; Wed, 11 Feb 2026 08:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770799775; bh=/e5FLaITB6aTJI/Ft1Jn5QjDQwpwtZrhk8oW4a8Zxes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jYCU4cGCa4nW3m/zHJPw33tugNASNyF9Snu4FBajL+qpoWv1L49BIhNnP/NWyD+cO hVlQFREDGZW6pLbX27NwF2xXxRo/56y+J/V2R8+dX9/EfrdVrPG9SRRUV7ckTdxwbZ oSSroDdh32+FluBFRPANkQmFO7BoMPJdg9OqwCwnV6G58ZOcVmU33cliEF5Nf9YxlD aIHsT0uJPji4OosQlhF74l95ciF7WEaqj67/52JMiLmRptGtQQIwhh8Vp1ZY/cOjB2 Wr6jHbTW7R23AlSYmPRBTiYHid2BCjywm9OcG+jMR3caw9AuPeAvMgjf3iTeCcG6l/ /OCyHUyiPLzKA== From: Jiri Olsa To: Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend Subject: [PATCHv3 bpf-next 3/5] libbpf: Add support to detect nop,nop5 instructions combo for usdt probe Date: Wed, 11 Feb 2026 09:48:56 +0100 Message-ID: <20260211084858.750950-4-jolsa@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260211084858.750950-1-jolsa@kernel.org> References: <20260211084858.750950-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adding support to detect nop,nop5 instructions combo for usdt probe by checking on probe's following nop5 instruction. When the nop,nop5 combo is detected together with uprobe syscall, we can place the probe on top of nop5 and get it optimized. [1] https://github.com/libbpf/usdt Signed-off-by: Jiri Olsa --- tools/lib/bpf/usdt.c | 55 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c index d1524f6f54ae..4e5f70bb4c31 100644 --- a/tools/lib/bpf/usdt.c +++ b/tools/lib/bpf/usdt.c @@ -262,6 +262,7 @@ struct usdt_manager { bool has_bpf_cookie; bool has_sema_refcnt; bool has_uprobe_multi; + bool has_uprobe_syscall; }; =20 struct usdt_manager *usdt_manager_new(struct bpf_object *obj) @@ -301,6 +302,13 @@ struct usdt_manager *usdt_manager_new(struct bpf_objec= t *obj) * usdt probes. */ man->has_uprobe_multi =3D kernel_supports(obj, FEAT_UPROBE_MULTI_LINK); + + /* + * Detect kernel support for uprobe() syscall, it's presence means we can + * take advantage of faster nop5 uprobe handling. + * Added in: 56101b69c919 ("uprobes/x86: Add uprobe syscall to speed up u= probe") + */ + man->has_uprobe_syscall =3D kernel_supports(obj, FEAT_UPROBE_SYSCALL); return man; } =20 @@ -585,13 +593,42 @@ static int parse_usdt_note(GElf_Nhdr *nhdr, const cha= r *data, size_t name_off, =20 static int parse_usdt_spec(struct usdt_spec *spec, const struct usdt_note = *note, __u64 usdt_cookie); =20 -static int collect_usdt_targets(struct usdt_manager *man, Elf *elf, const = char *path, pid_t pid, - const char *usdt_provider, const char *usdt_name, __u64 usdt_cookie, - struct usdt_target **out_targets, size_t *out_target_cnt) +#if defined(__x86_64__) +static bool has_nop_combo(int fd, long off) +{ + static unsigned char nop_combo[6] =3D { + 0x90, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nop,nop5 */ + }; + unsigned char buf[6] =3D {}; + + /* + * We are using file descriptor that backs Elf object, + * let's dup it to be on the safe side. + */ + fd =3D dup(fd); + if (fd < 0) + return false; + if (lseek(fd, off, SEEK_SET) =3D=3D off) + read(fd, buf, 6); + close(fd); + return memcmp(buf, nop_combo, 6) =3D=3D 0; +} +#else +static bool has_nop_combo(int fd, long off) +{ + return false; +} +#endif + +static int collect_usdt_targets(struct usdt_manager *man, struct elf_fd *e= lf_fd, const char *path, + pid_t pid, const char *usdt_provider, const char *usdt_name, + __u64 usdt_cookie, struct usdt_target **out_targets, + size_t *out_target_cnt) { size_t off, name_off, desc_off, seg_cnt =3D 0, vma_seg_cnt =3D 0, target_= cnt =3D 0; struct elf_seg *segs =3D NULL, *vma_segs =3D NULL; struct usdt_target *targets =3D NULL, *target; + Elf *elf =3D elf_fd->elf; long base_addr =3D 0; Elf_Scn *notes_scn, *base_scn; GElf_Shdr base_shdr, notes_shdr; @@ -784,6 +821,16 @@ static int collect_usdt_targets(struct usdt_manager *m= an, Elf *elf, const char * target =3D &targets[target_cnt]; memset(target, 0, sizeof(*target)); =20 + /* + * We have uprobe syscall and usdt with nop,nop5 instructions combo, + * so we can place the uprobe directly on nop5 (+1) and get this probe + * optimized. + */ + if (man->has_uprobe_syscall && has_nop_combo(elf_fd->fd, usdt_rel_ip)) { + usdt_abs_ip++; + usdt_rel_ip++; + } + target->abs_ip =3D usdt_abs_ip; target->rel_ip =3D usdt_rel_ip; target->sema_off =3D usdt_sema_off; @@ -998,7 +1045,7 @@ struct bpf_link *usdt_manager_attach_usdt(struct usdt_= manager *man, const struct /* discover USDT in given binary, optionally limiting * activations to a given PID, if pid > 0 */ - err =3D collect_usdt_targets(man, elf_fd.elf, path, pid, usdt_provider, u= sdt_name, + err =3D collect_usdt_targets(man, &elf_fd, path, pid, usdt_provider, usdt= _name, usdt_cookie, &targets, &target_cnt); if (err <=3D 0) { err =3D (err =3D=3D 0) ? -ENOENT : err; --=20 2.53.0 From nobody Fri Feb 13 17:30:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC5582C21F4; Wed, 11 Feb 2026 08:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799784; cv=none; b=ms+OGfKo1yIBGT/nT4jX5kzLIjJD5IXnhkCAQ6vMlZyrpnH4adLLEkWuMLoC1p9g9H4C5fKROwNTXTK+cFFdMp+sKxL6xdPDSnapabAHoG1+re3l4G0SoP0MQixW/rMIPFw5D7mUzXdbFBTBwEGE19yg+xu75LlahAIGM9JYKFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799784; c=relaxed/simple; bh=PpSC3jb5W1sy4VMa3Ob2gZonc/94SlYNf2jyVhLH5X4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tMlMK5IcTT2r2Y8ghJwF7RXX7FbAOb6VxfTlTpNKAMmRgYWUA+7ysRrlPWNp0CzwfBMtSkYxsnL7V3U6PwXajE0YD7YvlL9rh+CEvrX5eB1DrYIzs1oAdrGQC+AT092O2lnTDBPTrsH7TQ/uaYWlAgy/asYW+Ax75tP/y+xUXh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V2eecAAz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V2eecAAz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91B5EC4CEF7; Wed, 11 Feb 2026 08:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770799784; bh=PpSC3jb5W1sy4VMa3Ob2gZonc/94SlYNf2jyVhLH5X4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V2eecAAzVNMQLhfG4UvqJZ6mwDgHI5l8o0YcthWf4pKwW57JlDWC2mJkgCEjHPdUw /MWEpDjvK+mmNmAgZr8sC5qsS2Hs20l1YRNIxAH2RX9zPT5f5+bTkDzeGXdjsfxPCd J6HhtKvyxevoQeeuZ1U5+iBhvJ6hSJnrjRMa8vOd+l+0SH/FguEbB4ZHcIRNvUtbSD UOqkWG3qMygv9MORSvqLhY474nNPyHxFUHhdrjCsqsSVYJeKOKX8QicarexwHoShT7 tiAI0xgq6rWqxKCpIQZiBgknAxDrNdUYK4La2629KA9BN51z1GY02UHY3q4TWPd77A +R+yyCKX3MEJg== From: Jiri Olsa To: Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend Subject: [PATCHv3 bpf-next 4/5] selftests/bpf: Add test for checking correct nop of optimized usdt Date: Wed, 11 Feb 2026 09:48:57 +0100 Message-ID: <20260211084858.750950-5-jolsa@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260211084858.750950-1-jolsa@kernel.org> References: <20260211084858.750950-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adding test that attaches bpf program on usdt probe in 2 scenarios; - attach program on top of usdt_1, which is single nop instruction, so the probe stays on nop instruction and is not optimized. - attach program on top of usdt_2 which is probe defined on top of nop,nop5 combo, so the probe is placed on top of nop5 and is optimized. Signed-off-by: Jiri Olsa --- tools/testing/selftests/bpf/.gitignore | 2 + tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/prog_tests/usdt.c | 85 +++++++++++++++++++ tools/testing/selftests/bpf/progs/test_usdt.c | 9 ++ tools/testing/selftests/bpf/usdt_1.c | 18 ++++ tools/testing/selftests/bpf/usdt_2.c | 16 ++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/usdt_1.c create mode 100644 tools/testing/selftests/bpf/usdt_2.c diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftes= ts/bpf/.gitignore index a3ea98211ea6..bfdc5518ecc8 100644 --- a/tools/testing/selftests/bpf/.gitignore +++ b/tools/testing/selftests/bpf/.gitignore @@ -47,3 +47,5 @@ verification_cert.h *.BTF *.BTF_ids *.BTF.base +usdt_1 +usdt_2 diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index c6bf4dfb1495..306949162a5b 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -749,7 +749,8 @@ TRUNNER_EXTRA_SOURCES :=3D test_progs.c \ $(VERIFY_SIG_HDR) \ flow_dissector_load.h \ ip_check_defrag_frags.h \ - bpftool_helpers.c + bpftool_helpers.c \ + usdt_1.c usdt_2.c TRUNNER_LIB_SOURCES :=3D find_bit.c TRUNNER_EXTRA_FILES :=3D $(OUTPUT)/urandom_read \ $(OUTPUT)/liburandom_read.so \ diff --git a/tools/testing/selftests/bpf/prog_tests/usdt.c b/tools/testing/= selftests/bpf/prog_tests/usdt.c index f4be5269fa90..6daed3dfa75b 100644 --- a/tools/testing/selftests/bpf/prog_tests/usdt.c +++ b/tools/testing/selftests/bpf/prog_tests/usdt.c @@ -247,6 +247,89 @@ static void subtest_basic_usdt(bool optimized) #undef TRIGGER } =20 +#ifdef __x86_64__ +extern void usdt_1(void); +extern void usdt_2(void); + +/* nop, nop5 */ +static unsigned char nop1_nop5_combo[6] =3D { 0x90, 0x0f, 0x1f, 0x44, 0x00= , 0x00 }; +static unsigned char nop1[6] =3D { 0x90 }; + +static void *find_instr(void *fn, unsigned char *instr, size_t cnt) +{ + int i; + + for (i =3D 0; i < 10; i++) { + if (!memcmp(instr, fn + i, cnt)) + return fn + i; + } + return NULL; +} + +static void subtest_optimized_attach(void) +{ + struct test_usdt *skel; + __u8 *addr_1, *addr_2; + + /* usdt_1 USDT probe has single nop instruction */ + addr_1 =3D find_instr(usdt_1, nop1_nop5_combo, 6); + if (!ASSERT_NULL(addr_1, "usdt_1_find_nop1_nop5_combo")) + return; + + addr_1 =3D find_instr(usdt_1, nop1, 1); + if (!ASSERT_OK_PTR(addr_1, "usdt_1_find_nop1")) + return; + + /* usdt_1 USDT probe has nop,nop5 instructions combo */ + addr_2 =3D find_instr(usdt_2, nop1_nop5_combo, 6); + if (!ASSERT_OK_PTR(addr_2, "usdt_2_find_nop1_nop5_combo")) + return; + + skel =3D test_usdt__open_and_load(); + if (!ASSERT_OK_PTR(skel, "test_usdt__open_and_load")) + return; + + /* + * Attach program on top of usdt_1 which is single nop probe, + * so the probe won't get optimized. + */ + skel->links.usdt_executed =3D bpf_program__attach_usdt(skel->progs.usdt_e= xecuted, + 0 /*self*/, "/proc/self/exe", + "optimized_attach", "usdt_1", NULL); + if (!ASSERT_OK_PTR(skel->links.usdt_executed, "bpf_program__attach_usdt")) + goto cleanup; + + usdt_1(); + usdt_1(); + + /* nop is on addr_1 address */ + ASSERT_EQ(*addr_1, 0xcc, "int3"); + ASSERT_EQ(skel->bss->executed, 2, "executed"); + + bpf_link__destroy(skel->links.usdt_executed); + + /* + * Attach program on top of usdt_2 which is probe defined on top + * of nop1,nop5 combo, so the probe gets optimized on top of nop5. + */ + skel->links.usdt_executed =3D bpf_program__attach_usdt(skel->progs.usdt_e= xecuted, + 0 /*self*/, "/proc/self/exe", + "optimized_attach", "usdt_2", NULL); + if (!ASSERT_OK_PTR(skel->links.usdt_executed, "bpf_program__attach_usdt")) + goto cleanup; + + usdt_2(); + usdt_2(); + + /* nop5 is on addr_2 + 1 address */ + ASSERT_EQ(*(addr_2 + 1), 0xe8, "call"); + ASSERT_EQ(skel->bss->executed, 4, "executed"); + +cleanup: + test_usdt__destroy(skel); +} +#endif + unsigned short test_usdt_100_semaphore SEC(".probes"); unsigned short test_usdt_300_semaphore SEC(".probes"); unsigned short test_usdt_400_semaphore SEC(".probes"); @@ -516,6 +599,8 @@ void test_usdt(void) #ifdef __x86_64__ if (test__start_subtest("basic_optimized")) subtest_basic_usdt(true); + if (test__start_subtest("optimized_attach")) + subtest_optimized_attach(); #endif if (test__start_subtest("multispec")) subtest_multispec_usdt(); diff --git a/tools/testing/selftests/bpf/progs/test_usdt.c b/tools/testing/= selftests/bpf/progs/test_usdt.c index a78c87537b07..6911868cdf67 100644 --- a/tools/testing/selftests/bpf/progs/test_usdt.c +++ b/tools/testing/selftests/bpf/progs/test_usdt.c @@ -138,4 +138,13 @@ int usdt_sib(struct pt_regs *ctx) return 0; } =20 +int executed; + +SEC("usdt") +int usdt_executed(struct pt_regs *ctx) +{ + executed++; + return 0; +} + char _license[] SEC("license") =3D "GPL"; diff --git a/tools/testing/selftests/bpf/usdt_1.c b/tools/testing/selftests= /bpf/usdt_1.c new file mode 100644 index 000000000000..4f06e8bcf58b --- /dev/null +++ b/tools/testing/selftests/bpf/usdt_1.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 + +#if defined(__x86_64__) + +/* + * Include usdt.h with defined USDT_NOP macro to use single + * nop instruction. + */ +#define USDT_NOP .byte 0x90 +#include "usdt.h" + +__attribute__((aligned(16))) +void usdt_1(void) +{ + USDT(optimized_attach, usdt_1); +} + +#endif diff --git a/tools/testing/selftests/bpf/usdt_2.c b/tools/testing/selftests= /bpf/usdt_2.c new file mode 100644 index 000000000000..789883aaca4c --- /dev/null +++ b/tools/testing/selftests/bpf/usdt_2.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +#if defined(__x86_64__) + +/* + * Include usdt.h with default nop,nop5 instructions combo. + */ +#include "usdt.h" + +__attribute__((aligned(16))) +void usdt_2(void) +{ + USDT(optimized_attach, usdt_2); +} + +#endif --=20 2.53.0 From nobody Fri Feb 13 17:30:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7FDC34F46F; Wed, 11 Feb 2026 08:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799794; cv=none; b=q/QcPgx+u7u7CXzZSbaKpCq+raxbqNd54Xx0AGgbjNIhr0mcoBKcY3prMRo0C1stEdZ3U4eFH+OiDat/WeKgOV4Kqq06dSZFkh4xS8cB71+vLN7g96e3Fw33Udt9ajhUdqv/WlrtDybU8FB96SwYZWZy4oq9NTDFXyMHDx42biM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770799794; c=relaxed/simple; bh=tm8jIm/op7KXojpHNfv0TiK5xp5jE9hh1pFrepEOWO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e+h+9sNJUDuvcFdt/0guNuF/KcnoiBCQi9cbJIkv7I7LlqXMGgT/W2zfHMVZi1pU/cSHxnnDlNW8G+cGeRaj9+xRdlxPMc82zpMm5viM93w/hftsc5r/fNYK9blhQ0r2DprCI95881F6grteCaHJD0prr9DPF5TTFaJIaJozF/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aw3A8jOG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aw3A8jOG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9B9DC4CEF7; Wed, 11 Feb 2026 08:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770799794; bh=tm8jIm/op7KXojpHNfv0TiK5xp5jE9hh1pFrepEOWO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aw3A8jOGk11zeCEhYkjR42mjjT8pf1bgBThQQA8NDvYiba/pcHBlQPNMd5H7Wxmz9 3ccUG6cw3iB7yspEHFbL/Jb+Fhe3SZrVVyXps/02LdKvHfCG9VrJwnbyadICtHgcLy 4LqXh6w44a2as0QBjL6ndI9uwICf29RuR/x27nvOyDtLFPwAzkeg8sQrRCvGEQKsII RjsY+3RzW1kYJesyMz7VXop6FvCBiX1GGJdmvMIfGM54YjQ+peL4v+NfdfuiYbZoHd ZvK8BhTr45tFVnMyB577fKbSJ5NJA8B+a7vsf3RWeZAwY332vOO8A7oSCdCIolAanE /7uSNDZt01iXg== From: Jiri Olsa To: Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend Subject: [PATCHv3 bpf-next 5/5] selftests/bpf: Add usdt trigger bench Date: Wed, 11 Feb 2026 09:48:58 +0100 Message-ID: <20260211084858.750950-6-jolsa@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260211084858.750950-1-jolsa@kernel.org> References: <20260211084858.750950-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Adding usdt trigger bench for usdt: trig-usdt_nop - usdt on top of nop1 instruction trig-usdt_nop_combo - usdt on top of nop1/nop5 combo Adding it to benchs/run_bench_uprobes.sh script. Example run on x86_64 kernel with uprobe syscall: # ./benchs/run_bench_uprobes.sh usermode-count : 152.507 =C2=B1 0.098M/s syscall-count : 14.309 =C2=B1 0.093M/s uprobe-nop : 3.190 =C2=B1 0.012M/s uprobe-push : 3.057 =C2=B1 0.004M/s uprobe-ret : 1.095 =C2=B1 0.009M/s uprobe-nop5 : 7.305 =C2=B1 0.034M/s uretprobe-nop : 2.175 =C2=B1 0.005M/s uretprobe-push : 2.109 =C2=B1 0.003M/s uretprobe-ret : 0.945 =C2=B1 0.002M/s uretprobe-nop5 : 3.530 =C2=B1 0.006M/s usdt_nop : 3.235 =C2=B1 0.008M/s <-- added usdt_nop_combo : 7.511 =C2=B1 0.045M/s <-- added Signed-off-by: Jiri Olsa --- tools/testing/selftests/bpf/Makefile | 2 + tools/testing/selftests/bpf/bench.c | 4 ++ .../selftests/bpf/benchs/bench_trigger.c | 60 +++++++++++++++++++ .../selftests/bpf/benchs/run_bench_uprobes.sh | 2 +- .../selftests/bpf/progs/trigger_bench.c | 10 +++- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index 306949162a5b..9b2ca0028322 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -874,6 +874,8 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o \ $(OUTPUT)/bench_bpf_crypto.o \ $(OUTPUT)/bench_sockmap.o \ $(OUTPUT)/bench_lpm_trie_map.o \ + $(OUTPUT)/usdt_1.o \ + $(OUTPUT)/usdt_2.o \ # $(call msg,BINARY,,$@) $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@ diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/= bpf/bench.c index 8368bd3a0665..4dacb87e464e 100644 --- a/tools/testing/selftests/bpf/bench.c +++ b/tools/testing/selftests/bpf/bench.c @@ -541,6 +541,8 @@ extern const struct bench bench_trig_uprobe_nop5; extern const struct bench bench_trig_uretprobe_nop5; extern const struct bench bench_trig_uprobe_multi_nop5; extern const struct bench bench_trig_uretprobe_multi_nop5; +extern const struct bench bench_trig_usdt_nop; +extern const struct bench bench_trig_usdt_nop_combo; #endif =20 extern const struct bench bench_rb_libbpf; @@ -617,6 +619,8 @@ static const struct bench *benchs[] =3D { &bench_trig_uretprobe_nop5, &bench_trig_uprobe_multi_nop5, &bench_trig_uretprobe_multi_nop5, + &bench_trig_usdt_nop, + &bench_trig_usdt_nop_combo, #endif /* ringbuf/perfbuf benchmarks */ &bench_rb_libbpf, diff --git a/tools/testing/selftests/bpf/benchs/bench_trigger.c b/tools/tes= ting/selftests/bpf/benchs/bench_trigger.c index aeec9edd3851..b4b03fe1f61d 100644 --- a/tools/testing/selftests/bpf/benchs/bench_trigger.c +++ b/tools/testing/selftests/bpf/benchs/bench_trigger.c @@ -405,6 +405,23 @@ static void *uprobe_producer_nop5(void *input) uprobe_target_nop5(); return NULL; } + +void usdt_1(void); +void usdt_2(void); + +static void *uprobe_producer_usdt_nop(void *input) +{ + while (true) + usdt_1(); + return NULL; +} + +static void *uprobe_producer_usdt_nop_combo(void *input) +{ + while (true) + usdt_2(); + return NULL; +} #endif =20 static void usetup(bool use_retprobe, bool use_multi, void *target_addr) @@ -542,6 +559,47 @@ static void uretprobe_multi_nop5_setup(void) { usetup(true, true /* use_multi */, &uprobe_target_nop5); } + +static void usdt_setup(const char *name) +{ + struct bpf_link *link; + int err; + + setup_libbpf(); + + ctx.skel =3D trigger_bench__open(); + if (!ctx.skel) { + fprintf(stderr, "failed to open skeleton\n"); + exit(1); + } + + bpf_program__set_autoload(ctx.skel->progs.bench_trigger_usdt, true); + + err =3D trigger_bench__load(ctx.skel); + if (err) { + fprintf(stderr, "failed to load skeleton\n"); + exit(1); + } + + link =3D bpf_program__attach_usdt(ctx.skel->progs.bench_trigger_usdt, + 0 /*self*/, "/proc/self/exe", + "optimized_attach", name, NULL); + if (libbpf_get_error(link)) { + fprintf(stderr, "failed to attach optimized_attach:%s usdt probe\n", nam= e); + exit(1); + } + ctx.skel->links.bench_trigger_usdt =3D link; +} + +static void usdt_nop_setup(void) +{ + usdt_setup("usdt_1"); +} + +static void usdt_nop_combo_setup(void) +{ + usdt_setup("usdt_2"); +} #endif =20 const struct bench bench_trig_syscall_count =3D { @@ -609,4 +667,6 @@ BENCH_TRIG_USERMODE(uprobe_nop5, nop5, "uprobe-nop5"); BENCH_TRIG_USERMODE(uretprobe_nop5, nop5, "uretprobe-nop5"); BENCH_TRIG_USERMODE(uprobe_multi_nop5, nop5, "uprobe-multi-nop5"); BENCH_TRIG_USERMODE(uretprobe_multi_nop5, nop5, "uretprobe-multi-nop5"); +BENCH_TRIG_USERMODE(usdt_nop, usdt_nop, "usdt_nop"); +BENCH_TRIG_USERMODE(usdt_nop_combo, usdt_nop_combo, "usdt_nop_combo"); #endif diff --git a/tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh b/tool= s/testing/selftests/bpf/benchs/run_bench_uprobes.sh index 03f55405484b..3656676d99d2 100755 --- a/tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh +++ b/tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh @@ -2,7 +2,7 @@ =20 set -eufo pipefail =20 -for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop= 5} +for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop= 5} usdt_nop usdt_nop_combo do summary=3D$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | = cut -d' ' -f3-) printf "%-15s: %s\n" $i "$summary" diff --git a/tools/testing/selftests/bpf/progs/trigger_bench.c b/tools/test= ing/selftests/bpf/progs/trigger_bench.c index 4ea0422d1042..3225b4aee8ff 100644 --- a/tools/testing/selftests/bpf/progs/trigger_bench.c +++ b/tools/testing/selftests/bpf/progs/trigger_bench.c @@ -1,10 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2020 Facebook -#include +#include "vmlinux.h" #include #include #include #include "bpf_misc.h" +#include "bpf/usdt.bpf.h" =20 char _license[] SEC("license") =3D "GPL"; =20 @@ -180,3 +181,10 @@ int bench_trigger_rawtp(void *ctx) handle(ctx); return 0; } + +SEC("?usdt") +int bench_trigger_usdt(void *ctx) +{ + inc_counter(); + return 0; +} --=20 2.53.0