Skip to contentSkip to conversation

KVM: s390/crypto/vfio: guest dedicated crypto adapters

RFC Applied Tony Krowiak 7 participants 109 messages Oct 13, 2017 – Dec 6, 2017 2 messages not in the archive

Subsystems (6)
KVM s390 VFIO driver KVM s390 +2 more subsystems

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover KVM: s390/crypto/vfio: guest dedicated crypto adapters

Overview:
--------
An adjunct processor (AP) facility is an IBM Z cryptographic facility. The AP facility is comprised of three AP instructions and from 1 to 256 AP adapter cards. The design takes advantage of the interpretive execution mode provided by the SIE architecture. With interpretive execution mode, the AP instructions executed on the guest are interpreted by the hardware. This allows guests direct access to AP adapter cards. The first goal of this patch series is to provide direct access by a KVM guest to an AP as a pass-through device. The second goal is to provide administrators with the means to configure KVM guests to grant direct access to AP facilities assigned to the LPAR in which the host linux system is running.

To facilitate the comprehension of the design, let's present an overview of the AP architecture.

AP Architectural Overview
-------------------------
Let's start with some definitions:

* AP adapter

An AP adapter is an IBM Z adapter card that can perform cryptographic functionality. There can be from 0 to 256 adapters assigned to an LPAR.
Each adapter is identified by a number from 0 to 255. When
installed, an AP is accessed by AP instructions executed by any CPU.

* AP domain

An adapter can be partitioned into domains. An adapter can hold up to 256 domains. Each domain is identified by a number from 0 to 255. Domains can be further classified into two types:

* Usage domains are domains that can be accessed directly to process AP commands

* Control domains are domains that are accessed indirectly by AP commands sent to a usage domain to control or change the domain.

* AP Queue

An AP queue is the means by which an AP command is sent to an AP usage domain inside a specific AP. An AP queue is identified by a tuple comprised of an AP adapter ID and a usage domain index corresponding to a given usage domain within the adapter. This tuple forms an AP Queue Number (APQN) uniquely identifying an AP queue. AP instructions include a field containing the APQN to identify the AP queue to which the AP command is targetted.

* AP Instructions:

There are three AP instructions:

* NQAP: to enqueue an AP command-request message to a queue
* DQAP: to dequeue an AP command-reply message from a queue
* PQAP: to adminster the queues

Let's now see how AP instructions are interpreted by the hardware.

Start Interpretive Execution (SIE) Instruction
----------------------------------------------
A KVM guest is started by executing the Start Interpretive Execution (SIE) instruction. The SIE state description is a control block that contains the state information for a KVM guest and is supplied as input to the SIE instruction. The SIE state description contains a field that references a Crypto Control Block (CRYCB). The CRYCB contains three bitmask fields identifying the adapters, usage domains and control domains assigned to the KVM guest:

* The AP Mask (APM) field specifies the AP adapters assigned to the KVM guest. The APM controls which adapters are valid for the KVM guest. The bits in the mask, from left to right, correspond to APIDs 0 up to the number of adapters that can be assigned to the LPAR. If a bit is set, the corresponding adapter is valid for use by the KVM guest.

* The AP Queue Mask (AQM) field specifies the AP usage domains assigned to the KVM guest. The bits in the mask, from left to right, correspond to the usage domains, from 0 up to the number of domains that can be assigned to the LPAR. If a bit is set, the corresponding usage domain is valid for use by the KVM guest.

* The AP Domain Mask field specifies the AP control domains assigned to the KVM guest. The ADM bitmask controls which domains can be changed by an AP command-request message sent to a usage domain from the guest. The bits in the mask, from left to right, correspond to domain 0 up to the number of domains that can be assigned to the LPAR. If a bit is set, the corresponding domain can be modified by an AP command-request message sent to a usage domain configured for the KVM guest.

If you recall from the description of an AP Queue, AP instructions include an APQN to identify the AP adapter and the specific usage domain within the adapter to which an AP command-request message is to be sent (NQAP and PQAP instructions), or from which a command-reply message is to be received (DQAP instruction). The validity of an APQN is defined by the matrix calculated from the APM and AQM; it is the intersection of all assigned adapter numbers (APM) with all assigned usage domain numbers (AQM). For example, if adapters 1 and 2 and usage domains 5 and 6 are assigned to a guest, the APQNs (1,5), (1,6), (2,5) and (2,6) will be valid for the guest.

The APQNs provide secure key functionality - i.e., the key is stored on the adapter card - so when the adapter card is not virtualized - i.e., the adapter is accessed directly by the guest - each APQN must be assigned to at most one guest.

Example 1: Valid configuration:
------------------------------
Guest1: adapters 1,2 domains 5,6
Guest2: adapter 1,2 domain 7

This is valid because both guests have a unique set of APQNs: Guest1 has APQNs (1,5), (1,6), (2,5) and (2,6); Guest2 has APQN (1,7) and (2,7).

Example 2: Invalid configuration:
--------------------------------
Guest1: adapters 1,2 domains 5,6
Guest2: adapter 1 domains 6,7

This is an invalid configuration because both guests have access to APQNs (1,6).

Interruption architecture:

The AP interruption architecture may or may not generate interruptions to signal to the CPU the end of an AP transaction. The SIE interruption architecture, depending upon its configuration, may or may not redirect AP interrupts directly to a guest if the associated queue is valid for a guest, and may or may not report the interruption to the host.

Effective masking for guest level I and II:

A linux host running in the LPAR operates at guest-level 1 and has its own SIE state description. When operating at guest-level 1, the masks from the host's state description are used directly. A linux guest running in the host operates at guest-level 2. When operating at guest-level 2, the masks from the guest-level 1 (host) and guest-level 2 (guest) state descriptions are combined into a single description called an effective mask by performing a logical AND of the two state descriptions.

The effective mask algorithm is used for the APM, AQM and ADM to create an EAPM, EAQM and EADM respectively. Use of the EAPM, EAQM and EADM precludes a guest-level 1 host program from passing to a guest-level 2 program APQNs to which it does not have access.

Linux cryptographic bus driver:

Linux already has a cryptographic bus driver that provides one AP device per AP adapter and one device per AP queue. There is a device driver for each type of AP adapter device and each type of AP queue device. This design utilizes some of the interfaces and functionality provided by the AP bus driver.

Design Origin:
-------------

The original design was based on modelling AP Queue devices. The design utilized the VFIO mediated device framework whereby a mediated AP queue device would be created for each AP Queue bound to the VFIO AP Queue device driver. This at first seemed like the most logical design choice for the following reasons:

* Securing access to an AP Queue device by unbinding it from its default device driver and binding it to the VFIO device driver would not preclude the host from having access to the other usage domains contained within the same adapter card connected to the AP queue.

* An AP command is sent to a usage domain within a specific AP adapter via an AP queue.

It became readily apparent that modelling the design on an AP queue was very convoluted for a number of reasons:

* There is no convenient way to notify the VFIO device driver which guest will have access to a given mediated AP queue device until the mediated device's file descriptor is opened by the guest. Recall that the APQNs configured for the guest are an intersection of all of the bits set in both the APM and AQM, so the guest's APQNs can not be validated nor its SIE state description configured until all of the guest's mediated AP queue device file descriptors have been opened.

For example, suppose a guest opens file descriptors for mediated AP queue devices representing APQNs 3,5 and 4,6. If bits 3 and 4 are set in the guest's APM and bits 5 and 6 are set in the guest's AQM, then APQNs (3,5), (3,6), (4,5) and (4,6) will be valid for the guest, but mediated AP queue devices have been created only for APQNs (3,5) and (4,6). In this case, APQNs still assigned to the host would also be available to the guest which is a potential security breach.

* Control domains are not devices and are not logically modelled as mediated devices. In our original design, they were modelled as attributes of a mediated AP queue device, but this was a clumsy use of the VFIO mediated device model.

* The SIE state description models the assignment of AP resources as a matrix via the APM, AQM and ADM.

The design we ultimately settled upon was modelled on the AP matrix as defined by the SIE state description. Supplying the complete AP matrix to SIE using bitmasks when starting a guest simplifies the code, is far easier to secure, and more closely matches the model employed by SIE. This is the design model implemented via this patch set.

The Design
----------
This design introduces four new objects:

1. AP matrix bus

The sysfs location of the AP matrix bus is /sys/bus/ap_matrix. This bus will create a single AP matrix device (see below).

2. AP matrix device

The AP matrix device is a singleton that hangs off of the AP matrix bus. This device holds the AP Queues that have been reserved for use by KVM guests. The sysfs location of the AP matrix device is /sys/devices/ap_matrix/matrix. It is also linked from the AP matrix bus at /sys/bus/ap_matrix/devices/matrix.

3. VFIO AP matrix driver

This driver is based on the VFIO mediated device framework. When the driver is initialized, it will:

* Get the AP matrix device created by AP matrix bus from the bus

* Register with the AP bus to indicate that it can control AP Queue devices. This allows AP Queue devices unbound from AP device drivers to be bound to the VFIO AP matrix driver. The AP Queues bound to the VFIO AP matrix driver will be stored by the driver in the AP matrix device.

* Register the AP matrix device with the VFIO mediated device framework (MDEV). Registration with MDEV will create the sysfs structures needed to create mediated matrix devices. Each MDEV matrix device is used to configure the AP matrix for a KVM guest. The MDEV matrix device's file descriptor can be used by QEMU to communicate with the VFIO AP matrix device driver.

The VFIO AP matrix driver:

* Provides the interfaces the administrator can use to secure AP Queues for use by KVM guests. This is accomplished by unbinding the AP Queues needed by each KVM guest from its AP device driver and binding it to the VFIO AP queue driver. This prevents the host linux system from using these Queues.

* Provides an ioctl that can be used by QEMU to configure the CRYCB referenced by the KVM guest's SIE state description. The ioctl will

* Create an EAPM, EAQM and EADM by performing a logical AND of the APM, AQM and ADM configured via the MDEV matrix device's sysfs attributes files (see below) with the APM, AQM and ADM of the host's SIE state description respectively.

* Configure the SIE state description for the KVM guest using the effective masks created in the previous step.

4. VFIO MDEV matrix passthrough device

An MDEV matrix passthrough device must be created for each KVM guest that will need access to AP facilities. An MDEV matrix passthrough device is used by QEMU to configure the APM, AQM and ADM fields of the CRYCB referenced by the KVM guest's SIE state description. The file descriptor for the MDEV matrix passthrough device provides the communication pathway between QEMU and the VFIO AP matrix device driver.

The MDEV matrix passthrough device, like the CRYCB, contains three bitmasks - an APM, AQM and ADM - for specifying the AP matrix for the KVM guest. Three sets of attributes files will be provided to allow an administrator to set the bits in the MDEV matrix device's APM, AQM and ADM:

* A file to assign an AP adapter
* A file to unassign an AP adapter
* A file to display the adapters assigned

* A file to assign an AP domain
* A file to unassign an AP domain
* A file to display the domains assigned

* A file to assign an AP control domain
* A file to unassign an AP control domain
* A file to display the control domains assigned

Example:
-------
Let's now provide an example to illustrate how KVM guests may be given access to AP facilities. For this example, we will show how to configure two guests such that executing the lszcrypt command on the guests would look like this:

Guest1
------
CARD.DOMAIN TYPE MODE
------------------------------

05          CEX5C CCA-Coproc  
05.0004     CEX5C CCA-Coproc
05.00ab     CEX5C CCA-Coproc  
06          CEX5A Accelerator 
06.0004     CEX5A Accelerator 
06.00ab     CEX5C CCA-Coproc  

Guest2
------
CARD.DOMAIN TYPE MODE
------------------------------

05          CEX5A Accelerator 
05.0047     CEX5A Accelerator 
05.00ff     CEX5A Accelerator 

One thing to notice in this example is that each AP Queue set is identical. For example, the two AP Queue sets for Guest1 both contain APQI 0004 and 00ab. It would be an invalid condition if both queue sets did not contain the same set of queues. We could not, for example, configure Guest1 with access to AP queue 05.00ff because the AP queue set for adapter 06 does not contain AP queue 06.00ff. The point is, one must be careful to reserve a valid set of AP queues for a given guest.
a valid configuration.

These are the steps for configuring the Guest1 and Guest2:

1. The first thing that needs to be done is to secure the AP queues to be used by the two guests so that the host can not access them. This is done by unbinding each AP Queue device from its respective AP driver. In our example, these queues are bound to the cex4queue driver. This would be the sysfs location of these devices:

/sys/bus/ap
--- [drivers]
------ [cex4queue]
--------- [05.0004]
--------- [05.0047]
--------- [05.00ab]
--------- [05.00ff]
--------- [06.0004]
--------- [06.00ab]
--------- unbind

To unbind AP queue 05.0004 from the cex4queue device driver:

	echo 05.0004 > unbind

This must also be done for AP queues 05.00ab, 05.0047, 05.00ff, 06.0004, and 06.00ab.

2. The next step is to reserve the queues for use by the two KVM guests. This is accomplished by binding them to the VFIO AP matrix device driver. This is the sysfs location of the VFIO AP matrix device driver:

/sys/bus/ap
---[drivers]
------ [vfio_ap_matrix]
---------- bind

To bind queue 05.0004 to the vfio_ap_matrix driver:

	echo 05.0004 > bind

This must also be done for AP queues 05.00ab, 05.0047, 05.00ff, 06.0004, and 06.00ab.

3. Create the mediated devices needed to configure the AP matrices for the two guests and to provide an interface to the vfio_ap_matrix driver for use by the guests:

/sys/devices/
--- [ap_matrix]
------ [matrix] (this is the matrix device)
--------- [mdev_supported_types]
------------ [ap_matrix-passthrough] (passthrough mediated device type) --------------- create
--------------- [devices]

To create the mediated devices for the two guests:

uuidgen > create
uuidgen > create

This will create two mediated devices in the [devices] subdirectory named with the UUID written to the create attribute file. We call them $uuid1 and $uuid2:

/sys/devices/
--- [ap_matrix]
------ [matrix]
--------- [mdev_supported_types]
------------ [ap_matrix-passthrough]
--------------- [devices]
------------------ [$uuid1]
--------------------- adapters
--------------------- assign_adapter
--------------------- assign_control_domain
--------------------- assign_domain
--------------------- control_domains
--------------------- domains
--------------------- unassign_adapter
--------------------- unassign_control_domain
--------------------- unassign_domain
------------------ [$uuid2]
--------------------- adapters
--------------------- assign_adapter
--------------------- assign_control_domain
--------------------- assign_domain
--------------------- control_domains
--------------------- domains
--------------------- unassign_adapter
--------------------- unassign_control_domain
--------------------- unassign_domain

4. The administrator now needs to configure the matrices for mediated devices $uuid1 (for Guest1) and $uuid2 (for Guest2).

This is how the matrix is configured for Guest1:

echo 5 > assign_adapter
echo 6 > assign_adapter
echo 4 > assign_domain
echo ab > assign_domain

When the assign.xxx file is written, the corresponding bit in the respective MDEV matrix device's bitmask will be set. For example, when adapter 5 is assigned, bit 5 - numbered from left to right starting with bit 0 - will be set in the MDEV matrix device's APM.

By architectural convention, all usage domains - i.e., domains assigned via the assign_domain attribute file - will also be configured in the ADM field of the KVM guest's CRYCB, so there is no need to assign control domains here unless you want to assign control domains that are not assigned as usage domains.

If a mistake is made configuring an adapter, domain or control domain, you can use the unassign_xxx files to unassign the adapter, domain or control domain.

To display the matrix configuration for Guest1:

cat adapters
cat domains
cat control_domains

This is how the matrix is configured for Guest2:

echo 5 > assign_adapter
echo 47 > assign_domain
echo ff > assign_domain

When a KVM guest is started, QEMU will open the file descriptor for its MDEV matrix device. The VFIO AP matrix device driver will be notified and will store the reference to the KVM guest's SIE state description. QEMU will then call the VFIO AP matrix ioctl requesting that the KVM guest's matrix be configured. The matrix driver will set the bits in the APM, AQM and ADM fields of the CRYCB referenced by the guest's SIE state description from the EAPM, EAQM and EADM created by performing a logical AND of the AP masks configured in the MDEV matrix device and the masks configured in the host's SIE state description. When the guest comes up, it will have access to the APQNs identified in the AP matrix specified in the KVM guest's SIE state description. Programs running on the guest will then be able to use the cryptographic functions provided by the AP facilities configured for the guest.

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

 MAINTAINERS                                  |   13 +
 arch/s390/Kconfig                            |   13 +
 arch/s390/configs/default_defconfig          |    1 +
 arch/s390/configs/gcov_defconfig             |    1 +
 arch/s390/configs/performance_defconfig      |    1 +
 arch/s390/defconfig                          |    1 +
 arch/s390/include/asm/ap-config.h            |   32 +
 arch/s390/include/asm/kvm_host.h             |   26 +-
 arch/s390/kvm/Makefile                       |    2 +-
 arch/s390/kvm/ap-config.c                    |  224 ++++++++
 arch/s390/kvm/kvm-s390.c                     |   17 +-
 arch/s390/tools/gen_facilities.c             |    2 +
 drivers/s390/crypto/Makefile                 |    6 +-
 drivers/s390/crypto/ap_matrix_bus.c          |  115 ++++
 drivers/s390/crypto/ap_matrix_bus.h          |   25 +
 drivers/s390/crypto/vfio_ap_matrix_drv.c     |  107 ++++
 drivers/s390/crypto/vfio_ap_matrix_ops.c     |  790 ++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_matrix_private.h |   50 ++
 include/uapi/linux/vfio.h                    |   22 +
 19 files changed, 1438 insertions(+), 10 deletions(-)
 create mode 100644 arch/s390/include/asm/ap-config.h
 create mode 100644 arch/s390/kvm/ap-config.c
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.c
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.h
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_drv.c
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_ops.c
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_private.h
#1 lore raw

RFC 1/19 KVM: s390: SIE considerations for AP Queue virtualization

The Crypto Control Block (CRYCB) is referenced by the SIE state description and controls KVM guest access to the Adjunct Processor (AP) adapters, usage domains and control domains. This patch defines the AP control blocks to be used for controlling guest access to the AP adapters and domains.

---
 arch/s390/include/asm/kvm_host.h |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)
arch/s390/include/asm/kvm_host.h +21 -4
index 51375e7..50a6b25 100644
@@ -685,11 +685,28 @@ struct kvm_s390_crypto {
 	__u8 dea_kw;
 };
 
+#define APCB0_MASK_SIZE 1
+struct kvm_s390_apcb0 {
+	__u64 apm[APCB0_MASK_SIZE];		/* 0x0000 */
+	__u64 aqm[APCB0_MASK_SIZE];		/* 0x0008 */
+	__u64 adm[APCB0_MASK_SIZE];		/* 0x0010 */
+	__u64 reserved18;			/* 0x0018 */
+};
+
+#define APCB1_MASK_SIZE 4
+struct kvm_s390_apcb1 {
+	__u64 apm[APCB1_MASK_SIZE];		/* 0x0000 */
+	__u64 aqm[APCB1_MASK_SIZE];		/* 0x0020 */
+	__u64 adm[APCB1_MASK_SIZE];		/* 0x0040 */
+	__u64 reserved60[4];			/* 0x0060 */
+};
+
 struct kvm_s390_crypto_cb {
-	__u8    reserved00[72];                 /* 0x0000 */
-	__u8    dea_wrapping_key_mask[24];      /* 0x0048 */
-	__u8    aes_wrapping_key_mask[32];      /* 0x0060 */
-	__u8    reserved80[128];                /* 0x0080 */
+	struct kvm_s390_apcb0 apcb0;		/* 0x0000 */
+	__u8    reserved20[40];			/* 0x0020 */
+	__u8    dea_wrapping_key_mask[24];	/* 0x0048 */
+	__u8    aes_wrapping_key_mask[32];	/* 0x0060 */
+	struct kvm_s390_apcb1 apcb1;		/* 0x0080 */
 };
 
 /*
Signature · 1 line
1.7.1
#2 lore raw

Re: [RFC 01/19] KVM: s390: SIE considerations for AP Queue virtualization

To make the whole series smaller I will apply some of these patches directly (those of which are "obvious" and touch kvm/s390 only)

Quoted 7 lines · Tony Krowiak

The Crypto Control Block (CRYCB) is referenced by the SIE state description and controls KVM guest access to the Adjunct Processor (AP) adapters, usage domains and control domains. This patch defines the AP control blocks to be used for controlling guest access to the AP adapters and domains.

thanks applied.

Quoted 42 lines
---
 arch/s390/include/asm/kvm_host.h |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)
arch/s390/include/asm/kvm_host.h +21 -4
index 51375e7..50a6b25 100644
@@ -685,11 +685,28 @@ struct kvm_s390_crypto {
 	__u8 dea_kw;
 };
 
+#define APCB0_MASK_SIZE 1
+struct kvm_s390_apcb0 {
+	__u64 apm[APCB0_MASK_SIZE];		/* 0x0000 */
+	__u64 aqm[APCB0_MASK_SIZE];		/* 0x0008 */
+	__u64 adm[APCB0_MASK_SIZE];		/* 0x0010 */
+	__u64 reserved18;			/* 0x0018 */
+};
+
+#define APCB1_MASK_SIZE 4
+struct kvm_s390_apcb1 {
+	__u64 apm[APCB1_MASK_SIZE];		/* 0x0000 */
+	__u64 aqm[APCB1_MASK_SIZE];		/* 0x0020 */
+	__u64 adm[APCB1_MASK_SIZE];		/* 0x0040 */
+	__u64 reserved60[4];			/* 0x0060 */
+};
+
 struct kvm_s390_crypto_cb {
-	__u8    reserved00[72];                 /* 0x0000 */
-	__u8    dea_wrapping_key_mask[24];      /* 0x0048 */
-	__u8    aes_wrapping_key_mask[32];      /* 0x0060 */
-	__u8    reserved80[128];                /* 0x0080 */
+	struct kvm_s390_apcb0 apcb0;		/* 0x0000 */
+	__u8    reserved20[40];			/* 0x0020 */
+	__u8    dea_wrapping_key_mask[24];	/* 0x0048 */
+	__u8    aes_wrapping_key_mask[32];	/* 0x0060 */
+	struct kvm_s390_apcb1 apcb1;		/* 0x0080 */
 };
 
 /*
#3 lore raw

Re: [RFC 01/19] KVM: s390: SIE considerations for AP Queue virtualization

Quoted 2 lines · Christian Borntraeger

To make the whole series smaller I will apply some of these patches directly (those of which are "obvious" and touch kvm/s390 only)

Okay

Quoted 53 lines · Tony Krowiak
Quoted 7 lines

The Crypto Control Block (CRYCB) is referenced by the SIE state description and controls KVM guest access to the Adjunct Processor (AP) adapters, usage domains and control domains. This patch defines the AP control blocks to be used for controlling guest access to the AP adapters and domains.

thanks applied.

Quoted 42 lines
---
  arch/s390/include/asm/kvm_host.h |   25 +++++++++++++++++++++----
  1 files changed, 21 insertions(+), 4 deletions(-)
arch/s390/include/asm/kvm_host.h +21 -4
index 51375e7..50a6b25 100644
@@ -685,11 +685,28 @@ struct kvm_s390_crypto {
  	__u8 dea_kw;
  };
 
+#define APCB0_MASK_SIZE 1
+struct kvm_s390_apcb0 {
+	__u64 apm[APCB0_MASK_SIZE];		/* 0x0000 */
+	__u64 aqm[APCB0_MASK_SIZE];		/* 0x0008 */
+	__u64 adm[APCB0_MASK_SIZE];		/* 0x0010 */
+	__u64 reserved18;			/* 0x0018 */
+};
+
+#define APCB1_MASK_SIZE 4
+struct kvm_s390_apcb1 {
+	__u64 apm[APCB1_MASK_SIZE];		/* 0x0000 */
+	__u64 aqm[APCB1_MASK_SIZE];		/* 0x0020 */
+	__u64 adm[APCB1_MASK_SIZE];		/* 0x0040 */
+	__u64 reserved60[4];			/* 0x0060 */
+};
+
  struct kvm_s390_crypto_cb {
-	__u8    reserved00[72];                 /* 0x0000 */
-	__u8    dea_wrapping_key_mask[24];      /* 0x0048 */
-	__u8    aes_wrapping_key_mask[32];      /* 0x0060 */
-	__u8    reserved80[128];                /* 0x0080 */
+	struct kvm_s390_apcb0 apcb0;		/* 0x0000 */
+	__u8    reserved20[40];			/* 0x0020 */
+	__u8    dea_wrapping_key_mask[24];	/* 0x0048 */
+	__u8    aes_wrapping_key_mask[32];	/* 0x0060 */
+	struct kvm_s390_apcb1 apcb1;		/* 0x0080 */
  };
 
  /*
#4 lore raw

RFC 2/19 KVM: s390: refactor crypto initialization

In reply to Tony Krowiak

This patch introduces the following changes to crypto initialization.

* For key management operations support, the crypto control block (CRYCB) referenced by the KVM guest's SIE state description is formatted only if the Message-Security-Assist (MSA) extension 3 facility is installed (STFLE.76 is set). Virtualization of AP facilities, however; requires that a CRYCB of the appropriate format be made available to SIE regardless of the value of STFLE.76.

* The Execution Controls A (ECA) field bit 28 in the SIE block needs to be set to enable interpretive execution mode of adjunct processor (AP) instructions.

---
 arch/s390/include/asm/kvm_host.h |    1 +
 arch/s390/kvm/kvm-s390.c         |   17 +++++++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -0
index 50a6b25..5683f18 100644
@@ -188,6 +188,7 @@ struct kvm_s390_sie_block {
 #define ECA_MVPGI	0x01000000
 #define ECA_VX		0x00020000
 #define ECA_PROTEXCI	0x00002000
+#define ECA_AP		0x00000008
 #define ECA_SII		0x00000001
 	__u32	eca;			/* 0x004c */
 #define ICPT_INST	0x04
arch/s390/kvm/kvm-s390.c +13 -4
index 40d0a1a..e57fc9b 100644
@@ -1819,7 +1819,9 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
 {
 	kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb;
 
-	if (kvm_s390_apxa_installed())
+	if (!test_kvm_facility(kvm, 76))
+		kvm->arch.crypto.crycbd &= ~(CRYCB_FORMAT2); /* format 0 */
+	else if (kvm_s390_apxa_installed())
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
 	else
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
@@ -1836,12 +1838,12 @@ static u64 kvm_s390_get_initial_cpuid(void)
 
 static void kvm_s390_crypto_init(struct kvm *kvm)
 {
-	if (!test_kvm_facility(kvm, 76))
-		return;
-
 	kvm->arch.crypto.crycb = &kvm->arch.sie_page2->crycb;
 	kvm_s390_set_crycb_format(kvm);
 
+	if (!test_kvm_facility(kvm, 76))
+		return;
+
 	/* Enable AES/DEA protected key functions by default */
 	kvm->arch.crypto.aes_kw = 1;
 	kvm->arch.crypto.dea_kw = 1;
@@ -2366,8 +2368,15 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 	vcpu->arch.enabled_gmap = vcpu->arch.gmap;
 }
 
+static void kvm_s390_vcpu_set_crypto_exec_mode(struct kvm_vcpu *vcpu)
+{
+	vcpu->arch.sie_block->eca |= ECA_AP;
+}
+
 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
 {
+	kvm_s390_vcpu_set_crypto_exec_mode(vcpu);
+
 	if (!test_kvm_facility(vcpu->kvm, 76))
 		return;
 
Signature · 1 line
1.7.1
#5 lore raw

Re: [RFC 02/19] KVM: s390: refactor crypto initialization

Quoted 9 lines · Tony Krowiak

This patch introduces the following changes to crypto initialization.

* For key management operations support, the crypto control block (CRYCB) referenced by the KVM guest's SIE state description is formatted only if the Message-Security-Assist (MSA) extension 3 facility is installed (STFLE.76 is set). Virtualization of AP facilities, however; requires that a CRYCB of the appropriate format be made available to SIE regardless of the value of STFLE.76.

Quoted 3 lines

* The Execution Controls A (ECA) field bit 28 in the SIE block needs to be set to enable interpretive execution mode of adjunct processor (AP) instructions.

We should fence setting ECA to cases where we have virtualization capability for crypto. In addition we need to bind this somehow to the CPU model, so I guess we need to add some CRYPTO feature e.g. add KVM_S390_VM_CPU_FEAT_AP to the list of know features
(see arch/s390/include/uapi/asm/kvm.h)
---snip---

#define KVM_S390_VM_CPU_FEAT_ESOP       0
#define KVM_S390_VM_CPU_FEAT_SIEF2      1
#define KVM_S390_VM_CPU_FEAT_64BSCAO    2
#define KVM_S390_VM_CPU_FEAT_SIIF       3
#define KVM_S390_VM_CPU_FEAT_GPERE      4
#define KVM_S390_VM_CPU_FEAT_GSLS       5
#define KVM_S390_VM_CPU_FEAT_IB         6
#define KVM_S390_VM_CPU_FEAT_CEI        7
#define KVM_S390_VM_CPU_FEAT_IBS        8
#define KVM_S390_VM_CPU_FEAT_SKEY       9
#define KVM_S390_VM_CPU_FEAT_CMMA       10
#define KVM_S390_VM_CPU_FEAT_PFMFI      11
#define KVM_S390_VM_CPU_FEAT_SIGPIF     12
#define KVM_S390_VM_CPU_FEAT_KSS        13

---snip---

I will try to find out a way to properly detect that.

Quoted 66 lines
---
 arch/s390/include/asm/kvm_host.h |    1 +
 arch/s390/kvm/kvm-s390.c         |   17 +++++++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -0
index 50a6b25..5683f18 100644
@@ -188,6 +188,7 @@ struct kvm_s390_sie_block {
 #define ECA_MVPGI	0x01000000
 #define ECA_VX		0x00020000
 #define ECA_PROTEXCI	0x00002000
+#define ECA_AP		0x00000008
 #define ECA_SII		0x00000001
 	__u32	eca;			/* 0x004c */
 #define ICPT_INST	0x04
arch/s390/kvm/kvm-s390.c +13 -4
index 40d0a1a..e57fc9b 100644
@@ -1819,7 +1819,9 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
 {
 	kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb;
 
-	if (kvm_s390_apxa_installed())
+	if (!test_kvm_facility(kvm, 76))
+		kvm->arch.crypto.crycbd &= ~(CRYCB_FORMAT2); /* format 0 */
+	else if (kvm_s390_apxa_installed())
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
 	else
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
@@ -1836,12 +1838,12 @@ static u64 kvm_s390_get_initial_cpuid(void)
 
 static void kvm_s390_crypto_init(struct kvm *kvm)
 {
-	if (!test_kvm_facility(kvm, 76))
-		return;
-
 	kvm->arch.crypto.crycb = &kvm->arch.sie_page2->crycb;
 	kvm_s390_set_crycb_format(kvm);
 
+	if (!test_kvm_facility(kvm, 76))
+		return;
+
 	/* Enable AES/DEA protected key functions by default */
 	kvm->arch.crypto.aes_kw = 1;
 	kvm->arch.crypto.dea_kw = 1;
@@ -2366,8 +2368,15 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 	vcpu->arch.enabled_gmap = vcpu->arch.gmap;
 }
 
+static void kvm_s390_vcpu_set_crypto_exec_mode(struct kvm_vcpu *vcpu)
+{
+	vcpu->arch.sie_block->eca |= ECA_AP;
+}
+
 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
 {
+	kvm_s390_vcpu_set_crypto_exec_mode(vcpu);
+
 	if (!test_kvm_facility(vcpu->kvm, 76))
 		return;
 
#6 lore raw

Re: [RFC 02/19] KVM: s390: refactor crypto initialization

Quoted 34 lines · On Thu, 2 Nov 2017 13:41:18 +0100 Christian Borntraeger…
Quoted 9 lines · Tony Krowiak

This patch introduces the following changes to crypto initialization.

* For key management operations support, the crypto control block (CRYCB) referenced by the KVM guest's SIE state description is formatted only if the Message-Security-Assist (MSA) extension 3 facility is installed (STFLE.76 is set). Virtualization of AP facilities, however; requires that a CRYCB of the appropriate format be made available to SIE regardless of the value of STFLE.76.

Quoted 3 lines

* The Execution Controls A (ECA) field bit 28 in the SIE block needs to be set to enable interpretive execution mode of adjunct processor (AP) instructions.

We should fence setting ECA to cases where we have virtualization capability for crypto. In addition we need to bind this somehow to the CPU model, so I guess we need to add some CRYPTO feature e.g. add KVM_S390_VM_CPU_FEAT_AP to the list of know features
(see arch/s390/include/uapi/asm/kvm.h)
---snip---

#define KVM_S390_VM_CPU_FEAT_ESOP       0
#define KVM_S390_VM_CPU_FEAT_SIEF2      1
#define KVM_S390_VM_CPU_FEAT_64BSCAO    2
#define KVM_S390_VM_CPU_FEAT_SIIF       3
#define KVM_S390_VM_CPU_FEAT_GPERE      4
#define KVM_S390_VM_CPU_FEAT_GSLS       5
#define KVM_S390_VM_CPU_FEAT_IB         6
#define KVM_S390_VM_CPU_FEAT_CEI        7
#define KVM_S390_VM_CPU_FEAT_IBS        8
#define KVM_S390_VM_CPU_FEAT_SKEY       9
#define KVM_S390_VM_CPU_FEAT_CMMA       10
#define KVM_S390_VM_CPU_FEAT_PFMFI      11
#define KVM_S390_VM_CPU_FEAT_SIGPIF     12
#define KVM_S390_VM_CPU_FEAT_KSS        13
Quoted 1 line

---snip---

So, we need this so userspace can add the appropriate flags, right?

Quoted 3 lines

I will try to find out a way to properly detect that.

Did you manage to find out?

Quoted 70 lines
Quoted 69 lines
---
 arch/s390/include/asm/kvm_host.h |    1 +
 arch/s390/kvm/kvm-s390.c         |   17 +++++++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -0
index 50a6b25..5683f18 100644
@@ -188,6 +188,7 @@ struct kvm_s390_sie_block {
 #define ECA_MVPGI	0x01000000
 #define ECA_VX		0x00020000
 #define ECA_PROTEXCI	0x00002000
+#define ECA_AP		0x00000008
 #define ECA_SII		0x00000001
 	__u32	eca;			/* 0x004c */
 #define ICPT_INST	0x04
arch/s390/kvm/kvm-s390.c +13 -4
index 40d0a1a..e57fc9b 100644
@@ -1819,7 +1819,9 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
 {
 	kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb;
 
-	if (kvm_s390_apxa_installed())
+	if (!test_kvm_facility(kvm, 76))
+		kvm->arch.crypto.crycbd &= ~(CRYCB_FORMAT2); /* format 0 */
+	else if (kvm_s390_apxa_installed())
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
 	else
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
@@ -1836,12 +1838,12 @@ static u64 kvm_s390_get_initial_cpuid(void)
 
 static void kvm_s390_crypto_init(struct kvm *kvm)
 {
-	if (!test_kvm_facility(kvm, 76))
-		return;
-
 	kvm->arch.crypto.crycb = &kvm->arch.sie_page2->crycb;
 	kvm_s390_set_crycb_format(kvm);
 
+	if (!test_kvm_facility(kvm, 76))
+		return;
+
 	/* Enable AES/DEA protected key functions by default */
 	kvm->arch.crypto.aes_kw = 1;
 	kvm->arch.crypto.dea_kw = 1;
@@ -2366,8 +2368,15 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 	vcpu->arch.enabled_gmap = vcpu->arch.gmap;
 }
 
+static void kvm_s390_vcpu_set_crypto_exec_mode(struct kvm_vcpu *vcpu)
+{
+	vcpu->arch.sie_block->eca |= ECA_AP;
+}
+
 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
 {
+	kvm_s390_vcpu_set_crypto_exec_mode(vcpu);
+
 	if (!test_kvm_facility(vcpu->kvm, 76))
 		return;
 
#7 lore raw

Re: [RFC 02/19] KVM: s390: refactor crypto initialization

Quoted 37 lines · Cornelia Huck
Quoted 33 lines · On Thu, 2 Nov 2017 13:41:18 +0100 Christian Borntraeger…
Quoted 9 lines · Tony Krowiak

This patch introduces the following changes to crypto initialization.

* For key management operations support, the crypto control block (CRYCB) referenced by the KVM guest's SIE state description is formatted only if the Message-Security-Assist (MSA) extension 3 facility is installed (STFLE.76 is set). Virtualization of AP facilities, however; requires that a CRYCB of the appropriate format be made available to SIE regardless of the value of STFLE.76.

Quoted 3 lines

* The Execution Controls A (ECA) field bit 28 in the SIE block needs to be set to enable interpretive execution mode of adjunct processor (AP) instructions.

We should fence setting ECA to cases where we have virtualization capability for crypto. In addition we need to bind this somehow to the CPU model, so I guess we need to add some CRYPTO feature e.g. add KVM_S390_VM_CPU_FEAT_AP to the list of know features
(see arch/s390/include/uapi/asm/kvm.h)
---snip---

#define KVM_S390_VM_CPU_FEAT_ESOP       0
#define KVM_S390_VM_CPU_FEAT_SIEF2      1
#define KVM_S390_VM_CPU_FEAT_64BSCAO    2
#define KVM_S390_VM_CPU_FEAT_SIIF       3
#define KVM_S390_VM_CPU_FEAT_GPERE      4
#define KVM_S390_VM_CPU_FEAT_GSLS       5
#define KVM_S390_VM_CPU_FEAT_IB         6
#define KVM_S390_VM_CPU_FEAT_CEI        7
#define KVM_S390_VM_CPU_FEAT_IBS        8
#define KVM_S390_VM_CPU_FEAT_SKEY       9
#define KVM_S390_VM_CPU_FEAT_CMMA       10
#define KVM_S390_VM_CPU_FEAT_PFMFI      11
#define KVM_S390_VM_CPU_FEAT_SIGPIF     12
#define KVM_S390_VM_CPU_FEAT_KSS        13
Quoted 1 line

---snip---

Quoted 5 lines

So, we need this so userspace can add the appropriate flags, right?

Quoted 2 lines

I will try to find out a way to properly detect that.

Did you manage to find out

The AP bus (drivers/s390/crypto/ap_bus.c) calls ap_instructions_available() function in drivers/s390/crypto/ap_asm.c to determine whether AP instructions are installed. This function executes the PQAP(TAPQ) function and incorporates exception table to catch the operation exception if the AP instructions are not installed. I propose externalizing that function so it can be called from KVM.

Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
---
  arch/s390/include/asm/kvm_host.h |    1 +
  arch/s390/kvm/kvm-s390.c         |   17 +++++++++++++----
  2 files changed, 14 insertions(+), 4 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -0
index 50a6b25..5683f18 100644
@@ -188,6 +188,7 @@ struct kvm_s390_sie_block {
  #define ECA_MVPGI	0x01000000
  #define ECA_VX		0x00020000
  #define ECA_PROTEXCI	0x00002000
+#define ECA_AP		0x00000008
  #define ECA_SII		0x00000001
  	__u32	eca;			/* 0x004c */
  #define ICPT_INST	0x04
arch/s390/kvm/kvm-s390.c +13 -4
index 40d0a1a..e57fc9b 100644
@@ -1819,7 +1819,9 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
  {
  	kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb;
 
-	if (kvm_s390_apxa_installed())
+	if (!test_kvm_facility(kvm, 76))
+		kvm->arch.crypto.crycbd &= ~(CRYCB_FORMAT2); /* format 0 */
+	else if (kvm_s390_apxa_installed())
  		kvm->arch.crypto.crycbd |= CRYCB_FORMAT2;
  	else
  		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
@@ -1836,12 +1838,12 @@ static u64 kvm_s390_get_initial_cpuid(void)
 
  static void kvm_s390_crypto_init(struct kvm *kvm)
  {
-	if (!test_kvm_facility(kvm, 76))
-		return;
-
  	kvm->arch.crypto.crycb = &kvm->arch.sie_page2->crycb;
  	kvm_s390_set_crycb_format(kvm);
 
+	if (!test_kvm_facility(kvm, 76))
+		return;
+
  	/* Enable AES/DEA protected key functions by default */
  	kvm->arch.crypto.aes_kw = 1;
  	kvm->arch.crypto.dea_kw = 1;
@@ -2366,8 +2368,15 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
  	vcpu->arch.enabled_gmap = vcpu->arch.gmap;
  }
 
+static void kvm_s390_vcpu_set_crypto_exec_mode(struct kvm_vcpu *vcpu)
+{
+	vcpu->arch.sie_block->eca |= ECA_AP;
+}
+
  static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
  {
+	kvm_s390_vcpu_set_crypto_exec_mode(vcpu);
+
  	if (!test_kvm_facility(vcpu->kvm, 76))
  		return;
 
#8 lore raw

RFC 3/19 s390/zcrypt: new AP matrix bus

In reply to Tony Krowiak

Introduces an AP matrix bus. The sysfs location of the AP matrix bus is:

/sys/bus/ap_matrix

The AP matrix bus will create an AP matrix device that will hold the AP queues reserved for use by KVM guests.

---
 MAINTAINERS                         |    8 +++++
 drivers/s390/crypto/Makefile        |    4 +-
 drivers/s390/crypto/ap_matrix_bus.c |   52 +++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/ap_matrix_bus.h |   15 ++++++++++
 4 files changed, 77 insertions(+), 2 deletions(-)
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.c
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.h
MAINTAINERS +8 -0
index ef23cf5..cbd6f7c 100644
@@ -11711,6 +11711,14 @@ W:	http://www.ibm.com/developerworks/linux/linux390/
 S:	Supported
 F:	drivers/s390/crypto/
 
+S390 VFIO AP MATRIX DRIVER
+M:	Tony Krowiak <[email protected]>
+L:	[email protected]
+W:	http://www.ibm.com/developerworks/linux/linux390/
+S:	Supported
+F:	drivers/s390/crypto/ap_matrix_bus.h
+F:	drivers/s390/crypto/ap_matrix_bus.c
+
 S390 ZFCP DRIVER
 M:	Steffen Maier <[email protected]>
 M:	Benjamin Block <[email protected]>
drivers/s390/crypto/Makefile +2 -2
index be36f10..87646ca 100644
@@ -2,7 +2,7 @@
 # S/390 crypto devices
 #
 
-ap-objs := ap_bus.o ap_card.o ap_queue.o
+ap-objs := ap_bus.o ap_card.o ap_queue.o ap_matrix_bus.o
 obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
 # zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
 zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o
@@ -13,4 +13,4 @@ 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
+obj-$(CONFIG_PKEY) += pkey.o
\ No newline at end of file
drivers/s390/crypto/ap_matrix_bus.c new file +52 -0

52 lines not on this page · raw message

drivers/s390/crypto/ap_matrix_bus.h new file +15 -0
new file mode 100644
index 0000000..58e116f
@@ -0,0 +1,15 @@
+/*
+ * Adjunct processor matrix bus header file
+ *
+ * Copyright IBM Corp. 2017
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * Adjunct processor bus header file.
+ */
+
+#ifndef _AP_MATRIX_BUS_H_
+#define _AP_MATRIX_BUS_H_
+
+int ap_matrix_init(void);
+
+#endif /* _AP_MATRIX_BUS_H_ */
Signature · 1 line
1.7.1
#9 lore raw

Re: [RFC 03/19] s390/zcrypt: new AP matrix bus

Quoted 51 lines · On Fri, 13 Oct 2017 13:38:48 -0400 Tony Krowiak <[email protected]>…

Introduces an AP matrix bus. The sysfs location of the AP matrix bus is:

/sys/bus/ap_matrix

The AP matrix bus will create an AP matrix device that will hold the AP queues reserved for use by KVM guests.

---
 MAINTAINERS                         |    8 +++++
 drivers/s390/crypto/Makefile        |    4 +-
 drivers/s390/crypto/ap_matrix_bus.c |   52 +++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/ap_matrix_bus.h |   15 ++++++++++
 4 files changed, 77 insertions(+), 2 deletions(-)
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.c
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.h
MAINTAINERS +8 -0
index ef23cf5..cbd6f7c 100644
@@ -11711,6 +11711,14 @@ W:	http://www.ibm.com/developerworks/linux/linux390/
 S:	Supported
 F:	drivers/s390/crypto/
 
+S390 VFIO AP MATRIX DRIVER
+M:	Tony Krowiak <[email protected]>
+L:	[email protected]
+W:	http://www.ibm.com/developerworks/linux/linux390/
+S:	Supported
+F:	drivers/s390/crypto/ap_matrix_bus.h
+F:	drivers/s390/crypto/ap_matrix_bus.c
+
 S390 ZFCP DRIVER
 M:	Steffen Maier <[email protected]>
 M:	Benjamin Block <[email protected]>
drivers/s390/crypto/Makefile +1 -1
index be36f10..87646ca 100644
@@ -2,7 +2,7 @@
 # S/390 crypto devices
 #
 
-ap-objs := ap_bus.o ap_card.o ap_queue.o
+ap-objs := ap_bus.o ap_card.o ap_queue.o ap_matrix_bus.o
 obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
 # zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
 zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 6 lines
drivers/s390/crypto/Makefile +1 -1
@@ -13,4 +13,4 @@ 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
+obj-$(CONFIG_PKEY) += pkey.o
\ No newline at end of file

Try to avoid this newline hunk please. It is removed again with patch #5.

Quoted 69 lines
drivers/s390/crypto/ap_matrix_bus.c new file +52 -0
new file mode 100644
index 0000000..fbae175
@@ -0,0 +1,52 @@
+/*
+ * Copyright IBM Corp. 2017
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * Adjunct processor matrix bus.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <asm/ap.h>
+
+#include "ap_matrix_bus.h"
+
+MODULE_AUTHOR("Tony Krowiak <[email protected]");
+MODULE_DESCRIPTION("AP Matrix, Copyright IBM Corp. 2017");
+MODULE_LICENSE("GPL v2");
+
+#define AP_MATRIX_BUS_NAME "ap_matrix"
+
+static struct device *ap_matrix_root_device;
+
+static struct bus_type ap_matrix_bus_type = {
+	.name = AP_MATRIX_BUS_NAME,
+};
+
+int __init ap_matrix_init(void)
+{
+	int ret;
+
+	ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME);
+	ret = PTR_RET(ap_matrix_root_device);
+	if (ret)
+		goto done;
+
+	ret = bus_register(&ap_matrix_bus_type);
+	if (ret)
+		goto bus_reg_err;
+
+	return 0;
+
+bus_reg_err:
+	root_device_unregister(ap_matrix_root_device);
+
+done:
+	return ret;
+}
+device_initcall(ap_matrix_init);
drivers/s390/crypto/ap_matrix_bus.h new file +5 -0
new file mode 100644
index 0000000..58e116f
@@ -0,0 +1,15 @@
+/*
+ * Adjunct processor matrix bus header file
+ *
+ * Copyright IBM Corp. 2017
+ * Author(s): Tony Krowiak <[email protected]>

drivers/s390/crypto/ap_matrix_bus.h line 15

Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.h new file +10 -0
+ *
+ * Adjunct processor bus header file.
+ */
+
+#ifndef _AP_MATRIX_BUS_H_
+#define _AP_MATRIX_BUS_H_
+
+int ap_matrix_init(void);
+
+#endif /* _AP_MATRIX_BUS_H_ */

While I understand the approach to split the patches into meaningful parts, there is always a balance between too coarse and too fine granular.

I would merge patch #3, patch #4 and parts of patch #5 that affect ap_matrix_bus.c & ap_matrix_bus.h.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#10 lore raw

Re: [RFC 03/19] s390/zcrypt: new AP matrix bus

Quoted 55 lines · Martin Schwidefsky
Quoted 52 lines · On Fri, 13 Oct 2017 13:38:48 -0400 Tony Krowiak <[email protected]>…

Introduces an AP matrix bus. The sysfs location of the AP matrix bus is:

/sys/bus/ap_matrix

The AP matrix bus will create an AP matrix device that will hold the AP queues reserved for use by KVM guests.

---
  MAINTAINERS                         |    8 +++++
  drivers/s390/crypto/Makefile        |    4 +-
  drivers/s390/crypto/ap_matrix_bus.c |   52 +++++++++++++++++++++++++++++++++++
  drivers/s390/crypto/ap_matrix_bus.h |   15 ++++++++++
  4 files changed, 77 insertions(+), 2 deletions(-)

create mode 100644 drivers/s390/crypto/ap_matrix_bus.c create mode 100644 drivers/s390/crypto/ap_matrix_bus.h

MAINTAINERS +8 -0
index ef23cf5..cbd6f7c 100644
@@ -11711,6 +11711,14 @@ W:	http://www.ibm.com/developerworks/linux/linux390/
  S:	Supported
  F:	drivers/s390/crypto/
 
+S390 VFIO AP MATRIX DRIVER
+M:	Tony Krowiak <[email protected]>
+L:	[email protected]
+W:	http://www.ibm.com/developerworks/linux/linux390/
+S:	Supported
+F:	drivers/s390/crypto/ap_matrix_bus.h
+F:	drivers/s390/crypto/ap_matrix_bus.c
+
  S390 ZFCP DRIVER
  M:	Steffen Maier <[email protected]>
  M:	Benjamin Block <[email protected]>
drivers/s390/crypto/Makefile +1 -1
index be36f10..87646ca 100644
@@ -2,7 +2,7 @@
  # S/390 crypto devices
  #
 
-ap-objs := ap_bus.o ap_card.o ap_queue.o
+ap-objs := ap_bus.o ap_card.o ap_queue.o ap_matrix_bus.o
  obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
  # zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
  zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o
@@ -13,4 +13,4 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
 
Quoted 6 lines

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 5 lines
drivers/s390/crypto/Makefile +1 -1
  # pkey kernel module
  pkey-objs := pkey_api.o
-obj-$(CONFIG_PKEY) += pkey.o
+obj-$(CONFIG_PKEY) += pkey.o
\ No newline at end of file

Try to avoid this newline hunk please. It is removed again with patch #5.

Will do.

Quoted 83 lines
Quoted 70 lines
drivers/s390/crypto/ap_matrix_bus.c new file +52 -0
new file mode 100644
index 0000000..fbae175
@@ -0,0 +1,52 @@
+/*
+ * Copyright IBM Corp. 2017
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * Adjunct processor matrix bus.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <asm/ap.h>
+
+#include "ap_matrix_bus.h"
+
+MODULE_AUTHOR("Tony Krowiak <[email protected]");
+MODULE_DESCRIPTION("AP Matrix, Copyright IBM Corp. 2017");
+MODULE_LICENSE("GPL v2");
+
+#define AP_MATRIX_BUS_NAME "ap_matrix"
+
+static struct device *ap_matrix_root_device;
+
+static struct bus_type ap_matrix_bus_type = {
+	.name = AP_MATRIX_BUS_NAME,
+};
+
+int __init ap_matrix_init(void)
+{
+	int ret;
+
+	ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME);
+	ret = PTR_RET(ap_matrix_root_device);
+	if (ret)
+		goto done;
+
+	ret = bus_register(&ap_matrix_bus_type);
+	if (ret)
+		goto bus_reg_err;
+
+	return 0;
+
+bus_reg_err:
+	root_device_unregister(ap_matrix_root_device);
+
+done:
+	return ret;
+}
+device_initcall(ap_matrix_init);
drivers/s390/crypto/ap_matrix_bus.h new file +5 -0
new file mode 100644
index 0000000..58e116f
@@ -0,0 +1,15 @@
+/*
+ * Adjunct processor matrix bus header file
+ *
+ * Copyright IBM Corp. 2017
+ * Author(s): Tony Krowiak <[email protected]>

drivers/s390/crypto/ap_matrix_bus.h line 15

Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.h new file +10 -0
+ *
+ * Adjunct processor bus header file.
+ */
+
+#ifndef _AP_MATRIX_BUS_H_
+#define _AP_MATRIX_BUS_H_
+
+int ap_matrix_init(void);
+
+#endif /* _AP_MATRIX_BUS_H_ */

While I understand the approach to split the patches into meaningful parts, there is always a balance between too coarse and too fine granular.

Quoted 2 lines

I would merge patch #3, patch #4 and parts of patch #5 that affect ap_matrix_bus.c & ap_matrix_bus.h.

Will do.

Quoted 2 lines
#11 lore raw

Re: [RFC 03/19] s390/zcrypt: new AP matrix bus

In reply to Tony Krowiak
Quoted 33 lines · On Fri, 13 Oct 2017 13:38:48 -0400 Tony Krowiak <[email protected]>…

Introduces an AP matrix bus. The sysfs location of the AP matrix bus is:

/sys/bus/ap_matrix

The AP matrix bus will create an AP matrix device that will hold the AP queues reserved for use by KVM guests.

---
 MAINTAINERS                         |    8 +++++
 drivers/s390/crypto/Makefile        |    4 +-
 drivers/s390/crypto/ap_matrix_bus.c |   52 +++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/ap_matrix_bus.h |   15 ++++++++++
 4 files changed, 77 insertions(+), 2 deletions(-)
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.c
 create mode 100644 drivers/s390/crypto/ap_matrix_bus.h
drivers/s390/crypto/Makefile +1 -1
index be36f10..87646ca 100644
@@ -2,7 +2,7 @@
 # S/390 crypto devices
 #
 
-ap-objs := ap_bus.o ap_card.o ap_queue.o
+ap-objs := ap_bus.o ap_card.o ap_queue.o ap_matrix_bus.o
 obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
 # zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
 zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 5 lines
drivers/s390/crypto/Makefile +1 -1
@@ -13,4 +13,4 @@ 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
+obj-$(CONFIG_PKEY) += pkey.o

Unrelated change.

Quoted 1 line

\ No newline at end of file

#12 lore raw

Re: [RFC 03/19] s390/zcrypt: new AP matrix bus

Quoted 36 lines · Cornelia Huck
Quoted 33 lines · On Fri, 13 Oct 2017 13:38:48 -0400 Tony Krowiak <[email protected]>…

Introduces an AP matrix bus. The sysfs location of the AP matrix bus is:

/sys/bus/ap_matrix

The AP matrix bus will create an AP matrix device that will hold the AP queues reserved for use by KVM guests.

---
  MAINTAINERS                         |    8 +++++
  drivers/s390/crypto/Makefile        |    4 +-
  drivers/s390/crypto/ap_matrix_bus.c |   52 +++++++++++++++++++++++++++++++++++
  drivers/s390/crypto/ap_matrix_bus.h |   15 ++++++++++
  4 files changed, 77 insertions(+), 2 deletions(-)

create mode 100644 drivers/s390/crypto/ap_matrix_bus.c create mode 100644 drivers/s390/crypto/ap_matrix_bus.h

drivers/s390/crypto/Makefile +1 -1
index be36f10..87646ca 100644
@@ -2,7 +2,7 @@
  # S/390 crypto devices
  #
 
-ap-objs := ap_bus.o ap_card.o ap_queue.o
+ap-objs := ap_bus.o ap_card.o ap_queue.o ap_matrix_bus.o
  obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
  # zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
  zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o
@@ -13,4 +13,4 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
 
Quoted 5 lines

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 4 lines
drivers/s390/crypto/Makefile +1 -1
  # pkey kernel module
  pkey-objs := pkey_api.o
-obj-$(CONFIG_PKEY) += pkey.o
+obj-$(CONFIG_PKEY) += pkey.o

Unrelated change.

Will fix

Quoted 2 lines
Quoted 2 lines

\ No newline at end of file

#13 lore raw

Re: [RFC 03/19] s390/zcrypt: new AP matrix bus

In reply to Cornelia Huck
Quoted 36 lines · Cornelia Huck
Quoted 33 lines · On Fri, 13 Oct 2017 13:38:48 -0400 Tony Krowiak <[email protected]>…

Introduces an AP matrix bus. The sysfs location of the AP matrix bus is:

/sys/bus/ap_matrix

The AP matrix bus will create an AP matrix device that will hold the AP queues reserved for use by KVM guests.

---
  MAINTAINERS                         |    8 +++++
  drivers/s390/crypto/Makefile        |    4 +-
  drivers/s390/crypto/ap_matrix_bus.c |   52 +++++++++++++++++++++++++++++++++++
  drivers/s390/crypto/ap_matrix_bus.h |   15 ++++++++++
  4 files changed, 77 insertions(+), 2 deletions(-)

create mode 100644 drivers/s390/crypto/ap_matrix_bus.c create mode 100644 drivers/s390/crypto/ap_matrix_bus.h

drivers/s390/crypto/Makefile +1 -1
index be36f10..87646ca 100644
@@ -2,7 +2,7 @@
  # S/390 crypto devices
  #
 
-ap-objs := ap_bus.o ap_card.o ap_queue.o
+ap-objs := ap_bus.o ap_card.o ap_queue.o ap_matrix_bus.o
  obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
  # zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
  zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o
@@ -13,4 +13,4 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
 
Quoted 5 lines

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 4 lines
drivers/s390/crypto/Makefile +1 -1
  # pkey kernel module
  pkey-objs := pkey_api.o
-obj-$(CONFIG_PKEY) += pkey.o
+obj-$(CONFIG_PKEY) += pkey.o

Unrelated change.

will fix

Quoted 2 lines
Quoted 2 lines

\ No newline at end of file

#14 lore raw

Re: [RFC 03/19] s390/zcrypt: new AP matrix bus

In reply to Cornelia Huck
Quoted 36 lines · Cornelia Huck
Quoted 33 lines · On Fri, 13 Oct 2017 13:38:48 -0400 Tony Krowiak <[email protected]>…

Introduces an AP matrix bus. The sysfs location of the AP matrix bus is:

/sys/bus/ap_matrix

The AP matrix bus will create an AP matrix device that will hold the AP queues reserved for use by KVM guests.

---
  MAINTAINERS                         |    8 +++++
  drivers/s390/crypto/Makefile        |    4 +-
  drivers/s390/crypto/ap_matrix_bus.c |   52 +++++++++++++++++++++++++++++++++++
  drivers/s390/crypto/ap_matrix_bus.h |   15 ++++++++++
  4 files changed, 77 insertions(+), 2 deletions(-)

create mode 100644 drivers/s390/crypto/ap_matrix_bus.c create mode 100644 drivers/s390/crypto/ap_matrix_bus.h

drivers/s390/crypto/Makefile +1 -1
index be36f10..87646ca 100644
@@ -2,7 +2,7 @@
  # S/390 crypto devices
  #
 
-ap-objs := ap_bus.o ap_card.o ap_queue.o
+ap-objs := ap_bus.o ap_card.o ap_queue.o ap_matrix_bus.o
  obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
  # zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
  zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o
@@ -13,4 +13,4 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
 
Quoted 7 lines

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 4 lines
drivers/s390/crypto/Makefile +1 -1
  # pkey kernel module
  pkey-objs := pkey_api.o
-obj-$(CONFIG_PKEY) += pkey.o
+obj-$(CONFIG_PKEY) += pkey.o

Unrelated change.

Quoted 1 line

\ No newline at end of file

I will fix this

#15 lore raw

RFC 4/19 s390/zcrypt: create an AP matrix device on the AP matrix bus

In reply to Tony Krowiak

Creates a single AP matrix device on the AP matrix bus. The matrix device will be created as part of the AP matrix bus initialization. The matrix device will hold the AP queues that have been reserved for use by KVM guests. Mediated matrix devices can then be created for each guest. The mediated matrix devices can then be configured with a matrix of AP adapters, usage and control domains that will be made accessible to the guest.

The sysfs location of the matrix device is:

/sys/bus/ap_matrix
... [devices]
...... [matrix]

---
 drivers/s390/crypto/ap_matrix_bus.c |   54 +++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/ap_matrix_bus.h |    6 ++++
 2 files changed, 60 insertions(+), 0 deletions(-)
drivers/s390/crypto/ap_matrix_bus.c +54 -0
index fbae175..4eb1e3c 100644
@@ -12,6 +12,7 @@
 
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/slab.h>
 #include <asm/ap.h>
 
 #include "ap_matrix_bus.h"
@@ -21,13 +22,59 @@
 MODULE_LICENSE("GPL v2");
 
 #define AP_MATRIX_BUS_NAME "ap_matrix"
+#define AP_MATRIX_DEV_TYPE_NAME "ap_matrix"
+#define AP_MATRIX_DEV_NAME "matrix"
 
 static struct device *ap_matrix_root_device;
+static struct ap_matrix *matrix;
 
 static struct bus_type ap_matrix_bus_type = {
 	.name = AP_MATRIX_BUS_NAME,
 };
 
+static struct device_type ap_matrix_type = {
+	.name = AP_MATRIX_DEV_TYPE_NAME,
+};
+
+static void ap_matrix_dev_release(struct device *dev)
+{
+	struct ap_matrix *ap_matrix;
+
+	ap_matrix = container_of(dev, struct ap_matrix, device);
+
+	if (matrix == ap_matrix)
+		kfree(matrix);
+
+	matrix = NULL;
+}
+
+static int ap_matrix_dev_create(void)
+{
+	int ret;
+
+	matrix = kzalloc(sizeof(*matrix), GFP_KERNEL);
+	if (!matrix)
+		return -ENOMEM;
+
+	matrix->device.type = &ap_matrix_type;
+	dev_set_name(&matrix->device, "%s", AP_MATRIX_DEV_NAME);
+	matrix->device.bus = &ap_matrix_bus_type;
+	matrix->device.parent = ap_matrix_root_device;
+	matrix->device.release = ap_matrix_dev_release;
+
+	ret = device_register(&matrix->device);
+	if (ret) {
+		put_device(&matrix->device);
+		kfree(matrix);
+		matrix = NULL;
+		return ret;
+	}
+
+	get_device(&matrix->device);
+
+	return 0;
+}
+
 int __init ap_matrix_init(void)
 {
 	int ret;
@@ -41,8 +88,15 @@ int __init ap_matrix_init(void)
 	if (ret)
 		goto bus_reg_err;
 
+	ret = ap_matrix_dev_create();
+	if (ret)
+		goto matrix_create_err;
+
 	return 0;
 
+matrix_create_err:
+	bus_unregister(&ap_matrix_bus_type);
+
 bus_reg_err:
 	root_device_unregister(ap_matrix_root_device);
 
drivers/s390/crypto/ap_matrix_bus.h +6 -0
index 58e116f..225db4f 100644
@@ -10,6 +10,12 @@
 #ifndef _AP_MATRIX_BUS_H_
 #define _AP_MATRIX_BUS_H_
 
+#include <linux/device.h>
+
+struct ap_matrix {
+	struct device device;
+};
+
 int ap_matrix_init(void);
 
 #endif /* _AP_MATRIX_BUS_H_ */
Signature · 1 line
1.7.1
#16 lore raw

Re: [RFC 04/19] s390/zcrypt: create an AP matrix device on the AP matrix bus

On Fri, 13 Oct 2017 13:38:49 -0400
Tony Krowiak <[email protected]> wrote:

[Please take with a grain of salt as I did not yet have time to take more than a very superficial glance at the whole structure.]

Quoted 8 lines

Creates a single AP matrix device on the AP matrix bus. The matrix device will be created as part of the AP matrix bus initialization. The matrix device will hold the AP queues that have been reserved for use by KVM guests. Mediated matrix devices can then be created for each guest. The mediated matrix devices can then be configured with a matrix of AP adapters, usage and control domains that will be made accessible to the guest.

Quoted 5 lines

The sysfs location of the matrix device is:

/sys/bus/ap_matrix
... [devices]
...... [matrix]

Also /sys/devices/ap_matrix/matrix, isn't it?

Quoted 37 lines
---
 drivers/s390/crypto/ap_matrix_bus.c |   54 +++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/ap_matrix_bus.h |    6 ++++
 2 files changed, 60 insertions(+), 0 deletions(-)
drivers/s390/crypto/ap_matrix_bus.c +8 -0
index fbae175..4eb1e3c 100644
@@ -12,6 +12,7 @@
 
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/slab.h>
 #include <asm/ap.h>
 
 #include "ap_matrix_bus.h"
@@ -21,13 +22,59 @@
 MODULE_LICENSE("GPL v2");
 
 #define AP_MATRIX_BUS_NAME "ap_matrix"
+#define AP_MATRIX_DEV_TYPE_NAME "ap_matrix"
+#define AP_MATRIX_DEV_NAME "matrix"
 
 static struct device *ap_matrix_root_device;
+static struct ap_matrix *matrix;
 
 static struct bus_type ap_matrix_bus_type = {
 	.name = AP_MATRIX_BUS_NAME,
 };
 
+static struct device_type ap_matrix_type = {
+	.name = AP_MATRIX_DEV_TYPE_NAME,
+};
+

drivers/s390/crypto/ap_matrix_bus.c line 48

Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.c +10 -0
+static void ap_matrix_dev_release(struct device *dev)
+{
+	struct ap_matrix *ap_matrix;
+
+	ap_matrix = container_of(dev, struct ap_matrix, device);
+
+	if (matrix == ap_matrix)
+		kfree(matrix);
+
+	matrix = NULL;

This looks very, very odd. Refcounting should take care that the release function is only invoked if the device is really gone.

Also, I don't think you need to keep a pointer to the device as it is a
singleton: It's simply the only device on the list and you should be able to easily pick it that way. If your code does not register further devices on the bus, there won't be ambiguities.

Quoted 11 lines
drivers/s390/crypto/ap_matrix_bus.c +11 -0
+}
+
+static int ap_matrix_dev_create(void)
+{
+	int ret;
+
+	matrix = kzalloc(sizeof(*matrix), GFP_KERNEL);
+	if (!matrix)
+		return -ENOMEM;
+
+	matrix->device.type = &ap_matrix_type;

drivers/s390/crypto/ap_matrix_bus.c line 69

Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.c +10 -0
+	dev_set_name(&matrix->device, "%s", AP_MATRIX_DEV_NAME);
+	matrix->device.bus = &ap_matrix_bus_type;
+	matrix->device.parent = ap_matrix_root_device;
+	matrix->device.release = ap_matrix_dev_release;
+
+	ret = device_register(&matrix->device);
+	if (ret) {
+		put_device(&matrix->device);
+		kfree(matrix);
+		matrix = NULL;

That's wrong. The release function needs to clean up the embedding structure, so that kfree is at best useless and at worst wrong, if something else grabbed a reference.

drivers/s390/crypto/ap_matrix_bus.c line 73

Quoted 4 lines
drivers/s390/crypto/ap_matrix_bus.c +4 -0
+		return ret;
+	}
+
+	get_device(&matrix->device);

Why should you need an extra reference here? I'd expect the code hanging devices off this one to properly grab a reference, so you should be all good?

Quoted 22 lines
drivers/s390/crypto/ap_matrix_bus.c +11 -0
+
+	return 0;
+}
+
 int __init ap_matrix_init(void)
 {
 	int ret;
@@ -41,8 +88,15 @@ int __init ap_matrix_init(void)
 	if (ret)
 		goto bus_reg_err;
 
+	ret = ap_matrix_dev_create();
+	if (ret)
+		goto matrix_create_err;
+
 	return 0;
 
+matrix_create_err:
+	bus_unregister(&ap_matrix_bus_type);
+
 bus_reg_err:
 	root_device_unregister(ap_matrix_root_device);
#17 lore raw

Re: [RFC 04/19] s390/zcrypt: create an AP matrix device on the AP matrix bus

Quoted 14 lines · Cornelia Huck

On Fri, 13 Oct 2017 13:38:49 -0400
Tony Krowiak <[email protected]> wrote:

[Please take with a grain of salt as I did not yet have time to take more than a very superficial glance at the whole structure.]

Quoted 8 lines

Creates a single AP matrix device on the AP matrix bus. The matrix device will be created as part of the AP matrix bus initialization. The matrix device will hold the AP queues that have been reserved for use by KVM guests. Mediated matrix devices can then be created for each guest. The mediated matrix devices can then be configured with a matrix of AP adapters, usage and control domains that will be made accessible to the guest.

Quoted 6 lines
Quoted 5 lines

The sysfs location of the matrix device is:

/sys/bus/ap_matrix
... [devices]
...... [matrix]

Also /sys/devices/ap_matrix/matrix, isn't it?

Yes

Quoted 50 lines
Quoted 37 lines
---
  drivers/s390/crypto/ap_matrix_bus.c |   54 +++++++++++++++++++++++++++++++++++
  drivers/s390/crypto/ap_matrix_bus.h |    6 ++++
  2 files changed, 60 insertions(+), 0 deletions(-)
drivers/s390/crypto/ap_matrix_bus.c +8 -0
index fbae175..4eb1e3c 100644
@@ -12,6 +12,7 @@
 
  #include <linux/module.h>
  #include <linux/device.h>
+#include <linux/slab.h>
  #include <asm/ap.h>
 
  #include "ap_matrix_bus.h"
@@ -21,13 +22,59 @@
  MODULE_LICENSE("GPL v2");
 
  #define AP_MATRIX_BUS_NAME "ap_matrix"
+#define AP_MATRIX_DEV_TYPE_NAME "ap_matrix"
+#define AP_MATRIX_DEV_NAME "matrix"
 
  static struct device *ap_matrix_root_device;
+static struct ap_matrix *matrix;
 
  static struct bus_type ap_matrix_bus_type = {
  	.name = AP_MATRIX_BUS_NAME,
  };
 
+static struct device_type ap_matrix_type = {
+	.name = AP_MATRIX_DEV_TYPE_NAME,
+};
+

drivers/s390/crypto/ap_matrix_bus.c line 48

Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.c +10 -0
+static void ap_matrix_dev_release(struct device *dev)
+{
+	struct ap_matrix *ap_matrix;
+
+	ap_matrix = container_of(dev, struct ap_matrix, device);
+
+	if (matrix == ap_matrix)
+		kfree(matrix);
+
+	matrix = NULL;

This looks very, very odd. Refcounting should take care that the release function is only invoked if the device is really gone.

Quoted 4 lines

Also, I don't think you need to keep a pointer to the device as it is a
singleton: It's simply the only device on the list and you should be able to easily pick it that way. If your code does not register further devices on the bus, there won't be ambiguities.

Okay, I'll make that change

Quoted 17 lines
Quoted 17 lines
drivers/s390/crypto/ap_matrix_bus.c +16 -0
+}
+
+static int ap_matrix_dev_create(void)
+{
+	int ret;
+
+	matrix = kzalloc(sizeof(*matrix), GFP_KERNEL);
+	if (!matrix)
+		return -ENOMEM;
+
+	matrix->device.type = &ap_matrix_type;
+	dev_set_name(&matrix->device, "%s", AP_MATRIX_DEV_NAME);
+	matrix->device.bus = &ap_matrix_bus_type;
+	matrix->device.parent = ap_matrix_root_device;
+	matrix->device.release = ap_matrix_dev_release;
+
Quoted 8 lines

drivers/s390/crypto/ap_matrix_bus.c line 69

Quoted 5 lines
drivers/s390/crypto/ap_matrix_bus.c +5 -0
+	ret = device_register(&matrix->device);
+	if (ret) {
+		put_device(&matrix->device);
+		kfree(matrix);
+		matrix = NULL;

That's wrong. The release function needs to clean up the embedding structure, so that kfree is at best useless and at worst wrong, if something else grabbed a reference.

Good point.

Quoted 8 lines

drivers/s390/crypto/ap_matrix_bus.c line 73

Quoted 5 lines
drivers/s390/crypto/ap_matrix_bus.c +4 -0
+		return ret;
+	}
+
+	get_device(&matrix->device);

Why should you need an extra reference here? I'd expect the code hanging devices off this one to properly grab a reference, so you should be all good?

I'll remove this.

Quoted 23 lines
Quoted 23 lines
drivers/s390/crypto/ap_matrix_bus.c +11 -0
+
+	return 0;
+}
+
  int __init ap_matrix_init(void)
  {
  	int ret;
@@ -41,8 +88,15 @@ int __init ap_matrix_init(void)
  	if (ret)
  		goto bus_reg_err;
 
+	ret = ap_matrix_dev_create();
+	if (ret)
+		goto matrix_create_err;
+
  	return 0;
 
+matrix_create_err:
+	bus_unregister(&ap_matrix_bus_type);
+
  bus_reg_err:
  	root_device_unregister(ap_matrix_root_device);
#18 lore raw

RFC 5/19 s390/zcrypt: base implementation of AP matrix device driver

In reply to Tony Krowiak

Introduces a new AP matrix device driver. This device driver will ultimately perform the following functions:

* Register with the AP bus to let it know that the matrix driver can control AP queue devices. This will allow an administrator to unbind an AP queue device from its device driver and bind it to the matrix device driver. This is how AP queue devices will be reserved for use by guest machines.

* Register the matrix device created by the AP matrix bus with the VFIO mediated device framework. This will create the sysfs entries needed to create mediated matrix devices. Each mediated matrix device can be configured with a matrix of adapters, usage domains and control domains that can be accessed by a guest machine.

* Process requests via ioctl calls defined for the mediated matrix device. The guest can access the ioctl calls via the mediated device's file descriptor to:

* Grant access to the adapters, usage domains and control domains configured for the mediated matrix device.

This device driver
is built on the VFIO mediated device framework. The VFIO mediated device framework allows a mediated device to be dedicated exclusively to a single guest VM.

---
 MAINTAINERS                                  |    2 +
 arch/s390/Kconfig                            |   13 +++
 arch/s390/configs/default_defconfig          |    1 +
 arch/s390/configs/gcov_defconfig             |    1 +
 arch/s390/configs/performance_defconfig      |    1 +
 arch/s390/defconfig                          |    1 +
 drivers/s390/crypto/Makefile                 |    6 +-
 drivers/s390/crypto/ap_matrix_bus.c          |    8 ++
 drivers/s390/crypto/ap_matrix_bus.h          |    2 +-
 drivers/s390/crypto/vfio_ap_matrix_drv.c     |  102 ++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_matrix_private.h |   47 ++++++++++++
 11 files changed, 182 insertions(+), 2 deletions(-)
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_drv.c
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_private.h
MAINTAINERS +2 -0
index cbd6f7c..115965e 100644
@@ -11718,6 +11718,8 @@ W:	http://www.ibm.com/developerworks/linux/linux390/
 S:	Supported
 F:	drivers/s390/crypto/ap_matrix_bus.h
 F:	drivers/s390/crypto/ap_matrix_bus.c
+F:	drivers/s390/crypto/vfio_ap_matrix_drv.c
+F:	drivers/s390/crypto/vfio_ap_matrix_private.h
 
 S390 ZFCP DRIVER
 M:	Steffen Maier <[email protected]>
arch/s390/Kconfig +13 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW
 	  To compile this driver as a module, choose M here: the
 	  module will be called vfio_ccw.
 
+config VFIO_AP_MATRIX
+	def_tristate m
+	prompt "Support for Adjunct Processor Matrix device interface"
+	depends on ZCRYPT
+	select VFIO
+	select MDEV
+	select VFIO_MDEV
+	select VFIO_MDEV_DEVICE
+	select IOMMU_API
+	help
+		driver grants access to Adjunct Processor (AP) devices
+		via the VFIO mediated device interface.
+
 endmenu
 
 menu "Dump support"
arch/s390/configs/default_defconfig +1 -0
index 2820722..d913042 100644
@@ -725,3 +725,4 @@ CONFIG_APPLDATA_BASE=y
 CONFIG_KVM=m
 CONFIG_KVM_S390_UCONTROL=y
 CONFIG_VHOST_NET=m
+CONFIG_VFIO_AP_MATRIX=m
arch/s390/configs/gcov_defconfig +1 -0
index 3c6b781..5f08278 100644
@@ -666,3 +666,4 @@ CONFIG_APPLDATA_BASE=y
 CONFIG_KVM=m
 CONFIG_KVM_S390_UCONTROL=y
 CONFIG_VHOST_NET=m
+CONFIG_VFIO_AP_MATRIX=m
arch/s390/configs/performance_defconfig +1 -0
index 653d72b..4b77519 100644
@@ -664,3 +664,4 @@ CONFIG_APPLDATA_BASE=y
 CONFIG_KVM=m
 CONFIG_KVM_S390_UCONTROL=y
 CONFIG_VHOST_NET=m
+CONFIG_VFIO_AP_MATRIX=m
arch/s390/defconfig +1 -0
index 20244a3..aa46cb5 100644
@@ -242,3 +242,4 @@ CONFIG_CRC7=m
 # CONFIG_XZ_DEC_ARMTHUMB is not set
 # CONFIG_XZ_DEC_SPARC is not set
 CONFIG_CMM=m
+CONFIG_VFIO_AP_MATRIX=m
drivers/s390/crypto/Makefile +5 -1
index 87646ca..1983afa 100644
@@ -13,4 +13,8 @@ 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
\ No newline at end of file
+obj-$(CONFIG_PKEY) += pkey.o
+
+# adjunct processor matrix
+vfio_ap_matrix-objs := vfio_ap_matrix_drv.o
+obj-$(CONFIG_VFIO_AP_MATRIX) += vfio_ap_matrix.o
drivers/s390/crypto/ap_matrix_bus.c +8 -0
index 4eb1e3c..66bfa54 100644
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
 	return 0;
 }
 
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;
+}
+EXPORT_SYMBOL(ap_matrix_get_device);
+
 int __init ap_matrix_init(void)
 {
 	int ret;
 
+	matrix = NULL;
+
 	ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME);
 	ret = PTR_RET(ap_matrix_root_device);
 	if (ret)
drivers/s390/crypto/ap_matrix_bus.h +1 -1
index 225db4f..c2aff23 100644
@@ -16,6 +16,6 @@ struct ap_matrix {
 	struct device device;
 };
 
-int ap_matrix_init(void);
+struct ap_matrix *ap_matrix_get_device(void);
 
 #endif /* _AP_MATRIX_BUS_H_ */
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +102 -0

102 lines not on this page · raw message

drivers/s390/crypto/vfio_ap_matrix_private.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.1
#19 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 5 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
drivers/s390/crypto/Makefile +0 -0
index 87646ca..1983afa 100644

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 20

Quoted 10 lines
drivers/s390/crypto/Makefile +5 -1
@@ -13,4 +13,8 @@ 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
\ No newline at end of file
+obj-$(CONFIG_PKEY) += pkey.o
+
+# adjunct processor matrix
+vfio_ap_matrix-objs := vfio_ap_matrix_drv.o
+obj-$(CONFIG_VFIO_AP_MATRIX) += vfio_ap_matrix.o

With the fix to patch #3 the newline quirk will be gone.

Quoted 13 lines
drivers/s390/crypto/ap_matrix_bus.c +5 -0
index 4eb1e3c..66bfa54 100644
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
 	return 0;
 }
 
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;
+}
+EXPORT_SYMBOL(ap_matrix_get_device);

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 92

Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.c +3 -0
+
 int __init ap_matrix_init(void)
 {
 	int ret;
 
+	matrix = NULL;
+
 	ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME);
 	ret = PTR_RET(ap_matrix_root_device);
 	if (ret)

The global variable "matrix" is already NULL at the time ap_matrix_init is called. No need to set it again. And I would appreciate if the global variable would be named "ap_matrix".

Quoted 81 lines
drivers/s390/crypto/ap_matrix_bus.h +1 -1
index 225db4f..c2aff23 100644
@@ -16,6 +16,6 @@ struct ap_matrix {
 	struct device device;
 };
 
-int ap_matrix_init(void);
+struct ap_matrix *ap_matrix_get_device(void);
 
 #endif /* _AP_MATRIX_BUS_H_ */
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +63 -0
new file mode 100644
index 0000000..760ed56
@@ -0,0 +1,102 @@
+/*
+ * VFIO based AP Matrix device driver
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/slab.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+#include "vfio_ap_matrix_private.h"
+
+#define VFIO_AP_MATRIX_DRV_NAME "vfio_ap_queue"
+
+MODULE_AUTHOR("IBM Corporation");
+MODULE_DESCRIPTION("AP Matrix device driver, Copyright IBM Corp. 2017");
+MODULE_LICENSE("GPL v2");
+
+static struct ap_device_id ap_queue_ids[] = {
+	{ .dev_type = AP_DEVICE_TYPE_CEX4,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX5,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX6,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ /* end of list */ },
+};
+
+MODULE_DEVICE_TABLE(ap_matrix, ap_queue_ids);
+
+static struct ap_matrix_driver {
+	struct ap_driver ap_drv;
+	struct ap_matrix *ap_matrix;
+} vfio_ap_matrix_drv;
+
+static int ap_matrix_queue_dev_probe(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;
+
+	vapq = kzalloc(sizeof(*vapq), GFP_KERNEL);
+	if (!vapq)
+		return -ENOMEM;
+
+	INIT_LIST_HEAD(&vapq->list);
+	vapq->queue = apq;
+	spin_lock_bh(&ap_matrix->qlock);
+	list_add_tail(&vapq->list, &ap_matrix->queues);
+	spin_unlock_bh(&ap_matrix->qlock);
+
+	return 0;
+}
+
+static void ap_matrix_queue_dev_remove(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;

drivers/s390/crypto/vfio_ap_matrix_drv.c line 73

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +10 -0
+
+	vapq = find_vapq(ap_matrix, apq->qid);
+
+	if (vapq) {
+		spin_lock_bh(&ap_matrix->qlock);
+		list_del_init(&vapq->list);
+		spin_unlock_bh(&ap_matrix->qlock);
+		kfree(vapq);
+	}
+}

I would opt for a quick exit if find_vapq can not find the device. The un-indent the actual remove code.

Quoted 56 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +29 -0
+
+int __init ap_matrix_init(void)
+{
+
+	int ret;
+
+	vfio_ap_matrix_drv.ap_matrix = ap_matrix_get_device();
+	if (!vfio_ap_matrix_drv.ap_matrix)
+		return -ENODEV;
+
+	vfio_ap_matrix_drv.ap_drv.probe = ap_matrix_queue_dev_probe;
+	vfio_ap_matrix_drv.ap_drv.remove = ap_matrix_queue_dev_remove;
+	vfio_ap_matrix_drv.ap_drv.ids = ap_queue_ids;
+
+	ret = ap_driver_register(&vfio_ap_matrix_drv.ap_drv,
+				 THIS_MODULE, VFIO_AP_MATRIX_DRV_NAME);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
+void __exit ap_matrix_exit(void)
+{
+	ap_driver_unregister(&vfio_ap_matrix_drv.ap_drv);
+}
+
+module_init(ap_matrix_init);
+module_exit(ap_matrix_exit);
drivers/s390/crypto/vfio_ap_matrix_private.h new file +21 -0
new file mode 100644
index 0000000..11c5e02
@@ -0,0 +1,47 @@
+/*
+ * Private data and functions for adjunct processor VFIO matrix driver.
+ *
+ * Copyright IBM Corp. 2016
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#ifndef _VFIO_AP_PRIVATE_H_
+#define _VFIO_AP_PRIVATE_H_
+
+#include <linux/types.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+
+#define VFIO_AP_MATRIX_MODULE_NAME "vfio_ap_matrix"
+
+struct vfio_ap_queue {
+	struct ap_queue *queue;
+	struct list_head list;
+};

drivers/s390/crypto/vfio_ap_matrix_private.h line 31

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +10 -0
+
+static inline struct vfio_ap_queue *to_vapq(struct ap_device *ap_dev)
+{
+	struct ap_queue *ap_queue = to_ap_queue(&ap_dev->device);
+	struct vfio_ap_queue *vapq;
+
+	vapq = container_of(&ap_queue, struct vfio_ap_queue, queue);
+
+	return vapq;
+}

This can be shortened a bit

	return container_of(&ap_queue, struct vfio_ap_queue, queue);
Quoted 16 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +16 -0
+
+static inline struct vfio_ap_queue *find_vapq(struct ap_matrix *ap_matrix,
+					      ap_qid_t qid)
+{
+	struct vfio_ap_queue *vapq;
+
+	if (!list_empty(&ap_matrix->queues)) {
+		list_for_each_entry(vapq, &ap_matrix->queues, list)
+			if (vapq->queue->qid == qid)
+				return vapq;
+	}
+
+	return NULL;
+}
+
+#endif /* _VFIO_AP_PRIVATE_H_ */
Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#20 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 9 lines · Martin Schwidefsky
Quoted 6 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
drivers/s390/crypto/Makefile +0 -0
index 87646ca..1983afa 100644
@@ -13,4 +13,8 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
 
Quoted 10 lines

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 20

Quoted 9 lines
drivers/s390/crypto/Makefile +5 -1
  # pkey kernel module
  pkey-objs := pkey_api.o
-obj-$(CONFIG_PKEY) += pkey.o
\ No newline at end of file
+obj-$(CONFIG_PKEY) += pkey.o
+
+# adjunct processor matrix
+vfio_ap_matrix-objs := vfio_ap_matrix_drv.o
+obj-$(CONFIG_VFIO_AP_MATRIX) += vfio_ap_matrix.o

With the fix to patch #3 the newline quirk will be gone.

Yes it will.

Quoted 19 lines
Quoted 19 lines
drivers/s390/crypto/ap_matrix_bus.c +6 -0
index 4eb1e3c..66bfa54 100644
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
  	return 0;
  }
 
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;
+}
+EXPORT_SYMBOL(ap_matrix_get_device);
+
  int __init ap_matrix_init(void)
  {
  	int ret;
 
Quoted 8 lines

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 92

Quoted 5 lines
drivers/s390/crypto/ap_matrix_bus.c +2 -0
+	matrix = NULL;
+
  	ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME);
  	ret = PTR_RET(ap_matrix_root_device);
  	if (ret)

The global variable "matrix" is already NULL at the time ap_matrix_init is called. No need to set it again. And I would appreciate if the global variable would be named "ap_matrix".

Will make those changes.

Quoted 86 lines
Quoted 86 lines
drivers/s390/crypto/ap_matrix_bus.h +1 -1
index 225db4f..c2aff23 100644
@@ -16,6 +16,6 @@ struct ap_matrix {
  	struct device device;
  };
 
-int ap_matrix_init(void);
+struct ap_matrix *ap_matrix_get_device(void);
 
  #endif /* _AP_MATRIX_BUS_H_ */
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +67 -0
new file mode 100644
index 0000000..760ed56
@@ -0,0 +1,102 @@
+/*
+ * VFIO based AP Matrix device driver
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/slab.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+#include "vfio_ap_matrix_private.h"
+
+#define VFIO_AP_MATRIX_DRV_NAME "vfio_ap_queue"
+
+MODULE_AUTHOR("IBM Corporation");
+MODULE_DESCRIPTION("AP Matrix device driver, Copyright IBM Corp. 2017");
+MODULE_LICENSE("GPL v2");
+
+static struct ap_device_id ap_queue_ids[] = {
+	{ .dev_type = AP_DEVICE_TYPE_CEX4,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX5,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX6,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ /* end of list */ },
+};
+
+MODULE_DEVICE_TABLE(ap_matrix, ap_queue_ids);
+
+static struct ap_matrix_driver {
+	struct ap_driver ap_drv;
+	struct ap_matrix *ap_matrix;
+} vfio_ap_matrix_drv;
+
+static int ap_matrix_queue_dev_probe(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;
+
+	vapq = kzalloc(sizeof(*vapq), GFP_KERNEL);
+	if (!vapq)
+		return -ENOMEM;
+
+	INIT_LIST_HEAD(&vapq->list);
+	vapq->queue = apq;
+	spin_lock_bh(&ap_matrix->qlock);
+	list_add_tail(&vapq->list, &ap_matrix->queues);
+	spin_unlock_bh(&ap_matrix->qlock);
+
+	return 0;
+}
+
+static void ap_matrix_queue_dev_remove(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;
+
+	vapq = find_vapq(ap_matrix, apq->qid);
+
+	if (vapq) {
Quoted 8 lines

drivers/s390/crypto/vfio_ap_matrix_drv.c line 73

Quoted 6 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +6 -0
+		spin_lock_bh(&ap_matrix->qlock);
+		list_del_init(&vapq->list);
+		spin_unlock_bh(&ap_matrix->qlock);
+		kfree(vapq);
+	}
+}

I would opt for a quick exit if find_vapq can not find the device. The un-indent the actual remove code.

Okay, will do.

Quoted 69 lines
Quoted 57 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +29 -0
+
+int __init ap_matrix_init(void)
+{
+
+	int ret;
+
+	vfio_ap_matrix_drv.ap_matrix = ap_matrix_get_device();
+	if (!vfio_ap_matrix_drv.ap_matrix)
+		return -ENODEV;
+
+	vfio_ap_matrix_drv.ap_drv.probe = ap_matrix_queue_dev_probe;
+	vfio_ap_matrix_drv.ap_drv.remove = ap_matrix_queue_dev_remove;
+	vfio_ap_matrix_drv.ap_drv.ids = ap_queue_ids;
+
+	ret = ap_driver_register(&vfio_ap_matrix_drv.ap_drv,
+				 THIS_MODULE, VFIO_AP_MATRIX_DRV_NAME);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
+void __exit ap_matrix_exit(void)
+{
+	ap_driver_unregister(&vfio_ap_matrix_drv.ap_drv);
+}
+
+module_init(ap_matrix_init);
+module_exit(ap_matrix_exit);
drivers/s390/crypto/vfio_ap_matrix_private.h new file +21 -0
new file mode 100644
index 0000000..11c5e02
@@ -0,0 +1,47 @@
+/*
+ * Private data and functions for adjunct processor VFIO matrix driver.
+ *
+ * Copyright IBM Corp. 2016
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#ifndef _VFIO_AP_PRIVATE_H_
+#define _VFIO_AP_PRIVATE_H_
+
+#include <linux/types.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+
+#define VFIO_AP_MATRIX_MODULE_NAME "vfio_ap_matrix"
+
+struct vfio_ap_queue {
+	struct ap_queue *queue;
+	struct list_head list;
+};

drivers/s390/crypto/vfio_ap_matrix_private.h line 31

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +10 -0
+
+static inline struct vfio_ap_queue *to_vapq(struct ap_device *ap_dev)
+{
+	struct ap_queue *ap_queue = to_ap_queue(&ap_dev->device);
+	struct vfio_ap_queue *vapq;
+
+	vapq = container_of(&ap_queue, struct vfio_ap_queue, queue);
+
+	return vapq;
+}

This can be shortened a bit

Quoted 1 line
	return container_of(&ap_queue, struct vfio_ap_queue, queue);

Okay, will do.

Quoted 18 lines
Quoted 17 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +16 -0
+
+static inline struct vfio_ap_queue *find_vapq(struct ap_matrix *ap_matrix,
+					      ap_qid_t qid)
+{
+	struct vfio_ap_queue *vapq;
+
+	if (!list_empty(&ap_matrix->queues)) {
+		list_for_each_entry(vapq, &ap_matrix->queues, list)
+			if (vapq->queue->qid == qid)
+				return vapq;
+	}
+
+	return NULL;
+}
+
+#endif /* _VFIO_AP_PRIVATE_H_ */
#21 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

In reply to Tony Krowiak
Quoted 55 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…

Introduces a new AP matrix device driver. This device driver will ultimately perform the following functions:

* Register with the AP bus to let it know that the matrix driver can control AP queue devices. This will allow an administrator to unbind an AP queue device from its device driver and bind it to the matrix device driver. This is how AP queue devices will be reserved for use by guest machines.

* Register the matrix device created by the AP matrix bus with the VFIO mediated device framework. This will create the sysfs entries needed to create mediated matrix devices. Each mediated matrix device can be configured with a matrix of adapters, usage domains and control domains that can be accessed by a guest machine.

* Process requests via ioctl calls defined for the mediated matrix device. The guest can access the ioctl calls via the mediated device's file descriptor to:

* Grant access to the adapters, usage domains and control domains configured for the mediated matrix device.

This device driver
is built on the VFIO mediated device framework. The VFIO mediated device framework allows a mediated device to be dedicated exclusively to a single guest VM.

---
 MAINTAINERS                                  |    2 +
 arch/s390/Kconfig                            |   13 +++
 arch/s390/configs/default_defconfig          |    1 +
 arch/s390/configs/gcov_defconfig             |    1 +
 arch/s390/configs/performance_defconfig      |    1 +
 arch/s390/defconfig                          |    1 +
 drivers/s390/crypto/Makefile                 |    6 +-
 drivers/s390/crypto/ap_matrix_bus.c          |    8 ++
 drivers/s390/crypto/ap_matrix_bus.h          |    2 +-
 drivers/s390/crypto/vfio_ap_matrix_drv.c     |  102 ++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_matrix_private.h |   47 ++++++++++++
 11 files changed, 182 insertions(+), 2 deletions(-)
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_drv.c
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_private.h
arch/s390/Kconfig +0 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW
 	  To compile this driver as a module, choose M here: the
 	  module will be called vfio_ccw.

arch/s390/Kconfig config VFIO_CCW · line 733

Quoted 10 lines
arch/s390/Kconfig +9 -0
 
+config VFIO_AP_MATRIX
+	def_tristate m
+	prompt "Support for Adjunct Processor Matrix device interface"
+	depends on ZCRYPT
+	select VFIO
+	select MDEV
+	select VFIO_MDEV
+	select VFIO_MDEV_DEVICE
+	select IOMMU_API

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

Quoted 13 lines
arch/s390/Kconfig +4 -0
+	help
+		driver grants access to Adjunct Processor (AP) devices
+		via the VFIO mediated device interface.
+
 endmenu
 
 menu "Dump support"
drivers/s390/crypto/Makefile +0 -0
index 87646ca..1983afa 100644

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 6 lines
drivers/s390/crypto/Makefile +1 -1
@@ -13,4 +13,8 @@ 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
\ No newline at end of file
+obj-$(CONFIG_PKEY) += pkey.o

Another change of that line.

Quoted 9 lines
drivers/s390/crypto/Makefile +4 -0
+
+# adjunct processor matrix
+vfio_ap_matrix-objs := vfio_ap_matrix_drv.o
+obj-$(CONFIG_VFIO_AP_MATRIX) += vfio_ap_matrix.o
drivers/s390/crypto/ap_matrix_bus.c +0 -0
index 4eb1e3c..66bfa54 100644

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 80

Quoted 6 lines
drivers/s390/crypto/ap_matrix_bus.c +3 -0
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
 	return 0;
 }
 
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;

See the comments I had for the previous patch. In particular, I think it is better to retrieve a pointer to the matrix device via driver core methods.

Quoted 17 lines
drivers/s390/crypto/ap_matrix_bus.c +5 -0
+}
+EXPORT_SYMBOL(ap_matrix_get_device);
+
 int __init ap_matrix_init(void)
 {
 	int ret;
 
+	matrix = NULL;
+
 	ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME);
 	ret = PTR_RET(ap_matrix_root_device);
 	if (ret)
drivers/s390/crypto/ap_matrix_bus.h +0 -0
index 225db4f..c2aff23 100644

drivers/s390/crypto/ap_matrix_bus.h struct ap_matrix { · line 19

Quoted 4 lines
drivers/s390/crypto/ap_matrix_bus.h +0 -1
@@ -16,6 +16,6 @@ struct ap_matrix {
 	struct device device;
 };
 
-int ap_matrix_init(void);

So, was that not needed before?

Quoted 28 lines
drivers/s390/crypto/ap_matrix_bus.h +1 -0
+struct ap_matrix *ap_matrix_get_device(void);
 
 #endif /* _AP_MATRIX_BUS_H_ */
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +19 -0
new file mode 100644
index 0000000..760ed56
@@ -0,0 +1,102 @@
+/*
+ * VFIO based AP Matrix device driver
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/slab.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+#include "vfio_ap_matrix_private.h"
+
+#define VFIO_AP_MATRIX_DRV_NAME "vfio_ap_queue"
+
+MODULE_AUTHOR("IBM Corporation");

drivers/s390/crypto/vfio_ap_matrix_drv.c line 29

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +10 -0
+MODULE_DESCRIPTION("AP Matrix device driver, Copyright IBM Corp. 2017");
+MODULE_LICENSE("GPL v2");
+
+static struct ap_device_id ap_queue_ids[] = {
+	{ .dev_type = AP_DEVICE_TYPE_CEX4,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX5,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX6,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },

So, you explicitly don't match to all devices, but only to the newer ones? This needs an explaining comment.

drivers/s390/crypto/vfio_ap_matrix_drv.c line 37

Quoted 8 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +8 -0
+	{ /* end of list */ },
+};
+
+MODULE_DEVICE_TABLE(ap_matrix, ap_queue_ids);
+
+static struct ap_matrix_driver {
+	struct ap_driver ap_drv;
+	struct ap_matrix *ap_matrix;

Do you actually need that pointer to the matrix device? One usage is to pass it as an parameter to the mdev registration in the next patch. As you only support one matrix device, would it be better to move getting that device into the mdev code?

For the other usage, move getting it into find_vapq()?

Quoted 39 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +39 -0
+} vfio_ap_matrix_drv;
+
+static int ap_matrix_queue_dev_probe(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;
+
+	vapq = kzalloc(sizeof(*vapq), GFP_KERNEL);
+	if (!vapq)
+		return -ENOMEM;
+
+	INIT_LIST_HEAD(&vapq->list);
+	vapq->queue = apq;
+	spin_lock_bh(&ap_matrix->qlock);
+	list_add_tail(&vapq->list, &ap_matrix->queues);
+	spin_unlock_bh(&ap_matrix->qlock);
+
+	return 0;
+}
+
+static void ap_matrix_queue_dev_remove(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;
+
+	vapq = find_vapq(ap_matrix, apq->qid);
+
+	if (vapq) {
+		spin_lock_bh(&ap_matrix->qlock);
+		list_del_init(&vapq->list);
+		spin_unlock_bh(&ap_matrix->qlock);
+		kfree(vapq);
+	}
+}
+
+int __init ap_matrix_init(void)
+{

drivers/s390/crypto/vfio_ap_matrix_drv.c line 86

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +10 -0
+
+	int ret;
+
+	vfio_ap_matrix_drv.ap_matrix = ap_matrix_get_device();
+	if (!vfio_ap_matrix_drv.ap_matrix)
+		return -ENODEV;
+
+	vfio_ap_matrix_drv.ap_drv.probe = ap_matrix_queue_dev_probe;
+	vfio_ap_matrix_drv.ap_drv.remove = ap_matrix_queue_dev_remove;
+	vfio_ap_matrix_drv.ap_drv.ids = ap_queue_ids;

Can you use an static initializer for that?

Quoted 40 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +16 -0
+
+	ret = ap_driver_register(&vfio_ap_matrix_drv.ap_drv,
+				 THIS_MODULE, VFIO_AP_MATRIX_DRV_NAME);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
+void __exit ap_matrix_exit(void)
+{
+	ap_driver_unregister(&vfio_ap_matrix_drv.ap_drv);
+}
+
+module_init(ap_matrix_init);
+module_exit(ap_matrix_exit);
drivers/s390/crypto/vfio_ap_matrix_private.h new file +18 -0
new file mode 100644
index 0000000..11c5e02
@@ -0,0 +1,47 @@
+/*
+ * Private data and functions for adjunct processor VFIO matrix driver.
+ *
+ * Copyright IBM Corp. 2016
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#ifndef _VFIO_AP_PRIVATE_H_
+#define _VFIO_AP_PRIVATE_H_
+
+#include <linux/types.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+
+#define VFIO_AP_MATRIX_MODULE_NAME "vfio_ap_matrix"
+
+struct vfio_ap_queue {

drivers/s390/crypto/vfio_ap_matrix_private.h line 28

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +10 -0
+	struct ap_queue *queue;
+	struct list_head list;
+};
+
+static inline struct vfio_ap_queue *to_vapq(struct ap_device *ap_dev)
+{
+	struct ap_queue *ap_queue = to_ap_queue(&ap_dev->device);
+	struct vfio_ap_queue *vapq;
+
+	vapq = container_of(&ap_queue, struct vfio_ap_queue, queue);

Why not just return container_of(...); ?

Quoted 19 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +19 -0
+
+	return vapq;
+}
+
+static inline struct vfio_ap_queue *find_vapq(struct ap_matrix *ap_matrix,
+					      ap_qid_t qid)
+{
+	struct vfio_ap_queue *vapq;
+
+	if (!list_empty(&ap_matrix->queues)) {
+		list_for_each_entry(vapq, &ap_matrix->queues, list)
+			if (vapq->queue->qid == qid)
+				return vapq;
+	}
+
+	return NULL;
+}
+
+#endif /* _VFIO_AP_PRIVATE_H_ */
#22 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 58 lines · Cornelia Huck
Quoted 55 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…

Introduces a new AP matrix device driver. This device driver will ultimately perform the following functions:

* Register with the AP bus to let it know that the matrix driver can control AP queue devices. This will allow an administrator to unbind an AP queue device from its device driver and bind it to the matrix device driver. This is how AP queue devices will be reserved for use by guest machines.

* Register the matrix device created by the AP matrix bus with the VFIO mediated device framework. This will create the sysfs entries needed to create mediated matrix devices. Each mediated matrix device can be configured with a matrix of adapters, usage domains and control domains that can be accessed by a guest machine.

* Process requests via ioctl calls defined for the mediated matrix device. The guest can access the ioctl calls via the mediated device's file descriptor to:

* Grant access to the adapters, usage domains and control domains configured for the mediated matrix device.

This device driver
is built on the VFIO mediated device framework. The VFIO mediated device framework allows a mediated device to be dedicated exclusively to a single guest VM.

---
  MAINTAINERS                                  |    2 +
  arch/s390/Kconfig                            |   13 +++
  arch/s390/configs/default_defconfig          |    1 +
  arch/s390/configs/gcov_defconfig             |    1 +
  arch/s390/configs/performance_defconfig      |    1 +
  arch/s390/defconfig                          |    1 +
  drivers/s390/crypto/Makefile                 |    6 +-
  drivers/s390/crypto/ap_matrix_bus.c          |    8 ++
  drivers/s390/crypto/ap_matrix_bus.h          |    2 +-
  drivers/s390/crypto/vfio_ap_matrix_drv.c     |  102 ++++++++++++++++++++++++++
  drivers/s390/crypto/vfio_ap_matrix_private.h |   47 ++++++++++++
  11 files changed, 182 insertions(+), 2 deletions(-)

create mode 100644 drivers/s390/crypto/vfio_ap_matrix_drv.c create mode 100644 drivers/s390/crypto/vfio_ap_matrix_private.h

arch/s390/Kconfig +0 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW
  	  To compile this driver as a module, choose M here: the
  	  module will be called vfio_ccw.
 
Quoted 11 lines

arch/s390/Kconfig config VFIO_CCW · line 733

Quoted 9 lines
arch/s390/Kconfig +9 -0
+config VFIO_AP_MATRIX
+	def_tristate m
+	prompt "Support for Adjunct Processor Matrix device interface"
+	depends on ZCRYPT
+	select VFIO
+	select MDEV
+	select VFIO_MDEV
+	select VFIO_MDEV_DEVICE
+	select IOMMU_API

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

It's ironic because I originally changed from using 'depends on' and changed it based on review comments made on our internal mailing list. I'll go with 'depends on'.

Quoted 14 lines
Quoted 14 lines
arch/s390/Kconfig +4 -0
+	help
+		driver grants access to Adjunct Processor (AP) devices
+		via the VFIO mediated device interface.
+
  endmenu
 
  menu "Dump support"
drivers/s390/crypto/Makefile +0 -0
index 87646ca..1983afa 100644
@@ -13,4 +13,8 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
 
Quoted 6 lines

drivers/s390/crypto/Makefile obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o · line 16

Quoted 5 lines
drivers/s390/crypto/Makefile +1 -1
  # pkey kernel module
  pkey-objs := pkey_api.o
-obj-$(CONFIG_PKEY) += pkey.o
\ No newline at end of file
+obj-$(CONFIG_PKEY) += pkey.o

Another change of that line.

Will fix this

Quoted 13 lines
Quoted 13 lines
drivers/s390/crypto/Makefile +4 -0
+
+# adjunct processor matrix
+vfio_ap_matrix-objs := vfio_ap_matrix_drv.o
+obj-$(CONFIG_VFIO_AP_MATRIX) += vfio_ap_matrix.o
drivers/s390/crypto/ap_matrix_bus.c +0 -0
index 4eb1e3c..66bfa54 100644
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
  	return 0;
  }
 
Quoted 6 lines

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 80

Quoted 3 lines
drivers/s390/crypto/ap_matrix_bus.c +3 -0
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;

See the comments I had for the previous patch. In particular, I think it is better to retrieve a pointer to the matrix device via driver core methods.

I got some objections to creating a new bus and since there will only ever be a single AP matrix device, I decided there really wasn't a need for an AP matrix bus and got rid of it. I opted instead to create the matrix device in the init function of the vfio_ap_matrix driver. Rather than passing around a pointer, I put the following in vfio_ap_matrix_private.h:

    struct ap_matrix {
        struct device device;
        spinlock_t qlock;
        struct list_head queues;
    };

    extern struct ap_matrix ap_matrix;

... and declared the ap_matrix in the driver (vfio_ap_matrix_drv.c) file as:

    struct ap_matrix ap_matrix;

Does this seem like a reasonable approach?

Quoted 21 lines
Quoted 21 lines
drivers/s390/crypto/ap_matrix_bus.c +5 -0
+}
+EXPORT_SYMBOL(ap_matrix_get_device);
+
  int __init ap_matrix_init(void)
  {
  	int ret;
 
+	matrix = NULL;
+
  	ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME);
  	ret = PTR_RET(ap_matrix_root_device);
  	if (ret)
drivers/s390/crypto/ap_matrix_bus.h +0 -0
index 225db4f..c2aff23 100644
@@ -16,6 +16,6 @@ struct ap_matrix {
  	struct device device;
  };
 
Quoted 2 lines

drivers/s390/crypto/ap_matrix_bus.h struct ap_matrix { · line 19

Quoted 1 line
drivers/s390/crypto/ap_matrix_bus.h +0 -1
-int ap_matrix_init(void);

So, was that not needed before?

Forgot to remove it when I refactored a previous patch in which was introduced.

Quoted 33 lines
Quoted 33 lines
drivers/s390/crypto/ap_matrix_bus.h +1 -0
+struct ap_matrix *ap_matrix_get_device(void);
 
  #endif /* _AP_MATRIX_BUS_H_ */
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +23 -0
new file mode 100644
index 0000000..760ed56
@@ -0,0 +1,102 @@
+/*
+ * VFIO based AP Matrix device driver
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/slab.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+#include "vfio_ap_matrix_private.h"
+
+#define VFIO_AP_MATRIX_DRV_NAME "vfio_ap_queue"
+
+MODULE_AUTHOR("IBM Corporation");
+MODULE_DESCRIPTION("AP Matrix device driver, Copyright IBM Corp. 2017");
+MODULE_LICENSE("GPL v2");
+
+static struct ap_device_id ap_queue_ids[] = {
Quoted 8 lines

drivers/s390/crypto/vfio_ap_matrix_drv.c line 29

Quoted 6 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +6 -0
+	{ .dev_type = AP_DEVICE_TYPE_CEX4,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX5,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
+	{ .dev_type = AP_DEVICE_TYPE_CEX6,
+	  .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },

So, you explicitly don't match to all devices, but only to the newer ones? This needs an explaining comment.

Okay

Quoted 14 lines

drivers/s390/crypto/vfio_ap_matrix_drv.c line 37

Quoted 9 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +8 -0
+	{ /* end of list */ },
+};
+
+MODULE_DEVICE_TABLE(ap_matrix, ap_queue_ids);
+
+static struct ap_matrix_driver {
+	struct ap_driver ap_drv;
+	struct ap_matrix *ap_matrix;

Do you actually need that pointer to the matrix device? One usage is to pass it as an parameter to the mdev registration in the next patch. As you only support one matrix device, would it be better to move getting that device into the mdev code?

Quoted 1 line

For the other usage, move getting it into find_vapq()?

See my comments above regarding getting rid of the AP matrix bus.

Quoted 43 lines
Quoted 43 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +42 -0
+} vfio_ap_matrix_drv;
+
+static int ap_matrix_queue_dev_probe(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;
+
+	vapq = kzalloc(sizeof(*vapq), GFP_KERNEL);
+	if (!vapq)
+		return -ENOMEM;
+
+	INIT_LIST_HEAD(&vapq->list);
+	vapq->queue = apq;
+	spin_lock_bh(&ap_matrix->qlock);
+	list_add_tail(&vapq->list, &ap_matrix->queues);
+	spin_unlock_bh(&ap_matrix->qlock);
+
+	return 0;
+}
+
+static void ap_matrix_queue_dev_remove(struct ap_device *apdev)
+{
+	struct vfio_ap_queue *vapq;
+	struct ap_queue *apq = to_ap_queue(&apdev->device);
+	struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix;
+
+	vapq = find_vapq(ap_matrix, apq->qid);
+
+	if (vapq) {
+		spin_lock_bh(&ap_matrix->qlock);
+		list_del_init(&vapq->list);
+		spin_unlock_bh(&ap_matrix->qlock);
+		kfree(vapq);
+	}
+}
+
+int __init ap_matrix_init(void)
+{
+
+	int ret;
+
Quoted 8 lines

drivers/s390/crypto/vfio_ap_matrix_drv.c line 86

Quoted 7 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +7 -0
+	vfio_ap_matrix_drv.ap_matrix = ap_matrix_get_device();
+	if (!vfio_ap_matrix_drv.ap_matrix)
+		return -ENODEV;
+
+	vfio_ap_matrix_drv.ap_drv.probe = ap_matrix_queue_dev_probe;
+	vfio_ap_matrix_drv.ap_drv.remove = ap_matrix_queue_dev_remove;
+	vfio_ap_matrix_drv.ap_drv.ids = ap_queue_ids;

Can you use an static initializer for that?

This is how its done for the AP bus drivers, for example; see zcrypt_cex4.c.

Quoted 44 lines
Quoted 44 lines
drivers/s390/crypto/vfio_ap_matrix_drv.c new file +16 -0
+
+	ret = ap_driver_register(&vfio_ap_matrix_drv.ap_drv,
+				 THIS_MODULE, VFIO_AP_MATRIX_DRV_NAME);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
+void __exit ap_matrix_exit(void)
+{
+	ap_driver_unregister(&vfio_ap_matrix_drv.ap_drv);
+}
+
+module_init(ap_matrix_init);
+module_exit(ap_matrix_exit);
drivers/s390/crypto/vfio_ap_matrix_private.h new file +21 -0
new file mode 100644
index 0000000..11c5e02
@@ -0,0 +1,47 @@
+/*
+ * Private data and functions for adjunct processor VFIO matrix driver.
+ *
+ * Copyright IBM Corp. 2016
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#ifndef _VFIO_AP_PRIVATE_H_
+#define _VFIO_AP_PRIVATE_H_
+
+#include <linux/types.h>
+
+#include "ap_bus.h"
+#include "ap_matrix_bus.h"
+
+#define VFIO_AP_MATRIX_MODULE_NAME "vfio_ap_matrix"
+
+struct vfio_ap_queue {
+	struct ap_queue *queue;
+	struct list_head list;
+};
Quoted 8 lines

drivers/s390/crypto/vfio_ap_matrix_private.h line 28

Quoted 7 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +7 -0
+
+static inline struct vfio_ap_queue *to_vapq(struct ap_device *ap_dev)
+{
+	struct ap_queue *ap_queue = to_ap_queue(&ap_dev->device);
+	struct vfio_ap_queue *vapq;
+
+	vapq = container_of(&ap_queue, struct vfio_ap_queue, queue);

Why not just return container_of(...); ?

Will change it.

Quoted 20 lines
Quoted 20 lines
drivers/s390/crypto/vfio_ap_matrix_private.h new file +19 -0
+
+	return vapq;
+}
+
+static inline struct vfio_ap_queue *find_vapq(struct ap_matrix *ap_matrix,
+					      ap_qid_t qid)
+{
+	struct vfio_ap_queue *vapq;
+
+	if (!list_empty(&ap_matrix->queues)) {
+		list_for_each_entry(vapq, &ap_matrix->queues, list)
+			if (vapq->queue->qid == qid)
+				return vapq;
+	}
+
+	return NULL;
+}
+
+#endif /* _VFIO_AP_PRIVATE_H_ */
#23 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 34 lines · On Tue, 14 Nov 2017 11:37:05 -0500 Tony Krowiak <[email protected]>…
Quoted 11 lines · Cornelia Huck
Quoted 8 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
drivers/s390/crypto/ap_matrix_bus.c +0 -0
index 4eb1e3c..66bfa54 100644
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
  	return 0;
  }
 
Quoted 6 lines

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 80

Quoted 3 lines
drivers/s390/crypto/ap_matrix_bus.c +3 -0
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;  

See the comments I had for the previous patch. In particular, I think it is better to retrieve a pointer to the matrix device via driver core methods.

I got some objections to creating a new bus and since there will only ever be a single AP matrix device, I decided there really wasn't a need for an AP matrix bus and got rid of it. I opted instead to create the matrix device
in the init function of the vfio_ap_matrix driver. Rather than passing around a
pointer, I put the following in vfio_ap_matrix_private.h:

     struct ap_matrix {
         struct device device;
         spinlock_t qlock;
         struct list_head queues;
     };

     extern struct ap_matrix ap_matrix;
Quoted 6 lines

... and declared the ap_matrix in the driver (vfio_ap_matrix_drv.c) file as:

     struct ap_matrix ap_matrix;

Does this seem like a reasonable approach?

Getting rid of the bus as overhead is not unreasonable.

I'm feeling a bit queasy about the extern, however. I'd prefer a getter function (that also makes sure refcounting rules are followed).

We can't get around referencing this device from multiple files, can we?

#24 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 39 lines · Cornelia Huck
Quoted 36 lines · On Tue, 14 Nov 2017 11:37:05 -0500 Tony Krowiak <[email protected]>…
Quoted 10 lines · Cornelia Huck
Quoted 8 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
drivers/s390/crypto/ap_matrix_bus.c +0 -0
index 4eb1e3c..66bfa54 100644
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
   	return 0;
   }
 
Quoted 6 lines

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 80

Quoted 3 lines
drivers/s390/crypto/ap_matrix_bus.c +3 -0
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;

See the comments I had for the previous patch. In particular, I think it is better to retrieve a pointer to the matrix device via driver core methods.

I got some objections to creating a new bus and since there will only ever be a single AP matrix device, I decided there really wasn't a need for an AP matrix bus and got rid of it. I opted instead to create the matrix device
in the init function of the vfio_ap_matrix driver. Rather than passing around a
pointer, I put the following in vfio_ap_matrix_private.h:

      struct ap_matrix {
          struct device device;
          spinlock_t qlock;
          struct list_head queues;
      };

      extern struct ap_matrix ap_matrix;

... and declared the ap_matrix in the driver (vfio_ap_matrix_drv.c) file as:

Quoted 7 lines
Quoted 3 lines
      struct ap_matrix ap_matrix;

Does this seem like a reasonable approach?

Getting rid of the bus as overhead is not unreasonable.

I'm feeling a bit queasy about the extern, however. I'd prefer a getter function (that also makes sure refcounting rules are followed).

I now think I can avoid having to reference the ap_matrix device from multiple places. The reason the device is referenced in vfio_ap_matrix_ops.c is because there is a need for information about the AP queues that have been bound to the vfio_ap_matrix device driver. If interfaces are provided by the vfio_ap_matrix device driver to access the needed information, it won't be necessary to reference the ap_matrix device directly in vfio_ap_matrix_ops. I think this would be a better solution, don't you?

Quoted 2 lines

We can't get around referencing this device from multiple files, can we?

The only way would be to roll up vfio_ap_matrix_ops.c into vfio_ap_matrix_drv.c. I followed the pattern established by the vfio_ccw

Quoted 1 line
#25 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 47 lines · On Tue, 14 Nov 2017 13:15:27 -0500 Tony Krowiak <[email protected]>…
Quoted 39 lines · Cornelia Huck
Quoted 36 lines · On Tue, 14 Nov 2017 11:37:05 -0500 Tony Krowiak <[email protected]>…
Quoted 10 lines · Cornelia Huck
Quoted 8 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
drivers/s390/crypto/ap_matrix_bus.c +0 -0
index 4eb1e3c..66bfa54 100644
@@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void)
   	return 0;
   }
 
Quoted 6 lines

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 80

Quoted 3 lines
drivers/s390/crypto/ap_matrix_bus.c +3 -0
+struct ap_matrix *ap_matrix_get_device(void)
+{
+	return matrix;  

See the comments I had for the previous patch. In particular, I think it is better to retrieve a pointer to the matrix device via driver core methods.

I got some objections to creating a new bus and since there will only ever be a single AP matrix device, I decided there really wasn't a need for an AP matrix bus and got rid of it. I opted instead to create the matrix device
in the init function of the vfio_ap_matrix driver. Rather than passing around a
pointer, I put the following in vfio_ap_matrix_private.h:

      struct ap_matrix {
          struct device device;
          spinlock_t qlock;
          struct list_head queues;
      };

      extern struct ap_matrix ap_matrix;

... and declared the ap_matrix in the driver (vfio_ap_matrix_drv.c) file as:

Quoted 7 lines
Quoted 3 lines
      struct ap_matrix ap_matrix;

Does this seem like a reasonable approach?

Getting rid of the bus as overhead is not unreasonable.

I'm feeling a bit queasy about the extern, however. I'd prefer a getter function (that also makes sure refcounting rules are followed).

Quoted 9 lines

I now think I can avoid having to reference the ap_matrix device from multiple places. The reason the device is referenced in vfio_ap_matrix_ops.c is because there is a need for information about the AP queues that have been
bound to the vfio_ap_matrix device driver. If interfaces are provided by the
vfio_ap_matrix device driver to access the needed information, it won't be necessary to reference the ap_matrix device directly in vfio_ap_matrix_ops. I think this would be a better solution, don't you?

That sounds good, agreed.

#26 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

In reply to Tony Krowiak
Quoted 70 lines · Tony Krowiak
Quoted 61 lines · Cornelia Huck
Quoted 58 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…

Introduces a new AP matrix device driver. This device driver will ultimately perform the following functions:

* Register with the AP bus to let it know that the matrix driver can control AP queue devices. This will allow an administrator to unbind an AP queue device from its device driver and bind it to the matrix device driver. This is how AP queue devices will be reserved for use by guest machines.

* Register the matrix device created by the AP matrix bus with the VFIO mediated device framework. This will create the sysfs entries needed to create mediated matrix devices. Each mediated matrix device can be configured with a matrix of adapters, usage domains and control domains that can be accessed by a guest machine.

* Process requests via ioctl calls defined for the mediated matrix device. The guest can access the ioctl calls via the mediated device's file descriptor to:

     * Grant access to the adapters, usage domains and control domains configured for the mediated matrix device.

This device driver
is built on the VFIO mediated device framework. The VFIO mediated device framework allows a mediated device to be dedicated exclusively to a single guest VM.

---
  MAINTAINERS                                  |    2 + arch/s390/Kconfig                            |   13 +++ arch/s390/configs/default_defconfig          |    1 + arch/s390/configs/gcov_defconfig             |    1 + arch/s390/configs/performance_defconfig      |    1 + arch/s390/defconfig                          |    1 + drivers/s390/crypto/Makefile                 |    6 +- drivers/s390/crypto/ap_matrix_bus.c          |    8 ++ drivers/s390/crypto/ap_matrix_bus.h          |    2 +- drivers/s390/crypto/vfio_ap_matrix_drv.c     |  102
++++++++++++++++++++++++++
  drivers/s390/crypto/vfio_ap_matrix_private.h |   47 ++++++++++++

  11 files changed, 182 insertions(+), 2 deletions(-)

  create mode 100644 drivers/s390/crypto/vfio_ap_matrix_drv.c create mode 100644 drivers/s390/crypto/vfio_ap_matrix_private.h

arch/s390/Kconfig +0 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW

        To compile this driver as a module, choose M here: the module will be called vfio_ccw.
+config VFIO_AP_MATRIX
+    def_tristate m
+    prompt "Support for Adjunct Processor Matrix device interface"

Quoted 8 lines
Quoted 6 lines

+    depends on ZCRYPT
+    select VFIO
+    select MDEV
+    select VFIO_MDEV
+    select VFIO_MDEV_DEVICE
+    select IOMMU_API

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

Quoted 2 lines

It's ironic because I originally changed from using 'depends on' and changed it based on review comments made on our internal mailing list. I'll go with 'depends on'.

Is doing like the others a sufficient good reason? What if the first who did this did not really think about it?

When an administrator configure the kernel what does he think?

- I want to have AP through AP_VFIO in my guests
and he get implicitly VFIO
or
- I want to have VFIO
and he has to explicitly add AP_VFIO too

It seems to me that the first is much more user friendly.

Please tell me if I missed something. dependencies? collateral damages? my logic is wrong?

Regards,

Pierre

..snip...

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

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 38 lines · On Thu, 16 Nov 2017 13:02:26 +0100 Pierre Morel <[email protected]>…
Quoted 22 lines · Tony Krowiak
Quoted 13 lines · Cornelia Huck
Quoted 10 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
arch/s390/Kconfig +0 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW

        To compile this driver as a module, choose M here: the module will be called vfio_ccw.
+config VFIO_AP_MATRIX
+    def_tristate m
+    prompt "Support for Adjunct Processor Matrix device interface"

Quoted 8 lines
Quoted 6 lines

+    depends on ZCRYPT
+    select VFIO
+    select MDEV
+    select VFIO_MDEV
+    select VFIO_MDEV_DEVICE
+    select IOMMU_API

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

Quoted 3 lines

It's ironic because I originally changed from using 'depends on' and changed it based on review comments made
on our internal mailing list. I'll go with 'depends on'.

Is doing like the others a sufficient good reason? What if the first who did this did not really think about it?

When an administrator configure the kernel what does he think?

- I want to have AP through AP_VFIO in my guests
and he get implicitly VFIO
or
- I want to have VFIO
and he has to explicitly add AP_VFIO too

Quoted 4 lines

It seems to me that the first is much more user friendly.

Please tell me if I missed something. dependencies? collateral damages? my logic is wrong?

Using select for anything that's not a simple infrastructure dependency may lead into trouble (we've had issues in the past where options tried to enable other options but missed dependencies).

If a user wants to use vfio-ap, I think it is reasonable to expect them to figure out that they need both ap and vfio for that.

[And config help has gotten much better than it was years ago; it's not that hard to figure out what is actually needed.]

#28 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 47 lines · Cornelia Huck
Quoted 36 lines · On Thu, 16 Nov 2017 13:02:26 +0100 Pierre Morel <[email protected]>…
Quoted 21 lines · Tony Krowiak
Quoted 12 lines · Cornelia Huck
Quoted 10 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
arch/s390/Kconfig +3 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW
         To compile this driver as a module, choose M here: the
         module will be called vfio_ccw.
+config VFIO_AP_MATRIX
+    def_tristate m
+    prompt "Support for Adjunct Processor Matrix device interface"
Quoted 8 lines

arch/s390/Kconfig config VFIO_CCW · line 733

Quoted 6 lines
arch/s390/Kconfig +6 -0
+    depends on ZCRYPT
+    select VFIO
+    select MDEV
+    select VFIO_MDEV
+    select VFIO_MDEV_DEVICE
+    select IOMMU_API

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

Quoted 3 lines

It's ironic because I originally changed from using 'depends on' and changed it based on review comments made
on our internal mailing list. I'll go with 'depends on'.

Is doing like the others a sufficient good reason? What if the first who did this did not really think about it?

When an administrator configure the kernel what does he think?

- I want to have AP through AP_VFIO in my guests
and he get implicitly VFIO
or
- I want to have VFIO
and he has to explicitly add AP_VFIO too

Quoted 4 lines

It seems to me that the first is much more user friendly.

Please tell me if I missed something. dependencies? collateral damages? my logic is wrong?

Using select for anything that's not a simple infrastructure dependency may lead into trouble (we've had issues in the past where options tried to enable other options but missed dependencies).

Quoted 5 lines

If a user wants to use vfio-ap, I think it is reasonable to expect them to figure out that they need both ap and vfio for that.

[And config help has gotten much better than it was years ago; it's not that hard to figure out what is actually needed.]

Is it sufficient to specify 'depends on ZCRYPT && VFIO_MDEV_DEVICE' since 'VFIO_MDEV_DEVICE depends on VFIO && VFIO_MDEV' and 'VFIO_MDEV depends on VFIO' and 'VFIO depends on IOMMU_API'?

Quoted 1 line
#29 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 48 lines · On Thu, 16 Nov 2017 09:25:27 -0500 Tony Krowiak <[email protected]>…
Quoted 47 lines · Cornelia Huck
Quoted 36 lines · On Thu, 16 Nov 2017 13:02:26 +0100 Pierre Morel <[email protected]>…
Quoted 21 lines · Tony Krowiak
Quoted 12 lines · Cornelia Huck
Quoted 10 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
arch/s390/Kconfig +3 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW
         To compile this driver as a module, choose M here: the
         module will be called vfio_ccw.
+config VFIO_AP_MATRIX
+    def_tristate m
+    prompt "Support for Adjunct Processor Matrix device interface"
Quoted 8 lines

arch/s390/Kconfig config VFIO_CCW · line 733

Quoted 6 lines
arch/s390/Kconfig +6 -0
+    depends on ZCRYPT
+    select VFIO
+    select MDEV
+    select VFIO_MDEV
+    select VFIO_MDEV_DEVICE
+    select IOMMU_API  

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

Quoted 3 lines

It's ironic because I originally changed from using 'depends on' and changed it based on review comments made
on our internal mailing list. I'll go with 'depends on'.

Is doing like the others a sufficient good reason? What if the first who did this did not really think about it?

When an administrator configure the kernel what does he think?

- I want to have AP through AP_VFIO in my guests
and he get implicitly VFIO
or
- I want to have VFIO
and he has to explicitly add AP_VFIO too

Quoted 4 lines

It seems to me that the first is much more user friendly.

Please tell me if I missed something. dependencies? collateral damages? my logic is wrong?

Using select for anything that's not a simple infrastructure dependency may lead into trouble (we've had issues in the past where options tried to enable other options but missed dependencies).

Quoted 8 lines
Quoted 5 lines

If a user wants to use vfio-ap, I think it is reasonable to expect them to figure out that they need both ap and vfio for that.

[And config help has gotten much better than it was years ago; it's not that hard to figure out what is actually needed.]

Is it sufficient to specify 'depends on ZCRYPT && VFIO_MDEV_DEVICE' since 'VFIO_MDEV_DEVICE depends on VFIO && VFIO_MDEV' and 'VFIO_MDEV depends on VFIO' and 'VFIO depends on IOMMU_API'?

Perhaps ZCRYPT && VFIO_MDEV && VFIO_MDEV_DEVICE, to make it a bit more obvious?

[Also, is IOMMU_API only needed to satisfy dependencies?]

#30 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 54 lines · Cornelia Huck
Quoted 51 lines · On Thu, 16 Nov 2017 09:25:27 -0500 Tony Krowiak <[email protected]>…
Quoted 50 lines · Cornelia Huck
Quoted 36 lines · On Thu, 16 Nov 2017 13:02:26 +0100 Pierre Morel <[email protected]>…
Quoted 21 lines · Tony Krowiak
Quoted 12 lines · Cornelia Huck
Quoted 10 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
arch/s390/Kconfig +3 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW
          To compile this driver as a module, choose M here: the
          module will be called vfio_ccw.
+config VFIO_AP_MATRIX
+    def_tristate m
+    prompt "Support for Adjunct Processor Matrix device interface"
Quoted 8 lines

arch/s390/Kconfig config VFIO_CCW · line 732

Quoted 6 lines
arch/s390/Kconfig +6 -0
+    depends on ZCRYPT
+    select VFIO
+    select MDEV
+    select VFIO_MDEV
+    select VFIO_MDEV_DEVICE
+    select IOMMU_API

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

Quoted 3 lines

It's ironic because I originally changed from using 'depends on' and changed it based on review comments made
on our internal mailing list. I'll go with 'depends on'.

Is doing like the others a sufficient good reason? What if the first who did this did not really think about it?

When an administrator configure the kernel what does he think?

- I want to have AP through AP_VFIO in my guests
and he get implicitly VFIO
or
- I want to have VFIO
and he has to explicitly add AP_VFIO too

Quoted 4 lines

It seems to me that the first is much more user friendly.

Please tell me if I missed something. dependencies? collateral damages? my logic is wrong?

Using select for anything that's not a simple infrastructure dependency may lead into trouble (we've had issues in the past where options tried to enable other options but missed dependencies).

If a user wants to use vfio-ap, I think it is reasonable to expect them to figure out that they need both ap and vfio for that.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

[And config help has gotten much better than it was years ago; it's not that hard to figure out what is actually needed.]

Is it sufficient to specify 'depends on ZCRYPT && VFIO_MDEV_DEVICE' since 'VFIO_MDEV_DEVICE depends on VFIO && VFIO_MDEV' and 'VFIO_MDEV depends on VFIO' and 'VFIO depends on IOMMU_API'?

Perhaps ZCRYPT && VFIO_MDEV && VFIO_MDEV_DEVICE, to make it a bit more obvious?

Sure, why not.

Quoted 2 lines

[Also, is IOMMU_API only needed to satisfy dependencies?]

Yes, VFIO is dependent upon it.

Quoted 1 line
#31 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

Quoted 4 lines · On Fri, 17 Nov 2017 16:13:45 -0500 Tony Krowiak <[email protected]>…
Quoted 1 line · Cornelia Huck

[Also, is IOMMU_API only needed to satisfy dependencies?]

Yes, VFIO is dependent upon it.

Ah, my question was more whether we just need to make sure the api is there, but do not need to implement anything.

#32 lore raw

Re: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver

In reply to Cornelia Huck
Quoted 41 lines · Cornelia Huck
Quoted 38 lines · On Thu, 16 Nov 2017 13:02:26 +0100 Pierre Morel <[email protected]>…
Quoted 22 lines · Tony Krowiak
Quoted 13 lines · Cornelia Huck
Quoted 10 lines · On Fri, 13 Oct 2017 13:38:50 -0400 Tony Krowiak <[email protected]>…
arch/s390/Kconfig +3 -0
index 48af970..411c19a 100644
@@ -722,6 +722,19 @@ config VFIO_CCW
         To compile this driver as a module, choose M here: the
         module will be called vfio_ccw.
+config VFIO_AP_MATRIX
+    def_tristate m
+    prompt "Support for Adjunct Processor Matrix device interface"
Quoted 8 lines

arch/s390/Kconfig config VFIO_CCW · line 733

Quoted 6 lines
arch/s390/Kconfig +6 -0
+    depends on ZCRYPT
+    select VFIO
+    select MDEV
+    select VFIO_MDEV
+    select VFIO_MDEV_DEVICE
+    select IOMMU_API

I think the more common pattern is to depend on the VFIO configs instead of selecting them.

Quoted 3 lines

It's ironic because I originally changed from using 'depends on' and changed it based on review comments made
on our internal mailing list. I'll go with 'depends on'.

Is doing like the others a sufficient good reason? What if the first who did this did not really think about it?

When an administrator configure the kernel what does he think?

- I want to have AP through AP_VFIO in my guests
and he get implicitly VFIO
or
- I want to have VFIO
and he has to explicitly add AP_VFIO too

Quoted 8 lines
Quoted 4 lines

It seems to me that the first is much more user friendly.

Please tell me if I missed something. dependencies? collateral damages? my logic is wrong?

Using select for anything that's not a simple infrastructure dependency may lead into trouble (we've had issues in the past where options tried to enable other options but missed dependencies).

Understood, using dependencies is safer against a third party introducing a bug that would add a dependency to a member of the list but not update our list of selections.

Quoted 7 lines

If a user wants to use vfio-ap, I think it is reasonable to expect them to figure out that they need both ap and vfio for that.

[And config help has gotten much better than it was years ago; it's not that hard to figure out what is actually needed.]

OK for Darwin selection for admins, (a gentle Darwin :) I acknowledge) and on our side we spare to us running after our disappeared AP VFIO.

Regards,

Pierre

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

RFC 6/19 s390/zcrypt: register matrix device with VFIO mediated device framework

In reply to Tony Krowiak

Registers the matrix device created by the AP matrix bus with the VFIO mediated device framework. Registering the matrix device will create the sysfs structures needed to create mediated matrix devices that can be configured with a matrix of adapters, usage domains and control domains for a guest machine.

Registering the matrix device with the VFIO mediated device framework will create the following sysfs structures:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ available_instances
............ create
............ device_api
............ [devices]
............ name

To create a mediated device for the AP matrix device, write a UUID to the create file:

uuidgen > create

A symbolic link to the mediated device's directory will be created in the devices subdirectory named after the generated $uuid:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
............... [$uuid]

---
 MAINTAINERS                                  |    1 +
 drivers/s390/crypto/Makefile                 |    2 +-
 drivers/s390/crypto/ap_matrix_bus.c          |    1 +
 drivers/s390/crypto/ap_matrix_bus.h          |    4 +
 drivers/s390/crypto/vfio_ap_matrix_drv.c     |    5 +
 drivers/s390/crypto/vfio_ap_matrix_ops.c     |  172 ++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_matrix_private.h |    3 +
 include/uapi/linux/vfio.h                    |    1 +
 8 files changed, 188 insertions(+), 1 deletions(-)
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_ops.c
MAINTAINERS +1 -0
index 115965e..0c8855a 100644
@@ -11720,6 +11720,7 @@ F:	drivers/s390/crypto/ap_matrix_bus.h
 F:	drivers/s390/crypto/ap_matrix_bus.c
 F:	drivers/s390/crypto/vfio_ap_matrix_drv.c
 F:	drivers/s390/crypto/vfio_ap_matrix_private.h
+F:	drivers/s390/crypto/vfio_ap_matrix_ops.c
 
 S390 ZFCP DRIVER
 M:	Steffen Maier <[email protected]>
drivers/s390/crypto/Makefile +1 -1
index 1983afa..b2545c8 100644
@@ -16,5 +16,5 @@ pkey-objs := pkey_api.o
 obj-$(CONFIG_PKEY) += pkey.o
 
 # adjunct processor matrix
-vfio_ap_matrix-objs := vfio_ap_matrix_drv.o
+vfio_ap_matrix-objs := vfio_ap_matrix_drv.o vfio_ap_matrix_ops.o
 obj-$(CONFIG_VFIO_AP_MATRIX) += vfio_ap_matrix.o
drivers/s390/crypto/ap_matrix_bus.c +1 -0
index 66bfa54..418c23b 100644
@@ -61,6 +61,7 @@ static int ap_matrix_dev_create(void)
 	matrix->device.bus = &ap_matrix_bus_type;
 	matrix->device.parent = ap_matrix_root_device;
 	matrix->device.release = ap_matrix_dev_release;
+	INIT_LIST_HEAD(&matrix->queues);
 
 	ret = device_register(&matrix->device);
 	if (ret) {
drivers/s390/crypto/ap_matrix_bus.h +4 -0
index c2aff23..3eccc36 100644
@@ -12,8 +12,12 @@
 
 #include <linux/device.h>
 
+#include "ap_bus.h"
+
 struct ap_matrix {
 	struct device device;
+	spinlock_t qlock;
+	struct list_head queues;
 };
 
 struct ap_matrix *ap_matrix_get_device(void);
drivers/s390/crypto/vfio_ap_matrix_drv.c +5 -0
index 760ed56..664d2f7 100644
@@ -90,11 +90,16 @@ int __init ap_matrix_init(void)
 	if (ret)
 		return ret;
 
+	ret = ap_matrix_mdev_register(vfio_ap_matrix_drv.ap_matrix);
+	if (ret)
+		ap_driver_unregister(&vfio_ap_matrix_drv.ap_drv);
+
 	return ret;
 }
 
 void __exit ap_matrix_exit(void)
 {
+	ap_matrix_mdev_unregister(vfio_ap_matrix_drv.ap_matrix);
 	ap_driver_unregister(&vfio_ap_matrix_drv.ap_drv);
 }
 
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +172 -0

172 lines not on this page · raw message

drivers/s390/crypto/vfio_ap_matrix_private.h +3 -0
index 11c5e02..5c82bea 100644
@@ -44,4 +44,7 @@ struct vfio_ap_queue {
 	return NULL;
 }
 
+extern int ap_matrix_mdev_register(struct ap_matrix *ap_matrix);
+extern void ap_matrix_mdev_unregister(struct ap_matrix *ap_matrix);
+
 #endif /* _VFIO_AP_PRIVATE_H_ */
include/uapi/linux/vfio.h +1 -0
index ae46105..743456f 100644
@@ -214,6 +214,7 @@ struct vfio_device_info {
 #define VFIO_DEVICE_API_PLATFORM_STRING		"vfio-platform"
 #define VFIO_DEVICE_API_AMBA_STRING		"vfio-amba"
 #define VFIO_DEVICE_API_CCW_STRING		"vfio-ccw"
+#define VFIO_DEVICE_API_AP_MATRIX_STRING	"vfio-ap-matrix"
 
 /**
  * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8,
Signature · 1 line
1.7.1
#34 lore raw

Re: [RFC 06/19] s390/zcrypt: register matrix device with VFIO mediated device framework

Quoted 19 lines · On Fri, 13 Oct 2017 13:38:51 -0400 Tony Krowiak <[email protected]>…
drivers/s390/crypto/ap_matrix_bus.c +1 -0
index 66bfa54..418c23b 100644
@@ -61,6 +61,7 @@ static int ap_matrix_dev_create(void)
 	matrix->device.bus = &ap_matrix_bus_type;
 	matrix->device.parent = ap_matrix_root_device;
 	matrix->device.release = ap_matrix_dev_release;
+	INIT_LIST_HEAD(&matrix->queues);
 
 	ret = device_register(&matrix->device);
 	if (ret) {
drivers/s390/crypto/ap_matrix_bus.h +0 -0
index c2aff23..3eccc36 100644
@@ -12,8 +12,12 @@
 
 #include <linux/device.h>

drivers/s390/crypto/ap_matrix_bus.h line 23

Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.h +4 -0
 
+#include "ap_bus.h"
+
 struct ap_matrix {
 	struct device device;
+	spinlock_t qlock;
+	struct list_head queues;
 };
 
 struct ap_matrix *ap_matrix_get_device(void);

Move these two hunks into patch #5 please. Yes, strictly speaking the two elements in the struct ap_matrix are needed only with patch #6, but it is fine to introduce an element with a new driver that is only exploited with a later patch.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#35 lore raw

Re: [RFC 06/19] s390/zcrypt: register matrix device with VFIO mediated device framework

Quoted 31 lines · Martin Schwidefsky
Quoted 28 lines · On Fri, 13 Oct 2017 13:38:51 -0400 Tony Krowiak <[email protected]>…
drivers/s390/crypto/ap_matrix_bus.c +1 -0
index 66bfa54..418c23b 100644
@@ -61,6 +61,7 @@ static int ap_matrix_dev_create(void)
  	matrix->device.bus = &ap_matrix_bus_type;
  	matrix->device.parent = ap_matrix_root_device;
  	matrix->device.release = ap_matrix_dev_release;
+	INIT_LIST_HEAD(&matrix->queues);
 
  	ret = device_register(&matrix->device);
  	if (ret) {
drivers/s390/crypto/ap_matrix_bus.h +4 -0
index c2aff23..3eccc36 100644
@@ -12,8 +12,12 @@
 
  #include <linux/device.h>
 
+#include "ap_bus.h"
+
  struct ap_matrix {
  	struct device device;
+	spinlock_t qlock;
+	struct list_head queues;
  };
 
Quoted 4 lines

drivers/s390/crypto/ap_matrix_bus.h line 23

Quoted 1 line
drivers/s390/crypto/ap_matrix_bus.h +0 -0
  struct ap_matrix *ap_matrix_get_device(void);

Move these two hunks into patch #5 please. Yes, strictly speaking the two elements in the struct ap_matrix are needed only with patch #6, but it is fine to introduce an element with a new driver that is only exploited with a later patch.

Will do.

Quoted 1 line
#36 lore raw

Re: [RFC 06/19] s390/zcrypt: register matrix device with VFIO mediated device framework

In reply to Tony Krowiak
Quoted 54 lines · On Fri, 13 Oct 2017 13:38:51 -0400 Tony Krowiak <[email protected]>…

Registers the matrix device created by the AP matrix bus with the VFIO mediated device framework. Registering the matrix device will create the sysfs structures needed to create mediated matrix devices that can be configured with a matrix of adapters, usage domains and control domains for a guest machine.

Registering the matrix device with the VFIO mediated device framework will create the following sysfs structures:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ available_instances
............ create
............ device_api
............ [devices]
............ name

To create a mediated device for the AP matrix device, write a UUID to the create file:

uuidgen > create

A symbolic link to the mediated device's directory will be created in the devices subdirectory named after the generated $uuid:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
............... [$uuid]

---
 MAINTAINERS                                  |    1 +
 drivers/s390/crypto/Makefile                 |    2 +-
 drivers/s390/crypto/ap_matrix_bus.c          |    1 +
 drivers/s390/crypto/ap_matrix_bus.h          |    4 +
 drivers/s390/crypto/vfio_ap_matrix_drv.c     |    5 +
 drivers/s390/crypto/vfio_ap_matrix_ops.c     |  172 ++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_matrix_private.h |    3 +
 include/uapi/linux/vfio.h                    |    1 +
 8 files changed, 188 insertions(+), 1 deletions(-)
 create mode 100644 drivers/s390/crypto/vfio_ap_matrix_ops.c
drivers/s390/crypto/ap_matrix_bus.c +0 -0
index 66bfa54..418c23b 100644

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 64

Quoted 4 lines
drivers/s390/crypto/ap_matrix_bus.c +1 -0
@@ -61,6 +61,7 @@ static int ap_matrix_dev_create(void)
 	matrix->device.bus = &ap_matrix_bus_type;
 	matrix->device.parent = ap_matrix_root_device;
 	matrix->device.release = ap_matrix_dev_release;
+	INIT_LIST_HEAD(&matrix->queues);

Don't you also need to init the spin lock?

drivers/s390/crypto/ap_matrix_bus.h line 15

Quoted 12 lines
drivers/s390/crypto/ap_matrix_bus.c +0 -0
 	ret = device_register(&matrix->device);
 	if (ret) {
drivers/s390/crypto/ap_matrix_bus.h +1 -0
index c2aff23..3eccc36 100644
@@ -12,8 +12,12 @@
 
 #include <linux/device.h>
 
+#include "ap_bus.h"

Why do you need this include now? (IOW, does that need to go into another patch?)

Quoted 36 lines
drivers/s390/crypto/ap_matrix_bus.h +3 -0
+
 struct ap_matrix {
 	struct device device;
+	spinlock_t qlock;
+	struct list_head queues;
 };
 
 struct ap_matrix *ap_matrix_get_device(void);
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +21 -0
new file mode 100644
index 0000000..7d01f18
@@ -0,0 +1,172 @@
+/*
+ * Adjunct processor matrix VFIO device driver callbacks.
+ *
+ * Copyright IBM Corp. 2017
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ */
+#include <asm/ap-config.h>
+#include <linux/string.h>
+#include <linux/vfio.h>
+#include <linux/mdev.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+
+#include "vfio_ap_matrix_private.h"
+
+#define AP_MATRIX_MDEV_TYPE_HWVIRT "passthrough"
+#define AP_MATRIX_MDEV_NAME_HWVIRT "AP Matrix Passthrough Device"
+
+#define AP_MATRIX_MAX_AVAILABLE_INSTANCES	255

drivers/s390/crypto/vfio_ap_matrix_ops.c line 31

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +10 -0
+
+struct ap_matrix_mdev {
+	struct mdev_device *mdev;
+	struct list_head node;
+};
+
+struct ap_matrix	*matrix;
+struct mutex		mdev_devices_lock;
+struct list_head	mdev_devices;
+int			available_instances;

Having this as a global variable feels wrong. I see that vfio-ccw keeps things like this in driver data attached to its parent. Can you do something like that as well?

Quoted 12 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +12 -0
+
+static struct ap_matrix_mdev *ap_matrix_mdev_find_by_uuid(uuid_le uuid)
+{
+	struct ap_matrix_mdev *matrix_mdev;
+
+	list_for_each_entry(matrix_mdev, &mdev_devices, node) {
+		if (uuid_le_cmp(mdev_uuid(matrix_mdev->mdev), uuid) == 0)
+			return matrix_mdev;
+	}
+
+	return NULL;
+}

(...)

drivers/s390/crypto/vfio_ap_matrix_ops.c line 155

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +10 -0
+int ap_matrix_mdev_register(struct ap_matrix *ap_matrix)
+{
+	int ret;
+	struct device *dev = &ap_matrix->device;
+
+	ret = mdev_register_device(dev, &vfio_ap_matrix_ops);
+	if (ret)
+		return ret;
+
+	matrix = ap_matrix;

I'd just grab the (one) matrix device here...

drivers/s390/crypto/vfio_ap_matrix_ops.c line 167

Quoted 12 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +12 -0
+	mutex_init(&mdev_devices_lock);
+	INIT_LIST_HEAD(&mdev_devices);
+	available_instances = AP_MATRIX_MAX_AVAILABLE_INSTANCES;
+
+	return 0;
+}
+
+void ap_matrix_mdev_unregister(struct ap_matrix *ap_matrix)
+{
+	struct device *dev;
+
+	if (ap_matrix == matrix) {

...and lose this extra if.

Quoted 5 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +5 -0
+		dev = &matrix->device;
+		available_instances--;
+		mdev_unregister_device(dev);
+	}
+}
#37 lore raw

Re: [RFC 06/19] s390/zcrypt: register matrix device with VFIO mediated device framework

Quoted 51 lines · Cornelia Huck
Quoted 48 lines · On Fri, 13 Oct 2017 13:38:51 -0400 Tony Krowiak <[email protected]>…

Registers the matrix device created by the AP matrix bus with the VFIO mediated device framework. Registering the matrix device will create the sysfs structures needed to create mediated matrix devices that can be configured with a matrix of adapters, usage domains and control domains for a guest machine.

Registering the matrix device with the VFIO mediated device framework will create the following sysfs structures:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ available_instances
............ create
............ device_api
............ [devices]
............ name

To create a mediated device for the AP matrix device, write a UUID to the create file:

uuidgen > create

A symbolic link to the mediated device's directory will be created in the devices subdirectory named after the generated $uuid:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
............... [$uuid]

---
  MAINTAINERS                                  |    1 +
  drivers/s390/crypto/Makefile                 |    2 +-
  drivers/s390/crypto/ap_matrix_bus.c          |    1 +
  drivers/s390/crypto/ap_matrix_bus.h          |    4 +
  drivers/s390/crypto/vfio_ap_matrix_drv.c     |    5 +
  drivers/s390/crypto/vfio_ap_matrix_ops.c     |  172 ++++++++++++++++++++++++++
  drivers/s390/crypto/vfio_ap_matrix_private.h |    3 +
  include/uapi/linux/vfio.h                    |    1 +
  8 files changed, 188 insertions(+), 1 deletions(-)

create mode 100644 drivers/s390/crypto/vfio_ap_matrix_ops.c

Quoted 10 lines

drivers/s390/crypto/ap_matrix_bus.c static int ap_matrix_dev_create(void) · line 64

Quoted 9 lines
drivers/s390/crypto/ap_matrix_bus.c +1 -0
index 66bfa54..418c23b 100644
@@ -61,6 +61,7 @@ static int ap_matrix_dev_create(void)
  	matrix->device.bus = &ap_matrix_bus_type;
  	matrix->device.parent = ap_matrix_root_device;
  	matrix->device.release = ap_matrix_dev_release;
+	INIT_LIST_HEAD(&matrix->queues);

Don't you also need to init the spin lock?

Yes, but note that I am getting rid of the AP matrix bus - as we discussed earlier - so this code will be moved to the AP matrix driver.

Quoted 10 lines
Quoted 10 lines
drivers/s390/crypto/ap_matrix_bus.c +0 -0
  	ret = device_register(&matrix->device);
  	if (ret) {
drivers/s390/crypto/ap_matrix_bus.h +0 -0
index c2aff23..3eccc36 100644
@@ -12,8 +12,12 @@
 
Quoted 5 lines

drivers/s390/crypto/ap_matrix_bus.h line 15

Quoted 3 lines
drivers/s390/crypto/ap_matrix_bus.h +1 -0
  #include <linux/device.h>
 
+#include "ap_bus.h"

Why do you need this include now? (IOW, does that need to go into another patch?)

It is not needed here, but as discussed earlier, the AP matrix bus is going away.

Quoted 41 lines
Quoted 41 lines
drivers/s390/crypto/ap_matrix_bus.h +3 -0
+
  struct ap_matrix {
  	struct device device;
+	spinlock_t qlock;
+	struct list_head queues;
  };
 
  struct ap_matrix *ap_matrix_get_device(void);
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +26 -0
new file mode 100644
index 0000000..7d01f18
@@ -0,0 +1,172 @@
+/*
+ * Adjunct processor matrix VFIO device driver callbacks.
+ *
+ * Copyright IBM Corp. 2017
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ */
+#include <asm/ap-config.h>
+#include <linux/string.h>
+#include <linux/vfio.h>
+#include <linux/mdev.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+
+#include "vfio_ap_matrix_private.h"
+
+#define AP_MATRIX_MDEV_TYPE_HWVIRT "passthrough"
+#define AP_MATRIX_MDEV_NAME_HWVIRT "AP Matrix Passthrough Device"
+
+#define AP_MATRIX_MAX_AVAILABLE_INSTANCES	255
+
+struct ap_matrix_mdev {
+	struct mdev_device *mdev;
+	struct list_head node;
+};
Quoted 8 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c line 31

Quoted 5 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +5 -0
+
+struct ap_matrix	*matrix;
+struct mutex		mdev_devices_lock;
+struct list_head	mdev_devices;
+int			available_instances;

Having this as a global variable feels wrong. I see that vfio-ccw keeps things like this in driver data attached to its parent. Can you do something like that as well?

I am moving all of these variables into struct ap_matrix. The matrix device will be stored as driver data for the device so it will be retrievable by the mdev functions. This will eliminate the need for these globals and also omit the need to store a reference to the matrix device in multiple places.

Quoted 15 lines
Quoted 13 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +12 -0
+
+static struct ap_matrix_mdev *ap_matrix_mdev_find_by_uuid(uuid_le uuid)
+{
+	struct ap_matrix_mdev *matrix_mdev;
+
+	list_for_each_entry(matrix_mdev, &mdev_devices, node) {
+		if (uuid_le_cmp(mdev_uuid(matrix_mdev->mdev), uuid) == 0)
+			return matrix_mdev;
+	}
+
+	return NULL;
+}

(...)

Quoted 11 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c line 155

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +10 -0
+int ap_matrix_mdev_register(struct ap_matrix *ap_matrix)
+{
+	int ret;
+	struct device *dev = &ap_matrix->device;
+
+	ret = mdev_register_device(dev, &vfio_ap_matrix_ops);
+	if (ret)
+		return ret;
+
+	matrix = ap_matrix;

I'd just grab the (one) matrix device here...

I am changing this so the matrix device will be stored as driver data with the device:

dev_set_drvdata(dev)

Quoted 14 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c line 167

Quoted 13 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +12 -0
+	mutex_init(&mdev_devices_lock);
+	INIT_LIST_HEAD(&mdev_devices);
+	available_instances = AP_MATRIX_MAX_AVAILABLE_INSTANCES;
+
+	return 0;
+}
+
+void ap_matrix_mdev_unregister(struct ap_matrix *ap_matrix)
+{
+	struct device *dev;
+
+	if (ap_matrix == matrix) {

...and lose this extra if.

It is going bye bye.

Quoted 6 lines
Quoted 6 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c new file +5 -0
+		dev = &matrix->device;
+		available_instances--;
+		mdev_unregister_device(dev);
+	}
+}
#38 lore raw

RFC 7/19 KVM: s390: introduce AP matrix configuration interface

In reply to Tony Krowiak

This patch introduces a new compilation unit that will contain all of the data structures and logic for configuring AP adapters, usage domains and control domains for a KVM guest.

---
 MAINTAINERS                       |    2 ++
 arch/s390/include/asm/ap-config.h |   12 ++++++++++++
 arch/s390/kvm/Makefile            |    2 +-
 arch/s390/kvm/ap-config.c         |    9 +++++++++
 4 files changed, 24 insertions(+), 1 deletions(-)
 create mode 100644 arch/s390/include/asm/ap-config.h
 create mode 100644 arch/s390/kvm/ap-config.c
MAINTAINERS +2 -0
index 0c8855a..4de0904 100644
@@ -11721,6 +11721,8 @@ F:	drivers/s390/crypto/ap_matrix_bus.c
 F:	drivers/s390/crypto/vfio_ap_matrix_drv.c
 F:	drivers/s390/crypto/vfio_ap_matrix_private.h
 F:	drivers/s390/crypto/vfio_ap_matrix_ops.c
+F:	arch/s390/include/asm/kvm/ap-config.h
+F:	arch/s390/kvm/ap-config.c
 
 S390 ZFCP DRIVER
 M:	Steffen Maier <[email protected]>
arch/s390/include/asm/ap-config.h new file +12 -0
new file mode 100644
index 0000000..8491b5f
@@ -0,0 +1,12 @@
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#ifndef _ASM_KVM_AP_CONFIG_H_
+#define _ASM_KVM_AP_CONFIG_H_
+
+#endif /* _ASM_KVM_AP_CONFIG_H_ */
arch/s390/kvm/Makefile +1 -1
index 09a9e6d..0397b9c 100644
@@ -12,6 +12,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o  $(KVM)/async_pf.o $(KVM)/irqch
 ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
 
 kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o
-kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o
+kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o ap-config.o
 
 obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/ap-config.c new file +9 -0
new file mode 100644
index 0000000..84fdf43
@@ -0,0 +1,9 @@
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#include <asm/ap-config.h>
Signature · 1 line
1.7.1
#39 lore raw

Re: [RFC 07/19] KVM: s390: introduce AP matrix configuration interface

Quoted 63 lines · On Fri, 13 Oct 2017 13:38:52 -0400 Tony Krowiak <[email protected]>…

This patch introduces a new compilation unit that will contain all of the data structures and logic for configuring AP adapters, usage domains and control domains for a KVM guest.

---
 MAINTAINERS                       |    2 ++
 arch/s390/include/asm/ap-config.h |   12 ++++++++++++
 arch/s390/kvm/Makefile            |    2 +-
 arch/s390/kvm/ap-config.c         |    9 +++++++++
 4 files changed, 24 insertions(+), 1 deletions(-)
 create mode 100644 arch/s390/include/asm/ap-config.h
 create mode 100644 arch/s390/kvm/ap-config.c
MAINTAINERS +2 -0
index 0c8855a..4de0904 100644
@@ -11721,6 +11721,8 @@ F:	drivers/s390/crypto/ap_matrix_bus.c
 F:	drivers/s390/crypto/vfio_ap_matrix_drv.c
 F:	drivers/s390/crypto/vfio_ap_matrix_private.h
 F:	drivers/s390/crypto/vfio_ap_matrix_ops.c
+F:	arch/s390/include/asm/kvm/ap-config.h
+F:	arch/s390/kvm/ap-config.c
 
 S390 ZFCP DRIVER
 M:	Steffen Maier <[email protected]>
arch/s390/include/asm/ap-config.h new file +12 -0
new file mode 100644
index 0000000..8491b5f
@@ -0,0 +1,12 @@
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#ifndef _ASM_KVM_AP_CONFIG_H_
+#define _ASM_KVM_AP_CONFIG_H_
+
+#endif /* _ASM_KVM_AP_CONFIG_H_ */
arch/s390/kvm/Makefile +1 -1
index 09a9e6d..0397b9c 100644
@@ -12,6 +12,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o  $(KVM)/async_pf.o $(KVM)/irqch
 ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
 
 kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o
-kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o
+kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o ap-config.o
 
 obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/ap-config.c new file +0 -0
new file mode 100644
index 0000000..84fdf43

arch/s390/kvm/ap-config.c line 9

Quoted 9 lines
arch/s390/kvm/ap-config.c new file +9 -0
@@ -0,0 +1,9 @@
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#include <asm/ap-config.h>

Another patch that introduces empty files. Please don't do that. Merge patch #7 with patch #16. With the dependency in patch #8 on the ap-config.h header the new place for the combined patch would be prior to patch #8.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#40 lore raw

Re: [RFC 07/19] KVM: s390: introduce AP matrix configuration interface

Quoted 70 lines · Martin Schwidefsky
Quoted 67 lines · On Fri, 13 Oct 2017 13:38:52 -0400 Tony Krowiak <[email protected]>…

This patch introduces a new compilation unit that will contain all of the data structures and logic for configuring AP adapters, usage domains and control domains for a KVM guest.

---
  MAINTAINERS                       |    2 ++
  arch/s390/include/asm/ap-config.h |   12 ++++++++++++
  arch/s390/kvm/Makefile            |    2 +-
  arch/s390/kvm/ap-config.c         |    9 +++++++++
  4 files changed, 24 insertions(+), 1 deletions(-)

create mode 100644 arch/s390/include/asm/ap-config.h create mode 100644 arch/s390/kvm/ap-config.c

MAINTAINERS +2 -0
index 0c8855a..4de0904 100644
@@ -11721,6 +11721,8 @@ F:	drivers/s390/crypto/ap_matrix_bus.c
  F:	drivers/s390/crypto/vfio_ap_matrix_drv.c
  F:	drivers/s390/crypto/vfio_ap_matrix_private.h
  F:	drivers/s390/crypto/vfio_ap_matrix_ops.c
+F:	arch/s390/include/asm/kvm/ap-config.h
+F:	arch/s390/kvm/ap-config.c
 
  S390 ZFCP DRIVER
  M:	Steffen Maier <[email protected]>
arch/s390/include/asm/ap-config.h new file +12 -0
new file mode 100644
index 0000000..8491b5f
@@ -0,0 +1,12 @@
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#ifndef _ASM_KVM_AP_CONFIG_H_
+#define _ASM_KVM_AP_CONFIG_H_
+
+#endif /* _ASM_KVM_AP_CONFIG_H_ */
arch/s390/kvm/Makefile +1 -1
index 09a9e6d..0397b9c 100644
@@ -12,6 +12,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o  $(KVM)/async_pf.o $(KVM)/irqch
  ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
 
  kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o
-kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o
+kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o ap-config.o
 
  obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/ap-config.c new file +4 -0
new file mode 100644
index 0000000..84fdf43
@@ -0,0 +1,9 @@
+/*
+ * Adjunct Processor (AP) configuration management for KVM guests
+ *
+ * Copyright IBM Corp. 2017
Quoted 8 lines

arch/s390/kvm/ap-config.c line 9

Quoted 5 lines
arch/s390/kvm/ap-config.c new file +5 -0
+ *
+ * Author(s): Tony Krowiak <[email protected]>
+ */
+
+#include <asm/ap-config.h>

Another patch that introduces empty files. Please don't do that. Merge patch #7 with patch #16. With the dependency in patch #8 on the ap-config.h header the new place for the combined patch would be prior to patch #8.

Sounds reasonable, will do.

Quoted 1 line
#41 lore raw

Re: [RFC 07/19] KVM: s390: introduce AP matrix configuration interface

In reply to Tony Krowiak
Quoted 5 lines · On Fri, 13 Oct 2017 13:38:52 -0400 Tony Krowiak <[email protected]>…

This patch introduces a new compilation unit that will contain all of the data structures and logic for configuring AP adapters, usage domains and control domains for a KVM guest.

Quoted 8 lines
---
 MAINTAINERS                       |    2 ++
 arch/s390/include/asm/ap-config.h |   12 ++++++++++++
 arch/s390/kvm/Makefile            |    2 +-
 arch/s390/kvm/ap-config.c         |    9 +++++++++
 4 files changed, 24 insertions(+), 1 deletions(-)
 create mode 100644 arch/s390/include/asm/ap-config.h
 create mode 100644 arch/s390/kvm/ap-config.c

This is a bit useless on its own... merge this with the actual implementation?

#42 lore raw

Re: [RFC 07/19] KVM: s390: introduce AP matrix configuration interface

Quoted 16 lines · Cornelia Huck
Quoted 5 lines · On Fri, 13 Oct 2017 13:38:52 -0400 Tony Krowiak <[email protected]>…

This patch introduces a new compilation unit that will contain all of the data structures and logic for configuring AP adapters, usage domains and control domains for a KVM guest.

Quoted 8 lines
---
  MAINTAINERS                       |    2 ++
  arch/s390/include/asm/ap-config.h |   12 ++++++++++++
  arch/s390/kvm/Makefile            |    2 +-
  arch/s390/kvm/ap-config.c         |    9 +++++++++
  4 files changed, 24 insertions(+), 1 deletions(-)

create mode 100644 arch/s390/include/asm/ap-config.h create mode 100644 arch/s390/kvm/ap-config.c

Quoted 2 lines

This is a bit useless on its own... merge this with the actual implementation?

I agree, I'm going to squash patches 7 and 8

Quoted 1 line
#43 lore raw

RFC 8/19 s390/zcrypt: support for assigning adapters to matrix mdev

In reply to Tony Krowiak

Provides the sysfs interfaces for assigning an adapter to and unassigning an AP adapter from a mediated matrix device.

The IDs of the AP adapters assigned to the mediated matrix device are stored in a bit mask. The bits in the mask, from left to right, correspond to AP adapter numbers 0 to 255. The bit corresponding to the ID of the adapter being assigned will be set in the bit mask.

The relevant sysfs structures are:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
...............[$uuid]
.................. adapters
.................. assign_adapter
.................. unassign_adapter

To assign an adapter to the $uuid mediated matrix device, write ID of the adapter (hex value) to the assign_adapter file. To unassign an adapter, write the ID of the adapter (hex value) to the unassign_adapter file. The list of adapters that have been assigned can be viewed by displaying the contents of the adapters file.

For example, to assign adapter 0xad to mediated matrix device $uuid:

echo ad > assign_adapter

To unassign adapter 0xad:

echo ad > unassign_adapter

To see the list of adapters assigned:

cat adapters

---
 arch/s390/include/asm/ap-config.h        |   13 +++
 drivers/s390/crypto/vfio_ap_matrix_ops.c |  147 ++++++++++++++++++++++++++++++
 2 files changed, 160 insertions(+), 0 deletions(-)
arch/s390/include/asm/ap-config.h +13 -0
index 8491b5f..3064215 100644
@@ -9,4 +9,17 @@
 #ifndef _ASM_KVM_AP_CONFIG_H_
 #define _ASM_KVM_AP_CONFIG_H_
 
+#include <linux/types.h>
+
+#define AP_MATRIX_MAX_MASK_BITS		256
+#define AP_MATRIX_MASK_INDICES		(AP_MATRIX_MAX_MASK_BITS / \
+					(sizeof(u64) * 8))
+#define AP_MATRIX_MAX_MASK_BYTES	(AP_MATRIX_MASK_INDICES * sizeof(u64))
+
+struct ap_config_masks {
+	u64 apm[AP_MATRIX_MASK_INDICES];
+	u64 aqm[AP_MATRIX_MASK_INDICES];
+	u64 adm[AP_MATRIX_MASK_INDICES];
+};
+
 #endif /* _ASM_KVM_AP_CONFIG_H_ */
drivers/s390/crypto/vfio_ap_matrix_ops.c +147 -0

162 lines not on this page · raw message

Signature · 1 line
1.7.1
#44 lore raw

Re: [RFC 08/19] s390/zcrypt: support for assigning adapters to matrix mdev

Quoted 65 lines · On Fri, 13 Oct 2017 13:38:53 -0400 Tony Krowiak <[email protected]>…

Provides the sysfs interfaces for assigning an adapter to and unassigning an AP adapter from a mediated matrix device.

The IDs of the AP adapters assigned to the mediated matrix device are stored in a bit mask. The bits in the mask, from left to right, correspond to AP adapter numbers 0 to 255. The bit corresponding to the ID of the adapter being assigned will be set in the bit mask.

The relevant sysfs structures are:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
...............[$uuid]
.................. adapters
.................. assign_adapter
.................. unassign_adapter

To assign an adapter to the $uuid mediated matrix device, write ID of the adapter (hex value) to the assign_adapter file. To unassign an adapter, write the ID of the adapter (hex value) to the unassign_adapter file. The list of adapters that have been assigned can be viewed by displaying the contents of the adapters file.

For example, to assign adapter 0xad to mediated matrix device $uuid:

echo ad > assign_adapter

To unassign adapter 0xad:

echo ad > unassign_adapter

To see the list of adapters assigned:

cat adapters

---
 arch/s390/include/asm/ap-config.h        |   13 +++
 drivers/s390/crypto/vfio_ap_matrix_ops.c |  147 ++++++++++++++++++++++++++++++
 2 files changed, 160 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +2 -0
index 7d01f18..e4b1236 100644
@@ -23,6 +23,7 @@
 struct ap_matrix_mdev {
 	struct mdev_device *mdev;
 	struct list_head node;
+	struct ap_config_masks masks;
 };
 
 struct ap_matrix	*matrix;
@@ -136,9 +137,155 @@ static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
 	NULL,
 };
 
+static int ap_matrix_id_is_xnum(char *id)

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 150

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +10 -0
+{
+	size_t i;
+
+	for (i = 0; i < strlen(id); i++) {
+		if (!isxdigit(id[i]))
+			return 0;
+	}
+
+	return 1;
+}

This feels like something for which an utility function should already exist...

Quoted 32 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +32 -0
+
+static int ap_matrix_parse_id(const char *buf, unsigned int *id)
+{
+	int ret;
+	char *bufcpy;
+	char *id_str;
+
+	if ((strlen(buf) == 0) || (*buf == '\n')) {
+		pr_err("%s: input buffer '%s' contains no valid hex values",
+		       VFIO_AP_MATRIX_MODULE_NAME, buf);
+		return -EINVAL;
+	}
+
+	bufcpy = kzalloc(strlen(buf) + 1, GFP_KERNEL);
+	if (!bufcpy)
+		return -ENOMEM;
+
+	strcpy(bufcpy, buf);
+	id_str = strim(bufcpy);
+
+	if (!ap_matrix_id_is_xnum(id_str)) {
+		pr_err("%s: input id '%s' contains an invalid hex value '%s'",
+		       VFIO_AP_MATRIX_MODULE_NAME, buf, id_str);
+		ret = -EINVAL;
+		goto done;
+	}
+
+	ret = kstrtouint (id_str, 16, id);
+	if (ret || (*id >= AP_MATRIX_MAX_MASK_BITS)) {
+		pr_err("%s: input id '%s' is not a value from 0 to %x",
+		       VFIO_AP_MATRIX_MODULE_NAME, buf,
+		       AP_MATRIX_MAX_MASK_BITS);

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 192

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +10 -0
+		ret = -EINVAL;
+		goto done;
+	}
+
+	ret = 0;
+
+done:
+	kfree(bufcpy);
+	return ret;
+}

Similarly, I suspect you are not the first person with similar parsing needs.

Quoted 6 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +6 -0
+
+static ssize_t ap_matrix_adapters_assign(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t count)
+{
+	int ret;

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 208

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +10 -0
+	unsigned int apid;
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_matrix_parse_id(buf, &apid);
+	if (ret)
+		return ret;
+
+	set_bit_inv((unsigned long)apid,
+		    (unsigned long *)matrix_mdev->masks.apm);

Probably needs a comment regarding byte order of the masks somewhere.

Quoted 4 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +4 -0
+
+	return count;
+}
+static DEVICE_ATTR(assign_adapter, 0644, NULL, ap_matrix_adapters_assign);
#45 lore raw

Re: [RFC 08/19] s390/zcrypt: support for assigning adapters to matrix mdev

Quoted 66 lines · Cornelia Huck
Quoted 63 lines · On Fri, 13 Oct 2017 13:38:53 -0400 Tony Krowiak <[email protected]>…

Provides the sysfs interfaces for assigning an adapter to and unassigning an AP adapter from a mediated matrix device.

The IDs of the AP adapters assigned to the mediated matrix device are stored in a bit mask. The bits in the mask, from left to right, correspond to AP adapter numbers 0 to 255. The bit corresponding to the ID of the adapter being assigned will be set in the bit mask.

The relevant sysfs structures are:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
...............[$uuid]
.................. adapters
.................. assign_adapter
.................. unassign_adapter

To assign an adapter to the $uuid mediated matrix device, write ID of the adapter (hex value) to the assign_adapter file. To unassign an adapter, write the ID of the adapter (hex value) to the unassign_adapter file. The list of adapters that have been assigned can be viewed by displaying the contents of the adapters file.

For example, to assign adapter 0xad to mediated matrix device $uuid:

echo ad > assign_adapter

To unassign adapter 0xad:

echo ad > unassign_adapter

To see the list of adapters assigned:

cat adapters

---
  arch/s390/include/asm/ap-config.h        |   13 +++
  drivers/s390/crypto/vfio_ap_matrix_ops.c |  147 ++++++++++++++++++++++++++++++
  2 files changed, 160 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +1 -0
index 7d01f18..e4b1236 100644
@@ -23,6 +23,7 @@
  struct ap_matrix_mdev {
  	struct mdev_device *mdev;
  	struct list_head node;
+	struct ap_config_masks masks;
  };
 
  struct ap_matrix	*matrix;
@@ -136,9 +137,155 @@ static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
  	NULL,
  };
 
Quoted 13 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 150

Quoted 11 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +11 -0
+static int ap_matrix_id_is_xnum(char *id)
+{
+	size_t i;
+
+	for (i = 0; i < strlen(id); i++) {
+		if (!isxdigit(id[i]))
+			return 0;
+	}
+
+	return 1;
+}

This feels like something for which an utility function should already exist...

See comment below

Quoted 37 lines
Quoted 37 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +36 -0
+
+static int ap_matrix_parse_id(const char *buf, unsigned int *id)
+{
+	int ret;
+	char *bufcpy;
+	char *id_str;
+
+	if ((strlen(buf) == 0) || (*buf == '\n')) {
+		pr_err("%s: input buffer '%s' contains no valid hex values",
+		       VFIO_AP_MATRIX_MODULE_NAME, buf);
+		return -EINVAL;
+	}
+
+	bufcpy = kzalloc(strlen(buf) + 1, GFP_KERNEL);
+	if (!bufcpy)
+		return -ENOMEM;
+
+	strcpy(bufcpy, buf);
+	id_str = strim(bufcpy);
+
+	if (!ap_matrix_id_is_xnum(id_str)) {
+		pr_err("%s: input id '%s' contains an invalid hex value '%s'",
+		       VFIO_AP_MATRIX_MODULE_NAME, buf, id_str);
+		ret = -EINVAL;
+		goto done;
+	}
+
+	ret = kstrtouint (id_str, 16, id);
+	if (ret || (*id >= AP_MATRIX_MAX_MASK_BITS)) {
+		pr_err("%s: input id '%s' is not a value from 0 to %x",
+		       VFIO_AP_MATRIX_MODULE_NAME, buf,
+		       AP_MATRIX_MAX_MASK_BITS);
+		ret = -EINVAL;
+		goto done;
+	}
+
Quoted 8 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 192

Quoted 6 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +6 -0
+	ret = 0;
+
+done:
+	kfree(bufcpy);
+	return ret;
+}

Similarly, I suspect you are not the first person with similar parsing needs.

I am going to remove this function

Quoted 12 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 203

Quoted 12 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +11 -0
+
+static ssize_t ap_matrix_adapters_assign(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t count)
+{
+	int ret;
+	unsigned int apid;
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_matrix_parse_id(buf, &apid);

I'm going to replace this with a call to kstrtouint (buf, 0, &apid). This will allow the user to enter the adapter ID string using conventional semantics - e.g., 71 or 0x47 - and the function will determine if the value is valid.

Quoted 6 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 208

Quoted 5 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +5 -0
+	if (ret)
+		return ret;
+
+	set_bit_inv((unsigned long)apid,
+		    (unsigned long *)matrix_mdev->masks.apm);

Probably needs a comment regarding byte order of the masks somewhere.

Okay

Quoted 5 lines
Quoted 5 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +4 -0
+
+	return count;
+}
+static DEVICE_ATTR(assign_adapter, 0644, NULL, ap_matrix_adapters_assign);
#46 lore raw

Re: [RFC 08/19] s390/zcrypt: support for assigning adapters to matrix mdev

Quoted 4 lines · On Thu, 16 Nov 2017 18:53:07 -0500 Tony Krowiak <[email protected]>…
Quoted 2 lines · Cornelia Huck

On Fri, 13 Oct 2017 13:38:53 -0400
Tony Krowiak <[email protected]> wrote:

Quoted 14 lines
Quoted 10 lines

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t device_api_show(struct kobject *kobj, struct device *dev, · line 203

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +10 -0
+static ssize_t ap_matrix_adapters_assign(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t count)
+{
+	int ret;
+	unsigned int apid;
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_matrix_parse_id(buf, &apid);  

I'm going to replace this with a call to kstrtouint (buf, 0, &apid). This will allow the user to enter the adapter ID string using conventional semantics - e.g., 71 or 0x47 - and the function will determine if the value is valid.

Using an existing interface sounds good.

#47 lore raw

RFC 9/19 s390/zcrypt: validate adapter assignment

In reply to Tony Krowiak

Each adapter assigned to the mediated matrix device must be validated to ensure that the adapter is accessible from one of the AP queues bound to the AP matrix device driver. Each AP queue bound to the matrix device is identified by its AP Queue Number (APQN). An APQN is comprised of an adapter ID (APID) and an AP queue index (APQI) which corresponds to a domain ID. Consequently, each adapter being assigned will be validated as follows:

* If no domains have been assigned to the mediated matrix device:

* The ID of the adapter being assigned must correspond to the APID of at least one of the AP queue devices bound to the AP matrix device driver.

* If domains have been assigned to the mediated matrix device:

* Each APQN that can be derived from the ID of the adapter being assigned and the ID of each domain previously assigned must match the APQN of an AP queue bound to the AP matrix device driver.

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   63 ++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +63 -0
index e4b1236..2e63d1b 100644
@@ -191,6 +191,65 @@ static int ap_matrix_parse_id(const char *buf, unsigned int *id)
 	return ret;
 }
 
+static int ap_matrix_validate_adapter_queues(unsigned long apid,
+					     unsigned long *aqm)
+{
+	unsigned long apqi;
+	unsigned long nbits = AP_MATRIX_MAX_MASK_BITS;
+	ap_qid_t qid;
+
+	apqi = find_first_bit_inv(aqm, nbits);
+	while (apqi < nbits) {
+		qid = AP_MKQID(apid, apqi);
+
+		if (find_vapq(matrix, qid)) {
+			apqi = find_next_bit_inv(aqm, nbits, apqi + 1);
+			continue;
+		}
+
+		pr_err("%s: AP queue %02lx.%04lx not bound to driver",
+		       VFIO_AP_MATRIX_MODULE_NAME, apid, apqi);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int ap_matrix_validate_apid(unsigned long apid)
+{
+
+	struct vfio_ap_queue *vapq;
+
+	if (!list_empty(&matrix->queues)) {
+		list_for_each_entry(vapq, &matrix->queues, list)
+			if (AP_QID_CARD(vapq->queue->qid) == apid)
+				return 0;
+	}
+
+	pr_err("%s: AP queue with adapter %02lx is not bound to driver",
+	       VFIO_AP_MATRIX_MODULE_NAME, apid);
+
+	return -ENODEV;
+}
+
+static int ap_matrix_validate_adapter(struct ap_matrix_mdev *matrix_mdev,
+				      unsigned long apid)
+{
+	int ret = 0;
+	unsigned long nbits = AP_MATRIX_MAX_MASK_BITS;
+	unsigned long *aqm = (unsigned long *)matrix_mdev->masks.aqm;
+	unsigned long apqi;
+
+	apqi = find_first_bit_inv(aqm, nbits);
+	/* If no queues have yet been assigned */
+	if (apqi < nbits)
+		ret = ap_matrix_validate_adapter_queues(apid, aqm);
+	else
+		ret = ap_matrix_validate_apid(apid);
+
+	return ret;
+}
+
 static ssize_t ap_matrix_adapters_assign(struct device *dev,
 					 struct device_attribute *attr,
 					 const char *buf, size_t count)
@@ -204,6 +263,10 @@ static ssize_t ap_matrix_adapters_assign(struct device *dev,
 	if (ret)
 		return ret;
 
+	ret = ap_matrix_validate_adapter(matrix_mdev, apid);
+	if (ret)
+		return ret;
+
 	set_bit_inv((unsigned long)apid,
 		    (unsigned long *)matrix_mdev->masks.apm);
 
Signature · 1 line
1.7.1
#48 lore raw

RFC 10/19 s390/zcrypt: sysfs interfaces supporting AP domain assignment

In reply to Tony Krowiak

Provides the sysfs interfaces for assigning an AP usage domain to and unassigning a usage domain from a mediated matrix device.

The relevant sysfs structures are:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
...............[$uuid]
.................. assign_domain
.................. domains
.................. unassign_domain

To assign a domain to the $uuid mediated matrix device, write its domain ID (hex value) to the assign_domain file. To unassign a domain, write its domain ID (hex value) to the unassign_domain file. To view a list of domains which have been assigned, print the contents of the domains file

For example, to assign domain 0x04 to the $uuid mediated matrix device:

echo 4 > assign_domain

To unassign domain 0x04:

echo 4 > unassign_domain

To see the list of domains assigned:

cat domains

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   80 ++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +80 -0
index 2e63d1b..f54285c 100644
@@ -329,10 +329,90 @@ static ssize_t ap_matrix_adapters_show(struct device *dev,
 }
 static DEVICE_ATTR(adapters, 0644, ap_matrix_adapters_show, NULL);
 
+static ssize_t ap_matrix_domain_assign(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t count)
+{
+	int ret;
+	unsigned int apqi;
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_matrix_parse_id(buf, &apqi);
+	if (ret)
+		return ret;
+
+	set_bit_inv((unsigned long)apqi,
+		    (unsigned long *)matrix_mdev->masks.aqm);
+
+	return count;
+}
+static DEVICE_ATTR(assign_domain, 0644, NULL, ap_matrix_domain_assign);
+
+static ssize_t ap_matrix_domain_unassign(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t count)
+{
+	int ret;
+	unsigned int apqi;
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_matrix_parse_id(buf, &apqi);
+	if (ret)
+		return ret;
+
+	clear_bit_inv((unsigned long)apqi,
+		      (unsigned long *)matrix_mdev->masks.aqm);
+
+	return count;
+}
+static DEVICE_ATTR(unassign_domain, 0644, NULL, ap_matrix_domain_unassign);
+
+static ssize_t ap_matrix_domains_show(struct device *dev,
+				       struct device_attribute *attr,
+				       char *buf)
+{
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+	unsigned long *aqm = (unsigned long *)matrix_mdev->masks.aqm;
+	unsigned long id;
+	unsigned long nbits = 256;
+	char *bufpos = buf;
+	int nchars = 0;
+	int n;
+
+	id = find_first_bit_inv(aqm, nbits);
+	while (id < nbits) {
+		if (nchars) {
+			n = sprintf(bufpos, ",");
+			bufpos += n;
+			nchars += n;
+		}
+
+		n = sprintf(bufpos, "%04lx", id);
+		bufpos += n;
+		nchars += n;
+		id = find_next_bit_inv(aqm, nbits, id + 1);
+	}
+
+	n = sprintf(bufpos, "\n");
+	bufpos += n;
+	nchars += n;
+
+	return nchars;
+}
+
+static DEVICE_ATTR(domains, 0644, ap_matrix_domains_show,
+		   NULL);
+
 static struct attribute *ap_matrix_mdev_attrs[] = {
 	&dev_attr_assign_adapter.attr,
 	&dev_attr_unassign_adapter.attr,
 	&dev_attr_adapters.attr,
+	&dev_attr_assign_domain.attr,
+	&dev_attr_unassign_domain.attr,
+	&dev_attr_domains.attr,
 	NULL
 };
 
Signature · 1 line
1.7.1
#49 lore raw

RFC 11/19 s390/zcrypt: validate domain assignment

In reply to Tony Krowiak

Each domain assigned to the mediated matrix device must be validated to ensure that the domain is accessible from one of the AP queues bound to the AP matrix device driver.

Each AP queue bound to the device driver is identified by an AP Queue Number (APQN). An APQN is comprised of an adapter ID (APID) and an AP queue index (APQI) which corresponds to a domain ID. Consequently, each domain being assigned will be validated as follows:

* If no adapters have been assigned to the mediated matrix device:

* The ID of the domain being assigned must correspond to the APQI of at least one of the AP queue devices bound to the AP matrix device driver.

* If adapters have been assigned to the mediated matrix device:

* Each APQN that can be derived from the ID of the domain being assigned and the ID of each adapter previously assigned must match the APQN of an AP queue bound to the AP matrix device driver.

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   63 ++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +63 -0
index f54285c..74d7feb 100644
@@ -329,6 +329,65 @@ static ssize_t ap_matrix_adapters_show(struct device *dev,
 }
 static DEVICE_ATTR(adapters, 0644, ap_matrix_adapters_show, NULL);
 
+static int ap_matrix_validate_domain_queues(unsigned long apqi,
+					    unsigned long *apm)
+{
+	unsigned long apid;
+	unsigned long nbits = AP_MATRIX_MAX_MASK_BITS;
+	ap_qid_t qid;
+
+	apid = find_first_bit_inv(apm, nbits);
+	while (apid < nbits) {
+		qid = AP_MKQID(apid, apqi);
+
+		if (find_vapq(matrix, qid)) {
+			apid = find_next_bit_inv(apm, nbits, apid + 1);
+			continue;
+		}
+
+		pr_err("%s: AP queue %02lx.%04lx not bound to driver",
+		       VFIO_AP_MATRIX_MODULE_NAME, apid, apid);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int ap_matrix_validate_apqi(unsigned long apqi)
+{
+
+	struct vfio_ap_queue *vapq;
+
+	if (!list_empty(&matrix->queues)) {
+		list_for_each_entry(vapq, &matrix->queues, list)
+			if (AP_QID_QUEUE(vapq->queue->qid) == apqi)
+				return 0;
+	}
+
+	pr_err("%s: AP queue with domain %02lx is not bound to driver",
+	       VFIO_AP_MATRIX_MODULE_NAME, apqi);
+
+	return -ENODEV;
+}
+
+static int ap_matrix_validate_domain(struct ap_matrix_mdev *matrix_mdev,
+				     unsigned long apqi)
+{
+	int ret = 0;
+	unsigned long nbits = AP_MATRIX_MAX_MASK_BITS;
+	unsigned long *apm = (unsigned long *)matrix_mdev->masks.apm;
+	unsigned long apid;
+
+	apid = find_first_bit_inv(apm, nbits);
+	/* If no adapters have yet been assigned */
+	if (apid < nbits)
+		ret = ap_matrix_validate_apqi(apqi);
+	else
+		ret = ap_matrix_validate_domain_queues(apqi, apm);
+
+	return ret;
+}
+
 static ssize_t ap_matrix_domain_assign(struct device *dev,
 				       struct device_attribute *attr,
 				       const char *buf, size_t count)
@@ -342,6 +401,10 @@ static ssize_t ap_matrix_domain_assign(struct device *dev,
 	if (ret)
 		return ret;
 
+	ret = ap_matrix_validate_domain(matrix_mdev, apqi);
+	if (ret)
+		return ret;
+
 	set_bit_inv((unsigned long)apqi,
 		    (unsigned long *)matrix_mdev->masks.aqm);
 
Signature · 1 line
1.7.1
#50 lore raw

RFC 12/19 s390/zcrypt: sysfs support for control domain assignment

In reply to Tony Krowiak

Provides the sysfs interfaces for assigning an AP control domain to and unassigning a control domain from a mediated matrix device. The relevant sysfs structures are:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [ap_matrix-passthrough]
............ [devices]
...............[$uuid]
.................. assign_control_domain
.................. unassign_control_domain
.................. control_domains

To assign a control domain to the $uuid mediated matrix device, write its domain ID (hex value) to the assign_control_domain file. To unassign a control domain, write its domain ID to the unassign_control_domain file. To display the list of control domains assigned, print the domains file.

For example, to assign control domain 0xff to the $uuid mediated matrix device:

echo ff > assign_control_domain

To see the list of control domains assigned:

cat control_domains

To unassign control domain 0xff:

echo ff > unassign_control_domain

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   82 ++++++++++++++++++++++++++++++
 1 files changed, 82 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +82 -0
index 74d7feb..2387916 100644
@@ -469,6 +469,85 @@ static ssize_t ap_matrix_domains_show(struct device *dev,
 static DEVICE_ATTR(domains, 0644, ap_matrix_domains_show,
 		   NULL);
 
+static ssize_t ap_matrix_control_domain_assign(struct device *dev,
+					       struct device_attribute *attr,
+					       const char *buf, size_t count)
+{
+	int ret;
+	unsigned int id;
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_matrix_parse_id(buf, &id);
+	if (ret)
+		return ret;
+
+	set_bit_inv((unsigned long)id,
+		    (unsigned long *)matrix_mdev->masks.adm);
+
+	return count;
+}
+static DEVICE_ATTR(assign_control_domain, 0644, NULL,
+		   ap_matrix_control_domain_assign);
+
+static ssize_t ap_matrix_control_domain_unassign(struct device *dev,
+						  struct device_attribute *attr,
+						  const char *buf, size_t count)
+{
+	int ret;
+	unsigned int id;
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_matrix_parse_id(buf, &id);
+	if (ret)
+		return ret;
+
+	clear_bit_inv((unsigned long)id,
+		      (unsigned long *)matrix_mdev->masks.adm);
+
+	return count;
+}
+static DEVICE_ATTR(unassign_control_domain, 0644, NULL,
+		   ap_matrix_control_domain_unassign);
+
+static ssize_t ap_matrix_control_domains_show(struct device *dev,
+					      struct device_attribute *attr,
+					      char *buf)
+{
+	struct mdev_device *mdev = mdev_from_dev(dev);
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+	unsigned long *adm = (unsigned long *)matrix_mdev->masks.adm;
+	unsigned long id;
+	unsigned long nbits = 256;
+	char *bufpos = buf;
+	int nchars = 0;
+	int n;
+
+	id = find_first_bit_inv(adm, nbits);
+	while (id < nbits) {
+		if (nchars) {
+			n = sprintf(bufpos, ",");
+			bufpos += n;
+			nchars += n;
+		}
+
+		n = sprintf(bufpos, "%04lx", id);
+		bufpos += n;
+		nchars += n;
+		id = find_next_bit_inv(adm, nbits, id + 1);
+	}
+
+	n = sprintf(bufpos, "\n");
+	bufpos += n;
+	nchars += n;
+
+	return nchars;
+}
+
+static DEVICE_ATTR(control_domains, 0644, ap_matrix_control_domains_show,
+		   NULL);
+
 static struct attribute *ap_matrix_mdev_attrs[] = {
 	&dev_attr_assign_adapter.attr,
 	&dev_attr_unassign_adapter.attr,
@@ -476,6 +555,9 @@ static DEVICE_ATTR(domains, 0644, ap_matrix_domains_show,
 	&dev_attr_assign_domain.attr,
 	&dev_attr_unassign_domain.attr,
 	&dev_attr_domains.attr,
+	&dev_attr_assign_control_domain.attr,
+	&dev_attr_unassign_control_domain.attr,
+	&dev_attr_control_domains.attr,
 	NULL
 };
 
Signature · 1 line
1.7.1
#51 lore raw

RFC 13/19 s390/zcrypt: validate control domain assignment

In reply to Tony Krowiak

The AP control domain being assigned to the mediated matrix driver must be assigned to the LPAR.

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   33 ++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +33 -0
index 2387916..10a006c 100644
@@ -469,12 +469,41 @@ static ssize_t ap_matrix_domains_show(struct device *dev,
 static DEVICE_ATTR(domains, 0644, ap_matrix_domains_show,
 		   NULL);
 
+static int
+ap_matrix_validate_control_domains(struct ap_matrix_mdev *matrix_mdev,
+				   unsigned long id)
+{
+	int ret;
+	struct ap_config_info config;
+
+	memset(&config, 0, sizeof(config));
+
+	ret = ap_query_configuration(&config);
+	if (ret == -EOPNOTSUPP)
+		return 0;
+
+	if (ret) {
+		pr_err("%s: query AP configuration failed with rc %d",
+		       VFIO_AP_MATRIX_MODULE_NAME, ret);
+		return ret;
+	}
+
+	if (!test_bit_inv(id, (unsigned long *)config.adm)) {
+		pr_err("%s: control domain %04lx is not installed on the lpar",
+		       VFIO_AP_MATRIX_MODULE_NAME, id);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
 static ssize_t ap_matrix_control_domain_assign(struct device *dev,
 					       struct device_attribute *attr,
 					       const char *buf, size_t count)
 {
 	int ret;
 	unsigned int id;
+
 	struct mdev_device *mdev = mdev_from_dev(dev);
 	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
 
@@ -482,6 +511,10 @@ static ssize_t ap_matrix_control_domain_assign(struct device *dev,
 	if (ret)
 		return ret;
 
+	ret = ap_matrix_validate_control_domains(matrix_mdev, id);
+	if (ret)
+		return ret;
+
 	set_bit_inv((unsigned long)id,
 		    (unsigned long *)matrix_mdev->masks.adm);
 
Signature · 1 line
1.7.1
#52 lore raw

Re: [RFC 13/19] s390/zcrypt: validate control domain assignment

Quoted 55 lines · On Fri, 13 Oct 2017 13:38:58 -0400 Tony Krowiak <[email protected]>…

The AP control domain being assigned to the mediated matrix driver must be assigned to the LPAR.

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   33 ++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +29 -0
index 2387916..10a006c 100644
@@ -469,12 +469,41 @@ static ssize_t ap_matrix_domains_show(struct device *dev,
 static DEVICE_ATTR(domains, 0644, ap_matrix_domains_show,
 		   NULL);
 
+static int
+ap_matrix_validate_control_domains(struct ap_matrix_mdev *matrix_mdev,
+				   unsigned long id)
+{
+	int ret;
+	struct ap_config_info config;
+
+	memset(&config, 0, sizeof(config));
+
+	ret = ap_query_configuration(&config);
+	if (ret == -EOPNOTSUPP)
+		return 0;
+
+	if (ret) {
+		pr_err("%s: query AP configuration failed with rc %d",
+		       VFIO_AP_MATRIX_MODULE_NAME, ret);
+		return ret;
+	}
+
+	if (!test_bit_inv(id, (unsigned long *)config.adm)) {
+		pr_err("%s: control domain %04lx is not installed on the lpar",
+		       VFIO_AP_MATRIX_MODULE_NAME, id);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
 static ssize_t ap_matrix_control_domain_assign(struct device *dev,
 					       struct device_attribute *attr,
 					       const char *buf, size_t count)
 {
 	int ret;
 	unsigned int id;
+
 	struct mdev_device *mdev = mdev_from_dev(dev);
 	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
 

drivers/s390/crypto/vfio_ap_matrix_ops.c static ssize_t ap_matrix_control_domain_assign(struct device *dev, · line 520

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +4 -0
@@ -482,6 +511,10 @@ static ssize_t ap_matrix_control_domain_assign(struct device *dev,
 	if (ret)
 		return ret;
 
+	ret = ap_matrix_validate_control_domains(matrix_mdev, id);
+	if (ret)
+		return ret;
+
 	set_bit_inv((unsigned long)id,
 		    (unsigned long *)matrix_mdev->masks.adm);
 

Is there a specific reason why patch #13 is separate from patch #12 that introduces the domain assignment? The assignment code does not make much sense with the check if the domain is assigned to the LPAR, no?

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#53 lore raw

RFC 14/19 KVM: s390: Connect the AP mediated matrix device to KVM

In reply to Tony Krowiak

Registers a group notifier during the open of the mediated device to get information on KVM presence through the VFIO_GROUP_NOTIFY_SET_KVM event.

When notified, save the pointer to KVM inside mediated matrix device structure.

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   43 ++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +43 -0
index 10a006c..fd36074 100644
@@ -12,6 +12,9 @@
 #include <linux/device.h>
 #include <linux/list.h>
 #include <linux/ctype.h>
+#include <linux/kvm_host.h>
+#include <linux/eventfd.h>
+#include <linux/notifier.h>
 
 #include "vfio_ap_matrix_private.h"
 
@@ -24,6 +27,8 @@ struct ap_matrix_mdev {
 	struct mdev_device *mdev;
 	struct list_head node;
 	struct ap_config_masks masks;
+	struct notifier_block group_notifier;
+	struct kvm *kvm;
 };
 
 struct ap_matrix	*matrix;
@@ -97,6 +102,41 @@ static int ap_matrix_mdev_remove(struct mdev_device *mdev)
 	return 0;
 }
 
+static int ap_matrix_mdev_group_notifier(struct notifier_block *nb,
+					 unsigned long action, void *data)
+{
+	struct ap_matrix_mdev *matrix_mdev;
+
+	matrix_mdev = container_of(nb, struct ap_matrix_mdev, group_notifier);
+
+	if (action == VFIO_GROUP_NOTIFY_SET_KVM)
+		matrix_mdev->kvm = data;
+
+	return NOTIFY_OK;
+}
+
+static int ap_matrix_mdev_open(struct mdev_device *mdev)
+{
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+	unsigned long events;
+	int ret;
+
+	matrix_mdev->group_notifier.notifier_call =
+		ap_matrix_mdev_group_notifier;
+	events = VFIO_GROUP_NOTIFY_SET_KVM;
+	ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
+				     &events, &matrix_mdev->group_notifier);
+	return ret;
+}
+
+static void ap_matrix_mdev_release(struct mdev_device *mdev)
+{
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
+				 &matrix_mdev->group_notifier);
+}
+
 static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
 {
 	return sprintf(buf, "%s\n", AP_MATRIX_MDEV_NAME_HWVIRT);
@@ -609,6 +649,9 @@ static DEVICE_ATTR(control_domains, 0644, ap_matrix_control_domains_show,
 	.mdev_attr_groups	= ap_matrix_mdev_attr_groups,
 	.create                 = ap_matrix_mdev_create,
 	.remove                 = ap_matrix_mdev_remove,
+	.open                   = ap_matrix_mdev_open,
+	.release                = ap_matrix_mdev_release,
+
 };
 
 int ap_matrix_mdev_register(struct ap_matrix *ap_matrix)
Signature · 1 line
1.7.1
#54 lore raw

RFC 15/19 s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver

In reply to Tony Krowiak

Introduces ioctl access to the VFIO AP Matrix device driver by implementing the VFIO_DEVICE_GET_INFO ioctl. This ioctl provides the VFIO AP Matrix device driver information to the guest machine.

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   43 ++++++++++++++++++++++++++++++
 include/uapi/linux/vfio.h                |    1 +
 2 files changed, 44 insertions(+), 0 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +43 -0
index fd36074..74ea8db 100644
@@ -137,6 +137,48 @@ static void ap_matrix_mdev_release(struct mdev_device *mdev)
 				 &matrix_mdev->group_notifier);
 }
 
+static int ap_matrix_mdev_get_device_info(unsigned long arg)
+{
+	unsigned long minsz;
+	struct vfio_device_info info;
+
+	minsz = offsetofend(struct vfio_device_info, num_irqs);
+
+	if (copy_from_user(&info, (void __user *)arg, minsz))
+		return -EFAULT;
+
+	if (info.argsz < minsz) {
+		pr_err("%s: Argument size %u less than min size %li",
+		       VFIO_AP_MATRIX_MODULE_NAME, info.argsz, minsz);
+		return -EINVAL;
+	}
+
+	info.flags = VFIO_DEVICE_FLAGS_AP_MATRIX;
+	info.num_regions = 0;
+	info.num_irqs = 0;
+
+	return copy_to_user((void __user *)arg, &info, minsz);
+}
+
+static ssize_t ap_matrix_mdev_ioctl(struct mdev_device *mdev,
+				    unsigned int cmd, unsigned long arg)
+{
+	int ret;
+
+	switch (cmd) {
+	case VFIO_DEVICE_GET_INFO:
+		ret = ap_matrix_mdev_get_device_info(arg);
+		break;
+	default:
+		pr_err("%s: ioctl command %d is not a supported command",
+		       VFIO_AP_MATRIX_MODULE_NAME, cmd);
+		ret = -EOPNOTSUPP;
+		break;
+	}
+
+	return ret;
+}
+
 static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
 {
 	return sprintf(buf, "%s\n", AP_MATRIX_MDEV_NAME_HWVIRT);
@@ -651,6 +693,7 @@ static DEVICE_ATTR(control_domains, 0644, ap_matrix_control_domains_show,
 	.remove                 = ap_matrix_mdev_remove,
 	.open                   = ap_matrix_mdev_open,
 	.release                = ap_matrix_mdev_release,
+	.ioctl                  = ap_matrix_mdev_ioctl,
 
 };
 
include/uapi/linux/vfio.h +1 -0
index 743456f..08f1ab4 100644
@@ -199,6 +199,7 @@ struct vfio_device_info {
 #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)	/* vfio-platform device */
 #define VFIO_DEVICE_FLAGS_AMBA  (1 << 3)	/* vfio-amba device */
 #define VFIO_DEVICE_FLAGS_CCW	(1 << 4)	/* vfio-ccw device */
+#define VFIO_DEVICE_FLAGS_AP_MATRIX (1 << 5)	/* vfio-ap-matrix device */
 	__u32	num_regions;	/* Max region index + 1 */
 	__u32	num_irqs;	/* Max IRQ index + 1 */
 };
Signature · 1 line
1.7.1
#55 lore raw

RFC 16/19 KVM: s390: interface to configure KVM guest's AP matrix

In reply to Tony Krowiak

Provides an interface to assign AP adapters, usage domains and control domains to a KVM guest.

A KVM guest is started by executing the Start Interpretive Execution (SIE) instruction. The SIE state description is a control block that contains the state information for a KVM guest and is supplied as input to the SIE instruction. The SIE state description contains a field that references a Crypto Control Block (CRYCB). The CRYCB contains three bitmask fields identifying the adapters, usage domains and control domains assigned to the KVM guest:

* The AP Adapter Matrix (APM) field identifies the AP adapters assigned to the KVM guest

* The AP Queue Matrix (AQM) field identifies the usage domains assigned to the KVM guest

* The AP Domain matrix (ADM) field identifies the control domains assigned to the KVM guest.

Each adapter, usage domain and control domain are identified by a number from 0 to 255. The bits in each mask, from left to right, correspond to the numbers 0-255. When a bit is set, the corresponding adapter, usage domain or control domain will be assigned to the KVM guest.

This patch will set the bits in the APM, AQM and ADM fields of the CRYCB referenced by the KVM guest's SIE state description. The process used is:

1. Perform a logical AND of the AP matrix masks configured for the mediated AP matrix device via its sysfs attributes files with the matrix masks assigned to the LPAR in which the host linux system is running to create the effective masks, EAPM, EAQM and EADM.

2. Set the APM, AQM and ADM in the CRYCB from the EAPM, EAQM and EADM calculated in step 1.

---
 arch/s390/include/asm/ap-config.h |    7 ++
 arch/s390/kvm/ap-config.c         |  144 +++++++++++++++++++++++++++++++++++++
 2 files changed, 151 insertions(+), 0 deletions(-)
arch/s390/include/asm/ap-config.h +7 -0
index 3064215..866f008 100644
@@ -10,16 +10,23 @@
 #define _ASM_KVM_AP_CONFIG_H_
 
 #include <linux/types.h>
+#include <linux/kvm_host.h>
 
 #define AP_MATRIX_MAX_MASK_BITS		256
 #define AP_MATRIX_MASK_INDICES		(AP_MATRIX_MAX_MASK_BITS / \
 					(sizeof(u64) * 8))
 #define AP_MATRIX_MAX_MASK_BYTES	(AP_MATRIX_MASK_INDICES * sizeof(u64))
 
+#define AP_MATRIX_MASK_TYPE_ADAPTER	"adapter"
+#define AP_MATRIX_MASK_TYPE_DOMAIN	"domain"
+#define AP_MATRIX_MASK_TYPE_CONTROL	"control domain"
+
 struct ap_config_masks {
 	u64 apm[AP_MATRIX_MASK_INDICES];
 	u64 aqm[AP_MATRIX_MASK_INDICES];
 	u64 adm[AP_MATRIX_MASK_INDICES];
 };
 
+extern int ap_config_matrix(struct kvm *kvm, struct ap_config_masks *masks);
+
 #endif /* _ASM_KVM_AP_CONFIG_H_ */
arch/s390/kvm/ap-config.c +144 -0

147 lines not on this page · raw message

Signature · 1 line
1.7.1
#56 lore raw

Re: [RFC 16/19] KVM: s390: interface to configure KVM guest's AP matrix

Quoted 20 lines · Tony Krowiak

Provides an interface to assign AP adapters, usage domains and control domains to a KVM guest.

A KVM guest is started by executing the Start Interpretive Execution (SIE) instruction. The SIE state description is a control block that contains the state information for a KVM guest and is supplied as input to the SIE instruction. The SIE state description contains a field that references a Crypto Control Block (CRYCB). The CRYCB contains three bitmask fields identifying the adapters, usage domains and control domains assigned to the KVM guest:

* The AP Adapter Matrix (APM) field identifies the AP adapters assigned to the KVM guest

* The AP Queue Matrix (AQM) field identifies the usage domains assigned to the KVM guest

* The AP Domain matrix (ADM) field identifies the control domains assigned to the KVM guest.

Quoted 8 lines

Each adapter, usage domain and control domain are identified by a number from 0 to 255. The bits in each mask, from left to right, correspond to the numbers 0-255. When a bit is set, the corresponding adapter, usage domain or control domain will be assigned to the KVM guest.

This patch will set the bits in the APM, AQM and ADM fields of the CRYCB referenced by the KVM guest's SIE state description. The process used is:

There is a step missing here and is also missing from the code. By architectural convention, all bits set in the ADM must also be set in the AQM, but the ADM may have bits set that are not set in the AQM. In other words, all usage domains are control domains, but some control domains may not be usage usage domains. So, the ADM contained in the CRYCB will be set with the bits resulting from the logical OR of the ADM and AQM configured for the mediated AP matrix device via its sysfs attributes files.

Quoted 177 lines

1. Perform a logical AND of the AP matrix masks configured for the mediated AP matrix device via its sysfs attributes files with the matrix masks assigned to the LPAR in which the host linux system is running to create the effective masks, EAPM, EAQM and EADM.

2. Set the APM, AQM and ADM in the CRYCB from the EAPM, EAQM and EADM calculated in step 1.

---
  arch/s390/include/asm/ap-config.h |    7 ++
  arch/s390/kvm/ap-config.c         |  144 +++++++++++++++++++++++++++++++++++++
  2 files changed, 151 insertions(+), 0 deletions(-)
arch/s390/include/asm/ap-config.h +7 -0
index 3064215..866f008 100644
@@ -10,16 +10,23 @@
  #define _ASM_KVM_AP_CONFIG_H_
 
  #include <linux/types.h>
+#include <linux/kvm_host.h>
 
  #define AP_MATRIX_MAX_MASK_BITS		256
  #define AP_MATRIX_MASK_INDICES		(AP_MATRIX_MAX_MASK_BITS / \
  					(sizeof(u64) * 8))
  #define AP_MATRIX_MAX_MASK_BYTES	(AP_MATRIX_MASK_INDICES * sizeof(u64))
 
+#define AP_MATRIX_MASK_TYPE_ADAPTER	"adapter"
+#define AP_MATRIX_MASK_TYPE_DOMAIN	"domain"
+#define AP_MATRIX_MASK_TYPE_CONTROL	"control domain"
+
  struct ap_config_masks {
  	u64 apm[AP_MATRIX_MASK_INDICES];
  	u64 aqm[AP_MATRIX_MASK_INDICES];
  	u64 adm[AP_MATRIX_MASK_INDICES];
  };
 
+extern int ap_config_matrix(struct kvm *kvm, struct ap_config_masks *masks);
+
  #endif /* _ASM_KVM_AP_CONFIG_H_ */
arch/s390/kvm/ap-config.c +125 -0
index 84fdf43..dc79798 100644
@@ -7,3 +7,147 @@
   */
 
  #include <asm/ap-config.h>
+#include <asm/ap.h>
+#include <linux/bitops.h>
+
+static inline int is_format2_crycb(struct kvm *kvm)
+{
+	int fmt2_mask = kvm->arch.crypto.crycbd & CRYCB_FORMAT2;
+
+	return (fmt2_mask == CRYCB_FORMAT2);
+}
+
+static inline u64 *ap_config_get_crycb_apm(struct kvm *kvm)
+{
+	u64 *apm;
+
+	if (is_format2_crycb(kvm))
+		apm = kvm->arch.crypto.crycb->apcb1.apm;
+	else
+		apm = kvm->arch.crypto.crycb->apcb0.apm;
+
+	return apm;
+}
+
+static inline u64 *ap_config_get_crycb_aqm(struct kvm *kvm)
+{
+	u64 *aqm;
+
+	if (is_format2_crycb(kvm))
+		aqm = kvm->arch.crypto.crycb->apcb1.aqm;
+	else
+		aqm = kvm->arch.crypto.crycb->apcb0.aqm;
+
+	return aqm;
+}
+
+static inline u64 *ap_config_get_crycb_adm(struct kvm *kvm)
+{
+	u64 *adm;
+
+	if (is_format2_crycb(kvm))
+		adm = kvm->arch.crypto.crycb->apcb1.adm;
+	else
+		adm = kvm->arch.crypto.crycb->apcb0.adm;
+
+	return adm;
+}
+
+static void ap_config_set_crycb_masks(struct kvm *kvm,
+				    struct ap_config_masks *masks)
+{
+	size_t i;
+	size_t masksz;
+	u64 *mask = ap_config_get_crycb_apm(kvm);
+
+	masksz = (is_format2_crycb(kvm)) ? APCB1_MASK_SIZE : APCB0_MASK_SIZE;
+
+	for (i = 0; i < masksz; i++)
+		mask[i] = masks->apm[i];
+
+	mask = ap_config_get_crycb_aqm(kvm);
+
+	for (i = 0; i < masksz; i++)
+		mask[i] = masks->aqm[i];
+
+	mask = ap_config_get_crycb_adm(kvm);
+
+	for (i = 0; i < masksz; i++)
+		mask[i] = masks->adm[i];
+}
+
+static int ap_config_set_emask(const char *mask_type, unsigned long *mask,
+			       unsigned long *cfgmask)
+{
+	unsigned long id;
+	unsigned long nbits = AP_MATRIX_MAX_MASK_BITS;
+
+	id = find_first_bit_inv(mask, nbits);
+	while (id < nbits) {
+		if (!test_bit_inv(id, cfgmask)) {
+			clear_bit_inv(id, mask);
+			pr_err("%s: %s %02lx is not installed on the host system",
+			       __func__, mask_type, id);
+			return -ENODEV;
+		}
+
+		id = find_next_bit_inv(mask, nbits, id + 1);
+	}
+
+	return 0;
+}
+
+static int ap_config_get_emasks(struct ap_config_masks *masks)
+{
+	int ret;
+	struct ap_config_info config;
+
+	ret = ap_query_configuration(&config);
+	if (ret) {
+		if (ret == -EOPNOTSUPP) {
+			pr_err("%s: Query AP configuration not supported",
+			       __func__);
+
+			return ret;
+		}
+
+		pr_err("%s: Query AP configuration failed with rc=%d",
+		       __func__, ret);
+
+		return ret;
+	}
+
+	ret = ap_config_set_emask(AP_MATRIX_MASK_TYPE_ADAPTER,
+				  (unsigned long *)masks->apm,
+				  (unsigned long *)config.apm);
+	if (ret)
+		return ret;
+
+	ret = ap_config_set_emask(AP_MATRIX_MASK_TYPE_DOMAIN,
+				  (unsigned long *)masks->aqm,
+				  (unsigned long *)config.aqm);
+	if (ret)
+		return ret;
+
+	ret = ap_config_set_emask(AP_MATRIX_MASK_TYPE_CONTROL,
+				  (unsigned long *)masks->adm,
+				  (unsigned long *)config.adm);

arch/s390/kvm/ap-config.c line 144

Quoted 10 lines
arch/s390/kvm/ap-config.c +10 -0
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+int ap_config_matrix(struct kvm *kvm, struct ap_config_masks *masks)
+{
+	int ret;
+

For the reasons stated earlier in this response, we need to do a logical OR of the bits in the ADM with those in the AQM here:

size_t i;

for (i = 0; i < AP_MATRIX_MASK_INDICES; i++)

    masks->adm[i] |= masks->aqm[i];
Quoted 9 lines
arch/s390/kvm/ap-config.c +9 -0
+	ret = ap_config_get_emasks(masks);
+	if (ret)
+		return ret;
+
+	ap_config_set_crycb_masks(kvm, masks);
+
+	return 0;
+}
+EXPORT_SYMBOL(ap_config_matrix);
#57 lore raw

Re: [RFC 16/19] KVM: s390: interface to configure KVM guest's AP matrix

In reply to Tony Krowiak
Quoted 47 lines · On Fri, 13 Oct 2017 13:39:01 -0400 Tony Krowiak <[email protected]>…

Provides an interface to assign AP adapters, usage domains and control domains to a KVM guest.

A KVM guest is started by executing the Start Interpretive Execution (SIE) instruction. The SIE state description is a control block that contains the state information for a KVM guest and is supplied as input to the SIE instruction. The SIE state description contains a field that references a Crypto Control Block (CRYCB). The CRYCB contains three bitmask fields identifying the adapters, usage domains and control domains assigned to the KVM guest:

* The AP Adapter Matrix (APM) field identifies the AP adapters assigned to the KVM guest

* The AP Queue Matrix (AQM) field identifies the usage domains assigned to the KVM guest

* The AP Domain matrix (ADM) field identifies the control domains assigned to the KVM guest.

Each adapter, usage domain and control domain are identified by a number from 0 to 255. The bits in each mask, from left to right, correspond to the numbers 0-255. When a bit is set, the corresponding adapter, usage domain or control domain will be assigned to the KVM guest.

This patch will set the bits in the APM, AQM and ADM fields of the CRYCB referenced by the KVM guest's SIE state description. The process used is:

1. Perform a logical AND of the AP matrix masks configured for the mediated AP matrix device via its sysfs attributes files with the matrix masks assigned to the LPAR in which the host linux system is running to create the effective masks, EAPM, EAQM and EADM.

2. Set the APM, AQM and ADM in the CRYCB from the EAPM, EAQM and EADM calculated in step 1.

---
 arch/s390/include/asm/ap-config.h |    7 ++
 arch/s390/kvm/ap-config.c         |  144 +++++++++++++++++++++++++++++++++++++
 2 files changed, 151 insertions(+), 0 deletions(-)
arch/s390/kvm/ap-config.c +2 -0
+static int ap_config_get_emasks(struct ap_config_masks *masks)
+{

arch/s390/kvm/ap-config.c line 111

Quoted 10 lines
arch/s390/kvm/ap-config.c +10 -0
+	int ret;
+	struct ap_config_info config;
+
+	ret = ap_query_configuration(&config);
+	if (ret) {
+		if (ret == -EOPNOTSUPP) {
+			pr_err("%s: Query AP configuration not supported",
+			       __func__);
+
+			return ret;

I'm wondering whether we should check this at init time for vfio-ap? If PQAP(QCI) is not supported, it probably does not make any sense to pretend that we could do device assignment...

Quoted 42 lines
arch/s390/kvm/ap-config.c +42 -0
+		}
+
+		pr_err("%s: Query AP configuration failed with rc=%d",
+		       __func__, ret);
+
+		return ret;
+	}
+
+	ret = ap_config_set_emask(AP_MATRIX_MASK_TYPE_ADAPTER,
+				  (unsigned long *)masks->apm,
+				  (unsigned long *)config.apm);
+	if (ret)
+		return ret;
+
+	ret = ap_config_set_emask(AP_MATRIX_MASK_TYPE_DOMAIN,
+				  (unsigned long *)masks->aqm,
+				  (unsigned long *)config.aqm);
+	if (ret)
+		return ret;
+
+	ret = ap_config_set_emask(AP_MATRIX_MASK_TYPE_CONTROL,
+				  (unsigned long *)masks->adm,
+				  (unsigned long *)config.adm);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+int ap_config_matrix(struct kvm *kvm, struct ap_config_masks *masks)
+{
+	int ret;
+
+	ret = ap_config_get_emasks(masks);
+	if (ret)
+		return ret;
+
+	ap_config_set_crycb_masks(kvm, masks);
+
+	return 0;
+}
+EXPORT_SYMBOL(ap_config_matrix);
#58 lore raw

RFC 17/19 KVM: s390: validate input to AP matrix config interface

In reply to Tony Krowiak

Verifies that the AP matrix assigned to the KVM guest is not shared by any other KVM guest running on the same system.

The Crypto Control Block referenced by a KVM guest's SIE state description contains two bit mask fields that identify the AP adapters and usage domains to assigned to the
guest: The AP Matrix (APM) identifies the AP adapters assigned to the KVM guest; and the AP Queue Matrix (AQM) identifies the usage domains assigned to the KVM guest. Each adapter and usage domain is identified by a number from 0 to 255. The bits in each mask, from left to right, correspond to the numbers 0-255. When a bit is set, the corresponding adapter or usage domain is assigned to the KVM guest.

AP instructions identify the AP device to use to perform the cryptographic function contained in the instruction's payload. The AP device is identified by and AP Queue Number (APQN). The APQN is comprised of two fields: The AP Identifier (APID) that specifies an adapter ID; and an AP Queue Identifier (APQI) that specifies a domain ID.

The bits in the APM and AQM fields of the KVM guest's CRYCB specify the list of APQNs that are valid for instructions submitted from the KVM guest. When an AP instruction is executed by the KVM guest, if the bit in the APM corresponding to the APID contained in the APQN specified in the AP instruction is not set, the instruction will fail. Likewise, if the bit in the AQM corresponding to the APQI contained in the APQN specified in the AP instruction is not set, the instruction will fail.

The APQNs that can be derived from the bits set in the APM and AQM fields of the KVM guest's CRYCB must not be available to any other KVM guest running on the same system. If any APQN is not unique to the KVM guest, the ioctl will fail.

---
 arch/s390/kvm/ap-config.c |   71 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
arch/s390/kvm/ap-config.c +71 -0
index dc79798..4b0794d 100644
@@ -138,6 +138,73 @@ static int ap_config_get_emasks(struct ap_config_masks *masks)
 	return 0;
 }
 
+static unsigned long ap_config_get_num_mask_bits(struct kvm *kvm)
+{
+	return is_format2_crycb(kvm) ? sizeof(u64) * APCB1_MASK_SIZE * 8 :
+				       sizeof(u64) * APCB0_MASK_SIZE * 8;
+}
+
+static int ap_config_validate_queue(struct kvm *kvm, unsigned long apid,
+				    unsigned long apqi)
+{
+	int ret = 0;
+	struct kvm *vm;
+	u64 *mask;
+
+	mutex_lock(&kvm->lock);
+
+	/* No other VM may share an AP Queue with the input VM */
+	list_for_each_entry(vm, &vm_list, vm_list) {
+		if (kvm == vm)
+			continue;
+
+		mask = ap_config_get_crycb_apm(vm);
+		if (!test_bit_inv(apid, (unsigned long *)mask))
+			continue;
+
+		mask = ap_config_get_crycb_aqm(vm);
+		if (!test_bit_inv(apqi, (unsigned long *)mask))
+			continue;
+
+		pr_err("%s: AP queue %02lx.%04lx is already registered to %s",
+		       __func__, apid, apqi, kvm->arch.dbf->name);
+		ret = -EBUSY;
+
+		goto done;
+	}
+
+done:
+	mutex_unlock(&kvm->lock);
+	return ret;
+}
+
+static int ap_config_validate_queues(struct kvm *kvm,
+				     struct ap_config_masks *masks)
+{
+	int ret;
+	const unsigned long *apm = (unsigned long *)masks->apm;
+	const unsigned long *aqm = (unsigned long *)masks->aqm;
+	unsigned long nbits = ap_config_get_num_mask_bits(kvm);
+	unsigned long apid;
+	unsigned long apqi;
+
+	apid = find_first_bit_inv(apm, nbits);
+	while (apid < nbits) {
+		apqi = find_first_bit_inv(aqm, nbits);
+		while (apqi < nbits) {
+			ret = ap_config_validate_queue(kvm, apid, apqi);
+			if (ret)
+				return ret;
+
+			apqi = find_next_bit_inv(aqm, nbits, apqi + 1);
+		}
+
+		apid = find_next_bit_inv(apm, nbits, apid + 1);
+	}
+
+	return 0;
+}
+
 int ap_config_matrix(struct kvm *kvm, struct ap_config_masks *masks)
 {
 	int ret;
@@ -146,6 +213,10 @@ int ap_config_matrix(struct kvm *kvm, struct ap_config_masks *masks)
 	if (ret)
 		return ret;
 
+	ret = ap_config_validate_queues(kvm, masks);
+	if (ret)
+		return ret;
+
 	ap_config_set_crycb_masks(kvm, masks);
 
 	return 0;
Signature · 1 line
1.7.1
#59 lore raw

RFC 18/19 KVM: s390: New ioctl to configure KVM guest's AP matrix

In reply to Tony Krowiak

Implements an ioctl to configure the adapters, usage domains and control domains to which a KVM guest will be granted access. The ioctl is invoked using the VFIO mediated matrix device's file descriptor.

Guest access to AP adapters, usage domains and control domains is controlled by three bit masks referenced from the guest's SIE state description: The AP Mask (APM) controls access to the AP adapters; the AP Queue Mask (AQM) controls access to the AP usage domains; and the AP Domain Mask (ADM) controls access to the AP control domains. Each bit in the APM represents an adapter, from left to right, starting with adapter 0. Each bit in the AQM represents a usage domain, from left to right, starting with domain 0. Each bit in the ADM represents a control domain, from left to right, starting with domain 0.

The APM, AQM and ADM bit masks will be populated from the bit masks stored in the corresponding mediated matrix device's sysfs files. The bit masks will also be returned by the ioctl call to the caller.

---
 drivers/s390/crypto/vfio_ap_matrix_ops.c |   68 +++++++++++++++++++++++++++++-
 include/uapi/linux/vfio.h                |   20 +++++++++
 2 files changed, 86 insertions(+), 2 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +66 -2
index 74ea8db..d81e3ab 100644
@@ -160,8 +160,69 @@ static int ap_matrix_mdev_get_device_info(unsigned long arg)
 	return copy_to_user((void __user *)arg, &info, minsz);
 }
 
-static ssize_t ap_matrix_mdev_ioctl(struct mdev_device *mdev,
-				    unsigned int cmd, unsigned long arg)
+static int ap_matrix_configure(struct mdev_device *mdev)
+{
+	int ret;
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_config_matrix(matrix_mdev->kvm, &matrix_mdev->masks);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int ap_matrix_copy_to_user(struct mdev_device *mdev,
+				  struct vfio_ap_matrix_config *mcfg,
+				  unsigned long arg)
+{
+	size_t i;
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+
+	for (i = 0; i < AP_MATRIX_MASK_INDICES; i++) {
+		if (i < VFIO_AP_MATRIX_MASK_INDICES) {
+			mcfg->apm[i] = matrix_mdev->masks.apm[i];
+			mcfg->aqm[i] = matrix_mdev->masks.aqm[i];
+			mcfg->adm[i] = matrix_mdev->masks.adm[i];
+		}
+	}
+
+	if (copy_to_user((void __user *)arg, &mcfg, sizeof(mcfg)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static ssize_t ap_matrix_mdev_configure(struct mdev_device *mdev,
+					unsigned long arg)
+{
+	int ret;
+	unsigned long minsz;
+	struct vfio_ap_matrix_config mcfg;
+
+	minsz = offsetofend(struct vfio_ap_matrix_config, adm);
+
+	if (copy_from_user(&mcfg, (void __user *)arg, minsz))
+		return -EFAULT;
+
+	if (mcfg.argsz < minsz) {
+		pr_err("%s: Argument size %u less than min size %li",
+		       VFIO_AP_MATRIX_MODULE_NAME, mcfg.argsz, minsz);
+		return -EINVAL;
+	}
+
+	ret = ap_matrix_configure(mdev);
+	if (ret)
+		return ret;
+
+	ret = ap_matrix_copy_to_user(mdev, &mcfg, arg);
+
+	return 0;
+}
+
+static long ap_matrix_mdev_ioctl(struct mdev_device *mdev,
+				 unsigned int cmd, unsigned long arg)
 {
 	int ret;
 
@@ -169,6 +230,9 @@ static ssize_t ap_matrix_mdev_ioctl(struct mdev_device *mdev,
 	case VFIO_DEVICE_GET_INFO:
 		ret = ap_matrix_mdev_get_device_info(arg);
 		break;
+	case VFIO_AP_MATRIX_CONFIGURE:
+		ret = ap_matrix_mdev_configure(mdev, arg);
+		break;
 	default:
 		pr_err("%s: ioctl command %d is not a supported command",
 		       VFIO_AP_MATRIX_MODULE_NAME, cmd);
include/uapi/linux/vfio.h +20 -0
index 08f1ab4..2d96c57 100644
@@ -716,6 +716,26 @@ struct vfio_iommu_spapr_tce_remove {
 };
 #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
+/**
+ * VFIO_AP_MATRIX_CONFIGURE		_IO(VFIO_TYPE, VFIO_BASE + 21
+ *
+ * Configure the AP matrix for a KVM guest.
+ */
+#define VFIO_AP_MATRIX_CONFIGURE	_IO(VFIO_TYPE, VFIO_BASE + 21)
+
+#define VFIO_AP_MATRIX_MASK_INDICES	4
+#define VFIO_AP_MATTRIX_MASK_BYTES	(VFIO_AP_MATRIX_MASK_INDICES * \
+					 sizeof(__u64))
+#define VFIO_AP_MATRIX_MASK_BITS	(VFIO_AP_MATTRIX_MASK_BYTES * 8)
+
+struct vfio_ap_matrix_config {
+	__u32 argsz;
+	__u32 flags;
+	/* out */
+	__u64 apm[VFIO_AP_MATRIX_MASK_INDICES];
+	__u64 aqm[VFIO_AP_MATRIX_MASK_INDICES];
+	__u64 adm[VFIO_AP_MATRIX_MASK_INDICES];
+};
 /* ***************************************************************** */
 
 #endif /* _UAPIVFIO_H */
Signature · 1 line
1.7.1
#60 lore raw

Re: [RFC 18/19] KVM: s390: New ioctl to configure KVM guest's AP matrix

Quoted 58 lines · Tony Krowiak

Implements an ioctl to configure the adapters, usage domains and control domains to which a KVM guest will be granted access. The ioctl is invoked using the VFIO mediated matrix device's file descriptor.

Guest access to AP adapters, usage domains and control domains is controlled by three bit masks referenced from the guest's SIE state description: The AP Mask (APM) controls access to the AP adapters; the AP Queue Mask (AQM) controls access to the AP usage domains; and the AP Domain Mask (ADM) controls access to the AP control domains. Each bit in the APM represents an adapter, from left to right, starting with adapter 0. Each bit in the AQM represents a usage domain, from left to right, starting with domain 0. Each bit in the ADM represents a control domain, from left to right, starting with domain 0.

The APM, AQM and ADM bit masks will be populated from the bit masks stored in the corresponding mediated matrix device's sysfs files. The bit masks will also be returned by the ioctl call to the caller.

---
  drivers/s390/crypto/vfio_ap_matrix_ops.c |   68 +++++++++++++++++++++++++++++-
  include/uapi/linux/vfio.h                |   20 +++++++++
  2 files changed, 86 insertions(+), 2 deletions(-)
drivers/s390/crypto/vfio_ap_matrix_ops.c +20 -2
index 74ea8db..d81e3ab 100644
@@ -160,8 +160,69 @@ static int ap_matrix_mdev_get_device_info(unsigned long arg)
  	return copy_to_user((void __user *)arg, &info, minsz);
  }
 
-static ssize_t ap_matrix_mdev_ioctl(struct mdev_device *mdev,
-				    unsigned int cmd, unsigned long arg)
+static int ap_matrix_configure(struct mdev_device *mdev)
+{
+	int ret;
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+	ret = ap_config_matrix(matrix_mdev->kvm, &matrix_mdev->masks);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int ap_matrix_copy_to_user(struct mdev_device *mdev,
+				  struct vfio_ap_matrix_config *mcfg,
+				  unsigned long arg)
+{
+	size_t i;
+	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+

drivers/s390/crypto/vfio_ap_matrix_ops.c static int ap_matrix_mdev_get_device_info(unsigned long arg) · line 192

Quoted 10 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +10 -0
+	for (i = 0; i < AP_MATRIX_MASK_INDICES; i++) {
+		if (i < VFIO_AP_MATRIX_MASK_INDICES) {
+			mcfg->apm[i] = matrix_mdev->masks.apm[i];
+			mcfg->aqm[i] = matrix_mdev->masks.aqm[i];
+			mcfg->adm[i] = matrix_mdev->masks.adm[i];
+		}
+	}
+
+	if (copy_to_user((void __user *)arg, &mcfg, sizeof(mcfg)))
+		return -EFAULT;

This is in error and needs to be:

if (copy_to_user((void __user *)arg, &mcfg, sizeof(*mcfg)))

	return -EFAULT;
Quoted 77 lines
drivers/s390/crypto/vfio_ap_matrix_ops.c +36 -0
+
+	return 0;
+}
+
+static ssize_t ap_matrix_mdev_configure(struct mdev_device *mdev,
+					unsigned long arg)
+{
+	int ret;
+	unsigned long minsz;
+	struct vfio_ap_matrix_config mcfg;
+
+	minsz = offsetofend(struct vfio_ap_matrix_config, adm);
+
+	if (copy_from_user(&mcfg, (void __user *)arg, minsz))
+		return -EFAULT;
+
+	if (mcfg.argsz < minsz) {
+		pr_err("%s: Argument size %u less than min size %li",
+		       VFIO_AP_MATRIX_MODULE_NAME, mcfg.argsz, minsz);
+		return -EINVAL;
+	}
+
+	ret = ap_matrix_configure(mdev);
+	if (ret)
+		return ret;
+
+	ret = ap_matrix_copy_to_user(mdev, &mcfg, arg);
+
+	return 0;
+}
+
+static long ap_matrix_mdev_ioctl(struct mdev_device *mdev,
+				 unsigned int cmd, unsigned long arg)
  {
  	int ret;
 
@@ -169,6 +230,9 @@ static ssize_t ap_matrix_mdev_ioctl(struct mdev_device *mdev,
  	case VFIO_DEVICE_GET_INFO:
  		ret = ap_matrix_mdev_get_device_info(arg);
  		break;
+	case VFIO_AP_MATRIX_CONFIGURE:
+		ret = ap_matrix_mdev_configure(mdev, arg);
+		break;
  	default:
  		pr_err("%s: ioctl command %d is not a supported command",
  		       VFIO_AP_MATRIX_MODULE_NAME, cmd);
include/uapi/linux/vfio.h +20 -0
index 08f1ab4..2d96c57 100644
@@ -716,6 +716,26 @@ struct vfio_iommu_spapr_tce_remove {
  };
  #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
+/**
+ * VFIO_AP_MATRIX_CONFIGURE		_IO(VFIO_TYPE, VFIO_BASE + 21
+ *
+ * Configure the AP matrix for a KVM guest.
+ */
+#define VFIO_AP_MATRIX_CONFIGURE	_IO(VFIO_TYPE, VFIO_BASE + 21)
+
+#define VFIO_AP_MATRIX_MASK_INDICES	4
+#define VFIO_AP_MATTRIX_MASK_BYTES	(VFIO_AP_MATRIX_MASK_INDICES * \
+					 sizeof(__u64))
+#define VFIO_AP_MATRIX_MASK_BITS	(VFIO_AP_MATTRIX_MASK_BYTES * 8)
+
+struct vfio_ap_matrix_config {
+	__u32 argsz;
+	__u32 flags;
+	/* out */
+	__u64 apm[VFIO_AP_MATRIX_MASK_INDICES];
+	__u64 aqm[VFIO_AP_MATRIX_MASK_INDICES];
+	__u64 adm[VFIO_AP_MATRIX_MASK_INDICES];
+};
  /* ***************************************************************** */
 
  #endif /* _UAPIVFIO_H */
#61 lore raw

RFC 19/19 s390/facilities: enable AP facilities needed by guest

In reply to Tony Krowiak

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
 arch/s390/tools/gen_facilities.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +2 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {
 			8,  /* enhanced-DAT 1 */
 			9,  /* sense-running-status */
 			10, /* conditional sske */
+			12, /* AP query configuration */
 			13, /* ipte-range */
 			14, /* nonquiescing key-setting */
+			15, /* AP special-command facility */
 			73, /* transactional execution */
 			75, /* access-exception-fetch/store indication */
 			76, /* msa extension 3 */
Signature · 1 line
1.7.1
#62 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 21 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
 arch/s390/tools/gen_facilities.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +0 -0
index 70dd8f1..eeaa7db 100644

arch/s390/tools/gen_facilities.c struct facility_def { · line 83

Quoted 10 lines
arch/s390/tools/gen_facilities.c +2 -0
@@ -74,8 +74,10 @@ struct facility_def {
 			8,  /* enhanced-DAT 1 */
 			9,  /* sense-running-status */
 			10, /* conditional sske */
+			12, /* AP query configuration */
 			13, /* ipte-range */
 			14, /* nonquiescing key-setting */
+			15, /* AP special-command facility */
 			73, /* transactional execution */
 			75, /* access-exception-fetch/store indication */
 			76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#63 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 32 lines · Martin Schwidefsky
Quoted 29 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
 arch/s390/tools/gen_facilities.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +2 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {
 			8,  /* enhanced-DAT 1 */
 			9,  /* sense-running-status */
 			10, /* conditional sske */
+			12, /* AP query configuration */
 			13, /* ipte-range */
 			14, /* nonquiescing key-setting */
+			15, /* AP special-command facility */
 			73, /* transactional execution */
Quoted 8 lines

arch/s390/tools/gen_facilities.c struct facility_def { · line 83

Quoted 2 lines
arch/s390/tools/gen_facilities.c +0 -0
 			75, /* access-exception-fetch/store indication */
 			76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

#64 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 44 lines · Christian Borntraeger
Quoted 32 lines · Martin Schwidefsky
Quoted 29 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
 arch/s390/tools/gen_facilities.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +2 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {
 			8,  /* enhanced-DAT 1 */
 			9,  /* sense-running-status */
 			10, /* conditional sske */
+			12, /* AP query configuration */
 			13, /* ipte-range */
 			14, /* nonquiescing key-setting */
+			15, /* AP special-command facility */
 			73, /* transactional execution */
Quoted 8 lines

arch/s390/tools/gen_facilities.c struct facility_def { · line 83

Quoted 2 lines
arch/s390/tools/gen_facilities.c +0 -0
 			75, /* access-exception-fetch/store indication */
 			76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

Quoted 3 lines

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

I've tried to figure these things out last week but I've failed.

Right at the beginning of AR-10334-03-POK we have this text:
"An adjunct processor (AP) facility consists of the three AP instructions, and one to sixty-four APs.". This reads like if we have AP facility we have to have at least one AP.

But when I've tried to get a better understanding how the presence/absence of the AP facility is indicated and what facility bits do we have in this context I got confused.

Tony, could you please give us a detailed summary on this (best with references, and focusing on the (guest) program perspective)?

Regards,
Halil

A message that is not in the archive (sent off-list or not yet received): [email protected]

#66 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 42 lines · Tony Krowiak
Quoted 41 lines · Christian Borntraeger
Quoted 39 lines · Martin Schwidefsky
Quoted 21 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
 arch/s390/tools/gen_facilities.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +0 -0
index 70dd8f1..eeaa7db 100644

arch/s390/tools/gen_facilities.c struct facility_def { · line 83

Quoted 10 lines
arch/s390/tools/gen_facilities.c +2 -0
@@ -74,8 +74,10 @@ struct facility_def {
 			8,  /* enhanced-DAT 1 */
 			9,  /* sense-running-status */
 			10, /* conditional sske */
+			12, /* AP query configuration */
 			13, /* ipte-range */
 			14, /* nonquiescing key-setting */
+			15, /* AP special-command facility */
 			73, /* transactional execution */
 			75, /* access-exception-fetch/store indication */
 			76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

Quoted 6 lines
Quoted 3 lines

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

I don't believe these facilities control whether or not AP instructions will be available

to the guest.

This is actually handled by your patch2 enabling the ECA bit.
I think we must decide if we want to be able to disable these instructions via the cpu model. If yes we must then couple the facilities with the enablement.

#67 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 46 lines · Christian Borntraeger
Quoted 44 lines · Tony Krowiak
Quoted 43 lines · Christian Borntraeger
Quoted 31 lines · Martin Schwidefsky
Quoted 28 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
  arch/s390/tools/gen_facilities.c |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +2 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {
  			8,  /* enhanced-DAT 1 */
  			9,  /* sense-running-status */
  			10, /* conditional sske */
+			12, /* AP query configuration */
  			13, /* ipte-range */
  			14, /* nonquiescing key-setting */
+			15, /* AP special-command facility */
Quoted 8 lines

arch/s390/tools/gen_facilities.c struct facility_def { · line 83

Quoted 3 lines
arch/s390/tools/gen_facilities.c +0 -0
  			73, /* transactional execution */
  			75, /* access-exception-fetch/store indication */
  			76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

Quoted 6 lines
Quoted 3 lines

I don't believe these facilities control whether or not AP instructions will be available

to the guest.

This is actually handled by your patch2 enabling the ECA bit.
I think we must decide if we want to be able to disable these instructions via the cpu model. If yes we must then couple the facilities with the enablement.

The ECA.28 bit controls whether instructions are intercepted or interpreted - i.e., handled via hardware virtualization. If set, as is done in patch2, then instructions will be interpreted. I don't see how that affects enabling or disabling AP instructions, unless we don't set ECA.28, intercept every instruction and program check. Am I missing something here?

Quoted 1 line
#68 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 49 lines · Tony Krowiak
Quoted 48 lines · Christian Borntraeger
Quoted 46 lines · Tony Krowiak
Quoted 40 lines · Christian Borntraeger
Quoted 31 lines · Martin Schwidefsky
Quoted 28 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
     * STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
     * STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
  arch/s390/tools/gen_facilities.c |    2 ++

  1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +0 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {

              8,  /* enhanced-DAT 1 */
              9,  /* sense-running-status */ 10, /* conditional sske */
+            12, /* AP query configuration */ 13, /* ipte-range */
              14, /* nonquiescing key-setting */ +            15, /* AP special-command facility */

Quoted 8 lines
Quoted 3 lines

              73, /* transactional execution */
              75, /* access-exception-fetch/store indication */ 76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

Quoted 3 lines

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

I don't believe these facilities control whether or not AP instructions will be available

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

to the guest.

This is actually handled by your patch2 enabling the ECA bit.
I think we must decide if we want to be able to disable these instructions via the cpu model. If yes we must then couple the facilities with the enablement.

The ECA.28 bit controls whether instructions are intercepted or interpreted - i.e., handled via hardware virtualization. If set, as is done in patch2, then instructions will be interpreted. I don't see how that affects enabling or disabling AP instructions, unless we don't set ECA.28, intercept every instruction and program check. Am I missing something here?

If we do not set ECA.28 these instructions intercept and we (the hypervisor) can then decide what to do. For example we can give an PIC01 operation exception (illegal instruction) - thats what we do today.

Now: if we want to be able to migrate a guest from a new kernel back to an old kernel, there must be a way to disable the new behaviour so that the user can configure a guest that does NOT have these 3 instructions. That means, I want to bind the ap instruction to a cpu model feature, so that we only enable ECA.28 and the facility bits, if the feature is enabled in the CPU model. Otherwise we have no control on what happens when the guest issues these instructions.

Imagine what happens if we not do this and you migrate from an identical hw with an identical libvirt/qemu but from a new kernel to an old kernel:

The guest boots starts up on the new kernel
guest kernel: drivers/s390/crypto/ap_bus.c ap_module_init -> ap_instructions_available checks if the instructions work. They do and now the guest driver assumes that all instructions will continue to work.

Now the guest is migrated back to an old kernel
sooner or later the ap_scan_bus kthread will run to scan the bus (or some crypto operation is started) and the instruction will be rejected with a PIC01. kernel oops.

#69 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 72 lines · Christian Borntraeger
Quoted 48 lines · Tony Krowiak
Quoted 47 lines · Christian Borntraeger
Quoted 46 lines · Tony Krowiak
Quoted 40 lines · Christian Borntraeger
Quoted 31 lines · Martin Schwidefsky
Quoted 28 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
   arch/s390/tools/gen_facilities.c |    2 ++
   1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +2 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {
               8,  /* enhanced-DAT 1 */
               9,  /* sense-running-status */
               10, /* conditional sske */
+            12, /* AP query configuration */
               13, /* ipte-range */
               14, /* nonquiescing key-setting */
+            15, /* AP special-command facility */
Quoted 8 lines

arch/s390/tools/gen_facilities.c struct facility_def { · line 83

Quoted 3 lines
arch/s390/tools/gen_facilities.c +0 -0
               73, /* transactional execution */
               75, /* access-exception-fetch/store indication */
               76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

Quoted 3 lines

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

I don't believe these facilities control whether or not AP instructions will be available

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

to the guest.

This is actually handled by your patch2 enabling the ECA bit.
I think we must decide if we want to be able to disable these instructions via the cpu model. If yes we must then couple the facilities with the enablement.

The ECA.28 bit controls whether instructions are intercepted or interpreted - i.e., handled via hardware virtualization. If set, as is done in patch2, then instructions will be interpreted. I don't see how that affects enabling or disabling AP instructions, unless we don't set ECA.28, intercept every instruction and program check. Am I missing something here?

If we do not set ECA.28 these instructions intercept and we (the hypervisor) can then decide what to do. For example we can give an PIC01 operation exception (illegal instruction) - thats what we do today.

Now: if we want to be able to migrate a guest from a new kernel back to an old kernel, there must be a way to disable the new behaviour so that the user can configure a guest that does NOT have these 3 instructions. That means, I want to bind the ap instruction to a cpu model feature, so that we only enable ECA.28 and the facility bits, if the feature is enabled in the CPU model. Otherwise we have no control on what happens when the guest issues these instructions.

Imagine what happens if we not do this and you migrate from an identical hw with an identical libvirt/qemu but from a new kernel to an old kernel:

Quoted 8 lines

The guest boots starts up on the new kernel
guest kernel: drivers/s390/crypto/ap_bus.c ap_module_init -> ap_instructions_available checks if the instructions work. They do and now the guest driver assumes that all instructions will continue to work.

Now the guest is migrated back to an old kernel
sooner or later the ap_scan_bus kthread will run to scan the bus (or some crypto operation is started) and the instruction will be rejected with a PIC01. kernel oops.

There are several scenarios that have to be accounted for, such as:
* Migrating from a linux host where both the KVM/kernel and QEMU support AP matrix devices to a guest host where neither the KVM/kernel nor QEMU support
AP matrix
devices;
* Migrating from a linux host where both the KVM/kernel and QEMU support AP matrix devices to a guest host where the KVM/kernel does not support AP
matrix devices
but QEMU does;
* Starting a guest on a linux host where QEMU supports AP matrix devices and the KVM/kernel does not;
* etc.

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For
example,
if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed,
then AP
queues 04.0047, 05.0047 and 06.0047 will not be made available.

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers
discovered
by the AP bus scan will not get bound to any AP device drivers. Since
the
AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

If the AP bus running on the guest is expected to mimic the behavior of an AP bus running on the host, then I think we need a CPU model feature for each facility. Otherwise, I think we can group them within a CPU model feature that indicates AP matrix devices are supported. What say you?

Quoted 2 lines
#70 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 101 lines · Tony Krowiak
Quoted 72 lines · Christian Borntraeger
Quoted 48 lines · Tony Krowiak
Quoted 47 lines · Christian Borntraeger
Quoted 46 lines · Tony Krowiak
Quoted 40 lines · Christian Borntraeger
Quoted 31 lines · Martin Schwidefsky
Quoted 28 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
      * STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
      * STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
   arch/s390/tools/gen_facilities.c |    2 ++

   1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +0 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {

               8,  /* enhanced-DAT 1 */
               9,  /* sense-running-status */ 10, /* conditional sske */ +            12, /* AP query configuration */ 13, /* ipte-range */
               14, /* nonquiescing key-setting */ +            15, /* AP special-command facility */

Quoted 8 lines
Quoted 3 lines

               73, /* transactional execution */
               75, /* access-exception-fetch/store indication */ 76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

Quoted 3 lines

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

I don't believe these facilities control whether or not AP instructions will be available

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

to the guest.

This is actually handled by your patch2 enabling the ECA bit.
I think we must decide if we want to be able to disable these instructions via the cpu model. If yes we must then couple the facilities with the enablement.

The ECA.28 bit controls whether instructions are intercepted or interpreted - i.e., handled via hardware virtualization. If set, as is done in patch2, then instructions will be interpreted. I don't see how that affects enabling or disabling AP instructions, unless we don't set ECA.28, intercept every instruction and program check. Am I missing something here?

If we do not set ECA.28 these instructions intercept and we (the hypervisor) can then decide what to do. For example we can give an PIC01 operation exception (illegal instruction) - thats what we do today.

Now: if we want to be able to migrate a guest from a new kernel back to an old kernel, there must be a way to disable the new behaviour so that the user can configure a guest that does NOT have these 3 instructions. That means, I want to bind the ap instruction to a cpu model feature, so that we only enable ECA.28 and the facility bits, if the feature is enabled in the CPU model. Otherwise we have no control on what happens when the guest issues these instructions.

Imagine what happens if we not do this and you migrate from an identical hw with an identical libvirt/qemu but from a new kernel to an old kernel:

Quoted 8 lines

The guest boots starts up on the new kernel
guest kernel: drivers/s390/crypto/ap_bus.c  ap_module_init -> ap_instructions_available checks if the instructions work. They do and now the guest driver assumes that all instructions will continue to work.

Now the guest is migrated back to an old kernel
sooner or later the ap_scan_bus kthread will run to scan the bus (or some crypto operation is started) and the instruction will be rejected with a PIC01. kernel oops.

There are several scenarios that have to be accounted for, such as:
* Migrating from a linux host where both the KVM/kernel and QEMU support AP matrix devices to a guest host where neither the KVM/kernel nor QEMU support AP matrix devices;
* Migrating from a linux host where both the KVM/kernel and QEMU support AP matrix devices to a guest host where the KVM/kernel does not support AP matrix devices but QEMU does;
* Starting a guest on a linux host where QEMU supports AP matrix devices and the KVM/kernel does not;
* etc.

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

Quoted 16 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

If the AP bus running on the guest is expected to mimic the behavior of an AP bus running on the host, then I think we need a CPU model feature for each facility. Otherwise, I think we can group them within a CPU model feature that indicates AP matrix devices are supported. What say you?

Quoted 2 lines
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-s390" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#71 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 21 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 9 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

Quoted 3 lines
Quoted 3 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

#72 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 33 lines · Cornelia Huck
Quoted 21 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 9 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

Yes, STFLE 65, it is for AP only.

QCI, STFLE 12, is no present on older systems, in this case AP uses TAPQ to retrieve information for each AP

So for my point of view, it make sense to separate the three facilities to enable migration on older systems.

Pierre

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

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 43 lines · On Tue, 5 Dec 2017 15:23:50 +0100 Pierre Morel <[email protected]>…
Quoted 33 lines · Cornelia Huck
Quoted 21 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 9 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

Quoted 4 lines

Yes, STFLE 65, it is for AP only.

QCI, STFLE 12, is no present on older systems, in this case AP uses TAPQ to retrieve information for each AP

Dumb question: How old? Machines that are still supported?

Quoted 3 lines

So for my point of view, it make sense to separate the three facilities to enable migration on older systems.

OK, if STFLE 12 might not be present (pending my question above), but STFLE 15 is indeed a must-have, we should split this up.

#74 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 46 lines · Cornelia Huck
Quoted 43 lines · On Tue, 5 Dec 2017 15:23:50 +0100 Pierre Morel <[email protected]>…
Quoted 41 lines · Cornelia Huck
Quoted 21 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 9 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

Quoted 3 lines
Quoted 3 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

Quoted 6 lines
Quoted 4 lines

Yes, STFLE 65, it is for AP only.

QCI, STFLE 12, is no present on older systems, in this case AP uses TAPQ to retrieve information for each AP

Dumb question: How old? Machines that are still supported?

No idea which machine are supported or not, will ask.

What I can say is that I have here a Lpar which does not support QCI. It seems to be a zEC12.2.
z13 support it.

Quoted 8 lines
Quoted 4 lines

So for my point of view, it make sense to separate the three facilities to enable migration on older systems.

OK, if STFLE 12 might not be present (pending my question above), but STFLE 15 is indeed a must-have, we should split this up.

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

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

In reply to Pierre Morel
Quoted 50 lines · Pierre Morel
Quoted 39 lines · Cornelia Huck
Quoted 27 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 9 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 6 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15.
For example,
if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are
installed, then AP
queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 9 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers
discovered
by the AP bus scan will not get bound to any AP device drivers.
Since theI think
STFLE.12
AP matrix model supports only CEX4 and greater, no devices will
be bound
to any driver for a guest.

Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt
handlers
to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

Quoted 5 lines

Yes, STFLE 65, it is for AP only.

QCI, STFLE 12, is no present on older systems, in this case AP uses TAPQ to retrieve information for each AP

So for my point of view, it make sense to separate the three facilities to enable migration on older syste

In the interest of keeping things simple, this makes sense.

Quoted 5 lines

Pierre

#76 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

In reply to Cornelia Huck
Quoted 23 lines · Cornelia Huck
Quoted 20 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 9 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

Quoted 7 lines
Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

After thinking about this a little more, I've come to the conclusion that all of this might be moot for the following reasons:

* If STFLE.12 is not set for the linux host, then AP bus scan running on the host will not detect any domains with a domain number higher than 15, so no AP queues with a queue index higher than 15 will be available to bind to the vfio_ap_matrix driver. Consequently, no domain higher than 15 can be assigned to any guest. In this case, the AP bus scan
running on
the guest will never detect a domain higher than 15, regardless of the setting of STFLE.12 for the guest.

* If STFLE.15 is not set for the linux host, then then there will be no CEX4, CEX5 or CEX6 queues available to bind to the vfio_ap_matrix driver, so no AP adapters or domains can be assigned to any KVM guest.

The bottom line is the STFLE bit settings for the linux host will control what APs are available to the KVM guest. Since STFLE.15 controls whether any CEX4,5 or 6 devices are even available, I think this bit can be combined into the feature that indicates whether AP is available. As long as AP instructions are available on the linux host, I'm not sure whether STFLE.12 needs a feature at all.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

Yes, this indicates AP interrupts only. The plan is to enable this when GISA is available and we can implement interrupt processing.

Quoted 1 line
#77 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 48 lines · Tony Krowiak
Quoted 23 lines · Cornelia Huck
Quoted 20 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 9 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

Quoted 7 lines
Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

After thinking about this a little more, I've come to the conclusion that all of this might be moot for the following reasons:

* If STFLE.12 is not set for the linux host, then AP bus scan running on the host will not detect any domains with a domain number higher than
15,
  so no AP queues with a queue index higher than 15 will be available to bind to the vfio_ap_matrix driver. Consequently, no domain higher than 15 can be assigned to any guest. In this case, the AP bus scan
running on
  the guest will never detect a domain higher than 15, regardless of the setting of STFLE.12 for the guest.

* If STFLE.15 is not set for the linux host, then then there will be no CEX4, CEX5 or CEX6 queues available to bind to the vfio_ap_matrix driver, so no AP adapters or domains can be assigned to any KVM guest.

Quoted 6 lines

The bottom line is the STFLE bit settings for the linux host will control what APs are available to the KVM guest. Since STFLE.15 controls whether any CEX4,5 or 6 devices are even available, I think this bit can be combined into the feature that indicates whether AP is available. As long as AP instructions are available on the linux host, I'm not sure whether STFLE.12 needs a feature at all.

We are implementing VFIO with SIE interpretation.

1) Providing more:
The simple way is to provide to the guest only features existing on the host.
If we do provide features not existing on the host we need to be able to emulate them.
Even it is possible, it could be done in a future enhancement, but AFAIK it is not the goal of the current development.

2) Providing less:
On the other hand we can mask to the guest some of the features provided by the host if we can intercept the scanning of the features.

What I understand from this is that we need all these features being separately toggled to be able to be compatible with an older system even if we have a 1:1 host:guest features match in a first version.

If several features where introduced together in a new architecture and are available on all systems issued from this architecture we can then gather them in a set. (But I will wonder why we have several features then)

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

Yes, this indicates AP interrupts only. The plan is to enable this when GISA is available and we can implement interrupt processing.

If we want to be able to work on system where STFLE.65 is not available, even if GISA is available I think it would be interesting to have a Matrix implementation with only polling.

Regards,

Pierre

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

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 77 lines · On Wed, 6 Dec 2017 10:15:51 +0100 Pierre Morel <[email protected]>…
Quoted 67 lines · Tony Krowiak
Quoted 47 lines · Cornelia Huck
Quoted 35 lines · On Tue, 5 Dec 2017 08:52:57 +0100 Harald Freudenberger…
Quoted 16 lines · Tony Krowiak

I agree with your suggestion that defining a new CPU model feature is probably
the best way to resolve this issue. The question is, should we define a single
feature indicating whether AP instructions are installed and set features bits
for the guest based on whether or not they are set in the linux host, or should
we define additional CPU model features for turning features bits on and off?
I guess it boils down to what behavior is expected for the AP bus running on
the linux guest. Here is a rundown of the facilities bits associated with AP
and how they affect the behavior of the AP bus:

Quoted 7 lines

* STFLE.12 indicates whether the AP query function is available. If this bit
   is not set, then the AP bus scan will only test domains 0-15. For example,
   if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP
   queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 9 lines

* STFLE.15 indicates whether the AP facilities test function is available. If
   this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered
   by the AP bus scan will not get bound to any AP device drivers. Since the
   AP matrix model supports only CEX4 and greater, no devices will be bound
   to any driver for a guest.

Quoted 9 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only
supports CEX4 and upper then this bit could also act as the indicator for
AP instructions available. Of course if you want to implement pure virtual
full simulated AP without any real AP hardware on the host this bit can't
be the indicator.

Quoted 2 lines

It would probably make sense to group these two together. Or is there any advantage in supporting only a part of it?

After thinking about this a little more, I've come to the conclusion that all of this might be moot for the following reasons:

* If STFLE.12 is not set for the linux host, then AP bus scan running on the host will not detect any domains with a domain number higher than
15,
  so no AP queues with a queue index higher than 15 will be available to bind to the vfio_ap_matrix driver. Consequently, no domain higher than 15 can be assigned to any guest. In this case, the AP bus scan
running on
  the guest will never detect a domain higher than 15, regardless of the setting of STFLE.12 for the guest.

* If STFLE.15 is not set for the linux host, then then there will be no CEX4, CEX5 or CEX6 queues available to bind to the vfio_ap_matrix driver, so no AP adapters or domains can be assigned to any KVM guest.

Quoted 6 lines

The bottom line is the STFLE bit settings for the linux host will control what APs are available to the KVM guest. Since STFLE.15 controls whether any CEX4,5 or 6 devices are even available, I think this bit can be combined into the feature that indicates whether AP is available. As long as AP instructions are available on the linux host, I'm not sure whether STFLE.12 needs a feature at all.

We are implementing VFIO with SIE interpretation.

Quoted 7 lines

1) Providing more:
The simple way is to provide to the guest only features existing on the host.
If we do provide features not existing on the host we need to be able to emulate them.
Even it is possible, it could be done in a future enhancement, but AFAIK it is not the goal of the current development.

Yes. I think we currently want to provide a subset of what the SIE can do. Any emulation would be icing on top.

Quoted 4 lines

2) Providing less:
On the other hand we can mask to the guest some of the features provided by the host if we can intercept the scanning of the features.

Yes. I think that applies to bit 65 (interrupts) for now.

Quoted 5 lines

What I understand from this is that we need all these features being separately toggled to be able to be compatible with an older system even if we have a 1:1 host:guest features match in a first version.

This seems to be the case for the mentioned bits if I followed the discussion correctly.

Quoted 4 lines

If several features where introduced together in a new architecture and are available on all systems issued from this architecture we can then gather them in a set. (But I will wonder why we have several features then)

You're expecting that all architecture is making sense ;)

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not
   set, then the AP bus will use polling instead of using interrupt handlers
   to process AP events.

So, does this indicate "adapter interrupts for AP" only? If so, we should keep this separate and only enable it when we have the gisa etc. ready.

Quoted 6 lines
Quoted 2 lines

Yes, this indicates AP interrupts only. The plan is to enable this when GISA is available and we can implement interrupt processing.

If we want to be able to work on system where STFLE.65 is not available, even if GISA is available I think it would be interesting to have a Matrix implementation with only polling.

Agreed.

So, it seems what we want is:

- A feature for STFLE 12. This seems to be a z13 or later facility, so it probably makes sense to indicate it in the guest for z13 or newer if the host supports it and for older machines if it is explicitly specified (and the host supports it).
- A feature for STFLE 15. Similar to the one above, but starting with a different generation (when was this introduced?)
- A feature for STFLE 65. Can be deferred to when GISA is implemented (and exploited by vfio-ap). Same as above (I think this has existed for a long time, probably for any of the machines we support?)

Thoughts?

#79 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

In reply to Harald Freudenberger
Quoted 111 lines · Harald Freudenberger
Quoted 100 lines · Tony Krowiak
Quoted 71 lines · Christian Borntraeger
Quoted 48 lines · Tony Krowiak
Quoted 47 lines · Christian Borntraeger
Quoted 46 lines · Tony Krowiak
Quoted 40 lines · Christian Borntraeger
Quoted 31 lines · Martin Schwidefsky
Quoted 28 lines · On Fri, 13 Oct 2017 13:39:04 -0400 Tony Krowiak <[email protected]>…

Sets up the following facilities bits to enable the specified AP facilities for the guest VM:
* STFLE.12: Enables the AP Query Configuration Information facility. The AP bus running in the guest uses the information returned from this instruction to configure AP adapters and domains for the guest machine.
* STFLE.15: Indicates the AP facilities test is available. The AP bus running in the guest uses the information.

---
    arch/s390/tools/gen_facilities.c |    2 ++
    1 files changed, 2 insertions(+), 0 deletions(-)
arch/s390/tools/gen_facilities.c +2 -0
index 70dd8f1..eeaa7db 100644
@@ -74,8 +74,10 @@ struct facility_def {
                8,  /* enhanced-DAT 1 */
                9,  /* sense-running-status */
                10, /* conditional sske */
+            12, /* AP query configuration */
                13, /* ipte-range */
                14, /* nonquiescing key-setting */
+            15, /* AP special-command facility */
Quoted 8 lines

arch/s390/tools/gen_facilities.c struct facility_def { · line 83

Quoted 3 lines
arch/s390/tools/gen_facilities.c +0 -0
                73, /* transactional execution */
                75, /* access-exception-fetch/store indication */
                76, /* msa extension 3 */

With this all KVM guests will always have the AP instructions available, no? In principles I like this approach, but it differs from the way z/VM does things, there the guest will get an exception if it tries to execute an AP instruction if there are no AP devices assigned to the guest. I wonder if there is a reason why z/VM does it the way it does.

Quoted 3 lines

A good question. For LPAR it seems that you have AP instructions even if you have no crypto cards.

I don't believe these facilities control whether or not AP instructions will be available

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

to the guest.

This is actually handled by your patch2 enabling the ECA bit.
I think we must decide if we want to be able to disable these instructions via the cpu model. If yes we must then couple the facilities with the enablement.

The ECA.28 bit controls whether instructions are intercepted or interpreted - i.e., handled via hardware virtualization. If set, as is done in patch2, then instructions will be interpreted. I don't see how that affects enabling or disabling AP instructions, unless we don't set ECA.28, intercept every instruction and program check. Am I missing something here?

If we do not set ECA.28 these instructions intercept and we (the hypervisor) can then decide what to do. For example we can give an PIC01 operation exception (illegal instruction) - thats what we do today.

Now: if we want to be able to migrate a guest from a new kernel back to an old kernel, there must be a way to disable the new behaviour so that the user can configure a guest that does NOT have these 3 instructions. That means, I want to bind the ap instruction to a cpu model feature, so that we only enable ECA.28 and the facility bits, if the feature is enabled in the CPU model. Otherwise we have no control on what happens when the guest issues these instructions.

Imagine what happens if we not do this and you migrate from an identical hw with an identical libvirt/qemu but from a new kernel to an old kernel:

Quoted 8 lines

The guest boots starts up on the new kernel
guest kernel: drivers/s390/crypto/ap_bus.c ap_module_init -> ap_instructions_available checks if the instructions work. They do and now the guest driver assumes that all instructions will continue to work.

Now the guest is migrated back to an old kernel
sooner or later the ap_scan_bus kthread will run to scan the bus (or some crypto operation is started) and the instruction will be rejected with a PIC01. kernel oops.

There are several scenarios that have to be accounted for, such as:
* Migrating from a linux host where both the KVM/kernel and QEMU support AP matrix devices to a guest host where neither the KVM/kernel nor QEMU support AP matrix devices;
* Migrating from a linux host where both the KVM/kernel and QEMU support AP matrix devices to a guest host where the KVM/kernel does not support AP matrix devices but QEMU does;
* Starting a guest on a linux host where QEMU supports AP matrix devices and the KVM/kernel does not;
* etc.

I agree with your suggestion that defining a new CPU model feature is probably the best way to resolve this issue. The question is, should we define a single feature indicating whether AP instructions are installed and set features bits for the guest based on whether or not they are set in the linux host, or should we define additional CPU model features for turning features bits on and off? I guess it boils down to what behavior is expected for the AP bus running on the linux guest. Here is a rundown of the facilities bits associated with AP and how they affect the behavior of the AP bus:

Quoted 4 lines

* STFLE.12 indicates whether the AP query function is available. If this bit is not set, then the AP bus scan will only test domains 0-15. For example, if adapters 4, 5, and 6 and domains 12 and 71 (0x47) are installed, then AP queues 04.0047, 05.0047 and 06.0047 will not be made available.

STFLE 12 is the indication for Query AP Configuration Information (QCI) available.

Quoted 5 lines

* STFLE.15 indicates whether the AP facilities test function is available. If this bit is not set, then the CEX4, CEX5 and CEX6 device drivers discovered by the AP bus scan will not get bound to any AP device drivers. Since the AP matrix model supports only CEX4 and greater, no devices will be bound to any driver for a guest.

Quoted 5 lines

This T-Bit extension to the TAPQ subfunction is a must have. When kvm only supports CEX4 and upper then this bit could also act as the indicator for AP instructions available. Of course if you want to implement pure virtual full simulated AP without any real AP hardware on the host this bit can't be the indicator.

The context for this discussion is whether we should model the STFLE bits as individual CPU model features or include them with the CPU model feature indicating AP instructions are installed. In either case, the setting of these bits for the guest is dependent upon whether they are set for the host or not. In other words, we can not set a bit for the guest if it is not set for the host for dedicated crypto.

Quoted 14 lines
Quoted 14 lines

* STFLE.65 indicates whether AP interrupts are available. If this bit is not set, then the AP bus will use polling instead of using interrupt handlers to process AP events.

If the AP bus running on the guest is expected to mimic the behavior of an AP bus running on the host, then I think we need a CPU model feature for each facility. Otherwise, I think we can group them within a CPU model feature that indicates AP matrix devices are supported. What say you?

Quoted 1 line
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-s390" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): OF182217F7.6A47A64E-ON002581CD.002BCF58-C12581CD.002D4127@notes.na.collabserv.com

#81 lore raw

Re: [RFC 19/19] s390/facilities: enable AP facilities needed by guest

Quoted 2 lines · Harald Freudenberger

I talked with the firmware guys about this.
The answer is that the AP 3 instructions (NQAP, DQAP, PQAP) are always available.

That is true for basic mode and LPAR, but certainly not for z/VM or KVM guests.

Quoted 7 lines

Tony is right with the facility bits.
facility bit 15 tells if the T bit is supported with the PQAP(TAPQ) subcommand, facility bit 12 tells if the PQAP(QCI) subcommand is available.

As far as I could discover the AP instructions where optional on some older machines. This may be the reason why zVM throws an exception if there is no AP device assigned. However, for all machines still in service the AP instructions are available at al time.

We have to distinguish LPARs and 2nd level guests under KVM/z/VM. For those 2nd level guests there are configurations out there TODAY that do not support PQAP and friends.

#82 lore raw
In reply to Tony Krowiak
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment

Quoted 8 lines

s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Overall I am quite happy with the patches, only minor things I would like to see improved. We have to agree how we want to approach the upstream process between my s390/linux tree and the s390/kvm tree. Probably a tip branch again for the both tress to pull from.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#83 lore raw
Quoted 25 lines · Martin Schwidefsky
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment

Quoted 8 lines

s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 4 lines

Overall I am quite happy with the patches, only minor things I would like to see improved. We have to agree how we want to approach the upstream process between my s390/linux tree and the s390/kvm tree. Probably a tip branch again for the both tress to pull from.

Thanks a lot for the review of the zcrypt patches. Its very good to know that these base changes are ok with you.

Regarding merging: yes, this should be a tip branch then. Before that, we have to finalize the interface and design to make sure that the changes will work throughout the whole stack (kvm/vfio/qemu/libvirt).

#84 lore raw
Quoted 30 lines · Christian Borntraeger
Quoted 24 lines · Martin Schwidefsky
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment

Quoted 8 lines

s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 4 lines

Overall I am quite happy with the patches, only minor things I would like to see improved. We have to agree how we want to approach the upstream process between my s390/linux tree and the s390/kvm tree. Probably a tip branch again for the both tress to pull from.

Quoted 6 lines

Thanks a lot for the review of the zcrypt patches. Its very good to know that these base changes are ok with you.

Regarding merging: yes, this should be a tip branch then. Before that, we have to finalize the interface and design to make sure that the changes will work throughout the whole stack (kvm/vfio/qemu/libvirt).

I would also like to add my thank you for the review comments. I am currently debugging the QEMU code I've written and Farhan Ali is in the review process for the libvirt component.

Quoted 3 lines
#85 lore raw
In reply to Tony Krowiak
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Overview:
--------
An adjunct processor (AP) facility is an IBM Z cryptographic facility. The AP facility is comprised of three AP instructions and from 1 to 256 AP adapter cards. The design takes advantage of the interpretive execution mode provided by the SIE architecture. With interpretive execution mode, the AP instructions executed on the guest are interpreted by the hardware. This allows guests direct access to AP adapter cards. The first goal of this patch series is to provide direct access by a KVM guest to an AP as a pass-through device. The second goal is to provide administrators with the means to configure KVM guests to grant direct access to AP facilities assigned to the LPAR in which the host linux system is running.

Quoted 2 lines

To facilitate the comprehension of the design, let's present an overview of the AP architecture.

I have not yet looked at the patches (and I'm not sure whether I'll be able to do so until after the KVM Forum), but I think this also needs some explanation under Documentation/, so people can still make sense of it in the future.

#86 lore raw
Quoted 16 lines · Cornelia Huck
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Overview:
--------
An adjunct processor (AP) facility is an IBM Z cryptographic facility. The AP facility is comprised of three AP instructions and from 1 to 256 AP adapter cards. The design takes advantage of the interpretive execution mode provided by the SIE architecture. With interpretive execution mode, the AP instructions executed on the guest are interpreted by the hardware. This allows guests direct access to AP adapter cards. The first goal of this patch series is to provide direct access by a KVM guest to an AP as a pass-through device. The second goal is to provide administrators with the means to configure KVM guests to grant direct access to AP facilities assigned to the LPAR in which the host linux system is running.

Quoted 6 lines
Quoted 2 lines

To facilitate the comprehension of the design, let's present an overview of the AP architecture.

I have not yet looked at the patches (and I'm not sure whether I'll be able to do so until after the KVM Forum), but I think this also needs some explanation under Documentation/, so people can still make sense of it in the future.

That makes sense, I will create a document.

Quoted 1 line
#87 lore raw
In reply to Tony Krowiak

As a remark. I think it makes more sense to concentrate on the whole concept before doing an depth review (of course, if you have the cycles - feel free to go ahead :-) ).
Let me just summarize the HW idea in a very simplified fashion, so that we can try to let everybody understand what is going on here.

Implementation-wise (in LPAR and as supported by the HW-virtualization for KVM) the implementation itself is really really simple. As a satellite block of the state descriptor (sie control block) there is the crypto control block. (usually one per guest). This contains 3 256bit bitfields which allow/disallow
1. adapters by number (0-255)
2. usage domains by number (0-255)
3. control domains by number (0-255)

For simplicity lets ignore the control domains, the mechanism is similar to the usage domain.

The guest will then have access to ALL elements of the cross product. So adapter 1,2,3 and domain 10,11,12 will result in 9 tuples accessible by the guest (1,10) ; (1,11) ; (1,12) ; (2,10) ; (2,11) ; (2,12) ; (3,10) ; (3,11) ; (3,12)
the admin (or the management instance) must ensure that each tuple is only in use by 1 guest.
Setting the bits is basically all what is needed (plus some minimal glue and handling), everything else will be handled by hardware/firmware.

Now if we do not need to care about security, we could just use some kvm ioctl and be done with it. As we learned for PCI, this is not going to be secure as qemu is untrusted in svirt/appamor contexts.

So this is basically using vfio and mdev as a means to orchestrate things. And this is where things get complicated and multiple options are possible.

Christian

#88 lore raw
In reply to Tony Krowiak
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment

Quoted 8 lines

s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

I'll try to summarize all of this in my own words, both to make sure I understand the design correctly and to give others a different view on this.

[I'm completely disregarding control domains here.]

On s390, we have cryptographic coprocessor cards, which are modeled on Linux as devices on the AP bus. There's also a concept called domains, which means an individual queue of a crypto device is basically a (card,domain) tuple. We model this something like the following (assuming we have access to cards 3 and 4 and domains 1 and 2):

AP -> card3 -> queue (3,1)

            -> queue (3,2)
   -> card4 -> queue (4,1)
            -> queue (4,2)

(The AP bus is a bit different for backwards compat.)

If we want to virtualize this, we can use a feature provided by the hardware. We basically attach a satellite control block to our main hardware virtualization control block and the hardware takes care of (mostly) everything.

For this control block, we don't specify explicit tuples, but a list of cards and a list of domains. The guest will get access to the cross product.

Because of this, we need to take care that the lists provided to different guests don't overlap; i.e., we need to enforce sane configurations. Otherwise, one guest may get access to things like secret keys for another guest.

The idea of this patch set is to introduce a new device, the matrix device. This matrix device hangs off a different root and acts as the node where mdev devices hang off.

If you now want to give the tuples (4,1) and (4,2), you need to do the following:

- Unbind the (4,1) and (4,2) tuples from their ap bus driver.
- Bind the (4,1) and (4,2) tuples to the ap matrix driver.
- Create the mediated device.
- Assign card 4 and domains 1 and 2.

QEMU will now simply consume the mediated device and things should work.

#89 lore raw

adding qemu devel and add Daniel and Erik from libvirt to keep them in the loop.

Quoted 65 lines · Cornelia Huck
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment

Quoted 8 lines

s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

I'll try to summarize all of this in my own words, both to make sure I understand the design correctly and to give others a different view on this.

[I'm completely disregarding control domains here.]

On s390, we have cryptographic coprocessor cards, which are modeled on Linux as devices on the AP bus. There's also a concept called domains, which means an individual queue of a crypto device is basically a (card,domain) tuple. We model this something like the following (assuming we have access to cards 3 and 4 and domains 1 and 2):

AP -> card3 -> queue (3,1)

            -> queue (3,2)
   -> card4 -> queue (4,1)
            -> queue (4,2)

(The AP bus is a bit different for backwards compat.)

If we want to virtualize this, we can use a feature provided by the hardware. We basically attach a satellite control block to our main hardware virtualization control block and the hardware takes care of (mostly) everything.

For this control block, we don't specify explicit tuples, but a list of cards and a list of domains. The guest will get access to the cross product.

Because of this, we need to take care that the lists provided to different guests don't overlap; i.e., we need to enforce sane configurations. Otherwise, one guest may get access to things like secret keys for another guest.

The idea of this patch set is to introduce a new device, the matrix device. This matrix device hangs off a different root and acts as the node where mdev devices hang off.

If you now want to give the tuples (4,1) and (4,2), you need to do the following:

Quoted 7 lines

- Unbind the (4,1) and (4,2) tuples from their ap bus driver.
- Bind the (4,1) and (4,2) tuples to the ap matrix driver.
- Create the mediated device.
- Assign card 4 and domains 1 and 2.

QEMU will now simply consume the mediated device and things should work.

This is probably the shortest possible summary I can imagine. Tony can you double check if it matches your understanding as well?

#90 lore raw
Quoted 72 lines · Christian Borntraeger

adding qemu devel and add Daniel and Erik from libvirt to keep them in the loop.

Quoted 69 lines · Cornelia Huck
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment

Quoted 8 lines

s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

I'll try to summarize all of this in my own words, both to make sure I understand the design correctly and to give others a different view on this.

[I'm completely disregarding control domains here.]

On s390, we have cryptographic coprocessor cards, which are modeled on Linux as devices on the AP bus. There's also a concept called domains, which means an individual queue of a crypto device is basically a (card,domain) tuple. We model this something like the following (assuming we have access to cards 3 and 4 and domains 1 and 2):

AP -> card3 -> queue (3,1)

             -> queue (3,2)
    -> card4 -> queue (4,1)
             -> queue (4,2)

(The AP bus is a bit different for backwards compat.)

If we want to virtualize this, we can use a feature provided by the hardware. We basically attach a satellite control block to our main hardware virtualization control block and the hardware takes care of (mostly) everything.

For this control block, we don't specify explicit tuples, but a list of cards and a list of domains. The guest will get access to the cross product.

Because of this, we need to take care that the lists provided to different guests don't overlap; i.e., we need to enforce sane configurations. Otherwise, one guest may get access to things like secret keys for another guest.

The idea of this patch set is to introduce a new device, the matrix device. This matrix device hangs off a different root and acts as the node where mdev devices hang off.

If you now want to give the tuples (4,1) and (4,2), you need to do the following:

- Unbind the (4,1) and (4,2) tuples from their ap bus driver.
- Bind the (4,1) and (4,2) tuples to the ap matrix driver.
- Create the mediated device.
- Assign card 4 and domains 1 and 2.

Quoted 5 lines
Quoted 2 lines

QEMU will now simply consume the mediated device and things should work.

This is probably the shortest possible summary I can imagine. Tony can you double check if it matches your understanding as well?

Yes, this is a concise summary of the patch set.

#91 lore raw
In reply to Christian Borntraeger
Quoted 72 lines · Christian Borntraeger

adding qemu devel and add Daniel and Erik from libvirt to keep them in the loop.

Quoted 69 lines · Cornelia Huck
Quoted 13 lines · On Fri, 13 Oct 2017 13:38:45 -0400 Tony Krowiak <[email protected]>…

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment

Quoted 8 lines

s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

I'll try to summarize all of this in my own words, both to make sure I understand the design correctly and to give others a different view on this.

[I'm completely disregarding control domains here.]

On s390, we have cryptographic coprocessor cards, which are modeled on Linux as devices on the AP bus. There's also a concept called domains, which means an individual queue of a crypto device is basically a (card,domain) tuple. We model this something like the following (assuming we have access to cards 3 and 4 and domains 1 and 2):

AP -> card3 -> queue (3,1)

             -> queue (3,2)
    -> card4 -> queue (4,1)
             -> queue (4,2)

(The AP bus is a bit different for backwards compat.)

If we want to virtualize this, we can use a feature provided by the hardware. We basically attach a satellite control block to our main hardware virtualization control block and the hardware takes care of (mostly) everything.

For this control block, we don't specify explicit tuples, but a list of cards and a list of domains. The guest will get access to the cross product.

Because of this, we need to take care that the lists provided to different guests don't overlap; i.e., we need to enforce sane configurations. Otherwise, one guest may get access to things like secret keys for another guest.

The idea of this patch set is to introduce a new device, the matrix device. This matrix device hangs off a different root and acts as the node where mdev devices hang off.

If you now want to give the tuples (4,1) and (4,2), you need to do the following:

- Unbind the (4,1) and (4,2) tuples from their ap bus driver.
- Bind the (4,1) and (4,2) tuples to the ap matrix driver.
- Create the mediated device.
- Assign card 4 and domains 1 and 2.

Quoted 4 lines
Quoted 2 lines

QEMU will now simply consume the mediated device and things should work.

This is probably the shortest possible summary I can imagine. Tony can you double check if it matches your understanding as well?

This is a concise and accurate summary.

Quoted 1 line
#92 lore raw
In reply to Tony Krowiak

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 512 lines

Overview:
--------
An adjunct processor (AP) facility is an IBM Z cryptographic facility. The AP facility is comprised of three AP instructions and from 1 to 256 AP adapter cards. The design takes advantage of the interpretive execution mode provided by the SIE architecture. With interpretive execution mode, the AP instructions executed on the guest are interpreted by the hardware. This allows guests direct access to AP adapter cards. The first goal of this patch series is to provide direct access by a KVM guest to an AP as a pass-through device. The second goal is to provide administrators with the means to configure KVM guests to grant direct access to AP facilities assigned to the LPAR in which the host linux system is running.

To facilitate the comprehension of the design, let's present an overview of the AP architecture.

AP Architectural Overview
-------------------------
Let's start with some definitions:

* AP adapter

An AP adapter is an IBM Z adapter card that can perform cryptographic functionality. There can be from 0 to 256 adapters assigned to an LPAR.
Each adapter is identified by a number from 0 to 255. When
installed, an AP is accessed by AP instructions executed by any CPU.

* AP domain

An adapter can be partitioned into domains. An adapter can hold up to 256 domains. Each domain is identified by a number from 0 to 255. Domains can be further classified into two types:

* Usage domains are domains that can be accessed directly to process AP commands

* Control domains are domains that are accessed indirectly by AP commands sent to a usage domain to control or change the domain.

* AP Queue

An AP queue is the means by which an AP command is sent to an AP usage domain inside a specific AP. An AP queue is identified by a tuple comprised of an AP adapter ID and a usage domain index corresponding to a given usage domain within the adapter. This tuple forms an AP Queue Number (APQN) uniquely identifying an AP queue. AP instructions include a field containing the APQN to identify the AP queue to which the AP command is targetted.

* AP Instructions:

There are three AP instructions:

* NQAP: to enqueue an AP command-request message to a queue
* DQAP: to dequeue an AP command-reply message from a queue
* PQAP: to adminster the queues

Let's now see how AP instructions are interpreted by the hardware.

Start Interpretive Execution (SIE) Instruction
----------------------------------------------
A KVM guest is started by executing the Start Interpretive Execution (SIE) instruction. The SIE state description is a control block that contains the state information for a KVM guest and is supplied as input to the SIE instruction. The SIE state description contains a field that references a Crypto Control Block (CRYCB). The CRYCB contains three bitmask fields identifying the adapters, usage domains and control domains assigned to the KVM guest:

* The AP Mask (APM) field specifies the AP adapters assigned to the KVM guest. The APM controls which adapters are valid for the KVM guest. The bits in the mask, from left to right, correspond to APIDs 0 up to the number of adapters that can be assigned to the LPAR. If a bit is set, the corresponding adapter is valid for use by the KVM guest.

* The AP Queue Mask (AQM) field specifies the AP usage domains assigned to the KVM guest. The bits in the mask, from left to right, correspond to the usage domains, from 0 up to the number of domains that can be assigned to the LPAR. If a bit is set, the corresponding usage domain is valid for use by the KVM guest.

* The AP Domain Mask field specifies the AP control domains assigned to the KVM guest. The ADM bitmask controls which domains can be changed by an AP command-request message sent to a usage domain from the guest. The bits in the mask, from left to right, correspond to domain 0 up to the number of domains that can be assigned to the LPAR. If a bit is set, the corresponding domain can be modified by an AP command-request message sent to a usage domain configured for the KVM guest.

If you recall from the description of an AP Queue, AP instructions include an APQN to identify the AP adapter and the specific usage domain within the adapter to which an AP command-request message is to be sent (NQAP and PQAP instructions), or from which a command-reply message is to be received (DQAP instruction). The validity of an APQN is defined by the matrix calculated from the APM and AQM; it is the intersection of all assigned adapter numbers (APM) with all assigned usage domain numbers (AQM). For example, if adapters 1 and 2 and usage domains 5 and 6 are assigned to a guest, the APQNs (1,5), (1,6), (2,5) and (2,6) will be valid for the guest.

The APQNs provide secure key functionality - i.e., the key is stored on the adapter card - so when the adapter card is not virtualized - i.e., the adapter is accessed directly by the guest - each APQN must be assigned to at most one guest.

Example 1: Valid configuration:
------------------------------
Guest1: adapters 1,2 domains 5,6
Guest2: adapter 1,2 domain 7

This is valid because both guests have a unique set of APQNs: Guest1 has APQNs (1,5), (1,6), (2,5) and (2,6); Guest2 has APQN (1,7) and (2,7).

Example 2: Invalid configuration:
--------------------------------
Guest1: adapters 1,2 domains 5,6
Guest2: adapter 1 domains 6,7

This is an invalid configuration because both guests have access to APQNs (1,6).

Interruption architecture:

The AP interruption architecture may or may not generate interruptions to signal to the CPU the end of an AP transaction. The SIE interruption architecture, depending upon its configuration, may or may not redirect AP interrupts directly to a guest if the associated queue is valid for a guest, and may or may not report the interruption to the host.

Effective masking for guest level I and II:

A linux host running in the LPAR operates at guest-level 1 and has its own SIE state description. When operating at guest-level 1, the masks from the host's state description are used directly. A linux guest running in the host operates at guest-level 2. When operating at guest-level 2, the masks from the guest-level 1 (host) and guest-level 2 (guest) state descriptions are combined into a single description called an effective mask by performing a logical AND of the two state descriptions.

The effective mask algorithm is used for the APM, AQM and ADM to create an EAPM, EAQM and EADM respectively. Use of the EAPM, EAQM and EADM precludes a guest-level 1 host program from passing to a guest-level 2 program APQNs to which it does not have access.

Linux cryptographic bus driver:

Linux already has a cryptographic bus driver that provides one AP device per AP adapter and one device per AP queue. There is a device driver for each type of AP adapter device and each type of AP queue device. This design utilizes some of the interfaces and functionality provided by the AP bus driver.

Design Origin:
-------------

The original design was based on modelling AP Queue devices. The design utilized the VFIO mediated device framework whereby a mediated AP queue device would be created for each AP Queue bound to the VFIO AP Queue device driver. This at first seemed like the most logical design choice for the following reasons:

* Securing access to an AP Queue device by unbinding it from its default device driver and binding it to the VFIO device driver would not preclude the host from having access to the other usage domains contained within the same adapter card connected to the AP queue.

* An AP command is sent to a usage domain within a specific AP adapter via an AP queue.

It became readily apparent that modelling the design on an AP queue was very convoluted for a number of reasons:

* There is no convenient way to notify the VFIO device driver which guest will have access to a given mediated AP queue device until the mediated device's file descriptor is opened by the guest. Recall that the APQNs configured for the guest are an intersection of all of the bits set in both the APM and AQM, so the guest's APQNs can not be validated nor its SIE state description configured until all of the guest's mediated AP queue device file descriptors have been opened.

For example, suppose a guest opens file descriptors for mediated AP queue devices representing APQNs 3,5 and 4,6. If bits 3 and 4 are set in the guest's APM and bits 5 and 6 are set in the guest's AQM, then APQNs (3,5), (3,6), (4,5) and (4,6) will be valid for the guest, but mediated AP queue devices have been created only for APQNs (3,5) and (4,6). In this case, APQNs still assigned to the host would also be available to the guest which is a potential security breach.

* Control domains are not devices and are not logically modelled as mediated devices. In our original design, they were modelled as attributes of a mediated AP queue device, but this was a clumsy use of the VFIO mediated device model.

* The SIE state description models the assignment of AP resources as a matrix via the APM, AQM and ADM.

The design we ultimately settled upon was modelled on the AP matrix as defined by the SIE state description. Supplying the complete AP matrix to SIE using bitmasks when starting a guest simplifies the code, is far easier to secure, and more closely matches the model employed by SIE. This is the design model implemented via this patch set.

The Design
----------
This design introduces four new objects:

1. AP matrix bus

The sysfs location of the AP matrix bus is /sys/bus/ap_matrix. This bus will create a single AP matrix device (see below).

2. AP matrix device

The AP matrix device is a singleton that hangs off of the AP matrix bus. This device holds the AP Queues that have been reserved for use by KVM guests. The sysfs location of the AP matrix device is /sys/devices/ap_matrix/matrix. It is also linked from the AP matrix bus at /sys/bus/ap_matrix/devices/matrix.

3. VFIO AP matrix driver

This driver is based on the VFIO mediated device framework. When the driver is initialized, it will:

* Get the AP matrix device created by AP matrix bus from the bus

* Register with the AP bus to indicate that it can control AP Queue devices. This allows AP Queue devices unbound from AP device drivers to be bound to the VFIO AP matrix driver. The AP Queues bound to the VFIO AP matrix driver will be stored by the driver in the AP matrix device.

* Register the AP matrix device with the VFIO mediated device framework (MDEV). Registration with MDEV will create the sysfs structures needed to create mediated matrix devices. Each MDEV matrix device is used to configure the AP matrix for a KVM guest. The MDEV matrix device's file descriptor can be used by QEMU to communicate with the VFIO AP matrix device driver.

The VFIO AP matrix driver:

* Provides the interfaces the administrator can use to secure AP Queues for use by KVM guests. This is accomplished by unbinding the AP Queues needed by each KVM guest from its AP device driver and binding it to the VFIO AP queue driver. This prevents the host linux system from using these Queues.

* Provides an ioctl that can be used by QEMU to configure the CRYCB referenced by the KVM guest's SIE state description. The ioctl will

* Create an EAPM, EAQM and EADM by performing a logical AND of the APM, AQM and ADM configured via the MDEV matrix device's sysfs attributes files (see below) with the APM, AQM and ADM of the host's SIE state description respectively.

* Configure the SIE state description for the KVM guest using the effective masks created in the previous step.

4. VFIO MDEV matrix passthrough device

An MDEV matrix passthrough device must be created for each KVM guest that will need access to AP facilities. An MDEV matrix passthrough device is used by QEMU to configure the APM, AQM and ADM fields of the CRYCB referenced by the KVM guest's SIE state description. The file descriptor for the MDEV matrix passthrough device provides the communication pathway between QEMU and the VFIO AP matrix device driver.

The MDEV matrix passthrough device, like the CRYCB, contains three bitmasks - an APM, AQM and ADM - for specifying the AP matrix for the KVM guest. Three sets of attributes files will be provided to allow an administrator to set the bits in the MDEV matrix device's APM, AQM and ADM:

* A file to assign an AP adapter
* A file to unassign an AP adapter
* A file to display the adapters assigned

* A file to assign an AP domain
* A file to unassign an AP domain
* A file to display the domains assigned

* A file to assign an AP control domain
* A file to unassign an AP control domain
* A file to display the control domains assigned

Example:
-------
Let's now provide an example to illustrate how KVM guests may be given access to AP facilities. For this example, we will show how to configure two guests such that executing the lszcrypt command on the guests would look like this:

Guest1
------
CARD.DOMAIN TYPE MODE
------------------------------

05          CEX5C CCA-Coproc
05.0004     CEX5C CCA-Coproc
05.00ab     CEX5C CCA-Coproc
06          CEX5A Accelerator
06.0004     CEX5A Accelerator
06.00ab     CEX5C CCA-Coproc

Guest2
------
CARD.DOMAIN TYPE MODE
------------------------------

05          CEX5A Accelerator
05.0047     CEX5A Accelerator
05.00ff     CEX5A Accelerator

One thing to notice in this example is that each AP Queue set is identical. For example, the two AP Queue sets for Guest1 both contain APQI 0004 and 00ab. It would be an invalid condition if both queue sets did not contain the same set of queues. We could not, for example, configure Guest1 with access to AP queue 05.00ff because the AP queue set for adapter 06 does not contain AP queue 06.00ff. The point is, one must be careful to reserve a valid set of AP queues for a given guest.
a valid configuration.

These are the steps for configuring the Guest1 and Guest2:

1. The first thing that needs to be done is to secure the AP queues to be

    used by the two guests so that the host can not access them. This is done
    by unbinding each AP Queue device from its respective AP driver. In our
    example, these queues are bound to the cex4queue driver. This would be
    the sysfs location of these devices:

    /sys/bus/ap
    --- [drivers]
    ------ [cex4queue]
    --------- [05.0004]
    --------- [05.0047]
    --------- [05.00ab]
    --------- [05.00ff]
    --------- [06.0004]
    --------- [06.00ab]
    --------- unbind

    To unbind AP queue 05.0004 from the cex4queue device driver:

	echo 05.0004 > unbind

    This must also be done for AP queues 05.00ab, 05.0047, 05.00ff, 06.0004,
    and 06.00ab.

2. The next step is to reserve the queues for use by the two KVM guests.

    This is accomplished by binding them to the VFIO AP matrix device driver.
    This is the sysfs location of the VFIO AP matrix device driver:

    /sys/bus/ap
    ---[drivers]
    ------ [vfio_ap_matrix]
    ---------- bind

    To bind queue 05.0004 to the vfio_ap_matrix driver:

	echo 05.0004 > bind

    This must also be done for AP queues 05.00ab, 05.0047, 05.00ff, 06.0004,
    and 06.00ab.

3. Create the mediated devices needed to configure the AP matrices for the

    two guests and to provide an interface to the vfio_ap_matrix driver for
    use by the guests:

    /sys/devices/
    --- [ap_matrix]
    ------ [matrix] (this is the matrix device)
    --------- [mdev_supported_types]
    ------------ [ap_matrix-passthrough] (passthrough mediated device type)
    --------------- create
    --------------- [devices]

    To create the mediated devices for the two guests:

	uuidgen > create
	uuidgen > create

    This will create two mediated devices in the [devices] subdirectory named
    with the UUID written to the create attribute file. We call them $uuid1
    and $uuid2:

    /sys/devices/
    --- [ap_matrix]
    ------ [matrix]
    --------- [mdev_supported_types]
    ------------ [ap_matrix-passthrough]
    --------------- [devices]
    ------------------ [$uuid1]
    --------------------- adapters
    --------------------- assign_adapter
    --------------------- assign_control_domain
    --------------------- assign_domain
    --------------------- control_domains
    --------------------- domains
    --------------------- unassign_adapter
    --------------------- unassign_control_domain
    --------------------- unassign_domain
    ------------------ [$uuid2]
    --------------------- adapters
    --------------------- assign_adapter
    --------------------- assign_control_domain
    --------------------- assign_domain
    --------------------- control_domains
    --------------------- domains
    --------------------- unassign_adapter
    --------------------- unassign_control_domain
    --------------------- unassign_domain

4. The administrator now needs to configure the matrices for mediated devices $uuid1 (for Guest1) and $uuid2 (for Guest2).

This is how the matrix is configured for Guest1:

echo 5 > assign_adapter
echo 6 > assign_adapter
echo 4 > assign_domain
echo ab > assign_domain

When the assign.xxx file is written, the corresponding bit in the respective MDEV matrix device's bitmask will be set. For example, when adapter 5 is assigned, bit 5 - numbered from left to right starting with bit 0 - will be set in the MDEV matrix device's APM.

By architectural convention, all usage domains - i.e., domains assigned via the assign_domain attribute file - will also be configured in the ADM field of the KVM guest's CRYCB, so there is no need to assign control domains here unless you want to assign control domains that are not assigned as usage domains.

If a mistake is made configuring an adapter, domain or control domain, you can use the unassign_xxx files to unassign the adapter, domain or control domain.

To display the matrix configuration for Guest1:

cat adapters
cat domains
cat control_domains

This is how the matrix is configured for Guest2:

echo 5 > assign_adapter
echo 47 > assign_domain
echo ff > assign_domain

When a KVM guest is started, QEMU will open the file descriptor for its MDEV matrix device. The VFIO AP matrix device driver will be notified and will store the reference to the KVM guest's SIE state description. QEMU will then call the VFIO AP matrix ioctl requesting that the KVM guest's matrix be configured. The matrix driver will set the bits in the APM, AQM and ADM fields of the CRYCB referenced by the guest's SIE state description from the EAPM, EAQM and EADM created by performing a logical AND of the AP masks configured in the MDEV matrix device and the masks configured in the host's SIE state description. When the guest comes up, it will have access to the APQNs identified in the AP matrix specified in the KVM guest's SIE state description. Programs running on the guest will then be able to use the cryptographic functions provided by the AP facilities configured for the guest.

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

  MAINTAINERS                                  |   13 +
  arch/s390/Kconfig                            |   13 +
  arch/s390/configs/default_defconfig          |    1 +
  arch/s390/configs/gcov_defconfig             |    1 +
  arch/s390/configs/performance_defconfig      |    1 +
  arch/s390/defconfig                          |    1 +
  arch/s390/include/asm/ap-config.h            |   32 +
  arch/s390/include/asm/kvm_host.h             |   26 +-
  arch/s390/kvm/Makefile                       |    2 +-
  arch/s390/kvm/ap-config.c                    |  224 ++++++++
  arch/s390/kvm/kvm-s390.c                     |   17 +-
  arch/s390/tools/gen_facilities.c             |    2 +
  drivers/s390/crypto/Makefile                 |    6 +-
  drivers/s390/crypto/ap_matrix_bus.c          |  115 ++++
  drivers/s390/crypto/ap_matrix_bus.h          |   25 +
  drivers/s390/crypto/vfio_ap_matrix_drv.c     |  107 ++++
  drivers/s390/crypto/vfio_ap_matrix_ops.c     |  790 ++++++++++++++++++++++++++
  drivers/s390/crypto/vfio_ap_matrix_private.h |   50 ++
  include/uapi/linux/vfio.h                    |   22 +
  19 files changed, 1438 insertions(+), 10 deletions(-)

create mode 100644 arch/s390/include/asm/ap-config.h create mode 100644 arch/s390/kvm/ap-config.c
create mode 100644 drivers/s390/crypto/ap_matrix_bus.c create mode 100644 drivers/s390/crypto/ap_matrix_bus.h create mode 100644 drivers/s390/crypto/vfio_ap_matrix_drv.c create mode 100644 drivers/s390/crypto/vfio_ap_matrix_ops.c create mode 100644 drivers/s390/crypto/vfio_ap_matrix_private.h

#93 lore raw
Quoted 24 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance
- this needs documentation (as I already said)
- some of the driver/device modelling feels a bit awkward (commented in patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly
- some minor stuff

#94 lore raw
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation, then replace the cover letter patch with a more concise summary.

Quoted 3 lines

- some of the driver/device modelling feels a bit awkward (commented in patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

Quoted 2 lines

- some minor stuff

#95 lore raw
Quoted 32 lines · Tony Krowiak
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
    KVM: s390: SIE considerations for AP Queue virtualization
    KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
    s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device framework
    KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
    KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
    KVM: s390: interface to configure KVM guest's AP matrix
    KVM: s390: validate input to AP matrix config interface
    KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Quoted 8 lines

Which patches would you squash?

Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation, then replace the cover letter patch with a more concise summary.

Quoted 3 lines

- some of the driver/device modelling feels a bit awkward (commented in patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

I think that instead of responding to each patch individually we should have a discussion on the design because I think a lot could change and discussing about each patch as they may be completely redesigned for the next version may not be very useful.

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it
- which kind of devices we need
- how to handle the repartition of queues on boot, reset and hotplug
- interaction with the host drivers
- validation of the matrix for guests and host views

or even features we need to add like
- interruptions
- PAPQ/TAPQ-t and APQI interception
- virtualization of the AP
- CPU model and KVM capabilities

In my understanding these points must be cleared before we really start to discuss the details of the implementation.

Best regards,

Pierre

Quoted 3 lines
Quoted 2 lines

- some minor stuff

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#96 lore raw
Quoted 48 lines · On Thu, 16 Nov 2017 17:06:58 +0100 Pierre Morel <[email protected]>…
Quoted 33 lines · Tony Krowiak
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
    KVM: s390: SIE considerations for AP Queue virtualization
    KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
    s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device framework
    KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
    KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
    KVM: s390: interface to configure KVM guest's AP matrix
    KVM: s390: validate input to AP matrix config interface
    KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 8 lines
Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Quoted 3 lines

- some of the driver/device modelling feels a bit awkward (commented in patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

I think that instead of responding to each patch individually we should have a discussion on the design because I think a lot could change and discussing about each patch as they may be completely redesigned for the next version may not be very useful.

Quoted 6 lines

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

Quoted 1 line

- which kind of devices we need

What is still unclear? Which card generations to support?

Quoted 1 line

- how to handle the repartition of queues on boot, reset and hotplug

That's something I'd like to see a writeup for.

Quoted 1 line

- interaction with the host drivers

The driver model should already handle that, no?

Quoted 1 line

- validation of the matrix for guests and host views

I saw validation code in the patches, although I have not reviewed it.

Quoted 3 lines

or even features we need to add like
- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

Quoted 1 line

- PAPQ/TAPQ-t and APQI interception

I can't say anything about that, as this is not documented :(

Quoted 1 line

- virtualization of the AP

Is this really needed? It would complicate everything a lot.

Quoted 1 line

- CPU model and KVM capabilities

That already has been discussed with the individual patches.

Quoted 3 lines

In my understanding these points must be cleared before we really start to discuss the details of the implementation.

The general design already looks fine to me. Do you really expect that a major redesign is needed?

#97 lore raw
Quoted 51 lines · Cornelia Huck
Quoted 48 lines · On Thu, 16 Nov 2017 17:06:58 +0100 Pierre Morel <[email protected]>…
Quoted 33 lines · Tony Krowiak
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
    KVM: s390: SIE considerations for AP Queue virtualization
    KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
    s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device framework
    KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
    KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
    KVM: s390: interface to configure KVM guest's AP matrix
    KVM: s390: validate input to AP matrix config interface
    KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 8 lines
Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Quoted 3 lines

- some of the driver/device modelling feels a bit awkward (commented in patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

I think that instead of responding to each patch individually we should have a discussion on the design because I think a lot could change and discussing about each patch as they may be completely redesigned for the next version may not be very useful.

Quoted 8 lines
Quoted 6 lines

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

I have not see any comment on the matrix bus.

Quoted 4 lines
Quoted 2 lines

- which kind of devices we need

What is still unclear? Which card generations to support?

No, I mean the relation bus/device/driver/mdev...

Quoted 4 lines
Quoted 2 lines

- how to handle the repartition of queues on boot, reset and hotplug

That's something I'd like to see a writeup for.

yes, and it may have an influence on the bus/device/driver/mdev design

Quoted 4 lines
Quoted 2 lines

- interaction with the host drivers

The driver model should already handle that, no?

yes it should, but it is not clear for me.

Quoted 6 lines
Quoted 2 lines

- validation of the matrix for guests and host views

I saw validation code in the patches, although I have not reviewed it.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

or even features we need to add like
- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

you are right I forgot that it is optional

Quoted 4 lines
Quoted 2 lines

- PAPQ/TAPQ-t and APQI interception

I can't say anything about that, as this is not documented :(

Right we can live without these too.

Quoted 4 lines
Quoted 2 lines

- virtualization of the AP

Is this really needed? It would complicate everything a lot.

Concern has no sens without interception.

Quoted 4 lines
Quoted 2 lines

- CPU model and KVM capabilities

That already has been discussed with the individual patches.

Well, if there are no interceptions the individual patches discussions are enough.

Quoted 8 lines
Quoted 4 lines

In my understanding these points must be cleared before we really start to discuss the details of the implementation.

The general design already looks fine to me. Do you really expect that a major redesign is needed?

I am worry about the following:
- Will the matrix bus be accepted
- What happens on host reset and hot plug/unplug in host
- What happens with the queues on guest start/halt/restart

Regards,

Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#98 lore raw
Quoted 46 lines · Pierre Morel
Quoted 45 lines · Cornelia Huck
Quoted 42 lines · On Thu, 16 Nov 2017 17:06:58 +0100 Pierre Morel <[email protected]>…
Quoted 41 lines · Tony Krowiak
Quoted 25 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Quoted 5 lines

- some of the driver/device modelling feels a bit awkward (commented in
patches) -- I'm not sure that my proposal is better, but I
think we
should make sure the interdependencies are modeled correctly

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

I am responding to each patch review individually.

I think that instead of responding to each patch individually we should have a discussion on the design because I think a lot could change and discussing about each patch as they may be completely redesigned for the next version may not be very useful.

How do you suggest this discussion should be structured? Aren't the patches themselves an ultimate expression of the design? A lot could change, but can't those issues can be dealt with and discussed as we move forward?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

I have not see any comment on the matrix bus.

As stated in a previous email responding to Connie, I decided to scrap the AP matrix bus. There will only ever be one matrix device that serves two
purposes: To hold the APQNs of the queue devices bound to the VFIO AP matrix device driver; to serve as a parent of the mediated devices created for guests requiring access to the APQNs reserved for their use. So, instead of an AP matrix bus creating the matrix device, it will be created by the VFIO AP matrix driver in /sys/devices/ap_matrix/ during driver initialization.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- which kind of devices we need

What is still unclear? Which card generations to support?

No, I mean the relation bus/device/driver/mdev...

I think that is pretty well spelled out in the cover letter patch and in the descriptions of the patches themselves. What is it you don't understand?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

- how to handle the repartition of queues on boot, reset and hotplug

What do you mean by repartition of queues on boot?

Quoted 4 lines
Quoted 2 lines

That's something I'd like to see a writeup for.

yes, and it may have an influence on the bus/device/driver/mdev design

I don't understand the need to avoid implementation details. If you recall, the original design was modeled on AP queue devices. It was only after implementing that design that the shortcomings were revealed which is why we decided to base the model on the AP matrix. Keep in mind, this is an RFC, not a final patch set. I would expect some change from the implementation herein. In fact, I've already made many changes based on Connie's and Christian's review comments, none of which resulted in an overhaul of the design.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- interaction with the host drivers

The driver model should already handle that, no?

yes it should, but it is not clear for me.

What is it that is not clear? This cover letter seeks to describe the patch set, so why not annotate those areas that are not clear? I'm don't understand what it is you are expecting. I thought the purpose of submitting these patches here was to generate discussion.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

- validation of the matrix for guests and host views

I saw validation code in the patches, although I have not reviewed it.

Patches 9, 11, and 13 validate the adapters, domains and control domains configured for the mdev matrix device and patch 17 verifies that the KVM guest's matrix does not define any APQNs in use by other guests.

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines

or even features we need to add like
- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

you are right I forgot that it is optional

If the facilities bit (STFLE.65) indicating interrupts are available is not set for the guest, then the AP bus running on the guest will poll and interrupts will not have to be handled. This patch set does not enable interrupts, so it is not relevant at this time. We will not be able to handle interrupts for the guest until the GISA for passthrough patches are available. This will be addressed at that time.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- PAPQ/TAPQ-t and APQI interception

I can't say anything about that, as this is not documented :(

Right we can live without these too.

I have implemented interception of the PQAP(TAPQ) instruction and will include it in the next set of patches. It was not documented here because this patch set was submitted as an RFC for the purpose of determining if we are on the right track with regard to the overall AP matrix design.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- virtualization of the AP

Is this really needed? It would complicate everything a lot.

Concern has no sens without interception.

Virtualization of AP is not on the table right now.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

- CPU model and KVM capabilities

That already has been discussed with the individual patches.

Well, if there are no interceptions the individual patches discussions are enough.

As I stated above, these patches were submitted as an RFC for the purpose of getting a stamp of approval for the general design. Additional functions such as hot plug and interception will be introduced in phases in the near future. As I stated above, I already have the implementation of PQAP(TAPQ) and will include it in the next submission. It does not change the general design one iota.

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

In my understanding these points must be cleared before we really start to discuss the details of the implementation.

The general design already looks fine to me. Do you really expect that a major redesign is needed?

I thought the point of submitting this RFC was to get a sanity check of the design concepts. According to Christian, he discussed the design with several maintainers at the KVM forum and they agreed this design was sane.

Quoted 4 lines
Quoted 1 line

I am worry about the following:
- Will the matrix bus be accepted

I am eliminating the matrix bus - based on comments made by Connie for an individual patch - so no need to worry;-)

Quoted 2 lines

- What happens on host reset and hot plug/unplug in host

TBD, but I don't anticipate a major overhaul of the design to accommodate these eventualities, particularly hot plug which I considered while creating this design.

Quoted 2 lines

- What happens with the queues on guest start/halt/restart

TBD

Quoted 5 lines

Regards,

Pierre

#99 lore raw
Quoted 67 lines · Tony Krowiak
Quoted 45 lines · Pierre Morel
Quoted 44 lines · Cornelia Huck
Quoted 41 lines · On Thu, 16 Nov 2017 17:06:58 +0100 Pierre Morel <[email protected]>…
Quoted 40 lines · Tony Krowiak
Quoted 25 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
     KVM: s390: SIE considerations for AP Queue virtualization
     KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
     s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device framework
     KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
     KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
     KVM: s390: interface to configure KVM guest's AP matrix
     KVM: s390: validate input to AP matrix config interface
     KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Quoted 4 lines

- some of the driver/device modelling feels a bit awkward (commented in
    patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

I am responding to each patch review individually.

I think that instead of responding to each patch individually we should have a discussion on the design because I think a lot could change and discussing about each patch as they may be completely redesigned for the next version may not be very useful.

How do you suggest this discussion should be structured? Aren't the patches themselves an ultimate expression of the design? A lot could change, but can't those issues can be dealt with and discussed as we move forward?

Quoted 11 lines
Quoted 10 lines
Quoted 8 lines

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

Quoted 8 lines
Quoted 1 line

I have not see any comment on the matrix bus.

As stated in a previous email responding to Connie, I decided to scrap the AP matrix bus. There will only ever be one matrix device that serves two
purposes: To hold the APQNs of the queue devices bound to the VFIO AP matrix device driver; to serve as a parent of the mediated devices created for guests requiring access to the APQNs reserved for their use. So, instead of an AP matrix bus creating the matrix device, it will be created by the VFIO AP matrix driver in /sys/devices/ap_matrix/ during driver initialization.

Sorry, I did not see the mail, this of course change a lot of things...

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- which kind of devices we need

What is still unclear? Which card generations to support?

No, I mean the relation bus/device/driver/mdev...

I think that is pretty well spelled out in the cover letter patch and in the descriptions of the patches themselves. What is it you don't understand?

If we have no matrix bus anymore I prefer to wait for the cover letter of V2 to discuss this.

Quoted 70 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

- how to handle the repartition of queues on boot, reset and hotplug

What do you mean by repartition of queues on boot?

Quoted 4 lines
Quoted 2 lines

That's something I'd like to see a writeup for.

yes, and it may have an influence on the bus/device/driver/mdev design

I don't understand the need to avoid implementation details. If you recall, the original design was modeled on AP queue devices. It was only after implementing that design that the shortcomings were revealed which is why we decided to base the model on the AP matrix. Keep in mind, this is an RFC, not a final patch set. I would expect some change from the implementation herein. In fact, I've already made many changes based on Connie's and Christian's review comments, none of which resulted in an overhaul of the design.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- interaction with the host drivers

The driver model should already handle that, no?

yes it should, but it is not clear for me.

What is it that is not clear? This cover letter seeks to describe the patch set, so why not annotate those areas that are not clear? I'm don't understand what it is you are expecting. I thought the purpose of submitting these patches here was to generate discussion.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

- validation of the matrix for guests and host views

I saw validation code in the patches, although I have not reviewed it.

Patches 9, 11, and 13 validate the adapters, domains and control domains configured for the mdev matrix device and patch 17 verifies that the KVM guest's matrix does not define any APQNs in use by other guests.

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines

or even features we need to add like
- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

you are right I forgot that it is optional

If the facilities bit (STFLE.65) indicating interrupts are available is not set for the guest, then the AP bus running on the guest will poll and interrupts will not have to be handled. This patch set does not enable interrupts, so it is not relevant at this time. We will not be able to handle interrupts for the guest until the GISA for passthrough patches are available. This will be addressed at that time.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- PAPQ/TAPQ-t and APQI interception

I can't say anything about that, as this is not documented :(

Right we can live without these too.

I have implemented interception of the PQAP(TAPQ) instruction and will include it in the next set of patches. It was not documented here because this patch set was submitted as an RFC for the purpose of determining if we are on the right track with regard to the overall AP matrix design. >>

Quoted 2 lines
Quoted 2 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

- virtualization of the AP

Is this really needed? It would complicate everything a lot.

Concern has no sens without interception.

Virtualization of AP is not on the table right now.

If we implement interception, we must speak about this, even to say how we do not implement virtualization.

Quoted 31 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

- CPU model and KVM capabilities

That already has been discussed with the individual patches.

Well, if there are no interceptions the individual patches discussions are enough.

As I stated above, these patches were submitted as an RFC for the purpose of getting a stamp of approval for the general design. Additional functions such as hot plug and interception will be introduced in phases in the near future. As I stated above, I already have the implementation of PQAP(TAPQ) and will include it in the next submission. It does not change the general design one iota.

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

In my understanding these points must be cleared before we really start to discuss the details of the implementation.

The general design already looks fine to me. Do you really expect that a major redesign is needed?

I thought the point of submitting this RFC was to get a sanity check of the design concepts. According to Christian, he discussed the design with several maintainers at the KVM forum and they agreed this design was sane.

Quoted 4 lines
Quoted 1 line

I am worry about the following:
- Will the matrix bus be accepted

I am eliminating the matrix bus - based on comments made by Connie for an individual patch - so no need to worry;-)

Quoted 1 line
Quoted 7 lines
Quoted 1 line

- What happens on host reset and hot plug/unplug in host

TBD, but I don't anticipate a major overhaul of the design to accommodate these eventualities, particularly hot plug which I considered while creating this design.

Quoted 2 lines

- What happens with the queues on guest start/halt/restart

TBD

AFAIU These two points are crucials for device driver design.

Pierre

Quoted 6 lines
Quoted 5 lines

Regards,

Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#100 lore raw
Quoted 51 lines · On Fri, 17 Nov 2017 08:07:15 +0100 Pierre Morel <[email protected]>…
Quoted 50 lines · Tony Krowiak
Quoted 49 lines · Pierre Morel
Quoted 48 lines · Cornelia Huck
Quoted 45 lines · On Thu, 16 Nov 2017 17:06:58 +0100 Pierre Morel <[email protected]>…
Quoted 43 lines · Tony Krowiak
Quoted 25 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
     KVM: s390: SIE considerations for AP Queue virtualization
     KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
     s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device framework
     KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
     KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
     KVM: s390: interface to configure KVM guest's AP matrix
     KVM: s390: validate input to AP matrix config interface
     KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 6 lines

I think the approach is fine, and the code also looks fine for the most
part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Quoted 5 lines

- some of the driver/device modelling feels a bit awkward (commented in
    patches) -- I'm not sure that my proposal is better, but I think we
    should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

I think that instead of responding to each patch individually we should have a discussion on the design because I think a lot could change and discussing about each patch as they may be completely redesigned for the
next version may not be very useful.

How do you suggest this discussion should be structured? Aren't the patches themselves an ultimate expression of the design? A lot could change, but can't those issues can be dealt with and discussed as we move forward?

FWIW, I think the basic design is already fine, and I don't think many of the points raised would become useless. For one, if something looks a bit strange in detail, it might be a pointer to something bigger that should be reshuffled (like where to anchor information).

Quoted 23 lines
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

I have not see any comment on the matrix bus.

Quoted 9 lines

As stated in a previous email responding to Connie, I decided to scrap the AP matrix bus. There will only ever be one matrix device that serves two
purposes: To hold the APQNs of the queue devices bound to the VFIO AP matrix
device driver; to serve as a parent of the mediated devices created for guests requiring access to the APQNs reserved for their use. So, instead of an AP matrix bus creating the matrix device, it will be created by the VFIO AP matrix driver in /sys/devices/ap_matrix/ during driver initialization.

Quoted 1 line

Sorry, I did not see the mail, this of course change a lot of things...

One thing that would be useful for the next iteration is some ascii-art representation that shows how the different parts (matrix, ap driver, mdev, ...) tie together. That also would be useful to have in the documentation.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

- which kind of devices we need

What is still unclear? Which card generations to support?

Quoted 25 lines
Quoted 4 lines
Quoted 1 line

No, I mean the relation bus/device/driver/mdev...

I think that is pretty well spelled out in the cover letter patch and in the descriptions of the patches themselves. What is it you don't understand?

If we have no matrix bus anymore I prefer to wait for the cover letter of V2 to discuss this.

Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

- how to handle the repartition of queues on boot, reset and hotplug

What do you mean by repartition of queues on boot?

Quoted 4 lines
Quoted 2 lines

That's something I'd like to see a writeup for.

yes, and it may have an influence on the bus/device/driver/mdev design

I don't understand the need to avoid implementation details. If you recall, the original design was modeled on AP queue devices. It was only after implementing that design that the shortcomings were revealed which is why we decided to base the model on the AP matrix. Keep in mind, this is an RFC, not a final patch set. I would expect some change from the implementation herein. In fact, I've already made many changes based on Connie's and Christian's review comments, none of which resulted in an overhaul of the design.

I expect that any of the above can be accommodated by the design. A short writeup of what we may want to do for that would certainly help to validate that, though.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

- interaction with the host drivers

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

The driver model should already handle that, no?

yes it should, but it is not clear for me.

What is it that is not clear? This cover letter seeks to describe the patch set, so why not annotate those areas that are not clear? I'm don't understand what it is you are expecting. I thought the purpose of submitting these patches here was to generate discussion.

The simple fact of unbinding from the normal drivers and rebinding to the specialized ones should already take care of interactions, shouldn't it? Combined with the validation we should be all set.

Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

- validation of the matrix for guests and host views

I saw validation code in the patches, although I have not reviewed it.

Patches 9, 11, and 13 validate the adapters, domains and control domains configured for the mdev matrix device and patch 17 verifies that the KVM guest's matrix does not define any APQNs in use by other guests.

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

or even features we need to add like
- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

you are right I forgot that it is optional

If the facilities bit (STFLE.65) indicating interrupts are available is not set for the guest, then the AP bus running on the guest will poll and interrupts will not have to be handled. This patch set does not enable interrupts, so it is not relevant at this time. We will not be able to handle interrupts for the guest until the GISA for passthrough patches are available. This will be addressed at that time.

If you think it can be easily added later on, that would be fine for me. (I cannot comment on gisa details until it has been posted, obviously.)

Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

- PAPQ/TAPQ-t and APQI interception

I can't say anything about that, as this is not documented :(

Right we can live without these too.

I have implemented interception of the PQAP(TAPQ) instruction and will include it in the next set of patches. It was not documented here because this patch set was submitted as an RFC for the purpose of determining if we are on the right track with regard to the overall AP matrix design. >>

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

- virtualization of the AP

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

Is this really needed? It would complicate everything a lot.

Concern has no sens without interception.

Virtualization of AP is not on the table right now.

If we implement interception, we must speak about this, even to say how we do not implement virtualization.

A note that we do not plan to virtualize it right now would be sensible, yes.

From what I remember, this would mean opening a huge can of worms for something that might be only of limited use. I'd prefer a simplistic but usable approach first. If virtualization should really become a requirement in the future, it might be better served by a different mechanism anyway.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

- CPU model and KVM capabilities

That already has been discussed with the individual patches.

Well, if there are no interceptions the individual patches discussions are enough.

Quoted 9 lines
Quoted 9 lines

As I stated above, these patches were submitted as an RFC for the purpose of
getting a stamp of approval for the general design. Additional functions such as
hot plug and interception will be introduced in phases in the near future. As
I stated above, I already have the implementation of PQAP(TAPQ) and will include
it in the next submission. It does not change the general design one iota.

The intersection was mainly with things like the cpu model. A different part of the interface that does not really have an impact on the rest of the design.

(That does not mean that we don't need to figure it out, of course.)

Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

In my understanding these points must be cleared before we really start to discuss the details of the implementation.

The general design already looks fine to me. Do you really expect that a major redesign is needed?

I thought the point of submitting this RFC was to get a sanity check of the design concepts. According to Christian, he discussed the design with several maintainers at the KVM forum and they agreed this design was sane.

Quoted 4 lines
Quoted 1 line

I am worry about the following:
- Will the matrix bus be accepted

I am eliminating the matrix bus - based on comments made by Connie for an individual patch - so no need to worry;-)

Quoted 2 lines

- What happens on host reset and hot plug/unplug in host

Quoted 8 lines
Quoted 6 lines

TBD, but I don't anticipate a major overhaul of the design to accommodate these eventualities, particularly hot plug which I considered while creating this design.

Quoted 2 lines

- What happens with the queues on guest start/halt/restart

TBD

AFAIU These two points are crucials for device driver design.

A writeup for these two points would be most welcome. I think the base design is sane; it does not hurt to validate, though.

#101 lore raw
Quoted 58 lines · Cornelia Huck
Quoted 55 lines · On Fri, 17 Nov 2017 08:07:15 +0100 Pierre Morel <[email protected]>…
Quoted 54 lines · Tony Krowiak
Quoted 53 lines · Pierre Morel
Quoted 52 lines · Cornelia Huck
Quoted 49 lines · On Thu, 16 Nov 2017 17:06:58 +0100 Pierre Morel <[email protected]>…
Quoted 37 lines · Tony Krowiak
Quoted 25 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 6 lines

I think the approach is fine, and the code also looks fine for the most
part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Quoted 6 lines
Quoted 5 lines

- some of the driver/device modelling feels a bit awkward (commented in
patches) -- I'm not sure that my proposal is better, but I
think we
should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

I think that instead of responding to each patch individually we should have a discussion on the design because I think a lot could change and discussing about each patch as they may be completely redesigned for the
next version may not be very useful.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

How do you suggest this discussion should be structured? Aren't the patches themselves an ultimate expression of the design? A lot could change, but can't those issues can be dealt with and discussed as we move forward?

FWIW, I think the basic design is already fine, and I don't think many of the points raised would become useless. For one, if something looks a bit strange in detail, it might be a pointer to something bigger that should be reshuffled (like where to anchor information).

I agree.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
Quoted 9 lines

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

I have not see any comment on the matrix bus.

As stated in a previous email responding to Connie, I decided to scrap the AP matrix bus. There will only ever be one matrix device that serves two
purposes: To hold the APQNs of the queue devices bound to the VFIO AP matrix
device driver; to serve as a parent of the mediated devices created for guests requiring access to the APQNs reserved for their use. So, instead of an AP matrix bus creating the matrix device, it will be created by the VFIO AP matrix driver in /sys/devices/ap_matrix/ during driver initialization.

Quoted 5 lines
Quoted 1 line

Sorry, I did not see the mail, this of course change a lot of things...

One thing that would be useful for the next iteration is some ascii-art representation that shows how the different parts (matrix, ap driver, mdev, ...) tie together. That also would be useful to have in the documentation.

I plan on including some drawings with the documentation and will include it in the cover letter as well.

Quoted 26 lines
Quoted 26 lines
Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

- which kind of devices we need

What is still unclear? Which card generations to support?

No, I mean the relation bus/device/driver/mdev...

I think that is pretty well spelled out in the cover letter patch and in the descriptions of the patches themselves. What is it you don't understand?

If we have no matrix bus anymore I prefer to wait for the cover letter of V2 to discuss this.

Quoted 14 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- how to handle the repartition of queues on boot, reset and hotplug

What do you mean by repartition of queues on boot?

Quoted 2 lines
Quoted 1 line

That's something I'd like to see a writeup for.

yes, and it may have an influence on the bus/device/driver/mdev design

I don't understand the need to avoid implementation details. If you recall, the original design was modeled on AP queue devices. It was only after implementing that design that the shortcomings were revealed which is why we decided to base the model on the AP matrix. Keep in mind, this is an RFC, not a final patch set. I would expect some change from the implementation herein. In fact, I've already made many changes based on Connie's and Christian's review comments, none of which resulted in an overhaul of the design.

Quoted 3 lines

I expect that any of the above can be accommodated by the design. A short writeup of what we may want to do for that would certainly help to validate that, though.

I have spent some time thinking about hotplug implementation and I believe it can be accommodated within this design. I haven't looked at the implications for reset yet and I don't really know what is meant by "repartition of queues". I will include a write-up in the next submission.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

- interaction with the host drivers

The driver model should already handle that, no?

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

yes it should, but it is not clear for me.

What is it that is not clear? This cover letter seeks to describe the patch set, so why not annotate those areas that are not clear? I'm don't understand what it is you are expecting. I thought the purpose of submitting these patches here was to generate discussion.

The simple fact of unbinding from the normal drivers and rebinding to the specialized ones should already take care of interactions, shouldn't it? Combined with the validation we should be all set.

Unbinding from the host drivers and binding to the VFIO AP matrix driver reserves the APQNs (adapter ID and queue index tuple) for use by guests. The APQNs reserved are stored with the AP matrix device. Mediated matrix devices can be created for the matrix device, one for each guest that will be using the reserved APQNs. When a mediated matrix device is created, sysfs attribute files are created to assign adapters, domains and control domains to the mediated matrix device to configure the AP matrix for a guest. Validation is done at the time of assignment to insure that APQNs that can be derived from the matrix have in fact been reserved.

The mediated device file descriptor provides a communication pathway between QEMU and the VFIO AP matrix device driver. Communication between QEMU and the device driver is established by opening the file descriptor. The device driver provides mediated device ioctl to configure the the APM, AQM and ADM of the KVM guest's CRYCB from the AP matrix configured via the mediated matrix device's attribute files. Validation is performed by the ioctl to ensure no other guest is using any APQN that can be derived from matrix.

The interception of AP instructions will be handled via an ioctl call on the same communication pathway.

I believe that about covers it.

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

- validation of the matrix for guests and host views

I saw validation code in the patches, although I have not reviewed it.

Patches 9, 11, and 13 validate the adapters, domains and control domains configured for the mdev matrix device and patch 17 verifies that the KVM guest's matrix does not define any APQNs in use by other guests.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

or even features we need to add like
- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

you are right I forgot that it is optional

If the facilities bit (STFLE.65) indicating interrupts are available is not set for the guest, then the AP bus running on the guest will poll and interrupts will not have to be handled. This patch set does not enable interrupts, so it is not relevant at this time. We will not be able to handle interrupts for the guest until the GISA for passthrough patches are available. This will be addressed at that time.

Quoted 3 lines

If you think it can be easily added later on, that would be fine for me. (I cannot comment on gisa details until it has been posted, obviously.)

Enabling AP interrupts is accomplished using the PQAP(AQIC) instruction which is a mandatory interception. The instruction will be forwarded to the VFIO AP device driver via an ioctl call on the mediated matrix device file descriptor. There will be some GISA set up needed and code to feed the interrupt back to user space, but I believe that will be provided by the forthcoming GISA passthrough patches. The bottom line is, I don't anticipate any major design change to handle interrupt processing.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

- PAPQ/TAPQ-t and APQI interception

I can't say anything about that, as this is not documented :(

Right we can live without these too.

I have implemented interception of the PQAP(TAPQ) instruction and will include it in the next set of patches. It was not documented here because this patch set was submitted as an RFC for the purpose of determining if we are on the right track with regard to the overall AP matrix design. >>

Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

- virtualization of the AP

Is this really needed? It would complicate everything a lot.

Concern has no sens without interception.

Virtualization of AP is not on the table right now.

If we implement interception, we must speak about this, even to say how we do not implement virtualization.

A note that we do not plan to virtualize it right now would be sensible, yes.

Will do.

Quoted 6 lines

From what I remember, this would mean opening a huge can of worms for
something that might be only of limited use. I'd prefer a simplistic but usable approach first. If virtualization should really become a requirement in the future, it might be better served by a different mechanism anyway.

I have done a little proof of concept code to get an idea if the AP matrix design will be extensible to handle virtualization. I modeled the proof of concept on the AP matrix model by creating a second mediated matrix device type for virtualization. Of course, virtual and passthrough matrix device types would have to be mutually exclusive; the admin would have to choose one or the other. The sysfs model looked like this:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [vfio_ap_matrix-virtual]
............ create
............... [devices]
.................. [$uuid]
..................... assign_adapter
..................... assign_domain

Using the a assign_adapter file, one can assign a virtual adapter ID to one or more real adapter IDs. For example, to assign virtual adapter 4 to real adapters 3, 22 and 254:

echo 4:3,22,254 > assign_adapter

Using the a assign_domain file, one can assign a virtual domain ID to one or more real domain IDs. For example, to assign virtual domain 0 to real domains 8 and 71:

echo 0:8,0x47 > assign_domain

All AP instructions would be intercepted for a virtual matrix. The intercepted instructions would be forwarded to the VFIO AP matrix device driver by QEMU using an ioctl implemented by the VFIO AP matrix driver. If the mediated matrix device is vfio_ap_matrix-passthrough type, things would work as they do now. If the type is vfio_ap_matrix-virtual, the the driver would:

1. Calculate all of the real APQNs that can be used by:
* Retrieving the adapter IDs mapped to the APID specified in the APQN contained in the AP instruction
* Retrieving the domain IDs mapped to the APQI specified in the APQN contained in the AP instruction
* Combining all of the permutations of APID/APQI
2. Determine which APQN would be best to use.
3. Execute the instruction
4. Return the result to the caller

In other words, I think the current design is extensible; but even if not, I see no reason we can't design a completely different mechanism for virtualization.

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

- CPU model and KVM capabilities

That already has been discussed with the individual patches.

Well, if there are no interceptions the individual patches discussions are enough.

Quoted 9 lines
Quoted 9 lines

As I stated above, these patches were submitted as an RFC for the purpose of
getting a stamp of approval for the general design. Additional functions such as
hot plug and interception will be introduced in phases in the near future. As
I stated above, I already have the implementation of PQAP(TAPQ) and will include
it in the next submission. It does not change the general design one iota.

Quoted 5 lines

The intersection was mainly with things like the cpu model. A different part of the interface that does not really have an impact on the rest of the design.

(That does not mean that we don't need to figure it out, of course.)

Of course.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

In my understanding these points must be cleared before we really start to discuss the details of the implementation.

The general design already looks fine to me. Do you really expect that a major redesign is needed?

I thought the point of submitting this RFC was to get a sanity check of the design concepts. According to Christian, he discussed the design with several maintainers at the KVM forum and they agreed this design was sane.

Quoted 3 lines
Quoted 1 line

I am worry about the following:
- Will the matrix bus be accepted

I am eliminating the matrix bus - based on comments made by Connie for an individual patch - so no need to worry;-)

Quoted 1 line

- What happens on host reset and hot plug/unplug in host

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

TBD, but I don't anticipate a major overhaul of the design to accommodate these eventualities, particularly hot plug which I considered while creating this design.

Quoted 1 line

- What happens with the queues on guest start/halt/restart

TBD

AFAIU These two points are crucials for device driver design.

A writeup for these two points would be most welcome. I think the base design is sane; it does not hurt to validate, though.

Will do.

Quoted 1 line
#102 lore raw
Quoted 27 lines · On Fri, 17 Nov 2017 15:28:16 -0500 Tony Krowiak <[email protected]>…
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Fri, 17 Nov 2017 08:07:15 +0100 Pierre Morel <[email protected]>…
Quoted 22 lines · Tony Krowiak
Quoted 4 lines · Pierre Morel
Quoted 2 lines · Cornelia Huck

On Thu, 16 Nov 2017 17:06:58 +0100
Pierre Morel <[email protected]> wrote:

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

I have not see any comment on the matrix bus.

As stated in a previous email responding to Connie, I decided to scrap the AP matrix bus. There will only ever be one matrix device that serves two
purposes: To hold the APQNs of the queue devices bound to the VFIO AP matrix
device driver; to serve as a parent of the mediated devices created for guests requiring access to the APQNs reserved for their use. So, instead of an AP matrix bus creating the matrix device, it will be created by the VFIO AP matrix driver in /sys/devices/ap_matrix/ during driver initialization.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Sorry, I did not see the mail, this of course change a lot of things...

One thing that would be useful for the next iteration is some ascii-art representation that shows how the different parts (matrix, ap driver, mdev, ...) tie together. That also would be useful to have in the documentation.

I plan on including some drawings with the documentation and will include it in the cover letter as well.

Sounds good.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

- how to handle the repartition of queues on boot, reset and hotplug

What do you mean by repartition of queues on boot?

Quoted 2 lines
Quoted 1 line

That's something I'd like to see a writeup for.

yes, and it may have an influence on the bus/device/driver/mdev design

I don't understand the need to avoid implementation details. If you recall, the original design was modeled on AP queue devices. It was only after implementing that design that the shortcomings were revealed which is why we decided to base the model on the AP matrix. Keep in mind, this is an RFC, not a final patch set. I would expect some change from the implementation herein. In fact, I've already made many changes based on Connie's and Christian's review comments, none of which resulted in an overhaul of the design.

Quoted 8 lines
Quoted 3 lines

I expect that any of the above can be accommodated by the design. A short writeup of what we may want to do for that would certainly help to validate that, though.

I have spent some time thinking about hotplug implementation and I believe it can be accommodated within this design. I haven't looked at the implications for reset yet and I don't really know what is meant by "repartition of queues". I will include a write-up in the next submission.

FWIW, "repartition of queues" is also unclear to me.

Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

you are right I forgot that it is optional

If the facilities bit (STFLE.65) indicating interrupts are available is not set for the guest, then the AP bus running on the guest will poll and interrupts will not have to be handled. This patch set does not enable interrupts, so it is not relevant at this time. We will not be able to handle interrupts for the guest until the GISA for passthrough patches are available. This will be addressed at that time.

Quoted 3 lines

If you think it can be easily added later on, that would be fine for me. (I cannot comment on gisa details until it has been posted, obviously.)

Quoted 7 lines

Enabling AP interrupts is accomplished using the PQAP(AQIC) instruction which is a mandatory interception. The instruction will be forwarded to the VFIO AP device driver via an ioctl call on the mediated matrix device file descriptor. There will be some GISA set up needed and code to feed the interrupt back to user space, but I believe that will be provided by the forthcoming GISA passthrough patches. The bottom line is, I don't anticipate any major design change to handle interrupt processing.

Cool, that's what I wanted to hear.

Quoted 63 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

- virtualization of the AP

Is this really needed? It would complicate everything a lot.

Concern has no sens without interception.

Virtualization of AP is not on the table right now.

If we implement interception, we must speak about this, even to say how we do not implement virtualization.

A note that we do not plan to virtualize it right now would be sensible, yes.

Will do.

Quoted 6 lines

From what I remember, this would mean opening a huge can of worms for
something that might be only of limited use. I'd prefer a simplistic but usable approach first. If virtualization should really become a requirement in the future, it might be better served by a different mechanism anyway.

I have done a little proof of concept code to get an idea if the AP matrix design will be extensible to handle virtualization. I modeled the proof of concept on the AP matrix model by creating a second mediated matrix device type for virtualization. Of course, virtual and passthrough matrix device types would have to be mutually exclusive; the admin would have
to choose one or the other. The sysfs model looked like this:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [vfio_ap_matrix-virtual]
............ create
............... [devices]
.................. [$uuid]
..................... assign_adapter
..................... assign_domain

Using the a assign_adapter file, one can assign a virtual adapter ID to one or more real adapter IDs. For example, to assign virtual adapter 4 to real adapters 3, 22 and 254:

echo 4:3,22,254 > assign_adapter

Using the a assign_domain file, one can assign a virtual domain ID to one or more real domain IDs. For example, to assign virtual domain 0 to real domains 8 and 71:

echo 0:8,0x47 > assign_domain

All AP instructions would be intercepted for a virtual matrix. The intercepted
instructions would be forwarded to the VFIO AP matrix device driver by QEMU using an ioctl implemented by the VFIO AP matrix driver. If the mediated matrix
device is vfio_ap_matrix-passthrough type, things would work as they do now. If the type is vfio_ap_matrix-virtual, the the driver would:

1. Calculate all of the real APQNs that can be used by:
* Retrieving the adapter IDs mapped to the APID specified in the APQN contained in the AP instruction
* Retrieving the domain IDs mapped to the APQI specified in the APQN contained in the AP instruction
* Combining all of the permutations of APID/APQI
2. Determine which APQN would be best to use.
3. Execute the instruction
4. Return the result to the caller

Quoted 3 lines

In other words, I think the current design is extensible; but even if not, I see no reason we can't design a completely different mechanism for virtualization.

So it's basically a one-time effort at (re)configuration, and the virtualization facility will basically take care of the rest?

#103 lore raw
Quoted 145 lines · Cornelia Huck
Quoted 26 lines · On Fri, 17 Nov 2017 15:28:16 -0500 Tony Krowiak <[email protected]>…
Quoted 25 lines · Cornelia Huck
Quoted 22 lines · On Fri, 17 Nov 2017 08:07:15 +0100 Pierre Morel <[email protected]>…
Quoted 21 lines · Tony Krowiak
Quoted 11 lines · Pierre Morel
Quoted 9 lines · Cornelia Huck
Quoted 6 lines · On Thu, 16 Nov 2017 17:06:58 +0100 Pierre Morel <[email protected]>…

So I totally agree with Conny on that we should stabilize the bus/device/driver modeling.

I think it would be here a good place to start the discussion on things like we started to discuss, Harald and I, off-line:
- why a matrix bus, in which case we can avoid it

I thought it had been agreed that we should be able to ditch it?

I have not see any comment on the matrix bus.

As stated in a previous email responding to Connie, I decided to scrap the AP matrix bus. There will only ever be one matrix device that serves two
purposes: To hold the APQNs of the queue devices bound to the VFIO AP matrix
device driver; to serve as a parent of the mediated devices created for guests requiring access to the APQNs reserved for their use. So, instead of an AP matrix bus creating the matrix device, it will be created by the VFIO AP matrix driver in /sys/devices/ap_matrix/ during driver initialization.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Sorry, I did not see the mail, this of course change a lot of things...

One thing that would be useful for the next iteration is some ascii-art representation that shows how the different parts (matrix, ap driver, mdev, ...) tie together. That also would be useful to have in the documentation.

I plan on including some drawings with the documentation and will include it in the cover letter as well.

Sounds good.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

- how to handle the repartition of queues on boot, reset and hotplug

What do you mean by repartition of queues on boot?

Quoted 2 lines
Quoted 1 line

That's something I'd like to see a writeup for.

yes, and it may have an influence on the bus/device/driver/mdev design

I don't understand the need to avoid implementation details. If you recall, the original design was modeled on AP queue devices. It was only after implementing that design that the shortcomings were revealed which is why we decided to base the model on the AP matrix. Keep in mind, this is an RFC, not a final patch set. I would expect some change from the implementation herein. In fact, I've already made many changes based on Connie's and Christian's review comments, none of which resulted in an overhaul of the design.

Quoted 8 lines
Quoted 3 lines

I expect that any of the above can be accommodated by the design. A short writeup of what we may want to do for that would certainly help to validate that, though.

I have spent some time thinking about hotplug implementation and I believe it can be accommodated within this design. I haven't looked at the implications for reset yet and I don't really know what is meant by "repartition of queues". I will include a write-up in the next submission.

FWIW, "repartition of queues" is also unclear to me.

Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

- interruptions

My understanding is that interrupts are optional so they can be left out in the first shot. With the gisa (that has not yet been posted), it should not be too difficult, no?

you are right I forgot that it is optional

If the facilities bit (STFLE.65) indicating interrupts are available is not set for the guest, then the AP bus running on the guest will poll and interrupts will not have to be handled. This patch set does not enable interrupts, so it is not relevant at this time. We will not be able to handle interrupts for the guest until the GISA for passthrough patches are available. This will be addressed at that time.

Quoted 3 lines

If you think it can be easily added later on, that would be fine for me. (I cannot comment on gisa details until it has been posted, obviously.)

Quoted 7 lines

Enabling AP interrupts is accomplished using the PQAP(AQIC) instruction which is a mandatory interception. The instruction will be forwarded to the VFIO AP device driver via an ioctl call on the mediated matrix device file descriptor. There will be some GISA set up needed and code to feed the interrupt back to user space, but I believe that will be provided by the forthcoming GISA passthrough patches. The bottom line is, I don't anticipate any major design change to handle interrupt processing.

Cool, that's what I wanted to hear.

Quoted 62 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

- virtualization of the AP

Is this really needed? It would complicate everything a lot.

Concern has no sens without interception.

Virtualization of AP is not on the table right now.

If we implement interception, we must speak about this, even to say how we do not implement virtualization.

A note that we do not plan to virtualize it right now would be sensible, yes.

Will do.

Quoted 5 lines

From what I remember, this would mean opening a huge can of worms for
something that might be only of limited use. I'd prefer a simplistic but usable approach first. If virtualization should really become a requirement in the future, it might be better served by a different mechanism anyway.

I have done a little proof of concept code to get an idea if the AP matrix design will be extensible to handle virtualization. I modeled the proof of concept on the AP matrix model by creating a second mediated matrix device type for virtualization. Of course, virtual and passthrough matrix device types would have to be mutually exclusive; the admin would have
to choose one or the other. The sysfs model looked like this:

/sys/devices/ap_matrix
... [matrix]
...... [mdev_supported_types]
......... [vfio_ap_matrix-virtual]
............ create
............... [devices]
.................. [$uuid]
..................... assign_adapter
..................... assign_domain

Using the a assign_adapter file, one can assign a virtual adapter ID to one or more real adapter IDs. For example, to assign virtual adapter 4 to real adapters 3, 22 and 254:

echo 4:3,22,254 > assign_adapter

Using the a assign_domain file, one can assign a virtual domain ID to one or more real domain IDs. For example, to assign virtual domain 0 to real domains 8 and 71:

echo 0:8,0x47 > assign_domain

All AP instructions would be intercepted for a virtual matrix. The intercepted
instructions would be forwarded to the VFIO AP matrix device driver by QEMU using an ioctl implemented by the VFIO AP matrix driver. If the mediated matrix
device is vfio_ap_matrix-passthrough type, things would work as they do now. If the type is vfio_ap_matrix-virtual, the the driver would:

1. Calculate all of the real APQNs that can be used by:
* Retrieving the adapter IDs mapped to the APID specified in the APQN contained in the AP instruction
* Retrieving the domain IDs mapped to the APQI specified in the APQN contained in the AP instruction
* Combining all of the permutations of APID/APQI
2. Determine which APQN would be best to use.
3. Execute the instruction
4. Return the result to the caller

Quoted 5 lines
Quoted 3 lines

In other words, I think the current design is extensible; but even if not, I see no reason we can't design a completely different mechanism for virtualization.

So it's basically a one-time effort at (re)configuration, and the virtualization facility will basically take care of the rest?

I am not quite sure what you are asking, but I'll attempt to answer what I think you're asking. A new type of mediated matrix device will be introduced to configure a virtual matrix for a guest that provides the interfaces to map a virtual adapter/domain ID to one or more real adapter/domain IDs. If by virtualization facility, you are talking about the VFIO AP matrix driver, then yes, the driver will handle ioctl requests based on the type of the mediated matrix device through which the request was submitted:

If the request is to configure the KVM guest's matrix:

* If the mediated matrix device type is passthrough:
* Do validation of matrix
* Configure the APM, AQM and ADM in the KVM guest's CRYCB according to the configuration specified via the mediated device's sysfs attribute files.
* If the mediated matrix device type is virtual:
* Do validation of matrix
* No need to configure CRYCB since all instructions will be intercepted

If the request is to execute an intercepted AP instruction:

* If the mediated matrix device type is passthrough:
* Forward the instruction to the AP device and return the result to QEMU.

* If the mediated matrix device type is virtual:

* Retrieve all of the real APQNs mapped to the virtual adapter and domain IDs configured in the mediated matrix device's sysfs attribute files
* If there is more than one APQN mapping, then determine which would be best to use - algorithm TBD
* Forward the instruction to the AP device and return the result.

Of course, these are just preliminary ideas at this time. I've only prototyped the sysfs configuration interfaces. No back end prototyping has been undertaken yet. If the ideas do not pan out, however; I think virtualization can be introduced as an independent design.

Quoted 1 line
#104 lore raw
Quoted 11 lines · On Tue, 21 Nov 2017 11:08:01 -0500 Tony Krowiak <[email protected]>…

I am not quite sure what you are asking, but I'll attempt to answer what I think you're asking. A new type of mediated matrix device will be introduced to configure a virtual matrix for a guest that provides the interfaces to map a virtual adapter/domain ID to one or more real adapter/domain IDs. If by virtualization facility, you are talking about the VFIO AP matrix driver, then yes, the driver will handle ioctl requests based on the type of the mediated matrix device through which the request was submitted:

If the request is to configure the KVM guest's matrix:

Quoted 9 lines

* If the mediated matrix device type is passthrough:
* Do validation of matrix
* Configure the APM, AQM and ADM in the KVM guest's CRYCB according to the configuration specified via the mediated device's sysfs attribute files.
* If the mediated matrix device type is virtual:
* Do validation of matrix
* No need to configure CRYCB since all instructions will be intercepted

Ok, so we would have two distinct paths here...

Quoted 9 lines

If the request is to execute an intercepted AP instruction:

* If the mediated matrix device type is passthrough:
* Forward the instruction to the AP device and return the result to QEMU.

* If the mediated matrix device type is virtual:

Quoted 7 lines

* Retrieve all of the real APQNs mapped to the virtual adapter and domain IDs configured in the mediated matrix device's sysfs attribute files
* If there is more than one APQN mapping, then determine which would be best to use - algorithm TBD
* Forward the instruction to the AP device and return the result.

...and two distinct paths for most instructions here as well.

Quoted 6 lines

Of course, these are just preliminary ideas at this time. I've only prototyped the sysfs configuration interfaces. No back end prototyping has been undertaken yet. If the ideas do not pan out, however; I think virtualization can be introduced as an independent design.

Yes, let's cross that bridge when we get to it.

#105 lore raw
Quoted 24 lines · Cornelia Huck
Quoted 11 lines · On Tue, 21 Nov 2017 11:08:01 -0500 Tony Krowiak <[email protected]>…

I am not quite sure what you are asking, but I'll attempt to answer what I think you're asking. A new type of mediated matrix device will be introduced to configure a virtual matrix for a guest that provides the interfaces to map a virtual adapter/domain ID to one or more real adapter/domain IDs. If by virtualization facility, you are talking about the VFIO AP matrix driver, then yes, the driver will handle ioctl requests based on the type of the mediated matrix device through which the request was submitted:

If the request is to configure the KVM guest's matrix:

Quoted 9 lines

* If the mediated matrix device type is passthrough:
* Do validation of matrix
* Configure the APM, AQM and ADM in the KVM guest's CRYCB according to the configuration specified via the mediated device's sysfs attribute files.
* If the mediated matrix device type is virtual:
* Do validation of matrix
* No need to configure CRYCB since all instructions will be intercepted

Quoted 1 line

Ok, so we would have two distinct paths here...

It depends upon what you mean by two distinct paths. Configuring the mediated device would require a new mediated device type for virtualized AP matrices. The ioctl for configuring the KVM guest's CRYCB would require an additional check to determine whether the CRYCB need be configured or not.

Quoted 9 lines
Quoted 9 lines

If the request is to execute an intercepted AP instruction:

* If the mediated matrix device type is passthrough:
* Forward the instruction to the AP device and return the result to QEMU.

* If the mediated matrix device type is virtual:

Quoted 8 lines
Quoted 7 lines

* Retrieve all of the real APQNs mapped to the virtual adapter and domain IDs configured in the mediated matrix device's sysfs attribute files
* If there is more than one APQN mapping, then determine which would be best to use - algorithm TBD
* Forward the instruction to the AP device and return the result.

...and two distinct paths for most instructions here as well.

The driver would require additional ioctls to handle interception of all AP instructions for virtual matrices and additional code to remap virtual APQNs to real APQNs and determine which real APQN to which intercepted instructions should be forwarded.

Quoted 7 lines
Quoted 6 lines

Of course, these are just preliminary ideas at this time. I've only prototyped the sysfs configuration interfaces. No back end prototyping has been undertaken yet. If the ideas do not pan out, however; I think virtualization can be introduced as an independent design.

Yes, let's cross that bridge when we get to it.

That is the plan. Given Pierre's objections, I thought it might help to touch on this.

Quoted 1 line
#106 lore raw
Quoted 25 lines · On Mon, 27 Nov 2017 19:39:32 -0500 Tony Krowiak <[email protected]>…
Quoted 24 lines · Cornelia Huck
Quoted 20 lines · On Tue, 21 Nov 2017 11:08:01 -0500 Tony Krowiak <[email protected]>…

I am not quite sure what you are asking, but I'll attempt to answer what I think you're asking. A new type of mediated matrix device will be introduced to configure a virtual matrix for a guest that provides the interfaces to map a virtual adapter/domain ID to one or more real adapter/domain IDs. If by virtualization facility, you are talking about the VFIO AP matrix driver, then yes, the driver will handle ioctl requests based on the type of the mediated matrix device through which the request was submitted:

If the request is to configure the KVM guest's matrix:

* If the mediated matrix device type is passthrough:
* Do validation of matrix
* Configure the APM, AQM and ADM in the KVM guest's CRYCB according to the configuration specified via the mediated device's sysfs attribute files.
* If the mediated matrix device type is virtual:
* Do validation of matrix
* No need to configure CRYCB since all instructions will be intercepted

Quoted 6 lines
Quoted 1 line

Ok, so we would have two distinct paths here...

It depends upon what you mean by two distinct paths. Configuring the mediated device would require a new mediated device type for virtualized AP matrices. The ioctl for configuring the KVM guest's CRYCB would require an additional check to determine whether the CRYCB need be configured or not.

Yes, the new type makes this distinct enough so that we can think about this later.

Quoted 22 lines
Quoted 9 lines
Quoted 9 lines

If the request is to execute an intercepted AP instruction:

* If the mediated matrix device type is passthrough:
* Forward the instruction to the AP device and return the result to QEMU.

* If the mediated matrix device type is virtual:

Quoted 8 lines
Quoted 7 lines

* Retrieve all of the real APQNs mapped to the virtual adapter and domain IDs configured in the mediated matrix device's sysfs attribute files
* If there is more than one APQN mapping, then determine which would be best to use - algorithm TBD
* Forward the instruction to the AP device and return the result.

...and two distinct paths for most instructions here as well.

The driver would require additional ioctls to handle interception of all AP instructions for virtual matrices and additional code to remap virtual APQNs to real APQNs and determine which real APQN to which intercepted instructions should be forwarded.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Of course, these are just preliminary ideas at this time. I've only prototyped the sysfs configuration interfaces. No back end prototyping has been undertaken yet. If the ideas do not pan out, however; I think virtualization can be introduced as an independent design.

Yes, let's cross that bridge when we get to it.

That is the plan. Given Pierre's objections, I thought it might help to touch on this.

OK, so I admit that I lost track a bit. Are there any remaining issues beyond the feature handling? Would it make sense to post a v2?

#107 lore raw
Quoted 64 lines · Cornelia Huck
Quoted 25 lines · On Mon, 27 Nov 2017 19:39:32 -0500 Tony Krowiak <[email protected]>…
Quoted 24 lines · Cornelia Huck
Quoted 20 lines · On Tue, 21 Nov 2017 11:08:01 -0500 Tony Krowiak <[email protected]>…

I am not quite sure what you are asking, but I'll attempt to answer what I think you're asking. A new type of mediated matrix device will be introduced to configure a virtual matrix for a guest that provides the interfaces to map a virtual adapter/domain ID to one or more real adapter/domain IDs. If by virtualization facility, you are talking about the VFIO AP matrix driver, then yes, the driver will handle ioctl requests based on the type of the mediated matrix device through which the request was submitted:

If the request is to configure the KVM guest's matrix:

* If the mediated matrix device type is passthrough:
* Do validation of matrix
* Configure the APM, AQM and ADM in the KVM guest's CRYCB according to the configuration specified via the mediated device's sysfs attribute files.
* If the mediated matrix device type is virtual:
* Do validation of matrix
* No need to configure CRYCB since all instructions will be intercepted

Quoted 6 lines
Quoted 1 line

Ok, so we would have two distinct paths here...

It depends upon what you mean by two distinct paths. Configuring the mediated device would require a new mediated device type for virtualized AP matrices. The ioctl for configuring the KVM guest's CRYCB would require an additional check to determine whether the CRYCB need be configured or not.

Yes, the new type makes this distinct enough so that we can think about this later.

Quoted 27 lines
Quoted 9 lines
Quoted 9 lines

If the request is to execute an intercepted AP instruction:

* If the mediated matrix device type is passthrough:
* Forward the instruction to the AP device and return the result to QEMU.

* If the mediated matrix device type is virtual:

Quoted 8 lines
Quoted 7 lines

* Retrieve all of the real APQNs mapped to the virtual adapter and domain IDs configured in the mediated matrix device's sysfs attribute files
* If there is more than one APQN mapping, then determine which would be best to use - algorithm TBD
* Forward the instruction to the AP device and return the result.

...and two distinct paths for most instructions here as well.

The driver would require additional ioctls to handle interception of all AP instructions for virtual matrices and additional code to remap virtual APQNs to real APQNs and determine which real APQN to which intercepted instructions should be forwarded.

Quoted 6 lines
Quoted 6 lines

Of course, these are just preliminary ideas at this time. I've only prototyped the sysfs configuration interfaces. No back end prototyping has been undertaken yet. If the ideas do not pan out, however; I think virtualization can be introduced as an independent design.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Yes, let's cross that bridge when we get to it.

That is the plan. Given Pierre's objections, I thought it might help to touch on this.

OK, so I admit that I lost track a bit. Are there any remaining issues beyond the feature handling? Would it make sense to post a v2?

I was planning on posting a V2 once the features issue is settled.

Quoted 1 line
#108 lore raw
In reply to Tony Krowiak
Quoted 27 lines · On Thu, 16 Nov 2017 10:23:25 -0500 Tony Krowiak <[email protected]>…
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 6 lines
Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

See the patches. As a rule, I find it more sensible to introduce interface + implementation together rather than separate.

Quoted 4 lines
Quoted 1 line

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Sounds good.

Quoted 7 lines
Quoted 3 lines

- some of the driver/device modelling feels a bit awkward (commented in patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

Quoted 2 lines

- some minor stuff

#109 lore raw
Quoted 30 lines · Cornelia Huck
Quoted 27 lines · On Thu, 16 Nov 2017 10:23:25 -0500 Tony Krowiak <[email protected]>…
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

See the patches. As a rule, I find it more sensible to introduce interface + implementation together rather than separate.

The only patch that introduces an interface separate from the implementation is patch7:

KVM: s390: introduce AP matrix configuration interface

I've squashed that with patch8, s390/zcrypt: support for assigning adapters to matrix mdev

Quoted 13 lines
Quoted 5 lines
Quoted 2 lines

- this needs documentation (as I already said)

My plan is to take the cover letter patch and incorporate that into documentation,
then replace the cover letter patch with a more concise summary.

Sounds good.

Quoted 6 lines
Quoted 3 lines

- some of the driver/device modelling feels a bit awkward (commented in patches) -- I'm not sure that my proposal is better, but I think we should make sure the interdependencies are modeled correctly

I am responding to each patch review individually.

Quoted 2 lines

- some minor stuff

#110 lore raw
Quoted 37 lines · On Thu, 16 Nov 2017 18:41:29 -0500 Tony Krowiak <[email protected]>…
Quoted 36 lines · Cornelia Huck
Quoted 33 lines · On Thu, 16 Nov 2017 10:23:25 -0500 Tony Krowiak <[email protected]>…
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Tue, 31 Oct 2017 15:39:09 -0400 Tony Krowiak <[email protected]>…

On 10/13/2017 01:38 PM, Tony Krowiak wrote:
Ping

Quoted 21 lines

Tony Krowiak (19):
KVM: s390: SIE considerations for AP Queue virtualization
KVM: s390: refactor crypto initialization s390/zcrypt: new AP matrix bus
s390/zcrypt: create an AP matrix device on the AP matrix bus s390/zcrypt: base implementation of AP matrix device driver s390/zcrypt: register matrix device with VFIO mediated device
framework
KVM: s390: introduce AP matrix configuration interface s390/zcrypt: support for assigning adapters to matrix mdev s390/zcrypt: validate adapter assignment s390/zcrypt: sysfs interfaces supporting AP domain assignment s390/zcrypt: validate domain assignment s390/zcrypt: sysfs support for control domain assignment s390/zcrypt: validate control domain assignment
KVM: s390: Connect the AP mediated matrix device to KVM s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver
KVM: s390: interface to configure KVM guest's AP matrix
KVM: s390: validate input to AP matrix config interface
KVM: s390: New ioctl to configure KVM guest's AP matrix s390/facilities: enable AP facilities needed by guest

Quoted 5 lines

I think the approach is fine, and the code also looks fine for the most part. Some comments:

- various patches can be squashed together to give a better understanding at a glance

Which patches would you squash?

Quoted 8 lines
Quoted 2 lines

See the patches. As a rule, I find it more sensible to introduce interface + implementation together rather than separate.

The only patch that introduces an interface separate from the implementation is patch7:

KVM: s390: introduce AP matrix configuration interface

I've squashed that with patch8, s390/zcrypt: support for assigning adapters to matrix mdev

Sounds good!