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 7E51BC77B7F for ; Fri, 19 May 2023 15:46:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02059900004; Fri, 19 May 2023 11:46:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE9ED900003; Fri, 19 May 2023 11:46:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8C76900004; Fri, 19 May 2023 11:46:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BC613900003 for ; Fri, 19 May 2023 11:46:44 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 99548AD3F4 for ; Fri, 19 May 2023 15:46:44 +0000 (UTC) X-FDA: 80807432328.16.53399BE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id D9767A000F for ; Fri, 19 May 2023 15:46:42 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf15.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=1684511203; 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=f+zoR2iEm7aGMHaSwecuAA8cnDFK0R6Q+yLXMDss1HM=; b=pQZoN7HRD17XUCtbpPmijhT6uUTR+uNQOUvpOBrqA5wv8WFjHhNrG1q19I7y6XsiZgjaHl 4jSpDUBqjWdsjVvFvO+Da79lcx6NioRzxDaSiRePyhqDQiv8TA4kD6vmolM62gengKTxsU km0CbnBmCfmJOLsk2c1jHfFVCvcDWUs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf15.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=1684511203; a=rsa-sha256; cv=none; b=PLFTiGC61BYe0QjBp5rFU+8H+YCxmy9vrXgUgw9+jdpaSvYuJQJsUTOZDiijtW95OVdt13 5Opwm2jvr2ykbnyd6QAVcJvY1C0LvDoTKeRU0RYblizEAa1E0fG+7FViQ/zMQawWBBKqjx qvsI7KpbYo/KjpNt0C7Mb4PacQvQgBw= 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 F2519643CF; Fri, 19 May 2023 15:46:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 247B1C433D2; Fri, 19 May 2023 15:46:37 +0000 (UTC) Date: Fri, 19 May 2023 16:46:35 +0100 From: Catalin Marinas To: Robin Murphy Cc: Linus Torvalds , Arnd Bergmann , Christoph Hellwig , 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 v4 13/15] iommu/dma: Force bouncing if the size is not cacheline-aligned Message-ID: References: <20230518173403.1150549-1-catalin.marinas@arm.com> <20230518173403.1150549-14-catalin.marinas@arm.com> <9dc3e036-75cd-debf-7093-177ef6c7a3ae@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D9767A000F X-Stat-Signature: jg8ej54nr6tr7ft5r7e7gur1sitwsnnr X-Rspam-User: X-HE-Tag: 1684511202-223489 X-HE-Meta: U2FsdGVkX1+pEEAgIftg6Wfl88RntvmlwuYsL/kN0/RSSpGSXeMSsLzoPKcPV2sTXMa8YZRbKy2VViS3e7xujvpuC+nanaGSz6RZkaBrKySs+QR5Ea3ijTjaXV7Z32Bl0pXzWU6KBrtV0lCNOk6PJUfAR0P2/4CpSxewpkYDwzjqEXbrc0MyTvmP3qCbFmpqsqd1Z2yJYbUubx2YxtyLJ0wNglJVTrVPlcu7aBWWXTeWJ8Lc6LcVqrPGdwB3F4ge8qUbcXWs/MCO8SOPhX4BiVGYy9qAh/AwePWudzKbbB2LMpB7VvV8YYnAQST2pIvGwsTDsvqBTsXpxBdGzkWboKUvNGD/GSl5BOWFu1V1I1duJkBJ1BbBrcuHiiTO8wl+RpTIgflhhO1GId2p5DzRwtGp2FUPP53TD7FuGaBANonGylMtG+Yopxl0M9o1cniA2zJlI/uJDIcm+QM8T9rn4R0K7oOBhQaKTP3KPoxiKRiu7oBFxaH4EDKQiUqcVMdY/Pgm6wPC/IW43TgkXSNGFiZE8XN6ZJxWCEaYphlsETecf2kTio4g/L7x7wyUOgForod5jCgD09YFwjd3Evsj9Ax860wkyKIUu/1E/Eu0DK4B4RQLcBMBPPmJH01mZfq+xjAH9cI7uHNjkCL18voaiiXgF5m17HDjKQ9edzbvWhKNCK1OVB3n7aBaqJJVdmoaBuwnCFK/kebXu5fzgaVol/GcCVDpsnWswfHnmzyXfAE8ojGFLFG1l14kf9CqE2rd5t2YUK3zLRmi8fc0gzj7LXJgNm0lXjrZjgtteK3H+KcmdfQNIa40wiWv05m4rM+q7hlXJG9QpC8BglqdG1zdOsRVaE0kvoQeGBEiTyhCxtifBV2POiCfvDuKJIoUcBadDkpAvsnsLHdf26T/7bCE7ZSt2Q7ihosZ95ySydvGT8wKg7uLF50ApfmOMr1R3rpvXfMX83VT8wSpv8kgAZV s5nSDFIA BT6MzXH9btPo9kfAsZvg0mSlD8CcN5jAsgytzoZHAeR3OjLK801CLn+GuvptlT+2Amqe6TpXevIjdAk5cgdK7oIv0piDrvTcqcEp2PCn1K1Rf4h6iR/qG47xm7pwyIvkRZZORY1UVjTig2C95we3EA0Um97qpdwzvK5K18Wx6srFqCtGrz5d5H86vI2zXz3kzCDQfA+sBKUK3EL3UqGQeQB+nu5Oq/Suoseh/SbEPKtDrsjUGySMIN18/99VYXiKGjQW5Vm1bBrtRMahAp79PADXlyvvGDt4QAhYFjeHZOwgndBd/CPmh3qL23wDmthNLsX2/JPi2CqY5KuNpnP+HYJr3qyYipJfvQP/3CyIMSiKMhzY+jeqHZOvIGrQRlVXbiwHs8foKwC38S2FRx7wt0RgHra0XgYubjK5x 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 19, 2023 at 03:02:24PM +0100, Catalin Marinas wrote: > On Fri, May 19, 2023 at 01:29:38PM +0100, Robin Murphy wrote: > > On 2023-05-18 18:34, Catalin Marinas wrote: > > > + sg_dma_mark_bounced(sg); > > > > I'd prefer to have iommu_dma_map_sg_swiotlb() mark the segments, since > > that's in charge of the actual bouncing. Then we can fold the alignment > > check into dev_use_swiotlb() (with the dev_is_untrusted() condition taking > > priority), and sync/unmap can simply rely on sg_is_dma_bounced() alone. > > With this patch we only set the SG_DMA_BOUNCED on the first element of > the sglist. Do you want to set this flag only on individual elements > being bounced? It makes some sense in principle but the > iommu_dma_unmap_sg() path would need to scan the list again to decide > whether to go the swiotlb path. > > If we keep the SG_DMA_BOUNCED flag only on the first element, I can > change it to your suggestion, assuming I understood it. Can one call: iommu_dma_map_sg(sg, nents); ... iommu_dma_unmap_sg(sg + n, nents - n); (i.e. unmap it in multiple steps) If yes, setting SG_DMA_BOUNCED on the first element only won't work. I don't find this an unlikely scenario, so we maybe we do have to walk the list again in unmap to search for the flag. -- Catalin