From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Jason Gunthorpe <jgg@ziepe.ca>
Cc: virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Christoph Hellwig <hch@infradead.org>
Subject: [RFC] iommu/virtio: Use single flush queue (EXPERIMENTAL)
Date: Wed, 26 Jul 2023 13:14:33 +0200 [thread overview]
Message-ID: <20230726111433.1105665-1-schnelle@linux.ibm.com> (raw)
In-Reply-To: <20230717-dma_iommu-v11-0-a7a0b83c355c@linux.ibm.com>
Just like on paged s390 guests with their virtual IOMMU, syncing
mappings via virtio-iommu is quite expensive. It can thus benefit from
queueing unmapped IOVAs and flushing them in batches but less so from
parallel flushes which is what the shadow_on_flush flag introduced for
s390 tunes dma-iommu to do.
For this to work .flush_iotlb_all is implemented. Furthermore
.iotlb_sync_map is also implemented and used to pull the sync out of the
mapping operation for some additional batching and performance gain.
In a basic test with NVMe pass-through to a KVM guest on a Ryzen 3900X
these changes together lead to about 19% more IOPS in a fio test and
slightly more bandwidth too.
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
Note:
The idea of using the single flush queue scheme from my series "iommu/dma: s390
DMA API conversion and optimized IOTLB flushing"[0] for virtio-iommu was already
mentioned in the cover letter. I now wanted to explore this with this patch
which may also serve as a test vehicle for the single flush queue scheme usable
on non-s390.
Besides limited testing, this is marked experimental mainly because the use of
queuing needs to be a concious decision as it allows continued access to
unmapped pages for up to a second with the currently proposed single flush
queue mechanism. Also it might make sense to split this patch to do the
introduction and use of .iotlb_sync_map separately but as a test vehicle
I found it easier to consume as a single patch.
[0]: https://lore.kernel.org/linux-iommu/20230717-dma_iommu-v11-0-a7a0b83c355c@linux.ibm.com/
drivers/iommu/virtio-iommu.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 3551ed057774..f29eb4ce2b88 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -843,7 +843,7 @@ static int viommu_map_pages(struct iommu_domain *domain, unsigned long iova,
.flags = cpu_to_le32(flags),
};
- ret = viommu_send_req_sync(vdomain->viommu, &map, sizeof(map));
+ ret = viommu_add_req(vdomain->viommu, &map, sizeof(map));
if (ret) {
viommu_del_mappings(vdomain, iova, end);
return ret;
@@ -909,6 +909,27 @@ static void viommu_iotlb_sync(struct iommu_domain *domain,
{
struct viommu_domain *vdomain = to_viommu_domain(domain);
+ if (!vdomain->nr_endpoints)
+ return;
+ viommu_sync_req(vdomain->viommu);
+}
+
+static int viommu_iotlb_sync_map(struct iommu_domain *domain,
+ unsigned long iova, size_t size)
+{
+ struct viommu_domain *vdomain = to_viommu_domain(domain);
+
+ if (!vdomain->nr_endpoints)
+ return 0;
+ return viommu_sync_req(vdomain->viommu);
+}
+
+static void viommu_flush_iotlb_all(struct iommu_domain *domain)
+{
+ struct viommu_domain *vdomain = to_viommu_domain(domain);
+
+ if (!vdomain->nr_endpoints)
+ return;
viommu_sync_req(vdomain->viommu);
}
@@ -991,6 +1012,7 @@ static struct iommu_device *viommu_probe_device(struct device *dev)
if (ret)
goto err_free_dev;
}
+ dev->iommu->shadow_on_flush = 1;
return &viommu->iommu;
@@ -1037,6 +1059,8 @@ static bool viommu_capable(struct device *dev, enum iommu_cap cap)
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
return true;
+ case IOMMU_CAP_DEFERRED_FLUSH:
+ return true;
default:
return false;
}
@@ -1057,7 +1081,9 @@ static struct iommu_ops viommu_ops = {
.map_pages = viommu_map_pages,
.unmap_pages = viommu_unmap_pages,
.iova_to_phys = viommu_iova_to_phys,
+ .flush_iotlb_all = viommu_flush_iotlb_all,
.iotlb_sync = viommu_iotlb_sync,
+ .iotlb_sync_map = viommu_iotlb_sync_map,
.free = viommu_domain_free,
}
};
base-commit: 5514392fe77cd45b0d33bf239f13ba594a6759e5
--
2.39.2
next prev parent reply other threads:[~2023-07-26 11:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-17 11:00 [PATCH v11 0/6] iommu/dma: s390 DMA API conversion and optimized IOTLB flushing Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 1/6] iommu: Allow .iotlb_sync_map to fail and handle s390's -ENOMEM return Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 2/6] s390/pci: prepare is_passed_through() for dma-iommu Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 3/6] s390/pci: Use dma-iommu layer Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 4/6] iommu/s390: Force ISM devices to use IOMMU_DOMAIN_DMA Niklas Schnelle
2023-07-19 12:56 ` Matthew Rosato
2023-08-18 19:10 ` Robin Murphy
2023-08-23 10:53 ` Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 5/6] iommu/dma: Allow a single FQ in addition to per-CPU FQs Niklas Schnelle
2023-08-18 18:16 ` Robin Murphy
2023-08-23 14:21 ` Niklas Schnelle
2023-08-29 15:39 ` Robin Murphy
2023-07-17 11:00 ` [PATCH v11 6/6] iommu/dma: Use a large flush queue and timeout for shadow_on_flush Niklas Schnelle
2023-08-18 19:06 ` Robin Murphy
2023-07-26 11:14 ` Niklas Schnelle [this message]
2023-08-02 12:36 ` [RFC] iommu/virtio: Use single flush queue (EXPERIMENTAL) Jean-Philippe Brucker
2023-08-02 13:44 ` Jason Gunthorpe
2023-08-25 12:22 ` Niklas Schnelle
2023-08-18 16:51 ` [PATCH v11 0/6] iommu/dma: s390 DMA API conversion and optimized IOTLB flushing Jason Gunthorpe
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=20230726111433.1105665-1-schnelle@linux.ibm.com \
--to=schnelle@linux.ibm.com \
--cc=baolu.lu@linux.intel.com \
--cc=borntraeger@linux.ibm.com \
--cc=hch@infradead.org \
--cc=jean-philippe@linaro.org \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=robin.murphy@arm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=will@kernel.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).