From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Shuah Khan <shuah@kernel.org>,
Jakub Sitnicki <jakub@cloudflare.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Jiawei Zhao <phoenix500526@163.com>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf 1/2] libbpf: Fix usdt attach failure when nop10 crosses page boundary
Date: Tue, 25 Aug 2026 22:29:15 +0800 [thread overview]
Message-ID: <016aecc5-b3dc-4d8d-be1b-67b9b4b0a24e@linux.dev> (raw)
In-Reply-To: <ao2fomkGLiwm032U@krava>
On 8/25/26 9:58 PM, Jiri Olsa wrote:
> On Mon, Aug 24, 2026 at 05:28:36PM +0800, Jiayuan Chen wrote:
>> The kernel refuses to attach to a nop10 that crosses a page boundary,
>> since it can't be atomically rewritten:
>>
>> /* can_optimize(), arch/x86/kernel/uprobes.c */
>> /* We can't do cross page atomic writes yet. */
>> return PAGE_SIZE - (vaddr & ~PAGE_MASK) >= OPT_INSN_SIZE;
>>
>> Whether the nop10 crosses a page is purely up to the binary layout, so
>> this does happen in practice. libbpf doesn't check for it and blindly
>> shifts the uprobe onto the nop10, and the attach then fails with
>> -ENOTSUPP. Just keep the uprobe on the preceding 1-byte nop in that
>> case, it works everywhere as a regular int3 uprobe.
>>
>> Fixes: 41a5c7df4466 ("libbpf: Add support to detect nop,nop5 instructions combo for usdt probe")
>> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
>> ---
>> tools/lib/bpf/usdt.c | 23 +++++++++++++++++++++--
>> 1 file changed, 21 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
>> index 2e56e3ab5b6c..c266ac93cbdd 100644
>> --- a/tools/lib/bpf/usdt.c
>> +++ b/tools/lib/bpf/usdt.c
>> @@ -614,11 +614,28 @@ static bool has_nop_combo(int fd, long off)
>> return false;
>> return memcmp(buf, nop_combo, 11) == 0;
>> }
>> +
>> +/*
>> + * The kernel refuses to attach to a nop10 that crosses a page boundary,
>> + * as it can't be atomically rewritten. Page offset of the probe is the
>> + * same in the file and in any mapping, so this can be checked statically.
>> + */
>> +static bool nop10_within_page(long off)
>> +{
>> + long page_sz = getpagesize();
>> +
>> + return off % page_sz + 10 <= page_sz;
> could this be another check in has_nop_combo ? so we do not
> need to introduce another stub
>
> otherwise lgtm, thanks
>
> jirka
>
Thanks Jirka
Sound reasonable, I will do it.
next prev parent reply other threads:[~2026-08-25 14:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 9:28 [PATCH bpf 1/2] libbpf: Fix usdt attach failure when nop10 crosses page boundary Jiayuan Chen
2026-08-24 9:28 ` [PATCH bpf 2/2] selftests/bpf: Add test for usdt probe with page-crossing nop10 Jiayuan Chen
2026-08-24 10:03 ` bot+bpf-ci
2026-08-24 10:03 ` [PATCH bpf 1/2] libbpf: Fix usdt attach failure when nop10 crosses page boundary bot+bpf-ci
2026-08-24 10:27 ` Jiayuan Chen
2026-08-25 13:58 ` Jiri Olsa
2026-08-25 14:29 ` Jiayuan Chen [this message]
2026-08-25 18:32 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=016aecc5-b3dc-4d8d-be1b-67b9b4b0a24e@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jakub@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=olsajiri@gmail.com \
--cc=peterz@infradead.org \
--cc=phoenix500526@163.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox