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