Skip to contentSkip to conversation

Pass zPCI hardware information via VFIO

PATCH Superseded Matthew Rosato 4 participants 18 messages Sep 19, 2020 – Sep 22, 2020

Subsystems (5)
KVM s390 VFIO driver s390 PCI +1 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Matthew Rosato

author maintainer
#0 lore raw

cover Pass zPCI hardware information via VFIO

This patchset provides a means by which hardware information about the underlying PCI device can be passed up to userspace (ie, QEMU) so that this hardware information can be used rather than previously hard-coded assumptions. A new VFIO region type is defined which holds this information.

A form of these patches saw some rounds last year but has been back- tabled for a while. The original work for this feature was done by Pierre Morel. I'd like to refresh the discussion on this and get this finished up so that we can move forward with better-supporting additional types of PCI-attached devices. The proposal here presents a completely different region mapping vs the prior approach, taking inspiration from vfio info capability chains to provide device CLP information in a way that allows for future expansion (new CLP features).

This feature is toggled via the CONFIG_VFIO_PCI_ZDEV configuration entry.

Matthew Rosato (4):
s390/pci: stash version in the zpci_dev
s390/pci: track whether util_str is valid in the zpci_dev vfio-pci/zdev: define the vfio_zdev header vfio-pci/zdev: use a device region to retrieve zPCI information

 arch/s390/include/asm/pci.h         |   4 +-
 arch/s390/pci/pci_clp.c             |   2 +
 drivers/vfio/pci/Kconfig            |  13 ++
 drivers/vfio/pci/Makefile           |   1 +
 drivers/vfio/pci/vfio_pci.c         |   8 ++
 drivers/vfio/pci/vfio_pci_private.h |  10 ++
 drivers/vfio/pci/vfio_pci_zdev.c    | 242 ++++++++++++++++++++++++++++++++++++
 include/uapi/linux/vfio.h           |   5 +
 include/uapi/linux/vfio_zdev.h      | 116 +++++++++++++++++
 9 files changed, 400 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vfio/pci/vfio_pci_zdev.c
 create mode 100644 include/uapi/linux/vfio_zdev.h
Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw

PATCH 1/4 s390/pci: stash version in the zpci_dev

In preparation for passing the info on to vfio-pci devices, stash the supported PCI version for the target device in the zpci_dev.

---
 arch/s390/include/asm/pci.h | 1 +
 arch/s390/pci/pci_clp.c     | 1 +
 2 files changed, 2 insertions(+)
arch/s390/include/asm/pci.h +1 -0
index 99b92c3..882e233 100644
@@ -179,6 +179,7 @@ struct zpci_dev {
 	atomic64_t mapped_pages;
 	atomic64_t unmapped_pages;
 
+	u8		version;
 	enum pci_bus_speed max_bus_speed;
 
 	struct dentry	*debugfs_dev;
arch/s390/pci/pci_clp.c +1 -0
index 7e735f4..48bf316 100644
@@ -102,6 +102,7 @@ static void clp_store_query_pci_fngrp(struct zpci_dev *zdev,
 	zdev->msi_addr = response->msia;
 	zdev->max_msi = response->noi;
 	zdev->fmb_update = response->mui;
+	zdev->version = response->version;
 
 	switch (response->version) {
 	case 1:
Signature · 1 line
1.8.3.1
maintainer Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] s390/pci: stash version in the zpci_dev

Hi Matthew,

Quoted 4 lines · Matthew Rosato

In preparation for passing the info on to vfio-pci devices, stash the supported PCI version for the target device in the zpci_dev.

Quoted 30 lines
---
 arch/s390/include/asm/pci.h | 1 +
 arch/s390/pci/pci_clp.c     | 1 +
 2 files changed, 2 insertions(+)
arch/s390/include/asm/pci.h +1 -0
index 99b92c3..882e233 100644
@@ -179,6 +179,7 @@ struct zpci_dev {
 	atomic64_t mapped_pages;
 	atomic64_t unmapped_pages;
 
+	u8		version;
 	enum pci_bus_speed max_bus_speed;
 
 	struct dentry	*debugfs_dev;
arch/s390/pci/pci_clp.c +1 -0
index 7e735f4..48bf316 100644
@@ -102,6 +102,7 @@ static void clp_store_query_pci_fngrp(struct zpci_dev *zdev,
 	zdev->msi_addr = response->msia;
 	zdev->max_msi = response->noi;
 	zdev->fmb_update = response->mui;
+	zdev->version = response->version;
 
 	switch (response->version) {
 	case 1:
Acked-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] s390/pci: stash version in the zpci_dev

In reply to Matthew Rosato
Quoted 4 lines · Matthew Rosato

In preparation for passing the info on to vfio-pci devices, stash the supported PCI version for the target device in the zpci_dev.

In case this will go via the vfio tree, with my s390 kernel maintainer hat on:

Quoted 30 lines
---
 arch/s390/include/asm/pci.h | 1 +
 arch/s390/pci/pci_clp.c     | 1 +
 2 files changed, 2 insertions(+)
arch/s390/include/asm/pci.h +1 -0
index 99b92c3..882e233 100644
@@ -179,6 +179,7 @@ struct zpci_dev {
 	atomic64_t mapped_pages;
 	atomic64_t unmapped_pages;
 
+	u8		version;
 	enum pci_bus_speed max_bus_speed;
 
 	struct dentry	*debugfs_dev;
arch/s390/pci/pci_clp.c +1 -0
index 7e735f4..48bf316 100644
@@ -102,6 +102,7 @@ static void clp_store_query_pci_fngrp(struct zpci_dev *zdev,
 	zdev->msi_addr = response->msia;
 	zdev->max_msi = response->noi;
 	zdev->fmb_update = response->mui;
+	zdev->version = response->version;
 
 	switch (response->version) {
 	case 1:
#4 lore raw

Re: [PATCH 1/4] s390/pci: stash version in the zpci_dev

In reply to Matthew Rosato
Quoted 2 lines · On Sat, 19 Sep 2020 11:28:35 -0400 Matthew Rosato <[email protected]>…

In preparation for passing the info on to vfio-pci devices, stash the supported PCI version for the target device in the zpci_dev.

Hm, what kind of version is that? The version of the zPCI interface?

Inquiring minds want to know :)

Quoted 6 lines
---
 arch/s390/include/asm/pci.h | 1 +
 arch/s390/pci/pci_clp.c     | 1 +
 2 files changed, 2 insertions(+)
author maintainer
#5 lore raw

Re: [PATCH 1/4] s390/pci: stash version in the zpci_dev

Quoted 10 lines · Cornelia Huck
Quoted 2 lines · On Sat, 19 Sep 2020 11:28:35 -0400 Matthew Rosato <[email protected]>…

In preparation for passing the info on to vfio-pci devices, stash the supported PCI version for the target device in the zpci_dev.

Hm, what kind of version is that? The version of the zPCI interface?

Inquiring minds want to know :)

Ha :) It's related to PCI-SIG spec versions and which one the zPCI facility supports for this device.

Quoted 7 lines
Quoted 6 lines
---
  arch/s390/include/asm/pci.h | 1 +
  arch/s390/pci/pci_clp.c     | 1 +
  2 files changed, 2 insertions(+)
Acked-by
#6 lore raw

Re: [PATCH 1/4] s390/pci: stash version in the zpci_dev

Quoted 7 lines · On Mon, 21 Sep 2020 11:44:20 -0400 Matthew Rosato <[email protected]>…
Quoted 6 lines · Cornelia Huck
Quoted 2 lines · On Sat, 19 Sep 2020 11:28:35 -0400 Matthew Rosato <[email protected]>…

In preparation for passing the info on to vfio-pci devices, stash the supported PCI version for the target device in the zpci_dev.

Quoted 7 lines
Quoted 4 lines

Hm, what kind of version is that? The version of the zPCI interface?

Inquiring minds want to know :)

Ha :) It's related to PCI-SIG spec versions and which one the zPCI facility supports for this device.

Thanks for the info :)

Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
---
  arch/s390/include/asm/pci.h | 1 +
  arch/s390/pci/pci_clp.c     | 1 +
  2 files changed, 2 insertions(+)  

FWIW,

author maintainer
#7 lore raw

PATCH 2/4 s390/pci: track whether util_str is valid in the zpci_dev

In reply to Matthew Rosato

We'll need to keep track of whether or not the byte string in util_str is valid and thus needs to be passed to a vfio-pci passthrough device.

---
 arch/s390/include/asm/pci.h | 3 ++-
 arch/s390/pci/pci_clp.c     | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/s390/include/asm/pci.h +2 -1
index 882e233..32eb975 100644
@@ -132,7 +132,8 @@ struct zpci_dev {
 	u8		rid_available	: 1;
 	u8		has_hp_slot	: 1;
 	u8		is_physfn	: 1;
-	u8		reserved	: 5;
+	u8		util_avail	: 1;
+	u8		reserved	: 4;
 	unsigned int	devfn;		/* DEVFN part of the RID*/
 
 	struct mutex lock;
arch/s390/pci/pci_clp.c +1 -0
index 48bf316..d011134 100644
@@ -168,6 +168,7 @@ static int clp_store_query_pci_fn(struct zpci_dev *zdev,
 	if (response->util_str_avail) {
 		memcpy(zdev->util_str, response->util_str,
 		       sizeof(zdev->util_str));
+		zdev->util_avail = 1;
 	}
 	zdev->mio_capable = response->mio_addr_avail;
 	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
Signature · 1 line
1.8.3.1
Acked-by on v1 2/4
#8 lore raw

Re: [PATCH 2/4] s390/pci: track whether util_str is valid in the zpci_dev

Quoted 4 lines · Matthew Rosato

We'll need to keep track of whether or not the byte string in util_str is valid and thus needs to be passed to a vfio-pci passthrough device.

If this goes via the vfio tree,

(please wait for an ack from Niklas Schnelle as well)

Quoted 32 lines
---
 arch/s390/include/asm/pci.h | 3 ++-
 arch/s390/pci/pci_clp.c     | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/s390/include/asm/pci.h +2 -1
index 882e233..32eb975 100644
@@ -132,7 +132,8 @@ struct zpci_dev {
 	u8		rid_available	: 1;
 	u8		has_hp_slot	: 1;
 	u8		is_physfn	: 1;
-	u8		reserved	: 5;
+	u8		util_avail	: 1;
+	u8		reserved	: 4;
 	unsigned int	devfn;		/* DEVFN part of the RID*/
 
 	struct mutex lock;
arch/s390/pci/pci_clp.c +1 -0
index 48bf316..d011134 100644
@@ -168,6 +168,7 @@ static int clp_store_query_pci_fn(struct zpci_dev *zdev,
 	if (response->util_str_avail) {
 		memcpy(zdev->util_str, response->util_str,
 		       sizeof(zdev->util_str));
+		zdev->util_avail = 1;
 	}
 	zdev->mio_capable = response->mio_addr_avail;
 	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
maintainer Acked-by on v1 2/4
#9 lore raw

Re: [PATCH 2/4] s390/pci: track whether util_str is valid in the zpci_dev

In reply to Matthew Rosato

Hi Matthew,

Quoted 14 lines · Matthew Rosato

We'll need to keep track of whether or not the byte string in util_str is valid and thus needs to be passed to a vfio-pci passthrough device.

---
 arch/s390/include/asm/pci.h | 3 ++-
 arch/s390/pci/pci_clp.c     | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/s390/include/asm/pci.h +0 -0
index 882e233..32eb975 100644

arch/s390/include/asm/pci.h struct zpci_dev { · line 135

Quoted 5 lines
arch/s390/include/asm/pci.h +1 -1
@@ -132,7 +132,8 @@ struct zpci_dev {
 	u8		rid_available	: 1;
 	u8		has_hp_slot	: 1;
 	u8		is_physfn	: 1;
-	u8		reserved	: 5;
+	u8		util_avail	: 1;

Any reason you're not matching the util_str_avail name in the response struct? I think this is currently always an EBCDIC encoded string so the information that even if it looks like binary for anyone with a non-mainframe background it is in fact a string seems quite helpful.
Other than that

Quoted 17 lines
arch/s390/include/asm/pci.h +1 -0
+	u8		reserved	: 4;
 	unsigned int	devfn;		/* DEVFN part of the RID*/
 
 	struct mutex lock;
arch/s390/pci/pci_clp.c +1 -0
index 48bf316..d011134 100644
@@ -168,6 +168,7 @@ static int clp_store_query_pci_fn(struct zpci_dev *zdev,
 	if (response->util_str_avail) {
 		memcpy(zdev->util_str, response->util_str,
 		       sizeof(zdev->util_str));
+		zdev->util_avail = 1;
 	}
 	zdev->mio_capable = response->mio_addr_avail;
 	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
author maintainer
#10 lore raw

Re: [PATCH 2/4] s390/pci: track whether util_str is valid in the zpci_dev

Quoted 12 lines · Niklas Schnelle

Hi Matthew,

Quoted 9 lines · Matthew Rosato

We'll need to keep track of whether or not the byte string in util_str is valid and thus needs to be passed to a vfio-pci passthrough device.

---
  arch/s390/include/asm/pci.h | 3 ++-
  arch/s390/pci/pci_clp.c     | 1 +
  2 files changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

arch/s390/include/asm/pci.h struct zpci_dev { · line 135

Quoted 10 lines
arch/s390/include/asm/pci.h +1 -1
index 882e233..32eb975 100644
@@ -132,7 +132,8 @@ struct zpci_dev {
  	u8		rid_available	: 1;
  	u8		has_hp_slot	: 1;
  	u8		is_physfn	: 1;
-	u8		reserved	: 5;
+	u8		util_avail	: 1;

Any reason you're not matching the util_str_avail name in the response struct? > I think this is currently always an EBCDIC encoded string so the

information that

Quoted 2 lines

even if it looks like binary for anyone with a non-mainframe background it is in fact a string seems quite helpful.

Frankly, the dropping of 'str_' was arbitrary on my part -- I'll go ahead and rename it to util_str_avail with v2.

Quoted 4 lines

Other than that

Thanks!

Quoted 17 lines
Quoted 17 lines
arch/s390/include/asm/pci.h +1 -0
+	u8		reserved	: 4;
  	unsigned int	devfn;		/* DEVFN part of the RID*/
 
  	struct mutex lock;
arch/s390/pci/pci_clp.c +1 -0
index 48bf316..d011134 100644
@@ -168,6 +168,7 @@ static int clp_store_query_pci_fn(struct zpci_dev *zdev,
  	if (response->util_str_avail) {
  		memcpy(zdev->util_str, response->util_str,
  		       sizeof(zdev->util_str));
+		zdev->util_avail = 1;
  	}
  	zdev->mio_capable = response->mio_addr_avail;
  	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
author maintainer
#11 lore raw

PATCH 3/4 vfio-pci/zdev: define the vfio_zdev header

In reply to Matthew Rosato

We define a new device region in vfio.h to be able to get the ZPCI CLP information by reading this region from userspace.

We create a new file, vfio_zdev.h to define the structure of the new region defined in vfio.h

---
 include/uapi/linux/vfio.h      |   5 ++
 include/uapi/linux/vfio_zdev.h | 116 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 include/uapi/linux/vfio_zdev.h
include/uapi/linux/vfio.h +5 -0
index 9204705..65eb367 100644
@@ -326,6 +326,11 @@ struct vfio_region_info_cap_type {
  * to do TLB invalidation on a GPU.
  */
 #define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD	(1)
+/*
+ * IBM zPCI specific hardware feature information for a devcie.  The contents
+ * of this region are mapped by struct vfio_region_zpci_info.
+ */
+#define VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP	(2)
 
 /* sub-types for VFIO_REGION_TYPE_GFX */
 #define VFIO_REGION_SUBTYPE_GFX_EDID            (1)
include/uapi/linux/vfio_zdev.h new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#12 lore raw

Re: [PATCH 3/4] vfio-pci/zdev: define the vfio_zdev header

Quoted 18 lines · On Sat, 19 Sep 2020 11:28:37 -0400 Matthew Rosato <[email protected]>…

We define a new device region in vfio.h to be able to get the ZPCI CLP information by reading this region from userspace.

We create a new file, vfio_zdev.h to define the structure of the new region defined in vfio.h

---
 include/uapi/linux/vfio.h      |   5 ++
 include/uapi/linux/vfio_zdev.h | 116 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)
 create mode 100644 include/uapi/linux/vfio_zdev.h
include/uapi/linux/vfio.h +0 -0
index 9204705..65eb367 100644

include/uapi/linux/vfio.h struct vfio_region_info_cap_type { · line 333

Quoted 8 lines
include/uapi/linux/vfio.h +5 -0
@@ -326,6 +326,11 @@ struct vfio_region_info_cap_type {
  * to do TLB invalidation on a GPU.
  */
 #define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD	(1)
+/*
+ * IBM zPCI specific hardware feature information for a devcie.  The contents
+ * of this region are mapped by struct vfio_region_zpci_info.
+ */
+#define VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP	(2)

This is not really for a 10de vendor, but for all pci devices accessed via zpci, isn't it?

We obviously want to avoid collisions here; not really sure how to cover all possible vendors. Maybe just pick a high number?

Quoted 21 lines
include/uapi/linux/vfio.h +0 -0
 /* sub-types for VFIO_REGION_TYPE_GFX */
 #define VFIO_REGION_SUBTYPE_GFX_EDID            (1)
include/uapi/linux/vfio_zdev.h new file +12 -0
new file mode 100644
index 0000000..c9e4891
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Region definition for ZPCI devices
+ *
+ * Copyright IBM Corp. 2020
+ *
+ * Author(s): Pierre Morel <[email protected]>
+ *            Matthew Rosato <[email protected]>
+ */
+
+#ifndef _VFIO_ZDEV_H_
+#define _VFIO_ZDEV_H_

include/uapi/linux/vfio_zdev.h line 22

Quoted 10 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+
+#include <linux/types.h>
+
+/**
+ * struct vfio_region_zpci_info - ZPCI information
+ *
+ * This region provides zPCI specific hardware feature information for a
+ * device.
+ *
+ * The ZPCI information structure is presented as a chain of CLP features

"CLP features" == "features returned by the CLP instruction", I guess? Maybe mention that explicitly?

include/uapi/linux/vfio_zdev.h line 30

Quoted 8 lines
include/uapi/linux/vfio_zdev.h new file +8 -0
+ * defined below. argsz provides the size of the entire region, and offset
+ * provides the location of the first CLP feature in the chain.
+ *
+ */
+struct vfio_region_zpci_info {
+	__u32 argsz;		/* Size of entire payload */
+	__u32 offset;		/* Location of first entry */
+} __packed;

This '__packed' annotation seems redundant. I think that all of these structures should be defined in a way that packing is unneeded (which seems to be the case on a quick browse.)

include/uapi/linux/vfio_zdev.h line 40

Quoted 10 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+
+/**
+ * struct vfio_region_zpci_info_hdr - ZPCI header information
+ *
+ * This structure is included at the top of each CLP feature to define what
+ * type of CLP feature is presented / the structure version. The next value
+ * defines the offset of the next CLP feature, and is an offset from the very
+ * beginning of the region (vfio_region_zpci_info).
+ *
+ * Each CLP feature must have it's own unique 'id'.

s/it's/its/

Is the 'id' something that is already provided by the CLP instruction?

include/uapi/linux/vfio_zdev.h line 51

Quoted 11 lines
include/uapi/linux/vfio_zdev.h new file +11 -0
+ */
+struct vfio_region_zpci_info_hdr {
+	__u16 id;		/* Identifies the CLP type */
+	__u16	version;	/* version of the CLP data */
+	__u32 next;		/* Offset of next entry */
+} __packed;
+
+/**
+ * struct vfio_region_zpci_info_qpci - Initial Query PCI information
+ *
+ * This region provides an initial set of data from the Query PCI Function

What does 'initial' mean in this context? Information you get for a freshly initialized function?

Quoted 31 lines
include/uapi/linux/vfio_zdev.h new file +31 -0
+ * CLP.
+ */
+#define VFIO_REGION_ZPCI_INFO_QPCI	1
+
+struct vfio_region_zpci_info_qpci {
+	struct vfio_region_zpci_info_hdr hdr;
+	__u64 start_dma;	/* Start of available DMA addresses */
+	__u64 end_dma;		/* End of available DMA addresses */
+	__u16 pchid;		/* Physical Channel ID */
+	__u16 vfn;		/* Virtual function number */
+	__u16 fmb_length;	/* Measurement Block Length (in bytes) */
+	__u8 pft;		/* PCI Function Type */
+	__u8 gid;		/* PCI function group ID */
+} __packed;
+
+
+/**
+ * struct vfio_region_zpci_info_qpcifg - Initial Query PCI Function Group info
+ *
+ * This region provides an initial set of data from the Query PCI Function
+ * Group CLP.
+ */
+#define VFIO_REGION_ZPCI_INFO_QPCIFG	2
+
+struct vfio_region_zpci_info_qpcifg {
+	struct vfio_region_zpci_info_hdr hdr;
+	__u64 dasm;		/* DMA Address space mask */
+	__u64 msi_addr;		/* MSI address */
+	__u64 flags;
+#define VFIO_PCI_ZDEV_FLAGS_REFRESH 1 /* Use program-specified TLB refresh */
+	__u16 mui;		/* Measurement Block Update Interval */

include/uapi/linux/vfio_zdev.h line 92

Quoted 10 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+	__u16 noi;		/* Maximum number of MSIs */
+	__u16 maxstbl;		/* Maximum Store Block Length */
+	__u8 version;		/* Supported PCI Version */
+} __packed;
+
+/**
+ * struct vfio_region_zpci_info_util - Utility String
+ *
+ * This region provides the utility string for the associated device, which is
+ * a device identifier string.

Is there an upper boundary for this string?

Is this a classic NUL-terminated string, or a list of EBCDIC characters?

Quoted 4 lines
include/uapi/linux/vfio_zdev.h new file +4 -0
+ */
+#define VFIO_REGION_ZPCI_INFO_UTIL	3
+
+struct vfio_region_zpci_info_util {

include/uapi/linux/vfio_zdev.h line 106

Quoted 10 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+	struct vfio_region_zpci_info_hdr hdr;
+	__u32 size;
+	__u8 util_str[];
+} __packed;
+
+/**
+ * struct vfio_region_zpci_info_pfip - PCI Function Path
+ *
+ * This region provides the PCI function path string, which is an identifier
+ * that describes the internal hardware path of the device.

Same question here.

Quoted 10 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+ */
+#define VFIO_REGION_ZPCI_INFO_PFIP	4
+
+struct vfio_region_zpci_info_pfip {
+struct vfio_region_zpci_info_hdr hdr;
+	__u32 size;
+	__u8 pfip[];
+} __packed;
+
+#endif
author maintainer
#13 lore raw

Re: [PATCH 3/4] vfio-pci/zdev: define the vfio_zdev header

Quoted 16 lines · Cornelia Huck
Quoted 13 lines · On Sat, 19 Sep 2020 11:28:37 -0400 Matthew Rosato <[email protected]>…

We define a new device region in vfio.h to be able to get the ZPCI CLP information by reading this region from userspace.

We create a new file, vfio_zdev.h to define the structure of the new region defined in vfio.h

---
  include/uapi/linux/vfio.h      |   5 ++
  include/uapi/linux/vfio_zdev.h | 116 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 121 insertions(+)

create mode 100644 include/uapi/linux/vfio_zdev.h

Quoted 16 lines

include/uapi/linux/vfio.h struct vfio_region_info_cap_type { · line 333

Quoted 13 lines
include/uapi/linux/vfio.h +5 -0
index 9204705..65eb367 100644
@@ -326,6 +326,11 @@ struct vfio_region_info_cap_type {
   * to do TLB invalidation on a GPU.
   */
  #define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD	(1)
+/*
+ * IBM zPCI specific hardware feature information for a devcie.  The contents
+ * of this region are mapped by struct vfio_region_zpci_info.
+ */
+#define VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP	(2)

This is not really for a 10de vendor, but for all pci devices accessed via zpci, isn't it?

s/10de/1014/ (10de is the set of regions prior to this one)

1014 == PCI_VENDOR_ID_IBM

But yes, this region is intended to be assigned to all pci devices accessed thru zpci. But the next patch always assigns the region to the zpci device using type 1014 subtype 2 (and userspace always searches using that pair) -- So it should always be unique as I understand it unless someone re-defines another type 1014 subtype 2?

Quoted 3 lines

We obviously want to avoid collisions here; not really sure how to cover all possible vendors. Maybe just pick a high number?

I don't think this is necessary unless I'm misunderstanding something.

Quoted 26 lines
Quoted 26 lines
include/uapi/linux/vfio.h +0 -0
  /* sub-types for VFIO_REGION_TYPE_GFX */
  #define VFIO_REGION_SUBTYPE_GFX_EDID            (1)
include/uapi/linux/vfio_zdev.h new file +17 -0
new file mode 100644
index 0000000..c9e4891
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Region definition for ZPCI devices
+ *
+ * Copyright IBM Corp. 2020
+ *
+ * Author(s): Pierre Morel <[email protected]>
+ *            Matthew Rosato <[email protected]>
+ */
+
+#ifndef _VFIO_ZDEV_H_
+#define _VFIO_ZDEV_H_
+
+#include <linux/types.h>
+
+/**
+ * struct vfio_region_zpci_info - ZPCI information
Quoted 8 lines

include/uapi/linux/vfio_zdev.h line 22

Quoted 5 lines
include/uapi/linux/vfio_zdev.h new file +5 -0
+ *
+ * This region provides zPCI specific hardware feature information for a
+ * device.
+ *
+ * The ZPCI information structure is presented as a chain of CLP features

"CLP features" == "features returned by the CLP instruction", I guess? Maybe mention that explicitly?

Yes, that's correct. I'm trying to clarify that these things aren't a 1:1 relationship to a CLP instruction payload.

Quoted 14 lines

include/uapi/linux/vfio_zdev.h line 30

Quoted 9 lines
include/uapi/linux/vfio_zdev.h new file +8 -0
+ * defined below. argsz provides the size of the entire region, and offset
+ * provides the location of the first CLP feature in the chain.
+ *
+ */
+struct vfio_region_zpci_info {
+	__u32 argsz;		/* Size of entire payload */
+	__u32 offset;		/* Location of first entry */
+} __packed;

This '__packed' annotation seems redundant. I think that all of these structures should be defined in a way that packing is unneeded (which seems to be the case on a quick browse.)

OK, I'll double-check and remove the __packed annotation.

Quoted 13 lines

include/uapi/linux/vfio_zdev.h line 40

Quoted 10 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+
+/**
+ * struct vfio_region_zpci_info_hdr - ZPCI header information
+ *
+ * This structure is included at the top of each CLP feature to define what
+ * type of CLP feature is presented / the structure version. The next value
+ * defines the offset of the next CLP feature, and is an offset from the very
+ * beginning of the region (vfio_region_zpci_info).
+ *
+ * Each CLP feature must have it's own unique 'id'.

s/it's/its/

Quoted 2 lines

Is the 'id' something that is already provided by the CLP instruction?

No, these IDs correspond only to the API for the vfio region and don't directly relate to which CLP instruction they are associated with. The term 'CLP feature' was intended to abstract these structures from individual CLP instructions.

So, it might help to explain the design a bit here -- The CLP instructions each return a specific, hardware-architected payload. But we're not sending the entirety of that payload to the guest, rather identifying a subset to forward via the vfio region. Currently, I've sub-divided it as follows:

1) query pci info we currently care about
2) query pci fg info we currently care about
3) utility string
4) function path

This was done in such a way that, when we need to add further CLP information to this region (ex: new device support, new zpci feature support, etc) we can do so by adding new 'CLP features' to the region. Those 'CLP features' could be additional parts of the query pci CLP, additional parts of the query pci fg CLP, or parts of some other CLP. Technically, #3 and #4 are part of query pci info, but the nature of the way they are sized made it more convenient to make them separate features.

Userspace can then scan the region only for the 'CLP features' it understands (or is enabled for) and pick only those (and use defaults and/or turn support off for 'CLP features' it cannot find but expected to).

Quoted 6 lines
Quoted 6 lines
include/uapi/linux/vfio_zdev.h new file +6 -0
+ */
+struct vfio_region_zpci_info_hdr {
+	__u16 id;		/* Identifies the CLP type */
+	__u16	version;	/* version of the CLP data */
+	__u32 next;		/* Offset of next entry */
+} __packed;
Quoted 9 lines

include/uapi/linux/vfio_zdev.h line 51

Quoted 5 lines
include/uapi/linux/vfio_zdev.h new file +5 -0
+
+/**
+ * struct vfio_region_zpci_info_qpci - Initial Query PCI information
+ *
+ * This region provides an initial set of data from the Query PCI Function

What does 'initial' mean in this context? Information you get for a freshly initialized function?

So this goes back to my statement above about 'query pci info we currently care about' - It's not the entire query pci payload and I was trying to avoid implying it was to prevent future confusion. So 'initial' is more in a sense of 'what we initially care to send to userspace.'

But really, the vfio region API doesn't care which CLP the info came from / where userspace is planning to stick these fields -- Perhaps I should drop 'initial' and re-phrase without mentioning the CLP itself. This feature is providing basic descriptive information about the device, so maybe something like "Base zPCI device information"

Quoted 14 lines
Quoted 14 lines
include/uapi/linux/vfio_zdev.h new file +14 -0
+ * CLP.
+ */
+#define VFIO_REGION_ZPCI_INFO_QPCI	1
+
+struct vfio_region_zpci_info_qpci {
+	struct vfio_region_zpci_info_hdr hdr;
+	__u64 start_dma;	/* Start of available DMA addresses */
+	__u64 end_dma;		/* End of available DMA addresses */
+	__u16 pchid;		/* Physical Channel ID */
+	__u16 vfn;		/* Virtual function number */
+	__u16 fmb_length;	/* Measurement Block Length (in bytes) */
+	__u8 pft;		/* PCI Function Type */
+	__u8 gid;		/* PCI function group ID */
+} __packed;
Quoted 8 lines

include/uapi/linux/vfio_zdev.h line 73

Quoted 8 lines
include/uapi/linux/vfio_zdev.h new file +8 -0
+
+
+/**
+ * struct vfio_region_zpci_info_qpcifg - Initial Query PCI Function Group info
+ *
+ * This region provides an initial set of data from the Query PCI Function
+ * Group CLP.
+ */

And the same thing here -- It's the subset of query pci fg info we currently care about -- So I can rename and drop the 'Initial' bit. Something like "Base zPCI group information"

Quoted 22 lines
Quoted 9 lines
include/uapi/linux/vfio_zdev.h new file +9 -0
+#define VFIO_REGION_ZPCI_INFO_QPCIFG	2
+
+struct vfio_region_zpci_info_qpcifg {
+	struct vfio_region_zpci_info_hdr hdr;
+	__u64 dasm;		/* DMA Address space mask */
+	__u64 msi_addr;		/* MSI address */
+	__u64 flags;
+#define VFIO_PCI_ZDEV_FLAGS_REFRESH 1 /* Use program-specified TLB refresh */
+	__u16 mui;		/* Measurement Block Update Interval */

include/uapi/linux/vfio_zdev.h line 92

Quoted 10 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+	__u16 noi;		/* Maximum number of MSIs */
+	__u16 maxstbl;		/* Maximum Store Block Length */
+	__u8 version;		/* Supported PCI Version */
+} __packed;
+
+/**
+ * struct vfio_region_zpci_info_util - Utility String
+ *
+ * This region provides the utility string for the associated device, which is
+ * a device identifier string.

Is there an upper boundary for this string?

Quoted 2 lines

Is this a classic NUL-terminated string, or a list of EBCDIC characters?

EBCDIC characters.

So, there is indeed an upper-boundary for the string, CLP_UTIL_STR_LEN. It's coming from a hardware-architected field and shouldn't change size, but we send the length anyway so that the API can act independent of the CLP hardware region. So the expectation is that userspace (qemu) would compare the provided size of the util_str with what it expects the CLP hardware payload to look like -- If it's too big, userspace can't use that string to properly emulate the CLP response so it would have to ignore this feature and use defaults.

Quoted 8 lines
Quoted 8 lines
include/uapi/linux/vfio_zdev.h new file +8 -0
+ */
+#define VFIO_REGION_ZPCI_INFO_UTIL	3
+
+struct vfio_region_zpci_info_util {
+	struct vfio_region_zpci_info_hdr hdr;
+	__u32 size;
+	__u8 util_str[];
+} __packed;
Quoted 8 lines

include/uapi/linux/vfio_zdev.h line 106

Quoted 6 lines
include/uapi/linux/vfio_zdev.h new file +6 -0
+
+/**
+ * struct vfio_region_zpci_info_pfip - PCI Function Path
+ *
+ * This region provides the PCI function path string, which is an identifier
+ * that describes the internal hardware path of the device.

Same question here.

Hex string bounded by CLP_PFIP_NR_SEGMENTS and again coming from a hardware-architected field that shouldn't change -- the rest of my answer from above applies here too.

Quoted 12 lines
Quoted 11 lines
include/uapi/linux/vfio_zdev.h new file +10 -0
+ */
+#define VFIO_REGION_ZPCI_INFO_PFIP	4
+
+struct vfio_region_zpci_info_pfip {
+struct vfio_region_zpci_info_hdr hdr;
+	__u32 size;
+	__u8 pfip[];
+} __packed;
+
+#endif
author maintainer
#14 lore raw

PATCH 4/4 vfio-pci/zdev: use a device region to retrieve zPCI information

In reply to Matthew Rosato

Define a new configuration entry VFIO_PCI_ZDEV for VFIO/PCI.

When this s390-only feature is configured we initialize a new device region, VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP, to hold information provided by the underlying hardware.

This patch is based on work previously done by Pierre Morel.

---
 drivers/vfio/pci/Kconfig            |  13 ++
 drivers/vfio/pci/Makefile           |   1 +
 drivers/vfio/pci/vfio_pci.c         |   8 ++
 drivers/vfio/pci/vfio_pci_private.h |  10 ++
 drivers/vfio/pci/vfio_pci_zdev.c    | 242 ++++++++++++++++++++++++++++++++++++
 5 files changed, 274 insertions(+)
 create mode 100644 drivers/vfio/pci/vfio_pci_zdev.c
drivers/vfio/pci/Kconfig +13 -0
index ac3c1dd..07b4a35 100644
@@ -45,3 +45,16 @@ config VFIO_PCI_NVLINK2
 	depends on VFIO_PCI && PPC_POWERNV
 	help
 	  VFIO PCI support for P9 Witherspoon machine with NVIDIA V100 GPUs
+
+config VFIO_PCI_ZDEV
+	bool "VFIO PCI ZPCI device CLP support"
+	depends on VFIO_PCI && S390
+	default y
+	help
+	  Enabling this options exposes a region containing hardware
+	  configuration for zPCI devices. This enables userspace (e.g. QEMU)
+	  to supply proper configuration values instead of hard-coded defaults
+	  for zPCI devices passed through via VFIO on s390.
+
+	  Say Y here.
+
drivers/vfio/pci/Makefile +1 -0
index f027f8a..781e080 100644
@@ -3,5 +3,6 @@
 vfio-pci-y := vfio_pci.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o
 vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o
 vfio-pci-$(CONFIG_VFIO_PCI_NVLINK2) += vfio_pci_nvlink2.o
+vfio-pci-$(CONFIG_VFIO_PCI_ZDEV) += vfio_pci_zdev.o
 
 obj-$(CONFIG_VFIO_PCI) += vfio-pci.o
drivers/vfio/pci/vfio_pci.c +8 -0
index 1ab1f5c..cfb04d9 100644
@@ -409,6 +409,14 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
 		}
 	}
 
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV)) {
+		ret = vfio_pci_zdev_init(vdev);
+		if (ret && ret != -ENODEV) {
+			pci_warn(pdev, "Failed to setup zPCI CLP region\n");
+			goto disable_exit;
+		}
+	}
+
 	vfio_pci_probe_mmaps(vdev);
 
 	return 0;
drivers/vfio/pci/vfio_pci_private.h +10 -0
index 61ca8ab..729af20 100644
@@ -213,4 +213,14 @@ static inline int vfio_pci_ibm_npu2_init(struct vfio_pci_device *vdev)
 	return -ENODEV;
 }
 #endif
+
+#ifdef CONFIG_VFIO_PCI_ZDEV
+extern int vfio_pci_zdev_init(struct vfio_pci_device *vdev);
+#else
+static inline int vfio_pci_zdev_init(struct vfio_pci_device *vdev)
+{
+	return -ENODEV;
+}
+#endif
+
 #endif /* VFIO_PCI_PRIVATE_H */
drivers/vfio/pci/vfio_pci_zdev.c new file +242 -0

242 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#15 lore raw

Re: [PATCH 4/4] vfio-pci/zdev: use a device region to retrieve zPCI information

Quoted 8 lines · On Sat, 19 Sep 2020 11:28:38 -0400 Matthew Rosato <[email protected]>…

Define a new configuration entry VFIO_PCI_ZDEV for VFIO/PCI.

When this s390-only feature is configured we initialize a new device region, VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP, to hold information provided by the underlying hardware.

This patch is based on work previously done by Pierre Morel.

Quoted 7 lines
---
 drivers/vfio/pci/Kconfig            |  13 ++
 drivers/vfio/pci/Makefile           |   1 +
 drivers/vfio/pci/vfio_pci.c         |   8 ++
 drivers/vfio/pci/vfio_pci_private.h |  10 ++
 drivers/vfio/pci/vfio_pci_zdev.c    | 242 ++++++++++++++++++++++++++++++++++++

Maybe you want to add yourself to MAINTAINERS for the zdev-specific files? You're probably better suited to review changes to the zpci-specific code :)

Quoted 2 lines
 5 files changed, 274 insertions(+)
 create mode 100644 drivers/vfio/pci/vfio_pci_zdev.c

(...)

Quoted 26 lines
drivers/vfio/pci/vfio_pci_zdev.c new file +26 -0
+int vfio_pci_zdev_init(struct vfio_pci_device *vdev)
+{
+	struct vfio_region_zpci_info *region;
+	struct zpci_dev *zdev;
+	size_t clp_offset;
+	int size;
+	int ret;
+
+	if (!vdev->pdev->bus)
+		return -ENODEV;
+
+	zdev = to_zpci(vdev->pdev);
+	if (!zdev)
+		return -ENODEV;
+
+	/* Calculate size needed for all supported CLP features  */
+	size = sizeof(*region) +
+	       sizeof(struct vfio_region_zpci_info_qpci) +
+	       sizeof(struct vfio_region_zpci_info_qpcifg) +
+	       (sizeof(struct vfio_region_zpci_info_util) + CLP_UTIL_STR_LEN) +
+	       (sizeof(struct vfio_region_zpci_info_pfip) +
+		CLP_PFIP_NR_SEGMENTS);
+
+	region = kmalloc(size, GFP_KERNEL);
+	if (!region)
+		return -ENOMEM;

drivers/vfio/pci/vfio_pci_zdev.c line 232

Quoted 10 lines
drivers/vfio/pci/vfio_pci_zdev.c new file +10 -0
+
+	/* Fill in header */
+	region->argsz = size;
+	clp_offset = region->offset = sizeof(struct vfio_region_zpci_info);
+
+	/* Fill the supported CLP features */
+	clp_offset = vfio_pci_zdev_add_qpci(zdev, region, clp_offset);
+	clp_offset = vfio_pci_zdev_add_qpcifg(zdev, region, clp_offset);
+	clp_offset = vfio_pci_zdev_add_util(zdev, region, clp_offset);
+	clp_offset = vfio_pci_zdev_add_pfip(zdev, region, clp_offset);

So, the regions are populated once. Can any of the values in the hardware structures be modified by a guest? Or changed from the hardware side?

Quoted 10 lines
drivers/vfio/pci/vfio_pci_zdev.c new file +10 -0
+
+	ret = vfio_pci_register_dev_region(vdev,
+		PCI_VENDOR_ID_IBM | VFIO_REGION_TYPE_PCI_VENDOR_TYPE,
+		VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP, &vfio_pci_zdev_regops,
+		size, VFIO_REGION_INFO_FLAG_READ, region);
+	if (ret)
+		kfree(region);
+
+	return ret;
+}
author maintainer
#16 lore raw

Re: [PATCH 4/4] vfio-pci/zdev: use a device region to retrieve zPCI information

Quoted 19 lines · Cornelia Huck
Quoted 8 lines · On Sat, 19 Sep 2020 11:28:38 -0400 Matthew Rosato <[email protected]>…

Define a new configuration entry VFIO_PCI_ZDEV for VFIO/PCI.

When this s390-only feature is configured we initialize a new device region, VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP, to hold information provided by the underlying hardware.

This patch is based on work previously done by Pierre Morel.

Quoted 7 lines
---
  drivers/vfio/pci/Kconfig            |  13 ++
  drivers/vfio/pci/Makefile           |   1 +
  drivers/vfio/pci/vfio_pci.c         |   8 ++
  drivers/vfio/pci/vfio_pci_private.h |  10 ++
  drivers/vfio/pci/vfio_pci_zdev.c    | 242 ++++++++++++++++++++++++++++++++++++
Quoted 3 lines

Maybe you want to add yourself to MAINTAINERS for the zdev-specific files? You're probably better suited to review changes to the zpci-specific code :)

Of course, will do. Looking at how we split vfio-ap and vfio-ccw, I'll add an S390 VFIO-PCI DRIVER category and point to the new .h and .c file for now.

Quoted 38 lines
Quoted 3 lines
  5 files changed, 274 insertions(+)

create mode 100644 drivers/vfio/pci/vfio_pci_zdev.c

(...)

Quoted 32 lines
drivers/vfio/pci/vfio_pci_zdev.c new file +32 -0
+int vfio_pci_zdev_init(struct vfio_pci_device *vdev)
+{
+	struct vfio_region_zpci_info *region;
+	struct zpci_dev *zdev;
+	size_t clp_offset;
+	int size;
+	int ret;
+
+	if (!vdev->pdev->bus)
+		return -ENODEV;
+
+	zdev = to_zpci(vdev->pdev);
+	if (!zdev)
+		return -ENODEV;
+
+	/* Calculate size needed for all supported CLP features  */
+	size = sizeof(*region) +
+	       sizeof(struct vfio_region_zpci_info_qpci) +
+	       sizeof(struct vfio_region_zpci_info_qpcifg) +
+	       (sizeof(struct vfio_region_zpci_info_util) + CLP_UTIL_STR_LEN) +
+	       (sizeof(struct vfio_region_zpci_info_pfip) +
+		CLP_PFIP_NR_SEGMENTS);
+
+	region = kmalloc(size, GFP_KERNEL);
+	if (!region)
+		return -ENOMEM;
+
+	/* Fill in header */
+	region->argsz = size;
+	clp_offset = region->offset = sizeof(struct vfio_region_zpci_info);
+
+	/* Fill the supported CLP features */
Quoted 9 lines

drivers/vfio/pci/vfio_pci_zdev.c line 232

Quoted 4 lines
drivers/vfio/pci/vfio_pci_zdev.c new file +4 -0
+	clp_offset = vfio_pci_zdev_add_qpci(zdev, region, clp_offset);
+	clp_offset = vfio_pci_zdev_add_qpcifg(zdev, region, clp_offset);
+	clp_offset = vfio_pci_zdev_add_util(zdev, region, clp_offset);
+	clp_offset = vfio_pci_zdev_add_pfip(zdev, region, clp_offset);

So, the regions are populated once. Can any of the values in the hardware structures be modified by a guest? Or changed from the hardware side?

The region is created read-only (vfio_pci_zdev_rw returns -EINVAL on writes), so no guest modification. The expectation is the guest can read the region and take what it wants / ignore what it doesn't.

The CLPs covered by this region are not intended to change once the device is up.

If we end up needing either of the above for a different CLP, I would think an additional/different region would be appropriate.

Quoted 11 lines
Quoted 10 lines
drivers/vfio/pci/vfio_pci_zdev.c new file +10 -0
+
+	ret = vfio_pci_register_dev_region(vdev,
+		PCI_VENDOR_ID_IBM | VFIO_REGION_TYPE_PCI_VENDOR_TYPE,
+		VFIO_REGION_SUBTYPE_IBM_ZPCI_CLP, &vfio_pci_zdev_regops,
+		size, VFIO_REGION_INFO_FLAG_READ, region);
+	if (ret)
+		kfree(region);
+
+	return ret;
+}
author maintainer
#17 lore raw
In reply to Matthew Rosato
Quoted 15 lines · Matthew Rosato

This patchset provides a means by which hardware information about the underlying PCI device can be passed up to userspace (ie, QEMU) so that this hardware information can be used rather than previously hard-coded assumptions. A new VFIO region type is defined which holds this information.

A form of these patches saw some rounds last year but has been back- tabled for a while. The original work for this feature was done by Pierre Morel. I'd like to refresh the discussion on this and get this finished up so that we can move forward with better-supporting additional types of PCI-attached devices. The proposal here presents a completely different region mapping vs the prior approach, taking inspiration from vfio info capability chains to provide device CLP information in a way that allows for future expansion (new CLP features).

Quoted 1 line

This feature is toggled via the CONFIG_VFIO_PCI_ZDEV configuration entry.

QEMU patchset that exploits the new region:
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg07076.html

Quoted 20 lines

Matthew Rosato (4):
s390/pci: stash version in the zpci_dev
s390/pci: track whether util_str is valid in the zpci_dev vfio-pci/zdev: define the vfio_zdev header vfio-pci/zdev: use a device region to retrieve zPCI information

  arch/s390/include/asm/pci.h         |   4 +-
  arch/s390/pci/pci_clp.c             |   2 +
  drivers/vfio/pci/Kconfig            |  13 ++
  drivers/vfio/pci/Makefile           |   1 +
  drivers/vfio/pci/vfio_pci.c         |   8 ++
  drivers/vfio/pci/vfio_pci_private.h |  10 ++
  drivers/vfio/pci/vfio_pci_zdev.c    | 242 ++++++++++++++++++++++++++++++++++++
  include/uapi/linux/vfio.h           |   5 +
  include/uapi/linux/vfio_zdev.h      | 116 +++++++++++++++++
  9 files changed, 400 insertions(+), 1 deletion(-)

create mode 100644 drivers/vfio/pci/vfio_pci_zdev.c create mode 100644 include/uapi/linux/vfio_zdev.h