Skip to contentSkip to conversation

Refactoring of AIS support

RFC PATCH In review Pierre Morel 5 participants 37 messages Oct 4, 2017 – Nov 6, 2017

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

cover Refactoring of AIS support

Currently AIS support has several problems:

- AIS support in KVM is reported if KVM has AIS capability.
- Testing if KVM FLIC attributes for AIS are supported does not take into account if AIS is supported by KVM.
- KVM report supporting the AIS FLIC features but denies their usage if the host kernel does not support the AIS feature.
- Testing if the Adapter interrupt must be suppressed is done looking at the ISC and ignores the adapter properties.
- Emulation of PCI devices can only be done with KVM support for AIS.
- Migration of emulated devices can only be done if both side support AIS in KVM

I would like to make some modifications to the code where I think things are not handled at the right place.

Therefor I propose these changes.
- Use the CPU model to enable AIS in the guest, even without KVM backup
- Ask KVM for AIS support in kvm_flic realize
- add simm/nimm attributes to the KVM FLIC interface to support emulation and migration between hosts with and without AIS support in KVM.
- Modify the zPCI VFIO realize function to refuse VFIO PCI devices without AIS support in KVM.
- Modify the AIS migration to support emulation and heterogeneous hosts.

Pierre Morel (5):
s390x/kvm: Enable AIS from CPU model always
s390x/css: Use AIS AIRQ injection only if adapter support AIS s390x/intc: Emulate Adapter Interrupt Suppression s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported s390x/intc: AIS is now always migratable

 hw/intc/s390_flic.c     |  3 +-
 hw/intc/s390_flic_kvm.c | 94 ++++++++++++++++++++++++++++++++++++++-----------
 hw/s390x/css.c          |  6 ++--
 hw/s390x/s390-pci-bus.c | 12 +++++++
 target/s390x/kvm.c      |  1 +
 5 files changed, 91 insertions(+), 25 deletions(-)
Signature · 1 line
2.3.0
#4 lore raw

PATCH 2/5 s390x/css: Use AIS AIRQ injection only if adapter support AIS

Testing to use Adapter Interrupt suppression or not depend on AIS being enabled in the kernel.
To implement AIS emulation we must move this test inside the FLIC dedicated irq_inject function.

Furthermore, a test to verify that the adapter is subject to the AIS must be added.

Last, there is no need to crash QEMU if the injection failed, the guest may recover from it.

---
 hw/s390x/css.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/s390x/css.c +4 -2
index 901dc6a..6e74a5c 100644
@@ -672,10 +672,12 @@ void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
     }
 
     trace_css_adapter_interrupt(isc);
-    if (fs->ais_supported) {
+    /* Use standard IRQ injection for adapters not supporting AIS */
+    if (adapter->flags & S390_ADAPTER_SUPPRESSIBLE) {
+        /* Use AIRQ injection for adapters subject to AIS */
         if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
             error_report("Failed to inject airq with AIS supported");
-            exit(1);
+            /* Report error - guest will handle not receiving interrupts */
         }
     } else {
         s390_io_interrupt(0, 0, 0, io_int_word);
Signature · 1 line
2.3.0
#12 lore raw

PATCH 4/5 s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

In reply to Pierre Morel

In S390x the Adapter Interrupt Suppression facility is used to mask interrupts of other PCI devices during interruption handling.

VFIO PCI allows the interrupts to be delivered rapidely through KVM via IRQfd or to be delivered through QEMU.
The choice is made through the x-kvm-intx and x-kvo-misx properties of the VFIO PCI device.

If the VFIO PCI device is using the direct KVM access through IRQfd and we know that KVM does not implement AIS support we refuse to realize the VFIO PCI device.

In all other cases, emulation and VFIO PCI sending interrupts through QEMU, we intercept the propagated IRQ, and protect it with the QEMU AIS implementation before to send it to the guest through KVM.

---
 hw/s390x/s390-pci-bus.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/s390x/s390-pci-bus.c +12 -0
index d9c294a..4afe49b 100644
@@ -21,18 +21,21 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/pci/msi.h"
+#include "hw/vfio/pci.h"
 #include "qemu/error-report.h"
 
 #ifndef DEBUG_S390PCI_BUS
 #define DEBUG_S390PCI_BUS  0
 #endif
 
+#ifndef DPRINTF
 #define DPRINTF(fmt, ...)                                         \
     do {                                                          \
         if (DEBUG_S390PCI_BUS) {                                  \
             fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
         }                                                         \
     } while (0)
+#endif
 
 S390pciState *s390_get_phb(void)
 {
@@ -751,6 +754,15 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
         }
 
         if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+            S390FLICState *fs = s390_get_flic();
+            VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
+
+            if ((!vdev->no_kvm_msix || !vdev->no_kvm_msix) &&
+                (!fs || !fs->ais_supported)) {
+                error_setg(errp, "VFIO PCI is not supported "
+                           "because kernel has no AIS capability.");
+                return;
+            }
             pbdev->fh |= FH_SHM_VFIO;
         } else {
             pbdev->fh |= FH_SHM_EMUL;
Signature · 1 line
2.3.0
#7 lore raw

PATCH 3/5 s390x/intc: Emulate Adapter Interrupt Suppression

In reply to Pierre Morel

Emulate the Adapter Interrupt Suppression in the KVM FLIC interface when the kernel does not support AIS.

When the kernel KVM does not support AIS, we can not support VFIO PCI devices but we still can support emulated devices if we emulate AIS inside QEMU.
Let's emulate AIS, allowing to use emulated PCI devices without KVM AIS support.

---
 hw/intc/s390_flic.c     |  3 +-
 hw/intc/s390_flic_kvm.c | 76 ++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 64 insertions(+), 15 deletions(-)
hw/intc/s390_flic.c +1 -2
index 6eaf178..33a7cde 100644
@@ -185,8 +185,7 @@ static void s390_flic_common_realize(DeviceState *dev, Error **errp)
                    " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
         return;
     }
-
-    fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION);
+    fs->ais_supported = false;
 }
 
 static void s390_flic_class_init(ObjectClass *oc, void *data)
hw/intc/s390_flic_kvm.c +63 -13

111 lines not on this page · raw message

Signature · 1 line
2.3.0
#1 lore raw

PATCH 1/5 s390x/kvm: Enable AIS from CPU model always

In reply to Pierre Morel

As this patchset will introduce AIS emulation, we always enable Adapter Interrupt Suppression, depending only from the CPU model.

---
 target/s390x/kvm.c | 1 +
 1 file changed, 1 insertion(+)
target/s390x/kvm.c +1 -0
index 931b85f..06fe56d 100644
@@ -2807,6 +2807,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
     if (pci_available) {
         set_bit(S390_FEAT_ZPCI, model->features);
     }
+    set_bit(S390_FEAT_ADAPTER_INT_SUPPRESSION, model->features);
     set_bit(S390_FEAT_ADAPTER_EVENT_NOTIFICATION, model->features);
 
     if (s390_known_cpu_type(cpu_type)) {
Signature · 1 line
2.3.0
#23 lore raw

PATCH 5/5 s390x/intc: AIS is now always migratable

In reply to Pierre Morel

Adapter Interrupt Suppression can now be emulated if the host kernel does not support the FLIC AIS attributes in KVM.

It follows it can always be migrated.

In the case AIS is supported by the kernel at one side of the migration

1) SRC and DST AIS in KVM
All PCI devices can be created on SRC and DST
All PCI devices can migrate

2) SRC and DST AIS NOT in KVM
Only emulated PCI devices can be used on SRC and DST Only emulated PCI devices can migrate

3) SRC AIS in KVM DST has NOT AIS in KVM
Only emulated PCI devices can migrate
Only emulated PCI devices can be created on SRC and DST VFIO PCI devices can be used only on SRC

4) SRC has NOT AIS in KVM DST AIS in KVM
Only emulated PCI devices can migrate
Only emulated PCI devices can be created on SRC and DST VFIO PCI devices can be used only on DST

---
 hw/intc/s390_flic_kvm.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
hw/intc/s390_flic_kvm.c +10 -8
index fd1aa22..6f44b1d 100644
@@ -457,6 +457,12 @@ static void kvm_flic_ais_pre_save(void *opaque)
         .attr = sizeof(ais),
     };
 
+    if (!flic->parent_obj.ais_supported) {
+        tmp->simm = flic->simm;
+        tmp->nimm = flic->nimm;
+        return;
+    }
+
     if (ioctl(flic->fd, KVM_GET_DEVICE_ATTR, &attr)) {
         error_report("Failed to retrieve kvm flic ais states");
         return;
@@ -479,14 +485,10 @@ static int kvm_flic_ais_post_load(void *opaque, int version_id)
         .addr = (uint64_t)&ais,
     };
 
-    /* This can happen when the user mis-configures its guests in an
-     * incompatible fashion or without a CPU model. For example using
-     * qemu with -cpu host (which is not migration safe) and do a
-     * migration from a host that has AIS to a host that has no AIS.
-     * In that case the target system will reject the migration here.
-     */
-    if (!ais_needed(flic)) {
-        return -ENOSYS;
+    if (!flic->parent_obj.ais_supported) {
+        flic->simm = tmp->simm;
+        flic->nimm = tmp->nimm;
+        return 0;
     }
 
     return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
Signature · 1 line
2.3.0
#5 lore raw

Re: [Qemu-devel] [PATCH v1 2/5] s390x/css: Use AIS AIRQ injection only if adapter support AIS

In reply to Pierre Morel
Quoted 21 lines · On Wed, 4 Oct 2017 15:49:36 +0200 Pierre Morel <[email protected]>…

Testing to use Adapter Interrupt suppression or not depend on AIS being enabled in the kernel.
To implement AIS emulation we must move this test inside the FLIC dedicated irq_inject function.

Furthermore, a test to verify that the adapter is subject to the AIS must be added.

Last, there is no need to crash QEMU if the injection failed, the guest may recover from it.

---
 hw/s390x/css.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/s390x/css.c +0 -0
index 901dc6a..6e74a5c 100644

hw/s390x/css.c void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc) · line 675

Quoted 5 lines
hw/s390x/css.c +1 -1
@@ -672,10 +672,12 @@ void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
     }
 
     trace_css_adapter_interrupt(isc);
-    if (fs->ais_supported) {
+    /* Use standard IRQ injection for adapters not supporting AIS */

I'd move that comment to the else branch.

hw/s390x/css.c void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc) · line 680

Quoted 6 lines
hw/s390x/css.c +3 -1
+    if (adapter->flags & S390_ADAPTER_SUPPRESSIBLE) {
+        /* Use AIRQ injection for adapters subject to AIS */
         if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
             error_report("Failed to inject airq with AIS supported");
-            exit(1);
+            /* Report error - guest will handle not receiving interrupts */

I'm not 100% sure that this is the right thing to do. I have always operated under the assumption "if the hardware (host) accepts the I/O, it owes you an interrupt". (Don't the other failed interrupt injection paths do a hard stop as well? Is there any reasonable way for an injection failure to be transient?)

Quoted 3 lines
hw/s390x/css.c +0 -0
         }
     } else {
         s390_io_interrupt(0, 0, 0, io_int_word);
#8 lore raw

Re: [Qemu-devel] [PATCH v1 3/5] s390x/intc: Emulate Adapter Interrupt Suppression

In reply to Pierre Morel
Quoted 34 lines · On Wed, 4 Oct 2017 15:49:37 +0200 Pierre Morel <[email protected]>…

Emulate the Adapter Interrupt Suppression in the KVM FLIC interface when the kernel does not support AIS.

When the kernel KVM does not support AIS, we can not support VFIO PCI devices but we still can support emulated devices if we emulate AIS inside QEMU.
Let's emulate AIS, allowing to use emulated PCI devices without KVM AIS support.

---
 hw/intc/s390_flic.c     |  3 +-
 hw/intc/s390_flic_kvm.c | 76 ++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 64 insertions(+), 15 deletions(-)
hw/intc/s390_flic.c +1 -2
index 6eaf178..33a7cde 100644
@@ -185,8 +185,7 @@ static void s390_flic_common_realize(DeviceState *dev, Error **errp)
                    " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
         return;
     }
-
-    fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION);
+    fs->ais_supported = false;
 }
 
 static void s390_flic_class_init(ObjectClass *oc, void *data)
hw/intc/s390_flic_kvm.c +0 -0
index 7ead17a..fd1aa22 100644

hw/intc/s390_flic_kvm.c typedef struct KVMS390FLICState { · line 38

Quoted 6 lines
hw/intc/s390_flic_kvm.c +2 -0
@@ -33,6 +33,8 @@ typedef struct KVMS390FLICState {
 
     uint32_t fd;
     bool clear_io_supported;
+    uint8_t simm;
+    uint8_t nimm;
 } KVMS390FLICState;

Instead of duplicating this, move simm/nimm into the common flic state?

Quoted 16 lines
hw/intc/s390_flic_kvm.c +5 -3
 DeviceState *s390_flic_kvm_create(void)
@@ -164,11 +166,24 @@ static int kvm_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
         .addr = (uint64_t)&req,
     };
 
-    if (!fs->ais_supported) {
-        return -ENOSYS;
+    if (fs->ais_supported) {
+        return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
     }
 
-    return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
+    /* Kernel does not support AIS, emulate it here */
+    switch (mode) {
+    case SIC_IRQ_MODE_ALL:

hw/intc/s390_flic_kvm.c static int kvm_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc, · line 185

Quoted 10 lines
hw/intc/s390_flic_kvm.c +10 -0
+        flic->simm &= ~AIS_MODE_MASK(isc);
+        flic->nimm &= ~AIS_MODE_MASK(isc);
+        break;
+    case SIC_IRQ_MODE_SINGLE:
+        flic->simm |= AIS_MODE_MASK(isc);
+        flic->nimm &= ~AIS_MODE_MASK(isc);
+        break;
+    default:
+        return -EINVAL;
+    }

That's just the same as for the qemu flic. What about creating a wrapper (to be called from css.c) in the common flic code that calls a specific callback (only needed for kvm) and falls back to emulating if it was not successful?

Quoted 17 lines
hw/intc/s390_flic_kvm.c +4 -3
+    return 0;
 }
 
 static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type,
@@ -180,12 +195,23 @@ static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type,
         .group = KVM_DEV_FLIC_AIRQ_INJECT,
         .attr = id,
     };
+    uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
 
-    if (!fs->ais_supported) {
-        return -ENOSYS;
+    if (fs->ais_supported) {
+        return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
     }
 
-    return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;

hw/intc/s390_flic_kvm.c static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type, · line 213

Quoted 10 lines
hw/intc/s390_flic_kvm.c +10 -0
+    /* Kernel does not support AIS, emulate it here */
+    if (flags && (flic->nimm & AIS_MODE_MASK(isc))) {
+        return 0;
+    }
+
+    s390_io_interrupt(0, 0, 0, io_int_word);
+
+    if (flags && (flic->simm & AIS_MODE_MASK(isc))) {
+        flic->nimm |= AIS_MODE_MASK(isc);
+    }

Same here: I think doing this in the generic flic would make sense.

Quoted 12 lines
hw/intc/s390_flic_kvm.c +5 -0
+    return 0;
 }
 
 /**
@@ -557,6 +583,32 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
     test_attr.group = KVM_DEV_FLIC_CLEAR_IO_IRQ;
     flic_state->clear_io_supported = !ioctl(flic_state->fd,
                                             KVM_HAS_DEVICE_ATTR, test_attr);
+    /* To support ais we need all these three FLIC attributes */
+    test_attr.group = KVM_DEV_FLIC_AISM;
+    ret = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr);
+    flic_state->parent_obj.ais_supported &= ret;

hw/intc/s390_flic_kvm.c static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) · line 599

Quoted 10 lines
hw/intc/s390_flic_kvm.c +10 -0
+
+    test_attr.group = KVM_DEV_FLIC_AIRQ_INJECT;
+    ret = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr);
+    flic_state->parent_obj.ais_supported &= ret;
+
+    test_attr.group = KVM_DEV_FLIC_AISM_ALL;
+    ret &= !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr);
+    flic_state->parent_obj.ais_supported &= ret;
+
+    /* For buggy kernels we need to really test that the attribute is supported */

Ugh.

Quoted 34 lines
hw/intc/s390_flic_kvm.c +17 -7
+    {
+        struct kvm_s390_ais_req req = {
+            .mode = SIC_IRQ_MODE_ALL,
+        };
+        struct kvm_device_attr attr = {
+            .group = KVM_DEV_FLIC_AISM,
+            .addr = (uint64_t)&req,
+        };
+        ret = !ioctl(flic_state->fd, KVM_SET_DEVICE_ATTR, &attr);
+    }
+    flic_state->parent_obj.ais_supported &= ret;
+
     return;
 fail:
     error_propagate(errp, errp_local);
@@ -578,13 +630,11 @@ static void kvm_s390_flic_reset(DeviceState *dev)
 
     flic_disable_wait_pfault(flic);
 
-    if (fs->ais_supported) {
-        for (isc = 0; isc <= MAX_ISC; isc++) {
-            rc = kvm_s390_modify_ais_mode(fs, isc, SIC_IRQ_MODE_ALL);
-            if (rc) {
-                error_report("Failed to reset ais mode for isc %d: %s",
-                             isc, strerror(-rc));
-            }
+    for (isc = 0; isc <= MAX_ISC; isc++) {
+        rc = kvm_s390_modify_ais_mode(fs, isc, SIC_IRQ_MODE_ALL);
+        if (rc) {
+            error_report("Failed to reset ais mode for isc %d: %s",
+                         isc, strerror(-rc));
         }
     }
 
#13 lore raw

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

In reply to Pierre Morel

On Wed, 4 Oct 2017 15:49:38 +0200
Pierre Morel <[email protected]> wrote:

"not supported", surely?

Quoted 34 lines

In S390x the Adapter Interrupt Suppression facility is used to mask interrupts of other PCI devices during interruption handling.

VFIO PCI allows the interrupts to be delivered rapidely through KVM via IRQfd or to be delivered through QEMU.
The choice is made through the x-kvm-intx and x-kvo-misx properties of the VFIO PCI device.

If the VFIO PCI device is using the direct KVM access through IRQfd and we know that KVM does not implement AIS support we refuse to realize the VFIO PCI device.

In all other cases, emulation and VFIO PCI sending interrupts through QEMU, we intercept the propagated IRQ, and protect it with the QEMU AIS implementation before to send it to the guest through KVM.

---
 hw/s390x/s390-pci-bus.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/s390x/s390-pci-bus.c +1 -0
index d9c294a..4afe49b 100644
@@ -21,18 +21,21 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/pci/msi.h"
+#include "hw/vfio/pci.h"
 #include "qemu/error-report.h"
 
 #ifndef DEBUG_S390PCI_BUS
 #define DEBUG_S390PCI_BUS  0

hw/s390x/s390-pci-bus.c line 38

Quoted 10 lines
hw/s390x/s390-pci-bus.c +2 -0
 #endif
 
+#ifndef DPRINTF
 #define DPRINTF(fmt, ...)                                         \
     do {                                                          \
         if (DEBUG_S390PCI_BUS) {                                  \
             fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
         }                                                         \
     } while (0)
+#endif

Ugh. Is there DPRINTF redefinition going on?

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 760

Quoted 11 lines
hw/s390x/s390-pci-bus.c +4 -0
 S390pciState *s390_get_phb(void)
 {
@@ -751,6 +754,15 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
         }
 
         if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+            S390FLICState *fs = s390_get_flic();
+            VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
+
+            if ((!vdev->no_kvm_msix || !vdev->no_kvm_msix) &&

One of the no_kvm_msix should probably be something else :)

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 763

Quoted 3 lines
hw/s390x/s390-pci-bus.c +3 -0
+                (!fs || !fs->ais_supported)) {
+                error_setg(errp, "VFIO PCI is not supported "
+                           "because kernel has no AIS capability.");

I think failure is per-device (i.e., you would be able to plug a different vfio device if you turned off irqfd support for it); should that be reflected in the error message?

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 765

Quoted 2 lines
hw/s390x/s390-pci-bus.c +2 -0
+                return;
+            }

Would it make sense to fail plugging before we try to create a zpci device?

Quoted 3 lines
hw/s390x/s390-pci-bus.c +0 -0
             pbdev->fh |= FH_SHM_VFIO;
         } else {
             pbdev->fh |= FH_SHM_EMUL;
#9 lore raw

Re: [Qemu-devel] [PATCH v1 3/5] s390x/intc: Emulate Adapter Interrupt Suppression

In reply to Cornelia Huck
Quoted 38 lines · On Mon, 9 Oct 2017 10:42:44 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 35 lines · On Wed, 4 Oct 2017 15:49:37 +0200 Pierre Morel <[email protected]>…

Emulate the Adapter Interrupt Suppression in the KVM FLIC interface when the kernel does not support AIS.

When the kernel KVM does not support AIS, we can not support VFIO PCI devices but we still can support emulated devices if we emulate AIS inside QEMU.
Let's emulate AIS, allowing to use emulated PCI devices without KVM AIS support.

---
 hw/intc/s390_flic.c     |  3 +-
 hw/intc/s390_flic_kvm.c | 76 ++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 64 insertions(+), 15 deletions(-)
hw/intc/s390_flic.c +1 -2
index 6eaf178..33a7cde 100644
@@ -185,8 +185,7 @@ static void s390_flic_common_realize(DeviceState *dev, Error **errp)
                    " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
         return;
     }
-
-    fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION);
+    fs->ais_supported = false;
 }
 
 static void s390_flic_class_init(ObjectClass *oc, void *data)
hw/intc/s390_flic_kvm.c +0 -0
index 7ead17a..fd1aa22 100644
@@ -33,6 +33,8 @@ typedef struct KVMS390FLICState {
 
Quoted 7 lines

hw/intc/s390_flic_kvm.c typedef struct KVMS390FLICState { · line 38

Quoted 5 lines
hw/intc/s390_flic_kvm.c +2 -0
     uint32_t fd;
     bool clear_io_supported;
+    uint8_t simm;
+    uint8_t nimm;
 } KVMS390FLICState;  

Instead of duplicating this, move simm/nimm into the common flic state?

Also, simm/nimm need to be reset (done for the qemu flic, but not for the kvm flic). Doing that in common flic code would take care of that as well.

#2 lore raw

Re: [Qemu-devel] [PATCH v1 1/5] s390x/kvm: Enable AIS from CPU model always

In reply to Pierre Morel
Quoted 13 lines · On Wed, 4 Oct 2017 15:49:35 +0200 Pierre Morel <[email protected]>…

As this patchset will introduce AIS emulation, we always enable Adapter Interrupt Suppression, depending only from the CPU model.

---
 target/s390x/kvm.c | 1 +
 1 file changed, 1 insertion(+)
target/s390x/kvm.c +0 -0
index 931b85f..06fe56d 100644

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

Quoted 7 lines
target/s390x/kvm.c +1 -0
@@ -2807,6 +2807,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
     if (pci_available) {
         set_bit(S390_FEAT_ZPCI, model->features);
     }
+    set_bit(S390_FEAT_ADAPTER_INT_SUPPRESSION, model->features);
     set_bit(S390_FEAT_ADAPTER_EVENT_NOTIFICATION, model->features);
 
     if (s390_known_cpu_type(cpu_type)) {

I would move that patch until after emulation has actually been provided.

#6 lore raw

Re: [Qemu-devel] [PATCH v1 2/5] s390x/css: Use AIS AIRQ injection only if adapter support AIS

In reply to Cornelia Huck
Quoted 26 lines · Cornelia Huck
Quoted 23 lines · On Wed, 4 Oct 2017 15:49:36 +0200 Pierre Morel <[email protected]>…

Testing to use Adapter Interrupt suppression or not depend on AIS being enabled in the kernel.
To implement AIS emulation we must move this test inside the FLIC dedicated irq_inject function.

Furthermore, a test to verify that the adapter is subject to the AIS must be added.

Last, there is no need to crash QEMU if the injection failed, the guest may recover from it.

---
  hw/s390x/css.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
hw/s390x/css.c +0 -0
index 901dc6a..6e74a5c 100644
@@ -672,10 +672,12 @@ void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)
      }
 
Quoted 5 lines

hw/s390x/css.c void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc) · line 675

Quoted 3 lines
hw/s390x/css.c +1 -1
      trace_css_adapter_interrupt(isc);
-    if (fs->ais_supported) {
+    /* Use standard IRQ injection for adapters not supporting AIS */

I'd move that comment to the else branch.

yes, clear.

Quoted 8 lines

hw/s390x/css.c void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc) · line 680

Quoted 7 lines
hw/s390x/css.c +3 -1
+    if (adapter->flags & S390_ADAPTER_SUPPRESSIBLE) {
+        /* Use AIRQ injection for adapters subject to AIS */
          if (fsc->inject_airq(fs, type, isc, adapter->flags)) {
              error_report("Failed to inject airq with AIS supported");
-            exit(1);
+            /* Report error - guest will handle not receiving interrupts */
Quoted 5 lines

I'm not 100% sure that this is the right thing to do. I have always operated under the assumption "if the hardware (host) accepts the I/O, it owes you an interrupt". (Don't the other failed interrupt injection paths do a hard stop as well? Is there any reasonable way for an injection failure to be transient?)

You are right and it is out of scope.
So I will let this untouch.

Quoted 5 lines
Quoted 4 lines
hw/s390x/css.c +0 -0
          }
      } else {
          s390_io_interrupt(0, 0, 0, io_int_word);
Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#3 lore raw

Re: [Qemu-devel] [PATCH v1 1/5] s390x/kvm: Enable AIS from CPU model always

In reply to Cornelia Huck
Quoted 22 lines · Cornelia Huck
Quoted 19 lines · On Wed, 4 Oct 2017 15:49:35 +0200 Pierre Morel <[email protected]>…

As this patchset will introduce AIS emulation, we always enable Adapter Interrupt Suppression, depending only from the CPU model.

---
  target/s390x/kvm.c | 1 +
  1 file changed, 1 insertion(+)
target/s390x/kvm.c +1 -0
index 931b85f..06fe56d 100644
@@ -2807,6 +2807,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
      if (pci_available) {
          set_bit(S390_FEAT_ZPCI, model->features);
      }
+    set_bit(S390_FEAT_ADAPTER_INT_SUPPRESSION, model->features);
      set_bit(S390_FEAT_ADAPTER_EVENT_NOTIFICATION, model->features);
 
Quoted 5 lines

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

Quoted 1 line
target/s390x/kvm.c +0 -0
      if (s390_known_cpu_type(cpu_type)) {

I would move that patch until after emulation has actually been provided.

Yes, clear.

Thanks,
Pierre

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

Re: [Qemu-devel] [PATCH v1 3/5] s390x/intc: Emulate Adapter Interrupt Suppression

In reply to Cornelia Huck
Quoted 38 lines · Cornelia Huck
Quoted 35 lines · On Wed, 4 Oct 2017 15:49:37 +0200 Pierre Morel <[email protected]>…

Emulate the Adapter Interrupt Suppression in the KVM FLIC interface when the kernel does not support AIS.

When the kernel KVM does not support AIS, we can not support VFIO PCI devices but we still can support emulated devices if we emulate AIS inside QEMU.
Let's emulate AIS, allowing to use emulated PCI devices without KVM AIS support.

---
  hw/intc/s390_flic.c     |  3 +-
  hw/intc/s390_flic_kvm.c | 76 ++++++++++++++++++++++++++++++++++++++++---------
  2 files changed, 64 insertions(+), 15 deletions(-)
hw/intc/s390_flic.c +1 -2
index 6eaf178..33a7cde 100644
@@ -185,8 +185,7 @@ static void s390_flic_common_realize(DeviceState *dev, Error **errp)
                     " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
          return;
      }
-
-    fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION);
+    fs->ais_supported = false;
  }
 
  static void s390_flic_class_init(ObjectClass *oc, void *data)
hw/intc/s390_flic_kvm.c +0 -0
index 7ead17a..fd1aa22 100644
@@ -33,6 +33,8 @@ typedef struct KVMS390FLICState {
 
Quoted 7 lines

hw/intc/s390_flic_kvm.c typedef struct KVMS390FLICState { · line 38

Quoted 5 lines
hw/intc/s390_flic_kvm.c +2 -0
      uint32_t fd;
      bool clear_io_supported;
+    uint8_t simm;
+    uint8_t nimm;
  } KVMS390FLICState;

Instead of duplicating this, move simm/nimm into the common flic state?

OK.

Quoted 24 lines
Quoted 24 lines
hw/intc/s390_flic_kvm.c +12 -3
  DeviceState *s390_flic_kvm_create(void)
@@ -164,11 +166,24 @@ static int kvm_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
          .addr = (uint64_t)&req,
      };
 
-    if (!fs->ais_supported) {
-        return -ENOSYS;
+    if (fs->ais_supported) {
+        return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
      }
 
-    return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
+    /* Kernel does not support AIS, emulate it here */
+    switch (mode) {
+    case SIC_IRQ_MODE_ALL:
+        flic->simm &= ~AIS_MODE_MASK(isc);
+        flic->nimm &= ~AIS_MODE_MASK(isc);
+        break;
+    case SIC_IRQ_MODE_SINGLE:
+        flic->simm |= AIS_MODE_MASK(isc);
+        flic->nimm &= ~AIS_MODE_MASK(isc);
+        break;
Quoted 8 lines

hw/intc/s390_flic_kvm.c static int kvm_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc, · line 185

Quoted 3 lines
hw/intc/s390_flic_kvm.c +3 -0
+    default:
+        return -EINVAL;
+    }

That's just the same as for the qemu flic. What about creating a wrapper (to be called from css.c) in the common flic code that calls a specific callback (only needed for kvm) and falls back to emulating if it was not successful?

Yes, OK.

Quoted 17 lines
Quoted 17 lines
hw/intc/s390_flic_kvm.c +4 -2
+    return 0;
  }
 
  static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type,
@@ -180,12 +195,23 @@ static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type,
          .group = KVM_DEV_FLIC_AIRQ_INJECT,
          .attr = id,
      };
+    uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
 
-    if (!fs->ais_supported) {
-        return -ENOSYS;
+    if (fs->ais_supported) {
+        return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
      }
 
Quoted 13 lines

hw/intc/s390_flic_kvm.c static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type, · line 213

Quoted 11 lines
hw/intc/s390_flic_kvm.c +10 -1
-    return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0;
+    /* Kernel does not support AIS, emulate it here */
+    if (flags && (flic->nimm & AIS_MODE_MASK(isc))) {
+        return 0;
+    }
+
+    s390_io_interrupt(0, 0, 0, io_int_word);
+
+    if (flags && (flic->simm & AIS_MODE_MASK(isc))) {
+        flic->nimm |= AIS_MODE_MASK(isc);
+    }

Same here: I think doing this in the generic flic would make sense.

OK

Quoted 45 lines
Quoted 13 lines
hw/intc/s390_flic_kvm.c +5 -0
+    return 0;
  }
 
  /**
@@ -557,6 +583,32 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
      test_attr.group = KVM_DEV_FLIC_CLEAR_IO_IRQ;
      flic_state->clear_io_supported = !ioctl(flic_state->fd,
                                              KVM_HAS_DEVICE_ATTR, test_attr);
+    /* To support ais we need all these three FLIC attributes */
+    test_attr.group = KVM_DEV_FLIC_AISM;
+    ret = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr);
+    flic_state->parent_obj.ais_supported &= ret;

hw/intc/s390_flic_kvm.c static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) · line 599

Quoted 10 lines
hw/intc/s390_flic_kvm.c +10 -0
+
+    test_attr.group = KVM_DEV_FLIC_AIRQ_INJECT;
+    ret = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr);
+    flic_state->parent_obj.ais_supported &= ret;
+
+    test_attr.group = KVM_DEV_FLIC_AISM_ALL;
+    ret &= !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr);
+    flic_state->parent_obj.ais_supported &= ret;
+
+    /* For buggy kernels we need to really test that the attribute is supported */

Ugh.

Quoted 19 lines
hw/intc/s390_flic_kvm.c +12 -0
+    {
+        struct kvm_s390_ais_req req = {
+            .mode = SIC_IRQ_MODE_ALL,
+        };
+        struct kvm_device_attr attr = {
+            .group = KVM_DEV_FLIC_AISM,
+            .addr = (uint64_t)&req,
+        };
+        ret = !ioctl(flic_state->fd, KVM_SET_DEVICE_ATTR, &attr);
+    }
+    flic_state->parent_obj.ais_supported &= ret;
+
      return;
  fail:
      error_propagate(errp, errp_local);
@@ -578,13 +630,11 @@ static void kvm_s390_flic_reset(DeviceState *dev)
 
      flic_disable_wait_pfault(flic);
 
Quoted 17 lines
Quoted 5 lines
hw/intc/s390_flic_kvm.c +0 -5
-    if (fs->ais_supported) {
-        for (isc = 0; isc <= MAX_ISC; isc++) {
-            rc = kvm_s390_modify_ais_mode(fs, isc, SIC_IRQ_MODE_ALL);
-            if (rc) {
-                error_report("Failed to reset ais mode for isc %d: %s",

hw/intc/s390_flic_kvm.c static void kvm_s390_flic_reset(DeviceState *dev) · line 640

Quoted 10 lines
hw/intc/s390_flic_kvm.c +5 -2
-                             isc, strerror(-rc));
-            }
+    for (isc = 0; isc <= MAX_ISC; isc++) {
+        rc = kvm_s390_modify_ais_mode(fs, isc, SIC_IRQ_MODE_ALL);
+        if (rc) {
+            error_report("Failed to reset ais mode for isc %d: %s",
+                         isc, strerror(-rc));
          }
      }
 

OK, I promote the simm/nimm to the common flic state .

Thanks for review.
Pierre

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

Re: [Qemu-devel] [PATCH v1 3/5] s390x/intc: Emulate Adapter Interrupt Suppression

In reply to Cornelia Huck
Quoted 49 lines · Cornelia Huck
Quoted 38 lines · On Mon, 9 Oct 2017 10:42:44 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 35 lines · On Wed, 4 Oct 2017 15:49:37 +0200 Pierre Morel <[email protected]>…

Emulate the Adapter Interrupt Suppression in the KVM FLIC interface when the kernel does not support AIS.

When the kernel KVM does not support AIS, we can not support VFIO PCI devices but we still can support emulated devices if we emulate AIS inside QEMU.
Let's emulate AIS, allowing to use emulated PCI devices without KVM AIS support.

---
  hw/intc/s390_flic.c     |  3 +-
  hw/intc/s390_flic_kvm.c | 76 ++++++++++++++++++++++++++++++++++++++++---------
  2 files changed, 64 insertions(+), 15 deletions(-)
hw/intc/s390_flic.c +1 -2
index 6eaf178..33a7cde 100644
@@ -185,8 +185,7 @@ static void s390_flic_common_realize(DeviceState *dev, Error **errp)
                     " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
          return;
      }
-
-    fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION);
+    fs->ais_supported = false;
  }
 
  static void s390_flic_class_init(ObjectClass *oc, void *data)
hw/intc/s390_flic_kvm.c +0 -0
index 7ead17a..fd1aa22 100644
@@ -33,6 +33,8 @@ typedef struct KVMS390FLICState {
 
Quoted 7 lines

hw/intc/s390_flic_kvm.c typedef struct KVMS390FLICState { · line 38

Quoted 5 lines
hw/intc/s390_flic_kvm.c +2 -0
      uint32_t fd;
      bool clear_io_supported;
+    uint8_t simm;
+    uint8_t nimm;
  } KVMS390FLICState;

Instead of duplicating this, move simm/nimm into the common flic state?

Quoted 4 lines

Also, simm/nimm need to be reset (done for the qemu flic, but not for the kvm flic). Doing that in common flic code would take care of that as well.

right.
Thanks,

Pierre

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

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

In reply to Cornelia Huck
Quoted 4 lines · Cornelia Huck

On Wed, 4 Oct 2017 15:49:38 +0200
Pierre Morel <[email protected]> wrote:

"not supported", surely?

:)
yes, "not supported"

Quoted 37 lines
Quoted 37 lines

In S390x the Adapter Interrupt Suppression facility is used to mask interrupts of other PCI devices during interruption handling.

VFIO PCI allows the interrupts to be delivered rapidely through KVM via IRQfd or to be delivered through QEMU.
The choice is made through the x-kvm-intx and x-kvo-misx properties of the VFIO PCI device.

If the VFIO PCI device is using the direct KVM access through IRQfd and we know that KVM does not implement AIS support we refuse to realize the VFIO PCI device.

In all other cases, emulation and VFIO PCI sending interrupts through QEMU, we intercept the propagated IRQ, and protect it with the QEMU AIS implementation before to send it to the guest through KVM.

---
  hw/s390x/s390-pci-bus.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
hw/s390x/s390-pci-bus.c +1 -0
index d9c294a..4afe49b 100644
@@ -21,18 +21,21 @@
  #include "hw/pci/pci_bus.h"
  #include "hw/pci/pci_bridge.h"
  #include "hw/pci/msi.h"
+#include "hw/vfio/pci.h"
  #include "qemu/error-report.h"
 
  #ifndef DEBUG_S390PCI_BUS
  #define DEBUG_S390PCI_BUS  0
  #endif
 
Quoted 10 lines

hw/s390x/s390-pci-bus.c line 38

Quoted 8 lines
hw/s390x/s390-pci-bus.c +2 -0
+#ifndef DPRINTF
  #define DPRINTF(fmt, ...)                                         \
      do {                                                          \
          if (DEBUG_S390PCI_BUS) {                                  \
              fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
          }                                                         \
      } while (0)
+#endif

Ugh. Is there DPRINTF redefinition going on?

Yes in hw/vfio/vfio-common.h

But I think I better do an undef / def instead of a ifndef

#ifdef DPRINTF
#undef DPRINTF
#endif
#define DPRINTF(fmt, ...)
...

Quoted 7 lines
Quoted 7 lines
hw/s390x/s390-pci-bus.c +0 -0
  S390pciState *s390_get_phb(void)
  {
@@ -751,6 +754,15 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
          }
 
Quoted 7 lines

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 760

Quoted 5 lines
hw/s390x/s390-pci-bus.c +4 -0
          if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+            S390FLICState *fs = s390_get_flic();
+            VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
+
+            if ((!vdev->no_kvm_msix || !vdev->no_kvm_msix) &&

One of the no_kvm_msix should probably be something else :)

:) yes

Historicaly, it used to be a no_kvm_intx but since AIS only works with AEN intx has no reason to be here.

So the second no_kvm_msix must disappear.

Quoted 8 lines

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 763

Quoted 4 lines
hw/s390x/s390-pci-bus.c +3 -0
+                (!fs || !fs->ais_supported)) {
+                error_setg(errp, "VFIO PCI is not supported "
+                           "because kernel has no AIS capability.");

I think failure is per-device (i.e., you would be able to plug a different vfio device if you turned off irqfd support for it); should that be reflected in the error message?

OK, I will find something better.

Quoted 6 lines

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 765

Quoted 3 lines
hw/s390x/s390-pci-bus.c +2 -0
+                return;
+            }

Would it make sense to fail plugging before we try to create a zpci device?

clearly yes. I will put these test before the eventual zpci allocation.

Quoted 6 lines

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 768

Quoted 4 lines
hw/s390x/s390-pci-bus.c +0 -0
              pbdev->fh |= FH_SHM_VFIO;
          } else {
              pbdev->fh |= FH_SHM_EMUL;

Thanks,

Pierre

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

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

In reply to Pierre Morel
Quoted 34 lines · On Wed, 4 Oct 2017 15:49:38 +0200 Pierre Morel <[email protected]>…

In S390x the Adapter Interrupt Suppression facility is used to mask interrupts of other PCI devices during interruption handling.

VFIO PCI allows the interrupts to be delivered rapidely through KVM via IRQfd or to be delivered through QEMU.
The choice is made through the x-kvm-intx and x-kvo-misx properties of the VFIO PCI device.

If the VFIO PCI device is using the direct KVM access through IRQfd and we know that KVM does not implement AIS support we refuse to realize the VFIO PCI device.

In all other cases, emulation and VFIO PCI sending interrupts through QEMU, we intercept the propagated IRQ, and protect it with the QEMU AIS implementation before to send it to the guest through KVM.

---
 hw/s390x/s390-pci-bus.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/s390x/s390-pci-bus.c +1 -0
index d9c294a..4afe49b 100644
@@ -21,18 +21,21 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/pci/msi.h"
+#include "hw/vfio/pci.h"
 #include "qemu/error-report.h"
 
 #ifndef DEBUG_S390PCI_BUS
 #define DEBUG_S390PCI_BUS  0

hw/s390x/s390-pci-bus.c line 38

Quoted 10 lines
hw/s390x/s390-pci-bus.c +2 -0
 #endif
 
+#ifndef DPRINTF
 #define DPRINTF(fmt, ...)                                         \
     do {                                                          \
         if (DEBUG_S390PCI_BUS) {                                  \
             fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
         }                                                         \
     } while (0)
+#endif

Maybe a sign we shouldn't be including vfio/pci.h

Quoted 5 lines
hw/s390x/s390-pci-bus.c +0 -0
 S390pciState *s390_get_phb(void)
 {
@@ -751,6 +754,15 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
         }
 

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 765

Quoted 10 lines
hw/s390x/s390-pci-bus.c +9 -0
         if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+            S390FLICState *fs = s390_get_flic();
+            VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
+
+            if ((!vdev->no_kvm_msix || !vdev->no_kvm_msix) &&
+                (!fs || !fs->ais_supported)) {
+                error_setg(errp, "VFIO PCI is not supported "
+                           "because kernel has no AIS capability.");
+                return;
+            }

Hmm, you're basically looking at private data structure fields for experimental disable flags, which no user, or more importantly no management tool, could rightfully be expected to provide. Can we not take this into account to automatically do the right thing, ie. automatically set the necessary flag during the device realize? Thanks,

Alex

#16 lore raw

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

Quoted 64 lines · Alex Williamson
Quoted 34 lines · On Wed, 4 Oct 2017 15:49:38 +0200 Pierre Morel <[email protected]>…

In S390x the Adapter Interrupt Suppression facility is used to mask interrupts of other PCI devices during interruption handling.

VFIO PCI allows the interrupts to be delivered rapidely through KVM via IRQfd or to be delivered through QEMU.
The choice is made through the x-kvm-intx and x-kvo-misx properties of the VFIO PCI device.

If the VFIO PCI device is using the direct KVM access through IRQfd and we know that KVM does not implement AIS support we refuse to realize the VFIO PCI device.

In all other cases, emulation and VFIO PCI sending interrupts through QEMU, we intercept the propagated IRQ, and protect it with the QEMU AIS implementation before to send it to the guest through KVM.

---
  hw/s390x/s390-pci-bus.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
hw/s390x/s390-pci-bus.c +1 -0
index d9c294a..4afe49b 100644
@@ -21,18 +21,21 @@
  #include "hw/pci/pci_bus.h"
  #include "hw/pci/pci_bridge.h"
  #include "hw/pci/msi.h"
+#include "hw/vfio/pci.h"
  #include "qemu/error-report.h"
 
  #ifndef DEBUG_S390PCI_BUS
  #define DEBUG_S390PCI_BUS  0

hw/s390x/s390-pci-bus.c line 38

Quoted 10 lines
hw/s390x/s390-pci-bus.c +2 -0
  #endif
 
+#ifndef DPRINTF
  #define DPRINTF(fmt, ...)                                         \
      do {                                                          \
          if (DEBUG_S390PCI_BUS) {                                  \
              fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
          }                                                         \
      } while (0)
+#endif

Maybe a sign we shouldn't be including vfio/pci.h

Quoted 14 lines
hw/s390x/s390-pci-bus.c +8 -0
  S390pciState *s390_get_phb(void)
  {
@@ -751,6 +754,15 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
          }
 
          if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+            S390FLICState *fs = s390_get_flic();
+            VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
+
+            if ((!vdev->no_kvm_msix || !vdev->no_kvm_msix) &&
+                (!fs || !fs->ais_supported)) {
+                error_setg(errp, "VFIO PCI is not supported "
+                           "because kernel has no AIS capability.");
+                return;
Quoted 8 lines

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 765

Quoted 1 line
hw/s390x/s390-pci-bus.c +1 -0
+            }

Hmm, you're basically looking at private data structure fields for experimental disable flags, which no user, or more importantly no management tool, could rightfully be expected to provide. Can we not take this into account to automatically do the right thing, ie. automatically set the necessary flag during the device realize? Thanks,

I am not sure to understand.

Here we are in a s390x specific device and without vfio/pci.h, we have no access to the PCI VFIOdevice structure from the realize function.

Do you mean to add an entry in the VFIOPCIdevice realize?
A new quirk ?
An architecture callback, because we also need access to S390FLICState ?

We also have the possibility to not fall-back to AIS emulation for VFIO but we would loose the possibility to migrate to a host not supporting AIS.

Thanks for your help.

Pierre

Quoted 3 lines

Alex

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

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

Quoted 79 lines · On Mon, 9 Oct 2017 19:16:23 +0200 Pierre Morel <[email protected]>…
Quoted 64 lines · Alex Williamson
Quoted 34 lines · On Wed, 4 Oct 2017 15:49:38 +0200 Pierre Morel <[email protected]>…

In S390x the Adapter Interrupt Suppression facility is used to mask interrupts of other PCI devices during interruption handling.

VFIO PCI allows the interrupts to be delivered rapidely through KVM via IRQfd or to be delivered through QEMU.
The choice is made through the x-kvm-intx and x-kvo-misx properties of the VFIO PCI device.

If the VFIO PCI device is using the direct KVM access through IRQfd and we know that KVM does not implement AIS support we refuse to realize the VFIO PCI device.

In all other cases, emulation and VFIO PCI sending interrupts through QEMU, we intercept the propagated IRQ, and protect it with the QEMU AIS implementation before to send it to the guest through KVM.

---
  hw/s390x/s390-pci-bus.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
hw/s390x/s390-pci-bus.c +1 -0
index d9c294a..4afe49b 100644
@@ -21,18 +21,21 @@
  #include "hw/pci/pci_bus.h"
  #include "hw/pci/pci_bridge.h"
  #include "hw/pci/msi.h"
+#include "hw/vfio/pci.h"
  #include "qemu/error-report.h"
 
  #ifndef DEBUG_S390PCI_BUS
  #define DEBUG_S390PCI_BUS  0

hw/s390x/s390-pci-bus.c line 38

Quoted 10 lines
hw/s390x/s390-pci-bus.c +2 -0
  #endif
 
+#ifndef DPRINTF
  #define DPRINTF(fmt, ...)                                         \
      do {                                                          \
          if (DEBUG_S390PCI_BUS) {                                  \
              fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
          }                                                         \
      } while (0)
+#endif  

Maybe a sign we shouldn't be including vfio/pci.h

Quoted 14 lines
hw/s390x/s390-pci-bus.c +8 -0
  S390pciState *s390_get_phb(void)
  {
@@ -751,6 +754,15 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
          }
 
          if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+            S390FLICState *fs = s390_get_flic();
+            VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
+
+            if ((!vdev->no_kvm_msix || !vdev->no_kvm_msix) &&
+                (!fs || !fs->ais_supported)) {
+                error_setg(errp, "VFIO PCI is not supported "
+                           "because kernel has no AIS capability.");
+                return;
Quoted 8 lines

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 765

Quoted 1 line
hw/s390x/s390-pci-bus.c +1 -0
+            }  

Hmm, you're basically looking at private data structure fields for experimental disable flags, which no user, or more importantly no management tool, could rightfully be expected to provide. Can we not take this into account to automatically do the right thing, ie. automatically set the necessary flag during the device realize? Thanks,

I am not sure to understand.

Here we are in a s390x specific device and without vfio/pci.h, we have no access to the PCI VFIOdevice structure from the realize function.

Quoted 7 lines

Do you mean to add an entry in the VFIOPCIdevice realize?
A new quirk ?
An architecture callback, because we also need access to S390FLICState ?

We also have the possibility to not fall-back to AIS emulation for VFIO but we would loose the possibility to migrate to a host not supporting AIS.

Thinking about this some more: The problem is generally "if we have to fall back to ais emulation, we cannot support any pci device that bypasses qemu's interrupt injection", no?

So this would imply vfio devices where the experimental switch is not used, but also virtio-pci if it is configured to use irqfd, I think.

The ugly thing is that the platform-specific code depends on a property of the plugged device being set or not set... and that's likely to be different from device type to device type, and may not even be configurable for some device types.

#18 lore raw

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

Quoted 94 lines · Cornelia Huck
Quoted 79 lines · On Mon, 9 Oct 2017 19:16:23 +0200 Pierre Morel <[email protected]>…
Quoted 64 lines · Alex Williamson
Quoted 34 lines · On Wed, 4 Oct 2017 15:49:38 +0200 Pierre Morel <[email protected]>…

In S390x the Adapter Interrupt Suppression facility is used to mask interrupts of other PCI devices during interruption handling.

VFIO PCI allows the interrupts to be delivered rapidely through KVM via IRQfd or to be delivered through QEMU.
The choice is made through the x-kvm-intx and x-kvo-misx properties of the VFIO PCI device.

If the VFIO PCI device is using the direct KVM access through IRQfd and we know that KVM does not implement AIS support we refuse to realize the VFIO PCI device.

In all other cases, emulation and VFIO PCI sending interrupts through QEMU, we intercept the propagated IRQ, and protect it with the QEMU AIS implementation before to send it to the guest through KVM.

---
   hw/s390x/s390-pci-bus.c | 12 ++++++++++++
   1 file changed, 12 insertions(+)
hw/s390x/s390-pci-bus.c +1 -0
index d9c294a..4afe49b 100644
@@ -21,18 +21,21 @@
   #include "hw/pci/pci_bus.h"
   #include "hw/pci/pci_bridge.h"
   #include "hw/pci/msi.h"
+#include "hw/vfio/pci.h"
   #include "qemu/error-report.h"
 
   #ifndef DEBUG_S390PCI_BUS
   #define DEBUG_S390PCI_BUS  0

hw/s390x/s390-pci-bus.c line 38

Quoted 10 lines
hw/s390x/s390-pci-bus.c +2 -0
   #endif
 
+#ifndef DPRINTF
   #define DPRINTF(fmt, ...)                                         \
       do {                                                          \
           if (DEBUG_S390PCI_BUS) {                                  \
               fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
           }                                                         \
       } while (0)
+#endif

Maybe a sign we shouldn't be including vfio/pci.h

Quoted 14 lines
hw/s390x/s390-pci-bus.c +8 -0
   S390pciState *s390_get_phb(void)
   {
@@ -751,6 +754,15 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
           }
 
           if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
+            S390FLICState *fs = s390_get_flic();
+            VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
+
+            if ((!vdev->no_kvm_msix || !vdev->no_kvm_msix) &&
+                (!fs || !fs->ais_supported)) {
+                error_setg(errp, "VFIO PCI is not supported "
+                           "because kernel has no AIS capability.");
+                return;
Quoted 8 lines

hw/s390x/s390-pci-bus.c static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, · line 765

Quoted 1 line
hw/s390x/s390-pci-bus.c +1 -0
+            }

Hmm, you're basically looking at private data structure fields for experimental disable flags, which no user, or more importantly no management tool, could rightfully be expected to provide. Can we not take this into account to automatically do the right thing, ie. automatically set the necessary flag during the device realize? Thanks,

I am not sure to understand.

Here we are in a s390x specific device and without vfio/pci.h, we have no access to the PCI VFIOdevice structure from the realize function.

Quoted 7 lines

Do you mean to add an entry in the VFIOPCIdevice realize?
A new quirk ?
An architecture callback, because we also need access to S390FLICState ?

We also have the possibility to not fall-back to AIS emulation for VFIO but we would loose the possibility to migrate to a host not supporting AIS.

Thinking about this some more: The problem is generally "if we have to fall back to ais emulation, we cannot support any pci device that bypasses qemu's interrupt injection", no?

Quoted 8 lines

So this would imply vfio devices where the experimental switch is not used, but also virtio-pci if it is configured to use irqfd, I think.

The ugly thing is that the platform-specific code depends on a property of the plugged device being set or not set... and that's likely to be different from device type to device type, and may not even be configurable for some device types.

Yes, right.
Since in the case we have no AIS in KVM only PCI is impacted, do you think we can fence IRQFD for MSI with

kvm_msi_via_irqfd_allowed = false;

in kvm_arch_init_irq_routing() ?

In fact, if we also verify the AIS availability in the same routine we can avoid the ugly include of vfio/pci.h

Regards,

Pierre

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

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

Quoted 6 lines · On Tue, 10 Oct 2017 18:01:53 +0200 Pierre Morel <[email protected]>…

Since in the case we have no AIS in KVM only PCI is impacted, do you think we can fence IRQFD for MSI with

kvm_msi_via_irqfd_allowed = false;

in kvm_arch_init_irq_routing() ?

Hm, it seems we never set that for s390x... does that imply that we never support irqfd for pci anyway?

Quoted 3 lines

In fact, if we also verify the AIS availability in the same routine we can avoid the ugly include of vfio/pci.h

If we can get the serialization right (and setting that value to false does indeed have the desired effect), that's probably the way to go.

#20 lore raw

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

Quoted 14 lines · Cornelia Huck
Quoted 6 lines · On Tue, 10 Oct 2017 18:01:53 +0200 Pierre Morel <[email protected]>…

Since in the case we have no AIS in KVM only PCI is impacted, do you think we can fence IRQFD for MSI with

kvm_msi_via_irqfd_allowed = false;

in kvm_arch_init_irq_routing() ?

Hm, it seems we never set that for s390x... does that imply that we never support irqfd for pci anyway?

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

In fact, if we also verify the AIS availability in the same routine we can avoid the ugly include of vfio/pci.h

If we can get the serialization right (and setting that value to false does indeed have the desired effect), that's probably the way to go.

OK, thanks, I give it a try and propose a v2 on this basis.

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

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

In reply to Cornelia Huck
Quoted 6 lines · Cornelia Huck
Quoted 3 lines · On Tue, 10 Oct 2017 18:01:53 +0200 Pierre Morel <[email protected]>…

Since in the case we have no AIS in KVM only PCI is impacted, do you think we can fence IRQFD for MSI with

Quoted 6 lines
Quoted 3 lines

kvm_msi_via_irqfd_allowed = false;

in kvm_arch_init_irq_routing() ?

Hm, it seems we never set that for s390x... does that imply that we never support irqfd for pci anyway?

... yes, we never supported irqfd for virtio-pci anyway. This explains a lot of things to me.
:)

Quoted 8 lines
Quoted 4 lines

In fact, if we also verify the AIS availability in the same routine we can avoid the ugly include of vfio/pci.h

If we can get the serialization right (and setting that value to false does indeed have the desired effect), that's probably the way to go.

So now, in v2, we will be able to **enable** irqfd if we detect that we handle AIS in kernel. :)

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

Re: [Qemu-devel] [PATCH v1 4/5] s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported

Quoted 9 lines · On Thu, 12 Oct 2017 16:48:26 +0200 Pierre Morel <[email protected]>…
Quoted 8 lines · Cornelia Huck
Quoted 5 lines · On Tue, 10 Oct 2017 18:01:53 +0200 Pierre Morel <[email protected]>…

Since in the case we have no AIS in KVM only PCI is impacted, do you think we can fence IRQFD for MSI with

kvm_msi_via_irqfd_allowed = false;

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

in kvm_arch_init_irq_routing() ?

Hm, it seems we never set that for s390x... does that imply that we never support irqfd for pci anyway?

... yes, we never supported irqfd for virtio-pci anyway. This explains a lot of things to me.
:)

:D

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

In fact, if we also verify the AIS availability in the same routine we can avoid the ugly include of vfio/pci.h

Quoted 6 lines
Quoted 3 lines

If we can get the serialization right (and setting that value to false does indeed have the desired effect), that's probably the way to go.

So now, in v2, we will be able to **enable** irqfd if we detect that we handle AIS in kernel. :)

Let's see how that works out :)

#24 lore raw
In reply to Pierre Morel

Now I thought about that for a while and I start to think that we cannot implement ais in QEMU and cover all cases.
One aspect was certainly passthrough (like you handled in patch 4). Another aspect is that some interrupts might be injected from the kernel - even for emulated devices. e.g. virtio-pci together with vhost-net, will inject interrupts via the set_irq callback. I think disabling irqfd for these cases is not a good idea.

So what about adding a new KVM capability (for 4.14), fixup the other things in QEMU and then bind it to the new capability?

Christian

Quoted 39 lines · Pierre Morel

Currently AIS support has several problems:

- AIS support in KVM is reported if KVM has AIS capability.
- Testing if KVM FLIC attributes for AIS are supported does not take into account if AIS is supported by KVM.
- KVM report supporting the AIS FLIC features but denies their usage if the host kernel does not support the AIS feature.
- Testing if the Adapter interrupt must be suppressed is done looking at the ISC and ignores the adapter properties.
- Emulation of PCI devices can only be done with KVM support for AIS.
- Migration of emulated devices can only be done if both side support AIS in KVM

I would like to make some modifications to the code where I think things are not handled at the right place.

Therefor I propose these changes.
- Use the CPU model to enable AIS in the guest, even without KVM backup
- Ask KVM for AIS support in kvm_flic realize
- add simm/nimm attributes to the KVM FLIC interface to support emulation and migration between hosts with and without AIS support in KVM.
- Modify the zPCI VFIO realize function to refuse VFIO PCI devices without AIS support in KVM.
- Modify the AIS migration to support emulation and heterogeneous hosts.

Pierre Morel (5):
s390x/kvm: Enable AIS from CPU model always
s390x/css: Use AIS AIRQ injection only if adapter support AIS s390x/intc: Emulate Adapter Interrupt Suppression s390x/pci: Refuse to realize VFIO-PCI if AIS needed but supported s390x/intc: AIS is now always migratable

 hw/intc/s390_flic.c     |  3 +-
 hw/intc/s390_flic_kvm.c | 94 ++++++++++++++++++++++++++++++++++++++-----------
 hw/s390x/css.c          |  6 ++--
 hw/s390x/s390-pci-bus.c | 12 +++++++
 target/s390x/kvm.c      |  1 +
 5 files changed, 91 insertions(+), 25 deletions(-)
#25 lore raw
Quoted 6 lines · On Mon, 30 Oct 2017 09:28:09 +0100 Christian Borntraeger…

Now I thought about that for a while and I start to think that we cannot implement ais in QEMU and cover all cases.
One aspect was certainly passthrough (like you handled in patch 4). Another aspect is that some interrupts might be injected from the kernel - even for emulated devices. e.g. virtio-pci together with vhost-net, will inject interrupts via the set_irq callback. I think disabling irqfd for these cases is not a good idea.

Is there still a fallback for irqfd emulation?

Quoted 3 lines

So what about adding a new KVM capability (for 4.14), fixup the other things in QEMU and then bind it to the new capability?

For 4.15, surely?

Probably the only way we can make this work correctly...

#26 lore raw
Quoted 11 lines · Cornelia Huck
Quoted 6 lines · On Mon, 30 Oct 2017 09:28:09 +0100 Christian Borntraeger…

Now I thought about that for a while and I start to think that we cannot implement ais in QEMU and cover all cases.
One aspect was certainly passthrough (like you handled in patch 4). Another aspect is that some interrupts might be injected from the kernel - even for emulated devices. e.g. virtio-pci together with vhost-net, will inject interrupts via the set_irq callback. I think disabling irqfd for these cases is not a good idea.

Is there still a fallback for irqfd emulation?

it might disable dataplane or other things. (it once did). So I think we should not go down this path.

Quoted 9 lines
Quoted 4 lines

So what about adding a new KVM capability (for 4.14), fixup the other things in QEMU and then bind it to the new capability?

For 4.15, surely?

Probably the only way we can make this work correctly...

#27 lore raw
Quoted 13 lines · Christian Borntraeger
Quoted 10 lines · Cornelia Huck
Quoted 6 lines · On Mon, 30 Oct 2017 09:28:09 +0100 Christian Borntraeger…

Now I thought about that for a while and I start to think that we cannot implement ais in QEMU and cover all cases.
One aspect was certainly passthrough (like you handled in patch 4). Another aspect is that some interrupts might be injected from the kernel - even for emulated devices. e.g. virtio-pci together with vhost-net, will inject interrupts via the set_irq callback. I think disabling irqfd for these cases is not a good idea.

Quoted 14 lines
Quoted 1 line

Is there still a fallback for irqfd emulation?

it might disable dataplane or other things. (it once did). So I think we should not go down this path.

Quoted 9 lines
Quoted 4 lines

So what about adding a new KVM capability (for 4.14), fixup the other things in QEMU and then bind it to the new capability?

For 4.15, surely?

Probably the only way we can make this work correctly...

I may have not understand.

Why do we need a new capability, we already have the KVM_CAP_S390_AIS capability?
The PCI device has a netdev property pointing to a netdev, if this netdev sets the vhost property, can't we test this to know if we can realize this device or not?

Using virtio-pci instead of virtio-ccw is not the first choice for S390. The use case I see for S390 using virtio-pci is as a fallback in case for the migration of a PCI device the target host does not support AIS or do not have VFIO device and one do not want to modify the guest.

Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#28 lore raw
Quoted 24 lines · Pierre Morel
Quoted 23 lines · Christian Borntraeger
Quoted 11 lines · Cornelia Huck
Quoted 6 lines · On Mon, 30 Oct 2017 09:28:09 +0100 Christian Borntraeger…

Now I thought about that for a while and I start to think that we cannot implement ais in QEMU and cover all cases.
One aspect was certainly passthrough (like you handled in patch 4). Another aspect is that some interrupts might be injected from the kernel - even for emulated devices. e.g. virtio-pci together with vhost-net, will inject interrupts via the set_irq callback. I think disabling irqfd for these cases is not a good idea.

Is there still a fallback for irqfd emulation?

it might disable dataplane or other things. (it once did). So I think we should not go down this path.

Quoted 5 lines
Quoted 4 lines

So what about adding a new KVM capability (for 4.14), fixup the other things in QEMU and then bind it to the new capability?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

For 4.15, surely?

Probably the only way we can make this work correctly...

I may have not understand.

Why do we need a new capability, we already have the KVM_CAP_S390_AIS capability?

To mark a kernel that supports AIS+migration without having to instantiate a flic device.

Quoted 3 lines

The PCI device has a netdev property pointing to a netdev, if this netdev sets the vhost property, can't we test this to know if we can realize this device or not?

Using virtio-pci instead of virtio-ccw is not the first choice for S390. The use case I see for S390 using virtio-pci is as a fallback in case for the migration of a PCI device the target host does not support AIS or do not have VFIO device and one do not want to modify the guest.

This was just one example. Having the interrupt controller in the kernel, implementing AIS in qemu is very prone to break something that we have forgotten about.

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -1
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
        if (!s390_pci_probe)
                return 0;
 
-       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                return 0;
 
        rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +3 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
 #include <linux/export.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
+#include <asm/facility.h>
 #include <asm/pci_insn.h>
 #include <asm/pci_debug.h>
 #include <asm/processor.h>
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
 /* Set Interruption Controls */
 void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
 {
+       if (!test_facility(72))
+               return;
        asm volatile (
                "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
                : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));
#29 lore raw
Quoted 29 lines · Christian Borntraeger
Quoted 26 lines · Pierre Morel
Quoted 25 lines · Christian Borntraeger
Quoted 11 lines · Cornelia Huck
Quoted 6 lines · On Mon, 30 Oct 2017 09:28:09 +0100 Christian Borntraeger…

Now I thought about that for a while and I start to think that we cannot implement ais in QEMU and cover all cases.
One aspect was certainly passthrough (like you handled in patch 4). Another aspect is that some interrupts might be injected from the kernel - even for emulated devices. e.g. virtio-pci together with vhost-net, will inject interrupts via the set_irq callback. I think disabling irqfd for these cases is not a good idea.

Is there still a fallback for irqfd emulation?

it might disable dataplane or other things. (it once did). So I think we should not go down this path.

Quoted 7 lines
Quoted 4 lines

So what about adding a new KVM capability (for 4.14), fixup the other things in QEMU and then bind it to the new capability?

For 4.15, surely?

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Probably the only way we can make this work correctly...

I may have not understand.

Why do we need a new capability, we already have the KVM_CAP_S390_AIS capability?

To mark a kernel that supports AIS+migration without having to instantiate a flic device.

It's about libvirt probing AFAIU. Right now, to tell if we have migration for AIS we need a flic device instantiated in the kernel (we need the fd to tell if the flic attributes are supported by the kernel).

Quoted 8 lines
Quoted 4 lines

The PCI device has a netdev property pointing to a netdev, if this netdev sets the vhost property, can't we test this to know if we can realize this device or not?

Using virtio-pci instead of virtio-ccw is not the first choice for S390. The use case I see for S390 using virtio-pci is as a fallback in case for the migration of a PCI device the target host does not support AIS or do not have VFIO device and one do not want to modify the guest.

This was just one example. Having the interrupt controller in the kernel, implementing AIS in qemu is very prone to break something that we have forgotten about.

I tend to agree with Christian. While doing emulation AIS in QEMU for scenarios where all adapter interrupts (subject to AIS) are guaranteed to go through QEMU is possible, it is also bound to introduce a whole lot of added complexity.

Frankly, I doubt the gain outweighs the pain in this case.

Regards,
Halil

#30 lore raw
In reply to Christian Borntraeger
Quoted 30 lines · On Mon, 30 Oct 2017 14:48:23 +0100 Christian Borntraeger…

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -1
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
        if (!s390_pci_probe)
                return 0;
 
-       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                return 0;
 
        rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +1 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
 #include <linux/export.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
+#include <asm/facility.h>
 #include <asm/pci_insn.h>
 #include <asm/pci_debug.h>
 #include <asm/processor.h>

arch/s390/pci/pci_insn.c int zpci_refresh_trans(u64 fn, u64 addr, u64 range) · line 101

Quoted 8 lines
arch/s390/pci/pci_insn.c +2 -0
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
 /* Set Interruption Controls */
 void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
 {
+       if (!test_facility(72))
+               return;
        asm volatile (
                "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
                : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));

Sounds good. Presumably this makes the adapter interrupt handling work as for virtio (and qdio)? Is there any ais-less pci hardware out in the wild?

#31 lore raw
Quoted 38 lines · Cornelia Huck
Quoted 34 lines · On Mon, 30 Oct 2017 14:48:23 +0100 Christian Borntraeger…

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -1
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
        if (!s390_pci_probe)
                return 0;
 
-       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                return 0;
 
        rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +3 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
 #include <linux/export.h>
 #include <linux/errno.h>
 #include <linux/delay.h>
+#include <asm/facility.h>
 #include <asm/pci_insn.h>
 #include <asm/pci_debug.h>
 #include <asm/processor.h>
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
 /* Set Interruption Controls */
 void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
 {
+       if (!test_facility(72))
+               return;
Quoted 9 lines

arch/s390/pci/pci_insn.c int zpci_refresh_trans(u64 fn, u64 addr, u64 range) · line 101

Quoted 4 lines
arch/s390/pci/pci_insn.c +0 -0
        asm volatile (
                "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
                : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));

Sounds good. Presumably this makes the adapter interrupt handling work as for virtio (and qdio)? Is there any ais-less pci hardware out in the wild?

ais is z specific, not PCI specific. So PCI cards should not care as far as I can tell.

#32 lore raw
Quoted 50 lines · Christian Borntraeger
Quoted 38 lines · Cornelia Huck
Quoted 34 lines · On Mon, 30 Oct 2017 14:48:23 +0100 Christian Borntraeger…

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -1
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
         if (!s390_pci_probe)
                 return 0;
 
-       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                 return 0;
 
         rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +3 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
  #include <linux/export.h>
  #include <linux/errno.h>
  #include <linux/delay.h>
+#include <asm/facility.h>
  #include <asm/pci_insn.h>
  #include <asm/pci_debug.h>
  #include <asm/processor.h>
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
  /* Set Interruption Controls */
  void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
  {
+       if (!test_facility(72))
+               return;
Quoted 9 lines

arch/s390/pci/pci_insn.c int zpci_refresh_trans(u64 fn, u64 addr, u64 range) · line 101

Quoted 4 lines
arch/s390/pci/pci_insn.c +0 -0
         asm volatile (
                 "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
                 : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));

Sounds good. Presumably this makes the adapter interrupt handling work as for virtio (and qdio)? Is there any ais-less pci hardware out in the wild?

Quoted 3 lines

ais is z specific, not PCI specific. So PCI cards should not care as far as I can tell.

I bet Conny meant PCI hardware globaly, including zPCI adapters. I bet none but I will better ask Sebastian or Gerald if they know.

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#33 lore raw
Quoted 39 lines · Pierre Morel
Quoted 38 lines · Christian Borntraeger
Quoted 36 lines · Cornelia Huck
Quoted 32 lines · On Mon, 30 Oct 2017 14:48:23 +0100 Christian Borntraeger…

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -0
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
          if (!s390_pci_probe)
                  return 0;
   -       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                  return 0;
            rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +3 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
   #include <linux/export.h>
   #include <linux/errno.h>
   #include <linux/delay.h>
+#include <asm/facility.h>
   #include <asm/pci_insn.h>
   #include <asm/pci_debug.h>
   #include <asm/processor.h>
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
   /* Set Interruption Controls */
   void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
   {
+       if (!test_facility(72))
+               return;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

         asm volatile (
                 "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n" : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));

Sounds good. Presumably this makes the adapter interrupt handling work as for virtio (and qdio)? Is there any ais-less pci hardware out in the wild?

@Connie:
Do you have something in mind, or is curiosity the only reason for asking?

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

ais is z specific, not PCI specific. So PCI cards should not care as far as I can tell.

I bet Conny meant PCI hardware globaly, including zPCI adapters. I bet none but I will better ask Sebastian or Gerald if they know.

I side with Christian: it is a machine thing and not a card thing. So the question is if there is a z machine which supports zpci but does not support AIS. My guess is that such a machine was never produced.

Halil

#34 lore raw
Quoted 49 lines · On Mon, 30 Oct 2017 19:58:15 +0100 Halil Pasic <[email protected]> wrote:
Quoted 39 lines · Pierre Morel
Quoted 38 lines · Christian Borntraeger
Quoted 36 lines · Cornelia Huck
Quoted 32 lines · On Mon, 30 Oct 2017 14:48:23 +0100 Christian Borntraeger…

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -0
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
          if (!s390_pci_probe)
                  return 0;
   -       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                  return 0;
            rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +3 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
   #include <linux/export.h>
   #include <linux/errno.h>
   #include <linux/delay.h>
+#include <asm/facility.h>
   #include <asm/pci_insn.h>
   #include <asm/pci_debug.h>
   #include <asm/processor.h>
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
   /* Set Interruption Controls */
   void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
   {
+       if (!test_facility(72))
+               return;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

         asm volatile (
                 "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n" : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));

Sounds good. Presumably this makes the adapter interrupt handling work as for virtio (and qdio)? Is there any ais-less pci hardware out in the wild?

Quoted 2 lines

@Connie:
Do you have something in mind, or is curiosity the only reason for asking?

I just want to make sure we don't miss anything.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

ais is z specific, not PCI specific. So PCI cards should not care as far as I can tell.

Quoted 7 lines
Quoted 3 lines

I bet Conny meant PCI hardware globaly, including zPCI adapters. I bet none but I will better ask Sebastian or Gerald if they know.

I side with Christian: it is a machine thing and not a card thing. So the question is if there is a z machine which supports zpci but does not support AIS. My guess is that such a machine was never produced.

That's exactly what I meant, and I would not expect such a machine to exist either.

#35 lore raw
Quoted 68 lines · Cornelia Huck
Quoted 49 lines · On Mon, 30 Oct 2017 19:58:15 +0100 Halil Pasic <[email protected]> wrote:
Quoted 39 lines · Pierre Morel
Quoted 38 lines · Christian Borntraeger
Quoted 36 lines · Cornelia Huck
Quoted 32 lines · On Mon, 30 Oct 2017 14:48:23 +0100 Christian Borntraeger…

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -0
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
          if (!s390_pci_probe)
                  return 0;
   -       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                  return 0;
            rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +3 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
   #include <linux/export.h>
   #include <linux/errno.h>
   #include <linux/delay.h>
+#include <asm/facility.h>
   #include <asm/pci_insn.h>
   #include <asm/pci_debug.h>
   #include <asm/processor.h>
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
   /* Set Interruption Controls */
   void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
   {
+       if (!test_facility(72))
+               return;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

         asm volatile (
                 "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n" : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));

Sounds good. Presumably this makes the adapter interrupt handling work as for virtio (and qdio)? Is there any ais-less pci hardware out in the wild?

Quoted 2 lines

@Connie:
Do you have something in mind, or is curiosity the only reason for asking?

I just want to make sure we don't miss anything.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

ais is z specific, not PCI specific. So PCI cards should not care as far as I can tell.

I bet Conny meant PCI hardware globaly, including zPCI adapters. I bet none but I will better ask Sebastian or Gerald if they know.

Quoted 6 lines
Quoted 3 lines

I side with Christian: it is a machine thing and not a card thing. So the question is if there is a z machine which supports zpci but does not support AIS. My guess is that such a machine was never produced.

That's exactly what I meant, and I would not expect such a machine to exist either.

That machine is called qemu 2.10 :-p

FWIW, I talked with Sebastian about that and he is fine with such a change. He required some changes and I will work on such a patch.

#36 lore raw
Quoted 78 lines · Christian Borntraeger
Quoted 68 lines · Cornelia Huck
Quoted 49 lines · On Mon, 30 Oct 2017 19:58:15 +0100 Halil Pasic <[email protected]> wrote:
Quoted 39 lines · Pierre Morel
Quoted 38 lines · Christian Borntraeger
Quoted 36 lines · Cornelia Huck
Quoted 32 lines · On Mon, 30 Oct 2017 14:48:23 +0100 Christian Borntraeger…

FWIW, I am testing a guest patch that enables zPCI without AIS. Its as simple as

arch/s390/pci/pci.c +1 -0
index 7b30af5..9b24836 100644
@@ -953,7 +953,7 @@ static int __init pci_base_init(void)
          if (!s390_pci_probe)
                  return 0;
   -       if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+       if (!test_facility(69) || !test_facility(71))
                  return 0;
            rc = zpci_debug_init();
arch/s390/pci/pci_insn.c +3 -0
index ea34086..61f8c82 100644
@@ -7,6 +7,7 @@
   #include <linux/export.h>
   #include <linux/errno.h>
   #include <linux/delay.h>
+#include <asm/facility.h>
   #include <asm/pci_insn.h>
   #include <asm/pci_debug.h>
   #include <asm/processor.h>
@@ -93,6 +94,8 @@ int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
   /* Set Interruption Controls */
   void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
   {
+       if (!test_facility(72))
+               return;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

arch/s390/pci/pci_insn.c int zpci_refresh_trans(u64 fn, u64 addr, u64 range) · line 101

Quoted 4 lines
arch/s390/pci/pci_insn.c +0 -0
          asm volatile (
                  "       .insn   rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
                  : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));

Sounds good. Presumably this makes the adapter interrupt handling work as for virtio (and qdio)? Is there any ais-less pci hardware out in the wild?

Quoted 2 lines

@Connie:
Do you have something in mind, or is curiosity the only reason for asking?

I just want to make sure we don't miss anything.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

ais is z specific, not PCI specific. So PCI cards should not care as far as I can tell.

I bet Conny meant PCI hardware globaly, including zPCI adapters. I bet none but I will better ask Sebastian or Gerald if they know.

Quoted 6 lines
Quoted 3 lines

I side with Christian: it is a machine thing and not a card thing. So the question is if there is a z machine which supports zpci but does not support AIS. My guess is that such a machine was never produced.

That's exactly what I meant, and I would not expect such a machine to exist either.

Quoted 8 lines

That machine is called qemu 2.10 :-p

FWIW, I talked with Sebastian about that and he is fine with such a change. He required some changes and I will work on such a patch.

My analyze is that providing AIS to the guest can work, with the precaution to handle spurious interrupts, until we use GISA for PCI.

Then when we introduce GISA for PCI, we will need to think again about providing AIS to the guest.

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