From patchwork Tue Nov 21 17:27:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 10068643 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 7B73E6038F for ; Tue, 21 Nov 2017 17:28:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6636129804 for ; Tue, 21 Nov 2017 17:28:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5ACCE2985C; Tue, 21 Nov 2017 17:28:49 +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 9E38029804 for ; Tue, 21 Nov 2017 17:28:48 +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:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=KJIJt+IbKoHuhUYckZfMaMyjR3tHn9nXvaVhlGVe4D8=; b=K7tPmG3wuHlRO3 Pio6O+Z6Q3JoKD2RhyySzyN8NHoGB1tdDmp9QSxxmkR3LQ3UvrM2dDMJJKc0JS4ZTAEs2tlXiAdCS z8vs43kiAkIlVw9M17wYwxLp2rPKm6eyFPc5qcgnvenJzVLRlYpkf7RBfDLvRggzF62WdTRbwfU2u eaKq0h3pN4NMDRVqCt+LQlBpKIM7ILL0AZ+1OKHZF4XuxyHsiqM3GYeLsLI9m+ql9LY1YxDGI8aNh aXe8byn0DFFnH99C4DtX1RskT2s1OdqaEkD+kJC6rRPClSoQZ+rXhbUCPpaV3VVFejl8fL8XOeAgs hRhiK9T0QqdkyrIWYrGg==; 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 1eHCLg-0006af-M7; Tue, 21 Nov 2017 17:28:40 +0000 Received: from frisell.zx2c4.com ([192.95.5.64]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eHCLd-0006Zm-40 for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2017 17:28:39 +0000 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 8626e851; Tue, 21 Nov 2017 17:23:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=mail; bh=c0+460oZbN7KwdgEBGtDzjH/B d4=; b=fvby3TgGYgcE8boJcSgwv2JYBA9jrsg/3DuWbrpYGZ1rzPgyaExHCta1X GRPbkHaMUHhUKFqA2JazKnT39ja1wgneKn6fEMEA6j3+d5ZwbbUxYeZ97iSJYZ2P 1C8N6ZbdIEKNMoivxg7UHGTgH4XzzJ0n3NIosOmVr32mqF3dwhEAWzh5/cKB7fiS VxaHxY0RqEdI7hNyR1Oip4g5HFodumC0CMRskbQ5nWmVxv6nIbzXC0sO03TwA9i6 6tGksZnKkwwI/XYVZni2o9UHSZsOeRe2+vETbl6c9NicBYlz9y1+T3gVnc2+9WGk akaleMUwpVh3HrJhYigAGO9vFw/jg== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 88ee8b58 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Tue, 21 Nov 2017 17:23:11 +0000 (UTC) From: "Jason A. Donenfeld" To: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org, lkml@vger.kernel.org Subject: [PATCH] arm: ensure symbol is a thumb symbol in new binutils Date: Tue, 21 Nov 2017 18:27:51 +0100 Message-Id: <20171121172751.29545-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171121_092837_384155_689B997C X-CRM114-Status: GOOD ( 10.32 ) 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: "Jason A. Donenfeld" , stable@vger.kernel.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 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: Tested-by: Chen-Yu Tsai --- 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 Cc: stable@vger.kernel.org --- arch/arm/include/asm/assembler.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index ad301f107dd2..c62a3b6b0a3e 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -194,10 +194,9 @@ */ .irp c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo .macro badr\c, rd, sym -#ifdef CONFIG_THUMB2_KERNEL - adr\c \rd, \sym + 1 -#else adr\c \rd, \sym +#ifdef CONFIG_THUMB2_KERNEL + orr\c \rd, \rd, 1 #endif .endm .endr