From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D943C47258 for ; Tue, 5 May 2020 13:26:24 +0000 (UTC) Received: from lists.lttng.org (lists.lttng.org [167.114.26.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 989E82078D for ; Tue, 5 May 2020 13:26:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.lttng.org header.i=@lists.lttng.org header.b="ABE7v0zi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 989E82078D Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=lists.lttng.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lttng-dev-bounces@lists.lttng.org Received: from lists-lttng01.efficios.com (localhost [IPv6:::1]) by lists.lttng.org (Postfix) with ESMTP id 49GgV54rlfz1qsR; Tue, 5 May 2020 09:26:21 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.lttng.org; s=default; t=1588685182; bh=+jF9pRZ1dmMb2QWdV7cXXQi7I3FfTh+wkJs5483w2lw=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ABE7v0zinNSwqgv2FW310tK9l5C+/a3x8J6VueOdF+x/3hVPQnUVBOV6Q4p0gBLDn q94fweDZ9FTVHL2VkTikzajKfAfSpqaLJjqEYbMVnaF0adDRhAH1akIt5ONbRnuHWc KuQPa/ubuxwqLs2MpOAHLoliArJ7Pl/6pTP/z8TsaNmYzptqIT3qC8h1cyoUTr1EgU uk2DurXlSaCxd3p968h/LVxkkYeyWCiLCmGR9CNaEtMkoZLOHQgAzeorvvLRzqrBbH LlLLERQm+ylsbmtvnqklI1P+cN3Nu7GUaJfFpaOhHbVdLI1RnsCvomWzTwW2tzqfqI 37zUiOhGi1t0g== Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by lists.lttng.org (Postfix) with ESMTPS id 49GgV41fKbz1qmt for ; Tue, 5 May 2020 09:26:20 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id AA31729C20B; Tue, 5 May 2020 09:26:19 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id GPAoB7EdSFnP; Tue, 5 May 2020 09:26:19 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 2FC1129C289; Tue, 5 May 2020 09:26:19 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 2FC1129C289 X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 8pF1U_dEre4z; Tue, 5 May 2020 09:26:19 -0400 (EDT) Received: from localhost.localdomain (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by mail.efficios.com (Postfix) with ESMTPSA id DE45529C288; Tue, 5 May 2020 09:26:18 -0400 (EDT) To: lttng-dev@lists.lttng.org Date: Tue, 5 May 2020 09:25:50 -0400 Message-ID: <20200505132550.24537-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.17.1 Subject: [lttng-dev] [PATCH lttng-modules] Unbreak LTTng for kernel 5.7 X-BeenThere: lttng-dev@lists.lttng.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: LTTng development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mathieu Desnoyers via lttng-dev Reply-To: Mathieu Desnoyers Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, rostedt@goodmis.org, Alexei Starovoitov , Masami Hiramatsu , Thomas Gleixner , Will Deacon , akpm@linux-foundation.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: lttng-dev-bounces@lists.lttng.org Sender: "lttng-dev" Message-ID: <20200505132550.QdgOTFJ51CpXeerfLrGZ9C2ccRNtofO-gmAJpo5ZpUs@z> Linux commit 0bd476e6c67190b5eb7b6e105c8db8ff61103281 ("kallsyms: unexport kallsyms_lookup_name() and kallsyms_on_each_symbol()") breaks LTTng-modules by removing symbols used by the LTTng-modules out-of-tree tracer. I pointed this out when the change was originally considered before the 5.7 merge window. This generated some discussion but it did not lead to any concrete proposal to fix the issue. [1] The commit has been merged in the 5.7 merge window. At that point, as maintainer of LTTng, I immediately raised a flag about this issue, proposing an alternative approach to solve this: expose the few symbols needed by LTTng to GPL modules. This was NACKed on the ground that the Linux kernel cannot export GPL symbols when there are no in-tree users. [2] Steven Rostedt has shown interest in merging LTTng-modules upstream. LTTng-modules being LGPL, this is very much doable. I have prepared a tree of LTTng-modules "for upstreaming" and sent it to him privately so he can review it. Even if in an ideal scenario LTTng-modules is merged for the following merge window, it leaves LTTng-modules broken on the 5.7 kernel. In order to ensure that the LTTng-modules kernel tracer continues working for my end users on kernels 5.7 onwards, as a very last resort, this is with great reluctance that I created this fix for LTTng modules. It basically uses kprobes to lookup the kallsyms_lookup_name symbol, and continues using kallsyms_lookup_name as before. Link: https://lore.kernel.org/r/20200302192811.n6o5645rsib44vco@localhost [1] Link: https://lore.kernel.org/r/20200409193543.18115-1-mathieu.desnoyers@efficios.com [2] Link: https://lwn.net/Articles/817988/ Signed-off-by: Mathieu Desnoyers CC: Thomas Gleixner CC: Will Deacon CC: akpm@linux-foundation.org CC: Greg Kroah-Hartman CC: Masami Hiramatsu CC: rostedt@goodmis.org CC: Alexei Starovoitov --- Makefile | 1 + README.md | 1 + wrapper/kallsyms.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ wrapper/kallsyms.h | 20 +++++++++++-- 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 wrapper/kallsyms.c diff --git a/Makefile b/Makefile index c977996..6e6c2fe 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,7 @@ ifneq ($(KERNELRELEASE),) lttng-wrapper-objs := wrapper/page_alloc.o \ wrapper/random.o \ wrapper/trace-clock.o \ + wrapper/kallsyms.o \ wrapper/irqdesc.o \ wrapper/fdtable.o \ lttng-wrapper-impl.o diff --git a/README.md b/README.md index 450f363..7b04cd8 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Make sure your target kernel has the following config options enabled: - `CONFIG_TRACEPOINTS`: kernel tracepoint instrumentation (enabled as a side-effect of any of the perf/ftrace/blktrace instrumentation features). + - `CONFIG_KPROBES` (5.7+): use kallsyms for kernel 5.7 and newer. ### Supported (optional) kernel config options diff --git a/wrapper/kallsyms.c b/wrapper/kallsyms.c new file mode 100644 index 0000000..6af77f5 --- /dev/null +++ b/wrapper/kallsyms.c @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) + * + * wrapper/kallsyms.c + * + * Wrapper around kallsyms. Using kprobes to get its address when available. + * + * Can we mainline LTTng already so we don't have to waste our time doing this + * kind of hack ? + * + * Copyright (C) 2020 Mathieu Desnoyers + */ + +#include +#include +#include + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) + +#ifndef CONFIG_KPROBES +# error "LTTng-modules requires CONFIG_KPROBES on kernels >= 5.7.0" +#endif + +static +unsigned long (*kallsyms_lookup_name_sym)(const char *name); + +static +int dummy_kprobe_handler(struct kprobe *p, struct pt_regs *regs) +{ + return 0; +} + +static +unsigned long do_get_kallsyms(void) +{ + struct kprobe probe; + int ret; + unsigned long addr; + + memset(&probe, 0, sizeof(probe)); + probe.pre_handler = dummy_kprobe_handler; + probe.symbol_name = "kallsyms_lookup_name"; + ret = register_kprobe(&probe); + if (ret) + return 0; + addr = (unsigned long)probe.addr; +#ifdef CONFIG_ARM +#ifdef CONFIG_THUMB2_KERNEL + if (addr) + addr |= 1; /* set bit 0 in address for thumb mode */ +#endif +#endif + unregister_kprobe(&probe); + return addr; +} + +unsigned long wrapper_kallsyms_lookup_name(const char *name) +{ + if (!kallsyms_lookup_name_sym) { + kallsyms_lookup_name_sym = (void *)do_get_kallsyms(); + } + if (kallsyms_lookup_name_sym) + return kallsyms_lookup_name_sym(name); + else { + printk_once(KERN_WARNING "LTTng requires kallsyms_lookup_name\n"); + return 0; + } +} +EXPORT_SYMBOL_GPL(wrapper_kallsyms_lookup_name); + +#endif diff --git a/wrapper/kallsyms.h b/wrapper/kallsyms.h index 0e4fcee..7f4d830 100644 --- a/wrapper/kallsyms.h +++ b/wrapper/kallsyms.h @@ -14,6 +14,7 @@ #define _LTTNG_WRAPPER_KALLSYMS_H #include +#include /* * PowerPC ABIv1 needs KALLSYMS_ALL to get the function descriptor, @@ -25,12 +26,26 @@ # endif #endif +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) + +unsigned long wrapper_kallsyms_lookup_name(const char *name); + +#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) */ + +static inline +unsigned long wrapper_kallsyms_lookup_name(const char *name) +{ + return kallsyms_lookup_name(name); +} + +#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) */ + static inline unsigned long kallsyms_lookup_funcptr(const char *name) { unsigned long addr; - addr = kallsyms_lookup_name(name); + addr = wrapper_kallsyms_lookup_name(name); #ifdef CONFIG_ARM #ifdef CONFIG_THUMB2_KERNEL if (addr) @@ -43,6 +58,7 @@ unsigned long kallsyms_lookup_funcptr(const char *name) static inline unsigned long kallsyms_lookup_dataptr(const char *name) { - return kallsyms_lookup_name(name); + return wrapper_kallsyms_lookup_name(name); } + #endif /* _LTTNG_WRAPPER_KALLSYMS_H */ -- 2.17.1 _______________________________________________ lttng-dev mailing list lttng-dev@lists.lttng.org https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev