diff options
Diffstat (limited to 'arch/powerpc/kernel/rtas.c')
| -rw-r--r-- | arch/powerpc/kernel/rtas.c | 54 | 
1 files changed, 42 insertions, 12 deletions
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c index 31175b34856a..c087eeee320f 100644 --- a/arch/powerpc/kernel/rtas.c +++ b/arch/powerpc/kernel/rtas.c @@ -16,6 +16,7 @@  #include <linux/init.h>  #include <linux/kconfig.h>  #include <linux/kernel.h> +#include <linux/lockdep.h>  #include <linux/memblock.h>  #include <linux/of.h>  #include <linux/of_fdt.h> @@ -68,7 +69,7 @@ struct rtas_filter {   *                            functions are believed to have no users on   *                            ppc64le, and we want to keep it that way. It does   *                            not make sense for this to be set when @filter - *                            is false. + *                            is NULL.   */  struct rtas_function {  	s32 token; @@ -453,6 +454,16 @@ static struct rtas_function rtas_function_table[] __ro_after_init = {  	},  }; +/* + * Nearly all RTAS calls need to be serialized. All uses of the + * default rtas_args block must hold rtas_lock. + * + * Exceptions to the RTAS serialization requirement (e.g. stop-self) + * must use a separate rtas_args structure. + */ +static DEFINE_RAW_SPINLOCK(rtas_lock); +static struct rtas_args rtas_args; +  /**   * rtas_function_token() - RTAS function token lookup.   * @handle: Function handle, e.g. RTAS_FN_EVENT_SCAN. @@ -560,6 +571,9 @@ static void __do_enter_rtas(struct rtas_args *args)  static void __do_enter_rtas_trace(struct rtas_args *args)  {  	const char *name = NULL; + +	if (args == &rtas_args) +		lockdep_assert_held(&rtas_lock);  	/*  	 * If the tracepoints that consume the function name aren't  	 * active, avoid the lookup. @@ -619,16 +633,6 @@ static void do_enter_rtas(struct rtas_args *args)  struct rtas_t rtas; -/* - * Nearly all RTAS calls need to be serialized. All uses of the - * default rtas_args block must hold rtas_lock. - * - * Exceptions to the RTAS serialization requirement (e.g. stop-self) - * must use a separate rtas_args structure. - */ -static DEFINE_RAW_SPINLOCK(rtas_lock); -static struct rtas_args rtas_args; -  DEFINE_SPINLOCK(rtas_data_buf_lock);  EXPORT_SYMBOL_GPL(rtas_data_buf_lock); @@ -951,6 +955,8 @@ static char *__fetch_rtas_last_error(char *altbuf)  	u32 bufsz;  	char *buf = NULL; +	lockdep_assert_held(&rtas_lock); +  	if (token == -1)  		return NULL; @@ -981,7 +987,7 @@ static char *__fetch_rtas_last_error(char *altbuf)  				buf = kmalloc(RTAS_ERROR_LOG_MAX, GFP_ATOMIC);  		}  		if (buf) -			memcpy(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX); +			memmove(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX);  	}  	return buf; @@ -1016,6 +1022,23 @@ va_rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret,  	do_enter_rtas(args);  } +/** + * rtas_call_unlocked() - Invoke an RTAS firmware function without synchronization. + * @args: RTAS parameter block to be used for the call, must obey RTAS addressing + *        constraints. + * @token: Identifies the function being invoked. + * @nargs: Number of input parameters. Does not include token. + * @nret: Number of output parameters, including the call status. + * @....: List of @nargs input parameters. + * + * Invokes the RTAS function indicated by @token, which the caller + * should obtain via rtas_function_token(). + * + * This function is similar to rtas_call(), but must be used with a + * limited set of RTAS calls specifically exempted from the general + * requirement that only one RTAS call may be in progress at any + * time. Examples include stop-self and ibm,nmi-interlock. + */  void rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, ...)  {  	va_list list; @@ -1091,6 +1114,7 @@ static bool token_is_restricted_errinjct(s32 token)   */  int rtas_call(int token, int nargs, int nret, int *outputs, ...)  { +	struct pin_cookie cookie;  	va_list list;  	int i;  	unsigned long flags; @@ -1117,6 +1141,8 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)  	}  	raw_spin_lock_irqsave(&rtas_lock, flags); +	cookie = lockdep_pin_lock(&rtas_lock); +  	/* We use the global rtas args buffer */  	args = &rtas_args; @@ -1134,6 +1160,7 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)  			outputs[i] = be32_to_cpu(args->rets[i + 1]);  	ret = (nret > 0) ? be32_to_cpu(args->rets[0]) : 0; +	lockdep_unpin_lock(&rtas_lock, cookie);  	raw_spin_unlock_irqrestore(&rtas_lock, flags);  	if (buff_copy) { @@ -1765,6 +1792,7 @@ err:  /* We assume to be passed big endian arguments */  SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)  { +	struct pin_cookie cookie;  	struct rtas_args args;  	unsigned long flags;  	char *buff_copy, *errbuf = NULL; @@ -1833,6 +1861,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)  	buff_copy = get_errorlog_buffer();  	raw_spin_lock_irqsave(&rtas_lock, flags); +	cookie = lockdep_pin_lock(&rtas_lock);  	rtas_args = args;  	do_enter_rtas(&rtas_args); @@ -1843,6 +1872,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)  	if (be32_to_cpu(args.rets[0]) == -1)  		errbuf = __fetch_rtas_last_error(buff_copy); +	lockdep_unpin_lock(&rtas_lock, cookie);  	raw_spin_unlock_irqrestore(&rtas_lock, flags);  	if (buff_copy) {  |