Received: by 10.192.165.148 with SMTP id m20csp4998111imm; Tue, 8 May 2018 19:37:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrs9kSXi8geZvM4eeqY7Vg83MY3qpwsu6bgw37/VtI4wNSv+G87sQUjP1toLekAMjfPD46U X-Received: by 10.98.150.92 with SMTP id c89mr42393457pfe.37.1525833446630; Tue, 08 May 2018 19:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525833446; cv=none; d=google.com; s=arc-20160816; b=D2eTc/FAF4+PHgMBV3FeRfzWKH2jrGYhr3TCKUx0RRXZfEME4EmUuTjIkiecmOXn3+ p0LmKJZG2Qye900fGBx72sw9+eIaKRBYJLVP7W5zn4LCkyE86T9f6Zp2urR0NohiI5Ag fA4G9yzLUzHs8Vu9G5HFG8oT1l9TaAD5wyMeoolUpPip2s8thXLF+jHMy5w1Qx7nqcuY GjSd/lvc1ci1CvA0GC4vqiSOjM585zihAzGjNVfWyMIiux/EjiVEIcOIvPVx+qwfFUGG 7YSYqvyFZqGPbfBBt9iToSRdOaVAUEUUDLXXVlUDc2f2VFQwVrXvKRGAV8vVT2laNKET LlNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=HLL3Dn7SVHz3ktVRPzIWaJQo0sf6haqbg3pUFUSO7EQ=; b=MPA9kWSzPE7TMBOk8NMsKjl2H2PMwbDPKmlMRNPBjNQRILV8XzDJxlH3tM5TMot4tK Ah97Y0gY6qEDS91HzLiRJw73UBZPVQa1Y03gqkEcYJOUT+4ZAeQfSrwm/Nie8IBDu+oe 77ozcunNGdnTkugMfuL1sRDZgVTH9rIEtosH+lVfSdhtk+/3Jv6eqlsl2jMaHZSD965j Q/0lQ+EBM0YpIIdeU81PyBy2KxfSTRXbP1uL5lRW/MXtHZ2ZaOner1bpjLidi5G0F4z0 saF/7T92tc2QUqzo6Yfdl6kaG1VkPCIJWqL13F+jKZPhscb/Foh0Oc3bbSSuBCcRr4pT 6w4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f28-v6si27055420plj.255.2018.05.08.19.37.12; Tue, 08 May 2018 19:37:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933590AbeEICgu (ORCPT + 99 others); Tue, 8 May 2018 22:36:50 -0400 Received: from exmail.andestech.com ([59.124.169.137]:29487 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932115AbeEICgt (ORCPT ); Tue, 8 May 2018 22:36:49 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w492S5kQ096948; Wed, 9 May 2018 10:28:05 +0800 (GMT-8) (envelope-from alankao@andestech.com) Received: from andestech.com (10.0.1.85) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Wed, 9 May 2018 10:36:04 +0800 Date: Wed, 9 May 2018 10:36:05 +0800 From: Alan Kao To: Steven Rostedt CC: Palmer Dabbelt , Albert Ou , , , "Ingo Molnar" , Greentime Hu , Zong Li Subject: Re: [PATCH] riscv/ftrace: Fix the problem modules cannot find _mcount Message-ID: <20180509023605.GB7303@andestech.com> References: <1525749717-384-1-git-send-email-alankao@andestech.com> <20180508091142.12b5231a@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180508091142.12b5231a@gandalf.local.home> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [10.0.1.85] X-DNSRBL: X-MAIL: ATCSQR.andestech.com w492S5kQ096948 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 08, 2018 at 09:11:42AM -0400, Steven Rostedt wrote: > On Tue, 8 May 2018 11:21:57 +0800 > Alan Kao wrote: > > > Enabling ftrace and module support at the same time fails the kernel > > build process, because modules cannot find the _mcount symbol. This > > patch fixes this issue. > > I think you have a much bigger issue. > Yes, we do, but not this one. Let me state more detail later. > > > > Signed-off-by: Alan Kao > > Cc: Greentime Hu > > Cc: Zong Li > > --- > > arch/riscv/kernel/mcount.S | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/riscv/kernel/mcount.S b/arch/riscv/kernel/mcount.S > > index ce9bdc57a2a1..5721624886a1 100644 > > --- a/arch/riscv/kernel/mcount.S > > +++ b/arch/riscv/kernel/mcount.S > > @@ -126,5 +126,5 @@ do_trace: > > RESTORE_ABI_STATE > > ret > > ENDPROC(_mcount) > > -EXPORT_SYMBOL(_mcount) > > #endif > > +EXPORT_SYMBOL(_mcount) > > How does this work? How do you export _mcount if _mcount isn't even > defined? _mcount is defined. This EXPORT_SYMBOL and the _mcount body was inside a "#ifndef CONFIG_DYNAMIC_FTRACE" section, so if the config has dynamic ftrace disabled, _mcount is visible. For the dynamic ftrace case, there is a code snippet in this file: > ENTRY(ftrace_stub) > #ifdef CONFIG_DYNAMIC_FTRACE > .global _mcount > .set _mcount, ftrace_stub > #endif > ret > ENDPROC(ftrace_stub) so the _mcount symbol is visible in the kernel, but not for modules. As a result, a module build always fails, because _mcount is neither exported, nor aliased to a defined symbol. That's the simple purpose of this patch: we just want to eliminate the errors during the kernel build process. > > -- Steve Talking about some bigger issues here, there will be twofold. 1. This patch lacks call-site collecting mechanism. This feature requires a pattern check in recordmcount.pl. With this, section __mcount_loc is properly constructed, and the call-sites will be registered during the loading stage. However, the loading will then fail at the first try of make_nop, due to the instruction check. This is thus the second issue. 2. The instruction check for kernel texts is not applicable to module texts. The check expects a call instruction to _mcount, but here it is a call to the .plt section of the module. After referencing the implementation of arm64, I think it would need much more work to have make_nop's and make_call's behavior right. Quick summary: This patch ensures that a kernel build will not fail because of the _mcount-missing problem. But ftrace cannot trace loading modules for now due to the stated reasons. Thanks, Alan Kao