Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp230338pxk; Wed, 16 Sep 2020 02:59:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhIGAlC9TPzx1ctLwzzgsPKYU2Of2/RjNUyR9KgV14qXrFsGo7owNs88EwYkaBL2GY9Lnd X-Received: by 2002:a17:906:3088:: with SMTP id 8mr13670030ejv.487.1600250377793; Wed, 16 Sep 2020 02:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600250377; cv=none; d=google.com; s=arc-20160816; b=NmrbbjhTZXWtumVUw3c5XO/JV1rjxNFje3JjSLP3tzXwDvNgHR12/kwYdgpU8n7Roh AsT02hvtbU+oWl7i4E3L2DemM/eM3PSLaZWBPgvIJ74Ec9JCuFsEBbN0zf91mDp+EDlI JT+wUtZJeUzsrdQMY0l5CYHCbEFxt+2xVNh4lo2uiXvijuSs5h6jPmQJTBE+MH3AKeY4 Daf8UbmRUSVCuRJhWdJU1WOzwGSx56NL3zhu5ytBab8c9z8h1BEvJOxv6m+ts65F8+k/ xABUkImEiV6HXO56n+IGye+FtfVtn0LX2XoAEOV0mI8pcOQxWVKGiiFILp3huaz9AOqT 2BaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=9nbtQ/rGGl9+VkjNBbE6FrPbmJQcn1rh+ajni2XcJMA=; b=HsEtytQz0HAgEta+jUH7ccJdGGPqZ4/EQ5bmDCJGmpQzKP2CjuIGIGsP3ZDmE7klN5 fH17aoSYYi1VCt1SMN9QDlJXy445Rd0qsXMV8G44bIihJU4gi9orAmV2hNWQrID6L2zB zIhpwJiR8KE7d3ZnCPQ7Yix8GreV2TdmyPZUMzRLG2f7tSEJjMeA2DmzAVA/k4y4RNZD 8XYYHRcFiVDwuNvLxPiobg06B4FARlkaQuK7JQFIZv/OySAF1GVoGoMnLi2hREeLfCk6 WGErB13H3E0rXMWmCCN9eL/3mrihJyMcEuFUdNZUA5AB+AwwmEIKusaM7TOxidq/reHK 6YfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oAEPLIi2; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k26si11433965edo.543.2020.09.16.02.59.08; Wed, 16 Sep 2020 02:59:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oAEPLIi2; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726349AbgIPJ7E (ORCPT + 99 others); Wed, 16 Sep 2020 05:59:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:35304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbgIPJ7C (ORCPT ); Wed, 16 Sep 2020 05:59:02 -0400 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 701AC22209 for ; Wed, 16 Sep 2020 09:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600250323; bh=qFni0sLz6kkB+YGb3b0+zGBDJ4LybpPsLb3ZISq3//w=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oAEPLIi2JgAiAC5Wi66g41NuprePDaKq2HPc9zHwbKyPSd2Ib2lL/Uvf1SgtI4rPe GKQpR7ytcXCzyI8CxOitn24fEi7vkf8xzSitenC0td6VPNzoDvCxIZoWjgkyyhK3gl LC9xvw1ql0ROKO05jmJT2NFetc/70RkH7zLOu6rA= Received: by mail-ot1-f53.google.com with SMTP id n61so6088234ota.10 for ; Wed, 16 Sep 2020 02:58:43 -0700 (PDT) X-Gm-Message-State: AOAM532BPOA7qfHrHbyUe9X6YFOxILD8SAyeif3wc97JZTlVMnSanrrq gZdE1hc+8ERsU+2ASQ4OinQrxhX+cFQK5FGATeA= X-Received: by 2002:a9d:6193:: with SMTP id g19mr15441181otk.108.1600250322785; Wed, 16 Sep 2020 02:58:42 -0700 (PDT) MIME-Version: 1.0 References: <20200915094619.32548-1-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Wed, 16 Sep 2020 12:58:31 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] crypto: arm/sha256-neon - avoid ADRL pseudo instruction To: Stefan Agner Cc: Nick Desaulniers , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Herbert Xu , Peter Smith Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, 16 Sep 2020 at 10:45, Stefan Agner wrote: > > On 2020-09-15 23:31, Ard Biesheuvel wrote: > > On Tue, 15 Sep 2020 at 21:50, Nick Desaulniers wrote: > >> > >> On Tue, Sep 15, 2020 at 2:46 AM Ard Biesheuvel wrote: > >> > > >> > The ADRL pseudo instruction is not an architectural construct, but a > >> > convenience macro that was supported by the ARM proprietary assembler > >> > and adopted by binutils GAS as well, but only when assembling in 32-bit > >> > ARM mode. Therefore, it can only be used in assembler code that is known > >> > to assemble in ARM mode only, but as it turns out, the Clang assembler > >> > does not implement ADRL at all, and so it is better to get rid of it > >> > entirely. > >> > > >> > So replace the ADRL instruction with a ADR instruction that refers to > >> > a nearer symbol, and apply the delta explicitly using an additional > >> > instruction. > >> > > >> > Cc: Nick Desaulniers > >> > Cc: Stefan Agner > >> > Cc: Peter Smith > >> > Signed-off-by: Ard Biesheuvel > >> > --- > >> > I will leave it to the Clang folks to decide whether this needs to be > >> > backported and how far, but a Cc stable seems reasonable here. > >> > > >> > arch/arm/crypto/sha256-armv4.pl | 4 ++-- > >> > arch/arm/crypto/sha256-core.S_shipped | 4 ++-- > >> > 2 files changed, 4 insertions(+), 4 deletions(-) > >> > > >> > diff --git a/arch/arm/crypto/sha256-armv4.pl b/arch/arm/crypto/sha256-armv4.pl > >> > index 9f96ff48e4a8..8aeb2e82f915 100644 > >> > --- a/arch/arm/crypto/sha256-armv4.pl > >> > +++ b/arch/arm/crypto/sha256-armv4.pl > >> > @@ -175,7 +175,6 @@ $code=<<___; > >> > #else > >> > .syntax unified > >> > # ifdef __thumb2__ > >> > -# define adrl adr > >> > .thumb > >> > # else > >> > .code 32 > >> > @@ -471,7 +470,8 @@ sha256_block_data_order_neon: > >> > stmdb sp!,{r4-r12,lr} > >> > > >> > sub $H,sp,#16*4+16 > >> > - adrl $Ktbl,K256 > >> > + adr $Ktbl,.Lsha256_block_data_order > >> > + add $Ktbl,$Ktbl,#K256-.Lsha256_block_data_order > >> > bic $H,$H,#15 @ align for 128-bit stores > >> > mov $t2,sp > >> > mov sp,$H @ alloca > >> > diff --git a/arch/arm/crypto/sha256-core.S_shipped b/arch/arm/crypto/sha256-core.S_shipped > >> > index ea04b2ab0c33..1861c4e8a5ba 100644 > >> > --- a/arch/arm/crypto/sha256-core.S_shipped > >> > +++ b/arch/arm/crypto/sha256-core.S_shipped > >> > @@ -56,7 +56,6 @@ > >> > #else > >> > .syntax unified > >> > # ifdef __thumb2__ > >> > -# define adrl adr > >> > .thumb > >> > # else > >> > .code 32 > >> > @@ -1885,7 +1884,8 @@ sha256_block_data_order_neon: > >> > stmdb sp!,{r4-r12,lr} > >> > > >> > sub r11,sp,#16*4+16 > >> > - adrl r14,K256 > >> > + adr r14,.Lsha256_block_data_order > >> > + add r14,r14,#K256-.Lsha256_block_data_order > >> > >> Hi Ard, > >> Thanks for the patch. With this patch applied: > >> > >> $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 LLVM_IAS=1 > >> -j71 defconfig > >> $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 LLVM_IAS=1 -j71 > >> ... > >> arch/arm/crypto/sha256-core.S:2038:2: error: out of range immediate fixup value > >> add r14,r14,#K256-.Lsha256_block_data_order > >> ^ > >> > >> :( > >> > > > > Strange. Could you change it to > > > > sub r14,r14,#.Lsha256_block_data_order-K256 > > > > and try again? > > > > If that does work, it means the Clang assembler does not update the > > instruction type for negative addends (add to sub in this case), which > > would be unfortunate, since it would be another functionality gap. > > Hm interesting, I did not come across another instance where this was a > problem. > > In this particular case, is it guaranteed to be a subtraction? I guess > then using sub for now would be fine...? > Yes for this code it is fine. > FWIW, we discussed possible solution also in this issue > (mach-omap2/sleep34xx.S case is handled already): > https://github.com/ClangBuiltLinux/linux/issues/430 > > -- > Stefan > > > > > > > > >> Would the adr_l macro you wrote in > >> https://lore.kernel.org/linux-arm-kernel/nycvar.YSQ.7.78.906.2009141003360.4095746@knanqh.ubzr/T/#t > >> be helpful here? > >> > >> > bic r11,r11,#15 @ align for 128-bit stores > >> > mov r12,sp > >> > mov sp,r11 @ alloca > >> > -- > >> > 2.17.1 > >> > > >> > >> > >> -- > >> Thanks, > >> ~Nick Desaulniers