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 B1F4BC7EE23 for ; Tue, 30 May 2023 13:39:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1992900002; Tue, 30 May 2023 09:39:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC9266B0074; Tue, 30 May 2023 09:39:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB8EF900002; Tue, 30 May 2023 09:39:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CDE556B0072 for ; Tue, 30 May 2023 09:39:07 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7BB6A1C7011 for ; Tue, 30 May 2023 13:39:07 +0000 (UTC) X-FDA: 80847027534.24.33974FE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 0812F40016 for ; Tue, 30 May 2023 13:39:03 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf11.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685453944; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0qTDO3SMv5reip0XBtU01sCjKdD4sTIIGFz51Ow9OaM=; b=YzRELWXgORbixI3PAV7Sbz+VESCTpnKFfqGCXhS19UmfBqghO8AMT4r/isHSjIKwJlEZ4c cXs3sxN+G5te6rFV/kwow1v2B5AhrsVwISECuwl5Ya+WtobossrkfE+HVpOUNCychwrAkR O/Sq6XtBz93/uF3Ouy0o4X/zYQmuPw4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf11.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685453944; a=rsa-sha256; cv=none; b=iW0sn+txExPXAt2qBUMAVPeLW4e6Wjd3NUJGu4ahPz1n0n0QO03tfOpL+Z4FG+sey4USYI FnJI+2xeQDVOfFkWfoCXpy9qJnE4jXcoCMQBcCrZY+bXCzIUxmAZSA2HmCbz54eXVvms/2 JF6XBvHsGzJFeVCflGQvC8TNuIj3MHc= 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 CC1D963045; Tue, 30 May 2023 13:39:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFFF6C433EF; Tue, 30 May 2023 13:38:58 +0000 (UTC) Date: Tue, 30 May 2023 14:38:55 +0100 From: Catalin Marinas To: Jonathan Cameron Cc: Linus Torvalds , Christoph Hellwig , Robin Murphy , Arnd Bergmann , Greg Kroah-Hartman , Will Deacon , Marc Zyngier , Andrew Morton , Herbert Xu , Ard Biesheuvel , Isaac Manjarres , Saravana Kannan , Alasdair Kergon , Daniel Vetter , Joerg Roedel , Mark Brown , Mike Snitzer , "Rafael J. Wysocki" , linux-mm@kvack.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v5 00/15] mm, dma, arm64: Reduce ARCH_KMALLOC_MINALIGN to 8 Message-ID: References: <20230524171904.3967031-1-catalin.marinas@arm.com> <20230525133138.000014b4@Huawei.com> <20230526170740.000000df@Huawei.com> <20230526172930.000015f8@Huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230526172930.000015f8@Huawei.com> X-Rspamd-Queue-Id: 0812F40016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: eufdp8seq1e75opzmj7kd88pirqodk53 X-HE-Tag: 1685453943-532005 X-HE-Meta: U2FsdGVkX18sky9x+kkorK25ITCNU2+jtZwezyn2aE+Sn8ABj7+EwG4NXByyHc4Gy2AwIsbAcUbqFaQ7yIMbg3PkhHxcl49qUI9IpvXml5o4MvV+rv6ElgS+O0mdKRBQngqH28c3JWuI9DSXG+7NKpiaYhcKCoNHKqf/xxlR4FLKClny4sov7bgukY3waGvQQ9b+J7dY0JevwnyXRAtprqquw344V+SqYBDHJYYkYub17CVCYLN4PmZfwFN/2QPidLiWO1AlO+f3ybUPQZ6P93HaLrzhn/luvePaQSKH2CHurElrsB08AzGUI+QPvNki4hHEI/bjmRsCuB97tiShBRcdW4fT4DxYf5vsBxfryB76/FK0BDNo7PJnKPL4tIDDVl8LXJJrkG7s8R3GoF/WVU9x4fPWrbV4F82Z43Rlc2meTnrCJBwTrg9I1Mhet34YQ9TeFuzc4yUMJc+QN6fk7gJuxxcnlVCIcQbAGbxHe44pRKBezuPnQuPN47rw3uPrZt1jpSsHxrE1/fLRDScuDDrxGpftOpdvmwFIujiTh6fSrbmN5hj0OzcucVmiykXPLroIW/5oPNc0TSCmElWB3qPlFiSD1/8IGjYR0UI+bHMVRljGCWdPYeEXOUK77DABW0JhyhxxLkdbYeb9kN8t4MS4KB65YJxc+MekRVHH7egBMhOf6dn80o6+x0ubeuKlcfoyuio2/1zOShKFfL8xYtuHWP4TVtmT0Fc9/2nOR7oK5zvotJ46rNmq/R4oA8J0vuCUuhyyD47Ieslk1vga72JU/PYpbpOV/53bV/9JIgQvQ5XhiLdFa7eHzGak9fA4VxVZhMA/hYePAlBY95XQJkJSIw8RFHeTOZkZAPzKpAr/0w3RNy0RvzTkBmKedl/Y0zzUMJTSr2PP3M/OyuBWqecI3dgSvZd/FjOK2rRw35fQ+gIwmJfL2VU3LBhGwfr3c6Ou9vxb5d/LgBuphZ0 yeH1J2bO 87mxhy2Xg0nFH9WKsw7Bex2DTuaQvDGOY6iGxj9kquQzf8HQqzJ66yrb9Y3/Dm6IwQGb9kjlqwM4r5Ef2FKhlP/BhZsaBZ6IbiqmRcp00LJ25arSJoUQ5VUU7P9AmOBh4q8ISMeUMpXZRms9xHOLv/TL5z9pR1jzaCNMY9pEvkLm0DhGAL7l9H2TTq3MhMeEoN4CrMK0WFBlO+I8TFHAV4oJHyYwyOiSjKZGE6TD2iJ3w3iaB/hR1zXYMbrYbexAopjYysIsroX296/YXI3Q+sF7uPAMaVdhFcH9xaqjW4FQXRYj+Gf61LlwcJ/d4IwY+cOWBDVyaIFm2l5l2UlYIDuOJOiXqZl49E7SvM+MnNZ0yYJsmq/QkCCzw/twoztJg20E//NqlgwzUpDGGfb80FJgUDZfGTyOoqd1+CCKkQccw0+CQwph2qop++JumAwvtiu4Bh0K+l7ClUT59QIWPQC8+UBVRjreqI7+DrE7QDGqDtnvvA/hc6z7iLjwhJUib6lDkZlZX+TX5e7UvQs3tRfhRuVdia0eL/l5o7zC67Bqvs7s= 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, May 26, 2023 at 05:29:30PM +0100, Jonathan Cameron wrote: > On Fri, 26 May 2023 17:07:40 +0100 > Jonathan Cameron wrote: > > On Thu, 25 May 2023 15:31:34 +0100 > > Catalin Marinas wrote: > > > On Thu, May 25, 2023 at 01:31:38PM +0100, Jonathan Cameron wrote: > > > > On Wed, 24 May 2023 18:18:49 +0100 > > > > Catalin Marinas wrote: > > > > > Another version of the series reducing the kmalloc() minimum alignment > > > > > on arm64 to 8 (from 128). Other architectures can easily opt in by > > > > > defining ARCH_KMALLOC_MINALIGN as 8 and selecting > > > > > DMA_BOUNCE_UNALIGNED_KMALLOC. > > > > > > > > > > The first 10 patches decouple ARCH_KMALLOC_MINALIGN from > > > > > ARCH_DMA_MINALIGN and, for arm64, limit the kmalloc() caches to those > > > > > aligned to the run-time probed cache_line_size(). On arm64 we gain the > > > > > kmalloc-{64,192} caches. > > > > > > > > > > The subsequent patches (11 to 15) further reduce the kmalloc() caches to > > > > > kmalloc-{8,16,32,96} if the default swiotlb is present by bouncing small > > > > > buffers in the DMA API. > > > > > > > > I think IIO_DMA_MINALIGN needs to switch to ARCH_DMA_MINALIGN as well. > > > > > > > > It's used to force static alignement of buffers with larger structures, > > > > to make them suitable for non coherent DMA, similar to your other cases. > > > > > > Ah, I forgot that you introduced that macro. However, at a quick grep, I > > > don't think this forced alignment always works as intended (irrespective > > > of this series). Let's take an example: > > > > > > struct ltc2496_driverdata { > > > /* this must be the first member */ > > > struct ltc2497core_driverdata common_ddata; > > > struct spi_device *spi; > > > > > > /* > > > * DMA (thus cache coherency maintenance) may require the > > > * transfer buffers to live in their own cache lines. > > > */ > > > unsigned char rxbuf[3] __aligned(IIO_DMA_MINALIGN); > > > unsigned char txbuf[3]; > > > }; > > > > > > The rxbuf is aligned to IIO_DMA_MINALIGN, the structure and its size as > > > well but txbuf is at an offset of 3 bytes from the aligned > > > IIO_DMA_MINALIGN. So basically any cache maintenance on rxbuf would > > > corrupt txbuf. > > > > That was intentional (though possibly wrong if I've misunderstood > > the underlying issue). > > > > For SPI controllers at least my understanding was that it is safe to > > assume that they won't trample on themselves. The driver doesn't > > touch the buffers when DMA is in flight - to do so would indeed result > > in corruption. > > > > So whilst we could end up with the SPI master writing stale data back > > to txbuf after the transfer it will never matter (as the value is unchanged). > > Any flushes in the other direction will end up flushing both rxbuf and > > txbuf anyway which is also harmless. > > Adding missing detail. As the driver never writes txbuf whilst any DMA > is going on, the second cache evict (to flush out any lines that have > crept back into cache after the flush - and write backs - pre DMA) will > find a clean line and will drop it without writing back - thus no corruption. Thanks for the clarification. One more thing, can the txbuf be written prior to the DMA_FROM_DEVICE transfer into rxbuf? Or the txbuf writing is always followed by a DMA_TO_DEVICE mapping (which would flush the cache line). -- Catalin