Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame^] | 1 | From 3c46ddc134621dba65030263aa321dd6bdae3ba3 Mon Sep 17 00:00:00 2001 |
| 2 | From: Michael Jeanson <mjeanson@efficios.com> |
| 3 | Date: Mon, 4 Apr 2022 15:02:10 -0400 |
| 4 | Subject: [PATCH 07/10] fix: kprobes: Use rethook for kretprobe if possible |
| 5 | (v5.18) |
| 6 | |
| 7 | See upstream commit : |
| 8 | |
| 9 | commit 73f9b911faa74ac5107879de05c9489c419f41bb |
| 10 | Author: Masami Hiramatsu <mhiramat@kernel.org> |
| 11 | Date: Sat Mar 26 11:27:05 2022 +0900 |
| 12 | |
| 13 | kprobes: Use rethook for kretprobe if possible |
| 14 | |
| 15 | Use rethook for kretprobe function return hooking if the arch sets |
| 16 | CONFIG_HAVE_RETHOOK=y. In this case, CONFIG_KRETPROBE_ON_RETHOOK is |
| 17 | set to 'y' automatically, and the kretprobe internal data fields |
| 18 | switches to use rethook. If not, it continues to use kretprobe |
| 19 | specific function return hooks. |
| 20 | |
| 21 | Upstream-Status: Backport |
| 22 | |
| 23 | Change-Id: I2b7670dc04e4769c1e3c372582ad2f555f6d7a66 |
| 24 | Signed-off-by: Michael Jeanson <mjeanson@efficios.com> |
| 25 | Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 26 | --- |
| 27 | include/wrapper/kprobes.h | 17 +++++++++++++++++ |
| 28 | src/probes/lttng-kretprobes.c | 2 +- |
| 29 | 2 files changed, 18 insertions(+), 1 deletion(-) |
| 30 | |
| 31 | diff --git a/include/wrapper/kprobes.h b/include/wrapper/kprobes.h |
| 32 | index b546d615..51d32b7c 100644 |
| 33 | --- a/include/wrapper/kprobes.h |
| 34 | +++ b/include/wrapper/kprobes.h |
| 35 | @@ -29,4 +29,21 @@ struct kretprobe *lttng_get_kretprobe(struct kretprobe_instance *ri) |
| 36 | |
| 37 | #endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0) */ |
| 38 | |
| 39 | + |
| 40 | +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0)) |
| 41 | +static inline |
| 42 | +unsigned long lttng_get_kretprobe_retaddr(struct kretprobe_instance *ri) |
| 43 | +{ |
| 44 | + return get_kretprobe_retaddr(ri); |
| 45 | +} |
| 46 | + |
| 47 | +#else |
| 48 | + |
| 49 | +static inline |
| 50 | +unsigned long lttng_get_kretprobe_retaddr(struct kretprobe_instance *ri) |
| 51 | +{ |
| 52 | + return (unsigned long) ri->ret_addr; |
| 53 | +} |
| 54 | +#endif |
| 55 | + |
| 56 | #endif /* _LTTNG_WRAPPER_KPROBES_H */ |
| 57 | diff --git a/src/probes/lttng-kretprobes.c b/src/probes/lttng-kretprobes.c |
| 58 | index 5cb2e953..565df739 100644 |
| 59 | --- a/src/probes/lttng-kretprobes.c |
| 60 | +++ b/src/probes/lttng-kretprobes.c |
| 61 | @@ -81,7 +81,7 @@ int _lttng_kretprobes_handler(struct kretprobe_instance *krpi, |
| 62 | int ret; |
| 63 | |
| 64 | payload.ip = (unsigned long) lttng_get_kretprobe(krpi)->kp.addr; |
| 65 | - payload.parent_ip = (unsigned long) krpi->ret_addr; |
| 66 | + payload.parent_ip = lttng_get_kretprobe_retaddr(krpi); |
| 67 | |
| 68 | lib_ring_buffer_ctx_init(&ctx, event_recorder, sizeof(payload), |
| 69 | lttng_alignof(payload), <tng_probe_ctx); |
| 70 | -- |
| 71 | 2.19.1 |
| 72 | |