EEH Support for VFIO PCI devices on PowerKVM guest
Subsystems (5)
v2 cover EEH Support for VFIO PCI devices on PowerKVM guest
The series of patches intends to 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_INFO) and gets handled in host kernel.
- The error injection infrastructure need support request from the userland utility "errinjct" and PowerKVM based guest. The userland utility "errinjct" works on pSeries platform well with dedicated syscall, which helps invoking RTAS service to fulfil error injection in kernel. From the perspective, it's reasonable to extend the syscall to support PowerNV platform so that OPAL call can be invoked in host kernel for injecting errors. The data transported between userland and kerenl is still following "struct rtas_args" for both cases of PowerNV (OPAL) and pSeries (RTAS).
The series of patches requires corresponding firmware changes from Mike Qiu to support error injection and QEMU changes to support EEH for guest. QEMU patchset will be sent separately.
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.
Testing on P7
======
- Emulex adapter
Testing on P8
======
- Need more testing after design is finalized.
-----
Gavin Shan (10):
drivers/vfio: Introduce CONFIG_VFIO_EEH powerpc/eeh: Info to trace passed devices powerpc/eeh: Search EEH device by guest address powerpc/eeh: Search EEH PE by guest address drivers/vfio: New IOCTL command VFIO_EEH_INFO powerpc/eeh: Avoid event on passed PE powerpc/powernv: Sync OPAL header file with firmware
powerpc: Extend syscall ppc_rtas() powerpc/powernv: Implement ppc_call_opal() powerpc/powernv: Error injection infrastructure
arch/powerpc/include/asm/eeh.h | 52 +++++++++++++ arch/powerpc/include/asm/opal.h | 74 +++++++++++++++++- arch/powerpc/include/asm/rtas.h | 10 ++- arch/powerpc/include/asm/syscalls.h | 2 +- arch/powerpc/include/asm/systbl.h | 2 +- arch/powerpc/include/uapi/asm/unistd.h | 2 +- arch/powerpc/kernel/eeh.c | 8 ++ arch/powerpc/kernel/eeh_pe.c | 80 +++++++++++++++++++ arch/powerpc/kernel/rtas.c | 57 +++----------- arch/powerpc/kernel/syscalls.c | 50 ++++++++++++ arch/powerpc/platforms/powernv/Makefile | 3 +- arch/powerpc/platforms/powernv/eeh-ioda.c | 3 +- arch/powerpc/platforms/powernv/eeh-vfio.c | 584 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/errinject.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + arch/powerpc/platforms/powernv/opal.c | 93 ++++++++++++++++++++++ drivers/vfio/Kconfig | 6 ++ drivers/vfio/vfio_iommu_spapr_tce.c | 12 +++ include/uapi/linux/vfio.h | 61 +++++++++++++++ kernel/sys_ni.c | 2 +- 20 files changed, 1271 insertions(+), 53 deletions(-)
create mode 100644 arch/powerpc/platforms/powernv/eeh-vfio.c create mode 100644 arch/powerpc/platforms/powernv/errinject.c
Thanks,
Gavin
PATCH v2 1/10 drivers/vfio: Introduce CONFIG_VFIO_EEH
The patch introduces CONFIG_VFIO_EEH for more IOCTL commands on tce_iommu_driver_ops to support EEH funtionality for PCI devices that are passed through from host to guest.
--- drivers/vfio/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/vfio/Kconfig +6 -0
@@ -8,11 +8,17 @@ config VFIO_IOMMU_SPAPR_TCE depends on VFIO && SPAPR_TCE_IOMMU default n +config VFIO_EEH + tristate + depends on EEH && VFIO_IOMMU_SPAPR_TCE + default n + menuconfig VFIO tristate "VFIO Non-Privileged userspace driver framework" depends on IOMMU_API select VFIO_IOMMU_TYPE1 if X86 select VFIO_IOMMU_SPAPR_TCE if (PPC_POWERNV || PPC_PSERIES) + select VFIO_EEH if PPC_POWERNV select ANON_INODES help VFIO provides a framework for secure userspace device drivers.
Signature · 1 line
1.8.3.2
PATCH v2 2/10 powerpc/eeh: Info to trace passed devices
In reply to Gavin ShanThe address of passed PCI devices (domain:bus:slot:func) might be quite different from the perspective of host and guest. We have to trace the address mapping so that we can emulate EEH RTAS requests from guest. The patch introduces additional fields to eeh_pe and eeh_dev for the purpose.
--- arch/powerpc/include/asm/eeh.h | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
arch/powerpc/include/asm/eeh.h +46 -0
@@ -48,6 +48,14 @@ struct device_node;#define EEH_PE_RST_HOLD_TIME 250#define EEH_PE_RST_SETTLE_TIME 1800 +#ifdef CONFIG_VFIO_EEH +struct eeh_vfio_pci_addr { +uint64_t buid;/* PHB BUID */ +uint16_t bdn;/* Bus/Device/Function number */ +uint32_t pe_addr;/* PE configuration address */ +}; +#endif /* CONFIG_VFIO_EEH */ +/* * The struct is used to trace PE related EEH functionality. * In theory, there will have one instance of the struct to
@@ -72,6 +80,7 @@ struct device_node;#define EEH_PE_RESET (1 << 2)/* PE reset in progress */ #define EEH_PE_KEEP (1 << 8)/* Keep PE on hotplug */ +#define EEH_PE_PASSTHROUGH (1 << 9)/* PE owned by guest */ struct eeh_pe {int type;/* PE type: PHB/Bus/Device */
@@ -85,6 +94,9 @@ struct eeh_pe {struct timeval tstamp;/* Time on first-time freeze */ int false_positives;/* Times of reported #ff's */ struct eeh_pe *parent;/* Parent PE */ +#ifdef CONFIG_VFIO_EEH +struct eeh_vfio_pci_addr gaddr;/* Address in guest */ +#endif struct list_head child_list;/* Link PE to the child list */ struct list_head edevs;/* Link list of EEH devices */ struct list_head child;/* Child PEs */
@@ -93,6 +105,21 @@ 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 ? !!(pe->state &EEH_PE_PASSTHROUGH ) : false; +} + +static inline void eeh_pe_set_passed (struct eeh_pe *pe,bool passed) +{ +if (pe) { +if (passed) + pe->state |=EEH_PE_PASSTHROUGH ; +else + pe->state &= ~EEH_PE_PASSTHROUGH ; + } +} +/* * The struct is used to trace EEH state for the associated * PCI device node or PCI device. In future, it might
@@ -110,6 +137,7 @@ struct eeh_pe {#define EEH_DEV_SYSFS (1 << 9)/* Sysfs created */ #define EEH_DEV_REMOVED (1 << 10)/* Removed permanently */ #define EEH_DEV_FRESET (1 << 11)/* Fundamental reset */ +#define EEH_DEV_PASSTHROUGH (1 << 12)/* Owned by guest */ struct eeh_dev {int mode;/* EEH mode */
@@ -126,6 +154,9 @@ struct eeh_dev {struct device_node *dn;/* Associated device node */ struct pci_dev *pdev;/* Associated PCI device */ struct pci_bus *bus;/* PCI bus for partial hotplug */ +#ifdef CONFIG_VFIO_EEH +struct eeh_vfio_pci_addr gaddr;/* Address in guest */ +#endif };static inline struct device_node *eeh_dev_to_of_node (struct eeh_dev *edev)
@@ -138,6 +169,21 @@ static inline struct pci_dev *eeh_dev_to_pci_dev(struct eeh_dev *edev)return edev ? edev->pdev :NULL ; } +static inline bool eeh_dev_passed (struct eeh_dev *dev) +{ +return dev ? !!(dev->mode &EEH_DEV_PASSTHROUGH ) : false; +} + +static inline void eeh_dev_set_passed (struct eeh_dev *dev,bool passed) +{ +if (dev) { +if (passed) + dev->mode |=EEH_DEV_PASSTHROUGH ; +else + dev->mode &= ~EEH_DEV_PASSTHROUGH ; + } +} +/* Return values from eeh_ops::next_error */ enum {EEH_NEXT_ERR_NONE =0 ,
Signature · 1 line
1.8.3.2
PATCH v2 3/10 powerpc/eeh: Search EEH device by guest address
In reply to Gavin ShanThe patch introduces function eeh_vfio_dev_get() to search the EEH device according to its guest address, which is made up of PHB BUID, bus, slot and function number. The function is useful in the backends for EEH RTAS emulation.
--- arch/powerpc/include/asm/eeh.h | 5 +++++ arch/powerpc/kernel/eeh_pe.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
arch/powerpc/include/asm/eeh.h +5 -0
@@ -381,6 +381,11 @@ static inline void eeh_remove_device(struct pci_dev *dev) { }#define EEH_IO_ERROR_VALUE (size) (-1UL)#endif /* CONFIG_EEH */ + +#ifdef CONFIG_VFIO_EEH +struct eeh_dev *eeh_vfio_dev_get (struct eeh_vfio_pci_addr *addr); +#endif /* CONFIG_VFIO_EEH */ +#ifdef CONFIG_PPC64 /* * MMIO read/write operations with EEH support.
arch/powerpc/kernel/eeh_pe.c +42 -0
48 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v2 4/10 powerpc/eeh: Search EEH PE by guest address
In reply to Gavin ShanThe patch introduces function eeh_vfio_pe_get() to search the EEH PE according to its guest address, which is made up of PHB ID and PE configuration address. The function will be useful in backends for EEH RTAS emulation.
--- arch/powerpc/include/asm/eeh.h | 1 + arch/powerpc/kernel/eeh_pe.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
arch/powerpc/include/asm/eeh.h +1 -0
@@ -384,6 +384,7 @@ static inline void eeh_remove_device(struct pci_dev *dev) { }#ifdef CONFIG_VFIO_EEH struct eeh_dev *eeh_vfio_dev_get (struct eeh_vfio_pci_addr *addr); +struct eeh_pe *eeh_vfio_pe_get (struct eeh_vfio_pci_addr *addr);#endif /* CONFIG_VFIO_EEH */ #ifdef CONFIG_PPC64
arch/powerpc/kernel/eeh_pe.c +38 -0
@@ -288,6 +288,44 @@ struct eeh_dev *eeh_vfio_dev_get(struct eeh_vfio_pci_addr *addr)return NULL ; } + +static void *__eeh_vfio_pe_get (void *data,void *flag) +{ +struct eeh_pe *pe = (struct eeh_pe *)data; +struct eeh_vfio_pci_addr *addr = (struct eeh_vfio_pci_addr *)flag; + +if (!eeh_pe_passed (pe)) +return NULL ; + +/* Comparing the address */ +if (addr->buid = pe->gaddr.buid && + addr->pe_addr = pe->gaddr.pe_addr) +return pe; + +return NULL ; +} + +/** +* eeh_vfio_pe_get - Search EEH PE based on guest's address +* @addr: EEH PE guest address +* +* Search the EEH PE according to the guest address, which +* is made up of VM indicator, PHB BUID, and PE configuration +* address. +*/ +struct eeh_pe *eeh_vfio_pe_get (struct eeh_vfio_pci_addr *addr) +{ +struct eeh_pe *root; +struct eeh_pe *pe; + +list_for_each_entry (root, &eeh_phb_pe, child) { + pe =eeh_pe_traverse (root, __eeh_vfio_pe_get, addr); +if (pe) +return pe; + } + +return NULL ; +}#endif /* CONFIG_VFIO_EEH */ /**
Signature · 1 line
1.8.3.2
PATCH v2 5/10 drivers/vfio: New IOCTL command VFIO_EEH_INFO
In reply to Gavin ShanThe patch adds new IOCTL command VFIO_EEH_INFO to VFIO container to support EEH functionality for PCI devices, which have been passed from host to guest via VFIO.
--- arch/powerpc/platforms/powernv/Makefile | 1 + arch/powerpc/platforms/powernv/eeh-vfio.c | 584 ++++++++++++++++++++++++++++++ drivers/vfio/vfio_iommu_spapr_tce.c | 12 + include/uapi/linux/vfio.h | 61 ++++ 4 files changed, 658 insertions(+) create mode 100644 arch/powerpc/platforms/powernv/eeh-vfio.c
arch/powerpc/platforms/powernv/Makefile +1 -0
@@ -6,5 +6,6 @@ obj-y += opal-msglog.o obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_PCI) += pci.o pci-p5ioc2.o pci-ioda.o obj-$(CONFIG_EEH) += eeh-ioda.o eeh-powernv.o +obj-$(CONFIG_VFIO_EEH) += eeh-vfio.o obj-$(CONFIG_PPC_SCOM) += opal-xscom.o obj-$(CONFIG_MEMORY_FAILURE) += opal-memory-errors.o
arch/powerpc/platforms/powernv/eeh-vfio.c new file +584 -0
584 lines not on this page · raw message
drivers/vfio/vfio_iommu_spapr_tce.c +12 -0
@@ -26,6 +26,11 @@#define DRIVER_AUTHOR "[email protected]"#define DRIVER_DESC "VFIO IOMMU SPAPR TCE" +#ifdef CONFIG_VFIO_EEH +extern void eeh_vfio_release (struct iommu_table *tbl); +extern int eeh_vfio_ioctl (unsigned long arg); +#endif +static void tce_iommu_detach_group (void *iommu_data,struct iommu_group *iommu_group);
@@ -283,6 +288,10 @@ static long tce_iommu_ioctl(void *iommu_data,tce_iommu_disable (container);mutex_unlock (&container->lock);return 0 ; +#ifdef CONFIG_VFIO_EEH +case VFIO_EEH_INFO : +return eeh_vfio_ioctl (arg); +#endif }return -ENOTTY ;
@@ -342,6 +351,9 @@ static void tce_iommu_detach_group(void *iommu_data,/* pr_debug("tce_vfio: detaching group #%u from iommu %p\n", iommu_group_id(iommu_group), iommu_group); */ container->tbl =NULL ; +#ifdef CONFIG_VFIO_EEH +eeh_vfio_release (tbl); +#endif iommu_release_ownership (tbl); }mutex_unlock (&container->lock);
include/uapi/linux/vfio.h +61 -0
67 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v2 6/10 powerpc/eeh: Avoid event on passed PE
In reply to Gavin ShanIf we detects frozen state on PE that has been passed to guest, we needn't handle it. Instead, we rely on the guest to detect and recover it. The patch avoid EEH event on the frozen passed PE so that the guest can have chance to handle that.
--- arch/powerpc/kernel/eeh.c | 8 ++++++++ arch/powerpc/platforms/powernv/eeh-ioda.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-)
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 has been passed to guest, we won't check the +* state. Instead, let the guest 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
@@ -890,7 +890,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 v2 7/10 powerpc/powernv: Sync OPAL header file with firmware
In reply to Gavin ShanThe patch synchronizes OPAL header file with firmware so that the host kernel can make OPAL call to do error injection.
--- arch/powerpc/include/asm/opal.h | 65 ++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + 2 files changed, 66 insertions(+)
arch/powerpc/include/asm/opal.h +65 -0
@@ -175,6 +175,7 @@ extern int opal_enter_rtas(struct rtas_args *args,#define OPAL_SET_PARAM 90#define OPAL_DUMP_RESEND 91#define OPAL_DUMP_INFO2 94 +#define OPAL_ERR_INJECT 96#ifndef __ASSEMBLY__
@@ -219,6 +220,69 @@ enum OpalPciErrorSeverity {OPAL_EEH_SEV_INF =5 }; +enum OpalErrinjctType { + OpalErrinjctTypeFirst =0 , + OpalErrinjctTypeFatal =1 , + OpalErrinjctTypeRecoverRandomEvent =2 , + OpalErrinjctTypeRecoverSpecialEvent =3 , + OpalErrinjctTypeCorruptedPage =4 , + OpalErrinjctTypeCorruptedSlb =5 , + OpalErrinjctTypeTranslatorFailure =6 , + OpalErrinjctTypeIoaBusError =7 , + OpalErrinjctTypeIoaBusError64 =8 , + OpalErrinjctTypePlatformSpecific =9 , + OpalErrinjctTypeDcacheStart =10 , + OpalErrinjctTypeDcacheEnd =11 , + OpalErrinjctTypeIcacheStart =12 , + OpalErrinjctTypeIcacheEnd =13 , + OpalErrinjctTypeTlbStart =14 , + OpalErrinjctTypeTlbEnd =15 , + OpalErrinjctTypeUpstreamIoError =16 , + OpalErrinjctTypeLast =17 , + +/* IoaBusError & IoaBusError64 */ + OpalEjtIoaLoadMemAddr =0 , + OpalEjtIoaLoadMemData =1 , + OpalEjtIoaLoadIoAddr =2 , + OpalEjtIoaLoadIoData =3 , + OpalEjtIoaLoadConfigAddr =4 , + OpalEjtIoaLoadConfigData =5 , + OpalEjtIoaStoreMemAddr =6 , + OpalEjtIoaStoreMemData =7 , + OpalEjtIoaStoreIoAddr =8 , + OpalEjtIoaStoreIoData =9 , + OpalEjtIoaStoreConfigAddr =10 , + OpalEjtIoaStoreConfigData =11 , + OpalEjtIoaDmaReadMemAddr =12 , + OpalEjtIoaDmaReadMemData =13 , + OpalEjtIoaDmaReadMemMaster =14 , + OpalEjtIoaDmaReadMemTarget =15 , + OpalEjtIoaDmaWriteMemAddr =16 , + OpalEjtIoaDmaWriteMemData =17 , + OpalEjtIoaDmaWriteMemMaster =18 , + OpalEjtIoaDmaWriteMemTarget =19 , +}; + +struct OpalErrinjct { +int32_t type; +union { +struct { +uint32_t addr; +uint32_t mask; +uint64_t phb_id; +uint32_t pe; +uint32_t function; + }ioa; +struct { +uint64_t addr; +uint64_t mask; +uint64_t phb_id; +uint32_t pe; +uint32_t function; + }ioa64; + }; +}; +enum OpalShpcAction {OPAL_SHPC_GET_LINK_STATE =0 ,OPAL_SHPC_GET_SLOT_STATE =1
@@ -839,6 +903,7 @@ int64_t opal_pci_get_phb_diag_data(uint64_t phb_id, void *diag_buffer, uint64_t diag_buffer_len);int64_t opal_pci_get_phb_diag_data2 (uint64_t phb_id,void *diag_buffer,uint64_t diag_buffer_len); +int64_t opal_err_injct (void *data);int64_t opal_pci_fence_phb (uint64_t phb_id);int64_t opal_pci_reinit (uint64_t phb_id,uint64_t reinit_scope,uint64_t data);int64_t opal_pci_mask_pe_error (uint64_t phb_id,uint16_t pe_number,uint8_t error_type,uint8_t mask_action);
arch/powerpc/platforms/powernv/opal-wrappers.S +1 -0
@@ -119,6 +119,7 @@ OPAL_CALL(opal_pci_next_error, OPAL_PCI_NEXT_ERROR); OPAL_CALL(opal_pci_poll, OPAL_PCI_POLL); OPAL_CALL(opal_pci_msi_eoi, OPAL_PCI_MSI_EOI); OPAL_CALL(opal_pci_get_phb_diag_data2, OPAL_PCI_GET_PHB_DIAG_DATA2); +OPAL_CALL(opal_err_injct, OPAL_ERR_INJECT); OPAL_CALL(opal_xscom_read, OPAL_XSCOM_READ); OPAL_CALL(opal_xscom_write, OPAL_XSCOM_WRITE); OPAL_CALL(opal_lpc_read, OPAL_LPC_READ);
Signature · 1 line
1.8.3.2
PATCH v2 8/10 powerpc: Extend syscall ppc_rtas()
In reply to Gavin ShanOriginally, syscall ppc_rtas() can be used to invoke RTAS call from user space. Utility "errinjct" is using it to inject various errors to the system for testing purpose. The patch intends to extend the syscall to support both pSeries and PowerNV platform. With that, RTAS and OPAL call can be invoked from user space. In turn, utility "errinjct" can be supported on pSeries and PowerNV platform at same time.
The original syscall handler ppc_rtas() is renamed to ppc_firmware(), which calls ppc_call_rtas() or ppc_call_opal() depending on the running platform. The data transported between userland and kerenl is by "struct rtas_args". It's platform specific on how to use the data.
--- arch/powerpc/include/asm/rtas.h | 10 +++++- arch/powerpc/include/asm/syscalls.h | 2 +- arch/powerpc/include/asm/systbl.h | 2 +- arch/powerpc/include/uapi/asm/unistd.h | 2 +- arch/powerpc/kernel/rtas.c | 57 +++++++--------------------------- arch/powerpc/kernel/syscalls.c | 50 +++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal.c | 7 +++++ kernel/sys_ni.c | 2 +- 8 files changed, 82 insertions(+), 50 deletions(-)
arch/powerpc/include/asm/rtas.h +9 -1
@@ -20,7 +20,7 @@#define RTAS_UNKNOWN_SERVICE (-1)#define RTAS_INSTANTIATE_MAX (1ULL<<30)/* Don't instantiate rtas at/above this value */ -/* Buffer size for ppc_rtas system call. */ +/* Buffer size for ppc_firmware system call. */ #define RTAS_RMOBUF_MAX (64 * 1024)/* RTAS return status codes */
@@ -427,9 +427,17 @@ static inline int page_is_rtas_user_buf(unsigned long pfn)/* Not the best place to put pSeries_coalesce_init, will be fixed when we * move some of the rtas suspend-me stuff to pseries */ extern void pSeries_coalesce_init (void ); +extern int ppc_call_rtas (struct rtas_args *args);#else static inline int page_is_rtas_user_buf (unsigned long pfn) {return 0 ;}static inline void pSeries_coalesce_init (void ) { } +static inline int ppc_call_rtas (struct rtas_args *args) {return -ENXIO ; } +#endif + +#ifdef CONFIG_PPC_POWERNV +extern int ppc_call_opal (struct rtas_args *args); +#else +static inline int ppc_call_opal (struct rtas_arts *args) {return -ENXIO ; }#endif extern int call_rtas (const char *,int ,int ,unsigned long *, ...);
arch/powerpc/include/asm/syscalls.h +1 -1
@@ -15,7 +15,7 @@ asmlinkage unsigned long sys_mmap2(unsigned long addr, size_t len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long pgoff);asmlinkage long ppc64_personality (unsigned long personality); -asmlinkage int ppc_rtas(struct rtas_args __user *uargs); +asmlinkage int ppc_firmware(struct rtas_args __user *uargs);#endif /* __KERNEL__ */ #endif /* __ASM_POWERPC_SYSCALLS_H */
arch/powerpc/include/asm/systbl.h +1 -1
@@ -259,7 +259,7 @@ COMPAT_SYS_SPU(utimes) COMPAT_SYS_SPU(statfs64) COMPAT_SYS_SPU(fstatfs64) SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64) -PPC_SYS_SPU(rtas) +PPC_SYS_SPU(firmware) OLDSYS(debug_setcontext) SYSCALL(ni_syscall) COMPAT_SYS(migrate_pages)
arch/powerpc/include/uapi/asm/unistd.h +1 -1
@@ -273,7 +273,7 @@#ifndef __powerpc64__#define __NR_fadvise64_64 254#endif -#define __NR_rtas 255 +#define __NR_firmware 255#define __NR_sys_debug_setcontext 256/* Number 257 is reserved for vserver */ #define __NR_migrate_pages 258
arch/powerpc/kernel/rtas.c +12 -45
84 lines not on this page · raw message
arch/powerpc/kernel/syscalls.c +50 -0
56 lines not on this page · raw message
arch/powerpc/platforms/powernv/opal.c +7 -0
@@ -25,6 +25,7 @@#include <asm/opal.h> #include <asm/firmware.h> #include <asm/mce.h> +#include <asm/rtas.h> #include "powernv.h"
@@ -701,3 +702,9 @@ void opal_free_sg_list(struct opal_sg_list *sg) sg =NULL ; } } + +/* Extend it later */ +int ppc_call_opal (struct rtas_args *args) +{ +return 0 ; +}
kernel/sys_ni.c +1 -1
@@ -159,7 +159,7 @@ cond_syscall(sys_pciconfig_read);cond_syscall (sys_pciconfig_write);cond_syscall (sys_pciconfig_iobase);cond_syscall (compat_sys_s390_ipc); -cond_syscall (ppc_rtas); +cond_syscall (ppc_firmware);cond_syscall (sys_spu_run);cond_syscall (sys_spu_create);cond_syscall (sys_subpage_prot);
Signature · 1 line
1.8.3.2
PATCH v2 9/10 powerpc/powernv: Implement ppc_call_opal()
In reply to Gavin ShanIf we're running PowerNV platform, ppc_firmware() will be directed to ppc_call_opal() where we can call to OPAL API accordingly. In ppc_call_opal(), the input argument are parsed out and call to appropriate OPAL API to handle that. Each request passed to the function is identified with token. As we get to the function either from host owned application (e.g. errinjct) or VM, we always have the first parameter (so-called "virtual") to differentiate the cases.
The patch implements above logic and OPAL call handler dynamica registeration mechanism so that the handlers could be distributed.
--- arch/powerpc/include/asm/opal.h | 3 +- arch/powerpc/platforms/powernv/opal.c | 90 ++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/opal.h +2 -1
@@ -997,7 +997,8 @@ extern void opal_lpc_init(void);struct opal_sg_list *opal_vmalloc_to_sg_list (void *vmalloc_addr,unsigned long vmalloc_size);void opal_free_sg_list (struct opal_sg_list *sg); - +int opal_call_handler_register (bool virt,int token, +int (*fn)(struct rtas_args *));#endif /* __ASSEMBLY__ */ #endif /* __OPAL_H */
arch/powerpc/platforms/powernv/opal.c +88 -2
108 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v2 10/10 powerpc/powernv: Error injection infrastructure
In reply to Gavin ShanThe patch intends to implemdent the error injection infrastructure for PowerNV platform. The predetermined handlers will be called according to the type of injected error (e.g. OpalErrinjctTypeIoaBusError). For now, we just support PCI error injection. We need support injecting other types of errors in future.
--- arch/powerpc/include/asm/opal.h | 6 + arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/errinject.c | 224 +++++++++++++++++++++++++++++ 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/platforms/powernv/errinject.c
arch/powerpc/include/asm/opal.h +6 -0
@@ -794,6 +794,12 @@ typedef struct oppanel_line {uint64_t line_len; } oppanel_line_t; +enum OpalCallToken { +OPAL_CALL_TOKEN_MIN =0 , +OPAL_CALL_TOKEN_ERRINJCT , +OPAL_CALL_TOKEN_MAX +}; +/* /sys/firmware/opal */ extern struct kobject *opal_kobj;
arch/powerpc/platforms/powernv/Makefile +1 -1
@@ -1,7 +1,7 @@ obj-y += setup.o opal-takeover.o opal-wrappers.o opal.o opal-async.o obj-y += opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o obj-y += rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o -obj-y += opal-msglog.o +obj-y += opal-msglog.o errinject.o obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_PCI) += pci.o pci-p5ioc2.o pci-ioda.o
arch/powerpc/platforms/powernv/errinject.c new file +224 -0
224 lines not on this page · raw message
Signature · 1 line
1.8.3.2
On Fri, May 09, 2014 at 05:49:32PM +1000, Gavin Shan wrote:
Sorry for having missed cc'ing Alex Graf. Amending it.
Quoted 80 lines
The series of patches intends to 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_INFO) and gets handled in host kernel.- The error injection infrastructure need support request from the userland utility "errinjct" and PowerKVM based guest. The userland utility "errinjct" works on pSeries platform well with dedicated syscall, which helps invoking RTAS service to fulfil error injection in kernel. From the perspective, it's reasonable to extend the syscall to support PowerNV platform so that OPAL call can be invoked in host kernel for injecting errors. The data transported between userland and kerenl is still following "struct
rtas_args" for both cases of PowerNV (OPAL) and pSeries (RTAS).The series of patches requires corresponding firmware changes from Mike Qiu to support error injection and QEMU changes to support EEH for guest. QEMU patchset will be sent separately.
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.Testing on P7
======>
- Emulex adapterTesting on P8
======>
- Need more testing after design is finalized.-----
Gavin Shan (10):
drivers/vfio: IntroduceCONFIG_VFIO_EEHpowerpc/eeh: Info to trace passed devices powerpc/eeh: Search EEH device by guest address powerpc/eeh: Search EEH PE by guest addressdrivers/vfio: New IOCTL commandVFIO_EEH_INFOpowerpc/eeh: Avoid event on passed PE powerpc/powernv: Sync OPAL header file with firmware
powerpc: Extend syscallppc_rtas()powerpc/powernv: Implementppc_call_opal()powerpc/powernv: Error injection infrastructurearch/powerpc/include/asm/eeh.h | 52 +++++++++++++ arch/powerpc/include/asm/opal.h | 74 +++++++++++++++++- arch/powerpc/include/asm/rtas.h | 10 ++- arch/powerpc/include/asm/syscalls.h | 2 +- arch/powerpc/include/asm/systbl.h | 2 +- arch/powerpc/include/uapi/asm/unistd.h | 2 +- arch/powerpc/kernel/eeh.c | 8 ++ arch/powerpc/kernel/eeh_pe.c | 80 +++++++++++++++++++ arch/powerpc/kernel/rtas.c | 57 +++----------- arch/powerpc/kernel/syscalls.c | 50 ++++++++++++ arch/powerpc/platforms/powernv/Makefile | 3 +- arch/powerpc/platforms/powernv/eeh-ioda.c | 3 +- arch/powerpc/platforms/powernv/eeh-vfio.c | 584 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/errinject.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + arch/powerpc/platforms/powernv/opal.c | 93 ++++++++++++++++++++++ drivers/vfio/Kconfig | 6 ++ drivers/vfio/vfio_iommu_spapr_tce.c | 12 +++ include/uapi/linux/vfio.h | 61 +++++++++++++++ kernel/sys_ni.c | 2 +- 20 files changed, 1271 insertions(+), 53 deletions(-)create mode 100644
arch/powerpc/platforms/powernv/eeh-vfio.ccreate mode 100644arch/powerpc/platforms/powernv/errinject.cThanks,
Gavin