Commit af8bc682 authored by Nathan Lynch's avatar Nathan Lynch Committed by Michael Ellerman

powerpc/rtas: lockdep annotations

Add lockdep annotations for the following properties that must hold:

* Any error log retrieval must be atomically coupled with the prior
  RTAS call, without a window for another RTAS call to occur before the
  error log can be retrieved.

* All users of the core rtas_args parameter block must hold rtas_lock.

Move the definitions of rtas_lock and rtas_args up in the file so that
__do_enter_rtas_trace() can refer to them.
Signed-off-by: default avatarNathan Lynch <nathanl@linux.ibm.com>
Reviewed-by: default avatarAndrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230220-rtas-queue-for-6-4-v1-6-010e4416f13f@linux.ibm.com
parent 32740fce
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/kconfig.h> #include <linux/kconfig.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/lockdep.h>
#include <linux/memblock.h> #include <linux/memblock.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_fdt.h> #include <linux/of_fdt.h>
...@@ -453,6 +454,16 @@ static struct rtas_function rtas_function_table[] __ro_after_init = { ...@@ -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. * rtas_function_token() - RTAS function token lookup.
* @handle: Function handle, e.g. RTAS_FN_EVENT_SCAN. * @handle: Function handle, e.g. RTAS_FN_EVENT_SCAN.
...@@ -560,6 +571,9 @@ static void __do_enter_rtas(struct rtas_args *args) ...@@ -560,6 +571,9 @@ static void __do_enter_rtas(struct rtas_args *args)
static void __do_enter_rtas_trace(struct rtas_args *args) static void __do_enter_rtas_trace(struct rtas_args *args)
{ {
const char *name = NULL; const char *name = NULL;
if (args == &rtas_args)
lockdep_assert_held(&rtas_lock);
/* /*
* If the tracepoints that consume the function name aren't * If the tracepoints that consume the function name aren't
* active, avoid the lookup. * active, avoid the lookup.
...@@ -619,16 +633,6 @@ static void do_enter_rtas(struct rtas_args *args) ...@@ -619,16 +633,6 @@ static void do_enter_rtas(struct rtas_args *args)
struct rtas_t rtas; 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); DEFINE_SPINLOCK(rtas_data_buf_lock);
EXPORT_SYMBOL_GPL(rtas_data_buf_lock); EXPORT_SYMBOL_GPL(rtas_data_buf_lock);
...@@ -951,6 +955,8 @@ static char *__fetch_rtas_last_error(char *altbuf) ...@@ -951,6 +955,8 @@ static char *__fetch_rtas_last_error(char *altbuf)
u32 bufsz; u32 bufsz;
char *buf = NULL; char *buf = NULL;
lockdep_assert_held(&rtas_lock);
if (token == -1) if (token == -1)
return NULL; return NULL;
...@@ -1108,6 +1114,7 @@ static bool token_is_restricted_errinjct(s32 token) ...@@ -1108,6 +1114,7 @@ static bool token_is_restricted_errinjct(s32 token)
*/ */
int rtas_call(int token, int nargs, int nret, int *outputs, ...) int rtas_call(int token, int nargs, int nret, int *outputs, ...)
{ {
struct pin_cookie cookie;
va_list list; va_list list;
int i; int i;
unsigned long flags; unsigned long flags;
...@@ -1134,6 +1141,8 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) ...@@ -1134,6 +1141,8 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
} }
raw_spin_lock_irqsave(&rtas_lock, flags); raw_spin_lock_irqsave(&rtas_lock, flags);
cookie = lockdep_pin_lock(&rtas_lock);
/* We use the global rtas args buffer */ /* We use the global rtas args buffer */
args = &rtas_args; args = &rtas_args;
...@@ -1151,6 +1160,7 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) ...@@ -1151,6 +1160,7 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
outputs[i] = be32_to_cpu(args->rets[i + 1]); outputs[i] = be32_to_cpu(args->rets[i + 1]);
ret = (nret > 0) ? be32_to_cpu(args->rets[0]) : 0; ret = (nret > 0) ? be32_to_cpu(args->rets[0]) : 0;
lockdep_unpin_lock(&rtas_lock, cookie);
raw_spin_unlock_irqrestore(&rtas_lock, flags); raw_spin_unlock_irqrestore(&rtas_lock, flags);
if (buff_copy) { if (buff_copy) {
...@@ -1782,6 +1792,7 @@ static bool block_rtas_call(int token, int nargs, ...@@ -1782,6 +1792,7 @@ static bool block_rtas_call(int token, int nargs,
/* We assume to be passed big endian arguments */ /* We assume to be passed big endian arguments */
SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
{ {
struct pin_cookie cookie;
struct rtas_args args; struct rtas_args args;
unsigned long flags; unsigned long flags;
char *buff_copy, *errbuf = NULL; char *buff_copy, *errbuf = NULL;
...@@ -1850,6 +1861,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) ...@@ -1850,6 +1861,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
buff_copy = get_errorlog_buffer(); buff_copy = get_errorlog_buffer();
raw_spin_lock_irqsave(&rtas_lock, flags); raw_spin_lock_irqsave(&rtas_lock, flags);
cookie = lockdep_pin_lock(&rtas_lock);
rtas_args = args; rtas_args = args;
do_enter_rtas(&rtas_args); do_enter_rtas(&rtas_args);
...@@ -1860,6 +1872,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) ...@@ -1860,6 +1872,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
if (be32_to_cpu(args.rets[0]) == -1) if (be32_to_cpu(args.rets[0]) == -1)
errbuf = __fetch_rtas_last_error(buff_copy); errbuf = __fetch_rtas_last_error(buff_copy);
lockdep_unpin_lock(&rtas_lock, cookie);
raw_spin_unlock_irqrestore(&rtas_lock, flags); raw_spin_unlock_irqrestore(&rtas_lock, flags);
if (buff_copy) { if (buff_copy) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment