Skip to content

Commit 102227b

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rv: Add Runtime Verification (RV) interface
RV is a lightweight (yet rigorous) method that complements classical exhaustive verification techniques (such as model checking and theorem proving) with a more practical approach to complex systems. RV works by analyzing the trace of the system's actual execution, comparing it against a formal specification of the system behavior. RV can give precise information on the runtime behavior of the monitored system while enabling the reaction for unexpected events, avoiding, for example, the propagation of a failure on safety-critical systems. The development of this interface roots in the development of the paper: De Oliveira, Daniel Bristot; Cucinotta, Tommaso; De Oliveira, Romulo Silva. Efficient formal verification for the Linux kernel. In: International Conference on Software Engineering and Formal Methods. Springer, Cham, 2019. p. 315-332. And: De Oliveira, Daniel Bristot. Automata-based formal analysis and verification of the real-time Linux kernel. PhD Thesis, 2020. The RV interface resembles the tracing/ interface on purpose. The current path for the RV interface is /sys/kernel/tracing/rv/. It presents these files: "available_monitors" - List the available monitors, one per line. For example: # cat available_monitors wip wwnr "enabled_monitors" - Lists the enabled monitors, one per line; - Writing to it enables a given monitor; - Writing a monitor name with a '!' prefix disables it; - Truncating the file disables all enabled monitors. For example: # cat enabled_monitors # echo wip > enabled_monitors # echo wwnr >> enabled_monitors # cat enabled_monitors wip wwnr # echo '!wip' >> enabled_monitors # cat enabled_monitors wwnr # echo > enabled_monitors # cat enabled_monitors # Note that more than one monitor can be enabled concurrently. "monitoring_on" - It is an on/off general switcher for monitoring. Note that it does not disable enabled monitors or detach events, but stop the per-entity monitors of monitoring the events received from the system. It resembles the "tracing_on" switcher. "monitors/" Each monitor will have its one directory inside "monitors/". There the monitor specific files will be presented. The "monitors/" directory resembles the "events" directory on tracefs. For example: # cd monitors/wip/ # ls desc enable # cat desc wakeup in preemptive per-cpu testing monitor. # cat enable 0 For further information, see the comments in the header of kernel/trace/rv/rv.c from this patch. Link: https://lkml.kernel.org/r/a4bfe038f50cb047bfb343ad0e12b0e646ab308b.1659052063.git.bristot@kernel.org Cc: Wim Van Sebroeck <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Marco Elver <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Gabriele Paoloni <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Clark Williams <[email protected]> Cc: Tao Zhou <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent ac6c1b2 commit 102227b

File tree

10 files changed

+898
-0
lines changed

10 files changed

+898
-0
lines changed

include/linux/rv.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Runtime Verification.
4+
*
5+
* For futher information, see: kernel/trace/rv/rv.c.
6+
*/
7+
#ifndef _LINUX_RV_H
8+
#define _LINUX_RV_H
9+
10+
#ifdef CONFIG_RV
11+
12+
/*
13+
* Per-task RV monitors count. Nowadays fixed in RV_PER_TASK_MONITORS.
14+
* If we find justification for more monitors, we can think about
15+
* adding more or developing a dynamic method. So far, none of
16+
* these are justified.
17+
*/
18+
#define RV_PER_TASK_MONITORS 1
19+
#define RV_PER_TASK_MONITOR_INIT (RV_PER_TASK_MONITORS)
20+
21+
/*
22+
* Futher monitor types are expected, so make this a union.
23+
*/
24+
union rv_task_monitor {
25+
};
26+
27+
struct rv_monitor {
28+
const char *name;
29+
const char *description;
30+
bool enabled;
31+
int (*enable)(void);
32+
void (*disable)(void);
33+
void (*reset)(void);
34+
};
35+
36+
bool rv_monitoring_on(void);
37+
int rv_unregister_monitor(struct rv_monitor *monitor);
38+
int rv_register_monitor(struct rv_monitor *monitor);
39+
int rv_get_task_monitor_slot(void);
40+
void rv_put_task_monitor_slot(int slot);
41+
42+
#endif /* CONFIG_RV */
43+
#endif /* _LINUX_RV_H */

include/linux/sched.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/rseq.h>
3535
#include <linux/seqlock.h>
3636
#include <linux/kcsan.h>
37+
#include <linux/rv.h>
3738
#include <asm/kmap_size.h>
3839

3940
/* task_struct member predeclarations (sorted alphabetically): */
@@ -1500,6 +1501,16 @@ struct task_struct {
15001501
struct callback_head l1d_flush_kill;
15011502
#endif
15021503

1504+
#ifdef CONFIG_RV
1505+
/*
1506+
* Per-task RV monitor. Nowadays fixed in RV_PER_TASK_MONITORS.
1507+
* If we find justification for more monitors, we can think
1508+
* about adding more or developing a dynamic method. So far,
1509+
* none of these are justified.
1510+
*/
1511+
union rv_task_monitor rv[RV_PER_TASK_MONITORS];
1512+
#endif
1513+
15031514
/*
15041515
* New fields for task_struct should be added above here, so that
15051516
* they are included in the randomized portion of task_struct.

kernel/trace/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,4 +1106,6 @@ config HIST_TRIGGERS_DEBUG
11061106

11071107
If unsure, say N.
11081108

1109+
source "kernel/trace/rv/Kconfig"
1110+
11091111
endif # FTRACE

kernel/trace/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ obj-$(CONFIG_FPROBE) += fprobe.o
106106
obj-$(CONFIG_RETHOOK) += rethook.o
107107

108108
obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o
109+
obj-$(CONFIG_RV) += rv/
109110

110111
libftrace-y := ftrace.o

kernel/trace/rv/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
menuconfig RV
4+
bool "Runtime Verification"
5+
depends on TRACING
6+
help
7+
Enable the kernel runtime verification infrastructure. RV is a
8+
lightweight (yet rigorous) method that complements classical
9+
exhaustive verification techniques (such as model checking and
10+
theorem proving). RV works by analyzing the trace of the system's
11+
actual execution, comparing it against a formal specification of
12+
the system behavior.

kernel/trace/rv/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
obj-$(CONFIG_RV) += rv.o

0 commit comments

Comments
 (0)