Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp294229pxw; Fri, 8 Apr 2022 07:47:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPV3o9xXf86YL0pFDFEyhn/ACAcouCAyuX9/S8o/dNRv17ETw0Pcu6dBpK8WIfnDNmaWbG X-Received: by 2002:a63:78ca:0:b0:398:ae5:6515 with SMTP id t193-20020a6378ca000000b003980ae56515mr15884286pgc.345.1649429264774; Fri, 08 Apr 2022 07:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649429264; cv=none; d=google.com; s=arc-20160816; b=gKHHl/4F5aZFnJTc2VwaNbVqJIsiOUeTj2fOSMpOWt6uB1Wlvcc9DsMlmJ/CnBlRCK 6falPCc8cyyeYHPGMTIjETNSb6POgsnujOPzcTbucTNdpAs+SKEv7Y4Gvu3vNB1RAHnK luTrcanl23QpoHS9s07f+u2xOIUfYEizibCNvkQbMDNA1L3AMAf2cOV9Dyimrk1LxX6C MYROuvIJqhJddwgKo3ycIj6oojZVFetGuoaQJljoLO0ate6XD3aJ3mbLD5152Cwwl6TN GbKrfhWViIfZk7VWyEgKWVB2oW6ewqD+DucNvoLZCxXU5xot9JgAKEsQ+UMoRZlsF0t4 TdKA== 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=aAn672kMORdxmoZUAweDlLLwVMSKn9ctI2ULbQiV1fc=; b=odev3yYNMu8/wk+VLas+O+CVCMBYP1KXLiuh6f61KgKfeuJyTalFbQM9bGaluWAN1I Jgd7MfxNUPJ1r84vZMPMA5n4EVPkIah961XNMMTcbILi0A0VAxxv0UVO3vEJLj7Npo1i 1I1ca6SNJVWhsBdNYBRkOG2AzMPXlRq8RxJ62uI76j9m9K4qzhGTUsMZAD7uznj2cc/L miVt9J6JyIwLjW7oPd+QJ/cjTv3YWu7LfPEeyXFm20KUr16jhZnUUIJL2J7YDbGeb2x+ +BEkrLvKGXYXIQxp9L/FtQWYq0+cjxSZHJjrcQdHnz7GBmeKBECW6G+AO23jWXYo0CYi iQmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020a170902728400b00155f7af1822si935496pll.484.2022.04.08.07.47.29; Fri, 08 Apr 2022 07:47:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S232078AbiDHJHI (ORCPT + 99 others); Fri, 8 Apr 2022 05:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbiDHJHF (ORCPT ); Fri, 8 Apr 2022 05:07:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C2FA80213 for ; Fri, 8 Apr 2022 02:05:01 -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 1136C61C4A for ; Fri, 8 Apr 2022 09:05:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AEE8C385A3; Fri, 8 Apr 2022 09:04:58 +0000 (UTC) Date: Fri, 8 Apr 2022 10:04:54 +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=-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-kernel@vger.kernel.org On Fri, Apr 08, 2022 at 11:25:29AM +0800, Herbert Xu wrote: > On Thu, Apr 07, 2022 at 05:28:10PM +0100, Catalin Marinas wrote: > > I can see in many cases that the kmalloc() caller aligns the requested > > size to something like crypto_tfm_ctx_alignment(). So this would > > guarantee a kmalloc() object aligned to CRYPTO_MINALIGN. > > crypto_tfm_ctx_alignment is basically the same as CRYPTO_MINALIGN. > We assume any kmalloced pointers to be aligned to that. > > Specific algorithms may ask for an alignment greater than that > and we will use the knowledge that kmalloc is aligned to > CRYPTO_MINALIGN to derive the extra memory we need to get. > > So if kmalloc no longer returns memory aligned to MINALIGN then > we'll get memory overruns. My point is that if the crypto code kmallocs a size aligned to crypto_tfm_ctx_alignment() (and CRYPTO_MINALIGN), the slab allocator will return memory aligned to CRYPTO_MINALIGN even if ARCH_KMALLOC_MINALIGN is smaller. Would the crypto code, say, do a kmalloc(64) and expect a 128 byte alignment (when CRYPTO_MINALIGN == 128)? Or does it align the size to CRYPTO_MINALIGN and do a kmalloc(128) directly? If it's the latter, I don't think there's a problem. -- Catalin