Skip to contentSkip to conversation

s390x/pci: some small fixes

PATCH Superseded Matthew Rosato 2 participants 7 messages Dec 3, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover s390x/pci: some small fixes

A collection of small fixes for s390x PCI (not urgent). The first 3 are fixes related to always using the host-provided CLP value when provided vs a hard-coded value. The last patch adds logic for QEMU to report a proper DTSM clp response rather than just 0s (guest linux doesn't look at this field today).

Changes for v2:
- Add review tags (thanks!)
- Fix patch 4 (copy into guest payload)
- Small change to commit message for patches 1 & 4 (Pierre)

Matthew Rosato (4):
s390x/pci: use a reserved ID for the default PCI group s390x/pci: don't use hard-coded dma range in reg_ioat s390x/pci: use the passthrough measurement update interval s390x/pci: add supported DT information to clp response

 hw/s390x/s390-pci-bus.c         |  1 +
 hw/s390x/s390-pci-inst.c        | 15 +++++++++------
 hw/s390x/s390-pci-vfio.c        |  1 +
 include/hw/s390x/s390-pci-bus.h |  3 ++-
 include/hw/s390x/s390-pci-clp.h |  3 ++-
 5 files changed, 15 insertions(+), 8 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 1/4 s390x/pci: use a reserved ID for the default PCI group

The current default PCI group being used can technically collide with a real group ID passed from a hostdev. Let's instead use a group ID that comes from a special pool (0xF0-0xFF) that is architected to be reserved for simulated devices.

Fixes 28dc86a072 ("s390x/pci: use a PCI Group structure")
---
 include/hw/s390x/s390-pci-bus.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/s390x/s390-pci-bus.h +1 -1
index aa891c178d..2727e7bdef 100644
@@ -313,7 +313,7 @@ typedef struct ZpciFmb {
 } ZpciFmb;
 QEMU_BUILD_BUG_MSG(offsetof(ZpciFmb, fmt0) != 48, "padding in ZpciFmb");
 
-#define ZPCI_DEFAULT_FN_GRP 0x20
+#define ZPCI_DEFAULT_FN_GRP 0xFF
 typedef struct S390PCIGroup {
     ClpRspQueryPciGrp zpci_group;
     int id;
Signature · 1 line
2.27.0
#2 lore raw

PATCH v2 2/4 s390x/pci: don't use hard-coded dma range in reg_ioat

In reply to Matthew Rosato

Instead use the values from clp info, they will either be the hard-coded values or what came from the host driver via vfio.

Fixes 9670ee752727 ("s390x/pci: use a PCI Function structure")
---
 hw/s390x/s390-pci-inst.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/s390x/s390-pci-inst.c +5 -4
index 1c8ad91175..11b7f6bfa1 100644
@@ -916,9 +916,10 @@ int pci_dereg_irqs(S390PCIBusDevice *pbdev)
     return 0;
 }
 
-static int reg_ioat(CPUS390XState *env, S390PCIIOMMU *iommu, ZpciFib fib,
+static int reg_ioat(CPUS390XState *env, S390PCIBusDevice *pbdev, ZpciFib fib,
                     uintptr_t ra)
 {
+    S390PCIIOMMU *iommu = pbdev->iommu;
     uint64_t pba = ldq_p(&fib.pba);
     uint64_t pal = ldq_p(&fib.pal);
     uint64_t g_iota = ldq_p(&fib.iota);
@@ -927,7 +928,7 @@ static int reg_ioat(CPUS390XState *env, S390PCIIOMMU *iommu, ZpciFib fib,
 
     pba &= ~0xfff;
     pal |= 0xfff;
-    if (pba > pal || pba < ZPCI_SDMA_ADDR || pal > ZPCI_EDMA_ADDR) {
+    if (pba > pal || pba < pbdev->zpci_fn.sdma || pal > pbdev->zpci_fn.edma) {
         s390_program_interrupt(env, PGM_OPERAND, ra);
         return -EINVAL;
     }
@@ -1125,7 +1126,7 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar,
         } else if (pbdev->iommu->enabled) {
             cc = ZPCI_PCI_LS_ERR;
             s390_set_status_code(env, r1, ZPCI_MOD_ST_SEQUENCE);
-        } else if (reg_ioat(env, pbdev->iommu, fib, ra)) {
+        } else if (reg_ioat(env, pbdev, fib, ra)) {
             cc = ZPCI_PCI_LS_ERR;
             s390_set_status_code(env, r1, ZPCI_MOD_ST_INSUF_RES);
         }
@@ -1150,7 +1151,7 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar,
             s390_set_status_code(env, r1, ZPCI_MOD_ST_SEQUENCE);
         } else {
             pci_dereg_ioat(pbdev->iommu);
-            if (reg_ioat(env, pbdev->iommu, fib, ra)) {
+            if (reg_ioat(env, pbdev, fib, ra)) {
                 cc = ZPCI_PCI_LS_ERR;
                 s390_set_status_code(env, r1, ZPCI_MOD_ST_INSUF_RES);
             }
Signature · 1 line
2.27.0
#3 lore raw

PATCH v2 3/4 s390x/pci: use the passthrough measurement update interval

In reply to Matthew Rosato

We may have gotten a measurement update interval from the underlying host via vfio -- Use it to set the interval via which we update the function measurement block.

Fixes 28dc86a072 ("s390x/pci: use a PCI Group structure")
---
 hw/s390x/s390-pci-inst.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/s390x/s390-pci-inst.c +3 -2
index 11b7f6bfa1..07bab85ce5 100644
@@ -1046,7 +1046,7 @@ static void fmb_update(void *opaque)
                       sizeof(pbdev->fmb.last_update))) {
         return;
     }
-    timer_mod(pbdev->fmb_timer, t + DEFAULT_MUI);
+    timer_mod(pbdev->fmb_timer, t + pbdev->pci_group->zpci_group.mui);
 }
 
 int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar,
@@ -1204,7 +1204,8 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar,
         }
         pbdev->fmb_addr = fmb_addr;
         timer_mod(pbdev->fmb_timer,
-                  qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + DEFAULT_MUI);
+                  qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+                                    pbdev->pci_group->zpci_group.mui);
         break;
     }
     default:
Signature · 1 line
2.27.0
#4 lore raw

PATCH v2 4/4 s390x/pci: add supported DT information to clp response

In reply to Matthew Rosato

The DTSM is a mask that specifies which I/O Address Translation designation types are supported. Today QEMU only supports DT=1.

---
 hw/s390x/s390-pci-bus.c         | 1 +
 hw/s390x/s390-pci-inst.c        | 1 +
 hw/s390x/s390-pci-vfio.c        | 1 +
 include/hw/s390x/s390-pci-bus.h | 1 +
 include/hw/s390x/s390-pci-clp.h | 3 ++-
 5 files changed, 6 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-bus.c +1 -0
index 1b51a72838..01b58ebc70 100644
@@ -782,6 +782,7 @@ static void s390_pci_init_default_group(void)
     resgrp->i = 128;
     resgrp->maxstbl = 128;
     resgrp->version = 0;
+    resgrp->dtsm = ZPCI_DTSM;
 }
 
 static void set_pbdev_info(S390PCIBusDevice *pbdev)
hw/s390x/s390-pci-inst.c +1 -0
index 07bab85ce5..f3feba5d74 100644
@@ -329,6 +329,7 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_t ra)
         stw_p(&resgrp->i, group->zpci_group.i);
         stw_p(&resgrp->maxstbl, group->zpci_group.maxstbl);
         resgrp->version = group->zpci_group.version;
+        resgrp->version = group->zpci_group.dtsm;
         stw_p(&resgrp->hdr.rsp, CLP_RC_OK);
         break;
     }
hw/s390x/s390-pci-vfio.c +1 -0
index 2a153fa8c9..6f80a47e29 100644
@@ -160,6 +160,7 @@ static void s390_pci_read_group(S390PCIBusDevice *pbdev,
         resgrp->i = cap->noi;
         resgrp->maxstbl = cap->maxstbl;
         resgrp->version = cap->version;
+        resgrp->dtsm = ZPCI_DTSM;
     }
 }
 
include/hw/s390x/s390-pci-bus.h +1 -0
index 2727e7bdef..da3cde2bb4 100644
@@ -37,6 +37,7 @@
 #define ZPCI_MAX_UID 0xffff
 #define UID_UNDEFINED 0
 #define UID_CHECKING_ENABLED 0x01
+#define ZPCI_DTSM 0x40
 
 OBJECT_DECLARE_SIMPLE_TYPE(S390pciState, S390_PCI_HOST_BRIDGE)
 OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBus, S390_PCI_BUS)
include/hw/s390x/s390-pci-clp.h +2 -1
index 96b8e3f133..cc8c8662b8 100644
@@ -163,7 +163,8 @@ typedef struct ClpRspQueryPciGrp {
     uint8_t fr;
     uint16_t maxstbl;
     uint16_t mui;
-    uint64_t reserved3;
+    uint8_t dtsm;
+    uint8_t reserved3[7];
     uint64_t dasm; /* dma address space mask */
     uint64_t msia; /* MSI address */
     uint64_t reserved4;
Signature · 1 line
2.27.0
#5 lore raw

Re: [PATCH v2 4/4] s390x/pci: add supported DT information to clp response

Quoted 29 lines · Matthew Rosato

The DTSM is a mask that specifies which I/O Address Translation designation types are supported. Today QEMU only supports DT=1.

---
  hw/s390x/s390-pci-bus.c         | 1 +
  hw/s390x/s390-pci-inst.c        | 1 +
  hw/s390x/s390-pci-vfio.c        | 1 +
  include/hw/s390x/s390-pci-bus.h | 1 +
  include/hw/s390x/s390-pci-clp.h | 3 ++-
  5 files changed, 6 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-bus.c +1 -0
index 1b51a72838..01b58ebc70 100644
@@ -782,6 +782,7 @@ static void s390_pci_init_default_group(void)
      resgrp->i = 128;
      resgrp->maxstbl = 128;
      resgrp->version = 0;
+    resgrp->dtsm = ZPCI_DTSM;
  }
 
  static void set_pbdev_info(S390PCIBusDevice *pbdev)
hw/s390x/s390-pci-inst.c +0 -0
index 07bab85ce5..f3feba5d74 100644

hw/s390x/s390-pci-inst.c int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_t ra) · line 332

Quoted 4 lines
hw/s390x/s390-pci-inst.c +1 -0
@@ -329,6 +329,7 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_t ra)
          stw_p(&resgrp->i, group->zpci_group.i);
          stw_p(&resgrp->maxstbl, group->zpci_group.maxstbl);
          resgrp->version = group->zpci_group.version;
+        resgrp->version = group->zpci_group.dtsm;

;) cut and past error

...snip...

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#6 lore raw

Re: [PATCH v2 4/4] s390x/pci: add supported DT information to clp response

Quoted 39 lines · Pierre Morel
Quoted 28 lines · Matthew Rosato

The DTSM is a mask that specifies which I/O Address Translation designation types are supported.  Today QEMU only supports DT=1.

---
  hw/s390x/s390-pci-bus.c         | 1 +
  hw/s390x/s390-pci-inst.c        | 1 +
  hw/s390x/s390-pci-vfio.c        | 1 +
  include/hw/s390x/s390-pci-bus.h | 1 +
  include/hw/s390x/s390-pci-clp.h | 3 ++-

  5 files changed, 6 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-bus.c +1 -0
index 1b51a72838..01b58ebc70 100644
@@ -782,6 +782,7 @@ static void s390_pci_init_default_group(void)
       resgrp->i = 128;
       resgrp->maxstbl = 128;
       resgrp->version = 0;
+    resgrp->dtsm = ZPCI_DTSM;
   }
   static void set_pbdev_info(S390PCIBusDevice *pbdev)
hw/s390x/s390-pci-inst.c +0 -0
index 07bab85ce5..f3feba5d74 100644

hw/s390x/s390-pci-inst.c int clp_service_call(S390CPU *cpu, uint8_t r2, · line 333

Quoted 5 lines
hw/s390x/s390-pci-inst.c +1 -0
@@ -329,6 +329,7 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, 
 uintptr_t ra)
           stw_p(&resgrp->i, group->zpci_group.i);
           stw_p(&resgrp->maxstbl, group->zpci_group.maxstbl);
           resgrp->version = group->zpci_group.version;
+        resgrp->version = group->zpci_group.dtsm;

;) cut and past error

Quoted 2 lines

...snip...

... And this is why I should not write code first thing in the morning!

Thanks, will send a v3 in a bit.