From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PULL 09/10] vfio: Allow hotplug of containers onto existing guest IOMMU mappings
Date: Mon, 05 Oct 2015 14:37:50 -0600 [thread overview]
Message-ID: <20151005203748.310.35820.stgit@gimli.home> (raw)
In-Reply-To: <20151005203357.310.44414.stgit@gimli.home>
From: David Gibson <david@gibson.dropbear.id.au>
At present the memory listener used by vfio to keep host IOMMU mappings
in sync with the guest memory image assumes that if a guest IOMMU
appears, then it has no existing mappings.
This may not be true if a VFIO device is hotplugged onto a guest bus
which didn't previously include a VFIO device, and which has existing
guest IOMMU mappings.
Therefore, use the memory_region_register_iommu_notifier_replay()
function in order to fix this case, replaying existing guest IOMMU
mappings, bringing the host IOMMU into sync with the guest IOMMU.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
hw/vfio/common.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index f666de2..6797208 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -312,6 +312,11 @@ out:
rcu_read_unlock();
}
+static hwaddr vfio_container_granularity(VFIOContainer *container)
+{
+ return (hwaddr)1 << ctz64(container->iova_pgsizes);
+}
+
static void vfio_listener_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@@ -369,26 +374,16 @@ static void vfio_listener_region_add(MemoryListener *listener,
* would be the right place to wire that up (tell the KVM
* device emulation the VFIO iommu handles to use).
*/
- /*
- * This assumes that the guest IOMMU is empty of
- * mappings at this point.
- *
- * One way of doing this is:
- * 1. Avoid sharing IOMMUs between emulated devices or different
- * IOMMU groups.
- * 2. Implement VFIO_IOMMU_ENABLE in the host kernel to fail if
- * there are some mappings in IOMMU.
- *
- * VFIO on SPAPR does that. Other IOMMU models may do that different,
- * they must make sure there are no existing mappings or
- * loop through existing mappings to map them into VFIO.
- */
giommu = g_malloc0(sizeof(*giommu));
giommu->iommu = section->mr;
giommu->container = container;
giommu->n.notify = vfio_iommu_map_notify;
QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next);
+
memory_region_register_iommu_notifier(giommu->iommu, &giommu->n);
+ memory_region_iommu_replay(giommu->iommu, &giommu->n,
+ vfio_container_granularity(container),
+ false);
return;
}
next prev parent reply other threads:[~2015-10-05 20:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-05 20:36 [Qemu-devel] [PULL 00/10] VFIO updates for 2015-10-05 Alex Williamson
2015-10-05 20:36 ` [Qemu-devel] [PULL 01/10] hw/vfio/platform: irqfd setup sequence update Alex Williamson
2015-10-05 20:36 ` [Qemu-devel] [PULL 02/10] hw/vfio/platform: change interrupt/unmask fields into pointer Alex Williamson
2015-10-05 20:36 ` [Qemu-devel] [PULL 03/10] hw/vfio/platform: do not set resamplefd for edge-sensitive IRQS Alex Williamson
2015-10-05 20:37 ` [Qemu-devel] [PULL 04/10] vfio: Remove unneeded union from VFIOContainer Alex Williamson
2015-10-05 20:37 ` [Qemu-devel] [PULL 05/10] vfio: Generalize vfio_listener_region_add failure path Alex Williamson
2015-10-05 20:37 ` [Qemu-devel] [PULL 06/10] vfio: Check guest IOVA ranges against host IOMMU capabilities Alex Williamson
2015-10-05 20:37 ` [Qemu-devel] [PULL 07/10] vfio: Record host IOMMU's available IO page sizes Alex Williamson
2015-10-05 20:37 ` [Qemu-devel] [PULL 08/10] memory: Allow replay of IOMMU mapping notifications Alex Williamson
2015-10-05 20:37 ` Alex Williamson [this message]
2015-10-05 20:37 ` [Qemu-devel] [PULL 10/10] vfio: Expose a VFIO PCI device's group for EEH Alex Williamson
2015-10-06 14:50 ` [Qemu-devel] [PULL 00/10] VFIO updates for 2015-10-05 Peter Maydell
2015-10-06 15:35 ` Alex Williamson
2015-10-06 23:31 ` David Gibson
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=20151005203748.310.35820.stgit@gimli.home \
--to=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.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).