mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tomasz Figa <tfiga@chromium.org>
To: iommu@lists.linux-foundation.org
Cc: Tomasz Figa <tfiga@chromium.org>, Joerg Roedel <joro@8bytes.org>,
	Hiroshi Doyu <hdoyu@nvidia.com>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Alexandre Courbot <gnurou@gmail.com>,
	Vince Hsu <vince.h@nvidia.com>,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Paul Walmsley <paul@pwsan.com>,
	Mikko Perttunen <mperttunen@nvidia.com>,
	Tomeu Vizoso <tomeu.vizoso@collabora.com>,
	Will Deacon <will.deacon@arm.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Antonios Motakis <a.motakis@virtualopensystems.com>,
	Olav Haugan <ohaugan@codeaurora.org>,
	Nicolas Iooss <nicolas.iooss_linux@m4x.org>,
	linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: [RFC PATCH 1/3] iommu: Add support for out of band flushing
Date: Tue, 29 Sep 2015 14:25:24 +0900	[thread overview]
Message-ID: <1443504379-31841-2-git-send-email-tfiga@chromium.org> (raw)
In-Reply-To: <1443504379-31841-1-git-send-email-tfiga@chromium.org>

This patch adds a new "flush" callback to iommu_ops, which is supposed
to perform any necessary flushes within given IOMMU domain to make any
changes to mappings of given area [iova; iova + size) be reflected to
IOMMU clients.

The purpose is to let IOMMU drivers skip page-by-page flushes and
replace it with one flush of full address range on devices which support
it.

Signed-off-by: Tomasz Figa <tfiga@chromium.org>
---
 drivers/iommu/iommu.c | 33 ++++++++++++++++++++++++++++++---
 include/linux/iommu.h |  2 ++
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 049df49..d6bb8fe 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1286,8 +1286,15 @@ static size_t iommu_pgsize(struct iommu_domain *domain,
 	return pgsize;
 }
 
-int iommu_map(struct iommu_domain *domain, unsigned long iova,
-	      phys_addr_t paddr, size_t size, int prot)
+static void iommu_flush(struct iommu_domain *domain, unsigned long iova,
+			size_t size)
+{
+	if (domain->ops->flush)
+		domain->ops->flush(domain, iova, size);
+}
+
+static int __iommu_map(struct iommu_domain *domain, unsigned long iova,
+		       phys_addr_t paddr, size_t size, int prot)
 {
 	unsigned long orig_iova = iova;
 	unsigned int min_pagesz;
@@ -1340,6 +1347,20 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
 
 	return ret;
 }
+
+int iommu_map(struct iommu_domain *domain, unsigned long iova,
+	      phys_addr_t paddr, size_t size, int prot)
+{
+	int ret;
+
+	ret = __iommu_map(domain, iova, paddr, size, prot);
+	if (ret)
+		return ret;
+
+	iommu_flush(domain, iova, size);
+
+	return 0;
+}
 EXPORT_SYMBOL_GPL(iommu_map);
 
 size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
@@ -1389,6 +1410,7 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
 		unmapped += unmapped_page;
 	}
 
+	iommu_flush(domain, orig_iova, unmapped);
 	trace_unmap(orig_iova, size, unmapped);
 	return unmapped;
 }
@@ -1419,19 +1441,24 @@ size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
 		if (!IS_ALIGNED(s->offset, min_pagesz))
 			goto out_err;
 
-		ret = iommu_map(domain, iova + mapped, phys, s->length, prot);
+		ret = __iommu_map(domain, iova + mapped, phys, s->length, prot);
 		if (ret)
 			goto out_err;
 
 		mapped += s->length;
 	}
 
+	iommu_flush(domain, iova, mapped);
+
 	return mapped;
 
 out_err:
 	/* undo mappings already done */
 	iommu_unmap(domain, iova, mapped);
 
+	/* flush in case part of our mapping already got cached */
+	iommu_flush(domain, iova, mapped);
+
 	return 0;
 
 }
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index f9c1b6d..18e59a9 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -164,6 +164,8 @@ struct iommu_ops {
 		     size_t size);
 	size_t (*map_sg)(struct iommu_domain *domain, unsigned long iova,
 			 struct scatterlist *sg, unsigned int nents, int prot);
+	void (*flush)(struct iommu_domain *domain, unsigned long iova,
+		      size_t size);
 	phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
 	int (*add_device)(struct device *dev);
 	void (*remove_device)(struct device *dev);
-- 
2.6.0.rc2.230.g3dd15c0


  reply	other threads:[~2015-09-29  5:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29  5:25 [RFC PATCH 0/3] iommu: Add range flush operation Tomasz Figa
2015-09-29  5:25 ` Tomasz Figa [this message]
2015-09-29  9:32   ` [RFC PATCH 1/3] iommu: Add support for out of band flushing Thierry Reding
2015-09-29 11:56     ` Tomasz Figa
2015-09-29  5:25 ` [RFC PATCH 2/3] memory: tegra: add TLB cache line size Tomasz Figa
2015-09-29  9:43   ` Thierry Reding
2015-09-29 12:11     ` Tomasz Figa
2015-09-29  5:25 ` [RFC PATCH 3/3] iommu/tegra-smmu: Make the driver use out of band flushing Tomasz Figa
2015-09-29  9:27 ` [RFC PATCH 0/3] iommu: Add range flush operation Thierry Reding
2015-09-29 11:54   ` Tomasz Figa
2015-09-29 12:22   ` Joerg Roedel
2015-09-29 12:20 ` Joerg Roedel
2015-09-29 14:20 ` Robin Murphy
2015-09-29 14:32   ` Russell King - ARM Linux
2015-09-29 16:27     ` Robin Murphy
2015-09-29 16:40       ` Russell King - ARM Linux
2015-09-29 17:13         ` Robin Murphy

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=1443504379-31841-2-git-send-email-tfiga@chromium.org \
    --to=tfiga@chromium.org \
    --cc=a.motakis@virtualopensystems.com \
    --cc=alex.williamson@redhat.com \
    --cc=arnd@arndb.de \
    --cc=gnurou@gmail.com \
    --cc=hdoyu@nvidia.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mperttunen@nvidia.com \
    --cc=nicolas.iooss_linux@m4x.org \
    --cc=ohaugan@codeaurora.org \
    --cc=paul@pwsan.com \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=swarren@wwwdotorg.org \
    --cc=thierry.reding@gmail.com \
    --cc=tomeu.vizoso@collabora.com \
    --cc=vince.h@nvidia.com \
    --cc=will.deacon@arm.com \
    /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

all inboxes | Powered by JetHome®