Skip to contentSkip to conversation

s390x: vfio-ap: guest dedicated crypto adapters

PATCH In review Tony Krowiak 8 participants 42 messages Oct 9, 2018 – Oct 10, 2018

v10 of 11 In review Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v10 cover s390x: vfio-ap: guest dedicated crypto adapters

From: Tony Krowiak <[email protected]>

This patch series is the QEMU counterpart to the KVM/kernel support for guest dedicated crypto adapters. The KVM/kernel model is built on the VFIO mediated device framework and provides the infrastructure for granting exclusive guest access to crypto devices installed on the linux host. This patch series introduces a new QEMU command line option, QEMU object model and CPU model features to exploit the KVM/kernel model.

See the detailed specifications for AP virtualization provided by this patch set in docs/vfio-ap.txt for a more complete discussion of the design introduced by this patch series.

v9 => v10 Change log:
====================
* Removed KVM_S390_VM_CPU_FEAT_AP feature from kvm.h
* Moved check for KVM_S390_VM_CRYPTO_ENABLE_APIE from patch 2/6 to patch 3/6
* Removed vfio from all function names in ap-bridge.c
* Removed unused macros and structure from ap-bridge.h
* Removed unused macros from ap-device.h

v8 => v9 Change log:
===================
* Removed all references to VFIO in AP bridge and bus
* Expose AP feature only if the KVM_S390_VM_CRYPTO_ENABLE_APIE VM attribute is exposed by KVM - i.e., if AP instructions are available on the linux host.
* Enable AP interpretation only if AP feature is switched on; no need to disable because it is disabled by default.

v7 => v8 Change log:
===================
* Enable SIE interpretation AP instructions if the CPU model feature for AP instructions is turned on for the guest.

v6 => v7 Change log;
===================
* Changed email address for Signed-off-by

v5 => v6 Change log:
===================
* Added reset handling fo vfio-ap device
* Added a bridge/bus to AP device object model - thanks to Halil Pasic

v4 => v5 Change log:
===================
* Added MAINTAINERS entries for VFIO AP
* Added explanation for why we are only supporting zEC12 and newer CPU models.
* Changed CPU model feature qci=on|off to apqci=on|off
* Misc. minor changes

v3 => v4 Change log:
===================
* Made vfio-ap device unpluggable for now
* Renamed command line CPU model feature for QCI: qci=on -> apqci=on
* Removed call to KVM_S390_VM_CRYPTO_INTERPRET_AP ioctl - ioctl was removed from kernel and AP instruction interpretation is set from the VFIO device driver
* Added check to ensure only one vfio-ap device can be configured per guest
* Removed AP instruction interception handlers: AP instructions will be interpreted by default if AP facilities are installed to handle the case where feature ap=on and no vfio-ap device is configured for the guest.

Tony Krowiak (6):
linux-headers: linux header updates for AP support s390x/cpumodel: Set up CPU model for AP device support s390x/kvm: enable AP instruction interpretation for guest s390x/ap: base Adjunct Processor (AP) object model s390x/vfio: ap: Introduce VFIO AP device
s390: doc: detailed specifications for AP virtualization

 MAINTAINERS                       |  14 +
 default-configs/s390x-softmmu.mak |   1 +
 docs/vfio-ap.txt                  | 825 ++++++++++++++++++++++++++++++
 hw/s390x/Makefile.objs            |   2 +
 hw/s390x/ap-bridge.c              |  78 +++
 hw/s390x/ap-device.c              |  39 ++
 hw/s390x/s390-virtio-ccw.c        |   4 +
 hw/vfio/Makefile.objs             |   1 +
 hw/vfio/ap.c                      | 180 +++++++
 include/hw/s390x/ap-bridge.h      |  19 +
 include/hw/s390x/ap-device.h      |  23 +
 include/hw/vfio/vfio-common.h     |   1 +
 linux-headers/asm-s390/kvm.h      |   2 +
 linux-headers/linux/vfio.h        |   2 +
 target/s390x/cpu_features.c       |   3 +
 target/s390x/cpu_features_def.h   |   3 +
 target/s390x/cpu_models.c         |   2 +
 target/s390x/gen-features.c       |   3 +
 target/s390x/kvm.c                |  19 +
 19 files changed, 1221 insertions(+)
 create mode 100644 docs/vfio-ap.txt
 create mode 100644 hw/s390x/ap-bridge.c
 create mode 100644 hw/s390x/ap-device.c
 create mode 100644 hw/vfio/ap.c
 create mode 100644 include/hw/s390x/ap-bridge.h
 create mode 100644 include/hw/s390x/ap-device.h
Signature · 1 line
2.19.0.221.g150f307
#1 lore raw

PATCH v10 1/6 linux-headers: linux header updates for AP support

Updates the linux header files in preparation for introduction of the VFIO AP device:

* Added device attributes to the KVM_S390_VM_CRYPTO group to indicate whether AP instructions are to be interpreted

* Added VFIO device information for AP devices

---
 linux-headers/asm-s390/kvm.h | 2 ++
 linux-headers/linux/vfio.h   | 2 ++
 2 files changed, 4 insertions(+)
linux-headers/asm-s390/kvm.h +2 -0
index 1ab9901911bf..0265482f8fdf 100644
@@ -160,6 +160,8 @@ struct kvm_s390_vm_cpu_subfunc {
 #define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW	1
 #define KVM_S390_VM_CRYPTO_DISABLE_AES_KW	2
 #define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW	3
+#define KVM_S390_VM_CRYPTO_ENABLE_APIE		4
+#define KVM_S390_VM_CRYPTO_DISABLE_APIE		5
 
 /* kvm attributes for migration mode */
 #define KVM_S390_VM_MIGRATION_STOP	0
linux-headers/linux/vfio.h +2 -0
index 3615a269d378..838919a4c03a 100644
@@ -200,6 +200,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 (1 << 5)		/* vfio-ap device */
 	__u32	num_regions;	/* Max region index + 1 */
 	__u32	num_irqs;	/* Max IRQ index + 1 */
 };
@@ -215,6 +216,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_STRING		"vfio-ap"
 
 /**
  * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8,
Signature · 1 line
2.19.0.221.g150f307
#2 lore raw

Re: [Qemu-devel] [PATCH v10 1/6] linux-headers: linux header updates for AP support

Quoted 6 lines · On Tue, 9 Oct 2018 13:52:21 -0400 Tony Krowiak <[email protected]>…

Updates the linux header files in preparation for introduction of the VFIO AP device:

* Added device attributes to the KVM_S390_VM_CRYPTO group to indicate whether AP instructions are to be interpreted

Quoted 7 lines

* Added VFIO device information for AP devices

---
 linux-headers/asm-s390/kvm.h | 2 ++
 linux-headers/linux/vfio.h   | 2 ++
 2 files changed, 4 insertions(+)

The needed changes are all in kvm/next, and we're near the next Linux merge window, so I'll just replace this one with a proper header sync against kvm/next.

#3 lore raw

PATCH v10 2/6 s390x/cpumodel: Set up CPU model for AP device support

In reply to Tony Krowiak

A new CPU model feature and two new CPU model facilities are introduced to support AP devices for a KVM guest.

CPU model features:

1. The S390_FEAT_AP CPU model feature indicates whether AP instructions are available to the guest. This feature will be enabled only if the AP instructions are available on the linux host as determined by the availability of the KVM_S390_VM_CRYPTO_ENABLE_APIE VM attribute which is exposed by KVM only if the AP instructions are available on the host.

This feature must be turned on from userspace to execute AP instructions on the KVM guest. The QEMU command line to turn this feature on looks something like this:

	qemu-system-s390x ... -cpu xxx,ap=on ...

This feature will be supported for zEC12 and newer CPU models. The feature will not be supported for older models because there are few older systems on which to test and the older crypto cards will be going out of service in the relatively near future.

CPU model facilities:

1. The S390_FEAT_AP_QUERY_CONFIG_INFO feature indicates whether the AP Query Configuration Information (QCI) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if the QCI facility is installed on the host.

2. The S390_FEAT_AP_FACILITY_TEST feature indicates whether the AP Facility Test (APFT) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if APFT is installed on the host.

---
 target/s390x/cpu_features.c     | 3 +++
 target/s390x/cpu_features_def.h | 3 +++
 target/s390x/cpu_models.c       | 2 ++
 target/s390x/gen-features.c     | 3 +++
 4 files changed, 11 insertions(+)
target/s390x/cpu_features.c +3 -0
index 172fb18df718..60cfeba48f4e 100644
@@ -39,8 +39,10 @@ static const S390FeatDef s390_features[] = {
     FEAT_INIT("srs", S390_FEAT_TYPE_STFL, 9, "Sense-running-status facility"),
     FEAT_INIT("csske", S390_FEAT_TYPE_STFL, 10, "Conditional-SSKE facility"),
     FEAT_INIT("ctop", S390_FEAT_TYPE_STFL, 11, "Configuration-topology facility"),
+    FEAT_INIT("apqci", S390_FEAT_TYPE_STFL, 12, "Query AP Configuration Information facility"),
     FEAT_INIT("ipter", S390_FEAT_TYPE_STFL, 13, "IPTE-range facility"),
     FEAT_INIT("nonqks", S390_FEAT_TYPE_STFL, 14, "Nonquiescing key-setting facility"),
+    FEAT_INIT("apft", S390_FEAT_TYPE_STFL, 15, "AP Facilities Test facility"),
     FEAT_INIT("etf2", S390_FEAT_TYPE_STFL, 16, "Extended-translation facility 2"),
     FEAT_INIT("msa-base", S390_FEAT_TYPE_STFL, 17, "Message-security-assist facility (excluding subfunctions)"),
     FEAT_INIT("ldisp", S390_FEAT_TYPE_STFL, 18, "Long-displacement facility"),
@@ -129,6 +131,7 @@ static const S390FeatDef s390_features[] = {
 
     FEAT_INIT_MISC("dateh2", "DAT-enhancement facility 2"),
     FEAT_INIT_MISC("cmm", "Collaborative-memory-management facility"),
+    FEAT_INIT_MISC("ap", "AP instructions installed"),
 
     FEAT_INIT("plo-cl", S390_FEAT_TYPE_PLO, 0, "PLO Compare and load (32 bit in general registers)"),
     FEAT_INIT("plo-clg", S390_FEAT_TYPE_PLO, 1, "PLO Compare and load (64 bit in parameter list)"),
target/s390x/cpu_features_def.h +3 -0
index ac2c947f30a8..5fc7e7bf0116 100644
@@ -27,8 +27,10 @@ typedef enum {
     S390_FEAT_SENSE_RUNNING_STATUS,
     S390_FEAT_CONDITIONAL_SSKE,
     S390_FEAT_CONFIGURATION_TOPOLOGY,
+    S390_FEAT_AP_QUERY_CONFIG_INFO,
     S390_FEAT_IPTE_RANGE,
     S390_FEAT_NONQ_KEY_SETTING,
+    S390_FEAT_AP_FACILITIES_TEST,
     S390_FEAT_EXTENDED_TRANSLATION_2,
     S390_FEAT_MSA,
     S390_FEAT_LONG_DISPLACEMENT,
@@ -119,6 +121,7 @@ typedef enum {
     /* Misc */
     S390_FEAT_DAT_ENH_2,
     S390_FEAT_CMM,
+    S390_FEAT_AP,
 
     /* PLO */
     S390_FEAT_PLO_CL,
target/s390x/cpu_models.c +2 -0
index 265d25c937bb..7c253ff308c5 100644
@@ -786,6 +786,8 @@ static void check_consistency(const S390CPUModel *model)
         { S390_FEAT_PRNO_TRNG_QRTCR, S390_FEAT_MSA_EXT_5 },
         { S390_FEAT_PRNO_TRNG, S390_FEAT_MSA_EXT_5 },
         { S390_FEAT_SIE_KSS, S390_FEAT_SIE_F2 },
+        { S390_FEAT_AP_QUERY_CONFIG_INFO, S390_FEAT_AP },
+        { S390_FEAT_AP_FACILITIES_TEST, S390_FEAT_AP },
     };
     int i;
 
target/s390x/gen-features.c +3 -0
index 384b61cd67b9..70015eaaf5df 100644
@@ -447,6 +447,9 @@ static uint16_t full_GEN12_GA1[] = {
     S390_FEAT_ADAPTER_INT_SUPPRESSION,
     S390_FEAT_EDAT_2,
     S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2,
+    S390_FEAT_AP_QUERY_CONFIG_INFO,
+    S390_FEAT_AP_FACILITIES_TEST,
+    S390_FEAT_AP,
 };
 
 static uint16_t full_GEN12_GA2[] = {
Signature · 1 line
2.19.0.221.g150f307
Reviewed-by on v10 2/6
#4 lore raw

Re: [Qemu-devel] [PATCH v10 2/6] s390x/cpumodel: Set up CPU model for AP device support

Quoted 33 lines · Tony Krowiak

A new CPU model feature and two new CPU model facilities are introduced to support AP devices for a KVM guest.

CPU model features:

1. The S390_FEAT_AP CPU model feature indicates whether AP instructions are available to the guest. This feature will be enabled only if the AP instructions are available on the linux host as determined by the availability of the KVM_S390_VM_CRYPTO_ENABLE_APIE VM attribute which is exposed by KVM only if the AP instructions are available on the host.

This feature must be turned on from userspace to execute AP instructions on the KVM guest. The QEMU command line to turn this feature on looks something like this:

	qemu-system-s390x ... -cpu xxx,ap=on ...

This feature will be supported for zEC12 and newer CPU models. The feature will not be supported for older models because there are few older systems on which to test and the older crypto cards will be going out of service in the relatively near future.

CPU model facilities:

1. The S390_FEAT_AP_QUERY_CONFIG_INFO feature indicates whether the AP Query Configuration Information (QCI) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if the QCI facility is installed on the host.

Quoted 8 lines

2. The S390_FEAT_AP_FACILITY_TEST feature indicates whether the AP Facility Test (APFT) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if APFT is installed on the host.

and as you have moved the one hunk, Davids RB should still count.

Quoted 81 lines
---
 target/s390x/cpu_features.c     | 3 +++
 target/s390x/cpu_features_def.h | 3 +++
 target/s390x/cpu_models.c       | 2 ++
 target/s390x/gen-features.c     | 3 +++
 4 files changed, 11 insertions(+)
target/s390x/cpu_features.c +3 -0
index 172fb18df718..60cfeba48f4e 100644
@@ -39,8 +39,10 @@ static const S390FeatDef s390_features[] = {
     FEAT_INIT("srs", S390_FEAT_TYPE_STFL, 9, "Sense-running-status facility"),
     FEAT_INIT("csske", S390_FEAT_TYPE_STFL, 10, "Conditional-SSKE facility"),
     FEAT_INIT("ctop", S390_FEAT_TYPE_STFL, 11, "Configuration-topology facility"),
+    FEAT_INIT("apqci", S390_FEAT_TYPE_STFL, 12, "Query AP Configuration Information facility"),
     FEAT_INIT("ipter", S390_FEAT_TYPE_STFL, 13, "IPTE-range facility"),
     FEAT_INIT("nonqks", S390_FEAT_TYPE_STFL, 14, "Nonquiescing key-setting facility"),
+    FEAT_INIT("apft", S390_FEAT_TYPE_STFL, 15, "AP Facilities Test facility"),
     FEAT_INIT("etf2", S390_FEAT_TYPE_STFL, 16, "Extended-translation facility 2"),
     FEAT_INIT("msa-base", S390_FEAT_TYPE_STFL, 17, "Message-security-assist facility (excluding subfunctions)"),
     FEAT_INIT("ldisp", S390_FEAT_TYPE_STFL, 18, "Long-displacement facility"),
@@ -129,6 +131,7 @@ static const S390FeatDef s390_features[] = {
 
     FEAT_INIT_MISC("dateh2", "DAT-enhancement facility 2"),
     FEAT_INIT_MISC("cmm", "Collaborative-memory-management facility"),
+    FEAT_INIT_MISC("ap", "AP instructions installed"),
 
     FEAT_INIT("plo-cl", S390_FEAT_TYPE_PLO, 0, "PLO Compare and load (32 bit in general registers)"),
     FEAT_INIT("plo-clg", S390_FEAT_TYPE_PLO, 1, "PLO Compare and load (64 bit in parameter list)"),
target/s390x/cpu_features_def.h +3 -0
index ac2c947f30a8..5fc7e7bf0116 100644
@@ -27,8 +27,10 @@ typedef enum {
     S390_FEAT_SENSE_RUNNING_STATUS,
     S390_FEAT_CONDITIONAL_SSKE,
     S390_FEAT_CONFIGURATION_TOPOLOGY,
+    S390_FEAT_AP_QUERY_CONFIG_INFO,
     S390_FEAT_IPTE_RANGE,
     S390_FEAT_NONQ_KEY_SETTING,
+    S390_FEAT_AP_FACILITIES_TEST,
     S390_FEAT_EXTENDED_TRANSLATION_2,
     S390_FEAT_MSA,
     S390_FEAT_LONG_DISPLACEMENT,
@@ -119,6 +121,7 @@ typedef enum {
     /* Misc */
     S390_FEAT_DAT_ENH_2,
     S390_FEAT_CMM,
+    S390_FEAT_AP,
 
     /* PLO */
     S390_FEAT_PLO_CL,
target/s390x/cpu_models.c +2 -0
index 265d25c937bb..7c253ff308c5 100644
@@ -786,6 +786,8 @@ static void check_consistency(const S390CPUModel *model)
         { S390_FEAT_PRNO_TRNG_QRTCR, S390_FEAT_MSA_EXT_5 },
         { S390_FEAT_PRNO_TRNG, S390_FEAT_MSA_EXT_5 },
         { S390_FEAT_SIE_KSS, S390_FEAT_SIE_F2 },
+        { S390_FEAT_AP_QUERY_CONFIG_INFO, S390_FEAT_AP },
+        { S390_FEAT_AP_FACILITIES_TEST, S390_FEAT_AP },
     };
     int i;
 
target/s390x/gen-features.c +3 -0
index 384b61cd67b9..70015eaaf5df 100644
@@ -447,6 +447,9 @@ static uint16_t full_GEN12_GA1[] = {
     S390_FEAT_ADAPTER_INT_SUPPRESSION,
     S390_FEAT_EDAT_2,
     S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2,
+    S390_FEAT_AP_QUERY_CONFIG_INFO,
+    S390_FEAT_AP_FACILITIES_TEST,
+    S390_FEAT_AP,
 };
 
 static uint16_t full_GEN12_GA2[] = {
Reviewed-by
#5 lore raw

Re: [Qemu-devel] [PATCH v10 2/6] s390x/cpumodel: Set up CPU model for AP device support

Quoted 42 lines · Christian Borntraeger
Quoted 39 lines · Tony Krowiak

A new CPU model feature and two new CPU model facilities are introduced to support AP devices for a KVM guest.

CPU model features:

1. The S390_FEAT_AP CPU model feature indicates whether AP instructions are available to the guest. This feature will be enabled only if the AP instructions are available on the linux host as determined by the availability of the KVM_S390_VM_CRYPTO_ENABLE_APIE VM attribute which is exposed by KVM only if the AP instructions are available on the host.

This feature must be turned on from userspace to execute AP instructions on the KVM guest. The QEMU command line to turn this feature on looks something like this:

	qemu-system-s390x ... -cpu xxx,ap=on ...

This feature will be supported for zEC12 and newer CPU models. The feature will not be supported for older models because there are few older systems on which to test and the older crypto cards will be going out of service in the relatively near future.

CPU model facilities:

1. The S390_FEAT_AP_QUERY_CONFIG_INFO feature indicates whether the AP Query Configuration Information (QCI) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if the QCI facility is installed on the host.

2. The S390_FEAT_AP_FACILITY_TEST feature indicates whether the AP Facility Test (APFT) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if APFT is installed on the host.

Quoted 7 lines
Quoted 2 lines

and as you have moved the one hunk, Davids RB should still count.

Indeed

Signature · 3 lines
Thanks,

David / dhildenb
#6 lore raw

Re: [Qemu-devel] [PATCH v10 2/6] s390x/cpumodel: Set up CPU model for AP device support

Quoted 47 lines · David Hildenbrand
Quoted 46 lines · Christian Borntraeger
Quoted 41 lines · Tony Krowiak

A new CPU model feature and two new CPU model facilities are introduced to support AP devices for a KVM guest.

CPU model features:

1. The S390_FEAT_AP CPU model feature indicates whether AP instructions are available to the guest. This feature will be enabled only if the AP instructions are available on the linux host as determined by the availability of the KVM_S390_VM_CRYPTO_ENABLE_APIE VM attribute which is exposed by KVM only if the AP instructions are available on the host.

This feature must be turned on from userspace to execute AP instructions on the KVM guest. The QEMU command line to turn this feature on looks something like this:

qemu-system-s390x ... -cpu xxx,ap=on ...

This feature will be supported for zEC12 and newer CPU models. The feature will not be supported for older models because there are few older systems on which to test and the older crypto cards will be going out of service in the relatively near future.

CPU model facilities:

1. The S390_FEAT_AP_QUERY_CONFIG_INFO feature indicates whether the AP Query Configuration Information (QCI) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if the QCI facility is installed on the host.

2. The S390_FEAT_AP_FACILITY_TEST feature indicates whether the AP Facility Test (APFT) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if APFT is installed on the host.

Quoted 7 lines
Quoted 3 lines

and as you have moved the one hunk, Davids RB should still count.

Indeed

Got it.

Quoted 2 lines
#7 lore raw

Re: [Qemu-devel] [PATCH v10 2/6] s390x/cpumodel: Set up CPU model for AP device support

In reply to Tony Krowiak

On Tue, 9 Oct 2018 13:52:22 -0400
Tony Krowiak <[email protected]> wrote:

(...)

Quoted 1 line

This patch (and the others) have a mismatch between the author (address with vnet), and the s-o-b (address without vnet). While these are obviously the same person, the addresses really should match.

Should I fix up the author to use the vnet-less address?

Quoted 7 lines
---
 target/s390x/cpu_features.c     | 3 +++
 target/s390x/cpu_features_def.h | 3 +++
 target/s390x/cpu_models.c       | 2 ++
 target/s390x/gen-features.c     | 3 +++
 4 files changed, 11 insertions(+)
#8 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 2/6] s390x/cpumodel: Set up CPU model for AP device support

Quoted 5 lines · Cornelia Huck

On Tue, 9 Oct 2018 13:52:22 -0400
Tony Krowiak <[email protected]> wrote:

(...)

Quoted 7 lines
Quoted 1 line

This patch (and the others) have a mismatch between the author (address with vnet), and the s-o-b (address without vnet). While these are obviously the same person, the addresses really should match.

Should I fix up the author to use the vnet-less address?

yes please.

Quoted 9 lines
Quoted 8 lines
---
 target/s390x/cpu_features.c     | 3 +++
 target/s390x/cpu_features_def.h | 3 +++
 target/s390x/cpu_models.c       | 2 ++
 target/s390x/gen-features.c     | 3 +++
 4 files changed, 11 insertions(+)
Reviewed-by on v10 2/6
#9 lore raw

Re: [Qemu-devel] [PATCH v10 2/6] s390x/cpumodel: Set up CPU model for AP device support

In reply to Tony Krowiak
Quoted 33 lines · Tony Krowiak

A new CPU model feature and two new CPU model facilities are introduced to support AP devices for a KVM guest.

CPU model features:

1. The S390_FEAT_AP CPU model feature indicates whether AP instructions are available to the guest. This feature will be enabled only if the AP instructions are available on the linux host as determined by the availability of the KVM_S390_VM_CRYPTO_ENABLE_APIE VM attribute which is exposed by KVM only if the AP instructions are available on the host.

This feature must be turned on from userspace to execute AP instructions on the KVM guest. The QEMU command line to turn this feature on looks something like this:

	qemu-system-s390x ... -cpu xxx,ap=on ...

This feature will be supported for zEC12 and newer CPU models. The feature will not be supported for older models because there are few older systems on which to test and the older crypto cards will be going out of service in the relatively near future.

CPU model facilities:

1. The S390_FEAT_AP_QUERY_CONFIG_INFO feature indicates whether the AP Query Configuration Information (QCI) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if the QCI facility is installed on the host.

Quoted 8 lines

2. The S390_FEAT_AP_FACILITY_TEST feature indicates whether the AP Facility Test (APFT) facility is available to the guest as determined by whether the facility is available on the host. This feature will be exposed by KVM only if APFT is installed on the host.

#10 lore raw

PATCH v10 3/6 s390x/kvm: enable AP instruction interpretation for guest

In reply to Tony Krowiak

From: Tony Krowiak <[email protected]>

Let's use the KVM_SET_DEVICE_ATTR ioctl to enable hardware interpretation of AP instructions executed on the guest. If the S390_FEAT_AP feature is switched on for the guest, AP instructions must be interpreted by default; otherwise, they will be intercepted.

This attribute setting may be overridden by a device. For example, a device may want to provide AP instructions to the guest (i.e., S390_FEAT_AP turned on), but it may want to emulate them. In this case, the AP instructions executed on the guest must be intercepted; so when the device is realized, it must disable interpretation.

---
 target/s390x/kvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
target/s390x/kvm.c +19 -0
index 348e8cc5467a..d042deed1af3 100644
@@ -2291,11 +2291,26 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
         error_setg(errp, "KVM: host CPU model could not be identified");
         return;
     }
+    /* for now, we can only provide the AP feature with HW support */
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
+        KVM_S390_VM_CRYPTO_ENABLE_APIE)) {
+        set_bit(S390_FEAT_AP, model->features);
+    }
     /* strip of features that are not part of the maximum model */
     bitmap_and(model->features, model->features, model->def->full_feat,
                S390_FEAT_MAX);
 }
 
+static void kvm_s390_configure_apie(bool interpret)
+{
+    uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
+                                KVM_S390_VM_CRYPTO_DISABLE_APIE;
+
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
+        kvm_s390_set_attr(attr);
+    }
+}
+
 void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
 {
     struct kvm_s390_vm_cpu_processor prop  = {
@@ -2345,6 +2360,10 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
     if (test_bit(S390_FEAT_CMM, model->features)) {
         kvm_s390_enable_cmma();
     }
+
+    if (test_bit(S390_FEAT_AP, model->features)) {
+        kvm_s390_configure_apie(true);
+    }
 }
 
 void kvm_s390_restart_interrupt(S390CPU *cpu)
Signature · 1 line
2.19.0.221.g150f307
Reviewed-by on v10 3/6
#11 lore raw

Re: [Qemu-devel] [PATCH v10 3/6] s390x/kvm: enable AP instruction interpretation for guest

Quoted 54 lines · Tony Krowiak

From: Tony Krowiak <[email protected]>

Let's use the KVM_SET_DEVICE_ATTR ioctl to enable hardware interpretation of AP instructions executed on the guest. If the S390_FEAT_AP feature is switched on for the guest, AP instructions must be interpreted by default; otherwise, they will be intercepted.

This attribute setting may be overridden by a device. For example, a device may want to provide AP instructions to the guest (i.e., S390_FEAT_AP turned on), but it may want to emulate them. In this case, the AP instructions executed on the guest must be intercepted; so when the device is realized, it must disable interpretation.

---
 target/s390x/kvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
target/s390x/kvm.c +15 -0
index 348e8cc5467a..d042deed1af3 100644
@@ -2291,11 +2291,26 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
         error_setg(errp, "KVM: host CPU model could not be identified");
         return;
     }
+    /* for now, we can only provide the AP feature with HW support */
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
+        KVM_S390_VM_CRYPTO_ENABLE_APIE)) {
+        set_bit(S390_FEAT_AP, model->features);
+    }
     /* strip of features that are not part of the maximum model */
     bitmap_and(model->features, model->features, model->def->full_feat,
                S390_FEAT_MAX);
 }
 
+static void kvm_s390_configure_apie(bool interpret)
+{
+    uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
+                                KVM_S390_VM_CRYPTO_DISABLE_APIE;
+
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
+        kvm_s390_set_attr(attr);
+    }
+}
+
 void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
 {
     struct kvm_s390_vm_cpu_processor prop  = {

target/s390x/kvm.c void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp) · line 2369

Quoted 10 lines
target/s390x/kvm.c +4 -0
@@ -2345,6 +2360,10 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
     if (test_bit(S390_FEAT_CMM, model->features)) {
         kvm_s390_enable_cmma();
     }
+
+    if (test_bit(S390_FEAT_AP, model->features)) {
+        kvm_s390_configure_apie(true);
+    }
 }
 
 void kvm_s390_restart_interrupt(S390CPU *cpu)
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v10 3/6
#12 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 3/6] s390x/kvm: enable AP instruction interpretation for guest

In reply to Tony Krowiak
Quoted 15 lines · Tony Krowiak

From: Tony Krowiak <[email protected]>

Let's use the KVM_SET_DEVICE_ATTR ioctl to enable hardware interpretation of AP instructions executed on the guest. If the S390_FEAT_AP feature is switched on for the guest, AP instructions must be interpreted by default; otherwise, they will be intercepted.

This attribute setting may be overridden by a device. For example, a device may want to provide AP instructions to the guest (i.e., S390_FEAT_AP turned on), but it may want to emulate them. In this case, the AP instructions executed on the guest must be intercepted; so when the device is realized, it must disable interpretation.

Quoted 5 lines
---
 target/s390x/kvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Reviewed-by on v10 3/6
#13 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 3/6] s390x/kvm: enable AP instruction interpretation for guest

In reply to Tony Krowiak
Quoted 15 lines · Tony Krowiak

From: Tony Krowiak <[email protected]>

Let's use the KVM_SET_DEVICE_ATTR ioctl to enable hardware interpretation of AP instructions executed on the guest. If the S390_FEAT_AP feature is switched on for the guest, AP instructions must be interpreted by default; otherwise, they will be intercepted.

This attribute setting may be overridden by a device. For example, a device may want to provide AP instructions to the guest (i.e., S390_FEAT_AP turned on), but it may want to emulate them. In this case, the AP instructions executed on the guest must be intercepted; so when the device is realized, it must disable interpretation.

Quoted 2 lines
Quoted 47 lines
---
 target/s390x/kvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
target/s390x/kvm.c +19 -0
index 348e8cc5467a..d042deed1af3 100644
@@ -2291,11 +2291,26 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
         error_setg(errp, "KVM: host CPU model could not be identified");
         return;
     }
+    /* for now, we can only provide the AP feature with HW support */
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
+        KVM_S390_VM_CRYPTO_ENABLE_APIE)) {
+        set_bit(S390_FEAT_AP, model->features);
+    }
     /* strip of features that are not part of the maximum model */
     bitmap_and(model->features, model->features, model->def->full_feat,
                S390_FEAT_MAX);
 }
 
+static void kvm_s390_configure_apie(bool interpret)
+{
+    uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
+                                KVM_S390_VM_CRYPTO_DISABLE_APIE;
+
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {
+        kvm_s390_set_attr(attr);
+    }
+}
+
 void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
 {
     struct kvm_s390_vm_cpu_processor prop  = {
@@ -2345,6 +2360,10 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
     if (test_bit(S390_FEAT_CMM, model->features)) {
         kvm_s390_enable_cmma();
     }
+
+    if (test_bit(S390_FEAT_AP, model->features)) {
+        kvm_s390_configure_apie(true);
+    }
 }
 
 void kvm_s390_restart_interrupt(S390CPU *cpu)
Acked-by on v10 3/6
#14 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 3/6] s390x/kvm: enable AP instruction interpretation for guest

In reply to Tony Krowiak
Quoted 15 lines · Tony Krowiak

From: Tony Krowiak <[email protected]>

Let's use the KVM_SET_DEVICE_ATTR ioctl to enable hardware interpretation of AP instructions executed on the guest. If the S390_FEAT_AP feature is switched on for the guest, AP instructions must be interpreted by default; otherwise, they will be intercepted.

This attribute setting may be overridden by a device. For example, a device may want to provide AP instructions to the guest (i.e., S390_FEAT_AP turned on), but it may want to emulate them. In this case, the AP instructions executed on the guest must be intercepted; so when the device is realized, it must disable interpretation.

Quoted 2 lines
Quoted 18 lines
---
 target/s390x/kvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
target/s390x/kvm.c +5 -0
index 348e8cc5467a..d042deed1af3 100644
@@ -2291,11 +2291,26 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
         error_setg(errp, "KVM: host CPU model could not be identified");
         return;
     }
+    /* for now, we can only provide the AP feature with HW support */
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO,
+        KVM_S390_VM_CRYPTO_ENABLE_APIE)) {
+        set_bit(S390_FEAT_AP, model->features);
+    }
     /* strip of features that are not part of the maximum model */

target/s390x/kvm.c void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp) · line 2309

Quoted 10 lines
target/s390x/kvm.c +6 -0
     bitmap_and(model->features, model->features, model->def->full_feat,
                S390_FEAT_MAX);
 }
 
+static void kvm_s390_configure_apie(bool interpret)
+{
+    uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
+                                KVM_S390_VM_CRYPTO_DISABLE_APIE;
+
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {

Not sure this check is necessary, and that the behavior if it fails is intuitive, but whatever.

Quoted 19 lines
target/s390x/kvm.c +8 -0
+        kvm_s390_set_attr(attr);
+    }
+}
+
 void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
 {
     struct kvm_s390_vm_cpu_processor prop  = {
@@ -2345,6 +2360,10 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
     if (test_bit(S390_FEAT_CMM, model->features)) {
         kvm_s390_enable_cmma();
     }
+
+    if (test_bit(S390_FEAT_AP, model->features)) {
+        kvm_s390_configure_apie(true);
+    }
 }
 
 void kvm_s390_restart_interrupt(S390CPU *cpu)
#15 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 3/6] s390x/kvm: enable AP instruction interpretation for guest

Quoted 11 lines · On Wed, 10 Oct 2018 13:38:51 +0200 Halil Pasic <[email protected]> wrote:

target/s390x/kvm.c void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp) · line 2309

Quoted 6 lines · Tony Krowiak
target/s390x/kvm.c +6 -0
+static void kvm_s390_configure_apie(bool interpret)
+{
+    uint64_t attr = interpret ? KVM_S390_VM_CRYPTO_ENABLE_APIE :
+                                KVM_S390_VM_CRYPTO_DISABLE_APIE;
+
+    if (kvm_vm_check_attr(kvm_state, KVM_S390_VM_CRYPTO, attr)) {  

Not sure this check is necessary, and that the behavior if it fails is intuitive, but whatever.

It's not an uncommon pattern, and this is not a call where performance matters, so it's fine with me.

Quoted 5 lines
Quoted 5 lines
target/s390x/kvm.c +4 -0
+        kvm_s390_set_attr(attr);
+    }
+}
+
#16 lore raw

PATCH v10 4/6 s390x/ap: base Adjunct Processor (AP) object model

In reply to Tony Krowiak

From: Tony Krowiak <[email protected]>

Introduces the base object model for virtualizing AP devices.

---
 MAINTAINERS                  | 12 ++++++
 hw/s390x/Makefile.objs       |  2 +
 hw/s390x/ap-bridge.c         | 78 ++++++++++++++++++++++++++++++++++++
 hw/s390x/ap-device.c         | 39 ++++++++++++++++++
 hw/s390x/s390-virtio-ccw.c   |  4 ++
 include/hw/s390x/ap-bridge.h | 19 +++++++++
 include/hw/s390x/ap-device.h | 23 +++++++++++
 7 files changed, 177 insertions(+)
 create mode 100644 hw/s390x/ap-bridge.c
 create mode 100644 hw/s390x/ap-device.c
 create mode 100644 include/hw/s390x/ap-bridge.h
 create mode 100644 include/hw/s390x/ap-device.h
MAINTAINERS +12 -0
index d12518c08f10..97e8ed808bc0 100644
@@ -1199,6 +1199,18 @@ F: include/hw/s390x/s390-ccw.h
 T: git git://github.com/cohuck/qemu.git s390-next
 L: [email protected]
 
+vfio-ap
+M: Christian Borntraeger <[email protected]>
+M: Tony Krowiak <[email protected]>
+M: Halil Pasic <[email protected]>
+M: Pierre Morel <[email protected]>
+S: Supported
+F: hw/s390x/ap-device.c
+F: hw/s390x/ap-bridge.c
+F: include/hw/s390x/ap-device.h
+F: include/hw/s390x/ap-bridge.h
+L: [email protected]
+
 vhost
 M: Michael S. Tsirkin <[email protected]>
 S: Supported
hw/s390x/Makefile.objs +2 -0
index 93282f7c593c..add89b150d90 100644
@@ -20,3 +20,5 @@ obj-$(CONFIG_TCG) += tod-qemu.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
 obj-$(CONFIG_KVM) += s390-stattrib-kvm.o
 obj-y += s390-ccw.o
+obj-y += ap-device.o
+obj-y += ap-bridge.o
hw/s390x/ap-bridge.c new file +78 -0

78 lines not on this page · raw message

hw/s390x/ap-device.c new file +39 -0
new file mode 100644
index 000000000000..fb6e35024c82
@@ -0,0 +1,39 @@
+/*
+ * Adjunct Processor (AP) matrix device
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qapi/error.h"
+#include "hw/qdev.h"
+#include "hw/s390x/ap-device.h"
+
+static void ap_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->desc = "AP device class";
+    dc->hotpluggable = false;
+}
+
+static const TypeInfo ap_device_info = {
+    .name = AP_DEVICE_TYPE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(APDevice),
+    .class_size = sizeof(DeviceClass),
+    .class_init = ap_class_init,
+    .abstract = true,
+};
+
+static void ap_device_register(void)
+{
+    type_register_static(&ap_device_info);
+}
+
+type_init(ap_device_register)
hw/s390x/s390-virtio-ccw.c +4 -0
index f0f7fdcaddf2..3c100c24f3e8 100644
@@ -32,6 +32,7 @@
 #include "ipl.h"
 #include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/s390x/css-bridge.h"
+#include "hw/s390x/ap-bridge.h"
 #include "migration/register.h"
 #include "cpu_models.h"
 #include "hw/nmi.h"
@@ -263,6 +264,9 @@ static void ccw_init(MachineState *machine)
     /* init the SIGP facility */
     s390_init_sigp();
 
+    /* create AP bridge and bus(es) */
+    s390_init_ap();
+
     /* get a BUS */
     css_bus = virtual_css_bus_init();
     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
include/hw/s390x/ap-bridge.h new file +19 -0
new file mode 100644
index 000000000000..470e439a98ed
@@ -0,0 +1,19 @@
+/*
+ * ap bridge
+ *
+ * Copyright 2018 IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef HW_S390X_AP_BRIDGE_H
+#define HW_S390X_AP_BRIDGE_H
+
+#define TYPE_AP_BRIDGE "ap-bridge"
+#define TYPE_AP_BUS "ap-bus"
+
+void s390_init_ap(void);
+
+#endif
include/hw/s390x/ap-device.h new file +23 -0
new file mode 100644
index 000000000000..4fb3c9ab82f2
@@ -0,0 +1,23 @@
+/*
+ * Adjunct Processor (AP) matrix device interfaces
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#ifndef HW_S390X_AP_DEVICE_H
+#define HW_S390X_AP_DEVICE_H
+
+#define AP_DEVICE_TYPE       "ap-device"
+
+typedef struct APDevice {
+    DeviceState parent_obj;
+} APDevice;
+
+#define AP_DEVICE(obj) \
+    OBJECT_CHECK(APDevice, (obj), AP_DEVICE_TYPE)
+
+#endif /* HW_S390X_AP_DEVICE_H */
Signature · 1 line
2.19.0.221.g150f307
Reviewed-by on v10 4/6
#17 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 4/6] s390x/ap: base Adjunct Processor (AP) object model

Quoted 250 lines · Tony Krowiak

From: Tony Krowiak <[email protected]>

Introduces the base object model for virtualizing AP devices.

---
 MAINTAINERS                  | 12 ++++++
 hw/s390x/Makefile.objs       |  2 +
 hw/s390x/ap-bridge.c         | 78 ++++++++++++++++++++++++++++++++++++
 hw/s390x/ap-device.c         | 39 ++++++++++++++++++
 hw/s390x/s390-virtio-ccw.c   |  4 ++
 include/hw/s390x/ap-bridge.h | 19 +++++++++
 include/hw/s390x/ap-device.h | 23 +++++++++++
 7 files changed, 177 insertions(+)
 create mode 100644 hw/s390x/ap-bridge.c
 create mode 100644 hw/s390x/ap-device.c
 create mode 100644 include/hw/s390x/ap-bridge.h
 create mode 100644 include/hw/s390x/ap-device.h
MAINTAINERS +12 -0
index d12518c08f10..97e8ed808bc0 100644
@@ -1199,6 +1199,18 @@ F: include/hw/s390x/s390-ccw.h
 T: git git://github.com/cohuck/qemu.git s390-next
 L: [email protected]
 
+vfio-ap
+M: Christian Borntraeger <[email protected]>
+M: Tony Krowiak <[email protected]>
+M: Halil Pasic <[email protected]>
+M: Pierre Morel <[email protected]>
+S: Supported
+F: hw/s390x/ap-device.c
+F: hw/s390x/ap-bridge.c
+F: include/hw/s390x/ap-device.h
+F: include/hw/s390x/ap-bridge.h
+L: [email protected]
+
 vhost
 M: Michael S. Tsirkin <[email protected]>
 S: Supported
hw/s390x/Makefile.objs +2 -0
index 93282f7c593c..add89b150d90 100644
@@ -20,3 +20,5 @@ obj-$(CONFIG_TCG) += tod-qemu.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
 obj-$(CONFIG_KVM) += s390-stattrib-kvm.o
 obj-y += s390-ccw.o
+obj-y += ap-device.o
+obj-y += ap-bridge.o
hw/s390x/ap-bridge.c new file +78 -0
new file mode 100644
index 000000000000..3795d30dd7c9
@@ -0,0 +1,78 @@
+/*
+ * ap bridge
+ *
+ * Copyright 2018 IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "qemu/bitops.h"
+#include "hw/s390x/ap-bridge.h"
+#include "cpu.h"
+
+static char *ap_bus_get_dev_path(DeviceState *dev)
+{
+    /* at most one */
+    return g_strdup_printf("/1");
+}
+
+static void ap_bus_class_init(ObjectClass *oc, void *data)
+{
+    BusClass *k = BUS_CLASS(oc);
+
+    k->get_dev_path = ap_bus_get_dev_path;
+    /* More than one ap device does not make sense */
+    k->max_dev = 1;
+}
+
+static const TypeInfo ap_bus_info = {
+    .name = TYPE_AP_BUS,
+    .parent = TYPE_BUS,
+    .instance_size = 0,
+    .class_init = ap_bus_class_init,
+};
+
+void s390_init_ap(void)
+{
+    DeviceState *dev;
+
+    /* If no AP instructions then no need for AP bridge */
+    if (!s390_has_feat(S390_FEAT_AP)) {
+        return;
+    }
+
+    /* Create bridge device */
+    dev = qdev_create(NULL, TYPE_AP_BRIDGE);
+    object_property_add_child(qdev_get_machine(), TYPE_AP_BRIDGE,
+                              OBJECT(dev), NULL);
+    qdev_init_nofail(dev);
+
+    /* Create bus on bridge device */
+    qbus_create(TYPE_AP_BUS, dev, TYPE_AP_BUS);
+ }
+
+static void ap_bridge_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+}
+
+static const TypeInfo ap_bridge_info = {
+    .name          = TYPE_AP_BRIDGE,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = 0,
+    .class_init    = ap_bridge_class_init,
+};
+
+static void ap_register(void)
+{
+    type_register_static(&ap_bridge_info);
+    type_register_static(&ap_bus_info);
+}
+
+type_init(ap_register)
hw/s390x/ap-device.c new file +39 -0
new file mode 100644
index 000000000000..fb6e35024c82
@@ -0,0 +1,39 @@
+/*
+ * Adjunct Processor (AP) matrix device
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qapi/error.h"
+#include "hw/qdev.h"
+#include "hw/s390x/ap-device.h"
+
+static void ap_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->desc = "AP device class";
+    dc->hotpluggable = false;
+}
+
+static const TypeInfo ap_device_info = {
+    .name = AP_DEVICE_TYPE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(APDevice),
+    .class_size = sizeof(DeviceClass),
+    .class_init = ap_class_init,
+    .abstract = true,
+};
+
+static void ap_device_register(void)
+{
+    type_register_static(&ap_device_info);
+}
+
+type_init(ap_device_register)
hw/s390x/s390-virtio-ccw.c +4 -0
index f0f7fdcaddf2..3c100c24f3e8 100644
@@ -32,6 +32,7 @@
 #include "ipl.h"
 #include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/s390x/css-bridge.h"
+#include "hw/s390x/ap-bridge.h"
 #include "migration/register.h"
 #include "cpu_models.h"
 #include "hw/nmi.h"
@@ -263,6 +264,9 @@ static void ccw_init(MachineState *machine)
     /* init the SIGP facility */
     s390_init_sigp();
 
+    /* create AP bridge and bus(es) */
+    s390_init_ap();
+
     /* get a BUS */
     css_bus = virtual_css_bus_init();
     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
include/hw/s390x/ap-bridge.h new file +19 -0
new file mode 100644
index 000000000000..470e439a98ed
@@ -0,0 +1,19 @@
+/*
+ * ap bridge
+ *
+ * Copyright 2018 IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef HW_S390X_AP_BRIDGE_H
+#define HW_S390X_AP_BRIDGE_H
+
+#define TYPE_AP_BRIDGE "ap-bridge"
+#define TYPE_AP_BUS "ap-bus"
+
+void s390_init_ap(void);
+
+#endif
include/hw/s390x/ap-device.h new file +13 -0
new file mode 100644
index 000000000000..4fb3c9ab82f2
@@ -0,0 +1,23 @@
+/*
+ * Adjunct Processor (AP) matrix device interfaces
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#ifndef HW_S390X_AP_DEVICE_H
+#define HW_S390X_AP_DEVICE_H
+

include/hw/s390x/ap-device.h line 23

Quoted 10 lines
include/hw/s390x/ap-device.h new file +10 -0
+#define AP_DEVICE_TYPE       "ap-device"
+
+typedef struct APDevice {
+    DeviceState parent_obj;
+} APDevice;
+
+#define AP_DEVICE(obj) \
+    OBJECT_CHECK(APDevice, (obj), AP_DEVICE_TYPE)
+
+#endif /* HW_S390X_AP_DEVICE_H */
#18 lore raw

Re: [Qemu-devel] [PATCH v10 4/6] s390x/ap: base Adjunct Processor (AP) object model

In reply to Tony Krowiak

hw/s390x/ap-device.c line 5

Quoted 11 lines · On Tue, 9 Oct 2018 13:52:24 -0400 Tony Krowiak <[email protected]>…
hw/s390x/ap-device.c new file +5 -0
new file mode 100644
index 000000000000..fb6e35024c82
@@ -0,0 +1,39 @@
+/*
+ * Adjunct Processor (AP) matrix device
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>

Do you also want this to use the vnet-less form instead?

Quoted 12 lines
hw/s390x/ap-device.c new file +5 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
include/hw/s390x/ap-device.h new file +0 -0
new file mode 100644
index 000000000000..4fb3c9ab82f2

include/hw/s390x/ap-device.h line 5

Quoted 5 lines
include/hw/s390x/ap-device.h new file +5 -0
@@ -0,0 +1,23 @@
+/*
+ * Adjunct Processor (AP) matrix device interfaces
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>

Same here.

#19 lore raw

Re: [Qemu-devel] [PATCH v10 4/6] s390x/ap: base Adjunct Processor (AP) object model

Quoted 23 lines · Cornelia Huck

hw/s390x/ap-device.c line 5

Quoted 11 lines · On Tue, 9 Oct 2018 13:52:24 -0400 Tony Krowiak <[email protected]>…
hw/s390x/ap-device.c new file +5 -0
new file mode 100644
index 000000000000..fb6e35024c82
@@ -0,0 +1,39 @@
+/*
+ * Adjunct Processor (AP) matrix device
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>

Do you also want this to use the vnet-less form instead?

Quoted 5 lines
hw/s390x/ap-device.c new file +5 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
Quoted 13 lines

include/hw/s390x/ap-device.h line 5

Quoted 11 lines
include/hw/s390x/ap-device.h new file +5 -0
new file mode 100644
index 000000000000..4fb3c9ab82f2
@@ -0,0 +1,23 @@
+/*
+ * Adjunct Processor (AP) matrix device interfaces
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>

Same here.

Yes. Shall I just submit a v11?

Quoted 1 line
#20 lore raw

Re: [Qemu-devel] [PATCH v10 4/6] s390x/ap: base Adjunct Processor (AP) object model

Quoted 38 lines · On Wed, 10 Oct 2018 09:59:55 -0400 Tony Krowiak <[email protected]> wrote:
Quoted 23 lines · Cornelia Huck

hw/s390x/ap-device.c line 5

Quoted 11 lines · On Tue, 9 Oct 2018 13:52:24 -0400 Tony Krowiak <[email protected]>…
hw/s390x/ap-device.c new file +5 -0
new file mode 100644
index 000000000000..fb6e35024c82
@@ -0,0 +1,39 @@
+/*
+ * Adjunct Processor (AP) matrix device
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>  

Do you also want this to use the vnet-less form instead?

Quoted 5 lines
hw/s390x/ap-device.c new file +5 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */  
Quoted 13 lines

include/hw/s390x/ap-device.h line 5

Quoted 11 lines
include/hw/s390x/ap-device.h new file +5 -0
new file mode 100644
index 000000000000..4fb3c9ab82f2
@@ -0,0 +1,23 @@
+/*
+ * Adjunct Processor (AP) matrix device interfaces
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>  

Same here.

Quoted 1 line

Yes. Shall I just submit a v11?

Please submit a v11 with the various things mentioned during review (and the r-bs etc. collected).

Reviewed-by on v10 4/6
#21 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 4/6] s390x/ap: base Adjunct Processor (AP) object model

In reply to Tony Krowiak
Quoted 7 lines · Tony Krowiak

From: Tony Krowiak <[email protected]>

Introduces the base object model for virtualizing AP devices.

Quoted 204 lines
---
 MAINTAINERS                  | 12 ++++++
 hw/s390x/Makefile.objs       |  2 +
 hw/s390x/ap-bridge.c         | 78 ++++++++++++++++++++++++++++++++++++
 hw/s390x/ap-device.c         | 39 ++++++++++++++++++
 hw/s390x/s390-virtio-ccw.c   |  4 ++
 include/hw/s390x/ap-bridge.h | 19 +++++++++
 include/hw/s390x/ap-device.h | 23 +++++++++++
 7 files changed, 177 insertions(+)
 create mode 100644 hw/s390x/ap-bridge.c
 create mode 100644 hw/s390x/ap-device.c
 create mode 100644 include/hw/s390x/ap-bridge.h
 create mode 100644 include/hw/s390x/ap-device.h
MAINTAINERS +12 -0
index d12518c08f10..97e8ed808bc0 100644
@@ -1199,6 +1199,18 @@ F: include/hw/s390x/s390-ccw.h
 T: git git://github.com/cohuck/qemu.git s390-next
 L: [email protected]
 
+vfio-ap
+M: Christian Borntraeger <[email protected]>
+M: Tony Krowiak <[email protected]>
+M: Halil Pasic <[email protected]>
+M: Pierre Morel <[email protected]>
+S: Supported
+F: hw/s390x/ap-device.c
+F: hw/s390x/ap-bridge.c
+F: include/hw/s390x/ap-device.h
+F: include/hw/s390x/ap-bridge.h
+L: [email protected]
+
 vhost
 M: Michael S. Tsirkin <[email protected]>
 S: Supported
hw/s390x/Makefile.objs +2 -0
index 93282f7c593c..add89b150d90 100644
@@ -20,3 +20,5 @@ obj-$(CONFIG_TCG) += tod-qemu.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
 obj-$(CONFIG_KVM) += s390-stattrib-kvm.o
 obj-y += s390-ccw.o
+obj-y += ap-device.o
+obj-y += ap-bridge.o
hw/s390x/ap-bridge.c new file +78 -0
new file mode 100644
index 000000000000..3795d30dd7c9
@@ -0,0 +1,78 @@
+/*
+ * ap bridge
+ *
+ * Copyright 2018 IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "qemu/bitops.h"
+#include "hw/s390x/ap-bridge.h"
+#include "cpu.h"
+
+static char *ap_bus_get_dev_path(DeviceState *dev)
+{
+    /* at most one */
+    return g_strdup_printf("/1");
+}
+
+static void ap_bus_class_init(ObjectClass *oc, void *data)
+{
+    BusClass *k = BUS_CLASS(oc);
+
+    k->get_dev_path = ap_bus_get_dev_path;
+    /* More than one ap device does not make sense */
+    k->max_dev = 1;
+}
+
+static const TypeInfo ap_bus_info = {
+    .name = TYPE_AP_BUS,
+    .parent = TYPE_BUS,
+    .instance_size = 0,
+    .class_init = ap_bus_class_init,
+};
+
+void s390_init_ap(void)
+{
+    DeviceState *dev;
+
+    /* If no AP instructions then no need for AP bridge */
+    if (!s390_has_feat(S390_FEAT_AP)) {
+        return;
+    }
+
+    /* Create bridge device */
+    dev = qdev_create(NULL, TYPE_AP_BRIDGE);
+    object_property_add_child(qdev_get_machine(), TYPE_AP_BRIDGE,
+                              OBJECT(dev), NULL);
+    qdev_init_nofail(dev);
+
+    /* Create bus on bridge device */
+    qbus_create(TYPE_AP_BUS, dev, TYPE_AP_BUS);
+ }
+
+static void ap_bridge_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+}
+
+static const TypeInfo ap_bridge_info = {
+    .name          = TYPE_AP_BRIDGE,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = 0,
+    .class_init    = ap_bridge_class_init,
+};
+
+static void ap_register(void)
+{
+    type_register_static(&ap_bridge_info);
+    type_register_static(&ap_bus_info);
+}
+
+type_init(ap_register)
hw/s390x/ap-device.c new file +39 -0
new file mode 100644
index 000000000000..fb6e35024c82
@@ -0,0 +1,39 @@
+/*
+ * Adjunct Processor (AP) matrix device
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qapi/error.h"
+#include "hw/qdev.h"
+#include "hw/s390x/ap-device.h"
+
+static void ap_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->desc = "AP device class";
+    dc->hotpluggable = false;
+}
+
+static const TypeInfo ap_device_info = {
+    .name = AP_DEVICE_TYPE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(APDevice),
+    .class_size = sizeof(DeviceClass),
+    .class_init = ap_class_init,
+    .abstract = true,
+};
+
+static void ap_device_register(void)
+{
+    type_register_static(&ap_device_info);
+}
+
+type_init(ap_device_register)
hw/s390x/s390-virtio-ccw.c +4 -0
index f0f7fdcaddf2..3c100c24f3e8 100644
@@ -32,6 +32,7 @@
 #include "ipl.h"
 #include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/s390x/css-bridge.h"
+#include "hw/s390x/ap-bridge.h"
 #include "migration/register.h"
 #include "cpu_models.h"
 #include "hw/nmi.h"
@@ -263,6 +264,9 @@ static void ccw_init(MachineState *machine)
     /* init the SIGP facility */
     s390_init_sigp();
 
+    /* create AP bridge and bus(es) */
+    s390_init_ap();
+
     /* get a BUS */
     css_bus = virtual_css_bus_init();
     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
include/hw/s390x/ap-bridge.h new file +0 -0
new file mode 100644
index 000000000000..470e439a98ed

include/hw/s390x/ap-bridge.h line 5

Quoted 5 lines
include/hw/s390x/ap-bridge.h new file +5 -0
@@ -0,0 +1,19 @@
+/*
+ * ap bridge
+ *
+ * Copyright 2018 IBM Corp.
+ *

This one does not have 'Author(s):' and Connie already mentioned that some others use vnet address.

I would prefer resolving this by not adding any 'Author(s):' for any the files introduce by this series.

My r-b stands regardless of the resolution.

Quoted 44 lines
include/hw/s390x/ap-bridge.h new file +14 -0
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef HW_S390X_AP_BRIDGE_H
+#define HW_S390X_AP_BRIDGE_H
+
+#define TYPE_AP_BRIDGE "ap-bridge"
+#define TYPE_AP_BUS "ap-bus"
+
+void s390_init_ap(void);
+
+#endif
include/hw/s390x/ap-device.h new file +23 -0
new file mode 100644
index 000000000000..4fb3c9ab82f2
@@ -0,0 +1,23 @@
+/*
+ * Adjunct Processor (AP) matrix device interfaces
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#ifndef HW_S390X_AP_DEVICE_H
+#define HW_S390X_AP_DEVICE_H
+
+#define AP_DEVICE_TYPE       "ap-device"
+
+typedef struct APDevice {
+    DeviceState parent_obj;
+} APDevice;
+
+#define AP_DEVICE(obj) \
+    OBJECT_CHECK(APDevice, (obj), AP_DEVICE_TYPE)
+
+#endif /* HW_S390X_AP_DEVICE_H */
#22 lore raw

PATCH v10 5/6 s390x/vfio: ap: Introduce VFIO AP device

In reply to Tony Krowiak

Introduces a VFIO based AP device. The device is defined via the QEMU command line by specifying:

-device vfio-ap,sysfsdev=<path-to-mediated-matrix-device>

There may be only one vfio-ap device configured for a guest.

The mediated matrix device is created by the VFIO AP device driver by writing a UUID to a sysfs attribute file (see docs/vfio-ap.txt). The mediated matrix device will be named after the UUID. Symbolic links to the $uuid are created in many places, so the path to the mediated matrix device $uuid can be specified in any of the following ways:

/sys/devices/vfio_ap/matrix/$uuid /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid /sys/bus/mdev/devices/$uuid
/sys/bus/mdev/drivers/vfio_mdev/$uuid

When the vfio-ap device is realized, it acquires and opens the VFIO iommu group to which the mediated matrix device is bound. This causes a VFIO group notification event to be signaled. The vfio_ap device driver's group notification handler will get called at which time the device driver will configure the the AP devices to which the guest will be granted access.

---
 MAINTAINERS                       |   1 +
 default-configs/s390x-softmmu.mak |   1 +
 hw/vfio/Makefile.objs             |   1 +
 hw/vfio/ap.c                      | 180 ++++++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h     |   1 +
 5 files changed, 184 insertions(+)
 create mode 100644 hw/vfio/ap.c
MAINTAINERS +1 -0
index 97e8ed808bc0..29041da69237 100644
@@ -1209,6 +1209,7 @@ F: hw/s390x/ap-device.c
 F: hw/s390x/ap-bridge.c
 F: include/hw/s390x/ap-device.h
 F: include/hw/s390x/ap-bridge.h
+F: hw/vfio/ap.c
 L: [email protected]
 
 vhost
default-configs/s390x-softmmu.mak +1 -0
index d6b67d50f0e4..5eef37592451 100644
@@ -7,3 +7,4 @@ CONFIG_S390_FLIC=y
 CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
 CONFIG_VFIO_CCW=$(CONFIG_LINUX)
 CONFIG_WDT_DIAG288=y
+CONFIG_VFIO_AP=$(CONFIG_LINUX)
hw/vfio/Makefile.objs +1 -0
index a2e7a0a7cf02..8b3f664d85f7 100644
@@ -6,4 +6,5 @@ obj-$(CONFIG_SOFTMMU) += platform.o
 obj-$(CONFIG_VFIO_XGMAC) += calxeda-xgmac.o
 obj-$(CONFIG_VFIO_AMD_XGBE) += amd-xgbe.o
 obj-$(CONFIG_SOFTMMU) += spapr.o
+obj-$(CONFIG_VFIO_AP) += ap.o
 endif
hw/vfio/ap.c new file +180 -0

180 lines not on this page · raw message

include/hw/vfio/vfio-common.h +1 -0
index 821def05658f..6be9a93f611b 100644
@@ -37,6 +37,7 @@ enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
     VFIO_DEVICE_TYPE_CCW = 2,
+    VFIO_DEVICE_TYPE_AP = 3,
 };
 
 typedef struct VFIOMmap {
Signature · 1 line
2.19.0.221.g150f307
#23 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 19 lines
hw/vfio/ap.c new file +18 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);

hw/vfio/ap.c line 111

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+

I commented on the old version that this is wrong (if I am not starting to lose my memory). This has to go. (there is no such property, this will simply report an error we ignore)

(can most probably be fixed when applying)

Signature · 3 lines
Thanks,

David / dhildenb
#24 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 34 lines · David Hildenbrand
Quoted 19 lines
hw/vfio/ap.c new file +18 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);

hw/vfio/ap.c line 111

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+

I commented on the old version that this is wrong (if I am not starting to lose my memory). This has to go. (there is no such property, this will simply report an error we ignore)

Quoted 2 lines

(can most probably be fixed when applying)

+1
absolutely no problem to remove this line.
I also tested without this line.

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

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 35 lines · On Wed, 10 Oct 2018 09:29:10 +0200 Pierre Morel <[email protected]> wrote:
Quoted 34 lines · David Hildenbrand
Quoted 19 lines
hw/vfio/ap.c new file +18 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);

hw/vfio/ap.c line 111

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+  

I commented on the old version that this is wrong (if I am not starting to lose my memory). This has to go. (there is no such property, this will simply report an error we ignore)

Quoted 7 lines
Quoted 2 lines

(can most probably be fixed when applying)

+1
absolutely no problem to remove this line.
I also tested without this line.

Yes, I can simply drop it when applying. Thanks for verifying :)

#26 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

In reply to David Hildenbrand
Quoted 34 lines · David Hildenbrand
Quoted 19 lines
hw/vfio/ap.c new file +18 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);

hw/vfio/ap.c line 111

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+

I commented on the old version that this is wrong (if I am not starting to lose my memory). This has to go. (there is no such property, this will simply report an error we ignore)

Quoted 1 line

(can most probably be fixed when applying)

I don't recall whether you mentioned it, but I will fix it, or it can be fixed when applied .... Connie?

Quoted 1 line
#27 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

In reply to Tony Krowiak
Quoted 30 lines · Tony Krowiak

Introduces a VFIO based AP device. The device is defined via the QEMU command line by specifying:

-device vfio-ap,sysfsdev=<path-to-mediated-matrix-device>

There may be only one vfio-ap device configured for a guest.

The mediated matrix device is created by the VFIO AP device driver by writing a UUID to a sysfs attribute file (see docs/vfio-ap.txt). The mediated matrix device will be named after the UUID. Symbolic links to the $uuid are created in many places, so the path to the mediated matrix device $uuid can be specified in any of the following ways:

/sys/devices/vfio_ap/matrix/$uuid /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid /sys/bus/mdev/devices/$uuid
/sys/bus/mdev/drivers/vfio_mdev/$uuid

When the vfio-ap device is realized, it acquires and opens the VFIO iommu group to which the mediated matrix device is bound. This causes a VFIO group notification event to be signaled. The vfio_ap device driver's group notification handler will get called at which time the device driver will configure the the AP devices to which the guest will be granted access.

---

[...]

Quoted 13 lines
hw/vfio/ap.c new file +13 -0
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);
+    g_free(symlink);
+
+    if (!group_path) {
+        error_setg(errp, "%s: no iommu_group found for %s: %s",
+                   VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);

hw/vfio/ap.c line 82

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+        return NULL;
+    }
+
+    if (sscanf(basename(group_path), "%d", &groupid) != 1) {
+        error_setg(errp, "vfio: failed to read %s", group_path);
+        return NULL;
+    }
+
+    return vfio_get_group(groupid, &address_space_memory, errp);
+}

I think you've got to g_free(group_path) after you don't need it anymore.

Quoted 31 lines
hw/vfio/ap.c new file +31 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+
+    return;
+
+out_get_dev_err:

hw/vfio/ap.c line 124

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(vfio_group);
+out_err:
+    error_propagate(errp, local_err);
+}
+
+static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
+{
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);

Didn't you want to remove the DO_UPCASTs ?

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+    VFIOGroup *group = vapdev->vdev.group;
+
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(group);
+}
+

hw/vfio/ap.c line 140

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+static Property vfio_ap_properties[] = {
+    DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vfio_ap_reset(DeviceState *dev)
+{
+    int ret;
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);

dito

hw/vfio/ap.c line 147

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+    ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);
+    if (ret) {
+        error_report("%s: failed to reset %s device: %s", __func__,
+                     vapdev->vdev.name, strerror(ret));
+    }
+}

Thomas

#28 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 83 lines · On Wed, 10 Oct 2018 10:25:22 +0200 Thomas Huth <[email protected]> wrote:

On 2018-10-09 19:52, Tony Krowiak wrote:

[...]

Quoted 13 lines
hw/vfio/ap.c new file +13 -0
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);
+    g_free(symlink);
+
+    if (!group_path) {
+        error_setg(errp, "%s: no iommu_group found for %s: %s",
+                   VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);

hw/vfio/ap.c line 82

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+        return NULL;
+    }
+
+    if (sscanf(basename(group_path), "%d", &groupid) != 1) {
+        error_setg(errp, "vfio: failed to read %s", group_path);
+        return NULL;
+    }
+
+    return vfio_get_group(groupid, &address_space_memory, errp);
+}  

I think you've got to g_free(group_path) after you don't need it anymore.

Quoted 31 lines
hw/vfio/ap.c new file +31 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+
+    return;
+
+out_get_dev_err:

hw/vfio/ap.c line 124

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(vfio_group);
+out_err:
+    error_propagate(errp, local_err);
+}
+
+static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
+{
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);  

Didn't you want to remove the DO_UPCASTs ?

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    VFIOGroup *group = vapdev->vdev.group;
+
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(group);
+}
+
+static Property vfio_ap_properties[] = {
+    DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
+    DEFINE_PROP_END_OF_LIST(),
+};
Quoted 15 lines

hw/vfio/ap.c line 140

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+
+static void vfio_ap_reset(DeviceState *dev)
+{
+    int ret;
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);  

dito

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+    ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);
+    if (ret) {
+        error_report("%s: failed to reset %s device: %s", __func__,
+                     vapdev->vdev.name, strerror(ret));
+    }
+}  

OK, this is now a bit too much stuff all in all to change while applying...

Tony, can you please do a respin with these changes and the other things people have noticed? Thanks!

#29 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 102 lines · Cornelia Huck
Quoted 83 lines · On Wed, 10 Oct 2018 10:25:22 +0200 Thomas Huth <[email protected]> wrote:

On 2018-10-09 19:52, Tony Krowiak wrote:

[...]

Quoted 13 lines
hw/vfio/ap.c new file +13 -0
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);
+    g_free(symlink);
+
+    if (!group_path) {
+        error_setg(errp, "%s: no iommu_group found for %s: %s",
+                   VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);

hw/vfio/ap.c line 82

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+        return NULL;
+    }
+
+    if (sscanf(basename(group_path), "%d", &groupid) != 1) {
+        error_setg(errp, "vfio: failed to read %s", group_path);
+        return NULL;
+    }
+
+    return vfio_get_group(groupid, &address_space_memory, errp);
+}

I think you've got to g_free(group_path) after you don't need it anymore.

Quoted 31 lines
hw/vfio/ap.c new file +31 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+
+    return;
+
+out_get_dev_err:

hw/vfio/ap.c line 124

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(vfio_group);
+out_err:
+    error_propagate(errp, local_err);
+}
+
+static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
+{
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);

Didn't you want to remove the DO_UPCASTs ?

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+    VFIOGroup *group = vapdev->vdev.group;
+
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(group);
+}
+
+static Property vfio_ap_properties[] = {
+    DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
+    DEFINE_PROP_END_OF_LIST(),
+};
Quoted 15 lines

hw/vfio/ap.c line 140

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+
+static void vfio_ap_reset(DeviceState *dev)
+{
+    int ret;
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);

dito

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+    ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);
+    if (ret) {
+        error_report("%s: failed to reset %s device: %s", __func__,
+                     vapdev->vdev.name, strerror(ret));
+    }
+}
Quoted 5 lines

OK, this is now a bit too much stuff all in all to change while applying...

Tony, can you please do a respin with these changes and the other things people have noticed? Thanks!

I will have v11 posted today.

Quoted 1 line
#30 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

In reply to Thomas Huth
Quoted 49 lines · Thomas Huth
Quoted 30 lines · Tony Krowiak

Introduces a VFIO based AP device. The device is defined via the QEMU command line by specifying:

-device vfio-ap,sysfsdev=<path-to-mediated-matrix-device>

There may be only one vfio-ap device configured for a guest.

The mediated matrix device is created by the VFIO AP device driver by writing a UUID to a sysfs attribute file (see docs/vfio-ap.txt). The mediated matrix device will be named after the UUID. Symbolic links to the $uuid are created in many places, so the path to the mediated matrix device $uuid can be specified in any of the following ways:

/sys/devices/vfio_ap/matrix/$uuid /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid /sys/bus/mdev/devices/$uuid
/sys/bus/mdev/drivers/vfio_mdev/$uuid

When the vfio-ap device is realized, it acquires and opens the VFIO iommu group to which the mediated matrix device is bound. This causes a VFIO group notification event to be signaled. The vfio_ap device driver's group notification handler will get called at which time the device driver will configure the the AP devices to which the guest will be granted access.

---

[...]

Quoted 17 lines
hw/vfio/ap.c new file +17 -0
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);
+    g_free(symlink);
+
+    if (!group_path) {
+        error_setg(errp, "%s: no iommu_group found for %s: %s",
+                   VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);
+        return NULL;
+    }
+
+    if (sscanf(basename(group_path), "%d", &groupid) != 1) {
Quoted 8 lines

hw/vfio/ap.c line 82

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+        error_setg(errp, "vfio: failed to read %s", group_path);
+        return NULL;
+    }
+
+    return vfio_get_group(groupid, &address_space_memory, errp);
+}

I think you've got to g_free(group_path) after you don't need it anymore.

Right you are.

Quoted 36 lines
Quoted 36 lines
hw/vfio/ap.c new file +35 -0
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+
+    return;
+
+out_get_dev_err:
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(vfio_group);
+out_err:
+    error_propagate(errp, local_err);
Quoted 8 lines

hw/vfio/ap.c line 124

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+}
+
+static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
+{
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);

Didn't you want to remove the DO_UPCASTs ?

oops, missed these .... fixed them in the realize function, but missed this one and the next .... will fix

Quoted 11 lines
Quoted 11 lines
hw/vfio/ap.c new file +10 -0
+    VFIOGroup *group = vapdev->vdev.group;
+
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(group);
+}
+
+static Property vfio_ap_properties[] = {
+    DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
+    DEFINE_PROP_END_OF_LIST(),
+};
Quoted 8 lines

hw/vfio/ap.c line 140

Quoted 6 lines
hw/vfio/ap.c new file +6 -0
+
+static void vfio_ap_reset(DeviceState *dev)
+{
+    int ret;
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);

dito

ditto

Quoted 10 lines

hw/vfio/ap.c line 147

Quoted 7 lines
hw/vfio/ap.c new file +6 -0
+    ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);
+    if (ret) {
+        error_report("%s: failed to reset %s device: %s", __func__,
+                     vapdev->vdev.name, strerror(ret));
+    }
+}

Thomas

#31 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

In reply to Tony Krowiak

MAINTAINERS F: hw/s390x/ap-device.c · line 1215

Quoted 12 lines · On Tue, 9 Oct 2018 13:52:25 -0400 Tony Krowiak <[email protected]>…
MAINTAINERS +1 -0
index 97e8ed808bc0..29041da69237 100644
@@ -1209,6 +1209,7 @@ F: hw/s390x/ap-device.c
 F: hw/s390x/ap-bridge.c
 F: include/hw/s390x/ap-device.h
 F: include/hw/s390x/ap-bridge.h
+F: hw/vfio/ap.c
 L: [email protected]
 
 vhost

Can you please also add hw/vfio/ap.c to the overall s390 architecture section in MAINTAINERS? The existing pattern does not catch it (but it does catch the files added in the last patch, so that's ok.)

#32 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 15 lines · Cornelia Huck
Quoted 11 lines · On Tue, 9 Oct 2018 13:52:25 -0400 Tony Krowiak <[email protected]>…
MAINTAINERS +1 -0
index 97e8ed808bc0..29041da69237 100644
@@ -1209,6 +1209,7 @@ F: hw/s390x/ap-device.c
  F: hw/s390x/ap-bridge.c
  F: include/hw/s390x/ap-device.h
  F: include/hw/s390x/ap-bridge.h
+F: hw/vfio/ap.c
  L: [email protected]
 
Quoted 5 lines

MAINTAINERS F: hw/s390x/ap-device.c · line 1215

Quoted 1 line
MAINTAINERS +0 -0
  vhost

Can you please also add hw/vfio/ap.c to the overall s390 architecture section in MAINTAINERS? The existing pattern does not catch it (but it does catch the files added in the last patch, so that's ok.)

Yes I can.

Quoted 1 line
Acked-by on v10 5/6
#33 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

In reply to Tony Krowiak
Quoted 27 lines · Tony Krowiak

Introduces a VFIO based AP device. The device is defined via the QEMU command line by specifying:

-device vfio-ap,sysfsdev=<path-to-mediated-matrix-device>

There may be only one vfio-ap device configured for a guest.

The mediated matrix device is created by the VFIO AP device driver by writing a UUID to a sysfs attribute file (see docs/vfio-ap.txt). The mediated matrix device will be named after the UUID. Symbolic links to the $uuid are created in many places, so the path to the mediated matrix device $uuid can be specified in any of the following ways:

/sys/devices/vfio_ap/matrix/$uuid /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid /sys/bus/mdev/devices/$uuid
/sys/bus/mdev/drivers/vfio_mdev/$uuid

When the vfio-ap device is realized, it acquires and opens the VFIO iommu group to which the mediated matrix device is bound. This causes a VFIO group notification event to be signaled. The vfio_ap device driver's group notification handler will get called at which time the device driver will configure the the AP devices to which the guest will be granted access.

Quoted 2 lines

Whit the things Thomas and David noticed fixed:

Quoted 239 lines
---
 MAINTAINERS                       |   1 +
 default-configs/s390x-softmmu.mak |   1 +
 hw/vfio/Makefile.objs             |   1 +
 hw/vfio/ap.c                      | 180 ++++++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h     |   1 +
 5 files changed, 184 insertions(+)
 create mode 100644 hw/vfio/ap.c
MAINTAINERS +1 -0
index 97e8ed808bc0..29041da69237 100644
@@ -1209,6 +1209,7 @@ F: hw/s390x/ap-device.c
 F: hw/s390x/ap-bridge.c
 F: include/hw/s390x/ap-device.h
 F: include/hw/s390x/ap-bridge.h
+F: hw/vfio/ap.c
 L: [email protected]
 
 vhost
default-configs/s390x-softmmu.mak +1 -0
index d6b67d50f0e4..5eef37592451 100644
@@ -7,3 +7,4 @@ CONFIG_S390_FLIC=y
 CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
 CONFIG_VFIO_CCW=$(CONFIG_LINUX)
 CONFIG_WDT_DIAG288=y
+CONFIG_VFIO_AP=$(CONFIG_LINUX)
hw/vfio/Makefile.objs +1 -0
index a2e7a0a7cf02..8b3f664d85f7 100644
@@ -6,4 +6,5 @@ obj-$(CONFIG_SOFTMMU) += platform.o
 obj-$(CONFIG_VFIO_XGMAC) += calxeda-xgmac.o
 obj-$(CONFIG_VFIO_AMD_XGBE) += amd-xgbe.o
 obj-$(CONFIG_SOFTMMU) += spapr.o
+obj-$(CONFIG_VFIO_AP) += ap.o
 endif
hw/vfio/ap.c new file +180 -0
new file mode 100644
index 000000000000..5543406afc58
@@ -0,0 +1,180 @@
+/*
+ * VFIO based AP matrix device assignment
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *            Halil Pasic <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include <linux/vfio.h>
+#include <sys/ioctl.h>
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "hw/vfio/vfio.h"
+#include "hw/vfio/vfio-common.h"
+#include "hw/s390x/ap-device.h"
+#include "qemu/error-report.h"
+#include "qemu/queue.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "cpu.h"
+#include "kvm_s390x.h"
+#include "sysemu/sysemu.h"
+#include "hw/s390x/ap-bridge.h"
+#include "exec/address-spaces.h"
+
+#define VFIO_AP_DEVICE_TYPE      "vfio-ap"
+
+typedef struct VFIOAPDevice {
+    APDevice apdev;
+    VFIODevice vdev;
+} VFIOAPDevice;
+
+#define VFIO_AP_DEVICE(obj) \
+        OBJECT_CHECK(VFIOAPDevice, (obj), VFIO_AP_DEVICE_TYPE)
+
+static void vfio_ap_compute_needs_reset(VFIODevice *vdev)
+{
+    vdev->needs_reset = false;
+}
+
+/*
+ * We don't need vfio_hot_reset_multi and vfio_eoi operations for
+ * vfio-ap device now.
+ */
+struct VFIODeviceOps vfio_ap_ops = {
+    .vfio_compute_needs_reset = vfio_ap_compute_needs_reset,
+};
+
+static void vfio_ap_put_device(VFIOAPDevice *vapdev)
+{
+    g_free(vapdev->vdev.name);
+    vfio_put_base_device(&vapdev->vdev);
+}
+
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);
+    g_free(symlink);
+
+    if (!group_path) {
+        error_setg(errp, "%s: no iommu_group found for %s: %s",
+                   VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev, gerror->message);
+        return NULL;
+    }
+
+    if (sscanf(basename(group_path), "%d", &groupid) != 1) {
+        error_setg(errp, "vfio: failed to read %s", group_path);
+        return NULL;
+    }
+
+    return vfio_get_group(groupid, &address_space_memory, errp);
+}
+
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+    int ret;
+    char *mdevid;
+    Error *local_err = NULL;
+    VFIOGroup *vfio_group;
+    APDevice *apdev = AP_DEVICE(dev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+
+    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    if (!vfio_group) {
+        goto out_err;
+    }
+
+    vapdev->vdev.ops = &vfio_ap_ops;
+    vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
+    mdevid = basename(vapdev->vdev.sysfsdev);
+    vapdev->vdev.name = g_strdup_printf("%s", mdevid);
+    vapdev->vdev.dev = dev;
+
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    if (ret) {
+        goto out_get_dev_err;
+    }
+
+    /* Enable hardware to intepret AP instructions executed on the guest */
+    object_property_set_bool(OBJECT(qdev_get_machine()), true, "apie", NULL);
+
+    return;
+
+out_get_dev_err:
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(vfio_group);
+out_err:
+    error_propagate(errp, local_err);
+}
+
+static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
+{
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);
+    VFIOGroup *group = vapdev->vdev.group;
+
+    vfio_ap_put_device(vapdev);
+    vfio_put_group(group);
+}
+
+static Property vfio_ap_properties[] = {
+    DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vfio_ap_reset(DeviceState *dev)
+{
+    int ret;
+    APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+    VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev);
+
+    ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);
+    if (ret) {
+        error_report("%s: failed to reset %s device: %s", __func__,
+                     vapdev->vdev.name, strerror(ret));
+    }
+}
+
+static const VMStateDescription vfio_ap_vmstate = {
+    .name = VFIO_AP_DEVICE_TYPE,
+    .unmigratable = 1,
+};
+
+static void vfio_ap_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = vfio_ap_properties;
+    dc->vmsd = &vfio_ap_vmstate;
+    dc->desc = "VFIO-based AP device assignment";
+    dc->realize = vfio_ap_realize;
+    dc->unrealize = vfio_ap_unrealize;
+    dc->hotpluggable = false;
+    dc->reset = vfio_ap_reset;
+    dc->bus_type = TYPE_AP_BUS;
+}
+
+static const TypeInfo vfio_ap_info = {
+    .name = VFIO_AP_DEVICE_TYPE,
+    .parent = AP_DEVICE_TYPE,
+    .instance_size = sizeof(VFIOAPDevice),
+    .class_init = vfio_ap_class_init,
+};
+
+static void vfio_ap_type_init(void)
+{
+    type_register_static(&vfio_ap_info);
+}
+
+type_init(vfio_ap_type_init)
include/hw/vfio/vfio-common.h +1 -0
index 821def05658f..6be9a93f611b 100644
@@ -37,6 +37,7 @@ enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
     VFIO_DEVICE_TYPE_CCW = 2,
+    VFIO_DEVICE_TYPE_AP = 3,
 };
 
 typedef struct VFIOMmap {
#34 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

In reply to Tony Krowiak
Quoted 132 lines · Tony Krowiak

Introduces a VFIO based AP device. The device is defined via the QEMU command line by specifying:

-device vfio-ap,sysfsdev=<path-to-mediated-matrix-device>

There may be only one vfio-ap device configured for a guest.

The mediated matrix device is created by the VFIO AP device driver by writing a UUID to a sysfs attribute file (see docs/vfio-ap.txt). The mediated matrix device will be named after the UUID. Symbolic links to the $uuid are created in many places, so the path to the mediated matrix device $uuid can be specified in any of the following ways:

/sys/devices/vfio_ap/matrix/$uuid /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid /sys/bus/mdev/devices/$uuid
/sys/bus/mdev/drivers/vfio_mdev/$uuid

When the vfio-ap device is realized, it acquires and opens the VFIO iommu group to which the mediated matrix device is bound. This causes a VFIO group notification event to be signaled. The vfio_ap device driver's group notification handler will get called at which time the device driver will configure the the AP devices to which the guest will be granted access.

---
  MAINTAINERS                       |   1 +
  default-configs/s390x-softmmu.mak |   1 +
  hw/vfio/Makefile.objs             |   1 +
  hw/vfio/ap.c                      | 180 ++++++++++++++++++++++++++++++
  include/hw/vfio/vfio-common.h     |   1 +
  5 files changed, 184 insertions(+)

create mode 100644 hw/vfio/ap.c

MAINTAINERS +1 -0
index 97e8ed808bc0..29041da69237 100644
@@ -1209,6 +1209,7 @@ F: hw/s390x/ap-device.c
  F: hw/s390x/ap-bridge.c
  F: include/hw/s390x/ap-device.h
  F: include/hw/s390x/ap-bridge.h
+F: hw/vfio/ap.c
  L: [email protected]
 
  vhost
default-configs/s390x-softmmu.mak +1 -0
index d6b67d50f0e4..5eef37592451 100644
@@ -7,3 +7,4 @@ CONFIG_S390_FLIC=y
  CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
  CONFIG_VFIO_CCW=$(CONFIG_LINUX)
  CONFIG_WDT_DIAG288=y
+CONFIG_VFIO_AP=$(CONFIG_LINUX)
hw/vfio/Makefile.objs +1 -0
index a2e7a0a7cf02..8b3f664d85f7 100644
@@ -6,4 +6,5 @@ obj-$(CONFIG_SOFTMMU) += platform.o
  obj-$(CONFIG_VFIO_XGMAC) += calxeda-xgmac.o
  obj-$(CONFIG_VFIO_AMD_XGBE) += amd-xgbe.o
  obj-$(CONFIG_SOFTMMU) += spapr.o
+obj-$(CONFIG_VFIO_AP) += ap.o
  endif
hw/vfio/ap.c new file +57 -0
new file mode 100644
index 000000000000..5543406afc58
@@ -0,0 +1,180 @@
+/*
+ * VFIO based AP matrix device assignment
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *            Halil Pasic <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include <linux/vfio.h>
+#include <sys/ioctl.h>
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "hw/vfio/vfio.h"
+#include "hw/vfio/vfio-common.h"
+#include "hw/s390x/ap-device.h"
+#include "qemu/error-report.h"
+#include "qemu/queue.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "cpu.h"
+#include "kvm_s390x.h"
+#include "sysemu/sysemu.h"
+#include "hw/s390x/ap-bridge.h"
+#include "exec/address-spaces.h"
+
+#define VFIO_AP_DEVICE_TYPE      "vfio-ap"
+
+typedef struct VFIOAPDevice {
+    APDevice apdev;
+    VFIODevice vdev;
+} VFIOAPDevice;
+
+#define VFIO_AP_DEVICE(obj) \
+        OBJECT_CHECK(VFIOAPDevice, (obj), VFIO_AP_DEVICE_TYPE)
+
+static void vfio_ap_compute_needs_reset(VFIODevice *vdev)
+{
+    vdev->needs_reset = false;
+}
+
+/*
+ * We don't need vfio_hot_reset_multi and vfio_eoi operations for
+ * vfio-ap device now.
+ */
+struct VFIODeviceOps vfio_ap_ops = {
+    .vfio_compute_needs_reset = vfio_ap_compute_needs_reset,
+};
+
+static void vfio_ap_put_device(VFIOAPDevice *vapdev)
+{
+    g_free(vapdev->vdev.name);
+    vfio_put_base_device(&vapdev->vdev);

hw/vfio/ap.c line 67

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+}
+
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);

hum I oversaw this, it leads to segfault.

You must initialize gerror before use.
The following patch avoid a segmentation fault:

hw/vfio/ap.c +1 -1
index 5543406afc..3b8e9ba6dc 100644
@@ -59,7 +59,7 @@ static void vfio_ap_put_device(VFIOAPDevice *vapdev)
 
 static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
 {
-    GError *gerror;
+    GError *gerror = NULL;
     char *symlink, *group_path;
     int groupid;
 

Regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
Tested-by on v10 5/6
#35 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

In reply to Tony Krowiak
Quoted 132 lines · Tony Krowiak

Introduces a VFIO based AP device. The device is defined via the QEMU command line by specifying:

-device vfio-ap,sysfsdev=<path-to-mediated-matrix-device>

There may be only one vfio-ap device configured for a guest.

The mediated matrix device is created by the VFIO AP device driver by writing a UUID to a sysfs attribute file (see docs/vfio-ap.txt). The mediated matrix device will be named after the UUID. Symbolic links to the $uuid are created in many places, so the path to the mediated matrix device $uuid can be specified in any of the following ways:

/sys/devices/vfio_ap/matrix/$uuid /sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid /sys/bus/mdev/devices/$uuid
/sys/bus/mdev/drivers/vfio_mdev/$uuid

When the vfio-ap device is realized, it acquires and opens the VFIO iommu group to which the mediated matrix device is bound. This causes a VFIO group notification event to be signaled. The vfio_ap device driver's group notification handler will get called at which time the device driver will configure the the AP devices to which the guest will be granted access.

---
  MAINTAINERS                       |   1 +
  default-configs/s390x-softmmu.mak |   1 +
  hw/vfio/Makefile.objs             |   1 +
  hw/vfio/ap.c                      | 180 ++++++++++++++++++++++++++++++
  include/hw/vfio/vfio-common.h     |   1 +
  5 files changed, 184 insertions(+)

create mode 100644 hw/vfio/ap.c

MAINTAINERS +1 -0
index 97e8ed808bc0..29041da69237 100644
@@ -1209,6 +1209,7 @@ F: hw/s390x/ap-device.c
  F: hw/s390x/ap-bridge.c
  F: include/hw/s390x/ap-device.h
  F: include/hw/s390x/ap-bridge.h
+F: hw/vfio/ap.c
  L: [email protected]
 
  vhost
default-configs/s390x-softmmu.mak +1 -0
index d6b67d50f0e4..5eef37592451 100644
@@ -7,3 +7,4 @@ CONFIG_S390_FLIC=y
  CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
  CONFIG_VFIO_CCW=$(CONFIG_LINUX)
  CONFIG_WDT_DIAG288=y
+CONFIG_VFIO_AP=$(CONFIG_LINUX)
hw/vfio/Makefile.objs +1 -0
index a2e7a0a7cf02..8b3f664d85f7 100644
@@ -6,4 +6,5 @@ obj-$(CONFIG_SOFTMMU) += platform.o
  obj-$(CONFIG_VFIO_XGMAC) += calxeda-xgmac.o
  obj-$(CONFIG_VFIO_AMD_XGBE) += amd-xgbe.o
  obj-$(CONFIG_SOFTMMU) += spapr.o
+obj-$(CONFIG_VFIO_AP) += ap.o
  endif
hw/vfio/ap.c new file +57 -0
new file mode 100644
index 000000000000..5543406afc58
@@ -0,0 +1,180 @@
+/*
+ * VFIO based AP matrix device assignment
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak <[email protected]>
+ *            Halil Pasic <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include <linux/vfio.h>
+#include <sys/ioctl.h>
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "hw/vfio/vfio.h"
+#include "hw/vfio/vfio-common.h"
+#include "hw/s390x/ap-device.h"
+#include "qemu/error-report.h"
+#include "qemu/queue.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "cpu.h"
+#include "kvm_s390x.h"
+#include "sysemu/sysemu.h"
+#include "hw/s390x/ap-bridge.h"
+#include "exec/address-spaces.h"
+
+#define VFIO_AP_DEVICE_TYPE      "vfio-ap"
+
+typedef struct VFIOAPDevice {
+    APDevice apdev;
+    VFIODevice vdev;
+} VFIOAPDevice;
+
+#define VFIO_AP_DEVICE(obj) \
+        OBJECT_CHECK(VFIOAPDevice, (obj), VFIO_AP_DEVICE_TYPE)
+
+static void vfio_ap_compute_needs_reset(VFIODevice *vdev)
+{
+    vdev->needs_reset = false;
+}
+
+/*
+ * We don't need vfio_hot_reset_multi and vfio_eoi operations for
+ * vfio-ap device now.
+ */
+struct VFIODeviceOps vfio_ap_ops = {
+    .vfio_compute_needs_reset = vfio_ap_compute_needs_reset,
+};
+
+static void vfio_ap_put_device(VFIOAPDevice *vapdev)
+{
+    g_free(vapdev->vdev.name);
+    vfio_put_base_device(&vapdev->vdev);

hw/vfio/ap.c line 67

Quoted 10 lines
hw/vfio/ap.c new file +10 -0
+}
+
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);

hum I oversaw this change, it leads to segfault.

You must initialize gerror before use.
The following patch avoid a segmentation fault:

hw/vfio/ap.c +1 -1
index 5543406afc..3b8e9ba6dc 100644
@@ -59,7 +59,7 @@ static void vfio_ap_put_device(VFIOAPDevice *vapdev)
 
 static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
 {
-    GError *gerror;
+    GError *gerror = NULL;
     char *symlink, *group_path;
     int groupid;
 

Regards,
Pierre

With this:

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

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 13 lines · Pierre Morel

Review

Quoted 8 lines · Tony Krowiak
(quoted diff) +8 -0
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);

hum I oversaw this change, it leads to segfault.

Yes, this was a review feedback from v9 to use the glib function.

Quoted 10 lines

You must initialize gerror before use.
The following patch avoid a segmentation fault:

hw/vfio/ap.c +0 -0
index 5543406afc..3b8e9ba6dc 100644

hw/vfio/ap.c static void vfio_ap_put_device(VFIOAPDevice *vapdev) · line 64

Quoted 7 lines
hw/vfio/ap.c +1 -1
@@ -59,7 +59,7 @@ static void vfio_ap_put_device(VFIOAPDevice *vapdev)
 
  static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
  {
-    GError *gerror;
+    GError *gerror = NULL;
      char *symlink, *group_path;
      int groupid;

With that fix, series

Tony, can you fold that fixup from Pierre into your v11?

#37 lore raw

Re: [Qemu-devel] [PATCH v10 5/6] s390x/vfio: ap: Introduce VFIO AP device

Quoted 37 lines · Christian Borntraeger
Quoted 13 lines · Pierre Morel

Review

Quoted 8 lines · Tony Krowiak
(quoted diff) +8 -0
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+    GError *gerror;
+    char *symlink, *group_path;
+    int groupid;
+
+    symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+    group_path = g_file_read_link(symlink, &gerror);

hum I oversaw this change, it leads to segfault.

Yes, this was a review feedback from v9 to use the glib function.

Quoted 10 lines

You must initialize gerror before use.
The following patch avoid a segmentation fault:

hw/vfio/ap.c +0 -0
index 5543406afc..3b8e9ba6dc 100644

hw/vfio/ap.c static void vfio_ap_put_device(VFIOAPDevice *vapdev) · line 64

Quoted 7 lines
hw/vfio/ap.c +1 -1
@@ -59,7 +59,7 @@ static void vfio_ap_put_device(VFIOAPDevice *vapdev)
 
  static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
  {
-    GError *gerror;
+    GError *gerror = NULL;
      char *symlink, *group_path;
      int groupid;

With that fix, series

Quoted 3 lines

Tony, can you fold that fixup from Pierre into your v11?

It is done.

Quoted 1 line
#38 lore raw

PATCH v10 6/6 s390: doc: detailed specifications for AP virtualization

In reply to Tony Krowiak

This patch provides documentation describing the AP architecture and design concepts behind the virtualization of AP devices. It also includes an example of how to configure AP devices for exclusive use of KVM guests.

---
 MAINTAINERS      |   1 +
 docs/vfio-ap.txt | 825 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 826 insertions(+)
 create mode 100644 docs/vfio-ap.txt
MAINTAINERS +1 -0
index 29041da69237..b64a12034c2c 100644
@@ -1210,6 +1210,7 @@ F: hw/s390x/ap-bridge.c
 F: include/hw/s390x/ap-device.h
 F: include/hw/s390x/ap-bridge.h
 F: hw/vfio/ap.c
+F: docs/vfio-ap.txt
 L: [email protected]
 
 vhost
docs/vfio-ap.txt new file +825 -0

825 lines not on this page · raw message

Signature · 1 line
2.19.0.221.g150f307
#39 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 6/6] s390: doc: detailed specifications for AP virtualization

Quoted 13 lines · Tony Krowiak

This patch provides documentation describing the AP architecture and design concepts behind the virtualization of AP devices. It also includes an example of how to configure AP devices for exclusive use of KVM guests.

---
 MAINTAINERS      |   1 +
 docs/vfio-ap.txt | 825 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 826 insertions(+)
 create mode 100644 docs/vfio-ap.txt

[...]

docs/vfio-ap.txt line 258

Quoted 5 lines
docs/vfio-ap.txt new file +5 -0
+      * Individual bits in the mask can be switched on and off by specifying
+        each bit number to be switched in a comma separated list. Each bit
+        number string must be prepended with a ('+') or minus ('-') to indicate
+        the corresponding bit is to be switched on ('+') or off ('-'). Some
+        valid values are: 

Nit: My git complains about a superfluous white space after "are:"

[...]

docs/vfio-ap.txt line 356

Quoted 7 lines
docs/vfio-ap.txt new file +7 -0
+assign_adapter
+   To assign an AP adapter to the mediated matrix device, its APID is written
+   to the 'assign_adapter' file. This may be done multiple times to assign more
+   than one adapter. The APID may be specified using conventional semantics
+   as a decimal, hexidecimal, or octal number. For example, to assign adapters
+   4, 5 and 16 to a mediated matrix device in decimal, hexidecimal and octal
+   respectively:

In case you respin: I'd still prefer s/hexidecimal/hexadecimal/g in the whole document (but it's just a nit, so no need to respin just because of this)

Thomas

#40 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH v10 6/6] s390: doc: detailed specifications for AP virtualization

Quoted 14 lines · Thomas Huth
Quoted 5 lines · Tony Krowiak

This patch provides documentation describing the AP architecture and design concepts behind the virtualization of AP devices. It also includes an example of how to configure AP devices for exclusive use of KVM guests.

Quoted 8 lines
---
  MAINTAINERS      |   1 +
  docs/vfio-ap.txt | 825 +++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 826 insertions(+)

create mode 100644 docs/vfio-ap.txt

Quoted 8 lines

[...]

docs/vfio-ap.txt line 258

Quoted 5 lines
docs/vfio-ap.txt new file +5 -0
+      * Individual bits in the mask can be switched on and off by specifying
+        each bit number to be switched in a comma separated list. Each bit
+        number string must be prepended with a ('+') or minus ('-') to indicate
+        the corresponding bit is to be switched on ('+') or off ('-'). Some
+        valid values are:

Nit: My git complains about a superfluous white space after "are:"

I ran checkpatch and my git did not complain, but I'll make sure there are no whitespaces at the end of the lines.

Quoted 10 lines

[...]

docs/vfio-ap.txt line 356

Quoted 7 lines
docs/vfio-ap.txt new file +7 -0
+assign_adapter
+   To assign an AP adapter to the mediated matrix device, its APID is written
+   to the 'assign_adapter' file. This may be done multiple times to assign more
+   than one adapter. The APID may be specified using conventional semantics
+   as a decimal, hexidecimal, or octal number. For example, to assign adapters
+   4, 5 and 16 to a mediated matrix device in decimal, hexidecimal and octal
+   respectively:
Quoted 3 lines

In case you respin: I'd still prefer s/hexidecimal/hexadecimal/g in the whole document (but it's just a nit, so no need to respin just because of this)

I will be submitting a v11, so I'll go ahead and fix this.

Quoted 3 lines

Thomas

#41 lore raw

Re: [Qemu-devel] [PATCH v10 6/6] s390: doc: detailed specifications for AP virtualization

In reply to Tony Krowiak

MAINTAINERS F: hw/s390x/ap-bridge.c · line 1216

Quoted 12 lines · On Tue, 9 Oct 2018 13:52:26 -0400 Tony Krowiak <[email protected]>…
MAINTAINERS +1 -0
index 29041da69237..b64a12034c2c 100644
@@ -1210,6 +1210,7 @@ F: hw/s390x/ap-bridge.c
 F: include/hw/s390x/ap-device.h
 F: include/hw/s390x/ap-bridge.h
 F: hw/vfio/ap.c
+F: docs/vfio-ap.txt
 L: [email protected]
 
 vhost

Same here. This should go into the overall s390 section as well.