Skip to contentSkip to conversation

Two minor fixes on virtio-iommu and smmu

PATCH In review Zhenzhong Duan 2 participants 5 messages Jan 25, 2024 – Jan 29, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover Two minor fixes on virtio-iommu and smmu

Hi,

PATCH1 fixes a potential issue with vfio devices when reboot to a different OS which set bus number differently from previous OS. I didn't reproduce the issue in reality, but it's still possible in theory. VTD doesn't have same issue as it use some verify logic to ensure right iommu MR is picked.

PATCH2 does same thing for smmu.

v2:
- Remove redundant memset in realize (Cédric)
- Add a patch for smmu (Eric)
- Drop the patch to support PCI device alias for now, as it's tricky in using two different IOMMU MRs and Eric already sent a smarter fix.

Thanks
Zhenzhong

Zhenzhong Duan (2):
virtio_iommu: Clear IOMMUPciBus pointer cache when system reset
smmu: Clear SMMUPciBus pointer cache when system reset

 hw/arm/smmu-common.c     | 2 ++
 hw/virtio/virtio-iommu.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 virtio_iommu: Clear IOMMUPciBus pointer cache when system reset

s->iommu_pcibus_by_bus_num is a IOMMUPciBus pointer cache indexed by bus number, bus number may not always be a fixed value, i.e., guest reboot to different kernel which set bus number with different algorithm.

This could lead to endpoint binding to wrong iommu MR in virtio_iommu_get_endpoint(), then vfio device setup wrong mapping from other device.

Remove the memset in virtio_iommu_device_realize() to avoid redundancy with memset in system reset.

---
 hw/virtio/virtio-iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/virtio-iommu.c +2 -2
index 8a4bd933c6..86623d55a5 100644
@@ -1264,6 +1264,8 @@ static void virtio_iommu_system_reset(void *opaque)
 
     trace_virtio_iommu_system_reset();
 
+    memset(s->iommu_pcibus_by_bus_num, 0, sizeof(s->iommu_pcibus_by_bus_num));
+
     /*
      * config.bypass is sticky across device reset, but should be restored on
      * system reset
@@ -1302,8 +1304,6 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
 
     virtio_init(vdev, VIRTIO_ID_IOMMU, sizeof(struct virtio_iommu_config));
 
-    memset(s->iommu_pcibus_by_bus_num, 0, sizeof(s->iommu_pcibus_by_bus_num));
-
     s->req_vq = virtio_add_queue(vdev, VIOMMU_DEFAULT_QUEUE_SIZE,
                              virtio_iommu_handle_command);
     s->event_vq = virtio_add_queue(vdev, VIOMMU_DEFAULT_QUEUE_SIZE, NULL);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/2 smmu: Clear SMMUPciBus pointer cache when system reset

In reply to Zhenzhong Duan

s->smmu_pcibus_by_bus_num is a SMMUPciBus pointer cache indexed by bus number, bus number may not always be a fixed value, i.e., guest reboot to different kernel which set bus number with different algorithm.

This could lead to smmu_iommu_mr() providing the wrong iommu MR.

---
 hw/arm/smmu-common.c | 2 ++
 1 file changed, 2 insertions(+)
hw/arm/smmu-common.c +2 -0
index 9a8ac45431..f58261bb81 100644
@@ -675,6 +675,8 @@ static void smmu_base_reset_hold(Object *obj)
 {
     SMMUState *s = ARM_SMMU(obj);
 
+    memset(s->smmu_pcibus_by_bus_num, 0, sizeof(s->smmu_pcibus_by_bus_num));
+
     g_hash_table_remove_all(s->configs);
     g_hash_table_remove_all(s->iotlb);
 }
Signature · 1 line
2.34.1
Reviewed-by Tested-by on the v2 series
#3 lore raw
In reply to Zhenzhong Duan

Hi Zhenzhong,

Quoted 8 lines · Zhenzhong Duan

Hi,

PATCH1 fixes a potential issue with vfio devices when reboot to a different OS which set bus number differently from previous OS. I didn't reproduce the issue in reality, but it's still possible in theory. VTD doesn't have same issue as it use some verify logic to ensure right iommu MR is picked.

Quoted 7 lines

PATCH2 does same thing for smmu.

v2:
- Remove redundant memset in realize (Cédric)
- Add a patch for smmu (Eric)
- Drop the patch to support PCI device alias for now, as it's tricky in using two different IOMMU MRs and Eric already sent a smarter fix.

For the series:

Thanks

Eric

Quoted 13 lines

Thanks
Zhenzhong

Zhenzhong Duan (2):
virtio_iommu: Clear IOMMUPciBus pointer cache when system reset
smmu: Clear SMMUPciBus pointer cache when system reset

 hw/arm/smmu-common.c     | 2 ++
 hw/virtio/virtio-iommu.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
#4 lore raw
Quoted 25 lines

-----Original Message-----
From: Eric Auger <[email protected]>
Subject: Re: [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu

Hi Zhenzhong,

Quoted 8 lines · Zhenzhong Duan

Hi,

PATCH1 fixes a potential issue with vfio devices when reboot to a different OS which set bus number differently from previous OS. I didn't reproduce the issue in reality, but it's still possible in theory. VTD doesn't have same issue as it use some verify logic to ensure right iommu MR is picked.

Quoted 7 lines

PATCH2 does same thing for smmu.

v2:
- Remove redundant memset in realize (Cédric)
- Add a patch for smmu (Eric)
- Drop the patch to support PCI device alias for now, as it's tricky in using two different IOMMU MRs and Eric already sent a smarter fix.

Quoted 4 lines

For the series:

Thanks Eric.

BRs.
Zhenzhong