From patchwork Tue Nov 21 17:38:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 10068651 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 C588B6022E for ; Tue, 21 Nov 2017 17:39:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B14C72961A for ; Tue, 21 Nov 2017 17:39:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A38F429879; Tue, 21 Nov 2017 17:39:43 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham 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 9242B2961A for ; Tue, 21 Nov 2017 17:39:42 +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=N1aGXx96NS6QYgvFVwPS0r3zpGDIreyAX3deVNi3oG0=; b=IwQ9wihi5cRG1L x9FklKEBWXbAqkKuzosgdcdELAVszftGrxx+/M6WKsNX+UIrp8GZhyOJkzng/l2KYSpjUby4Fj6dA HhXLwIU7UJdL4q39gILbMRIO0z8rlEKJoAwW/ddRqxy9e3tQ8sGIG+EaZ+9+QBDoOBXprZ30n3FxK 2I3Kn88tpqH8ZaaVuSUPg/7Bs8qa41cqPpij3cY/k4RpYkM/0zQVrIb6vQ13+qnLSi9d+qkMmdwQa XS3kyZ1o4KNdVAdLtW6xU8Y0Lkol57D8t5m0BRaBmMhFzUXo9Oiw6OESztvdMNEsAvoclkLC4EzK4 nf0wgqtKabAItgLGSWIw==; 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 1eHCWK-0003LU-9E; Tue, 21 Nov 2017 17:39:40 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eHCWF-00037M-Km for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2017 17:39:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=3q3P8dYaJEdOyabwK5jiVd7Nfm0vogoCJyw62qM7aHE=; b=ORoLS7hReMSrujidveDKvjHSIkVlu/vHppc93prMRapgpSvNYsuRWfEER7HA8K2LaSfA/pQVuzhuIZJmCyygbBsFJ/FFLs+quw6d15F0XZyZvXS0NafEETDbt1pr80t/51RzkiLN7QVoBVKSiC3t/yacjz0nRGaQLlf5oPL3WOE=; Received: from n2100.armlinux.org.uk ([fd8f:7570:feb6:1:214:fdff:fe10:4f86]:32886) by pandora.armlinux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1eHCVh-0005SW-E8; Tue, 21 Nov 2017 17:39:01 +0000 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.76) (envelope-from ) id 1eHCVe-0007nZ-CD; Tue, 21 Nov 2017 17:38:58 +0000 Date: Tue, 21 Nov 2017 17:38:57 +0000 From: Russell King - ARM Linux To: "Jason A. Donenfeld" , Will Deacon Subject: Re: [PATCH] arm: ensure symbol is a thumb symbol in new binutils Message-ID: <20171121173857.GJ31757@n2100.armlinux.org.uk> References: <20171121172751.29545-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171121172751.29545-1-Jason@zx2c4.com> 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-20171121_093936_210705_D41A52D1 X-CRM114-Status: GOOD ( 22.88 ) 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: stable@vger.kernel.org, lkml@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 Tue, Nov 21, 2017 at 06:27:51PM +0100, Jason A. Donenfeld wrote: > On older versions of binutils, \sym points to an aligned address. On > newer versions of binutils, \sym sometimes points to the unaligned thumb > address in mysterious and buggy circumstances. In order to homogenize > this behavior, rather than adding 1, we simply OR in 1, so that already > unaligned instructions don't change. This fix is required for a > pedestrian THUMB2_KERNEL to boot without crashing when built with > non-old binutils. > > While it works, the downside is that we have to add an `orr` instruction > to a fast path. The assembler can't do this at assemble time via "|1" > because "invalid operands (.text and *ABS* sections) for `|'", so we're > forced to do this. A better solution would be to have consistent > binutils behavior, or to have some kind of \sym feature detection that > won't turn into a maze of version comparisons. However, it's at the > moment unclear how to achieve this. > > The rest of this commit message contains all of the relevant > information. > > My tests concerned these versions: > broken: GNU ld (Gentoo 2.29.1 p3) 2.29.1 > working: GNU ld (GNU Binutils for Ubuntu) 2.26.1 > > These produced the following code: > --- broken 2017-11-21 17:44:14.523416082 +0100 > +++ working 2017-11-21 17:44:44.548461234 +0100 > @@ -133,7 +133,7 @@ > 160: f01a 0ff0 tst.w sl, #240 ; 0xf0 > 164: d111 bne.n 18a <__sys_trace> > 166: f5b7 7fc8 cmp.w r7, #400 ; 0x190 > - 16a: f2af 1e6a subw lr, pc, #362 ; 0x16a > + 16a: f2af 1e6b subw lr, pc, #363 ; 0x16b > 16e: bf38 it cc > 170: f858 f027 ldrcc.w pc, [r8, r7, lsl #2] > 174: a902 add r1, sp, #8 > > The differing instruction corresponds with this actual line in > arch/arm/kernel/entry-common.S: > badr lr, ret_fast_syscall @ return address > > Running the broken kernel results in a runtime OOPS with: > PC is at ret_fast_syscall+0x4/0x52 > LR is at ret_fast_syscall+0x2/0x52 > > The disassembly of that function for the crashing kernel is: > .text:00000000 ret_fast_syscall ; CODE XREF: sys_syscall+1C↓j > .text:00000000 CPSID I ; jumptable 00000840 cases 15,18-376 > .text:00000002 > .text:00000002 loc_2 ; DATA XREF: sys_syscall-6BA↓o > .text:00000002 LDR.W R2, [R9,#8] > .text:00000006 CMP.W R2, #0xBF000000 > > Signed-off-by: Jason A. Donenfeld As it just seems to be a limited range of binutils versions that are affected, I'd rather not impact the kernel fast-paths with extra cycles just because binutils decided to change behaviour. I'd prefer to inform people about the problem and get them to change to a non- buggy binutils. This seems to be the second binutils bug that's biting us within the last month... what's going on with binutils QA? arch/arm/Makefile | 7 +++++-- arch/arm/tools/Makefile | 5 ++++- arch/arm/tools/toolcheck | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 1cfac5119545..9e70d0435121 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -319,16 +319,19 @@ all: $(notdir $(KBUILD_IMAGE)) $(KBUILD_DTBS) archheaders: $(Q)$(MAKE) $(build)=arch/arm/tools uapi -archprepare: +archprepare: toolcheck $(Q)$(MAKE) $(build)=arch/arm/tools kapi +toolcheck: + $(Q)$(MAKE) $(build)=arch/arm/tools $@ + # Convert bzImage to zImage bzImage: zImage BOOT_TARGETS = zImage Image xipImage bootpImage uImage INSTALL_TARGETS = zinstall uinstall install -PHONY += bzImage $(BOOT_TARGETS) $(INSTALL_TARGETS) +PHONY += bzImage $(BOOT_TARGETS) $(INSTALL_TARGETS) toolcheck bootpImage uImage: zImage zImage: Image diff --git a/arch/arm/tools/Makefile b/arch/arm/tools/Makefile index ddb89a7db36f..fa77351ccefd 100644 --- a/arch/arm/tools/Makefile +++ b/arch/arm/tools/Makefile @@ -23,12 +23,15 @@ uapi-hdrs-y += $(uapi)/unistd-eabi.h targets += $(addprefix ../../../,$(gen-y) $(kapi-hdrs-y) $(uapi-hdrs-y)) -PHONY += kapi uapi +PHONY += kapi uapi toolcheck kapi: $(kapi-hdrs-y) $(gen-y) uapi: $(uapi-hdrs-y) +toolcheck: + @$(CONFIG_SHELL) '$(srctree)/$(src)/toolcheck' + # Create output directory if not already present _dummy := $(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)') \ $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') diff --git a/arch/arm/tools/toolcheck b/arch/arm/tools/toolcheck index e69de29bb2d1..97bbeeb691da 100644 --- a/arch/arm/tools/toolcheck +++ b/arch/arm/tools/toolcheck @@ -0,0 +1,24 @@ +#!/bin/sh -ex +if grep -q 'CONFIG_THUMB2_KERNEL=y' .config; then + tmp=$(mktemp -d /tmp/binutils-test.XXXXXXXXXX) + cat <&2 + $AS --version | head -n1 >&2 + rm $tmp/*.o + rmdir $tmp + exit 1 + fi + rm $tmp/*.o + rmdir $tmp +fi