From patchwork Wed May 31 15:48:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13262454 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 26FFBC77B7A for ; Wed, 31 May 2023 15:48:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B46958E0005; Wed, 31 May 2023 11:48:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF70E8E0001; Wed, 31 May 2023 11:48:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BE6B8E0005; Wed, 31 May 2023 11:48:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8E8418E0001 for ; Wed, 31 May 2023 11:48:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 49A8D16029D for ; Wed, 31 May 2023 15:48:49 +0000 (UTC) X-FDA: 80850983178.08.FFB9F5E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 81BE4C0020 for ; Wed, 31 May 2023 15:48:47 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685548127; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yoW/ReeYfZSTzC2TZN9dmK/8gq9+nyhtUUc+/CgA4gM=; b=TdMsCRk1kPhsMljrEX1njk7ooKOc362faqlsdLoFP/qjati7hvw7VyLR9M/NZTtohSOhC3 raqKZRkaWhkD1qrIN4PeqljqODk4Y9FFvNtH7jph81rEWwq+TTmuDE76rFMRPbI5aUeMv2 9NKD5bjpfbJcTiMPMJGcpf3OvMEZ5/Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685548127; a=rsa-sha256; cv=none; b=2e4yLokbZPnSeVI66gfaQgVMPYjEh468L8bBZYsWki0Ror5UO/jedmM3RKgM8T4L8LjO0m f2aDeVEEO/7RgxKJYGs4zJcIWc96tLULIKLJV+++f3wwh6y4/AMbuOydNZAoZvf4r7qlEr hD7ZWZlGFDdoVgbo8nO5fxKFBcposU0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) 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 B2C546380B; Wed, 31 May 2023 15:48:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69AD3C4339E; Wed, 31 May 2023 15:48:42 +0000 (UTC) From: Catalin Marinas To: Linus Torvalds , Christoph Hellwig , Robin Murphy Cc: Arnd Bergmann , Greg Kroah-Hartman , Will Deacon , Marc Zyngier , Andrew Morton , Herbert Xu , Ard Biesheuvel , Isaac Manjarres , Saravana Kannan , Alasdair Kergon , Daniel Vetter , Joerg Roedel , Mark Brown , Mike Snitzer , "Rafael J. Wysocki" , Jonathan Cameron , linux-mm@kvack.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 01/17] mm/slab: Decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN Date: Wed, 31 May 2023 16:48:20 +0100 Message-Id: <20230531154836.1366225-2-catalin.marinas@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531154836.1366225-1-catalin.marinas@arm.com> References: <20230531154836.1366225-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-Stat-Signature: zopfwupbqjowpuqqdcfb157o1k648z3g X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 81BE4C0020 X-Rspam-User: X-HE-Tag: 1685548127-769303 X-HE-Meta: U2FsdGVkX19TDTxAIy0ZgL8f6FmipVA/6s73Zf71xZGNC6ojKqdxiJxOe1YFXvW14kmWunGxEDAcMpjpNUCFjo3yz02UeHxFHSbZaaGN1VV+WrEHGyUebR8sY5tHjkt8GiGliK288TgTmFe3xMAyvs1v6AYz30pcO/fByaoWA+KVzkEn3eoyn9zFN5lj2h/DCPAS4zCVp2Y0nep5LPPBFk354z6+Nl6OcV5Yl8UoC0LqMdlaeFGcjVnH+UT8r9w81QnYQ8Y56RCKmP/LTpOuK75BSuUemXzf8uGLb5hBnMCtt21tgp5CJOaex/2qtLXbuZAk6XYJGlzj876qAUw9rmyf9GvgbnoANk4MWct4j7pEb4RhAewIrG8j+z+jI20lQBXj4YIOLQYHULdW2EfKC0mgHhWdbdT7ML8lcHykEi6iFcdLME1cRBqau3MjD1ijd8kawIG1bvsy5grnTGIavLoztWM/t+IvjwZ6h8Iq50k6rGsGGptZIvhKFtmk1aQd1fOf2TjaAwcWFRj0Uyr8as8b2BEmgpIkNWrY83CfcDgzK45gboXwY95c8bEB+IJzJO9fwYhERDa7z45/EwtxBttzIkLOJ4ZtQcNhnA41EpIe7FkJA/EKU6/jmWh5bIwH2WcIiu0BMmfUX+yWmuTObRuKPQsWYE4vfhtDlr/p4U4EUAN7BZ8jYj5gsxXbGvy9F3emKsptc6THDf7guampGR/fXrC5/Tr1RlKrNFHNXjleiBmnHDTJvmVbmpxllfwTeIS4T8ALGAvtc1ti2T6849CtnxMiNyL3ganyfOAsXlxD+RgU4hSh7Gw2yrPG1oBpNX+g+yrADDv7tB9oATPbZuMqUFaD0I0zRrZdQ8/065c7H2XdZrFchSzz+d8K/dUdZNvaZ1fl0dhU5R6Dl7oBvbxrbMqDjUJ9ktHeMfV4jobO8+ZRDm/EjaWsEcXNwHjgKSiuWeCVr8miZdyduXB 4TF1wJdy E27+zHfG5BMyc8rsJoNh64l4+jnkHl5jIEckhXcRRnVoxIr/7MkZSvKhFKUDwnnXBvP0Bc3YwgQBC31ucOmHWDwHhEcL7EViBl29z9vH1Tg9q4yW1I8derX6qQ13YnjVPo0fUL9vGxI3NjyaXnGqUEd/8m0s7g5LO6cHuA51VWhgk6LFr5o+DSA1hhtWxDGYQSe6Y9iyhleu0L66mkSzDGyYQfXbMDml9jjDEB0uHDwTRwNVV7pQq7yyZItYp4tFzraH8VkzY9jvLRs3nALWvZ336KbNgdaQx7LCcuMVaCDcEWnBwxsNYGFsbWftDyERKiHWbAn95D394MJm1E3gzD8lmWqNKS4wSU/raQhbMl5hynjaOfv2FN6mC6qwtuMMtZb3I7wZpAzGMDHgmT7Q0Rg/yFAn9p/iwB+7FjpmK54VpNgWJozPQBvAhEUOMlq2ORMryePcEr184/P/SrbX8wB4wnoOj5o0Oy/oaNLvxZ1SopXe9Ht5xIiTkiaXPBngYN2rivtA3Pdr1bp49GZjxME3UX1iFScW0VfvZ9wC1vR1pGix/Ucvdfc6Qxdi5B6aKlzXu 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: In preparation for supporting a kmalloc() minimum alignment smaller than the arch DMA alignment, decouple the two definitions. This requires that either the kmalloc() caches are aligned to a (run-time) cache-line size or the DMA API bounces unaligned kmalloc() allocations. Subsequent patches will implement both options. After this patch, ARCH_DMA_MINALIGN is expected to be used in static alignment annotations and defined by an architecture to be the maximum alignment for all supported configurations/SoCs in a single Image. Architectures opting in to a smaller ARCH_KMALLOC_MINALIGN will need to define its value in the arch headers. Since ARCH_DMA_MINALIGN is now always defined, adjust the #ifdef in dma_get_cache_alignment() so that there is no change for architectures not requiring a minimum DMA alignment. Signed-off-by: Catalin Marinas Cc: Andrew Morton Cc: Christoph Hellwig Cc: Robin Murphy --- include/linux/dma-mapping.h | 2 +- include/linux/slab.h | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 0ee20b764000..3288a1339271 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -545,7 +545,7 @@ static inline int dma_set_min_align_mask(struct device *dev, static inline int dma_get_cache_alignment(void) { -#ifdef ARCH_DMA_MINALIGN +#ifdef ARCH_HAS_DMA_MINALIGN return ARCH_DMA_MINALIGN; #endif return 1; diff --git a/include/linux/slab.h b/include/linux/slab.h index 6b3e155b70bf..50dcf9cfbf62 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -235,12 +235,20 @@ void kmem_dump_obj(void *object); * alignment larger than the alignment of a 64-bit integer. * Setting ARCH_DMA_MINALIGN in arch headers allows that. */ -#if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8 +#ifdef ARCH_DMA_MINALIGN +#define ARCH_HAS_DMA_MINALIGN +#if ARCH_DMA_MINALIGN > 8 && !defined(ARCH_KMALLOC_MINALIGN) #define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN -#define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN -#define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN) +#endif #else +#define ARCH_DMA_MINALIGN __alignof__(unsigned long long) +#endif + +#ifndef ARCH_KMALLOC_MINALIGN #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) +#elif ARCH_KMALLOC_MINALIGN > 8 +#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN +#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE) #endif /*