Skip to content

Commit 4f739ed

Browse files
t-8chglemco
authored andcommitted
rv: Pass va_list to reactors
The only thing the reactors can do with the passed in varargs is to convert it into a va_list. Do that in a central helper instead. It simplifies the reactors, removes some hairy macro-generated code and introduces a convenient hook point to modify reactor behavior. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://lore.kernel.org/r/20251014-rv-lockdep-v1-1-0b9e51919ea8@linutronix.de Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
1 parent 0c0cd93 commit 4f739ed

6 files changed

Lines changed: 41 additions & 51 deletions

File tree

include/linux/rv.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ union rv_task_monitor {
8888
struct rv_reactor {
8989
const char *name;
9090
const char *description;
91-
__printf(1, 2) void (*react)(const char *msg, ...);
91+
__printf(1, 0) void (*react)(const char *msg, va_list args);
9292
struct list_head list;
9393
};
9494
#endif
@@ -102,7 +102,7 @@ struct rv_monitor {
102102
void (*reset)(void);
103103
#ifdef CONFIG_RV_REACTORS
104104
struct rv_reactor *reactor;
105-
__printf(1, 2) void (*react)(const char *msg, ...);
105+
__printf(1, 0) void (*react)(const char *msg, va_list args);
106106
#endif
107107
struct list_head list;
108108
struct rv_monitor *parent;
@@ -119,11 +119,18 @@ void rv_put_task_monitor_slot(int slot);
119119
bool rv_reacting_on(void);
120120
int rv_unregister_reactor(struct rv_reactor *reactor);
121121
int rv_register_reactor(struct rv_reactor *reactor);
122+
__printf(2, 3)
123+
void rv_react(struct rv_monitor *monitor, const char *msg, ...);
122124
#else
123125
static inline bool rv_reacting_on(void)
124126
{
125127
return false;
126128
}
129+
130+
__printf(2, 3)
131+
static inline void rv_react(struct rv_monitor *monitor, const char *msg, ...)
132+
{
133+
}
127134
#endif /* CONFIG_RV_REACTORS */
128135

129136
#endif /* CONFIG_RV */

include/rv/da_monitor.h

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,19 @@
1616
#include <linux/bug.h>
1717
#include <linux/sched.h>
1818

19-
#ifdef CONFIG_RV_REACTORS
20-
21-
#define DECLARE_RV_REACTING_HELPERS(name, type) \
22-
static void cond_react_##name(type curr_state, type event) \
23-
{ \
24-
if (!rv_reacting_on() || !rv_##name.react) \
25-
return; \
26-
rv_##name.react("rv: monitor %s does not allow event %s on state %s\n", \
27-
#name, \
28-
model_get_event_name_##name(event), \
29-
model_get_state_name_##name(curr_state)); \
30-
}
31-
32-
#else /* CONFIG_RV_REACTOR */
33-
34-
#define DECLARE_RV_REACTING_HELPERS(name, type) \
35-
static void cond_react_##name(type curr_state, type event) \
36-
{ \
37-
return; \
38-
}
39-
#endif
40-
4119
/*
4220
* Generic helpers for all types of deterministic automata monitors.
4321
*/
4422
#define DECLARE_DA_MON_GENERIC_HELPERS(name, type) \
4523
\
46-
DECLARE_RV_REACTING_HELPERS(name, type) \
24+
static void react_##name(type curr_state, type event) \
25+
{ \
26+
rv_react(&rv_##name, \
27+
"rv: monitor %s does not allow event %s on state %s\n", \
28+
#name, \
29+
model_get_event_name_##name(event), \
30+
model_get_state_name_##name(curr_state)); \
31+
} \
4732
\
4833
/* \
4934
* da_monitor_reset_##name - reset a monitor and setting it to init state \
@@ -126,7 +111,7 @@ da_event_##name(struct da_monitor *da_mon, enum events_##name event) \
126111
for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) { \
127112
next_state = model_get_next_state_##name(curr_state, event); \
128113
if (next_state == INVALID_STATE) { \
129-
cond_react_##name(curr_state, event); \
114+
react_##name(curr_state, event); \
130115
trace_error_##name(model_get_state_name_##name(curr_state), \
131116
model_get_event_name_##name(event)); \
132117
return false; \
@@ -165,7 +150,7 @@ static inline bool da_event_##name(struct da_monitor *da_mon, struct task_struct
165150
for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) { \
166151
next_state = model_get_next_state_##name(curr_state, event); \
167152
if (next_state == INVALID_STATE) { \
168-
cond_react_##name(curr_state, event); \
153+
react_##name(curr_state, event); \
169154
trace_error_##name(tsk->pid, \
170155
model_get_state_name_##name(curr_state), \
171156
model_get_event_name_##name(event)); \

include/rv/ltl_monitor.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,12 @@
1616
#error "Please include $(MODEL_NAME).h generated by rvgen"
1717
#endif
1818

19-
#ifdef CONFIG_RV_REACTORS
2019
#define RV_MONITOR_NAME CONCATENATE(rv_, MONITOR_NAME)
21-
static struct rv_monitor RV_MONITOR_NAME;
2220

23-
static void rv_cond_react(struct task_struct *task)
24-
{
25-
if (!rv_reacting_on() || !RV_MONITOR_NAME.react)
26-
return;
27-
RV_MONITOR_NAME.react("rv: "__stringify(MONITOR_NAME)": %s[%d]: violation detected\n",
28-
task->comm, task->pid);
29-
}
21+
#ifdef CONFIG_RV_REACTORS
22+
static struct rv_monitor RV_MONITOR_NAME;
3023
#else
31-
static void rv_cond_react(struct task_struct *task)
32-
{
33-
}
24+
extern struct rv_monitor RV_MONITOR_NAME;
3425
#endif
3526

3627
static int ltl_monitor_slot = RV_PER_TASK_MONITOR_INIT;
@@ -98,7 +89,8 @@ static void ltl_monitor_destroy(void)
9889
static void ltl_illegal_state(struct task_struct *task, struct ltl_monitor *mon)
9990
{
10091
CONCATENATE(trace_error_, MONITOR_NAME)(task);
101-
rv_cond_react(task);
92+
rv_react(&RV_MONITOR_NAME, "rv: "__stringify(MONITOR_NAME)": %s[%d]: violation detected\n",
93+
task->comm, task->pid);
10294
}
10395

10496
static void ltl_attempt_start(struct task_struct *task, struct ltl_monitor *mon)

kernel/trace/rv/reactor_panic.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
#include <linux/init.h>
1414
#include <linux/rv.h>
1515

16-
__printf(1, 2) static void rv_panic_reaction(const char *msg, ...)
16+
__printf(1, 0) static void rv_panic_reaction(const char *msg, va_list args)
1717
{
18-
va_list args;
19-
20-
va_start(args, msg);
2118
vpanic(msg, args);
22-
va_end(args);
2319
}
2420

2521
static struct rv_reactor rv_panic = {

kernel/trace/rv/reactor_printk.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@
1212
#include <linux/init.h>
1313
#include <linux/rv.h>
1414

15-
__printf(1, 2) static void rv_printk_reaction(const char *msg, ...)
15+
__printf(1, 0) static void rv_printk_reaction(const char *msg, va_list args)
1616
{
17-
va_list args;
18-
19-
va_start(args, msg);
2017
vprintk_deferred(msg, args);
21-
va_end(args);
2218
}
2319

2420
static struct rv_reactor rv_printk = {

kernel/trace/rv/rv_reactors.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ int reactor_populate_monitor(struct rv_monitor *mon)
438438
/*
439439
* Nop reactor register
440440
*/
441-
__printf(1, 2) static void rv_nop_reaction(const char *msg, ...)
441+
__printf(1, 0) static void rv_nop_reaction(const char *msg, va_list args)
442442
{
443443
}
444444

@@ -477,3 +477,17 @@ int init_rv_reactors(struct dentry *root_dir)
477477
out_err:
478478
return -ENOMEM;
479479
}
480+
481+
void rv_react(struct rv_monitor *monitor, const char *msg, ...)
482+
{
483+
va_list args;
484+
485+
if (!rv_reacting_on() || !monitor->react)
486+
return;
487+
488+
va_start(args, msg);
489+
490+
monitor->react(msg, args);
491+
492+
va_end(args);
493+
}

0 commit comments

Comments
 (0)