RTAS function table and tracepoints
v2 cover RTAS function table and tracepoints
Resubmiting with revisions the remainder from the earlier "RTAS maintenance" series[1] for further comments.
Components:
* Improved function token lookups, including efficient "reverse" token-to-name mappings.
* Static tracepoints for RTAS entry and exit.
Changes:
* Rebase on current powerpc/next.
* Drop unnecessary cast for xa_load() key argument. (Nick Child)
* Document RTAS_FN_FLAG_BANNED_FOR_SYSCALL_ON_LE. (Andrew Donnellan)
* Skip tracepoints in unsafe contexts (real mode, CPU offline). (Nicholas Piggin)
* Convert RTAS tracepoint definitions to unconditional variants (TRACE_EVENT_CONDITION() -> TRACE_EVENT()), dropping a cpu_online() check that duplicates work already done at the call site.
[1] https://lore.kernel.org/linuxppc-dev/[email protected]/
Nathan Lynch (4):
powerpc/rtas: improve function information lookups powerpc/rtas: strengthen do_enter_rtas() type safety, drop inline powerpc/tracing: tracepoints for RTAS entry and exit powerpc/rtas: add tracepoints around RTAS entry
arch/powerpc/include/asm/rtas.h | 87 ++++ arch/powerpc/include/asm/trace.h | 103 ++++ arch/powerpc/kernel/rtas.c | 806 ++++++++++++++++++++++++++----- 3 files changed, 874 insertions(+), 122 deletions(-)
Signature · 1 line
2.37.1
PATCH v2 1/4 powerpc/rtas: improve function information lookups
The core RTAS support code and its clients perform two types of lookup for RTAS firmware function information.
First, mapping a known function name to a token. The typical use case invokes rtas_token() to retrieve the token value to pass to rtas_call(). rtas_token() relies on of_get_property(), which performs a linear search of the /rtas node's property list under a lock with IRQs disabled.
Second, and less common: given a token value, looking up some information about the function. The primary example is the sys_rtas filter path, which linearly scans a small table to match the token to a rtas_filter struct. Another use case to come is RTAS entry/exit tracepoints, which will require efficient lookup of function names from token values. Currently there is no general API for this.
We need something much like the existing rtas_filters table, but more general and organized to facilitate efficient lookups.
Introduce:
* A new rtas_function type, aggregating function name, token, and filter. Other function characteristics could be added in the future.
* An array of rtas_function, where each element corresponds to a known RTAS function. All information in the table is static save the token values, which are derived from the device tree at boot. The array is sorted by function name to allow binary search.
* A named constant for each known RTAS function, used to index the function array. These also will be used in a client-facing API to be added later.
* An xarray that maps valid tokens to rtas_function objects.
Fold the existing rtas_filter table into the new rtas_function array, with the appropriate adjustments to block_rtas_call(). Remove now-redundant fields from struct rtas_filter. Preserve the function of the CONFIG_CPU_BIG_ENDIAN guard in the current filter table by introducing a per-function flag that is set for the function entries related to pseries LPAR migration. These have never had working users via sys_rtas on ppc64le; see commit de0f7349a0dd ("powerpc/rtas:
prevent suspend-related sys_rtas use on LE").
Convert rtas_token() to use a lockless binary search on the function table. Fall back to the old behavior for lookups against names that are not known to be RTAS functions, but issue a warning. rtas_token() is for function names; it is not a general facility for accessing arbitrary properties of the /rtas node. All known misuses of rtas_token() have been converted to more appropriate of_ APIs in preceding changes.
--- arch/powerpc/include/asm/rtas.h | 87 ++++ arch/powerpc/kernel/rtas.c | 741 +++++++++++++++++++++++++++----- 2 files changed, 715 insertions(+), 113 deletions(-)
arch/powerpc/include/asm/rtas.h +87 -0
@@ -16,6 +16,93 @@* Copyright (C) 2001 PPC 64 Team, IBM Corp */ +#define rtas_fnidx (x_) RTAS_FNIDX__ ## x_ + +enum rtas_function_index { + rtas_fnidx(CHECK_EXCEPTION), + rtas_fnidx(DISPLAY_CHARACTER), + rtas_fnidx(EVENT_SCAN), + rtas_fnidx(FREEZE_TIME_BASE), + rtas_fnidx(GET_POWER_LEVEL), + rtas_fnidx(GET_SENSOR_STATE), + rtas_fnidx(GET_TERM_CHAR), + rtas_fnidx(GET_TIME_OF_DAY), + rtas_fnidx(IBM_ACTIVATE_FIRMWARE), + rtas_fnidx(IBM_CBE_START_PTCAL), + rtas_fnidx(IBM_CBE_STOP_PTCAL), + rtas_fnidx(IBM_CHANGE_MSI), + rtas_fnidx(IBM_CLOSE_ERRINJCT), + rtas_fnidx(IBM_CONFIGURE_BRIDGE), + rtas_fnidx(IBM_CONFIGURE_CONNECTOR), + rtas_fnidx(IBM_CONFIGURE_KERNEL_DUMP), + rtas_fnidx(IBM_CONFIGURE_PE), + rtas_fnidx(IBM_CREATE_PE_DMA_WINDOW), + rtas_fnidx(IBM_DISPLAY_MESSAGE), + rtas_fnidx(IBM_ERRINJCT), + rtas_fnidx(IBM_EXTI2C), + rtas_fnidx(IBM_GET_CONFIG_ADDR_INFO), + rtas_fnidx(IBM_GET_CONFIG_ADDR_INFO2), + rtas_fnidx(IBM_GET_DYNAMIC_SENSOR_STATE), + rtas_fnidx(IBM_GET_INDICES), + rtas_fnidx(IBM_GET_RIO_TOPOLOGY), + rtas_fnidx(IBM_GET_SYSTEM_PARAMETER), + rtas_fnidx(IBM_GET_VPD), + rtas_fnidx(IBM_GET_XIVE), + rtas_fnidx(IBM_INT_OFF), + rtas_fnidx(IBM_INT_ON), + rtas_fnidx(IBM_IO_QUIESCE_ACK), + rtas_fnidx(IBM_LPAR_PERFTOOLS), + rtas_fnidx(IBM_MANAGE_FLASH_IMAGE), + rtas_fnidx(IBM_MANAGE_STORAGE_PRESERVATION), + rtas_fnidx(IBM_NMI_INTERLOCK), + rtas_fnidx(IBM_NMI_REGISTER), + rtas_fnidx(IBM_OPEN_ERRINJCT), + rtas_fnidx(IBM_OPEN_SRIOV_ALLOW_UNFREEZE), + rtas_fnidx(IBM_OPEN_SRIOV_MAP_PE_NUMBER), + rtas_fnidx(IBM_OS_TERM), + rtas_fnidx(IBM_PARTNER_CONTROL), + rtas_fnidx(IBM_PHYSICAL_ATTESTATION), + rtas_fnidx(IBM_PLATFORM_DUMP), + rtas_fnidx(IBM_POWER_OFF_UPS), + rtas_fnidx(IBM_QUERY_INTERRUPT_SOURCE_NUMBER), + rtas_fnidx(IBM_QUERY_PE_DMA_WINDOW), + rtas_fnidx(IBM_READ_PCI_CONFIG), + rtas_fnidx(IBM_READ_SLOT_RESET_STATE), + rtas_fnidx(IBM_READ_SLOT_RESET_STATE2), + rtas_fnidx(IBM_REMOVE_PE_DMA_WINDOW), + rtas_fnidx(IBM_RESET_PE_DMA_WINDOWS), + rtas_fnidx(IBM_SCAN_LOG_DUMP), + rtas_fnidx(IBM_SET_DYNAMIC_INDICATOR), + rtas_fnidx(IBM_SET_EEH_OPTION), + rtas_fnidx(IBM_SET_SLOT_RESET), + rtas_fnidx(IBM_SET_SYSTEM_PARAMETER), + rtas_fnidx(IBM_SET_XIVE), + rtas_fnidx(IBM_SLOT_ERROR_DETAIL), + rtas_fnidx(IBM_SUSPEND_ME), + rtas_fnidx(IBM_TUNE_DMA_PARMS), + rtas_fnidx(IBM_UPDATE_FLASH_64_AND_REBOOT), + rtas_fnidx(IBM_UPDATE_NODES), + rtas_fnidx(IBM_UPDATE_PROPERTIES), + rtas_fnidx(IBM_VALIDATE_FLASH_IMAGE), + rtas_fnidx(IBM_WRITE_PCI_CONFIG), + rtas_fnidx(NVRAM_FETCH), + rtas_fnidx(NVRAM_STORE), + rtas_fnidx(POWER_OFF), + rtas_fnidx(PUT_TERM_CHAR), + rtas_fnidx(QUERY_CPU_STOPPED_STATE), + rtas_fnidx(READ_PCI_CONFIG), + rtas_fnidx(RTAS_LAST_ERROR), + rtas_fnidx(SET_INDICATOR), + rtas_fnidx(SET_POWER_LEVEL), + rtas_fnidx(SET_TIME_FOR_POWER_ON), + rtas_fnidx(SET_TIME_OF_DAY), + rtas_fnidx(START_CPU), + rtas_fnidx(STOP_SELF), + rtas_fnidx(SYSTEM_REBOOT), + rtas_fnidx(THAW_TIME_BASE), + rtas_fnidx(WRITE_PCI_CONFIG), +}; +#define RTAS_UNKNOWN_SERVICE (-1)#define RTAS_INSTANTIATE_MAX (1ULL<<30)/* Don't instantiate rtas at/above this value */
arch/powerpc/kernel/rtas.c +628 -113
811 lines not on this page · raw message
Signature · 1 line
2.37.1
PATCH v2 2/4 powerpc/rtas: strengthen do_enter_rtas() type safety, drop inline
In reply to Nathan LynchMake do_enter_rtas() take a pointer to struct rtas_args and do the __pa() conversion in one place instead of leaving it to callers. This also makes it possible to introduce enter/exit tracepoints that access the rtas_args struct fields.
There's no apparent reason to force inlining of do_enter_rtas() either, and it seems to bloat the code a bit. Let the compiler decide.
--- arch/powerpc/kernel/rtas.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/kernel/rtas.c +5 -5
@@ -528,7 +528,7 @@ static const struct rtas_function *rtas_token_to_function(s32 token)/* This is here deliberately so it's only used in this file */ void enter_rtas (unsigned long ); -static inline void do_enter_rtas (unsigned long args) +static void do_enter_rtas (struct rtas_args *args) {unsigned long msr;
@@ -543,7 +543,7 @@ static inline void do_enter_rtas(unsigned long args)hard_irq_disable ();/* Ensure MSR[EE] is disabled on PPC64 */ -enter_rtas (args); +enter_rtas (__pa (args));srr_regs_clobbered ();/* rtas uses SRRs, invalidate */ }
@@ -914,7 +914,7 @@ static char *__fetch_rtas_last_error(char *altbuf) save_args = rtas.args; rtas.args = err_args; -do_enter_rtas (__pa (&rtas.args)); +do_enter_rtas (&rtas.args); err_args = rtas.args; rtas.args = save_args;
@@ -961,7 +961,7 @@ va_rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret,for (i =0 ; i < nret; ++i) args->rets[i] =0 ; -do_enter_rtas (__pa (args)); +do_enter_rtas (args); }void rtas_call_unlocked (struct rtas_args *args,int token,int nargs,int nret, ...)
@@ -1736,7 +1736,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) flags =lock_rtas (); rtas.args = args; -do_enter_rtas (__pa (&rtas.args)); +do_enter_rtas (&rtas.args); args = rtas.args;/* A -1 return code indicates that the last command couldn't
Signature · 1 line
2.37.1
PATCH v2 3/4 powerpc/tracing: tracepoints for RTAS entry and exit
In reply to Nathan LynchAdd two sets of tracepoints to be used around RTAS entry:
* rtas_input/rtas_output, which emit the function name, its inputs, the returned status, and any other outputs. These produce an API-level record of OS<->RTAS activity.
* rtas_ll_entry/rtas_ll_exit, which are lower-level and emit the entire contents of the parameter block (aka rtas_args) on entry and exit. Likely useful only for debugging.
With uses of these tracepoints in do_enter_rtas() to be added in the following patch, examples of get-time-of-day and event-scan functions as rendered by trace-cmd (with some multi-line formatting manually imposed on the rtas_ll_* entries to avoid extremely long lines in the commit message):
cat-36800 [059] 4978.518303: rtas_input: get-time-of-day arguments:
cat-36800 [059] 4978.518306: rtas_ll_entry: token=3 nargs=0 nret=8
params: [0]=0x00000000 [1]=0x00000000 [2]=0x00000000 [3]=0x00000000
[4]=0x00000000 [5]=0x00000000 [6]=0x00000000 [7]=0x00000000
[8]=0x00000000 [9]=0x00000000 [10]=0x00000000 [11]=0x00000000
[12]=0x00000000 [13]=0x00000000 [14]=0x00000000 [15]=0x00000000
cat-36800 [059] 4978.518366: rtas_ll_exit: token=3 nargs=0 nret=8
params: [0]=0x00000000 [1]=0x000007e6 [2]=0x0000000b [3]=0x00000001
[4]=0x00000000 [5]=0x0000000e [6]=0x00000008 [7]=0x2e0dac40
[8]=0x00000000 [9]=0x00000000 [10]=0x00000000 [11]=0x00000000
[12]=0x00000000 [13]=0x00000000 [14]=0x00000000 [15]=0x00000000cat-36800 [059] 4978.518366: rtas_output: get-time-of-day status: 0, other outputs: 2022 11 1 0 14 8 772648000
kworker/39:1-336 [039] 4982.731623: rtas_input: event-scan arguments: 4294967295 0 80484920 2048
kworker/39:1-336 [039] 4982.731626: rtas_ll_entry: token=6 nargs=4 nret=1
params: [0]=0xffffffff [1]=0x00000000 [2]=0x04cc1a38 [3]=0x00000800
[4]=0x00000000 [5]=0x0000000e [6]=0x00000008 [7]=0x2e0dac40
[8]=0x00000000 [9]=0x00000000 [10]=0x00000000 [11]=0x00000000
[12]=0x00000000 [13]=0x00000000 [14]=0x00000000 [15]=0x00000000
kworker/39:1-336 [039] 4982.731676: rtas_ll_exit: token=6 nargs=4 nret=1
params: [0]=0xffffffff [1]=0x00000000 [2]=0x04cc1a38 [3]=0x00000800
[4]=0x00000001 [5]=0x0000000e [6]=0x00000008 [7]=0x2e0dac40
[8]=0x00000000 [9]=0x00000000 [10]=0x00000000 [11]=0x00000000
[12]=0x00000000 [13]=0x00000000 [14]=0x00000000 [15]=0x00000000kworker/39:1-336 [039] 4982.731677: rtas_output: event-scan status: 1, other outputs:
--- arch/powerpc/include/asm/trace.h | 103 +++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+)
arch/powerpc/include/asm/trace.h +103 -0
@@ -119,6 +119,109 @@ TRACE_EVENT_FN_COND(hcall_exit, );#endif +#ifdef CONFIG_PPC_RTAS + +#include <asm/rtas-types.h> + +TRACE_EVENT (rtas_input, + + TP_PROTO(struct rtas_args *rtas_args, const char *name), + +TP_ARGS (rtas_args, name), + +TP_STRUCT__entry ( + __field(__u32, nargs) + __string(name, name) +__dynamic_array (__u32, inputs,be32_to_cpu (rtas_args->nargs)) + ), + +TP_fast_assign ( + __entry->nargs = be32_to_cpu(rtas_args->nargs); + __assign_str(name, name); + be32_to_cpu_array(__get_dynamic_array(inputs), rtas_args->args, __entry->nargs); + ), + +TP_printk ("%s arguments: %s" ,__get_str (name), +__print_array (__get_dynamic_array (inputs), __entry->nargs,4 ) + ) +); + +TRACE_EVENT (rtas_output, + + TP_PROTO(struct rtas_args *rtas_args, const char *name), + +TP_ARGS (rtas_args, name), + +TP_STRUCT__entry ( + __field(__u32, nr_other) + __field(__s32, status) + __string(name, name) +__dynamic_array (__u32, other_outputs,be32_to_cpu (rtas_args->nret) -1 ) + ), + +TP_fast_assign ( + __entry->nr_other = be32_to_cpu(rtas_args->nret) - 1; + __entry->status = be32_to_cpu(rtas_args->rets[0]); + __assign_str(name, name); +be32_to_cpu_array (__get_dynamic_array (other_outputs), + &rtas_args->rets[1], __entry->nr_other); + ), + +TP_printk ("%s status: %d, other outputs: %s" ,__get_str (name), __entry->status, +__print_array (__get_dynamic_array (other_outputs), + __entry->nr_other,4 ) + ) +); + +DECLARE_EVENT_CLASS (rtas_parameter_block, + + TP_PROTO(struct rtas_args *rtas_args), + +TP_ARGS (rtas_args), + +TP_STRUCT__entry ( + __field(u32, token) + __field(u32, nargs) + __field(u32, nret) +__array (__u32, params,16 ) + ), + +TP_fast_assign ( + __entry->token = be32_to_cpu(rtas_args->token); + __entry->nargs = be32_to_cpu(rtas_args->nargs); + __entry->nret = be32_to_cpu(rtas_args->nret); + be32_to_cpu_array(__entry->params, rtas_args->args, ARRAY_SIZE(rtas_args->args)); + ), + +TP_printk ("token=%u nargs=%u nret=%u params:" +" [0]=0x%08x [1]=0x%08x [2]=0x%08x [3]=0x%08x" +" [4]=0x%08x [5]=0x%08x [6]=0x%08x [7]=0x%08x" +" [8]=0x%08x [9]=0x%08x [10]=0x%08x [11]=0x%08x" +" [12]=0x%08x [13]=0x%08x [14]=0x%08x [15]=0x%08x" , + __entry->token, __entry->nargs, __entry->nret, + __entry->params[0 ], __entry->params[1 ], __entry->params[2 ], __entry->params[3 ], + __entry->params[4 ], __entry->params[5 ], __entry->params[6 ], __entry->params[7 ], + __entry->params[8 ], __entry->params[9 ], __entry->params[10 ], __entry->params[11 ], + __entry->params[12 ], __entry->params[13 ], __entry->params[14 ], __entry->params[15 ] + ) +); + +DEFINE_EVENT (rtas_parameter_block, rtas_ll_entry, + + TP_PROTO(struct rtas_args *rtas_args), + +TP_ARGS (rtas_args) +); + +DEFINE_EVENT (rtas_parameter_block, rtas_ll_exit, + + TP_PROTO(struct rtas_args *rtas_args), + +TP_ARGS (rtas_args) +); + +#endif /* CONFIG_PPC_RTAS */ +#ifdef CONFIG_PPC_POWERNV extern int opal_tracepoint_regfunc (void );extern void opal_tracepoint_unregfunc (void );
Signature · 1 line
2.37.1
PATCH v2 4/4 powerpc/rtas: add tracepoints around RTAS entry
In reply to Nathan LynchDecompose the RTAS entry C code into tracing and non-tracing variants, calling the just-added tracepoints in the tracing-enabled path. Skip tracing in contexts known to be unsafe (real mode, CPU offline).
--- arch/powerpc/kernel/rtas.c | 59 ++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 6 deletions(-)
arch/powerpc/kernel/rtas.c +53 -6
@@ -38,6 +38,7 @@#include <asm/page.h> #include <asm/rtas.h> #include <asm/time.h> +#include <asm/trace.h> #include <asm/udbg.h> /**
@@ -528,24 +529,70 @@ static const struct rtas_function *rtas_token_to_function(s32 token)/* This is here deliberately so it's only used in this file */ void enter_rtas (unsigned long ); +static void __do_enter_rtas (struct rtas_args *args) +{ +enter_rtas (__pa (args)); +srr_regs_clobbered ();/* rtas uses SRRs, invalidate */ +} + +static void __do_enter_rtas_trace (struct rtas_args *args) +{ +const char *name =NULL ; +/* +* If the tracepoints that consume the function name aren't +* active, avoid the lookup. +*/ +if ((trace_rtas_input_enabled () ||trace_rtas_output_enabled ())) { +const s32 token =be32_to_cpu (args->token); +const struct rtas_function *func =rtas_token_to_function (token); + + name = func->name; + } + +trace_rtas_input (args, name); +trace_rtas_ll_entry (args); + +__do_enter_rtas (args); + +trace_rtas_ll_exit (args); +trace_rtas_output (args, name); +} +static void do_enter_rtas (struct rtas_args *args) { -unsigned long msr; - +const unsigned long msr =mfmsr (); +/* +* Situations where we want to skip any active tracepoints for +* safety reasons: +* +* 1. The last code executed on an offline CPU as it stops, +* i.e. we're about to call stop-self. The tracepoints' +* function name lookup uses xarray, which uses RCU, which +* isn't valid to call on an offline CPU. Any events +* emitted on an offline CPU will be discarded anyway. +* +* 2. In real mode, as when invoking ibm,nmi-interlock from +* the pseries MCE handler. We cannot count on trace +* buffers or the entries in rtas_token_to_function_xarray +* to be contained in the RMO. +*/ +const unsigned long mask =MSR_IR |MSR_DR ; +const bool can_trace =likely (cpu_online (raw_smp_processor_id ()) && + (msr & mask) == mask);/* * Make sure MSR[RI] is currently enabled as it will be forced later * in enter_rtas. */ - msr =mfmsr ();BUG_ON (!(msr &MSR_RI ));BUG_ON (!irqs_disabled ());hard_irq_disable ();/* Ensure MSR[EE] is disabled on PPC64 */ -enter_rtas (__pa (args)); - -srr_regs_clobbered ();/* rtas uses SRRs, invalidate */ +if (can_trace) +__do_enter_rtas_trace (args); +else +__do_enter_rtas (args); }struct rtas_t rtas = {
Signature · 1 line
2.37.1