Skip to contentSkip to conversation

s390x/pci: small set of fixes

PATCH In review Matthew Rosato 4 participants 7 messages Nov 10, 2023 – Nov 13, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover s390x/pci: small set of fixes

The following set of changes are associated with issues exposed by testing of the 'vfio: Adopt iommufd' series.

The first patch fixes an existing assumption that a vfio device will always have a group fd (which is no longer true if cdev is used, which can only happen once the iommufd backend is used). This patch really only needs to go into 8.2 if the 'vfio: Adopt iommufd' series does (but would be fine to go into 8.2 without it too).

The second patch fixes an issue where we do not detect that a vfio DMA limit was never read from vfio. This is actually an existing bug as it's possible for an older host kernel to be missing this support today; so ideally this one should be targeted for 8.2 regardless.

Changes for v2:
- minor style changes (Phil, Thomas)

Matthew Rosato (2):
s390x/pci: bypass vfio DMA counting when using cdev s390x/pci: only limit DMA aperture if vfio DMA limit reported

 hw/s390x/s390-pci-vfio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/2 s390x/pci: bypass vfio DMA counting when using cdev

The current code assumes that there is always a vfio group, but that's no longer guaranteed with the iommufd backend when using cdev. In this case, we don't need to track the vfio dma limit anyway.

---
 hw/s390x/s390-pci-vfio.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/s390x/s390-pci-vfio.c +4 -0
index 59a2e03873..e28573b593 100644
@@ -66,6 +66,10 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
 
     assert(vpdev);
 
+    if (!vpdev->vbasedev.group) {
+        return NULL;
+    }
+
     id = vpdev->vbasedev.group->container->fd;
 
     if (!s390_pci_update_dma_avail(id, &avail)) {
Signature · 1 line
2.41.0
#2 lore raw

PATCH v2 2/2 s390x/pci: only limit DMA aperture if vfio DMA limit reported

In reply to Matthew Rosato

If the host kernel lacks vfio DMA limit reporting, do not attempt to shrink the guest DMA aperture.

Fixes df202e3ff3 ("s390x/pci: shrink DMA aperture to be bound by vfio DMA limit")
---
 hw/s390x/s390-pci-vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/s390-pci-vfio.c +1 -1
index e28573b593..7dbbc76823 100644
@@ -136,7 +136,7 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
      * to the guest based upon the vfio DMA limit.
      */
     vfio_size = pbdev->iommu->max_dma_limit << TARGET_PAGE_BITS;
-    if (vfio_size < (cap->end_dma - cap->start_dma + 1)) {
+    if (vfio_size > 0 && vfio_size < cap->end_dma - cap->start_dma + 1) {
         pbdev->zpci_fn.edma = cap->start_dma + vfio_size - 1;
     }
 }
Signature · 1 line
2.41.0
#3 lore raw

Re: [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported

Quoted 5 lines · Matthew Rosato

If the host kernel lacks vfio DMA limit reporting, do not attempt to shrink the guest DMA aperture.

Fixes df202e3ff3 ("s390x/pci: shrink DMA aperture to be bound by vfio DMA limit")

Is this stable-8.1 material?

Thanks,

/mjt

Quoted 17 lines
---
  hw/s390x/s390-pci-vfio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/s390-pci-vfio.c +1 -1
index e28573b593..7dbbc76823 100644
@@ -136,7 +136,7 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
       * to the guest based upon the vfio DMA limit.
       */
      vfio_size = pbdev->iommu->max_dma_limit << TARGET_PAGE_BITS;
-    if (vfio_size < (cap->end_dma - cap->start_dma + 1)) {
+    if (vfio_size > 0 && vfio_size < cap->end_dma - cap->start_dma + 1) {
          pbdev->zpci_fn.edma = cap->start_dma + vfio_size - 1;
      }
  }
#4 lore raw

Re: [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported

Quoted 4 lines · Michael Tokarev
Quoted 3 lines · Matthew Rosato

If the host kernel lacks vfio DMA limit reporting, do not attempt to shrink the guest DMA aperture.

Quoted 9 lines
Quoted 2 lines
Fixes df202e3ff3 ("s390x/pci: shrink DMA aperture to be bound by vfio DMA limit")

Is this stable-8.1 material?

Thanks,

/mjt

Yes, I believe it is (sorry, should have added CC stable)

If you have a host kernel that doesn't report the vfio DMA limit the resulting PCI device will be rendered unusable in the s390x guest due this bug.

Thanks,
Matt

#5 lore raw
In reply to Matthew Rosato
Quoted 17 lines · Matthew Rosato

The following set of changes are associated with issues exposed by testing of the 'vfio: Adopt iommufd' series.

The first patch fixes an existing assumption that a vfio device will always have a group fd (which is no longer true if cdev is used, which can only happen once the iommufd backend is used). This patch really only needs to go into 8.2 if the 'vfio: Adopt iommufd' series does (but would be fine to go into 8.2 without it too).

The second patch fixes an issue where we do not detect that a vfio DMA limit was never read from vfio. This is actually an existing bug as it's possible for an older host kernel to be missing this support today; so ideally this one should be targeted for 8.2 regardless.

Changes for v2:
- minor style changes (Phil, Thomas)

Quoted 6 lines

Matthew Rosato (2):
s390x/pci: bypass vfio DMA counting when using cdev s390x/pci: only limit DMA aperture if vfio DMA limit reported

  hw/s390x/s390-pci-vfio.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

Thank you, queued them now!

Thomas

Reviewed-by on the v2 series
#6 lore raw
In reply to Matthew Rosato
Quoted 3 lines · Matthew Rosato

The following set of changes are associated with issues exposed by testing
of the 'vfio: Adopt iommufd' series.

...snip...

Quoted 7 lines

Matthew Rosato (2):
  s390x/pci: bypass vfio DMA counting when using cdev s390x/pci: only limit DMA aperture if vfio DMA limit reported

 hw/s390x/s390-pci-vfio.c | 6 +++++-

 1 file changed, 5 insertions(+), 1 deletion(-)

Apologies for missing v1 while I was out, but FWIW, for the series: