From patchwork Mon Jun 12 15:31:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13276857 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 9ECBDC88CB2 for ; Mon, 12 Jun 2023 15:32:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F0C48E0005; Mon, 12 Jun 2023 11:32:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A1E18E0002; Mon, 12 Jun 2023 11:32:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAA3E8E0005; Mon, 12 Jun 2023 11:32:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DCEB68E0002 for ; Mon, 12 Jun 2023 11:32:20 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E75331402B3 for ; Mon, 12 Jun 2023 15:32:16 +0000 (UTC) X-FDA: 80894487072.09.AAE315B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 05942160023 for ; Mon, 12 Jun 2023 15:32:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.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=1686583934; 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=UUvO9n2es88yTASKvPq57Bk5K7ngON6nudF22+6AUl4=; b=tzVhxAiM8R1IOmlLVgsc/cNAe0pVg1+UUgxER8vk1AWNbeW2cGXYKOGDzyU3/2h6s/29Oq dHhGf76V8ji9vyRLvDXweH9CwUu5el296cCPTC7fxYa1UUBLINI4HCRsgXQpzGXXXKwqZl yy0OlxQXv9x1W63cqCugjYrye7FKz1U= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686583934; a=rsa-sha256; cv=none; b=OIQfvEg1MEYxZVYSY3kHt5qSOFrh7Fm9riCH7BijDDVrxt8r//weR3bs6rXN9GfIjmHBP7 ihcv1T5yuDoNMc7y4dJ/0OrozLhxDmh6+V6Hbk0uoJEyeNi5wob5q8CDC5kStc+4vNgROx GFfrQ7SUHLmwALO1S2x7eHExNs2OUjE= 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 01CC7617E7; Mon, 12 Jun 2023 15:32:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 589BBC433A0; Mon, 12 Jun 2023 15:32:08 +0000 (UTC) From: Catalin Marinas To: Andrew Morton , Linus Torvalds Cc: Christoph Hellwig , Robin Murphy , Arnd Bergmann , Greg Kroah-Hartman , Will Deacon , Marc Zyngier , Herbert Xu , Ard Biesheuvel , Isaac Manjarres , Saravana Kannan , Alasdair Kergon , Daniel Vetter , Joerg Roedel , Mark Brown , Mike Snitzer , "Rafael J. Wysocki" , Jonathan Cameron , Vlastimil Babka , linux-mm@kvack.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 01/17] mm/slab: Decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN Date: Mon, 12 Jun 2023 16:31:45 +0100 Message-Id: <20230612153201.554742-2-catalin.marinas@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230612153201.554742-1-catalin.marinas@arm.com> References: <20230612153201.554742-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 05942160023 X-Rspam-User: X-Stat-Signature: dtonk9k1b9hxqyu4qyx7dc6qa5j1pyz8 X-Rspamd-Server: rspam01 X-HE-Tag: 1686583933-578805 X-HE-Meta: U2FsdGVkX19GX30t6xvUTUerte+7/qIi/GmFegx4GoBytRBXn8CKamxH3ZRi8kFqaJ/xDYWI8Li219DFiGEaqmO93Bd8tiZltcd0+VUmpcDFGkQ9XtDnv99Trfvf2CunTfFKWnzVtVpvigrLXXISttgbcdhXT/rQsmHsqR26+NhKtv0CTyX4doh0U8DkP1oReMNI+EkkhadIgW0bVOHt5rHYOP7/DiXTdcRLpLm2xB51wO2xM54ZARL8mOUMVshtZfMNe4r6iMA73Bo+T2vTydHwxcVjNYIXk+SgYd68eNnFzYjwY4nDnD7z3Gte6ac7XO6ETU+ikvs8olQuxpZ0Ya4rfIT9OqJ6Nv1R/zivM3XOQYyJ+xDFPF0Kg/adNFoBZJ9YW8yWfYrdqsZ53WpcCFE8J6UV/RvwVO6vi1OSZptBFwgHpbm5JYtlmvEM8QwXNux7GLTmlOUCpepfhLkqneMHV4M6t6v3NVxxOj4mD5w2Gj7C7fAgNOjJ7zDMr/N21LET4d2mv1HzmuTI0GUrxmiO/KL1mz1fkU2oCCh11PjDuG8G7cTyhzFYH3SO+zt5LPTB+ogxArlMXjWs/Uz/0cIZLLNs1qFn9556ydFeEMbN1plYXbhm9tcWiyq9Yc4HBmQkMGJ/qpYTg3iHOPDbLRcyB+50HJoKmEzcNQciaRt3bj9rCSTr/oATDYOMUSFDIMVWozEinSL02LJLs3Zl/uy50AYTP2ZOTEroMpEpZQLYtymWP/rdskXqauMLlAQ39QolOje0XrROapXeOJDA3QzihnCDG2ICgX/kc4AqG+XOLJCjfssMI5C/HGCmhQ4wraZBjC1GeHNJjMfOJaGeKQIiP4/xvUuIQ0d34JpCfrjVdeT26YlZkr4gT+ZKPJ31F9DE7s6c+/kI+jBoichEdF3BkuWCKmeSeSBvNYgDrOhMROs9zU2bt60KzJ0mhOFxdwHTB0JQrNpW+StpzMv oNRklool YfnR9aRsxf3eeYR/0yRtuQi5AeeIlHh+x2CRq7RksGvVtuFr0GR7W8BOlLsLwfi55LNDKbBrZlyOt2ijtAlVnF+JdLg3nVNB4ZRLS3Gx+4A5Zi+0ToBQfaoSwbW1TsiOx0yAG/nsc1uuFCPJIT/AOWAWH/9mQSoiMigAFhG/C4fUjoxTJ4pWhGfcQYbr2XIdvd7JKFKy9ZI8JCIps+4TUX4Euyu2K4tOGMcycpIXojIOH18u187YM1htKAOwBpUS603l5yn94Pt4sR1AKh5Rhup62Ug0nqVcgiMfV+AcJmqJmO12Q/eE6C+0iHZC8Jf+0t5Ji08+KtoHyzyFAu2GReUFk+tabNta29VroI+kW4odhF7/T1+Ex7aQou50p6zcSaummdt1z2hJAHZVLUYbENKb57T3qwEKK9L7VSAyikSeQ5qsRpYtov92nrdTgm+E1c+7y96wzMGcdAKD6805foipAMnimEVTaT2uhgPfCuW2NbsjPbDLi+9N4Ngh79y82jQvXaET1Rjel+xHEjDcq7PEWDqsyw5TTjtTCaOnuCoG6ZIArZYVb4IgsWko3+0cVIIkjhzQYwFlWT24F1Gg+HiTt8Q== 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: Vlastimil Babka Cc: Christoph Hellwig Cc: Robin Murphy Tested-by: Isaac J. Manjarres Acked-by: Vlastimil Babka --- include/linux/cache.h | 6 ++++++ include/linux/dma-mapping.h | 3 ++- include/linux/slab.h | 14 ++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/linux/cache.h b/include/linux/cache.h index 5da1bbd96154..9900d20b76c2 100644 --- a/include/linux/cache.h +++ b/include/linux/cache.h @@ -98,4 +98,10 @@ struct cacheline_padding { #define CACHELINE_PADDING(name) #endif +#ifdef ARCH_DMA_MINALIGN +#define ARCH_HAS_DMA_MINALIGN +#else +#define ARCH_DMA_MINALIGN __alignof__(unsigned long long) +#endif + #endif /* __LINUX_CACHE_H */ diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 0ee20b764000..a50375331eac 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -2,6 +2,7 @@ #ifndef _LINUX_DMA_MAPPING_H #define _LINUX_DMA_MAPPING_H +#include #include #include #include @@ -545,7 +546,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..ca53425e9b32 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -12,6 +12,7 @@ #ifndef _LINUX_SLAB_H #define _LINUX_SLAB_H +#include #include #include #include @@ -235,12 +236,17 @@ 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_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) -#else +#endif +#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 /*