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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CB89C433F5 for ; Thu, 7 Apr 2022 11:01:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE9676B0071; Thu, 7 Apr 2022 07:01:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B725A6B0073; Thu, 7 Apr 2022 07:01:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A12A96B0074; Thu, 7 Apr 2022 07:01:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 8AAA36B0071 for ; Thu, 7 Apr 2022 07:01:22 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 454BA184218ED for ; Thu, 7 Apr 2022 11:01:12 +0000 (UTC) X-FDA: 79329791184.27.0FB6FED Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf16.hostedemail.com (Postfix) with ESMTP id B2E6E18000E for ; Thu, 7 Apr 2022 11:01:11 +0000 (UTC) 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 ams.source.kernel.org (Postfix) with ESMTPS id A906AB81A13; Thu, 7 Apr 2022 11:01:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5464BC385A4; Thu, 7 Apr 2022 11:01:06 +0000 (UTC) Date: Thu, 7 Apr 2022 12:01:02 +0100 From: Catalin Marinas To: Herbert Xu Cc: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "David S. Miller" Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: <20220405135758.774016-1-catalin.marinas@arm.com> <20220405135758.774016-8-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B2E6E18000E X-Stat-Signature: wg9hqgkmzyaj3cpqe7q4gsjp6eouqpq4 X-HE-Tag: 1649329271-508909 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Apr 07, 2022 at 02:30:54PM +1000, Herbert Xu wrote: > On Wed, Apr 06, 2022 at 09:49:42AM +0100, Catalin Marinas wrote: > > is any change to the crypto code. > > But the crypto API assumes that memory returned by kmalloc is > automatically aligned to CRYPTO_MINALIGN, would this still be > the case if you change it to ARCH_DMA_MINALIGN? No but I think that's a valid point. Taking the crypto_tfm structure as an example with ARCH_DMA_MINALIGN of 128: #define CRYPTO_MINALIGN 128 #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) struct crypto_tfm { u32 crt_flags; int node; void (*exit)(struct crypto_tfm *tfm); struct crypto_alg *__crt_alg; void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; }; The alignof(struct crypto_tfm) is 128. However, a kmalloc() would only guarantee the smaller ARCH_KMALLOC_MINALIGN which, after this series, would be 64 for arm64. From the DMA perspective there's no issue with the smaller kmalloc() alignment since, if a crypto_tfm pointer is DMA-aligned for the hardware it is running on, so would __ctr_ctx[] at an offset multiple of the dynamic DMA alignment. If we used ARCH_KMALLOC_MINALIGN instead and the hardware alignment requirement was larger, than we would have a potential problem with non-coherent DMA. The only issue is whether the compiler gets confused by a pointer to a structure with a smaller alignment than alignof(struct ...). I don't see a performance or correctness issue on arm64 here. It would be a problem if instead of 16 we went down to 8 or 4 due to unaligned accesses but from 128 to 64 (or even 16), I don't think it matters. -- Catalin