All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, Peter Xu <peterx@redhat.com>,
	Eric Auger <eric.auger@redhat.com>
Subject: [PULL v2 07/16] vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support
Date: Fri, 5 Feb 2021 10:03:49 -0500	[thread overview]
Message-ID: <20210205150135.94643-8-mst@redhat.com> (raw)
In-Reply-To: <20210205150135.94643-1-mst@redhat.com>

From: Peter Xu <peterx@redhat.com>

Previous work on dev-iotlb message broke vhost on either SMMU or virtio-iommu
since dev-iotlb (or PCIe ATS) is not yet supported for those archs.

An initial idea is that we can let IOMMU to export this information to vhost so
that vhost would know whether the vIOMMU would support dev-iotlb, then vhost
can conditionally register to dev-iotlb or the old iotlb way.  We can work
based on some previous patch to introduce PCIIOMMUOps as Yi Liu proposed [1].

However it's not as easy as I thought since vhost_iommu_region_add() does not
have a PCIDevice context at all since it's completely a backend.  It seems
non-trivial to pass over a PCI device to the backend during init.  E.g. when
the IOMMU notifier registered hdev->vdev is still NULL.

To make the fix smaller and easier, this patch goes the other way to leverage
the flag_changed() hook of vIOMMUs so that SMMU and virtio-iommu can trap the
dev-iotlb registration and fail it.  Then vhost could try the fallback solution
as using UNMAP invalidation for it's translations.

[1] https://lore.kernel.org/qemu-devel/1599735398-6829-4-git-send-email-yi.l.liu@intel.com/

Reported-by: Eric Auger <eric.auger@redhat.com>
Fixes: b68ba1ca57677acf870d5ab10579e6105c1f5338
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20210204191228.187550-1-peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/arm/smmuv3.c          |  5 +++++
 hw/virtio/vhost.c        | 13 +++++++++++--
 hw/virtio/virtio-iommu.c |  5 +++++
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 98b99d4fe8..bd1f97000d 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1497,6 +1497,11 @@ static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
     SMMUv3State *s3 = sdev->smmu;
     SMMUState *s = &(s3->smmu_state);
 
+    if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
+        error_setg(errp, "SMMUv3 does not support dev-iotlb yet");
+        return -EINVAL;
+    }
+
     if (new & IOMMU_NOTIFIER_MAP) {
         error_setg(errp,
                    "device %02x.%02x.%x requires iommu MAP notifier which is "
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 28c7d78172..6e17d631f7 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -704,6 +704,7 @@ static void vhost_iommu_region_add(MemoryListener *listener,
     Int128 end;
     int iommu_idx;
     IOMMUMemoryRegion *iommu_mr;
+    int ret;
 
     if (!memory_region_is_iommu(section->mr)) {
         return;
@@ -726,8 +727,16 @@ static void vhost_iommu_region_add(MemoryListener *listener,
     iommu->iommu_offset = section->offset_within_address_space -
                           section->offset_within_region;
     iommu->hdev = dev;
-    memory_region_register_iommu_notifier(section->mr, &iommu->n,
-                                          &error_fatal);
+    ret = memory_region_register_iommu_notifier(section->mr, &iommu->n, NULL);
+    if (ret) {
+        /*
+         * Some vIOMMUs do not support dev-iotlb yet.  If so, try to use the
+         * UNMAP legacy message
+         */
+        iommu->n.notifier_flags = IOMMU_NOTIFIER_UNMAP;
+        memory_region_register_iommu_notifier(section->mr, &iommu->n,
+                                              &error_fatal);
+    }
     QLIST_INSERT_HEAD(&dev->iommu_list, iommu, iommu_next);
     /* TODO: can replay help performance here? */
 }
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 6b9ef7f6b2..c2883a2f6c 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -893,6 +893,11 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr,
                                             IOMMUNotifierFlag new,
                                             Error **errp)
 {
+    if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
+        error_setg(errp, "Virtio-iommu does not support dev-iotlb yet");
+        return -EINVAL;
+    }
+
     if (old == IOMMU_NOTIFIER_NONE) {
         trace_virtio_iommu_notify_flag_add(iommu_mr->parent_obj.name);
     } else if (new == IOMMU_NOTIFIER_NONE) {
-- 
MST



  parent reply	other threads:[~2021-02-05 15:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 15:03 [PULL v2 00/16] pc,virtio,pci: fixes, features,code removal Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 01/16] pci: reject too large ROMs Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 02/16] pci: add romsize property Michael S. Tsirkin
2021-02-05 15:03   ` Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 03/16] virtio: move 'use-disabled-flag' property to hw_compat_4_2 Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 04/16] virtio-mmio: fix guest kernel crash with SHM regions Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 05/16] virtio: Add corresponding memory_listener_unregister to unrealize Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 06/16] virtio-pmem: add trace events Michael S. Tsirkin
2021-02-05 15:03 ` Michael S. Tsirkin [this message]
2021-02-05 15:03 ` [PULL v2 08/16] hw/i386: Remove the deprecated pc-1.x machine types Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 09/16] hw/virtio/virtio-balloon: Remove the "class" property Michael S. Tsirkin
2021-02-05 15:03 ` [PULL v2 10/16] vhost: Check for valid vdev in vhost_backend_handle_iotlb_msg Michael S. Tsirkin
2021-02-05 15:04 ` [PULL v2 11/16] tests/acpi: allow updates for expected data files Michael S. Tsirkin
2021-02-05 15:04 ` [PULL v2 12/16] acpi: Permit OEM ID and OEM table ID fields to be changed Michael S. Tsirkin
2021-02-05 15:04 ` [PULL v2 13/16] acpi: use constants as strncpy limit Michael S. Tsirkin
2021-02-05 15:04 ` [PULL v2 14/16] tests/acpi: add OEM ID and OEM TABLE ID test Michael S. Tsirkin
2021-02-05 15:04 ` [PULL v2 15/16] tests/acpi: update expected data files Michael S. Tsirkin
2021-02-05 15:04 ` [PULL v2 16/16] tests/acpi: disallow updates for " Michael S. Tsirkin
2021-02-05 16:46 ` [PULL v2 00/16] pc,virtio,pci: fixes, features,code removal Peter Maydell

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=20210205150135.94643-8-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.