iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
To: joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org,
	hch-jcswGhMUV9g@public.gmane.org
Cc: guohanjun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
	catalin.marinas-5wv7dgnIgG8@public.gmane.org,
	will.deacon-5wv7dgnIgG8@public.gmane.org,
	linuxarm-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: [PATCH v2 3/3] arm64/dma-mapping: Mildly optimise non-coherent IOMMU ops
Date: Wed, 12 Sep 2018 16:24:14 +0100	[thread overview]
Message-ID: <b6d77151ac0133a39f3a3e69766f7bcf13edc70f.1536764440.git.robin.murphy@arm.com> (raw)
In-Reply-To: <cover.1536764440.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>

Whilst the symmetry of deferring to the existing sync callback in
__iommu_map_page() is nice, taking a round-trip through
iommu_iova_to_phys() is a pretty heavyweight way to get an address we
can trivially compute from the page we already have. Tweaking it to just
perform the cache maintenance directly when appropriate doesn't really
make the code any more complicated, and the runtime efficiency gain can
only be a benefit.

Furthermore, the sync operations themselves know they can only be
invoked on a managed DMA ops domain, so can use the fast specific domain
lookup to avoid excessive manipulation of the group refcount
(particularly in the scatterlist cases).

Acked-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
---

v2: Don't be totally broken by forgetting the offset

 arch/arm64/mm/dma-mapping.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 072c51fb07d7..cf017c5bb5e7 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -712,7 +712,7 @@ static void __iommu_sync_single_for_cpu(struct device *dev,
 	if (is_device_dma_coherent(dev))
 		return;
 
-	phys = iommu_iova_to_phys(iommu_get_domain_for_dev(dev), dev_addr);
+	phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dev_addr);
 	__dma_unmap_area(phys_to_virt(phys), size, dir);
 }
 
@@ -725,7 +725,7 @@ static void __iommu_sync_single_for_device(struct device *dev,
 	if (is_device_dma_coherent(dev))
 		return;
 
-	phys = iommu_iova_to_phys(iommu_get_domain_for_dev(dev), dev_addr);
+	phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dev_addr);
 	__dma_map_area(phys_to_virt(phys), size, dir);
 }
 
@@ -738,9 +738,9 @@ static dma_addr_t __iommu_map_page(struct device *dev, struct page *page,
 	int prot = dma_info_to_prot(dir, coherent, attrs);
 	dma_addr_t dev_addr = iommu_dma_map_page(dev, page, offset, size, prot);
 
-	if (!iommu_dma_mapping_error(dev, dev_addr) &&
-	    (attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
-		__iommu_sync_single_for_device(dev, dev_addr, size, dir);
+	if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
+	    !iommu_dma_mapping_error(dev, dev_addr))
+		__dma_map_area(page_address(page) + offset, size, dir);
 
 	return dev_addr;
 }
-- 
2.19.0.dirty

  parent reply	other threads:[~2018-09-12 15:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 15:24 [PATCH v2 0/3] iommu: Avoid DMA ops domain refcount contention Robin Murphy
     [not found] ` <cover.1536764440.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-09-12 15:24   ` [PATCH v2 1/3] iommu: Add fast hook for getting DMA domains Robin Murphy
2018-09-12 15:24   ` [PATCH v2 2/3] iommu/dma: Use fast DMA domain lookup Robin Murphy
     [not found]     ` <e42771992a73620f23128c0479b2ae91b3e177bf.1536764440.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-09-28 13:26       ` Marek Szyprowski
     [not found]         ` <20180928132605eucas1p1d39fedc3be3e4e2c16035c01a40cfab6~Ykz2Rax6e0538205382eucas1p17-MHMrYXj8g+pqW5MlFJXMulaTQe2KTcn/@public.gmane.org>
2018-09-28 13:52           ` Robin Murphy
     [not found]             ` <78a5b373-d569-4461-e258-3104286ba322-5wv7dgnIgG8@public.gmane.org>
2018-09-28 14:21               ` Marek Szyprowski
     [not found]                 ` <20180928142148eucas1p17d6ecbd5c98b3fe1bf008dbcf0626c76~YlkfonoPN1120711207eucas1p1u-MHMrYXj8g+pqW5MlFJXMulaTQe2KTcn/@public.gmane.org>
2018-09-28 15:31                   ` Robin Murphy
     [not found]                     ` <CGME20180928160945eucas1p17ff77fe34854548719880638ecb9c54d@eucas1p1.samsung.com>
2018-09-28 16:09                       ` [PATCH] drm/exynos: Use selected dma_dev default iommu domain instead of a fake one Marek Szyprowski
2018-09-28 16:13                         ` Robin Murphy
     [not found]                     ` <a9eb4b79-1fb8-eec7-0566-966f84022d7b-5wv7dgnIgG8@public.gmane.org>
2018-09-28 15:33                       ` [PATCH v2 2/3] iommu/dma: Use fast DMA domain lookup Christoph Hellwig
     [not found]                         ` <20180928153334.GA9462-jcswGhMUV9g@public.gmane.org>
2018-09-28 15:46                           ` Robin Murphy
2018-09-28 16:18                       ` Marek Szyprowski
2018-10-01 10:55                         ` Inki Dae
2018-09-12 15:24   ` Robin Murphy [this message]
2018-09-14 12:48   ` [PATCH v2 0/3] iommu: Avoid DMA ops domain refcount contention Will Deacon
     [not found]     ` <20180914124858.GA4010-5wv7dgnIgG8@public.gmane.org>
2018-09-17 11:20       ` John Garry
     [not found]         ` <dbb9e48f-e31b-b8a1-0287-378c35e9fdb9-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2018-09-20 12:51           ` John Garry
2018-09-17 13:33       ` Christoph Hellwig
     [not found]         ` <20180917133359.GA972-jcswGhMUV9g@public.gmane.org>
2018-09-18 13:28           ` Tom Murphy
2018-09-25  8:24   ` Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b6d77151ac0133a39f3a3e69766f7bcf13edc70f.1536764440.git.robin.murphy@arm.com \
    --to=robin.murphy-5wv7dgnigg8@public.gmane.org \
    --cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
    --cc=guohanjun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=hch-jcswGhMUV9g@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linuxarm-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).