BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Woojin Ji <random6.xyz@gmail.com>,
	Quentin Monnet <qmo@kernel.org>,
	bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Song Liu <song@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Jakub Kicinski <kuba@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf] bpftool: Use libbpf error code for flow dissector query
Date: Tue, 2 Jun 2026 12:49:08 -0700	[thread overview]
Message-ID: <22ab9375-e7e6-4929-a80c-0ee9cc74a907@linux.dev> (raw)
In-Reply-To: <18dda63b-79d0-47ad-b60b-82436ae0a017@linux.dev>


On 6/2/26 12:43 PM, Yonghong Song wrote:
>
>
> On 6/2/26 10:03 AM, Woojin Ji wrote:
>> bpf_prog_query() returns a negative errno on failure. 
>> query_flow_dissector()
>> currently closes the namespace fd and then reads errno to decide whether
>> -EINVAL means that the running kernel does not support flow dissector 
>> queries.
>>
>> That errno check controls behavior, not just diagnostics: -EINVAL is 
>> handled
>> as a non-fatal old-kernel case, while any other error makes bpftool 
>> net fail.
>> Reading errno after close() is fragile, because close() can overwrite 
>> errno
>> before the check. Use the libbpf-returned error code instead so the
>
> Do you have evidence that close() is fragile?

The patch itself looks good to me. But it would be great in commit message
to answer why. Note that fd is readonly: fd = open("/proc/self/ns/net", O_RDONLY).

>
>> compatibility branch is based on the BPF_PROG_QUERY result itself.
>>
>> Keep the existing errno reset in the non-fatal path to preserve batch 
>> mode
>> behavior. The success path is unchanged.
>>
>> Fixes: 7f0c57fec80f ("bpftool: show flow_dissector attachment status")
>> Assisted-by: ChatGPT:gpt-5.5
>> Signed-off-by: Woojin Ji <random6.xyz@gmail.com>
>> ---
>>   tools/bpf/bpftool/net.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c
>> index 974189da8a91..dba28755d284 100644
>> --- a/tools/bpf/bpftool/net.c
>> +++ b/tools/bpf/bpftool/net.c
>> @@ -603,14 +603,14 @@ static int query_flow_dissector(struct 
>> bpf_attach_info *attach_info)
>>                    &attach_flags, prog_ids, &prog_cnt);
>>       close(fd);
>>       if (err) {
>> -        if (errno == EINVAL) {
>> +        if (err == -EINVAL) {
>>               /* Older kernel's don't support querying
>>                * flow dissector programs.
>>                */
>>               errno = 0;
>>               return 0;
>>           }
>> -        p_err("can't query prog: %s", strerror(errno));
>> +        p_err("can't query prog: %s", strerror(-err));
>>           return -1;
>>       }
>
>


  reply	other threads:[~2026-06-02 19:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 17:03 [PATCH bpf] bpftool: Use libbpf error code for flow dissector query Woojin Ji
2026-06-02 19:43 ` Yonghong Song
2026-06-02 19:49   ` Yonghong Song [this message]
2026-06-03  0:15     ` Woojin Ji
2026-06-03  0:33     ` [PATCH bpf v2] " Woojin Ji
2026-06-03  1:45       ` Leon Hwang
2026-06-03  3:01       ` Yonghong Song
2026-06-03  9:28         ` Quentin Monnet
2026-06-03 22:40       ` patchwork-bot+netdevbpf

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=22ab9375-e7e6-4929-a80c-0ee9cc74a907@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=qmo@kernel.org \
    --cc=random6.xyz@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    /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