From: Yafang Shao <laoar.shao@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Kees Cook <keescook@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
Petr Mladek <pmladek@suse.com>,
Peter Ziljstra <peterz@infradead.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Valentin Schneider <valentin.schneider@arm.com>,
Qiang Zhang <qiang.zhang@windriver.com>,
robdclark <robdclark@chromium.org>,
Christian Brauner <christian@brauner.io>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
john fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
"linux-perf-use." <linux-perf-users@vger.kernel.org>,
linux-fsdevel@vger.kernel.org,
open list <linux-kernel@vger.kernel.org>,
kernel test robot <oliver.sang@intel.com>,
kbuild test robot <lkp@intel.com>
Subject: Re: [PATCH v5 13/15] tools/testing/selftests/bpf: use TASK_COMM_LEN_16 instead of hard-coded 16
Date: Fri, 22 Oct 2021 14:36:00 +0800 [thread overview]
Message-ID: <CALOAHbB6KS8iscsz6y7zd=aGfKfo4jPbyMBKXL4ORY8taZRa8A@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzYTEoDwWzXd91MeMH5Qr9L853Ff3Qq8_wnwfJ8GK0oLnw@mail.gmail.com>
On Fri, Oct 22, 2021 at 6:44 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Oct 20, 2021 at 8:46 PM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > The hard-coded 16 is used in various bpf progs. These progs get task
> > comm either via bpf_get_current_comm() or prctl() or
> > bpf_core_read_str(), all of which can work well even if the task comm size
> > is changed.
> > Below is the detailed information,
> >
> > bpf_get_current_comm:
> > progs/test_ringbuf.c
> > progs/test_ringbuf_multi.c
> >
> > prctl:
> > prog_tests/test_overhead.c
> > prog_tests/trampoline_count.c
> >
> > bpf_core_read_str:
> > progs/test_core_reloc_kernel.c
> > progs/test_sk_storage_tracing.c
> >
> > We'd better replace the hard-coded 16 with TASK_COMM_LEN_16 to make it
> > more grepable.
> >
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> > Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Steven Rostedt <rostedt@goodmis.org>
> > Cc: Kees Cook <keescook@chromium.org>
> > Cc: Al Viro <viro@zeniv.linux.org.uk>
> > Cc: Petr Mladek <pmladek@suse.com>
> > ---
> > tools/testing/selftests/bpf/Makefile | 2 +-
> > tools/testing/selftests/bpf/prog_tests/ringbuf.c | 3 ++-
> > tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c | 3 ++-
> > .../testing/selftests/bpf/prog_tests/sk_storage_tracing.c | 3 ++-
> > tools/testing/selftests/bpf/prog_tests/test_overhead.c | 3 ++-
> > tools/testing/selftests/bpf/prog_tests/trampoline_count.c | 3 ++-
> > tools/testing/selftests/bpf/progs/profiler.h | 7 ++++---
> > tools/testing/selftests/bpf/progs/profiler.inc.h | 8 ++++----
> > tools/testing/selftests/bpf/progs/pyperf.h | 4 ++--
> > tools/testing/selftests/bpf/progs/strobemeta.h | 6 +++---
> > .../testing/selftests/bpf/progs/test_core_reloc_kernel.c | 3 ++-
> > tools/testing/selftests/bpf/progs/test_ringbuf.c | 3 ++-
> > tools/testing/selftests/bpf/progs/test_ringbuf_multi.c | 3 ++-
> > .../testing/selftests/bpf/progs/test_sk_storage_tracing.c | 5 +++--
> > tools/testing/selftests/bpf/progs/test_skb_helpers.c | 5 ++---
> > tools/testing/selftests/bpf/progs/test_stacktrace_map.c | 5 +++--
> > tools/testing/selftests/bpf/progs/test_tracepoint.c | 5 +++--
> > 17 files changed, 41 insertions(+), 30 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index 799b88152e9e..5e72d783d3fe 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -279,7 +279,7 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
> >
> > CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
> > BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
> > - -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
> > + -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) -I${TOOLSINCDIR} \
>
> please don't add new include paths unnecessarily. See my comment on
> another patch, if you add those new constants as enums, they will be
> automatically available in vmlinux BTF and thus in auto-generated
> vmlinux.h header (for those programs using it).
Yes, after converting it to enum, the BPF programs can get it from the
generated vmlinux.h.
> For others, I'd just
> leave hard-coded 16 or re-defined TASK_COMM_LEN_16 where appropriate.
>
It seems not all the BPF programs can include the vmlinux.h.
What we really care about here is the copy of task comm should be with
a nul terminator, if we can assure it, then the size used by the BPF
is not important.
I have checked the copy of task comm in all these BPF programs one by
one, and replaced the unsafe bpf_probe_read_kernel() with
bpf_probe_read_kernel_str(), after that change, I think we can leave
hard-coded 16 for the progs which can't include vmlinux.h.
> > -I$(abspath $(OUTPUT)/../usr/include)
> >
> > CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
> > diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> > index 4706cee84360..ac82d57c09dc 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> > @@ -12,6 +12,7 @@
> > #include <sys/sysinfo.h>
> > #include <linux/perf_event.h>
> > #include <linux/ring_buffer.h>
> > +#include <linux/sched/task.h>
> > #include "test_ringbuf.lskel.h"
> >
> > #define EDONE 7777
> > @@ -22,7 +23,7 @@ struct sample {
> > int pid;
> > int seq;
> > long value;
> > - char comm[16];
> > + char comm[TASK_COMM_LEN_16];
>
> how much value is in this "grep-ability", really? I'm not convinced
> all this code churn is justified.
>
> > };
> >
> > static int sample_cnt;
> > diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
> > index 167cd8a2edfd..f0748305ffd6 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
> > @@ -2,6 +2,7 @@
> > #define _GNU_SOURCE
> > #include <test_progs.h>
> > #include <sys/epoll.h>
> > +#include <linux/sched/task.h>
> > #include "test_ringbuf_multi.skel.h"
> >
> > static int duration = 0;
>
> [...]
--
Thanks
Yafang
next prev parent reply other threads:[~2021-10-22 6:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 3:45 [PATCH v5 10/15] tools/lib/perf: use TASK_COMM_LEN_16 instead of hard-coded 16 Yafang Shao
2021-10-21 3:45 ` [PATCH v5 11/15] tools/bpf/bpftool: " Yafang Shao
2021-10-21 22:38 ` Andrii Nakryiko
2021-10-21 3:46 ` [PATCH v5 12/15] tools/perf/test: make perf test adopt to task comm size change Yafang Shao
2021-10-21 3:46 ` [PATCH v5 13/15] tools/testing/selftests/bpf: use TASK_COMM_LEN_16 instead of hard-coded 16 Yafang Shao
2021-10-21 22:44 ` Andrii Nakryiko
2021-10-22 6:36 ` Yafang Shao [this message]
2021-10-22 23:41 ` Andrii Nakryiko
2021-10-21 3:46 ` [PATCH v5 14/15] sched.h: extend task comm from 16 to 24 for CONFIG_BASE_FULL Yafang Shao
2021-10-21 3:46 ` [PATCH v5 15/15] kernel/kthread: show a warning if kthread's comm is truncated Yafang Shao
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='CALOAHbB6KS8iscsz6y7zd=aGfKfo4jPbyMBKXL4ORY8taZRa8A@mail.gmail.com' \
--to=laoar.shao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=arnaldo.melo@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=christian@brauner.io \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dietmar.eggemann@arm.com \
--cc=john.fastabend@gmail.com \
--cc=juri.lelli@redhat.com \
--cc=kafai@fb.com \
--cc=keescook@chromium.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=lkp@intel.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=oliver.sang@intel.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=qiang.zhang@windriver.com \
--cc=robdclark@chromium.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=valentin.schneider@arm.com \
--cc=vincent.guittot@linaro.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yhs@fb.com \
/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;
as well as URLs for NNTP newsgroup(s).