Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp159212pxb; Thu, 7 Apr 2022 01:54:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCEP07+JVkCuVldcEtXbNrrp8Ic677fu/UuK4OYajUCGHoxWPCYRGUVr/+fwrnvv4yYBQ5 X-Received: by 2002:a05:6402:510d:b0:41d:88a:c9af with SMTP id m13-20020a056402510d00b0041d088ac9afmr1772680edd.410.1649321684982; Thu, 07 Apr 2022 01:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649321684; cv=none; d=google.com; s=arc-20160816; b=tXzQaZi2COksBKEMpDY9AnlyYyCQ9GZO1hUpZhgjKBWFZ9rqXhiQBBaMs/jGGMFfWA Nfs2tuYuqNl7v71iEnpltBEo6ZP9aljHjd3ZuL0V8r/AWT0MU/qs6qIBW9LNRgsE9XPF qDod2qasuJ3qcrCl17BioUrEfBdtoQncxF7X7xbStHNewuXZwByztQG2Eurp8gJ3WDq9 pb7GVpzq90HXKHQISUdx3R4+HM0+mVh6lIBlMSAF4UK6GvnW0LgfH9A5BkQmpFcITuhs npYEILXMlTvqWyiitIY+oBP1J6n7Jqe1UfpNwDALLyegmh3Kf//QCq38zb3vHXYgdlXk GMpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qDcfNWrbl7zeU5dUIyt3CklKBWK9LaKMhGXmUeW4Biw=; b=Z3YzgGyk32blSs6qX3Rm/ukiQLOfHFzoZHoA1HPsZnI2TKyaThL1kemgFQ4pfkeqwv /ePf+NIMbGh1HfsKsIbkGGfomNc8QSvoL75U9uInqJsjJYUYw2dbA8fX6ilSe55Gmjg0 mArf+jASoSUbvIR/edWGr2LRoy1b3N7UhJh2RBK9oxLDJWIoI9+aNMlY7LWsArFg8ajp JsvHBrBzDF4XMT56rOLn5sJRWrXSt7JOWHjZjrn9sBtd2ZQrSr2OVnxeKw1Txk0ZHLNi HONWcNVraaU7pYDcom+RVwx8klet5+NM6Um8EgV3wyrHqlR9R1y04cjeEqZCc7swf81U Hmsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SZz4iQzz; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y6-20020a056402358600b00418c2b5bf33si15798109edc.533.2022.04.07.01.54.07; Thu, 07 Apr 2022 01:54:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SZz4iQzz; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S243127AbiDGIee (ORCPT + 99 others); Thu, 7 Apr 2022 04:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243063AbiDGIea (ORCPT ); Thu, 7 Apr 2022 04:34:30 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06BE622BD5B for ; Thu, 7 Apr 2022 01:32:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 5E5ABCE26C6 for ; Thu, 7 Apr 2022 08:32:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A38DAC385A4 for ; Thu, 7 Apr 2022 08:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649320347; bh=UMGmo7XIYPYxpcneSgCZbK8w6IKxq/N9sRRSMlxHrck=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SZz4iQzzBVlHaVudcP76VcTNSuZdoidizKkOjRM63vv/i838bQJotztQQSwqtf1aC 0mvAVaxESdCCEVV5oclw1YWpAoo2lmJZgAPMFGNLCk/q0QgYL1Dw9X+yQbPUtDuQSV 9T53DRBv0wDC2l+FcAzIPWYSzcAmmEek+5fIdAjN1QtymqfIH4K8/h7AHdt0wYrk/w JfDudGQnoWxjNqUdh809MXaUYC8APTCiB9QEiKYtNpOiZFjxFvPcJyGPLli1/y+jke ZZUvfJTt6HmasjMKnA4S9pzITtaL9onlF3v/DHPdJ8kViR08aCxSGBEHKdquufI+5I Xh4oZ3L83yLAQ== Received: by mail-oi1-f182.google.com with SMTP id w127so4911399oig.10 for ; Thu, 07 Apr 2022 01:32:27 -0700 (PDT) X-Gm-Message-State: AOAM533v/Y1jQUJPpcBLHzllbh9wSOnxFQAmIqykD4Zf+d56elbSVyM6 6fiFCjCw66dIHG4DMQuWRTiDkYYSFaQSWtG1z5Y= X-Received: by 2002:aca:674c:0:b0:2d9:c460:707c with SMTP id b12-20020aca674c000000b002d9c460707cmr5312562oiy.126.1649320346789; Thu, 07 Apr 2022 01:32:26 -0700 (PDT) MIME-Version: 1.0 References: <20220406142715.2270256-1-ardb@kernel.org> <20220406142715.2270256-3-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Thu, 7 Apr 2022 10:32:15 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/8] crypto: safexcel - take request size after setting TFM To: Herbert Xu Cc: linux-crypto@vger.kernel.org, keescook@chromium.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, 7 Apr 2022 at 06:32, Herbert Xu wrote: > > On Wed, Apr 06, 2022 at 04:27:09PM +0200, Ard Biesheuvel wrote: > > > > +#define EIP197_SKCIPHER_REQ_SIZE (ALIGN(sizeof(struct skcipher_request), \ > > + CRYPTO_MINALIGN) + \ > > The whole point of CRYPTO_MINALIGN is that it comes for free > via kmalloc. > Yes, but kmalloc allocates the entire block at once, and so all the concatenated structures need to use the same alignment, which results in substantial padding overhead. > If you need alignment over and above that of kmalloc, you need > to do it explicitly in the driver. > But none of the drivers currently do so, and rely on the API to produce ctx struct pointers that are suitably aligned for DMA. Note that the main issue is not the alignment, but the rounding up of the size due to that. For instance, looking at crypto/adiantum.c: struct adiantum_request_ctx { ... other fields ... /* Sub-requests, must be last */ union { struct shash_desc hash_desc; struct skcipher_request streamcipher_req; } u; }; So on arm64, every skcipher_request that gets allocated will be: 128 bytes for the outer skcipher_request + padding 128 bytes for the adiantum request context + padding 128 bytes for the inner skcipher_request + padding n bytes for the inner context Given that the skcipher_request only needs 72 bytes on 64-bit architectures, and Adiantum's reqctx size of ~50 bytes, this results in an overhead of ~200 bytes for every allocation, which is rather wasteful. I think permitting DMA directly into these buffers was a mistake, but it is the situation we are in today. I am only trying to reduce the memory overhead for cases where it is not needed.