Skip to contentSkip to conversation

s390x/pci: Fixing s390 vfio-pci ISM support

PATCH In review Matthew Rosato 4 participants 27 messages Jan 19, 2021 – Jan 25, 2021

lore
Share & tools
lore
#6 lore raw

PATCH 6/8 s390x/pci: PCISTB via the vfio zPCI I/O region

In reply to Matthew Rosato

For ISM devices, use the vfio region to handle intercepted PCISTB instructions. This region will allow large block I/O instructions intercepted from the guest to be performed as a single I/O instruction on the host. This ensure that proper write patterns that are expected by the underlying device are respected and ensures that a non-MIO instruction is used to perform the operation (as ISM devices do not support the MIO instruction set).
Furthermore, add a requirement that the I/O region must be available in order to pass the device through to the guest.

---
 hw/s390x/s390-pci-bus.c          | 15 +++++++
 hw/s390x/s390-pci-inst.c         |  8 ++++
 hw/s390x/s390-pci-vfio.c         | 95 ++++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/s390-pci-bus.h  |  5 +++
 include/hw/s390x/s390-pci-inst.h |  1 +
 include/hw/s390x/s390-pci-vfio.h | 15 +++++++
 6 files changed, 139 insertions(+)
hw/s390x/s390-pci-bus.c +15 -0
index 784ca65..9d5c2c5 100644
@@ -977,6 +977,7 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     S390pciState *s = S390_PCI_HOST_BRIDGE(hotplug_dev);
     PCIDevice *pdev = NULL;
     S390PCIBusDevice *pbdev = NULL;
+    int ret;
 
     if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)) {
         PCIBridge *pb = PCI_BRIDGE(dev);
@@ -1027,6 +1028,20 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
             pbdev->iommu->dma_limit = s390_pci_start_dma_count(s, pbdev);
             /* Fill in CLP information passed via the vfio region */
             s390_pci_get_clp_info(pbdev);
+
+            /*
+             * For an ISM device, attempt to setup the special I/O region.  If
+             * this fails, the device cannot be passed through.
+             */
+            ret = 0;
+            if (pbdev->pft == ZPCI_PFT_ISM) {
+                ret = s390_pci_get_zpci_io_region(pbdev);
+            }
+            if (ret) {
+                error_setg(errp, "vfio zPCI I/O region support is mandatory "
+                           "for %02x:%02x.%01x", pci_dev_bus_num(pdev),
+                           PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
+            }
         } else {
             pbdev->fh |= FH_SHM_EMUL;
 
hw/s390x/s390-pci-inst.c +8 -0
index 67eb4a4..18a701f 100644
@@ -19,6 +19,7 @@
 #include "sysemu/hw_accel.h"
 #include "hw/s390x/s390-pci-inst.h"
 #include "hw/s390x/s390-pci-bus.h"
+#include "hw/s390x/s390-pci-vfio.h"
 #include "hw/s390x/tod.h"
 
 #ifndef DEBUG_S390PCI_INST
@@ -1000,6 +1001,8 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
     ret = pbdev->ops.pcistb(pbdev, cpu, gaddr, ar, pcias, len, offset);
 
     switch (ret) {
+    case -EIO:
+        /* fall through */
     case -EINVAL:
         s390_program_interrupt(env, PGM_OPERAND, ra);
         return 0;
@@ -1488,3 +1491,8 @@ void zpci_assign_default_ops(S390PCIBusDevice *pbdev)
     pbdev->ops.pcilg = pcilg_default;
     pbdev->ops.pcistb = pcistb_default;
 }
+
+void zpci_assign_ops_vfio_io_region(S390PCIBusDevice *pbdev)
+{
+    pbdev->ops.pcistb = s390_pci_vfio_pcistb;
+}
hw/s390x/s390-pci-vfio.c +95 -0

104 lines not on this page · raw message

include/hw/s390x/s390-pci-bus.h +5 -0
index 7c34c5b..aaef890 100644
@@ -43,6 +43,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBus, S390_PCI_BUS)
 OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBusDevice, S390_PCI_DEVICE)
 OBJECT_DECLARE_SIMPLE_TYPE(S390PCIIOMMU, S390_PCI_IOMMU)
 
+/* PCI Function Types */
+#define ZPCI_PFT_ISM 5
+
 #define HP_EVENT_TO_CONFIGURED        0x0301
 #define HP_EVENT_RESERVED_TO_STANDBY  0x0302
 #define HP_EVENT_DECONFIGURE_REQUEST  0x0303
@@ -355,6 +358,8 @@ struct S390PCIBusDevice {
     uint32_t fh;
     uint32_t fid;
     bool fid_defined;
+    uint64_t io_region_op_offset;
+    struct vfio_region_zpci_io *io_region;
     uint64_t fmb_addr;
     ZpciFmb fmb;
     QEMUTimer *fmb_timer;
include/hw/s390x/s390-pci-inst.h +1 -0
index c9fe3f1..7ed6175 100644
@@ -112,6 +112,7 @@ int stpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar,
                          uintptr_t ra);
 void fmb_timer_free(S390PCIBusDevice *pbdev);
 void zpci_assign_default_ops(S390PCIBusDevice *pbdev);
+void zpci_assign_ops_vfio_io_region(S390PCIBusDevice *pbdev);
 
 #define ZPCI_IO_BAR_MIN 0
 #define ZPCI_IO_BAR_MAX 5
include/hw/s390x/s390-pci-vfio.h +15 -0
index ff708ae..f0a994f 100644
@@ -21,6 +21,10 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
                                           S390PCIBusDevice *pbdev);
 void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt);
 void s390_pci_get_clp_info(S390PCIBusDevice *pbdev);
+int s390_pci_get_zpci_io_region(S390PCIBusDevice *pbdev);
+int s390_pci_vfio_pcistb(S390PCIBusDevice *pbdev, S390CPU *cpu, uint64_t gaddr,
+                         uint8_t ar, uint8_t pcias, uint16_t len,
+                         uint64_t offset);
 #else
 static inline bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
 {
@@ -34,6 +38,17 @@ static inline S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
 static inline void s390_pci_end_dma_count(S390pciState *s,
                                           S390PCIDMACount *cnt) { }
 static inline void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) { }
+static inline int s390_pci_get_zpci_io_region(S390PCIBusDevice *pbdev)
+{
+    return -EINVAL;
+}
+static inline int s390_pci_vfio_pcistb(S390PCIBusDevice *pbdev, S390CPU *cpu,
+                                       uint64_t gaddr, uint8_t ar,
+                                       uint8_t pcias, uint16_t len,
+                                       uint64_t offset)
+{
+    return -EIO;
+}
 #endif
 
 #endif
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/8 s390x/pci: Keep track of the PCI Function type

In reply to Matthew Rosato

We now receive the hardware identification of the PCI Function type through vfio. While we can't yet forward that to a guest via CLP, we can still use this to make device-type-dependent decisions in QEMU.

---
 hw/s390x/s390-pci-vfio.c        | 1 +
 include/hw/s390x/s390-pci-bus.h | 1 +
 2 files changed, 2 insertions(+)
hw/s390x/s390-pci-vfio.c +1 -0
index ead4f22..cb59e98 100644
@@ -125,6 +125,7 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
     /* The following values remain 0 until we support other FMB formats */
     pbdev->zpci_fn.fmbl = 0;
     pbdev->zpci_fn.pft = 0;
+    pbdev->pft = cap->pft;
 }
 
 static void s390_pci_read_group(S390PCIBusDevice *pbdev,
include/hw/s390x/s390-pci-bus.h +1 -0
index 49ae9f0..0662e7b 100644
@@ -342,6 +342,7 @@ struct S390PCIBusDevice {
     uint16_t noi;
     uint16_t maxstbl;
     uint8_t sum;
+    uint8_t pft;
     S390PCIGroup *pci_group;
     ClpRspQueryPci zpci_fn;
     S390MsixInfo msix;
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 8/8 s390x/pci: Prevent ISM device passthrough on older host kernels

In reply to Matthew Rosato

If the underlying host does not provide CLP capabilities, we cannot tell what type of function is being passed through, which means for ISM devices we can't properly tell if the vfio I/O region is necessary. If the ISM device is allowed to pass through erroneously, it will not function properly without the I/O region. Therefore, check for unclassified devices that do not have MSI-X support and still disallow these from being passed through, using the same error as known ISM devices when the vfio I/O region is unavailable.

---
 hw/s390x/s390-pci-bus.c         | 13 +++++++++++++
 include/hw/s390x/s390-pci-bus.h |  1 +
 2 files changed, 14 insertions(+)
hw/s390x/s390-pci-bus.c +13 -0
index 9d5c2c5..0dfdc88 100644
@@ -1037,6 +1037,19 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
             if (pbdev->pft == ZPCI_PFT_ISM) {
                 ret = s390_pci_get_zpci_io_region(pbdev);
             }
+            /*
+             * If the device type is unclassified, it may be due to the fact
+             * that CLP info was not provided by vfio -- Which means we cannot
+             * tell if this is actually an ISM device, which will not be able
+             * to function properly without proper identification and the I/O
+             * region.  Therefore, attempt to identify the ISM device via the
+             * lack of MSI-X and only in this case prevent the device from
+             * being passed through.
+             */
+            else if (pbdev->pft == ZPCI_PFT_UNCLASSIFIED &&
+                     !pci_find_capability(pbdev->pdev, PCI_CAP_ID_MSIX)) {
+                ret = -EINVAL;
+            }
             if (ret) {
                 error_setg(errp, "vfio zPCI I/O region support is mandatory "
                            "for %02x:%02x.%01x", pci_dev_bus_num(pdev),
include/hw/s390x/s390-pci-bus.h +1 -0
index aaef890..d75aad8 100644
@@ -44,6 +44,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBusDevice, S390_PCI_DEVICE)
 OBJECT_DECLARE_SIMPLE_TYPE(S390PCIIOMMU, S390_PCI_IOMMU)
 
 /* PCI Function Types */
+#define ZPCI_PFT_UNCLASSIFIED 0
 #define ZPCI_PFT_ISM 5
 
 #define HP_EVENT_TO_CONFIGURED        0x0301
Signature · 1 line
1.8.3.1
#0 lore raw

cover s390x/pci: Fixing s390 vfio-pci ISM support

Today, ISM devices are completely disallowed for vfio-pci passthrough as QEMU rejects the device due to an (inappropriate) MSI-X check. Removing this fence, however, reveals additional deficiencies in the s390x PCI interception layer that prevent ISM devices from working correctly. Namely, ISM block write operations have particular requirements in regards to the alignment, size and order of writes performed that cannot be guaranteed when breaking up write operations through the typical vfio_pci_bar_rw paths. Furthermore, ISM requires that legacy/non-MIO s390 PCI instructions are used, which is also not guaranteed when the I/O is passed through the typical userspace channels.

This patchset provides a set of fixes related to enabling ISM device passthrough and includes patches to enable use of a new vfio region that will allow s390x PCI pass-through devices to perform s390 PCI instructions in such a way that the same instruction issued on the guest is re-issued on the host.

Associated kernel patchset:
https://lkml.org/lkml/2021/1/19/874

Changes from RFC -> v1:
- Refresh the header sync (built using Eric's 'update-linux-headers:
Include const.h' + manually removed pvrdma_ring.h again)
- Remove s390x/pci: fix pcistb length (already merged)
- Remove s390x/pci: Fix memory_region_access_valid call (already merged)
- Fix bug: s390_pci_vfio_pcistb should use the pre-allocated PCISTB buffer pcistb_buf rather than allocating/freeing its own.
- New patch: track the PFT (PCI Function Type) separately from guest CLP response data -- we tell the guest '0' for now due to limitations in measurement block support, but we can still use the real value provided via the vfio CLP capabilities to make decisions.
- Use the PFT (pci function type) to determine when to use the region for PCISTB/PCILG (only for ISM), rather than using the relaxed alignment bit.
- As a result, the pcistb_default is now updated to also handle the possibility of relaxed alignment via 2 new functions, pcistb_validate_write and pcistb_write, which serve as wrappers to the memory_region calls.
- New patch, which partially restores the MSI-X fence for passthrough devices... Could potentially be squashed with 's390x/pci: MSI-X isn't strictly required for passthrough' but left separately for now as I felt it needed a clear commit description of why we should still fence this case.

Matthew Rosato (8):
linux-headers: update against 5.11-rc4
s390x/pci: Keep track of the PCI Function type s390x/pci: MSI-X isn't strictly required for passthrough s390x/pci: Introduce the ZpciOps structure
s390x/pci: Handle devices that support relaxed alignment s390x/pci: PCISTB via the vfio zPCI I/O region s390x/pci: PCILG via the vfio zPCI I/O region s390x/pci: Prevent ISM device passthrough on older host kernels

 hw/s390x/s390-pci-bus.c                            |  45 ++-
 hw/s390x/s390-pci-inst.c                           | 389 +++++++++++++++------
 hw/s390x/s390-pci-vfio.c                           | 152 ++++++++
 include/hw/s390x/s390-pci-bus.h                    |  29 ++
 include/hw/s390x/s390-pci-clp.h                    |   1 +
 include/hw/s390x/s390-pci-inst.h                   |   3 +
 include/hw/s390x/s390-pci-vfio.h                   |  23 ++
 .../infiniband/hw/vmw_pvrdma/pvrdma_verbs.h        |   2 +-
 include/standard-headers/drm/drm_fourcc.h          | 175 ++++++++-
 include/standard-headers/linux/ethtool.h           |   2 +-
 include/standard-headers/linux/fuse.h              |  30 +-
 include/standard-headers/linux/kernel.h            |   9 +-
 include/standard-headers/linux/pci_regs.h          |  16 +
 include/standard-headers/linux/vhost_types.h       |   9 +
 include/standard-headers/linux/virtio_gpu.h        |  82 +++++
 include/standard-headers/linux/virtio_ids.h        |  44 ++-
 linux-headers/asm-arm64/kvm.h                      |   3 -
 linux-headers/asm-generic/unistd.h                 |   6 +-
 linux-headers/asm-mips/unistd_n32.h                |   1 +
 linux-headers/asm-mips/unistd_n64.h                |   1 +
 linux-headers/asm-mips/unistd_o32.h                |   1 +
 linux-headers/asm-powerpc/unistd_32.h              |   1 +
 linux-headers/asm-powerpc/unistd_64.h              |   1 +
 linux-headers/asm-s390/unistd_32.h                 |   1 +
 linux-headers/asm-s390/unistd_64.h                 |   1 +
 linux-headers/asm-x86/kvm.h                        |   1 +
 linux-headers/asm-x86/unistd_32.h                  |   1 +
 linux-headers/asm-x86/unistd_64.h                  |   1 +
 linux-headers/asm-x86/unistd_x32.h                 |   1 +
 linux-headers/linux/kvm.h                          |  58 ++-
 linux-headers/linux/userfaultfd.h                  |   9 +
 linux-headers/linux/vfio.h                         |   5 +
 linux-headers/linux/vfio_zdev.h                    |  34 ++
 linux-headers/linux/vhost.h                        |   4 +
 34 files changed, 996 insertions(+), 145 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/8 linux-headers: update against 5.11-rc4

Placeholder commit to pull in changes from "vfio-pci/zdev: Pass the relaxed alignment flag" and "vfio-pci/zdev: Introduce the PCISTB vfio region"

---
 .../infiniband/hw/vmw_pvrdma/pvrdma_verbs.h        |   2 +-
 include/standard-headers/drm/drm_fourcc.h          | 175 ++++++++++++++++++++-
 include/standard-headers/linux/ethtool.h           |   2 +-
 include/standard-headers/linux/fuse.h              |  30 +++-
 include/standard-headers/linux/kernel.h            |   9 +-
 include/standard-headers/linux/pci_regs.h          |  16 ++
 include/standard-headers/linux/vhost_types.h       |   9 ++
 include/standard-headers/linux/virtio_gpu.h        |  82 ++++++++++
 include/standard-headers/linux/virtio_ids.h        |  44 +++---
 linux-headers/asm-arm64/kvm.h                      |   3 -
 linux-headers/asm-generic/unistd.h                 |   6 +-
 linux-headers/asm-mips/unistd_n32.h                |   1 +
 linux-headers/asm-mips/unistd_n64.h                |   1 +
 linux-headers/asm-mips/unistd_o32.h                |   1 +
 linux-headers/asm-powerpc/unistd_32.h              |   1 +
 linux-headers/asm-powerpc/unistd_64.h              |   1 +
 linux-headers/asm-s390/unistd_32.h                 |   1 +
 linux-headers/asm-s390/unistd_64.h                 |   1 +
 linux-headers/asm-x86/kvm.h                        |   1 +
 linux-headers/asm-x86/unistd_32.h                  |   1 +
 linux-headers/asm-x86/unistd_64.h                  |   1 +
 linux-headers/asm-x86/unistd_x32.h                 |   1 +
 linux-headers/linux/kvm.h                          |  58 ++++++-
 linux-headers/linux/userfaultfd.h                  |   9 ++
 linux-headers/linux/vfio.h                         |   5 +
 linux-headers/linux/vfio_zdev.h                    |  34 ++++
 linux-headers/linux/vhost.h                        |   4 +
 27 files changed, 458 insertions(+), 41 deletions(-)
include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h +1 -1
index 0a8c7c9..1677208 100644
@@ -176,7 +176,7 @@ struct pvrdma_port_attr {
 	uint8_t			subnet_timeout;
 	uint8_t			init_type_reply;
 	uint8_t			active_width;
-	uint16_t			active_speed;
+	uint8_t			active_speed;
 	uint8_t			phys_state;
 	uint8_t			reserved[2];
 };
include/standard-headers/drm/drm_fourcc.h +174 -1

205 lines not on this page · raw message

include/standard-headers/linux/ethtool.h +1 -1
index 0df22f7..8bfd01d 100644
@@ -16,7 +16,7 @@
 
 #include "net/eth.h"
 
-#include "standard-headers/linux/kernel.h"
+#include "standard-headers/linux/const.h"
 #include "standard-headers/linux/types.h"
 #include "standard-headers/linux/if_ether.h"
 
include/standard-headers/linux/fuse.h +25 -5
index 82c0a38..950d7ed 100644
@@ -175,6 +175,10 @@
  *
  *  7.32
  *  - add flags to fuse_attr, add FUSE_ATTR_SUBMOUNT, add FUSE_SUBMOUNTS
+ *
+ *  7.33
+ *  - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUIDGID
+ *  - add FUSE_OPEN_KILL_SUIDGID
  */
 
 #ifndef _LINUX_FUSE_H
@@ -206,7 +210,7 @@
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 32
+#define FUSE_KERNEL_MINOR_VERSION 33
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
@@ -267,6 +271,7 @@ struct fuse_file_lock {
 #define FATTR_MTIME_NOW	(1 << 8)
 #define FATTR_LOCKOWNER	(1 << 9)
 #define FATTR_CTIME	(1 << 10)
+#define FATTR_KILL_SUIDGID	(1 << 11)
 
 /**
  * Flags returned by the OPEN request
@@ -316,6 +321,11 @@ struct fuse_file_lock {
  *		       foffset and moffset fields in struct
  *		       fuse_setupmapping_out and fuse_removemapping_one.
  * FUSE_SUBMOUNTS: kernel supports auto-mounting directory submounts
+ * FUSE_HANDLE_KILLPRIV_V2: fs kills suid/sgid/cap on write/chown/trunc.
+ *			Upon write/truncate suid/sgid is only killed if caller
+ *			does not have CAP_FSETID. Additionally upon
+ *			write/truncate sgid is killed only if file has group
+ *			execute permission. (Same as Linux VFS behavior).
  */
 #define FUSE_ASYNC_READ		(1 << 0)
 #define FUSE_POSIX_LOCKS	(1 << 1)
@@ -345,6 +355,7 @@ struct fuse_file_lock {
 #define FUSE_EXPLICIT_INVAL_DATA (1 << 25)
 #define FUSE_MAP_ALIGNMENT	(1 << 26)
 #define FUSE_SUBMOUNTS		(1 << 27)
+#define FUSE_HANDLE_KILLPRIV_V2	(1 << 28)
 
 /**
  * CUSE INIT request/reply flags
@@ -374,11 +385,14 @@ struct fuse_file_lock {
  *
  * FUSE_WRITE_CACHE: delayed write from page cache, file handle is guessed
  * FUSE_WRITE_LOCKOWNER: lock_owner field is valid
- * FUSE_WRITE_KILL_PRIV: kill suid and sgid bits
+ * FUSE_WRITE_KILL_SUIDGID: kill suid and sgid bits
  */
 #define FUSE_WRITE_CACHE	(1 << 0)
 #define FUSE_WRITE_LOCKOWNER	(1 << 1)
-#define FUSE_WRITE_KILL_PRIV	(1 << 2)
+#define FUSE_WRITE_KILL_SUIDGID (1 << 2)
+
+/* Obsolete alias; this flag implies killing suid/sgid only. */
+#define FUSE_WRITE_KILL_PRIV	FUSE_WRITE_KILL_SUIDGID
 
 /**
  * Read flags
@@ -427,6 +441,12 @@ struct fuse_file_lock {
  */
 #define FUSE_ATTR_SUBMOUNT      (1 << 0)
 
+/**
+ * Open flags
+ * FUSE_OPEN_KILL_SUIDGID: Kill suid and sgid if executable
+ */
+#define FUSE_OPEN_KILL_SUIDGID	(1 << 0)
+
 enum fuse_opcode {
 	FUSE_LOOKUP		= 1,
 	FUSE_FORGET		= 2,  /* no reply */
@@ -588,14 +608,14 @@ struct fuse_setattr_in {
 
 struct fuse_open_in {
 	uint32_t	flags;
-	uint32_t	unused;
+	uint32_t	open_flags;	/* FUSE_OPEN_... */
 };
 
 struct fuse_create_in {
 	uint32_t	flags;
 	uint32_t	mode;
 	uint32_t	umask;
-	uint32_t	padding;
+	uint32_t	open_flags;	/* FUSE_OPEN_... */
 };
 
 struct fuse_open_out {
include/standard-headers/linux/kernel.h +1 -8
index 1eeba2e..7848c5a 100644
@@ -3,13 +3,6 @@
 #define _LINUX_KERNEL_H
 
 #include "standard-headers/linux/sysinfo.h"
-
-/*
- * 'kernel.h' contains some often-used function prototypes etc
- */
-#define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
-#define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
-
-#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+#include "standard-headers/linux/const.h"
 
 #endif /* _LINUX_KERNEL_H */
include/standard-headers/linux/pci_regs.h +16 -0
index a95d55f..e709ae8 100644
@@ -531,6 +531,7 @@
 #define  PCI_EXP_LNKCAP_SLS_8_0GB 0x00000003 /* LNKCAP2 SLS Vector bit 2 */
 #define  PCI_EXP_LNKCAP_SLS_16_0GB 0x00000004 /* LNKCAP2 SLS Vector bit 3 */
 #define  PCI_EXP_LNKCAP_SLS_32_0GB 0x00000005 /* LNKCAP2 SLS Vector bit 4 */
+#define  PCI_EXP_LNKCAP_SLS_64_0GB 0x00000006 /* LNKCAP2 SLS Vector bit 5 */
 #define  PCI_EXP_LNKCAP_MLW	0x000003f0 /* Maximum Link Width */
 #define  PCI_EXP_LNKCAP_ASPMS	0x00000c00 /* ASPM Support */
 #define  PCI_EXP_LNKCAP_ASPM_L0S 0x00000400 /* ASPM L0s Support */
@@ -562,6 +563,7 @@
 #define  PCI_EXP_LNKSTA_CLS_8_0GB 0x0003 /* Current Link Speed 8.0GT/s */
 #define  PCI_EXP_LNKSTA_CLS_16_0GB 0x0004 /* Current Link Speed 16.0GT/s */
 #define  PCI_EXP_LNKSTA_CLS_32_0GB 0x0005 /* Current Link Speed 32.0GT/s */
+#define  PCI_EXP_LNKSTA_CLS_64_0GB 0x0006 /* Current Link Speed 64.0GT/s */
 #define  PCI_EXP_LNKSTA_NLW	0x03f0	/* Negotiated Link Width */
 #define  PCI_EXP_LNKSTA_NLW_X1	0x0010	/* Current Link Width x1 */
 #define  PCI_EXP_LNKSTA_NLW_X2	0x0020	/* Current Link Width x2 */
@@ -670,6 +672,7 @@
 #define  PCI_EXP_LNKCAP2_SLS_8_0GB	0x00000008 /* Supported Speed 8GT/s */
 #define  PCI_EXP_LNKCAP2_SLS_16_0GB	0x00000010 /* Supported Speed 16GT/s */
 #define  PCI_EXP_LNKCAP2_SLS_32_0GB	0x00000020 /* Supported Speed 32GT/s */
+#define  PCI_EXP_LNKCAP2_SLS_64_0GB	0x00000040 /* Supported Speed 64GT/s */
 #define  PCI_EXP_LNKCAP2_CROSSLINK	0x00000100 /* Crosslink supported */
 #define PCI_EXP_LNKCTL2		48	/* Link Control 2 */
 #define  PCI_EXP_LNKCTL2_TLS		0x000f
@@ -678,6 +681,7 @@
 #define  PCI_EXP_LNKCTL2_TLS_8_0GT	0x0003 /* Supported Speed 8GT/s */
 #define  PCI_EXP_LNKCTL2_TLS_16_0GT	0x0004 /* Supported Speed 16GT/s */
 #define  PCI_EXP_LNKCTL2_TLS_32_0GT	0x0005 /* Supported Speed 32GT/s */
+#define  PCI_EXP_LNKCTL2_TLS_64_0GT	0x0006 /* Supported Speed 64GT/s */
 #define  PCI_EXP_LNKCTL2_ENTER_COMP	0x0010 /* Enter Compliance */
 #define  PCI_EXP_LNKCTL2_TX_MARGIN	0x0380 /* Transmit Margin */
 #define  PCI_EXP_LNKCTL2_HASD		0x0020 /* HW Autonomous Speed Disable */
@@ -723,6 +727,7 @@
 #define PCI_EXT_CAP_ID_DPC	0x1D	/* Downstream Port Containment */
 #define PCI_EXT_CAP_ID_L1SS	0x1E	/* L1 PM Substates */
 #define PCI_EXT_CAP_ID_PTM	0x1F	/* Precision Time Measurement */
+#define PCI_EXT_CAP_ID_DVSEC	0x23	/* Designated Vendor-Specific */
 #define PCI_EXT_CAP_ID_DLF	0x25	/* Data Link Feature */
 #define PCI_EXT_CAP_ID_PL_16GT	0x26	/* Physical Layer 16.0 GT/s */
 #define PCI_EXT_CAP_ID_MAX	PCI_EXT_CAP_ID_PL_16GT
@@ -831,6 +836,13 @@
 #define  PCI_PWR_CAP_BUDGET(x)	((x) & 1)	/* Included in system budget */
 #define PCI_EXT_CAP_PWR_SIZEOF	16
 
+/* Root Complex Event Collector Endpoint Association  */
+#define PCI_RCEC_RCIEP_BITMAP	4	/* Associated Bitmap for RCiEPs */
+#define PCI_RCEC_BUSN		8	/* RCEC Associated Bus Numbers */
+#define  PCI_RCEC_BUSN_REG_VER	0x02	/* Least version with BUSN present */
+#define  PCI_RCEC_BUSN_NEXT(x)	(((x) >> 8) & 0xff)
+#define  PCI_RCEC_BUSN_LAST(x)	(((x) >> 16) & 0xff)
+
 /* Vendor-Specific (VSEC, PCI_EXT_CAP_ID_VNDR) */
 #define PCI_VNDR_HEADER		4	/* Vendor-Specific Header */
 #define  PCI_VNDR_HEADER_ID(x)	((x) & 0xffff)
@@ -1066,6 +1078,10 @@
 #define  PCI_L1SS_CTL1_LTR_L12_TH_SCALE	0xe0000000  /* LTR_L1.2_THRESHOLD_Scale */
 #define PCI_L1SS_CTL2		0x0c	/* Control 2 Register */
 
+/* Designated Vendor-Specific (DVSEC, PCI_EXT_CAP_ID_DVSEC) */
+#define PCI_DVSEC_HEADER1		0x4 /* Designated Vendor-Specific Header1 */
+#define PCI_DVSEC_HEADER2		0x8 /* Designated Vendor-Specific Header2 */
+
 /* Data Link Feature */
 #define PCI_DLF_CAP		0x04	/* Capabilities Register */
 #define  PCI_DLF_EXCHANGE_ENABLE	0x80000000  /* Data Link Feature Exchange Enable */
include/standard-headers/linux/vhost_types.h +9 -0
index 486630b..0bd2684 100644
@@ -138,6 +138,15 @@ struct vhost_vdpa_config {
 	uint8_t buf[0];
 };
 
+/* vhost vdpa IOVA range
+ * @first: First address that can be mapped by vhost-vDPA
+ * @last: Last address that can be mapped by vhost-vDPA
+ */
+struct vhost_vdpa_iova_range {
+	uint64_t first;
+	uint64_t last;
+};
+
 /* Feature bits */
 /* Log all write descriptors. Can be changed while device is active. */
 #define VHOST_F_LOG_ALL 26
include/standard-headers/linux/virtio_gpu.h +82 -0

116 lines not on this page · raw message

include/standard-headers/linux/virtio_ids.h +25 -19

49 lines not on this page · raw message

linux-headers/asm-arm64/kvm.h +0 -3
index a72de1a..b6a0eaa 100644
@@ -156,9 +156,6 @@ struct kvm_sync_regs {
 	__u64 device_irq_level;
 };
 
-struct kvm_arch_memory_slot {
-};
-
 /*
  * PMU filter structure. Describe a range of events with a particular
  * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER.
linux-headers/asm-generic/unistd.h +4 -2
index 2056318..7287529 100644
@@ -517,7 +517,7 @@ __SC_COMP(__NR_settimeofday, sys_settimeofday, compat_sys_settimeofday)
 __SC_3264(__NR_adjtimex, sys_adjtimex_time32, sys_adjtimex)
 #endif
 
-/* kernel/timer.c */
+/* kernel/sys.c */
 #define __NR_getpid 172
 __SYSCALL(__NR_getpid, sys_getpid)
 #define __NR_getppid 173
@@ -859,9 +859,11 @@ __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
 __SYSCALL(__NR_faccessat2, sys_faccessat2)
 #define __NR_process_madvise 440
 __SYSCALL(__NR_process_madvise, sys_process_madvise)
+#define __NR_epoll_pwait2 441
+__SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2)
 
 #undef __NR_syscalls
-#define __NR_syscalls 441
+#define __NR_syscalls 442
 
 /*
  * 32 bit systems traditionally used different
linux-headers/asm-mips/unistd_n32.h +1 -0
index aba284d..59e53b6 100644
@@ -370,6 +370,7 @@
 #define __NR_pidfd_getfd	(__NR_Linux + 438)
 #define __NR_faccessat2	(__NR_Linux + 439)
 #define __NR_process_madvise	(__NR_Linux + 440)
+#define __NR_epoll_pwait2	(__NR_Linux + 441)
 
 
 #endif /* _ASM_MIPS_UNISTD_N32_H */
linux-headers/asm-mips/unistd_n64.h +1 -0
index 0465ab9..683558a 100644
@@ -346,6 +346,7 @@
 #define __NR_pidfd_getfd	(__NR_Linux + 438)
 #define __NR_faccessat2	(__NR_Linux + 439)
 #define __NR_process_madvise	(__NR_Linux + 440)
+#define __NR_epoll_pwait2	(__NR_Linux + 441)
 
 
 #endif /* _ASM_MIPS_UNISTD_N64_H */
linux-headers/asm-mips/unistd_o32.h +1 -0
index 5222a0d..ca6a7e5 100644
@@ -416,6 +416,7 @@
 #define __NR_pidfd_getfd	(__NR_Linux + 438)
 #define __NR_faccessat2	(__NR_Linux + 439)
 #define __NR_process_madvise	(__NR_Linux + 440)
+#define __NR_epoll_pwait2	(__NR_Linux + 441)
 
 
 #endif /* _ASM_MIPS_UNISTD_O32_H */
linux-headers/asm-powerpc/unistd_32.h +1 -0
index 21066a3..4624c90 100644
@@ -423,6 +423,7 @@
 #define __NR_pidfd_getfd	438
 #define __NR_faccessat2	439
 #define __NR_process_madvise	440
+#define __NR_epoll_pwait2	441
 
 
 #endif /* _ASM_POWERPC_UNISTD_32_H */
linux-headers/asm-powerpc/unistd_64.h +1 -0
index c153da2..7e851b3 100644
@@ -395,6 +395,7 @@
 #define __NR_pidfd_getfd	438
 #define __NR_faccessat2	439
 #define __NR_process_madvise	440
+#define __NR_epoll_pwait2	441
 
 
 #endif /* _ASM_POWERPC_UNISTD_64_H */
linux-headers/asm-s390/unistd_32.h +1 -0
index 3b4f2dd..c94d2c3 100644
@@ -413,5 +413,6 @@
 #define __NR_pidfd_getfd 438
 #define __NR_faccessat2 439
 #define __NR_process_madvise 440
+#define __NR_epoll_pwait2 441
 
 #endif /* _ASM_S390_UNISTD_32_H */
linux-headers/asm-s390/unistd_64.h +1 -0
index 030a51f..984a06b 100644
@@ -361,5 +361,6 @@
 #define __NR_pidfd_getfd 438
 #define __NR_faccessat2 439
 #define __NR_process_madvise 440
+#define __NR_epoll_pwait2 441
 
 #endif /* _ASM_S390_UNISTD_64_H */
linux-headers/asm-x86/kvm.h +1 -0
index 89e5f3d..8e76d37 100644
@@ -12,6 +12,7 @@
 
 #define KVM_PIO_PAGE_OFFSET 1
 #define KVM_COALESCED_MMIO_PAGE_OFFSET 2
+#define KVM_DIRTY_LOG_PAGE_OFFSET 64
 
 #define DE_VECTOR 0
 #define DB_VECTOR 1
linux-headers/asm-x86/unistd_32.h +1 -0
index cfba368..18fb99d 100644
@@ -431,6 +431,7 @@
 #define __NR_pidfd_getfd 438
 #define __NR_faccessat2 439
 #define __NR_process_madvise 440
+#define __NR_epoll_pwait2 441
 
 
 #endif /* _ASM_X86_UNISTD_32_H */
linux-headers/asm-x86/unistd_64.h +1 -0
index 61af725..bde9593 100644
@@ -353,6 +353,7 @@
 #define __NR_pidfd_getfd 438
 #define __NR_faccessat2 439
 #define __NR_process_madvise 440
+#define __NR_epoll_pwait2 441
 
 
 #endif /* _ASM_X86_UNISTD_64_H */
linux-headers/asm-x86/unistd_x32.h +1 -0
index a6890cb..4ff6b17 100644
@@ -306,6 +306,7 @@
 #define __NR_pidfd_getfd (__X32_SYSCALL_BIT + 438)
 #define __NR_faccessat2 (__X32_SYSCALL_BIT + 439)
 #define __NR_process_madvise (__X32_SYSCALL_BIT + 440)
+#define __NR_epoll_pwait2 (__X32_SYSCALL_BIT + 441)
 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
 #define __NR_ioctl (__X32_SYSCALL_BIT + 514)
linux-headers/linux/kvm.h +57 -1

92 lines not on this page · raw message

linux-headers/linux/userfaultfd.h +9 -0
index 8d3996e..1ba9a9f 100644
@@ -257,4 +257,13 @@ struct uffdio_writeprotect {
 	__u64 mode;
 };
 
+/*
+ * Flags for the userfaultfd(2) system call itself.
+ */
+
+/*
+ * Create a userfaultfd that can handle page faults only in user mode.
+ */
+#define UFFD_USER_MODE_ONLY 1
+
 #endif /* _LINUX_USERFAULTFD_H */
linux-headers/linux/vfio.h +5 -0
index b92dcc4..f14e46c 100644
@@ -338,6 +338,10 @@ struct vfio_region_info_cap_type {
  * to do TLB invalidation on a GPU.
  */
 #define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD	(1)
+/*
+ * IBM zPCI I/O region
+ */
+#define VFIO_REGION_SUBTYPE_IBM_ZPCI_IO		(2)
 
 /* sub-types for VFIO_REGION_TYPE_GFX */
 #define VFIO_REGION_SUBTYPE_GFX_EDID            (1)
@@ -820,6 +824,7 @@ enum {
 enum {
 	VFIO_CCW_IO_IRQ_INDEX,
 	VFIO_CCW_CRW_IRQ_INDEX,
+	VFIO_CCW_REQ_IRQ_INDEX,
 	VFIO_CCW_NUM_IRQS
 };
 
linux-headers/linux/vfio_zdev.h +34 -0
index b430939..830acca 100644
@@ -43,6 +43,7 @@ struct vfio_device_info_cap_zpci_group {
 	__u64 msi_addr;		/* MSI address */
 	__u64 flags;
 #define VFIO_DEVICE_INFO_ZPCI_FLAG_REFRESH 1 /* Program-specified TLB refresh */
+#define VFIO_DEVICE_INFO_ZPCI_FLAG_RELAXED 2 /* Relaxed Length and Alignment */
 	__u16 mui;		/* Measurement Block Update Interval */
 	__u16 noi;		/* Maximum number of MSIs */
 	__u16 maxstbl;		/* Maximum Store Block Length */
@@ -75,4 +76,37 @@ struct vfio_device_info_cap_zpci_pfip {
 	__u8 pfip[];
 };
 
+/**
+ * VFIO_REGION_SUBTYPE_IBM_ZPCI_IO - VFIO zPCI PCI Direct I/O Region
+ *
+ * This region is used to transfer I/O operations from the guest directly
+ * to the host zPCI I/O layer.  The same instruction requested by the guest
+ * (e.g. PCISTB) will always be used, even if the MIO variant is available.
+ *
+ * The _hdr area is user-readable and is used to provide setup information.
+ * The _req area is user-writable and is used to provide the I/O operation.
+ */
+struct vfio_zpci_io_hdr {
+	__u64 flags;
+	__u16 max;		/* Max block operation size allowed */
+	__u16 reserved;
+	__u32 reserved2;
+};
+
+struct vfio_zpci_io_req {
+	__u64 flags;
+#define VFIO_ZPCI_IO_FLAG_READ (1 << 0) /* Read Operation Specified */
+#define VFIO_ZPCI_IO_FLAG_BLOCKW (1 << 1) /* Block Write Operation Specified */
+	__u64 gaddr;		/* Address of guest data */
+	__u64 offset;		/* Offset into target PCI Address Space */
+	__u32 reserved;
+	__u16 len;		/* Length of guest operation */
+	__u8 pcias;		/* Target PCI Address Space */
+	__u8 reserved2;
+};
+
+struct vfio_region_zpci_io {
+	struct vfio_zpci_io_hdr hdr;
+	struct vfio_zpci_io_req req;
+};
 #endif
linux-headers/linux/vhost.h +4 -0
index 7523218..c998860 100644
@@ -146,4 +146,8 @@
 
 /* Set event fd for config interrupt*/
 #define VHOST_VDPA_SET_CONFIG_CALL	_IOW(VHOST_VIRTIO, 0x77, int)
+
+/* Get the valid iova range */
+#define VHOST_VDPA_GET_IOVA_RANGE	_IOR(VHOST_VIRTIO, 0x78, \
+					     struct vhost_vdpa_iova_range)
 #endif
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/8 s390x/pci: MSI-X isn't strictly required for passthrough

In reply to Matthew Rosato

s390 PCI currently disallows PCI devices without the MSI-X capability. However, this fence doesn't make sense for passthrough devices. Move the check to only fence emulated devices (e.g., virtio).

---
 hw/s390x/s390-pci-bus.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
hw/s390x/s390-pci-bus.c +8 -6
index dd138da..dc732e2 100644
@@ -1028,12 +1028,12 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
             s390_pci_get_clp_info(pbdev);
         } else {
             pbdev->fh |= FH_SHM_EMUL;
-        }
 
-        if (s390_pci_msix_init(pbdev)) {
-            error_setg(errp, "MSI-X support is mandatory "
-                       "in the S390 architecture");
-            return;
+            if (s390_pci_msix_init(pbdev)) {
+                error_setg(errp, "MSI-X support is mandatory "
+                           "in the S390 architecture");
+                return;
+            }
         }
 
         if (dev->hotplugged) {
@@ -1073,7 +1073,9 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
         devfn = pci_dev->devfn;
         qdev_unrealize(dev);
 
-        s390_pci_msix_free(pbdev);
+        if (pbdev->fh & FH_SHM_EMUL) {
+            s390_pci_msix_free(pbdev);
+        }
         s390_pci_iommu_free(s, bus, devfn);
         pbdev->pdev = NULL;
         pbdev->state = ZPCI_FS_RESERVED;
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/8 s390x/pci: Introduce the ZpciOps structure

In reply to Matthew Rosato

As inftrastructure to introduce different PCI instruction handlers, introduce the ZpciOps structure to contain function pointers for the handlers. Add default handlers for the PCISTG, PCILG and PCISTB instructions.

---
 hw/s390x/s390-pci-bus.c          |   3 +
 hw/s390x/s390-pci-inst.c         | 246 ++++++++++++++++++++++++++-------------
 include/hw/s390x/s390-pci-bus.h  |  22 ++++
 include/hw/s390x/s390-pci-inst.h |   1 +
 4 files changed, 189 insertions(+), 83 deletions(-)
hw/s390x/s390-pci-bus.c +3 -0
index dc732e2..784ca65 100644
@@ -1020,6 +1020,7 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         pbdev->iommu->pbdev = pbdev;
         pbdev->state = ZPCI_FS_DISABLED;
         set_pbdev_info(pbdev);
+        zpci_assign_default_ops(pbdev);
 
         if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
             pbdev->fh |= FH_SHM_VFIO;
@@ -1079,6 +1080,8 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
         s390_pci_iommu_free(s, bus, devfn);
         pbdev->pdev = NULL;
         pbdev->state = ZPCI_FS_RESERVED;
+        if (pbdev->pcistb_buf)
+            qemu_vfree(pbdev->pcistb_buf);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
         pbdev = S390_PCI_DEVICE(dev);
         pbdev->fid = 0;
hw/s390x/s390-pci-inst.c +163 -83

322 lines not on this page · raw message

include/hw/s390x/s390-pci-bus.h +22 -0
index 0662e7b..7c34c5b 100644
@@ -325,6 +325,26 @@ typedef struct S390PCIGroup {
 S390PCIGroup *s390_group_create(int id);
 S390PCIGroup *s390_group_find(int id);
 
+typedef struct ZpciOps {
+    int (*pcistg)(S390PCIBusDevice *pbdev,
+                  uint64_t data,
+                  uint8_t pcias,
+                  uint16_t len,
+                  uint64_t offset);
+    int (*pcilg)(S390PCIBusDevice *pbdev,
+                 uint64_t *data,
+                 uint8_t pcias,
+                 uint16_t len,
+                 uint64_t offset);
+    int (*pcistb)(S390PCIBusDevice *pbdev,
+                  S390CPU *cpu,
+                  uint64_t gaddr,
+                  uint8_t ar,
+                  uint8_t pcias,
+                  uint16_t len,
+                  uint64_t offset);
+} ZpciOps;
+
 struct S390PCIBusDevice {
     DeviceState qdev;
     PCIDevice *pdev;
@@ -351,6 +371,8 @@ struct S390PCIBusDevice {
     MemoryRegion msix_notify_mr;
     IndAddr *summary_ind;
     IndAddr *indicator;
+    ZpciOps ops;
+    uint8_t *pcistb_buf;
     bool pci_unplug_request_processed;
     bool unplug_requested;
     QTAILQ_ENTRY(S390PCIBusDevice) link;
include/hw/s390x/s390-pci-inst.h +1 -0
index a55c448..c9fe3f1 100644
@@ -111,6 +111,7 @@ 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,
                          uintptr_t ra);
 void fmb_timer_free(S390PCIBusDevice *pbdev);
+void zpci_assign_default_ops(S390PCIBusDevice *pbdev);
 
 #define ZPCI_IO_BAR_MIN 0
 #define ZPCI_IO_BAR_MAX 5
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/8 s390x/pci: Handle devices that support relaxed alignment

In reply to Matthew Rosato

Certain zPCI device types (e.g. ISM) allow for a different set of address alignment rules for PCISTB instructions. Recognize this distinction and perform only a subset of alignment checks for intercepted PCISTB instructions. Furthermore for the default path, handle the potential for writes that are not aligned and sized to 8B chunks.

---
 hw/s390x/s390-pci-inst.c        | 152 +++++++++++++++++++++++++++++++++-------
 hw/s390x/s390-pci-vfio.c        |   3 +
 include/hw/s390x/s390-pci-clp.h |   1 +
 3 files changed, 132 insertions(+), 24 deletions(-)
hw/s390x/s390-pci-inst.c +128 -24
index 2d440a3..67eb4a4 100644
@@ -784,6 +784,92 @@ err:
     return 0;
 }
 
+static int pcistb_write_validate(MemoryRegion *mr, uint64_t offset,
+                                 uint16_t len)
+{
+    uint8_t size;
+
+    switch (offset & 0x07UL) {
+    case 0:
+        size = 8;
+        if (size <= len) {
+            break;
+        }
+        /* fall through */
+    case 4:
+        size = 4;
+        if (size <= len) {
+            break;
+        }
+        /* fall through */
+    case 6:
+    case 2:
+        size = 2;
+        if (size <= len) {
+            break;
+        }
+        /* fall through */
+    default:
+        size = 1;
+    }
+
+    if (!memory_region_access_valid(mr, offset, size, true,
+                                    MEMTXATTRS_UNSPECIFIED)) {
+        return -EINVAL;
+    }
+
+    return size;
+}
+
+static int pcistb_write(MemoryRegion *mr, uint8_t *buffer, uint64_t offset,
+                        uint16_t len)
+{
+    MemTxResult result;
+    uint64_t size;
+    uint64_t data;
+    MemOp opsize;
+
+    switch (offset & 0x07UL) {
+    case 0:
+        size = 8;
+        if (size <= len) {
+            opsize = MO_64;
+            data = ldq_p(buffer);
+            break;
+        }
+        /* fall through */
+    case 4:
+        size = 4;
+        if (size <= len) {
+            opsize = MO_32;
+            data = ldl_p(buffer);
+            break;
+        }
+        /* fall through */
+    case 6:
+    case 2:
+        size = 2;
+        if (size <= len) {
+            opsize = MO_16;
+            data = lduw_p(buffer);
+            break;
+        }
+        /* fall through */
+    default:
+        size = 1;
+        opsize = MO_8;
+        data = ldub_p(buffer);
+    }
+
+    result = memory_region_dispatch_write(mr, offset, data, opsize,
+                                          MEMTXATTRS_UNSPECIFIED);
+    if (result != MEMTX_OK) {
+        return -EINVAL;
+    }
+
+    return size;
+}
+
 /*
  * The default PCISTB handler will break PCISTB instructions into a series of
  * 8B memory operations.
@@ -792,32 +878,44 @@ static int pcistb_default(S390PCIBusDevice *pbdev, S390CPU *cpu,
                            uint64_t gaddr, uint8_t ar, uint8_t pcias,
                            uint16_t len, uint64_t offset)
 {
-    MemTxResult result;
     MemoryRegion *mr;
-    int i;
+    uint64_t curroff;
+    uint16_t currlen;
+    uint8_t *currbuff;
+    int size;
 
     mr = pbdev->pdev->io_regions[pcias].memory;
     mr = s390_get_subregion(mr, offset, len);
     offset -= mr->addr;
 
-    for (i = 0; i < len; i += 8) {
-        if (!memory_region_access_valid(mr, offset + i, 8, true,
-                                        MEMTXATTRS_UNSPECIFIED)) {
+    /* Loop over the proposed area and validate that writes will work. */
+    curroff = offset;
+    currlen = len;
+    while (currlen > 0) {
+        size = pcistb_write_validate(mr, curroff, currlen);
+        if (size <= 0) {
             return -EINVAL;
         }
+        curroff += size;
+        currlen -= size;
     }
 
     if (s390_cpu_virt_mem_read(cpu, gaddr, ar, pbdev->pcistb_buf, len)) {
         return -EACCES;
     }
 
-    for (i = 0; i < len; i += 8) {
-        result = memory_region_dispatch_write(mr, offset + i,
-                                              ldq_p(pbdev->pcistb_buf + i),
-                                              MO_64, MEMTXATTRS_UNSPECIFIED);
-        if (result != MEMTX_OK) {
+    /* Perform the chain of previously-validated writes */
+    currbuff = pbdev->pcistb_buf;
+    curroff = offset;
+    currlen = len;
+    while (currlen > 0) {
+        size = pcistb_write(mr, currbuff, curroff, currlen);
+        if (size < 0) {
             return -EINVAL;
         }
+        currbuff += size;
+        curroff += size;
+        currlen -= size;
     }
 
     return 0;
@@ -873,25 +971,31 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
         return 0;
     }
 
-    /* Verify the address, offset and length */
-    /* offset must be a multiple of 8 */
-    if (offset % 8) {
-        goto specification_error;
-    }
-    /* Length must be greater than 8, a multiple of 8 */
-    /* and not greater than maxstbl */
-    if ((len <= 8) || (len % 8) ||
-        (len > pbdev->pci_group->zpci_group.maxstbl)) {
-        goto specification_error;
+    /*
+     * If the specified device supports relaxed alignment, some checks can
+     * be skipped.
+     */
+    if (!(pbdev->pci_group->zpci_group.fr & CLP_RSP_QPCIG_MASK_RELAXED)) {
+        /* Verify the address, offset and length */
+        /* offset must be a multiple of 8 */
+        if (offset % 8) {
+            goto specification_error;
+        }
+        /* Length must be greater than 8, a multiple of 8 */
+        /* and not greater than maxstbl */
+        if ((len <= 8) || (len % 8) ||
+            (len > pbdev->pci_group->zpci_group.maxstbl)) {
+            goto specification_error;
+        }
+        /* Guest address must be double word aligned */
+        if (gaddr & 0x07UL) {
+            goto specification_error;
+        }
     }
     /* Do not cross a 4K-byte boundary */
     if (((offset & 0xfff) + len) > 0x1000) {
         goto specification_error;
     }
-    /* Guest address must be double word aligned */
-    if (gaddr & 0x07UL) {
-        goto specification_error;
-    }
 
     ret = pbdev->ops.pcistb(pbdev, cpu, gaddr, ar, pcias, len, offset);
 
hw/s390x/s390-pci-vfio.c +3 -0
index cb59e98..4cee640 100644
@@ -158,6 +158,9 @@ static void s390_pci_read_group(S390PCIBusDevice *pbdev,
         if (cap->flags & VFIO_DEVICE_INFO_ZPCI_FLAG_REFRESH) {
             resgrp->fr = 1;
         }
+        if (cap->flags & VFIO_DEVICE_INFO_ZPCI_FLAG_RELAXED) {
+            resgrp->fr |= CLP_RSP_QPCIG_MASK_RELAXED;
+        }
         resgrp->dasm = cap->dasm;
         resgrp->msia = cap->msi_addr;
         resgrp->mui = cap->mui;
include/hw/s390x/s390-pci-clp.h +1 -0
index 96b8e3f..73a28a0 100644
@@ -158,6 +158,7 @@ typedef struct ClpRspQueryPciGrp {
 #define CLP_RSP_QPCIG_MASK_NOI 0xfff
     uint16_t i;
     uint8_t version;
+#define CLP_RSP_QPCIG_MASK_RELAXED 0x8
 #define CLP_RSP_QPCIG_MASK_FRAME   0x2
 #define CLP_RSP_QPCIG_MASK_REFRESH 0x1
     uint8_t fr;
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 7/8 s390x/pci: PCILG via the vfio zPCI I/O region

In reply to Matthew Rosato

For ISM devices, use the vfio region to handle intercepted PCILG instructions. This will allow read I/Os intercepted from the guest to be performed as single operations that ensure the same non-MIO PCI instruction is used on the host as specified in the guest.

---
 hw/s390x/s390-pci-inst.c         |  3 ++-
 hw/s390x/s390-pci-vfio.c         | 53 ++++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/s390-pci-inst.h |  1 +
 include/hw/s390x/s390-pci-vfio.h |  8 ++++++
 4 files changed, 64 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-inst.c +2 -1
index 18a701f..97e9a7a 100644
@@ -352,7 +352,7 @@ out:
  * @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)
+int zpci_endian_swap(uint64_t *ptr, uint8_t len)
 {
     uint64_t data = *ptr;
 
@@ -1494,5 +1494,6 @@ void zpci_assign_default_ops(S390PCIBusDevice *pbdev)
 
 void zpci_assign_ops_vfio_io_region(S390PCIBusDevice *pbdev)
 {
+    pbdev->ops.pcilg = s390_pci_vfio_pcilg;
     pbdev->ops.pcistb = s390_pci_vfio_pcistb;
 }
hw/s390x/s390-pci-vfio.c +53 -0

59 lines not on this page · raw message

include/hw/s390x/s390-pci-inst.h +1 -0
index 7ed6175..fe368fb 100644
@@ -101,6 +101,7 @@ typedef struct ZpciFib {
 int pci_dereg_irqs(S390PCIBusDevice *pbdev);
 void pci_dereg_ioat(S390PCIIOMMU *iommu);
 int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_t ra);
+int zpci_endian_swap(uint64_t *ptr, uint8_t len);
 int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2, uintptr_t ra);
 int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2, uintptr_t ra);
 int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2, uintptr_t ra);
include/hw/s390x/s390-pci-vfio.h +8 -0
index f0a994f..d9fb3a4 100644
@@ -22,6 +22,8 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
 void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt);
 void s390_pci_get_clp_info(S390PCIBusDevice *pbdev);
 int s390_pci_get_zpci_io_region(S390PCIBusDevice *pbdev);
+int s390_pci_vfio_pcilg(S390PCIBusDevice *pbdev, uint64_t *data, uint8_t pcias,
+                        uint16_t len, uint64_t offset);
 int s390_pci_vfio_pcistb(S390PCIBusDevice *pbdev, S390CPU *cpu, uint64_t gaddr,
                          uint8_t ar, uint8_t pcias, uint16_t len,
                          uint64_t offset);
@@ -42,6 +44,12 @@ static inline int s390_pci_get_zpci_io_region(S390PCIBusDevice *pbdev)
 {
     return -EINVAL;
 }
+static inline int s390_pci_vfio_pcilg(S390PCIBusDevice *pbdev, uint64_t *data,
+                                      uint8_t pcias, uint16_t len,
+                                      uint64_t offset)
+{
+    return -EIO;
+}
 static inline int s390_pci_vfio_pcistb(S390PCIBusDevice *pbdev, S390CPU *cpu,
                                        uint64_t gaddr, uint8_t ar,
                                        uint8_t pcias, uint16_t len,
Signature · 1 line
1.8.3.1
#9 lore raw
In reply to Matthew Rosato
Quoted 33 lines · Matthew Rosato

Today, ISM devices are completely disallowed for vfio-pci passthrough as QEMU rejects the device due to an (inappropriate) MSI-X check. Removing this fence, however, reveals additional deficiencies in the s390x PCI interception layer that prevent ISM devices from working correctly. Namely, ISM block write operations have particular requirements in regards to the alignment, size and order of writes performed that cannot be guaranteed when breaking up write operations through the typical vfio_pci_bar_rw paths. Furthermore, ISM requires that legacy/non-MIO s390 PCI instructions are used, which is also not guaranteed when the I/O is passed through the typical userspace channels.

This patchset provides a set of fixes related to enabling ISM device passthrough and includes patches to enable use of a new vfio region that will allow s390x PCI pass-through devices to perform s390 PCI instructions in such a way that the same instruction issued on the guest is re-issued on the host.

Associated kernel patchset:
https://lkml.org/lkml/2021/1/19/874

Changes from RFC -> v1:
- Refresh the header sync (built using Eric's 'update-linux-headers:
Include const.h' + manually removed pvrdma_ring.h again)
- Remove s390x/pci: fix pcistb length (already merged)
- Remove s390x/pci: Fix memory_region_access_valid call (already merged)
- Fix bug: s390_pci_vfio_pcistb should use the pre-allocated PCISTB buffer pcistb_buf rather than allocating/freeing its own.
- New patch: track the PFT (PCI Function Type) separately from guest CLP response data -- we tell the guest '0' for now due to limitations in measurement block support, but we can still use the real value provided via the vfio CLP capabilities to make decisions.
- Use the PFT (pci function type) to determine when to use the region for PCISTB/PCILG (only for ISM), rather than using the relaxed alignment

Quoted 9 lines

bit.
- As a result, the pcistb_default is now updated to also handle the possibility of relaxed alignment via 2 new functions, pcistb_validate_write and pcistb_write, which serve as wrappers to the memory_region calls.
- New patch, which partially restores the MSI-X fence for passthrough devices... Could potentially be squashed with 's390x/pci: MSI-X isn't strictly required for passthrough' but left separately for now as I felt it needed a clear commit description of why we should still fence this case.

Hi,

The choice of using the new VFIO region is made on the ISM PCI function type (PFT), which makes the patch ISM specific, why don't we use here the MIO bit common to any zPCI function and present in kernel to make the choice?

Regards,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#10 lore raw
Quoted 45 lines · Pierre Morel
Quoted 33 lines · Matthew Rosato

Today, ISM devices are completely disallowed for vfio-pci passthrough as QEMU rejects the device due to an (inappropriate) MSI-X check.  Removing this fence, however, reveals additional deficiencies in the s390x PCI interception layer that prevent ISM devices from working correctly. Namely, ISM block write operations have particular requirements in regards to the alignment, size and order of writes performed that cannot be guaranteed when breaking up write operations through the typical vfio_pci_bar_rw paths. Furthermore, ISM requires that legacy/non-MIO s390 PCI instructions are used, which is also not guaranteed when the I/O is passed through the typical userspace channels.

This patchset provides a set of fixes related to enabling ISM device passthrough and includes patches to enable use of a new vfio region that will allow s390x PCI pass-through devices to perform s390 PCI instructions in such a way that the same instruction issued on the guest is re-issued on the host.

Associated kernel patchset:
https://lkml.org/lkml/2021/1/19/874

Changes from RFC -> v1:
- Refresh the header sync (built using Eric's 'update-linux-headers:
Include const.h' + manually removed pvrdma_ring.h again)
- Remove s390x/pci: fix pcistb length (already merged)
- Remove s390x/pci: Fix memory_region_access_valid call (already merged)
- Fix bug: s390_pci_vfio_pcistb should use the pre-allocated PCISTB buffer pcistb_buf rather than allocating/freeing its own.
- New patch: track the PFT (PCI Function Type) separately from guest CLP response data -- we tell the guest '0' for now due to limitations in measurement block support, but we can still use the real value provided via the vfio CLP capabilities to make decisions.
- Use the PFT (pci function type) to determine when to use the region for PCISTB/PCILG (only for ISM), rather than using the relaxed alignment

Quoted 9 lines

bit.
- As a result, the pcistb_default is now updated to also handle the possibility of relaxed alignment via 2 new functions, pcistb_validate_write and pcistb_write, which serve as wrappers to the memory_region calls.
- New patch, which partially restores the MSI-X fence for passthrough devices...  Could potentially be squashed with 's390x/pci: MSI-X isn't strictly required for passthrough' but left separately for now as I felt it needed a clear commit description of why we should still fence this case.

Quoted 4 lines

Hi,

The choice of using the new VFIO region is made on the ISM PCI function type (PFT), which makes the patch ISM specific, why don't we use here the MIO bit common to any zPCI function and present in kernel to make the choice?

As discussed during the RFC (and see my reply also to the kernel set), the use of this region only works for devices that do not rely on MSI-X interrupts. If we did as you suggest, other device types like mlx would not receive MSI-X interrupts in the guest (And I did indeed try variations where I used the special VFIO region for all PCISTG/PCILG/PCISTB for various device types)

So the idea for now was to solve the specific problem at hand (getting ISM devices working).

#11 lore raw
Quoted 46 lines · Matthew Rosato
Quoted 45 lines · Pierre Morel
Quoted 42 lines · Matthew Rosato

Today, ISM devices are completely disallowed for vfio-pci passthrough as QEMU rejects the device due to an (inappropriate) MSI-X check.  Removing this fence, however, reveals additional deficiencies in the s390x PCI interception layer that prevent ISM devices from working correctly. Namely, ISM block write operations have particular requirements in regards to the alignment, size and order of writes performed that cannot be guaranteed when breaking up write operations through the typical vfio_pci_bar_rw paths. Furthermore, ISM requires that legacy/non-MIO s390 PCI instructions are used, which is also not guaranteed when the I/O is passed through the typical userspace channels.

This patchset provides a set of fixes related to enabling ISM device passthrough and includes patches to enable use of a new vfio region that will allow s390x PCI pass-through devices to perform s390 PCI instructions in such a way that the same instruction issued on the guest is re-issued on the host.

Associated kernel patchset:
https://lkml.org/lkml/2021/1/19/874

Changes from RFC -> v1:
- Refresh the header sync (built using Eric's 'update-linux-headers:
Include const.h' + manually removed pvrdma_ring.h again)
- Remove s390x/pci: fix pcistb length (already merged)
- Remove s390x/pci: Fix memory_region_access_valid call (already merged)
- Fix bug: s390_pci_vfio_pcistb should use the pre-allocated PCISTB buffer pcistb_buf rather than allocating/freeing its own.
- New patch: track the PFT (PCI Function Type) separately from guest CLP response data -- we tell the guest '0' for now due to limitations in measurement block support, but we can still use the real value provided via the vfio CLP capabilities to make decisions.
- Use the PFT (pci function type) to determine when to use the region for PCISTB/PCILG (only for ISM), rather than using the relaxed alignment bit.
- As a result, the pcistb_default is now updated to also handle the possibility of relaxed alignment via 2 new functions, pcistb_validate_write and pcistb_write, which serve as wrappers to the memory_region calls.
- New patch, which partially restores the MSI-X fence for passthrough devices...  Could potentially be squashed with 's390x/pci: MSI-X isn't strictly required for passthrough' but left separately for now as I felt it needed a clear commit description of why we should still fence this case.

Quoted 10 lines
Quoted 4 lines

Hi,

The choice of using the new VFIO region is made on the ISM PCI function type (PFT), which makes the patch ISM specific, why don't we use here the MIO bit common to any zPCI function and present in kernel to make the choice?

As discussed during the RFC (and see my reply also to the kernel set), the use of this region only works for devices that do not rely on MSI-X interrupts.  If we did as you suggest, other device types like mlx would not receive MSI-X interrupts in the guest (And I did indeed try variations where I used the special VFIO region for all PCISTG/PCILG/PCISTB for various device types)

So the idea for now was to solve the specific problem at hand (getting ISM devices working).

Sorry, if I missed or forgot some discussions, but I understood that we are using this region to handle PCISTB instructions when the device do not support MIO. Don't we?

I do not understand the relation between MSI-X and MIO. Can you please explain?

Thanks,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#12 lore raw
Quoted 56 lines · Pierre Morel
Quoted 53 lines · Matthew Rosato
Quoted 51 lines · Pierre Morel
Quoted 35 lines · Matthew Rosato

Today, ISM devices are completely disallowed for vfio-pci passthrough as QEMU rejects the device due to an (inappropriate) MSI-X check. Removing this fence, however, reveals additional deficiencies in the s390x PCI interception layer that prevent ISM devices from working correctly. Namely, ISM block write operations have particular requirements in regards to the alignment, size and order of writes performed that cannot be guaranteed when breaking up write operations through the typical vfio_pci_bar_rw paths. Furthermore, ISM requires that legacy/non-MIO s390 PCI instructions are used, which is also not guaranteed when the I/O is passed through the typical userspace channels.

This patchset provides a set of fixes related to enabling ISM device passthrough and includes patches to enable use of a new vfio region that will allow s390x PCI pass-through devices to perform s390 PCI instructions in such a way that the same instruction issued on the guest is re-issued on the host.

Associated kernel patchset:
https://lkml.org/lkml/2021/1/19/874

Changes from RFC -> v1:
- Refresh the header sync (built using Eric's 'update-linux-headers:
Include const.h' + manually removed pvrdma_ring.h again)
- Remove s390x/pci: fix pcistb length (already merged)
- Remove s390x/pci: Fix memory_region_access_valid call (already merged)
- Fix bug: s390_pci_vfio_pcistb should use the pre-allocated PCISTB buffer pcistb_buf rather than allocating/freeing its own.
- New patch: track the PFT (PCI Function Type) separately from guest CLP
response data -- we tell the guest '0' for now due to limitations in measurement block support, but we can still use the real value provided via the vfio CLP capabilities to make decisions.
- Use the PFT (pci function type) to determine when to use the region for PCISTB/PCILG (only for ISM), rather than using the relaxed alignment

Quoted 9 lines

bit.
- As a result, the pcistb_default is now updated to also handle the possibility of relaxed alignment via 2 new functions, pcistb_validate_write and pcistb_write, which serve as wrappers to the memory_region calls.
- New patch, which partially restores the MSI-X fence for passthrough devices...  Could potentially be squashed with 's390x/pci: MSI-X isn't strictly required for passthrough' but left separately for now as I felt it needed a clear commit description of why we should still fence this case.

Hi,

The choice of using the new VFIO region is made on the ISM PCI function type (PFT), which makes the patch ISM specific, why don't we use here the MIO bit common to any zPCI function and present in kernel to make the choice?

Quoted 8 lines
Quoted 5 lines

As discussed during the RFC (and see my reply also to the kernel set), the use of this region only works for devices that do not rely on MSI-X interrupts.  If we did as you suggest, other device types like mlx would not receive MSI-X interrupts in the guest (And I did indeed try variations where I used the special VFIO region for all PCISTG/PCILG/PCISTB for various device types)

So the idea for now was to solve the specific problem at hand (getting ISM devices working).

Sorry, if I missed or forgot some discussions, but I understood that we are using this region to handle PCISTB instructions when the device do not support MIO. Don't we?

Sure thing - It's probably good to refresh the issue/rationale anyway as we've had the holidays in between.

You are correct, a primary reason we need to resort to a separate VFIO region for PCISTB (and PCILG) instructions for ISM devices is that they do not support the MIO instruction set, yet the host kernel will translate everything coming through the PCI I/O layer to MIO instructions whenever that facility is available to the host (and not purposely disabled). This issue is unique to vfio-pci/passthrough - in the host, the ISM driver directly invokes functions in s390 pci code to ensure that MIO instructions are not used.

But this is not the only reason. There are additional reasons for using this VFIO region:
1) ISM devices also don't support PCISTG instructions to certain address spaces and PCISTB must be used regardless of operation length. However the standard s390 PCI I/O path always uses PCISTG for anything <=8B. Trying to determine whether a given I/O is intended for an ISM device at that point in kernel code so as to use PCISTB instead of PCISTG is the same problem as attempting to decide whether to use MIO vs non-MIO instructions at that point.
2) It allows for much larger PCISTB operations (4K) than allowed via the memory regions (loop of 8B operations).
3) The above also has the added benefit of eliminating certain write pattern requirements that are unique to ISM that would be introduced if we split up the I/O into 8B chunks (if we can't write the whole PCISTB in one go, ISM requires data written in a certain order for some address spaces, or with certain bits on/off on the PCISTB instruction to signify the state of the larger operation)

Quoted 4 lines

I do not understand the relation between MSI-X and MIO. Can you please explain?

There is not a relation between MSI-X and MIO really. Rather, this is a case of the solution that is being offered here ONLY works for devices that use MSI -- and ISM is a device that only supports MSI. If you try to use this new VFIO region to pass I/O for an MSI-X enabled device, the notifiers set up via vfio_msix_setup won't be triggered because we are writing to the new VFIO region, not the virtual bar regions that may have had notifiers setup as part of vfio_msix_setup. This results in missing interrupts on MSI-X-enabled vfio-pci devices.

These notifiers aren't a factor when the device is using MSI.

#13 lore raw
Quoted 63 lines · Matthew Rosato
Quoted 62 lines · Pierre Morel
Quoted 58 lines · Matthew Rosato
Quoted 47 lines · Pierre Morel
Quoted 35 lines · Matthew Rosato

Today, ISM devices are completely disallowed for vfio-pci passthrough as QEMU rejects the device due to an (inappropriate) MSI-X check. Removing this fence, however, reveals additional deficiencies in the s390x PCI interception layer that prevent ISM devices from working correctly. Namely, ISM block write operations have particular requirements in regards to the alignment, size and order of writes performed that cannot be guaranteed when breaking up write operations through the typical vfio_pci_bar_rw paths. Furthermore, ISM requires that legacy/non-MIO s390 PCI instructions are used, which is also not guaranteed when the I/O is passed through the typical userspace channels.

This patchset provides a set of fixes related to enabling ISM device passthrough and includes patches to enable use of a new vfio region that will allow s390x PCI pass-through devices to perform s390 PCI instructions in such a way that the same instruction issued on the guest is re-issued on the host.

Associated kernel patchset:
https://lkml.org/lkml/2021/1/19/874

Changes from RFC -> v1:
- Refresh the header sync (built using Eric's 'update-linux-headers:
Include const.h' + manually removed pvrdma_ring.h again)
- Remove s390x/pci: fix pcistb length (already merged)
- Remove s390x/pci: Fix memory_region_access_valid call (already merged)
- Fix bug: s390_pci_vfio_pcistb should use the pre-allocated PCISTB buffer pcistb_buf rather than allocating/freeing its own.
- New patch: track the PFT (PCI Function Type) separately from guest CLP
response data -- we tell the guest '0' for now due to limitations in measurement block support, but we can still use the real value provided via the vfio CLP capabilities to make decisions.
- Use the PFT (pci function type) to determine when to use the region for PCISTB/PCILG (only for ISM), rather than using the relaxed alignment

Quoted 9 lines

bit.
- As a result, the pcistb_default is now updated to also handle the possibility of relaxed alignment via 2 new functions, pcistb_validate_write and pcistb_write, which serve as wrappers to the memory_region calls.
- New patch, which partially restores the MSI-X fence for passthrough devices...  Could potentially be squashed with 's390x/pci: MSI-X isn't strictly required for passthrough' but left separately for now as I felt it needed a clear commit description of why we should still fence this case.

Quoted 4 lines

Hi,

The choice of using the new VFIO region is made on the ISM PCI function type (PFT), which makes the patch ISM specific, why don't we use here the MIO bit common to any zPCI function and present in kernel to make the choice?

As discussed during the RFC (and see my reply also to the kernel set), the use of this region only works for devices that do not rely on MSI-X interrupts.  If we did as you suggest, other device types like mlx would not receive MSI-X interrupts in the guest (And I did indeed try variations where I used the special VFIO region for all PCISTG/PCILG/PCISTB for various device types)

So the idea for now was to solve the specific problem at hand (getting ISM devices working).

Quoted 6 lines
Quoted 2 lines

Sorry, if I missed or forgot some discussions, but I understood that we are using this region to handle PCISTB instructions when the device do not support MIO. Don't we?

Sure thing - It's probably good to refresh the issue/rationale anyway as we've had the holidays in between.

You are correct, a primary reason we need to resort to a separate VFIO region for PCISTB (and PCILG) instructions for ISM devices is that they do not support the MIO instruction set, yet the host kernel will translate everything coming through the PCI I/O layer to MIO instructions whenever that facility is available to the host (and not purposely disabled).  This issue is unique to vfio-pci/passthrough - in the host, the ISM driver directly invokes functions in s390 pci code to ensure that MIO instructions are not used.

QEMU intercepts and differentiates PCISTG and PCISTB. The new hardware support both MIO and legacy PCISTB/PCISTG.

QEMU does not support MIO

My first interrogation is why should we translate legacy to MIO?

But OK, say we do need this for some obscure reason.

Quoted 3 lines

But this is not the only reason.  There are additional reasons for using this VFIO region:
1) ISM devices also don't support PCISTG instructions to certain address spaces and PCISTB must be used regardless of operation length.  However the standard s390 PCI I/O path always uses PCISTG for anything <=8B. Trying to determine whether a given I/O is intended for an ISM device at that point in kernel code so as to use PCISTB instead of PCISTG is the

OK, this is clear.

Quoted 1 line

same problem as attempting to decide whether to use MIO vs non-MIO instructions at that point.

humm, this is not exactly the same problem for me, but OK to choose to handle it the same way.

Quoted 1 line

2) It allows for much larger PCISTB operations (4K) than allowed via the memory regions (loop of 8B operations).

OK

Quoted 1 line

3) The above also has the added benefit of eliminating certain write pattern requirements that are unique to ISM that would be introduced if we split up the I/O into 8B chunks (if we can't write the whole PCISTB in one go, ISM requires data written in a certain order for some address spaces, or with certain bits on/off on the PCISTB instruction to signify the state of the larger operation)

Yes, I suppose that the driver in the guest does it right and we need to do the same.

Quoted 9 lines
Quoted 5 lines

I do not understand the relation between MSI-X and MIO. Can you please explain?

There is not a relation between MSI-X and MIO really.  Rather, this is a case of the solution that is being offered here ONLY works for devices that use MSI -- and ISM is a device that only supports MSI.  If you try to use this new VFIO region to pass I/O for an MSI-X enabled device, the notifiers set up via vfio_msix_setup won't be triggered because we are writing to the new VFIO region, not the virtual bar regions that may have had notifiers setup as part of vfio_msix_setup.  This results in missing interrupts on MSI-X-enabled vfio-pci devices.

These notifiers aren't a factor when the device is using MSI.

I find this strange but we do not need to discuss it.

Quoted 1 line

So we have:
devices supporting MIO and MSIX
devices not supporting MIO nor MSIX
devices not supporting the use of PCISTG to emulate PCISTB

The first two are two different things indicated by two different entries in the clp query PCI function response.

The last one, we do not have an indicator as if the relaxed alignment and length is set, PCISTB can not be emulated with PCISTG

What I mean with this is that considering the proposed implementation and considering:
MIO MSIX RELAX

0 0 1 -> must use the new region (ISM)
1 1 0 -> must use the standard VFIO region (MLX)

we can discuss other 6 possibilities

0 0 0 -> must use the new region
0 1 0 -> NOOP
0 1 1 -> NOOP
1 0 0 -> can use any region
1 0 1 -> can use any region
1 1 1 -> NOOP

In my opinion the test for using one region or another should be done on these indicator instead of using the PFT. This may offer us more compatibility with other hardware we may not be aware of as today.

Regards,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#14 lore raw
Quoted 74 lines · Pierre Morel
Quoted 63 lines · Matthew Rosato
Quoted 62 lines · Pierre Morel
Quoted 58 lines · Matthew Rosato
Quoted 47 lines · Pierre Morel
Quoted 35 lines · Matthew Rosato

Today, ISM devices are completely disallowed for vfio-pci passthrough as QEMU rejects the device due to an (inappropriate) MSI-X check. Removing this fence, however, reveals additional deficiencies in the s390x PCI interception layer that prevent ISM devices from working correctly. Namely, ISM block write operations have particular requirements in regards to the alignment, size and order of writes performed that cannot be guaranteed when breaking up write operations through the typical vfio_pci_bar_rw paths. Furthermore, ISM requires that legacy/non-MIO s390 PCI instructions are used, which is also not guaranteed when the I/O is passed through the typical userspace channels.

This patchset provides a set of fixes related to enabling ISM device passthrough and includes patches to enable use of a new vfio region that will allow s390x PCI pass-through devices to perform s390 PCI instructions in such a way that the same instruction issued on the guest is re-issued on the host.

Associated kernel patchset:
https://lkml.org/lkml/2021/1/19/874

Changes from RFC -> v1:
- Refresh the header sync (built using Eric's 'update-linux-headers:
Include const.h' + manually removed pvrdma_ring.h again)
- Remove s390x/pci: fix pcistb length (already merged)
- Remove s390x/pci: Fix memory_region_access_valid call (already merged)
- Fix bug: s390_pci_vfio_pcistb should use the pre-allocated PCISTB buffer pcistb_buf rather than allocating/freeing its own.
- New patch: track the PFT (PCI Function Type) separately from guest CLP
response data -- we tell the guest '0' for now due to limitations in measurement block support, but we can still use the real value provided via the vfio CLP capabilities to make decisions.
- Use the PFT (pci function type) to determine when to use the region for PCISTB/PCILG (only for ISM), rather than using the relaxed alignment

Quoted 9 lines

bit.
- As a result, the pcistb_default is now updated to also handle the possibility of relaxed alignment via 2 new functions, pcistb_validate_write and pcistb_write, which serve as wrappers to the memory_region calls.
- New patch, which partially restores the MSI-X fence for passthrough devices...  Could potentially be squashed with 's390x/pci: MSI-X isn't strictly required for passthrough' but left separately for now as I felt it needed a clear commit description of why we should still fence this case.

Quoted 4 lines

Hi,

The choice of using the new VFIO region is made on the ISM PCI function type (PFT), which makes the patch ISM specific, why don't we use here the MIO bit common to any zPCI function and present in kernel to make the choice?

As discussed during the RFC (and see my reply also to the kernel set), the use of this region only works for devices that do not rely on MSI-X interrupts.  If we did as you suggest, other device types like mlx would not receive MSI-X interrupts in the guest (And I did indeed try variations where I used the special VFIO region for all PCISTG/PCILG/PCISTB for various device types)

So the idea for now was to solve the specific problem at hand (getting ISM devices working).

Quoted 6 lines
Quoted 2 lines

Sorry, if I missed or forgot some discussions, but I understood that we are using this region to handle PCISTB instructions when the device do not support MIO. Don't we?

Sure thing - It's probably good to refresh the issue/rationale anyway as we've had the holidays in between.

You are correct, a primary reason we need to resort to a separate VFIO region for PCISTB (and PCILG) instructions for ISM devices is that they do not support the MIO instruction set, yet the host kernel will translate everything coming through the PCI I/O layer to MIO instructions whenever that facility is available to the host (and not purposely disabled).  This issue is unique to vfio-pci/passthrough - in the host, the ISM driver directly invokes functions in s390 pci code to ensure that MIO instructions are not used.

Quoted 6 lines

QEMU intercepts and differentiates PCISTG and PCISTB. The new hardware support both MIO and legacy PCISTB/PCISTG.

QEMU does not support MIO

My first interrogation is why should we translate legacy to MIO?

This is existing behavior of the s390 kernel PCI layer, not something I'm introducing here.

So, as you say, QEMU does not support MIO, nor does it attempt to translate anything to MIO. The thing is, to the host kernel, PCI I/O coming from QEMU through the standard vfio-pci codepath just looks like any other userspace PCI I/O coming in to the kernel. So the memory_region operations against the vfio virtual address space bars in QEMU then turn into iowrite/ioread operations in vfio-pci in the kernel, which then subsequently end up in the s390 PCI kernel layer, and it's there that everything is turned into an MIO operation if MIO is available. That's not limited to vfio-pci, that's all PCI I/O in the host (except for the ISM driver, which bypasses this behavior by invoking s390 PCI kernel interfaces directly).

In an early (internal) version of the kernel component to this I floated the idea of trying to determine whether or not MIO instructions could be used for a given I/O operation, but the ideas I floated had various flaws -- I'd invite Niklas to chime in with why this got squashed.

But anyway... If we were to solve that somehow, this would still leave us with write operations capped at 8B and odd write pattern requirements for ISM passthrough. Using a VFIO region to pass the operation directly to the host kernel via a pinned page to overcome those limitations was your idea actually :)

Quoted 4 lines

But OK, say we do need this for some obscure reason.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

But this is not the only reason.  There are additional reasons for using this VFIO region:
1) ISM devices also don't support PCISTG instructions to certain address spaces and PCISTB must be used regardless of operation length.  However the standard s390 PCI I/O path always uses PCISTG for anything <=8B. Trying to determine whether a given I/O is intended for an ISM device at that point in kernel code so as to use PCISTB instead of PCISTG is the

OK, this is clear.

Quoted 1 line

same problem as attempting to decide whether to use MIO vs non-MIO instructions at that point.

humm, this is not exactly the same problem for me, but OK to choose to handle it the same way.

The problem isn't the same BUT the information needed to solve the problem is the same (for a given memory operation, knowing what device/type it is intended for, which can therefore be used to determine also whether it supports MIO or not).

Quoted 50 lines
Quoted 4 lines

2) It allows for much larger PCISTB operations (4K) than allowed via the memory regions (loop of 8B operations).

OK

Quoted 1 line

3) The above also has the added benefit of eliminating certain write pattern requirements that are unique to ISM that would be introduced if we split up the I/O into 8B chunks (if we can't write the whole PCISTB in one go, ISM requires data written in a certain order for some address spaces, or with certain bits on/off on the PCISTB instruction to signify the state of the larger operation)

Yes, I suppose that the driver in the guest does it right and we need to do the same.

Quoted 9 lines
Quoted 5 lines

I do not understand the relation between MSI-X and MIO. Can you please explain?

There is not a relation between MSI-X and MIO really.  Rather, this is a case of the solution that is being offered here ONLY works for devices that use MSI -- and ISM is a device that only supports MSI. If you try to use this new VFIO region to pass I/O for an MSI-X enabled device, the notifiers set up via vfio_msix_setup won't be triggered because we are writing to the new VFIO region, not the virtual bar regions that may have had notifiers setup as part of vfio_msix_setup.  This results in missing interrupts on MSI-X-enabled vfio-pci devices.

These notifiers aren't a factor when the device is using MSI.

I find this strange but we do not need to discuss it.

Quoted 1 line

So we have:
devices supporting MIO and MSIX
devices not supporting MIO nor MSIX
devices not supporting the use of PCISTG to emulate PCISTB

The first two are two different things indicated by two different entries in the clp query PCI function response.

The last one, we do not have an indicator as if the relaxed alignment and length is set, PCISTB can not be emulated with PCISTG

What I mean with this is that considering the proposed implementation and considering:
MIO MSIX RELAX

0 0 1  -> must use the new region (ISM)
1 1 0  -> must use the standard VFIO region (MLX)

we can discuss other 6 possibilities

0 0 0 -> must use the new region
0 1 0 -> NOOP
0 1 1 -> NOOP
1 0 0 -> can use any region
1 0 1 -> can use any region
1 1 1 -> NOOP

Quoted 2 lines

In my opinion the test for using one region or another should be done on these indicator instead of using the PFT. > This may offer us more compatibility with other hardware we may not be aware of as today.

This gets a little shaky, and goes both ways -- Using your list, a device that supports MIO, does not have MSI-X capability and doesn't support relaxed alignment (1 0 0 from above) can use any region -- but that may not always be true. What if "other hardware we may not be aware of as today" includes future hardware that ONLY supports the MIO instruction set? Then that device really can't use this region either.

But forgetting that possibility... I think we can really simplify the above matrix down to a statement of "if device doesn't support MSI-X but DOES support non-MIO instructions, it can use the region." I believe the latter half of that statement is implicit in the architecture today, so it's really then "if device doesn't support MSI-X, it can use the region". There's just the caveat of, if the device is ISM, it changes from 'can use the region' to 'must use the region'.

So, I mean I can change the code to be more permissive in that way (allow any device that doesn't have MSI-X capability to at least attempt to use the region). But the reality is that ISM specifically needs the region for successful pass through, so I don't see a reason to create a different bit for that vs just checking for the PFT in QEMU and using that value to decide whether or not region availability is a requirement for allowing the device to pass through.

#15 lore raw
Quoted 3 lines · Matthew Rosato
Quoted 2 lines · Pierre Morel

...snip...

Quoted 8 lines
Quoted 8 lines

So we have:
devices supporting MIO and MSIX
devices not supporting MIO nor MSIX
devices not supporting the use of PCISTG to emulate PCISTB

The first two are two different things indicated by two different entries in the clp query PCI function response.

The last one, we do not have an indicator as if the relaxed alignment and length is set, PCISTB can not be emulated with PCISTG

hum sorry, it seems I rewrote my sentence until it was wrong wrong! I wanted to say we DO HAVE an indicator with the relaxed bit...

Quoted 16 lines
Quoted 16 lines

What I mean with this is that considering the proposed implementation and considering:
MIO MSIX RELAX

0 0 1  -> must use the new region (ISM)
1 1 0  -> must use the standard VFIO region (MLX)

we can discuss other 6 possibilities

0 0 0 -> must use the new region
0 1 0 -> NOOP
0 1 1 -> NOOP
1 0 0 -> can use any region
1 0 1 -> can use any region
1 1 1 -> NOOP

Quoted 4 lines
Quoted 2 lines

In my opinion the test for using one region or another should be done on these indicator instead of using the PFT. > This may offer us more compatibility with other hardware we may not be aware of as today.

This gets a little shaky, and goes both ways -- Using your list, a device that supports MIO, does not have MSI-X capability and doesn't support relaxed alignment (1 0 0 from above) can use any region -- but that may not always be true.  What if "other hardware we may not be aware of as today" includes future hardware that ONLY supports the MIO instruction set?  Then that device really can't use this region either.

Right, but there is no bit in the CLP response for this case. Until there is one, the system is supposed to handle legacy instructions

Quoted 2 lines

But forgetting that possibility...  I think we can really simplify the above matrix down to a statement of "if device doesn't support MSI-X but DOES support non-MIO instructions, it can use the region."  I believe the latter half of that statement is implicit in the architecture today, so it's really then "if device doesn't support MSI-X, it can use the region".  There's just the caveat of, if the device is ISM, it changes from 'can use the region' to 'must use the region'.

There can surely be simplifications.

Quoted 2 lines

So, I mean I can change the code to be more permissive in that way (allow any device that doesn't have MSI-X capability to at least attempt to use the region).  But the reality is that ISM specifically needs the region for successful pass through, so I don't see a reason to create a different bit for that vs just checking for the PFT in QEMU and using that value to decide whether or not region availability is a requirement for allowing the device to pass through.

There is no need for a new bit to know if a device support MIO or not, as I said before, there is already one in the CLP query PCI function response and it is already used in the kernel zPCI architecture.

It is not a big think to do and does not change the general architecture of the patch, only the detection of which device is impacted to make it generic instead of device dedicated.

Regards,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#16 lore raw
Quoted 12 lines · Pierre Morel
Quoted 3 lines · Matthew Rosato
Quoted 2 lines · Pierre Morel

...snip...

Quoted 2 lines

So, I mean I can change the code to be more permissive in that way (allow any device that doesn't have MSI-X capability to at least attempt to use the region).  But the reality is that ISM specifically needs the region for successful pass through, so I don't see a reason to create a different bit for that vs just checking for the PFT in QEMU and using that value to decide whether or not region availability is a requirement for allowing the device to pass through.

Quoted 7 lines

There is no need for a new bit to know if a device support MIO or not, as I said before, there is already one in the CLP query PCI function response and it is already used in the kernel zPCI architecture.

It is not a big think to do and does not change the general architecture of the patch, only the detection of which device is impacted to make it generic instead of device dedicated.

Regards,
Pierre

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

One other point for me is that all these special requirements seem to stem from the fact that ISM is not a physical PCIe device but a special s390 only thing. That also implies that unlike with real PCI devices we are not going to find an existing Linux driver and infrastructure that just works. I'd bet if it's anywhere as special as ISM we will also need a QEMU change either way and if that change is only to change the PFT check then great, won't have trouble getting that backported...
So the PFT check ensures we're definitely trying the standard path first and only change it to a special case if we understand that it is required as we do for ISM.

That said it's also important to note that we are not searching for a be all end all solution here. The standard path's to-MIO translation, even though it is working, is weird enough and also not ideal for performance so we might look at that again in separate work and yes that could change things for this case too but that too will require QEMU and Kernel changes either way.
Furthermore we will be looking into handling more PCI without leaving SIE at which point we will also re-evaluate if that works for ISM. Again that needs QEMU and likely Kernel changes. I'm a great fan of general solutions that don't unnecessarily exclude something, so I do understand your concern but let's focus on what we know and want to fix now instead of trying to solve future theoretical issues that we have no strong reason to believe will ever appear.

If we stick with the PFT check I think we do need to change some wording especially for the Kernel changes.

Quoted 1 line
#17 lore raw
Quoted 20 lines · Niklas Schnelle
Quoted 17 lines · Pierre Morel
Quoted 3 lines · Matthew Rosato
Quoted 2 lines · Pierre Morel

...snip...

Quoted 2 lines

So, I mean I can change the code to be more permissive in that way (allow any device that doesn't have MSI-X capability to at least attempt to use the region).  But the reality is that ISM specifically needs the region for successful pass through, so I don't see a reason to create a different bit for that vs just checking for the PFT in QEMU and using that value to decide whether or not region availability is a requirement for allowing the device to pass through.

There is no need for a new bit to know if a device support MIO or not, as I said before, there is already one in the CLP query PCI function response and it is already used in the kernel zPCI architecture.

It is not a big think to do and does not change the general architecture of the patch, only the detection of which device is impacted to make it generic instead of device dedicated.

Quoted 7 lines
Quoted 2 lines

Regards,
Pierre

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

If we keep the PFT check, and we can do this of course, but is it a good solution if it appears we have other PFT with the same functionalities?

Please note that this is a minor code change, keeping track of the MIO support just as we keep track of the PFT and check on this instead of on the PFT.

It does not modify the general architecture of the patch series neither in kernel nor in QEMU at all.

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#18 lore raw
Quoted 31 lines · Pierre Morel
Quoted 20 lines · Niklas Schnelle
Quoted 17 lines · Pierre Morel
Quoted 3 lines · Matthew Rosato
Quoted 2 lines · Pierre Morel

...snip...

Quoted 2 lines

So, I mean I can change the code to be more permissive in that way (allow any device that doesn't have MSI-X capability to at least attempt to use the region).  But the reality is that ISM specifically needs the region for successful pass through, so I don't see a reason to create a different bit for that vs just checking for the PFT in QEMU and using that value to decide whether or not region availability is a requirement for allowing the device to pass through.

There is no need for a new bit to know if a device support MIO or not, as I said before, there is already one in the CLP query PCI function response and it is already used in the kernel zPCI architecture.

It is not a big think to do and does not change the general architecture of the patch, only the detection of which device is impacted to make it generic instead of device dedicated.

Quoted 7 lines
Quoted 2 lines

Regards,
Pierre

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

Quoted 5 lines

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

Yes but that goes both ways the functionality of the region has to match that of the device and at least in it's current state the regions functionality matches only ISM in a way that is so specific that it is very unlikely to match anything else. For example it can't support a PCI device that requires non-MIO but also MSI-X. In its current form it doesn't even support PCI Store only PCI Store Block, we had that in an earlier version and it's trivial but then we get the MSI-X problem.

Quoted 5 lines

If we keep the PFT check, and we can do this of course, but is it a good solution if it appears we have other PFT with the same functionalities?

Please note that this is a minor code change, keeping track of the MIO support just as we keep track of the PFT and check on this instead of on the PFT.

That is certainly true and I'm not strongly against matching on functionality it just seems to me that it's too specific for that to make sense and in that case I feel it's better to be clear about that and make it ISM specific in name and functionality.

If we manage to find a fix for the MSI-X problem which I'd be really happy about we can simply extend the regions functionality and reuse the same code for a backwards compatibile ISM region and a more generic zPCI non-MIO region that could even be used if the client (QEMU) uses non-MIO and the device can do both as is the case for all current physical devices.

Quoted 6 lines

It does not modify the general architecture of the patch series neither in kernel nor in QEMU at all.

Pierre

#25 lore raw
In reply to Pierre Morel
Quoted 13 lines · Pierre Morel
Quoted 3 lines · Matthew Rosato
Quoted 2 lines · Pierre Morel

...snip...

Quoted 5 lines
Quoted 5 lines

So we have:
devices supporting MIO and MSIX
devices not supporting MIO nor MSIX
devices not supporting the use of PCISTG to emulate PCISTB

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

The first two are two different things indicated by two different entries in the clp query PCI function response.

The last one, we do not have an indicator as if the relaxed alignment and length is set, PCISTB can not be emulated with PCISTG

hum sorry, it seems I rewrote my sentence until it was wrong wrong! I wanted to say we DO HAVE an indicator with the relaxed bit...

That's actually not quite true though... The relaxed bit does not directly imply that PCISTB cannot be emulated with PCISTG. Rather, it more generally implies that PCISTB could be used instead of PCISTG as the length and alignment requirements for PCISTB are waived. As far as I can tell, disallowing a PCISTG altogether is a trait that is unique to ISM and I don't see anywhere that it's otherwise indicated in architecture... And in fact, for a given ISM device, certain address spaces (command) WILL accept a series of PCISTG issued in a particular manner in place of a PCISTB; meanwhile other ISM address spaces (data) will not accept any PCISTG ever. :( The ISM driver just always uses PCISTB.

So that is why I suggested type==ISM must require use of the region whereas other types that implement MSI could request (but not require) use of the region.

But yes, any other theoretical piece of hardware that also does not support MIO would have a similar region requirement. I'll have a look at the MIO bit you referenced below and will have to verify that it does exactly what we expect for an ISM device. Assuming yes, I will consider the following sort of checking for the next version of QEMU...

if (!MIO) {
	if (MSIX) {
		// passthrough disallowed
	}
	else {
		// region required, disallow if unavailable
	}
}
else if(RELAX && !MSIX) {
	// use region if available
}

Sound good?

All said, this would result in another bit passed from the kernel as CLP info and some small changes to patch 6 of this set to determine when to call s390_pci_get_zpci_io_region(pbdev) -- But just about everything else is unaffected, so @all please feel free to provide other review comments for the series in the meanwhile.

Quoted 44 lines
Quoted 17 lines
Quoted 17 lines

What I mean with this is that considering the proposed implementation and considering:
MIO MSIX RELAX

0 0 1  -> must use the new region (ISM)
1 1 0  -> must use the standard VFIO region (MLX)

we can discuss other 6 possibilities

0 0 0 -> must use the new region
0 1 0 -> NOOP
0 1 1 -> NOOP
1 0 0 -> can use any region
1 0 1 -> can use any region
1 1 1 -> NOOP

Quoted 4 lines
Quoted 2 lines

In my opinion the test for using one region or another should be done on these indicator instead of using the PFT. > This may offer us more compatibility with other hardware we may not be aware of as today.

This gets a little shaky, and goes both ways -- Using your list, a device that supports MIO, does not have MSI-X capability and doesn't support relaxed alignment (1 0 0 from above) can use any region -- but that may not always be true.  What if "other hardware we may not be aware of as today" includes future hardware that ONLY supports the MIO instruction set?  Then that device really can't use this region either.

Right, but there is no bit in the CLP response for this case. Until there is one, the system is supposed to handle legacy instructions

Quoted 2 lines

But forgetting that possibility...  I think we can really simplify the above matrix down to a statement of "if device doesn't support MSI-X but DOES support non-MIO instructions, it can use the region."  I believe the latter half of that statement is implicit in the architecture today, so it's really then "if device doesn't support MSI-X, it can use the region".  There's just the caveat of, if the device is ISM, it changes from 'can use the region' to 'must use the region'.

There can surely be simplifications.

Quoted 2 lines

So, I mean I can change the code to be more permissive in that way (allow any device that doesn't have MSI-X capability to at least attempt to use the region).  But the reality is that ISM specifically needs the region for successful pass through, so I don't see a reason to create a different bit for that vs just checking for the PFT in QEMU and using that value to decide whether or not region availability is a requirement for allowing the device to pass through.

There is no need for a new bit to know if a device support MIO or not, as I said before, there is already one in the CLP query PCI function response and it is already used in the kernel zPCI architecture.

It is not a big think to do and does not change the general architecture of the patch, only the detection of which device is impacted to make it generic instead of device dedicated.

Regards,
Pierre

#19 lore raw
In reply to Niklas Schnelle
Quoted 16 lines · Niklas Schnelle
Quoted 11 lines · Pierre Morel
Quoted 5 lines

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

Quoted 7 lines

Yes but that goes both ways the functionality of the region has to match that of the device and at least in it's current state the regions functionality matches only ISM in a way that is so specific that it is very unlikely to match anything else. For example it can't support a PCI device that requires non-MIO but also MSI-X. In its current form it doesn't even support PCI Store only PCI Store Block, we had that in an earlier version and it's trivial but then we get the MSI-X problem.

What does that change if we take one or the other solution considering the checking of MIO/MSIX/relax versus PFT?

Quoted 12 lines
Quoted 6 lines

If we keep the PFT check, and we can do this of course, but is it a good solution if it appears we have other PFT with the same functionalities?

Please note that this is a minor code change, keeping track of the MIO support just as we keep track of the PFT and check on this instead of on the PFT.

That is certainly true and I'm not strongly against matching on functionality it just seems to me that it's too specific for that to make sense and in that case I feel it's better to be clear about that and make it ISM specific in name and functionality.

Quoted 5 lines

If we manage to find a fix for the MSI-X problem which I'd be really happy about we can simply extend the regions functionality and reuse the same code for a backwards compatibile ISM region and a more generic zPCI non-MIO region that could even be used if the client (QEMU) uses non-MIO and the device can do both as is the case for all current physical devices.

I think that the fix for this is in the kernel, in the MIO implementation. But we better discuss this offline.

Since neither of us have the decision, why don't we let the maintainer discuss now that they have all the information.

Regards,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#20 lore raw
Quoted 28 lines · Pierre Morel
Quoted 16 lines · Niklas Schnelle
Quoted 11 lines · Pierre Morel
Quoted 5 lines

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

Quoted 7 lines

Yes but that goes both ways the functionality of the region has to match that of the device and at least in it's current state the regions functionality matches only ISM in a way that is so specific that it is very unlikely to match anything else. For example it can't support a PCI device that requires non-MIO but also MSI-X. In its current form it doesn't even support PCI Store only PCI Store Block, we had that in an earlier version and it's trivial but then we get the MSI-X problem.

Quoted 1 line

What does that change if we take one or the other solution considering the checking of MIO/MSIX/relax versus PFT?

If it's !MIO && !MSIX && relax_align I'm fine with that check but then we should also add PCISTG to the region.

#26 lore raw
In reply to Matthew Rosato
Quoted 16 lines · Matthew Rosato
Quoted 15 lines · Pierre Morel
Quoted 3 lines · Matthew Rosato
Quoted 2 lines · Pierre Morel

...snip...

Quoted 7 lines
Quoted 7 lines

So we have:
devices supporting MIO and MSIX
devices not supporting MIO nor MSIX
devices not supporting the use of PCISTG to emulate PCISTB

The first two are two different things indicated by two different entries in the clp query PCI function response.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

The last one, we do not have an indicator as if the relaxed alignment and length is set, PCISTB can not be emulated with PCISTG

hum sorry, it seems I rewrote my sentence until it was wrong wrong! I wanted to say we DO HAVE an indicator with the relaxed bit...

That's actually not quite true though...  The relaxed bit does not directly imply that PCISTB cannot be emulated with PCISTG.

It does, PCISTG have stronger alignment enforcement as PCISTB with the relaxed bit set, as you say here under, so we agree.

Quoted 1 line

  Rather, it more generally implies that PCISTB could be used instead of PCISTG as the length and alignment requirements for PCISTB are waived.  As far as I can tell, disallowing a PCISTG altogether is a trait that is unique to ISM and I don't see anywhere that it's otherwise indicated in architecture...  And in fact, for a given ISM device, certain address spaces (command) WILL accept a series of PCISTG issued in a particular manner in place of a PCISTB; meanwhile other ISM address spaces (data) will not accept any PCISTG ever.  :(  The ISM driver just always uses PCISTB.

Very interresting!

Quoted 17 lines

So that is why I suggested type==ISM must require use of the region whereas other types that implement MSI could request (but not require) use of the region.

But yes, any other theoretical piece of hardware that also does not support MIO would have a similar region requirement.  I'll have a look at the MIO bit you referenced below and will have to verify that it does exactly what we expect for an ISM device.  Assuming yes, I will consider the following sort of checking for the next version of QEMU...

if (!MIO) {
    if (MSIX) {
        // passthrough disallowed
    }
    else {
        // region required, disallow if unavailable }
}
else if(RELAX && !MSIX) {
    // use region if available
}

Quoted 1 line

Sound good?

Yes sounds good to me.
I mean the idea, I will not try to simplify, I trust you on this.

Thanks,

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#21 lore raw
In reply to Niklas Schnelle
Quoted 29 lines · On Thu, 21 Jan 2021 15:54:22 +0100 Niklas Schnelle <[email protected]>…
Quoted 28 lines · Pierre Morel
Quoted 23 lines · Niklas Schnelle
Quoted 11 lines · Pierre Morel
Quoted 5 lines

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

Yes but that goes both ways the functionality of the region has to match that of the device and at least in it's current state the regions functionality matches only ISM in a way that is so specific that it is very unlikely to match anything else. For example it can't support a PCI device that requires non-MIO but also MSI-X. In its current form it doesn't even support PCI Store only PCI Store Block, we had that in an earlier version and it's trivial but then we get the MSI-X problem.

Quoted 6 lines
Quoted 1 line

What does that change if we take one or the other solution considering the checking of MIO/MSIX/relax versus PFT?

If it's !MIO && !MSIX && relax_align I'm fine with that check but then we should also add PCISTG to the region.

Just to double check: that would today cover only ISM (which doesn't use PCISTG), correct?

/me getting a bit lost in this discussion :)

#22 lore raw
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 21 Jan 2021 15:54:22 +0100 Niklas Schnelle <[email protected]>…
Quoted 29 lines · Pierre Morel
Quoted 16 lines · Niklas Schnelle
Quoted 11 lines · Pierre Morel
Quoted 5 lines

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

Quoted 7 lines

Yes but that goes both ways the functionality of the region has to match that of the device and at least in it's current state the regions functionality matches only ISM in a way that is so specific that it is very unlikely to match anything else. For example it can't support a PCI device that requires non-MIO but also MSI-X. In its current form it doesn't even support PCI Store only PCI Store Block, we had that in an earlier version and it's trivial but then we get the MSI-X problem.

What does that change if we take one or the other solution considering the checking of MIO/MSIX/relax versus PFT?

Quoted 7 lines
Quoted 3 lines

If it's !MIO && !MSIX && relax_align I'm fine with that check but then we should also add PCISTG to the region.

Just to double check: that would today cover only ISM (which doesn't use PCISTG), correct?

Yes, correct -- So to summarize the proposal outlined is to use those features to determine whether a device should be using the region or not rather rather than strictly saying only PFT==ISM may use it.

Practically speaking, ISM is the only device that fits the bill today when you combine these things, and ISM does not use PCISTG -- so PCISTG support was simply omitted from the region (prior versions before coming upstream included it, was dropped since ISM doesn't use it).

What Niklas suggests here is that, if we are going to be broad in determining whether the region can be used for a given device vs saying 'only PFT==ISM', then we can no longer assume that the device doesn't use PCISTG and as such is suggesting the region should also include PCISTG support as a means of future compatibility (to ensure non-MIO PCISTG is issued for the device).

Quoted 2 lines

/me getting a bit lost in this discussion :)

#23 lore raw
Quoted 53 lines · On Thu, 21 Jan 2021 13:06:24 -0500 Matthew Rosato <[email protected]>…
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 21 Jan 2021 15:54:22 +0100 Niklas Schnelle <[email protected]>…
Quoted 29 lines · Pierre Morel
Quoted 16 lines · Niklas Schnelle
Quoted 11 lines · Pierre Morel
Quoted 5 lines

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

Quoted 7 lines

Yes but that goes both ways the functionality of the region has to match that of the device and at least in it's current state the regions functionality matches only ISM in a way that is so specific that it is very unlikely to match anything else. For example it can't support a PCI device that requires non-MIO but also MSI-X. In its current form it doesn't even support PCI Store only PCI Store Block, we had that in an earlier version and it's trivial but then we get the MSI-X problem.

What does that change if we take one or the other solution considering the checking of MIO/MSIX/relax versus PFT?

Quoted 7 lines
Quoted 3 lines

If it's !MIO && !MSIX && relax_align I'm fine with that check but then we should also add PCISTG to the region.

Just to double check: that would today cover only ISM (which doesn't use PCISTG), correct?

Yes, correct -- So to summarize the proposal outlined is to use those features to determine whether a device should be using the region or not rather rather than strictly saying only PFT==ISM may use it.

Practically speaking, ISM is the only device that fits the bill today when you combine these things, and ISM does not use PCISTG -- so PCISTG support was simply omitted from the region (prior versions before coming upstream included it, was dropped since ISM doesn't use it).

Quoted 6 lines

What Niklas suggests here is that, if we are going to be broad in determining whether the region can be used for a given device vs saying 'only PFT==ISM', then we can no longer assume that the device doesn't use PCISTG and as such is suggesting the region should also include PCISTG support as a means of future compatibility (to ensure non-MIO PCISTG is issued for the device).

Yes, if we go the "check for features" route, including PCISTG makes sense.

However, I'm still not quite sure whether checking for ISM vs checking for features makes more sense in the long run. Is ISM that one weird device whose cousins you're not going to invite to the party, or is there a possibility that there will be devices that could make use of the region for performance etc.?

#24 lore raw
Quoted 63 lines · Cornelia Huck
Quoted 53 lines · On Thu, 21 Jan 2021 13:06:24 -0500 Matthew Rosato <[email protected]>…
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 21 Jan 2021 15:54:22 +0100 Niklas Schnelle <[email protected]>…
Quoted 29 lines · Pierre Morel
Quoted 16 lines · Niklas Schnelle
Quoted 11 lines · Pierre Morel
Quoted 5 lines

Just wanted to say that we've had a very similar discussion with Cornelia end of last year and came to the conclusion that explicitly matching the PFT is likely the safest bet:
https://lkml.org/lkml/2020/12/22/479

What I see there is a discussion on the relation between relaxed access and MIO without explaining to Connie that we have in the kernel the possibility to know if a device support MIO or not independently of it supports the relaxed access.

The all point here is about taking decisions for the right reasons.

We have the possibility to take the decision based on functionalities and not on a specific PCI function.

Quoted 7 lines

Yes but that goes both ways the functionality of the region has to match that of the device and at least in it's current state the regions functionality matches only ISM in a way that is so specific that it is very unlikely to match anything else. For example it can't support a PCI device that requires non-MIO but also MSI-X. In its current form it doesn't even support PCI Store only PCI Store Block, we had that in an earlier version and it's trivial but then we get the MSI-X problem.

What does that change if we take one or the other solution considering the checking of MIO/MSIX/relax versus PFT?

Quoted 7 lines
Quoted 3 lines

If it's !MIO && !MSIX && relax_align I'm fine with that check but then we should also add PCISTG to the region.

Just to double check: that would today cover only ISM (which doesn't use PCISTG), correct?

Yes, correct -- So to summarize the proposal outlined is to use those features to determine whether a device should be using the region or not rather rather than strictly saying only PFT==ISM may use it.

Practically speaking, ISM is the only device that fits the bill today when you combine these things, and ISM does not use PCISTG -- so PCISTG support was simply omitted from the region (prior versions before coming upstream included it, was dropped since ISM doesn't use it).

Quoted 6 lines

What Niklas suggests here is that, if we are going to be broad in determining whether the region can be used for a given device vs saying 'only PFT==ISM', then we can no longer assume that the device doesn't use PCISTG and as such is suggesting the region should also include PCISTG support as a means of future compatibility (to ensure non-MIO PCISTG is issued for the device).

Quoted 6 lines

Yes, if we go the "check for features" route, including PCISTG makes sense.

However, I'm still not quite sure whether checking for ISM vs checking for features makes more sense in the long run. Is ISM that one weird device whose cousins you're not going to invite to the party, or is

... Yes. :)

Quoted 3 lines

there a possibility that there will be devices that could make use of the region for performance etc.?

Also yes. Well, potentially. That's really what I wanted at the outset, but the fly in the ointment is that the region as I exploit it in QEMU today only works properly for devices without MSI-X, which frankly limits its general-purpose utility. If we could lift that restriction (whether it be now or at a later point) then the region becomes quite beneficial for performance of any devices making frequent use of large PCISTB operations.