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 60F68C433FE for ; Fri, 15 Apr 2022 09:52:58 +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=0bj+7I8p6PEoIKjlDLOPKbKh3x5Xz8EZkfEbBlAGbQc=; b=wDPrznM1wPcFL+ JH8az1kMYyV03wQhrGN1sKxwFellCIa+MM5Yy51WjmnjMUXQjlI7ssXQuHmnPUwdmFnbCkF4rWpzj gudHBJBWlLsFAJWqh4uknla4eRecOvQ5CTbvJn1HDGcUPxzqfsaa4CfuNqVomCh5hCYiFQkM54FHV Z3mPfw1mcxYyuXSEVfL1kbmA8uHc+QmUwiodv7QIIP6P9rVS5CWQUkq01pxzbvzN59MDYuPw+Pg9g b9P5OXZjgaDSnkVmwI+Wyj+QskSbNknt1xSaA1vx2GKjj3VjMMN3qH4zx9bP9ghFFYxRCcEzBX2Tx 7IZ8odKrlb6mkIcjl/fQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfIcJ-009WXQ-QR; Fri, 15 Apr 2022 09:51:51 +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 1nfIcH-009WWn-0J for linux-arm-kernel@lists.infradead.org; Fri, 15 Apr 2022 09:51:50 +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 7A88DB82D97; Fri, 15 Apr 2022 09:51:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D5D7C385A6; Fri, 15 Apr 2022 09:51:43 +0000 (UTC) Date: Fri, 15 Apr 2022 10:51:40 +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_025149_230166_37703EFF X-CRM114-Status: GOOD ( 19.95 ) 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 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. The compiler-generated code won't have any problem on arm64 accessing the struct x members. As I said a few times, it's not affecting any other architecture and not breaking arm64 either. Anyway, let's agree to disagree. I'll look into keeping CRYPTO_MINALIGN as ARCH_KMALLOC_MINALIGN and introduce a CRYPTO_DMA_MINALIGN (or just use ARCH_DMA_MINALIGN directly) together with something like Linus' dma_kmalloc() in places where an object aligned to ARCH_DMA_MINALIGN is needed in the crypto code. -- 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 0AF87C433F5 for ; Fri, 15 Apr 2022 09:51:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75EB76B0071; Fri, 15 Apr 2022 05:51:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E86E6B0073; Fri, 15 Apr 2022 05:51:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 588696B0074; Fri, 15 Apr 2022 05:51:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 45E6C6B0071 for ; Fri, 15 Apr 2022 05:51:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id DB151605F3 for ; Fri, 15 Apr 2022 09:51:49 +0000 (UTC) X-FDA: 79358646738.22.98ADA9D Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf28.hostedemail.com (Postfix) with ESMTP id 6C355C0005 for ; Fri, 15 Apr 2022 09:51:49 +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 7A88DB82D97; Fri, 15 Apr 2022 09:51:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D5D7C385A6; Fri, 15 Apr 2022 09:51:43 +0000 (UTC) Date: Fri, 15 Apr 2022 10:51:40 +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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6C355C0005 X-Stat-Signature: ec9ise6zrso13hzokmnnrwj5n43o9kp1 Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-HE-Tag: 1650016309-143815 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 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. The compiler-generated code won't have any problem on arm64 accessing the struct x members. As I said a few times, it's not affecting any other architecture and not breaking arm64 either. Anyway, let's agree to disagree. I'll look into keeping CRYPTO_MINALIGN as ARCH_KMALLOC_MINALIGN and introduce a CRYPTO_DMA_MINALIGN (or just use ARCH_DMA_MINALIGN directly) together with something like Linus' dma_kmalloc() in places where an object aligned to ARCH_DMA_MINALIGN is needed in the crypto code. -- Catalin