From patchwork Thu May 18 17:33:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13247149 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 B753CC7EE23 for ; Thu, 18 May 2023 17:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BA29900007; Thu, 18 May 2023 13:34:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54462900003; Thu, 18 May 2023 13:34:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E4B8900007; Thu, 18 May 2023 13:34:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2D9D7900003 for ; Thu, 18 May 2023 13:34:18 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E60E8A092E for ; Thu, 18 May 2023 17:34:17 +0000 (UTC) X-FDA: 80804074554.05.A13D7C3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 8337920005 for ; Thu, 18 May 2023 17:34:14 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf13.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=1684431254; 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=54tOsqc005inVEd0dWDBdtkpjhyjeg1kQ6gzKb3D0+8=; b=24+pFR2Mt4xN6yb0c4J/zvmIImcxfpyjEYXQbpu4ZvgKY2sePKk6gIs9RSu9uhUYKqI2bh EkvWFuyYNndxporh87sAFToUak9/+bczdkVlA+mZ3l4Uo2EvKPwUIsYB7YvEPjhgdEKcqK fTlprfAtWpf3kzyJTRXvyzezCjxXD2w= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf13.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=1684431254; a=rsa-sha256; cv=none; b=jYuj3BJf4NPqw5kqc/E9J1687GZQlHKZxdf+BYQ/yVFvvAVXZ43oASBomfHS/mCbxcPCx9 6sZxrwqu59RrXyG5wyWzkbkWFe9QnCXalsBBgeW4qXKEFPmrR2Stor9v0+YrJAgJ/mBfe2 VBSnasP6A/aIyNvK/U9siSGzMp9h+oY= 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 9FDD865151; Thu, 18 May 2023 17:34:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65FCDC433A7; Thu, 18 May 2023 17:34:09 +0000 (UTC) From: Catalin Marinas To: Linus Torvalds , Arnd Bergmann , Christoph Hellwig , Greg Kroah-Hartman Cc: 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" , Robin Murphy , linux-mm@kvack.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 01/15] mm/slab: Decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN Date: Thu, 18 May 2023 18:33:49 +0100 Message-Id: <20230518173403.1150549-2-catalin.marinas@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230518173403.1150549-1-catalin.marinas@arm.com> References: <20230518173403.1150549-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8337920005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ozsn8txioikm34i4j6m8qr5nxyfkqag5 X-HE-Tag: 1684431254-605421 X-HE-Meta: U2FsdGVkX1/uw+h+k5xHhCYZQzH78Ow+FWgfi7tJWsy0GgEgzR2uEEuIy4FhgBzXcTxDV+7AJTRe8gU5iwKii9lHjjLOV1ME8oDsLf/QoYxuAIC6RNOjQw+Kf2oF3S7CkbeL99TY7ezIjHD04J/mzUfluKhGBVGw8WyIC4Iht9pCd5Z1vVFoUF6RcGo/6gosx5L3pwrL9uHKRRIhpNIK1PmrZtxrWlWz2uEs0l1zZZsoCkUSYRrxfN/vxxxCeaLNpafT3jpFiZpYIIdOooOy2SijfaKuZ+0TCMVs98Bk7Vf8uihjyUzb1COsyF0V7+Y5xIAts/cog6aHR6KU+EXZUrTms06kI9DpVpfzctYazGDQtW/iUC/HFOwCbhYw5lZekb905o0aGgQJT3YMwh6tz2921zbx4erx1o1wxL7CumHxI6auEau1HxGdERPJto3FPzpiZYynyRA6WlvcWN7i39jsT+f8WlKEP/R9Unvhsx7BacqaiYe8IX+eIdkXCm4G4HmIVSsu2dEJhkuuC1Qv21u4AkzslJHwKlJ7pBIhCVwpP6NbzkQUKKmCSdEiVkTdXn4BdI2T8yNGsZCjUM1UjUyImFE6k1A/YWie7A2J8/HGN0C75APJydtAB8xho9XkFrIPq0YxhJtC5rSp7kLzM/W6Gytfl7yQXwHuHsXgglSZvWIk4qrqHVMYVG0bjeFqNPrgK1QpYmOqTYLgCXJMZN5cqdL0TYIW+83KN/WaO4toyVZy3w/n0FRxY+TBEWaZMq4j8N+1Lp2p56ZHMUeVnjnePN7NyLeZ0yyL1ChxSOHl/SG55QvXUKPOmQ4ClrAOpEa9oe76HrIpR7jb0AKHcDu3PXcshQl72wU0c8uJ2iajZFjQUHF/VHlhn60n12/wkmJ14nswT99GlW5z8YE5Ckh+bhGPw6IEpkTWaGISXpeXIlaq7hnfXM/IZLHJ++y9SLCNOrIT3Y1OJpp4Mxh joG+QeBs DRi09trs8Nakc5hq6GLc7VVKsgHPoHUNkXp4O60AtYRcyDz+R/DacbeXlMd+W0DfbO+PdfPakG0z3U1yEf02sl1lTKnBc3xDm4s9J3KBnwezcgNmwigrswIV40LerAnB8BrojQSYZW0fGzQh7tFHqEmO+gpjF5Z9fgHsdzrsnVm7NTVG55vGjbz3Lktf0bqtdBBuHvWfa2wOB1rdHRBC5nzDgZ2Hb5DvtZVkuj1TMGVLgwQ25SR7pE5SK1twnRrPAc0o12k5oWGVzOY1ZRB6zaS0Xz8/yI1VOcew807H24NdvtPKoQ2jnFvdDIO9PVHI1n3z8IOWYwRISKbxRxlUDpMWUXtPoNAFQavsMPFD6IdbSZoELios7tvMWCQ6HG1RA7Q/Y0IvZ+donGqe2raxr2Yht/63WJpX4UTEmj8oBP65YZxjUA5WLAqnRqWCfMCP4BE6Bax2Fcj8QZIvY3Wfzdns+fpO1CLfIqJKBKb+bQ/Q9xS0dLaOiJp1xUFfitcc25VA+WKKMQEM3poqpd3fMISQrCR4f9/d9jtw3XsXc/zTXxQN7AKmcPF+JgTY3hA9BqDZU 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 | 16 +++++++++++++--- 2 files changed, 14 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..3f76e7c53ada 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -235,14 +235,24 @@ 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) #endif +#if ARCH_KMALLOC_MINALIGN > 8 +#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN +#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE) +#endif + /* * Setting ARCH_SLAB_MINALIGN in arch headers allows a different alignment. * Intended for arches that get misalignment faults even for 64 bit integer