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 29266C433F5 for ; Fri, 15 Apr 2022 12:47:25 +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=fbPC+Hk5bBy72gRNbYFxKYOriR2H7qUgnBxyu5fAH5g=; b=Sjc47OjPNfDrac 4yVMO411YW7O5ZgsK90AJGXzpERB9jwqn6EFn8yK+MvZQgV3W0gwaCZ+NQ0422jit8UW3GEvj0oWD kTVW2sPiJ4NbBr1Ux5ABFS45onQTp18fJ0/dtWQvOJc3KHnuwXjX9DcOqMWL7v+FktTSmAMFIx18h LXoeCFc0/VdO2AEG1HtQU8segfx0NcLGNW0ZlVH6LS7NCoB1wE5tKrO7fUaR/T72AY1aNM1QJuFtJ EYUMnUx81hyVnRdwsVIuERs8wKahDk+RfP2WZpdSjnVEdcix/jaQnYntOL5vaC5dwBtwlUS/S+62w jBuGQ7jGlj8+WlNZTumA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfLKu-00A6uo-6Y; Fri, 15 Apr 2022 12:46:05 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfL6x-00A0Y5-6J for linux-arm-kernel@lists.infradead.org; Fri, 15 Apr 2022 12:31:42 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 65E3861D27; Fri, 15 Apr 2022 12:31:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78417C385A6; Fri, 15 Apr 2022 12:31:35 +0000 (UTC) Date: Fri, 15 Apr 2022 13:31:32 +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" Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: 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-20220415_053139_329282_D971206B X-CRM114-Status: GOOD ( 24.81 ) 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 15, 2022 at 10:51:40AM +0100, Catalin Marinas wrote: > On Fri, Apr 15, 2022 at 03:51:54PM +0800, Herbert Xu wrote: > > On Fri, Apr 15, 2022 at 09:49:12AM +0200, Ard Biesheuvel wrote: > > > I'm not sure I understand what would go wrong if that assumption no > > > longer holds. > > > > It's very simple, we don't do anything to the pointer returned > > by kmalloc before returning it as a tfm or other object with > > an alignment of CRYPTO_MINALIGN. IOW if kmalloc starts returning > > pointers that are not aligned to CRYPTO_MINALIGN then we'd be > > lying to the compiler. > > I agree that it would be lying to the compiler, but I don't think this > matters for arm64 where the CPU can do unaligned accesses just fine. We > don't even end up with unaligned accesses here. Let's say we have: > > struct x { > ... > } __attribute__ ((__aligned__ (128))); > > and the kmalloc(sizeof(struct x)) returns a 64-byte aligned pointer. This needs a clarification. For the above structure, kmalloc() will return a 128-byte aligned pointer since sizeof(x) is a multiple of 128. The potential problem is if you have something like: kmalloc(sizeof(struct x) + 64); The above could end up as a kmalloc(192) which is available with an ARCH_KMALLOC_MINALIGN of 64. If that's a real use-case, I can change the slab patch to not create the 192 (or 48 if we go for an even smaller ARCH_KMALLOC_MINALIGN) caches and we'd always have ARCH_DMA_MINALIGN guarantee if the structure itself is correctly aligned. No lying to the compiler. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel