Commit 0b1b4a3d authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull runtime verifier updates from Steven Rostedt:

 - Adapt the ftracetest script to be run from a different folder

   This uses the already existing OPT_TEST_DIR but extends it further to
   run independent tests, then add an --rv flag to allow using the
   script for testing RV (mostly) independently on ftrace.

 - Add basic RV selftests in selftests/verification for more validations

   Add more validations for available/enabled monitors and reactors.
   This could have caught the bug introducing kernel panic solved above.
   Tests use ftracetest.

 - Convert react() function in reactor to use va_list directly

   Use a central helper to handle the variadic arguments. Clean up
   macros and mark functions as static.

 - Add lockdep annotations to reactors to have lockdep complain of
   errors

   If the reactors are called from improper context. Useful to develop
   new reactors. This highlights a warning in the panic reactor that is
   related to the printk subsystem and not to RV.

 - Convert core RV code to use lock guards and __free helpers

   This completely removes goto statements.

 - Fix compilation if !CONFIG_RV_REACTORS

   Fix the warning by keeping LTL monitor variable as always static.

* tag 'trace-rv-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
  rv: Fix compilation if !CONFIG_RV_REACTORS
  rv: Convert to use __free
  rv: Convert to use lock guard
  rv: Add explicit lockdep context for reactors
  rv: Make rv_reacting_on() static
  rv: Pass va_list to reactors
  selftests/verification: Add initial RV tests
  selftest/ftrace: Generalise ftracetest to use with RV
parents 0771cee9 bbaacdc3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22700,6 +22700,7 @@ F: Documentation/trace/rv/
F:	include/linux/rv.h
F:	include/rv/
F:	kernel/trace/rv/
F:	tools/testing/selftests/verification/
F:	tools/verification/
RUST
+6 −5
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ union rv_task_monitor {
struct rv_reactor {
	const char		*name;
	const char		*description;
	__printf(1, 2) void	(*react)(const char *msg, ...);
	__printf(1, 0) void	(*react)(const char *msg, va_list args);
	struct list_head	list;
};
#endif
@@ -102,7 +102,7 @@ struct rv_monitor {
	void			(*reset)(void);
#ifdef CONFIG_RV_REACTORS
	struct rv_reactor	*reactor;
	__printf(1, 2) void	(*react)(const char *msg, ...);
	__printf(1, 0) void	(*react)(const char *msg, va_list args);
#endif
	struct list_head	list;
	struct rv_monitor	*parent;
@@ -116,13 +116,14 @@ int rv_get_task_monitor_slot(void);
void rv_put_task_monitor_slot(int slot);

#ifdef CONFIG_RV_REACTORS
bool rv_reacting_on(void);
int rv_unregister_reactor(struct rv_reactor *reactor);
int rv_register_reactor(struct rv_reactor *reactor);
__printf(2, 3)
void rv_react(struct rv_monitor *monitor, const char *msg, ...);
#else
static inline bool rv_reacting_on(void)
__printf(2, 3)
static inline void rv_react(struct rv_monitor *monitor, const char *msg, ...)
{
	return false;
}
#endif /* CONFIG_RV_REACTORS */

+10 −25
Original line number Diff line number Diff line
@@ -16,34 +16,19 @@
#include <linux/bug.h>
#include <linux/sched.h>

#ifdef CONFIG_RV_REACTORS

#define DECLARE_RV_REACTING_HELPERS(name, type)							\
static void cond_react_##name(type curr_state, type event)					\
{												\
	if (!rv_reacting_on() || !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));				\
}

#else /* CONFIG_RV_REACTOR */

#define DECLARE_RV_REACTING_HELPERS(name, type)							\
static void cond_react_##name(type curr_state, type event)					\
{												\
	return;											\
}
#endif

/*
 * Generic helpers for all types of deterministic automata monitors.
 */
#define DECLARE_DA_MON_GENERIC_HELPERS(name, type)						\
												\
DECLARE_RV_REACTING_HELPERS(name, type)								\
static void react_##name(type curr_state, type event)						\
{												\
	rv_react(&rv_##name,									\
		 "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));					\
}												\
												\
/*												\
 * 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) \
	for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) {					\
		next_state = model_get_next_state_##name(curr_state, event);			\
		if (next_state == INVALID_STATE) {						\
			cond_react_##name(curr_state, event);					\
			react_##name(curr_state, event);					\
			trace_error_##name(model_get_state_name_##name(curr_state),		\
					   model_get_event_name_##name(event));			\
			return false;								\
@@ -165,7 +150,7 @@ static inline bool da_event_##name(struct da_monitor *da_mon, struct task_struct
	for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) {					\
		next_state = model_get_next_state_##name(curr_state, event);			\
		if (next_state == INVALID_STATE) {						\
			cond_react_##name(curr_state, event);					\
			react_##name(curr_state, event);					\
			trace_error_##name(tsk->pid,						\
					   model_get_state_name_##name(curr_state),		\
					   model_get_event_name_##name(event));			\
+2 −15
Original line number Diff line number Diff line
@@ -16,23 +16,9 @@
#error "Please include $(MODEL_NAME).h generated by rvgen"
#endif

#ifdef CONFIG_RV_REACTORS
#define RV_MONITOR_NAME CONCATENATE(rv_, MONITOR_NAME)
static struct rv_monitor RV_MONITOR_NAME;

static void rv_cond_react(struct task_struct *task)
{
	if (!rv_reacting_on() || !RV_MONITOR_NAME.react)
		return;
	RV_MONITOR_NAME.react("rv: "__stringify(MONITOR_NAME)": %s[%d]: violation detected\n",
			      task->comm, task->pid);
}
#else
static void rv_cond_react(struct task_struct *task)
{
}
#endif

static int ltl_monitor_slot = RV_PER_TASK_MONITOR_INIT;

static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *mon);
@@ -98,7 +84,8 @@ static void ltl_monitor_destroy(void)
static void ltl_illegal_state(struct task_struct *task, struct ltl_monitor *mon)
{
	CONCATENATE(trace_error_, MONITOR_NAME)(task);
	rv_cond_react(task);
	rv_react(&RV_MONITOR_NAME, "rv: "__stringify(MONITOR_NAME)": %s[%d]: violation detected\n",
		 task->comm, task->pid);
}

static void ltl_attempt_start(struct task_struct *task, struct ltl_monitor *mon)
+1 −5
Original line number Diff line number Diff line
@@ -13,13 +13,9 @@
#include <linux/init.h>
#include <linux/rv.h>

__printf(1, 2) static void rv_panic_reaction(const char *msg, ...)
__printf(1, 0) static void rv_panic_reaction(const char *msg, va_list args)
{
	va_list args;

	va_start(args, msg);
	vpanic(msg, args);
	va_end(args);
}

static struct rv_reactor rv_panic = {
Loading