Error recovery for zPCI passthrough devices
PATCH v7 2/2 s390x/pci: Reset a device in error state
In reply to Farhan AliFor passthrough devices in error state, for a guest driven reset of the device we can attempt a reset to recover the device. A reset of the device will trigger a CLP disable/enable cycle on the host to bring the device into a recovered state.
--- hw/s390x/s390-pci-bus.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
hw/s390x/s390-pci-bus.c +15 -0
@@ -1505,6 +1505,21 @@ static void s390_pci_device_reset(DeviceState *dev)return ;case ZPCI_FS_STANDBY :break ; +case ZPCI_FS_ERROR : +/* +* Attempt a reset to recover the device. A device in ERROR state +* can be transitioned to ENABLED or DISABLED state via guest +* driven actions. Since this code path is also executed on +* subsystem_reset() and the expected state of a configured device +* after subsystem_reset() is to be in a DISABLED state, we need to +* transition from ERROR to DISABLED. +* +* Linux guests drive the state transition from ERROR to DISABLED +* via CLP_SET_DISABLE_PCI_FN. So it should be safe to transition +* from ERROR to DISABLED state. +*/ +pci_device_reset (pbdev->pdev); +/* fallthrough */ default : pbdev->fh &= ~FH_MASK_ENABLE ; pbdev->state =ZPCI_FS_DISABLED ;
Signature · 1 line
2.43.0
PATCH v7 1/2 s390x/pci: Add PCI error handling for vfio pci devices
In reply to Farhan AliAdd an s390x specific handler for vfio error notifier. For s390x pci devices, we have platform specific error information. We need to retrieve this error information for passthrough devices. This is done via a VFIO_DEVICE_FEATURE ioctl which exposes that information.
Once this error information is retrieved we can then inject an error into the guest, and let the guest drive the recovery.
--- hw/s390x/s390-pci-bus.c | 6 ++ hw/s390x/s390-pci-vfio-stubs.c | 6 ++ hw/s390x/s390-pci-vfio.c | 123 +++++++++++++++++++++++++++++++ include/hw/s390x/s390-pci-bus.h | 1 + include/hw/s390x/s390-pci-vfio.h | 1 + 5 files changed, 137 insertions(+)
hw/s390x/s390-pci-bus.c +6 -0
@@ -1085,6 +1085,7 @@ static void s390_pcihost_plug(const HotplugHandler *hotplug_dev, DeviceState *deS390pciState *s =S390_PCI_HOST_BRIDGE (hotplug_dev);PCIDevice *pdev =NULL ;S390PCIBusDevice *pbdev =NULL ; +Error *local_err =NULL ;int rc;if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_BRIDGE )) {
@@ -1175,6 +1176,11 @@ static void s390_pcihost_plug(const HotplugHandler *hotplug_dev, DeviceState *de pbdev->iommu->dma_limit =s390_pci_start_dma_count (s, pbdev);/* Fill in CLP information passed via the vfio region */ s390_pci_get_clp_info (pbdev); +/* Setup error handler for error recovery */ +if (!s390_pci_setup_err_handler (pbdev, &local_err)) { +warn_report_err (local_err); + } +if (!pbdev->interp) {/* Do vfio passthrough but intercept for I/O */ pbdev->fh |=FH_SHM_VFIO ;
hw/s390x/s390-pci-vfio-stubs.c +6 -0
@@ -30,3 +30,9 @@ bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh)void s390_pci_get_clp_info (S390PCIBusDevice *pbdev) { } + +bool s390_pci_setup_err_handler (S390PCIBusDevice *pbdev,Error **errp) +{ +error_setg (errp,"VFIO not available, cannot setup error handler" ); +return false; +}
hw/s390x/s390-pci-vfio.c +123 -0
144 lines not on this page · raw message
include/hw/s390x/s390-pci-bus.h +1 -0
@@ -365,6 +365,7 @@ struct S390PCIBusDevice {bool forwarding_assist;bool aif;bool rtr_avail; +uint32_t ccdf_err_length;QTAILQ_ENTRY (S390PCIBusDevice) link; };
include/hw/s390x/s390-pci-vfio.h +1 -0
@@ -20,5 +20,6 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,void s390_pci_end_dma_count (S390pciState *s,S390PCIDMACount *cnt);bool s390_pci_get_host_fh (S390PCIBusDevice *pbdev,uint32_t *fh);void s390_pci_get_clp_info (S390PCIBusDevice *pbdev); +bool s390_pci_setup_err_handler (S390PCIBusDevice *pbdev,Error **errp);#endif
Signature · 1 line
2.43.0
v7 cover Error recovery for zPCI passthrough devices
Hi,
This patch series introduces support for error recovery for passthrough PCI devices on System Z (s390x). This is the user space component for the Linux kernel patches [1]. The kernel patches were merged for 7.3 release.
The current design for QEMU updates the callback for vfio error notifier to an s390x specific error handler if the kernel supports the new device feature VFIO_DEVICE_FEATURE_ZPCI_ERROR, for s390 vfio-pci devices. So now on an eventfd notification for error notifier it will invoke the s390x specific error handler. The s390x error handler will retrieve the architecture specific PCI error information and inject the information into the guest. Once the guest receives the error information, the guest drivers will drive the error recovery. Typically recovery involves a device reset which translate to CLP disable/enable cycle for the device.
I would appreciate some feedback on this patch series.
Thanks
Farhan
[1] https://lore.kernel.org/all/[email protected]/
ChangeLog
---------
v6 https://lore.kernel.org/all/[email protected]/
v6 -> v7
- Address Matt's feedback.
- Add an explicit check for pci_aer (patch 1).
- Change return code for s390_pci_get_feature_err() to return <0 on error and 0 (on ENOMSG) or 1 on success as suggested by Matt.
- Use common code function pci_device_reset() as it will invoke the VFIO_RESET_DEVICE ioctl.
- Change state from ZPCI_FS_ERROR to ZPCI_FS_DISABLED on a reset from error state.
v5 https://lore.kernel.org/all/[email protected]/
v5 -> v6
- Address Cedric's feedback (patch 1).
- Update error handling to follow QEMU style (patch 1).
- Rebase on master.
- Remove linux-headers update as latest QEMU master has the VFIO headers merged.
v4 https://lore.kernel.org/all/[email protected]/
v4 -> v5
- Remove err_handler() callback in vfio pci core.
- Update the vfio error notifier callback to an s390x specific callback for s390x devices
- Include linux headers for 7.3-rc3.
v3 https://lore.kernel.org/qemu-devel/[email protected]/
v3 -> v4
- Include linux headers for 7.3-rc1.
- Rework VFIO API changes based on the kernel API (patch 3).
- Address Markus's comments from v3 (patch 2).
v2 https://lore.kernel.org/qemu-devel/[email protected]/
v2 -> v3
- Update arch_err_handler to err_handler and include Error ** in function definition. (patch 2)
- Introduce helper function to hide the internal indirection of device_feature() (patch 3)
- Update function definitions to include Error ** (patch 4)
v1 https://lore.kernel.org/qemu-devel/[email protected]/
v1 -> v2
- Use VFIO_DEVICE_FEATURE ioctl to get device error information. (Based on Alex's feedback on kernel series)
Farhan Ali (2):
s390x/pci: Add PCI error handling for vfio pci devices s390x/pci: Reset a device in error state
hw/s390x/s390-pci-bus.c | 21 ++++++ hw/s390x/s390-pci-vfio-stubs.c | 6 ++ hw/s390x/s390-pci-vfio.c | 123 +++++++++++++++++++++++++++++++ include/hw/s390x/s390-pci-bus.h | 1 + include/hw/s390x/s390-pci-vfio.h | 1 + 5 files changed, 152 insertions(+)
Signature · 1 line
2.43.0
Re: [PATCH v7 2/2] s390x/pci: Reset a device in error state
In reply to Farhan AliQuoted 6 lines · Farhan Ali
For passthrough devices in error state, for a guest driven reset of the device we can attempt a reset to recover the device. A reset of the device will trigger a CLP disable/enable cycle on the host to bring the device into a recovered state.
Signed-off-by Farhan Ali <[email protected]>
Re: [PATCH v7 1/2] s390x/pci: Add PCI error handling for vfio pci devices
In reply to Farhan AliQuoted 9 lines · Farhan Ali
Add an s390x specific handler for vfio error notifier. For s390x pci devices, we have platform specific error information. We need to retrieve this error information for passthrough devices. This is done via a
VFIO_DEVICE_FEATUREioctl which exposes that information.Once this error information is retrieved we can then inject an error into the guest, and let the guest drive the recovery.
Signed-off-by Farhan Ali <[email protected]>
A few comments below but I think no changes required...
[...]
Quoted 5 lines
hw/s390x/s390-pci-vfio-stubs.c +0
-0
hw/s390x/s390-pci-vfio-stubs.c bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh) · line 38
Quoted 9 lines
hw/s390x/s390-pci-vfio-stubs.c +6
-0@@ -30,3 +30,9 @@ bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh)void s390_pci_get_clp_info (S390PCIBusDevice *pbdev) { } + +bool s390_pci_setup_err_handler (S390PCIBusDevice *pbdev,Error **errp) +{ +error_setg (errp,"VFIO not available, cannot setup error handler" ); +return false; +}
I wondered for a bit about whether g_assert_not_reached() makes sense here, since we never call it without first detecting a vfio-pci device, which should be impossible without VFIO.
But this should also be fine: it satisfies error.h if we were ever to get here, I just don't expect we will.
[...]
hw/s390x/s390-pci-vfio-stubs.c static void s390_pci_read_base(S390PCIBusDevice *pbdev, · line 215
Quoted 8 lines
hw/s390x/s390-pci-vfio-stubs.c +4
-0@@ -134,6 +209,10 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,/* Store function type separately for type-specific behavior */ pbdev->pft = cap->pft; +if (hdr->version >=3 ) { + pbdev->ccdf_err_length = cap->ccdf_err_length; + } +
This value won't be migrated if we also take Konstantin's migration series. But that's OK since it's vfio-pci-only and we still won't allow migration of s390x vfio-pci with his series.
It also looks like a value we want to re-acquire on the target system, not migrate.
Quoted 74 lines
hw/s390x/s390-pci-vfio-stubs.c +44
-0/* * If the device is a passthrough ISM device, disallow relaxed * translation. @@ -371,3 +450,47 @@ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)s390_pci_read_util (pbdev, info);s390_pci_read_pfip (pbdev, info); } + +bool s390_pci_setup_err_handler (S390PCIBusDevice *pbdev,Error **errp) +{ +int ret; +int32_t fd; +VFIOPCIDevice *vfio_pci =VFIO_PCI_DEVICE (pbdev->pdev); +uint64_t buf[DIV_ROUND_UP (sizeof (struct vfio_device_feature ), +sizeof (uint64_t ))] = {}; +struct vfio_device_feature *feature = (struct vfio_device_feature *)buf; + + feature->argsz =sizeof (buf); + feature->flags =VFIO_DEVICE_FEATURE_PROBE |VFIO_DEVICE_FEATURE_ZPCI_ERROR ; + + ret =vfio_device_get_feature (&vfio_pci->vbasedev, feature); + +if (ret !=0 ) { +if (ret == -ENOTTY ) { +error_setg (errp,"Automated error recovery unavailable for device" ); + }else { +error_setg (errp, +"Failed to probe for VFIO_DEVICE_FEATURE_ZPCI_ERROR (ret=%d)" , + ret); + } +return false; + } + +if (sizeof (PciCcdfErr) != pbdev->ccdf_err_length) { +error_setg (errp, +"CCDF size mismatch expected size=%zu, provided size=%d" , +sizeof (PciCcdfErr), pbdev->ccdf_err_length); +return false; + } + +if (!vfio_pci->pci_aer) { +error_setg (errp,"%s: VFIO error notifier not registered for device" , + vfio_pci->vbasedev.name); +return false; + } + + fd =event_notifier_get_fd (&vfio_pci->err_notifier); +qemu_set_fd_handler (fd, s390_pci_err_handler,NULL , vfio_pci); + +return true; +}include/hw/s390x/s390-pci-bus.h +1
-0@@ -365,6 +365,7 @@ struct S390PCIBusDevice {bool forwarding_assist;bool aif;bool rtr_avail; +uint32_t ccdf_err_length;QTAILQ_ENTRY (S390PCIBusDevice) link; };include/hw/s390x/s390-pci-vfio.h +1
-0@@ -20,5 +20,6 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,void s390_pci_end_dma_count (S390pciState *s,S390PCIDMACount *cnt);bool s390_pci_get_host_fh (S390PCIBusDevice *pbdev,uint32_t *fh);void s390_pci_get_clp_info (S390PCIBusDevice *pbdev); +bool s390_pci_setup_err_handler (S390PCIBusDevice *pbdev,Error **errp);#endif
Quoted 16 lines · Farhan Ali
Hi,
This patch series introduces support for error recovery for passthrough PCI devices on System Z (s390x). This is the user space component for the Linux kernel patches [1]. The kernel patches were merged for 7.3 release.
The current design for QEMU updates the callback for vfio error notifier to an s390x specific error handler if the kernel supports the new device feature
VFIO_DEVICE_FEATURE_ZPCI_ERROR, for s390 vfio-pci devices. So now on an eventfd notification for error notifier it will invoke the s390x specific error handler. The s390x error handler will retrieve the architecture specific PCI error information and inject the information into the guest. Once the guest receives the error information, the guest drivers will drive the error recovery. Typically recovery involves a device reset which translate to CLP disable/enable cycle for the device.
Quoted 4 lines
I would appreciate some feedback on this patch series.
Thanks
Farhan
@Eric: Series LGTM at this point, let's give Cédric and/or Alex some time to look too.
This series should also either go after Konstantin's migration series or at least we should take my patch from that series (s390x/pci: implement IOMMU replay) to ensure that is in place prior to enabling this recovery feature; basically, we want that patch with whichever feature lands first.
Thanks,
Matt
Quoted 17 lines · Matthew Rosato
Quoted 16 lines · Farhan Ali
Hi,
This patch series introduces support for error recovery for passthrough PCI devices on System Z (s390x). This is the user space component for the Linux kernel patches [1]. The kernel patches were merged for 7.3 release.
The current design for QEMU updates the callback for vfio error notifier to an s390x specific error handler if the kernel supports the new device feature
VFIO_DEVICE_FEATURE_ZPCI_ERROR, for s390 vfio-pci devices. So now on an eventfd notification for error notifier it will invoke the s390x specific error handler. The s390x error handler will retrieve the architecture specific PCI error information and inject the information into the guest. Once the guest receives the error information, the guest drivers will drive the error recovery. Typically recovery involves a device reset which translate to CLP disable/enable cycle for the device.
Quoted 7 lines
Quoted 4 lines
I would appreciate some feedback on this patch series.
Thanks
Farhan@Eric: Series LGTM at this point, let's give Cédric and/or Alex some time to look too.
Looks OK to me. The ERRP_GUARD() is not useful anymore but it is minor.
Thanks,
C.
Quoted 27 lines · Cédric Le Goater
Quoted 17 lines · Matthew Rosato
Quoted 16 lines · Farhan Ali
Hi,
This patch series introduces support for error recovery for passthrough PCI devices on System Z (s390x). This is the user space component for the Linux kernel patches [1]. The kernel patches were merged for 7.3 release.
The current design for QEMU updates the callback for vfio error notifier to an s390x specific error handler if the kernel supports the new device feature
VFIO_DEVICE_FEATURE_ZPCI_ERROR, for s390 vfio-pci devices. So now on an eventfd notification for error notifier it will invoke the s390x specific error handler. The s390x error handler will retrieve the architecture specific PCI error information and inject the information into the guest. Once the guest receives the error information, the guest drivers will drive the error recovery. Typically recovery involves a device reset which translate to CLP disable/enable cycle for the device.Quoted 7 lines
Quoted 4 lines
I would appreciate some feedback on this patch series.
Thanks
Farhan@Eric: Series LGTM at this point, let's give Cédric and/or Alex some time to look too.
Quoted 6 lines
Looks OK to me. The
ERRP_GUARD()is not useful anymore but it is minor.Thanks,
C.
Thanks, all! Applied to the s390x queue for 11.2