Re: [PATCH v5 11/15] tools/bpf/bpftool: use TASK_COMM_LEN_16 instead of hard-coded 16

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 20, 2021 at 8:46 PM Yafang Shao <laoar.shao@xxxxxxxxx> wrote:
>
> Use TASK_COMM_LEN_16 instead of hard-coded 16 to make it more grepable.
> It uses bpf_probe_read_kernel() to get task comm, which may return a
> string without nul terminator. We should use bpf_probe_read_kernel_str()
> instead.
>
> Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
> Cc: Arnaldo Carvalho de Melo <arnaldo.melo@xxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Cc: Kees Cook <keescook@xxxxxxxxxxxx>
> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
> Cc: Petr Mladek <pmladek@xxxxxxxx>
> ---
>  tools/bpf/bpftool/Makefile                | 1 +
>  tools/bpf/bpftool/main.h                  | 3 ++-
>  tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 4 ++--
>  tools/bpf/bpftool/skeleton/pid_iter.h     | 4 +++-
>  4 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index d73232be1e99..33fbde84993c 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -164,6 +164,7 @@ $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF)
>         $(QUIET_CLANG)$(CLANG) \
>                 -I$(if $(OUTPUT),$(OUTPUT),.) \
>                 -I$(srctree)/tools/include/uapi/ \
> +               -I$(srctree)/tools/include/ \

bpftool shouldn't rely on internal kernel headers for compilation. If
you want to have TASK_COMM_LEN_16 constant for grep-ability, just
#define it where appropriate

>                 -I$(LIBBPF_PATH) \
>                 -I$(srctree)/tools/lib \
>                 -g -O2 -Wall -target bpf -c $< -o $@ && $(LLVM_STRIP) -g $@
> diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
> index 90caa42aac4c..5efa27188f68 100644
> --- a/tools/bpf/bpftool/main.h
> +++ b/tools/bpf/bpftool/main.h
> @@ -12,6 +12,7 @@
>  #include <linux/compiler.h>
>  #include <linux/kernel.h>
>  #include <linux/hashtable.h>
> +#include <linux/sched/task.h>
>  #include <tools/libc_compat.h>
>

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux