Add support for the 'ibm,open-errinjct' and 'ibm,close-errinjct' RTAS calls. These handlers manage exclusive access to error injection facilities through a simple session-based mechanism.
Updates include: - Implementation of rtas_ibm_open_errinjct() and rtas_ibm_close_errinjct() - Tracking field 'spapr->errinjct_token' in SpaprMachineState - New token definitions for the above RTAS calls - Return codes for already open or invalid close conditions This ensures that only one guest process can actively perform error injection at a time, improving reliability and preventing conflicts. Signed-off-by: Narayana Murty N <[email protected]> --- --- include/hw/ppc/spapr.h | 8 +++++- hw/ppc/spapr_pci.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index f762be030c..af9617b13e 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -283,6 +283,7 @@ struct SpaprMachineState { Error *fwnmi_migration_blocker; SpaprWatchdog wds[WDT_MAX_WATCHDOGS]; + uint32_t errinjct_token; }; #define H_SUCCESS 0 @@ -755,6 +756,9 @@ enum rtas_err_type { #define RTAS_OUT_PARAM_ERROR -3 #define RTAS_OUT_NOT_SUPPORTED -3 #define RTAS_OUT_NO_SUCH_INDICATOR -3 +#define RTAS_OUT_ALREADY_OPEN -4 +#define RTAS_OUT_NOT_OPEN -5 +#define RTAS_OUT_CLOSE_ERROR -6 #define RTAS_OUT_NOT_AUTHORIZED -9002 #define RTAS_OUT_SYSPARM_PARAM_ERROR -9999 @@ -818,8 +822,10 @@ enum rtas_err_type { #define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2B) #define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2C) #define RTAS_IBM_ERRINJCT (RTAS_TOKEN_BASE + 0x2D) +#define RTAS_IBM_OPEN_ERRINJCT (RTAS_TOKEN_BASE + 0x2E) +#define RTAS_IBM_CLOSE_ERRINJCT (RTAS_TOKEN_BASE + 0x2F) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2E) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x30) /* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 219099f5aa..4723b87c65 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -864,6 +864,65 @@ param_error_exit: rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); } +static void rtas_ibm_open_errinjct(PowerPCCPU *cpu, + SpaprMachineState *spapr, + uint32_t token, + uint32_t nargs, + target_ulong args, + uint32_t nret, + target_ulong rets) +{ + /* Validate argument count */ + if ((nargs != 0) || (nret != 2)) { + rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); + return; + } + + if (spapr->errinjct_token) { + /* Already open: return token=0 and code=ALREADY_OPEN */ + rtas_st(rets, 0, 0); + rtas_st(rets, 1, RTAS_OUT_ALREADY_OPEN); + return; + } + + spapr->errinjct_token = 1; + + /* + * Unlike most RTAS calls, ibm,open-errinjct returns + * the session token in the first output parameter + * and the status in the second. + */ + rtas_st(rets, 0, spapr->errinjct_token); + rtas_st(rets, 1, RTAS_OUT_SUCCESS); +} + +static void rtas_ibm_close_errinjct(PowerPCCPU *cpu, + SpaprMachineState *spapr, + uint32_t token, + uint32_t nargs, + target_ulong args, + uint32_t nret, + target_ulong rets) +{ + uint32_t o_token; + + if ((nargs != 1) || (nret != 1)) { + rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); + return; + } + + o_token = rtas_ld(args, 0); + + if (o_token != spapr->errinjct_token) { + rtas_st(rets, 0, RTAS_OUT_NOT_OPEN); + return; + } + + spapr->errinjct_token = 0; + + rtas_st(rets, 0, RTAS_OUT_SUCCESS); +} + static void pci_spapr_set_irq(void *opaque, int irq_num, int level) { /* @@ -2560,6 +2619,12 @@ void spapr_pci_rtas_init(void) spapr_rtas_register(RTAS_IBM_ERRINJCT, "ibm,errinjct", rtas_ibm_errinjct); + 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); } static void spapr_pci_register_types(void) -- 2.51.0
