From patchwork Thu May 18 17:34:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13247180 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 BE335C77B7D for ; Thu, 18 May 2023 17:35:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62EEF900016; Thu, 18 May 2023 13:35:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E019900003; Thu, 18 May 2023 13:35:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A877900016; Thu, 18 May 2023 13:35:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 344BC900003 for ; Thu, 18 May 2023 13:35:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 101661608BC for ; Thu, 18 May 2023 17:35:09 +0000 (UTC) X-FDA: 80804076738.08.D60F4E9 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 7954B40009 for ; Thu, 18 May 2023 17:35:07 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf27.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=1684431307; 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=bHWY9l8OJoLo8hdZQBx3YOP+S/Ayh/jMX0+APRJNrik=; b=TywxEVXikBNO5iawu5OWLjBi5/hLqcBW3bofjf60NyYZ74lvLj62aG32hJfOi//yQMvcgj HrxE5s0/bBz3P8JLzo5LSo2EzCpJ6otKpNpG+N4SM6YAIIRd/fPYMCkXcrN3bTM9J44rZP nBanGObkZhOrL00SzkGx4tHW+AXyg1Y= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf27.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=1684431307; a=rsa-sha256; cv=none; b=QKyeki9wHHVi1TOXq4DW0WX2uuKlHMdbnx+ZO3Lojb5FCyNM4gmQVrGGUV1HI2QtF8Kd3u wjtdoHc2yD5dS6/DISGaW+//LFRo9hKecd3A7MH63fNsXjPxYDJVGDnpadG/3ksDeEYDa8 JS+mrKNq5fWvrbLIMDN+r/+bm//MLHc= 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 A72FE65152; Thu, 18 May 2023 17:35:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61FC1C4339C; Thu, 18 May 2023 17:35:02 +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 14/15] mm: slab: Reduce the kmalloc() minimum alignment if DMA bouncing possible Date: Thu, 18 May 2023 18:34:02 +0100 Message-Id: <20230518173403.1150549-15-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-Server: rspam09 X-Rspamd-Queue-Id: 7954B40009 X-Stat-Signature: czstrifoh55yptks9oiwh3mga86dxwbk X-Rspam-User: X-HE-Tag: 1684431307-75098 X-HE-Meta: U2FsdGVkX18L1CfmWyM3OUkCFDvi5yJYVWi983CNNEFj9dgx5lXb55p4Q3tWTpMlLm+RCHQg3w/B/zHdcz3KdF4t5Bjm2tW1FlYVtCqXjMt5zayLImdnoOwlx8NNMPC1wpvXDNIFgX+bVZ5b5AsmLctyunOaXeCdbg4JPuu78TrycnLaVr/BCIxWH5g7fRWefk6KR9o5Wh9vot2HPEQZ6pVioZJ/dobD2SDhISCqNLIt/9mHb1d+krI9eg4uD5rKWaZNMvKFX6yIQglKPUIrLt7G6c52zlOG1FumKP9mPF+mxZiHImnA34HWYCrRo7zQr2xAdsoAFDOgWLMn+OXgFkNEpiqj9++Ag2XF8KJF18sNda8LbsDHDkrwpk9sAXQ6s+k/xN8BzXqL2Tm3JRhZBTATsVXY8GpLAEg7eigpLoasLWhJ8bJffvxo1tHtwhAq2C3qHZ7U2dGlq+4KDZnwzs7y1G8PYgBXj4ag9O5fqsLSDIFGzDRv600lVjVe9+YyPajzz+Js4N924oWSKs9xN4heaKTyXzQT/xaZK3ZWWX5/ykT8aMJAkrhLSe/ZntKzdqDRZPnp52cBygMvyVy0VFcErVypsS1s+rx/Rr6jHYEfQ/uSuURv/nym9EKz8RPvhoDZBStf7lf0VbVAtHh3hSWej9rbm73e/4RwkG8mO7YFa/m70hpxhIgV6SoHWyLrqK8Kg8lt6TYb0NKzTuy7tov2aSqIUh/fEIdq0Kp61bkvCFLlmD3zU4zBypMRZ60QSSVSkEE+yvF6+TlCiLpiUJqabwY9W7fXt+heM0lSxAf5ndDVYQ1JrtOBL8FTtszJ+cUoaOndYCIGt6N62KQJzWkTWzkuPGTkqVSoXvi+zi7eJvM8RCvrszzedJHN3WRHEHDer6F8xMUlAPVrEoU7UnOrqIzaCdPXhsey5DU/3JYygpZE4rK27blH7Hz/9G3H6XrWiJo9Shl8sr61O5J g1Io/JuA zWf/FI4NLAUkSRXEj2evUfJwOiCO1RdrofZLHUCByIQlwxcrATZJhTX8UBYWI+QPKNFQJ3YPokqSvvX0ev9tBAHDam6DUf2FwILKQVDHjMddf3v63WCIghuWnh9TBiyKo6c0lh606J4lvpuom13tFn6T6OPXGkBAw1o1HnIksXOb2dlxywVM1TKQ/CMWufaoFioBlkzfmR5Hnb7Vb6Vz+iJm4z44E9Yp2yp7SBVuWSPTZ2Oj5WROJKVtEDw+EJOY/LWDES2FGthiSoQ4YUshQlL3VoxxdvV4QswvEbWZpQoxb0MoJXB22Adh19NyUjuyU23XnNzpPnyR5lQ13nE/Q1OhHvqz90FvfInyzOEqJAoSS12/odhIRM3/O/vbxU4r3XjYtCANN9pkr8lNexZ/hQFQBTGVnWcDwPQtlVgnYDXSETkOFkDzrq6KNQ4R4tbV7IQaT/ifZpV5rsmIFJNV6P8w0MT9lOCA0vlvRrilFRL1QfRYlLbJjPvoNuNovOl0/+3YkPx0vDHCf8fbhgbLhbVtsCg== 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: If an architecture opted in to DMA bouncing of unaligned kmalloc() buffers (ARCH_WANT_KMALLOC_DMA_BOUNCE), reduce the minimum kmalloc() cache alignment below cache-line size to ARCH_KMALLOC_MINALIGN. Signed-off-by: Catalin Marinas Cc: Andrew Morton Cc: Christoph Hellwig Cc: Robin Murphy --- mm/slab_common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 7c6475847fdf..84e5a5e435d6 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -865,7 +866,13 @@ void __init setup_kmalloc_cache_index_table(void) static unsigned int __kmalloc_minalign(void) { - return dma_get_cache_alignment(); + int cache_align = dma_get_cache_alignment(); + + if (!IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) || + io_tlb_default_mem.nslabs == 0) + return cache_align; + + return ARCH_KMALLOC_MINALIGN; } void __init