blob: effd37ffe13609f15bf9e1b03d482ed7a60f1851 [file] [log] [blame]
Patrick Williams03907ee2022-05-01 06:28:52 -05001From 3c46ddc134621dba65030263aa321dd6bdae3ba3 Mon Sep 17 00:00:00 2001
2From: Michael Jeanson <mjeanson@efficios.com>
3Date: Mon, 4 Apr 2022 15:02:10 -0400
4Subject: [PATCH 07/10] fix: kprobes: Use rethook for kretprobe if possible
5 (v5.18)
6
7See 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
21Upstream-Status: Backport
22
23Change-Id: I2b7670dc04e4769c1e3c372582ad2f555f6d7a66
24Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
25Signed-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
31diff --git a/include/wrapper/kprobes.h b/include/wrapper/kprobes.h
32index 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 */
57diff --git a/src/probes/lttng-kretprobes.c b/src/probes/lttng-kretprobes.c
58index 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), &lttng_probe_ctx);
70--
712.19.1
72