Support EEH Error Injection
cover Support EEH Error Injection
The patchset depends on the corresponding host kernel changes:
https://patchwork.ozlabs.org/patch/448824/
https://patchwork.ozlabs.org/patch/448823/
According to PAPR specification 2.7, there're 3 RTAS calls relevent to error
injection: "ibm,open-errinjct", "ibm,close-errinjct", "ibm,errinjct". The userland utility "errinjct" running on guest utilizes those 3 RTAS calls like this way:
Call "ibm,open-errinjct" that returns open-token, which is passed to "ibm,errinjct" together with error specific arguments to do error injection. Finally, to return the open-token by calling "ibm,close-errinject".
"ibm,errinjct" can be used to inject various errors, not limited to EEH errors. However, this patchset is going to support injecting EEH errors only for VFIO PCI devices.
Gavin Shan (3):
linux-headers: Sync vfio.h
sPAPR: Support RTAS call ibm,{open,close}-errinjct
sPAPR: Support RTAS call ibm,errinjct
hw/ppc/spapr_pci.c | 47 +++++++++++++ hw/ppc/spapr_pci_vfio.c | 99 +++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 160 +++++++++++++++++++++++++++++++++++++++++++- include/hw/pci-host/spapr.h | 2 + include/hw/ppc/spapr.h | 55 ++++++++++++++- linux-headers/linux/vfio.h | 34 +++++++++- 6 files changed, 393 insertions(+), 4 deletions(-)
Signature · 1 line
1.8.3.2
PATCH 1/3 linux-headers: Sync vfio.h
The patch synchronizes vfio.h with the kernel to support EEH error injection.
--- linux-headers/linux/vfio.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
linux-headers/linux/vfio.h +33 -1
@@ -468,12 +468,21 @@ struct vfio_iommu_spapr_tce_info {* - unfreeze IO/DMA for frozen PE; * - read PE state; * - reset PE; -* - configure PE. +* - configure PE; +* - inject EEH error. */ +struct vfio_eeh_pe_err { +__u32 type; +__u32 func; +__u64 addr; +__u64 mask; +}; +struct vfio_eeh_pe_op {__u32 argsz;__u32 flags;__u32 op; +__u8 data[]; };#define VFIO_EEH_PE_DISABLE 0/* Disable EEH functionality */
@@ -490,6 +499,29 @@ struct vfio_eeh_pe_op {#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_INJECT_ERR 9/* Inject EEH error */ +#define VFIO_EEH_ERR_TYPE_32 0/* 32-bits EEH error type */ +#define VFIO_EEH_ERR_TYPE_64 1/* 64-bits EEH error type */ +#define VFIO_EEH_ERR_FUNC_LD_MEM_ADDR 0/* Memory load */ +#define VFIO_EEH_ERR_FUNC_LD_MEM_DATA 1 +#define VFIO_EEH_ERR_FUNC_LD_IO_ADDR 2/* IO load */ +#define VFIO_EEH_ERR_FUNC_LD_IO_DATA 3 +#define VFIO_EEH_ERR_FUNC_LD_CFG_ADDR 4/* Config load */ +#define VFIO_EEH_ERR_FUNC_LD_CFG_DATA 5 +#define VFIO_EEH_ERR_FUNC_ST_MEM_ADDR 6/* Memory store */ +#define VFIO_EEH_ERR_FUNC_ST_MEM_DATA 7 +#define VFIO_EEH_ERR_FUNC_ST_IO_ADDR 8/* IO store */ +#define VFIO_EEH_ERR_FUNC_ST_IO_DATA 9 +#define VFIO_EEH_ERR_FUNC_ST_CFG_ADDR 10/* Config store */ +#define VFIO_EEH_ERR_FUNC_ST_CFG_DATA 11 +#define VFIO_EEH_ERR_FUNC_DMA_RD_ADDR 12/* DMA read */ +#define VFIO_EEH_ERR_FUNC_DMA_RD_DATA 13 +#define VFIO_EEH_ERR_FUNC_DMA_RD_MASTER 14 +#define VFIO_EEH_ERR_FUNC_DMA_RD_TARGET 15 +#define VFIO_EEH_ERR_FUNC_DMA_WR_ADDR 16/* DMA write */ +#define VFIO_EEH_ERR_FUNC_DMA_WR_DATA 17 +#define VFIO_EEH_ERR_FUNC_DMA_WR_MASTER 18 +#define VFIO_EEH_ERR_FUNC_DMA_WR_TARGET 19#define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21)
Signature · 1 line
1.8.3.2
PATCH 2/3 sPAPR: Support RTAS call ibm, {open, close}-errinjct
In reply to Gavin ShanThe patch supports RTAS calls "ibm,{open,close}-errinjct" to manupliate the token, which is passed to RTAS call "ibm,errinjct" to indicate the valid context for error injection. Each VM is permitted to have only one token at once and we simply have one random number for that.
--- hw/ppc/spapr_rtas.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 ++++++- 2 files changed, 81 insertions(+), 1 deletion(-)
hw/ppc/spapr_rtas.c +73 -0
@@ -245,6 +245,75 @@ static void rtas_ibm_os_term(PowerPCCPU *cpu,rtas_st (rets,0 , ret); } +static void rtas_ibm_open_errinjct (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args,uint32_t nret, +target_ulong rets) +{ +int32_t ret; + +/* Sanity check on number of arguments */ +if ((nargs !=0 ) || (nret !=2 )) { + ret =RTAS_OUT_PARAM_ERROR ; + goto out; + } + +/* Check if we already had token */ +if (spapr->errinjct_token) { + ret =RTAS_OUT_TOKEN_OPENED ; + goto out; + } + +/* Grab random number as token */ + spapr->errinjct_token =random (); +if (spapr->errinjct_token ==0 ) { + ret =RTAS_OUT_BUSY ; + goto out; + } + +/* Success */ +rtas_st (rets,0 , spapr->errinjct_token); + ret =RTAS_OUT_SUCCESS ; +out: +rtas_st (rets,1 , ret); +} + +static void rtas_ibm_close_errinjct (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args,uint32_t nret, +target_ulong rets) +{ +uint32_t open_token; +int32_t ret; + +/* Sanity check on number of arguments */ +if ((nargs !=1 ) || (nret !=1 )) { + ret =RTAS_OUT_PARAM_ERROR ; + goto out; + } + +/* Check if we had opened token */ +if (!spapr->errinjct_token) { + ret =RTAS_OUT_CLOSE_ERROR ; + goto out; + } + +/* Check if it's the opened token */ + open_token =rtas_ld (args,0 ); +if (spapr->errinjct_token != open_token) { + ret =RTAS_OUT_CLOSE_ERROR ; + goto out; + } + +/* Success */ + spapr->errinjct_token =0 ; + ret =RTAS_OUT_SUCCESS ; +out: +rtas_st (rets,0 , ret); +} + static struct rtas_call { const char *name; spapr_rtas_fn fn;
@@ -370,6 +439,10 @@ static void core_rtas_register_types(void) rtas_ibm_set_system_parameter);spapr_rtas_register (RTAS_IBM_OS_TERM ,"ibm,os-term" , rtas_ibm_os_term); +spapr_rtas_register (RTAS_IBM_OPEN_ERRINJCT ,"ibm,open-errinjct" , + rtas_ibm_open_errinjct); +spapr_rtas_register (RTAS_IBM_CLOSE_ERRINJCT ,"ibm,close-errinjct" , + rtas_ibm_close_errinjct); }type_init (core_rtas_register_types)
include/hw/ppc/spapr.h +8 -1
@@ -39,6 +39,9 @@ typedef struct sPAPREnvironment {bool htab_first_pass;int htab_fd;bool htab_fd_stale; + +/* Error injection token */ +uint32_t errinjct_token; } sPAPREnvironment;#define H_SUCCESS 0
@@ -379,6 +382,8 @@ int spapr_allocate_irq_block(int num, bool lsi, bool msi);#define RTAS_OUT_BUSY -2#define RTAS_OUT_PARAM_ERROR -3#define RTAS_OUT_NOT_SUPPORTED -3 +#define RTAS_OUT_TOKEN_OPENED -4 +#define RTAS_OUT_CLOSE_ERROR -4#define RTAS_OUT_NOT_AUTHORIZED -9002/* RTAS tokens */
@@ -422,8 +427,10 @@ int spapr_allocate_irq_block(int num, bool lsi, bool msi);#define RTAS_IBM_SET_SLOT_RESET (RTAS_TOKEN_BASE + 0x23)#define RTAS_IBM_CONFIGURE_PE (RTAS_TOKEN_BASE + 0x24)#define RTAS_IBM_SLOT_ERROR_DETAIL (RTAS_TOKEN_BASE + 0x25) +#define RTAS_IBM_OPEN_ERRINJCT (RTAS_TOKEN_BASE + 0x26) +#define RTAS_IBM_CLOSE_ERRINJCT (RTAS_TOKEN_BASE + 0x27) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x26) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x28)/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20
Signature · 1 line
1.8.3.2
PATCH 3/3 sPAPR: Support RTAS call ibm,errinjct
In reply to Gavin ShanThe patch supports RTAS call "ibm,errinjct" to allow injecting EEH errors to VFIO PCI devices. The implementation is similiar to EEH support for VFIO PCI devices: The RTAS request is captured by QEMU and routed to sPAPRPHBClass::eeh_error_inject() where the request is translated to VFIO container IOCTL command to be handled by the host.
--- hw/ppc/spapr_pci.c | 47 +++++++++++++++++++++ hw/ppc/spapr_pci_vfio.c | 99 +++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 87 ++++++++++++++++++++++++++++++++++++++- include/hw/pci-host/spapr.h | 2 + include/hw/ppc/spapr.h | 48 +++++++++++++++++++++- 5 files changed, 280 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +47 -0
@@ -658,6 +658,53 @@ param_error_exit:rtas_st (rets,0 ,RTAS_OUT_PARAM_ERROR ); } +int spapr_rtas_errinjct_ioa (sPAPREnvironment *spapr, +target_ulong param_buf, +bool is_64bits) +{ +sPAPRPHBState *sphb; +sPAPRPHBClass *spc; +uint64_t buid, addr, mask; +uint32_t func; +int ret; + +if (is_64bits) { + addr =rtas_ldq (param_buf,0 ); + mask =rtas_ldq (param_buf,1 ); + buid = ((uint64_t )rtas_ld (param_buf,5 ) <<32 ) |rtas_ld (param_buf,6 ); + func =rtas_ld (param_buf,7 ); + }else { + addr =rtas_ld (param_buf,0 ); + mask =rtas_ld (param_buf,1 ); + buid = ((uint64_t )rtas_ld (param_buf,3 ) <<32 ) |rtas_ld (param_buf,4 ); + func =rtas_ld (param_buf,5 ); + } + +/* Check function is valid */ +if (func >RTAS_ERRINJCT_IOA_DMA_WR_MEM_TARGET ) { +return RTAS_OUT_PARAM_ERROR ; + } + +/* Find PHB */ + sphb =find_phb (spapr, buid); +if (!sphb) { +return RTAS_OUT_PARAM_ERROR ; + } + + spc =SPAPR_PCI_HOST_BRIDGE_GET_CLASS (sphb); +if (!spc->eeh_error_inject) { +return RTAS_OUT_PARAM_ERROR ; + } + +/* Handle the request */ + ret = spc->eeh_error_inject (sphb, func, addr, mask, is_64bits); +if (ret <0 ) { +return RTAS_OUT_HW_ERROR ; + } + +return RTAS_OUT_SUCCESS ; +} +static int pci_spapr_swizzle (int slot,int pin) {return (slot + pin) %PCI_NUM_PINS ;
hw/ppc/spapr_pci_vfio.c +99 -0
111 lines not on this page · raw message
hw/ppc/spapr_rtas.c +85 -2
105 lines not on this page · raw message
include/hw/pci-host/spapr.h +2 -0
@@ -53,6 +53,8 @@ struct sPAPRPHBClass {int (*eeh_get_state)(sPAPRPHBState *sphb,int *state);int (*eeh_reset)(sPAPRPHBState *sphb,int option);int (*eeh_configure)(sPAPRPHBState *sphb); +int (*eeh_error_inject)(sPAPRPHBState *sphb,uint32_t func, +uint64_t addr,uint64_t mask,bool is_64bits); }; typedef struct spapr_pci_msi {
include/hw/ppc/spapr.h +47 -1
73 lines not on this page · raw message
Signature · 1 line
1.8.3.2