From 087269072e2d96540d137789a6c91687edeb33bd 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 --- include/wrapper/kprobes.h | 32 ++++++++++++++++++++++++++++++++ src/probes/lttng-kretprobes.c | 6 +++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 include/wrapper/kprobes.h diff --git a/include/wrapper/kprobes.h b/include/wrapper/kprobes.h new file mode 100644 index 00000000..4d6993e2 --- /dev/null +++ b/include/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 */ diff --git a/src/probes/lttng-kretprobes.c b/src/probes/lttng-kretprobes.c index 8cde4edd..24cb52e4 100644 --- a/src/probes/lttng-kretprobes.c +++ b/src/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), -- 2.34.1