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 7CE34C433EF for ; Fri, 15 Apr 2022 12:20:26 +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=HXXgtUfwUWbHiSnYdSgk/F731Mr9NG7l7isVMkyOK2w=; b=raMCM1jPGaKBaH 7BrMb5n5N2JiHPUxGqj+esFizmUji06JtWF2f2LaY9oYhRpcdS8ZIe/dtOi0yE2DgsyQGUfTzoiNh tWrtxJ5D1t+Sl/iJhoD7nGaWuBUB/C6DBEoSAfheqfD1zOF96723+rfEMic5ONJEiQC0sqa1wJeXW bTHiBfWC2W5eL9/AiUIhn2CvLPhSS7GnoQixauMXBEb4GmSwsfDBP33uVyOAfubqdARTmZKLZPjJU BHjODwfgCIEoGqU/VgpSbnKmHv7oymeXkj7i3NE70KhUtpVl6T5Vck9rocqmqb+WuEdxJVq/rR5ao Aq6UBhSqKTkYpSlVbO/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfKum-009vId-8z; Fri, 15 Apr 2022 12:19:04 +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 1nfKui-009vI3-OX for linux-arm-kernel@lists.infradead.org; Fri, 15 Apr 2022 12:19:02 +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 0E02E6168F; Fri, 15 Apr 2022 12:19:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15709C385A6; Fri, 15 Apr 2022 12:18:56 +0000 (UTC) Date: Fri, 15 Apr 2022 13:18:53 +0100 From: Catalin Marinas To: Ard Biesheuvel Cc: Herbert Xu , 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_051900_870579_28049B6E X-CRM114-Status: GOOD ( 24.55 ) 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:05:21AM +0200, Ard Biesheuvel wrote: > On Fri, 15 Apr 2022 at 09:52, 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 guess that should be fixable. GIven that this is about padding > rather than alignment, we could do something like > > struct crypto_request { > union { > struct { > ... fields ... > }; > u8 __padding[ARCH_DMA_MINALIGN]; > }; > void __ctx[] __align(CRYPTO_MINALIGN); > }; > > And then hopefully, we can get rid of the padding once we fix drivers > doing non-cache coherent inbound DMA into those structures. But if we keep CRYPTO_MINALIGN as 128, don't we get the padding automatically? struct crypto_request { ... void *__ctx[] CRYPTO_MINALIGN_ATTR; }; __alignof__(struct crypto_request) == 128; sizeof(struct crypto_request) == N * 128 The same alignment and size is true for a structure like: struct crypto_alg { ... } CRYPTO_MINALIGN_ATTR; Any kmalloc() of sizeof(the above structures) will return a pointer aligned to 128, irrespective of what ARCH_KMALLOC_MINALIGN is. The problem is if you have a structure without any alignment attribute (just ABI default), making its sizeof() smaller than ARCH_DMA_MINALIGN. In this case kmalloc() could return a pointer aligned to something smaller. Is this the case in the crypto code today? I can see it uses the right alignment annotations already, no need for kmalloc() hacks. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel