Fix KFUNC_PROBE return value
authorMauricio Vásquez <mauricio@kinvolk.io>
Thu, 21 May 2020 16:50:52 +0000 (11:50 -0500)
committeryonghong-song <ys114321@gmail.com>
Thu, 21 May 2020 19:27:28 +0000 (12:27 -0700)
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 <mauricio@kinvolk.io>
src/cc/export/helpers.h
tools/klockstat.py
tools/opensnoop.py

index 79a3879..2b73d1c 100644 (file)
@@ -1012,7 +1012,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")                          \
@@ -1021,7 +1021,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)
index 540dd4e..7cb15ad 100755 (executable)
@@ -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);
 }
 
 """
index 995443e..28fe755 100755 (executable)
@@ -197,6 +197,8 @@ KRETFUNC_PROBE(do_sys_open, int dfd, const char __user *filename, int flags, int
     data.ret   = ret;
 
     events.perf_submit(ctx, &data, sizeof(data));
+
+    return 0:
 }
 """