From patchwork Tue Jun 19 07:48:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10473647 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 A83D2601D7 for ; Tue, 19 Jun 2018 07:54:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B38DA289E0 for ; Tue, 19 Jun 2018 07:54:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A845528A4F; Tue, 19 Jun 2018 07:54:44 +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 2A28C289E0 for ; Tue, 19 Jun 2018 07:54:44 +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:To:Subject:Message-ID:Date:From: References:In-Reply-To:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ik3JBPkw/XKFavNlnowUXWIDwlDk0Z4ju+Prs3Suapo=; b=TVHZbl5dlKg6BH es6ugrj9tppYhnjfOG/6j6TyL3ribmElbQJ/nMPEYK1s4Y476Gq+1w21fRjC90HeWRjwF3s9Sdp61 oFJ8KFIE/SJQs1tMcetZ+IdpPs0/ipC+qyONN17JbBX4Ot6sIpabh8ubQAxXke8gKsGvSzNwLc9nh ioes59cQIQYyWVW3T+1DwM31DEdz2b/pSgTWtRYonQfZNNJLQfyDCni2DabbEqvXDW1BdQ53yTL49 w7hhppi/V5ht4Y9upg/7++0nUl45H4P1GNAto39UneN/wG/B2zjVw1Cv2m05Yyl1+IYsxSMrhTsnC hHWsObVyPynhEBBYtaSg==; 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 1fVBTI-0001Xf-9D; Tue, 19 Jun 2018 07:54:36 +0000 Received: from mail-it0-x243.google.com ([2607:f8b0:4001:c0b::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVBNd-0005Qh-UT for linux-arm-kernel@lists.infradead.org; Tue, 19 Jun 2018 07:50:46 +0000 Received: by mail-it0-x243.google.com with SMTP id 188-v6so15818406ita.5 for ; Tue, 19 Jun 2018 00:48:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9cXZtrmGDYfDcl7fIjQLd2IFmwSiDih91kj5Drs6uSc=; b=NNaRmNhM3sNov4dqngIqr+csp302mX9hmG8DdFNhw494YdZ7svbeJHXcnzae2WWCh0 0dQk9i22Hpsi7LTqHEXTXWNrt/1gpLuthszqdfkbVHxqiBp6XFH1788gbnE2EWKJrNBs FnFj7PBHXHTkxVPvIlDJVF1cxVXMFazdEaIAY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9cXZtrmGDYfDcl7fIjQLd2IFmwSiDih91kj5Drs6uSc=; b=LEBIV0d1HdG8p7CtG53JSP+QwL4T03z4ywpQI9k++tnnwOezAik1TDkGKG8mdopgBY WY7E9Kpqfe9MigPppTAVHX63QMRpSy5Tq25WAy0IHgh8tOVmoKmv1QcAcaQRYus3/2VW +zwZLe4kK3WF1Eu1Rxr400hem938jgHiuCV8mgXtCfD8Qn6h/+bgPIjHoOVF+lJzznks uHkpAhQlQv2/cUf2Dv9vNhEEuotkThIaX8NQX4UuVzseJMOLBgt5b5AdTNFjB79s7FXo U7q+JLEhyWhKghg7+k5s63V8qrFm0lhWTHMkHyCdbeVTLBK0MuDXhTG7J69EfpaaqnWn B+GQ== X-Gm-Message-State: APt69E1vO20HNy8sXW8N09ES1J+07M58/9S+iI3xMdgYm7NpkTv0vVnL hyOVyFmH7FgQHutbN0D5UQhEr7SwNf3Il0sXqD3bDw== X-Google-Smtp-Source: ADUXVKKDrULtBpxqI2qRC3WFUmD6UoPH66tLxxq9k7cDIowj38g6x9LD0Z48UdldB+L02cD/gYL3+wOSFpw0GXXV6Ls= X-Received: by 2002:a24:1d0e:: with SMTP id 14-v6mr11918805itj.50.1529394514667; Tue, 19 Jun 2018 00:48:34 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Tue, 19 Jun 2018 00:48:34 -0700 (PDT) In-Reply-To: <1529384828-2452-1-git-send-email-linux@roeck-us.net> References: <1529384828-2452-1-git-send-email-linux@roeck-us.net> From: Ard Biesheuvel Date: Tue, 19 Jun 2018 09:48:34 +0200 Message-ID: Subject: Re: [RFC PATCH] ARM: Use logical or instead of addition for badr address calculation To: Guenter Roeck X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180619_004846_013829_876BAD07 X-CRM114-Status: GOOD ( 24.93 ) 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 , Arnd Bergmann , Russell King , linux-arm-kernel , Linux Kernel Mailing List 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 19 June 2018 at 07:07, Guenter Roeck wrote: > 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. > Hello Guenter, This issue has been discussed before. It appears the binutils people suddenly started caring about the thumb annotation of local function symbols, resulting in behavior that is not backwards compatible. https://marc.info/?l=linux-arm-kernel&m=151143776213636&w=2 https://sourceware.org/bugzilla/show_bug.cgi?id=21458 Can you try the fix below please? > 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 > -- > 2.7.4 ----------8<------------ From: Ard Biesheuvel Date: Tue, 16 Jan 2018 12:12:45 +0000 Subject: [PATCH] ARM: assembler: prevent ADR from setting the Thumb bit twice To work around recent issues where ADR references to Thumb function symbols may or may not have the Thumb bit set already when they are resolved by GAS, reference the symbol indirectly via a local symbol typed as 'object', stripping the ARM/Thumb annotation. Signed-off-by: Ard Biesheuvel diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 6ae42ad29518..dd2ff94ad90b 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -195,13 +195,19 @@ .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 + __badr \c, \rd, \sym #else adr\c \rd, \sym #endif .endm .endr + /* this needs to be a separate macro or \@ does not work correctly */ + .macro __badr, c, rd, sym + .eqv .Lsym\@, \sym + adr\c \rd, .Lsym\@ + 1 + .endm + /* * Get current thread_info. */