Skip to contentSkip to conversation

Additional vIOMMU fixes related to UNMAP notifiers

PATCH In review Eric Auger 7 participants 10 messages Feb 9, 2021 – Feb 11, 2021

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

cover Additional vIOMMU fixes related to UNMAP notifiers

958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support") fixed part of the UNMAP related regressions introduced by b68ba1ca5767 ("memory: Add IOMMU_NOTIFIER_DEVIOTLB_UNMAP IOMMUTLBNotificationType").

However the case of the spapr_iommu was not addressed. It should be identical to the others. Also 958ec334bca3 introduced a regresion on the VIRTIO-IOMMU/VFIO integration.

spapr_iommu is not tested.

Best Regards

Eric

Eric Auger (2):
vfio: Do not register any IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier
spapr_iommu: Fix vhost integration regression

 hw/ppc/spapr_iommu.c | 5 +++++
 hw/vfio/common.c     | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 1/2 vfio: Do not register any IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier

In an attempt to fix smmu/virtio-iommu - vhost regression, commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support") broke virtio-iommu integration. This is due to the fact VFIO registers IOMMU_NOTIFIER_ALL notifiers, which includes IOMMU_NOTIFIER_DEVIOTLB_UNMAP and this latter now is rejected by the virtio-iommu. As a consequence, the registration fails. VHOST behaves like a device with an ATC cache. The VFIO device does not support this scheme yet.

Let's register only legacy MAP and UNMAP notifiers.

Fixes 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support")
---
 hw/vfio/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/common.c +1 -1
index 6ff1daa763..a50b10c801 100644
@@ -787,7 +787,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
         iommu_idx = memory_region_iommu_attrs_to_index(iommu_mr,
                                                        MEMTXATTRS_UNSPECIFIED);
         iommu_notifier_init(&giommu->n, vfio_iommu_map_notify,
-                            IOMMU_NOTIFIER_ALL,
+                            IOMMU_NOTIFIER_IOTLB_EVENTS,
                             section->offset_within_region,
                             int128_get64(llend),
                             iommu_idx);
Signature · 1 line
2.26.2
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] vfio: Do not register any IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier

Quoted 21 lines · Eric Auger

In an attempt to fix smmu/virtio-iommu - vhost regression, commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support") broke virtio-iommu integration. This is due to the fact VFIO registers IOMMU_NOTIFIER_ALL notifiers, which includes IOMMU_NOTIFIER_DEVIOTLB_UNMAP and this latter now is rejected by the virtio-iommu. As a consequence, the registration fails. VHOST behaves like a device with an ATC cache. The VFIO device does not support this scheme yet.

Let's register only legacy MAP and UNMAP notifiers.

Fixes 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support")
---
  hw/vfio/common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/common.c +0 -0
index 6ff1daa763..a50b10c801 100644

hw/vfio/common.c static void vfio_listener_region_add(MemoryListener *listener, · line 793

Quoted 8 lines
hw/vfio/common.c +1 -1
@@ -787,7 +787,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
          iommu_idx = memory_region_iommu_attrs_to_index(iommu_mr,
                                                         MEMTXATTRS_UNSPECIFIED);
          iommu_notifier_init(&giommu->n, vfio_iommu_map_notify,
-                            IOMMU_NOTIFIER_ALL,
+                            IOMMU_NOTIFIER_IOTLB_EVENTS,
                              section->offset_within_region,
                              int128_get64(llend),
                              iommu_idx);
Acked-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] vfio: Do not register any IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier

In reply to Eric Auger
Quoted 21 lines · On Tue, 9 Feb 2021 22:32:32 +0100 Eric Auger <[email protected]> wrote:

In an attempt to fix smmu/virtio-iommu - vhost regression, commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support") broke virtio-iommu integration. This is due to the fact VFIO registers IOMMU_NOTIFIER_ALL notifiers, which includes IOMMU_NOTIFIER_DEVIOTLB_UNMAP and this latter now is rejected by the virtio-iommu. As a consequence, the registration fails. VHOST behaves like a device with an ATC cache. The VFIO device does not support this scheme yet.

Let's register only legacy MAP and UNMAP notifiers.

Fixes 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support")
---
 hw/vfio/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/common.c +0 -0
index 6ff1daa763..a50b10c801 100644

hw/vfio/common.c static void vfio_listener_region_add(MemoryListener *listener, · line 793

Quoted 8 lines
hw/vfio/common.c +1 -1
@@ -787,7 +787,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
         iommu_idx = memory_region_iommu_attrs_to_index(iommu_mr,
                                                        MEMTXATTRS_UNSPECIFIED);
         iommu_notifier_init(&giommu->n, vfio_iommu_map_notify,
-                            IOMMU_NOTIFIER_ALL,
+                            IOMMU_NOTIFIER_IOTLB_EVENTS,
                             section->offset_within_region,
                             int128_get64(llend),
                             iommu_idx);
author
#4 lore raw

PATCH 2/2 spapr_iommu: Fix vhost integration regression

In reply to Eric Auger

Previous work on dev-iotlb message broke spapr_iommu/vhost integration as it did for SMMU and virtio-iommu. The spapr_iommu currently only sends IOMMU_NOTIFIER_UNMAP notifications. Since commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support"), VHOST first tries to register IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier and if it fails, falls back to legacy IOMMU_NOTIFIER_UNMAP. So spapr_iommu must fail on the IOMMU_NOTIFIER_DEVIOTLB_UNMAP registration.

Fixes b68ba1ca57677acf870d5ab10579e6105c1f5338
---
 hw/ppc/spapr_iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ppc/spapr_iommu.c +5 -0
index 30352df00e..24537ffcbd 100644
@@ -212,6 +212,11 @@ static int spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu,
 {
     struct SpaprTceTable *tbl = container_of(iommu, SpaprTceTable, iommu);
 
+    if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
+        error_setg(errp, "spart_tce does not support dev-iotlb yet");
+        return -EINVAL;
+    }
+
     if (old == IOMMU_NOTIFIER_NONE && new != IOMMU_NOTIFIER_NONE) {
         spapr_tce_set_need_vfio(tbl, true);
     } else if (old != IOMMU_NOTIFIER_NONE && new == IOMMU_NOTIFIER_NONE) {
Signature · 1 line
2.26.2
Acked-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] spapr_iommu: Fix vhost integration regression

Quoted 9 lines · Eric Auger

Previous work on dev-iotlb message broke spapr_iommu/vhost integration as it did for SMMU and virtio-iommu. The spapr_iommu currently only sends IOMMU_NOTIFIER_UNMAP notifications. Since commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support"), VHOST first tries to register IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier and if it fails, falls back to legacy IOMMU_NOTIFIER_UNMAP. So spapr_iommu must fail on the IOMMU_NOTIFIER_DEVIOTLB_UNMAP registration.

Quoted 3 lines
Fixes b68ba1ca57677acf870d5ab10579e6105c1f5338
Quoted 20 lines
---
 hw/ppc/spapr_iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ppc/spapr_iommu.c +5 -0
index 30352df00e..24537ffcbd 100644
@@ -212,6 +212,11 @@ static int spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu,
 {
     struct SpaprTceTable *tbl = container_of(iommu, SpaprTceTable, iommu);
 
+    if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
+        error_setg(errp, "spart_tce does not support dev-iotlb yet");
+        return -EINVAL;
+    }
+
     if (old == IOMMU_NOTIFIER_NONE && new != IOMMU_NOTIFIER_NONE) {
         spapr_tce_set_need_vfio(tbl, true);
     } else if (old != IOMMU_NOTIFIER_NONE && new == IOMMU_NOTIFIER_NONE) {
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] spapr_iommu: Fix vhost integration regression

In reply to Eric Auger
Quoted 9 lines · Eric Auger

Previous work on dev-iotlb message broke spapr_iommu/vhost integration as it did for SMMU and virtio-iommu. The spapr_iommu currently only sends IOMMU_NOTIFIER_UNMAP notifications. Since commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support"), VHOST first tries to register IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier and if it fails, falls back to legacy IOMMU_NOTIFIER_UNMAP. So spapr_iommu must fail on the IOMMU_NOTIFIER_DEVIOTLB_UNMAP registration.

Quoted 3 lines
Fixes b68ba1ca57677acf870d5ab10579e6105c1f5338
Quoted 22 lines
---
 hw/ppc/spapr_iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ppc/spapr_iommu.c +5 -0
index 30352df00e..24537ffcbd 100644
@@ -212,6 +212,11 @@ static int spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu,
 {
     struct SpaprTceTable *tbl = container_of(iommu, SpaprTceTable, iommu);
 
+    if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
+        error_setg(errp, "spart_tce does not support dev-iotlb yet");
+        return -EINVAL;
+    }
+
     if (old == IOMMU_NOTIFIER_NONE && new != IOMMU_NOTIFIER_NONE) {
         spapr_tce_set_need_vfio(tbl, true);
     } else if (old != IOMMU_NOTIFIER_NONE && new == IOMMU_NOTIFIER_NONE) {
Signature · 1 line
2.26.2
Acked-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] spapr_iommu: Fix vhost integration regression

In reply to Eric Auger
Quoted 9 lines · Eric Auger

Previous work on dev-iotlb message broke spapr_iommu/vhost integration as it did for SMMU and virtio-iommu. The spapr_iommu currently only sends IOMMU_NOTIFIER_UNMAP notifications. Since commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support"), VHOST first tries to register IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier and if it fails, falls back to legacy IOMMU_NOTIFIER_UNMAP. So spapr_iommu must fail on the IOMMU_NOTIFIER_DEVIOTLB_UNMAP registration.

Quoted 4 lines
Fixes b68ba1ca57677acf870d5ab10579e6105c1f5338

---

Quoted 19 lines
  hw/ppc/spapr_iommu.c | 5 +++++
  1 file changed, 5 insertions(+)
hw/ppc/spapr_iommu.c +5 -0
index 30352df00e..24537ffcbd 100644
@@ -212,6 +212,11 @@ static int spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu,
  {
      struct SpaprTceTable *tbl = container_of(iommu, SpaprTceTable, iommu);
 
+    if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
+        error_setg(errp, "spart_tce does not support dev-iotlb yet");
+        return -EINVAL;
+    }
+
      if (old == IOMMU_NOTIFIER_NONE && new != IOMMU_NOTIFIER_NONE) {
          spapr_tce_set_need_vfio(tbl, true);
      } else if (old != IOMMU_NOTIFIER_NONE && new == IOMMU_NOTIFIER_NONE) {
Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] spapr_iommu: Fix vhost integration regression

In reply to Eric Auger
Quoted 9 lines · On Tue, 9 Feb 2021 22:32:33 +0100 Eric Auger <[email protected]> wrote:

Previous work on dev-iotlb message broke spapr_iommu/vhost integration as it did for SMMU and virtio-iommu. The spapr_iommu currently only sends IOMMU_NOTIFIER_UNMAP notifications. Since commit 958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support"), VHOST first tries to register IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier and if it fails, falls back to legacy IOMMU_NOTIFIER_UNMAP. So spapr_iommu must fail on the IOMMU_NOTIFIER_DEVIOTLB_UNMAP registration.

Quoted 4 lines
Fixes b68ba1ca57677acf870d5ab10579e6105c1f5338

---

Quoted 19 lines
 hw/ppc/spapr_iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ppc/spapr_iommu.c +5 -0
index 30352df00e..24537ffcbd 100644
@@ -212,6 +212,11 @@ static int spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu,
 {
     struct SpaprTceTable *tbl = container_of(iommu, SpaprTceTable, iommu);
 
+    if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
+        error_setg(errp, "spart_tce does not support dev-iotlb yet");
+        return -EINVAL;
+    }
+
     if (old == IOMMU_NOTIFIER_NONE && new != IOMMU_NOTIFIER_NONE) {
         spapr_tce_set_need_vfio(tbl, true);
     } else if (old != IOMMU_NOTIFIER_NONE && new == IOMMU_NOTIFIER_NONE) {
Reviewed-by on the v1 series
#9 lore raw
In reply to Eric Auger
Quoted 10 lines · Eric Auger

958ec334bca3 ("vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support") fixed part of the UNMAP related regressions introduced by b68ba1ca5767 ("memory: Add IOMMU_NOTIFIER_DEVIOTLB_UNMAP IOMMUTLBNotificationType").

However the case of the spapr_iommu was not addressed. It should be identical to the others. Also 958ec334bca3 introduced a regresion on the VIRTIO-IOMMU/VFIO integration.

spapr_iommu is not tested.

Thanks!

Signature · 1 line
Peter Xu