From patchwork Tue Jun 19 05:07:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10473171 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 C446760230 for ; Tue, 19 Jun 2018 05:07:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B389C287F5 for ; Tue, 19 Jun 2018 05:07:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A854A28C3A; Tue, 19 Jun 2018 05:07:31 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 63108287F5 for ; Tue, 19 Jun 2018 05:07:31 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Toe7kV7z5eDg9YHylkYb2e2jmbsARKd4W8/wW33NSiE=; b=KIz rEUadVGRNLGOklBbEqpTSHPCCw46k45CIpm1o5vyQl17/sb+xL0YuGJ3a+pjsn9HI/1be0MXjfUaw NkNeedK+oXAwrs1UfBGgevHJU8mekemvPZIsAYXX7dMUN5CcaHGYhQcmvJa1TsU0ZtBW7KQeUfZf4 YK36VgKFBa6Uq1twfKG6PgCnuRKBcFGVdV9j3zJ0JgolDo83gTzuSnhclx/mdoNUdn/kFfKS7vpgO khQghjJY/datH1PBTlHgESlfNX7jSCvkz05Nso9tizUPGc8vfRYEyHIjkClIFncf1ui/DwJBiukHD Z6GreTfvOWOtPNrqGPdLFJz+4vfNehg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fV8rV-0005oU-Hd; Tue, 19 Jun 2018 05:07:25 +0000 Received: from bh-25.webhostbox.net ([208.91.199.152]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fV8rS-0005mC-7C for linux-arm-kernel@lists.infradead.org; Tue, 19 Jun 2018 05:07:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z8cgD585kDnUvVqPEvFGplPJrwxAwOKkUDpJZ22iRLw=; b=lg7BLrE2LKnr6iL+zQOLNMV+jg k6o7DI0EY+Kfyy2O9LDx1gDfkHoBrDWr89+4yb9/5fU3zSEU/RvPwVawjse1p+z6ETUf9RrXPJDNh AeEdVjzU96fYK8gbPilXykE4VbmTdUANmn0Xg3f0COl3q7f9LibE4XEnHTvloX3e7/+ijGKHEf9NM 4KlDifY/GpbUHIMaQa+oeuEUAEfN73rtVZHqk7OPxLrsTEJASNP3/swOSQDFigFbktsMEwrdPYD6/ CbTxnvpx9Q/Tk56x22IedYN+ZmxCzKOdpNUd9u2zwQ01Ia78YX3N1PMSqkTdUS5UjAlSqQcyYIZf3 gGLE0bJQ==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:41206 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.89) (envelope-from ) id 1fV8rG-000M8D-Jd; Tue, 19 Jun 2018 05:07:11 +0000 From: Guenter Roeck To: Russell King Subject: [RFC PATCH] ARM: Use logical or instead of addition for badr address calculation Date: Mon, 18 Jun 2018 22:07:08 -0700 Message-Id: <1529384828-2452-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180618_220722_333873_69F0D482 X-CRM114-Status: GOOD ( 10.21 ) 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: Mark Rutland , Guenter Roeck , linux-arm-kernel@lists.infradead.org, Arnd Bergmann , linux-kernel@vger.kernel.org MIME-Version: 1.0 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 Modern assemblers may take the ISA into account when resolving local symbols. This can result in bad address calculations when using badr in the wrong location since the offset + 1 may be added twice, resulting in an even address target for THUMB instructions. This in turn results in an exception at (destination address + 2). Unhandled exception: IPSR = 00000006 LR = fffffff1 CPU: 0 PID: 1 Comm: init Not tainted 4.18.0-rc1-00026-gf773e5bdf0c9 #15 Hardware name: MPS2 (Device Tree Support) PC is at ret_fast_syscall+0x2/0x58 LR is at tty_ioctl+0x2a5/0x528 pc : [<21009002>] lr : [<210d1535>] psr: 4000000b sp : 21825fa8 ip : 0000001c fp : 21a95892 r10: 00000000 r9 : 21824000 r8 : 210091c0 r7 : 00000036 r6 : 21ae1ee0 r5 : 00000000 r4 : 21ae1f3c r3 : 00000000 r2 : 3d9adc25 r1 : 00000000 r0 : 00000000 xPSR: 4000000b CPU: 0 PID: 1 Comm: init Not tainted 4.18.0-rc1-00026-gf773e5bdf0c9 #15 Hardware name: MPS2 (Device Tree Support) [<2100bd8d>] (unwind_backtrace) from [<2100b13b>] (show_stack+0xb/0xc) [<2100b13b>] (show_stack) from [<2100b87b>] (__invalid_entry+0x4b/0x4c) Fix the problem by using a logical or instead of an addition. This is less efficient but guaranteed to work. Signed-off-by: Guenter Roeck --- RFC: I don't really like this, but my ARM assembler knowledge is quite limited. Just dropping the "+ 1" from badr doesn't work because some other code needs it (the image hangs completely if I try that). Ultimately I don't even know if the invoke_syscall macro should just have used adr instead of badr (but then how did this ever work ?). Seen with various toolchains based on gcc 7.x and binutils 2.30 when building and testing MPS2 images. arch/arm/include/asm/assembler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 0cd4dccbae78..24c87ff2060f 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -195,7 +195,8 @@ .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 + adr\c \rd, \sym + orr \rd, #1 #else adr\c \rd, \sym #endif