Message ID | 90868f1dd49680ec63c961ec8c72ceb64f1af091.1741708239.git.namcao@linutronix.de (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | RV: Linear temporal logic monitors for RT application | expand |
On Tue, 2025-03-11 at 18:05 +0100, Nam Cao wrote: > Each RV monitor has one static buffer to send to the reactors. If > multiple > errors are detected at the same time, the one buffer could be > overwritten. > > Instead, leave it to the reactors to handle buffering. > > Signed-off-by: Nam Cao <namcao@linutronix.de> > --- > Cc: Petr Mladek <pmladek@suse.com> > Cc: John Ogness <john.ogness@linutronix.de> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > --- > include/linux/printk.h | 1 + > include/linux/rv.h | 11 +++--- > include/rv/da_monitor.h | 61 ++++++------------------------ > -- > kernel/printk/internal.h | 1 - > kernel/trace/rv/reactor_panic.c | 7 +--- > kernel/trace/rv/reactor_printk.c | 8 +++-- > kernel/trace/rv/rv_reactors.c | 2 +- > 7 files changed, 26 insertions(+), 65 deletions(-) > > diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h > index 510c88bfabd4..c55d45544a16 100644 > --- a/include/rv/da_monitor.h > +++ b/include/rv/da_monitor.h > @@ -16,58 +16,11 @@ > #include <linux/bug.h> > #include <linux/sched.h> > > -#ifdef CONFIG_RV_REACTORS > - > -#define DECLARE_RV_REACTING_HELPERS(name, > type) \ > -static char > REACT_MSG_##name[1024]; \ > - > \ > -static inline char *format_react_msg_##name(type curr_state, type > event) \ > - > { \ > - snprintf(REACT_MSG_##name, > 1024, \ > - "rv: monitor %s does not allow event %s on state > %s\n", \ > - > #name, \ > - > model_get_event_name_##name(event), \ > - > model_get_state_name_##name(curr_state)); \ > - return > REACT_MSG_##name; \ > - > } \ > - > \ > -static void cond_react_##name(char > *msg) \ > - > { \ > - if > (rv_##name.react) \ > - > rv_##name.react(msg); \ > - > } \ > - > \ > -static bool > rv_reacting_on_##name(void) \ > - > { \ > - return > rv_reacting_on(); \ > -} > - > -#else /* CONFIG_RV_REACTOR */ > - > -#define DECLARE_RV_REACTING_HELPERS(name, > type) \ > -static inline char *format_react_msg_##name(type curr_state, type > event) \ > - > { \ > - return > NULL; \ > - > } \ > - > \ > -static void cond_react_##name(char > *msg) \ > - > { \ > - > return; \ > - > } \ > - > \ > -static bool > rv_reacting_on_##name(void) \ > - > { \ > - return > 0; \ > -} > -#endif > - I don't think you need to remove those helper functions, why not just having format_react_msg_ prepare the arguments for react? cond_react might be mildly useful also for ltl, we may think about putting it somewhere else and/or refactoring it a bit to include reacting_on (which is indeed global and doesn't require a per-monitor wrapper). > /* > * Generic helpers for all types of deterministic automata monitors. > */ > #define DECLARE_DA_MON_GENERIC_HELPERS(name, > type) \ > > \ > -DECLARE_RV_REACTING_HELPERS(name, > type) \ > - > \ > /* > \ > * da_monitor_reset_##name - reset a monitor and setting it to init > state \ > > */ \ > @@ -170,8 +123,11 @@ da_event_##name(struct da_monitor *da_mon, enum > events_##name event) \ > return > true; \ > } > \ > > \ > - if > (rv_reacting_on_##name()) \ > - > cond_react_##name(format_react_msg_##name(curr_state, event)); \ > + if (rv_reacting_on() && > rv_##name.react) \ > + rv_##name.react("rv: monitor %s does not allow event > %s on state %s\n", \ > + #name, > \ > + model_get_event_name_##name(event), > \ > + model_get_state_name_##name(curr_sta > te)); \ > > \ > trace_error_##name(model_get_state_name_##name(curr_state), > \ > > model_get_event_name_##name(event)); \ > @@ -202,8 +158,11 @@ static inline bool da_event_##name(struct > da_monitor *da_mon, struct task_struct > return > true; \ > } > \ > > \ > - if > (rv_reacting_on_##name()) \ > - > cond_react_##name(format_react_msg_##name(curr_state, event)); \ > + if (rv_reacting_on() && > rv_##name.react) \ > + rv_##name.react("rv: monitor %s does not allow event > %s on state %s\n", \ > + #name, > \ > + model_get_event_name_##name(event), > \ > + model_get_state_name_##name(curr_sta > te)); \ > > \ > trace_error_##name(tsk- > >pid, \ > > model_get_state_name_##name(curr_state), \ > diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h > index a91bdf802967..28afdeb58412 100644 > --- a/kernel/printk/internal.h > +++ b/kernel/printk/internal.h > @@ -71,7 +71,6 @@ int vprintk_store(int facility, int level, > const char *fmt, va_list args); > > __printf(1, 0) int vprintk_default(const char *fmt, va_list args); > -__printf(1, 0) int vprintk_deferred(const char *fmt, va_list args); > > void __printk_safe_enter(void); > void __printk_safe_exit(void); > diff --git a/kernel/trace/rv/reactor_panic.c > b/kernel/trace/rv/reactor_panic.c > index 0186ff4cbd0b..4addabc9bcf1 100644 > --- a/kernel/trace/rv/reactor_panic.c > +++ b/kernel/trace/rv/reactor_panic.c > @@ -13,15 +13,10 @@ > #include <linux/init.h> > #include <linux/rv.h> > > -static void rv_panic_reaction(char *msg) > -{ > - panic(msg); > -} > - > static struct rv_reactor rv_panic = { > .name = "panic", > .description = "panic the system if an exception is found.", > - .react = rv_panic_reaction > + .react = panic > }; For the sake of verbosity, I would still keep a wrapper function around panic, just to show directly from this file how should a react() function look like, as well as allowing future modifications, if needed. Not that the additional function call would be much of a problem during panic, I believe. Good improvement overall, thanks. Gabriele > > static int __init register_react_panic(void) > diff --git a/kernel/trace/rv/reactor_printk.c > b/kernel/trace/rv/reactor_printk.c > index 178759dbf89f..a15db3fc8b82 100644 > --- a/kernel/trace/rv/reactor_printk.c > +++ b/kernel/trace/rv/reactor_printk.c > @@ -12,9 +12,13 @@ > #include <linux/init.h> > #include <linux/rv.h> > > -static void rv_printk_reaction(char *msg) > +static void rv_printk_reaction(const char *msg, ...) > { > - printk_deferred(msg); > + va_list args; > + > + va_start(args, msg); > + vprintk_deferred(msg, args); > + va_end(args); > } > > static struct rv_reactor rv_printk = { > diff --git a/kernel/trace/rv/rv_reactors.c > b/kernel/trace/rv/rv_reactors.c > index 7b49cbe388d4..885661fe2b6e 100644 > --- a/kernel/trace/rv/rv_reactors.c > +++ b/kernel/trace/rv/rv_reactors.c > @@ -468,7 +468,7 @@ void reactor_cleanup_monitor(struct > rv_monitor_def *mdef) > /* > * Nop reactor register > */ > -static void rv_nop_reaction(char *msg) > +static void rv_nop_reaction(const char *msg, ...) > { > } >
Hi Gabriele, On Wed, Mar 12, 2025 at 08:58:56AM +0100, Gabriele Monaco wrote: > On Tue, 2025-03-11 at 18:05 +0100, Nam Cao wrote: > > diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h > > index 510c88bfabd4..c55d45544a16 100644 > > --- a/include/rv/da_monitor.h > > +++ b/include/rv/da_monitor.h > > @@ -16,58 +16,11 @@ > > #include <linux/bug.h> > > #include <linux/sched.h> > > > > -#ifdef CONFIG_RV_REACTORS > > - > > -#define DECLARE_RV_REACTING_HELPERS(name, > > type) \ > > -static char > > REACT_MSG_##name[1024]; \ > > - > > \ > > -static inline char *format_react_msg_##name(type curr_state, type > > event) \ > > - > > { \ > > - snprintf(REACT_MSG_##name, > > 1024, \ > > - "rv: monitor %s does not allow event %s on state > > %s\n", \ > > - > > #name, \ > > - > > model_get_event_name_##name(event), \ > > - > > model_get_state_name_##name(curr_state)); \ > > - return > > REACT_MSG_##name; \ > > - > > } \ > > - > > \ > > -static void cond_react_##name(char > > *msg) \ > > - > > { \ > > - if > > (rv_##name.react) \ > > - > > rv_##name.react(msg); \ > > - > > } \ > > - > > \ > > -static bool > > rv_reacting_on_##name(void) \ > > - > > { \ > > - return > > rv_reacting_on(); \ > > -} > > - > > -#else /* CONFIG_RV_REACTOR */ > > - > > -#define DECLARE_RV_REACTING_HELPERS(name, > > type) \ > > -static inline char *format_react_msg_##name(type curr_state, type > > event) \ > > - > > { \ > > - return > > NULL; \ > > - > > } \ > > - > > \ > > -static void cond_react_##name(char > > *msg) \ > > - > > { \ > > - > > return; \ > > - > > } \ > > - > > \ > > -static bool > > rv_reacting_on_##name(void) \ > > - > > { \ > > - return > > 0; \ > > -} > > -#endif > > - > > I don't think you need to remove those helper functions, why not just > having format_react_msg_ prepare the arguments for react? I'm not sure what you mean. Making format_react_msg_* a macro that is preprocessed into arguments? Then make cond_react_*() a variadic function, so that we can "pass" format_react_msg_* to it? Going that way would also need a vreact() variant, as cond_react_*() cannot pass on the variadic arguments to react(). Instead, is it cleaner to do the below? diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 510c88bfabd4..e185ebf894a4 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -19,22 +19,14 @@ #ifdef CONFIG_RV_REACTORS #define DECLARE_RV_REACTING_HELPERS(name, type) \ -static char REACT_MSG_##name[1024]; \ - \ -static inline char *format_react_msg_##name(type curr_state, type event) \ -{ \ - snprintf(REACT_MSG_##name, 1024, \ - "rv: monitor %s does not allow event %s on state %s\n", \ - #name, \ - model_get_event_name_##name(event), \ - model_get_state_name_##name(curr_state)); \ - return REACT_MSG_##name; \ -} \ - \ -static void cond_react_##name(char *msg) \ +static void cond_react_##name(type curr_state, type event) \ { \ - if (rv_##name.react) \ - rv_##name.react(msg); \ + if (!rv_##name.react) \ + return; \ + rv_##name.react("rv: monitor %s does not allow event %s on state %s\n", \ + #name, \ + model_get_event_name_##name(event), \ + model_get_state_name_##name(curr_state)); \ } \ \ static bool rv_reacting_on_##name(void) \ @@ -45,12 +37,7 @@ static bool rv_reacting_on_##name(void) \ #else /* CONFIG_RV_REACTOR */ #define DECLARE_RV_REACTING_HELPERS(name, type) \ -static inline char *format_react_msg_##name(type curr_state, type event) \ -{ \ - return NULL; \ -} \ - \ -static void cond_react_##name(char *msg) \ +static void cond_react_##name(type curr_state, type event) \ { \ return; \ } \ @@ -171,7 +158,7 @@ da_event_##name(struct da_monitor *da_mon, enum events_##name event) \ } \ \ if (rv_reacting_on_##name()) \ - cond_react_##name(format_react_msg_##name(curr_state, event)); \ + cond_react_##name(curr_state, event); \ \ trace_error_##name(model_get_state_name_##name(curr_state), \ model_get_event_name_##name(event)); \ @@ -203,7 +190,7 @@ static inline bool da_event_##name(struct da_monitor *da_mon, struct task_struct } \ \ if (rv_reacting_on_##name()) \ - cond_react_##name(format_react_msg_##name(curr_state, event)); \ + cond_react_##name(curr_state, event); \ \ trace_error_##name(tsk->pid, \ model_get_state_name_##name(curr_state), \ Best regards, Nam
On Thu, 2025-03-13 at 09:16 +0100, Nam Cao wrote: > Hi Gabriele, > > On Wed, Mar 12, 2025 at 08:58:56AM +0100, Gabriele Monaco wrote: > > On Tue, 2025-03-11 at 18:05 +0100, Nam Cao wrote: > > > diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h > > > index 510c88bfabd4..c55d45544a16 100644 > > > --- a/include/rv/da_monitor.h > > > +++ b/include/rv/da_monitor.h > > > @@ -16,58 +16,11 @@ > > > #include <linux/bug.h> > > > #include <linux/sched.h> > > > > > > -#ifdef CONFIG_RV_REACTORS > > > - > > > -#define DECLARE_RV_REACTING_HELPERS(name, > > > type) \ > > > -static char > > > REACT_MSG_##name[1024]; > > > \ > > > - > > > > > > \ > > > -static inline char *format_react_msg_##name(type curr_state, > > > type > > > event) \ > > > - > > > { > > > \ > > > - snprintf(REACT_MSG_##name, > > > 1024, \ > > > - "rv: monitor %s does not allow event %s on > > > state > > > %s\n", \ > > > - > > > #name, > > > \ > > > - > > > model_get_event_name_##name(event), > > > \ > > > - > > > model_get_state_name_##name(curr_state)); > > > \ > > > - return > > > REACT_MSG_##name; > > > \ > > > - > > > } > > > \ > > > - > > > > > > \ > > > -static void cond_react_##name(char > > > *msg) \ > > > - > > > { > > > \ > > > - if > > > (rv_##name.react) > > > \ > > > - > > > rv_##name.react(msg); > > > \ > > > - > > > } > > > \ > > > - > > > > > > \ > > > -static bool > > > rv_reacting_on_##name(void) > > > \ > > > - > > > { > > > \ > > > - return > > > rv_reacting_on(); > > > \ > > > -} > > > - > > > -#else /* CONFIG_RV_REACTOR */ > > > - > > > -#define DECLARE_RV_REACTING_HELPERS(name, > > > type) \ > > > -static inline char *format_react_msg_##name(type curr_state, > > > type > > > event) \ > > > - > > > { > > > \ > > > - return > > > NULL; > > > \ > > > - > > > } > > > \ > > > - > > > > > > \ > > > -static void cond_react_##name(char > > > *msg) \ > > > - > > > { > > > \ > > > - > > > return; > > > \ > > > - > > > } > > > \ > > > - > > > > > > \ > > > -static bool > > > rv_reacting_on_##name(void) > > > \ > > > - > > > { > > > \ > > > - return > > > 0; > > > \ > > > -} > > > -#endif > > > - > > > > I don't think you need to remove those helper functions, why not > > just > > having format_react_msg_ prepare the arguments for react? > > I'm not sure what you mean. Making format_react_msg_* a macro that is > preprocessed into arguments? Then make cond_react_*() a variadic > function, > so that we can "pass" format_react_msg_* to it? > > Going that way would also need a vreact() variant, as cond_react_*() > cannot > pass on the variadic arguments to react(). > > Instead, is it cleaner to do the below? Hi Nam, you're right, I got a bit confused, all I meant was to find a way not to repeat the arguments for implicit and per-task monitors. What you propose seems perfect to me. Also for the sake of simplifying things, a bit like you started, we could have the reacting_on() check inside cond_react and drop the per- monitor function. I believe the initial idea was to have a reacting_on toggle for each monitor but since it isn't the case, we don't really need it. Thanks, Gabriele > > diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h > index 510c88bfabd4..e185ebf894a4 100644 > --- a/include/rv/da_monitor.h > +++ b/include/rv/da_monitor.h > @@ -19,22 +19,14 @@ > #ifdef CONFIG_RV_REACTORS > > #define DECLARE_RV_REACTING_HELPERS(name, > type) \ > -static char > REACT_MSG_##name[1024]; \ > - > \ > -static inline char *format_react_msg_##name(type curr_state, type > event) \ > - > { \ > - snprintf(REACT_MSG_##name, > 1024, \ > - "rv: monitor %s does not allow event %s on state > %s\n", \ > - > #name, \ > - > model_get_event_name_##name(event), \ > - > model_get_state_name_##name(curr_state)); \ > - return > REACT_MSG_##name; \ > - > } \ > - > \ > -static void cond_react_##name(char > *msg) \ > +static void cond_react_##name(type curr_state, type > event) \ > { > \ > - if > (rv_##name.react) \ > - > rv_##name.react(msg); \ > + if > (!rv_##name.react) \ > + return; > \ > + rv_##name.react("rv: monitor %s does not allow event %s on > state %s\n", \ > + #name, > \ > + model_get_event_name_##name(event), > \ > + model_get_state_name_##name(curr_state)); > \ > } > \ > > \ > static bool > rv_reacting_on_##name(void) \ > @@ -45,12 +37,7 @@ static bool > rv_reacting_on_##name(void) \ > #else /* CONFIG_RV_REACTOR */ > > #define DECLARE_RV_REACTING_HELPERS(name, > type) \ > -static inline char *format_react_msg_##name(type curr_state, type > event) \ > - > { \ > - return > NULL; \ > - > } \ > - > \ > -static void cond_react_##name(char > *msg) \ > +static void cond_react_##name(type curr_state, type > event) \ > { > \ > return; > \ > } > \ > @@ -171,7 +158,7 @@ da_event_##name(struct da_monitor *da_mon, enum > events_##name event) \ > } > \ > > \ > if > (rv_reacting_on_##name()) \ > - > cond_react_##name(format_react_msg_##name(curr_state, event)); \ > + cond_react_##name(curr_state, > event); \ > > \ > trace_error_##name(model_get_state_name_##name(curr_state), > \ > > model_get_event_name_##name(event)); \ > @@ -203,7 +190,7 @@ static inline bool da_event_##name(struct > da_monitor *da_mon, struct task_struct > } > \ > > \ > if > (rv_reacting_on_##name()) \ > - > cond_react_##name(format_react_msg_##name(curr_state, event)); \ > + cond_react_##name(curr_state, > event); \ > > \ > trace_error_##name(tsk- > >pid, \ > > model_get_state_name_##name(curr_state), \ > > Best regards, > Nam >
Hi Nam, kernel test robot noticed the following build warnings: [auto build test WARNING on trace/for-next] [also build test WARNING on tip/x86/core tip/x86/mm linus/master v6.14-rc6 next-20250313] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Nam-Cao/rv-Add-undef-TRACE_INCLUDE_FILE/20250312-011043 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/90868f1dd49680ec63c961ec8c72ceb64f1af091.1741708239.git.namcao%40linutronix.de patch subject: [PATCH 02/10] rv: Let the reactors take care of buffers config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20250313/202503132340.zzBclxPj-lkp@intel.com/config) compiler: sh4-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/202503132340.zzBclxPj-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202503132340.zzBclxPj-lkp@intel.com/ All warnings (new ones prefixed by >>): >> kernel/trace/rv/reactor_panic.c:19:18: warning: initialization left-hand side might be a candidate for a format attribute [-Wsuggest-attribute=format] 19 | .react = panic | ^~~~~ vim +19 kernel/trace/rv/reactor_panic.c 15 16 static struct rv_reactor rv_panic = { 17 .name = "panic", 18 .description = "panic the system if an exception is found.", > 19 .react = panic 20 }; 21
Hi Nam, kernel test robot noticed the following build errors: [auto build test ERROR on trace/for-next] [also build test ERROR on tip/x86/core tip/x86/mm linus/master v6.14-rc6 next-20250313] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Nam-Cao/rv-Add-undef-TRACE_INCLUDE_FILE/20250312-011043 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/90868f1dd49680ec63c961ec8c72ceb64f1af091.1741708239.git.namcao%40linutronix.de patch subject: [PATCH 02/10] rv: Let the reactors take care of buffers config: parisc-randconfig-002-20250313 (https://download.01.org/0day-ci/archive/20250313/202503132350.aM5NZ6Vh-lkp@intel.com/config) compiler: hppa-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/202503132350.aM5NZ6Vh-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202503132350.aM5NZ6Vh-lkp@intel.com/ All errors (new ones prefixed by >>): kernel/trace/rv/reactor_printk.c: In function 'rv_printk_reaction': >> kernel/trace/rv/reactor_printk.c:20:9: error: implicit declaration of function 'vprintk_deferred'; did you mean '_printk_deferred'? [-Wimplicit-function-declaration] 20 | vprintk_deferred(msg, args); | ^~~~~~~~~~~~~~~~ | _printk_deferred vim +20 kernel/trace/rv/reactor_printk.c 14 15 static void rv_printk_reaction(const char *msg, ...) 16 { 17 va_list args; 18 19 va_start(args, msg); > 20 vprintk_deferred(msg, args); 21 va_end(args); 22 } 23
diff --git a/include/linux/printk.h b/include/linux/printk.h index 4217a9f412b2..11e49b299312 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -154,6 +154,7 @@ int vprintk_emit(int facility, int level, asmlinkage __printf(1, 0) int vprintk(const char *fmt, va_list args); +__printf(1, 0) int vprintk_deferred(const char *fmt, va_list args); asmlinkage __printf(1, 2) __cold int _printk(const char *fmt, ...); diff --git a/include/linux/rv.h b/include/linux/rv.h index 8883b41d88ec..5482651ed020 100644 --- a/include/linux/rv.h +++ b/include/linux/rv.h @@ -38,7 +38,7 @@ union rv_task_monitor { struct rv_reactor { const char *name; const char *description; - void (*react)(char *msg); + void (*react)(const char *msg, ...); }; #endif @@ -49,9 +49,7 @@ struct rv_monitor { int (*enable)(void); void (*disable)(void); void (*reset)(void); -#ifdef CONFIG_RV_REACTORS - void (*react)(char *msg); -#endif + void (*react)(const char *msg, ...); }; bool rv_monitoring_on(void); @@ -64,6 +62,11 @@ void rv_put_task_monitor_slot(int slot); bool rv_reacting_on(void); int rv_unregister_reactor(struct rv_reactor *reactor); int rv_register_reactor(struct rv_reactor *reactor); +#else +static inline bool rv_reacting_on(void) +{ + return false; +} #endif /* CONFIG_RV_REACTORS */ #endif /* CONFIG_RV */ diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 510c88bfabd4..c55d45544a16 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -16,58 +16,11 @@ #include <linux/bug.h> #include <linux/sched.h> -#ifdef CONFIG_RV_REACTORS - -#define DECLARE_RV_REACTING_HELPERS(name, type) \ -static char REACT_MSG_##name[1024]; \ - \ -static inline char *format_react_msg_##name(type curr_state, type event) \ -{ \ - snprintf(REACT_MSG_##name, 1024, \ - "rv: monitor %s does not allow event %s on state %s\n", \ - #name, \ - model_get_event_name_##name(event), \ - model_get_state_name_##name(curr_state)); \ - return REACT_MSG_##name; \ -} \ - \ -static void cond_react_##name(char *msg) \ -{ \ - if (rv_##name.react) \ - rv_##name.react(msg); \ -} \ - \ -static bool rv_reacting_on_##name(void) \ -{ \ - return rv_reacting_on(); \ -} - -#else /* CONFIG_RV_REACTOR */ - -#define DECLARE_RV_REACTING_HELPERS(name, type) \ -static inline char *format_react_msg_##name(type curr_state, type event) \ -{ \ - return NULL; \ -} \ - \ -static void cond_react_##name(char *msg) \ -{ \ - return; \ -} \ - \ -static bool rv_reacting_on_##name(void) \ -{ \ - return 0; \ -} -#endif - /* * Generic helpers for all types of deterministic automata monitors. */ #define DECLARE_DA_MON_GENERIC_HELPERS(name, type) \ \ -DECLARE_RV_REACTING_HELPERS(name, type) \ - \ /* \ * da_monitor_reset_##name - reset a monitor and setting it to init state \ */ \ @@ -170,8 +123,11 @@ da_event_##name(struct da_monitor *da_mon, enum events_##name event) \ return true; \ } \ \ - if (rv_reacting_on_##name()) \ - cond_react_##name(format_react_msg_##name(curr_state, event)); \ + if (rv_reacting_on() && rv_##name.react) \ + rv_##name.react("rv: monitor %s does not allow event %s on state %s\n", \ + #name, \ + model_get_event_name_##name(event), \ + model_get_state_name_##name(curr_state)); \ \ trace_error_##name(model_get_state_name_##name(curr_state), \ model_get_event_name_##name(event)); \ @@ -202,8 +158,11 @@ static inline bool da_event_##name(struct da_monitor *da_mon, struct task_struct return true; \ } \ \ - if (rv_reacting_on_##name()) \ - cond_react_##name(format_react_msg_##name(curr_state, event)); \ + if (rv_reacting_on() && rv_##name.react) \ + rv_##name.react("rv: monitor %s does not allow event %s on state %s\n", \ + #name, \ + model_get_event_name_##name(event), \ + model_get_state_name_##name(curr_state)); \ \ trace_error_##name(tsk->pid, \ model_get_state_name_##name(curr_state), \ diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index a91bdf802967..28afdeb58412 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -71,7 +71,6 @@ int vprintk_store(int facility, int level, const char *fmt, va_list args); __printf(1, 0) int vprintk_default(const char *fmt, va_list args); -__printf(1, 0) int vprintk_deferred(const char *fmt, va_list args); void __printk_safe_enter(void); void __printk_safe_exit(void); diff --git a/kernel/trace/rv/reactor_panic.c b/kernel/trace/rv/reactor_panic.c index 0186ff4cbd0b..4addabc9bcf1 100644 --- a/kernel/trace/rv/reactor_panic.c +++ b/kernel/trace/rv/reactor_panic.c @@ -13,15 +13,10 @@ #include <linux/init.h> #include <linux/rv.h> -static void rv_panic_reaction(char *msg) -{ - panic(msg); -} - static struct rv_reactor rv_panic = { .name = "panic", .description = "panic the system if an exception is found.", - .react = rv_panic_reaction + .react = panic }; static int __init register_react_panic(void) diff --git a/kernel/trace/rv/reactor_printk.c b/kernel/trace/rv/reactor_printk.c index 178759dbf89f..a15db3fc8b82 100644 --- a/kernel/trace/rv/reactor_printk.c +++ b/kernel/trace/rv/reactor_printk.c @@ -12,9 +12,13 @@ #include <linux/init.h> #include <linux/rv.h> -static void rv_printk_reaction(char *msg) +static void rv_printk_reaction(const char *msg, ...) { - printk_deferred(msg); + va_list args; + + va_start(args, msg); + vprintk_deferred(msg, args); + va_end(args); } static struct rv_reactor rv_printk = { diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c index 7b49cbe388d4..885661fe2b6e 100644 --- a/kernel/trace/rv/rv_reactors.c +++ b/kernel/trace/rv/rv_reactors.c @@ -468,7 +468,7 @@ void reactor_cleanup_monitor(struct rv_monitor_def *mdef) /* * Nop reactor register */ -static void rv_nop_reaction(char *msg) +static void rv_nop_reaction(const char *msg, ...) { }
Each RV monitor has one static buffer to send to the reactors. If multiple errors are detected at the same time, the one buffer could be overwritten. Instead, leave it to the reactors to handle buffering. Signed-off-by: Nam Cao <namcao@linutronix.de> --- Cc: Petr Mladek <pmladek@suse.com> Cc: John Ogness <john.ogness@linutronix.de> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> --- include/linux/printk.h | 1 + include/linux/rv.h | 11 +++--- include/rv/da_monitor.h | 61 ++++++-------------------------- kernel/printk/internal.h | 1 - kernel/trace/rv/reactor_panic.c | 7 +--- kernel/trace/rv/reactor_printk.c | 8 +++-- kernel/trace/rv/rv_reactors.c | 2 +- 7 files changed, 26 insertions(+), 65 deletions(-)