From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf] tools/bpftool: fix PID fetching with a lot of results
Date: Mon, 7 Dec 2020 19:35:23 -0800 [thread overview]
Message-ID: <8f4f8464-2b90-c5f1-0a97-3ff5743ea4d4@fb.com> (raw)
In-Reply-To: <CAEf4BzbE8ddJqj-uwJSJ19vWhgOpd-hbK34+JhdRo1PX-omY_w@mail.gmail.com>
On 12/7/20 6:55 PM, Andrii Nakryiko wrote:
> On Sat, Dec 5, 2020 at 11:11 AM Yonghong Song <yhs@fb.com> wrote:
>>
>>
>>
>> On 12/4/20 3:20 PM, Andrii Nakryiko wrote:
>>> In case of having so many PID results that they don't fit into a singe page
>>> (4096) bytes, bpftool will erroneously conclude that it got corrupted data due
>>> to 4096 not being a multiple of struct pid_iter_entry, so the last entry will
>>> be partially truncated. Fix this by sizing the buffer to fit exactly N entries
>>> with no truncation in the middle of record.
>>>
>>> Fixes: d53dee3fe013 ("tools/bpftool: Show info for processes holding BPF map/prog/link/btf FDs")
>>> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
>>
>> Ack with one nit below.
>>
>> Acked-by: Yonghong Song <yhs@fb.com>
>>
>>> ---
>>> tools/bpf/bpftool/pids.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c
>>> index df7d8ec76036..477e55d59c34 100644
>>> --- a/tools/bpf/bpftool/pids.c
>>> +++ b/tools/bpf/bpftool/pids.c
>>> @@ -89,9 +89,9 @@ libbpf_print_none(__maybe_unused enum libbpf_print_level level,
>>>
>>> int build_obj_refs_table(struct obj_refs_table *table, enum bpf_obj_type type)
>>> {
>>> - char buf[4096];
>>> - struct pid_iter_bpf *skel;
>>> struct pid_iter_entry *e;
>>> + char buf[4096 / sizeof(*e) * sizeof(*e)];
>>> + struct pid_iter_bpf *skel;
>>
>> No need to move "struct pid_iter_bpf *skel", right?
>
> It's actually a move of `struct pid_iter_entry *e;` in from of char
> buf[], to be able to use sizeof(*e) instead of sizeof(struct
> pid_iter_bpf). It's just that diff tool didn't catch this properly :)
Indeed. Looking at the final code, no unnecessary code churn.
>
>>
>>> int err, ret, fd = -1, i;
>>> libbpf_print_fn_t default_print;
>>>
>>>
next prev parent reply other threads:[~2020-12-08 3:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-04 23:20 [PATCH bpf] tools/bpftool: fix PID fetching with a lot of results Andrii Nakryiko
2020-12-05 19:11 ` Yonghong Song
2020-12-08 2:55 ` Andrii Nakryiko
2020-12-08 3:35 ` Yonghong Song [this message]
2020-12-08 15:50 ` 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=8f4f8464-2b90-c5f1-0a97-3ff5743ea4d4@fb.com \
--to=yhs@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.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