qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu
@ 2024-01-25  7:37 Zhenzhong Duan
  2024-01-25  7:37 ` [PATCH v2 1/2] virtio_iommu: Clear IOMMUPciBus pointer cache when system reset Zhenzhong Duan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Zhenzhong Duan @ 2024-01-25  7:37 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: eric.auger, jean-philippe, alex.williamson, clg, peterx, jasowang,
	mst, yi.l.liu, chao.p.peng, 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.

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(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] virtio_iommu: Clear IOMMUPciBus pointer cache when system reset
  2024-01-25  7:37 [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Zhenzhong Duan
@ 2024-01-25  7:37 ` Zhenzhong Duan
  2024-01-25  7:37 ` [PATCH v2 2/2] smmu: Clear SMMUPciBus " Zhenzhong Duan
  2024-01-29  9:27 ` [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Eric Auger
  2 siblings, 0 replies; 5+ messages in thread
From: Zhenzhong Duan @ 2024-01-25  7:37 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: eric.auger, jean-philippe, alex.williamson, clg, peterx, jasowang,
	mst, yi.l.liu, chao.p.peng, Zhenzhong Duan

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.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 hw/virtio/virtio-iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 8a4bd933c6..86623d55a5 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] smmu: Clear SMMUPciBus pointer cache when system reset
  2024-01-25  7:37 [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Zhenzhong Duan
  2024-01-25  7:37 ` [PATCH v2 1/2] virtio_iommu: Clear IOMMUPciBus pointer cache when system reset Zhenzhong Duan
@ 2024-01-25  7:37 ` Zhenzhong Duan
  2024-01-29  9:27 ` [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Eric Auger
  2 siblings, 0 replies; 5+ messages in thread
From: Zhenzhong Duan @ 2024-01-25  7:37 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: eric.auger, jean-philippe, alex.williamson, clg, peterx, jasowang,
	mst, yi.l.liu, chao.p.peng, Zhenzhong Duan, Peter Maydell

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.

Suggested-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 hw/arm/smmu-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
index 9a8ac45431..f58261bb81 100644
--- a/hw/arm/smmu-common.c
+++ b/hw/arm/smmu-common.c
@@ -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);
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu
  2024-01-25  7:37 [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Zhenzhong Duan
  2024-01-25  7:37 ` [PATCH v2 1/2] virtio_iommu: Clear IOMMUPciBus pointer cache when system reset Zhenzhong Duan
  2024-01-25  7:37 ` [PATCH v2 2/2] smmu: Clear SMMUPciBus " Zhenzhong Duan
@ 2024-01-29  9:27 ` Eric Auger
  2024-01-29  9:41   ` Duan, Zhenzhong
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Auger @ 2024-01-29  9:27 UTC (permalink / raw)
  To: Zhenzhong Duan, qemu-devel, qemu-arm
  Cc: jean-philippe, alex.williamson, clg, peterx, jasowang, mst,
	yi.l.liu, chao.p.peng

Hi Zhenzhong,

On 1/25/24 08:37, Zhenzhong Duan wrote:
> 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.

For the series:

Reviewed-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>

Thanks

Eric

>
>
> 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(-)
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu
  2024-01-29  9:27 ` [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Eric Auger
@ 2024-01-29  9:41   ` Duan, Zhenzhong
  0 siblings, 0 replies; 5+ messages in thread
From: Duan, Zhenzhong @ 2024-01-29  9:41 UTC (permalink / raw)
  To: eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org
  Cc: jean-philippe@linaro.org, alex.williamson@redhat.com,
	clg@redhat.com, peterx@redhat.com, jasowang@redhat.com,
	mst@redhat.com, Liu, Yi L, Peng, Chao P



>-----Original Message-----
>From: Eric Auger <eric.auger@redhat.com>
>Subject: Re: [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu
>
>Hi Zhenzhong,
>
>On 1/25/24 08:37, Zhenzhong Duan wrote:
>> 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.
>
>For the series:
>
>Reviewed-by: Eric Auger <eric.auger@redhat.com>
>Tested-by: Eric Auger <eric.auger@redhat.com>

Thanks Eric.

BRs.
Zhenzhong

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-29  9:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-25  7:37 [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Zhenzhong Duan
2024-01-25  7:37 ` [PATCH v2 1/2] virtio_iommu: Clear IOMMUPciBus pointer cache when system reset Zhenzhong Duan
2024-01-25  7:37 ` [PATCH v2 2/2] smmu: Clear SMMUPciBus " Zhenzhong Duan
2024-01-29  9:27 ` [PATCH v2 0/2] Two minor fixes on virtio-iommu and smmu Eric Auger
2024-01-29  9:41   ` Duan, Zhenzhong

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).