From patchwork Mon Jun 12 12:48:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 9781065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 65C7160212 for ; Mon, 12 Jun 2017 12:48:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72F7D283BF for ; Mon, 12 Jun 2017 12:48:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67CD028591; Mon, 12 Jun 2017 12:48:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0943D283BF for ; Mon, 12 Jun 2017 12:48:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xswLM6SYEwL0p1YFV4y0iVlG2ahUevI83gNBXcfFWCk=; b=lu6tNxqkXtEP01 3mWj/9Nf3Ai4dkb4wiN/OwIVmKlAxRblmJkXkn97HMdnoaLl7S1V1XOPtQFeSYEGiUMA7gfFO5W0c QoEQKpeS6INzpuC+qWKxWZvSk9fMmul3/QpREt/7wWUgBtM7RDJNGJKSTY2mJLlPc+La76tw/H97g ae9raahpe95beDczcazNgSaONQBUvD53ugQUKL7XW5bJPMBq0cSNJWnG6jvYCpQWYp/NEay8Rrl41 yfT8XiVDmY2uTWCUVOxuvKtarLSt+mWATiNzOSu6qLrBkMMxKfNSnUOZd3FHoUdAHrEH6omGqNy05 hi9NWI0moSiUSEhVlkbQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dKOlY-0001Fv-V9; Mon, 12 Jun 2017 12:48:20 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dKOlU-00013E-Up for linux-arm-kernel@lists.infradead.org; Mon, 12 Jun 2017 12:48:19 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 96ACD1596; Mon, 12 Jun 2017 05:47:56 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 68A4A3F483; Mon, 12 Jun 2017 05:47:56 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 302EE1AE17BD; Mon, 12 Jun 2017 13:48:06 +0100 (BST) Date: Mon, 12 Jun 2017 13:48:06 +0100 From: Will Deacon To: Arnd Bergmann Subject: Re: [PATCH] arm64: ftrace: fix building without CONFIG_MODULES Message-ID: <20170612124805.GA11581@arm.com> References: <20170609102807.2992510-1-arnd@arndb.de> <20170609113850.GF13955@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170612_054817_158630_613431F6 X-CRM114-Status: GOOD ( 17.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Catalin Marinas , Rusty Russell , Linux Kernel Mailing List , Steven Rostedt , Ingo Molnar , Jessica Yu , Linux ARM Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Jun 09, 2017 at 08:57:31PM +0200, Arnd Bergmann wrote: > On Fri, Jun 9, 2017 at 1:38 PM, Will Deacon wrote: > > On Fri, Jun 09, 2017 at 12:27:06PM +0200, Arnd Bergmann wrote: > >> When CONFIG_MODULES is disabled, we cannot dereference a module pointer: > >> > >> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_call': > >> arch/arm64/kernel/ftrace.c:107:36: error: dereferencing pointer to incomplete type 'struct module' > >> trampoline = (unsigned long *)mod->arch.ftrace_trampoline; > >> > >> Also, the within_module() function is not defined: > >> > >> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_nop': > >> arch/arm64/kernel/ftrace.c:171:8: error: implicit declaration of function 'within_module'; did you mean 'init_module'? [-Werror=implicit-function-declaration] > >> > >> This addresses both by adding the appropriate stubs. > >> > >> Fixes: e71a4e1bebaf ("arm64: ftrace: add support for far branches to dynamic ftrace") > >> Signed-off-by: Arnd Bergmann > >> --- > >> arch/arm64/include/asm/module.h | 6 ++++++ > >> arch/arm64/kernel/ftrace.c | 2 +- > >> include/linux/module.h | 5 +++++ > >> 3 files changed, 12 insertions(+), 1 deletion(-) > > > > I can't seem to reproduce this simply by disabling MODULES in defconfig. > > Could you share your .config, please? > > This is the randconfig I used: https://pastebin.com/SfKBY7f8 Thanks, I was forgetting to enable ftrace. I think a simpler patch (and one that I can just apply via arm64) is switching the IS_ENABLEDs out for #ifdefs. See below. Will --->8 Acked-by: Ard Biesheuvel diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index 8a42be0693c9..401aa27808a4 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -71,11 +71,12 @@ int ftrace_update_ftrace_func(ftrace_func_t func) int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) { unsigned long pc = rec->ip; - long offset = (long)pc - (long)addr; u32 old, new; - if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && - (offset < -SZ_128M || offset >= SZ_128M)) { +#ifdef CONFIG_ARM64_MODULE_PLTS + long offset = (long)pc - (long)addr; + + if (offset < -SZ_128M || offset >= SZ_128M) { unsigned long *trampoline; struct module *mod; @@ -121,6 +122,7 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) } addr = (unsigned long)&trampoline[1]; } +#endif /* CONFIG_ARM64_MODULE_PLTS */ old = aarch64_insn_gen_nop(); new = aarch64_insn_gen_branch_imm(pc, addr, AARCH64_INSN_BRANCH_LINK); @@ -135,12 +137,13 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr) { unsigned long pc = rec->ip; - long offset = (long)pc - (long)addr; bool validate = true; u32 old = 0, new; - if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && - (offset < -SZ_128M || offset >= SZ_128M)) { +#ifdef CONFIG_ARM64_MODULE_PLTS + long offset = (long)pc - (long)addr; + + if (offset < -SZ_128M || offset >= SZ_128M) { u32 replaced; /* @@ -177,6 +180,7 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, old = aarch64_insn_gen_branch_imm(pc, addr, AARCH64_INSN_BRANCH_LINK); } +#endif /* CONFIG_ARM64_MODULE_PLTS */ new = aarch64_insn_gen_nop();