Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1048456pxb; Wed, 6 Apr 2022 07:30:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVT14QwDr3d9QJfN0NhMtUhW54X+cUcVD/VJgsi7MbOE8Wc899m/j+E1t41E8UuCdc7LH8 X-Received: by 2002:a05:6808:209e:b0:2da:4de9:e632 with SMTP id s30-20020a056808209e00b002da4de9e632mr3746290oiw.214.1649255457905; Wed, 06 Apr 2022 07:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649255457; cv=none; d=google.com; s=arc-20160816; b=JQ1c5yb+F6FGRm4qG2syunB9O8u25ndhRZYS3R79XP0IawAJkpD6cxZFD9ox12H+mS MPioq3my+o+QOg/ilezkR4b35U7m6ZgOgrLwf0Vr5uGDYlk5c6tFo+MSyksePdAEvR12 5oOvLvGtu4+XwHlGV6R3ic03Uvjv4K7/iQoARTTKVvqRwjzlSty9NTouLy8daA5O6CBZ /44Y0S7/223LE+G54R8LNEcrc3vg+0kKVG0ZEXNqfv/f0bOuznKGbb0QPlL+cdMfFQgc TbnOl8LtBTwJuLHin8zyo6OkuIrD1L5CT1KPw0g8sA9Xh/MUidUVT5gsH16NwDhwymZJ W1Fg== 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=Lv+LIcmjqryuQ4u2Pk10PKB5oZxlB0YxnMboObU4/pI=; b=IkdiX4Ca/GEeE5z1xdV5bB0cmg8LfdpEwuoovAIVhFM/9YZ3NogFhIeJUdTGitS1bg TOwjLyMeE9rP8/RwxzBXe/dROJoZXE54uTseNQJdflxIpbz4dZGptJGguGjmzdhXqDf/ rCN7HYjrq46aKn3cOqvXqxzNrxi4OumlZsqDSIwyHR+7qWxJfys0uSv9OMgdM2QpDRFo jzZ/W3Agmm33H1ZGafbmKQcgFdJHQgVGvXIGFH6w/dYT0XbyxrgwppYudzlHwNu/UtrN Y33Laf388Q2Je5gDkIfO4gTht9JKjBQQW8qa0tAaZUhDqJUNoZKpInSIo1udjbGWDsFc GReg== 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 s3-20020a05683004c300b005e68de339afsi4526406otd.2.2022.04.06.07.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 07:30:57 -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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B5FB73184A3; Wed, 6 Apr 2022 05:11:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbiDFLun (ORCPT + 99 others); Wed, 6 Apr 2022 07:50:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbiDFLuW (ORCPT ); Wed, 6 Apr 2022 07:50:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEABC5AB658 for ; Wed, 6 Apr 2022 01:49:50 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 48EF261380 for ; Wed, 6 Apr 2022 08:49:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88C3EC385A3; Wed, 6 Apr 2022 08:49:46 +0000 (UTC) Date: Wed, 6 Apr 2022 09:49:42 +0100 From: Catalin Marinas To: Ard Biesheuvel Cc: Herbert Xu , 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, "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 Wed, Apr 06, 2022 at 08:53:33AM +0200, Ard Biesheuvel wrote: > On Wed, 6 Apr 2022 at 00:57, Herbert Xu 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 think this should remain as ARCH_KMALLOC_MINALIGN with the > > comment above modified. The reason is that we assume memory > > returned by kmalloc is already aligned to this value. > > > > Ard, you added the comment regarding the DMA requirement, so > > does anything actually rely on this? If they do, they now need > > to do their own alignment. > > This patch looks incorrect to me, as ARCH_DMA_MINALIGN is not > #define'd on all architectures. It is after the first patch: https://lore.kernel.org/all/20220405135758.774016-2-catalin.marinas@arm.com/ The series makes both ARCH_*_MINALIGN available irrespective of what an arch defines. If one needs guaranteed static alignment for DMA, use the DMA macro. If the minimum kmalloc() alignment is needed (e.g. to store some flags in the lower pointer bits), use the KMALLOC macro. I grep'ed through drivers/ and I've seen both cases (e.g. drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c for the latter use-case). > But I am fine with the intent: ARCH_DMA_MINALIGN will be >= > ARCH_KMALLOC_MINALIGN, and so the compile time layout of structs will > take the worst cast minimum DMA alignment into account, whereas their > placement in memory when they allocated dynamically may be aligned to > ARCH_KMALLOC_MINALIGN only. Since the latter will be based on the > actual cache geometry, this should be fine. That's the idea. > Apart from the 'shash desc on stack' issue solved by the patch that > also introduced the above comment(660d2062190d), I've never looked > into the actual memory footprint of the crypto related data structures > resulting from this alignment, but it seems to me that /if/ this is > significant, we should be able to punt this to the drivers that > actually need this, rather than impose it for the whole system. (This > would involve over-allocating the context struct, and aligning up the > pointer in the various xxx_ctx() getters iff needed by the driver in > question) Since ARCH_KMALLOC_MINALIGN on arm64 prior to this series is 128, there is any change to the crypto code. -- Catalin