From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4C20182 for ; Tue, 8 Nov 2022 10:51:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42ECEC433B5; Tue, 8 Nov 2022 10:51:11 +0000 (UTC) Date: Tue, 8 Nov 2022 10:51:07 +0000 From: Catalin Marinas To: Robin Murphy Cc: Christoph Hellwig , Linus Torvalds , 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 v3 03/13] iommu/dma: Force bouncing of the size is not cacheline-aligned Message-ID: References: <20221106220143.2129263-1-catalin.marinas@arm.com> <20221106220143.2129263-4-catalin.marinas@arm.com> <20221107094603.GB6055@lst.de> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Nov 07, 2022 at 01:26:21PM +0000, Robin Murphy wrote: > On 2022-11-07 10:54, Catalin Marinas wrote: > > On Mon, Nov 07, 2022 at 10:46:03AM +0100, Christoph Hellwig wrote: > > > > +static inline bool dma_sg_kmalloc_needs_bounce(struct device *dev, > > > > + struct scatterlist *sg, int nents, > > > > + enum dma_data_direction dir) > > > > +{ > > > > + struct scatterlist *s; > > > > + int i; > > > > + > > > > + if (!IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) || > > > > + dir == DMA_TO_DEVICE || dev_is_dma_coherent(dev)) > > > > + return false; > > > > > > This part should be shared with dma-direct in a well documented helper. > > > > > > > + for_each_sg(sg, s, nents, i) { > > > > + if (dma_kmalloc_needs_bounce(dev, s->length, dir)) > > > > + return true; > > > > + } > > > > > > And for this loop iteration I'd much prefer it to be out of line, and > > > also not available in a global helper. > > > > > > But maybe someone can come up with a nice tweak to the dma-iommu > > > code to not require the extra sglist walk anyway. > > > > An idea: we could add another member to struct scatterlist to track the > > bounced address. We can then do the bouncing in a similar way to > > iommu_dma_map_sg_swiotlb() but without the iova allocation. The latter > > would be a common path for both the bounced and non-bounced cases. > > FWIW I spent a little time looking at this as well; I'm pretty confident > it can be done without the extra walk if the iommu-dma bouncing is > completely refactored (and it might want a SWIOTLB helper to retrieve > the original page from a bounced address). Doesn't sg_page() provide the original page already? Either way, the swiotlb knows it as it needs to do the copying between buffers. > That's going to be a bigger > job than I'll be able to finish this cycle, and I concluded that this > in-between approach wouldn't be worth posting for its own sake, but as > part of this series I think it's a reasonable compromise. I'll drop my hack once you have something. Happy to carry it as part of this series. > diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h > index 375a5e90d86a..87aaf8b5cdb4 100644 > --- a/include/linux/scatterlist.h > +++ b/include/linux/scatterlist.h > @@ -16,7 +16,7 @@ struct scatterlist { > #ifdef CONFIG_NEED_SG_DMA_LENGTH > unsigned int dma_length; > #endif > -#ifdef CONFIG_PCI_P2PDMA > +#ifdef CONFIG_NEED_SG_DMA_FLAGS > unsigned int dma_flags; > #endif I initially had something similar but I decided it's overkill for a patch that I expected to be NAK'ed. I'll include your patch in my series in the meantime. -- Catalin 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16B6CC4332F for ; Tue, 8 Nov 2022 10:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RxPI6aTEaA3dU7jn9vcbdX5F/cIzjL2CS/Sz2/czNmE=; b=RnnMeVbLjdXhYm pzq69C5/20VgIPN+r8axZygWn9Gbnr+TcvJt9Ibym7gYIb8m5UoBhehU1krCH4GCItb1lVVeU0d8v Tbyekc11dNWfUhvyR2JpNq84zpnfG8OeAW0llB2qm/Ofqr0nxUoDjEjcSlTQ8oJUhDIS5o5VGCkeT J94ASb+w/5olGsgU7ucUFyXCeJEK37MVOCm1w8fb9stczSTn7fooNlDLx+slCgjeBO0u68ga+3CDH e3YHB9HBMCLTDVNdTcqkZTsHO7IXhrGCv8ItPh0su8oSsv8S7t+GqsTFT6QQUJHGdBbixe7hETKK9 mKvYH2dsBUjsgvxG6Qhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1osMCO-004g5m-95; Tue, 08 Nov 2022 10:51:20 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1osMCJ-004g3H-NV for linux-arm-kernel@lists.infradead.org; Tue, 08 Nov 2022 10:51:17 +0000 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 405EF614E5; Tue, 8 Nov 2022 10:51:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42ECEC433B5; Tue, 8 Nov 2022 10:51:11 +0000 (UTC) Date: Tue, 8 Nov 2022 10:51:07 +0000 From: Catalin Marinas To: Robin Murphy Cc: Christoph Hellwig , Linus Torvalds , 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 v3 03/13] iommu/dma: Force bouncing of the size is not cacheline-aligned Message-ID: References: <20221106220143.2129263-1-catalin.marinas@arm.com> <20221106220143.2129263-4-catalin.marinas@arm.com> <20221107094603.GB6055@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221108_025115_860035_F6F38909 X-CRM114-Status: GOOD ( 33.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 07, 2022 at 01:26:21PM +0000, Robin Murphy wrote: > On 2022-11-07 10:54, Catalin Marinas wrote: > > On Mon, Nov 07, 2022 at 10:46:03AM +0100, Christoph Hellwig wrote: > > > > +static inline bool dma_sg_kmalloc_needs_bounce(struct device *dev, > > > > + struct scatterlist *sg, int nents, > > > > + enum dma_data_direction dir) > > > > +{ > > > > + struct scatterlist *s; > > > > + int i; > > > > + > > > > + if (!IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) || > > > > + dir == DMA_TO_DEVICE || dev_is_dma_coherent(dev)) > > > > + return false; > > > > > > This part should be shared with dma-direct in a well documented helper. > > > > > > > + for_each_sg(sg, s, nents, i) { > > > > + if (dma_kmalloc_needs_bounce(dev, s->length, dir)) > > > > + return true; > > > > + } > > > > > > And for this loop iteration I'd much prefer it to be out of line, and > > > also not available in a global helper. > > > > > > But maybe someone can come up with a nice tweak to the dma-iommu > > > code to not require the extra sglist walk anyway. > > > > An idea: we could add another member to struct scatterlist to track the > > bounced address. We can then do the bouncing in a similar way to > > iommu_dma_map_sg_swiotlb() but without the iova allocation. The latter > > would be a common path for both the bounced and non-bounced cases. > > FWIW I spent a little time looking at this as well; I'm pretty confident > it can be done without the extra walk if the iommu-dma bouncing is > completely refactored (and it might want a SWIOTLB helper to retrieve > the original page from a bounced address). Doesn't sg_page() provide the original page already? Either way, the swiotlb knows it as it needs to do the copying between buffers. > That's going to be a bigger > job than I'll be able to finish this cycle, and I concluded that this > in-between approach wouldn't be worth posting for its own sake, but as > part of this series I think it's a reasonable compromise. I'll drop my hack once you have something. Happy to carry it as part of this series. > diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h > index 375a5e90d86a..87aaf8b5cdb4 100644 > --- a/include/linux/scatterlist.h > +++ b/include/linux/scatterlist.h > @@ -16,7 +16,7 @@ struct scatterlist { > #ifdef CONFIG_NEED_SG_DMA_LENGTH > unsigned int dma_length; > #endif > -#ifdef CONFIG_PCI_P2PDMA > +#ifdef CONFIG_NEED_SG_DMA_FLAGS > unsigned int dma_flags; > #endif I initially had something similar but I decided it's overkill for a patch that I expected to be NAK'ed. I'll include your patch in my series in the meantime. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel