EEH Support for VFIO PCI Device
Subsystems (5)
v8 cover EEH Support for VFIO PCI Device
The series of patches adds support EEH for PCI devices, which are passed through to PowerKVM based guest via VFIO. The implementation is straightforward based on the issues or problems we have to resolve to support EEH for PowerKVM based guest.
- Emulation for EEH RTAS requests. All EEH RTAS requests goes to QEMU firstly. If QEMU can't handle it, the request will be sent to host via newly introduced VFIO container IOCTL command (VFIO_EEH_OP) and gets handled in host kernel.
The series of patches requires corresponding QEMU changes.
Change log
=====
v1 -> v2:
* EEH RTAS requests are routed to QEMU, and then possiblly to host kerenl. The mechanism KVM in-kernel handling is dropped.
* Error injection is reimplemented based syscall, instead of KVM in-kerenl handling. The logic for error injection token management is moved to QEMU. The error injection request is routed to QEMU and then possiblly to host kernel.
v2 -> v3:
* Make the fields in struct eeh_vfio_pci_addr, struct vfio_eeh_info based on the comments from Alexey.
* Define macros for EEH VFIO operations (Alexey).
* Clear frozen state after successful PE reset.
* Merge original [PATCH 1/2/3] to one.
v3 -> v4:
* Remove the error injection from the patchset. Mike or I will work on that later.
* Rename CONFIG_VFIO_EEH to VFIO_PCI_EEH.
* Rename the IOCTL command to VFIO_EEH_OP and it's handled by VFIO-PCI device instead of VFIO container.
* Rename the IOCTL argument structure to "vfio_eeh_op" accordingly. Also, more fields added to hold return values for RTAS requests.
* The address mapping stuff is totally removed. When opening or releasing VFIO PCI device, notification sent to EEH to update the flags indicates the device is passed to guest or not.
* Change pr_warn() to pr_debug() to avoid DOS as pointed by Alex.W
* Argument size check issue pointed by Alex.W.
v4 -> v5:
* Functions for VFIO PCI EEH support are moved to eeh.c and exported from there. VFIO PCI driver just uses those functions to tackle IOCTL command VFIO_EEH_OP. All of this is to make the code organized in a good way as suggested by Alex.G. Another potential benefit is PowerNV/pSeries are sharing "eeh_ops" and same infrastructure could possiblly work for KVM_PR and KVM_HV mode at the same time.
* Don't clear error injection registers after finishing PE reset as the patchset is doing nothing related to error injection.
* Amending Documentation/vfio.txt, which was missed in last revision.
* No QEMU changes for this revision. "v4" works well. Also, remove "RFC" from the subject as the design is basically recognized.
v5 -> v6:
* CONFIG_VFIO_PCI_EEH removed. Instead to use CONFIG_EEH.
* Split one ioctl command to 5.
* In eeh.c, description has been added for those exported functions. Also, the functions have negative return values for error and information with other values. All digital numbers have been replaced by macros defined in eeh.h. The comments, including the function names have been amended not to mention "guest" or "vfio".
* Add one mutex to protect flag in eeh_dev_open()/release().
* More information on how to use those ioctl commands to Documentation/vfio.txt.
v6 -> v7:
* Remove ioctl command VFIO_EEH_PE_GET_ADDR, the PE address will be figured out in userland (e.g. QEMU) as Alex.G suggested.
* Let sPAPR VFIO container process the ioctl commands as VFIO container is naturally corresponds to IOMMU group (aka PE on sPAPR platform).
* All VFIO PCI EEH ioctl commands have "argsz+flags" for its companion data struct.
* For VFIO PCI EEH ioctl commands, ioctl() returns negative number to indicate error or zero for success. Additinal output information is transported by the companion data struct.
* Explaining PE in Documentation/vfio.txt, typo fixes, more comments suggested by Alex.G.
* Split/merge patches according to suggestions from Alex.G and Alex.W.
* To have EEH stub in drivers/vfio/pci/, which was suggested by Alex.W.
* Define various EEH options as macros in vfio.h for userland to use.
v7 -> v8:
* Change ioctl commands back to combined one.
* EEH related logic was put into drivers/vfio/vfio_eeh.c, which is only built with CONFIG_EEH. Otherwise, inline functions defined in include/linux/vfio.h
* Change vfio.txt according to the source code changes.
* Fix various comments from internal reviews by Alexey. Thanks to Alexey.
Gavin Shan (3):
powerpc/eeh: Avoid event on passed PE
powerpc/eeh: EEH support for VFIO PCI device
drivers/vfio: EEH support for VFIO PCI device
Documentation/vfio.txt | 87 +++++++++- arch/powerpc/include/asm/eeh.h | 21 +++ arch/powerpc/kernel/eeh.c | 276 ++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/eeh-ioda.c | 3 +- drivers/vfio/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 20 ++- drivers/vfio/vfio_iommu_spapr_tce.c | 17 +- drivers/vfio/vfio_spapr_eeh.c | 89 ++++++++++ include/linux/vfio.h | 23 +++ include/uapi/linux/vfio.h | 35 ++++ 10 files changed, 561 insertions(+), 11 deletions(-) create mode 100644 drivers/vfio/vfio_spapr_eeh.c
Signature · 1 line
1.8.3.2
PATCH v8 1/3 powerpc/eeh: Avoid event on passed PE
We must not handle EEH error on devices which are passed to somebody else. Instead, we expect that the frozen device owner detects an EEH error and recovers from it.
This avoids EEH error handling on passed through devices so the device owner gets a chance to handle them.
--- arch/powerpc/include/asm/eeh.h | 7 +++++++ arch/powerpc/kernel/eeh.c | 8 ++++++++ arch/powerpc/platforms/powernv/eeh-ioda.c | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/eeh.h +7 -0
@@ -25,6 +25,7 @@#include <linux/list.h> #include <linux/string.h> #include <linux/time.h> +#include <linux/atomic.h> struct pci_dev ;struct pci_bus ;
@@ -84,6 +85,7 @@ struct eeh_pe {int freeze_count;/* Times of froze up */ struct timeval tstamp;/* Time on first-time freeze */ int false_positives;/* Times of reported #ff's */ +atomic_t pass_dev_cnt;/* Count of passed through devs */ struct eeh_pe *parent;/* Parent PE */ struct list_head child_list;/* Link PE to the child list */ struct list_head edevs;/* Link list of EEH devices */
@@ -93,6 +95,11 @@ struct eeh_pe {#define eeh_pe_for_each_dev (pe, edev, tmp) \ list_for_each_entry_safe(edev, tmp, &pe->edevs, list) +static inline bool eeh_pe_passed (struct eeh_pe *pe) +{ +return pe ? !!atomic_read (&pe->pass_dev_cnt) : false; +} +/* * The struct is used to trace EEH state for the associated * PCI device node or PCI device. In future, it might
arch/powerpc/kernel/eeh.c +8 -0
@@ -400,6 +400,14 @@ int eeh_dev_check_failure(struct eeh_dev *edev)if (ret >0 )return ret; +/* +* If the PE isn't owned by us, we shouldn't check the +* state. Instead, let the owner handle it if the PE has +* been frozen. +*/ +if (eeh_pe_passed (pe)) +return 0 ; +/* If we already have a pending isolation event for this * slot, we know it's bad already, we don't need to check. * Do this checking under a lock; as multiple PCI devices
arch/powerpc/platforms/powernv/eeh-ioda.c +2 -1
@@ -892,7 +892,8 @@ static int ioda_eeh_next_error(struct eeh_pe **pe)opal_pci_eeh_freeze_clear (phb->opal_id, frozen_pe_no,OPAL_EEH_ACTION_CLEAR_FREEZE_ALL ); ret =EEH_NEXT_ERR_NONE ; - }else if ((*pe)->state &EEH_PE_ISOLATED ) { + }else if ((*pe)->state &EEH_PE_ISOLATED || +eeh_pe_passed (*pe)) { ret =EEH_NEXT_ERR_NONE ; }else { pr_err("EEH: Frozen PHB#%x-PE#%x (%s) detected\n",
Signature · 1 line
1.8.3.2
PATCH v8 2/3 powerpc/eeh: EEH support for VFIO PCI device
In reply to Gavin ShanThe patch exports functions to be used by new VFIO ioctl command, which will be introduced in subsequent patch, to support EEH functinality for VFIO PCI devices.
--- arch/powerpc/include/asm/eeh.h | 14 +++ arch/powerpc/kernel/eeh.c | 268 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+)
arch/powerpc/include/asm/eeh.h +14 -0
@@ -166,6 +166,8 @@ enum {#define EEH_OPT_ENABLE 1/* EEH enable */ #define EEH_OPT_THAW_MMIO 2/* MMIO enable */ #define EEH_OPT_THAW_DMA 3/* DMA enable */ +#define EEH_OPT_GET_PE_ADDR 0/* Get PE addr */ +#define EEH_OPT_GET_PE_MODE 1/* Get PE mode */ #define EEH_STATE_UNAVAILABLE (1 << 0)/* State unavailable */ #define EEH_STATE_NOT_SUPPORT (1 << 1)/* EEH not supported */ #define EEH_STATE_RESET_ACTIVE (1 << 2)/* Active reset */
@@ -173,6 +175,11 @@ enum {#define EEH_STATE_DMA_ACTIVE (1 << 4)/* Active DMA */ #define EEH_STATE_MMIO_ENABLED (1 << 5)/* MMIO enabled */ #define EEH_STATE_DMA_ENABLED (1 << 6)/* DMA enabled */ +#define EEH_PE_STATE_NORMAL 0/* Normal state */ +#define EEH_PE_STATE_RESET 1/* PE reset asserted */ +#define EEH_PE_STATE_STOPPED_IO_DMA 2/* Frozen PE */ +#define EEH_PE_STATE_STOPPED_DMA 4/* Stopped DMA, Enabled IO */ +#define EEH_PE_STATE_UNAVAIL 5/* Unavailable */ #define EEH_RESET_DEACTIVATE 0/* Deactivate the PE reset */ #define EEH_RESET_HOT 1/* Hot reset */ #define EEH_RESET_FUNDAMENTAL 3/* Fundamental reset */
@@ -280,6 +287,13 @@ void eeh_add_device_late(struct pci_dev *);void eeh_add_device_tree_late (struct pci_bus *);void eeh_add_sysfs_files (struct pci_bus *);void eeh_remove_device (struct pci_dev *); +int eeh_dev_open (struct pci_dev *pdev); +void eeh_dev_release (struct pci_dev *pdev); +struct eeh_pe *eeh_iommu_group_to_pe (struct iommu_group *group); +int eeh_pe_set_option (struct eeh_pe *pe,int option); +int eeh_pe_get_state (struct eeh_pe *pe); +int eeh_pe_reset (struct eeh_pe *pe,int option); +int eeh_pe_configure (struct eeh_pe *pe);/** * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure.
arch/powerpc/kernel/eeh.c +268 -0
286 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v8 2/3] powerpc/eeh: EEH support for VFIO PCI device
arch/powerpc/include/asm/eeh.h enum { · line 170
Quoted 2 lines · Gavin Shan
arch/powerpc/include/asm/eeh.h +2
-0+#define EEH_OPT_GET_PE_ADDR 0/* Get PE addr */ +#define EEH_OPT_GET_PE_MODE 1/* Get PE mode */
I assume that's just some leftover from the previous patches :-)
Don't respin just yet, let's see what other comments come in.
Cheers,
Ben.
Re: [PATCH v8 2/3] powerpc/eeh: EEH support for VFIO PCI device
Quoted 8 lines · Benjamin Herrenschmidt
arch/powerpc/include/asm/eeh.h enum { · line 170
Quoted 2 lines · Gavin Shan
arch/powerpc/include/asm/eeh.h +2
-0+#define EEH_OPT_GET_PE_ADDR 0/* Get PE addr */ +#define EEH_OPT_GET_PE_MODE 1/* Get PE mode */ I assume that's just some leftover from the previous patches :-)
Don't respin just yet, let's see what other comments come in.
Yep, I'll remove them in next revision. Thanks, Ben.
Thanks,
Gavin
PATCH v8 3/3 drivers/vfio: EEH support for VFIO PCI device
In reply to Gavin ShanThe patch adds new IOCTL commands for sPAPR VFIO container device to support EEH functionality for PCI devices, which have been passed through from host to somebody else via VFIO.
--- Documentation/vfio.txt | 87 ++++++++++++++++++++++++++++++++++-- drivers/vfio/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 20 ++++++--- drivers/vfio/vfio_iommu_spapr_tce.c | 17 ++++++- drivers/vfio/vfio_spapr_eeh.c | 89 +++++++++++++++++++++++++++++++++++++ include/linux/vfio.h | 23 ++++++++++ include/uapi/linux/vfio.h | 35 +++++++++++++++ 7 files changed, 262 insertions(+), 10 deletions(-) create mode 100644 drivers/vfio/vfio_spapr_eeh.c
Documentation/vfio.txt +84 -3
@@ -305,7 +305,15 @@ faster, the map/unmap handling has been implemented in real mode which provides an excellent performance which has limitations such as inability to do locked pages accounting in real time. -So 3 additional ioctls have been added: +4) According to sPAPR specification, A Partitionable Endpoint (PE) is an I/O +subtree that can be treated as a unit for the purposes of partitioning and +error recovery. A PE may be a single or multi-function IOA (IO Adapter), a +function of a multi-function IOA, or multiple IOAs (possibly including switch +and bridge structures above the multiple IOAs). PPC64 guests detect PCI errors +and recover from them via EEH RTAS services, which works on the basis of +additional ioctl commands. + +So 4 additional ioctls have been added: VFIO_IOMMU_SPAPR_TCE_GET_INFO - returns the size and the start of the DMA window on the PCI bus.
@@ -316,9 +324,12 @@ So 3 additional ioctls have been added: VFIO_IOMMU_DISABLE - disables the container. + VFIO_EEH_PE_OP - provides an API for EEH setup, error detection and recovery. The code flow from the example above should be slightly changed: + struct vfio_eeh_pe_op pe_op = { .argsz = sizeof(pe_op) }; + ..... /* Add the group to the container */ ioctl(group, VFIO_GROUP_SET_CONTAINER, &container);
@@ -342,9 +353,79 @@ The code flow from the example above should be slightly changed: dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE; /* Check here is .iova/.size are within DMA window from spapr_iommu_info */ - ioctl(container, VFIO_IOMMU_MAP_DMA, &dma_map); - ..... + + /* Get a file descriptor for the device */ + device = ioctl(group, VFIO_GROUP_GET_DEVICE_FD, "0000:06:0d.0"); + + .... + + /* Gratuitous device reset and go... */ + ioctl(device, VFIO_DEVICE_RESET); + + /* Make sure EEH is supported */ + ioctl(container, VFIO_CHECK_EXTENSION, VFIO_EEH); + + /* Enable the EEH functionality on the device */ + pe_op.op = VFIO_EEH_PE_ENABLE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* You're suggested to create additional data struct to represent + * PE, and put child devices belonging to same IOMMU group to the + * PE instance for later reference. + */ + + /* Check the PE's state and make sure it's in functional state */ + pe_op.op = VFIO_EEH_PE_GET_STATE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Save device state using pci_save_state(). + * EEH should be enabled on the specified device. + */ + + .... + + /* When 0xFF's returned from reading PCI config space or IO BARs + * of the PCI device. Check the PE's state to see if that has been + * frozen. + */ + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Waiting for pending PCI transactions to be completed and don't + * produce any more PCI traffic from/to the affected PE until + * recovery is finished. + */ + + /* Enable IO for the affected PE and collect logs. Usually, the + * standard part of PCI config space, AER registers are dumped + * as logs for further analysis. + */ + pe_op.op = VFIO_EEH_PE_UNFREEZE_IO; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* + * Issue PE reset: hot or fundamental reset. Usually, hot reset + * is enough. However, the firmware of some PCI adapters would + * require fundamental reset. + */ + pe_op.op = VFIO_EEH_PE_RESET_HOT; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + pe_op.op = VFIO_EEH_PE_RESET_DEACTIVATE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Configure the PCI bridges for the affected PE */ + pe_op.op = VFIO_EEH_PE_CONFIGURE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Restored state we saved at initialization time. pci_restore_state() + * is good enough as an example. + */ + + /* Hopefully, error is recovered successfully. Now, you can resume to + * start PCI traffic to/from the affected PE. + */ + + .... -------------------------------------------------------------------------------
drivers/vfio/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-$(CONFIG_VFIO) += vfio.o obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o +obj-$(CONFIG_EEH) += vfio_spapr_eeh.o obj-$(CONFIG_VFIO_PCI) += pci/
drivers/vfio/pci/vfio_pci.c +14 -6
@@ -156,8 +156,10 @@ static void vfio_pci_release(void *device_data) {struct vfio_pci_device *vdev = device_data; -if (atomic_dec_and_test (&vdev->refcnt)) +if (atomic_dec_and_test (&vdev->refcnt)) { +vfio_spapr_pci_eeh_release (vdev->pdev);vfio_pci_disable (vdev); + }module_put (THIS_MODULE ); }
@@ -165,19 +167,25 @@ static void vfio_pci_release(void *device_data)static int vfio_pci_open (void *device_data) {struct vfio_pci_device *vdev = device_data; +int ret;if (!try_module_get (THIS_MODULE ))return -ENODEV ;if (atomic_inc_return (&vdev->refcnt) =1 ) { -int ret =vfio_pci_enable (vdev); -if (ret) { -module_put (THIS_MODULE ); -return ret; - } + ret =vfio_pci_enable (vdev); +if (ret) + goto error; + + ret =vfio_spapr_pci_eeh_open (vdev->pdev); +if (ret) + goto error; }return 0 ; +error: +module_put (THIS_MODULE ); +return ret; }static int vfio_pci_get_irq_count (struct vfio_pci_device *vdev,int irq_type)
drivers/vfio/vfio_iommu_spapr_tce.c +16 -1
@@ -156,7 +156,16 @@ static long tce_iommu_ioctl(void *iommu_data,switch (cmd) {case VFIO_CHECK_EXTENSION : -return (arg =VFIO_SPAPR_TCE_IOMMU ) ?1 :0 ; +switch (arg) { +case VFIO_SPAPR_TCE_IOMMU : + ret =1 ; +break ; +default : + ret =vfio_spapr_iommu_eeh_ioctl (NULL , cmd, arg); +break ; + } + +return (ret <0 ) ?0 : ret;case VFIO_IOMMU_SPAPR_TCE_GET_INFO : {struct vfio_iommu_spapr_tce_info info;
@@ -283,6 +292,12 @@ static long tce_iommu_ioctl(void *iommu_data,tce_iommu_disable (container);mutex_unlock (&container->lock);return 0 ; +case VFIO_EEH_PE_OP : +if (!container->tbl || !container->tbl->it_group) +return -ENODEV ; + +return vfio_spapr_iommu_eeh_ioctl (container->tbl->it_group, + cmd, arg); }return -ENOTTY ;
drivers/vfio/vfio_spapr_eeh.c new file +89 -0
89 lines not on this page · raw message
include/linux/vfio.h +23 -0
@@ -99,4 +99,27 @@ extern int vfio_external_user_iommu_id(struct vfio_group *group);extern long vfio_external_check_extension (struct vfio_group *group,unsigned long arg); +#ifdef CONFIG_EEH +extern int vfio_spapr_pci_eeh_open (struct pci_dev *pdev); +extern void vfio_spapr_pci_eeh_release (struct pci_dev *pdev); +extern long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd, +unsigned long arg); +#else +static inline int vfio_spapr_pci_eeh_open (struct pci_dev *pdev) +{ +return 0 ; +} + +static inline void vfio_spapr_pci_eeh_release (struct pci_dev *pdev) +{ +} + +static inline long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd, +unsigned long arg) +{ +return -ENOTTY ; +} +#endif /* CONFIG_EEH */ #endif /* VFIO_H */
include/uapi/linux/vfio.h +35 -0
@@ -30,6 +30,9 @@*/ #define VFIO_DMA_CC_IOMMU 4 +/* Check if EEH is supported */ +#define VFIO_EEH 5 +/* * The IOCTL interface is designed for extensibility by embedding the * structure length (argsz) and flags into structures passed between
@@ -455,6 +458,38 @@ struct vfio_iommu_spapr_tce_info {#define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) +/* +* EEH PE operation struct provides ways to: +* - enable/disable EEH functionality; +* - unfreeze IO/DMA for frozen PE; +* - read PE state; +* - reset PE; +* - configure PE. +*/ +struct vfio_eeh_pe_op { +__u32 argsz; +__u32 flags; +__u32 op; +}; + +#define VFIO_EEH_PE_DISABLE 0/* Disable EEH functionality */ +#define VFIO_EEH_PE_ENABLE 1/* Enable EEH functionality */ +#define VFIO_EEH_PE_UNFREEZE_IO 2/* Enable IO for frozen PE */ +#define VFIO_EEH_PE_UNFREEZE_DMA 3/* Enable DMA for frozen PE */ +#define VFIO_EEH_PE_GET_STATE 4/* PE state retrieval */ +#define VFIO_EEH_PE_RESET_DEACTIVATE 5/* Deassert PE reset */ +#define VFIO_EEH_PE_RESET_HOT 6/* Assert hot reset */ +#define VFIO_EEH_PE_RESET_FUNDAMENTAL 7/* Assert fundamental reset */ +#define VFIO_EEH_PE_CONFIGURE 8/* PE configuration */ + +#define VFIO_EEH_PE_STATE_NORMAL 0/* PE in functional state */ +#define VFIO_EEH_PE_STATE_RESET 1/* PE reset in progress */ +#define VFIO_EEH_PE_STATE_STOPPED 2/* Stopped DMA and IO */ +#define VFIO_EEH_PE_STATE_STOPPED_DMA 4/* Stopped DMA only */ +#define VFIO_EEH_PE_STATE_UNAVAIL 5/* State unavailable */ + +#define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21) +/* ***************************************************************** */ #endif /* _UAPIVFIO_H */
Signature · 1 line
1.8.3.2
Re: [PATCH v8 3/3] drivers/vfio: EEH support for VFIO PCI device
Quoted 170 lines · Gavin Shan
The patch adds new IOCTL commands for sPAPR VFIO container device to support EEH functionality for PCI devices, which have been passed through from host to somebody else via VFIO.
Signed-off-by Gavin Shan <[email protected]>--- Documentation/vfio.txt | 87 ++++++++++++++++++++++++++++++++++-- drivers/vfio/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 20 ++++++--- drivers/vfio/vfio_iommu_spapr_tce.c | 17 ++++++- drivers/vfio/vfio_spapr_eeh.c | 89 +++++++++++++++++++++++++++++++++++++ include/linux/vfio.h | 23 ++++++++++ include/uapi/linux/vfio.h | 35 +++++++++++++++ 7 files changed, 262 insertions(+), 10 deletions(-) create mode 100644 drivers/vfio/vfio_spapr_eeh.cDocumentation/vfio.txt +84
-3@@ -305,7 +305,15 @@ faster, the map/unmap handling has been implemented in real mode which provides an excellent performance which has limitations such as inability to do locked pages accounting in real time. -So 3 additional ioctls have been added: +4) According to sPAPR specification, A Partitionable Endpoint (PE) is an I/O +subtree that can be treated as a unit for the purposes of partitioning and +error recovery. A PE may be a single or multi-function IOA (IO Adapter), a +function of a multi-function IOA, or multiple IOAs (possibly including switch +and bridge structures above the multiple IOAs). PPC64 guests detect PCI errors +and recover from them via EEH RTAS services, which works on the basis of +additional ioctl commands. + +So 4 additional ioctls have been added: VFIO_IOMMU_SPAPR_TCE_GET_INFO - returns the size and the start of the DMA window on the PCI bus.@@ -316,9 +324,12 @@ So 3 additional ioctls have been added: VFIO_IOMMU_DISABLE - disables the container. + VFIO_EEH_PE_OP - provides an API for EEH setup, error detection and recovery. The code flow from the example above should be slightly changed: + struct vfio_eeh_pe_op pe_op = { .argsz = sizeof(pe_op) }; + /* Add the group to the container */ ioctl(group, VFIO_GROUP_SET_CONTAINER, &container);@@ -342,9 +353,79 @@ The code flow from the example above should be slightly changed: dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE; /* Check here is .iova/.size are within DMA window from spapr_iommu_info */ - ioctl(container, VFIO_IOMMU_MAP_DMA, &dma_map); - ..... + + /* Get a file descriptor for the device */ + device = ioctl(group, VFIO_GROUP_GET_DEVICE_FD, "0000:06:0d.0"); + + .... + + /* Gratuitous device reset and go... */ + ioctl(device, VFIO_DEVICE_RESET); + + /* Make sure EEH is supported */ + ioctl(container, VFIO_CHECK_EXTENSION, VFIO_EEH); + + /* Enable the EEH functionality on the device */ + pe_op.op = VFIO_EEH_PE_ENABLE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* You're suggested to create additional data struct to represent + * PE, and put child devices belonging to same IOMMU group to the + * PE instance for later reference. + */ + + /* Check the PE's state and make sure it's in functional state */ + pe_op.op = VFIO_EEH_PE_GET_STATE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Save device state using pci_save_state(). + * EEH should be enabled on the specified device. + */ + + .... + + /* When 0xFF's returned from reading PCI config space or IO BARs + * of the PCI device. Check the PE's state to see if that has been + * frozen. + */ + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Waiting for pending PCI transactions to be completed and don't + * produce any more PCI traffic from/to the affected PE until + * recovery is finished. + */ + + /* Enable IO for the affected PE and collect logs. Usually, the + * standard part of PCI config space, AER registers are dumped + * as logs for further analysis. + */ + pe_op.op = VFIO_EEH_PE_UNFREEZE_IO; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* + * Issue PE reset: hot or fundamental reset. Usually, hot reset + * is enough. However, the firmware of some PCI adapters would + * require fundamental reset. + */ + pe_op.op = VFIO_EEH_PE_RESET_HOT; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + pe_op.op = VFIO_EEH_PE_RESET_DEACTIVATE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Configure the PCI bridges for the affected PE */ + pe_op.op = VFIO_EEH_PE_CONFIGURE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Restored state we saved at initialization time. pci_restore_state() + * is good enough as an example. + */ + + /* Hopefully, error is recovered successfully. Now, you can resume to + * start PCI traffic to/from the affected PE. + */ + + .... -------------------------------------------------------------------------------drivers/vfio/Makefile +1
-0@@ -1,4 +1,5 @@ obj-$(CONFIG_VFIO) += vfio.o obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o +obj-$(CONFIG_EEH) += vfio_spapr_eeh.o obj-$(CONFIG_VFIO_PCI) += pci/drivers/vfio/pci/vfio_pci.c +4
-3@@ -156,8 +156,10 @@ static void vfio_pci_release(void *device_data) {struct vfio_pci_device *vdev = device_data; -if (atomic_dec_and_test (&vdev->refcnt)) +if (atomic_dec_and_test (&vdev->refcnt)) { +vfio_spapr_pci_eeh_release (vdev->pdev);vfio_pci_disable (vdev); + }module_put (THIS_MODULE ); }@@ -165,19 +167,25 @@ static void vfio_pci_release(void *device_data)static int vfio_pci_open (void *device_data) {struct vfio_pci_device *vdev = device_data; +int ret;if (!try_module_get (THIS_MODULE ))return -ENODEV ;if (atomic_inc_return (&vdev->refcnt) =1 ) { -int ret =vfio_pci_enable (vdev); -if (ret) {
drivers/vfio/pci/vfio_pci.c static void vfio_pci_release(void *device_data) · line 182
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +7
-3-module_put (THIS_MODULE ); -return ret; - } + ret =vfio_pci_enable (vdev); +if (ret) + goto error; + + ret =vfio_spapr_pci_eeh_open (vdev->pdev); +if (ret) + goto error;
Missing cleanup of vfio_pci_enable() on error
Quoted 53 lines
drivers/vfio/pci/vfio_pci.c +3
-0}return 0 ; +error: +module_put (THIS_MODULE ); +return ret; }static int vfio_pci_get_irq_count (struct vfio_pci_device *vdev,int irq_type)drivers/vfio/vfio_iommu_spapr_tce.c +16
-1@@ -156,7 +156,16 @@ static long tce_iommu_ioctl(void *iommu_data,switch (cmd) {case VFIO_CHECK_EXTENSION : -return (arg =VFIO_SPAPR_TCE_IOMMU ) ?1 :0 ; +switch (arg) { +case VFIO_SPAPR_TCE_IOMMU : + ret =1 ; +break ; +default : + ret =vfio_spapr_iommu_eeh_ioctl (NULL , cmd, arg); +break ; + } + +return (ret <0 ) ?0 : ret;case VFIO_IOMMU_SPAPR_TCE_GET_INFO : {struct vfio_iommu_spapr_tce_info info;@@ -283,6 +292,12 @@ static long tce_iommu_ioctl(void *iommu_data,tce_iommu_disable (container);mutex_unlock (&container->lock);return 0 ; +case VFIO_EEH_PE_OP : +if (!container->tbl || !container->tbl->it_group) +return -ENODEV ; + +return vfio_spapr_iommu_eeh_ioctl (container->tbl->it_group, + cmd, arg); }return -ENOTTY ;drivers/vfio/vfio_spapr_eeh.c new file +3
-0@@ -0,0 +1,89 @@ +/* +* EEH functionality support for VFIO devices. The feature is only +* available on sPAPR compatible platforms.
drivers/vfio/vfio_spapr_eeh.c line 13
Quoted 10 lines
drivers/vfio/vfio_spapr_eeh.c new file +10
-0+* +* Copyright Gavin Shan, IBM Corporation 2014. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/iommu.h> +#include <linux/pci.h>
Hmm, doesn't seem like we need iommu.h & pci.h just to pass through a pointer. Can these be removed?
Quoted 145 lines
drivers/vfio/vfio_spapr_eeh.c new file +76
-0+#include <linux/uaccess.h> +#include <linux/vfio.h> +#include <asm/eeh.h> + +/* We might build address mapping here for "fast" path later */ +int vfio_spapr_pci_eeh_open (struct pci_dev *pdev) +{ +return eeh_dev_open (pdev); +} + +void vfio_spapr_pci_eeh_release (struct pci_dev *pdev) +{ +eeh_dev_release (pdev); +} + +long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd,unsigned long arg) +{ +struct eeh_pe *pe; +struct vfio_eeh_pe_op op; +unsigned long minsz; +long ret = -EINVAL ; + +switch (cmd) { +case VFIO_CHECK_EXTENSION : +if (arg =VFIO_EEH ) + ret =eeh_enabled () ?1 :0 ; +else + ret =0 ; +break ; +case VFIO_EEH_PE_OP : + pe =eeh_iommu_group_to_pe (group); +if (!pe) +return -ENODEV ; + + minsz = offsetofend(struct vfio_eeh_pe_op, op); +if (copy_from_user (&op, (void __user *)arg, minsz)) +return -EFAULT ; +if (op.argsz < minsz) +return -EINVAL ; + +switch (op.op) { +case VFIO_EEH_PE_DISABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_DISABLE ); +break ; +case VFIO_EEH_PE_ENABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_ENABLE ); +break ; +case VFIO_EEH_PE_UNFREEZE_IO : + ret =eeh_pe_set_option (pe,EEH_OPT_THAW_MMIO ); +break ; +case VFIO_EEH_PE_UNFREEZE_DMA : + ret =eeh_pe_set_option (pe,EEH_OPT_THAW_DMA ); +break ; +case VFIO_EEH_PE_GET_STATE : + ret =eeh_pe_get_state (pe); +break ; +case VFIO_EEH_PE_RESET_DEACTIVATE : + ret =eeh_pe_reset (pe,EEH_RESET_DEACTIVATE ); +break ; +case VFIO_EEH_PE_RESET_HOT : + ret =eeh_pe_reset (pe,EEH_RESET_HOT ); +break ; +case VFIO_EEH_PE_RESET_FUNDAMENTAL : + ret =eeh_pe_reset (pe,EEH_RESET_FUNDAMENTAL ); +break ; +case VFIO_EEH_PE_CONFIGURE : + ret =eeh_pe_configure (pe); +break ; +default : + ret = -EINVAL ; + } + } + +return ret; +}include/linux/vfio.h +23
-0@@ -99,4 +99,27 @@ extern int vfio_external_user_iommu_id(struct vfio_group *group);extern long vfio_external_check_extension (struct vfio_group *group,unsigned long arg); +#ifdef CONFIG_EEH +extern int vfio_spapr_pci_eeh_open (struct pci_dev *pdev); +extern void vfio_spapr_pci_eeh_release (struct pci_dev *pdev); +extern long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd, +unsigned long arg); +#else +static inline int vfio_spapr_pci_eeh_open (struct pci_dev *pdev) +{ +return 0 ; +} + +static inline void vfio_spapr_pci_eeh_release (struct pci_dev *pdev) +{ +} + +static inline long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd, +unsigned long arg) +{ +return -ENOTTY ; +} +#endif /* CONFIG_EEH */ #endif /* VFIO_H */ include/uapi/linux/vfio.h +22
-0@@ -30,6 +30,9 @@*/ #define VFIO_DMA_CC_IOMMU 4 +/* Check if EEH is supported */ +#define VFIO_EEH 5 +/* * The IOCTL interface is designed for extensibility by embedding the * structure length (argsz) and flags into structures passed between @@ -455,6 +458,38 @@ struct vfio_iommu_spapr_tce_info {#define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) +/* +* EEH PE operation struct provides ways to: +* - enable/disable EEH functionality; +* - unfreeze IO/DMA for frozen PE; +* - read PE state; +* - reset PE; +* - configure PE. +*/ +struct vfio_eeh_pe_op { +__u32 argsz; +__u32 flags; +__u32 op; +}; + +#define VFIO_EEH_PE_DISABLE 0/* Disable EEH functionality */ +#define VFIO_EEH_PE_ENABLE 1/* Enable EEH functionality */ +#define VFIO_EEH_PE_UNFREEZE_IO 2/* Enable IO for frozen PE */ +#define VFIO_EEH_PE_UNFREEZE_DMA 3/* Enable DMA for frozen PE */ +#define VFIO_EEH_PE_GET_STATE 4/* PE state retrieval */
include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_info { · line 489
Quoted 10 lines
include/uapi/linux/vfio.h +10
-0+#define VFIO_EEH_PE_RESET_DEACTIVATE 5/* Deassert PE reset */ +#define VFIO_EEH_PE_RESET_HOT 6/* Assert hot reset */ +#define VFIO_EEH_PE_RESET_FUNDAMENTAL 7/* Assert fundamental reset */ +#define VFIO_EEH_PE_CONFIGURE 8/* PE configuration */ + +#define VFIO_EEH_PE_STATE_NORMAL 0/* PE in functional state */ +#define VFIO_EEH_PE_STATE_RESET 1/* PE reset in progress */ +#define VFIO_EEH_PE_STATE_STOPPED 2/* Stopped DMA and IO */ +#define VFIO_EEH_PE_STATE_STOPPED_DMA 4/* Stopped DMA only */ +#define VFIO_EEH_PE_STATE_UNAVAIL 5/* State unavailable */
Please make it explicit that these are return values for VFIO_EEH_PE_GET_STATE. They could be defined inline after VFIO_EEH_PE_GET_STATE with indenting to make it clear. Thanks,
Alex
Quoted 6 lines
include/uapi/linux/vfio.h +3
-0+ +#define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21) +/* ***************************************************************** */ #endif /* _UAPIVFIO_H */
Re: [PATCH v8 3/3] drivers/vfio: EEH support for VFIO PCI device
Quoted 168 lines · Alex Williamson
Quoted 167 lines · Gavin Shan
The patch adds new IOCTL commands for sPAPR VFIO container device to support EEH functionality for PCI devices, which have been passed through from host to somebody else via VFIO.
Signed-off-by Gavin Shan <[email protected]>--- Documentation/vfio.txt | 87 ++++++++++++++++++++++++++++++++++-- drivers/vfio/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 20 ++++++--- drivers/vfio/vfio_iommu_spapr_tce.c | 17 ++++++- drivers/vfio/vfio_spapr_eeh.c | 89 +++++++++++++++++++++++++++++++++++++ include/linux/vfio.h | 23 ++++++++++ include/uapi/linux/vfio.h | 35 +++++++++++++++ 7 files changed, 262 insertions(+), 10 deletions(-) create mode 100644 drivers/vfio/vfio_spapr_eeh.cDocumentation/vfio.txt +84
-3@@ -305,7 +305,15 @@ faster, the map/unmap handling has been implemented in real mode which provides an excellent performance which has limitations such as inability to do locked pages accounting in real time. -So 3 additional ioctls have been added: +4) According to sPAPR specification, A Partitionable Endpoint (PE) is an I/O +subtree that can be treated as a unit for the purposes of partitioning and +error recovery. A PE may be a single or multi-function IOA (IO Adapter), a +function of a multi-function IOA, or multiple IOAs (possibly including switch +and bridge structures above the multiple IOAs). PPC64 guests detect PCI errors +and recover from them via EEH RTAS services, which works on the basis of +additional ioctl commands. + +So 4 additional ioctls have been added: VFIO_IOMMU_SPAPR_TCE_GET_INFO - returns the size and the start of the DMA window on the PCI bus.@@ -316,9 +324,12 @@ So 3 additional ioctls have been added: VFIO_IOMMU_DISABLE - disables the container. + VFIO_EEH_PE_OP - provides an API for EEH setup, error detection and recovery. The code flow from the example above should be slightly changed: + struct vfio_eeh_pe_op pe_op = { .argsz = sizeof(pe_op) }; + /* Add the group to the container */ ioctl(group, VFIO_GROUP_SET_CONTAINER, &container);@@ -342,9 +353,79 @@ The code flow from the example above should be slightly changed: dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE; /* Check here is .iova/.size are within DMA window from spapr_iommu_info */ - ioctl(container, VFIO_IOMMU_MAP_DMA, &dma_map); - ..... + + /* Get a file descriptor for the device */ + device = ioctl(group, VFIO_GROUP_GET_DEVICE_FD, "0000:06:0d.0"); + + .... + + /* Gratuitous device reset and go... */ + ioctl(device, VFIO_DEVICE_RESET); + + /* Make sure EEH is supported */ + ioctl(container, VFIO_CHECK_EXTENSION, VFIO_EEH); + + /* Enable the EEH functionality on the device */ + pe_op.op = VFIO_EEH_PE_ENABLE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* You're suggested to create additional data struct to represent + * PE, and put child devices belonging to same IOMMU group to the + * PE instance for later reference. + */ + + /* Check the PE's state and make sure it's in functional state */ + pe_op.op = VFIO_EEH_PE_GET_STATE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Save device state using pci_save_state(). + * EEH should be enabled on the specified device. + */ + + .... + + /* When 0xFF's returned from reading PCI config space or IO BARs + * of the PCI device. Check the PE's state to see if that has been + * frozen. + */ + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Waiting for pending PCI transactions to be completed and don't + * produce any more PCI traffic from/to the affected PE until + * recovery is finished. + */ + + /* Enable IO for the affected PE and collect logs. Usually, the + * standard part of PCI config space, AER registers are dumped + * as logs for further analysis. + */ + pe_op.op = VFIO_EEH_PE_UNFREEZE_IO; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* + * Issue PE reset: hot or fundamental reset. Usually, hot reset + * is enough. However, the firmware of some PCI adapters would + * require fundamental reset. + */ + pe_op.op = VFIO_EEH_PE_RESET_HOT; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + pe_op.op = VFIO_EEH_PE_RESET_DEACTIVATE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Configure the PCI bridges for the affected PE */ + pe_op.op = VFIO_EEH_PE_CONFIGURE; + ioctl(container, VFIO_EEH_PE_OP, &pe_op); + + /* Restored state we saved at initialization time. pci_restore_state() + * is good enough as an example. + */ + + /* Hopefully, error is recovered successfully. Now, you can resume to + * start PCI traffic to/from the affected PE. + */ + + .... -------------------------------------------------------------------------------drivers/vfio/Makefile +1
-0@@ -1,4 +1,5 @@ obj-$(CONFIG_VFIO) += vfio.o obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o +obj-$(CONFIG_EEH) += vfio_spapr_eeh.o obj-$(CONFIG_VFIO_PCI) += pci/drivers/vfio/pci/vfio_pci.c +4
-1@@ -156,8 +156,10 @@ static void vfio_pci_release(void *device_data) {struct vfio_pci_device *vdev = device_data; -if (atomic_dec_and_test (&vdev->refcnt)) +if (atomic_dec_and_test (&vdev->refcnt)) { +vfio_spapr_pci_eeh_release (vdev->pdev);vfio_pci_disable (vdev); + }module_put (THIS_MODULE ); }@@ -165,19 +167,25 @@ static void vfio_pci_release(void *device_data)static int vfio_pci_open (void *device_data) {struct vfio_pci_device *vdev = device_data; +int ret;if (!try_module_get (THIS_MODULE ))return -ENODEV ;
Quoted 16 lines
drivers/vfio/pci/vfio_pci.c static void vfio_pci_release(void *device_data) · line 182
Quoted 13 lines
drivers/vfio/pci/vfio_pci.c +7
-5if (atomic_inc_return (&vdev->refcnt) =1 ) { -int ret =vfio_pci_enable (vdev); -if (ret) { -module_put (THIS_MODULE ); -return ret; - } + ret =vfio_pci_enable (vdev); +if (ret) + goto error; + + ret =vfio_spapr_pci_eeh_open (vdev->pdev); +if (ret) + goto error;Missing cleanup of
vfio_pci_enable()on error
Yep, I need to call vfio_pci_disable(vdev) for the case. I'll fix, thanks.
Quoted 58 lines
Quoted 58 lines
drivers/vfio/pci/vfio_pci.c +3
-0}return 0 ; +error: +module_put (THIS_MODULE ); +return ret; }static int vfio_pci_get_irq_count (struct vfio_pci_device *vdev,int irq_type)drivers/vfio/vfio_iommu_spapr_tce.c +16
-1@@ -156,7 +156,16 @@ static long tce_iommu_ioctl(void *iommu_data,switch (cmd) {case VFIO_CHECK_EXTENSION : -return (arg =VFIO_SPAPR_TCE_IOMMU ) ?1 :0 ; +switch (arg) { +case VFIO_SPAPR_TCE_IOMMU : + ret =1 ; +break ; +default : + ret =vfio_spapr_iommu_eeh_ioctl (NULL , cmd, arg); +break ; + } + +return (ret <0 ) ?0 : ret;case VFIO_IOMMU_SPAPR_TCE_GET_INFO : {struct vfio_iommu_spapr_tce_info info;@@ -283,6 +292,12 @@ static long tce_iommu_ioctl(void *iommu_data,tce_iommu_disable (container);mutex_unlock (&container->lock);return 0 ; +case VFIO_EEH_PE_OP : +if (!container->tbl || !container->tbl->it_group) +return -ENODEV ; + +return vfio_spapr_iommu_eeh_ioctl (container->tbl->it_group, + cmd, arg); }return -ENOTTY ;drivers/vfio/vfio_spapr_eeh.c new file +8
-0@@ -0,0 +1,89 @@ +/* +* EEH functionality support for VFIO devices. The feature is only +* available on sPAPR compatible platforms. +* +* Copyright Gavin Shan, IBM Corporation 2014. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as
Quoted 9 lines
drivers/vfio/vfio_spapr_eeh.c line 13
Quoted 5 lines
drivers/vfio/vfio_spapr_eeh.c new file +5
-0+* published by the Free Software Foundation. +*/ + +#include <linux/iommu.h> +#include <linux/pci.h> Hmm, doesn't seem like we need
iommu.h&pci.hjust to pass through a pointer. Can these be removed?
Yes, we can. I'll remove those in next revision. Thanks.
Quoted 151 lines
Quoted 151 lines
drivers/vfio/vfio_spapr_eeh.c new file +76
-0+#include <linux/uaccess.h> +#include <linux/vfio.h> +#include <asm/eeh.h> + +/* We might build address mapping here for "fast" path later */ +int vfio_spapr_pci_eeh_open (struct pci_dev *pdev) +{ +return eeh_dev_open (pdev); +} + +void vfio_spapr_pci_eeh_release (struct pci_dev *pdev) +{ +eeh_dev_release (pdev); +} + +long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd,unsigned long arg) +{ +struct eeh_pe *pe; +struct vfio_eeh_pe_op op; +unsigned long minsz; +long ret = -EINVAL ; + +switch (cmd) { +case VFIO_CHECK_EXTENSION : +if (arg =VFIO_EEH ) + ret =eeh_enabled () ?1 :0 ; +else + ret =0 ; +break ; +case VFIO_EEH_PE_OP : + pe =eeh_iommu_group_to_pe (group); +if (!pe) +return -ENODEV ; + + minsz = offsetofend(struct vfio_eeh_pe_op, op); +if (copy_from_user (&op, (void __user *)arg, minsz)) +return -EFAULT ; +if (op.argsz < minsz) +return -EINVAL ; + +switch (op.op) { +case VFIO_EEH_PE_DISABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_DISABLE ); +break ; +case VFIO_EEH_PE_ENABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_ENABLE ); +break ; +case VFIO_EEH_PE_UNFREEZE_IO : + ret =eeh_pe_set_option (pe,EEH_OPT_THAW_MMIO ); +break ; +case VFIO_EEH_PE_UNFREEZE_DMA : + ret =eeh_pe_set_option (pe,EEH_OPT_THAW_DMA ); +break ; +case VFIO_EEH_PE_GET_STATE : + ret =eeh_pe_get_state (pe); +break ; +case VFIO_EEH_PE_RESET_DEACTIVATE : + ret =eeh_pe_reset (pe,EEH_RESET_DEACTIVATE ); +break ; +case VFIO_EEH_PE_RESET_HOT : + ret =eeh_pe_reset (pe,EEH_RESET_HOT ); +break ; +case VFIO_EEH_PE_RESET_FUNDAMENTAL : + ret =eeh_pe_reset (pe,EEH_RESET_FUNDAMENTAL ); +break ; +case VFIO_EEH_PE_CONFIGURE : + ret =eeh_pe_configure (pe); +break ; +default : + ret = -EINVAL ; + } + } + +return ret; +}include/linux/vfio.h +23
-0@@ -99,4 +99,27 @@ extern int vfio_external_user_iommu_id(struct vfio_group *group);extern long vfio_external_check_extension (struct vfio_group *group,unsigned long arg); +#ifdef CONFIG_EEH +extern int vfio_spapr_pci_eeh_open (struct pci_dev *pdev); +extern void vfio_spapr_pci_eeh_release (struct pci_dev *pdev); +extern long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd, +unsigned long arg); +#else +static inline int vfio_spapr_pci_eeh_open (struct pci_dev *pdev) +{ +return 0 ; +} + +static inline void vfio_spapr_pci_eeh_release (struct pci_dev *pdev) +{ +} + +static inline long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, +unsigned int cmd, +unsigned long arg) +{ +return -ENOTTY ; +} +#endif /* CONFIG_EEH */ #endif /* VFIO_H */ include/uapi/linux/vfio.h +28
-0@@ -30,6 +30,9 @@*/ #define VFIO_DMA_CC_IOMMU 4 +/* Check if EEH is supported */ +#define VFIO_EEH 5 +/* * The IOCTL interface is designed for extensibility by embedding the * structure length (argsz) and flags into structures passed between @@ -455,6 +458,38 @@ struct vfio_iommu_spapr_tce_info {#define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) +/* +* EEH PE operation struct provides ways to: +* - enable/disable EEH functionality; +* - unfreeze IO/DMA for frozen PE; +* - read PE state; +* - reset PE; +* - configure PE. +*/ +struct vfio_eeh_pe_op { +__u32 argsz; +__u32 flags; +__u32 op; +}; + +#define VFIO_EEH_PE_DISABLE 0/* Disable EEH functionality */ +#define VFIO_EEH_PE_ENABLE 1/* Enable EEH functionality */ +#define VFIO_EEH_PE_UNFREEZE_IO 2/* Enable IO for frozen PE */ +#define VFIO_EEH_PE_UNFREEZE_DMA 3/* Enable DMA for frozen PE */ +#define VFIO_EEH_PE_GET_STATE 4/* PE state retrieval */ +#define VFIO_EEH_PE_RESET_DEACTIVATE 5/* Deassert PE reset */ +#define VFIO_EEH_PE_RESET_HOT 6/* Assert hot reset */ +#define VFIO_EEH_PE_RESET_FUNDAMENTAL 7/* Assert fundamental reset */ +#define VFIO_EEH_PE_CONFIGURE 8/* PE configuration */ + +#define VFIO_EEH_PE_STATE_NORMAL 0/* PE in functional state */
Quoted 9 lines
include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_info { · line 489
Quoted 4 lines
include/uapi/linux/vfio.h +4
-0+#define VFIO_EEH_PE_STATE_RESET 1/* PE reset in progress */ +#define VFIO_EEH_PE_STATE_STOPPED 2/* Stopped DMA and IO */ +#define VFIO_EEH_PE_STATE_STOPPED_DMA 4/* Stopped DMA only */ +#define VFIO_EEH_PE_STATE_UNAVAIL 5/* State unavailable */ Please make it explicit that these are return values for
VFIO_EEH_PE_GET_STATE. They could be defined inline afterVFIO_EEH_PE_GET_STATEwith indenting to make it clear. Thanks,
Sure. I'll fix. Thanks :-)
Thanks,
Gavin
Quoted 9 lines
Quoted 6 lines
include/uapi/linux/vfio.h +3
-0+ +#define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21) +/* ***************************************************************** */ #endif /* _UAPIVFIO_H */
Quoted 10 lines · Gavin Shan
The series of patches adds support EEH for PCI devices, which are passed through to PowerKVM based guest via VFIO. The implementation is straightforward based on the issues or problems we have to resolve to support EEH for PowerKVM based guest.
- Emulation for EEH RTAS requests. All EEH RTAS requests goes to QEMU firstly. If QEMU can't handle it, the request will be sent to host via newly introduced VFIO container IOCTL command (
VFIO_EEH_OP) and gets handled in host kernel.The series of patches requires corresponding QEMU changes.
Alex
Quoted 7 lines · Alexander Graf
Quoted 5 lines · Gavin Shan
The series of patches adds support EEH for PCI devices, which are passed through to PowerKVM based guest via VFIO. The implementation is straightforward based on the issues or problems we have to resolve to support EEH for PowerKVM based guest.
Quoted 8 lines
Quoted 5 lines
- Emulation for EEH RTAS requests. All EEH RTAS requests goes to QEMU firstly. If QEMU can't handle it, the request will be sent to host via newly introduced VFIO container IOCTL command (
VFIO_EEH_OP) and gets handled in host kernel.The series of patches requires corresponding QEMU changes.
Acked-by Alexander Graf <[email protected]>
Thanks, Alex :)
Quoted 3 lines
Alex