From: Leon Hwang <leon.hwang@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
kernel-patches-bot@fb.com
Subject: Re: [PATCH bpf-next 1/2] bpf: Support fentry/fexit for functions with union args
Date: Fri, 12 Sep 2025 10:52:30 +0800 [thread overview]
Message-ID: <d704311e-1302-4b14-8993-f5b626d41d46@linux.dev> (raw)
In-Reply-To: <CAADnVQ+uk+sqZhYPJu78NETidUiCa617Wa_YdnmvefOZnNoeZg@mail.gmail.com>
On 10/9/25 08:54, Alexei Starovoitov wrote:
> On Fri, Sep 5, 2025 at 6:32 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>>
>> Currently, functions with 'union' arguments cannot be traced with
>> fentry/fexit:
>
> union-s passed _by value_.
> It's an important detail.
>
>>
>> bpftrace -e 'fentry:release_pages { exit(); }' -v
>> AST node count: 6
>> Attaching 1 probe...
>> ERROR: Error loading BPF program for fentry_vmlinux_release_pages_1.
>> Kernel error log:
>> The function release_pages arg0 type UNION is unsupported.
>> processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
>>
>> ERROR: Loading BPF object(s) failed.
>>
>> The type of the 'release_pages' argument is defined as:
>>
>> typedef union {
>> struct page **pages;
>> struct folio **folios;
>> struct encoded_page **encoded_pages;
>> } release_pages_arg __attribute__ ((__transparent_union__));
>>
>> This patch relaxes the restriction by allowing function arguments of type
>> 'union' to be traced.
>>
>> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
>> ---
>> kernel/bpf/btf.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index 64739308902f7..86883b3c97d20 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -6762,7 +6762,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
>> /* skip modifiers */
>> while (btf_type_is_modifier(t))
>> t = btf_type_by_id(btf, t->type);
>> - if (btf_type_is_small_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
>> + if (btf_type_is_small_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
>> /* accessing a scalar */
>> return true;
>> if (!btf_type_is_ptr(t)) {
>> @@ -7334,7 +7334,7 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
>> if (btf_type_is_ptr(t))
>> /* kernel size of pointer. Not BPF's size of pointer*/
>> return sizeof(void *);
>> - if (btf_type_is_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
>> + if (btf_type_is_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
>> return t->size;
>
> Did you look at
> commit 720e6a435194 ("bpf: Allow struct argument in trampoline based programs")
> that added support for accessing struct passed by value?
>
> Study it and figure out what part of the verifier you forgot
> to update while adding this support for accessing unions
> passed by value.
> Think it through and update the selftest to make sure it tests
> the support end-to-end and covers the bug in this patch.
>
Thanks for pointing this out.
You’re right — support for union arguments should follow the same
approach used for struct arguments in commit
720e6a435194 ("bpf: Allow struct argument in trampoline based
programs"). My current patch was too naive and missed several necessary
updates.
I’ll review that commit carefully, identify what I overlooked, and align
the implementation for unions accordingly.
I’ll also extend the selftests to ensure we have end-to-end coverage and
can catch the kind of bug exposed here.
Thanks,
Leon
next prev parent reply other threads:[~2025-09-12 2:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 13:32 [PATCH bpf-next 0/2] bpf: Support fentry/fexit for functions with union args Leon Hwang
2025-09-05 13:32 ` [PATCH bpf-next 1/2] " Leon Hwang
2025-09-10 0:54 ` Alexei Starovoitov
2025-09-12 2:52 ` Leon Hwang [this message]
2025-09-05 13:32 ` [PATCH bpf-next 2/2] selftests/bpf: Add test to access union argument in tracing program Leon Hwang
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=d704311e-1302-4b14-8993-f5b626d41d46@linux.dev \
--to=leon.hwang@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-patches-bot@fb.com \
--cc=martin.lau@linux.dev \
--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