From patchwork Wed May 24 17:19:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13254353 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 817F1C77B7C for ; Wed, 24 May 2023 17:20:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F204900011; Wed, 24 May 2023 13:20:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A2CC900002; Wed, 24 May 2023 13:20:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F39D7900011; Wed, 24 May 2023 13:20:10 -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 E4E97900002 for ; Wed, 24 May 2023 13:20:10 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B4A174097F for ; Wed, 24 May 2023 17:20:10 +0000 (UTC) X-FDA: 80825811780.21.01C48DD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 0DA4E160029 for ; Wed, 24 May 2023 17:20:08 +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=1684948809; 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=RYwKwBbFVhKuYYjB0bZAfV9ae8PLZlXqN8QaXAdpqek=; b=siBB1ZhhcNNPx6zEztb/+DjzWygrmq+71OefiiTuhmjQ8MJgL4KPEC4/8dACQ8Bbmp3pJA t7f7D00hKhRsfIlwGbWUoJH7K5BIsLQ39LxR50a6LOLoyT6KBsLTuRjCQOhaTMTyaYDF9d nDKgG1Xz5Khmnqmruw0j6slbb8ifaBc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684948809; a=rsa-sha256; cv=none; b=yUp8WOHgAyo33llRhXIEjIuYeWsU4d1EC+YYAUXHiG2SU4WAIJlcCmxSZwr90/mR/qinHj ncF9yTYfc0Nhn9pAMBTkl6lpwo7cLadc7HRc59fGBiawHMGJ4FWYGfZMqIZmfOn0dusaIV EG9ygvoKnvrmvAaAUBZ6s4lCmvpgQT8= 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) 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 23C8363F80; Wed, 24 May 2023 17:20:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC7BDC4339B; Wed, 24 May 2023 17:20:03 +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 14/15] mm: slab: Reduce the kmalloc() minimum alignment if DMA bouncing possible Date: Wed, 24 May 2023 18:19:03 +0100 Message-Id: <20230524171904.3967031-15-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-Rspamd-Queue-Id: 0DA4E160029 X-Rspam-User: X-Stat-Signature: shn6fqcco6buppw64i6w9mfagiqkt8ji X-Rspamd-Server: rspam03 X-HE-Tag: 1684948808-361777 X-HE-Meta: U2FsdGVkX1/7qNBbnPMBRzNKoPKKlTAxUJJIQWvI3cDR4OpwxD5KC1RiLwP93QqX+lzWYttJu7m6epicBRgZCICPVwp8VFybg2qGhZS/QBj0FR91Qy52qj6bYL91m/dnlp9VHl7lPl/CY/bsnu6hpNajjlrkLQWT1BulsEzxxUvvzGvlTtzYwrw3l6h9Rurc0dC4APLwSvfYacjr3Kp6bNToIEPHMDM5SxniFZ1Rf6/8pUttz8eLn7CO8ccy7/m1i4LrfZCVagHpS2urDDVosfmuQ2hOi/34Mc3DUUUIml0RF2w9SpM5LlcTqGMateGDC8/2lsHHlKwKBtYVHtvoVbiO4NvoMh12IwG0VfEMKsdYRzgOu0KJ2OhcKsNRzqxjT2fpAXrUnXiKLY+rnpwmlAaWR0ulZJTlA0aMkEkx2s25dK7zWy7IauC23/d8Ko+2Bj8WEP6faCqDYeaFM/CoyBCaOriTBNmgrZiauG6Zo4OVhXwmFGIuKI7edKBO5RjHMNtJuoYdgu4byJhNGWPib/n2QGxVl5PjaefDGmWL+RQtUP94JimLYlhsPcGAX1J2ojU5p+qYNCky9zQpFvAqP1+o0V20sypOGRVQd/uW5oNCVw5Tt/iQxAiu8jJCYUuv88vRZgOOHQgCHftq25KyeQIcRh3nUmIyt26YIwBoNO87dau4vPGUeBXBmPjyGia2nTifafqWtC8Yk0M+KsP/ffMVr/VVmn2dHIVAX/PRrW3HZ3vRQr4mStleD6BUI4vamUpXgFIAx/2nzLdl0vA7sMPMzc515VCBnIP1LSlfZQg9XwybUNCyO1YkrYmA4xt3j9g1s+/o9vMVqTe3ORNCQYJFqZVnsaZk4R01O51leg+bhafeGSNesAevkI8B3NhZuEvnE3MevrLITb+kMmPbT9zUEWMTieIT5DIMhBvn6lhvk3ifUWDd8cY3KDGsaeIzEelde6udBKx+vF9RDvB SkckaedE t6aly/02bR1dkzQz0aNmDdhnc4yk0AGdec7Q63f2C9hEe1/G5fyZjHaqUxkv5PtQVKTxhrROiSAiZtLun/cawBCmLNr8OQ9AebQaHho59WNoEiSWndUoyKkm8c0K/DtTayJZeru5xCSPZJrCVDGJXWcfOkpVkh03hT3x4lFER6/djB3WXmfig3hUBsEn1gLaMajNwh9j1blXG9Z9jhHH/a1b+/gCbMxlpz37mFd8G4+ggx0xZ/1z4L0ouVRSwJgMooUyJKXsiwOo1vNzF17xG44G5WT5W4Y7duh5juWFLwIiRLq79y6eRlbE4RSxVFhJV2pkuG+p8RnkiI91pcGyF7byMm0aEp/5KNT4tYwwjU/chLOUwk30ZvC5AcGH3ZsRqJOR+3oAqgG0DKpm4VZLx5fkGKlLm5in8bFA91lXftb2vRbbNyVxK+jU9Dq3TUazi07nqt5zYPt5MHeCiEuK7SKulaig1nfEKuugoSTXM0eh9MrJ6rCCL7IPRfbPaiOFdN6ZMVN5xVSj2EjjpK5eEq3VSBA== 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/slab_common.c b/mm/slab_common.c index 7c6475847fdf..fe46459a8b77 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -863,10 +864,19 @@ void __init setup_kmalloc_cache_index_table(void) } } +#ifdef CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC +static unsigned int __kmalloc_minalign(void) +{ + if (io_tlb_default_mem.nslabs) + return ARCH_KMALLOC_MINALIGN; + return dma_get_cache_alignment(); +} +#else static unsigned int __kmalloc_minalign(void) { return dma_get_cache_alignment(); } +#endif void __init new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags)