Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6193469iob; Tue, 10 May 2022 12:29:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1kBbKQQwUuH2s6lIYtlTilfah7GOBhobLmPzsd6c+edaQR7d3VfCjCAjpFv0fxIDEBLkv X-Received: by 2002:a17:903:2481:b0:15f:249c:2006 with SMTP id p1-20020a170903248100b0015f249c2006mr4722038plw.31.1652210966858; Tue, 10 May 2022 12:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652210966; cv=none; d=google.com; s=arc-20160816; b=B8rFF1xiH9g3p/LkteY5no0Zgu3ld9/ISXpcqLGj0zJVgEcCLiu7FKol5Kgy/XnFCr DLH9IB4pzzg+zmrhYeI9q/ZfXZs/VeW7RMbk4tHhIEx1WWp+0YlA1Hy6hT4Zeu8lWLhi JN2Svmt/L63xETtGYMryJH5WQThJ+qVoGZV5FQddFpmLoZMPH2V5WwbUQHjmCqyyCtUO jKVZEPM1/MyRepHo5Z4Ltz6YY0wno+mtNQih14ld5lImVaKdzBFA/V2IkuLFoVTvC3Oi 2Is5XMLpjgssNyWKmvCO9A6aE6CIEjTBktihLzqQREhd86nW8SMlyOUxMMCnGiJ9Uc3G SvyA== 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=Zn2SrBaxxrYa8nmRXx/ZGl/h/e2eqI9hBBit0tJ5JM4=; b=vcex9bYI7hktKI8C02NMPvDlHvXAnT/8lywwMCdngbqRevfxc22+vLJJToOoeuI34N k9b3xJymzWQXwOwm0worrRaVdnPVYKTGFs3N4qfvcZNBfF2XNKCGp/hPYcH9YEgGxKri Qev9R83ttyqIpMJgU26lv8MeEdYBUqjeaj26lTz3Jl+42fc2BQKDdXhmNPHLy1tLmZUH IS05c1ia57BLNJbTOYqA0JLthWOez1wEWqD8D0Tm6IzX3oGXLRO3ki+FsR+CMCyYxCNk W5KnJjDOjkoCFq4Z/g2bqLbSumN20/iNHsSyXKXaFEw/i3g+d5xgD2J2tXShLFPGCwDv DpTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y31-20020a63495f000000b003ab0293ef20si171339pgk.834.2022.05.10.12.29.00; Tue, 10 May 2022 12:29:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347790AbiEJROm (ORCPT + 99 others); Tue, 10 May 2022 13:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347787AbiEJROl (ORCPT ); Tue, 10 May 2022 13:14:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D378BC12; Tue, 10 May 2022 10:10:42 -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 948B9B81D2E; Tue, 10 May 2022 17:10:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6860C385A6; Tue, 10 May 2022 17:10:37 +0000 (UTC) Date: Tue, 10 May 2022 18:10:34 +0100 From: Catalin Marinas To: Herbert Xu Cc: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Subject: Re: [RFC PATCH 2/7] crypto: api - Add crypto_tfm_ctx_dma Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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-crypto@vger.kernel.org Hi Herbert, Thanks for putting this together. On Tue, May 10, 2022 at 07:07:10PM +0800, Herbert Xu wrote: > diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h > index f50c5d1725da5..cdf12e51c53a0 100644 > --- a/include/crypto/algapi.h > +++ b/include/crypto/algapi.h > @@ -189,10 +189,34 @@ static inline void crypto_xor_cpy(u8 *dst, const u8 *src1, const u8 *src2, > } > } > > +static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) > +{ > + return tfm->__crt_ctx; > +} > + > +static inline void *crypto_tfm_ctx_align(struct crypto_tfm *tfm, > + unsigned int align) > +{ > + if (align <= crypto_tfm_ctx_alignment()) > + align = 1; > + > + return PTR_ALIGN(crypto_tfm_ctx(tfm), align); > +} > + > static inline void *crypto_tfm_ctx_aligned(struct crypto_tfm *tfm) > { > - return PTR_ALIGN(crypto_tfm_ctx(tfm), > - crypto_tfm_alg_alignmask(tfm) + 1); > + return crypto_tfm_ctx_align(tfm, crypto_tfm_alg_alignmask(tfm) + 1); > +} > + > +static inline void *crypto_tfm_ctx_dma(struct crypto_tfm *tfm) > +{ > + unsigned int align = 1; > + > +#ifdef ARCH_DMA_MINALIGN > + align = ARCH_DMA_MINALIGN; > +#endif > + > + return crypto_tfm_ctx_align(tfm, align); > } Is there a case where a driver needs the minimum alignment between ARCH_DMA_MINALIGN and crypto_tfm_alg_alignmask()+1? Maybe for platforms where ARCH_DMA_MINALIGN is 8 (fully coherent) but the device's bus master alignment requirements are higher. My plan is to have ARCH_DMA_MINALIGN always defined but potentially higher than ARCH_KMALLOC_MINALIGN on specific architectures. I think crypto_tfm_ctx_dma() should use ARCH_KMALLOC_MINALIGN (and no #ifdefs) until I get my patches sorted and I'll replace it with ARCH_DMA_MINALIGN once it's defined globally (still no #ifdefs). Currently in mainline it's ARCH_KMALLOC_MINALIGN that gives the static DMA alignment. With the explicit crypto_tfm_ctx_dma(), can CRYPTO_MINALIGN_ATTR be dropped entirely? This may be beneficial in reducing the structure size when no DMA is required. -- Catalin