[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211021034603.4458-2-laoar.shao@gmail.com>
Date: Thu, 21 Oct 2021 03:45:59 +0000
From: Yafang Shao <laoar.shao@...il.com>
To: keescook@...omium.org, rostedt@...dmis.org,
mathieu.desnoyers@...icios.com, arnaldo.melo@...il.com,
pmladek@...e.com, peterz@...radead.org, viro@...iv.linux.org.uk,
akpm@...ux-foundation.org, valentin.schneider@....com,
qiang.zhang@...driver.com, robdclark@...omium.org,
christian@...uner.io, dietmar.eggemann@....com, mingo@...hat.com,
juri.lelli@...hat.com, vincent.guittot@...aro.org,
davem@...emloft.net, kuba@...nel.org, ast@...nel.org,
daniel@...earbox.net, andrii@...nel.org, kafai@...com,
songliubraving@...com, yhs@...com, john.fastabend@...il.com,
kpsingh@...nel.org
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
linux-perf-users@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, oliver.sang@...el.com, lkp@...el.com,
Yafang Shao <laoar.shao@...il.com>
Subject: [PATCH v5 11/15] tools/bpf/bpftool: use TASK_COMM_LEN_16 instead of hard-coded 16
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@...il.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@...il.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Kees Cook <keescook@...omium.org>
Cc: Al Viro <viro@...iv.linux.org.uk>
Cc: Petr Mladek <pmladek@...e.com>
---
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/ \
-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>
#include <bpf/libbpf.h>
@@ -124,7 +125,7 @@ struct obj_refs_table {
struct obj_ref {
int pid;
- char comm[16];
+ char comm[TASK_COMM_LEN_16];
};
struct obj_refs {
diff --git a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c
index d9b420972934..f70702fcb224 100644
--- a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c
+++ b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c
@@ -71,8 +71,8 @@ int iter(struct bpf_iter__task_file *ctx)
e.pid = task->tgid;
e.id = get_obj_id(file->private_data, obj_type);
- bpf_probe_read_kernel(&e.comm, sizeof(e.comm),
- task->group_leader->comm);
+ bpf_probe_read_kernel_str(&e.comm, sizeof(e.comm),
+ task->group_leader->comm);
bpf_seq_write(ctx->meta->seq, &e, sizeof(e));
return 0;
diff --git a/tools/bpf/bpftool/skeleton/pid_iter.h b/tools/bpf/bpftool/skeleton/pid_iter.h
index 5692cf257adb..675b2916567e 100644
--- a/tools/bpf/bpftool/skeleton/pid_iter.h
+++ b/tools/bpf/bpftool/skeleton/pid_iter.h
@@ -3,10 +3,12 @@
#ifndef __PID_ITER_H
#define __PID_ITER_H
+#include <linux/sched/task.h>
+
struct pid_iter_entry {
__u32 id;
int pid;
- char comm[16];
+ char comm[TASK_COMM_LEN_16];
};
#endif
--
2.17.1
Powered by blists - more mailing lists