Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3712592pxb; Mon, 21 Feb 2022 04:19:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0yoiXnCbs+xphTbTlDM/EBkEu8gfAtN5GdnIAHLyD7EwVyDtZEbizxNMNWAlUaJquVsGY X-Received: by 2002:aa7:8890:0:b0:4e1:b25b:634c with SMTP id z16-20020aa78890000000b004e1b25b634cmr20095044pfe.31.1645445994327; Mon, 21 Feb 2022 04:19:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645445994; cv=none; d=google.com; s=arc-20160816; b=UepSJnDaYoxtlQRzzu/IySoF9HVxeLt+UI3Y2h8Mprva6C225enC1KoUM0LX+y24w9 nrS5TeI5j1VKdsSePQCK3n5WeUgvgCkF/Nvo8V0LlPfbdX0T5q0DiyHyhRNYD8lDYn6A LM9iVSbdOEmZ25k3PLIRtwusZQukhHokidcLrDX5uVJD03t9wIkTVSnEeLcb/6bq3Oxm XQiawZDj7FhEqdlwiG9O5ROSeWqskl9t7AGCrcP7EK2uvCyJJ/fLfLe7m59wjuLk8LDr c5UJCnkSgnRPnTCVzha+LwlPJOrKFV0tmt0tNsiD62b/0aI3f15AtPGCx+/29DH0Xyq9 t+fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vlJIVYYJuvxvQIz42/3OAT9ssBDANJqgN05nTYvWmaw=; b=RISNwSLwYnJEFvAIAhSdQGT1M6FeB0rvyGkaXY0+npr5zjl/1PiQ1J5932Om5x6PgW 1Ugu03Jsqdh5ywCgqGU6SKpSxpOc2UAg3NmeLJ0yhD1GvvOHaojByB5L967vw+Mw3Fva 6mpaRfVkSFXCS7b2HsM7XR5sN+PQab2cJuCeLTV73e9gQqZFdeu0ThF59gKo8U7/QM1w HX2TdxkHf2ILu8P27jwhSZ6S31ooggifW3teFQFH1N9nF4APtlPWptfxGZmbXInpltNu TcetOmItuyxO529TJtmiE6t8VAfRHdR2Z9YFVMVAdq/VgacZBiOX7WbShn2jdVpqZwS5 khWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bGFJYiFM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id in15-20020a17090b438f00b001bc425aa6c9si2022919pjb.52.2022.02.21.04.19.39; Mon, 21 Feb 2022 04:19:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bGFJYiFM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347724AbiBUJIx (ORCPT + 99 others); Mon, 21 Feb 2022 04:08:53 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347135AbiBUJEA (ORCPT ); Mon, 21 Feb 2022 04:04:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32402DA9C; Mon, 21 Feb 2022 00:58:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AB3B8B80EAC; Mon, 21 Feb 2022 08:58:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E88E6C36AE3; Mon, 21 Feb 2022 08:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433901; bh=V+GAnAacYdkyKm/bNFvDuRxcECMVX1bM81QitkE3o3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bGFJYiFMUtoaMeQ9aM+dtGfddAfl8scLujkE3AJvvCn/m84ZPgwUjHx3B7IdLFPqY ZSsdq9OcB0JSJGgxXbxtGib21T3XfnL7v3coTi9pWfRRqfXrNxX6Qx033ls4NpOQ4p 1Kul/4MeIEEWwhuHljuu9gLVrFd2cgqApV6WWdZA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Helge Deller , "Steven Rostedt (VMware)" , Ard Biesheuvel , Torsten Duwe , Amit Daniel Kachhap , Sven Schnelle , Ingo Molnar , "James E.J. Bottomley" , Jessica Yu , linux-parisc@vger.kernel.org, Stephen Boyd Subject: [PATCH 5.4 24/80] module/ftrace: handle patchable-function-entry Date: Mon, 21 Feb 2022 09:49:04 +0100 Message-Id: <20220221084916.374474220@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland commit a1326b17ac03a9012cb3d01e434aacb4d67a416c upstream. When using patchable-function-entry, the compiler will record the callsites into a section named "__patchable_function_entries" rather than "__mcount_loc". Let's abstract this difference behind a new FTRACE_CALLSITE_SECTION, so that architectures don't have to handle this explicitly (e.g. with custom module linker scripts). As parisc currently handles this explicitly, it is fixed up accordingly, with its custom linker script removed. Since FTRACE_CALLSITE_SECTION is only defined when DYNAMIC_FTRACE is selected, the parisc module loading code is updated to only use the definition in that case. When DYNAMIC_FTRACE is not selected, modules shouldn't have this section, so this removes some redundant work in that case. To make sure that this is keep up-to-date for modules and the main kernel, a comment is added to vmlinux.lds.h, with the existing ifdeffery simplified for legibility. I built parisc generic-{32,64}bit_defconfig with DYNAMIC_FTRACE enabled, and verified that the section made it into the .ko files for modules. Signed-off-by: Mark Rutland Acked-by: Helge Deller Acked-by: Steven Rostedt (VMware) Reviewed-by: Ard Biesheuvel Reviewed-by: Torsten Duwe Tested-by: Amit Daniel Kachhap Tested-by: Sven Schnelle Tested-by: Torsten Duwe Cc: Ingo Molnar Cc: James E.J. Bottomley Cc: Jessica Yu Cc: linux-parisc@vger.kernel.org Cc: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- arch/parisc/Makefile | 1 - arch/parisc/kernel/module.c | 10 +++++++--- arch/parisc/kernel/module.lds | 7 ------- include/asm-generic/vmlinux.lds.h | 14 +++++++------- include/linux/ftrace.h | 5 +++++ kernel/module.c | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 arch/parisc/kernel/module.lds --- a/arch/parisc/Makefile +++ b/arch/parisc/Makefile @@ -65,7 +65,6 @@ KBUILD_CFLAGS += -DCC_USING_PATCHABLE_FU -DFTRACE_PATCHABLE_FUNCTION_SIZE=$(NOP_COUNT) CC_FLAGS_FTRACE := -fpatchable-function-entry=$(NOP_COUNT),$(shell echo $$(($(NOP_COUNT)-1))) -KBUILD_LDS_MODULE += $(srctree)/arch/parisc/kernel/module.lds endif OBJCOPY_FLAGS =-O binary -R .note -R .comment -S --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -862,7 +863,7 @@ int module_finalize(const Elf_Ehdr *hdr, const char *strtab = NULL; const Elf_Shdr *s; char *secstrings; - int err, symindex = -1; + int symindex = -1; Elf_Sym *newptr, *oldptr; Elf_Shdr *symhdr = NULL; #ifdef DEBUG @@ -946,11 +947,13 @@ int module_finalize(const Elf_Ehdr *hdr, /* patch .altinstructions */ apply_alternatives(aseg, aseg + s->sh_size, me->name); +#ifdef CONFIG_DYNAMIC_FTRACE /* For 32 bit kernels we're compiling modules with * -ffunction-sections so we must relocate the addresses in the - *__mcount_loc section. + * ftrace callsite section. */ - if (symindex != -1 && !strcmp(secname, "__mcount_loc")) { + if (symindex != -1 && !strcmp(secname, FTRACE_CALLSITE_SECTION)) { + int err; if (s->sh_type == SHT_REL) err = apply_relocate((Elf_Shdr *)sechdrs, strtab, symindex, @@ -962,6 +965,7 @@ int module_finalize(const Elf_Ehdr *hdr, if (err) return err; } +#endif } return 0; } --- a/arch/parisc/kernel/module.lds +++ /dev/null @@ -1,7 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -SECTIONS { - __mcount_loc : { - *(__patchable_function_entries) - } -} --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -110,17 +110,17 @@ #endif #ifdef CONFIG_FTRACE_MCOUNT_RECORD -#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY -#define MCOUNT_REC() . = ALIGN(8); \ - __start_mcount_loc = .; \ - KEEP(*(__patchable_function_entries)) \ - __stop_mcount_loc = .; -#else +/* + * The ftrace call sites are logged to a section whose name depends on the + * compiler option used. A given kernel image will only use one, AKA + * FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header + * dependencies for FTRACE_CALLSITE_SECTION's definition. + */ #define MCOUNT_REC() . = ALIGN(8); \ __start_mcount_loc = .; \ KEEP(*(__mcount_loc)) \ + KEEP(*(__patchable_function_entries)) \ __stop_mcount_loc = .; -#endif #else #define MCOUNT_REC() #endif --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -738,6 +738,11 @@ static inline unsigned long get_lock_par #ifdef CONFIG_FTRACE_MCOUNT_RECORD extern void ftrace_init(void); +#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY +#define FTRACE_CALLSITE_SECTION "__patchable_function_entries" +#else +#define FTRACE_CALLSITE_SECTION "__mcount_loc" +#endif #else static inline void ftrace_init(void) { } #endif --- a/kernel/module.c +++ b/kernel/module.c @@ -3377,7 +3377,7 @@ static int find_module_sections(struct m #endif #ifdef CONFIG_FTRACE_MCOUNT_RECORD /* sechdrs[0].sh_size is always zero */ - mod->ftrace_callsites = section_objs(info, "__mcount_loc", + mod->ftrace_callsites = section_objs(info, FTRACE_CALLSITE_SECTION, sizeof(*mod->ftrace_callsites), &mod->num_ftrace_callsites); #endif