Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp807539pxb; Fri, 15 Apr 2022 11:48:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkqL5zgbXIz7RSGEjEa+TU6P0zmFfEOVeQC9tzaUeNAqLHFJfeHv2+RzWIngx31f3A7+bD X-Received: by 2002:a17:902:cf0d:b0:156:1cc:f08f with SMTP id i13-20020a170902cf0d00b0015601ccf08fmr231836plg.42.1650048501809; Fri, 15 Apr 2022 11:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650048501; cv=none; d=google.com; s=arc-20160816; b=YCqv/hqxzE8CE1/KY7rIYRfWKXYpfLM6bdPkPBy0ooWy4MQH5JaUTToTkrrC3IUTzk XyYhWV6OmaS+o2nl/l+FT7pGiqWbCZWiC9aIsggO2TCBfif9JJjR4Rz2ENA9CN9IvvwA lBOIhsaA9uJFrJbcEH2fy6bNMwrwQ01kpiTUMdAVLS6okI1mkBnNsJnW+FbQ3ZFqfp3Z EFdkYzKUvhjFk7jLH+THCA6M9nELpdddjahV0au7B1YXZaBizgDlkkcsC9npLoHzs/sb n1Lr8NImj824RxopkV0s07jFbGg/tlKrj+GjQLMbtK6F9CycB2m6qXWMkfNhTD5B5TC/ x7Nw== 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=gTXjIiZdFYMfpnLEUkyq4U2qACISkZneYcienz60nKo=; b=YNGYsVrT5P177e3JXDeo1mSr+g63RZtD6dCXu+7Vj16CvKcm0vnDL6CyI2/6ro77At sPt1WdxbI26HjEYK/Qt8V5aexogbuThGpuBt99R/3RSTkrbdOZtSZJmNkmVOwgPudwih ICTczO8ILq4XJjBu7wtCPQDXsOf92gylPS+2pA65XJ/Yw90uQQP8vlbOL7r7CxcJF/if FvfsBAu7NnXBDIBn3qH9OFUEFEX5yUV3xI67dtY7lH+MgvBuHnSNMVhZYcnEZXD3keBd x94fNMGXnIWa0GIBMNENqrtMi+xYKbvMcL5a9AjsE69n6jyScLWvDCpD6bNDjfylOQmO o7sA== 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 y30-20020a056a001c9e00b004fa7630aa94si2213773pfw.126.2022.04.15.11.48.06; Fri, 15 Apr 2022 11:48:21 -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 S1353661AbiDOMfb (ORCPT + 99 others); Fri, 15 Apr 2022 08:35:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353634AbiDOMfH (ORCPT ); Fri, 15 Apr 2022 08:35:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7F60C8BF1 for ; Fri, 15 Apr 2022 05:31:38 -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 2402A61CEE for ; 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-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 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