Skip to contentSkip to conversation

Error recovery for zPCI passthrough devices

PATCH Superseded Farhan Ali 4 participants 21 messages Aug 31 – Sep 8 RISC-V

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Farhan Ali

author
#0 lore raw

v4 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 and it had some significant changes in VFIO API since the last QEMU series was posted. But the design for QEMU component is still the same.

For QEMU on eventfd notification for PCI error from vfio-pci driver we call the vfio error handler. We can use a per device error handler callback 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.

Thanks
Farhan

[1] https://lore.kernel.org/all/[email protected]/

ChangeLog
---------
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 (4):
linux-headers: Update Linux header to 7.3-rc1 vfio/pci: Add an error handler callback s390x/pci: Add PCI error handling for vfio pci devices s390x/pci: Reset a device in error state

 hw/s390x/s390-pci-bus.c                     |  16 ++
 hw/s390x/s390-pci-vfio-stubs.c              |  10 +
 hw/s390x/s390-pci-vfio.c                    | 110 +++++++++++
 hw/vfio/pci.c                               |  27 ++-
 hw/vfio/pci.h                               |   1 +
 include/hw/s390x/s390-pci-bus.h             |   2 +
 include/hw/s390x/s390-pci-vfio.h            |   2 +
 include/standard-headers/drm/drm_fourcc.h   | 209 ++++++++++++++++++--
 include/standard-headers/linux/ethtool.h    |   6 +
 include/standard-headers/linux/fuse.h       |  63 +++++-
 include/standard-headers/linux/virtio_ids.h |   1 +
 linux-headers/asm-arm64/kvm.h               |   1 +
 linux-headers/asm-riscv/kvm.h               |  13 ++
 linux-headers/linux/iommufd.h               |  45 ++++-
 linux-headers/linux/kvm.h                   |   1 +
 linux-headers/linux/userfaultfd.h           |  54 ++++-
 linux-headers/linux/vduse.h                 |  28 +++
 linux-headers/linux/vfio.h                  |  21 ++
 linux-headers/linux/vfio_zdev.h             |   2 +
 19 files changed, 579 insertions(+), 33 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v4 1/4 linux-headers: Update Linux header to 7.3-rc1

Update the headers to include VFIO and zPCI VFIO changes.

---
 include/standard-headers/drm/drm_fourcc.h   | 209 ++++++++++++++++++--
 include/standard-headers/linux/ethtool.h    |   6 +
 include/standard-headers/linux/fuse.h       |  63 +++++-
 include/standard-headers/linux/virtio_ids.h |   1 +
 linux-headers/asm-arm64/kvm.h               |   1 +
 linux-headers/asm-riscv/kvm.h               |  13 ++
 linux-headers/linux/iommufd.h               |  45 ++++-
 linux-headers/linux/kvm.h                   |   1 +
 linux-headers/linux/userfaultfd.h           |  54 ++++-
 linux-headers/linux/vduse.h                 |  28 +++
 linux-headers/linux/vfio.h                  |  21 ++
 linux-headers/linux/vfio_zdev.h             |   2 +
 12 files changed, 417 insertions(+), 27 deletions(-)
include/standard-headers/drm/drm_fourcc.h +191 -18
index 2ba0b5c925..ca4f4e3d8c 100644
@@ -1645,36 +1645,69 @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier)
  * For multi-plane formats the above surfaces get merged into one plane for
  * each format plane, based on the required alignment only.
  *
- * Bits  Parameter                Notes
- * ----- ------------------------ ---------------------------------------------
+ * Bits    Parameter                Notes
+ * ------- ------------------------ ---------------------------------------------
+ *
+ * DRM format modifier fields on AMD GPUs:
+ *     7:0 TILE_VERSION             Values are AMD_FMT_MOD_TILE_VER_*
+ *    12:8 TILE                     Values are AMD_FMT_MOD_TILE_<version>_*
+ *      13 DCC                      Delta Color Compression, supported on GFX8 and newer
+ *   55:14 (chip specific)          See below for details, depends on GFX block version
+ *   63:56 Vendor                   Value is DRM_FORMAT_MOD_VENDOR_AMD
+ *
+ * Chip specific fields on Gfx9 and newer:
+ *      14 DCC_RETILE
+ *      15 DCC_PIPE_ALIGN
+ *      16 DCC_INDEPENDENT_64B
+ *      17 DCC_INDEPENDENT_128B
+ *   19:18 DCC_MAX_COMPRESSED_BLOCK Values are AMD_FMT_MOD_DCC_BLOCK_*
+ *      20 DCC_CONSTANT_ENCODE
+ *   23:21 PIPE_XOR_BITS            Only for some chips
+ *   26:24 BANK_XOR_BITS            Only for some chips
+ *   29:27 PACKERS                  Only for some chips
+ *   32:30 RB                       Only for some chips
+ *   35:33 PIPE                     Only for some chips
+ *   55:36 -                        Reserved for future use, must be zero
+ *
+ * Chip specific fields on Gfx6-8:
+ *   16:14 MICROTILE                Micro tile format
+ *   21:17 PIPE_CONFIG              Number of pipes and how pipes are interleaved
+ *   24:22 TILE_SPLIT               Tile split size
+ *   26:25 BANK_WIDTH               Number of tiles in the X direction in the same bank
+ *   28:27 BANK_HEIGHT              Number of tiles in the Y direction in the same bank
+ *   30:29 MACRO_TILE_ASPECT        Macro tile aspect ratio
+ *   32:31 NUM_BANKS                Number of banks
+ *   55:33 -                        Reserved for future use, must be zero
  *
- *   7:0 TILE_VERSION             Values are AMD_FMT_MOD_TILE_VER_*
- *  12:8 TILE                     Values are AMD_FMT_MOD_TILE_<version>_*
- *    13 DCC
- *    14 DCC_RETILE
- *    15 DCC_PIPE_ALIGN
- *    16 DCC_INDEPENDENT_64B
- *    17 DCC_INDEPENDENT_128B
- * 19:18 DCC_MAX_COMPRESSED_BLOCK Values are AMD_FMT_MOD_DCC_BLOCK_*
- *    20 DCC_CONSTANT_ENCODE
- * 23:21 PIPE_XOR_BITS            Only for some chips
- * 26:24 BANK_XOR_BITS            Only for some chips
- * 29:27 PACKERS                  Only for some chips
- * 32:30 RB                       Only for some chips
- * 35:33 PIPE                     Only for some chips
- * 55:36 -                        Reserved for future use, must be zero
  */
 #define AMD_FMT_MOD fourcc_mod_code(AMD, 0)
 
 #define IS_AMD_FMT_MOD(val) (((val) >> 56) == DRM_FORMAT_MOD_VENDOR_AMD)
 
-/* Reserve 0 for GFX8 and older */
+#define AMD_FMT_MOD_TILE_VER_GFX6 0
 #define AMD_FMT_MOD_TILE_VER_GFX9 1
 #define AMD_FMT_MOD_TILE_VER_GFX10 2
 #define AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS 3
 #define AMD_FMT_MOD_TILE_VER_GFX11 4
 #define AMD_FMT_MOD_TILE_VER_GFX12 5
 
+/*
+ * Gfx6-8 tiling modes.
+ * A complete reference implementation is found in addrlib in the Mesa code base.
+ *
+ * - Microtiled modes (1D):
+ *   Pixel data is organized into micro tiles of 8x8 pixels.
+ *
+ * - Macrotiled modes (2D):
+ *   Micro tiles are further organized into macro tiles.
+ *   These are optimized for even load distribution among memory channels.
+ *
+ * Note that only THIN1 modes are exposed here.
+ * THICK and XTHICK are for 3D images and not relevant to DRM format modifiers.
+ */
+#define AMD_FMT_MOD_TILE_GFX6_1D_TILED_THIN1 0x2
+#define AMD_FMT_MOD_TILE_GFX6_2D_TILED_THIN1 0x4
+
 /*
  * 64K_S is the same for GFX9/GFX10/GFX10_RBPLUS and hence has GFX9 as canonical
  * version.
@@ -1773,6 +1806,146 @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier)
 #define AMD_FMT_MOD_PIPE_SHIFT 33
 #define AMD_FMT_MOD_PIPE_MASK 0x7
 
+/*
+ * MICRO_TILE_MODE, 3 bits. Determines the micro tile format.
+ * Only relevant to Gfx6-8.
+ *
+ * DISPLAY - Displayable tiling
+ * THIN - Non-displayable tiling, a.k.a thin micro tiling
+ * DEPTH, THICK - not exposed, not relevant to DRM format modifier use cases
+ * ROTATED - not exposed, not implemented in Linux or Mesa
+ */
+#define AMD_FMT_MOD_MICROTILE_SHIFT 14ULL
+#define AMD_FMT_MOD_MICROTILE_MASK 0x7
+
+#define AMD_FMT_MOD_MICROTILE_DISPLAY 0x0
+#define AMD_FMT_MOD_MICROTILE_THIN 0x1
+
+/*
+ * PIPE_CONFIG, 5 bits. Number of pipes and how pipes are interleaved on the surface,
+ * which means the shader engine tile size and packer tile size.
+ * Typically matches the number of memory channels, or number of RBs.
+ * Only relevant to Gfx6-8 macro tiled modes.
+ *
+ * P<n>_<a>x<b>_<c>x<d>
+ * where:
+ * <n> - number of pipes
+ * <a>x<b> - shader engine tile size
+ * <c>x<d> - packer tile size
+ */
+#define AMD_FMT_MOD_PIPE_CONFIG_SHIFT 17ULL
+#define AMD_FMT_MOD_PIPE_CONFIG_MASK 0x1f
+
+#define AMD_FMT_MOD_PIPE_CONFIG_P2 0x0
+#define AMD_FMT_MOD_PIPE_CONFIG_P4_8x16 0x4
+#define AMD_FMT_MOD_PIPE_CONFIG_P4_16x16 0x5
+#define AMD_FMT_MOD_PIPE_CONFIG_P4_16x32 0x6
+#define AMD_FMT_MOD_PIPE_CONFIG_P4_32x32 0x7
+#define AMD_FMT_MOD_PIPE_CONFIG_P8_16x16_8x16 0x8
+#define AMD_FMT_MOD_PIPE_CONFIG_P8_16x32_8x16 0x9
+#define AMD_FMT_MOD_PIPE_CONFIG_P8_32x32_8x16 0xa
+#define AMD_FMT_MOD_PIPE_CONFIG_P8_16x32_16x16 0xb
+#define AMD_FMT_MOD_PIPE_CONFIG_P8_32x32_16x16 0xc
+#define AMD_FMT_MOD_PIPE_CONFIG_P8_32x32_16x32 0xd
+#define AMD_FMT_MOD_PIPE_CONFIG_P8_32x64_32x32 0xe
+#define AMD_FMT_MOD_PIPE_CONFIG_P16_32x32_8x16 0x10
+#define AMD_FMT_MOD_PIPE_CONFIG_P16_32x32_16x16 0x11
+
+/*
+ * TILE_SPLIT, 3 bits.
+ * Only relevant to Gfx6-8 macro tiled modes.
+ *
+ * On GFX6 (or with depth tiling modes on GFX7 and newer),
+ * the GFX block uses the GB_TILE_MODE.TILE_SPLIT field directly.
+ *
+ * On GFX7 and newer with non-depth tiling modes, the GFX block uses a
+ * split factor which is stored in the GB_TILE_MODE.SAMPLE_SPLIT field.
+ * SAMPLE_SPLIT may be: 0 - 1 byte; 1 - 2 bytes; 2 - 4 bytes; 3 - 8 bytes.
+ * The actual tile size and tile split bytes are calculated as follows:
+ *
+ *    bpp = ... <- bits per pixel in the current image
+ *    thickness = ... <- depends on array mode; may be: 1, 4, 8
+ *    num_samples = ... <- number of samples in the current image
+ *    tile_size_pixels = 8 * 8
+ *    tile_bytes_1x = thickness * tile_size_pixels * bpp / 8
+ *    sample_split_factor = 1 << SAMPLE_SPLIT
+ *    tile_split_bytes = clamp(tile_bytes_1x * sample_split_factor, 256, dram_row_size_bytes)
+ *    tile_bytes = clamp(tile_bytes_1x * num_samples, 64, tile_split_bytes)
+ *
+ * In both cases, the display block (DCE) has no SAMPLE_SPLIT
+ * and just needs the tile split bytes in the GRPH_CONTROL.GRPH_TILE_SPLIT field.
+ * To maximize compatibility between GFX6-7, we don't include the SAMPLE_SPLIT
+ * in the format modifiers.
+ *
+ * The actual tile split in bytes is: 64 << field value
+ * Possible values of this field:
+ *
+ * 0 - Tile split is 64 bytes
+ * 1 - Tile split is 128 bytes
+ * 2 - Tile split is 256 bytes
+ * 3 - Tile split is 512 bytes
+ * 4 - Tile split is 1 KiB
+ * 5 - Tile split is 2 KiB
+ * 6 - Tile split is 4 KiB
+ */
+#define AMD_FMT_MOD_TILE_SPLIT_SHIFT 22ULL
+#define AMD_FMT_MOD_TILE_SPLIT_MASK 0x7
+
+/*
+ * BANK_WIDTH, 2 bits. Number of tiles in the X direction in the same bank.
+ * Only relevant to Gfx6-8 macro tiled modes.
+ * The actual bank width is: 1 << field value
+ * Possible values:
+ *
+ * 0 - bank width is 1
+ * 1 - bank width is 2
+ * 2 - bank width is 4
+ * 3 - bank width is 8
+ */
+#define AMD_FMT_MOD_BANK_WIDTH_SHIFT 25ULL
+#define AMD_FMT_MOD_BANK_WIDTH_MASK 0x3
+
+/*
+ * BANK_HEIGHT, 2 bits. Number of tiles in the Y direction in the same bank.
+ * Only relevant to Gfx6-8 macro tiled modes.
+ * The actual bank height is: 1 << field value
+ * Possible values:
+ *
+ * 0 - bank height is 1
+ * 1 - bank height is 2
+ * 2 - bank height is 4
+ * 3 - bank height is 8
+ */
+#define AMD_FMT_MOD_BANK_HEIGHT_SHIFT 27ULL
+#define AMD_FMT_MOD_BANK_HEIGHT_MASK 0x3
+
+/*
+ * MACRO_TILE_ASPECT, 2 bits. Macro tile aspect ratio.
+ * Only relevant to Gfx6-8 macro tiled modes.
+ * Possible values:
+ *
+ * 0 - aspect ratio is 1:1
+ * 1 - aspect ratio is 4:1
+ * 2 - aspect ratio is 16:1
+ * 3 - aspect ratio is 64:1
+ */
+#define AMD_FMT_MOD_MACRO_TILE_ASPECT_SHIFT 29ULL
+#define AMD_FMT_MOD_MACRO_TILE_ASPECT_MASK 0x3
+
+/*
+ * NUM_BANKS, 2 bits. Number of banks.
+ * Only relevant to Gfx6-8 macro tiled modes.
+ * The actual number of banks is: 2 << field value
+ * Possible values:
+ *
+ * 0 - number of banks is 2
+ * 1 - number of banks is 4
+ * 2 - number of banks is 8
+ * 3 - number of banks is 16
+ */
+#define AMD_FMT_MOD_NUM_BANKS_SHIFT 31ULL
+#define AMD_FMT_MOD_NUM_BANKS_MASK 0x3
+
 #define AMD_FMT_MOD_SET(field, value) \
 	((uint64_t)(value) << AMD_FMT_MOD_##field##_SHIFT)
 #define AMD_FMT_MOD_GET(field, value) \
include/standard-headers/linux/ethtool.h +6 -0
index 55f608c3a7..622d634d04 100644
@@ -2015,7 +2015,13 @@ enum ethtool_link_mode_bit_indices {
 	ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT	= 39,
 	ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT		= 40,
 	ETHTOOL_LINK_MODE_1000baseX_Full_BIT	= 41,
+
+	/* Despite the "baseCR" in 10000baseCR, this is not an IEEE 802.3 baseCR
+	 * It represents SFF-8431 Appendix-E SFP+ Direct Attach (10G-SFI-DA).
+	 * The name is kept as-is for uAPI backward compatibility.
+	 */
 	ETHTOOL_LINK_MODE_10000baseCR_Full_BIT	= 42,
+
 	ETHTOOL_LINK_MODE_10000baseSR_Full_BIT	= 43,
 	ETHTOOL_LINK_MODE_10000baseLR_Full_BIT	= 44,
 	ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT	= 45,
include/standard-headers/linux/fuse.h +61 -2

125 lines not on this page · raw message

include/standard-headers/linux/virtio_ids.h +1 -0
index 6c12db16fa..f9056af0c6 100644
@@ -69,6 +69,7 @@
 #define VIRTIO_ID_BT			40 /* virtio bluetooth */
 #define VIRTIO_ID_GPIO			41 /* virtio gpio */
 #define VIRTIO_ID_SPI			45 /* virtio spi */
+#define VIRTIO_ID_MEDIA			48 /* virtio media */
 
 /*
  * Virtio Transitional IDs
linux-headers/asm-arm64/kvm.h +1 -0
index 6aefe79738..780cc7f729 100644
@@ -106,6 +106,7 @@ struct kvm_regs {
 #define KVM_ARM_VCPU_PTRAUTH_GENERIC	6 /* VCPU uses generic authentication */
 #define KVM_ARM_VCPU_HAS_EL2		7 /* Support nested virtualization */
 #define KVM_ARM_VCPU_HAS_EL2_E2H0	8 /* Limit NV support to E2H RES0 */
+#define KVM_ARM_VCPU_PMU_V3_STRICT	9 /* No default PMU creation */
 
 struct kvm_vcpu_init {
 	__u32 target;
linux-headers/asm-riscv/kvm.h +13 -0
index 504e733053..20d9959ca4 100644
@@ -102,6 +102,11 @@ struct kvm_riscv_smstateen_csr {
 	unsigned long sstateen0;
 };
 
+/* Zicfiss CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
+struct kvm_riscv_zicfiss_csr {
+	unsigned long ssp;
+};
+
 /* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
 struct kvm_riscv_timer {
 	__u64 frequency;
@@ -199,6 +204,8 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_ZCLSD,
 	KVM_RISCV_ISA_EXT_ZILSD,
 	KVM_RISCV_ISA_EXT_ZALASR,
+	KVM_RISCV_ISA_EXT_ZICFILP,
+	KVM_RISCV_ISA_EXT_ZICFISS,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
@@ -240,6 +247,9 @@ struct kvm_riscv_sbi_fwft_feature {
 struct kvm_riscv_sbi_fwft {
 	struct kvm_riscv_sbi_fwft_feature misaligned_deleg;
 	struct kvm_riscv_sbi_fwft_feature pointer_masking;
+	struct kvm_riscv_sbi_fwft_feature pte_ad_hw_updating;
+	struct kvm_riscv_sbi_fwft_feature landing_pad;
+	struct kvm_riscv_sbi_fwft_feature shadow_stack;
 };
 
 /* If you need to interpret the index values, here is the key: */
@@ -263,12 +273,15 @@ struct kvm_riscv_sbi_fwft {
 #define KVM_REG_RISCV_CSR_GENERAL	(0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
 #define KVM_REG_RISCV_CSR_AIA		(0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
 #define KVM_REG_RISCV_CSR_SMSTATEEN	(0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
+#define KVM_REG_RISCV_CSR_ZICFISS	(0x3 << KVM_REG_RISCV_SUBTYPE_SHIFT)
 #define KVM_REG_RISCV_CSR_REG(name)	\
 		(offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long))
 #define KVM_REG_RISCV_CSR_AIA_REG(name)	\
 	(offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long))
 #define KVM_REG_RISCV_CSR_SMSTATEEN_REG(name)  \
 	(offsetof(struct kvm_riscv_smstateen_csr, name) / sizeof(unsigned long))
+#define KVM_REG_RISCV_CSR_ZICFISS_REG(name)  \
+	(offsetof(struct kvm_riscv_zicfiss_csr, name) / sizeof(unsigned long))
 
 /* Timer registers are mapped as type 4 */
 #define KVM_REG_RISCV_TIMER		(0x04 << KVM_REG_RISCV_TYPE_SHIFT)
linux-headers/linux/iommufd.h +42 -3

79 lines not on this page · raw message

linux-headers/linux/kvm.h +1 -0
index aea4ab5c69..f21c47bf8d 100644
@@ -987,6 +987,7 @@ struct kvm_enable_cap {
 #define KVM_CAP_S390_VSIE_ESAMODE 248
 #define KVM_CAP_S390_HPAGE_2G 249
 #define KVM_CAP_PPC_COMPAT_CAPS 250
+#define KVM_CAP_ARM_PMU_V3_STRICT 251
 
 struct kvm_irq_routing_irqchip {
 	__u32 irqchip;
linux-headers/linux/userfaultfd.h +50 -4

128 lines not on this page · raw message

linux-headers/linux/vduse.h +28 -0
index e19b3c0f51..bab47129db 100644
@@ -14,6 +14,12 @@
 
 #define VDUSE_API_VERSION_1	1
 
+/* The VDUSE instance expects a request for vq ready */
+#define VDUSE_F_QUEUE_READY	0
+
+/* The VDUSE instance expects a request for suspend */
+#define VDUSE_F_SUSPEND		1
+
 /*
  * Get the version of VDUSE API that kernel supported (VDUSE_API_VERSION).
  * This is used for future extension.
@@ -63,6 +69,12 @@ struct vduse_dev_config {
  */
 #define VDUSE_DESTROY_DEV	_IOW(VDUSE_BASE, 0x03, char[VDUSE_NAME_MAX])
 
+/* Get the VDUSE supported features */
+#define VDUSE_GET_FEATURES	_IOR(VDUSE_BASE, 0x04, __u64)
+
+/* Set the VDUSE features */
+#define VDUSE_SET_FEATURES	_IOW(VDUSE_BASE, 0x05, __u64)
+
 /* The ioctls for VDUSE device (/dev/vduse/$NAME) */
 
 /**
@@ -325,6 +337,8 @@ enum vduse_req_type {
 	VDUSE_SET_STATUS,
 	VDUSE_UPDATE_IOTLB,
 	VDUSE_SET_VQ_GROUP_ASID,
+	VDUSE_SET_VQ_READY,
+	VDUSE_SUSPEND,
 };
 
 /**
@@ -372,6 +386,15 @@ struct vduse_iova_range_v2 {
 	__u32 padding;
 };
 
+/**
+ * struct vduse_vq_ready - Virtqueue ready request message
+ * @num: Virtqueue number
+ */
+struct vduse_vq_ready {
+	__u32 num;
+	__u32 ready;
+};
+
 /**
  * struct vduse_dev_request - control request
  * @type: request type
@@ -382,6 +405,7 @@ struct vduse_iova_range_v2 {
  * @iova: IOVA range for updating
  * @iova_v2: IOVA range for updating if API_VERSION >= 1
  * @vq_group_asid: ASID of a virtqueue group
+ * @vq_ready: Virtqueue ready request
  * @padding: padding
  *
  * Structure used by read(2) on /dev/vduse/$NAME.
@@ -399,6 +423,10 @@ struct vduse_dev_request {
 		 */
 		struct vduse_iova_range_v2 iova_v2;
 		struct vduse_vq_group_asid vq_group_asid;
+
+		/* Only if VDUSE_F_QUEUE_READY is negotiated */
+		struct vduse_vq_ready vq_ready;
+
 		__u32 padding[32];
 	};
 };
linux-headers/linux/vfio.h +21 -0
index f3282b8e86..c85dcbfe30 100644
@@ -1534,6 +1534,27 @@ struct vfio_device_feature_dma_buf {
  */
 #define VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2  12
 
+/**
+ * VFIO_DEVICE_FEATURE_ZPCI_ERROR feature provides PCI error information to
+ * userspace for vfio-pci devices on s390. On s390, PCI error recovery
+ * involves platform firmware and notification to operating systems is done
+ * by architecture specific mechanism. Exposing this information to
+ * userspace allows it to take appropriate actions to handle an
+ * error on the device.
+ *
+ * Userspace provides an opaque buffer of fixed length, and the kernel
+ * fills it with the zpci_ccdf_err data structure. The length of
+ * zpci_ccdf_err is provided to userspace via the
+ * VFIO_DEVICE_INFO_CAP_ZPCI_BASE capability.
+ *
+ * The ioctl returns -ENOMSG if there are no pending PCI errors.
+ */
+struct vfio_device_feature_zpci_err {
+	__aligned_u64 data;
+};
+
+#define VFIO_DEVICE_FEATURE_ZPCI_ERROR 13
+
 /* -------- API for Type1 VFIO IOMMU -------- */
 
 /**
linux-headers/linux/vfio_zdev.h +2 -0
index 77f2aff1f2..d6c1175c88 100644
@@ -32,6 +32,8 @@ struct vfio_device_info_cap_zpci_base {
 	/* End of version 1 */
 	__u32 fh;		/* PCI function handle */
 	/* End of version 2 */
+	__u32 ccdf_err_length;	/* PCI CCDF length */
+	/* End of version 3 */
 };
 
 /**
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v4 2/4 vfio/pci: Add an error handler callback

In reply to Farhan Ali

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
 hw/vfio/pci.c | 27 +++++++++++++++++++++------
 hw/vfio/pci.h |  1 +
 2 files changed, 22 insertions(+), 6 deletions(-)
hw/vfio/pci.c +21 -6
index 428ab2f069..a2f489b34d 100644
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev)
 static void vfio_err_notifier_handler(void *opaque)
 {
     VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
 
     if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
         return;
     }
 
     /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate the
      * guest to contain the error.
      */
 
-    error_report("%s(%s) Unrecoverable error detected. Please collect any data possible and then kill the guest", __func__, vdev->vbasedev.name);
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }
+
+    if (err) {
+        error_prepend(&err, "Unrecoverable PCIe error detected for device %s",
+                      vdev->vbasedev.name);
+        error_report_err(err);
+    } else {
+        error_printf("Unrecoverable PCIe error detected for device %s",
+                     vdev->vbasedev.name);
+    }
+    error_printf("Please collect any data possible and then kill the guest");
 
     vm_stop(RUN_STATE_INTERNAL_ERROR);
 }
hw/vfio/pci.h +1 -0
index c9ab949870..c067bbbebc 100644
@@ -146,6 +146,7 @@ struct VFIOPCIDevice {
     EventNotifier err_notifier;
     EventNotifier req_notifier;
     int (*resetfn)(struct VFIOPCIDevice *);
+    bool (*err_handler)(struct VFIOPCIDevice *, Error **);
     uint32_t vendor_id;
     uint32_t device_id;
     uint32_t sub_vendor_id;
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

+Shameer, who is looking at forwarding AER errors to guest :

https://lore.kernel.org/qemu-devel/SJ0PR12MB8614DDFEE3A9575564EDEF99ABFF2@SJ0PR12MB8614.namprd12.prod.outlook.com/

Quoted 43 lines · Farhan Ali

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
  hw/vfio/pci.c | 27 +++++++++++++++++++++------
  hw/vfio/pci.h |  1 +
  2 files changed, 22 insertions(+), 6 deletions(-)
hw/vfio/pci.c +11 -6
index 428ab2f069..a2f489b34d 100644
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev)
  static void vfio_err_notifier_handler(void *opaque)
  {
      VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
 
      if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
          return;
      }
 
      /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate the
       * guest to contain the error.
       */
 
-    error_report("%s(%s) Unrecoverable error detected. Please collect any data possible and then kill the guest", __func__, vdev->vbasedev.name);
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev) · line 3276

Quoted 10 lines
hw/vfio/pci.c +10 -0
+
+    if (err) {
+        error_prepend(&err, "Unrecoverable PCIe error detected for device %s",
+                      vdev->vbasedev.name);
+        error_report_err(err);
+    } else {
+        error_printf("Unrecoverable PCIe error detected for device %s",
+                     vdev->vbasedev.name);
+    }
+    error_printf("Please collect any data possible and then kill the guest");

how about that instead :

  if (err) {
      error_report("Unrecoverable PCIe error detected for device %s: %s",
                   vdev->vbasedev.name, error_get_pretty(err));
      error_free(err);
  } else {
      error_report("Unrecoverable PCIe error detected for device %s",
                   vdev->vbasedev.name);
  }
  error_printf("Please collect any data possible and then kill the guest\n");

hw/vfio/pci.h struct VFIOPCIDevice { · line 149

Quoted 12 lines
hw/vfio/pci.c +0 -0
      vm_stop(RUN_STATE_INTERNAL_ERROR);
  }
hw/vfio/pci.h +1 -0
index c9ab949870..c067bbbebc 100644
@@ -146,6 +146,7 @@ struct VFIOPCIDevice {
      EventNotifier err_notifier;
      EventNotifier req_notifier;
      int (*resetfn)(struct VFIOPCIDevice *);
+    bool (*err_handler)(struct VFIOPCIDevice *, Error **);

Please add documentation, something like :

/*
* Platform-specific error recovery handler.
*
* Called when the host reports a PCI error via the VFIO error notifier.
* The handler should attempt to recover the device and forward the
* error to the guest if the platform supports it.
*
* @vdev: the VFIO PCI device that triggered the error
* @errp: set with the failure reason on false return
*
* Return true on success, the VM continues running.
* Return false on failure and set @errp, the VM will be stopped. */
bool (*err_handler)(struct VFIOPCIDevice *vdev, Error **errp);

That said, I'd prefer to see AER forwarding first.

Thanks,

C.

Quoted 3 lines
hw/vfio/pci.h +0 -0
      uint32_t vendor_id;
      uint32_t device_id;
      uint32_t sub_vendor_id;
#4 lore raw

RE: [PATCH v4 2/4] vfio/pci: Add an error handler callback

Quoted 12 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 02 September 2026 09:08
To: Farhan Ali <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shameer Kolothum Thodi <[email protected]>
Subject: Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

Quoted 4 lines

External email: Use caution opening links or attachments

+Shameer, who is looking at forwarding AER errors to guest :

Thanks Cédric.

I have sent out a kernel RFC series yesterday:
https://lore.kernel.org/all/[email protected]/

Please take a look. Probably this series can be extended later to come with a generic AER error handling incorporating the new eventfd proposed in that RFC. I will go through this one.

Thanks,
Shameer

Quoted 118 lines

https://lore.kernel.org/qemu-
devel/[email protected] amprd12.prod.outlook.com/

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice

Quoted 14 lines · Farhan Ali

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
  hw/vfio/pci.c | 27 +++++++++++++++++++++------
  hw/vfio/pci.h |  1 +
  2 files changed, 22 insertions(+), 6 deletions(-)
hw/vfio/pci.c index renamed from hw/vfio/pci.c +0 -0

428ab2f069..a2f489b34d 100644

hw/vfio/pci.c +0 -0
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice

*vdev)

Quoted 17 lines
hw/vfio/pci.c +3 -5
  static void vfio_err_notifier_handler(void *opaque)
  {
      VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
 
      if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
          return;
      }
 
      /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev)

Quoted 10 lines
hw/vfio/pci.c +6 -1
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate
+ the
       * guest to contain the error.
       */
 
-    error_report("%s(%s) Unrecoverable error detected. Please collect any

data possible and then kill the guest", __func__, vdev->vbasedev.name);

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev)

Quoted 6 lines
hw/vfio/pci.c +6 -0
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }
+
+    if (err) {
+        error_prepend(&err, "Unrecoverable PCIe error detected for device

%s",

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev)

Quoted 8 lines
hw/vfio/pci.c +8 -0
+                      vdev->vbasedev.name);
+        error_report_err(err);
+    } else {
+        error_printf("Unrecoverable PCIe error detected for device %s",
+                     vdev->vbasedev.name);
+    }
+    error_printf("Please collect any data possible and then kill the
+ guest");

how about that instead :

   if (err) {
       error_report("Unrecoverable PCIe error detected for device %s: %s",
                    vdev->vbasedev.name, error_get_pretty(err));
       error_free(err);
   } else {
       error_report("Unrecoverable PCIe error detected for device %s",
                    vdev->vbasedev.name);
   }
   error_printf("Please collect any data possible and then kill the guest\n");

hw/vfio/pci.h struct VFIOPCIDevice { · line 149

Quoted 12 lines
hw/vfio/pci.c +0 -0
      vm_stop(RUN_STATE_INTERNAL_ERROR);
  }
hw/vfio/pci.h index renamed from hw/vfio/pci.h +0 -0

c9ab949870..c067bbbebc 100644

hw/vfio/pci.h +1 -0
@@ -146,6 +146,7 @@ struct VFIOPCIDevice {
      EventNotifier err_notifier;
      EventNotifier req_notifier;
      int (*resetfn)(struct VFIOPCIDevice *);
+    bool (*err_handler)(struct VFIOPCIDevice *, Error **);

Please add documentation, something like :

/*
* Platform-specific error recovery handler.
*
* Called when the host reports a PCI error via the VFIO error notifier.
* The handler should attempt to recover the device and forward the
* error to the guest if the platform supports it.
*
* @vdev: the VFIO PCI device that triggered the error
* @errp: set with the failure reason on false return
*
* Return true on success, the VM continues running.
* Return false on failure and set @errp, the VM will be stopped. */
bool (*err_handler)(struct VFIOPCIDevice *vdev, Error **errp);

That said, I'd prefer to see AER forwarding first.

Thanks,

C.

Quoted 3 lines
hw/vfio/pci.h +0 -0
      uint32_t vendor_id;
      uint32_t device_id;
      uint32_t sub_vendor_id;
#5 lore raw

Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

In reply to Cédric Le Goater
Quoted 44 lines · Cédric Le Goater

+Shameer, who is looking at forwarding AER errors to guest :

   https://lore.kernel.org/qemu-devel/SJ0PR12MB8614DDFEE3A9575564EDEF99ABFF2@SJ0PR12MB8614.namprd12.prod.outlook.com/
Quoted 39 lines · Farhan Ali

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
  hw/vfio/pci.c | 27 +++++++++++++++++++++------
  hw/vfio/pci.h |  1 +
  2 files changed, 22 insertions(+), 6 deletions(-)
hw/vfio/pci.c +8 -5
index 428ab2f069..a2f489b34d 100644
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev)
  static void vfio_err_notifier_handler(void *opaque)
  {
      VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
 
      if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
          return;
      }
 
      /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate the
       * guest to contain the error.
       */
 
Quoted 8 lines

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev) · line 3270

Quoted 8 lines
hw/vfio/pci.c +7 -1
-    error_report("%s(%s) Unrecoverable error detected. Please collect any data possible and then kill the guest", __func__, vdev->vbasedev.name);
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }
+
+    if (err) {
+        error_prepend(&err, "Unrecoverable PCIe error detected for device %s",
+                      vdev->vbasedev.name);

This requires use of ERRP_GUARD(). See "Why, when and how to use ERRP_GUARD()" in qapi/error.h.

Quoted 9 lines

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev) · line 3276

Quoted 6 lines
hw/vfio/pci.c +6 -0
+        error_report_err(err);
+    } else {
+        error_printf("Unrecoverable PCIe error detected for device %s",
+                     vdev->vbasedev.name);
+    }
+    error_printf("Please collect any data possible and then kill the guest");

how about that instead :

Quoted 9 lines
   if (err) {
       error_report("Unrecoverable PCIe error detected for device %s: %s",
                    vdev->vbasedev.name, error_get_pretty(err));
       error_free(err);
   } else {
       error_report("Unrecoverable PCIe error detected for device %s",
                    vdev->vbasedev.name);
   }
   error_printf("Please collect any data possible and then kill the guest\n");

I prefer use of error_report_err(), because it displays hints added with error_append_hint(), if any.

Quoted 3 lines
Quoted 3 lines
hw/vfio/pci.c +0 -0
      vm_stop(RUN_STATE_INTERNAL_ERROR);
  }

[...]

author
#6 lore raw

Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

Quoted 46 lines · Markus Armbruster
Quoted 44 lines · Cédric Le Goater

+Shameer, who is looking at forwarding AER errors to guest :

    https://lore.kernel.org/qemu-devel/SJ0PR12MB8614DDFEE3A9575564EDEF99ABFF2@SJ0PR12MB8614.namprd12.prod.outlook.com/
Quoted 39 lines · Farhan Ali

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
   hw/vfio/pci.c | 27 +++++++++++++++++++++------
   hw/vfio/pci.h |  1 +
   2 files changed, 22 insertions(+), 6 deletions(-)
hw/vfio/pci.c +8 -5
index 428ab2f069..a2f489b34d 100644
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev)
   static void vfio_err_notifier_handler(void *opaque)
   {
       VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
 
       if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
           return;
       }
 
       /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate the
        * guest to contain the error.
        */
 
Quoted 10 lines
Quoted 8 lines

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev) · line 3270

Quoted 8 lines
hw/vfio/pci.c +7 -1
-    error_report("%s(%s) Unrecoverable error detected. Please collect any data possible and then kill the guest", __func__, vdev->vbasedev.name);
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }
+
+    if (err) {
+        error_prepend(&err, "Unrecoverable PCIe error detected for device %s",
+                      vdev->vbasedev.name);

This requires use of ERRP_GUARD(). See "Why, when and how to use ERRP_GUARD()" in qapi/error.h.

okay, I can add the ERRP_GUARD(). AFAIU it will then look something like this?

Error **errp = NULL;
ERRP_GUARD();

if (vdev->err_handler && vdev->err_handler(vdev, errp)) {
	return;
}
if (*errp) {
	//print error with errp
} else {
	//generic error
}

Thanks

Farhan

#7 lore raw

Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

Quoted 59 lines · Farhan Ali
Quoted 46 lines · Markus Armbruster
Quoted 44 lines · Cédric Le Goater

+Shameer, who is looking at forwarding AER errors to guest :

    https://lore.kernel.org/qemu-devel/SJ0PR12MB8614DDFEE3A9575564EDEF99ABFF2@SJ0PR12MB8614.namprd12.prod.outlook.com/
Quoted 39 lines · Farhan Ali

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
   hw/vfio/pci.c | 27 +++++++++++++++++++++------
   hw/vfio/pci.h |  1 +
   2 files changed, 22 insertions(+), 6 deletions(-)
hw/vfio/pci.c +8 -5
index 428ab2f069..a2f489b34d 100644
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev)
 static void vfio_err_notifier_handler(void *opaque)
 {
     VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
 
     if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
         return;
     }
 
     /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate the
      * guest to contain the error.
      */
 
Quoted 11 lines
Quoted 8 lines

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev) · line 3270

Quoted 8 lines
hw/vfio/pci.c +7 -1
-    error_report("%s(%s) Unrecoverable error detected. Please collect any data possible and then kill the guest", __func__, vdev->vbasedev.name);
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }
+
+    if (err) {
+        error_prepend(&err, "Unrecoverable PCIe error detected for device %s",
+                      vdev->vbasedev.name);

This requires use of ERRP_GUARD(). See "Why, when and how to use ERRP_GUARD()" in qapi/error.h.

Quoted 3 lines

okay, I can add the ERRP_GUARD(). AFAIU it will then look something like this?

Error **errp = NULL;

Pretty sure you mean

  Error *errp = NULL;
Quoted 1 line

ERRP_GUARD();

Put ERRP_GUARD() right at the beginning of the function.

Quoted 10 lines
if (vdev->err_handler && vdev->err_handler(vdev, errp)) {
	return;
}
if (*errp) {
	//print error with errp
} else {
	//generic error
}

I don't this "uh, have we got an error?", to be honest. What about:

        if (!vdev->err_handler) {
            error_report([...]);
        } else if (!vdev->err_handler(vdev, &err)) {
            error_prepend(&err, [...]);
            error_report_err(err);
        } else {
            /* Error handled */
            return;
        }

        vm_stop(RUN_STATE_INTERNAL_ERROR);

This makes it quite obvious what each error report is about. Requires vdev->err_handler() to set an error when it fails, which it totally should.

Matter of taste, and I'm not the maintainer here, Cédric and Alex are.

author
#8 lore raw

Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

In reply to Cédric Le Goater
Quoted 84 lines · Cédric Le Goater

+Shameer, who is looking at forwarding AER errors to guest :

https://lore.kernel.org/qemu-devel/SJ0PR12MB8614DDFEE3A9575564EDEF99ABFF2@SJ0PR12MB8614.namprd12.prod.outlook.com/

Quoted 42 lines · Farhan Ali

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
  hw/vfio/pci.c | 27 +++++++++++++++++++++------
  hw/vfio/pci.h |  1 +

  2 files changed, 22 insertions(+), 6 deletions(-)
hw/vfio/pci.c +13 -5
index 428ab2f069..a2f489b34d 100644
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev)
   static void vfio_err_notifier_handler(void *opaque)
   {
       VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
         if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
           return;
       }
         /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate the
        * guest to contain the error.
        */
   -    error_report("%s(%s) Unrecoverable error detected. Please collect any data possible and then kill the guest", __func__, vdev->vbasedev.name);
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }
+
+    if (err) {

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev) · line 3276

Quoted 10 lines
hw/vfio/pci.c +8 -0
+        error_prepend(&err, "Unrecoverable PCIe error detected for 
 device %s",
+                      vdev->vbasedev.name);
+        error_report_err(err);
+    } else {
+        error_printf("Unrecoverable PCIe error detected for device %s",
+                     vdev->vbasedev.name);
+    }
+    error_printf("Please collect any data possible and then kill the 
 guest");

how about that instead :

  if (err) {
      error_report("Unrecoverable PCIe error detected for device %s: %s", vdev->vbasedev.name, error_get_pretty(err)); error_free(err);
  } else {
      error_report("Unrecoverable PCIe error detected for device %s", vdev->vbasedev.name);
  }
  error_printf("Please collect any data possible and then kill the guest\n");

hw/vfio/pci.h struct VFIOPCIDevice { · line 149

Quoted 11 lines
hw/vfio/pci.c +0 -0
         vm_stop(RUN_STATE_INTERNAL_ERROR);
   }
hw/vfio/pci.h +1 -0
index c9ab949870..c067bbbebc 100644
@@ -146,6 +146,7 @@ struct VFIOPCIDevice {
       EventNotifier err_notifier;
       EventNotifier req_notifier;
       int (*resetfn)(struct VFIOPCIDevice *);
+    bool (*err_handler)(struct VFIOPCIDevice *, Error **);

Please add documentation, something like :

Quoted 15 lines

  /*
   * Platform-specific error recovery handler.
   *
   * Called when the host reports a PCI error via the VFIO error notifier.
   * The handler should attempt to recover the device and forward the
   * error to the guest if the platform supports it.
   *
   * @vdev: the VFIO PCI device that triggered the error
   * @errp: set with the failure reason on false return
   *
   * Return true on success, the VM continues running.
   * Return false on failure and set @errp, the VM will be stopped. */
  bool (*err_handler)(struct VFIOPCIDevice *vdev, Error **errp);

Yup, I can add that.

Quoted 2 lines

That said, I'd prefer to see AER forwarding first.

I am curious too to understand how AER forwarding will work. Based on qemu patches (which may not be complete) [1], I can't tell how AER or an event will be sent to a guest to notify of an error. Based on the discussion on the link you posted, it looks like APEI/GHES based events would be sent to the guest?

Another question regarding AER recovery series, do we need some mechanism to get the AER information from the kernel for userspace? I am trying to understand if QEMU has to forward an AER event, does it need to get information such status/mask registers etc?

[1] https://github.com/shamiali2008/qemu-master/commit/e45458710cd8509fa5bd81f4376126b77b6f40be

Quoted 10 lines

Thanks,

C.

Quoted 3 lines
hw/vfio/pci.h +0 -0
       uint32_t vendor_id;
       uint32_t device_id;
       uint32_t sub_vendor_id;
#9 lore raw

RE: [PATCH v4 2/4] vfio/pci: Add an error handler callback

Quoted 126 lines

-----Original Message-----
From: Farhan Ali <[email protected]>
Sent: 02 September 2026 17:34
To: Cédric Le Goater <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shameer Kolothum Thodi <[email protected]>
Subject: Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

External email: Use caution opening links or attachments

Quoted 3 lines · Cédric Le Goater

+Shameer, who is looking at forwarding AER errors to guest :

https://lore.kernel.org/qemu-

devel/[email protected] amprd12.prod.outlook.com/

Quoted 11 lines · Farhan Ali
Quoted 9 lines

Provide a vfio error handling callback, that can be used by devices to handle PCI errors for passthrough devices.

---
  hw/vfio/pci.c | 27 +++++++++++++++++++++------
  hw/vfio/pci.h |  1 +
  2 files changed, 22 insertions(+), 6 deletions(-)
Quoted 5 lines

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice

Quoted 5 lines
hw/vfio/pci.c +0 -0
index 428ab2f069..a2f489b34d 100644
@@ -3244,21 +3244,36 @@ void vfio_pci_put_device(VFIOPCIDevice

*vdev)

Quoted 68 lines
Quoted 30 lines
hw/vfio/pci.c +13 -5
  static void vfio_err_notifier_handler(void *opaque)
  {
      VFIOPCIDevice *vdev = opaque;
+    Error *err = NULL;
        if (!event_notifier_test_and_clear(&vdev->err_notifier)) {
          return;
      }
        /*
-     * TBD. Retrieve the error details and decide what action
-     * needs to be taken. One of the actions could be to pass
-     * the error to the guest and have the guest driver recover
-     * from the error. This requires that PCIe capabilities be
-     * exposed to the guest. For now, we just terminate the
+     * We can retrieve the error details and decide what action
+     * needs to be taken in err_handler(). One of the actions could
+     * be to pass the error to the guest and have the guest driver
+     * recover from the error. This requires that PCIe capabilities be
+     * exposed to the guest.
+     *
+     * If err_handler() is not implemented/fails, we just terminate the
       * guest to contain the error.
       */
  -    error_report("%s(%s) Unrecoverable error detected. Please
 collect any data possible and then kill the guest", __func__,
 vdev->vbasedev.name);
+    if (vdev->err_handler && vdev->err_handler(vdev, &err)) {
+        return;
+    }
+
+    if (err) {

hw/vfio/pci.c void vfio_pci_put_device(VFIOPCIDevice *vdev)

Quoted 10 lines
hw/vfio/pci.c +8 -0
+        error_prepend(&err, "Unrecoverable PCIe error detected for
 device %s",
+                      vdev->vbasedev.name);
+        error_report_err(err);
+    } else {
+        error_printf("Unrecoverable PCIe error detected for device %s",
+                     vdev->vbasedev.name);
+    }
+    error_printf("Please collect any data possible and then kill the
 guest");

how about that instead :

  if (err) {
      error_report("Unrecoverable PCIe error detected for device %s: %s",
                   vdev->vbasedev.name, error_get_pretty(err));
      error_free(err);

} else {
error_report("Unrecoverable PCIe error detected for device %s",
vdev->vbasedev.name);
}
error_printf("Please collect any data possible and then kill the
guest\n");

hw/vfio/pci.h struct VFIOPCIDevice { · line 149

Quoted 11 lines
hw/vfio/pci.c +0 -0
        vm_stop(RUN_STATE_INTERNAL_ERROR);
  }
hw/vfio/pci.h +1 -0
index c9ab949870..c067bbbebc 100644
@@ -146,6 +146,7 @@ struct VFIOPCIDevice {
      EventNotifier err_notifier;
      EventNotifier req_notifier;
      int (*resetfn)(struct VFIOPCIDevice *);
+    bool (*err_handler)(struct VFIOPCIDevice *, Error **);

Please add documentation, something like :

Quoted 16 lines

/*
* Platform-specific error recovery handler.
*
* Called when the host reports a PCI error via the VFIO error
notifier.
* The handler should attempt to recover the device and forward the
* error to the guest if the platform supports it.
*
* @vdev: the VFIO PCI device that triggered the error
* @errp: set with the failure reason on false return
*
* Return true on success, the VM continues running.
* Return false on failure and set @errp, the VM will be stopped. */
bool (*err_handler)(struct VFIOPCIDevice *vdev, Error **errp);

Yup, I can add that.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

That said, I'd prefer to see AER forwarding first.

I am curious too to understand how AER forwarding will work. Based on qemu patches (which may not be complete) [1], I can't tell how AER or an event will be sent to a guest to notify of an error. Based on the discussion on the link you posted, it looks like APEI/GHES based events would be sent to the guest?

Right, that QEMU branch is an early prototype which only observes and logs, so the forwarding is not in it.

I am working on a QEMU branch which adds it, based on the kernel RFC. The plan is to use native AER rather than GHES, so QEMU injects with pcie_aer_inject_error() and an emulated pcie-root-port raises the interrupt to the guest. I will post a link once it is ready.

Quoted 2 lines

Another question regarding AER recovery series, do we need some mechanism to get the AER information from the kernel for userspace?

Not as it stands. The feature reports how severe the event was and what the host did, not which error occurred, so QEMU cannot forward the real status bits today. If it is something that is useful then it probably needs to be added

Thanks,
Shameer

author
#10 lore raw

Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

Hi Shameer,

Thanks for your response!

Quoted 6 lines · Shameer Kolothum Thodi
Quoted 6 lines
Quoted 1 line

That said, I'd prefer to see AER forwarding first.

I am curious too to understand how AER forwarding will work. Based on qemu patches (which may not be complete) [1], I can't tell how AER or an event will be sent to a guest to notify of an error. Based on the discussion on the link you posted, it looks like APEI/GHES based events would be sent to the guest?

Quoted 7 lines

Right, that QEMU branch is an early prototype which only observes and logs, so the forwarding is not in it.

I am working on a QEMU branch which adds it, based on the kernel RFC. The plan is to use native AER rather than GHES, so QEMU injects with pcie_aer_inject_error() and an emulated pcie-root-port raises the interrupt to the guest. I will post a link once it is ready.

I am very curious to know (and learn) how we would do this.

Quoted 6 lines
Quoted 2 lines

Another question regarding AER recovery series, do we need some mechanism to get the AER information from the kernel for userspace?

Not as it stands. The feature reports how severe the event was and what the host did, not which error occurred, so QEMU cannot forward the real status bits today. If it is something that is useful then it probably needs to be added

IMHO I think there might be value in providing more detailed information to the QEMU/guest.

Based on my brief look at the kernel/QEMU patch series, it looks like there is not much coordination between the guest and host recovery. So when we inject an AER in the guest, is the device access still blocked? Is the device access enabled only after a guest completed the recovery?

Thanks

Farhan

Quoted 2 lines

Thanks,
Shameer

#11 lore raw

RE: [PATCH v4 2/4] vfio/pci: Add an error handler callback

Hi Farhan,

Quoted 26 lines

-----Original Message-----
From: Farhan Ali <[email protected]>
Sent: 03 September 2026 19:07
To: Shameer Kolothum Thodi <[email protected]>; Cédric Le Goater <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/4] vfio/pci: Add an error handler callback

External email: Use caution opening links or attachments

Hi Shameer,

Thanks for your response!

Quoted 9 lines · Shameer Kolothum Thodi
Quoted 6 lines
Quoted 1 line

That said, I'd prefer to see AER forwarding first.

I am curious too to understand how AER forwarding will work. Based on qemu patches (which may not be complete) [1], I can't tell how AER or an event will be sent to a guest to notify of an error. Based on the discussion on the link you posted, it looks like APEI/GHES based events would be sent to the guest?

Right, that QEMU branch is an early prototype which only observes and logs, so the forwarding is not in it.

Quoted 6 lines
Quoted 4 lines

I am working on a QEMU branch which adds it, based on the kernel RFC. The plan is to use native AER rather than GHES, so QEMU injects with pcie_aer_inject_error() and an emulated pcie-root-port raises the interrupt to the guest. I will post a link once it is ready.

I am very curious to know (and learn) how we would do this.

I have a branch that does the AER error injection into the guest here:
https://github.com/shamiali2008/qemu-master/commits/private-master-vfio-aer-test-v2/

Note: This is only for RFC test purposes.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

Another question regarding AER recovery series, do we need some mechanism to get the AER information from the kernel for userspace?

Not as it stands. The feature reports how severe the event was and what the host did, not which error occurred, so QEMU cannot forward the real status bits today. If it is something that is useful then it probably needs to be added

IMHO I think there might be value in providing more detailed information to the QEMU/guest.

Ok. I will have a look and see how we can propagate that into userspace.

Quoted 5 lines

Based on my brief look at the kernel/QEMU patch series, it looks like there is not much coordination between the guest and host recovery. So when we inject an AER in the guest, is the device access still blocked? Is the device access enabled only after a guest completed the recovery?

Access is already unblocked when the guest sees the error. QEMU injects the error only after host recovery has finished, so the guest driver runs against a device it can read.

You are right that there is no coordination between guest and host and that is deliberate. Please see Alex's reply here on which the RFC design is based:

https://lore.kernel.org/qemu-devel/[email protected]/

The cost is that the guest only recovers once the host has finished, and cannot influence what the host does. If the guest driver wants a reset it will do one, on a device the host has already reset.

Thanks,
Shameer

author
#12 lore raw

PATCH v4 3/4 s390x/pci: Add PCI error handling for vfio pci devices

In reply to Farhan Ali

Add 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 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          |   9 +++
 hw/s390x/s390-pci-vfio-stubs.c   |   6 ++
 hw/s390x/s390-pci-vfio.c         | 100 +++++++++++++++++++++++++++++++
 include/hw/s390x/s390-pci-bus.h  |   2 +
 include/hw/s390x/s390-pci-vfio.h |   1 +
 5 files changed, 118 insertions(+)
hw/s390x/s390-pci-bus.c +9 -0
index 9ecf3c30ad..b2db7f3df4 100644
@@ -160,6 +160,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);
     }
@@ -1123,6 +1125,7 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     S390pciState *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)) {
@@ -1189,6 +1192,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")) {
             /*
@@ -1213,6 +1217,11 @@ 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 */
+            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
index d9882b7aad..9fc84ca135 100644
@@ -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 +100 -0

115 lines not on this page · raw message

include/hw/s390x/s390-pci-bus.h +2 -0
index 9228523ce8..bc67f7e065 100644
@@ -364,6 +364,8 @@ struct S390PCIBusDevice {
     bool forwarding_assist;
     bool aif;
     bool rtr_avail;
+    QemuMutex err_handler_lock;
+    uint32_t ccdf_err_length;
     QTAILQ_ENTRY(S390PCIBusDevice) link;
 };
 
include/hw/s390x/s390-pci-vfio.h +1 -0
index f7d6149daf..c7886b63ea 100644
@@ -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
#13 lore raw

Re: [PATCH v4 3/4] s390x/pci: Add PCI error handling for vfio pci devices

Quoted 77 lines · Farhan Ali

Add 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 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          |   9 +++
  hw/s390x/s390-pci-vfio-stubs.c   |   6 ++
  hw/s390x/s390-pci-vfio.c         | 100 +++++++++++++++++++++++++++++++
  include/hw/s390x/s390-pci-bus.h  |   2 +
  include/hw/s390x/s390-pci-vfio.h |   1 +
  5 files changed, 118 insertions(+)
hw/s390x/s390-pci-bus.c +9 -0
index 9ecf3c30ad..b2db7f3df4 100644
@@ -160,6 +160,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);
      }
@@ -1123,6 +1125,7 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
      S390pciState *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)) {
@@ -1189,6 +1192,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")) {
              /*
@@ -1213,6 +1217,11 @@ 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 */
+            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
index d9882b7aad..9fc84ca135 100644
@@ -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 +0 -0
index db6de00bd2..9a63040e22 100644

hw/s390x/s390-pci-vfio.c void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt) · line 108

Quoted 4 lines
hw/s390x/s390-pci-vfio.c +1 -0
@@ -105,6 +105,73 @@ void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt)
      }
  }
 
+static int s390_pci_get_feature_err(VFIOPCIDevice *vfio_pci,

returning a bool would be preferred unless the errno is important

Quoted 28 lines
hw/s390x/s390-pci-vfio.c +28 -0
+                                    PciCcdfErr *ccdf,
+                                    uint32_t ccdf_err_length,
+                                    Error **errp)
+{
+    int ret;
+    size_t total_size;
+    struct vfio_device_feature_zpci_err *err;
+    g_autofree void *buf = NULL;
+    g_autofree struct vfio_device_feature *feature = NULL;
+
+    total_size = sizeof(*feature) + sizeof(*err);
+    feature = g_malloc(total_size);
+    feature->argsz = total_size;
+    feature->flags = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_ZPCI_ERROR;
+
+    buf = g_malloc(ccdf_err_length);
+    err = (void *)feature->data;
+    err->data = (uint64_t)buf;
+    ret = vfio_device_get_feature(&vfio_pci->vbasedev, feature);
+
+    if (ret) {
+        if (ret != -ENOMSG) {
+            error_setg(errp, "Failed feature get VFIO_DEVICE_FEATURE_ZPCI_ERROR"
+                              " (rc=%d)", ret);
+        }
+        return ret;
+    }
+

hw/s390x/s390-pci-vfio.c void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt) · line 146

Quoted 10 lines
hw/s390x/s390-pci-vfio.c +10 -0
+    memcpy(ccdf, (PciCcdfErr *) err->data, ccdf_err_length);
+
+    return 0;
+}
+
+static bool s390_pci_err_handler(VFIOPCIDevice *vfio_pci, Error **errp)
+{
+    S390PCIBusDevice *pbdev;
+    PciCcdfErr ccdf;
+    bool success = false;

This means errp should be set. It is not obvious from the code below.

hw/s390x/s390-pci-vfio.c void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt) · line 150

Quoted 4 lines
hw/s390x/s390-pci-vfio.c +4 -0
+    int ret = 0;
+
+    pbdev = s390_pci_find_dev_by_target(s390_get_phb(),
+                                        DEVICE(&vfio_pci->parent_obj)->id);

can pbdev be NULL ?

  if (!pbdev) {
      error_setg(errp, "No matching zpci device found");
      return false;

}

Quoted 9 lines
hw/s390x/s390-pci-vfio.c +9 -0
+
+    QEMU_LOCK_GUARD(&pbdev->err_handler_lock);
+    pbdev->state = ZPCI_FS_ERROR;
+
+    if (sizeof(ccdf) != pbdev->ccdf_err_length) {
+        error_setg(errp,
+                   "CCDF size mismatch expected size=%zu, provided size=%d",
+                   sizeof(ccdf), pbdev->ccdf_err_length);
+        return false;

hw/s390x/s390-pci-vfio.c void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt) · line 169

Quoted 10 lines
hw/s390x/s390-pci-vfio.c +10 -0
+    }
+
+    while (ret == 0) {
+        ret = s390_pci_get_feature_err(vfio_pci, &ccdf,
+                                       pbdev->ccdf_err_length, errp);
+        if (ret) {
+            success = ret == -ENOMSG ? true : false;
+            break;
+        }
+        s390_pci_generate_error_event(ccdf.pec, pbdev->fh, pbdev->fid, 0, 0);

why not use ccdf.e and ccdf.faddr for more diagnostic details ?

Quoted 76 lines
hw/s390x/s390-pci-vfio.c +38 -0
+    }
+
+    return success;
+}
+
  static void s390_pci_read_base(S390PCIBusDevice *pbdev,
                                 struct vfio_device_info *info)
  {
@@ -134,6 +201,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;
+    }
+
      /*
       * If the device is a passthrough ISM device, disallow relaxed
       * translation.
@@ -371,3 +442,32 @@ 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;
+    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;
+    }
+
+    vfio_pci->err_handler = s390_pci_err_handler;
+
+    return true;
+}
include/hw/s390x/s390-pci-bus.h +2 -0
index 9228523ce8..bc67f7e065 100644
@@ -364,6 +364,8 @@ struct S390PCIBusDevice {
      bool forwarding_assist;
      bool aif;
      bool rtr_avail;
+    QemuMutex err_handler_lock;
+    uint32_t ccdf_err_length;
      QTAILQ_ENTRY(S390PCIBusDevice) link;
  };
 
include/hw/s390x/s390-pci-vfio.h +1 -0
index f7d6149daf..c7886b63ea 100644
@@ -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
author
#14 lore raw

Re: [PATCH v4 3/4] s390x/pci: Add PCI error handling for vfio pci devices

Quoted 78 lines · Cédric Le Goater
Quoted 77 lines · Farhan Ali

Add 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 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          |   9 +++ hw/s390x/s390-pci-vfio-stubs.c   |   6 ++ hw/s390x/s390-pci-vfio.c         | 100 +++++++++++++++++++++++++++++++ include/hw/s390x/s390-pci-bus.h  |   2 + include/hw/s390x/s390-pci-vfio.h |   1 +

  5 files changed, 118 insertions(+)
hw/s390x/s390-pci-bus.c +1 -0
index 9ecf3c30ad..b2db7f3df4 100644
@@ -160,6 +160,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);

      }

hw/s390x/s390-pci-bus.c +7 -0
@@ -1123,6 +1125,7 @@ static void s390_pcihost_plug(HotplugHandler 
 *hotplug_dev, DeviceState *dev,
       S390pciState *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)) {
@@ -1189,6 +1192,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")) {
               /*
@@ -1213,6 +1217,11 @@ 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 */
+            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 +0 -0
index d9882b7aad..9fc84ca135 100644
@@ -30,3 +30,9 @@ bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, 
 uint32_t *fh)
   void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
   {

  }

hw/s390x/s390-pci-vfio-stubs.c +6 -0
+
+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 +0 -1
index db6de00bd2..9a63040e22 100644
--- a/hw/s390x/s390-pci-vfio.c
Quoted 9 lines

hw/s390x/s390-pci-vfio.c void s390_pci_end_dma_count(S390pciState *s, · line 108

Quoted 6 lines

+++ b/hw/s390x/s390-pci-vfio.c

hw/s390x/s390-pci-vfio.c +0 -0
@@ -105,6 +105,73 @@ void s390_pci_end_dma_count(S390pciState *s, 
 S390PCIDMACount *cnt)
       }
   }
   +static int s390_pci_get_feature_err(VFIOPCIDevice *vfio_pci,

returning a bool would be preferred unless the errno is important

I can change it to bool. Don't have a strong preference here.

Quoted 70 lines
Quoted 31 lines
hw/s390x/s390-pci-vfio.c +23 -0
+ PciCcdfErr *ccdf,
+                                    uint32_t ccdf_err_length,
+                                    Error **errp)
+{
+    int ret;
+    size_t total_size;
+    struct vfio_device_feature_zpci_err *err;
+    g_autofree void *buf = NULL;
+    g_autofree struct vfio_device_feature *feature = NULL;
+
+    total_size = sizeof(*feature) + sizeof(*err);
+    feature = g_malloc(total_size);
+    feature->argsz = total_size;
+    feature->flags = VFIO_DEVICE_FEATURE_GET | 
 VFIO_DEVICE_FEATURE_ZPCI_ERROR;
+
+    buf = g_malloc(ccdf_err_length);
+    err = (void *)feature->data;
+    err->data = (uint64_t)buf;
+    ret = vfio_device_get_feature(&vfio_pci->vbasedev, feature);
+
+    if (ret) {
+        if (ret != -ENOMSG) {
+            error_setg(errp, "Failed feature get 

VFIO_DEVICE_FEATURE_ZPCI_ERROR"
+                              " (rc=%d)", ret);
+        }
+        return ret;
+    }

hw/s390x/s390-pci-vfio.c +1 -0
+

hw/s390x/s390-pci-vfio.c void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt) · line 146

Quoted 10 lines
hw/s390x/s390-pci-vfio.c +10 -0
+    memcpy(ccdf, (PciCcdfErr *) err->data, ccdf_err_length);
+
+    return 0;
+}
+
+static bool s390_pci_err_handler(VFIOPCIDevice *vfio_pci, Error **errp)
+{
+    S390PCIBusDevice *pbdev;
+    PciCcdfErr ccdf;
+    bool success = false;

This means errp should be set. It is not obvious from the code below.

Quoted 4 lines

+    int ret = 0;
+
+    pbdev = s390_pci_find_dev_by_target(s390_get_phb(),
+ DEVICE(&vfio_pci->parent_obj)->id);

can pbdev be NULL ?

  if (!pbdev) {
      error_setg(errp, "No matching zpci device found"); return false;
  }

Quoted 15 lines
hw/s390x/s390-pci-vfio.c +7 -0
+
+    QEMU_LOCK_GUARD(&pbdev->err_handler_lock);
+    pbdev->state = ZPCI_FS_ERROR;
+
+    if (sizeof(ccdf) != pbdev->ccdf_err_length) {
+        error_setg(errp,
+                   "CCDF size mismatch expected size=%zu, provided 

size=%d",
+                   sizeof(ccdf), pbdev->ccdf_err_length); +        return false;
+    }
+
+    while (ret == 0) {
+        ret = s390_pci_get_feature_err(vfio_pci, &ccdf,
+ pbdev->ccdf_err_length, errp);

Quoted 8 lines
Quoted 6 lines

+        if (ret) {
+            success = ret == -ENOMSG ? true : false; +            break;
+        }
+        s390_pci_generate_error_event(ccdf.pec, pbdev->fh, pbdev->fid, 0, 0);

why not use ccdf.e and ccdf.faddr for more diagnostic details ?

That's a fair point, will add that. I think this was based on the older version which only had the pec as the valid information.

Thanks

Farhan

Quoted 82 lines
Quoted 81 lines

+    }

hw/s390x/s390-pci-vfio.c +4 -0
+
+    return success;
+}
+

  static void s390_pci_read_base(S390PCIBusDevice *pbdev, struct vfio_device_info *info) {

hw/s390x/s390-pci-vfio.c +3 -0
@@ -134,6 +201,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;
+    }
+
       /*
        * If the device is a passthrough ISM device, disallow relaxed

       * translation.

hw/s390x/s390-pci-vfio.c +8 -0
@@ -371,3 +442,32 @@ 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;
+    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;

hw/s390x/s390-pci-vfio.c +6 -0
+
+    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;
+    }

hw/s390x/s390-pci-vfio.c +5 -0
+
+    vfio_pci->err_handler = s390_pci_err_handler;
+
+    return true;
+}
include/hw/s390x/s390-pci-bus.h +2 -0
index 9228523ce8..bc67f7e065 100644
@@ -364,6 +364,8 @@ struct S390PCIBusDevice {
       bool forwarding_assist;
       bool aif;
       bool rtr_avail;
+    QemuMutex err_handler_lock;
+    uint32_t ccdf_err_length;
       QTAILQ_ENTRY(S390PCIBusDevice) link;
   };

  diff --git a/include/hw/s390x/s390-pci-vfio.h b/include/hw/s390x/s390-pci-vfio.h index f7d6149daf..c7886b63ea 100644

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
author
#15 lore raw

PATCH v4 4/4 s390x/pci: Reset a device in error state

In reply to 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.

---
 hw/s390x/s390-pci-bus.c          |  7 +++++++
 hw/s390x/s390-pci-vfio-stubs.c   |  4 ++++
 hw/s390x/s390-pci-vfio.c         | 10 ++++++++++
 include/hw/s390x/s390-pci-vfio.h |  1 +
 4 files changed, 22 insertions(+)
hw/s390x/s390-pci-bus.c +7 -0
index b2db7f3df4..283b5b62b0 100644
@@ -1546,6 +1546,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;
@@ -1558,6 +1560,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-stubs.c +4 -0
index 9fc84ca135..c68c612038 100644
@@ -36,3 +36,7 @@ bool s390_pci_setup_err_handler(S390PCIBusDevice *pbdev, Error **errp)
     error_setg(errp, "VFIO not available, cannot setup error handler");
     return false;
 }
+
+void s390_pci_reset(S390PCIBusDevice *pbdev)
+{
+}
hw/s390x/s390-pci-vfio.c +10 -0
index 9a63040e22..64eb28104b 100644
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
@@ -172,6 +173,15 @@ static bool s390_pci_err_handler(VFIOPCIDevice *vfio_pci, Error **errp)
     return success;
 }
 
+void s390_pci_reset(S390PCIBusDevice *pbdev)
+{
+    VFIOPCIDevice *vfio_pci = VFIO_PCI_DEVICE(pbdev->pdev);
+    if (ioctl(vfio_pci->vbasedev.fd, VFIO_DEVICE_RESET)) {
+        error_report("Failed to reset PCI device %s : %s ",
+                      vfio_pci->vbasedev.name, strerror(errno));
+    }
+}
+
 static void s390_pci_read_base(S390PCIBusDevice *pbdev,
                                struct vfio_device_info *info)
 {
include/hw/s390x/s390-pci-vfio.h +1 -0
index c7886b63ea..38ccf445ea 100644
@@ -21,5 +21,6 @@ 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);
+void s390_pci_reset(S390PCIBusDevice *pbdev);
 
 #endif
Signature · 1 line
2.43.0
#16 lore raw

Re: [PATCH v4 4/4] s390x/pci: Reset a device in error state

Quoted 63 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.

---
  hw/s390x/s390-pci-bus.c          |  7 +++++++
  hw/s390x/s390-pci-vfio-stubs.c   |  4 ++++
  hw/s390x/s390-pci-vfio.c         | 10 ++++++++++
  include/hw/s390x/s390-pci-vfio.h |  1 +
  4 files changed, 22 insertions(+)
hw/s390x/s390-pci-bus.c +7 -0
index b2db7f3df4..283b5b62b0 100644
@@ -1546,6 +1546,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;
@@ -1558,6 +1560,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-stubs.c +4 -0
index 9fc84ca135..c68c612038 100644
@@ -36,3 +36,7 @@ bool s390_pci_setup_err_handler(S390PCIBusDevice *pbdev, Error **errp)
      error_setg(errp, "VFIO not available, cannot setup error handler");
      return false;
  }
+
+void s390_pci_reset(S390PCIBusDevice *pbdev)
+{
+}
hw/s390x/s390-pci-vfio.c +1 -0
index 9a63040e22..64eb28104b 100644
@@ -10,6 +10,7 @@
   */
 
  #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 
  #include <sys/ioctl.h>
  #include <linux/vfio.h>

hw/s390x/s390-pci-vfio.c static bool s390_pci_err_handler(VFIOPCIDevice *vfio_pci, Error **errp) · line 182

Quoted 10 lines
hw/s390x/s390-pci-vfio.c +7 -0
@@ -172,6 +173,15 @@ static bool s390_pci_err_handler(VFIOPCIDevice *vfio_pci, Error **errp)
      return success;
  }
 
+void s390_pci_reset(S390PCIBusDevice *pbdev)
+{
+    VFIOPCIDevice *vfio_pci = VFIO_PCI_DEVICE(pbdev->pdev);
+    if (ioctl(vfio_pci->vbasedev.fd, VFIO_DEVICE_RESET)) {
+        error_report("Failed to reset PCI device %s : %s ",
+                      vfio_pci->vbasedev.name, strerror(errno));
+    }

and pbdev->state remains ZPCI_FS_ERROR ? I don't see it cleared.

C.

Quoted 16 lines
hw/s390x/s390-pci-vfio.c +2 -0
+}
+
  static void s390_pci_read_base(S390PCIBusDevice *pbdev,
                                 struct vfio_device_info *info)
  {
include/hw/s390x/s390-pci-vfio.h +1 -0
index c7886b63ea..38ccf445ea 100644
@@ -21,5 +21,6 @@ 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);
+void s390_pci_reset(S390PCIBusDevice *pbdev);
 
  #endif
author
#17 lore raw

Re: [PATCH v4 4/4] s390x/pci: Reset a device in error state

Quoted 78 lines · Cédric Le Goater
Quoted 64 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.

---
  hw/s390x/s390-pci-bus.c          |  7 +++++++ hw/s390x/s390-pci-vfio-stubs.c   |  4 ++++ hw/s390x/s390-pci-vfio.c         | 10 ++++++++++ include/hw/s390x/s390-pci-vfio.h |  1 +

  4 files changed, 22 insertions(+)
hw/s390x/s390-pci-bus.c +0 -0
index b2db7f3df4..283b5b62b0 100644
@@ -1546,6 +1546,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;

hw/s390x/s390-pci-bus.c +5 -0
@@ -1558,6 +1560,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-stubs.c +0 -0
index 9fc84ca135..c68c612038 100644
@@ -36,3 +36,7 @@ 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-stubs.c +4 -0
+
+void s390_pci_reset(S390PCIBusDevice *pbdev)
+{
+}
hw/s390x/s390-pci-vfio.c +1 -0
index 9a63040e22..64eb28104b 100644
@@ -10,6 +10,7 @@
    */
     #include "qemu/osdep.h"
+#include "qemu/error-report.h"
     #include <sys/ioctl.h>
   #include <linux/vfio.h>

hw/s390x/s390-pci-vfio.c static bool s390_pci_err_handler(VFIOPCIDevice · line 182

Quoted 10 lines
hw/s390x/s390-pci-vfio.c +6 -0
@@ -172,6 +173,15 @@ static bool s390_pci_err_handler(VFIOPCIDevice 
 *vfio_pci, Error **errp)
       return success;
   }
   +void s390_pci_reset(S390PCIBusDevice *pbdev)
+{
+    VFIOPCIDevice *vfio_pci = VFIO_PCI_DEVICE(pbdev->pdev);
+    if (ioctl(vfio_pci->vbasedev.fd, VFIO_DEVICE_RESET)) {
+        error_report("Failed to reset PCI device %s : %s ",
+                      vfio_pci->vbasedev.name, strerror(errno));
+    }

and pbdev->state remains  ZPCI_FS_ERROR ? I don't see it cleared.

Quoted 1 line

C.

The reset is done as part of CLP disable and on a disable the state is set to ZPCI_FS_DISABLED [1]. The device enabled again when the guest issues a CLP enabled.

[1] https://elixir.bootlin.com/qemu/v11.1.1/source/hw/s390x/s390-pci-inst.c#L271

Thanks

Farhan

Quoted 18 lines
Quoted 17 lines
hw/s390x/s390-pci-vfio.c +2 -0
+}
+
   static void s390_pci_read_base(S390PCIBusDevice *pbdev,
                                  struct vfio_device_info *info)

  {

include/hw/s390x/s390-pci-vfio.h +1 -0
index c7886b63ea..38ccf445ea 100644
@@ -21,5 +21,6 @@ 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);
+void s390_pci_reset(S390PCIBusDevice *pbdev);
     #endif
#18 lore raw
In reply to Farhan Ali
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 and it had some significant changes in VFIO API since the last QEMU series was posted. But the design for QEMU component is still the same.

For QEMU on eventfd notification for PCI error from vfio-pci driver we call the vfio error handler. We can use a per device error handler callback 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.

Quoted 1 line

I would appreciate some feedback on this patch series.

Hi Farhan,

Have you seen Shameer's kernel series for PCI error recovery [1] ? It uses a dedicated eventfd registered via VFIO_DEVICE_FEATURE_SET, with a self-contained handler independent of the legacy err_notifier.

The QEMU side [2] just probes the feature, installs the eventfd, and suppresses the legacy vm_stop path with a bool flag : no callback in generic VFIO PCI code, which is cleaner.

This is also the pattern used by the other s390 VFIO devices: vfio-ccw has three dedicated eventfds (io_notifier, crw_notifier, req_notifier) and vfio-ap has two (req_notifier, cfg_notifier).

For zPCI, it would mean extending VFIO_DEVICE_FEATURE_ZPCI_ERROR to support SET with an eventfd field. The ABI is still new so the struct can be extended, keeping the s390 error recovery code self-contained, with no changes to generic VFIO PCI code. I think this approach is preferable.

Thanks,

C.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/shamiali2008/qemu-master/commit/e45458710cd8509fa5bd81f4376126b77b6f40be

author
#19 lore raw
Quoted 17 lines · Cédric Le Goater
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 and it had some significant changes in VFIO API since the last QEMU series was posted. But the design for QEMU component is still the same.

For QEMU on eventfd notification for PCI error from vfio-pci driver we call the vfio error handler. We can use a per device error handler callback 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.

Quoted 2 lines
Quoted 1 line

I would appreciate some feedback on this patch series.

Hi Cedric,

Quoted 6 lines

Hi Farhan,

Have you seen Shameer's kernel series for PCI error recovery [1] ? It uses a dedicated eventfd registered via VFIO_DEVICE_FEATURE_SET, with a self-contained handler independent of the legacy err_notifier.

Quoted 7 lines

The QEMU side [2] just probes the feature, installs the eventfd, and suppresses the legacy vm_stop path with a bool flag : no callback in generic VFIO PCI code, which is cleaner.

This is also the pattern used by the other s390 VFIO devices: vfio-ccw has three dedicated eventfds (io_notifier, crw_notifier, req_notifier) and vfio-ap has two (req_notifier, cfg_notifier).

My thought process was to use the existing legacy err_notifier and let each vfio-pci device handle the error. I thought the callback would also provide some flexibility on each device handling the error.

I can take a look at Shameer's approach and see if its something we can do. Just briefly looking at the QEMU code, it looks like it it ties the eventfd to the generic vfio-pci code (of course this is in flux). This would become problematic for s390x as unfortunately AER recovery will not work for zPCI devices due to platform firmware being involved in the recovery process.

Quoted 6 lines

For zPCI, it would mean extending VFIO_DEVICE_FEATURE_ZPCI_ERROR to support SET with an eventfd field. The ABI is still new so the struct can be extended, keeping the s390 error recovery code self-contained, with no changes to generic VFIO  PCI code. I think this approach is preferable.

I would like to get some feedback from Alex to see if we could extend the ABI.

Thanks

Farhan

Quoted 8 lines

Thanks,

C.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/shamiali2008/qemu-master/commit/e45458710cd8509fa5bd81f4376126b77b6f40be

author
#20 lore raw
Quoted 41 lines · Farhan Ali
Quoted 17 lines · Cédric Le Goater
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 and it had some significant changes in VFIO API since the last QEMU series was posted. But the design for QEMU component is still the same.

For QEMU on eventfd notification for PCI error from vfio-pci driver we call the vfio error handler. We can use a per device error handler callback 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.

Quoted 2 lines
Quoted 1 line

I would appreciate some feedback on this patch series.

Hi Cedric,

Quoted 6 lines

Hi Farhan,

Have you seen Shameer's kernel series for PCI error recovery [1] ? It uses a dedicated eventfd registered via VFIO_DEVICE_FEATURE_SET, with a self-contained handler independent of the legacy err_notifier.

Quoted 7 lines

The QEMU side [2] just probes the feature, installs the eventfd, and suppresses the legacy vm_stop path with a bool flag : no callback in generic VFIO PCI code, which is cleaner.

This is also the pattern used by the other s390 VFIO devices: vfio-ccw has three dedicated eventfds (io_notifier, crw_notifier, req_notifier) and vfio-ap has two (req_notifier, cfg_notifier).

My thought process was to use the existing legacy err_notifier and let each vfio-pci device handle the error. I thought the callback would also provide some flexibility on each device handling the error.

I can take a look at Shameer's approach and see if its something we can do. Just briefly looking at the QEMU code, it looks like it it ties the eventfd to the generic vfio-pci code (of course this is in flux). This would become problematic for s390x as unfortunately AER recovery will not work for zPCI devices due to platform firmware being involved in the recovery process.

Quoted 9 lines
Quoted 6 lines

For zPCI, it would mean extending VFIO_DEVICE_FEATURE_ZPCI_ERROR to support SET with an eventfd field. The ABI is still new so the struct can be extended, keeping the s390 error recovery code self-contained, with no changes to generic VFIO  PCI code. I think this approach is preferable.

I would like to get some feedback from Alex to see if we could extend the ABI.

I had been thinking about this a bit more, and I think having a another eventfd for s390 to just notify on error would just be unnecessary duplication. Because now we will have the legacy err_notifier + s390 error notifer eventfds for the same purpose but with different handlers. Can we replace fd handler for the legacy err_notifier from vfio_err_notifier_handler() to an s390 specific handler for s390 devices? This would also avoid any callback in the vfio core common code.

Thanks

Farhan

Quoted 11 lines
Quoted 10 lines

Thanks,

C.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/shamiali2008/qemu-master/commit/e45458710cd8509fa5bd81f4376126b77b6f40be