From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C61A0C47088 for ; Wed, 26 May 2021 19:12:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 92603613B5 for ; Wed, 26 May 2021 19:12:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92603613B5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qKdkfHzjBJESROOlpFqxEBTI757wM4Q8gZJwdDciR8E=; b=JTWKrrBnY2dFS5 Fydrv8zK7aeUexRKMWsEPTdUjOQkBBYdXK1zBQTeOBpjT2+ufc0C9hrCXZYQUWTPMrNpwtqx78LY0 oZNgwXjBsthVSMG/9Zi+xngOT9miyDw7xS1wuGkdwylIkPgs2UCYzl7k0h+9ZT/20+6QaaEpnZ8na EizzyY/4G6vgTbxkneN7eArwHP/ZJ+1ag2ueAV3NEmU12Z+RYX7h7hDRlwgAQ9Gm4hhJjMJJsJnkA otsy384W3l5rK55hIvHM126gmIUvfBZ9J9U4G56x/F3V1l8oZ294NT9K2dzN1Y9c0dj0GEBPqcJl0 3ysanPIdKJFlAYzgI37w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llyuW-00Gpuj-Re; Wed, 26 May 2021 19:09:46 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1llxx3-00GNaE-Uh for linux-arm-kernel@lists.infradead.org; Wed, 26 May 2021 18:08:19 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E0F36113D for ; Wed, 26 May 2021 18:08:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622052497; bh=zAZnDSIbfABqd5FjYbFPVJIQeD9gn+rnSYeWj3D63Fs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iJKyoSOkCxXQU50KofSW9/CMJblQX683qy2zM6Rp4EfCRRtwgNeCetNqC4uybwg73 8YiJuLZcmJfO2cZ0ipG53cBqktigKFuFEDsGMgEA5aKDMLw5XgObvvWnQSHwYRnsvM TyiJ9U0uNvBHe1ucH25tQKDfAqt0kTg8a6OoMdBKtHtxEBrIxfLTwZ1H0+MKEeohC4 Dt8B93CDlIpccwxKA824KEVDPBOoQEyzbtQTvaLKDOJ3aNg/AlxtQVOh0D5f9FHMoR q3AJlY7u1TyL6oU5LGs8ru4OtGTy9eEjlcyrcbE9z5UsoHy0DKEpbTN53s/hzTBi3U SiwBxtsVLKLXA== Received: by mail-ot1-f46.google.com with SMTP id h24-20020a9d64180000b029036edcf8f9a6so1866291otl.3 for ; Wed, 26 May 2021 11:08:17 -0700 (PDT) X-Gm-Message-State: AOAM530IvbOidZKWs0nx+dr+g/bWyFAmQSA/6Wbz0IBzL+RMG9aGfclE RTfwJrw94fO7XVby41YciY5DjGAHC7ITkY/8NJQ= X-Google-Smtp-Source: ABdhPJydlSrS8LwujCrDRJIT5PtVl1P/VeL34UmOw7LukyNZdvJsNkGeKrafTNuzFWuM4Rik/o7Gn+OiawIi+8tJOug= X-Received: by 2002:a05:6830:4da:: with SMTP id s26mr3357643otd.77.1622052496611; Wed, 26 May 2021 11:08:16 -0700 (PDT) MIME-Version: 1.0 References: <20210526100729.12939-1-ardb@kernel.org> <20210526100729.12939-6-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Wed, 26 May 2021 20:08:05 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 5/6] crypto: arm64/aes-ccm - reduce NEON begin/end calls for common case To: Eric Biggers Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, will@kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210526_110818_071992_ACFDD299 X-CRM114-Status: GOOD ( 26.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 26 May 2021 at 19:14, Eric Biggers wrote: > > On Wed, May 26, 2021 at 12:07:28PM +0200, Ard Biesheuvel wrote: > > AES-CCM (as used in WPA2 CCMP, for instance) typically involves > > authenticate-only data, and operates on a single network packet, and so > > the common case is for the authenticate, en/decrypt and finalize SIMD > > helpers to all be called exactly once in sequence. Since > > kernel_neon_end() now involves manipulation of the preemption state as > > well as the softirq mask state, let's reduce the number of times we are > > forced to call it to only once if we are handling this common case. > > > > Signed-off-by: Ard Biesheuvel > > --- > > arch/arm64/crypto/aes-ce-ccm-core.S | 1 + > > arch/arm64/crypto/aes-ce-ccm-glue.c | 74 +++++++++++--------- > > 2 files changed, 43 insertions(+), 32 deletions(-) > > > > diff --git a/arch/arm64/crypto/aes-ce-ccm-core.S b/arch/arm64/crypto/aes-ce-ccm-core.S > > index 99a028e298ed..8adff299fcd3 100644 > > --- a/arch/arm64/crypto/aes-ce-ccm-core.S > > +++ b/arch/arm64/crypto/aes-ce-ccm-core.S > > @@ -124,6 +124,7 @@ SYM_FUNC_START(ce_aes_ccm_final) > > SYM_FUNC_END(ce_aes_ccm_final) > > > > .macro aes_ccm_do_crypt,enc > > + cbz x2, 5f > > ldr x8, [x6, #8] /* load lower ctr */ > > ld1 {v0.16b}, [x5] /* load mac */ > > CPU_LE( rev x8, x8 ) /* keep swabbed ctr in reg */ > > diff --git a/arch/arm64/crypto/aes-ce-ccm-glue.c b/arch/arm64/crypto/aes-ce-ccm-glue.c > > index 54bd2494a000..98159f2c49ae 100644 > > --- a/arch/arm64/crypto/aes-ce-ccm-glue.c > > +++ b/arch/arm64/crypto/aes-ce-ccm-glue.c > > @@ -97,10 +97,8 @@ static int ccm_init_mac(struct aead_request *req, u8 maciv[], u32 msglen) > > static void ccm_update_mac(struct crypto_aes_ctx *key, u8 mac[], u8 const in[], > > u32 abytes, u32 *macp) > > { > > - kernel_neon_begin(); > > ce_aes_ccm_auth_data(mac, in, abytes, macp, key->key_enc, > > num_rounds(key)); > > - kernel_neon_end(); > > } > [...] > > + if (req->assoclen) > > + ccm_calculate_auth_mac(req, mac); > > + > > This still makes all the associated data be processed under a single > kernel_neon_begin() / kernel_neon_end() pair, even if there is a large amount of > it. Shouldn't it be limited to a reasonable amount at a time, like 4K? > This sort of thing has been considered a bug before, e.g. see > commit 706024a52c6 ("crypto: arch/lib - limit simd usage to 4k chunks"). > > You could do the entire CCM operation under a single pair as long as there isn't > more than 4K of associated data. > Good point. I'll add a separate patch for that. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel