From patchwork Wed May 24 17:18:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13254340 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 456A6C77B73 for ; Wed, 24 May 2023 17:19:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5783900004; Wed, 24 May 2023 13:19:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A07A5900002; Wed, 24 May 2023 13:19:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CF65900004; Wed, 24 May 2023 13:19:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7AA36900002 for ; Wed, 24 May 2023 13:19:19 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 58030408DD for ; Wed, 24 May 2023 17:19:19 +0000 (UTC) X-FDA: 80825809638.05.BA04D1D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 73889140023 for ; Wed, 24 May 2023 17:19:17 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf26.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684948757; 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=2aa/9rtMYPXWU8npyxUTIzOc/VhPsnEGaH/Vu3K643eyL5ruNjc/nM3RYWjZjclYKYpnAY mpPfQV3N9KTv2xQW3e3XWtkH6e/Vy5yhEVMhWSwj4JV5jhNcgcVbZq4FzRpFAgIXsYKY3k uuGawUKfIzIIgd1qhFV6eMp+i6sD5TI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf26.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684948757; a=rsa-sha256; cv=none; b=cAfrsqMiTQP2nMJLHI2ToPX7olXXJqFUljFUkzyhJ4X6hyhyJjnAdDWf9j7sMG0XdlnxBl RmP4nPm0RN918WFdywr9CFDHmCXT9zDA5j2tuLNHthJ1LYtdUxLJiB7d+F+bjClgQ9yHjX x4iXOk3qisp3L9VxxSvTWTtwwt7bNR8= 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 BBED363E21; Wed, 24 May 2023 17:19:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8063AC4339C; Wed, 24 May 2023 17:19:10 +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" , linux-mm@kvack.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 01/15] mm/slab: Decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN Date: Wed, 24 May 2023 18:18:50 +0100 Message-Id: <20230524171904.3967031-2-catalin.marinas@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524171904.3967031-1-catalin.marinas@arm.com> References: <20230524171904.3967031-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: jb311octpxnxsfea5at8rapcztza51pt X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 73889140023 X-HE-Tag: 1684948757-755798 X-HE-Meta: U2FsdGVkX1+fBX0Yg1bP3hYbzsXtkD9kDND7lYXPtXnDvGM4cgXz9n6yFOeiPPbcUpCZ6L4ndc9+AJ0Xw7QiWqHYQwjIEbf+VbDP3Afkt29XXz6HpJCjgpgY56MUqgd/cD7i9q/jLkoKDHNxzQPt87JCg1oJE44/pP7de9DFn/5r7tmAagwkwh4VkfGJbQkB3RQulesIMsZpRrEA8VhmfFHWbNPNig55njmFqc0gMOlFXc94p8ZnbjKtsuyWsiEkAH32qOoMZK9G4obGxIpu40yt7z6RKDpM0C7xW2tckeKf7mWHPon5p8qDlQVhSukomcz6w7OcmmMf9TplaXxkD9nDiXHanL20yLHoHPUBvdYnJ2h/5hggFIAdV+4wzaWzDhcR+LhHB3kP3C9I2V1fLnRonTutgMOZG0L7LEk9WmFQvvX/SZB6tyCV5IozV/HKflkDGO3GpKfR/BP361as5303pqYAckZL+c3bQ2dzpFOTcCBdSD3lC3ON16Q9AAIZR2hTwRxiANmVVSQzQ7L+xL5asTw9TNMK2zdPism1wuyR5IGWxyh9QzOgwJqsrscb3dxzOZXfvVEvBLLLqSlaHxfWhajYkcBKNv6KHS6an+wJEuJhnx/xYIHrddnUtLMjWYcBS543LBNiVy5VtESkVJHBEbDvMrdRpHyez/iW6/kaln403ABjizdxMk4HOlHULL9eMPOttuVgFVtbmgcgBKxe2ptcSAev9dpnHEb7LbPQNlxRzbyNnz0A6IWEODZOMS7coUY7M3Afs8DiXZ6Xf60qaLjhLlKMTRrlMRv+/h2BHzbKtG/Bb1f24uHvpmdhYEEfCWte2nvOgCB6KWheG/3nIk4FtafilHZ1FNc1MLx1ONRz1gdmBUHKgU74FvG4CW+l25lvPLFiBFhyE73WHpd4bbCUsczSfJuor0oDNS5KXH02OIBR2olRhnTtoFeA2rL6iu5zBz8+Q3NFkcI mHQUoeqz IS/3Y9wsabsSRPx0ZBgwmZsQxnDosYUok5nYS0FXlon3fCfHkTVk8pOwky5ycu6IHkNZJjqAQ3K87EgTxX1HM1wEt6y4ckTYBOTGAtfsT5ylexubcGJwR6OzUFt+ZpAT2AM0T5ZX0LdnqD3fo4QMaOucVulbD6d64AcVnIgvjMn26QlB82rdIuk1Dn2TnQp9ykb4kE5EaA3vWQRWetYQB1s/oCFPMTMSfHgOB8Rrs0N61yfXvgEUQZknLJD12+oUL179hakyW7oAM6axICdEJ9TgEv3z7J2W/7TFzZ9hb5EnJoLjbspaWcLIigeymeHparIdwbO+EywJTFWLFZ4pXijz7nSfV8r+a69SvUtIN/9xT+3KS6ccj8MEeKHkRKL9pJJAYi0WPuaq/4WKBJsMIFqLy3VNWSzVyXD3T7vVzd/5ZOtc6Dw9XJESHR6thBFvhHv/r33c1ieXn5tXkdZlQfj1WMHWOCRzj9d/7WlzRPFG4CMXZD+7Ot33gBS2q68WYPxcpBroKjCmMiWjJ6IRnXAPg/mdVCNOPgCyTDaAUOfcGJ7RTqIAWVGyQ4DRMWeHEcQ23 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 /*