Skip to contentSkip to conversation

KVM: s390: enable zPCI for interpretive execution

PATCH Superseded Matthew Rosato 9 participants 63 messages Feb 4, 2022 – Feb 14, 2022

Subsystems (11)
KVM s390 IOMMU VFIO driver +7 more subsystems

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Matthew Rosato

author maintainer
#0 lore raw

v3 cover KVM: s390: enable zPCI for interpretive execution

Enable interpretive execution of zPCI instructions + adapter interruption forwarding for s390x KVM vfio-pci. This is done by introducing a series of new vfio-pci feature ioctls that are unique vfio-pci-zdev (s390x) and are used to negotiate the various aspects of zPCI interpretation setup. By allowing intepretation of zPCI instructions and firmware delivery of interrupts to guests, we can significantly reduce the frequency of guest SIE exits for zPCI. We then see additional gains by handling a hot-path instruction that can still intercept to the hypervisor (RPCIT) directly in kvm.

From the perspective of guest configuration, you passthrough zPCI devices in the same manner as before, with intepretation support being used by default if available in kernel+qemu.

Will reply with a link to the associated QEMU series.

Changelog v2->v3:
- More R-bs / ACKs (Thanks!)
- Re-word patch 6 commit message (Claudio)
- Patch 8 + some later patches: s/gd/gisa/ (Pierre)
- Patch 12: remove !mdd check (Pierre)
- some more virt/phys conversions (Pierre)
- Patch 18: check more sclp bits & facilities during interp probe (Pierre)
- Patch 21: fix fabricated status for some RPCIT intercept errors
- Patch 25-27: remove get/set checks from feature ioctl handlers as they are already done in vfio core (Pierre)
- Patch 26: s/aif/aif_float/ and s/fhost/aif_fhost/
- remove kvm_s390_pci_attach_kvm and just do the work inline (Pierre)
- Use CONFIG_VFIO_PCI_ZDEV instead of CONFIG_PCI in Makefile and other code locations (Pierre)
- Due to the above, re-arrange series order so CONFIG_VFIO_PCI_ZDEV is introduced earlier
- s/aift->lock/aift->aift_lock/ (Pierre)
- Break some AEN init code into local functions zpci_setup_aipb() and zpci_reset_aipb() (Pierre)
- check for errors on kvm_s390_gisc_register (Pierre)
- handle airq clear errors differently when we know the device is being removed vs any other reason aif is being disabled (Pierre)
- s/ioat->lock/ioat->ioat_lock/ (Pierre)
- Fix backout case in kvm_s390_pci_ioat_enable, re-arrange rc settings slightly (Pierre)
- Add a CONFIG_VFIO_PCI_ZDEV check when determining if its safe to allow KVM_S390_VM_CPU_FEAT_ZPCI_INTERP (need both the facilities and the kvm/pci.o pieces to allow intepretation)

Matthew Rosato (30):
s390/sclp: detect the zPCI load/store interpretation facility s390/sclp: detect the AISII facility
s390/sclp: detect the AENI facility
s390/sclp: detect the AISI facility
s390/airq: pass more TPI info to airq handlers
s390/airq: allow for airq structure that uses an input vector s390/pci: externalize the SIC operation controls and routine s390/pci: stash associated GISA designation
s390/pci: export some routines related to RPCIT processing s390/pci: stash dtsm and maxstbl
s390/pci: add helper function to find device by handle s390/pci: get SHM information from list pci
s390/pci: return status from zpci_refresh_trans
vfio/pci: re-introduce CONFIG_VFIO_PCI_ZDEV
KVM: s390: pci: add basic kvm_zdev structure
KVM: s390: pci: do initial setup for AEN interpretation
KVM: s390: pci: enable host forwarding of Adapter Event Notifications
KVM: s390: mechanism to enable guest zPCI Interpretation
KVM: s390: pci: provide routines for enabling/disabling interpretation
KVM: s390: pci: provide routines for enabling/disabling interrupt
forwarding
KVM: s390: pci: provide routines for enabling/disabling IOAT assist
KVM: s390: pci: handle refresh of PCI translations
KVM: s390: intercept the rpcit instruction
vfio-pci/zdev: wire up group notifier
vfio-pci/zdev: wire up zPCI interpretive execution support vfio-pci/zdev: wire up zPCI adapter interrupt forwarding support vfio-pci/zdev: wire up zPCI IOAT assist support vfio-pci/zdev: add DTSM to clp group capability
KVM: s390: introduce CPU feature for zPCI Interpretation
MAINTAINERS: additional files related kvm s390 pci passthrough

 MAINTAINERS                      |   2 +
 arch/s390/include/asm/airq.h     |   7 +-
 arch/s390/include/asm/kvm_host.h |   5 +
 arch/s390/include/asm/kvm_pci.h  |  60 +++
 arch/s390/include/asm/pci.h      |  12 +
 arch/s390/include/asm/pci_clp.h  |  11 +-
 arch/s390/include/asm/pci_dma.h  |   3 +
 arch/s390/include/asm/pci_insn.h |  31 +-
 arch/s390/include/asm/sclp.h     |   4 +
 arch/s390/include/asm/tpi.h      |  13 +
 arch/s390/include/uapi/asm/kvm.h |   1 +
 arch/s390/kvm/Makefile           |   1 +
 arch/s390/kvm/interrupt.c        |  95 +++-
 arch/s390/kvm/kvm-s390.c         |  57 ++-
 arch/s390/kvm/kvm-s390.h         |  10 +
 arch/s390/kvm/pci.c              | 850 +++++++++++++++++++++++++++++++
 arch/s390/kvm/pci.h              |  60 +++
 arch/s390/kvm/priv.c             |  49 ++
 arch/s390/pci/pci.c              |  31 ++
 arch/s390/pci/pci_clp.c          |  28 +-
 arch/s390/pci/pci_dma.c          |   7 +-
 arch/s390/pci/pci_insn.c         |  15 +-
 arch/s390/pci/pci_irq.c          |  48 +-
 drivers/iommu/s390-iommu.c       |   4 +-
 drivers/s390/char/sclp_early.c   |   4 +
 drivers/s390/cio/airq.c          |  12 +-
 drivers/s390/cio/qdio_thinint.c  |   6 +-
 drivers/s390/crypto/ap_bus.c     |   9 +-
 drivers/s390/virtio/virtio_ccw.c |   6 +-
 drivers/vfio/pci/Kconfig         |  11 +
 drivers/vfio/pci/Makefile        |   2 +-
 drivers/vfio/pci/vfio_pci_core.c |   8 +
 drivers/vfio/pci/vfio_pci_zdev.c | 275 +++++++++-
 include/linux/vfio_pci_core.h    |  42 +-
 include/uapi/linux/vfio.h        |  22 +
 include/uapi/linux/vfio_zdev.h   |  51 ++
 36 files changed, 1787 insertions(+), 65 deletions(-)
 create mode 100644 arch/s390/include/asm/kvm_pci.h
 create mode 100644 arch/s390/kvm/pci.c
 create mode 100644 arch/s390/kvm/pci.h
Signature · 1 line
2.27.0
author maintainer
#1 lore raw

PATCH v3 1/30 s390/sclp: detect the zPCI load/store interpretation facility

Detect the zPCI Load/Store Interpretation facility.

---
 arch/s390/include/asm/sclp.h   | 1 +
 drivers/s390/char/sclp_early.c | 1 +
 2 files changed, 2 insertions(+)
arch/s390/include/asm/sclp.h +1 -0
index c68ea35de498..58a4d3d354b7 100644
@@ -88,6 +88,7 @@ struct sclp_info {
 	unsigned char has_diag318 : 1;
 	unsigned char has_sipl : 1;
 	unsigned char has_dirq : 1;
+	unsigned char has_zpci_lsi : 1;
 	unsigned int ibc;
 	unsigned int mtid;
 	unsigned int mtid_cp;
drivers/s390/char/sclp_early.c +1 -0
index e9943a86c361..b88dd0da1231 100644
@@ -45,6 +45,7 @@ static void __init sclp_early_facilities_detect(void)
 	sclp.has_gisaf = !!(sccb->fac118 & 0x08);
 	sclp.has_hvs = !!(sccb->fac119 & 0x80);
 	sclp.has_kss = !!(sccb->fac98 & 0x01);
+	sclp.has_zpci_lsi = !!(sccb->fac118 & 0x01);
 	if (sccb->fac85 & 0x02)
 		S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
 	if (sccb->fac91 & 0x40)
Signature · 1 line
2.27.0
author maintainer
#2 lore raw

PATCH v3 2/30 s390/sclp: detect the AISII facility

In reply to Matthew Rosato

Detect the Adapter Interruption Source ID Interpretation facility.

---
 arch/s390/include/asm/sclp.h   | 1 +
 drivers/s390/char/sclp_early.c | 1 +
 2 files changed, 2 insertions(+)
arch/s390/include/asm/sclp.h +1 -0
index 58a4d3d354b7..8b56ac5ae496 100644
@@ -89,6 +89,7 @@ struct sclp_info {
 	unsigned char has_sipl : 1;
 	unsigned char has_dirq : 1;
 	unsigned char has_zpci_lsi : 1;
+	unsigned char has_aisii : 1;
 	unsigned int ibc;
 	unsigned int mtid;
 	unsigned int mtid_cp;
drivers/s390/char/sclp_early.c +1 -0
index b88dd0da1231..29fee179e197 100644
@@ -45,6 +45,7 @@ static void __init sclp_early_facilities_detect(void)
 	sclp.has_gisaf = !!(sccb->fac118 & 0x08);
 	sclp.has_hvs = !!(sccb->fac119 & 0x80);
 	sclp.has_kss = !!(sccb->fac98 & 0x01);
+	sclp.has_aisii = !!(sccb->fac118 & 0x40);
 	sclp.has_zpci_lsi = !!(sccb->fac118 & 0x01);
 	if (sccb->fac85 & 0x02)
 		S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
Signature · 1 line
2.27.0
author maintainer
#3 lore raw

PATCH v3 3/30 s390/sclp: detect the AENI facility

In reply to Matthew Rosato

Detect the Adapter Event Notification Interpretation facility.

---
 arch/s390/include/asm/sclp.h   | 1 +
 drivers/s390/char/sclp_early.c | 1 +
 2 files changed, 2 insertions(+)
arch/s390/include/asm/sclp.h +1 -0
index 8b56ac5ae496..8c2e142000d4 100644
@@ -90,6 +90,7 @@ struct sclp_info {
 	unsigned char has_dirq : 1;
 	unsigned char has_zpci_lsi : 1;
 	unsigned char has_aisii : 1;
+	unsigned char has_aeni : 1;
 	unsigned int ibc;
 	unsigned int mtid;
 	unsigned int mtid_cp;
drivers/s390/char/sclp_early.c +1 -0
index 29fee179e197..e9af01b4c97a 100644
@@ -46,6 +46,7 @@ static void __init sclp_early_facilities_detect(void)
 	sclp.has_hvs = !!(sccb->fac119 & 0x80);
 	sclp.has_kss = !!(sccb->fac98 & 0x01);
 	sclp.has_aisii = !!(sccb->fac118 & 0x40);
+	sclp.has_aeni = !!(sccb->fac118 & 0x20);
 	sclp.has_zpci_lsi = !!(sccb->fac118 & 0x01);
 	if (sccb->fac85 & 0x02)
 		S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
Signature · 1 line
2.27.0
author maintainer
#4 lore raw

PATCH v3 4/30 s390/sclp: detect the AISI facility

In reply to Matthew Rosato

Detect the Adapter Interruption Suppression Interpretation facility.

---
 arch/s390/include/asm/sclp.h   | 1 +
 drivers/s390/char/sclp_early.c | 1 +
 2 files changed, 2 insertions(+)
arch/s390/include/asm/sclp.h +1 -0
index 8c2e142000d4..33b174007848 100644
@@ -91,6 +91,7 @@ struct sclp_info {
 	unsigned char has_zpci_lsi : 1;
 	unsigned char has_aisii : 1;
 	unsigned char has_aeni : 1;
+	unsigned char has_aisi : 1;
 	unsigned int ibc;
 	unsigned int mtid;
 	unsigned int mtid_cp;
drivers/s390/char/sclp_early.c +1 -0
index e9af01b4c97a..c13e55cc4a5d 100644
@@ -47,6 +47,7 @@ static void __init sclp_early_facilities_detect(void)
 	sclp.has_kss = !!(sccb->fac98 & 0x01);
 	sclp.has_aisii = !!(sccb->fac118 & 0x40);
 	sclp.has_aeni = !!(sccb->fac118 & 0x20);
+	sclp.has_aisi = !!(sccb->fac118 & 0x10);
 	sclp.has_zpci_lsi = !!(sccb->fac118 & 0x01);
 	if (sccb->fac85 & 0x02)
 		S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
Signature · 1 line
2.27.0
author maintainer
#5 lore raw

PATCH v3 5/30 s390/airq: pass more TPI info to airq handlers

In reply to Matthew Rosato

A subsequent patch will introduce an airq handler that requires additional TPI information beyond directed vs floating, so pass the entire tpi_info structure via the handler. Only pci actually uses this information today, for the other airq handlers this is effectively a no-op.

---
 arch/s390/include/asm/airq.h     | 3 ++-
 arch/s390/kvm/interrupt.c        | 4 +++-
 arch/s390/pci/pci_irq.c          | 9 +++++++--
 drivers/s390/cio/airq.c          | 2 +-
 drivers/s390/cio/qdio_thinint.c  | 6 ++++--
 drivers/s390/crypto/ap_bus.c     | 9 ++++++---
 drivers/s390/virtio/virtio_ccw.c | 4 +++-
 7 files changed, 26 insertions(+), 11 deletions(-)
arch/s390/include/asm/airq.h +2 -1
index 01936fdfaddb..7918a7d09028 100644
@@ -12,10 +12,11 @@
 
 #include <linux/bit_spinlock.h>
 #include <linux/dma-mapping.h>
+#include <asm/tpi.h>
 
 struct airq_struct {
 	struct hlist_node list;		/* Handler queueing. */
-	void (*handler)(struct airq_struct *airq, bool floating);
+	void (*handler)(struct airq_struct *airq, struct tpi_info *tpi_info);
 	u8 *lsi_ptr;			/* Local-Summary-Indicator pointer */
 	u8 lsi_mask;			/* Local-Summary-Indicator mask */
 	u8 isc;				/* Interrupt-subclass */
arch/s390/kvm/interrupt.c +3 -1
index db933c252dbc..65e75ca2fc5d 100644
@@ -28,6 +28,7 @@
 #include <asm/switch_to.h>
 #include <asm/nmi.h>
 #include <asm/airq.h>
+#include <asm/tpi.h>
 #include "kvm-s390.h"
 #include "gaccess.h"
 #include "trace-s390.h"
@@ -3269,7 +3270,8 @@ int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc)
 }
 EXPORT_SYMBOL_GPL(kvm_s390_gisc_unregister);
 
-static void gib_alert_irq_handler(struct airq_struct *airq, bool floating)
+static void gib_alert_irq_handler(struct airq_struct *airq,
+				  struct tpi_info *tpi_info)
 {
 	inc_irq_stat(IRQIO_GAL);
 	process_gib_alert_list();
arch/s390/pci/pci_irq.c +7 -2
index 2b6062c486f5..cc4c8d7c8f5c 100644
@@ -11,6 +11,7 @@
 
 #include <asm/isc.h>
 #include <asm/airq.h>
+#include <asm/tpi.h>
 
 static enum {FLOATING, DIRECTED} irq_delivery;
 
@@ -216,8 +217,11 @@ static void zpci_handle_fallback_irq(void)
 	}
 }
 
-static void zpci_directed_irq_handler(struct airq_struct *airq, bool floating)
+static void zpci_directed_irq_handler(struct airq_struct *airq,
+				      struct tpi_info *tpi_info)
 {
+	bool floating = !tpi_info->directed_irq;
+
 	if (floating) {
 		inc_irq_stat(IRQIO_PCF);
 		zpci_handle_fallback_irq();
@@ -227,7 +231,8 @@ static void zpci_directed_irq_handler(struct airq_struct *airq, bool floating)
 	}
 }
 
-static void zpci_floating_irq_handler(struct airq_struct *airq, bool floating)
+static void zpci_floating_irq_handler(struct airq_struct *airq,
+				      struct tpi_info *tpi_info)
 {
 	unsigned long si, ai;
 	struct airq_iv *aibv;
drivers/s390/cio/airq.c +1 -1
index e56535c99888..2f2226786319 100644
@@ -99,7 +99,7 @@ static irqreturn_t do_airq_interrupt(int irq, void *dummy)
 	rcu_read_lock();
 	hlist_for_each_entry_rcu(airq, head, list)
 		if ((*airq->lsi_ptr & airq->lsi_mask) != 0)
-			airq->handler(airq, !tpi_info->directed_irq);
+			airq->handler(airq, tpi_info);
 	rcu_read_unlock();
 
 	return IRQ_HANDLED;
drivers/s390/cio/qdio_thinint.c +4 -2
index 8e09bf3a2fcd..9b9335dd06db 100644
@@ -15,6 +15,7 @@
 #include <asm/qdio.h>
 #include <asm/airq.h>
 #include <asm/isc.h>
+#include <asm/tpi.h>
 
 #include "cio.h"
 #include "ioasm.h"
@@ -93,9 +94,10 @@ static inline u32 clear_shared_ind(void)
 /**
  * tiqdio_thinint_handler - thin interrupt handler for qdio
  * @airq: pointer to adapter interrupt descriptor
- * @floating: flag to recognize floating vs. directed interrupts (unused)
+ * @tpi_info: interrupt information (e.g. floating vs directed -- unused)
  */
-static void tiqdio_thinint_handler(struct airq_struct *airq, bool floating)
+static void tiqdio_thinint_handler(struct airq_struct *airq,
+				   struct tpi_info *tpi_info)
 {
 	u64 irq_time = S390_lowcore.int_clock;
 	u32 si_used = clear_shared_ind();
drivers/s390/crypto/ap_bus.c +6 -3
index 1986243f9cd3..df1a038442db 100644
@@ -27,6 +27,7 @@
 #include <linux/kthread.h>
 #include <linux/mutex.h>
 #include <asm/airq.h>
+#include <asm/tpi.h>
 #include <linux/atomic.h>
 #include <asm/isc.h>
 #include <linux/hrtimer.h>
@@ -129,7 +130,8 @@ static int ap_max_adapter_id = 63;
 static struct bus_type ap_bus_type;
 
 /* Adapter interrupt definitions */
-static void ap_interrupt_handler(struct airq_struct *airq, bool floating);
+static void ap_interrupt_handler(struct airq_struct *airq,
+				 struct tpi_info *tpi_info);
 
 static bool ap_irq_flag;
 
@@ -442,9 +444,10 @@ static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
 /**
  * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
  * @airq: pointer to adapter interrupt descriptor
- * @floating: ignored
+ * @tpi_info: ignored
  */
-static void ap_interrupt_handler(struct airq_struct *airq, bool floating)
+static void ap_interrupt_handler(struct airq_struct *airq,
+				 struct tpi_info *tpi_info)
 {
 	inc_irq_stat(IRQIO_APB);
 	tasklet_schedule(&ap_tasklet);
drivers/s390/virtio/virtio_ccw.c +3 -1
index d35e7a3f7067..52c376d15978 100644
@@ -33,6 +33,7 @@
 #include <asm/virtio-ccw.h>
 #include <asm/isc.h>
 #include <asm/airq.h>
+#include <asm/tpi.h>
 
 /*
  * virtio related functions
@@ -203,7 +204,8 @@ static void drop_airq_indicator(struct virtqueue *vq, struct airq_info *info)
 	write_unlock_irqrestore(&info->lock, flags);
 }
 
-static void virtio_airq_handler(struct airq_struct *airq, bool floating)
+static void virtio_airq_handler(struct airq_struct *airq,
+				struct tpi_info *tpi_info)
 {
 	struct airq_info *info = container_of(airq, struct airq_info, airq);
 	unsigned long ai;
Signature · 1 line
2.27.0
maintainer Acked-by on v3 5/30
#6 lore raw

Re: [PATCH v3 05/30] s390/airq: pass more TPI info to airq handlers

Quoted 11 lines · Matthew Rosato

A subsequent patch will introduce an airq handler that requires additional TPI information beyond directed vs floating, so pass the entire tpi_info structure via the handler. Only pci actually uses this information today, for the other airq handlers this is effectively a no-op.

Quoted 9 lines
---
 arch/s390/include/asm/airq.h     | 3 ++-
 arch/s390/kvm/interrupt.c        | 4 +++-
 arch/s390/pci/pci_irq.c          | 9 +++++++--
 drivers/s390/cio/airq.c          | 2 +-
 drivers/s390/cio/qdio_thinint.c  | 6 ++++--
 drivers/s390/crypto/ap_bus.c     | 9 ++++++---
 drivers/s390/virtio/virtio_ccw.c | 4 +++-
 7 files changed, 26 insertions(+), 11 deletions(-)

For virtio-ccw:

author maintainer
#7 lore raw

PATCH v3 6/30 s390/airq: allow for airq structure that uses an input vector

In reply to Matthew Rosato

When doing device passthrough where interrupts are being forwarded from host to guest, we wish to use a pinned section of guest memory as the vector (the same memory used by the guest as the vector). To accomplish this, add a new parameter for airq_iv_create which allows passing an existing vector to be used instead of allocating a new one. The caller is responsible for ensuring the vector is pinned in memory as well as for unpinning the memory when the vector is no longer needed.

A subsequent patch will use this new parameter for zPCI interpretation.

---
 arch/s390/include/asm/airq.h     |  4 +++-
 arch/s390/pci/pci_irq.c          |  8 ++++----
 drivers/s390/cio/airq.c          | 10 +++++++---
 drivers/s390/virtio/virtio_ccw.c |  2 +-
 4 files changed, 15 insertions(+), 9 deletions(-)
arch/s390/include/asm/airq.h +3 -1
index 7918a7d09028..e82e5626e139 100644
@@ -47,8 +47,10 @@ struct airq_iv {
 #define AIRQ_IV_PTR		4	/* Allocate the ptr array */
 #define AIRQ_IV_DATA		8	/* Allocate the data array */
 #define AIRQ_IV_CACHELINE	16	/* Cacheline alignment for the vector */
+#define AIRQ_IV_GUESTVEC	32	/* Vector is a pinned guest page */
 
-struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags);
+struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags,
+			       unsigned long *vec);
 void airq_iv_release(struct airq_iv *iv);
 unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num);
 void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num);
arch/s390/pci/pci_irq.c +4 -4
index cc4c8d7c8f5c..0d0a02a9fbbf 100644
@@ -296,7 +296,7 @@ int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
 		zdev->aisb = bit;
 
 		/* Create adapter interrupt vector */
-		zdev->aibv = airq_iv_create(msi_vecs, AIRQ_IV_DATA | AIRQ_IV_BITLOCK);
+		zdev->aibv = airq_iv_create(msi_vecs, AIRQ_IV_DATA | AIRQ_IV_BITLOCK, NULL);
 		if (!zdev->aibv)
 			return -ENOMEM;
 
@@ -419,7 +419,7 @@ static int __init zpci_directed_irq_init(void)
 	union zpci_sic_iib iib = {{0}};
 	unsigned int cpu;
 
-	zpci_sbv = airq_iv_create(num_possible_cpus(), 0);
+	zpci_sbv = airq_iv_create(num_possible_cpus(), 0, NULL);
 	if (!zpci_sbv)
 		return -ENOMEM;
 
@@ -441,7 +441,7 @@ static int __init zpci_directed_irq_init(void)
 		zpci_ibv[cpu] = airq_iv_create(cache_line_size() * BITS_PER_BYTE,
 					       AIRQ_IV_DATA |
 					       AIRQ_IV_CACHELINE |
-					       (!cpu ? AIRQ_IV_ALLOC : 0));
+					       (!cpu ? AIRQ_IV_ALLOC : 0), NULL);
 		if (!zpci_ibv[cpu])
 			return -ENOMEM;
 	}
@@ -458,7 +458,7 @@ static int __init zpci_floating_irq_init(void)
 	if (!zpci_ibv)
 		return -ENOMEM;
 
-	zpci_sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC);
+	zpci_sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC, NULL);
 	if (!zpci_sbv)
 		goto out_free;
 
drivers/s390/cio/airq.c +7 -3
index 2f2226786319..375a58b1c838 100644
@@ -122,10 +122,12 @@ static inline unsigned long iv_size(unsigned long bits)
  * airq_iv_create - create an interrupt vector
  * @bits: number of bits in the interrupt vector
  * @flags: allocation flags
+ * @vec: pointer to pinned guest memory if AIRQ_IV_GUESTVEC
  *
  * Returns a pointer to an interrupt vector structure
  */
-struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
+struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags,
+			       unsigned long *vec)
 {
 	struct airq_iv *iv;
 	unsigned long size;
@@ -146,6 +148,8 @@ struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
 					     &iv->vector_dma);
 		if (!iv->vector)
 			goto out_free;
+	} else if (flags & AIRQ_IV_GUESTVEC) {
+		iv->vector = vec;
 	} else {
 		iv->vector = cio_dma_zalloc(size);
 		if (!iv->vector)
@@ -185,7 +189,7 @@ struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
 	kfree(iv->avail);
 	if (iv->flags & AIRQ_IV_CACHELINE && iv->vector)
 		dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma);
-	else
+	else if (!(iv->flags & AIRQ_IV_GUESTVEC))
 		cio_dma_free(iv->vector, size);
 	kfree(iv);
 out:
@@ -204,7 +208,7 @@ void airq_iv_release(struct airq_iv *iv)
 	kfree(iv->bitlock);
 	if (iv->flags & AIRQ_IV_CACHELINE)
 		dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma);
-	else
+	else if (!(iv->flags & AIRQ_IV_GUESTVEC))
 		cio_dma_free(iv->vector, iv_size(iv->bits));
 	kfree(iv->avail);
 	kfree(iv);
drivers/s390/virtio/virtio_ccw.c +1 -1
index 52c376d15978..410498d693f8 100644
@@ -241,7 +241,7 @@ static struct airq_info *new_airq_info(int index)
 		return NULL;
 	rwlock_init(&info->lock);
 	info->aiv = airq_iv_create(VIRTIO_IV_BITS, AIRQ_IV_ALLOC | AIRQ_IV_PTR
-				   | AIRQ_IV_CACHELINE);
+				   | AIRQ_IV_CACHELINE, NULL);
 	if (!info->aiv) {
 		kfree(info);
 		return NULL;
Signature · 1 line
2.27.0
maintainer Acked-by on v3 6/30
#8 lore raw

Re: [PATCH v3 06/30] s390/airq: allow for airq structure that uses an input vector

Quoted 10 lines · Matthew Rosato

When doing device passthrough where interrupts are being forwarded from host to guest, we wish to use a pinned section of guest memory as the vector (the same memory used by the guest as the vector). To accomplish this, add a new parameter for airq_iv_create which allows passing an existing vector to be used instead of allocating a new one. The caller is responsible for ensuring the vector is pinned in memory as well as for unpinning the memory when the vector is no longer needed.

A subsequent patch will use this new parameter for zPCI interpretation.

Quoted 8 lines
---
 arch/s390/include/asm/airq.h     |  4 +++-
 arch/s390/pci/pci_irq.c          |  8 ++++----
 drivers/s390/cio/airq.c          | 10 +++++++---
 drivers/s390/virtio/virtio_ccw.c |  2 +-
 4 files changed, 15 insertions(+), 9 deletions(-)

For virtio-ccw:

maintainer Reviewed-by on v3 6/30
#9 lore raw

Re: [PATCH v3 06/30] s390/airq: allow for airq structure that uses an input vector

In reply to Matthew Rosato
Quoted 8 lines · On Fri, 4 Feb 2022 16:15:12 -0500 Matthew Rosato <[email protected]>…

When doing device passthrough where interrupts are being forwarded from host to guest, we wish to use a pinned section of guest memory as the vector (the same memory used by the guest as the vector). To accomplish this, add a new parameter for airq_iv_create which allows passing an existing vector to be used instead of allocating a new one. The caller is responsible for ensuring the vector is pinned in memory as well as for unpinning the memory when the vector is no longer needed.

Quoted 4 lines

A subsequent patch will use this new parameter for zPCI interpretation.

Quoted 121 lines
---
 arch/s390/include/asm/airq.h     |  4 +++-
 arch/s390/pci/pci_irq.c          |  8 ++++----
 drivers/s390/cio/airq.c          | 10 +++++++---
 drivers/s390/virtio/virtio_ccw.c |  2 +-
 4 files changed, 15 insertions(+), 9 deletions(-)
arch/s390/include/asm/airq.h +3 -1
index 7918a7d09028..e82e5626e139 100644
@@ -47,8 +47,10 @@ struct airq_iv {
 #define AIRQ_IV_PTR		4	/* Allocate the ptr array */
 #define AIRQ_IV_DATA		8	/* Allocate the data array */
 #define AIRQ_IV_CACHELINE	16	/* Cacheline alignment for the vector */
+#define AIRQ_IV_GUESTVEC	32	/* Vector is a pinned guest page */
 
-struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags);
+struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags,
+			       unsigned long *vec);
 void airq_iv_release(struct airq_iv *iv);
 unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num);
 void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num);
arch/s390/pci/pci_irq.c +4 -4
index cc4c8d7c8f5c..0d0a02a9fbbf 100644
@@ -296,7 +296,7 @@ int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
 		zdev->aisb = bit;
 
 		/* Create adapter interrupt vector */
-		zdev->aibv = airq_iv_create(msi_vecs, AIRQ_IV_DATA | AIRQ_IV_BITLOCK);
+		zdev->aibv = airq_iv_create(msi_vecs, AIRQ_IV_DATA | AIRQ_IV_BITLOCK, NULL);
 		if (!zdev->aibv)
 			return -ENOMEM;
 
@@ -419,7 +419,7 @@ static int __init zpci_directed_irq_init(void)
 	union zpci_sic_iib iib = {{0}};
 	unsigned int cpu;
 
-	zpci_sbv = airq_iv_create(num_possible_cpus(), 0);
+	zpci_sbv = airq_iv_create(num_possible_cpus(), 0, NULL);
 	if (!zpci_sbv)
 		return -ENOMEM;
 
@@ -441,7 +441,7 @@ static int __init zpci_directed_irq_init(void)
 		zpci_ibv[cpu] = airq_iv_create(cache_line_size() * BITS_PER_BYTE,
 					       AIRQ_IV_DATA |
 					       AIRQ_IV_CACHELINE |
-					       (!cpu ? AIRQ_IV_ALLOC : 0));
+					       (!cpu ? AIRQ_IV_ALLOC : 0), NULL);
 		if (!zpci_ibv[cpu])
 			return -ENOMEM;
 	}
@@ -458,7 +458,7 @@ static int __init zpci_floating_irq_init(void)
 	if (!zpci_ibv)
 		return -ENOMEM;
 
-	zpci_sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC);
+	zpci_sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC, NULL);
 	if (!zpci_sbv)
 		goto out_free;
 
drivers/s390/cio/airq.c +7 -3
index 2f2226786319..375a58b1c838 100644
@@ -122,10 +122,12 @@ static inline unsigned long iv_size(unsigned long bits)
  * airq_iv_create - create an interrupt vector
  * @bits: number of bits in the interrupt vector
  * @flags: allocation flags
+ * @vec: pointer to pinned guest memory if AIRQ_IV_GUESTVEC
  *
  * Returns a pointer to an interrupt vector structure
  */
-struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
+struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags,
+			       unsigned long *vec)
 {
 	struct airq_iv *iv;
 	unsigned long size;
@@ -146,6 +148,8 @@ struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
 					     &iv->vector_dma);
 		if (!iv->vector)
 			goto out_free;
+	} else if (flags & AIRQ_IV_GUESTVEC) {
+		iv->vector = vec;
 	} else {
 		iv->vector = cio_dma_zalloc(size);
 		if (!iv->vector)
@@ -185,7 +189,7 @@ struct airq_iv *airq_iv_create(unsigned long bits, unsigned long flags)
 	kfree(iv->avail);
 	if (iv->flags & AIRQ_IV_CACHELINE && iv->vector)
 		dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma);
-	else
+	else if (!(iv->flags & AIRQ_IV_GUESTVEC))
 		cio_dma_free(iv->vector, size);
 	kfree(iv);
 out:
@@ -204,7 +208,7 @@ void airq_iv_release(struct airq_iv *iv)
 	kfree(iv->bitlock);
 	if (iv->flags & AIRQ_IV_CACHELINE)
 		dma_pool_free(airq_iv_cache, iv->vector, iv->vector_dma);
-	else
+	else if (!(iv->flags & AIRQ_IV_GUESTVEC))
 		cio_dma_free(iv->vector, iv_size(iv->bits));
 	kfree(iv->avail);
 	kfree(iv);
drivers/s390/virtio/virtio_ccw.c +1 -1
index 52c376d15978..410498d693f8 100644
@@ -241,7 +241,7 @@ static struct airq_info *new_airq_info(int index)
 		return NULL;
 	rwlock_init(&info->lock);
 	info->aiv = airq_iv_create(VIRTIO_IV_BITS, AIRQ_IV_ALLOC | AIRQ_IV_PTR
-				   | AIRQ_IV_CACHELINE);
+				   | AIRQ_IV_CACHELINE, NULL);
 	if (!info->aiv) {
 		kfree(info);
 		return NULL;
author maintainer
#10 lore raw

PATCH v3 7/30 s390/pci: externalize the SIC operation controls and routine

In reply to Matthew Rosato

A subsequent patch will be issuing SIC from KVM -- export the necessary routine and make the operation control definitions available from a header. Because the routine will now be exported, let's rename __zpci_set_irq_ctrl to zpci_set_irq_ctrl and get rid of the zero'd iib wrapper function of the same name.

---
 arch/s390/include/asm/pci_insn.h | 17 +++++++++--------
 arch/s390/pci/pci_insn.c         |  3 ++-
 arch/s390/pci/pci_irq.c          | 26 ++++++++++++--------------
 3 files changed, 23 insertions(+), 23 deletions(-)
arch/s390/include/asm/pci_insn.h +9 -8
index 61cf9531f68f..5331082fa516 100644
@@ -98,6 +98,14 @@ struct zpci_fib {
 	u32 gd;
 } __packed __aligned(8);
 
+/* Set Interruption Controls Operation Controls  */
+#define	SIC_IRQ_MODE_ALL		0
+#define	SIC_IRQ_MODE_SINGLE		1
+#define	SIC_IRQ_MODE_DIRECT		4
+#define	SIC_IRQ_MODE_D_ALL		16
+#define	SIC_IRQ_MODE_D_SINGLE		17
+#define	SIC_IRQ_MODE_SET_CPU		18
+
 /* directed interruption information block */
 struct zpci_diib {
 	u32 : 1;
@@ -134,13 +142,6 @@ int __zpci_store(u64 data, u64 req, u64 offset);
 int zpci_store(const volatile void __iomem *addr, u64 data, unsigned long len);
 int __zpci_store_block(const u64 *data, u64 req, u64 offset);
 void zpci_barrier(void);
-int __zpci_set_irq_ctrl(u16 ctl, u8 isc, union zpci_sic_iib *iib);
-
-static inline int zpci_set_irq_ctrl(u16 ctl, u8 isc)
-{
-	union zpci_sic_iib iib = {{0}};
-
-	return __zpci_set_irq_ctrl(ctl, isc, &iib);
-}
+int zpci_set_irq_ctrl(u16 ctl, u8 isc, union zpci_sic_iib *iib);
 
 #endif
arch/s390/pci/pci_insn.c +2 -1
index 4dd58b196cea..2a47b3936e44 100644
@@ -97,7 +97,7 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
 }
 
 /* Set Interruption Controls */
-int __zpci_set_irq_ctrl(u16 ctl, u8 isc, union zpci_sic_iib *iib)
+int zpci_set_irq_ctrl(u16 ctl, u8 isc, union zpci_sic_iib *iib)
 {
 	if (!test_facility(72))
 		return -EIO;
@@ -108,6 +108,7 @@ int __zpci_set_irq_ctrl(u16 ctl, u8 isc, union zpci_sic_iib *iib)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(zpci_set_irq_ctrl);
 
 /* PCI Load */
 static inline int ____pcilg(u64 *data, u64 req, u64 offset, u8 *status)
arch/s390/pci/pci_irq.c +12 -14
index 0d0a02a9fbbf..2f675355fd0c 100644
@@ -15,13 +15,6 @@
 
 static enum {FLOATING, DIRECTED} irq_delivery;
 
-#define	SIC_IRQ_MODE_ALL		0
-#define	SIC_IRQ_MODE_SINGLE		1
-#define	SIC_IRQ_MODE_DIRECT		4
-#define	SIC_IRQ_MODE_D_ALL		16
-#define	SIC_IRQ_MODE_D_SINGLE		17
-#define	SIC_IRQ_MODE_SET_CPU		18
-
 /*
  * summary bit vector
  * FLOATING - summary bit per function
@@ -154,6 +147,7 @@ static struct irq_chip zpci_irq_chip = {
 static void zpci_handle_cpu_local_irq(bool rescan)
 {
 	struct airq_iv *dibv = zpci_ibv[smp_processor_id()];
+	union zpci_sic_iib iib = {{0}};
 	unsigned long bit;
 	int irqs_on = 0;
 
@@ -165,7 +159,7 @@ static void zpci_handle_cpu_local_irq(bool rescan)
 				/* End of second scan with interrupts on. */
 				break;
 			/* First scan complete, reenable interrupts. */
-			if (zpci_set_irq_ctrl(SIC_IRQ_MODE_D_SINGLE, PCI_ISC))
+			if (zpci_set_irq_ctrl(SIC_IRQ_MODE_D_SINGLE, PCI_ISC, &iib))
 				break;
 			bit = 0;
 			continue;
@@ -193,6 +187,7 @@ static void zpci_handle_remote_irq(void *data)
 static void zpci_handle_fallback_irq(void)
 {
 	struct cpu_irq_data *cpu_data;
+	union zpci_sic_iib iib = {{0}};
 	unsigned long cpu;
 	int irqs_on = 0;
 
@@ -203,7 +198,7 @@ static void zpci_handle_fallback_irq(void)
 				/* End of second scan with interrupts on. */
 				break;
 			/* First scan complete, reenable interrupts. */
-			if (zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, PCI_ISC))
+			if (zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, PCI_ISC, &iib))
 				break;
 			cpu = 0;
 			continue;
@@ -234,6 +229,7 @@ static void zpci_directed_irq_handler(struct airq_struct *airq,
 static void zpci_floating_irq_handler(struct airq_struct *airq,
 				      struct tpi_info *tpi_info)
 {
+	union zpci_sic_iib iib = {{0}};
 	unsigned long si, ai;
 	struct airq_iv *aibv;
 	int irqs_on = 0;
@@ -247,7 +243,7 @@ static void zpci_floating_irq_handler(struct airq_struct *airq,
 				/* End of second scan with interrupts on. */
 				break;
 			/* First scan complete, reenable interrupts. */
-			if (zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, PCI_ISC))
+			if (zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, PCI_ISC, &iib))
 				break;
 			si = 0;
 			continue;
@@ -407,11 +403,12 @@ static struct airq_struct zpci_airq = {
 static void __init cpu_enable_directed_irq(void *unused)
 {
 	union zpci_sic_iib iib = {{0}};
+	union zpci_sic_iib ziib = {{0}};
 
 	iib.cdiib.dibv_addr = (u64) zpci_ibv[smp_processor_id()]->vector;
 
-	__zpci_set_irq_ctrl(SIC_IRQ_MODE_SET_CPU, 0, &iib);
-	zpci_set_irq_ctrl(SIC_IRQ_MODE_D_SINGLE, PCI_ISC);
+	zpci_set_irq_ctrl(SIC_IRQ_MODE_SET_CPU, 0, &iib);
+	zpci_set_irq_ctrl(SIC_IRQ_MODE_D_SINGLE, PCI_ISC, &ziib);
 }
 
 static int __init zpci_directed_irq_init(void)
@@ -426,7 +423,7 @@ static int __init zpci_directed_irq_init(void)
 	iib.diib.isc = PCI_ISC;
 	iib.diib.nr_cpus = num_possible_cpus();
 	iib.diib.disb_addr = virt_to_phys(zpci_sbv->vector);
-	__zpci_set_irq_ctrl(SIC_IRQ_MODE_DIRECT, 0, &iib);
+	zpci_set_irq_ctrl(SIC_IRQ_MODE_DIRECT, 0, &iib);
 
 	zpci_ibv = kcalloc(num_possible_cpus(), sizeof(*zpci_ibv),
 			   GFP_KERNEL);
@@ -471,6 +468,7 @@ static int __init zpci_floating_irq_init(void)
 
 int __init zpci_irq_init(void)
 {
+	union zpci_sic_iib iib = {{0}};
 	int rc;
 
 	irq_delivery = sclp.has_dirq ? DIRECTED : FLOATING;
@@ -502,7 +500,7 @@ int __init zpci_irq_init(void)
 	 * Enable floating IRQs (with suppression after one IRQ). When using
 	 * directed IRQs this enables the fallback path.
 	 */
-	zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, PCI_ISC);
+	zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, PCI_ISC, &iib);
 
 	return 0;
 out_airq:
Signature · 1 line
2.27.0
author maintainer
#11 lore raw

PATCH v3 8/30 s390/pci: stash associated GISA designation

In reply to Matthew Rosato

For passthrough devices, we will need to know the GISA designation of the guest if interpretation facilities are to be used. Setup to stash this in the zdev and set a default of 0 (no GISA designation) for now; a subsequent patch will set a valid GISA designation for passthrough devices. Also, extend mpcific routines to specify this stashed designation as part of the mpcific command.

---
 arch/s390/include/asm/pci.h     | 1 +
 arch/s390/include/asm/pci_clp.h | 3 ++-
 arch/s390/pci/pci.c             | 6 ++++++
 arch/s390/pci/pci_clp.c         | 1 +
 arch/s390/pci/pci_irq.c         | 5 +++++
 5 files changed, 15 insertions(+), 1 deletion(-)
arch/s390/include/asm/pci.h +1 -0
index 90824be5ce9a..d07d7c3205de 100644
@@ -123,6 +123,7 @@ struct zpci_dev {
 	enum zpci_state state;
 	u32		fid;		/* function ID, used by sclp */
 	u32		fh;		/* function handle, used by insn's */
+	u32		gisa;		/* GISA designation for passthrough */
 	u16		vfn;		/* virtual function number */
 	u16		pchid;		/* physical channel ID */
 	u8		pfgid;		/* function group ID */
arch/s390/include/asm/pci_clp.h +2 -1
index 1f4b666e85ee..f3286bc5ba6e 100644
@@ -173,7 +173,8 @@ struct clp_req_set_pci {
 	u16 reserved2;
 	u8 oc;				/* operation controls */
 	u8 ndas;			/* number of dma spaces */
-	u64 reserved3;
+	u32 reserved3;
+	u32 gisa;			/* GISA designation */
 } __packed;
 
 /* Set PCI function response */
arch/s390/pci/pci.c +6 -0
index 792f8e0f2178..ca9c29386de6 100644
@@ -119,6 +119,7 @@ int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas,
 	fib.pba = base;
 	fib.pal = limit;
 	fib.iota = iota | ZPCI_IOTA_RTTO_FLAG;
+	fib.gd = zdev->gisa;
 	cc = zpci_mod_fc(req, &fib, &status);
 	if (cc)
 		zpci_dbg(3, "reg ioat fid:%x, cc:%d, status:%d\n", zdev->fid, cc, status);
@@ -132,6 +133,8 @@ int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas)
 	struct zpci_fib fib = {0};
 	u8 cc, status;
 
+	fib.gd = zdev->gisa;
+
 	cc = zpci_mod_fc(req, &fib, &status);
 	if (cc)
 		zpci_dbg(3, "unreg ioat fid:%x, cc:%d, status:%d\n", zdev->fid, cc, status);
@@ -159,6 +162,7 @@ int zpci_fmb_enable_device(struct zpci_dev *zdev)
 	atomic64_set(&zdev->unmapped_pages, 0);
 
 	fib.fmb_addr = virt_to_phys(zdev->fmb);
+	fib.gd = zdev->gisa;
 	cc = zpci_mod_fc(req, &fib, &status);
 	if (cc) {
 		kmem_cache_free(zdev_fmb_cache, zdev->fmb);
@@ -177,6 +181,8 @@ int zpci_fmb_disable_device(struct zpci_dev *zdev)
 	if (!zdev->fmb)
 		return -EINVAL;
 
+	fib.gd = zdev->gisa;
+
 	/* Function measurement is disabled if fmb address is zero */
 	cc = zpci_mod_fc(req, &fib, &status);
 	if (cc == 3) /* Function already gone. */
arch/s390/pci/pci_clp.c +1 -0
index be077b39da33..4dcc37ddeeaf 100644
@@ -240,6 +240,7 @@ static int clp_set_pci_fn(struct zpci_dev *zdev, u32 *fh, u8 nr_dma_as, u8 comma
 		rrb->request.fh = zdev->fh;
 		rrb->request.oc = command;
 		rrb->request.ndas = nr_dma_as;
+		rrb->request.gisa = zdev->gisa;
 
 		rc = clp_req(rrb, CLP_LPS_PCI);
 		if (rrb->response.hdr.rsp == CLP_RC_SETPCIFN_BUSY) {
arch/s390/pci/pci_irq.c +5 -0
index 2f675355fd0c..a19ac0282929 100644
@@ -43,6 +43,7 @@ static int zpci_set_airq(struct zpci_dev *zdev)
 	fib.fmt0.aibvo = 0;	/* each zdev has its own interrupt vector */
 	fib.fmt0.aisb = virt_to_phys(zpci_sbv->vector) + (zdev->aisb / 64) * 8;
 	fib.fmt0.aisbo = zdev->aisb & 63;
+	fib.gd = zdev->gisa;
 
 	return zpci_mod_fc(req, &fib, &status) ? -EIO : 0;
 }
@@ -54,6 +55,8 @@ static int zpci_clear_airq(struct zpci_dev *zdev)
 	struct zpci_fib fib = {0};
 	u8 cc, status;
 
+	fib.gd = zdev->gisa;
+
 	cc = zpci_mod_fc(req, &fib, &status);
 	if (cc == 3 || (cc == 1 && status == 24))
 		/* Function already gone or IRQs already deregistered. */
@@ -72,6 +75,7 @@ static int zpci_set_directed_irq(struct zpci_dev *zdev)
 	fib.fmt = 1;
 	fib.fmt1.noi = zdev->msi_nr_irqs;
 	fib.fmt1.dibvo = zdev->msi_first_bit;
+	fib.gd = zdev->gisa;
 
 	return zpci_mod_fc(req, &fib, &status) ? -EIO : 0;
 }
@@ -84,6 +88,7 @@ static int zpci_clear_directed_irq(struct zpci_dev *zdev)
 	u8 cc, status;
 
 	fib.fmt = 1;
+	fib.gd = zdev->gisa;
 	cc = zpci_mod_fc(req, &fib, &status);
 	if (cc == 3 || (cc == 1 && status == 24))
 		/* Function already gone or IRQs already deregistered. */
Signature · 1 line
2.27.0
author maintainer
#12 lore raw

PATCH v3 9/30 s390/pci: export some routines related to RPCIT processing

In reply to Matthew Rosato

KVM will re-use dma_walk_cpu_trans to walk the host shadow table and will also need to be able to call zpci_refresh_trans to re-issue a RPCIT.

---
 arch/s390/pci/pci_dma.c  | 1 +
 arch/s390/pci/pci_insn.c | 1 +
 2 files changed, 2 insertions(+)
arch/s390/pci/pci_dma.c +1 -0
index f46833a25526..a81de48d5ea7 100644
@@ -116,6 +116,7 @@ unsigned long *dma_walk_cpu_trans(unsigned long *rto, dma_addr_t dma_addr)
 	px = calc_px(dma_addr);
 	return &pto[px];
 }
+EXPORT_SYMBOL_GPL(dma_walk_cpu_trans);
 
 void dma_update_cpu_trans(unsigned long *entry, phys_addr_t page_addr, int flags)
 {
arch/s390/pci/pci_insn.c +1 -0
index 2a47b3936e44..0509554301c7 100644
@@ -95,6 +95,7 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
 
 	return (cc) ? -EIO : 0;
 }
+EXPORT_SYMBOL_GPL(zpci_refresh_trans);
 
 /* Set Interruption Controls */
 int zpci_set_irq_ctrl(u16 ctl, u8 isc, union zpci_sic_iib *iib)
Signature · 1 line
2.27.0
author maintainer
#13 lore raw

PATCH v3 10/30 s390/pci: stash dtsm and maxstbl

In reply to Matthew Rosato

Store information about what IOAT designation types are supported by underlying hardware as well as the largest store block size allowed. These values will be needed by passthrough.

---
 arch/s390/include/asm/pci.h     | 2 ++
 arch/s390/include/asm/pci_clp.h | 6 ++++--
 arch/s390/pci/pci_clp.c         | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
arch/s390/include/asm/pci.h +2 -0
index d07d7c3205de..7ee52a70a96f 100644
@@ -126,9 +126,11 @@ struct zpci_dev {
 	u32		gisa;		/* GISA designation for passthrough */
 	u16		vfn;		/* virtual function number */
 	u16		pchid;		/* physical channel ID */
+	u16		maxstbl;	/* Maximum store block size */
 	u8		pfgid;		/* function group ID */
 	u8		pft;		/* pci function type */
 	u8		port;
+	u8		dtsm;		/* Supported DT mask */
 	u8		rid_available	: 1;
 	u8		has_hp_slot	: 1;
 	u8		has_resources	: 1;
arch/s390/include/asm/pci_clp.h +4 -2
index f3286bc5ba6e..d6189ed14f84 100644
@@ -153,9 +153,11 @@ struct clp_rsp_query_pci_grp {
 	u8			:  6;
 	u8 frame		:  1;
 	u8 refresh		:  1;	/* TLB refresh mode */
-	u16 reserved2;
+	u16			:  3;
+	u16 maxstbl		: 13;	/* Maximum store block size */
 	u16 mui;
-	u16			: 16;
+	u8 dtsm;			/* Supported DT mask */
+	u8 reserved3;
 	u16 maxfaal;
 	u16			:  4;
 	u16 dnoi		: 12;
arch/s390/pci/pci_clp.c +2 -0
index 4dcc37ddeeaf..dc733b58e74f 100644
@@ -103,6 +103,8 @@ static void clp_store_query_pci_fngrp(struct zpci_dev *zdev,
 	zdev->max_msi = response->noi;
 	zdev->fmb_update = response->mui;
 	zdev->version = response->version;
+	zdev->maxstbl = response->maxstbl;
+	zdev->dtsm = response->dtsm;
 
 	switch (response->version) {
 	case 1:
Signature · 1 line
2.27.0
author maintainer
#14 lore raw

PATCH v3 11/30 s390/pci: add helper function to find device by handle

In reply to Matthew Rosato

Intercepted zPCI instructions will specify the desired function via a function handle. Add a routine to find the device with the specified handle.

---
 arch/s390/include/asm/pci.h |  1 +
 arch/s390/pci/pci.c         | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
arch/s390/include/asm/pci.h +1 -0
index 7ee52a70a96f..3c0b9986dcdc 100644
@@ -275,6 +275,7 @@ static inline struct zpci_dev *to_zpci_dev(struct device *dev)
 }
 
 struct zpci_dev *get_zdev_by_fid(u32);
+struct zpci_dev *get_zdev_by_fh(u32 fh);
 
 /* DMA */
 int zpci_dma_init(void);
arch/s390/pci/pci.c +16 -0
index ca9c29386de6..04c16312ad54 100644
@@ -76,6 +76,22 @@ struct zpci_dev *get_zdev_by_fid(u32 fid)
 	return zdev;
 }
 
+struct zpci_dev *get_zdev_by_fh(u32 fh)
+{
+	struct zpci_dev *tmp, *zdev = NULL;
+
+	spin_lock(&zpci_list_lock);
+	list_for_each_entry(tmp, &zpci_list, entry) {
+		if (tmp->fh == fh) {
+			zdev = tmp;
+			break;
+		}
+	}
+	spin_unlock(&zpci_list_lock);
+	return zdev;
+}
+EXPORT_SYMBOL_GPL(get_zdev_by_fh);
+
 void zpci_remove_reserved_devices(void)
 {
 	struct zpci_dev *tmp, *zdev;
Signature · 1 line
2.27.0
author maintainer
#15 lore raw

PATCH v3 12/30 s390/pci: get SHM information from list pci

In reply to Matthew Rosato

KVM will need information on the special handle mask used to indicate emulated devices. In order to obtain this, a new type of list pci call must be made to gather the information. Extend clp_list_pci_req to also fetch the model-dependent-data field that holds this mask.

---
 arch/s390/include/asm/pci.h     |  1 +
 arch/s390/include/asm/pci_clp.h |  2 +-
 arch/s390/pci/pci_clp.c         | 25 ++++++++++++++++++++++---
 3 files changed, 24 insertions(+), 4 deletions(-)
arch/s390/include/asm/pci.h +1 -0
index 3c0b9986dcdc..e8a3fd5bc169 100644
@@ -227,6 +227,7 @@ int clp_enable_fh(struct zpci_dev *zdev, u32 *fh, u8 nr_dma_as);
 int clp_disable_fh(struct zpci_dev *zdev, u32 *fh);
 int clp_get_state(u32 fid, enum zpci_state *state);
 int clp_refresh_fh(u32 fid, u32 *fh);
+int zpci_get_mdd(u32 *mdd);
 
 /* UID */
 void update_uid_checking(bool new);
arch/s390/include/asm/pci_clp.h +1 -1
index d6189ed14f84..dc2041e97de4 100644
@@ -76,7 +76,7 @@ struct clp_req_list_pci {
 struct clp_rsp_list_pci {
 	struct clp_rsp_hdr hdr;
 	u64 resume_token;
-	u32 reserved2;
+	u32 mdd;
 	u16 max_fn;
 	u8			: 7;
 	u8 uid_checking		: 1;
arch/s390/pci/pci_clp.c +22 -3
index dc733b58e74f..7477956be632 100644
@@ -328,7 +328,7 @@ int clp_disable_fh(struct zpci_dev *zdev, u32 *fh)
 }
 
 static int clp_list_pci_req(struct clp_req_rsp_list_pci *rrb,
-			    u64 *resume_token, int *nentries)
+			    u64 *resume_token, int *nentries, u32 *mdd)
 {
 	int rc;
 
@@ -354,6 +354,8 @@ static int clp_list_pci_req(struct clp_req_rsp_list_pci *rrb,
 	*nentries = (rrb->response.hdr.len - LIST_PCI_HDR_LEN) /
 		rrb->response.entry_size;
 	*resume_token = rrb->response.resume_token;
+	if (mdd)
+		*mdd = rrb->response.mdd;
 
 	return rc;
 }
@@ -365,7 +367,7 @@ static int clp_list_pci(struct clp_req_rsp_list_pci *rrb, void *data,
 	int nentries, i, rc;
 
 	do {
-		rc = clp_list_pci_req(rrb, &resume_token, &nentries);
+		rc = clp_list_pci_req(rrb, &resume_token, &nentries, NULL);
 		if (rc)
 			return rc;
 		for (i = 0; i < nentries; i++)
@@ -383,7 +385,7 @@ static int clp_find_pci(struct clp_req_rsp_list_pci *rrb, u32 fid,
 	int nentries, i, rc;
 
 	do {
-		rc = clp_list_pci_req(rrb, &resume_token, &nentries);
+		rc = clp_list_pci_req(rrb, &resume_token, &nentries, NULL);
 		if (rc)
 			return rc;
 		fh_list = rrb->response.fh_list;
@@ -468,6 +470,23 @@ int clp_get_state(u32 fid, enum zpci_state *state)
 	return rc;
 }
 
+int zpci_get_mdd(u32 *mdd)
+{
+	struct clp_req_rsp_list_pci *rrb;
+	u64 resume_token = 0;
+	int nentries, rc;
+
+	rrb = clp_alloc_block(GFP_KERNEL);
+	if (!rrb)
+		return -ENOMEM;
+
+	rc = clp_list_pci_req(rrb, &resume_token, &nentries, mdd);
+
+	clp_free_block(rrb);
+	return rc;
+}
+EXPORT_SYMBOL_GPL(zpci_get_mdd);
+
 static int clp_base_slpc(struct clp_req *req, struct clp_req_rsp_slpc *lpcb)
 {
 	unsigned long limit = PAGE_SIZE - sizeof(lpcb->request);
Signature · 1 line
2.27.0
Acked-by on v3 12/30
#16 lore raw

Re: [PATCH v3 12/30] s390/pci: get SHM information from list pci

Quoted 52 lines · Matthew Rosato

KVM will need information on the special handle mask used to indicate emulated devices. In order to obtain this, a new type of list pci call must be made to gather the information. Extend clp_list_pci_req to also fetch the model-dependent-data field that holds this mask.

---
  arch/s390/include/asm/pci.h     |  1 +
  arch/s390/include/asm/pci_clp.h |  2 +-
  arch/s390/pci/pci_clp.c         | 25 ++++++++++++++++++++++---
  3 files changed, 24 insertions(+), 4 deletions(-)
arch/s390/include/asm/pci.h +1 -0
index 3c0b9986dcdc..e8a3fd5bc169 100644
@@ -227,6 +227,7 @@ int clp_enable_fh(struct zpci_dev *zdev, u32 *fh, u8 nr_dma_as);
  int clp_disable_fh(struct zpci_dev *zdev, u32 *fh);
  int clp_get_state(u32 fid, enum zpci_state *state);
  int clp_refresh_fh(u32 fid, u32 *fh);
+int zpci_get_mdd(u32 *mdd);
 
  /* UID */
  void update_uid_checking(bool new);
arch/s390/include/asm/pci_clp.h +1 -1
index d6189ed14f84..dc2041e97de4 100644
@@ -76,7 +76,7 @@ struct clp_req_list_pci {
  struct clp_rsp_list_pci {
  	struct clp_rsp_hdr hdr;
  	u64 resume_token;
-	u32 reserved2;
+	u32 mdd;
  	u16 max_fn;
  	u8			: 7;
  	u8 uid_checking		: 1;
arch/s390/pci/pci_clp.c +1 -1
index dc733b58e74f..7477956be632 100644
@@ -328,7 +328,7 @@ int clp_disable_fh(struct zpci_dev *zdev, u32 *fh)
  }
 
  static int clp_list_pci_req(struct clp_req_rsp_list_pci *rrb,
-			    u64 *resume_token, int *nentries)
+			    u64 *resume_token, int *nentries, u32 *mdd)
  {
  	int rc;
 

arch/s390/pci/pci_clp.c static int clp_list_pci_req(struct clp_req_rsp_list_pci *rrb, · line 358

Quoted 5 lines
arch/s390/pci/pci_clp.c +2 -0
@@ -354,6 +354,8 @@ static int clp_list_pci_req(struct clp_req_rsp_list_pci *rrb,
  	*nentries = (rrb->response.hdr.len - LIST_PCI_HDR_LEN) /
  		rrb->response.entry_size;
  	*resume_token = rrb->response.resume_token;
+	if (mdd)
+		*mdd = rrb->response.mdd;

mdd is a central value for ZPCI like zpci_unique_uid, I think both should be treated the same, i.e. belong to a central ZPCI structure or as today with zpci_unique_uid be global. An aventage of the design is that the clp_list_pci_req signature does not need to be modified and we do not need extra clp call.

However I come here late with this demand so I guess this simplification can be done later.

Quoted 46 lines
arch/s390/pci/pci_clp.c +19 -2
  	return rc;
  }
@@ -365,7 +367,7 @@ static int clp_list_pci(struct clp_req_rsp_list_pci *rrb, void *data,
  	int nentries, i, rc;
 
  	do {
-		rc = clp_list_pci_req(rrb, &resume_token, &nentries);
+		rc = clp_list_pci_req(rrb, &resume_token, &nentries, NULL);
  		if (rc)
  			return rc;
  		for (i = 0; i < nentries; i++)
@@ -383,7 +385,7 @@ static int clp_find_pci(struct clp_req_rsp_list_pci *rrb, u32 fid,
  	int nentries, i, rc;
 
  	do {
-		rc = clp_list_pci_req(rrb, &resume_token, &nentries);
+		rc = clp_list_pci_req(rrb, &resume_token, &nentries, NULL);
  		if (rc)
  			return rc;
  		fh_list = rrb->response.fh_list;
@@ -468,6 +470,23 @@ int clp_get_state(u32 fid, enum zpci_state *state)
  	return rc;
  }
 
+int zpci_get_mdd(u32 *mdd)
+{
+	struct clp_req_rsp_list_pci *rrb;
+	u64 resume_token = 0;
+	int nentries, rc;
+
+	rrb = clp_alloc_block(GFP_KERNEL);
+	if (!rrb)
+		return -ENOMEM;
+
+	rc = clp_list_pci_req(rrb, &resume_token, &nentries, mdd);
+
+	clp_free_block(rrb);
+	return rc;
+}
+EXPORT_SYMBOL_GPL(zpci_get_mdd);
+
  static int clp_base_slpc(struct clp_req *req, struct clp_req_rsp_slpc *lpcb)
  {
  	unsigned long limit = PAGE_SIZE - sizeof(lpcb->request);
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
author maintainer
#17 lore raw

PATCH v3 13/30 s390/pci: return status from zpci_refresh_trans

In reply to Matthew Rosato

Current callers of zpci_refresh_trans don't need to interrogate the status returned from the underlying instructions. However, a subsequent patch will add a KVM caller that needs this information. Add a new argument to zpci_refresh_trans to pass the address of a status byte and update existing call sites to provide it.

---
 arch/s390/include/asm/pci_insn.h |  2 +-
 arch/s390/pci/pci_dma.c          |  6 ++++--
 arch/s390/pci/pci_insn.c         | 10 +++++-----
 drivers/iommu/s390-iommu.c       |  4 +++-
 4 files changed, 13 insertions(+), 9 deletions(-)
arch/s390/include/asm/pci_insn.h +1 -1
index 5331082fa516..32759c407b8f 100644
@@ -135,7 +135,7 @@ union zpci_sic_iib {
 DECLARE_STATIC_KEY_FALSE(have_mio);
 
 u8 zpci_mod_fc(u64 req, struct zpci_fib *fib, u8 *status);
-int zpci_refresh_trans(u64 fn, u64 addr, u64 range);
+int zpci_refresh_trans(u64 fn, u64 addr, u64 range, u8 *status);
 int __zpci_load(u64 *data, u64 req, u64 offset);
 int zpci_load(u64 *data, const volatile void __iomem *addr, unsigned long len);
 int __zpci_store(u64 data, u64 req, u64 offset);
arch/s390/pci/pci_dma.c +4 -2
index a81de48d5ea7..b0a2380bcad8 100644
@@ -23,8 +23,9 @@ static u32 s390_iommu_aperture_factor = 1;
 
 static int zpci_refresh_global(struct zpci_dev *zdev)
 {
+	u8 status;
 	return zpci_refresh_trans((u64) zdev->fh << 32, zdev->start_dma,
-				  zdev->iommu_pages * PAGE_SIZE);
+				  zdev->iommu_pages * PAGE_SIZE, &status);
 }
 
 unsigned long *dma_alloc_cpu_table(void)
@@ -183,6 +184,7 @@ static int __dma_purge_tlb(struct zpci_dev *zdev, dma_addr_t dma_addr,
 			   size_t size, int flags)
 {
 	unsigned long irqflags;
+	u8 status;
 	int ret;
 
 	/*
@@ -201,7 +203,7 @@ static int __dma_purge_tlb(struct zpci_dev *zdev, dma_addr_t dma_addr,
 	}
 
 	ret = zpci_refresh_trans((u64) zdev->fh << 32, dma_addr,
-				 PAGE_ALIGN(size));
+				 PAGE_ALIGN(size), &status);
 	if (ret == -ENOMEM && !s390_iommu_strict) {
 		/* enable the hypervisor to free some resources */
 		if (zpci_refresh_global(zdev))
arch/s390/pci/pci_insn.c +5 -5
index 0509554301c7..ca6399d52767 100644
@@ -77,20 +77,20 @@ static inline u8 __rpcit(u64 fn, u64 addr, u64 range, u8 *status)
 	return cc;
 }
 
-int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
+int zpci_refresh_trans(u64 fn, u64 addr, u64 range, u8 *status)
 {
-	u8 cc, status;
+	u8 cc;
 
 	do {
-		cc = __rpcit(fn, addr, range, &status);
+		cc = __rpcit(fn, addr, range, status);
 		if (cc == 2)
 			udelay(ZPCI_INSN_BUSY_DELAY);
 	} while (cc == 2);
 
 	if (cc)
-		zpci_err_insn(cc, status, addr, range);
+		zpci_err_insn(cc, *status, addr, range);
 
-	if (cc == 1 && (status == 4 || status == 16))
+	if (cc == 1 && (*status == 4 || *status == 16))
 		return -ENOMEM;
 
 	return (cc) ? -EIO : 0;
drivers/iommu/s390-iommu.c +3 -1
index 50860ebdd087..845bb99c183e 100644
@@ -214,6 +214,7 @@ static int s390_iommu_update_trans(struct s390_domain *s390_domain,
 	unsigned long irq_flags, nr_pages, i;
 	unsigned long *entry;
 	int rc = 0;
+	u8 status;
 
 	if (dma_addr < s390_domain->domain.geometry.aperture_start ||
 	    dma_addr + size > s390_domain->domain.geometry.aperture_end)
@@ -238,7 +239,8 @@ static int s390_iommu_update_trans(struct s390_domain *s390_domain,
 	spin_lock(&s390_domain->list_lock);
 	list_for_each_entry(domain_device, &s390_domain->devices, list) {
 		rc = zpci_refresh_trans((u64) domain_device->zdev->fh << 32,
-					start_dma_addr, nr_pages * PAGE_SIZE);
+					start_dma_addr, nr_pages * PAGE_SIZE,
+					&status);
 		if (rc)
 			break;
 	}
Signature · 1 line
2.27.0
author maintainer
#18 lore raw

PATCH v3 14/30 vfio/pci: re-introduce CONFIG_VFIO_PCI_ZDEV

In reply to Matthew Rosato

This was previously removed as unnecessary; while that was true, subsequent changes will make KVM an additional required component for vfio-pci-zdev. Let's re-introduce CONFIG_VFIO_PCI_ZDEV as now there is actually a reason to say 'n' for it (when not planning to CONFIG_KVM).

---
 drivers/vfio/pci/Kconfig      | 11 +++++++++++
 drivers/vfio/pci/Makefile     |  2 +-
 include/linux/vfio_pci_core.h |  2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/vfio/pci/Kconfig +11 -0
index 860424ccda1b..fedd1d4cb592 100644
@@ -42,5 +42,16 @@ config VFIO_PCI_IGD
 	  and LPC bridge config space.
 
 	  To enable Intel IGD assignment through vfio-pci, say Y.
+
+config VFIO_PCI_ZDEV
+	bool "VFIO PCI extensions for s390x KVM passthrough"
+	depends on S390 && KVM
+	default y
+	help
+	  Support s390x-specific extensions to enable support for enhancements
+	  to KVM passthrough capabilities, such as interpretive execution of
+	  zPCI instructions.
+
+	  To enable s390x KVM vfio-pci extensions, say Y.
 endif
 endif
drivers/vfio/pci/Makefile +1 -1
index 349d68d242b4..01b1f83d83d7 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o
-vfio-pci-core-$(CONFIG_S390) += vfio_pci_zdev.o
+vfio-pci-core-$(CONFIG_VFIO_PCI_ZDEV) += vfio_pci_zdev.o
 obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o
 
 vfio-pci-y := vfio_pci.o
include/linux/vfio_pci_core.h +1 -1
index ef9a44b6cf5d..5e2bca3b89db 100644
@@ -195,7 +195,7 @@ static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 }
 #endif
 
-#ifdef CONFIG_S390
+#ifdef CONFIG_VFIO_PCI_ZDEV
 extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 				       struct vfio_info_cap *caps);
 #else
Signature · 1 line
2.27.0
maintainer
#19 lore raw

Re: [PATCH v3 14/30] vfio/pci: re-introduce CONFIG_VFIO_PCI_ZDEV

Quoted 4 lines · Matthew Rosato

This was previously removed as unnecessary; while that was true, subsequent changes will make KVM an additional required component for vfio-pci-zdev. Let's re-introduce CONFIG_VFIO_PCI_ZDEV as now there is actually a reason to say 'n' for it (when not planning to CONFIG_KVM).

Hm... can the file be split into parts that depend on KVM and parts that don't? Does anybody ever use vfio-pci on a non-kvm s390 system?

[Apologies if that has been discussed before, this is my first look at this series.]

Quoted 8 lines
---
 drivers/vfio/pci/Kconfig      | 11 +++++++++++
 drivers/vfio/pci/Makefile     |  2 +-
 include/linux/vfio_pci_core.h |  2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)
author maintainer
#20 lore raw

Re: [PATCH v3 14/30] vfio/pci: re-introduce CONFIG_VFIO_PCI_ZDEV

Quoted 10 lines · Cornelia Huck
Quoted 4 lines · Matthew Rosato

This was previously removed as unnecessary; while that was true, subsequent changes will make KVM an additional required component for vfio-pci-zdev. Let's re-introduce CONFIG_VFIO_PCI_ZDEV as now there is actually a reason to say 'n' for it (when not planning to CONFIG_KVM).

Hm... can the file be split into parts that depend on KVM and parts that don't? Does anybody ever use vfio-pci on a non-kvm s390 system?

It is possible to split out most of the prior CLP/ vfio capability work (but it would not be a totally clean split, zpci_group_cap for example would need to have an inline ifdef since it references a KVM structure) -- I suspect we'll see more of that in the future.
I'm not totally sure if there's value in the information being provided today -- this CLP information was all added specifically with userspace->guest delivery in mind. And to answer your other question, I'm not directly aware of non-kvm vfio-pci usage on s390 today; but that doesn't mean there isn't any or won't be in the future of course. With this series, you could CONFIG_KVM=n + CONFIG_VFIO_PCI=y|m and you'll get the standard vfio-pci support but never any vfio-pci-zdev extension.

If we wanted to provide everything we can where KVM isn't strictly required, then let's look at what a split would look like:

With or without KVM:
zcpi_base_cap
zpci_group_cap (with an inline ifdef for KVM [1]) zpci_util_cap
zpci_pfip_cap
vfio_pci_info_zdev_add_caps
vfio_pci_zdev_open (ifdef, just return when !KVM [1]) vfio_pci_zdev_release (ifdef, just return when !KVM [1])

KVM only:
vfio_pci_zdev_feat_interp
vfio_pci_zdev_feat_aif
vfio_pci_zdev_feat_ioat
vfio_pci_zdev_group_notifier

I suppose such a split has the benefit of flexibility / future-proofing... should a non-kvm use case arrive in the future for s390 and we find we need some s390-specific handling, we're still building vfio-pci-zdev into vfio-pci by default and can just extend that.

[1] In this case I would propose renaming CONFIG_VFIO_PCI_ZDEV as we would once again always be building some part of vfio-pci-zdev with vfio-pci on s390 -- maybe something like CONFIG_VFIO_PCI_ZDEV_KVM (wow that's a mouthful) and then use this setting to check "KVM" in my above split. Since this setting will imply PCI, VFIO_PCI and KVM, we can then s/CONFIG_VFIO_PCI_ZDEV/CONFIG_VFIO_PCI_ZDEV_KVM/ for the rest of the series (to continue covering cases like we build KVM but not pci, or not vfio-pci)

How does that sound?

maintainer
#21 lore raw

Re: [PATCH v3 14/30] vfio/pci: re-introduce CONFIG_VFIO_PCI_ZDEV

Quoted 12 lines · Matthew Rosato
Quoted 10 lines · Cornelia Huck
Quoted 4 lines · Matthew Rosato

This was previously removed as unnecessary; while that was true, subsequent changes will make KVM an additional required component for vfio-pci-zdev. Let's re-introduce CONFIG_VFIO_PCI_ZDEV as now there is actually a reason to say 'n' for it (when not planning to CONFIG_KVM).

Hm... can the file be split into parts that depend on KVM and parts that don't? Does anybody ever use vfio-pci on a non-kvm s390 system?

Quoted 11 lines

It is possible to split out most of the prior CLP/ vfio capability work (but it would not be a totally clean split, zpci_group_cap for example would need to have an inline ifdef since it references a KVM structure) -- I suspect we'll see more of that in the future.
I'm not totally sure if there's value in the information being provided today -- this CLP information was all added specifically with userspace->guest delivery in mind. And to answer your other question, I'm not directly aware of non-kvm vfio-pci usage on s390 today; but that doesn't mean there isn't any or won't be in the future of course. With this series, you could CONFIG_KVM=n + CONFIG_VFIO_PCI=y|m and you'll get the standard vfio-pci support but never any vfio-pci-zdev extension.

Yes. Remind me again: if you do standard vfio-pci without the extensions grabbing some card-specific information and making them available to the guest, you get a working setup, it just always looks like a specific card, right?

Quoted 33 lines

If we wanted to provide everything we can where KVM isn't strictly required, then let's look at what a split would look like:

With or without KVM:
zcpi_base_cap
zpci_group_cap (with an inline ifdef for KVM [1]) zpci_util_cap
zpci_pfip_cap
vfio_pci_info_zdev_add_caps
vfio_pci_zdev_open (ifdef, just return when !KVM [1]) vfio_pci_zdev_release (ifdef, just return when !KVM [1])

KVM only:
vfio_pci_zdev_feat_interp
vfio_pci_zdev_feat_aif
vfio_pci_zdev_feat_ioat
vfio_pci_zdev_group_notifier

I suppose such a split has the benefit of flexibility / future-proofing... should a non-kvm use case arrive in the future for s390 and we find we need some s390-specific handling, we're still building vfio-pci-zdev into vfio-pci by default and can just extend that.

[1] In this case I would propose renaming CONFIG_VFIO_PCI_ZDEV as we would once again always be building some part of vfio-pci-zdev with vfio-pci on s390 -- maybe something like CONFIG_VFIO_PCI_ZDEV_KVM (wow that's a mouthful) and then use this setting to check "KVM" in my above split. Since this setting will imply PCI, VFIO_PCI and KVM, we can then s/CONFIG_VFIO_PCI_ZDEV/CONFIG_VFIO_PCI_ZDEV_KVM/ for the rest of the series (to continue covering cases like we build KVM but not pci, or not vfio-pci)

Quoted 1 line

How does that sound?

Complex :)

I'm not really sure whether it's worth the hassle on an odd chance that we may want it for a !KVM usecase in the future (that goes beyond the "base" vfio-pci support.) OTOH, it would be cleaner. I'm a bit torn on this one.

author maintainer
#22 lore raw

Re: [PATCH v3 14/30] vfio/pci: re-introduce CONFIG_VFIO_PCI_ZDEV

Quoted 26 lines · Cornelia Huck
Quoted 12 lines · Matthew Rosato
Quoted 10 lines · Cornelia Huck
Quoted 4 lines · Matthew Rosato

This was previously removed as unnecessary; while that was true, subsequent changes will make KVM an additional required component for vfio-pci-zdev. Let's re-introduce CONFIG_VFIO_PCI_ZDEV as now there is actually a reason to say 'n' for it (when not planning to CONFIG_KVM).

Hm... can the file be split into parts that depend on KVM and parts that don't? Does anybody ever use vfio-pci on a non-kvm s390 system?

Quoted 11 lines

It is possible to split out most of the prior CLP/ vfio capability work (but it would not be a totally clean split, zpci_group_cap for example would need to have an inline ifdef since it references a KVM structure) -- I suspect we'll see more of that in the future.
I'm not totally sure if there's value in the information being provided today -- this CLP information was all added specifically with userspace->guest delivery in mind. And to answer your other question, I'm not directly aware of non-kvm vfio-pci usage on s390 today; but that doesn't mean there isn't any or won't be in the future of course. With this series, you could CONFIG_KVM=n + CONFIG_VFIO_PCI=y|m and you'll get the standard vfio-pci support but never any vfio-pci-zdev extension.

Quoted 5 lines

Yes. Remind me again: if you do standard vfio-pci without the extensions grabbing some card-specific information and making them available to the guest, you get a working setup, it just always looks like a specific card, right?

That's how QEMU treats it anyway, yes. Standard PCI aspects (e.g. config space) are fine, but for the s390-specific bits we end up making generalizations / using hard-coded values that are subsequently shared with the guest when it issues a CLP -- these bits are used to identify various s390-specific capabilities of the device (an example: based upon the function type, the guest could derive what format of the function measurement block can be used. The hard-coded value is otherwise effectively 'generic device' so use the basic format for this block).

Basically, we are using vfio to transmit information owned by the host s390 PCI layer to, ultimately, the guest s390 PCI layer (modified to reflect what kvm+QEMU supports), so that the guest can treat the device the same way that the host does. Anything else in between isn't going to be interested in that information unless it wants to do something very s390-specific.

Quoted 33 lines
Quoted 33 lines

If we wanted to provide everything we can where KVM isn't strictly required, then let's look at what a split would look like:

With or without KVM:
zcpi_base_cap
zpci_group_cap (with an inline ifdef for KVM [1]) zpci_util_cap
zpci_pfip_cap
vfio_pci_info_zdev_add_caps
vfio_pci_zdev_open (ifdef, just return when !KVM [1]) vfio_pci_zdev_release (ifdef, just return when !KVM [1])

KVM only:
vfio_pci_zdev_feat_interp
vfio_pci_zdev_feat_aif
vfio_pci_zdev_feat_ioat
vfio_pci_zdev_group_notifier

I suppose such a split has the benefit of flexibility / future-proofing... should a non-kvm use case arrive in the future for s390 and we find we need some s390-specific handling, we're still building vfio-pci-zdev into vfio-pci by default and can just extend that.

[1] In this case I would propose renaming CONFIG_VFIO_PCI_ZDEV as we would once again always be building some part of vfio-pci-zdev with vfio-pci on s390 -- maybe something like CONFIG_VFIO_PCI_ZDEV_KVM (wow that's a mouthful) and then use this setting to check "KVM" in my above split. Since this setting will imply PCI, VFIO_PCI and KVM, we can then s/CONFIG_VFIO_PCI_ZDEV/CONFIG_VFIO_PCI_ZDEV_KVM/ for the rest of the series (to continue covering cases like we build KVM but not pci, or not vfio-pci)

Quoted 9 lines
Quoted 1 line

How does that sound?

Complex :)

I'm not really sure whether it's worth the hassle on an odd chance that we may want it for a !KVM usecase in the future (that goes beyond the "base" vfio-pci support.) OTOH, it would be cleaner. I'm a bit torn on this one.

Well, another option would be to move ahead with this patch as-is, except to rename s/CONFIG_VFIO_PCI_ZDEV/CONFIG_VFIO_PCI_ZDEV_KVM/ or something like that (and naturally tweak the title and commit message a bit). Basically, don't have the name imply a 1:1 relationship with all of vfio-pci-zdev, even if it will have that effect in practice for now.

Net result with this series would be we stop building vfio-pci-zdev without KVM, which means we remove the zdev CLP capabilities when !KVM. And then if we have a !KVM usecase in the future that needs something non-standard for s390 (either this CLP info or more likely some other s390-specific tweak) we can then perform the split, perhaps just as I describe above. In this way we punt the need for complexity until a point when (if) we need it, without backing ourselves into a weird case where we must rename the config parameter (or live with the fact that we always build some part of vfio-pci-zdev even when CONFIG_VFIO_PCI_ZDEV=n)

maintainer
#23 lore raw

Re: [PATCH v3 14/30] vfio/pci: re-introduce CONFIG_VFIO_PCI_ZDEV

Quoted 42 lines · Matthew Rosato
Quoted 26 lines · Cornelia Huck
Quoted 12 lines · Matthew Rosato
Quoted 10 lines · Cornelia Huck
Quoted 4 lines · Matthew Rosato

This was previously removed as unnecessary; while that was true, subsequent changes will make KVM an additional required component for vfio-pci-zdev. Let's re-introduce CONFIG_VFIO_PCI_ZDEV as now there is actually a reason to say 'n' for it (when not planning to CONFIG_KVM).

Hm... can the file be split into parts that depend on KVM and parts that don't? Does anybody ever use vfio-pci on a non-kvm s390 system?

Quoted 11 lines

It is possible to split out most of the prior CLP/ vfio capability work (but it would not be a totally clean split, zpci_group_cap for example would need to have an inline ifdef since it references a KVM structure) -- I suspect we'll see more of that in the future.
I'm not totally sure if there's value in the information being provided today -- this CLP information was all added specifically with userspace->guest delivery in mind. And to answer your other question, I'm not directly aware of non-kvm vfio-pci usage on s390 today; but that doesn't mean there isn't any or won't be in the future of course. With this series, you could CONFIG_KVM=n + CONFIG_VFIO_PCI=y|m and you'll get the standard vfio-pci support but never any vfio-pci-zdev extension.

Quoted 5 lines

Yes. Remind me again: if you do standard vfio-pci without the extensions grabbing some card-specific information and making them available to the guest, you get a working setup, it just always looks like a specific card, right?

That's how QEMU treats it anyway, yes. Standard PCI aspects (e.g. config space) are fine, but for the s390-specific bits we end up making generalizations / using hard-coded values that are subsequently shared with the guest when it issues a CLP -- these bits are used to identify various s390-specific capabilities of the device (an example: based upon the function type, the guest could derive what format of the function measurement block can be used. The hard-coded value is otherwise effectively 'generic device' so use the basic format for this block).

Quoted 6 lines

Basically, we are using vfio to transmit information owned by the host s390 PCI layer to, ultimately, the guest s390 PCI layer (modified to reflect what kvm+QEMU supports), so that the guest can treat the device the same way that the host does. Anything else in between isn't going to be interested in that information unless it wants to do something very s390-specific.

Thanks, now I remember the details here :)

Quoted 50 lines
Quoted 34 lines
Quoted 34 lines

If we wanted to provide everything we can where KVM isn't strictly required, then let's look at what a split would look like:

With or without KVM:
zcpi_base_cap
zpci_group_cap (with an inline ifdef for KVM [1]) zpci_util_cap
zpci_pfip_cap
vfio_pci_info_zdev_add_caps
vfio_pci_zdev_open (ifdef, just return when !KVM [1]) vfio_pci_zdev_release (ifdef, just return when !KVM [1])

KVM only:
vfio_pci_zdev_feat_interp
vfio_pci_zdev_feat_aif
vfio_pci_zdev_feat_ioat
vfio_pci_zdev_group_notifier

I suppose such a split has the benefit of flexibility / future-proofing... should a non-kvm use case arrive in the future for s390 and we find we need some s390-specific handling, we're still building vfio-pci-zdev into vfio-pci by default and can just extend that.

[1] In this case I would propose renaming CONFIG_VFIO_PCI_ZDEV as we would once again always be building some part of vfio-pci-zdev with vfio-pci on s390 -- maybe something like CONFIG_VFIO_PCI_ZDEV_KVM (wow that's a mouthful) and then use this setting to check "KVM" in my above split. Since this setting will imply PCI, VFIO_PCI and KVM, we can then s/CONFIG_VFIO_PCI_ZDEV/CONFIG_VFIO_PCI_ZDEV_KVM/ for the rest of the series (to continue covering cases like we build KVM but not pci, or not vfio-pci)

Quoted 9 lines
Quoted 1 line

How does that sound?

Complex :)

I'm not really sure whether it's worth the hassle on an odd chance that we may want it for a !KVM usecase in the future (that goes beyond the "base" vfio-pci support.) OTOH, it would be cleaner. I'm a bit torn on this one.

Well, another option would be to move ahead with this patch as-is, except to rename s/CONFIG_VFIO_PCI_ZDEV/CONFIG_VFIO_PCI_ZDEV_KVM/ or something like that (and naturally tweak the title and commit message a bit). Basically, don't have the name imply a 1:1 relationship with all of vfio-pci-zdev, even if it will have that effect in practice for now.

Quoted 9 lines

Net result with this series would be we stop building vfio-pci-zdev without KVM, which means we remove the zdev CLP capabilities when !KVM. And then if we have a !KVM usecase in the future that needs something non-standard for s390 (either this CLP info or more likely some other s390-specific tweak) we can then perform the split, perhaps just as I describe above. In this way we punt the need for complexity until a point when (if) we need it, without backing ourselves into a weird case where we must rename the config parameter (or live with the fact that we always build some part of vfio-pci-zdev even when CONFIG_VFIO_PCI_ZDEV=n)

Ok, I think I like this option the best.

author maintainer
#24 lore raw

PATCH v3 15/30 KVM: s390: pci: add basic kvm_zdev structure

In reply to Matthew Rosato

This structure will be used to carry kvm passthrough information related to zPCI devices.

---
 arch/s390/include/asm/kvm_pci.h | 27 +++++++++++++++++++++++
 arch/s390/include/asm/pci.h     |  3 +++
 arch/s390/kvm/Makefile          |  1 +
 arch/s390/kvm/pci.c             | 38 +++++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+)
 create mode 100644 arch/s390/include/asm/kvm_pci.h
 create mode 100644 arch/s390/kvm/pci.c
arch/s390/include/asm/kvm_pci.h new file +27 -0
new file mode 100644
index 000000000000..ef10f9e46e37
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * KVM PCI Passthrough for virtual machines on s390
+ *
+ * Copyright IBM Corp. 2021
+ *
+ *    Author(s): Matthew Rosato <[email protected]>
+ */
+
+#ifndef ASM_KVM_PCI_H
+#define ASM_KVM_PCI_H
+
+#include <linux/types.h>
+#include <linux/kvm_types.h>
+#include <linux/kvm_host.h>
+#include <linux/kvm.h>
+#include <linux/pci.h>
+
+struct kvm_zdev {
+	struct zpci_dev *zdev;
+	struct kvm *kvm;
+};
+
+int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
+void kvm_s390_pci_dev_release(struct zpci_dev *zdev);
+
+#endif /* ASM_KVM_PCI_H */
arch/s390/include/asm/pci.h +3 -0
index e8a3fd5bc169..4faff673078b 100644
@@ -97,6 +97,7 @@ struct zpci_bar_struct {
 };
 
 struct s390_domain;
+struct kvm_zdev;
 
 #define ZPCI_FUNCTIONS_PER_BUS 256
 struct zpci_bus {
@@ -190,6 +191,8 @@ struct zpci_dev {
 	struct dentry	*debugfs_dev;
 
 	struct s390_domain *s390_domain; /* s390 IOMMU domain data */
+
+	struct kvm_zdev *kzdev; /* passthrough data */
 };
 
 static inline bool zdev_enabled(struct zpci_dev *zdev)
arch/s390/kvm/Makefile +1 -0
index 26f4a74e5ce4..b8263a160df8 100644
@@ -10,4 +10,5 @@ ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
 kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o
 kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
 
+kvm-$(CONFIG_VFIO_PCI_ZDEV) += pci.o
 obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/pci.c new file +38 -0
new file mode 100644
index 000000000000..bc1b7a564e55
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * s390 kvm PCI passthrough support
+ *
+ * Copyright IBM Corp. 2021
+ *
+ *    Author(s): Matthew Rosato <[email protected]>
+ */
+
+#include <linux/kvm_host.h>
+#include <linux/pci.h>
+#include <asm/kvm_pci.h>
+
+int kvm_s390_pci_dev_open(struct zpci_dev *zdev)
+{
+	struct kvm_zdev *kzdev;
+
+	kzdev = kzalloc(sizeof(struct kvm_zdev), GFP_KERNEL);
+	if (!kzdev)
+		return -ENOMEM;
+
+	kzdev->zdev = zdev;
+	zdev->kzdev = kzdev;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(kvm_s390_pci_dev_open);
+
+void kvm_s390_pci_dev_release(struct zpci_dev *zdev)
+{
+	struct kvm_zdev *kzdev;
+
+	kzdev = zdev->kzdev;
+	WARN_ON(kzdev->zdev != zdev);
+	zdev->kzdev = 0;
+	kfree(kzdev);
+}
+EXPORT_SYMBOL_GPL(kvm_s390_pci_dev_release);
Signature · 1 line
2.27.0
author maintainer
#25 lore raw

PATCH v3 16/30 KVM: s390: pci: do initial setup for AEN interpretation

In reply to Matthew Rosato

Initial setup for Adapter Event Notification Interpretation for zPCI passthrough devices. Specifically, allocate a structure for forwarding of adapter events and pass the address of this structure to firmware.

---
 arch/s390/include/asm/pci.h      |   4 +
 arch/s390/include/asm/pci_insn.h |  12 +++
 arch/s390/kvm/interrupt.c        |  14 +++
 arch/s390/kvm/kvm-s390.c         |   9 ++
 arch/s390/kvm/pci.c              | 154 +++++++++++++++++++++++++++++++
 arch/s390/kvm/pci.h              |  42 +++++++++
 arch/s390/pci/pci.c              |   6 ++
 7 files changed, 241 insertions(+)
 create mode 100644 arch/s390/kvm/pci.h
arch/s390/include/asm/pci.h +4 -0
index 4faff673078b..1ae49330d1c8 100644
@@ -9,6 +9,7 @@
 #include <asm-generic/pci.h>
 #include <asm/pci_clp.h>
 #include <asm/pci_debug.h>
+#include <asm/pci_insn.h>
 #include <asm/sclp.h>
 
 #define PCIBIOS_MIN_IO		0x1000
@@ -204,6 +205,9 @@ extern const struct attribute_group *zpci_attr_groups[];
 extern unsigned int s390_pci_force_floating __initdata;
 extern unsigned int s390_pci_no_rid;
 
+extern union zpci_sic_iib *zpci_aipb;
+extern struct airq_iv *zpci_aif_sbv;
+
 /* -----------------------------------------------------------------------------
   Prototypes
 ----------------------------------------------------------------------------- */
arch/s390/include/asm/pci_insn.h +12 -0
index 32759c407b8f..ad9000295c82 100644
@@ -101,6 +101,7 @@ struct zpci_fib {
 /* Set Interruption Controls Operation Controls  */
 #define	SIC_IRQ_MODE_ALL		0
 #define	SIC_IRQ_MODE_SINGLE		1
+#define	SIC_SET_AENI_CONTROLS		2
 #define	SIC_IRQ_MODE_DIRECT		4
 #define	SIC_IRQ_MODE_D_ALL		16
 #define	SIC_IRQ_MODE_D_SINGLE		17
@@ -127,9 +128,20 @@ struct zpci_cdiib {
 	u64 : 64;
 } __packed __aligned(8);
 
+/* adapter interruption parameters block */
+struct zpci_aipb {
+	u64 faisb;
+	u64 gait;
+	u16 : 13;
+	u16 afi : 3;
+	u32 : 32;
+	u16 faal;
+} __packed __aligned(8);
+
 union zpci_sic_iib {
 	struct zpci_diib diib;
 	struct zpci_cdiib cdiib;
+	struct zpci_aipb aipb;
 };
 
 DECLARE_STATIC_KEY_FALSE(have_mio);
arch/s390/kvm/interrupt.c +14 -0
index 65e75ca2fc5d..5e638f7c86f8 100644
@@ -32,6 +32,7 @@
 #include "kvm-s390.h"
 #include "gaccess.h"
 #include "trace-s390.h"
+#include "pci.h"
 
 #define PFAULT_INIT 0x0600
 #define PFAULT_DONE 0x0680
@@ -3286,6 +3287,11 @@ void kvm_s390_gib_destroy(void)
 {
 	if (!gib)
 		return;
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) && sclp.has_aeni && aift) {
+		mutex_lock(&aift->aift_lock);
+		kvm_s390_pci_aen_exit();
+		mutex_unlock(&aift->aift_lock);
+	}
 	chsc_sgib(0);
 	unregister_adapter_interrupt(&gib_alert_irq);
 	free_page((unsigned long)gib);
@@ -3323,6 +3329,14 @@ int kvm_s390_gib_init(u8 nisc)
 		goto out_unreg_gal;
 	}
 
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) && sclp.has_aeni) {
+		if (kvm_s390_pci_aen_init(nisc)) {
+			pr_err("Initializing AEN for PCI failed\n");
+			rc = -EIO;
+			goto out_unreg_gal;
+		}
+	}
+
 	KVM_EVENT(3, "gib 0x%pK (nisc=%d) initialized", gib, gib->nisc);
 	goto out;
 
arch/s390/kvm/kvm-s390.c +9 -0
index 577f1ead6a51..dd4f4bfb326b 100644
@@ -48,6 +48,7 @@
 #include <asm/fpu/api.h>
 #include "kvm-s390.h"
 #include "gaccess.h"
+#include "pci.h"
 
 #define CREATE_TRACE_POINTS
 #include "trace.h"
@@ -503,6 +504,14 @@ int kvm_arch_init(void *opaque)
 		goto out;
 	}
 
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV)) {
+		rc = kvm_s390_pci_init();
+		if (rc) {
+			pr_err("Unable to allocate AIFT for PCI\n");
+			goto out;
+		}
+	}
+
 	rc = kvm_s390_gib_init(GAL_ISC);
 	if (rc)
 		goto out;
arch/s390/kvm/pci.c +154 -0

163 lines not on this page · raw message

arch/s390/kvm/pci.h new file +42 -0

42 lines not on this page · raw message

arch/s390/pci/pci.c +6 -0
index 04c16312ad54..13033717cd4e 100644
@@ -61,6 +61,12 @@ DEFINE_STATIC_KEY_FALSE(have_mio);
 
 static struct kmem_cache *zdev_fmb_cache;
 
+/* AEN structures that must be preserved over KVM module re-insertion */
+union zpci_sic_iib *zpci_aipb;
+EXPORT_SYMBOL_GPL(zpci_aipb);
+struct airq_iv *zpci_aif_sbv;
+EXPORT_SYMBOL_GPL(zpci_aif_sbv);
+
 struct zpci_dev *get_zdev_by_fid(u32 fid)
 {
 	struct zpci_dev *tmp, *zdev = NULL;
Signature · 1 line
2.27.0
author maintainer
#26 lore raw

PATCH v3 17/30 KVM: s390: pci: enable host forwarding of Adapter Event Notifications

In reply to Matthew Rosato

In cases where interrupts are not forwarded to the guest via firmware, KVM is responsible for ensuring delivery. When an interrupt presents with the forwarding bit, we must process the forwarding tables until all interrupts are delivered.

---
 arch/s390/include/asm/kvm_host.h |  1 +
 arch/s390/include/asm/tpi.h      | 13 ++++++
 arch/s390/kvm/interrupt.c        | 77 +++++++++++++++++++++++++++++++-
 arch/s390/kvm/kvm-s390.c         |  3 +-
 arch/s390/kvm/pci.h              | 10 +++++
 5 files changed, 102 insertions(+), 2 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -0
index a22c9266ea05..b468d3a2215e 100644
@@ -757,6 +757,7 @@ struct kvm_vm_stat {
 	u64 inject_pfault_done;
 	u64 inject_service_signal;
 	u64 inject_virtio;
+	u64 aen_forward;
 };
 
 struct kvm_arch_memory_slot {
arch/s390/include/asm/tpi.h +13 -0
index 1ac538b8cbf5..f76e5fdff23a 100644
@@ -19,6 +19,19 @@ struct tpi_info {
 	u32 :12;
 } __packed __aligned(4);
 
+/* I/O-Interruption Code as stored by TPI for an Adapter I/O */
+struct tpi_adapter_info {
+	u32 aism:8;
+	u32 :22;
+	u32 error:1;
+	u32 forward:1;
+	u32 reserved;
+	u32 adapter_IO:1;
+	u32 directed_irq:1;
+	u32 isc:3;
+	u32 :27;
+} __packed __aligned(4);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_S390_TPI_H */
arch/s390/kvm/interrupt.c +76 -1

87 lines not on this page · raw message

arch/s390/kvm/kvm-s390.c +2 -1
index dd4f4bfb326b..24837d6050dc 100644
@@ -65,7 +65,8 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
 	STATS_DESC_COUNTER(VM, inject_float_mchk),
 	STATS_DESC_COUNTER(VM, inject_pfault_done),
 	STATS_DESC_COUNTER(VM, inject_service_signal),
-	STATS_DESC_COUNTER(VM, inject_virtio)
+	STATS_DESC_COUNTER(VM, inject_virtio),
+	STATS_DESC_COUNTER(VM, aen_forward)
 };
 
 const struct kvm_stats_header kvm_vm_stats_header = {
arch/s390/kvm/pci.h +10 -0
index 53e9968707c8..4d3db58beb74 100644
@@ -12,6 +12,7 @@
 
 #include <linux/pci.h>
 #include <linux/mutex.h>
+#include <linux/kvm_host.h>
 #include <asm/airq.h>
 #include <asm/kvm_pci.h>
 
@@ -34,6 +35,15 @@ struct zpci_aift {
 
 extern struct zpci_aift *aift;
 
+static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift,
+						 unsigned long si)
+{
+	if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) || aift->kzdev == 0 ||
+	    aift->kzdev[si] == 0)
+		return 0;
+	return aift->kzdev[si]->kvm;
+};
+
 int kvm_s390_pci_aen_init(u8 nisc);
 void kvm_s390_pci_aen_exit(void);
 
Signature · 1 line
2.27.0
#27 lore raw

Re: [PATCH v3 17/30] KVM: s390: pci: enable host forwarding of Adapter Event Notifications

I love your patch! Perhaps something to improve:

Hi Matthew,

I love your patch! Perhaps something to improve:

[auto build test WARNING on s390/features]
[also build test WARNING on v5.17-rc2 next-20220204]
[cannot apply to kvms390/next awilliam-vfio/next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Rosato/KVM-s390-enable-zPCI-for-interpretive-execution/20220205-052233
base:   https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git features
config: s390-randconfig-s032-20220131 (https://download.01.org/0day-ci/archive/20220205/202202052152.V6WfEnsb-lkp(a)intel.com/config)
compiler: s390-linux-gcc (GCC) 11.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/5889fc3e91862ce82ec0ce5f9491d6048c72d3e6
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Matthew-Rosato/KVM-s390-enable-zPCI-for-interpretive-execution/20220205-052233
git checkout 5889fc3e91862ce82ec0ce5f9491d6048c72d3e6
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=s390 SHELL=/bin/bash arch/s390/

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> arch/s390/kvm/interrupt.c:3288:20: sparse: sparse: Using plain integer as NULL pointer
   arch/s390/kvm/interrupt.c: note: in included file:
>> arch/s390/kvm/pci.h:41:65: sparse: sparse: Using plain integer as NULL pointer

arch/s390/kvm/pci.h:42:32: sparse: sparse: Using plain integer as NULL pointer arch/s390/kvm/pci.h:43:24: sparse: sparse: Using plain integer as NULL pointer

vim +3288 arch/s390/kvm/interrupt.c

3273
3274 static void aen_host_forward(unsigned long si)
3275 {
3276 struct kvm_s390_gisa_interrupt *gi;
3277 struct zpci_gaite *gaite;
3278 struct kvm *kvm;
3279
3280 gaite = (struct zpci_gaite *)aift->gait +
3281 (si * sizeof(struct zpci_gaite));
3282 if (gaite->count == 0)
3283 return;
3284 if (gaite->aisb != 0)
3285 set_bit_inv(gaite->aisbo, (unsigned long *)gaite->aisb);
3286
3287 kvm = kvm_s390_pci_si_to_kvm(aift, si);

> 3288		if (kvm == 0)

3289 return;
3290 gi = &kvm->arch.gisa_int;
3291
3292 if (!(gi->origin->g1.simm & AIS_MODE_MASK(gaite->gisc)) ||
3293 !(gi->origin->g1.nimm & AIS_MODE_MASK(gaite->gisc))) {
3294 gisa_set_ipm_gisc(gi->origin, gaite->gisc);
3295 if (hrtimer_active(&gi->timer))
3296 hrtimer_cancel(&gi->timer);
3297 hrtimer_start(&gi->timer, 0, HRTIMER_MODE_REL);
3298 kvm->stat.aen_forward++;
3299 }
3300 }
3301

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#28 lore raw

Re: [PATCH v3 17/30] KVM: s390: pci: enable host forwarding of Adapter Event Notifications

In reply to Matthew Rosato
Quoted 98 lines · Matthew Rosato

In cases where interrupts are not forwarded to the guest via firmware, KVM is responsible for ensuring delivery. When an interrupt presents with the forwarding bit, we must process the forwarding tables until all interrupts are delivered.

---
  arch/s390/include/asm/kvm_host.h |  1 +
  arch/s390/include/asm/tpi.h      | 13 ++++++
  arch/s390/kvm/interrupt.c        | 77 +++++++++++++++++++++++++++++++-
  arch/s390/kvm/kvm-s390.c         |  3 +-
  arch/s390/kvm/pci.h              | 10 +++++
  5 files changed, 102 insertions(+), 2 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -0
index a22c9266ea05..b468d3a2215e 100644
@@ -757,6 +757,7 @@ struct kvm_vm_stat {
  	u64 inject_pfault_done;
  	u64 inject_service_signal;
  	u64 inject_virtio;
+	u64 aen_forward;
  };
 
  struct kvm_arch_memory_slot {
arch/s390/include/asm/tpi.h +13 -0
index 1ac538b8cbf5..f76e5fdff23a 100644
@@ -19,6 +19,19 @@ struct tpi_info {
  	u32 :12;
  } __packed __aligned(4);
 
+/* I/O-Interruption Code as stored by TPI for an Adapter I/O */
+struct tpi_adapter_info {
+	u32 aism:8;
+	u32 :22;
+	u32 error:1;
+	u32 forward:1;
+	u32 reserved;
+	u32 adapter_IO:1;
+	u32 directed_irq:1;
+	u32 isc:3;
+	u32 :27;
+} __packed __aligned(4);
+
  #endif /* __ASSEMBLY__ */
 
  #endif /* _ASM_S390_TPI_H */
arch/s390/kvm/interrupt.c +40 -0
index 5e638f7c86f8..74a549d3d1e4 100644
@@ -3271,11 +3271,86 @@ int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc)
  }
  EXPORT_SYMBOL_GPL(kvm_s390_gisc_unregister);
 
+static void aen_host_forward(unsigned long si)
+{
+	struct kvm_s390_gisa_interrupt *gi;
+	struct zpci_gaite *gaite;
+	struct kvm *kvm;
+
+	gaite = (struct zpci_gaite *)aift->gait +
+		(si * sizeof(struct zpci_gaite));
+	if (gaite->count == 0)
+		return;
+	if (gaite->aisb != 0)
+		set_bit_inv(gaite->aisbo, (unsigned long *)gaite->aisb);
+
+	kvm = kvm_s390_pci_si_to_kvm(aift, si);
+	if (kvm == 0)
+		return;
+	gi = &kvm->arch.gisa_int;
+
+	if (!(gi->origin->g1.simm & AIS_MODE_MASK(gaite->gisc)) ||
+	    !(gi->origin->g1.nimm & AIS_MODE_MASK(gaite->gisc))) {
+		gisa_set_ipm_gisc(gi->origin, gaite->gisc);
+		if (hrtimer_active(&gi->timer))
+			hrtimer_cancel(&gi->timer);
+		hrtimer_start(&gi->timer, 0, HRTIMER_MODE_REL);
+		kvm->stat.aen_forward++;
+	}
+}
+
+static void aen_process_gait(u8 isc)
+{
+	bool found = false, first = true;
+	union zpci_sic_iib iib = {{0}};
+	unsigned long si, flags;
+
+	spin_lock_irqsave(&aift->gait_lock, flags);
+
+	if (!aift->gait) {
+		spin_unlock_irqrestore(&aift->gait_lock, flags);
+		return;
+	}

arch/s390/kvm/interrupt.c int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc) · line 3323

Quoted 10 lines
arch/s390/kvm/interrupt.c +10 -0
+
+	for (si = 0;;) {
+		/* Scan adapter summary indicator bit vector */
+		si = airq_iv_scan(aift->sbv, si, airq_iv_end(aift->sbv));
+		if (si == -1UL) {
+			if (first || found) {
+				/* Reenable interrupts. */
+				if (zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, isc,
+						      &iib))
+					break;

I thought we agreed that the test is not useful here.

arch/s390/kvm/interrupt.c int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc) · line 3330

Quoted 7 lines
arch/s390/kvm/interrupt.c +7 -0
+				first = found = false;
+			} else {
+				/* Interrupts on and all bits processed */
+				break;
+			}
+			found = false;
+			si = 0;

and about a comment here.
"rescan after re-enabling interrupts"
would make things clear

Quoted 14 lines
arch/s390/kvm/interrupt.c +11 -0
+			continue;
+		}
+		found = true;
+		aen_host_forward(si);
+	}
+
+	spin_unlock_irqrestore(&aift->gait_lock, flags);
+}
+
  static void gib_alert_irq_handler(struct airq_struct *airq,
  				  struct tpi_info *tpi_info)
  {
+	struct tpi_adapter_info *info = (struct tpi_adapter_info *)tpi_info;
+

arch/s390/kvm/interrupt.c int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc) · line 3353

Quoted 10 lines
arch/s390/kvm/interrupt.c +8 -1
  	inc_irq_stat(IRQIO_GAL);
-	process_gib_alert_list();
+
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) &&
+	    (info->forward || info->error)) {
+		aen_process_gait(info->isc);
+		if (info->aism != 0)
+			process_gib_alert_list();
+	} else
+		process_gib_alert_list();

Here we need braces.

Quoted 46 lines
arch/s390/kvm/interrupt.c +0 -0
  }
 
  static struct airq_struct gib_alert_irq = {
arch/s390/kvm/kvm-s390.c +2 -1
index dd4f4bfb326b..24837d6050dc 100644
@@ -65,7 +65,8 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
  	STATS_DESC_COUNTER(VM, inject_float_mchk),
  	STATS_DESC_COUNTER(VM, inject_pfault_done),
  	STATS_DESC_COUNTER(VM, inject_service_signal),
-	STATS_DESC_COUNTER(VM, inject_virtio)
+	STATS_DESC_COUNTER(VM, inject_virtio),
+	STATS_DESC_COUNTER(VM, aen_forward)
  };
 
  const struct kvm_stats_header kvm_vm_stats_header = {
arch/s390/kvm/pci.h +10 -0
index 53e9968707c8..4d3db58beb74 100644
@@ -12,6 +12,7 @@
 
  #include <linux/pci.h>
  #include <linux/mutex.h>
+#include <linux/kvm_host.h>
  #include <asm/airq.h>
  #include <asm/kvm_pci.h>
 
@@ -34,6 +35,15 @@ struct zpci_aift {
 
  extern struct zpci_aift *aift;
 
+static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift,
+						 unsigned long si)
+{
+	if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) || aift->kzdev == 0 ||
+	    aift->kzdev[si] == 0)
+		return 0;
+	return aift->kzdev[si]->kvm;
+};
+
  int kvm_s390_pci_aen_init(u8 nisc);
  void kvm_s390_pci_aen_exit(void);
 
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
author maintainer
#29 lore raw

Re: [PATCH v3 17/30] KVM: s390: pci: enable host forwarding of Adapter Event Notifications

Quoted 3 lines · Pierre Morel

On 2/4/22 22:15, Matthew Rosato wrote:

...

Quoted 16 lines
Quoted 16 lines
arch/s390/kvm/interrupt.c +16 -0
+static void aen_process_gait(u8 isc)
+{
+    bool found = false, first = true;
+    union zpci_sic_iib iib = {{0}};
+    unsigned long si, flags;
+
+    spin_lock_irqsave(&aift->gait_lock, flags);
+
+    if (!aift->gait) {
+        spin_unlock_irqrestore(&aift->gait_lock, flags);
+        return;
+    }
+
+    for (si = 0;;) {
+        /* Scan adapter summary indicator bit vector */
+        si = airq_iv_scan(aift->sbv, si, airq_iv_end(aift->sbv));
Quoted 8 lines
Quoted 6 lines

+        if (si == -1UL) {
+            if (first || found) {
+                /* Reenable interrupts. */
+                if (zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, isc, +                              &iib))
+                    break;

I thought we agreed that the test is not useful here.

Oops, you are correct -- it looks like I simply failed to apply any of your suggestions from that particular email, must have marked it 'done' on accident -- sorry about that. I've gone ahead and made these changes already on my in-progress v4 branch. Thanks for pointing it out.

author maintainer
#30 lore raw

PATCH v3 18/30 KVM: s390: mechanism to enable guest zPCI Interpretation

In reply to Matthew Rosato

The guest must have access to certain facilities in order to allow interpretive execution of zPCI instructions and adapter event notifications. However, there are some cases where a guest might disable interpretation -- provide a mechanism via which we can defer enabling the associated zPCI interpretation facilities until the guest indicates it wishes to use them.

---
 arch/s390/include/asm/kvm_host.h |  4 ++++
 arch/s390/kvm/kvm-s390.c         | 40 ++++++++++++++++++++++++++++++++
 arch/s390/kvm/kvm-s390.h         | 10 ++++++++
 3 files changed, 54 insertions(+)
arch/s390/include/asm/kvm_host.h +4 -0
index b468d3a2215e..bf61ab05f98c 100644
@@ -252,7 +252,10 @@ struct kvm_s390_sie_block {
 #define ECB2_IEP	0x20
 #define ECB2_PFMFI	0x08
 #define ECB2_ESCA	0x04
+#define ECB2_ZPCI_LSI	0x02
 	__u8    ecb2;                   /* 0x0062 */
+#define ECB3_AISI	0x20
+#define ECB3_AISII	0x10
 #define ECB3_DEA 0x08
 #define ECB3_AES 0x04
 #define ECB3_RI  0x01
@@ -938,6 +941,7 @@ struct kvm_arch{
 	int use_cmma;
 	int use_pfmfi;
 	int use_skf;
+	int use_zpci_interp;
 	int user_cpu_state_ctrl;
 	int user_sigp;
 	int user_stsi;
arch/s390/kvm/kvm-s390.c +40 -0
index 24837d6050dc..208b09d08385 100644
@@ -1029,6 +1029,44 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
 	return 0;
 }
 
+static void kvm_s390_vcpu_pci_setup(struct kvm_vcpu *vcpu)
+{
+	/* Only set the ECB bits after guest requests zPCI interpretation */
+	if (!vcpu->kvm->arch.use_zpci_interp)
+		return;
+
+	vcpu->arch.sie_block->ecb2 |= ECB2_ZPCI_LSI;
+	vcpu->arch.sie_block->ecb3 |= ECB3_AISII + ECB3_AISI;
+}
+
+void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm)
+{
+	struct kvm_vcpu *vcpu;
+	unsigned long i;
+
+	/*
+	 * If host is configured for PCI and the necessary facilities are
+	 * available, turn on interpretation for the life of this guest
+	 */
+	if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) || !sclp.has_zpci_lsi ||
+	    !sclp.has_aisii || !sclp.has_aeni || !sclp.has_aisi)
+		return;
+
+	mutex_lock(&kvm->lock);
+
+	kvm->arch.use_zpci_interp = 1;
+
+	kvm_s390_vcpu_block_all(kvm);
+
+	kvm_for_each_vcpu(i, vcpu, kvm) {
+		kvm_s390_vcpu_pci_setup(vcpu);
+		kvm_s390_sync_request(KVM_REQ_VSIE_RESTART, vcpu);
+	}
+
+	kvm_s390_vcpu_unblock_all(kvm);
+	mutex_unlock(&kvm->lock);
+}
+
 static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req)
 {
 	unsigned long cx;
@@ -3236,6 +3274,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
 
 	kvm_s390_vcpu_crypto_setup(vcpu);
 
+	kvm_s390_vcpu_pci_setup(vcpu);
+
 	mutex_lock(&vcpu->kvm->lock);
 	if (kvm_s390_pv_is_protected(vcpu->kvm)) {
 		rc = kvm_s390_pv_create_cpu(vcpu, &uvrc, &uvrrc);
arch/s390/kvm/kvm-s390.h +10 -0
index 098831e815e6..14bb2539f837 100644
@@ -496,6 +496,16 @@ void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
  */
 void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm);
 
+/**
+ * kvm_s390_vcpu_pci_enable_interp
+ *
+ * Set the associated PCI attributes for each vcpu to allow for zPCI Load/Store
+ * interpretation as well as adapter interruption forwarding.
+ *
+ * @kvm: the KVM guest
+ */
+void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm);
+
 /**
  * diag9c_forwarding_hz
  *
Signature · 1 line
2.27.0
Acked-by on v3 18/30
#31 lore raw

Re: [PATCH v3 18/30] KVM: s390: mechanism to enable guest zPCI Interpretation

Quoted 8 lines · Matthew Rosato

The guest must have access to certain facilities in order to allow interpretive execution of zPCI instructions and adapter event notifications. However, there are some cases where a guest might disable interpretation -- provide a mechanism via which we can defer enabling the associated zPCI interpretation facilities until the guest indicates it wishes to use them.

Didn't you forget my ACK?

Quoted 109 lines
---
  arch/s390/include/asm/kvm_host.h |  4 ++++
  arch/s390/kvm/kvm-s390.c         | 40 ++++++++++++++++++++++++++++++++
  arch/s390/kvm/kvm-s390.h         | 10 ++++++++
  3 files changed, 54 insertions(+)
arch/s390/include/asm/kvm_host.h +4 -0
index b468d3a2215e..bf61ab05f98c 100644
@@ -252,7 +252,10 @@ struct kvm_s390_sie_block {
  #define ECB2_IEP	0x20
  #define ECB2_PFMFI	0x08
  #define ECB2_ESCA	0x04
+#define ECB2_ZPCI_LSI	0x02
  	__u8    ecb2;                   /* 0x0062 */
+#define ECB3_AISI	0x20
+#define ECB3_AISII	0x10
  #define ECB3_DEA 0x08
  #define ECB3_AES 0x04
  #define ECB3_RI  0x01
@@ -938,6 +941,7 @@ struct kvm_arch{
  	int use_cmma;
  	int use_pfmfi;
  	int use_skf;
+	int use_zpci_interp;
  	int user_cpu_state_ctrl;
  	int user_sigp;
  	int user_stsi;
arch/s390/kvm/kvm-s390.c +40 -0
index 24837d6050dc..208b09d08385 100644
@@ -1029,6 +1029,44 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
  	return 0;
  }
 
+static void kvm_s390_vcpu_pci_setup(struct kvm_vcpu *vcpu)
+{
+	/* Only set the ECB bits after guest requests zPCI interpretation */
+	if (!vcpu->kvm->arch.use_zpci_interp)
+		return;
+
+	vcpu->arch.sie_block->ecb2 |= ECB2_ZPCI_LSI;
+	vcpu->arch.sie_block->ecb3 |= ECB3_AISII + ECB3_AISI;
+}
+
+void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm)
+{
+	struct kvm_vcpu *vcpu;
+	unsigned long i;
+
+	/*
+	 * If host is configured for PCI and the necessary facilities are
+	 * available, turn on interpretation for the life of this guest
+	 */
+	if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) || !sclp.has_zpci_lsi ||
+	    !sclp.has_aisii || !sclp.has_aeni || !sclp.has_aisi)
+		return;
+
+	mutex_lock(&kvm->lock);
+
+	kvm->arch.use_zpci_interp = 1;
+
+	kvm_s390_vcpu_block_all(kvm);
+
+	kvm_for_each_vcpu(i, vcpu, kvm) {
+		kvm_s390_vcpu_pci_setup(vcpu);
+		kvm_s390_sync_request(KVM_REQ_VSIE_RESTART, vcpu);
+	}
+
+	kvm_s390_vcpu_unblock_all(kvm);
+	mutex_unlock(&kvm->lock);
+}
+
  static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req)
  {
  	unsigned long cx;
@@ -3236,6 +3274,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
 
  	kvm_s390_vcpu_crypto_setup(vcpu);
 
+	kvm_s390_vcpu_pci_setup(vcpu);
+
  	mutex_lock(&vcpu->kvm->lock);
  	if (kvm_s390_pv_is_protected(vcpu->kvm)) {
  		rc = kvm_s390_pv_create_cpu(vcpu, &uvrc, &uvrrc);
arch/s390/kvm/kvm-s390.h +10 -0
index 098831e815e6..14bb2539f837 100644
@@ -496,6 +496,16 @@ void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
   */
  void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm);
 
+/**
+ * kvm_s390_vcpu_pci_enable_interp
+ *
+ * Set the associated PCI attributes for each vcpu to allow for zPCI Load/Store
+ * interpretation as well as adapter interruption forwarding.
+ *
+ * @kvm: the KVM guest
+ */
+void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm);
+
  /**
   * diag9c_forwarding_hz
   *
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
author maintainer
#32 lore raw

PATCH v3 19/30 KVM: s390: pci: provide routines for enabling/disabling interpretation

In reply to Matthew Rosato

These routines will be wired into the vfio_pci_zdev ioctl handlers to respond to requests to enable / disable a device for zPCI Load/Store interpretation.

The first time such a request is received, enable the necessary facilities for the guest.

---
 arch/s390/include/asm/kvm_pci.h |   4 ++
 arch/s390/kvm/pci.c             | 102 ++++++++++++++++++++++++++++++++
 arch/s390/pci/pci.c             |   3 +
 3 files changed, 109 insertions(+)
arch/s390/include/asm/kvm_pci.h +4 -0
index ef10f9e46e37..422701d526dd 100644
@@ -24,4 +24,8 @@ struct kvm_zdev {
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
 void kvm_s390_pci_dev_release(struct zpci_dev *zdev);
 
+int kvm_s390_pci_interp_probe(struct zpci_dev *zdev);
+int kvm_s390_pci_interp_enable(struct zpci_dev *zdev);
+int kvm_s390_pci_interp_disable(struct zpci_dev *zdev);
+
 #endif /* ASM_KVM_PCI_H */
arch/s390/kvm/pci.c +102 -0

115 lines not on this page · raw message

arch/s390/pci/pci.c +3 -0
index 13033717cd4e..5dbe49ec325e 100644
@@ -147,6 +147,7 @@ int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas,
 		zpci_dbg(3, "reg ioat fid:%x, cc:%d, status:%d\n", zdev->fid, cc, status);
 	return cc;
 }
+EXPORT_SYMBOL_GPL(zpci_register_ioat);
 
 /* Modify PCI: Unregister I/O address translation parameters */
 int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas)
@@ -727,6 +728,7 @@ int zpci_enable_device(struct zpci_dev *zdev)
 		zpci_update_fh(zdev, fh);
 	return rc;
 }
+EXPORT_SYMBOL_GPL(zpci_enable_device);
 
 int zpci_disable_device(struct zpci_dev *zdev)
 {
@@ -750,6 +752,7 @@ int zpci_disable_device(struct zpci_dev *zdev)
 	}
 	return rc;
 }
+EXPORT_SYMBOL_GPL(zpci_disable_device);
 
 /**
  * zpci_hot_reset_device - perform a reset of the given zPCI function
Signature · 1 line
2.27.0
Reviewed-by on v3 19/30
#33 lore raw

Re: [PATCH v3 19/30] KVM: s390: pci: provide routines for enabling/disabling interpretation

Quoted 43 lines · Matthew Rosato

These routines will be wired into the vfio_pci_zdev ioctl handlers to respond to requests to enable / disable a device for zPCI Load/Store interpretation.

The first time such a request is received, enable the necessary facilities for the guest.

---
  arch/s390/include/asm/kvm_pci.h |   4 ++
  arch/s390/kvm/pci.c             | 102 ++++++++++++++++++++++++++++++++
  arch/s390/pci/pci.c             |   3 +
  3 files changed, 109 insertions(+)
arch/s390/include/asm/kvm_pci.h +4 -0
index ef10f9e46e37..422701d526dd 100644
@@ -24,4 +24,8 @@ struct kvm_zdev {
  int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
  void kvm_s390_pci_dev_release(struct zpci_dev *zdev);
 
+int kvm_s390_pci_interp_probe(struct zpci_dev *zdev);
+int kvm_s390_pci_interp_enable(struct zpci_dev *zdev);
+int kvm_s390_pci_interp_disable(struct zpci_dev *zdev);
+
  #endif /* ASM_KVM_PCI_H */
arch/s390/kvm/pci.c +2 -0
index 9b8390133e15..16bef3935284 100644
@@ -12,7 +12,9 @@
  #include <asm/kvm_pci.h>
  #include <asm/pci.h>
  #include <asm/pci_insn.h>
+#include <asm/sclp.h>
  #include "pci.h"
+#include "kvm-s390.h"
 
  struct zpci_aift *aift;
 
@@ -153,6 +155,106 @@ int kvm_s390_pci_aen_init(u8 nisc)
  	return rc;

arch/s390/kvm/pci.c int kvm_s390_pci_aen_init(u8 nisc) · line 165

Quoted 10 lines
arch/s390/kvm/pci.c +8 -0
  }
 
+int kvm_s390_pci_interp_probe(struct zpci_dev *zdev)
+{
+	/* Must have appropriate hardware facilities */
+	if (!sclp.has_zpci_lsi || !sclp.has_aisii || !sclp.has_aeni ||
+	    !sclp.has_aisi || !test_facility(69) || !test_facility(70) ||
+	    !test_facility(71) || !test_facility(72)) {
+		return -EINVAL;
+	}

I do not think we need to check STFLE facilities when the SCLP bit indicating the interpretation of a facility is installed the STFLE bit indicating the interpreted facility is also installed.

Otherwise, look good to me, with this change:

Quoted 124 lines
arch/s390/kvm/pci.c +92 -0
+
+	/* Must have a KVM association registered */
+	if (!zdev->kzdev || !zdev->kzdev->kvm)
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(kvm_s390_pci_interp_probe);
+
+int kvm_s390_pci_interp_enable(struct zpci_dev *zdev)
+{
+	u32 gisa;
+	int rc;
+
+	if (!zdev->kzdev || !zdev->kzdev->kvm)
+		return -EINVAL;
+
+	/*
+	 * If this is the first request to use an interpreted device, make the
+	 * necessary vcpu changes
+	 */
+	if (!zdev->kzdev->kvm->arch.use_zpci_interp)
+		kvm_s390_vcpu_pci_enable_interp(zdev->kzdev->kvm);
+
+	/*
+	 * In the event of a system reset in userspace, the GISA designation
+	 * may still be assigned because the device is still enabled.
+	 * Verify it's the same guest before proceeding.
+	 */
+	gisa = (u32)virt_to_phys(&zdev->kzdev->kvm->arch.sie_page2->gisa);
+	if (zdev->gisa != 0 && zdev->gisa != gisa)
+		return -EPERM;
+
+	if (zdev_enabled(zdev)) {
+		zdev->gisa = 0;
+		rc = zpci_disable_device(zdev);
+		if (rc)
+			return rc;
+	}
+
+	/*
+	 * Store information about the identity of the kvm guest allowed to
+	 * access this device via interpretation to be used by host CLP
+	 */
+	zdev->gisa = gisa;
+
+	rc = zpci_enable_device(zdev);
+	if (rc)
+		goto err;
+
+	/* Re-register the IOMMU that was already created */
+	rc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
+				virt_to_phys(zdev->dma_table));
+	if (rc)
+		goto err;
+
+	return rc;
+
+err:
+	zdev->gisa = 0;
+	return rc;
+}
+EXPORT_SYMBOL_GPL(kvm_s390_pci_interp_enable);
+
+int kvm_s390_pci_interp_disable(struct zpci_dev *zdev)
+{
+	int rc;
+
+	if (zdev->gisa == 0)
+		return -EINVAL;
+
+	/* Remove the host CLP guest designation */
+	zdev->gisa = 0;
+
+	if (zdev_enabled(zdev)) {
+		rc = zpci_disable_device(zdev);
+		if (rc)
+			return rc;
+	}
+
+	rc = zpci_enable_device(zdev);
+	if (rc)
+		return rc;
+
+	/* Re-register the IOMMU that was already created */
+	rc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
+				virt_to_phys(zdev->dma_table));
+
+	return rc;
+}
+EXPORT_SYMBOL_GPL(kvm_s390_pci_interp_disable);
+
  int kvm_s390_pci_dev_open(struct zpci_dev *zdev)
  {
  	struct kvm_zdev *kzdev;
arch/s390/pci/pci.c +3 -0
index 13033717cd4e..5dbe49ec325e 100644
@@ -147,6 +147,7 @@ int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas,
  		zpci_dbg(3, "reg ioat fid:%x, cc:%d, status:%d\n", zdev->fid, cc, status);
  	return cc;
  }
+EXPORT_SYMBOL_GPL(zpci_register_ioat);
 
  /* Modify PCI: Unregister I/O address translation parameters */
  int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas)
@@ -727,6 +728,7 @@ int zpci_enable_device(struct zpci_dev *zdev)
  		zpci_update_fh(zdev, fh);
  	return rc;
  }
+EXPORT_SYMBOL_GPL(zpci_enable_device);
 
  int zpci_disable_device(struct zpci_dev *zdev)
  {
@@ -750,6 +752,7 @@ int zpci_disable_device(struct zpci_dev *zdev)
  	}
  	return rc;
  }
+EXPORT_SYMBOL_GPL(zpci_disable_device);
 
  /**
   * zpci_hot_reset_device - perform a reset of the given zPCI function
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
author maintainer
#34 lore raw

PATCH v3 20/30 KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding

In reply to Matthew Rosato

These routines will be wired into the vfio_pci_zdev ioctl handlers to respond to requests to enable / disable a device for Adapter Event Notifications / Adapter Interuption Forwarding.

---
 arch/s390/include/asm/kvm_pci.h |   9 +-
 arch/s390/kvm/pci.c             | 217 +++++++++++++++++++++++++++++++-
 arch/s390/pci/pci_insn.c        |   1 +
 3 files changed, 225 insertions(+), 2 deletions(-)
arch/s390/include/asm/kvm_pci.h +8 -1
index 422701d526dd..377eebcba2d1 100644
@@ -15,17 +15,24 @@
 #include <linux/kvm_host.h>
 #include <linux/kvm.h>
 #include <linux/pci.h>
+#include <asm/pci_insn.h>
 
 struct kvm_zdev {
 	struct zpci_dev *zdev;
 	struct kvm *kvm;
+	struct zpci_fib fib;
 };
 
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
 void kvm_s390_pci_dev_release(struct zpci_dev *zdev);
 
+int kvm_s390_pci_aif_probe(struct zpci_dev *zdev);
+int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
+			    bool assist);
+int kvm_s390_pci_aif_disable(struct zpci_dev *zdev, bool force);
+
 int kvm_s390_pci_interp_probe(struct zpci_dev *zdev);
 int kvm_s390_pci_interp_enable(struct zpci_dev *zdev);
-int kvm_s390_pci_interp_disable(struct zpci_dev *zdev);
+int kvm_s390_pci_interp_disable(struct zpci_dev *zdev, bool force);
 
 #endif /* ASM_KVM_PCI_H */
arch/s390/kvm/pci.c +216 -1

241 lines not on this page · raw message

arch/s390/pci/pci_insn.c +1 -0
index ca6399d52767..f7d0e29bbf0b 100644
@@ -59,6 +59,7 @@ u8 zpci_mod_fc(u64 req, struct zpci_fib *fib, u8 *status)
 
 	return cc;
 }
+EXPORT_SYMBOL_GPL(zpci_mod_fc);
 
 /* Refresh PCI Translations */
 static inline u8 __rpcit(u64 fn, u64 addr, u64 range, u8 *status)
Signature · 1 line
2.27.0
author maintainer
#35 lore raw

PATCH v3 21/30 KVM: s390: pci: provide routines for enabling/disabling IOAT assist

In reply to Matthew Rosato

These routines will be wired into the vfio_pci_zdev ioctl handlers to respond to requests to enable / disable a device for PCI I/O Address Translation assistance.

---
 arch/s390/include/asm/kvm_pci.h |  15 ++++
 arch/s390/include/asm/pci_dma.h |   2 +
 arch/s390/kvm/pci.c             | 142 ++++++++++++++++++++++++++++++++
 arch/s390/kvm/pci.h             |   2 +
 4 files changed, 161 insertions(+)
arch/s390/include/asm/kvm_pci.h +15 -0
index 377eebcba2d1..370d6ba041fe 100644
@@ -15,11 +15,21 @@
 #include <linux/kvm_host.h>
 #include <linux/kvm.h>
 #include <linux/pci.h>
+#include <linux/mutex.h>
 #include <asm/pci_insn.h>
+#include <asm/pci_dma.h>
+
+struct kvm_zdev_ioat {
+	unsigned long *head[ZPCI_TABLE_PAGES];
+	unsigned long **seg;
+	unsigned long ***pt;
+	struct mutex ioat_lock; /* Must be held when modifying head/seg/pt */
+};
 
 struct kvm_zdev {
 	struct zpci_dev *zdev;
 	struct kvm *kvm;
+	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
 };
 
@@ -31,6 +41,11 @@ int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
 			    bool assist);
 int kvm_s390_pci_aif_disable(struct zpci_dev *zdev, bool force);
 
+int kvm_s390_pci_ioat_probe(struct zpci_dev *zdev);
+int kvm_s390_pci_ioat_enable(struct zpci_dev *zdev, u64 iota);
+int kvm_s390_pci_ioat_disable(struct zpci_dev *zdev);
+u8 kvm_s390_pci_get_dtsm(struct zpci_dev *zdev);
+
 int kvm_s390_pci_interp_probe(struct zpci_dev *zdev);
 int kvm_s390_pci_interp_enable(struct zpci_dev *zdev);
 int kvm_s390_pci_interp_disable(struct zpci_dev *zdev, bool force);
arch/s390/include/asm/pci_dma.h +2 -0
index 91e63426bdc5..69e616d0712c 100644
@@ -50,6 +50,8 @@ enum zpci_ioat_dtype {
 #define ZPCI_TABLE_ALIGN		ZPCI_TABLE_SIZE
 #define ZPCI_TABLE_ENTRY_SIZE		(sizeof(unsigned long))
 #define ZPCI_TABLE_ENTRIES		(ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE)
+#define ZPCI_TABLE_PAGES		(ZPCI_TABLE_SIZE >> PAGE_SHIFT)
+#define ZPCI_TABLE_ENTRIES_PAGES	(ZPCI_TABLE_ENTRIES * ZPCI_TABLE_PAGES)
 
 #define ZPCI_TABLE_BITS			11
 #define ZPCI_PT_BITS			8
arch/s390/kvm/pci.c +142 -0

178 lines not on this page · raw message

arch/s390/kvm/pci.h +2 -0
index 4d3db58beb74..0fa0e3d61aaa 100644
@@ -16,6 +16,8 @@
 #include <asm/airq.h>
 #include <asm/kvm_pci.h>
 
+#define KVM_S390_PCI_DTSM_MASK 0x40
+
 struct zpci_gaite {
 	u32 gisa;
 	u8 gisc;
Signature · 1 line
2.27.0
author maintainer
#36 lore raw

PATCH v3 22/30 KVM: s390: pci: handle refresh of PCI translations

In reply to Matthew Rosato

Add a routine that will perform a shadow operation between a guest and host IOAT. A subsequent patch will invoke this in response to an 04 RPCIT instruction intercept.

---
 arch/s390/include/asm/kvm_pci.h |   1 +
 arch/s390/include/asm/pci_dma.h |   1 +
 arch/s390/kvm/pci.c             | 201 +++++++++++++++++++++++++++++++-
 arch/s390/kvm/pci.h             |   8 +-
 4 files changed, 209 insertions(+), 2 deletions(-)
arch/s390/include/asm/kvm_pci.h +1 -0
index 370d6ba041fe..e4696f5592e1 100644
@@ -29,6 +29,7 @@ struct kvm_zdev_ioat {
 struct kvm_zdev {
 	struct zpci_dev *zdev;
 	struct kvm *kvm;
+	u64 rpcit_count;
 	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
 };
arch/s390/include/asm/pci_dma.h +1 -0
index 69e616d0712c..38004e0a4383 100644
@@ -52,6 +52,7 @@ enum zpci_ioat_dtype {
 #define ZPCI_TABLE_ENTRIES		(ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE)
 #define ZPCI_TABLE_PAGES		(ZPCI_TABLE_SIZE >> PAGE_SHIFT)
 #define ZPCI_TABLE_ENTRIES_PAGES	(ZPCI_TABLE_ENTRIES * ZPCI_TABLE_PAGES)
+#define ZPCI_TABLE_ENTRIES_PER_PAGE	(ZPCI_TABLE_ENTRIES / ZPCI_TABLE_PAGES)
 
 #define ZPCI_TABLE_BITS			11
 #define ZPCI_PT_BITS			8
arch/s390/kvm/pci.c +200 -1

217 lines not on this page · raw message

arch/s390/kvm/pci.h +7 -1
index 0fa0e3d61aaa..a409680a1dc2 100644
@@ -18,6 +18,9 @@
 
 #define KVM_S390_PCI_DTSM_MASK 0x40
 
+#define KVM_S390_RPCIT_INS_RES 0x10
+#define KVM_S390_RPCIT_ERR 0x28
+
 struct zpci_gaite {
 	u32 gisa;
 	u8 gisc;
@@ -33,6 +36,7 @@ struct zpci_aift {
 	struct kvm_zdev **kzdev;
 	spinlock_t gait_lock; /* Protects the gait, used during AEN forward */
 	struct mutex aift_lock; /* Protects the other structures in aift */
+	u32 mdd;
 };
 
 extern struct zpci_aift *aift;
@@ -48,7 +52,9 @@ static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift,
 
 int kvm_s390_pci_aen_init(u8 nisc);
 void kvm_s390_pci_aen_exit(void);
-
+int kvm_s390_pci_refresh_trans(struct kvm_vcpu *vcpu, unsigned long req,
+			       unsigned long start, unsigned long end,
+			       u8 *status);
 int kvm_s390_pci_init(void);
 
 #endif /* __KVM_S390_PCI_H */
Signature · 1 line
2.27.0
author maintainer
#37 lore raw

PATCH v3 23/30 KVM: s390: intercept the rpcit instruction

In reply to Matthew Rosato

For faster handling of PCI translation refreshes, intercept in KVM and call the associated handler.

---
 arch/s390/kvm/priv.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
arch/s390/kvm/priv.c +49 -0
index 417154b314a6..d6a5784d8dde 100644
@@ -29,6 +29,7 @@
 #include <asm/ap.h>
 #include "gaccess.h"
 #include "kvm-s390.h"
+#include "pci.h"
 #include "trace.h"
 
 static int handle_ri(struct kvm_vcpu *vcpu)
@@ -335,6 +336,52 @@ static int handle_rrbe(struct kvm_vcpu *vcpu)
 	return 0;
 }
 
+static int handle_rpcit(struct kvm_vcpu *vcpu)
+{
+	int reg1, reg2;
+	u8 status;
+	int rc;
+
+	if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+		return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
+	/*
+	 * If the host doesn't support PCI passthrough interpretation, it must
+	 * be an emulated device.
+	 */
+	if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV))
+		return -EOPNOTSUPP;
+
+	kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
+
+	/* If the device has a SHM bit on, let userspace take care of this */
+	if (((vcpu->run->s.regs.gprs[reg1] >> 32) & aift->mdd) != 0)
+		return -EOPNOTSUPP;
+
+	rc = kvm_s390_pci_refresh_trans(vcpu, vcpu->run->s.regs.gprs[reg1],
+					vcpu->run->s.regs.gprs[reg2],
+					vcpu->run->s.regs.gprs[reg2 + 1],
+					&status);
+
+	switch (rc) {
+	case 0:
+		kvm_s390_set_psw_cc(vcpu, 0);
+		break;
+	case -EOPNOTSUPP:
+		return -EOPNOTSUPP;
+	default:
+		vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00ffffffUL;
+		vcpu->run->s.regs.gprs[reg1] |= (u64)status << 24;
+		if (status != 0)
+			kvm_s390_set_psw_cc(vcpu, 1);
+		else
+			kvm_s390_set_psw_cc(vcpu, 3);
+		break;
+	}
+
+	return 0;
+}
+
 #define SSKE_NQ 0x8
 #define SSKE_MR 0x4
 #define SSKE_MC 0x2
@@ -1275,6 +1322,8 @@ int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
 		return handle_essa(vcpu);
 	case 0xaf:
 		return handle_pfmf(vcpu);
+	case 0xd3:
+		return handle_rpcit(vcpu);
 	default:
 		return -EOPNOTSUPP;
 	}
Signature · 1 line
2.27.0
author maintainer
#38 lore raw

PATCH v3 24/30 vfio-pci/zdev: wire up group notifier

In reply to Matthew Rosato

KVM zPCI passthrough device logic will need a reference to the associated kvm guest that has access to the device. Let's register a group notifier for VFIO_GROUP_NOTIFY_SET_KVM to catch this information in order to create an association between a kvm guest and the host zdev.

---
 arch/s390/include/asm/kvm_pci.h  |  2 ++
 drivers/vfio/pci/vfio_pci_core.c |  2 ++
 drivers/vfio/pci/vfio_pci_zdev.c | 46 ++++++++++++++++++++++++++++++++
 include/linux/vfio_pci_core.h    | 10 +++++++
 4 files changed, 60 insertions(+)
arch/s390/include/asm/kvm_pci.h +2 -0
index e4696f5592e1..16290b4cf2a6 100644
@@ -16,6 +16,7 @@
 #include <linux/kvm.h>
 #include <linux/pci.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <asm/pci_insn.h>
 #include <asm/pci_dma.h>
 
@@ -32,6 +33,7 @@ struct kvm_zdev {
 	u64 rpcit_count;
 	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
+	struct notifier_block nb;
 };
 
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +2 -0
index f948e6cd2993..fc57d4d0abbe 100644
@@ -452,6 +452,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
 
 	vfio_pci_vf_token_user_add(vdev, -1);
 	vfio_spapr_pci_eeh_release(vdev->pdev);
+	vfio_pci_zdev_release(vdev);
 	vfio_pci_core_disable(vdev);
 
 	mutex_lock(&vdev->igate);
@@ -470,6 +471,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);
 void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
 {
 	vfio_pci_probe_mmaps(vdev);
+	vfio_pci_zdev_open(vdev);
 	vfio_spapr_pci_eeh_open(vdev->pdev);
 	vfio_pci_vf_token_user_add(vdev, 1);
 }
drivers/vfio/pci/vfio_pci_zdev.c +46 -0

55 lines not on this page · raw message

include/linux/vfio_pci_core.h +10 -0
index 5e2bca3b89db..05287f8ac855 100644
@@ -198,12 +198,22 @@ static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 #ifdef CONFIG_VFIO_PCI_ZDEV
 extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 				       struct vfio_info_cap *caps);
+void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev);
+void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev);
 #else
 static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 					      struct vfio_info_cap *caps)
 {
 	return -ENODEV;
 }
+
+static inline void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
+{
+}
+
+static inline void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev)
+{
+}
 #endif
 
 /* Will be exported for vfio pci drivers usage */
Signature · 1 line
2.27.0
#39 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 46 lines · On Fri, 4 Feb 2022 16:15:30 -0500 Matthew Rosato <[email protected]>…

KVM zPCI passthrough device logic will need a reference to the associated kvm guest that has access to the device. Let's register a group notifier for VFIO_GROUP_NOTIFY_SET_KVM to catch this information in order to create an association between a kvm guest and the host zdev.

---
 arch/s390/include/asm/kvm_pci.h  |  2 ++
 drivers/vfio/pci/vfio_pci_core.c |  2 ++
 drivers/vfio/pci/vfio_pci_zdev.c | 46 ++++++++++++++++++++++++++++++++
 include/linux/vfio_pci_core.h    | 10 +++++++
 4 files changed, 60 insertions(+)
arch/s390/include/asm/kvm_pci.h +2 -0
index e4696f5592e1..16290b4cf2a6 100644
@@ -16,6 +16,7 @@
 #include <linux/kvm.h>
 #include <linux/pci.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <asm/pci_insn.h>
 #include <asm/pci_dma.h>
 
@@ -32,6 +33,7 @@ struct kvm_zdev {
 	u64 rpcit_count;
 	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
+	struct notifier_block nb;
 };
 
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +1 -0
index f948e6cd2993..fc57d4d0abbe 100644
@@ -452,6 +452,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
 
 	vfio_pci_vf_token_user_add(vdev, -1);
 	vfio_spapr_pci_eeh_release(vdev->pdev);
+	vfio_pci_zdev_release(vdev);
 	vfio_pci_core_disable(vdev);
 
 	mutex_lock(&vdev->igate);

drivers/vfio/pci/vfio_pci_core.c EXPORT_SYMBOL_GPL(vfio_pci_core_close_device); · line 477

Quoted 7 lines
drivers/vfio/pci/vfio_pci_core.c +1 -0
@@ -470,6 +471,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);
 void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
 {
 	vfio_pci_probe_mmaps(vdev);
+	vfio_pci_zdev_open(vdev);
 	vfio_spapr_pci_eeh_open(vdev->pdev);
 	vfio_pci_vf_token_user_add(vdev, 1);
 }

If this handling were for a specific device, I think we'd be suggesting this is the point at which we cross over to a vendor variant making use of vfio-pci-core rather than hooking directly into the core code. But this is meant to extend vfio-pci proper for the whole arch. Is there a compromise in using #ifdefs in vfio_pci_ops to call into zpci specific code that implements these arch specific hooks and the core for everything else? SPAPR code could probably converted similarly, it exists here for legacy reasons. [Cc Jason]

Also, please note the DEVICE_FEATURE generalizations in the latest series from NVIDIA for mlx5 migration support:

https://lore.kernel.org/all/[email protected]/

If this series were to go in via the s390 tree, I'd request a branch so that we can continue to work on this in vfio code as well. Thanks,

Alex

Quoted 88 lines
drivers/vfio/pci/vfio_pci_zdev.c +46 -0
index ea4c0d2b0663..9f8284499111 100644
@@ -13,6 +13,7 @@
 #include <linux/vfio_zdev.h>
 #include <asm/pci_clp.h>
 #include <asm/pci_io.h>
+#include <asm/kvm_pci.h>
 
 #include <linux/vfio_pci_core.h>
 
@@ -136,3 +137,48 @@ int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 
 	return ret;
 }
+
+static int vfio_pci_zdev_group_notifier(struct notifier_block *nb,
+					unsigned long action, void *data)
+{
+	struct kvm_zdev *kzdev = container_of(nb, struct kvm_zdev, nb);
+
+	if (action == VFIO_GROUP_NOTIFY_SET_KVM) {
+		if (!data || !kzdev->zdev)
+			return NOTIFY_DONE;
+		kzdev->kvm = data;
+	}
+
+	return NOTIFY_OK;
+}
+
+void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
+{
+	unsigned long events = VFIO_GROUP_NOTIFY_SET_KVM;
+	struct zpci_dev *zdev = to_zpci(vdev->pdev);
+
+	if (!zdev)
+		return;
+
+	if (kvm_s390_pci_dev_open(zdev))
+		return;
+
+	zdev->kzdev->nb.notifier_call = vfio_pci_zdev_group_notifier;
+
+	if (vfio_register_notifier(vdev->vdev.dev, VFIO_GROUP_NOTIFY,
+				   &events, &zdev->kzdev->nb))
+		kvm_s390_pci_dev_release(zdev);
+}
+
+void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev)
+{
+	struct zpci_dev *zdev = to_zpci(vdev->pdev);
+
+	if (!zdev || !zdev->kzdev)
+		return;
+
+	vfio_unregister_notifier(vdev->vdev.dev, VFIO_GROUP_NOTIFY,
+				 &zdev->kzdev->nb);
+
+	kvm_s390_pci_dev_release(zdev);
+}
include/linux/vfio_pci_core.h +10 -0
index 5e2bca3b89db..05287f8ac855 100644
@@ -198,12 +198,22 @@ static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 #ifdef CONFIG_VFIO_PCI_ZDEV
 extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 				       struct vfio_info_cap *caps);
+void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev);
+void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev);
 #else
 static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 					      struct vfio_info_cap *caps)
 {
 	return -ENODEV;
 }
+
+static inline void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
+{
+}
+
+static inline void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev)
+{
+}
 #endif
 
 /* Will be exported for vfio pci drivers usage */
#40 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 44 lines · Alex Williamson
Quoted 41 lines · On Fri, 4 Feb 2022 16:15:30 -0500 Matthew Rosato <[email protected]>…

KVM zPCI passthrough device logic will need a reference to the associated kvm guest that has access to the device. Let's register a group notifier for VFIO_GROUP_NOTIFY_SET_KVM to catch this information in order to create an association between a kvm guest and the host zdev.

 arch/s390/include/asm/kvm_pci.h  |  2 ++
 drivers/vfio/pci/vfio_pci_core.c |  2 ++
 drivers/vfio/pci/vfio_pci_zdev.c | 46 ++++++++++++++++++++++++++++++++
 include/linux/vfio_pci_core.h    | 10 +++++++
 4 files changed, 60 insertions(+)
arch/s390/include/asm/kvm_pci.h +3 -0
index e4696f5592e1..16290b4cf2a6 100644
+++ b/arch/s390/include/asm/kvm_pci.h
@@ -16,6 +16,7 @@
 #include <linux/kvm.h>
 #include <linux/pci.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <asm/pci_insn.h>
 #include <asm/pci_dma.h>
 
@@ -32,6 +33,7 @@ struct kvm_zdev {
 	u64 rpcit_count;
 	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
+	struct notifier_block nb;
 };
 
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +2 -0
index f948e6cd2993..fc57d4d0abbe 100644
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -452,6 +452,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
 
 	vfio_pci_vf_token_user_add(vdev, -1);
 	vfio_spapr_pci_eeh_release(vdev->pdev);
+	vfio_pci_zdev_release(vdev);
 	vfio_pci_core_disable(vdev);
 
Quoted 13 lines

drivers/vfio/pci/vfio_pci_core.c EXPORT_SYMBOL_GPL(vfio_pci_core_close_device); · line 477

Quoted 9 lines
drivers/vfio/pci/vfio_pci_core.c +1 -0
 	mutex_lock(&vdev->igate);
@@ -470,6 +471,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);
 void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
 {
 	vfio_pci_probe_mmaps(vdev);
+	vfio_pci_zdev_open(vdev);
 	vfio_spapr_pci_eeh_open(vdev->pdev);
 	vfio_pci_vf_token_user_add(vdev, 1);
 }

If this handling were for a specific device, I think we'd be suggesting this is the point at which we cross over to a vendor variant making use of vfio-pci-core rather than hooking directly into the core code.

Personally, I think it is wrong layering for VFIO to be aware of KVM like this. This marks the first time that VFIO core code itself is being made aware of the KVM linkage.

It copies the same kind of design the s390 specific mdev use of putting VFIO in charge of KVM functionality. If we are doing this we should just give up and admit that KVM is a first-class part of struct vfio_device and get rid of the notifier stuff too, at least for s390.

Reading the patches and descriptions pretty much everything is boiling down to 'use vfio to tell the kvm architecture code to do something' - which I think needs to be handled through a KVM side ioctl.

Or, at the very least, everything needs to be described in some way that makes it clear what is happening to userspace, without kvm, through these ioctls.

This seems especially true now that it seems s390 PCI support is almost truely functional, with actual new userspace instructions to issue MMIO operations that work outside of KVM.

I'm not sure how this all fits together, but I would expect an outcome where DPDK could run on these new systems and not have to know anything more about s390 beyond using the proper MMIO instructions via some compilation time enablement.

(I've been reviewing s390 patches updating rdma for a parallel set of stuff)

Quoted 5 lines

this is meant to extend vfio-pci proper for the whole arch. Is there a compromise in using #ifdefs in vfio_pci_ops to call into zpci specific code that implements these arch specific hooks and the core for everything else? SPAPR code could probably converted similarly, it exists here for legacy reasons. [Cc Jason]

I'm not sure I get what you are suggesting? Where would these ifdefs be?

Quoted 4 lines

Also, please note the DEVICE_FEATURE generalizations in the latest series from NVIDIA for mlx5 migration support:

https://lore.kernel.org/all/[email protected]/

Yes, please don't implement a bunch of new FEATURE code without taking the cleanup patches for feature support from that series too.

I can put them on a branch for you if you needed.

Jason

#41 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 59 lines · On Tue, 8 Feb 2022 14:51:41 -0400 Jason Gunthorpe <[email protected]> wrote:
Quoted 44 lines · Alex Williamson
Quoted 41 lines · On Fri, 4 Feb 2022 16:15:30 -0500 Matthew Rosato <[email protected]>…

KVM zPCI passthrough device logic will need a reference to the associated kvm guest that has access to the device. Let's register a group notifier for VFIO_GROUP_NOTIFY_SET_KVM to catch this information in order to create an association between a kvm guest and the host zdev.

 arch/s390/include/asm/kvm_pci.h  |  2 ++
 drivers/vfio/pci/vfio_pci_core.c |  2 ++
 drivers/vfio/pci/vfio_pci_zdev.c | 46 ++++++++++++++++++++++++++++++++
 include/linux/vfio_pci_core.h    | 10 +++++++
 4 files changed, 60 insertions(+)
arch/s390/include/asm/kvm_pci.h +3 -0
index e4696f5592e1..16290b4cf2a6 100644
+++ b/arch/s390/include/asm/kvm_pci.h
@@ -16,6 +16,7 @@
 #include <linux/kvm.h>
 #include <linux/pci.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <asm/pci_insn.h>
 #include <asm/pci_dma.h>
 
@@ -32,6 +33,7 @@ struct kvm_zdev {
 	u64 rpcit_count;
 	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
+	struct notifier_block nb;
 };
 
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +2 -0
index f948e6cd2993..fc57d4d0abbe 100644
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -452,6 +452,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
 
 	vfio_pci_vf_token_user_add(vdev, -1);
 	vfio_spapr_pci_eeh_release(vdev->pdev);
+	vfio_pci_zdev_release(vdev);
 	vfio_pci_core_disable(vdev);
 
Quoted 13 lines

drivers/vfio/pci/vfio_pci_core.c EXPORT_SYMBOL_GPL(vfio_pci_core_close_device); · line 477

Quoted 9 lines
drivers/vfio/pci/vfio_pci_core.c +1 -0
 	mutex_lock(&vdev->igate);
@@ -470,6 +471,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);
 void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
 {
 	vfio_pci_probe_mmaps(vdev);
+	vfio_pci_zdev_open(vdev);
 	vfio_spapr_pci_eeh_open(vdev->pdev);
 	vfio_pci_vf_token_user_add(vdev, 1);
 }  

If this handling were for a specific device, I think we'd be suggesting this is the point at which we cross over to a vendor variant making use of vfio-pci-core rather than hooking directly into the core code.

Quoted 3 lines

Personally, I think it is wrong layering for VFIO to be aware of KVM like this. This marks the first time that VFIO core code itself is being made aware of the KVM linkage.

I agree, but I've resigned that I've lost that battle. Both mdev vGPU vendors make specific assumptions about running on a VM. VFIO was never intended to be tied to KVM or the specific use case of a VM.

Quoted 4 lines

It copies the same kind of design the s390 specific mdev use of putting VFIO in charge of KVM functionality. If we are doing this we should just give up and admit that KVM is a first-class part of struct vfio_device and get rid of the notifier stuff too, at least for s390.

Euw. You're right, I really don't like vfio core code embracing this dependency for s390, device specific use cases are bad enough.

Quoted 3 lines

Reading the patches and descriptions pretty much everything is boiling down to 'use vfio to tell the kvm architecture code to do something' - which I think needs to be handled through a KVM side ioctl.

AIF at least sounds a lot like the reason we invented the irq bypass mechanism to allow interrupt producers and consumers to register independently and associate to each other with a shared token.

Is the purpose of IOAT to associate the device to a set of KVM page tables? That seems like a container or future iommufd operation. I read DTSM as supported formats for the IOAT.

Quoted 3 lines

Or, at the very least, everything needs to be described in some way that makes it clear what is happening to userspace, without kvm, through these ioctls.

As I understand the discussion here:

https://lore.kernel.org/all/[email protected]/

The assumption is that there is no non-KVM userspace currently. This seems like a regression to me.

Quoted 8 lines

This seems especially true now that it seems s390 PCI support is almost truely functional, with actual new userspace instructions to issue MMIO operations that work outside of KVM.

I'm not sure how this all fits together, but I would expect an outcome where DPDK could run on these new systems and not have to know anything more about s390 beyond using the proper MMIO instructions via some compilation time enablement.

Yes, fully enabling zPCI with vfio, but only for KVM is not optimal.

Quoted 11 lines

(I've been reviewing s390 patches updating rdma for a parallel set of stuff)

Quoted 5 lines

this is meant to extend vfio-pci proper for the whole arch. Is there a compromise in using #ifdefs in vfio_pci_ops to call into zpci specific code that implements these arch specific hooks and the core for everything else? SPAPR code could probably converted similarly, it exists here for legacy reasons. [Cc Jason]

I'm not sure I get what you are suggesting? Where would these ifdefs be?

Essentially just:

static const struct vfio_device_ops vfio_pci_ops = {
.name = "vfio-pci",
#ifdef CONFIG_S390

        .open_device    = vfio_zpci_open_device,
        .close_device   = vfio_zpci_close_device,
        .ioctl          = vfio_zpci_ioctl,
#else
        .open_device    = vfio_pci_open_device,
        .close_device   = vfio_pci_core_close_device,
        .ioctl          = vfio_pci_core_ioctl,
#endif
        .read           = vfio_pci_core_read,
        .write          = vfio_pci_core_write,
        .mmap           = vfio_pci_core_mmap,
        .request        = vfio_pci_core_request,
        .match          = vfio_pci_core_match,

};

It would at least provide more validation/exercise of the core/vendor split. Thanks,

Alex

author maintainer
#42 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 78 lines · Alex Williamson
Quoted 59 lines · On Tue, 8 Feb 2022 14:51:41 -0400 Jason Gunthorpe <[email protected]> wrote:
Quoted 44 lines · Alex Williamson
Quoted 41 lines · On Fri, 4 Feb 2022 16:15:30 -0500 Matthew Rosato <[email protected]>…

KVM zPCI passthrough device logic will need a reference to the associated kvm guest that has access to the device. Let's register a group notifier for VFIO_GROUP_NOTIFY_SET_KVM to catch this information in order to create an association between a kvm guest and the host zdev.

  arch/s390/include/asm/kvm_pci.h  |  2 ++
  drivers/vfio/pci/vfio_pci_core.c |  2 ++
  drivers/vfio/pci/vfio_pci_zdev.c | 46 ++++++++++++++++++++++++++++++++
  include/linux/vfio_pci_core.h    | 10 +++++++
  4 files changed, 60 insertions(+)
arch/s390/include/asm/kvm_pci.h +3 -0
index e4696f5592e1..16290b4cf2a6 100644
+++ b/arch/s390/include/asm/kvm_pci.h
@@ -16,6 +16,7 @@
  #include <linux/kvm.h>
  #include <linux/pci.h>
  #include <linux/mutex.h>
+#include <linux/notifier.h>
  #include <asm/pci_insn.h>
  #include <asm/pci_dma.h>
 
@@ -32,6 +33,7 @@ struct kvm_zdev {
  	u64 rpcit_count;
  	struct kvm_zdev_ioat ioat;
  	struct zpci_fib fib;
+	struct notifier_block nb;
  };
 
  int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +2 -0
index f948e6cd2993..fc57d4d0abbe 100644
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -452,6 +452,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
 
  	vfio_pci_vf_token_user_add(vdev, -1);
  	vfio_spapr_pci_eeh_release(vdev->pdev);
+	vfio_pci_zdev_release(vdev);
  	vfio_pci_core_disable(vdev);
 
Quoted 13 lines

drivers/vfio/pci/vfio_pci_core.c EXPORT_SYMBOL_GPL(vfio_pci_core_close_device); · line 477

Quoted 9 lines
drivers/vfio/pci/vfio_pci_core.c +1 -0
  	mutex_lock(&vdev->igate);
@@ -470,6 +471,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);
  void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
  {
  	vfio_pci_probe_mmaps(vdev);
+	vfio_pci_zdev_open(vdev);
  	vfio_spapr_pci_eeh_open(vdev->pdev);
  	vfio_pci_vf_token_user_add(vdev, 1);
  }

If this handling were for a specific device, I think we'd be suggesting this is the point at which we cross over to a vendor variant making use of vfio-pci-core rather than hooking directly into the core code.

Quoted 3 lines

Personally, I think it is wrong layering for VFIO to be aware of KVM like this. This marks the first time that VFIO core code itself is being made aware of the KVM linkage.

I agree, but I've resigned that I've lost that battle. Both mdev vGPU vendors make specific assumptions about running on a VM. VFIO was never intended to be tied to KVM or the specific use case of a VM.

Quoted 4 lines

It copies the same kind of design the s390 specific mdev use of putting VFIO in charge of KVM functionality. If we are doing this we should just give up and admit that KVM is a first-class part of struct vfio_device and get rid of the notifier stuff too, at least for s390.

Euw. You're right, I really don't like vfio core code embracing this dependency for s390, device specific use cases are bad enough.

Quoted 7 lines
Quoted 3 lines

Reading the patches and descriptions pretty much everything is boiling down to 'use vfio to tell the kvm architecture code to do something' - which I think needs to be handled through a KVM side ioctl.

AIF at least sounds a lot like the reason we invented the irq bypass mechanism to allow interrupt producers and consumers to register independently and associate to each other with a shared token.

Yes, these do sound quite similar, looking at it now though I haven't yet fully grokked irq bypass... But with AIF you have the case where either the interrupt will be delivered directly to a guest from firmware via an s390 construct (gisa) or under various circumstances the host (kvm) will be prodded to perform the delivery (still via gisa) instead.

Quoted 3 lines

Is the purpose of IOAT to associate the device to a set of KVM page tables? That seems like a container or future iommufd operation. I

Yes, here we are establishing a relationship with the DMA table in the guest so that once mappings are established guest PCI operations (handled via special instructions in s390) don't need to go through the host but can be directly handled by firmware (so, effectively guest can keep running on its vcpu vs breaking out).

Quoted 5 lines

read DTSM as supported formats for the IOAT.

Quoted 3 lines

Or, at the very least, everything needs to be described in some way that makes it clear what is happening to userspace, without kvm, through these ioctls.

Nothing, they don't need these ioctls. Userspace without a KVM registration for the device in question gets -EINVAL.

Quoted 7 lines

As I understand the discussion here:

https://lore.kernel.org/all/[email protected]/

The assumption is that there is no non-KVM userspace currently. This seems like a regression to me.

It's more that non-KVM userspace doesn't care about what these ioctls are doing... The enabling of 'interp, aif, ioat' is only pertinent when there is a KVM userspace, specifically because the information being shared / actions being performed as a result are only relevant to properly enabling zPCI features when the zPCI device is being passed through to a VM guest. If you're just using a userspace driver to talk to the device (no KVM guest involved) then the kernel zPCI layer already has this device set up using whatever s390 facilities are available.

Quoted 11 lines
Quoted 9 lines

This seems especially true now that it seems s390 PCI support is almost truely functional, with actual new userspace instructions to issue MMIO operations that work outside of KVM.

I'm not sure how this all fits together, but I would expect an outcome where DPDK could run on these new systems and not have to know anything more about s390 beyond using the proper MMIO instructions via some compilation time enablement.

Yes, fully enabling zPCI with vfio, but only for KVM is not optimal.

See above. I think there is a misunderstanding here, it's not that we are only enabling zPCI with vfio for KVM, but rather than when using vfio to pass the device to a guest there is additional work that has to happen in order to 'fully enable' zPCI.

Quoted 38 lines
Quoted 4 lines

(I've been reviewing s390 patches updating rdma for a parallel set of stuff)

Quoted 8 lines
Quoted 5 lines

this is meant to extend vfio-pci proper for the whole arch. Is there a compromise in using #ifdefs in vfio_pci_ops to call into zpci specific code that implements these arch specific hooks and the core for everything else? SPAPR code could probably converted similarly, it exists here for legacy reasons. [Cc Jason]

I'm not sure I get what you are suggesting? Where would these ifdefs be?

Essentially just:

static const struct vfio_device_ops vfio_pci_ops = {
.name = "vfio-pci",
#ifdef CONFIG_S390

         .open_device    = vfio_zpci_open_device,
         .close_device   = vfio_zpci_close_device,
         .ioctl          = vfio_zpci_ioctl,
#else
         .open_device    = vfio_pci_open_device,
         .close_device   = vfio_pci_core_close_device,
         .ioctl          = vfio_pci_core_ioctl,
#endif
         .read           = vfio_pci_core_read,
         .write          = vfio_pci_core_write,
         .mmap           = vfio_pci_core_mmap,
         .request        = vfio_pci_core_request,
         .match          = vfio_pci_core_match,

};

It would at least provide more validation/exercise of the core/vendor split. Thanks,

Alex

#43 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 8 lines · Matthew Rosato
Quoted 2 lines

Is the purpose of IOAT to associate the device to a set of KVM page tables? That seems like a container or future iommufd operation. I

Yes, here we are establishing a relationship with the DMA table in the guest so that once mappings are established guest PCI operations (handled via special instructions in s390) don't need to go through the host but can be directly handled by firmware (so, effectively guest can keep running on its vcpu vs breaking out).

Oh, well, certainly sounds like a NAK on that - anything to do with the DMA translation of a PCI device must go through the iommu layer, not here.

Lets not repeat the iommu subsytem bypass mess power made please.

Quoted 6 lines

It's more that non-KVM userspace doesn't care about what these ioctls are doing... The enabling of 'interp, aif, ioat' is only pertinent when there is a KVM userspace, specifically because the information being shared / actions being performed as a result are only relevant to properly enabling zPCI features when the zPCI device is being passed through to a VM guest.

Then why are they KVM ioctls?

Jason

author maintainer
#44 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 17 lines · Jason Gunthorpe
Quoted 8 lines · Matthew Rosato
Quoted 2 lines

Is the purpose of IOAT to associate the device to a set of KVM page tables? That seems like a container or future iommufd operation. I

Yes, here we are establishing a relationship with the DMA table in the guest so that once mappings are established guest PCI operations (handled via special instructions in s390) don't need to go through the host but can be directly handled by firmware (so, effectively guest can keep running on its vcpu vs breaking out).

Oh, well, certainly sounds like a NAK on that - anything to do with the DMA translation of a PCI device must go through the iommu layer, not here.

Lets not repeat the iommu subsytem bypass mess power made please.

Quoted 8 lines
Quoted 6 lines

It's more that non-KVM userspace doesn't care about what these ioctls are doing... The enabling of 'interp, aif, ioat' is only pertinent when there is a KVM userspace, specifically because the information being shared / actions being performed as a result are only relevant to properly enabling zPCI features when the zPCI device is being passed through to a VM guest.

Then why are they KVM ioctls?

Well, the primary reason I ended up here was that I need to ensure the the operation is only performed when guest X owns host zPCI device Y. The vfio-pci device ioctl had the benefit of acting on device granularity + also already being aware of the host PCI (and thus zPCI) device association -- so I already know exactly what hostdev is being referenced for the operation. All that was needed was the KVM notifier to ensure the vfio device was associated to a KVM guest.

I think moving over to a KVM ioctl is doable; I might still need to rely on VFIO_GROUP_NOTIFY_SET_KVM though, not sure yet.

Based on prior comments in this thread I'm assuming Alex shares that view too (don't use vfio device ioctl for something only being used for VM passthrough) so I'll start looking at using KVM ioctls instead.

maintainer
#45 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

In reply to Jason Gunthorpe
Quoted 11 lines · Jason Gunthorpe
Quoted 8 lines · Matthew Rosato
Quoted 2 lines

Is the purpose of IOAT to associate the device to a set of KVM page tables? That seems like a container or future iommufd operation. I

Yes, here we are establishing a relationship with the DMA table in the guest so that once mappings are established guest PCI operations (handled via special instructions in s390) don't need to go through the host but can be directly handled by firmware (so, effectively guest can keep running on its vcpu vs breaking out).

Quoted 5 lines

Oh, well, certainly sounds like a NAK on that - anything to do with the DMA translation of a PCI device must go through the iommu layer, not here.

Lets not repeat the iommu subsytem bypass mess power made please.

Maybe some context on all of this. First it's important to note that on s390x the PCI IOMMU hardware is controlled with special instructions. For pass-through this is actually quite nice as it makes it relatively simple for us to always run with an IOMMU in the guest we simply need to provide the instructions. Meaning we get full IOMMU protection for pass-through devices on KVM guests, guests with pass-through remain pageable and we can even support nested pass-through.

This is possible with relatively little overhead because we can do all of the per map/unmap guest IOMMU operations with a single instruction intercept. The instruction we need to intercept is called Refresh PCI Translations (RPCIT). It's job is twofold.

For an OS running directly on our machine hypervisor LPAR it flushes the IOMMU's TLB by informing it which pages have been invalidated while the hardware walks the page tables and fills the TLB on it's own for establishing a mapping for previously invalid IOVAs.

In a KVM or z/VM guest the guest is informed that IOMMU translations need to be refreshed even for previously invalid IOVAs. With this the guest builds it's IOMMU translation tables as normal but then does a RPCIT for the IOVA range it touched. In the hypervisor we can then simply walk the translation tables, pin the guest pages and map them in the host IOMMU. Prior to this series this happened in QEMU which does the map via vfio-iommu-type1 from user-space. This works and will remain as a fallback. Sadly it is quite slow and has a large impact on performance as we need to do a lot of mapping operations as the DMA API of the guest goes through the virtual IOMMU. This series thus adds the same functionality but as a KVM intercept of RPCIT. Now I think this neatly fits into KVM, we're emulating an instruction after all and most of its work is KVM specific pinning of guest pages. Importantly all other handling like IOMMU domain attachment still goes through vfio- iommu-type1 and we just fast path the map/unmap operations.

In the code the map/unmap boils down to dma_walk_cpu_trans() and parts of dma_shadow_cpu_trans() both called in dma_table_shadow(). The former is a function already shared between our DMA API and IOMMU API implementations and the only code that walks the host translation tables. So in a way we're side stepping the IOMMU API ops that is true but we do not side step the IOMMU host table access code paths. Notice how our IOMMU API is also < 400 LOC because both the DMA and IOMMU APIs share code.

That said, I believe we should be able to do the mapping still in a KVM RPCIT intercept but going through IOMMU API ops if this side stepping is truly unacceptable. It definitely adds overhead though and I'm not sure what we gain in clarity or maintainability since we already share the actual host table access code and there is only one PCI IOMMU and that is part of the architecture. Also either KVM or QEMU needs to know about the same details for looking at guest IOMMU translation tables / emulating the guest IOMMU. It's also clear that the IOMMU API will remain functional on its own as it is necesssary for any non-KVM use case which of course can't intercept RPCIT but on the other hand can also keep mappings much longer signficantly reducing overhead.

#46 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 7 lines · Niklas Schnelle

In a KVM or z/VM guest the guest is informed that IOMMU translations need to be refreshed even for previously invalid IOVAs. With this the guest builds it's IOMMU translation tables as normal but then does a RPCIT for the IOVA range it touched. In the hypervisor we can then simply walk the translation tables, pin the guest pages and map them in the host IOMMU. Prior to this series this happened in QEMU which does the map via vfio-iommu-type1 from user-space. This works and will

Quoted 8 lines

remain as a fallback. Sadly it is quite slow and has a large impact on performance as we need to do a lot of mapping operations as the DMA API of the guest goes through the virtual IOMMU. This series thus adds the same functionality but as a KVM intercept of RPCIT. Now I think this neatly fits into KVM, we're emulating an instruction after all and most of its work is KVM specific pinning of guest pages. Importantly all other handling like IOMMU domain attachment still goes through vfio- iommu-type1 and we just fast path the map/unmap operations.

So you create an iommu_domain and then hand it over to kvm which then does map/unmap operations on it under the covers?

How does the page pinning work?

In the design we are trying to reach I would say this needs to be modeled as a special iommu_domain that has this automatic map/unmap behavior from following user pages. Creating it would specify the kvm and the in-guest base address of the guest's page table. Then the magic kernel code you describe can operate on its own domain without becoming confused with a normal map/unmap domain.

It is like the HW nested translation other CPUs are doing, but instead of HW nested, it is SW nested.

Jason

maintainer
#47 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 18 lines · Jason Gunthorpe
Quoted 7 lines · Niklas Schnelle

In a KVM or z/VM guest the guest is informed that IOMMU translations need to be refreshed even for previously invalid IOVAs. With this the guest builds it's IOMMU translation tables as normal but then does a RPCIT for the IOVA range it touched. In the hypervisor we can then simply walk the translation tables, pin the guest pages and map them in the host IOMMU. Prior to this series this happened in QEMU which does the map via vfio-iommu-type1 from user-space. This works and will

Quoted 8 lines

remain as a fallback. Sadly it is quite slow and has a large impact on performance as we need to do a lot of mapping operations as the DMA API of the guest goes through the virtual IOMMU. This series thus adds the same functionality but as a KVM intercept of RPCIT. Now I think this neatly fits into KVM, we're emulating an instruction after all and most of its work is KVM specific pinning of guest pages. Importantly all other handling like IOMMU domain attachment still goes through vfio- iommu-type1 and we just fast path the map/unmap operations.

Quoted 2 lines

So you create an iommu_domain and then hand it over to kvm which then does map/unmap operations on it under the covers?

Yes

Quoted 2 lines

How does the page pinning work?

The pinning is done directly in the RPCIT interception handler pinning both the IOMMU tables and the guest pages mapped for DMA.

Quoted 5 lines

In the design we are trying to reach I would say this needs to be modeled as a special iommu_domain that has this automatic map/unmap behavior from following user pages. Creating it would specify the kvm and the in-guest base address of the guest's page table.

Makes sense.

Quoted 3 lines

Then the
magic kernel code you describe can operate on its own domain without becoming confused with a normal map/unmap domain.

This sounds like an interesting idea. Looking at drivers/iommu/s390_iommu.c most of that is pretty trivial domain handling. I wonder if we could share this by marking the existing s390_iommu_domain type with kind of a "lent out to KVM" flag. Possibly by simply having a non-NULL pointer to a struct holding the guest base address and kvm etc? That way we can share the setup/tear down of the domain and of host IOMMU tables as well as aperture checks the same while also being able to keep the IOMMU API from interfering with the KVM RPCIT intercept and vice versa. I.e. while the domain is under control of KVM's RPCIT handling we make all IOMMU map/unmap fail.

To me this more direct involvement of IOMMU and KVM on s390x is also a direct consequence of it using special instructions. Naturally those instructions can be intercepted or run under hardware accelerated virtualization.

Quoted 3 lines

It is like the HW nested translation other CPUs are doing, but instead of HW nested, it is SW nested.

Yes very good analogy. Has any of that nested IOMMU translations work been merged yet? I know AMD had something in the works and nested translations have been around for the MMU for a while and are also used on s390x. We're definitely thinking about HW nested IOMMU translations too so any design we come up with would be able to deal with that too. Basically we would then execute RPCIT without leaving the hardware virtualization mode (SIE). We believe that that would require pinning all of guest memory though because HW can't really pin pages.

#48 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 4 lines · Niklas Schnelle
Quoted 1 line

How does the page pinning work?

The pinning is done directly in the RPCIT interception handler pinning both the IOMMU tables and the guest pages mapped for DMA.

And if pinning fails?

Quoted 8 lines
Quoted 3 lines

Then the
magic kernel code you describe can operate on its own domain without becoming confused with a normal map/unmap domain.

This sounds like an interesting idea. Looking at drivers/iommu/s390_iommu.c most of that is pretty trivial domain handling. I wonder if we could share this by marking the existing s390_iommu_domain type with kind of a "lent out to KVM" flag.

Lu has posted a series here:

https://lore.kernel.org/linux-iommu/[email protected]

Which allows the iommu driver to create a domain with unique ops, so you'd just fork the entire thing, have your own struct s390_kvm_iommu_domain and related ops.

When the special creation flow is triggered you'd just create one of these with the proper ops already setup.

We are imagining a special ioctl to create these things and each IOMMU HW driver can supply a unique implementation suited to their HW design.

Quoted 2 lines

KVM RPCIT intercept and vice versa. I.e. while the domain is under control of KVM's RPCIT handling we make all IOMMU map/unmap fail.

It is not "under the control of" the domain would be created as linked to kvm and would never, ever, be anything else.

Quoted 4 lines

To me this more direct involvement of IOMMU and KVM on s390x is also a direct consequence of it using special instructions. Naturally those instructions can be intercepted or run under hardware accelerated virtualization.

Well, no, you've just created a kernel-side SW emulated nested translation scheme. Other CPUs have talked about doing this too, but nobody has attempted it.

You can make the same argument for any CPU's scheme, a trapped mmio store is not fundamentally any different from a special instruction that traps, other than how the information is transferred.

Quoted 2 lines

Yes very good analogy. Has any of that nested IOMMU translations work been merged yet?

No. We are making quiet progress, slowly though. I'll add your interest to my list

Quoted 4 lines

too. Basically we would then execute RPCIT without leaving the hardware virtualization mode (SIE). We believe that that would require pinning all of guest memory though because HW can't really pin pages.

Right, this is what other iommu HW will have to do.

Jason

author maintainer
#49 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 8 lines · Jason Gunthorpe
Quoted 4 lines · Niklas Schnelle
Quoted 1 line

How does the page pinning work?

The pinning is done directly in the RPCIT interception handler pinning both the IOMMU tables and the guest pages mapped for DMA.

And if pinning fails?

The RPCIT instruction is goes back to the guest with an indication that informs it the operation failed / gives it impetus to kick off a guest DMA refresh and clear up space (unpin).

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

Then the
magic kernel code you describe can operate on its own domain without becoming confused with a normal map/unmap domain.

This sounds like an interesting idea. Looking at drivers/iommu/s390_iommu.c most of that is pretty trivial domain handling. I wonder if we could share this by marking the existing s390_iommu_domain type with kind of a "lent out to KVM" flag.

Quoted 8 lines

Lu has posted a series here:

https://lore.kernel.org/linux-iommu/[email protected]

Which allows the iommu driver to create a domain with unique ops, so you'd just fork the entire thing, have your own struct s390_kvm_iommu_domain and related ops.

OK, looking into this, thanks for the pointer... Sounds to me like we then want to make the determination upfront and then ensure the right iommu domain ops are registered for the device sometime before creation, based upon the usecase -- general userspace: s390_iommu_ops (existing), kvm: s390_kvm_iommu_domain (new).

Quoted 5 lines

When the special creation flow is triggered you'd just create one of these with the proper ops already setup. >
We are imagining a special ioctl to create these things and each IOMMU HW driver can supply a unique implementation suited to their HW design.

But I haven't connected the dots on this part -- At the end of the day for this 'special creation flow' I need the kvm + starting point of the guest table + format before we let the new s390_kvm_iommu_domain start doing automatic map/unmap during RPCIT intercept -- This initial setup has to come from a special ioctl as you say, but where do you see it living? I could certainly roll my own via a KVM ioctl or whatever, but it sounds like you're also referring to a general-purpose ioctl to encompass each of the different unique implementations, with this s390 kvm approach being one.

#50 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

Quoted 5 lines · Matthew Rosato

OK, looking into this, thanks for the pointer... Sounds to me like we then want to make the determination upfront and then ensure the right iommu domain ops are registered for the device sometime before creation, based upon the usecase -- general userspace: s390_iommu_ops (existing), kvm:
s390_kvm_iommu_domain (new).

Yes, that is the idea. I expect there will be many types of these special iommu domains. eg Intel has talked about directly using the KVM CPU page tabe as the IOMMU page table.

Quoted 6 lines
Quoted 5 lines

When the special creation flow is triggered you'd just create one of these with the proper ops already setup. >
We are imagining a special ioctl to create these things and each IOMMU HW driver can supply a unique implementation suited to their HW design.

Quoted 8 lines

But I haven't connected the dots on this part -- At the end of the day for this 'special creation flow' I need the kvm + starting point of the guest table + format before we let the new s390_kvm_iommu_domain start doing automatic map/unmap during RPCIT intercept -- This initial setup has to come from a special ioctl as you say, but where do you see it living? I could certainly roll my own via a KVM ioctl or whatever, but it sounds like you're also referring to a general-purpose ioctl to encompass each of the different unique implementations, with this s390 kvm approach being one.

So, the ioctl will need, as input, a kvm FD and an iommufd FD, and additional IOMMU driver specific data (format, starting, etc).

The kvm supplies the context for the RPCIT to be captured in

The result is the creation of an iommu_domain inside iommufd, done by some iommu_ops->alloc_domain_xxxx() driver callback

Which FD has the ioctl it is a bit of an aesthetic choice, but I predict that iommufd makes the most sense since an object is being created inside iommfd.

This flow is very similar to the 'userspace page table' flow others are looking at, but has the extra twist that a KVM FD is needed to supply the CPU page table.

It may overlap nicely with the intel direction I mentioned. It is just ugly layering wise that KVM is getting shoved into platform code and uapis all over the place, but I suppose that is unavoidable. And the required loose coupling with the kvm module means all kinds of symbol_gets'etc :(

Jason

#51 lore raw

Re: [PATCH v3 24/30] vfio-pci/zdev: wire up group notifier

In reply to Alex Williamson
Quoted 6 lines · Alex Williamson
Quoted 3 lines

Personally, I think it is wrong layering for VFIO to be aware of KVM like this. This marks the first time that VFIO core code itself is being made aware of the KVM linkage.

I agree, but I've resigned that I've lost that battle. Both mdev vGPU vendors make specific assumptions about running on a VM.

The vGPU's are not as egregious though, are they?

Quoted 10 lines
Quoted 3 lines

Or, at the very least, everything needs to be described in some way that makes it clear what is happening to userspace, without kvm, through these ioctls.

As I understand the discussion here:

https://lore.kernel.org/all/[email protected]/

The assumption is that there is no non-KVM userspace currently. This seems like a regression to me.

Indeed, I definitely don't like it either. This is not VFIO if is just driving KVM.

I would prefer they add a function to get the 'struct device *' from a VFIO device fd and drive more of this from kvm, as appropriate.

Quoted 27 lines
Quoted 8 lines
Quoted 5 lines

this is meant to extend vfio-pci proper for the whole arch. Is there a compromise in using #ifdefs in vfio_pci_ops to call into zpci specific code that implements these arch specific hooks and the core for everything else? SPAPR code could probably converted similarly, it exists here for legacy reasons. [Cc Jason]

I'm not sure I get what you are suggesting? Where would these ifdefs be?

Essentially just:

static const struct vfio_device_ops vfio_pci_ops = {
.name = "vfio-pci",
#ifdef CONFIG_S390

        .open_device    = vfio_zpci_open_device,
        .close_device   = vfio_zpci_close_device,
        .ioctl          = vfio_zpci_ioctl,
#else
        .open_device    = vfio_pci_open_device,
        .close_device   = vfio_pci_core_close_device,
        .ioctl          = vfio_pci_core_ioctl,
#endif
        .read           = vfio_pci_core_read,
        .write          = vfio_pci_core_write,
        .mmap           = vfio_pci_core_mmap,
        .request        = vfio_pci_core_request,
        .match          = vfio_pci_core_match,
Quoted 4 lines

};

It would at least provide more validation/exercise of the core/vendor split. Thanks,

This would have to be in every pci driver - this is not just code the universal vfio-pci has to enable, but every migration driver/etc too.

And we will need it again in vfio-cxl for s390 in 10 years too..

So, I think this approach is the right one, asided from the philosophical question of being so tightly linking s390 vfio to KVM.

Jason

author maintainer
#52 lore raw

PATCH v3 25/30 vfio-pci/zdev: wire up zPCI interpretive execution support

In reply to Matthew Rosato

Introduce support for VFIO_DEVICE_FEATURE_ZPCI_INTERP, which is a new VFIO_DEVICE_FEATURE ioctl. This interface is used to indicate that an s390x vfio-pci device wishes to enable/disable zPCI interpretive execution, which allows zPCI instructions to be executed directly by underlying firmware without KVM involvement.

---
 arch/s390/include/asm/kvm_pci.h  |  1 +
 drivers/vfio/pci/vfio_pci_core.c |  2 +
 drivers/vfio/pci/vfio_pci_zdev.c | 73 ++++++++++++++++++++++++++++++++
 include/linux/vfio_pci_core.h    | 10 +++++
 include/uapi/linux/vfio.h        |  7 +++
 include/uapi/linux/vfio_zdev.h   | 15 +++++++
 6 files changed, 108 insertions(+)
arch/s390/include/asm/kvm_pci.h +1 -0
index 16290b4cf2a6..8f7d371e3e59 100644
@@ -34,6 +34,7 @@ struct kvm_zdev {
 	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
 	struct notifier_block nb;
+	bool interpretation;
 };
 
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +2 -0
index fc57d4d0abbe..2b2d64a2190c 100644
@@ -1172,6 +1172,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 			mutex_unlock(&vdev->vf_token->lock);
 
 			return 0;
+		case VFIO_DEVICE_FEATURE_ZPCI_INTERP:
+			return vfio_pci_zdev_feat_interp(vdev, feature, arg);
 		default:
 			return -ENOTTY;
 		}
drivers/vfio/pci/vfio_pci_zdev.c +73 -0

96 lines not on this page · raw message

include/linux/vfio_pci_core.h +10 -0
index 05287f8ac855..0db2b1051931 100644
@@ -198,6 +198,9 @@ static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
 #ifdef CONFIG_VFIO_PCI_ZDEV
 extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 				       struct vfio_info_cap *caps);
+int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
+			      struct vfio_device_feature feature,
+			      unsigned long arg);
 void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev);
 void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev);
 #else
@@ -207,6 +210,13 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 	return -ENODEV;
 }
 
+static inline int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
+					    struct vfio_device_feature feature,
+					    unsigned long arg)
+{
+	return -ENOTTY;
+}
+
 static inline void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
 {
 }
include/uapi/linux/vfio.h +7 -0
index ef33ea002b0b..b9a75485b8e7 100644
@@ -1002,6 +1002,13 @@ struct vfio_device_feature {
  */
 #define VFIO_DEVICE_FEATURE_PCI_VF_TOKEN	(0)
 
+/*
+ * Provide support for enabling interpretation of zPCI instructions.  This
+ * feature is only valid for s390x PCI devices.  Data provided when setting
+ * and getting this feature is futher described in vfio_zdev.h
+ */
+#define VFIO_DEVICE_FEATURE_ZPCI_INTERP		(1)
+
 /* -------- API for Type1 VFIO IOMMU -------- */
 
 /**
include/uapi/linux/vfio_zdev.h +15 -0
index b4309397b6b2..575f0410dc66 100644
@@ -75,4 +75,19 @@ struct vfio_device_info_cap_zpci_pfip {
 	__u8 pfip[];
 };
 
+/**
+ * VFIO_DEVICE_FEATURE_ZPCI_INTERP
+ *
+ * This feature is used for enabling zPCI instruction interpretation for a
+ * device.  No data is provided when setting this feature.  When getting
+ * this feature, the following structure is provided which details whether
+ * or not interpretation is active and provides the guest with host device
+ * information necessary to enable interpretation.
+ */
+struct vfio_device_zpci_interp {
+	__u64 flags;
+#define VFIO_DEVICE_ZPCI_FLAG_INTERP 1
+	__u32 fh;		/* Host device function handle */
+};
+
 #endif
Signature · 1 line
2.27.0
author maintainer
#53 lore raw

PATCH v3 26/30 vfio-pci/zdev: wire up zPCI adapter interrupt forwarding support

In reply to Matthew Rosato

Introduce support for VFIO_DEVICE_FEATURE_ZPCI_AIF, which is a new VFIO_DEVICE_FEATURE ioctl. This interface is used to indicate that an s390x vfio-pci device wishes to enable/disable zPCI adapter interrupt forwarding, which allows underlying firmware to deliver interrupts directly to the associated kvm guest.

---
 arch/s390/include/asm/kvm_pci.h  |  2 +
 drivers/vfio/pci/vfio_pci_core.c |  2 +
 drivers/vfio/pci/vfio_pci_zdev.c | 93 +++++++++++++++++++++++++++++++-
 include/linux/vfio_pci_core.h    | 10 ++++
 include/uapi/linux/vfio.h        |  7 +++
 include/uapi/linux/vfio_zdev.h   | 20 +++++++
 6 files changed, 133 insertions(+), 1 deletion(-)
arch/s390/include/asm/kvm_pci.h +2 -0
index 8f7d371e3e59..93b61e61dc7f 100644
@@ -35,6 +35,8 @@ struct kvm_zdev {
 	struct zpci_fib fib;
 	struct notifier_block nb;
 	bool interpretation;
+	bool aif_float; /* Enabled for floating interrupt assist */
+	bool aif_host; /* Require host delivery */
 };
 
 int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +2 -0
index 2b2d64a2190c..01658de660bd 100644
@@ -1174,6 +1174,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 			return 0;
 		case VFIO_DEVICE_FEATURE_ZPCI_INTERP:
 			return vfio_pci_zdev_feat_interp(vdev, feature, arg);
+		case VFIO_DEVICE_FEATURE_ZPCI_AIF:
+			return vfio_pci_zdev_feat_aif(vdev, feature, arg);
 		default:
 			return -ENOTTY;
 		}
drivers/vfio/pci/vfio_pci_zdev.c +92 -1

112 lines not on this page · raw message

include/linux/vfio_pci_core.h +10 -0
index 0db2b1051931..7ec5e82e7933 100644
@@ -201,6 +201,9 @@ extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
 			      struct vfio_device_feature feature,
 			      unsigned long arg);
+int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
+			   struct vfio_device_feature feature,
+			   unsigned long arg);
 void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev);
 void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev);
 #else
@@ -217,6 +220,13 @@ static inline int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
 	return -ENOTTY;
 }
 
+static inline int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
+					 struct vfio_device_feature feature,
+					 unsigned long arg)
+{
+	return -ENOTTY;
+}
+
 static inline void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
 {
 }
include/uapi/linux/vfio.h +7 -0
index b9a75485b8e7..fe3bfd99bf50 100644
@@ -1009,6 +1009,13 @@ struct vfio_device_feature {
  */
 #define VFIO_DEVICE_FEATURE_ZPCI_INTERP		(1)
 
+/*
+ * Provide support for enbaling adapter interruption forwarding for zPCI
+ * devices.  This feature is only valid for s390x PCI devices.  Data provided
+ * when setting and getting this feature is further described in vfio_zdev.h
+ */
+#define VFIO_DEVICE_FEATURE_ZPCI_AIF		(2)
+
 /* -------- API for Type1 VFIO IOMMU -------- */
 
 /**
include/uapi/linux/vfio_zdev.h +20 -0
index 575f0410dc66..09f413dfb1c3 100644
@@ -90,4 +90,24 @@ struct vfio_device_zpci_interp {
 	__u32 fh;		/* Host device function handle */
 };
 
+/**
+ * VFIO_DEVICE_FEATURE_ZPCI_AIF
+ *
+ * This feature is used for enabling forwarding of adapter interrupts directly
+ * from firmware to the guest.  When setting this feature, the flags indicate
+ * whether to enable/disable the feature and the structure defined below is
+ * used to setup the forwarding structures.  When getting this feature, only
+ * the flags are used to indicate the current state.
+ */
+struct vfio_device_zpci_aif {
+	__u64 flags;
+#define VFIO_DEVICE_ZPCI_FLAG_AIF_FLOAT 1	/* Enable floating interrupts */
+#define VFIO_DEVICE_ZPCI_FLAG_AIF_HOST 2	/* Force host delivery */
+	__u64 ibv;		/* Address of guest interrupt bit vector */
+	__u64 sb;		/* Address of guest summary bit */
+	__u32 noi;		/* Number of interrupts */
+	__u8 isc;		/* Guest interrupt subclass */
+	__u8 sbo;		/* Offset of guest summary bit vector */
+};
+
 #endif
Signature · 1 line
2.27.0
Reviewed-by on v3 26/30
#54 lore raw

Re: [PATCH v3 26/30] vfio-pci/zdev: wire up zPCI adapter interrupt forwarding support

Quoted 7 lines · Matthew Rosato

Introduce support for VFIO_DEVICE_FEATURE_ZPCI_AIF, which is a new VFIO_DEVICE_FEATURE ioctl. This interface is used to indicate that an s390x vfio-pci device wishes to enable/disable zPCI adapter interrupt forwarding, which allows underlying firmware to deliver interrupts directly to the associated kvm guest.

Quoted 230 lines
---
  arch/s390/include/asm/kvm_pci.h  |  2 +
  drivers/vfio/pci/vfio_pci_core.c |  2 +
  drivers/vfio/pci/vfio_pci_zdev.c | 93 +++++++++++++++++++++++++++++++-
  include/linux/vfio_pci_core.h    | 10 ++++
  include/uapi/linux/vfio.h        |  7 +++
  include/uapi/linux/vfio_zdev.h   | 20 +++++++
  6 files changed, 133 insertions(+), 1 deletion(-)
arch/s390/include/asm/kvm_pci.h +2 -0
index 8f7d371e3e59..93b61e61dc7f 100644
@@ -35,6 +35,8 @@ struct kvm_zdev {
  	struct zpci_fib fib;
  	struct notifier_block nb;
  	bool interpretation;
+	bool aif_float; /* Enabled for floating interrupt assist */
+	bool aif_host; /* Require host delivery */
  };
 
  int kvm_s390_pci_dev_open(struct zpci_dev *zdev);
drivers/vfio/pci/vfio_pci_core.c +2 -0
index 2b2d64a2190c..01658de660bd 100644
@@ -1174,6 +1174,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
  			return 0;
  		case VFIO_DEVICE_FEATURE_ZPCI_INTERP:
  			return vfio_pci_zdev_feat_interp(vdev, feature, arg);
+		case VFIO_DEVICE_FEATURE_ZPCI_AIF:
+			return vfio_pci_zdev_feat_aif(vdev, feature, arg);
  		default:
  			return -ENOTTY;
  		}
drivers/vfio/pci/vfio_pci_zdev.c +92 -1
index 71cc1eb8085f..74508bdc5f88 100644
@@ -13,6 +13,7 @@
  #include <linux/vfio_zdev.h>
  #include <asm/pci_clp.h>
  #include <asm/pci_io.h>
+#include <asm/pci_insn.h>
  #include <asm/kvm_pci.h>
 
  #include <linux/vfio_pci_core.h>
@@ -203,6 +204,94 @@ int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
  	return rc;
  }
 
+int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
+			   struct vfio_device_feature feature,
+			   unsigned long arg)
+{
+	struct zpci_dev *zdev = to_zpci(vdev->pdev);
+	struct vfio_device_zpci_aif *data;
+	struct vfio_device_feature *feat;
+	unsigned long minsz;
+	int size, rc = 0;
+
+	if (!zdev || !zdev->kzdev)
+		return -EINVAL;
+
+	/* If PROBE specified, return probe results immediately */
+	if (feature.flags & VFIO_DEVICE_FEATURE_PROBE)
+		return kvm_s390_pci_aif_probe(zdev);
+
+	size = sizeof(*feat) + sizeof(*data);
+	feat = kzalloc(size, GFP_KERNEL);
+	if (!feat)
+		return -ENOMEM;
+
+	data = (struct vfio_device_zpci_aif *)&feat->data;
+	minsz = offsetofend(struct vfio_device_feature, flags);
+
+	if (feature.argsz < minsz + sizeof(*data))
+		return -EINVAL;
+
+	/* Get the rest of the payload for GET/SET */
+	rc = copy_from_user(data, (void __user *)(arg + minsz),
+			    sizeof(*data));
+	if (rc)
+		rc = -EINVAL;
+
+	if (feature.flags & VFIO_DEVICE_FEATURE_GET) {
+		if (zdev->kzdev->aif_float)
+			data->flags = VFIO_DEVICE_ZPCI_FLAG_AIF_FLOAT;
+		if (zdev->kzdev->aif_host)
+			data->flags |= VFIO_DEVICE_ZPCI_FLAG_AIF_HOST;
+
+		if (copy_to_user((void __user *)arg, feat, size))
+			rc = -EFAULT;
+	} else if (feature.flags & VFIO_DEVICE_FEATURE_SET) {
+		if (data->flags & VFIO_DEVICE_ZPCI_FLAG_AIF_FLOAT) {
+			/* create a guest fib */
+			struct zpci_fib fib;
+
+			fib.fmt0.aibv = data->ibv;
+			fib.fmt0.isc = data->isc;
+			fib.fmt0.noi = data->noi;
+			if (data->sb != 0) {
+				fib.fmt0.aisb = data->sb;
+				fib.fmt0.aisbo = data->sbo;
+				fib.fmt0.sum = 1;
+			} else {
+				fib.fmt0.aisb = 0;
+				fib.fmt0.aisbo = 0;
+				fib.fmt0.sum = 0;
+			}
+			if (data->flags & VFIO_DEVICE_ZPCI_FLAG_AIF_HOST) {
+				rc = kvm_s390_pci_aif_enable(zdev, &fib, false);
+				if (!rc) {
+					zdev->kzdev->aif_float = true;
+					zdev->kzdev->aif_host = true;
+				}
+			} else {
+				rc = kvm_s390_pci_aif_enable(zdev, &fib, true);
+				if (!rc)
+					zdev->kzdev->aif_float = true;
+			}
+		} else if (data->flags == 0) {
+			rc = kvm_s390_pci_aif_disable(zdev, false);
+			if (!rc) {
+				zdev->kzdev->aif_float = false;
+				zdev->kzdev->aif_host = false;
+			}
+		} else {
+			rc = -EINVAL;
+		}
+	} else {
+		/* Neither GET nor SET were specified */
+		rc = -EINVAL;
+	}
+
+	kfree(feat);
+	return rc;
+}
+
  static int vfio_pci_zdev_group_notifier(struct notifier_block *nb,
  					unsigned long action, void *data)
  {
@@ -250,8 +339,10 @@ void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev)
  	 * If the device was using interpretation, don't trust that userspace
  	 * did the appropriate cleanup
  	 */
-	if (zdev->gisa != 0)
+	if (zdev->gisa != 0) {
+		kvm_s390_pci_aif_disable(zdev, true);
  		kvm_s390_pci_interp_disable(zdev, true);
+	}
 
  	kvm_s390_pci_dev_release(zdev);
  }
include/linux/vfio_pci_core.h +10 -0
index 0db2b1051931..7ec5e82e7933 100644
@@ -201,6 +201,9 @@ extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
  int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
  			      struct vfio_device_feature feature,
  			      unsigned long arg);
+int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
+			   struct vfio_device_feature feature,
+			   unsigned long arg);
  void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev);
  void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev);
  #else
@@ -217,6 +220,13 @@ static inline int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
  	return -ENOTTY;
  }
 
+static inline int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
+					 struct vfio_device_feature feature,
+					 unsigned long arg)
+{
+	return -ENOTTY;
+}
+
  static inline void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
  {
  }
include/uapi/linux/vfio.h +7 -0
index b9a75485b8e7..fe3bfd99bf50 100644
@@ -1009,6 +1009,13 @@ struct vfio_device_feature {
   */
  #define VFIO_DEVICE_FEATURE_ZPCI_INTERP		(1)
 
+/*
+ * Provide support for enbaling adapter interruption forwarding for zPCI
+ * devices.  This feature is only valid for s390x PCI devices.  Data provided
+ * when setting and getting this feature is further described in vfio_zdev.h
+ */
+#define VFIO_DEVICE_FEATURE_ZPCI_AIF		(2)
+
  /* -------- API for Type1 VFIO IOMMU -------- */
 
  /**
include/uapi/linux/vfio_zdev.h +20 -0
index 575f0410dc66..09f413dfb1c3 100644
@@ -90,4 +90,24 @@ struct vfio_device_zpci_interp {
  	__u32 fh;		/* Host device function handle */
  };
 
+/**
+ * VFIO_DEVICE_FEATURE_ZPCI_AIF
+ *
+ * This feature is used for enabling forwarding of adapter interrupts directly
+ * from firmware to the guest.  When setting this feature, the flags indicate
+ * whether to enable/disable the feature and the structure defined below is
+ * used to setup the forwarding structures.  When getting this feature, only
+ * the flags are used to indicate the current state.
+ */
+struct vfio_device_zpci_aif {
+	__u64 flags;
+#define VFIO_DEVICE_ZPCI_FLAG_AIF_FLOAT 1	/* Enable floating interrupts */
+#define VFIO_DEVICE_ZPCI_FLAG_AIF_HOST 2	/* Force host delivery */
+	__u64 ibv;		/* Address of guest interrupt bit vector */
+	__u64 sb;		/* Address of guest summary bit */
+	__u32 noi;		/* Number of interrupts */
+	__u8 isc;		/* Guest interrupt subclass */
+	__u8 sbo;		/* Offset of guest summary bit vector */
+};
+
  #endif
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
author maintainer
#55 lore raw

PATCH v3 27/30 vfio-pci/zdev: wire up zPCI IOAT assist support

In reply to Matthew Rosato

Introduce support for VFIO_DEVICE_FEATURE_ZPCI_IOAT, which is a new VFIO_DEVICE_FEATURE ioctl. This interface is used to indicate that an s390x vfio-pci device wishes to enable/disable zPCI I/O Address Translation assistance, allowing the host to perform address translation and shadowing.

---
 arch/s390/include/asm/kvm_pci.h  |  1 +
 drivers/vfio/pci/vfio_pci_core.c |  2 ++
 drivers/vfio/pci/vfio_pci_zdev.c | 58 ++++++++++++++++++++++++++++++++
 include/linux/vfio_pci_core.h    | 10 ++++++
 include/uapi/linux/vfio.h        |  8 +++++
 include/uapi/linux/vfio_zdev.h   | 13 +++++++
 6 files changed, 92 insertions(+)
arch/s390/include/asm/kvm_pci.h +1 -0
index 93b61e61dc7f..71d27863ab97 100644
@@ -31,6 +31,7 @@ struct kvm_zdev {
 	struct zpci_dev *zdev;
 	struct kvm *kvm;
 	u64 rpcit_count;
+	u64 iota;
 	struct kvm_zdev_ioat ioat;
 	struct zpci_fib fib;
 	struct notifier_block nb;
drivers/vfio/pci/vfio_pci_core.c +2 -0
index 01658de660bd..709d9ba22a60 100644
@@ -1176,6 +1176,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 			return vfio_pci_zdev_feat_interp(vdev, feature, arg);
 		case VFIO_DEVICE_FEATURE_ZPCI_AIF:
 			return vfio_pci_zdev_feat_aif(vdev, feature, arg);
+		case VFIO_DEVICE_FEATURE_ZPCI_IOAT:
+			return vfio_pci_zdev_feat_ioat(vdev, feature, arg);
 		default:
 			return -ENOTTY;
 		}
drivers/vfio/pci/vfio_pci_zdev.c +58 -0

70 lines not on this page · raw message

include/linux/vfio_pci_core.h +10 -0
index 7ec5e82e7933..f17d761ae14e 100644
@@ -204,6 +204,9 @@ int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
 int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
 			   struct vfio_device_feature feature,
 			   unsigned long arg);
+int vfio_pci_zdev_feat_ioat(struct vfio_pci_core_device *vdev,
+			    struct vfio_device_feature feature,
+			    unsigned long arg);
 void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev);
 void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev);
 #else
@@ -227,6 +230,13 @@ static inline int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
 	return -ENOTTY;
 }
 
+static inline int vfio_pci_zdev_feat_ioat(struct vfio_pci_core_device *vdev,
+					  struct vfio_device_feature feature,
+					  unsigned long arg)
+{
+	return -ENOTTY;
+}
+
 static inline void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
 {
 }
include/uapi/linux/vfio.h +8 -0
index fe3bfd99bf50..32c687388f48 100644
@@ -1016,6 +1016,14 @@ struct vfio_device_feature {
  */
 #define VFIO_DEVICE_FEATURE_ZPCI_AIF		(2)
 
+/*
+ * Provide support for enabling guest I/O address translation assistance for
+ * zPCI devices.  This feature is only valid for s390x PCI devices.  Data
+ * provided when setting and getting this feature is further described in
+ * vfio_zdev.h
+ */
+#define VFIO_DEVICE_FEATURE_ZPCI_IOAT		(3)
+
 /* -------- API for Type1 VFIO IOMMU -------- */
 
 /**
include/uapi/linux/vfio_zdev.h +13 -0
index 09f413dfb1c3..b77e6ef355cb 100644
@@ -110,4 +110,17 @@ struct vfio_device_zpci_aif {
 	__u8 sbo;		/* Offset of guest summary bit vector */
 };
 
+/**
+ * VFIO_DEVICE_FEATURE_ZPCI_IOAT
+ *
+ * This feature is used for enabling guest I/O translation assistance for
+ * passthrough zPCI devices using instruction interpretation.  When setting
+ * this feature, the iota specifies a KVM guest I/O translation anchor.  When
+ * getting this feature, the most recently set anchor (or 0) is returned in
+ * iota.
+ */
+struct vfio_device_zpci_ioat {
+	__u64 iota;
+};
+
 #endif
Signature · 1 line
2.27.0
author maintainer
#56 lore raw

PATCH v3 28/30 vfio-pci/zdev: add DTSM to clp group capability

In reply to Matthew Rosato

The DTSM, or designation type supported mask, indicates what IOAT formats are available to the guest. For an interpreted device, userspace will not know what format(s) the IOAT assist supports, so pass it via the capability chain. Since the value belongs to the Query PCI Function Group clp, let's extend the existing capability with a new version.

---
 drivers/vfio/pci/vfio_pci_zdev.c | 9 ++++++---
 include/uapi/linux/vfio_zdev.h   | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/vfio/pci/vfio_pci_zdev.c +6 -3
index f0a6e0f0e4b0..046d91085358 100644
@@ -45,19 +45,22 @@ static int zpci_group_cap(struct zpci_dev *zdev, struct vfio_info_cap *caps)
 {
 	struct vfio_device_info_cap_zpci_group cap = {
 		.header.id = VFIO_DEVICE_INFO_CAP_ZPCI_GROUP,
-		.header.version = 1,
+		.header.version = 2,
 		.dasm = zdev->dma_mask,
 		.msi_addr = zdev->msi_addr,
 		.flags = VFIO_DEVICE_INFO_ZPCI_FLAG_REFRESH,
 		.mui = zdev->fmb_update,
 		.noi = zdev->max_msi,
 		.maxstbl = ZPCI_MAX_WRITE_SIZE,
-		.version = zdev->version
+		.version = zdev->version,
+		.dtsm = 0
 	};
 
 	/* Some values are different for interpreted devices */
-	if (zdev->kzdev && zdev->kzdev->interpretation)
+	if (zdev->kzdev && zdev->kzdev->interpretation) {
 		cap.maxstbl = zdev->maxstbl;
+		cap.dtsm = kvm_s390_pci_get_dtsm(zdev);
+	}
 
 	return vfio_info_add_capability(caps, &cap.header, sizeof(cap));
 }
include/uapi/linux/vfio_zdev.h +3 -0
index b77e6ef355cb..133df1002ecb 100644
@@ -47,6 +47,9 @@ struct vfio_device_info_cap_zpci_group {
 	__u16 noi;		/* Maximum number of MSIs */
 	__u16 maxstbl;		/* Maximum Store Block Length */
 	__u8 version;		/* Supported PCI Version */
+	/* End of version 1 */
+	__u8 dtsm;		/* Supported IOAT Designations */
+	/* End of version 2 */
 };
 
 /**
Signature · 1 line
2.27.0
author maintainer
#57 lore raw

PATCH v3 29/30 KVM: s390: introduce CPU feature for zPCI Interpretation

In reply to Matthew Rosato

KVM_S390_VM_CPU_FEAT_ZPCI_INTERP relays whether zPCI interpretive execution is possible based on the available hardware facilities.

---
 arch/s390/include/uapi/asm/kvm.h | 1 +
 arch/s390/kvm/kvm-s390.c         | 5 +++++
 2 files changed, 6 insertions(+)
arch/s390/include/uapi/asm/kvm.h +1 -0
index 7a6b14874d65..ed06458a871f 100644
@@ -130,6 +130,7 @@ struct kvm_s390_vm_cpu_machine {
 #define KVM_S390_VM_CPU_FEAT_PFMFI	11
 #define KVM_S390_VM_CPU_FEAT_SIGPIF	12
 #define KVM_S390_VM_CPU_FEAT_KSS	13
+#define KVM_S390_VM_CPU_FEAT_ZPCI_INTERP 14
 struct kvm_s390_vm_cpu_feat {
 	__u64 feat[16];
 };
arch/s390/kvm/kvm-s390.c +5 -0
index 208b09d08385..e20d9ac1935d 100644
@@ -434,6 +434,11 @@ static void kvm_s390_cpu_feat_init(void)
 	if (test_facility(151)) /* DFLTCC */
 		__insn32_query(INSN_DFLTCC, kvm_s390_available_subfunc.dfltcc);
 
+	/* zPCI Interpretation */
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) && test_facility(69) &&
+	    test_facility(70) && test_facility(71) && test_facility(72))
+		allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ZPCI_INTERP);
+
 	if (MACHINE_HAS_ESOP)
 		allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ESOP);
 	/*
Signature · 1 line
2.27.0
Reviewed-by on v3 29/30
#58 lore raw

Re: [PATCH v3 29/30] KVM: s390: introduce CPU feature for zPCI Interpretation

Quoted 4 lines · Matthew Rosato

KVM_S390_VM_CPU_FEAT_ZPCI_INTERP relays whether zPCI interpretive execution is possible based on the available hardware facilities.

Quoted 34 lines
---
  arch/s390/include/uapi/asm/kvm.h | 1 +
  arch/s390/kvm/kvm-s390.c         | 5 +++++
  2 files changed, 6 insertions(+)
arch/s390/include/uapi/asm/kvm.h +1 -0
index 7a6b14874d65..ed06458a871f 100644
@@ -130,6 +130,7 @@ struct kvm_s390_vm_cpu_machine {
  #define KVM_S390_VM_CPU_FEAT_PFMFI	11
  #define KVM_S390_VM_CPU_FEAT_SIGPIF	12
  #define KVM_S390_VM_CPU_FEAT_KSS	13
+#define KVM_S390_VM_CPU_FEAT_ZPCI_INTERP 14
  struct kvm_s390_vm_cpu_feat {
  	__u64 feat[16];
  };
arch/s390/kvm/kvm-s390.c +5 -0
index 208b09d08385..e20d9ac1935d 100644
@@ -434,6 +434,11 @@ static void kvm_s390_cpu_feat_init(void)
  	if (test_facility(151)) /* DFLTCC */
  		__insn32_query(INSN_DFLTCC, kvm_s390_available_subfunc.dfltcc);
 
+	/* zPCI Interpretation */
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV) && test_facility(69) &&
+	    test_facility(70) && test_facility(71) && test_facility(72))
+		allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ZPCI_INTERP);
+
  	if (MACHINE_HAS_ESOP)
  		allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ESOP);
  	/*
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
author maintainer
#59 lore raw

PATCH v3 30/30 MAINTAINERS: additional files related kvm s390 pci passthrough

In reply to Matthew Rosato

Add entries from the s390 kvm subdirectory related to pci passthrough.

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index bb83dcbcb619..2762295ad85e 100644
@@ -16900,6 +16900,8 @@ M:	Eric Farman <[email protected]>
 L:	[email protected]
 L:	[email protected]
 S:	Supported
+F:	arch/s390/include/asm/kvm_pci.h
+F:	arch/s390/kvm/pci*
 F:	drivers/vfio/pci/vfio_pci_zdev.c
 F:	include/uapi/linux/vfio_zdev.h
 
Signature · 1 line
2.27.0
#60 lore raw

Re: [PATCH v3 30/30] MAINTAINERS: additional files related kvm s390 pci passthrough

Am 04.02.22 um 22:15 schrieb Matthew Rosato:

Quoted 3 lines

Add entries from the s390 kvm subdirectory related to pci passthrough.

Can you change that to [email protected] ?

Quoted 18 lines
---
  MAINTAINERS | 2 ++
  1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index bb83dcbcb619..2762295ad85e 100644
@@ -16900,6 +16900,8 @@ M:	Eric Farman <[email protected]>
  L:	[email protected]
  L:	[email protected]
  S:	Supported
+F:	arch/s390/include/asm/kvm_pci.h
+F:	arch/s390/kvm/pci*
  F:	drivers/vfio/pci/vfio_pci_zdev.c
  F:	include/uapi/linux/vfio_zdev.h
 
author maintainer
#61 lore raw

Re: [PATCH v3 30/30] MAINTAINERS: additional files related kvm s390 pci passthrough

Quoted 10 lines · Christian Borntraeger

Am 04.02.22 um 22:15 schrieb Matthew Rosato:

Quoted 3 lines

Add entries from the s390 kvm subdirectory related to pci passthrough.

Can you change that to  [email protected] ?

Sure. It looks like this happened on some of the earlier patches in this series too, I'll go ahead and adjust them all.

author maintainer
#62 lore raw
In reply to Matthew Rosato
Quoted 10 lines · Matthew Rosato

Enable interpretive execution of zPCI instructions + adapter interruption forwarding for s390x KVM vfio-pci. This is done by introducing a series of new vfio-pci feature ioctls that are unique vfio-pci-zdev (s390x) and are used to negotiate the various aspects of zPCI interpretation setup. By allowing intepretation of zPCI instructions and firmware delivery of interrupts to guests, we can significantly reduce the frequency of guest SIE exits for zPCI. We then see additional gains by handling a hot-path instruction that can still intercept to the hypervisor (RPCIT) directly in kvm.

Quoted 5 lines

From the perspective of guest configuration, you passthrough zPCI devices
in the same manner as before, with intepretation support being used by default if available in kernel+qemu.

Will reply with a link to the associated QEMU series.

https://lore.kernel.org/qemu-devel/[email protected]/