Error recovery for zPCI passthrough devices
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]. For QEMU on eventfd notification for PCI error from vfio-pci driver we call the vfio error handler. We can use an architecture specific error handler to override the default vfio error handler.
For s390x specific error handler, we 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 to understand if such an approach is acceptable.
Thanks
Farhan
[1] https://lore.kernel.org/linux-s390/[email protected]/T/#m7c763e718501a2bbd77f0356f8845b77545d61e1
Farhan Ali (4):
[NOTFORMERGE] linux-headers: Update for zpci vfio device vfio/pci: Add an architecture specific error handler s390x/pci: Add PCI error handling for vfio pci devices s390x/pci: Reset a device in error state
hw/s390x/s390-pci-bus.c | 12 +++++ hw/s390x/s390-pci-vfio.c | 88 ++++++++++++++++++++++++++++++++ hw/vfio/pci.c | 5 ++ hw/vfio/pci.h | 1 + include/hw/s390x/s390-pci-bus.h | 1 + include/hw/s390x/s390-pci-vfio.h | 4 ++ linux-headers/linux/vfio.h | 2 + linux-headers/linux/vfio_zdev.h | 5 ++ 8 files changed, 118 insertions(+)
Signature · 1 line
2.43.0
PATCH 1/4 linux-headers: Update for zpci vfio device
--- linux-headers/linux/vfio.h | 2 ++ linux-headers/linux/vfio_zdev.h | 5 +++++ 2 files changed, 7 insertions(+)
linux-headers/linux/vfio.h +2 -0
@@ -369,6 +369,8 @@ struct vfio_region_info_cap_type {*/ #define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD (1) +#define VFIO_REGION_SUBTYPE_IBM_ZPCI_ERROR_REGION (2) +/* sub-types for VFIO_REGION_TYPE_GFX */ #define VFIO_REGION_SUBTYPE_GFX_EDID (1)
linux-headers/linux/vfio_zdev.h +5 -0
@@ -82,4 +82,9 @@ struct vfio_device_info_cap_zpci_pfip { __u8 pfip[]; }; +struct vfio_device_zpci_err_region { +__u16 pec; +int pending_errors; +}; +#endif
Signature · 1 line
2.43.0
PATCH 2/4 vfio/pci: Add an architecture specific error handler
In reply to Farhan AliProvide a architecture specific error handling callback, that can be used by platforms to handle PCI errors for passthrough devices.
--- hw/vfio/pci.c | 5 +++++ hw/vfio/pci.h | 1 + 2 files changed, 6 insertions(+)
hw/vfio/pci.c +5 -0
@@ -3026,6 +3026,11 @@ static void vfio_err_notifier_handler(void *opaque)return ; } +if (vdev->arch_err_handler) { + vdev->arch_err_handler (vdev); +return ; + } +/* * TBD. Retrieve the error details and decide what action * needs to be taken. One of the actions could be to pass
hw/vfio/pci.h +1 -0
@@ -145,6 +145,7 @@ struct VFIOPCIDevice {EventNotifier err_notifier;EventNotifier req_notifier;int (*resetfn)(struct VFIOPCIDevice *); +void (*arch_err_handler)(struct VFIOPCIDevice *);uint32_t vendor_id;uint32_t device_id;uint32_t sub_vendor_id;
Signature · 1 line
2.43.0
PATCH 3/4 s390x/pci: Add PCI error handling for vfio pci devices
In reply to Farhan AliAdd an s390x specific callback for vfio error handling. 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 memory region 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 | 5 ++ hw/s390x/s390-pci-vfio.c | 82 ++++++++++++++++++++++++++++++++ include/hw/s390x/s390-pci-bus.h | 1 + include/hw/s390x/s390-pci-vfio.h | 2 + 4 files changed, 90 insertions(+)
hw/s390x/s390-pci-bus.c +5 -0
@@ -158,6 +158,8 @@ static void s390_pci_perform_unplug(S390PCIBusDevice *pbdev) {HotplugHandler *hotplug_ctrl; +qemu_mutex_destroy (&pbdev->err_handler_lock); +if (pbdev->pft ==ZPCI_PFT_ISM ) {notifier_remove (&pbdev->shutdown_notifier); }
@@ -1140,6 +1142,7 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev, pbdev->iommu->pbdev = pbdev; pbdev->state =ZPCI_FS_DISABLED ;set_pbdev_info (pbdev); +qemu_mutex_init (&pbdev->err_handler_lock);if (object_dynamic_cast (OBJECT (dev),"vfio-pci" )) {/*
@@ -1164,6 +1167,8 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev, 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 */ +s390_pci_setup_err_handler (pbdev);if (!pbdev->interp) {/* Do vfio passthrough but intercept for I/O */ pbdev->fh |=FH_SHM_VFIO ;
hw/s390x/s390-pci-vfio.c +82 -0
97 lines not on this page · raw message
include/hw/s390x/s390-pci-bus.h +1 -0
@@ -364,6 +364,7 @@ struct S390PCIBusDevice {bool forwarding_assist;bool aif;bool rtr_avail; +QemuMutex err_handler_lock;QTAILQ_ENTRY (S390PCIBusDevice) link; };
include/hw/s390x/s390-pci-vfio.h +2 -0
@@ -22,6 +22,7 @@ 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); +void s390_pci_setup_err_handler (S390PCIBusDevice *pbdev);#else static inline bool s390_pci_update_dma_avail (int fd,unsigned int *avail) {
@@ -39,6 +40,7 @@ static inline bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh)return false; }static inline void s390_pci_get_clp_info (S390PCIBusDevice *pbdev) { } +static inline void s390_pci_setup_err_handler (S390PCIBusDevice *pbdev) { }#endif #endif
Signature · 1 line
2.43.0
PATCH 4/4 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 hot reset to recover the device. A hot 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 | 7 +++++++ hw/s390x/s390-pci-vfio.c | 6 ++++++ include/hw/s390x/s390-pci-vfio.h | 2 ++ 3 files changed, 15 insertions(+)
hw/s390x/s390-pci-bus.c +7 -0
@@ -1493,6 +1493,8 @@ static void s390_pci_device_reset(DeviceState *dev)return ;case ZPCI_FS_STANDBY :break ; +case ZPCI_FS_ERROR : +break ;default : pbdev->fh &= ~FH_MASK_ENABLE ; pbdev->state =ZPCI_FS_DISABLED ;
@@ -1505,6 +1507,11 @@ static void s390_pci_device_reset(DeviceState *dev) }else if (pbdev->summary_ind) {pci_dereg_irqs (pbdev); } + +if (pbdev->state ==ZPCI_FS_ERROR ) { +s390_pci_reset (pbdev); + } +if (pbdev->iommu->enabled) {pci_dereg_ioat (pbdev->iommu); }
hw/s390x/s390-pci-vfio.c +6 -0
@@ -168,6 +168,12 @@ static void s390_pci_err_handler(VFIOPCIDevice *vfio_pci)return ; } +void s390_pci_reset (S390PCIBusDevice *pbdev) +{ +VFIOPCIDevice *vfio_pci =container_of (pbdev->pdev, VFIOPCIDevice, pdev); +ioctl (vfio_pci->vbasedev.fd,VFIO_DEVICE_RESET ); +} +static void s390_pci_read_base (S390PCIBusDevice *pbdev,struct vfio_device_info *info) {
include/hw/s390x/s390-pci-vfio.h +2 -0
@@ -23,6 +23,7 @@ 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);void s390_pci_setup_err_handler (S390PCIBusDevice *pbdev); +void s390_pci_reset (S390PCIBusDevice *pbdev);#else static inline bool s390_pci_update_dma_avail (int fd,unsigned int *avail) {
@@ -41,6 +42,7 @@ static inline bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh) }static inline void s390_pci_get_clp_info (S390PCIBusDevice *pbdev) { }static inline void s390_pci_setup_err_handler (S390PCIBusDevice *pbdev) { } +void s390_pci_reset (S390PCIBusDevice *pbdev) { }#endif #endif
Signature · 1 line
2.43.0