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 2A3C2C43217 for ; Fri, 15 Apr 2022 12:25:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8394C6B0071; Fri, 15 Apr 2022 08:25:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E7F26B0073; Fri, 15 Apr 2022 08:25:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6890D6B0074; Fri, 15 Apr 2022 08:25:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 55EC16B0071 for ; Fri, 15 Apr 2022 08:25:36 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1E70C26176 for ; Fri, 15 Apr 2022 12:25:36 +0000 (UTC) X-FDA: 79359034272.22.97224F0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 8399540002 for ; Fri, 15 Apr 2022 12:25:35 +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 dfw.source.kernel.org (Postfix) with ESMTPS id BC5FB6168E for ; Fri, 15 Apr 2022 12:25:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A03DC385AD for ; Fri, 15 Apr 2022 12:25:34 +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-f45.google.com with SMTP id g17-20020a9d6191000000b005e8d8583c36so5283444otk.8 for ; Fri, 15 Apr 2022 05:25:33 -0700 (PDT) X-Gm-Message-State: AOAM532zIpZ9HFY1UzE5CKhWwpcKAGh5SOaDyp3AjzTuWW4A0icgGSxz C+lxgjId3n62HkAvkoSUP40Oahq0uGb+KuASlx0= X-Google-Smtp-Source: ABdhPJyq39krpe9z+Gp7B5aYHY58HMPsCZSR8rk8R3+dy4FhmDm7RCJ4PRkY/ftj0dMkr/QFZfSuIwG7hhI/028eLpo= 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" Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tOHxKo7/"; spf=pass (imf01.hostedemail.com: domain of ardb@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=ardb@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: r8w3dwswxp9hhtqe4x8aizkh9phgynnh X-Rspamd-Queue-Id: 8399540002 X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650025535-665422 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, 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.