From patchwork Thu Nov 12 10:30:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 56420 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp335443lbb; Thu, 12 Nov 2015 02:32:56 -0800 (PST) X-Received: by 10.68.98.129 with SMTP id ei1mr21704539pbb.7.1447324376770; Thu, 12 Nov 2015 02:32:56 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id tw1si19163140pab.195.2015.11.12.02.32.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Nov 2015 02:32:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zwp9X-00085W-TA; Thu, 12 Nov 2015 10:30:51 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zwp9U-00084F-JK for linux-arm-kernel@lists.infradead.org; Thu, 12 Nov 2015 10:30:49 +0000 Received: by wmww144 with SMTP id w144so194197187wmw.1 for ; Thu, 12 Nov 2015 02:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=dDwHtMA9yjPfPwRHflttoRdHWqF3e2RnlFfyLnAEsaI=; b=unZD8fuapmYeJ20wT+LLKu+8hLh+lnm/9Ix+U72Kljpjvrt+OAquimAKsenstEnamo 1qLPY64J5+44YgbKrWIZiaSBoq3IonOEEUfnzjIf85CPQSsyGVWxPhkAeKOl/RxVuUCk LM2VO+upX8EijwuhhIOsdQa1B5c62hJXsg6egAi3qCO+uwM/gcSGydyz6f/poS+PPFEw /SlYPiCc1b0yOvA/0n5iuIdSeNon9ZHAophlMgrwy5ImQtiqNq7cS5VtroS3jN+N4cUi sG2TRM5uR8xYzdomaRLwnRc2IojHJd2A/TDd82HLNa8EkRY9Dv1ZUYSa66JVkLuVNRiB bqUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=dDwHtMA9yjPfPwRHflttoRdHWqF3e2RnlFfyLnAEsaI=; b=VuUh1W0FGLlSw84pP9EcMQntYjn6Hzggm+5X2FVdaISqD5wq70/WPxKnouiPs8nVTj ELJEFuQPuYNH9mJIGQ8Cg0O7KkOcijYAYD0jyoIv6vouSRGAmvjwySYb9snbqARUBX2N 862VgNgOBszCDOpat9TEMIbEHCdVwl1AI6tH6fDGwn0oVr0BFNvVeQNn5BIM7yIF4y0k RgTte9IFF4hP2Q/wxNai7Eh/xVegGEU+NIatbU/5KPtpbY5vhlDqY5Xx5Yzw/Reir1Z9 aUcTNMZW5WET5YQI6r6Luci33Yz/8dRPbDkc97hpXAPQHBXL9X+OwhsT6ucFgYqvIMdt CW0A== X-Gm-Message-State: ALoCoQkueMBbPaQwPfzQmfT0LWbAMCESYj/7GAbmF1JHzWL1TXJjwvJLZfzK/yc1vizb4tUKz3h6 X-Received: by 10.194.186.238 with SMTP id fn14mr16919304wjc.128.1447324226795; Thu, 12 Nov 2015 02:30:26 -0800 (PST) Received: from [192.168.1.5] (net-93-67-204-118.cust.vodafonedsl.it. [93.67.204.118]) by smtp.gmail.com with ESMTPSA id at4sm13707621wjc.9.2015.11.12.02.30.25 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 Nov 2015 02:30:26 -0800 (PST) From: Ard Biesheuvel Subject: Re: pj4 -marm breaks thumb ftrace To: Stephen Boyd References: <20151112095020.GB15032@codeaurora.org> Message-ID: <56446A40.7000304@linaro.org> Date: Thu, 12 Nov 2015 11:30:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <20151112095020.GB15032@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151112_023048_789780_64EFCFDE X-CRM114-Status: GOOD ( 25.41 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:234 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Olof Johansson , Russell King , "linux-arm-kernel@lists.infradead.org" , Nicolas Pitre Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org On 12 November 2015 at 10:50, Stephen Boyd wrote: > When I boot up a thumb2 multi-v7 kernel with ftrace enabled I get > this ftrace bug splat. > > WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:1979 > ftrace_bug+0x115/0x1bc() > Modules linked in: > CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.3.0-10337-g3ea2911b81d3-dirty #129 > Hardware name: Qualcomm (Flattened Device Tree) > [] (unwind_backtrace) from [] (show_stack+0x11/0x14) > [] (show_stack) from [] (dump_stack+0x57/0x6c) > [] (dump_stack) from [] (warn_slowpath_common+0x57/0x88) > [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) > [] (warn_slowpath_null) from [] (ftrace_bug+0x115/0x1bc) > [] (ftrace_bug) from [] (ftrace_process_locs+0x1d7/0x3e4) > [] (ftrace_process_locs) from [] (ftrace_init+0x49/0xb0) > [] (ftrace_init) from [] (start_kernel+0x26f/0x2d8) > [] (start_kernel) from [<0020807f>] (0x20807f) > ---[ end trace cb88537fdc8fa200 ]--- > ftrace failed to modify [] iwmmxt_do+0x8/0x3c > actual: dc:f8:ff:fa > ftrace record flags: 0 > (0) expected tramp: c030c565 > > I suspect this is caused by commit 13d1b9575ac2 (ARM: 8221/1: > PJ4: allow building in Thumb-2 mode, 2014-11-25) which adds an > -marm flag to the compilation of arch/arm/kernel/pj4-cp0.c. When > ftrace tries to replace the instruction in ftrace_make_nop() -> > ftrace_modify_code(), it gets confused because it checks to make > sure the instruction it's replacing is actually a branch to > mcount with a thumb encoding. But given that the branch is done > in arm instead of thumb it doesn't see the instruction it's > looking for and bails out with this bug. > > Should we mark this whole file as notrace? That at least seems to > fix the problem for me. I imagine we could make things more > complicated and try to figure out if the branch is either arm or > thumb and replace it with the appropriate nop or interworking > branch to ftrace code, but do we really care? > I wonder if we should simply fix the code instead. Compiling pj4-cp0.c in thumb mode fails on the sub instruction in the following sequence: static void __init pj4_cp_access_write(u32 value) { u32 temp; __asm__ __volatile__ ( "mcr p15, 0, %1, c1, c0, 2\n\t" "mrc p15, 0, %0, c1, c0, 2\n\t" "mov %0, %0\n\t" "sub pc, pc, #4\n\t" : "=r" (temp) : "r" (value)); } I wonder if the sub instruction is simply there to flush the pipeline, but let's not get into that. I propose we just apply the patch below to move this code (and its _read() counterpart) to iwmmxt.S, which is already built as ARM, and not subject to instrumentation. -----8<----- From de52762b71c85c6c2142a67ba8833a13d4ca8acb Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Thu, 12 Nov 2015 11:17:46 +0100 Subject: [PATCH] ARM: PJ4: move coprocessor register access sequences to iwmmxt.S The PJ4 inline asm sequences in pj4-cp0.c cannot be built in Thumb-2 mode, due to the way they perform arithmetic on the program counter, so it is built in ARM mode instead. However, building C files in ARM mode under CONFIG_THUMB2_KERNEL is problematic, since the instrumentation performed by subsystems like ftrace does not expect having to deal with interworking branches. So instead, revert to building pj4-cp0.c in Thumb-2 mode, and move the offending sequences to iwmmxt.S, which is not instrumented anyway, and is already built in ARM mode unconditionally. Reported-by: Stephen Boyd Signed-off-by: Ard Biesheuvel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index af9e59bf3831..3c789496297f 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -73,7 +73,6 @@ obj-$(CONFIG_IWMMXT) += iwmmxt.o obj-$(CONFIG_PERF_EVENTS) += perf_regs.o perf_callchain.o obj-$(CONFIG_HW_PERF_EVENTS) += perf_event_xscale.o perf_event_v6.o \ perf_event_v7.o -CFLAGS_pj4-cp0.o := -marm AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt obj-$(CONFIG_ARM_CPU_TOPOLOGY) += topology.o obj-$(CONFIG_VDSO) += vdso.o diff --git a/arch/arm/kernel/iwmmxt.S b/arch/arm/kernel/iwmmxt.S index 49fadbda8c63..2cd418f1b9c3 100644 --- a/arch/arm/kernel/iwmmxt.S +++ b/arch/arm/kernel/iwmmxt.S @@ -370,3 +370,19 @@ ENDPROC(iwmmxt_task_release) concan_owner: .word 0 +#if defined(CONFIG_CPU_PJ4) || defined(CONFIG_CPU_PJ4B) + +ENTRY(pj4_cp_access_read) + mrc p15, 0, r0, c1, c0, 2 + ret lr +ENDPROC(pj4_cp_access_read) + +ENTRY(pj4_cp_access_write) + mcr p15, 0, r0, c1, c0, 2 + mrc p15, 0, r0, c1, c0, 2 + mov r0, r0 + sub pc, pc, #4 + ret lr +ENDPROC(pj4_cp_access_write) + +#endif diff --git a/arch/arm/kernel/pj4-cp0.c b/arch/arm/kernel/pj4-cp0.c index 8153e36b2491..4f226e175734 100644 --- a/arch/arm/kernel/pj4-cp0.c +++ b/arch/arm/kernel/pj4-cp0.c @@ -49,28 +49,8 @@ .notifier_call = iwmmxt_do, }; - -static u32 __init pj4_cp_access_read(void) -{ - u32 value; - - __asm__ __volatile__ ( - "mrc p15, 0, %0, c1, c0, 2\n\t" - : "=r" (value)); - return value; -} - -static void __init pj4_cp_access_write(u32 value) -{ - u32 temp; - - __asm__ __volatile__ ( - "mcr p15, 0, %1, c1, c0, 2\n\t" - "mrc p15, 0, %0, c1, c0, 2\n\t" - "mov %0, %0\n\t" - "sub pc, pc, #4\n\t" - : "=r" (temp) : "r" (value)); -} +asmlinkage u32 pj4_cp_access_read(void); +asmlinkage void pj4_cp_access_write(u32 value); static int __init pj4_get_iwmmxt_version(void) {