Skip to contentSkip to conversation

s390x/pci: Improve zPCI to cover more cases

PATCH In review Pierre Morel 2 participants 13 messages Nov 30, 2017 – Dec 1, 2017

lore
Share & tools
lore
#0 lore raw

v4 cover s390x/pci: Improve zPCI to cover more cases

This patch fixes the following BUG:
Even a guest is able to detect virtio_pci device, the init function the Linux virtio_pci driver will hang because zPCI does not support the subregions used by virtio_pci.

It follows that right now the PCI support is very limited (e.g. pass through of a host vfio device)
To enable features like virtio-pci several modifications needs to be done.

As already stated above, Virtio-PCI uses subregions, which may eventually be discontinuous inside bars instead of a single flat region often used by real devices.
The address offset being formerly calculated from the BAR base address must be adapted to the subregions instead of to the single region.

This patch provides the new calculation for the three kind of BAR access, zPCI STORE, zPCI LOAD and zPCI STORE BLOCK done by zPCI.

We use the opportunity to
- enhance the fault detection for zPCI STORE and LOAD,
- enhance the fault detection and to provide the maximum STORE BLOCK block size, maxstbl, for zPCI STORE BLOCK
- factor out part of the code used to calculate the offset and access the BARs,
- factor out the code for endianess conversion.

Pierre Morel (7):
s390x/pci: factor out endianess conversion s390x/pci: rework PCI STORE
s390x/pci: rework PCI LOAD
s390x/pci: rework PCI STORE BLOCK s390x/pci: move the memory region read from pcilg s390x/pci: move the memory region write from pcistg s390x/pci: search for subregion inside the BARs

 hw/s390x/s390-pci-bus.h  |   1 +
 hw/s390x/s390-pci-inst.c | 251 ++++++++++++++++++++++++++++-------------------
 hw/s390x/s390-pci-inst.h |   6 +-
 3 files changed, 158 insertions(+), 100 deletions(-)
Signature · 19 lines
2.7.4

Changelog:

from v3
- added explanation why we always need to swap bytes
- #define for BAR definitions (Conny)
- renamed "other" to "subregion" (Thomas)
- renamed label "addressing_error" to "specification_error" (Thomas)
- added some comments to explain why testing states is not needed (Conny)

from v2
- rewording of comments, coding style.

from v1
- suppress fallthrough to PCI_ROM_SLOT to handle it in the default case.
- reword most of the patch commit messages
- add comments to the endianness conversion
- reword somme comments inside the patches
#1 lore raw

PATCH v4 1/7 s390x/pci: factor out endianess conversion

There are two places where the same endianness conversion is done.
Let's factor this out into a static function.

Note that the conversion must always be done for data in a register:

The S390 BE guest converted date to le before issuing the instruction.

After interception in a BE host:
ZPCI VFIO using pwrite must make the conversion back for the BE kernel. Kernel will do BE to le translation when loading the register for the real instruction.

After interception in a le host:
TCG stores a BE register in le, swapping bytes.
But since the data in the register was already le it is now BE ZPCI VFIO must convert it to le before writing to the PCI memory.

In both cases ZPCI VFIO must swap the bytes from the register.

---
 hw/s390x/s390-pci-inst.c | 59 +++++++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 26 deletions(-)
hw/s390x/s390-pci-inst.c +33 -26
index 8e088f3..3e1f1a0 100644
@@ -314,6 +314,36 @@ out:
     return 0;
 }
 
+/**
+ * Swap data contained in s390x big endian registers to little endian
+ * PCI bars.
+ *
+ * @ptr: a pointer to a uint64_t data field
+ * @len: the length of the valid data, must be 1,2,4 or 8
+ */
+static int zpci_endian_swap(uint64_t *ptr, uint8_t len)
+{
+    uint64_t data = *ptr;
+
+    switch (len) {
+    case 1:
+        break;
+    case 2:
+        data = bswap16(data);
+        break;
+    case 4:
+        data = bswap32(data);
+        break;
+    case 8:
+        data = bswap64(data);
+        break;
+    default:
+        return -EINVAL;
+    }
+    *ptr = data;
+    return 0;
+}
+
 int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
 {
     CPUS390XState *env = &cpu->env;
@@ -385,19 +415,7 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
         data =  pci_host_config_read_common(
                    pbdev->pdev, offset, pci_config_size(pbdev->pdev), len);
 
-        switch (len) {
-        case 1:
-            break;
-        case 2:
-            data = bswap16(data);
-            break;
-        case 4:
-            data = bswap32(data);
-            break;
-        case 8:
-            data = bswap64(data);
-            break;
-        default:
+        if (zpci_endian_swap(&data, len)) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
@@ -500,19 +518,8 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
-        switch (len) {
-        case 1:
-            break;
-        case 2:
-            data = bswap16(data);
-            break;
-        case 4:
-            data = bswap32(data);
-            break;
-        case 8:
-            data = bswap64(data);
-            break;
-        default:
+
+        if (zpci_endian_swap(&data, len)) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
Signature · 1 line
2.7.4
#2 lore raw

PATCH v4 2/7 s390x/pci: rework PCI STORE

In reply to Pierre Morel

Enhance the fault detection, correction of the fault reporting.

---
 hw/s390x/s390-pci-inst.c | 42 +++++++++++++++++++++++++-----------------
 hw/s390x/s390-pci-inst.h |  4 ++++
 2 files changed, 29 insertions(+), 17 deletions(-)
hw/s390x/s390-pci-inst.c +25 -17
index 3e1f1a0..134484f 100644
@@ -470,6 +470,12 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
     pcias = (env->regs[r2] >> 16) & 0xf;
     len = env->regs[r2] & 0xf;
     offset = env->regs[r2 + 1];
+    data = env->regs[r1];
+
+    if (!(fh & FH_MASK_ENABLE)) {
+        setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);
+        return 0;
+    }
 
     pbdev = s390_pci_find_dev_by_fh(s390_get_phb(), fh);
     if (!pbdev) {
@@ -479,12 +485,10 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
     }
 
     switch (pbdev->state) {
-    case ZPCI_FS_RESERVED:
-    case ZPCI_FS_STANDBY:
-    case ZPCI_FS_DISABLED:
+    /* ZPCI_FS_RESERVED, ZPCI_FS_STANDBY and ZPCI_FS_DISABLED
+     * are already covered by the FH_MASK_ENABLE check above
+     */
     case ZPCI_FS_PERMANENT_ERROR:
-        setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);
-        return 0;
     case ZPCI_FS_ERROR:
         setcc(cpu, ZPCI_PCI_LS_ERR);
         s390_set_status_code(env, r2, ZPCI_PCI_ST_BLOCKED);
@@ -493,9 +497,13 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
         break;
     }
 
-    data = env->regs[r1];
-    if (pcias < 6) {
-        if ((8 - (offset & 0x7)) < len) {
+    switch (pcias) {
+        /* A ZPCI PCI card may use any BAR from BAR 0 to BAR 5 */
+    case ZPCI_IO_BAR_MIN ... ZPCI_IO_BAR_MAX:
+        /* Check length:
+         * A length of 0 is invalid and length should not cross a double word
+         */
+        if (!len || (len > (8 - (offset & 0x7)))) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
@@ -513,21 +521,21 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
-    } else if (pcias == 15) {
-        if ((4 - (offset & 0x3)) < len) {
-            program_interrupt(env, PGM_OPERAND, 4);
-            return 0;
-        }
-
-        if (zpci_endian_swap(&data, len)) {
+        break;
+    case ZPCI_CONFIG_BAR:
+        /* ZPCI uses the pseudo BAR number 15 as configuration space */
+        /* possible access lengths are 1,2,4 and must not cross a word */
+        if (!len || (len > (4 - (offset & 0x3))) || len == 3) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
-
+        /* len = 1,2,4 so we do not need to test */
+        zpci_endian_swap(&data, len);
         pci_host_config_write_common(pbdev->pdev, offset,
                                      pci_config_size(pbdev->pdev),
                                      data, len);
-    } else {
+        break;
+    default:
         DPRINTF("pcistg invalid space\n");
         setcc(cpu, ZPCI_PCI_LS_ERR);
         s390_set_status_code(env, r2, ZPCI_PCI_ST_INVAL_AS);
hw/s390x/s390-pci-inst.h +4 -0
index 94a959f..4be58fe 100644
@@ -302,4 +302,8 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
 int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar);
 int stpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar);
 
+#define ZPCI_IO_BAR_MIN 0
+#define ZPCI_IO_BAR_MAX 5
+#define ZPCI_CONFIG_BAR 15
+
 #endif
Signature · 1 line
2.7.4
#3 lore raw

Re: [Qemu-devel] [PATCH v4 2/7] s390x/pci: rework PCI STORE

Quoted 11 lines · On Thu, 30 Nov 2017 13:55:25 +0100 Pierre Morel <[email protected]>…

Enhance the fault detection, correction of the fault reporting.

---
 hw/s390x/s390-pci-inst.c | 42 +++++++++++++++++++++++++-----------------
 hw/s390x/s390-pci-inst.h |  4 ++++
 2 files changed, 29 insertions(+), 17 deletions(-)

hw/s390x/s390-pci-inst.c int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2) · line 502

Quoted 9 lines
hw/s390x/s390-pci-inst.c +3 -3
@@ -493,9 +497,13 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
         break;
     }
 
-    data = env->regs[r1];
-    if (pcias < 6) {
-        if ((8 - (offset & 0x7)) < len) {
+    switch (pcias) {
+        /* A ZPCI PCI card may use any BAR from BAR 0 to BAR 5 */
+    case ZPCI_IO_BAR_MIN ... ZPCI_IO_BAR_MAX:

Will make this

case ZPCI_IO_BAR_MIN...ZPCI_IO_BAR_MAX:

Quoted 7 lines
hw/s390x/s390-pci-inst.c +4 -0
+        /* Check length:
+         * A length of 0 is invalid and length should not cross a double word
+         */
+        if (!len || (len > (8 - (offset & 0x7)))) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
#4 lore raw

PATCH v4 3/7 s390x/pci: rework PCI LOAD

In reply to Pierre Morel

Enhance the fault detection, correction of the fault reporting.

---
 hw/s390x/s390-pci-inst.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
hw/s390x/s390-pci-inst.c +14 -11
index 134484f..bab347e 100644
@@ -373,6 +373,11 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
     len = env->regs[r2] & 0xf;
     offset = env->regs[r2 + 1];
 
+    if (!(fh & FH_MASK_ENABLE)) {
+        setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);
+        return 0;
+    }
+
     pbdev = s390_pci_find_dev_by_fh(s390_get_phb(), fh);
     if (!pbdev) {
         DPRINTF("pcilg no pci dev\n");
@@ -381,12 +386,7 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
     }
 
     switch (pbdev->state) {
-    case ZPCI_FS_RESERVED:
-    case ZPCI_FS_STANDBY:
-    case ZPCI_FS_DISABLED:
     case ZPCI_FS_PERMANENT_ERROR:
-        setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);
-        return 0;
     case ZPCI_FS_ERROR:
         setcc(cpu, ZPCI_PCI_LS_ERR);
         s390_set_status_code(env, r2, ZPCI_PCI_ST_BLOCKED);
@@ -395,8 +395,9 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
         break;
     }
 
-    if (pcias < 6) {
-        if ((8 - (offset & 0x7)) < len) {
+    switch (pcias) {
+    case ZPCI_IO_BAR_MIN ... ZPCI_IO_BAR_MAX:
+        if (!len || (len > (8 - (offset & 0x7)))) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
@@ -407,8 +408,9 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
-    } else if (pcias == 15) {
-        if ((4 - (offset & 0x3)) < len) {
+        break;
+    case ZPCI_CONFIG_BAR:
+        if (!len || (len > (4 - (offset & 0x3))) || len == 3) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
@@ -419,8 +421,9 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
-    } else {
-        DPRINTF("invalid space\n");
+        break;
+    default:
+        DPRINTF("pcilg invalid space\n");
         setcc(cpu, ZPCI_PCI_LS_ERR);
         s390_set_status_code(env, r2, ZPCI_PCI_ST_INVAL_AS);
         return 0;
Signature · 1 line
2.7.4
#5 lore raw

Re: [Qemu-devel] [PATCH v4 3/7] s390x/pci: rework PCI LOAD

Quoted 10 lines · On Thu, 30 Nov 2017 13:55:26 +0100 Pierre Morel <[email protected]>…

Enhance the fault detection, correction of the fault reporting.

---
 hw/s390x/s390-pci-inst.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

hw/s390x/s390-pci-inst.c int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2) · line 399

Quoted 7 lines
hw/s390x/s390-pci-inst.c +2 -2
@@ -395,8 +395,9 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
         break;
     }
 
-    if (pcias < 6) {
-        if ((8 - (offset & 0x7)) < len) {
+    switch (pcias) {
+    case ZPCI_IO_BAR_MIN ... ZPCI_IO_BAR_MAX:

Will make this

case ZPCI_IO_BAR_MIN...ZPCI_IO_BAR_MAX:

Quoted 4 lines
hw/s390x/s390-pci-inst.c +1 -0
+        if (!len || (len > (8 - (offset & 0x7)))) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
#6 lore raw

PATCH v4 4/7 s390x/pci: rework PCI STORE BLOCK

In reply to Pierre Morel

Enhance the fault detection.

Fixup the precedence to check the destination path existance before checking for the source accessibility.

Add the maxstbl entry to both the Query PCI Function Group response and the PCIBusDevice structure.

Initialize the maxstbl to 128 per default until we get the actual data from the hardware.

---
 hw/s390x/s390-pci-bus.h  |  1 +
 hw/s390x/s390-pci-inst.c | 63 ++++++++++++++++++++++++++++++------------------
 hw/s390x/s390-pci-inst.h |  2 +-
 3 files changed, 41 insertions(+), 25 deletions(-)
hw/s390x/s390-pci-bus.h +1 -0
index 560bd82..2993f0d 100644
@@ -284,6 +284,7 @@ struct S390PCIBusDevice {
     uint64_t fmb_addr;
     uint8_t isc;
     uint16_t noi;
+    uint16_t maxstbl;
     uint8_t sum;
     S390MsixInfo msix;
     AdapterRoutes routes;
hw/s390x/s390-pci-inst.c +39 -24

108 lines not on this page · raw message

hw/s390x/s390-pci-inst.h +1 -1
index 4be58fe..d4578d2 100644
@@ -162,7 +162,7 @@ typedef struct ClpRspQueryPciGrp {
 #define CLP_RSP_QPCIG_MASK_FRAME   0x2
 #define CLP_RSP_QPCIG_MASK_REFRESH 0x1
     uint8_t fr;
-    uint16_t reserved2;
+    uint16_t maxstbl;
     uint16_t mui;
     uint64_t reserved3;
     uint64_t dasm; /* dma address space mask */
Signature · 1 line
2.7.4
#7 lore raw

PATCH v4 5/7 s390x/pci: move the memory region read from pcilg

In reply to Pierre Morel

Let's move the memory region read from pcilg into a dedicated function. This allows us to prepare a later patch.

---
 hw/s390x/s390-pci-inst.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
hw/s390x/s390-pci-inst.c +11 -4
index bab7353..c702e8d 100644
@@ -345,13 +345,22 @@ static int zpci_endian_swap(uint64_t *ptr, uint8_t len)
     return 0;
 }
 
+static MemTxResult zpci_read_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
+                                 uint64_t offset, uint64_t *data, uint8_t len)
+{
+    MemoryRegion *mr;
+
+    mr = pbdev->pdev->io_regions[pcias].memory;
+    return memory_region_dispatch_read(mr, offset, data, len,
+                                       MEMTXATTRS_UNSPECIFIED);
+}
+
 int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
 {
     CPUS390XState *env = &cpu->env;
     S390PCIBusDevice *pbdev;
     uint64_t offset;
     uint64_t data;
-    MemoryRegion *mr;
     MemTxResult result;
     uint8_t len;
     uint32_t fh;
@@ -402,9 +411,7 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
         }
-        mr = pbdev->pdev->io_regions[pcias].memory;
-        result = memory_region_dispatch_read(mr, offset, &data, len,
-                                             MEMTXATTRS_UNSPECIFIED);
+        result = zpci_read_bar(pbdev, pcias, offset, &data, len);
         if (result != MEMTX_OK) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
Signature · 1 line
2.7.4
#8 lore raw

PATCH v4 6/7 s390x/pci: move the memory region write from pcistg

In reply to Pierre Morel

Let's move the memory region write from pcistg into a dedicated function.
This allows us to prepare a later patch searching for subregions inside of the memory region.

---
 hw/s390x/s390-pci-inst.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
hw/s390x/s390-pci-inst.c +17 -10
index c702e8d..1277d62 100644
@@ -454,12 +454,27 @@ static int trap_msix(S390PCIBusDevice *pbdev, uint64_t offset, uint8_t pcias)
     }
 }
 
+static MemTxResult zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
+                                  uint64_t offset, uint64_t data, uint8_t len)
+{
+    MemoryRegion *mr;
+
+    if (trap_msix(pbdev, offset, pcias)) {
+        offset = offset - pbdev->msix.table_offset;
+        mr = &pbdev->pdev->msix_table_mmio;
+    } else {
+        mr = pbdev->pdev->io_regions[pcias].memory;
+    }
+
+    return memory_region_dispatch_write(mr, offset, data, len,
+                                        MEMTXATTRS_UNSPECIFIED);
+}
+
 int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
 {
     CPUS390XState *env = &cpu->env;
     uint64_t offset, data;
     S390PCIBusDevice *pbdev;
-    MemoryRegion *mr;
     MemTxResult result;
     uint8_t len;
     uint32_t fh;
@@ -519,15 +534,7 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
             return 0;
         }
 
-        if (trap_msix(pbdev, offset, pcias)) {
-            offset = offset - pbdev->msix.table_offset;
-            mr = &pbdev->pdev->msix_table_mmio;
-        } else {
-            mr = pbdev->pdev->io_regions[pcias].memory;
-        }
-
-        result = memory_region_dispatch_write(mr, offset, data, len,
-                                     MEMTXATTRS_UNSPECIFIED);
+        result = zpci_write_bar(pbdev, pcias, offset, data, len);
         if (result != MEMTX_OK) {
             program_interrupt(env, PGM_OPERAND, 4);
             return 0;
Signature · 1 line
2.7.4
#9 lore raw

PATCH v4 7/7 s390x/pci: search for subregion inside the BARs

In reply to Pierre Morel

When dispatching memory access to PCI BAR region, we must look for possible subregions, used by the PCI device to map different memory areas inside the same PCI BAR.

Since the data offset we received is calculated starting at the region start address we need to adjust the offset for the subregion.

The data offset inside the subregion is calculated by substracting the subregion's starting address from the data offset in the region.

The access to the MSIX region is now handled in a generic way, we do not need the specific trap_msix() function anymore.

---
 hw/s390x/s390-pci-inst.c | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)
hw/s390x/s390-pci-inst.c +25 -19
index 1277d62..ca110e0 100644
@@ -345,12 +345,31 @@ static int zpci_endian_swap(uint64_t *ptr, uint8_t len)
     return 0;
 }
 
+static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
+                                        uint8_t len)
+{
+    MemoryRegion *subregion;
+    uint64_t subregion_size;
+
+    QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
+        subregion_size = int128_get64(subregion->size);
+        if ((offset >= subregion->addr) &&
+            (offset + len) <= (subregion->addr + subregion_size)) {
+            mr = subregion;
+            break;
+        }
+    }
+    return mr;
+}
+
 static MemTxResult zpci_read_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
                                  uint64_t offset, uint64_t *data, uint8_t len)
 {
     MemoryRegion *mr;
 
     mr = pbdev->pdev->io_regions[pcias].memory;
+    mr = s390_get_subregion(mr, offset, len);
+    offset -= mr->addr;
     return memory_region_dispatch_read(mr, offset, data, len,
                                        MEMTXATTRS_UNSPECIFIED);
 }
@@ -442,30 +461,14 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)
     return 0;
 }
 
-static int trap_msix(S390PCIBusDevice *pbdev, uint64_t offset, uint8_t pcias)
-{
-    if (pbdev->msix.available && pbdev->msix.table_bar == pcias &&
-        offset >= pbdev->msix.table_offset &&
-        offset < (pbdev->msix.table_offset +
-                  pbdev->msix.entries * PCI_MSIX_ENTRY_SIZE)) {
-        return 1;
-    } else {
-        return 0;
-    }
-}
-
 static MemTxResult zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
                                   uint64_t offset, uint64_t data, uint8_t len)
 {
     MemoryRegion *mr;
 
-    if (trap_msix(pbdev, offset, pcias)) {
-        offset = offset - pbdev->msix.table_offset;
-        mr = &pbdev->pdev->msix_table_mmio;
-    } else {
-        mr = pbdev->pdev->io_regions[pcias].memory;
-    }
-
+    mr = pbdev->pdev->io_regions[pcias].memory;
+    mr = s390_get_subregion(mr, offset, len);
+    offset -= mr->addr;
     return memory_region_dispatch_write(mr, offset, data, len,
                                         MEMTXATTRS_UNSPECIFIED);
 }
@@ -729,6 +732,9 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
     }
 
     mr = pbdev->pdev->io_regions[pcias].memory;
+    mr = s390_get_subregion(mr, offset, len);
+    offset -= mr->addr;
+
     if (!memory_region_access_valid(mr, offset, len, true)) {
         program_interrupt(env, PGM_OPERAND, 6);
         return 0;
Signature · 1 line
2.7.4
#10 lore raw
In reply to Pierre Morel
Quoted 37 lines · On Thu, 30 Nov 2017 13:55:23 +0100 Pierre Morel <[email protected]>…

This patch fixes the following BUG:
Even a guest is able to detect virtio_pci device, the init function the Linux virtio_pci driver will hang because zPCI does not support the subregions used by virtio_pci.

It follows that right now the PCI support is very limited (e.g. pass through of a host vfio device)
To enable features like virtio-pci several modifications needs to be done.

As already stated above, Virtio-PCI uses subregions, which may eventually be discontinuous inside bars instead of a single flat region often used by real devices.
The address offset being formerly calculated from the BAR base address must be adapted to the subregions instead of to the single region.

This patch provides the new calculation for the three kind of BAR access, zPCI STORE, zPCI LOAD and zPCI STORE BLOCK done by zPCI.

We use the opportunity to
- enhance the fault detection for zPCI STORE and LOAD,
- enhance the fault detection and to provide the maximum STORE BLOCK block size, maxstbl, for zPCI STORE BLOCK
- factor out part of the code used to calculate the offset and access the BARs,
- factor out the code for endianess conversion.

Pierre Morel (7):
s390x/pci: factor out endianess conversion s390x/pci: rework PCI STORE
s390x/pci: rework PCI LOAD
s390x/pci: rework PCI STORE BLOCK s390x/pci: move the memory region read from pcilg s390x/pci: move the memory region write from pcistg s390x/pci: search for subregion inside the BARs

Quoted 5 lines
 hw/s390x/s390-pci-bus.h  |   1 +
 hw/s390x/s390-pci-inst.c | 251 ++++++++++++++++++++++++++++-------------------
 hw/s390x/s390-pci-inst.h |   6 +-
 3 files changed, 158 insertions(+), 100 deletions(-)

Thanks, queued to s390-next.

#11 lore raw
In reply to Pierre Morel
Quoted 37 lines · On Thu, 30 Nov 2017 13:55:23 +0100 Pierre Morel <[email protected]>…

This patch fixes the following BUG:
Even a guest is able to detect virtio_pci device, the init function the Linux virtio_pci driver will hang because zPCI does not support the subregions used by virtio_pci.

It follows that right now the PCI support is very limited (e.g. pass through of a host vfio device)
To enable features like virtio-pci several modifications needs to be done.

As already stated above, Virtio-PCI uses subregions, which may eventually be discontinuous inside bars instead of a single flat region often used by real devices.
The address offset being formerly calculated from the BAR base address must be adapted to the subregions instead of to the single region.

This patch provides the new calculation for the three kind of BAR access, zPCI STORE, zPCI LOAD and zPCI STORE BLOCK done by zPCI.

We use the opportunity to
- enhance the fault detection for zPCI STORE and LOAD,
- enhance the fault detection and to provide the maximum STORE BLOCK block size, maxstbl, for zPCI STORE BLOCK
- factor out part of the code used to calculate the offset and access the BARs,
- factor out the code for endianess conversion.

Pierre Morel (7):
s390x/pci: factor out endianess conversion s390x/pci: rework PCI STORE
s390x/pci: rework PCI LOAD
s390x/pci: rework PCI STORE BLOCK s390x/pci: move the memory region read from pcilg s390x/pci: move the memory region write from pcistg s390x/pci: search for subregion inside the BARs

Quoted 5 lines
 hw/s390x/s390-pci-bus.h  |   1 +
 hw/s390x/s390-pci-inst.c | 251 ++++++++++++++++++++++++++++-------------------
 hw/s390x/s390-pci-inst.h |   6 +-
 3 files changed, 158 insertions(+), 100 deletions(-)

I massaged this to fit on top of David's patchset and it still works fine with my pci/tcg patches.

Some small comments for things I can fix up myself (will reply to individual patches). On the whole, I'm inclined to queue this.

#12 lore raw
Quoted 46 lines · Cornelia Huck
Quoted 37 lines · On Thu, 30 Nov 2017 13:55:23 +0100 Pierre Morel <[email protected]>…

This patch fixes the following BUG:
Even a guest is able to detect virtio_pci device, the init function the Linux virtio_pci driver will hang because zPCI does not support the subregions used by virtio_pci.

It follows that right now the PCI support is very limited (e.g. pass through of a host vfio device)
To enable features like virtio-pci several modifications needs to be done.

As already stated above, Virtio-PCI uses subregions, which may eventually be discontinuous inside bars instead of a single flat region often used by real devices.
The address offset being formerly calculated from the BAR base address must be adapted to the subregions instead of to the single region.

This patch provides the new calculation for the three kind of BAR access, zPCI STORE, zPCI LOAD and zPCI STORE BLOCK done by zPCI.

We use the opportunity to
- enhance the fault detection for zPCI STORE and LOAD,
- enhance the fault detection and to provide the maximum STORE BLOCK block size, maxstbl, for zPCI STORE BLOCK
- factor out part of the code used to calculate the offset and access the BARs,
- factor out the code for endianess conversion.

Pierre Morel (7):

   s390x/pci: factor out endianess conversion
   s390x/pci: rework PCI STORE
   s390x/pci: rework PCI LOAD
   s390x/pci: rework PCI STORE BLOCK
   s390x/pci: move the memory region read from pcilg
   s390x/pci: move the memory region write from pcistg
   s390x/pci: search for subregion inside the BARs
Quoted 5 lines
  hw/s390x/s390-pci-bus.h  |   1 +
  hw/s390x/s390-pci-inst.c | 251 ++++++++++++++++++++++++++++-------------------
  hw/s390x/s390-pci-inst.h |   6 +-
  3 files changed, 158 insertions(+), 100 deletions(-)
Quoted 6 lines

I massaged this to fit on top of David's patchset and it still works fine with my pci/tcg patches.

Some small comments for things I can fix up myself (will reply to individual patches). On the whole, I'm inclined to queue this.

Great, thanks.

Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany