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 EA4BEC433EF for ; Sun, 17 Apr 2022 08:38:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A5E16B0072; Sun, 17 Apr 2022 04:38:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 255576B0073; Sun, 17 Apr 2022 04:38:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11F336B0074; Sun, 17 Apr 2022 04:38:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 035A86B0072 for ; Sun, 17 Apr 2022 04:38:48 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CB51420957 for ; Sun, 17 Apr 2022 08:38:47 +0000 (UTC) X-FDA: 79365720294.04.300DE25 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 43A4F120004 for ; Sun, 17 Apr 2022 08:38:47 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 8A1756115A; Sun, 17 Apr 2022 08:38:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8B32C385A4; Sun, 17 Apr 2022 08:38:43 +0000 (UTC) Date: Sun, 17 Apr 2022 09:38:40 +0100 From: Catalin Marinas To: Herbert Xu Cc: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf29.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 43A4F120004 X-Stat-Signature: t5xb8z1htndg7a8zfped6yipn73fsh4r X-HE-Tag: 1650184727-111078 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 Sun, Apr 17, 2022 at 04:11:22PM +0800, Herbert Xu wrote: > On Fri, Apr 15, 2022 at 01:31:32PM +0100, Catalin Marinas wrote: > > > > This needs a clarification. For the above structure, kmalloc() will > > return a 128-byte aligned pointer since sizeof(x) is a multiple of 128. > > The potential problem is if you have something like: > > > > kmalloc(sizeof(struct x) + 64); > > > > The above could end up as a kmalloc(192) which is available with an > > ARCH_KMALLOC_MINALIGN of 64. If that's a real use-case, I can change the > > slab patch to not create the 192 (or 48 if we go for an even smaller > > ARCH_KMALLOC_MINALIGN) caches and we'd always have ARCH_DMA_MINALIGN > > guarantee if the structure itself is correctly aligned. No lying to the > > compiler. > > Yes I suppose that should work: > > 1) Enlarge each crypto API object so that they're >= 128 bytes; I don't think we need to do anything here. A structure like: struct x { char y; char z[] CRYPTO_MINALIGN_ATTR; }; is already of size 128. Without CRYPTO_MINALIGN_ATTR, its size would be 1 but otherwise the whole structure inherits the alignment of its member and this translates into an aligned size. > 2) Modify kmalloc so that for sizes >= 128 bytes they're padded > to multiples of 128. This doesn't look like a hack, we want to honour the power of 2 alignments. -- Catalin