Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp55737pxh; Thu, 7 Apr 2022 13:49:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNchmZIabdxmLuR8W6oJt6u4dTCjqz8NOMhDqbNJqLeEePBzdcQmJtRQwx3jeSp6BAMJk1 X-Received: by 2002:aa7:8385:0:b0:4f6:ef47:e943 with SMTP id u5-20020aa78385000000b004f6ef47e943mr16267955pfm.38.1649364597554; Thu, 07 Apr 2022 13:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649364597; cv=none; d=google.com; s=arc-20160816; b=lhDnGfPqS+G4RRZABzZh11HX938A73CB5xUX76qYExPprblcpOKKvDhtmCT6x9Szkz fpGZLmBsPuH2dehRbq4plntkfG48iQ2NULwPC/bhufu993h7ADOVs4uf6tTrq8I8f3Tc PX1rMb8iV0x1W+bjY33uE/SdBTGWRnnp4dbihrM9ihvvgZhFXEMxuQXcJpH1KolF9Rkg FjIRLYIQS4FK974ipOZP3Rh/A6vbLHLo1NVtJRGew/mYsEA6bKBvDidgAN7r5tiM6C3y uPxcD7EBePszOTeqLZNnDiBXhgGXE3dEkLSrl+3U8YAQWGP/6QNptd8E556chQ/p1q/7 xdqg== 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=35FaJr4u0ywpuxDLRkYnTXm1iq7rKtv5YPiSniiO+ek=; b=bulcYeiUga4VwJwvoNX8W1L1iDB1JDOYsY+3C8f4sJrGUv7mIYkNMtvYsjQOMHkWBA +k5puCRJ1+2a8BqPmmChC0MPmPaCUcw/2PXmMrDc40R0YKU16OAn63yEm/Eya1fijt3/ qEUSyaA8fnAJ4LHCspdNq3jC/F9c9Buck+QH53VtpVt6VaQI2BRrnkmLOmsgjgH4tROV 3/Q9/3Z5jg7qMEA787oXCL2uyoT7st2rmMSN01ATqrPUo8xbTUyxqV2I8qkR90mGPzM0 vI9U/8lOk3RYpVTK1dcqyj7ZrTjwmEtuqidyEkBhfCjjHbYJAr6b0sJH4XmsBGNsFfG4 mgPw== 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 o3-20020a635d43000000b003816043f14dsi6727351pgm.834.2022.04.07.13.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:49: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 35DC03DE707; Thu, 7 Apr 2022 12:55:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231954AbiDGLDO (ORCPT + 99 others); Thu, 7 Apr 2022 07:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbiDGLDK (ORCPT ); Thu, 7 Apr 2022 07:03:10 -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 702FB10FDC9 for ; Thu, 7 Apr 2022 04:01:11 -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 B3688B826B8 for ; Thu, 7 Apr 2022 11:01:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5464BC385A4; Thu, 7 Apr 2022 11:01:06 +0000 (UTC) Date: Thu, 7 Apr 2022 12:01:02 +0100 From: Catalin Marinas To: Herbert Xu Cc: Ard Biesheuvel , 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 Thu, Apr 07, 2022 at 02:30:54PM +1000, Herbert Xu wrote: > On Wed, Apr 06, 2022 at 09:49:42AM +0100, Catalin Marinas wrote: > > is any change to the crypto code. > > But the crypto API assumes that memory returned by kmalloc is > automatically aligned to CRYPTO_MINALIGN, would this still be > the case if you change it to ARCH_DMA_MINALIGN? No but I think that's a valid point. Taking the crypto_tfm structure as an example with ARCH_DMA_MINALIGN of 128: #define CRYPTO_MINALIGN 128 #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) struct crypto_tfm { u32 crt_flags; int node; void (*exit)(struct crypto_tfm *tfm); struct crypto_alg *__crt_alg; void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; }; The alignof(struct crypto_tfm) is 128. However, a kmalloc() would only guarantee the smaller ARCH_KMALLOC_MINALIGN which, after this series, would be 64 for arm64. From the DMA perspective there's no issue with the smaller kmalloc() alignment since, if a crypto_tfm pointer is DMA-aligned for the hardware it is running on, so would __ctr_ctx[] at an offset multiple of the dynamic DMA alignment. If we used ARCH_KMALLOC_MINALIGN instead and the hardware alignment requirement was larger, than we would have a potential problem with non-coherent DMA. The only issue is whether the compiler gets confused by a pointer to a structure with a smaller alignment than alignof(struct ...). I don't see a performance or correctness issue on arm64 here. It would be a problem if instead of 16 we went down to 8 or 4 due to unaligned accesses but from 128 to 64 (or even 16), I don't think it matters. -- Catalin