Skip to contentSkip to conversation

s390: vfio-ap: base implementation of VFIO AP device driver

GIT PULL Christian Borntraeger 1 participant 1 message Oct 2, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

From: Tony Krowiak <[email protected]>

Introduces a new AP device driver. This device driver is built on the VFIO mediated device framework. The framework provides sysfs interfaces that facilitate passthrough access by guests to devices installed on the linux host.

The VFIO AP device driver will serve two purposes:

1. Provide the interfaces to reserve AP devices for exclusive use by KVM guests. This is accomplished by unbinding the devices to be reserved for guest usage from the zcrypt device driver and binding them to the VFIO AP device driver.

2. Implements the functions, callbacks and sysfs attribute interfaces required to create one or more VFIO mediated devices each of which will be used to configure the AP matrix for a guest and serve as a file descriptor for facilitating communication between QEMU and the VFIO AP device driver.

When the VFIO AP device driver is initialized:

* It registers with the AP bus for control of type 10 (CEX4 and newer) AP queue devices. This limitation was imposed due to:

1. A desire to keep the code as simple as possible;

2. Some older models are no longer supported by the kernel and others are getting close to end of service.

3. A lack of older systems on which to test older devices.

The probe and remove callbacks will be provided to support the binding/unbinding of AP queue devices to/from the VFIO AP device driver.

* Creates a matrix device, /sys/devices/vfio_ap/matrix, to serve as the parent of the mediated devices created, one for each guest, and to hold the APQNs of the AP devices bound to the VFIO AP device driver.

Message-Id: <[email protected]>

---
 MAINTAINERS                           |  10 ++
 arch/s390/Kconfig                     |  11 ++
 drivers/iommu/Kconfig                 |   8 ++
 drivers/s390/crypto/Makefile          |   4 +
 drivers/s390/crypto/vfio_ap_drv.c     | 138 ++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_private.h |  34 +++++++
 6 files changed, 205 insertions(+)
 create mode 100644 drivers/s390/crypto/vfio_ap_drv.c
 create mode 100644 drivers/s390/crypto/vfio_ap_private.h
MAINTAINERS +10 -0
index 4ece30f15777..558f2abe7073 100644
@@ -12668,6 +12668,16 @@ W:	http://www.ibm.com/developerworks/linux/linux390/
 S:	Supported
 F:	drivers/s390/crypto/
 
+S390 VFIO AP DRIVER
+M:	Tony Krowiak <[email protected]>
+M:	Pierre Morel <[email protected]>
+M:	Halil Pasic <[email protected]>
+L:	[email protected]
+W:	http://www.ibm.com/developerworks/linux/linux390/
+S:	Supported
+F:	drivers/s390/crypto/vfio_ap_drv.c
+F:	drivers/s390/crypto/vfio_ap_private.h
+
 S390 ZFCP DRIVER
 M:	Steffen Maier <[email protected]>
 M:	Benjamin Block <[email protected]>
arch/s390/Kconfig +11 -0
index 9a9c7a6fe925..8cc8f25d9576 100644
@@ -773,6 +773,17 @@ config VFIO_CCW
 	  To compile this driver as a module, choose M here: the
 	  module will be called vfio_ccw.
 
+config VFIO_AP
+	def_tristate n
+	prompt "VFIO support for AP devices"
+	depends on S390_AP_IOMMU && VFIO_MDEV_DEVICE && KVM
+	help
+		This driver grants access to Adjunct Processor (AP) devices
+		via the VFIO mediated device interface.
+
+		To compile this driver as a module, choose M here: the module
+		will be called vfio_ap.
+
 endmenu
 
 menu "Dump support"
drivers/iommu/Kconfig +8 -0
index c60395b7470f..83e6d993fca5 100644
@@ -372,6 +372,14 @@ config S390_CCW_IOMMU
 	  Enables bits of IOMMU API required by VFIO. The iommu_ops
 	  is not implemented as it is not necessary for VFIO.
 
+config S390_AP_IOMMU
+	bool "S390 AP IOMMU Support"
+	depends on S390 && ZCRYPT
+	select IOMMU_API
+	help
+	  Enables bits of IOMMU API required by VFIO. The iommu_ops
+	  is not implemented as it is not necessary for VFIO.
+
 config MTK_IOMMU
 	bool "MTK IOMMU Support"
 	depends on ARM || ARM64
drivers/s390/crypto/Makefile +4 -0
index b59af548ed1c..48e466eb19cf 100644
@@ -15,3 +15,7 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
 # pkey kernel module
 pkey-objs := pkey_api.o
 obj-$(CONFIG_PKEY) += pkey.o
+
+# adjunct processor matrix
+vfio_ap-objs := vfio_ap_drv.o
+obj-$(CONFIG_VFIO_AP) += vfio_ap.o
drivers/s390/crypto/vfio_ap_drv.c new file +138 -0

138 lines not on this page · raw message

drivers/s390/crypto/vfio_ap_private.h new file +34 -0
new file mode 100644
index 000000000000..6141420c8bb0
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Private data and functions for adjunct processor VFIO matrix driver.
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * Copyright IBM Corp. 2018
+ */
+
+#ifndef _VFIO_AP_PRIVATE_H_
+#define _VFIO_AP_PRIVATE_H_
+
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/mdev.h>
+#include <linux/delay.h>
+#include <linux/mutex.h>
+
+#include "ap_bus.h"
+
+#define VFIO_AP_MODULE_NAME "vfio_ap"
+#define VFIO_AP_DRV_NAME "vfio_ap"
+
+/**
+ * ap_matrix_dev - the AP matrix device structure
+ * @device:	generic device structure associated with the AP matrix device
+ */
+struct ap_matrix_dev {
+	struct device device;
+};
+
+extern struct ap_matrix_dev *matrix_dev;
+
+#endif /* _VFIO_AP_PRIVATE_H_ */
Signature · 1 line
2.17.0