From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93005C433F5 for ; Fri, 8 Apr 2022 09:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iefQcQKJUCrvPGXngpGlXXhRyuhPV3nJYG95KngMVY0=; b=fmQeBnw8LqXGXL CxD7BBBkfyvS49XNKEP6/dJrvUbevenjanV3Ysj+xHO5CGTHd3l6YzKDHn8xXQFk00gU9nRZfvr+3 X+YLr9YR1s77THe9Uhh6UqlwMSsc+OI7DBIQOxRczmJArBmQS36Xd3OGkIW7wsLwiqDQPulVrY+so 97xC5VcZnge7Cpquq0oHKvTF/FsGZR+Ydz/tI0aIT0I7ieyZnA6ltfEfTsAIg4DZdeIo3HDk+lZWw G+WDnjRb0js6t12y9oDdIDQQXMEEsW7YOX/OddgDshLuOwueKLjYI1p6pP3x0TskGXQMX+8RqAoIb tZI0gI5gcVePIcv2ri6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nckYF-00G2gf-0Y; Fri, 08 Apr 2022 09:05:07 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nckYB-00G2f9-LZ for linux-arm-kernel@lists.infradead.org; Fri, 08 Apr 2022 09:05:05 +0000 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 C4DBBB829EA; 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_020503_882890_2BF49E14 X-CRM114-Status: GOOD ( 18.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24205C433F5 for ; Fri, 8 Apr 2022 09:05:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD4FA6B0071; Fri, 8 Apr 2022 05:05:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A850D6B0072; Fri, 8 Apr 2022 05:05:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94D3C6B0074; Fri, 8 Apr 2022 05:05:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 820A36B0071 for ; Fri, 8 Apr 2022 05:05:04 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4F60F251DA for ; Fri, 8 Apr 2022 09:05:04 +0000 (UTC) X-FDA: 79333127328.03.50F6B23 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf22.hostedemail.com (Postfix) with ESMTP id CC1C9C0005 for ; Fri, 8 Apr 2022 09:05:03 +0000 (UTC) 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 C4DBBB829EA; 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-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: gw3ob4eordzyke9wnytrkgedpyssht79 Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf22.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Rspamd-Queue-Id: CC1C9C0005 X-HE-Tag: 1649408703-994734 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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