Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp25397lfe; Fri, 15 Apr 2022 17:45:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHMDUbASX/4M4VqlQN/7HvzCgaUVw1L2+sMoukisY8/aCG1H046R2Q+ZekVUzeoyYCgRnj X-Received: by 2002:a65:6181:0:b0:39d:871:2199 with SMTP id c1-20020a656181000000b0039d08712199mr1138002pgv.521.1650069934382; Fri, 15 Apr 2022 17:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650069934; cv=none; d=google.com; s=arc-20160816; b=NEEvWkpomLYdPLTjSeAtY9idRHB92dtaxLYGzoU3UbGTOUPtq09fMB7edrnGYCi0Zh G3aGkKt2UKBhObmr8TECoEyEYBU360rU7djJS9lSWGjpv10FmbsTyIrMziq2/Y2k7mQd mUHYbtlKrJtpREjQytEhLgkHM1zLkOf6KFHDF2y0S/cAS0Z/btYSgIY2zoRKTxfU0uae +3EK2JbYz0VQjMhJ+iRPNqSVDQfs5NZvDBysBbKA1yIY2ddo6klB7eFGU7sPP7/PUzsX n8rWBccTMTVBMz0c9RjZHRVC37NcxuxuO4sk8oKvU53OeU8vE1VHe1VPWE96YRBR1pJt Kbfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EMC4vL0Gb45eTPnLl3gvnblr08KqUoDe+vLqfogkpoo=; b=d53+M5EI+WBmd0kWsi1CHN/uGbzbfyHryM4NAITyw6GPDHWTqiozxDLHCbX9lPEAM2 w24wf0OJfd9slqTOf6gFQCFWFg4eXkAdgC9Ko+HFtBiAE5F+yNauDeQ7VO1Fszo0NUyk 2pw3H8JE+Vj4jY656tznE+c7Tb9NpFlngZI9Gu9gEWHBPZNUounDwUmPBlPBn1m3mzO7 C1ziq4msPz1/PQT+AyWRVhxS5JkZIPDH6vcd5g6SHNv6Rej7lHgrwCtmikPzJ5NbROXq 9wrNDw0dvx9yc8H9jCDpcVUOedSm5m/uww+fsugq8sON/RDMnBtb3SIdtJ8vqTFN8pOl ufDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="tOHxKo7/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b184-20020a6334c1000000b0039d91c88814si3044078pga.149.2022.04.15.17.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:45:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="tOHxKo7/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8411BF3FA5; Fri, 15 Apr 2022 17:37:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353462AbiDOM2Q (ORCPT + 99 others); Fri, 15 Apr 2022 08:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353467AbiDOM2C (ORCPT ); Fri, 15 Apr 2022 08:28:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBB10BF946 for ; Fri, 15 Apr 2022 05:25:34 -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 8B0AA61771 for ; Fri, 15 Apr 2022 12:25:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA82CC385A6 for ; Fri, 15 Apr 2022 12:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650025534; bh=peoji69cmwuartQe2i8D75ZJFCK0CFwaXH4nduVKmKI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tOHxKo7/rNGCwK41O/fR8wXFKYKKKZ0wQ0CZFboPixfg+fU9canaSUDY+bA8bdFmi jkKUDq43xMCjzuq7VJjgfCzszITzQ4scBSJ3y0Fs0VgiCfXD720S0ihI2rQHX3VQ0K dFoaBmZp3SJSnFVeuiXRooCOpQ1hm9f0WO4a/vwEzvJl1AhXgf24e9TnyEN3NJjktH t6VNXOUh4xvPfy3/9zBmMmtNurk7chYHBab/sE7+XYl2KJ0lgkLESTDypXDW7kBQYY NNLGCwpAeutGw1JDJGKQpGyTXTvKoOakUp9DnSETCD7cqe7fESVtQgXm5Ycu5AecUs SfQPKmK0a8vrQ== Received: by mail-ot1-f43.google.com with SMTP id i23-20020a9d6117000000b005cb58c354e6so5279982otj.10 for ; Fri, 15 Apr 2022 05:25:33 -0700 (PDT) X-Gm-Message-State: AOAM530qPr2dhV9PSbd3+s6FnziiZ0KVs4XnRgs0iIWaNQk56VoInTT7 hlmBY9Gw+IMCILQDKSUykGXEl7vZYtiTABU96Ls= X-Received: by 2002:a05:6830:2e7:b0:5b2:68c1:182a with SMTP id r7-20020a05683002e700b005b268c1182amr2547283ote.71.1650025533158; Fri, 15 Apr 2022 05:25:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ard Biesheuvel Date: Fri, 15 Apr 2022 14:25:21 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN To: Catalin Marinas 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" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, 15 Apr 2022 at 14:19, Catalin Marinas wrote: > > 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? > I suppose, yes. > 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. > As long as CRYPTO_MINALIGN >= ARCH_KMALLOC_MINALIGN, we won't be lying to the compiler when casting kmalloc buffers to these struct types. I'd still like to fix the bad DMA behavior but I suppose it is a separate issue.