Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp44157pxh; Thu, 7 Apr 2022 13:28:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymnzkip579WrgJT8dFOmeXeWFlkafOmmOhwaEGbbjV35ZePXFu3uGn6CjerV4WTBjsFREt X-Received: by 2002:a63:b555:0:b0:398:4ca1:4be0 with SMTP id u21-20020a63b555000000b003984ca14be0mr12594019pgo.294.1649363292050; Thu, 07 Apr 2022 13:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363292; cv=none; d=google.com; s=arc-20160816; b=SfMaFWFe8yZA0ijuy0SWCEup4sYsWttQv86ejMIZJEIiHe7uTe2wtK7LeJQCHCGwhp HQj/VwzHUXwdjRiQvTITw+osk4BF0kKNVnf0UsPGQ8qSoPHhEP2ILd7oVIIXjLu3TsRI 0AqIRvelLvYBgkKuqbUZtexaq9XkEJmIJJa21d21GAwgo+Dq2AUZQo38k64CnlYh7WAR cKXGK+D/Q2rUojbzBwVLeHmKnSDePKws9KNbAcII+GnCawrc6hG80JvqxGrel7wgG1Uh mvPbAI6cLxkT6Zx+r/1qmH0knijirH41yo/zCT8kpTCZaq7TrdBrZoZcPSG3HIF3EnPK yGzA== 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; bh=q7cVQvBP1515B7kcUPBoZWscePhC2Gj35qd6Sp9gxg4=; b=gsg8tjMi3qrlFD92l9xzjm6Gm7Xxrf91vfaXP6Riw6/QSxOIunR821Q6wiXKliN3Nu gVoo3i/WqVW6fT4v8JfH/NsQhIzY5pOXiL7UlWwxRadsJBC7e1uRXAzgaqPqhuiFlZjA 0mDyXiafsVHiBiaZ+vHeaIncTd9rh/BJwMh0QN7vSwgc4kzr+NESpCglc5IjNEAgSF4y opyXt3+1r0V2VT8Yyv3wRBFjXjkVU7q2nS4m81jzreWPoSb4xpvHzDWs/N/9dA/WLIrD 5wZteB9xaIXC23zSUmDkkunWWJ8BOD97+aIm3YtuEz63HGsr4a6lVHqY76tpI5uEz6rb Kdzw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bv6-20020a056a00414600b005056f4bee63si764920pfb.377.2022.04.07.13.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:28:12 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B54B92545BC; Thu, 7 Apr 2022 12:43:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234328AbiDGLIX (ORCPT + 99 others); Thu, 7 Apr 2022 07:08:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbiDGLIT (ORCPT ); Thu, 7 Apr 2022 07:08:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 544BA7C7A6 for ; Thu, 7 Apr 2022 04:06:18 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 55947B82729 for ; Thu, 7 Apr 2022 11:06:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8100C385A0; Thu, 7 Apr 2022 11:06:13 +0000 (UTC) Date: Thu, 7 Apr 2022 12:06:10 +0100 From: Catalin Marinas To: Muchun Song Cc: Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , LAK , LKML , Herbert Xu , "David S. Miller" Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: <20220405135758.774016-1-catalin.marinas@arm.com> <20220405135758.774016-8-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 Thu, Apr 07, 2022 at 06:00:10PM +0800, Muchun Song wrote: > On Thu, Apr 7, 2022 at 5:25 PM Catalin Marinas wrote: > > On Thu, Apr 07, 2022 at 02:14:15PM +0800, Muchun Song wrote: > > > On Tue, Apr 05, 2022 at 02:57:55PM +0100, Catalin Marinas wrote: > > > > ARCH_DMA_MINALIGN represents the minimum (static) alignment for safe DMA > > > > operations while ARCH_KMALLOC_MINALIGN is the minimum kmalloc() objects > > > > alignment. > > > > > > > > Signed-off-by: Catalin Marinas > > > > Cc: Herbert Xu > > > > Cc: "David S. Miller" > > > > --- > > > > include/linux/crypto.h | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/include/linux/crypto.h b/include/linux/crypto.h > > > > index 2324ab6f1846..654b9c355575 100644 > > > > --- a/include/linux/crypto.h > > > > +++ b/include/linux/crypto.h > > > > @@ -167,7 +167,7 @@ > > > > * maintenance for non-coherent DMA (cache invalidation in particular) does not > > > > * affect data that may be accessed by the CPU concurrently. > > > > */ > > > > -#define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN > > > > +#define CRYPTO_MINALIGN ARCH_DMA_MINALIGN > > > > > > I don't think this should be changed since ARCH_KMALLOC_MINALIGN is > > > already aligned with the size what you need. > > > > With this series, ARCH_KMALLOC_MINALIGN is no longer safe for > > non-coherent DMA on all arm64 SoCs, that's what ARCH_DMA_MINALIGN will > > cover. > > > > Now, looking at the comment for CRYPTO_MINALIGN, one aspect it covers is > > the minimum alignment required by C for the crypto_tfm structure access. > > So a smaller ARCH_KMALLOC_MINALIGN would do. But the other part of the > > comment mentions in-structure alignment for non-coherent DMA. Here we'd > > need the upper bound alignment, ARCH_DMA_MINALIGN. > > > > I'll follow up on Herbert's email as I think he has a good point on > > structure vs kmalloc() alignment. > > Got it. Now I know what you want to do. You want to set > ARCH_KMALLOC_MINALIGN to 64, however, the smallest > size of kmem_cache depends on the cache line size at > runtime. But we have to know the safe alignment at building > time. So we have to make those align with ARCH_DMA_MINALIGN. > Right? Right. > I think you are on the right road since most CPUs have a 64-byte cache > line. Yeah, apart from about three SoCs with 128, the rest use 64-byte cache lines. Longer term we should try reduce such alignment below the cache line size *if* the SoC fully DMA-coherent (like x86). In that case cache maintenance for DMA doesn't exist, so there's no risk to smaller allocations. Of course, one can use a kmem_cache_create() with SLAB_HWCACHE_ALIGN and get the cacheline alignment for performance reasons. -- Catalin