Skip to contentSkip to conversation

s390x/pci: small set of fixes

PATCH Superseded Matthew Rosato 4 participants 7 messages Nov 9, 2023 – Nov 10, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

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 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-vfio.c +5 -1
index 59a2e03873..7218583883 100644
@@ -66,7 +66,11 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
 
     assert(vpdev);
 
-    id = vpdev->vbasedev.group->container->fd;
+    if (vpdev->vbasedev.group) {
+        id = vpdev->vbasedev.group->container->fd;
+    } else {
+        return NULL;
+    }
 
     if (!s390_pci_update_dma_avail(id, &avail)) {
         return NULL;
Signature · 1 line
2.41.0
#2 lore raw

Re: [PATCH 1/2] s390x/pci: bypass vfio DMA counting when using cdev

Quoted 15 lines · Matthew Rosato

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 | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-vfio.c +0 -0
index 59a2e03873..7218583883 100644

hw/s390x/s390-pci-vfio.c S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s, · line 68

Quoted 3 lines
hw/s390x/s390-pci-vfio.c +0 -0
@@ -66,7 +66,11 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
 
      assert(vpdev);
 

Matter of taste, simpler as:

       if (!vpdev->vbasedev.group) {
           return NULL;
       }

hw/s390x/s390-pci-vfio.c S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s, · line 69

Quoted 1 line
hw/s390x/s390-pci-vfio.c +0 -1
-    id = vpdev->vbasedev.group->container->fd;

and this line isn't changed.

Quoted 8 lines
hw/s390x/s390-pci-vfio.c +5 -0
+    if (vpdev->vbasedev.group) {
+        id = vpdev->vbasedev.group->container->fd;
+    } else {
+        return NULL;
+    }
 
      if (!s390_pci_update_dma_avail(id, &avail)) {
          return NULL;
#3 lore raw

Re: [PATCH 1/2] s390x/pci: bypass vfio DMA counting when using cdev

[Sent too fast by inadvertence...]

Hi Matthew,

Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Matthew Rosato

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 | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-vfio.c +0 -0
index 59a2e03873..7218583883 100644

hw/s390x/s390-pci-vfio.c S390PCIDMACount · line 67

Quoted 2 lines
hw/s390x/s390-pci-vfio.c +0 -0
@@ -66,7 +66,11 @@ S390PCIDMACount 
 *s390_pci_start_dma_count(S390pciState *s,
       assert(vpdev);

Matter of taste, simpler as:

Quoted 16 lines

       if (!vpdev->vbasedev.group) {
           return NULL;
       }

hw/s390x/s390-pci-vfio.c S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s, · line 69

Quoted 1 line
hw/s390x/s390-pci-vfio.c +0 -1
-    id = vpdev->vbasedev.group->container->fd;

and this line isn't changed.

Quoted 7 lines
hw/s390x/s390-pci-vfio.c +5 -0
+    if (vpdev->vbasedev.group) {
+        id = vpdev->vbasedev.group->container->fd;
+    } else {
+        return NULL;
+    }
       if (!s390_pci_update_dma_avail(id, &avail)) {
           return NULL;

Regards,

Phil :)

#4 lore raw

PATCH 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 7218583883..22b39a7d18 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
#5 lore raw

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

Quoted 14 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")
---
  hw/s390x/s390-pci-vfio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/s390-pci-vfio.c +0 -0
index 7218583883..22b39a7d18 100644

hw/s390x/s390-pci-vfio.c static void s390_pci_read_base(S390PCIBusDevice *pbdev, · line 139

Quoted 5 lines
hw/s390x/s390-pci-vfio.c +1 -1
@@ -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))) {

Please drop the superfluous parantheses:

if (vfio_size > 0 && vfio_size < cap->end_dma - cap->start_dma + 1) {

Thanks,
Thomas

Quoted 3 lines
hw/s390x/s390-pci-vfio.c +0 -0
          pbdev->zpci_fn.edma = cap->start_dma + vfio_size - 1;
      }
  }
#6 lore raw
In reply to Matthew Rosato

Hello Matthew,

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

It is a bit late for the 8.2. So we have time to polish v5 of the 'vfio: Adopt iommufd' series a bit more. I should include the v6 in an early PR for a 9.0.

Quoted 4 lines

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.

Nevertheless, I hope these two fixes can reached 8.2 since they are good to have anyhow.

Thanks,

C.

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 | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)