Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp906357pxb; Wed, 6 Apr 2022 03:55:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEutOCiYonF1dFbTM1kHc47UK7/ya7FBRA3dg2qea/uGg74GIvtpHgyi6/l5/uK+/IfLDG X-Received: by 2002:a17:90b:4b02:b0:1c7:1bc3:690b with SMTP id lx2-20020a17090b4b0200b001c71bc3690bmr9344649pjb.174.1649242545163; Wed, 06 Apr 2022 03:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649242545; cv=none; d=google.com; s=arc-20160816; b=Kb0hZ6w7BPCiPNrffB+WNSLN3nLQKQGknmNMoZwyFg+ohfT6QFRljOZgVfrKEo3iUW xNjxdIjErfSI5n0T8saVuXhxdeZtOKifhn1pcck9s9QIabGyUdxWU8Zperw9HvYz78qW DOeNkBiF0bfnrSg81cMf64Ro9X7fb1EVpjHlTIHoNIuuVrsC92AWZWeTx9tJR1bhuQ4R /fUQXRE5XIlAa+Jc+dt3Ufc5x79aQ4FLCD05Yh4TPapH9SeBqMn5BPbk5aclOZr+jmyr KbdafzIacLpCnuvlWstiRBbf2eWNozWVSCMX/PSAgm0WpsZzdZHlZyGDINsS0UToGy6P hOhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+pKWlLT8OBUODk8YNvFLSMhBfA/iojejnVtSVsASRAk=; b=fUXnTOFTUTp4HY1kHhOY9BaV8GJBQAAcAw2wPWW16WpuCZGGIryj8wo43lP9NrZL03 R5D0gsk7L1wcUhjNCShAktf5MvX7kwYebJSNvwla+c0tPowtqngVryUtcHd8V8JSo1aL QNSqAT0zrq+0jrZ01IzznHNfaeWMsJDmpJ8+GLnRCrPtGSRkMVYFvxlSJHAaidfFF2lF lzbixJX0UiEp2RI6C9PjWOJaS2w8RbHGsRnZbkpXOFCMvHhpIR+9twuNkAea8JnhS6Ax HWu2U84sgwuNT0rB2CpYsqG/Bk/gMw6Sq2k44AwEAgQOVvneESL4/FQOWR8Q9Vjgms/q T8Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YXBL1QT1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j20-20020a62e914000000b004faa21eb5dasi13700605pfh.244.2022.04.06.03.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 03:55:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YXBL1QT1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C8F995A5FE2; Wed, 6 Apr 2022 02:14:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443348AbiDFDd5 (ORCPT + 99 others); Tue, 5 Apr 2022 23:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1446436AbiDFDEx (ORCPT ); Tue, 5 Apr 2022 23:04:53 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A584C403DF for ; Tue, 5 Apr 2022 16:59:28 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id s2so942110pfh.6 for ; Tue, 05 Apr 2022 16:59:28 -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=hDvmEXB9XTv4f1+o8ZIm+SpIQFSBvA5C8J3o83e+igOQ0KynfDVeEPFnSE64w8z5xj cAJ643i3yKUThehAI3n5yev9f5J//X4O480AZEnJlBichcI+bdtSGvdsXULzhoRjOUI4 1JwAygYJLs0JF7n4Q6gUnqpk84tVQIuG5xAyC30I9SmZgSMhAgevK7ZF/ro5ULqQMFJ3 fatgdiHz5luLfCMfgI+ptxPRctle2WbSyzOEHBGrFpNZbkxJ5PJTwAP6F7kUoLCbwC95 MMRAVX0ptn4iiFC5zhTpGPPVRZhqLWv0+YBY9nyFsjOjyOD6Q5Gnz/MbouelrwTGIc1Z QhuQ== X-Gm-Message-State: AOAM532xkeuF8rPmjm7UEZMZy4UZQamBrE/4JMSd9royTZlXVJzMatKP tCzD3WaSBgMGWVBOMRsVa8E= 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-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > /* >