Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2914110pxk; Tue, 15 Sep 2020 05:50:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOcbQqijKAr/lHCNuKnlNZUEyHc28LEGWZ1+tpXEuS6IT3e+3pTYkNRSEBqyoNq/MBRjjL X-Received: by 2002:a50:fe82:: with SMTP id d2mr21512397edt.86.1600174218957; Tue, 15 Sep 2020 05:50:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1600174218; cv=pass; d=google.com; s=arc-20160816; b=Mzvz0Ke2sxdhW9JYDlGMNj1WPR0Ns/eRk7l5QC8WbY3xp8O3LJi/yIjJstFXZDMcCE Fx95KxyRPG5jNzReRx+iRuL5552FyE3S5Gwg4+fnMHpaDbmzVpsaUJkkUJ6WCCs1dRXY MKAJhM/gl1r+8n4zv6xVsfz3ti99RmbgBilXcNU4PHSXzlCpikS2N1t9p7TFoWWJglPg kMeAbXoRjRBSsKP3lBx4BO0SwEDXhGJWosWAxIIzSF7Oyo3HS+6u2jHnFE8b7nURsULH a62kozmhfXdTJDeotzvcYmtk8dL/tr0aP3IRllo2xqJ5XrEwUcEg2Jw32IejAkUfonSC 5Dgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature; bh=w/KVV9nEo7vVEtEkmiU0s2Uue4gBmhIfDdsab/KBGlA=; b=zSVkdkvTC/rLwLt2/drhZ3RtmqlyycTo4+jdw+WiVLRHlgtNgupBSkqvDolOogd5QA SQoOmfudNweCp5mFJgtZsyXarfBe/acrA+hNmoXR+yQ2IzVnqtq9UVxby0QCshzlt5pz /RZ+DGtElijnBY8v+yP9bogeqKLh+LW/S5SP83bAjOiOLxza6rT0gvyPvD0wrQV5VGuq kVB3BbBMKj735ZBO1PLoS4HNsoEfV/Fh7GC4JqGFkAGDqMBmhqhl6eDti0yfhqWnYV5P dY7WDxXVsrFa9qY8TTWyDX47tS2/4WQWCNeMyRBy8VcTw2cJ9zYDiT+0bFJYC8vXXdSF JK3w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Gw3ocHnW; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l21si9724004ejg.119.2020.09.15.05.49.45; Tue, 15 Sep 2020 05:50:18 -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=@nxp.com header.s=selector2 header.b=Gw3ocHnW; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbgIOMpw (ORCPT + 99 others); Tue, 15 Sep 2020 08:45:52 -0400 Received: from mail-eopbgr150080.outbound.protection.outlook.com ([40.107.15.80]:7554 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726183AbgIOMpC (ORCPT ); Tue, 15 Sep 2020 08:45:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CzVDCeIEY6MrYRFEv8OdRb1O1DEKZMK9kM9ZiHGy4TyxIecEUq+tC6vaBR6Ia6btDfTrAVCrcCxILnnw8EBrh70WV0DwMyx9yiYg2LLKVUwOqjVgjfTKTh3TskmWoXgGC0YTYbdLnqS3mLEN0jXWEVGKHn8nuOlcFq2E3J7hXr3EPjwbU1LW6bF2pnjipcLyQd29KazpihkMdr7rTO6ajadfI2XDhOY3G+2aDdq3AYryalgz0+Mb0VFVvXqGO/UiyiAtVhOZ/qsBmkXNcWBphAzh1zCOhn/muiLBmfpiNKExCE1gAjwHEJLv5BgLRCpyMtXuW282uoCd3NR3nX3aFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w/KVV9nEo7vVEtEkmiU0s2Uue4gBmhIfDdsab/KBGlA=; b=TxVUMQnMDpvLm8U3NF28Y5vyhXeddpT9L6BZ7C1pD2VOiQJCPiQ2xpsm27wpXn/bAIdZOhsXcu9IqDuJWylVr4eYZjankqvQyd2ZWuSCxE3C75HWhDiDzoUx4+2bB+6f36G729rvr3cbAUmzywVxTuA1Of8uCbmGNyvvp/M9h971tTLLHamlc9yxdVUPnOUVNwlRt5i/yyRnj37autuumvAzojj7ZGdZnNyk+Ca0hBRDXqkmG3xdR/H6inho9Wuslq/H62EvmA4SIQiJIARzQQEhIC4f9KdmHpqWy35sd4XESvte/eObFJLkLx51fo5C4LvRVMNpMMW8xY7nRXLaPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w/KVV9nEo7vVEtEkmiU0s2Uue4gBmhIfDdsab/KBGlA=; b=Gw3ocHnWGYhLQWEkv3ZzO2n7aaO5avP8IQipRWtQ8bCXoDVqx7RMtqIk45Aary/3ENTksi9E8iiyq+uZJHyy0/XL63/krrVEZsrpc8LlSPSDLJGV7THmw3yWt49gmDMNoCZhg0r4XUaZFS7VxgBxaWdWoUX//rLzemRHMV1yQL0= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB4046.eurprd04.prod.outlook.com (2603:10a6:803:4d::29) by VE1PR04MB6558.eurprd04.prod.outlook.com (2603:10a6:803:11b::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Tue, 15 Sep 2020 12:44:56 +0000 Received: from VI1PR04MB4046.eurprd04.prod.outlook.com ([fe80::847a:fcdb:3b92:7a7d]) by VI1PR04MB4046.eurprd04.prod.outlook.com ([fe80::847a:fcdb:3b92:7a7d%5]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 12:44:56 +0000 Subject: Re: [PATCH RESEND 1/9] crypto: caam/jr - add fallback for XTS with more than 8B IV To: Ard Biesheuvel Cc: Herbert Xu , "Andrei Botila (OSS)" , Aymen Sghaier , "David S. Miller" , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20200806163551.14395-1-andrei.botila@oss.nxp.com> <20200806163551.14395-2-andrei.botila@oss.nxp.com> <20200821034651.GA25442@gondor.apana.org.au> <20200908221019.GA23497@gondor.apana.org.au> <67159207-1082-48be-d085-971a84b525e0@nxp.com> <38f9904b-5bf7-ea99-ed8a-27cb49f405bd@nxp.com> <4393bf96-30fd-0d1c-73fe-f5ef7c967f76@nxp.com> From: =?UTF-8?Q?Horia_Geant=c4=83?= Message-ID: <89b9c29d-afb1-0082-66f6-8bb930710884@nxp.com> Date: Tue, 15 Sep 2020 15:44:52 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-ClientProxiedBy: AM0PR03CA0013.eurprd03.prod.outlook.com (2603:10a6:208:14::26) To VI1PR04MB4046.eurprd04.prod.outlook.com (2603:10a6:803:4d::29) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.0.129] (78.97.206.147) by AM0PR03CA0013.eurprd03.prod.outlook.com (2603:10a6:208:14::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11 via Frontend Transport; Tue, 15 Sep 2020 12:44:55 +0000 X-Originating-IP: [78.97.206.147] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5c19f377-8e63-4ea8-8d5e-08d859752618 X-MS-TrafficTypeDiagnostic: VE1PR04MB6558: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C/un5SP33D5XQQBSB15EP3FyaL/w0Y8itrsyEW0jPF4jiTbx9CDhlJLdwuEqbhuPGu+UQyBXeD1CYhhyGuLFxrmqQGsFTIzm6X6TnH8VWWjuGsHO6O1QglRzetxCHfY8RroRzlb84W69qS3hDeeHteyCAmWXsu5D9pPudIhCEVtoBvacBLiNQD898fohjdvIckgngXZCL5hcVfDeLWnQ9XqnEee9GJZw9xaQfe34uQz0hNjXaaDzKzqbZgZDYvWtQKWMC+1OWcOYgYiHp0x4UWsC625YIthFDVyuoEJJbTi6AdtvityFWKfHiBYe4dWwqvHnOX4A5OOXik8MU7YYbmqzhi/MkYorLcI7vCraXeDsvs+7PYendaKl3YdBQoE4hxxjz0LfLf/2NOcEkNyWIDLqOrm/57jQJbE52R6wE9uF/fnuQWqoblmnKJoxXsU2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB4046.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(376002)(39860400002)(346002)(136003)(396003)(8936002)(6916009)(4326008)(8676002)(316002)(6666004)(186003)(16526019)(16576012)(31686004)(36756003)(2906002)(53546011)(26005)(86362001)(66476007)(52116002)(66946007)(31696002)(66556008)(478600001)(5660300002)(956004)(2616005)(54906003)(83380400001)(6486002)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cPS778RxxUabvB6Uxwg2kJcie7tgJJknssHJJgkwMvpFzrFnsVQpCG7qXbpRPNHs9O0iWq7t7UXuqYCJLICRu3oC8u6A4svCX36iLUtkZcOCFUo48HzM06ZVyBay9VhnwMZfMIvgd0HFPxwVms82jN32MnhvPM+4Qq3mRDWY+umhOtvBiQ4hAmCMvgVWrr2Ys7LjYbEi3nTllre9Gse+9NHHg9yeY+TosXY+dnFhvlpDY0q1vdHpoJ7Fu43Rb3dw14r3QsHuVyLacqoYPSkgW8gF/XbKIohkbfsBBAZAi9ctFNr2PShlmSzVYkCqquVtu+oFDzdYyPVDree4mxQWdgl9/YoBS5lbR4e4De6pA2lxWxUytV2QMFrWykJuxijcy9G1hXCOl5Fr12w0pF108oG6JRpsfP8KjfTZY+IyJUQ1je57bFq1x9OQx+osb/3ibG/jHb09ddXsMCkzu+bkoEKzCyCHlm9sxv+viHbL07alTN0RCR5pL9Gw5hAFrXFO32fMc9nvS0ElIDr4FhNh3jYCK6iCwvNluH2xnvs2+BL+2JZtC65ZU7CK16hINLv0cCp9Wr60WAetyhiI6PIQJaLOR8PYJOLbOh+ZojkMnXSYN2gyJ9C3tfHN6PkNt/Bq1zIV6x/J70QK1Q4GG1lcuA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c19f377-8e63-4ea8-8d5e-08d859752618 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB4046.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 12:44:56.0742 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0xBBXnK8TJ5H/IYz5MetT+fffF9h7GYkedju48L/K2SV7gd6RMsWO99c/f4FAUe3JQp7e7eMMlFA8lOibJualg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6558 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 9/15/2020 1:26 PM, Ard Biesheuvel wrote: > On Tue, 15 Sep 2020 at 13:02, Horia Geantă wrote: >> >> On 9/14/2020 9:20 PM, Ard Biesheuvel wrote: >>> On Mon, 14 Sep 2020 at 20:12, Horia Geantă wrote: >>>> >>>> On 9/14/2020 7:28 PM, Ard Biesheuvel wrote: >>>>> On Mon, 14 Sep 2020 at 19:24, Horia Geantă wrote: >>>>>> >>>>>> On 9/9/2020 1:10 AM, Herbert Xu wrote: >>>>>>> On Tue, Sep 08, 2020 at 01:35:04PM +0300, Horia Geantă wrote: >>>>>>>> >>>>>>>>> Just go with the get_unaligned unconditionally. >>>>>>>> >>>>>>>> Won't this lead to sub-optimal code for ARMv7 >>>>>>>> in case the IV is aligned? >>>>>>> >>>>>>> If this should be optimised in ARMv7 then that should be done >>>>>>> in get_unaligned itself and not open-coded. >>>>>>> >>>>>> I am not sure what's wrong with avoiding using the unaligned accessors >>>>>> in case data is aligned. >>>>>> >>>>>> Documentation/core-api/unaligned-memory-access.rst clearly states: >>>>>> These macros work for memory accesses of any length (not just 32 bits as >>>>>> in the examples above). Be aware that when compared to standard access of >>>>>> aligned memory, using these macros to access unaligned memory can be costly in >>>>>> terms of performance. >>>>>> >>>>>> So IMO it makes sense to use get_unaligned() only when needed. >>>>>> There are several cases of users doing this, e.g. siphash. >>>>>> >>>>> >>>>> For ARMv7 code, using the unaligned accessors unconditionally is fine, >>>>> and it will not affect performance. >>>>> >>>>> In general, when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is defined, >>>>> you can use the unaligned accessors. If it is not, it helps to have >>>>> different code paths. >>>>> >>>> arch/arm/include/asm/unaligned.h doesn't make use of >>>> linux/unaligned/access_ok.h, even if CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS >>>> is set. >>>> >>>> I understand the comment in the file, however using get_unaligned() >>>> unconditionally takes away the opportunity to generate optimized code >>>> (using ldrd/ldm) when data is aligned. >>>> >>> >>> But the minimal optimization that is possible here (one ldrd/ldm >>> instruction vs two ldr instructions) is defeated by the fact that you >>> are using a conditional branch to select between the two. And this is >>> not even a hot path to begin with, >>> >> This is actually on the hot path (encrypt/decrypt callbacks), >> but you're probably right that the conditional branching is going to offset >> the optimized code. >> > > This is called once per XTS request, right? And you are saying the > extra cycle makes a difference? > Yes, once per request and no, not super-important. >> To avoid branching, code could be rewritten as: >> >> #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS >> size = *(u64 *)(req->iv + (ivsize / 2)); >> #else >> size = get_unaligned((u64 *)(req->iv + (ivsize / 2))); >> #endif >> >> however in this case ARMv7 would suffer since >> CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y and >> ldrd/ldm for accesses not word-aligned are inefficient - lead to traps. >> > > CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS means 'just use the unaligned > accessors as they are basically free'. Casting a potentially > misaligned u8* to a u64* is not permitted by the C standard. > Seems that I misunderstood CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS. Looking at its usage, e.g. ether_addr_equal() or __crypto_memneq_*(), I see similar casts of pointers possibly misaligned. >> Would it be ok to use: >> #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && !defined(CONFIG_ARM) >> to workaround the ARMv7 inconsistency? >> > > No, please just use the get_unaligned() accessor. > Ok. Thanks, Horia