From 9097b0c20a70a6e764d926fcb41399f40072e612 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 7 Jan 2021 14:50:50 -0500 Subject: [PATCH] fix: kprobes: Remove kretprobe hash (v5.11) See upstream commit: commit d741bf41d7c7db4898bacfcb020353cddc032fd8 Author: Peter Zijlstra Date: Sat Aug 29 22:03:24 2020 +0900 kprobes: Remove kretprobe hash The kretprobe hash is mostly superfluous, replace it with a per-task variable. This gets rid of the task hash and it's related locking. Note that this may change the kprobes module-exported API for kretprobe handlers. If any out-of-tree kretprobe user uses ri->rp, use get_kretprobe(ri) instead. Link: https://lore.kernel.org/r/159870620431.1229682.16325792502413731312.stgit@devnote2 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers Change-Id: I855765f390ad7caf481ef5fea334645e852f5b0f --- probes/lttng-kretprobes.c | 6 +++--- wrapper/kprobes.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 wrapper/kprobes.h diff --git a/probes/lttng-kretprobes.c b/probes/lttng-kretprobes.c index a6bcd218..2da3143c 100644 --- a/probes/lttng-kretprobes.c +++ b/probes/lttng-kretprobes.c @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include #include @@ -36,7 +36,7 @@ int _lttng_kretprobes_handler(struct kretprobe_instance *krpi, enum lttng_kretprobe_type type) { struct lttng_krp *lttng_krp = - container_of(krpi->rp, struct lttng_krp, krp); + container_of(lttng_get_kretprobe(krpi), struct lttng_krp, krp); struct lttng_event *event = lttng_krp->event[type]; struct lttng_probe_ctx lttng_probe_ctx = { @@ -58,7 +58,7 @@ int _lttng_kretprobes_handler(struct kretprobe_instance *krpi, if (unlikely(!LTTNG_READ_ONCE(event->enabled))) return 0; - payload.ip = (unsigned long) krpi->rp->kp.addr; + payload.ip = (unsigned long) lttng_get_kretprobe(krpi)->kp.addr; payload.parent_ip = (unsigned long) krpi->ret_addr; lib_ring_buffer_ctx_init(&ctx, chan->chan, <tng_probe_ctx, sizeof(payload), diff --git a/wrapper/kprobes.h b/wrapper/kprobes.h new file mode 100644 index 00000000..4d6993e2 --- /dev/null +++ b/wrapper/kprobes.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * src/wrapper/kprobes.h + * + * Copyright (C) 2021 Michael Jeanson + */ + +#ifndef _LTTNG_WRAPPER_KPROBES_H +#define _LTTNG_WRAPPER_KPROBES_H + +#include +#include + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0)) + +static inline +struct kretprobe *lttng_get_kretprobe(struct kretprobe_instance *ri) +{ + return get_kretprobe(ri); +} + +#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0) */ + +static inline +struct kretprobe *lttng_get_kretprobe(struct kretprobe_instance *ri) +{ + return ri->rp; +} + +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0) */ + +#endif /* _LTTNG_WRAPPER_KPROBES_H */ -- 2.34.1