From cdfa74f35910421e807d7e1deb212a5bca138413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mauricio=20V=C3=A1squez?= Date: Thu, 21 May 2020 11:50:52 -0500 Subject: [PATCH 1/3] Fix KFUNC_PROBE return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The KFUNC_PROBE macro is using "void" as return type, this is causing problems in some tools that have a filtering enable that returns 0. Reproducer: (Notice that it requires BTF support) ``` $ python opensnoop.py --pid 5 /virtual/main.c:33:21: error: void function '____kretfunc__do_sys_open' should not return a value [-Wreturn-type] if (pid != 5) { return 0; } ^ ~ 1 error generated. ... ``` Signed-off-by: Mauricio Vásquez --- src/cc/export/helpers.h | 4 ++-- tools/klockstat.py | 6 +++--- tools/opensnoop.py | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h index b38b3f20..c6edc9cd 100644 --- a/src/cc/export/helpers.h +++ b/src/cc/export/helpers.h @@ -998,7 +998,7 @@ int raw_tracepoint__##event(struct bpf_raw_tracepoint_args *ctx) #define BPF_PROG(name, args...) \ int name(unsigned long long *ctx); \ __attribute__((always_inline)) \ -static void ____##name(unsigned long long *ctx, ##args); \ +static int ____##name(unsigned long long *ctx, ##args); \ int name(unsigned long long *ctx) \ { \ _Pragma("GCC diagnostic push") \ @@ -1007,7 +1007,7 @@ int name(unsigned long long *ctx) \ _Pragma("GCC diagnostic pop") \ return 0; \ } \ -static void ____##name(unsigned long long *ctx, ##args) +static int ____##name(unsigned long long *ctx, ##args) #define KFUNC_PROBE(event, args...) \ BPF_PROG(kfunc__ ## event, args) diff --git a/tools/klockstat.py b/tools/klockstat.py index 540dd4e7..7cb15ad3 100755 --- a/tools/klockstat.py +++ b/tools/klockstat.py @@ -352,17 +352,17 @@ int mutex_lock_enter(struct pt_regs *ctx) program_kfunc = """ KFUNC_PROBE(mutex_unlock, void *lock) { - do_mutex_unlock_enter(); + return do_mutex_unlock_enter(); } KRETFUNC_PROBE(mutex_lock, void *lock, int ret) { - do_mutex_lock_return(); + return do_mutex_lock_return(); } KFUNC_PROBE(mutex_lock, void *lock) { - do_mutex_lock_enter(ctx, 3); + return do_mutex_lock_enter(ctx, 3); } """ diff --git a/tools/opensnoop.py b/tools/opensnoop.py index b28d7d55..9a526625 100755 --- a/tools/opensnoop.py +++ b/tools/opensnoop.py @@ -197,6 +197,8 @@ KRETFUNC_PROBE(do_sys_open, int dfd, const char *filename, int flags, int mode, data.ret = ret; events.perf_submit(ctx, &data, sizeof(data)); + + return 0: } """ -- 2.25.4