From mboxrd@z Thu Jan 1 00:00:00 1970 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 7CAA3C433F5 for ; Tue, 5 Apr 2022 23:59:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03DAC6B0072; Tue, 5 Apr 2022 19:59:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2EB36B0073; Tue, 5 Apr 2022 19:59:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF66D6B0074; Tue, 5 Apr 2022 19:59:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id D20806B0072 for ; Tue, 5 Apr 2022 19:59:40 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9F9B523E75 for ; Tue, 5 Apr 2022 23:59:30 +0000 (UTC) X-FDA: 79324494900.20.3D7E59F Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf07.hostedemail.com (Postfix) with ESMTP id 4839D40017 for ; Tue, 5 Apr 2022 23:59:29 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id q19so742610pgm.6 for ; Tue, 05 Apr 2022 16:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+pKWlLT8OBUODk8YNvFLSMhBfA/iojejnVtSVsASRAk=; b=YXBL1QT1SI7i+Bh2c/Dc8P9v+q9zH8NYCPf0bo/FnxGd06vvrjm+O0FsoJBk0fLEbN TaQbFXB8NNZ5nHIWMYME2kE1OjLFWBJxGzKfqq81r6V+XTnnibuYyxUjQDDC1SvWvxZh ZmGZTT02QcLWDCHdVr7gAerq/tjYtPmAx7wIvPAAVsLt56zt8AXu8yuNmg1JanvGP+x9 vpdZfL07mSEahEQOb/pPxEelhv2k4QH8DOCgTRmA8ssHD5rbeiGZ7EDjvLzqiSTf81Z9 c1S5njgI/BUvyLBAbpVZNDPhZH69GLSVdZ+WHHdLvA57R4MqqDkvpKVvRvDnzLutqjII 7cqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+pKWlLT8OBUODk8YNvFLSMhBfA/iojejnVtSVsASRAk=; b=uLmZQ2339SNqFFoNDaWBY6QZ/NqYXrUrkrNxgecRoZUh0OtY6xU6h+sPQECMssP90L Go0CEcb48z5H5kKXFVx2RhJeZHoGrMIb+iK7ynRZg+XWEY5g6dZCYuTyWKFZBehvVVQP dGN7cQucvzYn/+SWMKMiNfLHn3n0SaBDmtRiuMyY0JFskL53UF4SfXbam4KYK9dOf3E/ qBXlOS243r/XWDeLrfuSG9O66KdsAv5AcnDuzpsZJDftrcLvDAU4ICeLbfove31tYz2+ KnpiwF6ebPvqJTg2IFs9ifyuk6kZyKWGWWnj2HdnQ/H/zCvAmO+TYO5tbS45J1zzrr+p 2Qww== X-Gm-Message-State: AOAM53327WWwa0s1u9TdfWXVpwvv9Kqh+ws7CD86S04/wHiJo/p3fmyR Gw0kT+5+OSO9AaozyrP6GBI= X-Google-Smtp-Source: ABdhPJwr8lCDx3qo0NcIt/6xVkEHW9WW1AsHFqpf8jte3twaF6gnt2JTp/x1cETmV5k6VXwhRd9jwQ== X-Received: by 2002:a05:6a00:130e:b0:4cc:3c7d:4dec with SMTP id j14-20020a056a00130e00b004cc3c7d4decmr6050466pfu.32.1649203168112; Tue, 05 Apr 2022 16:59:28 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id s135-20020a63778d000000b0038259e54389sm13949197pgc.19.2022.04.05.16.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:59:27 -0700 (PDT) Date: Wed, 6 Apr 2022 08:59:18 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Catalin Marinas Cc: Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, cl@linux.com, vbabka@suse.cz, iamjoonsoo.kim@lge.com, rientjes@google.com, penberg@kernel.org, roman.gushchin@linux.dev Subject: Re: [PATCH 01/10] mm/slab: Decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN Message-ID: References: <20220405135758.774016-1-catalin.marinas@arm.com> <20220405135758.774016-2-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220405135758.774016-2-catalin.marinas@arm.com> X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YXBL1QT1; spf=pass (imf07.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4839D40017 X-Stat-Signature: gux5uctjb547i14k15xzdp41yhcb41up X-HE-Tag: 1649203169-691870 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: On Tue, Apr 05, 2022 at 02:57:49PM +0100, Catalin Marinas wrote: > In preparation for supporting a dynamic kmalloc() minimum alignment, > allow architectures to define ARCH_KMALLOC_MINALIGN independently of > ARCH_DMA_MINALIGN. In addition, always define ARCH_DMA_MINALIGN even if > an architecture does not override it. > [ +Cc slab maintainer/reviewers ] I get why you want to set minimum alignment of kmalloc() dynamically. That's because cache line size can be different and we cannot statically know that, right? But I don't get why you are trying to decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN. kmalloc'ed buffer is always supposed to be DMA-safe. I'm afraid this series may break some archs/drivers. in Documentation/dma-api-howto.rst: > 2) ARCH_DMA_MINALIGN > > Architectures must ensure that kmalloc'ed buffer is > DMA-safe. Drivers and subsystems depend on it. If an architecture > isn't fully DMA-coherent (i.e. hardware doesn't ensure that data in > the CPU cache is identical to data in main memory), > ARCH_DMA_MINALIGN must be set so that the memory allocator > makes sure that kmalloc'ed buffer doesn't share a cache line with > the others. See arch/arm/include/asm/cache.h as an example. > > Note that ARCH_DMA_MINALIGN is about DMA memory alignment > constraints. You don't need to worry about the architecture data > alignment constraints (e.g. the alignment constraints about 64-bit > objects). If I'm missing something, please let me know :) Thanks, Hyeonggon > 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. > ARCH_KMALLOC_MINALIGN, if different, is the minimum alignment guaranteed > by kmalloc(). > > Signed-off-by: Catalin Marinas > Cc: Andrew Morton > --- > include/linux/slab.h | 23 ++++++++++++++++++----- > 1 file changed, 18 insertions(+), 5 deletions(-) > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index 373b3ef99f4e..d58211bdeceb 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -187,17 +187,30 @@ bool kmem_valid_obj(void *object); > void kmem_dump_obj(void *object); > #endif > > +/* > + * slob does not support independent control of ARCH_KMALLOC_MINALIGN and > + * ARCH_DMA_MINALIGN. > + */ > +#ifdef CONFIG_SLOB > +#undef ARCH_KMALLOC_MINALIGN > +#endif > + > /* > * Some archs want to perform DMA into kmalloc caches and need a guaranteed > * alignment larger than the alignment of a 64-bit integer. > - * Setting ARCH_KMALLOC_MINALIGN in arch headers allows that. > + * Setting ARCH_DMA_MINALIGN in arch headers allows that. > */ > -#if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8 > +#ifndef ARCH_DMA_MINALIGN > +#define ARCH_DMA_MINALIGN __alignof__(unsigned long long) > +#elif 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 > + > +#ifndef ARCH_KMALLOC_MINALIGN > #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) > +#else > +#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN > +#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE) > #endif > > /* >