The Runtime Verification (RV) interface
Subsystems (4)
v2 cover The Runtime Verification (RV) interface
Over the last years, I've been exploring the possibility of verifying the Linux kernel behavior using Runtime Verification.
Runtime Verification (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 for complex systems.
Instead of relying on a fine-grained model of a system (e.g., a re-implementation a instruction level), RV works by analyzing the trace of the system's actual execution, comparing it against a formal specification of the system behavior.
The usage of deterministic automaton for RV is a well-established approach. In the specific case of the Linux kernel, you can check how to model complex behavior of the Linux kernel with this 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 how efficient is this approach here:
DE OLIVEIRA, Daniel B.; DE OLIVEIRA, Romulo S.; CUCINOTTA, Tommaso. *A thread synchronization model for the PREEMPT_RT Linux kernel.* Journal of Systems Architecture, 2020, 107: 101729.
tlrd: it is possible to model complex behaviors in a modular way, with an acceptable overhead (even for production systems). See this presentation at 2019's ELCE: https://www.youtube.com/watch?v=BfTuEHafNgg
Here I am proposing a more practical approach for the usage of deterministic automata for runtime verification, and it includes:
- An interface for controlling the verification;
- A tool and set of headers that enables the automatic code generation of the RV monitor (Monitor Synthesis);
- Sample monitors to evaluate the interface;
- A sample monitor developed in the context of the Elisa Project demonstrating how to use RV in the context of safety-critical systems.
Given that RV is a tracing consumer, the code is being placed inside the tracing subsystem (Steven and I have been talking about it for a while).
The changes since V1 includes:
- rebased to the latest kernel;
- code cleanup;
- the watchdog dev monitor;
- safety app;
The TODO list still includes:
- Make per-task monitor use the task struct to store the per monitor state (Suggested by peterz)
- Add a reactor tha enables the visualization of the visited states via KCOV (Marco Elver & Dmitry Vyukov)
- Add a CRC method to check from user-space if the values exported by the monitor were not corrupted by any other kernel task (Gabriele Paoloni)
I am sending the V2 with some TODOs because I need
some feedback on the interface/files placement inside the kernel, so I can adjust all the patches accordingly. Also, to make it possible for people in the Elisa Project to evaluate the safety_app approach.
Daniel Bristot de Oliveira (21):
rv: Add Runtime Verification (RV) interface
rv: Add runtime reactors interface
rv/include: Add helper functions for deterministic automata rv/include: Add deterministic automata monitor definition via C macros rv/include: Add tracing helper functions
tools/rv: Add dot2c
tools/rv: Add dot2k
rv/monitor: Add the wip monitor skeleton created by dot2k rv/monitor: wip instrumentation and Makefile/Kconfig entries rv/monitor: Add the wwnr monitor skeleton created by dot2k rv/monitor: wwnr instrumentation and Makefile/Kconfig entries rv/reactor: Add the printk reactor
rv/reactor: Add the panic reactor
Documentation/rv: Add a basic documentation Documentation/rv: Add deterministic automata monitor synthesis
documentation
Documentation/rv: Add deterministic automata instrumentation
documentation
watchdog/dev: Add tracepoints
rv/monitor: Add safe watchdog monitor
rv/monitor: Add safe watchdog nowayout monitor rv/safety_app: Add an safety_app sample
Documentation/rv: Add watchdog-monitor documentation
Documentation/trace/index.rst | 1 + .../trace/rv/da_monitor_instrumentation.rst | 230 ++++++ .../trace/rv/da_monitor_synthesis.rst | 286 +++++++ Documentation/trace/rv/index.rst | 9 + .../trace/rv/runtime-verification.rst | 233 ++++++ Documentation/trace/rv/watchdog-monitor.rst | 307 ++++++++ drivers/watchdog/watchdog_dev.c | 41 +- include/linux/rv.h | 31 + include/linux/watchdog.h | 7 +- include/rv/automata.h | 52 ++ include/rv/da_monitor.h | 398 ++++++++++ include/rv/trace_helpers.h | 69 ++ include/trace/events/watchdog.h | 103 +++ kernel/trace/Kconfig | 2 + kernel/trace/Makefile | 2 + kernel/trace/rv/Kconfig | 78 ++ kernel/trace/rv/Makefile | 10 + kernel/trace/rv/monitor_safe_wtd/model.h | 84 +++ kernel/trace/rv/monitor_safe_wtd/safe_wtd.c | 322 ++++++++ kernel/trace/rv/monitor_safe_wtd/safe_wtd.h | 64 ++ kernel/trace/rv/monitor_safe_wtd_nwo/model.h | 61 ++ .../rv/monitor_safe_wtd_nwo/safe_wtd_nwo.c | 309 ++++++++ .../rv/monitor_safe_wtd_nwo/safe_wtd_nwo.h | 64 ++ kernel/trace/rv/monitor_wip/model.h | 38 + kernel/trace/rv/monitor_wip/wip.c | 124 +++ kernel/trace/rv/monitor_wip/wip.h | 64 ++ kernel/trace/rv/monitor_wwnr/model.h | 38 + kernel/trace/rv/monitor_wwnr/wwnr.c | 122 +++ kernel/trace/rv/monitor_wwnr/wwnr.h | 70 ++ kernel/trace/rv/reactor_panic.c | 44 ++ kernel/trace/rv/reactor_printk.c | 43 ++ kernel/trace/rv/rv.c | 700 +++++++++++++++++ kernel/trace/rv/rv.h | 50 ++ kernel/trace/rv/rv_reactors.c | 478 ++++++++++++ kernel/trace/trace.c | 4 + kernel/trace/trace.h | 2 + tools/tracing/rv/dot2/Makefile | 26 + tools/tracing/rv/dot2/automata.py | 179 +++++ tools/tracing/rv/dot2/dot2c | 30 + tools/tracing/rv/dot2/dot2c.py | 240 ++++++ tools/tracing/rv/dot2/dot2k | 46 ++ tools/tracing/rv/dot2/dot2k.py | 184 +++++ .../rv/dot2/dot2k_templates/main_global.c | 96 +++ .../rv/dot2/dot2k_templates/main_global.h | 64 ++ .../rv/dot2/dot2k_templates/main_per_cpu.c | 96 +++ .../rv/dot2/dot2k_templates/main_per_cpu.h | 64 ++ .../rv/dot2/dot2k_templates/main_per_task.c | 96 +++ .../rv/dot2/dot2k_templates/main_per_task.h | 70 ++ tools/tracing/rv/safety_app/Makefile | 51 ++ tools/tracing/rv/safety_app/safety_app.c | 713 ++++++++++++++++++ 50 files changed, 6486 insertions(+), 9 deletions(-) create mode 100644 Documentation/trace/rv/da_monitor_instrumentation.rst create mode 100644 Documentation/trace/rv/da_monitor_synthesis.rst create mode 100644 Documentation/trace/rv/index.rst create mode 100644 Documentation/trace/rv/runtime-verification.rst create mode 100644 Documentation/trace/rv/watchdog-monitor.rst create mode 100644 include/linux/rv.h create mode 100644 include/rv/automata.h create mode 100644 include/rv/da_monitor.h create mode 100644 include/rv/trace_helpers.h create mode 100644 include/trace/events/watchdog.h create mode 100644 kernel/trace/rv/Kconfig create mode 100644 kernel/trace/rv/Makefile create mode 100644 kernel/trace/rv/monitor_safe_wtd/model.h create mode 100644 kernel/trace/rv/monitor_safe_wtd/safe_wtd.c create mode 100644 kernel/trace/rv/monitor_safe_wtd/safe_wtd.h create mode 100644 kernel/trace/rv/monitor_safe_wtd_nwo/model.h create mode 100644 kernel/trace/rv/monitor_safe_wtd_nwo/safe_wtd_nwo.c create mode 100644 kernel/trace/rv/monitor_safe_wtd_nwo/safe_wtd_nwo.h create mode 100644 kernel/trace/rv/monitor_wip/model.h create mode 100644 kernel/trace/rv/monitor_wip/wip.c create mode 100644 kernel/trace/rv/monitor_wip/wip.h create mode 100644 kernel/trace/rv/monitor_wwnr/model.h create mode 100644 kernel/trace/rv/monitor_wwnr/wwnr.c create mode 100644 kernel/trace/rv/monitor_wwnr/wwnr.h create mode 100644 kernel/trace/rv/reactor_panic.c create mode 100644 kernel/trace/rv/reactor_printk.c create mode 100644 kernel/trace/rv/rv.c create mode 100644 kernel/trace/rv/rv.h create mode 100644 kernel/trace/rv/rv_reactors.c create mode 100644 tools/tracing/rv/dot2/Makefile create mode 100644 tools/tracing/rv/dot2/automata.py create mode 100644 tools/tracing/rv/dot2/dot2c create mode 100644 tools/tracing/rv/dot2/dot2c.py create mode 100644 tools/tracing/rv/dot2/dot2k create mode 100644 tools/tracing/rv/dot2/dot2k.py create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_global.c create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_global.h create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_cpu.c create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_cpu.h create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_task.c create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_task.h create mode 100644 tools/tracing/rv/safety_app/Makefile create mode 100644 tools/tracing/rv/safety_app/safety_app.c
Signature · 1 line
2.33.1
RFC v2 1/21 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, et al. 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:
[root@f32 rv]# 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:
[root@f32 rv]# cat enabled_monitors
[root@f32 rv]# echo wip > enabled_monitors
[root@f32 rv]# echo wwnr >> enabled_monitors
[root@f32 rv]# cat enabled_monitors
wip
wwnr
[root@f32 rv]# echo -wip >> enabled_monitors
[root@f32 rv]# cat enabled_monitors
wwnr
[root@f32 rv]# echo > enabled_monitors
[root@f32 rv]# cat enabled_monitors
[root@f32 rv]#
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, but stop the per-entity monitors of monitoring the events received from the system. It resambles 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 resambles the "events" directory on tracefs.
For example:
[root@f32 rv]# cd monitors/wip/
[root@f32 wip]# ls
desc enable
[root@f32 wip]# cat desc
auto-generated wakeup in preemptive monitor.
[root@f32 wip]# cat enable
0
For further information, see the comments in the header of kernel/trace/rv/rv.c from this patch.
--- include/linux/rv.h | 21 ++ kernel/trace/Kconfig | 2 + kernel/trace/Makefile | 2 + kernel/trace/rv/Kconfig | 12 + kernel/trace/rv/Makefile | 3 + kernel/trace/rv/rv.c | 687 +++++++++++++++++++++++++++++++++++++++ kernel/trace/rv/rv.h | 31 ++ kernel/trace/trace.c | 4 + kernel/trace/trace.h | 2 + 9 files changed, 764 insertions(+) create mode 100644 include/linux/rv.h create mode 100644 kernel/trace/rv/Kconfig create mode 100644 kernel/trace/rv/Makefile create mode 100644 kernel/trace/rv/rv.c create mode 100644 kernel/trace/rv/rv.h
include/linux/rv.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Runtime Verification. +* +* For futher information, see: kernel/trace/rv/rv.c. +* +* Copyright (C) 2019-2022 Daniel Bristot de Oliveira <[email protected]> +*/ + +struct rv_monitor { +const char *name; +const char *description; +bool enabled; +int (*start)(void ); +void (*stop)(void ); +void (*reset)(void ); +}; + +extern bool monitoring_on; +int rv_unregister_monitor (struct rv_monitor *monitor); +int rv_register_monitor (struct rv_monitor *monitor);
kernel/trace/Kconfig +2 -0
@@ -1062,4 +1062,6 @@ config HIST_TRIGGERS_DEBUG If unsure, say N. +source "kernel/trace/rv/Kconfig" + endif # FTRACE
kernel/trace/Makefile +2 -0
@@ -101,3 +101,5 @@ obj-$(CONFIG_FTRACE_RECORD_RECURSION) += trace_recursion_record.o obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o libftrace-y := ftrace.o + +obj-$(CONFIG_RV) += rv/
kernel/trace/rv/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +menuconfig RV + bool "Runtime Verification" + depends on TRACING + help + Enable the kernel runtime verification infrastructure. RV is a + lightweight (yet rigorous) method that complements classical + exhaustive verification techniques (such as model checking and + theorem proving). RV works by analyzing the trace of the system's + actual execution, comparing it against a formal specification of + the system behavior.
kernel/trace/rv/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_RV) += rv.o
kernel/trace/rv/rv.c new file +687 -0
687 lines not on this page · raw message
kernel/trace/rv/rv.h new file +31 -0
@@ -0,0 +1,31 @@ +#include <linux/mutex.h> + +struct rv_interface { +struct dentry *root_dir; +struct dentry *monitors_dir; +}; + +#include "../trace.h" +#include <linux/tracefs.h> +#include <linux/rv.h> + +#define rv_create_dir tracefs_create_dir +#define rv_create_file tracefs_create_file +#define rv_remove tracefs_remove + +#define MAX_RV_MONITOR_NAME_SIZE 100 + +extern struct mutex rv_interface_lock; + +struct rv_monitor_def { +struct list_head list; +struct rv_monitor *monitor; +struct dentry *root_d; +bool enabled; +bool reacting; +}; + +extern bool monitoring_on; +struct dentry *get_monitors_root (void ); +void reset_all_monitors (void ); +int init_rv_monitors (struct dentry *root_dir);
kernel/trace/trace.c +4 -0
@@ -9712,6 +9712,10 @@ static __init int tracer_init_tracefs(void)update_tracer_options (&global_trace); +#ifdef CONFIG_RV +rv_init_interface (); +#endif +return 0 ; }
kernel/trace/trace.h +2 -0
@@ -2010,4 +2010,6 @@ struct trace_min_max_param {extern const struct file_operations trace_min_max_fops; +extern int rv_init_interface (void ); +#endif /* _LINUX_KERNEL_TRACE_H */
Signature · 1 line
2.33.1
kernel test robot
build botRe: [RFC V2 01/21] rv: Add Runtime Verification (RV) interface
[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]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on rostedt-trace/for-next]
[also build test WARNING on lwn/docs-next linus/master v5.17-rc4 next-20220214] [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]
url: https://github.com/0day-ci/linux/commits/Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next config: hexagon-allyesconfig (https://download.01.org/0day-ci/archive/20220215/202202150143.3BpCqVdF-lkp(a)intel.com/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project ea071884b0cc7210b3cc5fe858f0e892a779a23b)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f99370d1c81f0a3b56d6630ff62631f6ecfdf8d8
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 git checkout f99370d1c81f0a3b56d6630ff62631f6ecfdf8d8
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash kernel/trace/rv/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/trace/rv/rv.c:189:6: warning: no previous prototype for function 'disable_monitor' [-Wmissing-prototypes]
void disable_monitor(struct rv_monitor_def *mdef)
^
kernel/trace/rv/rv.c:189:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void disable_monitor(struct rv_monitor_def *mdef)
^
static
>> kernel/trace/rv/rv.c:202:6: warning: no previous prototype for function 'enable_monitor' [-Wmissing-prototypes]
void enable_monitor(struct rv_monitor_def *mdef)
^ kernel/trace/rv/rv.c:202:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void enable_monitor(struct rv_monitor_def *mdef)
^
static
2 warnings generated.
vim +/disable_monitor +189 kernel/trace/rv/rv.c
185
186 /*
187 * Disable a given runtime monitor.
188 */
> 189 void disable_monitor(struct rv_monitor_def *mdef)
190 {
191 if (mdef->monitor->enabled) {
192 mdef->monitor->enabled = 0;
193 mdef->monitor->stop();
194 }
195
196 mdef->enabled = 0;
197 }
198
199 /*
200 * Enable a given monitor.
201 */
> 202 void enable_monitor(struct rv_monitor_def *mdef) 203 {
204 /*
205 * Reset all internal monitors before starting.
206 */
207 mdef->monitor->reset();
208 if (!mdef->monitor->enabled)
209 mdef->monitor->start();
210
211 mdef->monitor->enabled = 1;
212 mdef->enabled = 1;
213 }
214
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC V2 01/21] rv: Add Runtime Verification (RV) interface
In reply to Daniel Bristot de Oliveira[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]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on rostedt-trace/for-next]
[also build test WARNING on lwn/docs-next linus/master v5.17-rc4 next-20220214] [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]
url: https://github.com/0day-ci/linux/commits/Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next config: csky-allmodconfig (https://download.01.org/0day-ci/archive/20220215/202202150225.IlpGVxKc-lkp(a)intel.com/config) compiler: csky-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f99370d1c81f0a3b56d6630ff62631f6ecfdf8d8
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 git checkout f99370d1c81f0a3b56d6630ff62631f6ecfdf8d8
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=csky SHELL=/bin/bash drivers/tty/serial/ kernel/trace/rv/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/trace/rv/rv.c:189:6: warning: no previous prototype for 'disable_monitor' [-Wmissing-prototypes]
189 | void disable_monitor(struct rv_monitor_def *mdef)
| ^~~~~~~~~~~~~~~
>> kernel/trace/rv/rv.c:202:6: warning: no previous prototype for 'enable_monitor' [-Wmissing-prototypes] 202 | void enable_monitor(struct rv_monitor_def *mdef)
| ^~~~~~~~~~~~~~
vim +/disable_monitor +189 kernel/trace/rv/rv.c
185
186 /*
187 * Disable a given runtime monitor.
188 */
> 189 void disable_monitor(struct rv_monitor_def *mdef)
190 {
191 if (mdef->monitor->enabled) {
192 mdef->monitor->enabled = 0;
193 mdef->monitor->stop();
194 }
195
196 mdef->enabled = 0;
197 }
198
199 /*
200 * Enable a given monitor.
201 */
> 202 void enable_monitor(struct rv_monitor_def *mdef) 203 {
204 /*
205 * Reset all internal monitors before starting.
206 */
207 mdef->monitor->reset();
208 if (!mdef->monitor->enabled)
209 mdef->monitor->start();
210
211 mdef->monitor->enabled = 1;
212 mdef->enabled = 1;
213 }
214
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 2/21 Add runtime reactors interface
In reply to Daniel Bristot de OliveiraA runtime monitor can cause a reaction to the detection of an exception on the model's execution. By default, the monitors have tracing reactions, printing the monitor output via tracepoints. But other reactions can be added (on-demand) via this interface.
The user interface resembles the kernel tracing interface and presents these files:
"available_reactors"
- Reading shows the available reactors, one per line.
For example:
[root@f32 rv]# cat available_reactors
nop
panic
printk
"reacting_on"
- It is an on/off general switch for reactors, disabling all reactions.
"monitors/MONITOR/reactors"
- List available reactors, with the select reaction for the given MONITOR inside []. The default one is the nop (no operation) reactor.
- Writing the name of a reactor enables it to the given MONITOR.
For example:
[root@f32 rv]# cat monitors/wip/reactors [nop]
panic
printk
[root@f32 rv]# echo panic > monitors/wip/reactors [root@f32 rv]# cat monitors/wip/reactors nop
[panic]
printk
--- include/linux/rv.h | 10 + kernel/trace/rv/Kconfig | 14 + kernel/trace/rv/Makefile | 1 + kernel/trace/rv/rv.c | 17 +- kernel/trace/rv/rv.h | 19 ++ kernel/trace/rv/rv_reactors.c | 478 ++++++++++++++++++++++++++++++++++ 6 files changed, 537 insertions(+), 2 deletions(-) create mode 100644 kernel/trace/rv/rv_reactors.c
include/linux/rv.h +10 -0
@@ -6,6 +6,11 @@* * Copyright (C) 2019-2022 Daniel Bristot de Oliveira <[email protected]> */ +struct rv_reactor { +char *name; +char *description; +void (*react)(char *); +};struct rv_monitor {const char *name;
@@ -14,8 +19,13 @@ struct rv_monitor {int (*start)(void );void (*stop)(void );void (*reset)(void ); +void (*react)(char *); };extern bool monitoring_on;int rv_unregister_monitor (struct rv_monitor *monitor);int rv_register_monitor (struct rv_monitor *monitor); + +extern bool reacting_on; +int rv_unregister_reactor (struct rv_reactor *reactor); +int rv_register_reactor (struct rv_reactor *reactor);
kernel/trace/rv/Kconfig +14 -0
@@ -10,3 +10,17 @@ menuconfig RV theorem proving). RV works by analyzing the trace of the system's actual execution, comparing it against a formal specification of the system behavior. + +if RV + +config RV_REACTORS + bool "Runtime verification reactors" + default y if RV + help + Enables the online runtime verification reactors. A runtime + monitor can cause a reaction to the detection of an exception + on the model's execution. By default, the monitors have + tracing reactions, printing the monitor output via tracepoints, + but other reactions can be added (on-demand) via this interface. + +endif # RV
kernel/trace/rv/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_RV) += rv.o +obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
kernel/trace/rv/rv.c +15 -2
@@ -312,8 +312,13 @@ static int create_monitor_dir(struct rv_monitor_def *mdef) retval = -ENOMEM ; goto out_remove_root; } +#ifdef CONFIG_RV_REACTORS + retval =reactor_create_monitor_files (mdef); +if (retval) + goto out_remove_root; +#endif -return retval; +return 0 ; out_remove_root:rv_remove (mdef->root_d);
@@ -621,7 +626,11 @@ int rv_register_monitor(struct rv_monitor *monitor) r->monitor = monitor; -create_monitor_dir (r); + retval =create_monitor_dir (r); +if (retval) { +kfree (r); + goto out_unlock; + }list_add_tail (&r->list, &rv_monitors_list);
@@ -681,6 +690,10 @@ int __init rv_init_interface(void)rv_create_file ("monitoring_on" ,0600 , rv_root.root_dir,NULL , &monitoring_on_fops); +#ifdef CONFIG_RV_REACTORS +init_rv_reactors (rv_root.root_dir); + reacting_on=true; +#endif monitoring_on=true;return 0 ;
kernel/trace/rv/rv.h +19 -0
@@ -14,12 +14,25 @@ struct rv_interface {#define rv_remove tracefs_remove#define MAX_RV_MONITOR_NAME_SIZE 100 +#define MAX_RV_REACTOR_NAME_SIZE 100extern struct mutex rv_interface_lock; +#ifdef CONFIG_RV_REACTORS +struct rv_reactor_def { +struct list_head list; +struct rv_reactor *reactor; +/* protected by the monitor interface lock */ +int counter; +}; +#endif +struct rv_monitor_def {struct list_head list;struct rv_monitor *monitor; +#ifdef CONFIG_RV_REACTORS +struct rv_reactor_def *rdef; +#endif struct dentry *root_d;bool enabled;bool reacting;
@@ -29,3 +42,9 @@ extern bool monitoring_on;struct dentry *get_monitors_root (void );void reset_all_monitors (void );int init_rv_monitors (struct dentry *root_dir); + +#ifdef CONFIG_RV_REACTORS +extern bool reacting_on; +int reactor_create_monitor_files (struct rv_monitor_def *mdef); +int init_rv_reactors (struct dentry *root_dir); +#endif
kernel/trace/rv/rv_reactors.c new file +478 -0
478 lines not on this page · raw message
Signature · 1 line
2.33.1
kernel test robot
build botRe: [RFC V2 02/21] rv: Add runtime reactors interface
[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]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on rostedt-trace/for-next]
[also build test WARNING on lwn/docs-next linus/master v5.17-rc4 next-20220214] [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]
url: https://github.com/0day-ci/linux/commits/Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next config: hexagon-allyesconfig (https://download.01.org/0day-ci/archive/20220215/202202150232.GmgML41h-lkp(a)intel.com/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project ea071884b0cc7210b3cc5fe858f0e892a779a23b)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/e716a88380b48ccbfe62acc96f536718e439130e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 git checkout e716a88380b48ccbfe62acc96f536718e439130e
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash kernel/trace/rv/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/trace/rv/rv_reactors.c:76:24: warning: no previous prototype for function 'get_reactor_rdef_by_name' [-Wmissing-prototypes]
struct rv_reactor_def *get_reactor_rdef_by_name(char *name)
^ kernel/trace/rv/rv_reactors.c:76:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct rv_reactor_def *get_reactor_rdef_by_name(char *name)
^
static
1 warning generated.
vim +/get_reactor_rdef_by_name +76 kernel/trace/rv/rv_reactors.c
75
> 76 struct rv_reactor_def *get_reactor_rdef_by_name(char *name)
77 {
78 struct rv_reactor_def *r;
79 list_for_each_entry(r, &rv_reactors_list, list) {
80 if (strcmp(name, r->reactor->name) == 0)
81 return r;
82 }
83
84 return NULL;
85 }
86 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 3/21 rv/include: Add helper functions for deterministic automata
In reply to Daniel Bristot de OliveiraFormally, a deterministic automaton, denoted by G, is defined as a quintuple:
G = { X, E, f, x_0, X_m }
where:
- X is the set of states;
- E is the finite set of events;
- x_0 is the initial state;
- X_m (subset of X) is the set of marked states.
- f : X x E -> X $ is the transition function. It defines the state transition in the occurrence of a event from E in the state X. In the special case of deterministic automata, the occurence of the event in E in a state in X has a deterministic next state from X.
An automaton can also be represented using a graphical format of vertices (nodes) and edges. The open-source tool Graphviz can produce this graphic format using the (textual) DOT language as the source code.
The dot2c tool presented in this 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.
Translates a deterministic automaton in the DOT format into a C source code representation that to be used for monitoring.
This header file implements helper functions to facilitate the usage of the C output from dot2c for monitoring.
--- include/rv/automata.h | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 include/rv/automata.h
include/rv/automata.h new file +52 -0
@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Deterministic automata helper functions, to be used with the automata +* models in C generated by the dot2k tool. +* +* The dot2k tool is available at https://gitlab.com/linux-rv-tools/dot2/. +* +* Copyright (C) 2019-2022 Daniel Bristot de Oliveira <[email protected]> +*/ + +#define DECLARE_AUTOMATA_HELPERS (name, type) \ + \ +static inline void *model_get_model_##name(void) \ +{ \ + return (void *) &automaton_##name; \ +} \ + \ +char *model_get_state_name_##name(enum states_##name state) \ +{ \ + return automaton_##name.state_names[state]; \ +} \ + \ +char *model_get_event_name_##name(enum events_##name event) \ +{ \ + return automaton_##name.event_names[event]; \ +} \ + \ +static inline type model_get_init_state_##name(void) \ +{ \ + return automaton_##name.initial_state; \ +} \ + \ +static inline type \ +model_get_next_state_##name(enum states_##name curr_state, \ + enum events_##name event) \ +{ \ + if ((curr_state < 0) || (curr_state > state_max)) \ + return -1; \ + \ + if ((event < 0) || (event > event_max)) \ + return -1; \ + \ + return automaton_##name.function[curr_state][event]; \ +} \ + \ +static inline bool model_is_final_state_##name(enum states_##name state) \ +{ \ + if ((state < 0) || (state > state_max)) \ + return 0; \ + \ + return !!automaton_##name.final_states[state]; \ +}
Signature · 1 line
2.33.1
RFC v2 4/21 rv/include: Add deterministic automata monitor definition via C macros
In reply to Daniel Bristot de OliveiraIn Linux terms, the runtime verification monitors are encapsulated inside the "RV monitor" abstraction. The "RV monitor" includes a set of instances of the monitor (per-cpu monitor, per-task monitor, and so on), the helper functions that glue the monitor to the system reference model, and the trace output as a reaction for event parsing and exceptions, as depicted below:
Linux +----- RV Monitor ----------------------------------+ Formal
Realm | | Realm
+-------------------+ +----------------+ +-----------------+
| Linux kernel | | Monitor | | Reference |
| Tracing | -> | Instance(s) | <- | Model |
| (instrumentation) | | (verification) | | (specification) |
+-------------------+ +----------------+ +-----------------+
| | |
| V |
| +----------+ |
| | Reaction | |
| +--+--+--+-+ |
| | | | |
| | | +-> trace output ? |
+------------------------|--|----------------------+
| +----> panic ?
+-------> <user-specified>The dot2c tool presented in this 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.
Translates a deterministic automaton in the DOT format into a C source code representation that to be used for monitoring connecting the Formal Reaml to Linux-like code.
This header file goes beyond, extending the code generation to the verification stage, generating the code to the Monitor Instance(s) level using C macros. The trace event code inspires this approach.
The benefits of the usage of macro for monitor synthesis is 3-fold:
- Reduces the code duplication;
- Facilitates the bug fix/improvement;
(but mainly:)
- Avoids the case of developers changing the core of the monitor code to manipulate the model in a (let's say) non-standard way.
This initial implementation presents two different types of monitor instances:
- #define DECLARE_DA_MON_PER_CPU(name, type)
- #define DECLARE_DA_MON_PER_TASK(name, type)
The first declares the functions for deterministic automata monitor with per-cpu instances, and the second with per-task instances.
In both cases, the name is a string that identifies the monitor, and the type is the data type used by dot2c/k on the representation of the model.
For example, the model "wip" below:
preempt_disable sched_waking
+############+ >------------------> +################+ >------------+
-># preemptive # # non-preemptive # |
+############+ <-----------------< +################+ <------------+
preempt_enable
with two states and three events can be stored in a 'char' type. Considering that the preemption control is a per-cpu behavior, the monitor declaration will be:
DECLARE_DA_MON_PER_CPU(wip, char);
The monitor is executed by sending events to be processed via the functions presented below:
da_handle_event_$(MONITOR_NAME)($(event from event enum)); da_handle_init_event_$(MONITOR_NAME)($(event from event enum));
The function da_handle_event_$(MONITOR_NAME) is the regular case, while the function da_handle_init_event_$(MONITOR_NAME)() is a special case used to synchronize the system with the model.
When a monitor is enabled, it is placed in the initial state of the automata. However, the monitor does not know if the system is in the initial state. Hence, the monitor ignores events sent by sent by da_handle_event_$(MONITOR_NAME) until the function da_handle_init_event_$(MONITOR_NAME)() is called.
The function da_handle_init_event_$(MONITOR_NAME)() should be used for the case in which the system generates the event is the one that returns the automata to the initial state.
After receiving a da_handle_init_event_$(MONITOR_NAME)() event, the monitor will know that it is in sync with the system and hence will start processing the next events.
Using the wip model as example, the events "preempt_disable" and "sched_waking" should be sent to to monitor, respectively, via:
da_handle_event_wip(preempt_disable);
da_handle_event_wip(sched_waking);While the event "preempt_enabled" will use:
da_handle_init_event_wip(preempt_enable);
To notify the monitor that the system will be returning to the initial state, so the system and the monitor should be in sync.
With the monitor synthesis in place, using these headers and dot2k, the developer's work should be limited to the instrumentation of the system, increasing the confidence in the overall approach.
--- include/rv/da_monitor.h | 398 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 398 insertions(+) create mode 100644 include/rv/da_monitor.h
include/rv/da_monitor.h new file +398 -0
@@ -0,0 +1,398 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Deterministic automata (DA) monitor functions, to be used togheter +* with automata models in C generated by the dot2k tool. +* +* The dot2k tool is available at tools/tracing/rv/ +* +* Copyright (C) 2019-2022 Daniel Bristot de Oliveira <[email protected]> +*/ + +#include <rv/automata.h> +#include <rv/trace_helpers.h> + +struct da_monitor { +char curr_state; +bool monitoring; +void *model; +}; + +#define MAX_PID 1024000 + +/* +* Generic helpers for all types of deterministic automata monitors. +*/ +#define DECLARE_DA_MON_GENERIC_HELPERS (name, type) \ +static char REACT_MSG[1024]; \ + \ +static inline char \ +*format_react_msg(type curr_state, type event) \ +{ \ + snprintf(REACT_MSG, 1024, \ + "rv: monitor %s does not allow event %s on state %s\n", \ + MODULE_NAME, \ + model_get_event_name_##name(event), \ + model_get_state_name_##name(curr_state)); \ + return REACT_MSG; \ +} \ + \ +static void cond_react(char *msg) \ +{ \ + if (rv_##name.react) \ + rv_##name.react(msg); \ +} \ + \ +static inline void da_monitor_reset_##name(struct da_monitor *da_mon) \ +{ \ + da_mon->monitoring = 0; \ + da_mon->curr_state = model_get_init_state_##name(); \ +} \ + \ +static inline type da_monitor_curr_state_##name(struct da_monitor *da_mon) \ +{ \ + return da_mon->curr_state; \ +} \ + \ +static inline void \ +da_monitor_set_state_##name(struct da_monitor *da_mon, enum states_##name state)\ +{ \ + da_mon->curr_state = state; \ +} \ +static inline void da_monitor_start_##name(struct da_monitor *da_mon) \ +{ \ + da_mon->monitoring = 1; \ +} \ + \ +static inline bool da_monitoring_##name(struct da_monitor *da_mon) \ +{ \ + return da_mon->monitoring; \ +} + + +/* +* Event handler for implict monitors. Implicity monitor is the one which the +* handler does not need to specify which da_monitor to manilupulate. Examples +* of implicit monitor are the per_cpu or the global ones. +*/ +#define DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT (name, type) \ +static inline void \ +trace_event_##name(type state, type event, type next_state, bool safe); \ +static inline void trace_error_##name(type state, type event); \ + \ +static inline bool \ +da_event_##name(struct da_monitor *da_mon, enum events_##name event) \ +{ \ + type curr_state = da_monitor_curr_state_##name(da_mon); \ + type next_state = model_get_next_state_##name(curr_state, event); \ + \ + if (next_state >= 0) { \ + da_monitor_set_state_##name(da_mon, next_state); \ + \ + trace_event_##name(curr_state, event, next_state, \ + model_is_final_state_##name(next_state)); \ + \ + return true; \ + } \ + \ + if (reacting_on) \ + cond_react(format_react_msg(curr_state, event)); \ + \ + trace_error_##name(curr_state, event); \ + \ + return false; \ +} \ + +/* +* Event handler for per_task monitors. +*/ +#define DECLARE_DA_MON_MODEL_HANDLER_PER_TASK (name, type) \ + \ +static inline void \ +trace_event_##name(pid_t pid, type state, type event, \ + type next_state, bool safe); \ +static inline void trace_error_##name(pid_t pid, type state, type event); \ + \ +static inline type \ +da_event_##name(struct da_monitor *da_mon, pid_t pid, enum events_##name event) \ +{ \ + type curr_state = da_monitor_curr_state_##name(da_mon); \ + type next_state = model_get_next_state_##name(curr_state, event); \ + \ + if (next_state >= 0) { \ + da_monitor_set_state_##name(da_mon, next_state); \ + \ + trace_event_##name(pid, curr_state, event, next_state, \ + model_is_final_state_##name(next_state)); \ + \ + return true; \ + } \ + \ + if (reacting_on && rv_##name.react) \ + rv_##name.react(format_react_msg(curr_state, event)); \ + \ + trace_error_##name(pid, curr_state, event); \ + \ + return false; \ +} + +/* +* Functions to define, init and get a global monitor. +*/ +#define DECLARE_DA_MON_INIT_GLOBAL (name, type) \ + \ +static struct da_monitor da_mon_##name; \ + \ +struct da_monitor *da_get_monitor_##name(void) \ +{ \ + return &da_mon_##name; \ +} \ + \ +void da_monitor_reset_all_##name(void) \ +{ \ + da_monitor_reset_##name(da_mon_##name); \ +} \ + \ +static inline void da_monitor_init_##name(void) \ +{ \ + struct da_monitor *da_mon = &da_mon_##name \ + da_mon->curr_state = model_get_init_state_##name(); \ + da_mon->monitoring = 0; \ + da_mon->model = model_get_model_##name(); \ +} \ + +/* +* Functions to define, init and get a per-cpu monitor. +* +* XXX: Make it dynamic. +*/ +#define DECLARE_DA_MON_INIT_PER_CPU (name, type) \ + \ +DEFINE_PER_CPU(struct da_monitor, da_mon_##name); \ + \ +struct da_monitor *da_get_monitor_##name(void) \ +{ \ + return this_cpu_ptr(&da_mon_##name); \ +} \ + \ +void da_monitor_reset_all_##name(void) \ +{ \ + struct da_monitor *da_mon; \ + int cpu; \ + for_each_cpu(cpu, cpu_online_mask) { \ + da_mon = per_cpu_ptr(&da_mon_##name, cpu); \ + da_monitor_reset_##name(da_mon); \ + } \ +} \ + \ +static inline void da_monitor_init_##name(void) \ +{ \ + struct da_monitor *da_mon; \ + int cpu; \ + for_each_cpu(cpu, cpu_online_mask) { \ + da_mon = per_cpu_ptr(&da_mon_##name, cpu); \ + da_mon->curr_state = model_get_init_state_##name(); \ + da_mon->monitoring = 0; \ + da_mon->model = model_get_model_##name(); \ + } \ +} \ + + +/* +* Functions to define, init and get a per-task monitor. +* +* XXX: Make it dynamic using a list in task_struct (peterz) +*/ +#define DECLARE_DA_MON_INIT_PER_TASK (name, type) \ + \ +struct da_monitor da_mon_##name[MAX_PID]; \ + \ +static inline struct da_monitor *da_get_monitor_##name(pid_t pid) \ +{ \ + return &da_mon_##name[pid]; \ +} \ + \ +void da_monitor_reset_all_##name(void) \ +{ \ + struct da_monitor *mon = da_mon_##name; \ + int i; \ + for (i = 0; i < MAX_PID; i++) \ + da_monitor_reset_##name(&mon[i]); \ +} \ + \ +static void da_monitor_init_##name(void) \ +{ \ + struct da_monitor *mon = da_mon_##name; \ + int i; \ + \ + for (i = 0; i < MAX_PID; i++) { \ + mon[i].curr_state = model_get_init_state_##name(); \ + mon[i].monitoring = 0; \ + mon[i].model = model_get_model_##name(); \ + } \ +} \ + +/* +* Handle event for implicit monitor: da_get_monitor_##name() will figure out +* the monitor. +*/ +#define DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT (name, type) \ + \ +static inline void __da_handle_event_##name(struct da_monitor *da_mon, \ + enum events_##name event) \ +{ \ + int retval; \ + \ + if (unlikely(!monitoring_on)) \ + return; \ + \ + if (unlikely(!rv_##name.enabled)) \ + return; \ + \ + if (unlikely(!da_monitoring_##name(da_mon))) \ + return; \ + \ + retval = da_event_##name(da_mon, event); \ + \ + if (!retval) \ + da_monitor_reset_##name(da_mon); \ +} \ + \ +static inline void da_handle_event_##name(enum events_##name event) \ +{ \ + struct da_monitor *da_mon = da_get_monitor_##name(); \ + __da_handle_event_##name(da_mon, event); \ +} \ + \ +static inline bool da_handle_init_event_##name(enum events_##name event) \ +{ \ + struct da_monitor *da_mon; \ + \ + if (unlikely(!rv_##name.enabled)) \ + return false; \ + \ + da_mon = da_get_monitor_##name(); \ + \ + if (unlikely(!da_monitoring_##name(da_mon))) { \ + da_monitor_start_##name(da_mon); \ + return false; \ + } \ + \ + __da_handle_event_##name(da_mon, event); \ + \ + return true; \ +} \ + \ +static inline bool da_handle_init_run_event_##name(enum events_##name event) \ +{ \ + struct da_monitor *da_mon; \ + \ + if (unlikely(!rv_##name.enabled)) \ + return false; \ + \ + da_mon = da_get_monitor_##name(); \ + \ + if (unlikely(!da_monitoring_##name(da_mon))) \ + da_monitor_start_##name(da_mon); \ + \ + __da_handle_event_##name(da_mon, event); \ + \ + return true; \ +} + +/* +* Handle event for per task. +*/ +#define DECLARE_DA_MON_MONITOR_HANDLER_PER_TASK (name, type) \ + \ +static inline void \ +__da_handle_event_##name(struct da_monitor *da_mon, pid_t pid, \ + enum events_##name event) \ +{ \ + int retval; \ + \ + if (unlikely(!monitoring_on)) \ + return; \ + \ + if (unlikely(!rv_##name.enabled)) \ + return; \ + \ + if (unlikely(!da_monitoring_##name(da_mon))) \ + return; \ + \ + retval = da_event_##name(da_mon, pid, event); \ + \ + if (!retval) \ + da_monitor_reset_##name(da_mon); \ +} \ + \ +static inline void \ +da_handle_event_##name(pid_t pid, enum events_##name event) \ +{ \ + struct da_monitor *da_mon = da_get_monitor_##name(pid); \ + __da_handle_event_##name(da_mon, pid, event); \ +} \ + \ +static inline bool \ +da_handle_init_event_##name(pid_t pid, enum events_##name event) \ +{ \ + struct da_monitor *da_mon; \ + \ + if (unlikely(!rv_##name.enabled)) \ + return false; \ + \ + da_mon = da_get_monitor_##name(pid); \ + \ + if (unlikely(!da_monitoring_##name(da_mon))) { \ + da_monitor_start_##name(da_mon); \ + return false; \ + } \ + \ + __da_handle_event_##name(da_mon, pid, event); \ + \ + return true; \ +} + +/* +* Entry point for the global monitor. +*/ +#define DECLARE_DA_MON_GLOBAL (name, type) \ + \ +DECLARE_AUTOMATA_HELPERS(name, type); \ + \ +DECLARE_DA_MON_GENERIC_HELPERS(name, type); \ + \ +DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type); \ + \ +DECLARE_DA_MON_INIT_PER_CPU(name, type); \ + \ +DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type); + +/* +* Entry point for the per-cpu monitor. +*/ +#define DECLARE_DA_MON_PER_CPU (name, type) \ + \ +DECLARE_AUTOMATA_HELPERS(name, type); \ + \ +DECLARE_DA_MON_GENERIC_HELPERS(name, type); \ + \ +DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type); \ + \ +DECLARE_DA_MON_INIT_PER_CPU(name, type); \ + \ +DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type); + +/* +* Entry point for the per-task monitor. +*/ +#define DECLARE_DA_MON_PER_TASK (name, type) \ + \ +DECLARE_AUTOMATA_HELPERS(name, type); \ + \ +DECLARE_DA_MON_GENERIC_HELPERS(name, type); \ + \ +DECLARE_DA_MON_MODEL_HANDLER_PER_TASK(name, type); \ + \ +DECLARE_DA_MON_INIT_PER_TASK(name, type); \ + \ +DECLARE_DA_MON_MONITOR_HANDLER_PER_TASK(name, type);
Signature · 1 line
2.33.1
RFC v2 5/21 rv/include: Add tracing helper functions
In reply to Daniel Bristot de OliveiraTracing helper functions to facilitate the instrumentation of auto-generated RV monitors create by dot2k.
--- include/rv/trace_helpers.h | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 include/rv/trace_helpers.h
include/rv/trace_helpers.h new file +69 -0
@@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Helper functions to facilitate the instrumentation of auto-generated +* RV monitors create by dot2k. +* +* The dot2k tool is available at tools/tracing/rv/dot2/ +* +* Copyright (C) 2019-2022 Daniel Bristot de Oliveira <[email protected]> +*/ + +#include <linux/ftrace.h> + +struct tracepoint_hook_helper { +struct tracepoint *tp; +void *probe; +int registered; +char *name; +}; + +static inline void thh_compare_name (struct tracepoint *tp,void *priv) +{ +struct tracepoint_hook_helper *thh = priv; + +if (!strcmp (thh->name, tp->name)) + thh->tp = tp; +} + +static inline bool thh_fill_struct_tracepoint (struct tracepoint_hook_helper *thh) +{ +for_each_kernel_tracepoint (thh_compare_name, thh); + +return !!thh->tp; +} + +static inline void thh_unhook_probes (struct tracepoint_hook_helper *thh,int helpers_count) +{ +int i; + +for (i =0 ; i < helpers_count; i++) { +if (!thh[i].registered) +continue ; + +tracepoint_probe_unregister (thh[i].tp, thh[i].probe,NULL ); + } +} + +static inline int thh_hook_probes (struct tracepoint_hook_helper *thh,int helpers_count) +{ +int retval; +int i; + +for (i =0 ; i < helpers_count; i++) { + retval =thh_fill_struct_tracepoint (&thh[i]); +if (!retval) + goto out_err; + + retval =tracepoint_probe_register (thh[i].tp, thh[i].probe,NULL ); + +if (retval) + goto out_err; + + thh[i].registered =1 ; + } +return 0 ; + +out_err: +thh_unhook_probes (thh, helpers_count); +return -EINVAL ; +}
Signature · 1 line
2.33.1
RFC v2 6/21 tools/rv: Add dot2c
In reply to Daniel Bristot de Oliveiradot2c is a tool that transforms an automata in the graphiviz .dot file into an C representation of the automata.
usage: dot2c [-h] dot_file
dot2c: converts a .dot file into a C structure
positional arguments:
dot_file The dot file to be converted
optional arguments:
-h, --help show this help message and exit
--- tools/tracing/rv/dot2/Makefile | 21 +++ tools/tracing/rv/dot2/automata.py | 179 ++++++++++++++++++++++ tools/tracing/rv/dot2/dot2c | 30 ++++ tools/tracing/rv/dot2/dot2c.py | 240 ++++++++++++++++++++++++++++++ 4 files changed, 470 insertions(+) create mode 100644 tools/tracing/rv/dot2/Makefile create mode 100644 tools/tracing/rv/dot2/automata.py create mode 100644 tools/tracing/rv/dot2/dot2c create mode 100644 tools/tracing/rv/dot2/dot2c.py
tools/tracing/rv/dot2/Makefile new file +21 -0
@@ -0,0 +1,21 @@ +INSTALL=install + +prefix ?= /usr +bindir ?= $(prefix)/bin +mandir ?= $(prefix)/share/man +miscdir ?= $(prefix)/share/dot2 +srcdir ?= $(prefix)/src + +PYLIB ?= $(shell python3 -c 'import distutils.sysconfig; print (distutils.sysconfig.get_python_lib())') + +.PHONY: all +all: + +.PHONY: clean +clean: + +.PHONY: install +install: + $(INSTALL) automata.py -D -m 644 $(DESTDIR)$(PYLIB)/dot2/automata.py + $(INSTALL) dot2c.py -D -m 644 $(DESTDIR)$(PYLIB)/dot2/dot2c.py + $(INSTALL) dot2c -D -m 755 $(DESTDIR)$(bindir)/
tools/tracing/rv/dot2/automata.py new file +179 -0
179 lines not on this page · raw message
tools/tracing/rv/dot2/dot2c new file +30 -0
@@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +# +# dot2m: transform dot files into C structures. +# For more information, see: +# https://bristot.me/efficient-formal-verification-for-the-linux-kernel/ +# +# This program was written in the development of this paper: +# de Oliveira, D. B. and Cucinotta, T. and de Oliveira, R. S. +# "Efficient Formal Verification for the Linux Kernel." International +# Conference on Software Engineering and Formal Methods. Springer, Cham, 2019. +# +# Copyright 2018-2020 Red Hat, Inc. +# +# Author: +# Daniel Bristot de Oliveira <[email protected]> + +if __name__ == '__main__': + from dot2 import dot2c + import argparse + import ntpath + import sys + + parser = argparse.ArgumentParser(description='dot2c: converts a .dot file into a C structure') + parser.add_argument('dot_file', help='The dot file to be converted') + + + args = parser.parse_args() + d=dot2c.Dot2c(args.dot_file) + d.print_model_classic()
tools/tracing/rv/dot2/dot2c.py new file +240 -0
240 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC v2 7/21 tools/rv: Add dot2k
In reply to Daniel Bristot de Oliveiratransform .dot file into kernel rv monitor
usage: dot2k [-h] -d DOT_FILE -t MONITOR_TYPE [-n MODEL_NAME] [-D DESCRIPTION]
optional arguments:
-h, --help show this help message and exit
-d DOT_FILE, --dot DOT_FILE
-t MONITOR_TYPE, --monitor_type MONITOR_TYPE
-n MODEL_NAME, --model_name MODEL_NAME
-D DESCRIPTION, --description DESCRIPTION
--- tools/tracing/rv/dot2/Makefile | 5 + tools/tracing/rv/dot2/dot2k | 46 +++++ tools/tracing/rv/dot2/dot2k.py | 184 ++++++++++++++++++ .../rv/dot2/dot2k_templates/main_global.c | 96 +++++++++ .../rv/dot2/dot2k_templates/main_global.h | 64 ++++++ .../rv/dot2/dot2k_templates/main_per_cpu.c | 96 +++++++++ .../rv/dot2/dot2k_templates/main_per_cpu.h | 64 ++++++ .../rv/dot2/dot2k_templates/main_per_task.c | 96 +++++++++ .../rv/dot2/dot2k_templates/main_per_task.h | 70 +++++++ 9 files changed, 721 insertions(+) create mode 100644 tools/tracing/rv/dot2/dot2k create mode 100644 tools/tracing/rv/dot2/dot2k.py create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_global.c create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_global.h create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_cpu.c create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_cpu.h create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_task.c create mode 100644 tools/tracing/rv/dot2/dot2k_templates/main_per_task.h
tools/tracing/rv/dot2/Makefile +5 -0
@@ -19,3 +19,8 @@ install: $(INSTALL) automata.py -D -m 644 $(DESTDIR)$(PYLIB)/dot2/automata.py $(INSTALL) dot2c.py -D -m 644 $(DESTDIR)$(PYLIB)/dot2/dot2c.py $(INSTALL) dot2c -D -m 755 $(DESTDIR)$(bindir)/ + $(INSTALL) dot2k.py -D -m 644 $(DESTDIR)$(PYLIB)/dot2/dot2k.py + $(INSTALL) dot2k -D -m 755 $(DESTDIR)$(bindir)/ + + mkdir -p ${miscdir}/ + cp -rp dot2k_templates $(DESTDIR)$(miscdir)/
tools/tracing/rv/dot2/dot2k new file +46 -0
46 lines not on this page · raw message
tools/tracing/rv/dot2/dot2k.py new file +184 -0
184 lines not on this page · raw message
tools/tracing/rv/dot2/dot2k_templates/main_global.c new file +96 -0
96 lines not on this page · raw message
tools/tracing/rv/dot2/dot2k_templates/main_global.h new file +64 -0
64 lines not on this page · raw message
tools/tracing/rv/dot2/dot2k_templates/main_per_cpu.c new file +96 -0
96 lines not on this page · raw message
tools/tracing/rv/dot2/dot2k_templates/main_per_cpu.h new file +64 -0
64 lines not on this page · raw message
tools/tracing/rv/dot2/dot2k_templates/main_per_task.c new file +96 -0
96 lines not on this page · raw message
tools/tracing/rv/dot2/dot2k_templates/main_per_task.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC v2 8/21 rv/monitor: Add the wip monitor skeleton created by dot2k
In reply to Daniel Bristot de OliveiraThis is the direct output this command line:
$ dot2k -d ~/wip.dot -t per_cpu
with wip.dot as:
----- %< -----
digraph state_automaton {
center = true;
size = "7,11";
rankdir = LR;
{node [shape = circle] "non_preemptive"};
{node [shape = plaintext, style=invis, label=""] "__init_preemptive"};
{node [shape = doublecircle] "preemptive"};
{node [shape = circle] "preemptive"};
"__init_preemptive" -> "preemptive";
"non_preemptive" [label = "non_preemptive"];
"non_preemptive" -> "non_preemptive" [ label = "sched_waking" ];
"non_preemptive" -> "preemptive" [ label = "preempt_enable" ];
"preemptive" [label = "preemptive"];
"preemptive" -> "non_preemptive" [ label = "preempt_disable" ];
{ rank = min ;
"__init_preemptive";
"preemptive";
}
}----- >% -----
This model is broken because preempt_disable_notrace(). It is broken on purpose to test the reactors.
It does not compile because it lacks the instrumentation, which will be add next.
--- kernel/trace/rv/monitor_wip/model.h | 38 +++++++++ kernel/trace/rv/monitor_wip/wip.c | 124 ++++++++++++++++++++++++++++ kernel/trace/rv/monitor_wip/wip.h | 64 ++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 kernel/trace/rv/monitor_wip/model.h create mode 100644 kernel/trace/rv/monitor_wip/wip.c create mode 100644 kernel/trace/rv/monitor_wip/wip.h
kernel/trace/rv/monitor_wip/model.h new file +38 -0
@@ -0,0 +1,38 @@ +enum states_wip { + preemptive =0 , + non_preemptive, + state_max +}; + +enum events_wip { + preempt_disable =0 , + preempt_enable, + sched_waking, + event_max +}; + +struct automaton_wip { +char *state_names[state_max]; +char *event_names[event_max]; +char function[state_max][event_max]; +char initial_state; +char final_states[state_max]; +}; + +struct automaton_wip automaton_wip = { + .state_names = { +"preemptive" , +"non_preemptive" + }, + .event_names = { +"preempt_disable" , +"preempt_enable" , +"sched_waking" + }, + .function = { + { non_preemptive,-1 ,-1 }, + {-1 , preemptive, non_preemptive }, + }, + .initial_state = preemptive, + .final_states = {1 ,0 }, +};
kernel/trace/rv/monitor_wip/wip.c new file +124 -0
124 lines not on this page · raw message
kernel/trace/rv/monitor_wip/wip.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC v2 9/21 rv/monitor: wip instrumentation and Makefile/Kconfig entries
In reply to Daniel Bristot de OliveiraAdds the instrumentation to the previously created wip monitor, as an example of the developer work. It also adds a Makefile and Kconfig entries.
This is a good example of the manual work that is left for the developer to do.
--- kernel/trace/rv/Kconfig | 7 +++++++ kernel/trace/rv/Makefile | 1 + kernel/trace/rv/monitor_wip/wip.c | 16 ++++++++-------- kernel/trace/rv/monitor_wip/wip.h | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-)
kernel/trace/rv/Kconfig +7 -0
@@ -13,6 +13,13 @@ menuconfig RV if RV +config RV_MON_WIP + depends on PREEMPTIRQ_TRACEPOINTS + tristate "WIP monitor" + help + Enable WIP sample monitor, this is a sample monitor that + illustrates the usage of per-cpu monitors. + config RV_REACTORS bool "Runtime verification reactors" default y if RV
kernel/trace/rv/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_RV) += rv.o obj-$(CONFIG_RV_REACTORS) += rv_reactors.o +obj-$(CONFIG_RV_MON_WIP) += monitor_wip/wip.o
kernel/trace/rv/monitor_wip/wip.c +8 -8
@@ -33,36 +33,36 @@ DECLARE_DA_MON_PER_CPU(wip, char);* */ -void handle_preempt_disable(void *data, /* XXX: fill header */) +void handle_preempt_disable (void *data,unsigned long ip,unsigned long parent_ip) {da_handle_event_wip (preempt_disable); } -void handle_preempt_enable(void *data, /* XXX: fill header */) +void handle_preempt_enable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_wip (preempt_enable); +da_handle_init_event_wip (preempt_enable); } -void handle_sched_waking(void *data, /* XXX: fill header */) +void handle_sched_waking (void *data,struct task_struct *task) {da_handle_event_wip (sched_waking); } -#define NR_TP 3 +#define NR_TP 3static struct tracepoint_hook_helper tracepoints_to_hook[NR_TP ] = { { .probe = handle_preempt_disable, - .name = /* XXX: tracepoint name here */, + .name ="preempt_disable" , .registered =0 }, { .probe = handle_preempt_enable, - .name = /* XXX: tracepoint name here */, + .name ="preempt_enable" , .registered =0 }, { .probe = handle_sched_waking, - .name = /* XXX: tracepoint name here */, + .name ="sched_wakeup" , .registered =0 }, };
kernel/trace/rv/monitor_wip/wip.h +1 -1
@@ -59,6 +59,6 @@ TRACE_EVENT(error_wip,/* This part ust be outside protection */ #undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_PATH ../kernel/trace/rv/monitor_wip/ #define TRACE_INCLUDE_FILE wip#include <trace/define_trace.h>
Signature · 1 line
2.33.1
kernel test robot
build botRe: [RFC V2 09/21] rv/monitor: wip instrumentation and Makefile/Kconfig entries
[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]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on rostedt-trace/for-next]
[also build test WARNING on lwn/docs-next linus/master v5.17-rc4 next-20220214] [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]
url: https://github.com/0day-ci/linux/commits/Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next config: hexagon-allyesconfig (https://download.01.org/0day-ci/archive/20220215/202202150429.Rn1Sp6Xo-lkp(a)intel.com/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project ea071884b0cc7210b3cc5fe858f0e892a779a23b)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d19976adc824ba2162ba4c5690e0a2f2aba219a6
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 git checkout d19976adc824ba2162ba4c5690e0a2f2aba219a6
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash kernel/trace/rv/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> kernel/trace/rv/monitor_wip/wip.c:23:1: warning: no previous prototype for function 'model_get_state_name_wip' [-Wmissing-prototypes]
DECLARE_DA_MON_PER_CPU(wip, char);
^
include/rv/da_monitor.h:374:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/automata.h:18:7: note: expanded from macro '\
DECLARE_AUTOMATA_HELPERS'
char *model_get_state_name_##name(enum states_##name state) \
^
<scratch space>:86:1: note: expanded from here
model_get_state_name_wip
^
kernel/trace/rv/monitor_wip/wip.c:23:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/rv/da_monitor.h:374:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/automata.h:17:11: note: expanded from macro '\
DECLARE_AUTOMATA_HELPERS'
\
^
>> kernel/trace/rv/monitor_wip/wip.c:23:1: warning: no previous prototype for function 'model_get_event_name_wip' [-Wmissing-prototypes]
DECLARE_DA_MON_PER_CPU(wip, char);
^
include/rv/da_monitor.h:374:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/automata.h:23:7: note: expanded from macro '\
DECLARE_AUTOMATA_HELPERS'
char *model_get_event_name_##name(enum events_##name event) \
^
<scratch space>:89:1: note: expanded from here
model_get_event_name_wip
^
kernel/trace/rv/monitor_wip/wip.c:23:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/rv/da_monitor.h:374:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/automata.h:22:11: note: expanded from macro '\
DECLARE_AUTOMATA_HELPERS'
\
^
>> kernel/trace/rv/monitor_wip/wip.c:23:1: warning: no previous prototype for function 'da_get_monitor_wip' [-Wmissing-prototypes]
DECLARE_DA_MON_PER_CPU(wip, char);
^
include/rv/da_monitor.h:380:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/da_monitor.h:172:20: note: expanded from macro '\
DECLARE_DA_MON_INIT_PER_CPU'
struct da_monitor *da_get_monitor_##name(void) \
^
<scratch space>:126:1: note: expanded from here
da_get_monitor_wip
^
kernel/trace/rv/monitor_wip/wip.c:23:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/rv/da_monitor.h:380:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/da_monitor.h:171:11: note: expanded from macro '\
DECLARE_DA_MON_INIT_PER_CPU'
\
^
>> kernel/trace/rv/monitor_wip/wip.c:23:1: warning: no previous prototype for function 'da_monitor_reset_all_wip' [-Wmissing-prototypes]
DECLARE_DA_MON_PER_CPU(wip, char);
^
include/rv/da_monitor.h:380:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/da_monitor.h:177:6: note: expanded from macro '\
DECLARE_DA_MON_INIT_PER_CPU'
void da_monitor_reset_all_##name(void) \
^
<scratch space>:128:1: note: expanded from here
da_monitor_reset_all_wip
^
kernel/trace/rv/monitor_wip/wip.c:23:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/rv/da_monitor.h:380:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/da_monitor.h:176:11: note: expanded from macro '\
DECLARE_DA_MON_INIT_PER_CPU'
\
^
>> kernel/trace/rv/monitor_wip/wip.c:36:6: warning: no previous prototype for function 'handle_preempt_disable' [-Wmissing-prototypes]
void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip)
^
kernel/trace/rv/monitor_wip/wip.c:36:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip)
^
static
>> kernel/trace/rv/monitor_wip/wip.c:41:6: warning: no previous prototype for function 'handle_preempt_enable' [-Wmissing-prototypes]
void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip)
^
kernel/trace/rv/monitor_wip/wip.c:41:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip)
^
static
>> kernel/trace/rv/monitor_wip/wip.c:46:6: warning: no previous prototype for function 'handle_sched_waking' [-Wmissing-prototypes]
void handle_sched_waking(void *data, struct task_struct *task)
^
kernel/trace/rv/monitor_wip/wip.c:46:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void handle_sched_waking(void *data, struct task_struct *task)
^
static
>> kernel/trace/rv/monitor_wip/wip.c:105:5: warning: no previous prototype for function 'register_wip' [-Wmissing-prototypes]
int register_wip(void)
^
kernel/trace/rv/monitor_wip/wip.c:105:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int register_wip(void)
^
static
>> kernel/trace/rv/monitor_wip/wip.c:111:6: warning: no previous prototype for function 'unregister_wip' [-Wmissing-prototypes]
void unregister_wip(void)
^
kernel/trace/rv/monitor_wip/wip.c:111:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void unregister_wip(void)
^
static
kernel/trace/rv/monitor_wip/wip.c:23:1: warning: unused function 'da_handle_init_run_event_wip' [-Wunused-function]
DECLARE_DA_MON_PER_CPU(wip, char);
^
include/rv/da_monitor.h:382:11: note: expanded from macro 'DECLARE_DA_MON_PER_CPU'
\
^
include/rv/da_monitor.h:285:20: note: expanded from macro '\
DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT'
static inline bool da_handle_init_run_event_##name(enum events_##name event) \
^ <scratch space>:152:1: note: expanded from here da_handle_init_run_event_wip
^
10 warnings generated.
vim +/model_get_state_name_wip +23 kernel/trace/rv/monitor_wip/wip.c
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 16
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 17 /*
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 18 * Declare the deterministic automata monitor.
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 19 *
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 20 * The rv monitor reference is needed for the monitor declaration.
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 21 */
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 22 struct rv_monitor rv_wip;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 @23 DECLARE_DA_MON_PER_CPU(wip, char);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 24
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 25 #define CREATE_TRACE_POINTS
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 26 #include "wip.h"
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 27
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 28 /*
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 29 * This is the instrumentation part of the monitor.
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 30 *
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 31 * This is the section where manual work is required. Here the kernel events
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 32 * are translated into model's event.
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 33 *
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 34 */
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 35
d19976adc824ba Daniel Bristot de Oliveira 2022-02-14 @36 void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 37 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 38 da_handle_event_wip(preempt_disable);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 39 }
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 40
d19976adc824ba Daniel Bristot de Oliveira 2022-02-14 @41 void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 42 {
d19976adc824ba Daniel Bristot de Oliveira 2022-02-14 43 da_handle_init_event_wip(preempt_enable);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 44 }
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 45
d19976adc824ba Daniel Bristot de Oliveira 2022-02-14 @46 void handle_sched_waking(void *data, struct task_struct *task)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 47 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 48 da_handle_event_wip(sched_waking);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 49 }
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 50
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 51 #define NR_TP 3
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 52 static struct tracepoint_hook_helper tracepoints_to_hook[NR_TP] = {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 53 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 54 .probe = handle_preempt_disable,
d19976adc824ba Daniel Bristot de Oliveira 2022-02-14 55 .name = "preempt_disable",
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 56 .registered = 0
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 57 },
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 58 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 59 .probe = handle_preempt_enable,
d19976adc824ba Daniel Bristot de Oliveira 2022-02-14 60 .name = "preempt_enable",
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 61 .registered = 0
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 62 },
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 63 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 64 .probe = handle_sched_waking,
d19976adc824ba Daniel Bristot de Oliveira 2022-02-14 65 .name = "sched_wakeup",
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 66 .registered = 0
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 67 },
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 68 };
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 69
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 70 static int start_wip(void)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 71 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 72 int retval;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 73
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 74 da_monitor_init_wip();
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 75
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 76 retval = thh_hook_probes(tracepoints_to_hook, NR_TP);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 77 if (retval)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 78 goto out_err;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 79
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 80 return 0;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 81
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 82 out_err:
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 83 return -EINVAL;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 84 }
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 85
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 86 static void stop_wip(void)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 87 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 88 rv_wip.enabled = 0;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 89 thh_unhook_probes(tracepoints_to_hook, NR_TP);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 90 return;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 91 }
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 92
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 93 /*
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 94 * This is the monitor register section.
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 95 */
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 96 struct rv_monitor rv_wip = {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 97 .name = "wip",
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 98 .description = "auto-generated wip",
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 99 .start = start_wip,
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 100 .stop = stop_wip,
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 101 .reset = da_monitor_reset_all_wip,
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 102 .enabled = 0,
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 103 };
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 104
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 @105 int register_wip(void)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 106 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 107 rv_register_monitor(&rv_wip);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 108 return 0;
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 109 }
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 110
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 @111 void unregister_wip(void)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 112 {
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 113 if (rv_wip.enabled)
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 114 stop_wip();
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 115
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 116 rv_unregister_monitor(&rv_wip);
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 117 }
66e3ae1a584a3c Daniel Bristot de Oliveira 2022-02-14 118 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 10/21 rv/monitor: Add the wwnr monitor skeleton created by dot2k
In reply to Daniel Bristot de OliveiraPer task wakeup while not running (wwnr) monitor, generated by dot2k with this command line:
$ dot2k -d wwnr.dot -t per_task
The model is:
----- %< -----
digraph state_automaton {
center = true;
size = "7,11";
{node [shape = plaintext, style=invis, label=""] "__init_not_running"};
{node [shape = ellipse] "not_running"};
{node [shape = plaintext] "not_running"};
{node [shape = plaintext] "running"};
"__init_not_running" -> "not_running";
"not_running" [label = "not_running", color = green3];
"not_running" -> "not_running" [ label = "wakeup" ];
"not_running" -> "running" [ label = "switch_in" ];
"running" [label = "running"];
"running" -> "not_running" [ label = "switch_out" ];
{ rank = min ;
"__init_not_running";
"not_running";
}
}----- >% -----
This model is broken, the reason is that a task can be running in the processor without being set as RUNNABLE. Think about a task about to sleep:
1: set_current_state(TASK_UNINTERRUPTIBLE);
2: schedule();
And then imagine an IRQ happening in between the lines one and two, waking the task up. BOOM, the wakeup will happen while the task is running.
Q: Why do we need this model, so?
A: To test the reactors.
--- kernel/trace/rv/monitor_wwnr/model.h | 38 ++++++++ kernel/trace/rv/monitor_wwnr/wwnr.c | 127 +++++++++++++++++++++++++++ kernel/trace/rv/monitor_wwnr/wwnr.h | 70 +++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 kernel/trace/rv/monitor_wwnr/model.h create mode 100644 kernel/trace/rv/monitor_wwnr/wwnr.c create mode 100644 kernel/trace/rv/monitor_wwnr/wwnr.h
kernel/trace/rv/monitor_wwnr/model.h new file +38 -0
@@ -0,0 +1,38 @@ +enum states_wwnr { + not_running =0 , + running, + state_max +}; + +enum events_wwnr { + switch_in =0 , + switch_out, + wakeup, + event_max +}; + +struct automaton_wwnr { +char *state_names[state_max]; +char *event_names[event_max]; +char function[state_max][event_max]; +char initial_state; +char final_states[state_max]; +}; + +struct automaton_wwnr automaton_wwnr = { + .state_names = { +"not_running" , +"running" + }, + .event_names = { +"switch_in" , +"switch_out" , +"wakeup" + }, + .function = { + { running,-1 , not_running }, + {-1 , not_running,-1 }, + }, + .initial_state = not_running, + .final_states = {1 ,0 }, +};
kernel/trace/rv/monitor_wwnr/wwnr.c new file +127 -0
127 lines not on this page · raw message
kernel/trace/rv/monitor_wwnr/wwnr.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC v2 11/21 rv/monitor: wwnr instrumentation and Makefile/Kconfig entries
In reply to Daniel Bristot de OliveiraAdds the instrumentation to the previously created wwnr monitor, as an example of the developer work. It also adds a Makefile and Kconfig entries.
--- kernel/trace/rv/Kconfig | 7 ++++++ kernel/trace/rv/Makefile | 1 + kernel/trace/rv/monitor_wwnr/wwnr.c | 35 +++++++++++++---------------- kernel/trace/rv/monitor_wwnr/wwnr.h | 2 +- 4 files changed, 24 insertions(+), 21 deletions(-)
kernel/trace/rv/Kconfig +7 -0
@@ -20,6 +20,13 @@ config RV_MON_WIP Enable WIP sample monitor, this is a sample monitor that illustrates the usage of per-cpu monitors. +config RV_MON_WWNR + tristate "WWNR monitor" + help + Enable WWNR sample monitor, this is a sample monitor that + illustrates the usage of per-task monitor. The model is + broken on purpose: it serves to test reactors. + config RV_REACTORS bool "Runtime verification reactors" default y if RV
kernel/trace/rv/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_RV) += rv.o obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_MON_WIP) += monitor_wip/wip.o +obj-$(CONFIG_RV_MON_WWNR) += monitor_wwnr/wwnr.o
kernel/trace/rv/monitor_wwnr/wwnr.c +15 -20
@@ -33,39 +33,34 @@ DECLARE_DA_MON_PER_TASK(wwnr, char);* */ -void handle_switch_in(void *data, /* XXX: fill header */) +static void handle_switch (void *data,bool preempt,struct task_struct *p,struct task_struct *n) { - pid_t pid = /* XXX how do I get the pid? */; -da_handle_event_wwnr (pid, switch_in); -} +int ppid = p->pid; +int npid = n->pid; -void handle_switch_out(void *data, /* XXX: fill header */) -{ - pid_t pid = /* XXX how do I get the pid? */; -da_handle_event_wwnr (pid, switch_out); +if (ppid && ppid <MAX_PID ) +da_handle_init_event_wwnr (ppid, switch_out); + +if (npid && npid <MAX_PID ) +da_handle_event_wwnr (npid, switch_in); } -void handle_wakeup(void *data, /* XXX: fill header */) +static void handle_wakeup (void *data,struct task_struct *p) { - pid_t pid = /* XXX how do I get the pid? */; -da_handle_event_wwnr (pid, wakeup); +if (p->pid && p->pid <MAX_PID ) +da_handle_event_wwnr (p->pid, wakeup); } -#define NR_TP 3 +#define NR_TP 2static struct tracepoint_hook_helper tracepoints_to_hook[NR_TP ] = { { - .probe = handle_switch_in, - .name = /* XXX: tracepoint name here */, - .registered =0 - }, - { - .probe = handle_switch_out, - .name = /* XXX: tracepoint name here */, + .probe = handle_switch, + .name ="sched_switch" , .registered =0 }, { .probe = handle_wakeup, - .name = /* XXX: tracepoint name here */, + .name ="sched_wakeup" , .registered =0 }, };
kernel/trace/rv/monitor_wwnr/wwnr.h +1 -1
@@ -65,6 +65,6 @@ TRACE_EVENT(error_wwnr,/* This part ust be outside protection */ #undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_PATH ../kernel/trace/rv/monitor_wwnr/ #define TRACE_INCLUDE_FILE wwnr#include <trace/define_trace.h>
Signature · 1 line
2.33.1
RFC v2 12/21 rv/reactor: Add the printk reactor
In reply to Daniel Bristot de OliveiraSample reactor that printks the reaction message.
Note: do not use this reactor with rq_lock taken, it will lock the system until printk can handle that.
--- kernel/trace/rv/Kconfig | 8 ++++++ kernel/trace/rv/Makefile | 3 ++- kernel/trace/rv/reactor_printk.c | 43 ++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 kernel/trace/rv/reactor_printk.c
kernel/trace/rv/Kconfig +8 -0
@@ -37,4 +37,12 @@ config RV_REACTORS tracing reactions, printing the monitor output via tracepoints, but other reactions can be added (on-demand) via this interface. +config RV_REACT_PRINTK + tristate "Printk reactor" + depends on RV_REACTORS + default y if RV_REACTORS + help + Enables the printk reactor. The printk reactor emmits a printk() + message if an exception is found. + endif # RV
kernel/trace/rv/Makefile +2 -1
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_RV) += rv.o -obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_MON_WIP) += monitor_wip/wip.o obj-$(CONFIG_RV_MON_WWNR) += monitor_wwnr/wwnr.o +obj-$(CONFIG_RV_REACTORS) += rv_reactors.o +obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
kernel/trace/rv/reactor_printk.c new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.33.1
Shuah Khan
reviewerRe: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 2 lines · Daniel Bristot de Oliveira
Sample reactor that printks the reaction message.
Who is supposed to take action on this message and how do they get notified?
Quoted 2 lines
Note: do not use this reactor with
rq_locktaken, it will lock the system until printk can handle that.
Please give more details on "lock the system" and how locking would impact users and system operation
Quoted 106 lines
Cc Jonathan Corbet <[email protected]>Cc Steven Rostedt <[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]>Signed-off-by Daniel Bristot de Oliveira <[email protected]>--- kernel/trace/rv/Kconfig | 8 ++++++ kernel/trace/rv/Makefile | 3 ++- kernel/trace/rv/reactor_printk.c | 43 ++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-)create mode 100644
kernel/trace/rv/reactor_printk.ckernel/trace/rv/Kconfig +8
-0@@ -37,4 +37,12 @@ config RV_REACTORS tracing reactions, printing the monitor output via tracepoints, but other reactions can be added (on-demand) via this interface. +config RV_REACT_PRINTK + tristate "Printk reactor" + depends on RV_REACTORS + default y if RV_REACTORS + help + Enables the printk reactor. The printk reactor emmits a printk() + message if an exception is found. + endif # RVkernel/trace/rv/Makefile +2
-1@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_RV) += rv.o -obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_MON_WIP) += monitor_wip/wip.o obj-$(CONFIG_RV_MON_WWNR) += monitor_wwnr/wwnr.o +obj-$(CONFIG_RV_REACTORS) += rv_reactors.o +obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.okernel/trace/rv/reactor_printk.c new file +43
-0@@ -0,0 +1,43 @@ +/* +* Printk RV reactor: +* Prints the exception msg to the kernel message log. +* +* Copyright (C) 2019-2022 Daniel Bristot de Oliveira <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0 +*/ +#include <linux/ftrace.h> +#include <linux/tracepoint.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/rv.h> + +static void rv_printk_reaction (char *msg) +{ +printk (msg); +} + +struct rv_reactor rv_printk = { + .name ="printk" , + .description ="prints the exception msg to the kernel message log" , + .react = rv_printk_reaction +}; + +int register_react_printk (void ) +{ +rv_register_reactor (&rv_printk); +return 0 ; +} + +void unregister_react_printk (void ) +{ +rv_unregister_reactor (&rv_printk); +} + +module_init (register_react_printk); +module_exit (unregister_react_printk); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Daniel Bristot de Oliveira" ); +MODULE_DESCRIPTION ("printk rv reactor: printk if an exception is hit" );
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 6 lines · Shuah Khan
Quoted 2 lines · Daniel Bristot de Oliveira
Sample reactor that printks the reaction message.
Who is supposed to take action on this message and how do they get notified?
The same people that use printk to debug systems (who never?), on conditions where other debugging methods might not available.
Quoted 6 lines
Quoted 3 lines
Note: do not use this reactor with rq_lock taken, it will lock the system until printk can handle that.
Please give more details on "lock the system" and how locking would impact users and system operation
It is a deadlock on the rq_lock. Hopefully the new printk implementation handles that better.
/me looks at John Ogness
-- Daniel
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 10 lines · Daniel Bristot de Oliveira
Quoted 6 lines · Shuah Khan
Quoted 2 lines · Daniel Bristot de Oliveira
Note: do not use this reactor with rq_lock taken, it will lock the system until printk can handle that.
Please give more details on "lock the system" and how locking would impact users and system operation
It is a deadlock on the
rq_lock. Hopefully the new printk implementation handles that better.
I suggest using printk_deferred() for this reactor for now. With printk_deferred() the message and timestamp are immediately and locklessly stored in the buffer, and the printing is performed in a separate context. printk_deferred() is safe for all contexts.
John
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 9 lines · John Ogness
Quoted 8 lines · Daniel Bristot de Oliveira
Quoted 6 lines · Shuah Khan
Quoted 2 lines · Daniel Bristot de Oliveira
Note: do not use this reactor with rq_lock taken, it will lock the system until printk can handle that.
Please give more details on "lock the system" and how locking would impact users and system operation
Quoted 7 lines
Quoted 2 lines
It is a deadlock on the
rq_lock. Hopefully the new printk implementation handles that better.I suggest using
printk_deferred()for this reactor for now. Withprintk_deferred()the message and timestamp are immediately and locklessly stored in the buffer, and the printing is performed in a separate context.printk_deferred()is safe for all contexts.
Question: Does it always postpone or only postpone when in a particular contexts, like, with irqs disabled?
-- Daniel
Quoted 1 line
John
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 7 lines · Daniel Bristot de Oliveira
Quoted 4 lines
I suggest using
printk_deferred()for this reactor for now. Withprintk_deferred()the message and timestamp are immediately and locklessly stored in the buffer, and the printing is performed in a separate context.printk_deferred()is safe for all contexts.Question: Does it always postpone or only postpone when in a particular contexts, like, with irqs disabled?
printk_deferred() always postpones printing.
Quoted 2 lines
Note: do not use this reactor with
rq_locktaken, it will lock the system until printk can handle that.
Perhaps you could explain thi comment in your commit message? printk() should never lock the system.
John
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 8 lines · John Ogness
Quoted 6 lines · Daniel Bristot de Oliveira
Quoted 4 lines
I suggest using
printk_deferred()for this reactor for now. Withprintk_deferred()the message and timestamp are immediately and locklessly stored in the buffer, and the printing is performed in a separate context.printk_deferred()is safe for all contexts.Question: Does it always postpone or only postpone when in a particular contexts, like, with irqs disabled?
printk_deferred()always postpones printing.
That is why printk() seems to be the better option, though I can use the deferred option too.
Noting that, I am aware of printk_deferred(), and every once and while I am Cc'ed on patches suggesting changing printk() to printk_deferred(), but they are not, let's say, welcome [1]... that is why I am not using it.
Quoted 4 lines
Quoted 2 lines
Note: do not use this reactor with
rq_locktaken, it will lock the system until printk can handle that.Perhaps you could explain thi comment in your commit message?
printk()should never lock the system.
I saw deadlocks in the past, and while testing the WIP monitor some time ago, it seems it depends on the console type. If such restriction does not exist anymore, I can remove that comment, it would be even better!
-- Daniel
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 3 lines · Daniel Bristot de Oliveira
I am aware of
printk_deferred(), and every once and while I am Cc'ed on patches suggesting changingprintk()toprintk_deferred(), but they are not, let's say, welcome [1]... that is why I am not using it.
Yes. printk_deferred() is a workaround until we can get printk "PROVE_RAW_LOCK_NESTING clean". But currently there is real deadlock potential in the kernel with printk. For the most common cases, we use printk_deferred() to get around it. Once printk() is clean, we can replace all printk_deferred() call sites with printk().
I haven't looked into the details of your runtime verification method, but I assume it digs deep into some interfaces. In that case, the deadlock potential of printk may be relatively high. (And indeed, you have seen some.) IMHO, before warning users not to use this reactor if locks XYZ are taken, it would be better just to use printk_deferred() and it will always log without causing problems to the system you are trying to verify.
Quoted 4 lines
I saw deadlocks in the past, and while testing the WIP monitor some time ago, it seems it depends on the console type. If such restriction does not exist anymore, I can remove that comment, it would be even better!
If you say it depended on the console type, then it was probably the framebuffer console that was at fault. The fbcon is a landmine for deadlocks, which is why PREEMPT_RT avoids fbcon printing from non-preemptible context. For mainline, the series is currently in review.
Perhaps avoiding fbcon would be good enough for you to avoid deadlocks with this reactor using printk().
John
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 4 lines · John Ogness
Quoted 4 lines
I saw deadlocks in the past, and while testing the WIP monitor some time ago, it seems it depends on the console type. If such restriction does not exist anymore, I can remove that comment, it would be even better!
Quoted 8 lines
If you say it depended on the console type, then it was probably the framebuffer console that was at fault. The fbcon is a landmine for deadlocks, which is why
PREEMPT_RTavoids fbcon printing from non-preemptible context. For mainline, the series is currently in review.Perhaps avoiding fbcon would be good enough for you to avoid deadlocks with this reactor using
printk().
So, I will keep printk(), add a depends on *!* fbcon, and remove the comment. What do you think?
-- Daniel
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 2 lines · Daniel Bristot de Oliveira
So, I will keep
printk(), add a depends on *!* fbcon, and remove the comment. What do you think?
printk() and depends on !VT_CONSOLE. OK for me. Hopefully soon this restriction can be removed.
John
Re: [RFC V2 12/21] rv/reactor: Add the printk reactor
Quoted 5 lines · John Ogness
Quoted 2 lines · Daniel Bristot de Oliveira
So, I will keep
printk(), add a depends on *!* fbcon, and remove the comment. What do you think?
printk()and depends on !VT_CONSOLE. OK for me. Hopefully soon this restriction can be removed.
ack.
Thanks, John!
-- Daniel
Quoted 1 line
John
RFC v2 13/21 rv/reactor: Add the panic reactor
In reply to Daniel Bristot de OliveiraSample reactor that panics the system when an exception is found. This is useful both to capture a vmcore, or to fail-safe a critical system.
--- kernel/trace/rv/Kconfig | 8 ++++++ kernel/trace/rv/Makefile | 1 + kernel/trace/rv/reactor_panic.c | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 kernel/trace/rv/reactor_panic.c
kernel/trace/rv/Kconfig +8 -0
@@ -45,4 +45,12 @@ config RV_REACT_PRINTK Enables the printk reactor. The printk reactor emmits a printk() message if an exception is found. +config RV_REACT_PANIC + tristate "Panic reactor" + depends on RV_REACTORS + default y if RV_REACTORS + help + Enables the panic reactor. The panic reactor emmits a printk() + message if an exception is found and panic()s the system. + endif # RV
kernel/trace/rv/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_RV_MON_WIP) += monitor_wip/wip.o obj-$(CONFIG_RV_MON_WWNR) += monitor_wwnr/wwnr.o obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o +obj-$(CONFIG_RV_REACT_PANIC) += reactor_panic.o
kernel/trace/rv/reactor_panic.c new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC v2 14/21 Documentation/rv: Add a basic documentation
In reply to Daniel Bristot de OliveiraAdd the runtime-verification.rst document, explaining the basics of RV and how to use the interface.
--- Documentation/trace/index.rst | 1 + Documentation/trace/rv/index.rst | 9 + .../trace/rv/runtime-verification.rst | 233 ++++++++++++++++++ kernel/trace/rv/Kconfig | 3 + 4 files changed, 246 insertions(+) create mode 100644 Documentation/trace/rv/index.rst create mode 100644 Documentation/trace/rv/runtime-verification.rst
Documentation/trace/index.rst +1 -0
@@ -30,3 +30,4 @@ Linux Tracing Technologies stm sys-t coresight/index + rv/index
Documentation/trace/rv/index.rst new file +9 -0
@@ -0,0 +1,9 @@ +=================================== +RV - Runtime Verification Interface +=================================== + +.. toctree:: + :maxdepth: 2 + :glob: + + *
Documentation/trace/rv/runtime-verification.rst new file +233 -0
233 lines not on this page · raw message
kernel/trace/rv/Kconfig +3 -0
@@ -11,6 +11,9 @@ menuconfig RV actual execution, comparing it against a formal specification of the system behavior. + For further information, see: + Documentation/trace/rv/runtime-verification.rst + if RV config RV_MON_WIP
Signature · 1 line
2.33.1
RFC v2 15/21 Documentation/rv: Add deterministic automata monitor synthesis documentation
In reply to Daniel Bristot de OliveiraAdd the da_monitor_synthesis.rst introduces some concepts behind the Deterministic Automata (DA) monitor synthesis and interface.
--- .../trace/rv/da_monitor_synthesis.rst | 286 ++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 Documentation/trace/rv/da_monitor_synthesis.rst
Documentation/trace/rv/da_monitor_synthesis.rst new file +286 -0
@@ -0,0 +1,286 @@ +Deterministic Automata Monitor Synthesis +======================================== + +The starting point for the application of runtime verification (RV) technics is +the *specification* or *modeling* of the desired (or undesired) behavior of the +system under scrutiny. + +The formal representation needs to be then *synthesized* into a *monitor* that +can then be used in the analysis of the trace of the system. The *monitor* +conects to the system via an *instrumentation* layer, that converts the events +from the *system* to the events of the *specification*. + +This document introduces some concepts behind the **Deterministic Automata +(DA)** monitor synthesis. + +DA monitor synthesis in a nutshell +------------------------------------------------------ + +The synthesis of automata-based models into the Linux *RV monitor* abstraction +is automatized by a tool named "dot2k", and the "rv/da_monitor.h" provided +by the RV interface. + +Given a file "wip.dot", representing a per-cpu monitor, with this content:: + + digraph state_automaton { + center = true; + size = "7,11"; + rankdir = LR; + {node [shape = circle] "non_preemptive"}; + {node [shape = plaintext, style=invis, label=""] "__init_preemptive"}; + {node [shape = doublecircle] "preemptive"}; + {node [shape = circle] "preemptive"}; + "__init_preemptive" -> "preemptive"; + "non_preemptive" [label = "non_preemptive"]; + "non_preemptive" -> "non_preemptive" [ label = "sched_waking" ]; + "non_preemptive" -> "preemptive" [ label = "preempt_enable" ]; + "preemptive" [label = "preemptive"]; + "preemptive" -> "non_preemptive" [ label = "preempt_disable" ]; + { rank = min ; + "__init_preemptive"; + "preemptive"; + } + } + +Run the dot2k tool with the model, specifying that it is a "per-cpu" +model:: + + $ dot2k -d ~/wip.dot -t per_cpu + +This will create a directory named "wip/" with the following files: + +- model.h: the wip in C +- wip.h: tracepoints that report the execution of the events by the + monitor +- wip.c: the RV monitor + +The following line in the "wip.c" file is responsible for the monitor +synthesis:: + + DECLARE_DA_MON_PER_CPU(wip, char); + +With that in place, the work left to be done is the *instrumentation* of +the monitor, which is already initialized by dot2k. + +DA: Introduction and representation formats +--------------------------------------------------------------- + +Formally, a deterministic automaton, denoted by G, is defined as a quintuple: + + *G* = { *X*, *E*, *f*, x\ :subscript:`0`, X\ :subscript:`m` } + +where: + +- *X* is the set of states; +- *E* is the finite set of events; +- x\ :subscript:`0` is the initial state; +- X\ :subscript:`m` (subset of *X*) is the set of marked states. +- *f* : *X* x *E* -> *X* $ is the transition function. It defines the state + transition in the occurrence of an event from *E* in the state *X*. In the + special case of deterministic automata, the occurrence of the event in *E* + in a state in *X* has a deterministic next state from *X*. + +One of the most evident benefits for the practical application of the automata +formalism is its *graphic representation*, represented using vertices (nodes) +and edges, which is very intuitive for *operating system* practitioners. + +For example, given an automata wip, with a regular representation of: + +- *X* = { ``preemptive``, ``non_preemptive``} +- *E* = { ``preempt_enable``, ``preempt_disable``, ``sched_waking``} +- x\ :subscript:`0` = ``preemptive`` +- X\ :subscript:`m` = {``preemptive``} +- *f* = + - *f*\ (``preemptive``, ``preempt_disable``) = ``non_preemptive`` + - *f*\ (``non_preemptive``, ``sched_waking``) = ``non_preemptive`` + - *f*\ (``non_preemptive``, ``preempt_enable``) = ``preemptive`` + + +It can also be represented in a graphic format, without any loss, using this +format:: + + preempt_enable + +---------------------------------+ + v | + #============# preempt_disable +------------------+ + --> H preemptive H -----------------> | non_preemptive | + #============# +------------------+ + ^ sched_waking | + +--------------+ + +The Graphviz open-source tool can produce this graphic format using the +(textual) DOT language as the source code. The DOT format is widely +used and can be converted to many other formats, including the ASCII art above. + +The dot2c tool presented in: + + 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. + +Translates a deterministic automaton in the DOT format into a C source +code. For instance, using the wip model as input for dot2c results in +the following C representation:: + + enum states { + preemptive = 0, + non_preemptive, + state_max + }; + + enum events { + preempt_disable = 0, + preempt_enable, + sched_waking, + event_max + }; + + struct automaton { + char *state_names[state_max]; + char *event_names[event_max]; + char function[state_max][event_max]; + char initial_state; + char final_states[state_max]; + }; + + struct automaton aut = { + .state_names = { + "preemptive", + "non_preemptive" + }, + .event_names = { + "preempt_disable", + "preempt_enable", + "sched_waking" + }, + .function = { + { non_preemptive, -1, -1 }, + { -1, preemptive, non_preemptive }, + }, + .initial_state = preemptive, + .final_states = { 1, 0 }, + }; + +DA monitor synthesis for Linux +------------------------------ + +In Linux terms, the runtime verification monitors are encapsulated +inside the "RV monitor" abstraction. The "RV monitor" includes a set +of instances of the monitor (per-cpu monitor, per-task monitor, and +so on), the helper functions that glue the monitor to the system +reference model, and the trace output as a reaction for event parsing +and exceptions, as depicted below:: + + Linux +----- RV Monitor ----------------------------------+ Formal + Realm | | Realm + +-------------------+ +----------------+ +-----------------+ + | Linux kernel | | Monitor | | Reference | + | Tracing | -> | Instance(s) | <- | Model | + | (instrumentation) | | (verification) | | (specification) | + +-------------------+ +----------------+ +-----------------+ + | | | + | V | + | +----------+ | + | | Reaction | | + | +--+--+--+-+ | + | | | | | + | | | +-> trace output ? | + +------------------------|--|----------------------+ + | +----> panic ? + +-------> <user-specified> + + +The dot2c tool works connecting the *Reference Model* to the *RV Monitor* +abstraction by translating the *formal notation* into *code*. + +The "rv/da_monitor.h" header goes beyond dot2c, extending the code +generation to the verification stage, generating the code to the *Monitor +Instance(s)* level using C macros. The trace event code inspires this +approach. + +The benefits of the usage of macro for monitor synthesis is 3-fold: + +- Reduces the code duplication; +- Facilitates the bug fix/improvement; +- Avoids the case of developers changing the core of the monitor code + to manipulate the model in a (let's say) non-standard way. + +This initial implementation presents two different types of monitor instances: + +- ``#define DECLARE_DA_MON_PER_CPU(name, type)`` +- ``#define DECLARE_DA_MON_PER_TASK(name, type)`` + +The first declares the functions for deterministic automata monitor with +per-cpu instances, and the second with per-task instances. + +In both cases, the name is a string that identifies the monitor, and the type +is the data type used by dot2c/k on the representation of the model. + +For example, the "wip" model with two states and three events can be +stored in a "char" type. Considering that the preemption control is a +per-cpu behavior, the monitor declaration will be:: + + DECLARE_DA_MON_PER_CPU(wip, char); + +The monitor is executed by sending events to be processed via the functions +presented below:: + + da_handle_event_$(MONITOR_NAME)($(event from event enum)); + da_handle_init_event_$(MONITOR_NAME)($(event from event enum)); + +The function ``da_handle_event_$(MONITOR_NAME)()`` is the regular case, +while the function ``da_handle_init_event_$(MONITOR_NAME)()`` is a special +case used to synchronize the system with the model. + +When a monitor is enabled, it is placed in the initial state of the automata. +However, the monitor does not know if the system is in the *initial state*. +Hence, the monitor ignores events sent by sent by +``da_handle_event_$(MONITOR_NAME)()`` until the function +``da_handle_init_event_$(MONITOR_NAME)()`` is called. + +The function ``da_handle_init_event_$(MONITOR_NAME)()`` should be used for +the case in which the system generates the event is the one that returns +the automata to the initial state. + +After receiving a ``da_handle_init_event_$(MONITOR_NAME)()`` event, the +monitor will know that it is in sync with the system and hence will +start processing the next events. + +Using the wip model as example, the events "preempt_disable" and +"sched_waking" should be sent to to monitor, respectively, via:: + + da_handle_event_wip(preempt_disable); + da_handle_event_wip(sched_waking); + +While the event "preempt_enabled" will use:: + + da_handle_init_event_wip(preempt_enable); + +To notify the monitor that the system will be returning to the initial state, +so the system and the monitor should be in sync. + +rv/da_monitor.h +------------------------------------------- + +The "rv/da_monitor.h" is, mostly, a set of C macros that create function +definitions based on the paremeters passed via ``DECLARE_DA_MON_*``. + +In fewer words, the declaration of a monitor generates: + +- Helper functions for getting information from the automata model generated + by dot2k. +- Helper functions for the analysis of a deterministic automata model +- Functions for the initialization of the monitor instances +- The definition of the structure to store the monitor instances' data + +One important aspect is that the monitor does not call external functions +for the handling of the events sent by the instrumentation, except for +generating *tracing events* or *reactions*. + +Final remarks +------------- + +With the monitor synthesis in place using, the "rv/da_monitor.h" and +dot2k, the developer's work should be limited to the instrumentation +of the system, increasing the confidence in the overall approach.
Signature · 1 line
2.33.1
RFC v2 16/21 Documentation/rv: Add deterministic automata instrumentation documentation
In reply to Daniel Bristot de OliveiraAdd the da_monitor_instrumentation.rst. It describes the basics of RV monitor instrumentation.
--- .../trace/rv/da_monitor_instrumentation.rst | 230 ++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 Documentation/trace/rv/da_monitor_instrumentation.rst
Documentation/trace/rv/da_monitor_instrumentation.rst new file +230 -0
@@ -0,0 +1,230 @@ +Deterministic Automata Instrumentation +======================================== + +This document introduces some concepts behind the **Deterministic Automata +(DA)** monitor instrumentation. + +The synthesis of automata-based models into the Linux *RV monitor* abstraction +is automatized by a tool named dot2k, and the "rv/da_monitor.h" provided +by the RV interface. + +For example, given a file "wip.dot", representing a per-cpu monitor, with +this content:: + + digraph state_automaton { + center = true; + size = "7,11"; + rankdir = LR; + {node [shape = circle] "non_preemptive"}; + {node [shape = plaintext, style=invis, label=""] "__init_preemptive"}; + {node [shape = doublecircle] "preemptive"}; + {node [shape = circle] "preemptive"}; + "__init_preemptive" -> "preemptive"; + "non_preemptive" [label = "non_preemptive"]; + "non_preemptive" -> "non_preemptive" [ label = "sched_waking" ]; + "non_preemptive" -> "preemptive" [ label = "preempt_enable" ]; + "preemptive" [label = "preemptive"]; + "preemptive" -> "non_preemptive" [ label = "preempt_disable" ]; + { rank = min ; + "__init_preemptive"; + "preemptive"; + } + } + +That is the "DOT" representation of this automata model:: + + preempt_enable + +---------------------------------+ + v | + #============# preempt_disable +------------------+ + --> H preemptive H -----------------> | non_preemptive | + #============# +------------------+ + ^ sched_waking | + +--------------+ + + +Run the dot2k tool with the model, specifying that it is a "per-cpu" +model:: + + $ dot2k -d ~/wip.dot -t per_cpu + +This will create a directory named "wip/" with the following files: + +- model.h: the wip in C +- wip.h: tracepoints that report the execution of the events by the + monitor +- wip.c: the RV monitor + +The monitor instrumentation should be done entirely in the RV monitor, +in the example above, in the wip.c file. + +The RV monitor instrumentation section +-------------------------------------- + +The RV monitor file created by dot2k, with the name "$MODEL_NAME.c" +will include a section dedicated to instrumentation. + +In the example of the wip.dot above, it will look like:: + + /* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel events + * are translated into model's event. + * + */ + + void handle_preempt_disable(void *data, /* XXX: fill header */) + { + da_handle_event_wip(preempt_disable); + } + + void handle_preempt_enable(void *data, /* XXX: fill header */) + { + da_handle_event_wip(preempt_enable); + } + + void handle_sched_waking(void *data, /* XXX: fill header */) + { + da_handle_event_wip(sched_waking); + } + + #define NR_TP 3 + struct tracepoint_hook_helper tracepoints_to_hook[NR_TP] = { + { + .probe = handle_preempt_disable, + .name = /* XXX: tracepoint name here */, + .registered = 0 + }, + { + .probe = handle_preempt_enable, + .name = /* XXX: tracepoint name here */, + .registered = 0 + }, + { + .probe = handle_sched_waking, + .name = /* XXX: tracepoint name here */, + .registered = 0 + }, + }; + +The comment at the top of the section explains the general idea: the +instrumentation section translates *kernel events* into the *events +accepted by the model*. + +Tracing callback functions +----------------------------- + +The first three functions are skeletons for callback *handler functions* for +each of the three events from the wip model. The developer does not +necessarily need to use them: they are just starting points. + +Using the example of:: + + void handle_preempt_disable(void *data, /* XXX: fill header */) + { + da_handle_event_wip(preempt_disable); + } + +The "preempt_disable" event from the model conects directly to the +"preemptirq:preempt_disable". The "preemptirq:preempt_disable" event +has the following signature, from "include/trace/events/preemptirq.h":: + + TP_PROTO(unsigned long ip, unsigned long parent_ip) + +Hence, the "handle_preempt_disable()" function will look like:: + + void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip) + +In this case, the kernel even translates one to one with the automata event, +and indeed, no other change is needed for this function. + +The next handler function, "handle_preempt_enable()" has the same argument +list from the "handle_preempt_disable()". The difference is that the +"preempt_enable" event will be used to synchronize the system to the model. + +Initially, the *model* is placed in the initial state. However, the *system* +might, or might not be in the initial state. The monitor cannot start +processing events until it knows that the system reached the initial state. Otherwise the monitor and the system could be out-of-sync. + +Looking at the automata definition, it is possible to see that the system +and the model are expected to return to the initial state after the +"preempt_enable" execution. Hence, it can be used to synchronize the +system and the model at the initialization of the monitoring section. + +The initialization is informed via an special handle function, the +"da_handle_init_event_$(MONITOR)(event)", in this case:: + + da_handle_event_wip(preempt_disable); + +So, the callback function will look like:: + + void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip) + { + da_handle_init_event_wip(preempt_enable); + } + +Finally, the "handle_sched_waking()" will look like:: + + void handle_sched_waking(void *data, struct task_struct *task) + { + da_handle_event_wip(sched_waking); + } + +And the explanation is left for the reader as an exercise. + +Tracepoint hook helpers +-------------------------- + +Still in the previous example, the next code section is the +"tracepoint_to_hook" definition, which is a structure that aims to help to +connect a monitor *handler function* with a given "tracepoint". Note that +this is just a suggestion. Indeed, the *handler functions* can hook to anything +that is possible to hook in the kernel, not even limited to the +tracing interface. + +For the specific case of wip, the "tracepoints_to_hook" structure was +defined as:: + + #define NR_TP 3 + struct tracepoint_hook_helper tracepoints_to_hook[NR_TP] = { + { + .probe = handle_preempt_disable, + .name = "preempt_disable", + .registered = 0 + }, + { + .probe = handle_preempt_enable, + .name = "preempt_enable", + .registered = 0 + }, + { + .probe = handle_sched_waking, + .name = "sched_wakeup", + .registered = 0 + }, + }; + +And that is the instrumentation required for the wip sample model. + +Start and Stop functions +------------------------ + +Finally, dot2k automatically creates two special functions:: + + start_$MODELNAME() + stop_$MODELNAME() + +These functions are called when the monitor is enabled and disabled, +respectivelly. +They should be used to *hook* and *unhook* the instrumentation to the running +system. The developer must add to the relative function all that is needed to +*hook* and *unhook* its monitor to the system. + +For the wip case, these functions were named:: + + start_wip() + stop_wip() + +But no change was required because: by default, these functions *hook* and +*unhook* the tracepoints_to_hook, which was enough for this case.
Signature · 1 line
2.33.1
RFC v2 17/21 watchdog/dev: Add tracepoints
In reply to Daniel Bristot de OliveiraAdd a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_alive
--- drivers/watchdog/watchdog_dev.c | 41 ++++++++++++- include/linux/watchdog.h | 7 +-- include/trace/events/watchdog.h | 103 ++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 include/trace/events/watchdog.h
drivers/watchdog/watchdog_dev.c +38 -3
@@ -44,6 +44,9 @@#include <linux/watchdog.h> /* For watchdog specific items */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ +#define CREATE_TRACE_POINTS +#include <trace/events/watchdog.h> +#include "watchdog_core.h" #include "watchdog_pretimeout.h"
@@ -130,9 +133,11 @@ static inline void watchdog_update_worker(struct watchdog_device *wdd)if (watchdog_need_worker (wdd)) {ktime_t t =watchdog_next_keepalive (wdd); -if (t >0 ) +if (t >0 ) {hrtimer_start (&wd_data->timer, t,HRTIMER_MODE_REL_HARD ); +trace_watchdog_set_keep_alive (wdd,ktime_to_ms (t)); + } }else {hrtimer_cancel (&wd_data->timer); }
@@ -149,14 +154,16 @@ static int __watchdog_ping(struct watchdog_device *wdd) now =ktime_get ();if (ktime_after (earliest_keepalive, now)) { -hrtimer_start (&wd_data->timer, -ktime_sub (earliest_keepalive, now), +ktime_t t =ktime_sub (earliest_keepalive, now); +hrtimer_start (&wd_data->timer, t,HRTIMER_MODE_REL_HARD ); +trace_watchdog_set_keep_alive (wdd,ktime_to_ms (t));return 0 ; } wd_data->last_hw_keepalive = now; +trace_watchdog_ping (wdd);if (wdd->ops->ping) err = wdd->ops->ping (wdd);/* ping the watchdog */ else
@@ -215,6 +222,7 @@ static void watchdog_ping_work(struct kthread_work *work) wd_data = container_of(work, struct watchdog_core_data, work);mutex_lock (&wd_data->lock); +trace_watchdog_keep_alive (wd_data->wdd);if (watchdog_worker_should_ping (wd_data))__watchdog_ping (wd_data->wdd);mutex_unlock (&wd_data->lock);
@@ -252,6 +260,8 @@ static int watchdog_start(struct watchdog_device *wdd)set_bit (_WDOG_KEEPALIVE, &wd_data->status); +trace_watchdog_start (wdd); + started_at =ktime_get ();if (watchdog_hw_running (wdd) && wdd->ops->ping) { err =__watchdog_ping (wdd);
@@ -298,6 +308,7 @@ static int watchdog_stop(struct watchdog_device *wdd)return -EBUSY ; } +trace_watchdog_stop (wdd);if (wdd->ops->stop) {clear_bit (WDOG_HW_RUNNING , &wdd->status); err = wdd->ops->stop (wdd);
@@ -370,6 +381,7 @@ static int watchdog_set_timeout(struct watchdog_device *wdd,if (watchdog_timeout_invalid (wdd, timeout))return -EINVAL ; +trace_watchdog_set_timeout (wdd, timeout);if (wdd->ops->set_timeout) { err = wdd->ops->set_timeout (wdd, timeout); }else {
@@ -432,6 +444,23 @@ static int watchdog_get_timeleft(struct watchdog_device *wdd,return 0 ; } +/* +* watchdog_set_nowayout - set nowaout bit +* @wdd: The watchdog device to set nowayoutbit +* @nowayout A boolean on/off switcher +* +* If nowayout boolean is true, the nowayout option is set. No action is +* taken if nowayout is false. +*/ +void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout) +{ +if (nowayout) { +set_bit (WDOG_NO_WAY_OUT , &wdd->status); +trace_watchdog_nowayout (wdd); + } +} +EXPORT_SYMBOL (watchdog_set_nowayout); +#ifdef CONFIG_WATCHDOG_SYSFS static ssize_t nowayout_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -457,6 +486,7 @@ static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr,/* nowayout cannot be disabled once set */ if (test_bit (WDOG_NO_WAY_OUT , &wdd->status) && !value)return -EPERM ; +watchdog_set_nowayout (wdd, value);return len; }
@@ -858,6 +888,8 @@ static int watchdog_open(struct inode *inode, struct file *file) goto out_clear; } +trace_watchdog_open (wdd); + err =watchdog_start (wdd);if (err <0 ) goto out_mod;
@@ -880,6 +912,7 @@ static int watchdog_open(struct inode *inode, struct file *file)return stream_open (inode, file); out_mod: +trace_watchdog_close (wdd);module_put (wd_data->wdd->ops->owner); out_clear:clear_bit (_WDOG_DEV_OPEN, &wd_data->status);
@@ -940,6 +973,7 @@ static int watchdog_release(struct inode *inode, struct file *file)/* make sure that /dev/watchdog can be re-opened */ clear_bit (_WDOG_DEV_OPEN, &wd_data->status); +trace_watchdog_close (wdd); done: running = wdd &&watchdog_hw_running (wdd);mutex_unlock (&wd_data->lock);
@@ -952,6 +986,7 @@ static int watchdog_release(struct inode *inode, struct file *file)module_put (wd_data->cdev.owner);put_device (&wd_data->dev); } +return 0 ; }
include/linux/watchdog.h +1 -6
@@ -139,12 +139,7 @@ static inline bool watchdog_hw_running(struct watchdog_device *wdd)return test_bit (WDOG_HW_RUNNING , &wdd->status); } -/* Use the following function to set the nowayout feature */ -static inline void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout) -{ -if (nowayout) -set_bit (WDOG_NO_WAY_OUT , &wdd->status); -} +void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout);/* Use the following function to stop the watchdog on reboot */ static inline void watchdog_stop_on_reboot (struct watchdog_device *wdd)
include/trace/events/watchdog.h new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
2.33.1
Guenter Roeck
maintainerRe: [RFC V2 17/21] watchdog/dev: Add tracepoints
Quoted 69 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_aliveCc Wim Van Sebroeck <[email protected]>Cc Guenter Roeck <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Steven Rostedt <[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]>Signed-off-by Daniel Bristot de Oliveira <[email protected]>--- drivers/watchdog/watchdog_dev.c | 41 ++++++++++++- include/linux/watchdog.h | 7 +-- include/trace/events/watchdog.h | 103 ++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 9 deletions(-)create mode 100644
include/trace/events/watchdog.hdrivers/watchdog/watchdog_dev.c +6
-1@@ -44,6 +44,9 @@#include <linux/watchdog.h> /* For watchdog specific items */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ +#define CREATE_TRACE_POINTS +#include <trace/events/watchdog.h> +#include "watchdog_core.h" #include "watchdog_pretimeout.h" @@ -130,9 +133,11 @@ static inline void watchdog_update_worker(struct watchdog_device *wdd)if (watchdog_need_worker (wdd)) {ktime_t t =watchdog_next_keepalive (wdd); -if (t >0 ) +if (t >0 ) {hrtimer_start (&wd_data->timer, t,HRTIMER_MODE_REL_HARD ); +trace_watchdog_set_keep_alive (wdd,ktime_to_ms (t)); + } }else {hrtimer_cancel (&wd_data->timer); }
drivers/watchdog/watchdog_dev.c static int __watchdog_ping(struct watchdog_device *wdd) · line 157
Quoted 6 lines
drivers/watchdog/watchdog_dev.c +1
-2@@ -149,14 +154,16 @@ static int __watchdog_ping(struct watchdog_device *wdd) now =ktime_get ();if (ktime_after (earliest_keepalive, now)) { - hrtimer_start(&wd_data->timer, - ktime_sub(earliest_keepalive, now), +ktime_t t =ktime_sub (earliest_keepalive, now);
I am quite sure this line creates a checkpatch warning.
Quoted 46 lines
drivers/watchdog/watchdog_dev.c +8
-0+hrtimer_start (&wd_data->timer, t,HRTIMER_MODE_REL_HARD ); +trace_watchdog_set_keep_alive (wdd,ktime_to_ms (t));return 0 ; } wd_data->last_hw_keepalive = now; +trace_watchdog_ping (wdd);if (wdd->ops->ping) err = wdd->ops->ping (wdd);/* ping the watchdog */ else @@ -215,6 +222,7 @@ static void watchdog_ping_work(struct kthread_work *work) wd_data = container_of(work, struct watchdog_core_data, work);mutex_lock (&wd_data->lock); +trace_watchdog_keep_alive (wd_data->wdd);if (watchdog_worker_should_ping (wd_data))__watchdog_ping (wd_data->wdd);mutex_unlock (&wd_data->lock);@@ -252,6 +260,8 @@ static int watchdog_start(struct watchdog_device *wdd)set_bit (_WDOG_KEEPALIVE, &wd_data->status); +trace_watchdog_start (wdd); + started_at =ktime_get ();if (watchdog_hw_running (wdd) && wdd->ops->ping) { err =__watchdog_ping (wdd);@@ -298,6 +308,7 @@ static int watchdog_stop(struct watchdog_device *wdd)return -EBUSY ; } +trace_watchdog_stop (wdd);if (wdd->ops->stop) {clear_bit (WDOG_HW_RUNNING , &wdd->status); err = wdd->ops->stop (wdd);@@ -370,6 +381,7 @@ static int watchdog_set_timeout(struct watchdog_device *wdd,if (watchdog_timeout_invalid (wdd, timeout))return -EINVAL ; +trace_watchdog_set_timeout (wdd, timeout);if (wdd->ops->set_timeout) { err = wdd->ops->set_timeout (wdd, timeout); }else {
drivers/watchdog/watchdog_dev.c static int watchdog_get_timeleft(struct watchdog_device *wdd, · line 447
Quoted 4 lines
drivers/watchdog/watchdog_dev.c +1
-0@@ -432,6 +444,23 @@ static int watchdog_get_timeleft(struct watchdog_device *wdd,return 0 ; } +/*
/** ?
Quoted 53 lines
drivers/watchdog/watchdog_dev.c +21
-0+* watchdog_set_nowayout - set nowaout bit +* @wdd: The watchdog device to set nowayoutbit +* @nowayout A boolean on/off switcher +* +* If nowayout boolean is true, the nowayout option is set. No action is +* taken if nowayout is false. +*/ +void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout) +{ +if (nowayout) { +set_bit (WDOG_NO_WAY_OUT , &wdd->status); +trace_watchdog_nowayout (wdd); + } +} +EXPORT_SYMBOL (watchdog_set_nowayout); +#ifdef CONFIG_WATCHDOG_SYSFS static ssize_t nowayout_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -457,6 +486,7 @@ static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr,/* nowayout cannot be disabled once set */ if (test_bit (WDOG_NO_WAY_OUT , &wdd->status) && !value)return -EPERM ; +watchdog_set_nowayout (wdd, value);return len; }@@ -858,6 +888,8 @@ static int watchdog_open(struct inode *inode, struct file *file) goto out_clear; } +trace_watchdog_open (wdd); + err =watchdog_start (wdd);if (err <0 ) goto out_mod;@@ -880,6 +912,7 @@ static int watchdog_open(struct inode *inode, struct file *file)return stream_open (inode, file); out_mod: +trace_watchdog_close (wdd);module_put (wd_data->wdd->ops->owner); out_clear:clear_bit (_WDOG_DEV_OPEN, &wd_data->status);@@ -940,6 +973,7 @@ static int watchdog_release(struct inode *inode, struct file *file)/* make sure that /dev/watchdog can be re-opened */ clear_bit (_WDOG_DEV_OPEN, &wd_data->status); +trace_watchdog_close (wdd); done: running = wdd &&watchdog_hw_running (wdd);mutex_unlock (&wd_data->lock);
drivers/watchdog/watchdog_dev.c static int watchdog_release(struct inode *inode, struct file *file) · line 989
Quoted 4 lines
drivers/watchdog/watchdog_dev.c +1
-0@@ -952,6 +986,7 @@ static int watchdog_release(struct inode *inode, struct file *file)module_put (wd_data->cdev.owner);put_device (&wd_data->dev); } +
You may disagree with current empty lines or other cosmetics, but that is not an acceptable reason for such changes. Please drop this change and the similar change further up.
Guenter
Quoted 130 lines
drivers/watchdog/watchdog_dev.c +0
-0return 0 ; }include/linux/watchdog.h +1
-6@@ -139,12 +139,7 @@ static inline bool watchdog_hw_running(struct watchdog_device *wdd)return test_bit (WDOG_HW_RUNNING , &wdd->status); } -/* Use the following function to set the nowayout feature */ -static inline void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout) -{ -if (nowayout) -set_bit (WDOG_NO_WAY_OUT , &wdd->status); -} +void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout);/* Use the following function to stop the watchdog on reboot */ static inline void watchdog_stop_on_reboot (struct watchdog_device *wdd)include/trace/events/watchdog.h new file +103
-0@@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM watchdog + +#if !defined(_TRACE_WATCHDOG_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_WATCHDOG_H + +#include <linux/tracepoint.h> + +DECLARE_EVENT_CLASS (dev_operations_template, + + TP_PROTO(struct watchdog_device *wdd), + +TP_ARGS (wdd), + +TP_STRUCT__entry ( +__field (__u32, id) + ), + +TP_fast_assign ( + __entry->id = wdd->id; + ), + +TP_printk ("id=%d" , + __entry->id) +); + +/* +* Add a comment +*/ +DEFINE_EVENT (dev_operations_template, watchdog_open, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_close, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_start, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_stop, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_ping, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_keep_alive, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_nowayout, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + + +TRACE_EVENT (watchdog_set_timeout, + + TP_PROTO(struct watchdog_device *wdd, u64 timeout), + +TP_ARGS (wdd, timeout), + +TP_STRUCT__entry ( + __field(__u32, id) +__field (__u64, timeout) + ), + +TP_fast_assign ( + __entry->id = wdd->id; + __entry->timeout = timeout; + ), + +TP_printk ("id=%d timeout=%llus" , + __entry->id, __entry->timeout) +); + +TRACE_EVENT (watchdog_set_keep_alive, + + TP_PROTO(struct watchdog_device *wdd, u64 timeout), + +TP_ARGS (wdd, timeout), + +TP_STRUCT__entry ( + __field(__u32, id) +__field (__u64, timeout) + ), + +TP_fast_assign ( + __entry->id = wdd->id; + __entry->timeout = timeout; + ), + +TP_printk ("id=%d keep_alive=%llums" , + __entry->id, __entry->timeout) +); + +#endif /* _TRACE_WATCHDOG_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h>
Re: [RFC V2 17/21] watchdog/dev: Add tracepoints
Quoted 67 lines · Guenter Roeck
Quoted 66 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open watchdog:watchdog_close watchdog:watchdog_start watchdog:watchdog_stop watchdog:watchdog_set_timeout watchdog:watchdog_ping watchdog:watchdog_nowayout watchdog:watchdog_set_keep_alive watchdog:watchdog_keep_aliveCc Wim Van Sebroeck <[email protected]>Cc Guenter Roeck <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Steven Rostedt <[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]>Signed-off-by Daniel Bristot de Oliveira <[email protected]>---
drivers/watchdog/watchdog_dev.c| 41 ++++++++++++- include/linux/watchdog.h | 7 +--include/trace/events/watchdog.h| 103 ++++++++++++++++++++++++++++++++3 files changed, 142 insertions(+), 9 deletions(-)create mode 100644
include/trace/events/watchdog.hdrivers/watchdog/watchdog_dev.c +0
-0@@ -44,6 +44,9 @@ #include <linux/watchdog.h> /* For watchdog specific items */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */+#define
CREATE_TRACE_POINTSdrivers/watchdog/watchdog_dev.c +2
-0+#include <trace/events/watchdog.h> +#include "
watchdog_core.h"
#include "watchdog_pretimeout.h"
@@ -130,9 +133,11 @@ static inline voidwatchdog_update_worker(struct watchdog_device *wdd)
if (watchdog_need_worker(wdd)) {
ktime_tt =watchdog_next_keepalive(wdd);
- if (t > 0)
+ if (t > 0) {
hrtimer_start(&wd_data->timer, t, HRTIMER_MODE_REL_HARD);
+trace_watchdog_set_keep_alive(wdd, ktime_to_ms(t)); + }
} else {
hrtimer_cancel(&wd_data->timer);
}
Quoted 8 lines
drivers/watchdog/watchdog_dev.c static int __watchdog_ping(struct watchdog_device *wdd) · line 156
Quoted 6 lines
drivers/watchdog/watchdog_dev.c +1
-2@@ -149,14 +154,16 @@ static int __watchdog_ping(struct watchdog_device *wdd) now = ktime_get(); if (ktime_after(earliest_keepalive, now)) { - hrtimer_start(&wd_data->timer, - ktime_sub(earliest_keepalive, now), + ktime_t t = ktime_sub(earliest_keepalive, now);I am quite sure this line creates a checkpatch warning.
right, I will fix it.
Quoted 38 lines
Quoted 38 lines
drivers/watchdog/watchdog_dev.c +2
-0+ hrtimer_start(&wd_data->timer, t, HRTIMER_MODE_REL_HARD); + trace_watchdog_set_keep_alive(wdd, ktime_to_ms(t)); return 0; } wd_data->last_hw_keepalive = now; + trace_watchdog_ping(wdd); if (wdd->ops->ping)err = wdd->ops->ping(wdd); /* ping the watchdog */ else
drivers/watchdog/watchdog_dev.c +2
-0@@ -215,6 +222,7 @@ static void watchdog_ping_work(struct kthread_work *work) wd_data = container_of(work, struct watchdog_core_data, work); mutex_lock(&wd_data->lock); + trace_watchdog_keep_alive(wd_data->wdd); if (watchdog_worker_should_ping(wd_data)) __watchdog_ping(wd_data->wdd); mutex_unlock(&wd_data->lock);@@ -252,6 +260,8 @@ static int watchdog_start(struct watchdog_device *wdd) set_bit(_WDOG_KEEPALIVE, &wd_data->status); + trace_watchdog_start(wdd); + started_at = ktime_get(); if (watchdog_hw_running(wdd) && wdd->ops->ping) { err = __watchdog_ping(wdd);@@ -298,6 +308,7 @@ static int watchdog_stop(struct watchdog_device *wdd) return -EBUSY; } + trace_watchdog_stop(wdd); if (wdd->ops->stop) { clear_bit(WDOG_HW_RUNNING, &wdd->status); err = wdd->ops->stop(wdd);@@ -370,6 +381,7 @@ static int watchdog_set_timeout(struct watchdog_device *wdd, if (watchdog_timeout_invalid(wdd, timeout)) return -EINVAL; + trace_watchdog_set_timeout(wdd, timeout); if (wdd->ops->set_timeout) { err = wdd->ops->set_timeout(wdd, timeout);
Quoted 8 lines
Quoted 6 lines
drivers/watchdog/watchdog_dev.c +0
-0} else {@@ -432,6 +444,23 @@ static int watchdog_get_timeleft(struct watchdog_device *wdd, return 0; }+/*
/** ?
yep, I will fix this too.
Quoted 55 lines
Quoted 55 lines
+ *
watchdog_set_nowayout- set nowaout bit
+ * @wdd: The watchdog device to set nowayoutbit
+ * @nowayout A boolean on/off switcher
+ *
+ * If nowayout boolean is true, the nowayout option is set. No action is
+ * taken if nowayout is false.
+ */drivers/watchdog/watchdog_dev.c +9
-0+void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout) +{ + if (nowayout) { + set_bit(WDOG_NO_WAY_OUT, &wdd->status); + trace_watchdog_nowayout(wdd); + } +} +EXPORT_SYMBOL (watchdog_set_nowayout); +#ifdef
CONFIG_WATCHDOG_SYSFS
staticssize_tnowayout_show(struct device *dev, struct device_attribute *attr, char *buf)drivers/watchdog/watchdog_dev.c +1
-0@@ -457,6 +486,7 @@ static ssize_t nowayout_store(struct device *dev, structdevice_attribute *attr, /* nowayout cannot be disabled once set */ if (test_bit(WDOG_NO_WAY_OUT, &wdd->status) && !value) return -EPERM; + watchdog_set_nowayout(wdd, value); return len;}
drivers/watchdog/watchdog_dev.c +1
-0@@ -858,6 +888,8 @@ static int watchdog_open(struct inode *inode, struct file *file) goto out_clear; } + trace_watchdog_open(wdd); + err = watchdog_start(wdd); if (err < 0)goto
out_mod;drivers/watchdog/watchdog_dev.c +0
-0@@ -880,6 +912,7 @@ static int watchdog_open(struct inode *inode, struct file *file) return stream_open(inode, file);
out_mod:
+trace_watchdog_close(wdd);module_put(wd_data->wdd->ops->owner);out_clear:
clear_bit(_WDOG_DEV_OPEN, &wd_data->status);drivers/watchdog/watchdog_dev.c +0
-0@@ -940,6 +973,7 @@ static int watchdog_release(struct inode *inode, struct file *file) /* make sure that /dev/watchdog can be re-opened */ clear_bit(_WDOG_DEV_OPEN, &wd_data->status); + trace_watchdog_close(wdd);done:
running = wdd &&watchdog_hw_running(wdd);mutex_unlock(&wd_data->lock);drivers/watchdog/watchdog_dev.c +0
-0@@ -952,6 +986,7 @@ static int watchdog_release(struct inode *inode, struct file *file)
Quoted 8 lines
drivers/watchdog/watchdog_dev.c static int watchdog_release(struct inode *inode, struct file *file) · line 989
Quoted 4 lines
drivers/watchdog/watchdog_dev.c +1
-0module_put(wd_data->cdev.owner); put_device(&wd_data->dev); } +You may disagree with current empty lines or other cosmetics, but that is not an acceptable reason for such changes. Please drop this change and the similar change further up.
It was miss attention from my side. I probably did some changes around these lines in an early patch version but forgot to remove those "+<empty>" changes. My bad. I will remove them.
Thanks, Guenter!
-- Daniel
Quoted 1 line
Guenter
Re: [RFC V2 17/21] watchdog/dev: Add tracepoints
In reply to Daniel Bristot de OliveiraQuoted 13 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_alive
Some watchdogs have a bark functionality, I think it should be event for that too.
Quoted 298 lines
Cc Wim Van Sebroeck <[email protected]>Cc Guenter Roeck <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Steven Rostedt <[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]>Signed-off-by Daniel Bristot de Oliveira <[email protected]>--- drivers/watchdog/watchdog_dev.c | 41 ++++++++++++- include/linux/watchdog.h | 7 +-- include/trace/events/watchdog.h | 103 ++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 include/trace/events/watchdog.hdrivers/watchdog/watchdog_dev.c +38
-3@@ -44,6 +44,9 @@#include <linux/watchdog.h> /* For watchdog specific items */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ +#define CREATE_TRACE_POINTS +#include <trace/events/watchdog.h> +#include "watchdog_core.h" #include "watchdog_pretimeout.h" @@ -130,9 +133,11 @@ static inline void watchdog_update_worker(struct watchdog_device *wdd)if (watchdog_need_worker (wdd)) {ktime_t t =watchdog_next_keepalive (wdd); -if (t >0 ) +if (t >0 ) {hrtimer_start (&wd_data->timer, t,HRTIMER_MODE_REL_HARD ); +trace_watchdog_set_keep_alive (wdd,ktime_to_ms (t)); + } }else {hrtimer_cancel (&wd_data->timer); }@@ -149,14 +154,16 @@ static int __watchdog_ping(struct watchdog_device *wdd) now =ktime_get ();if (ktime_after (earliest_keepalive, now)) { -hrtimer_start (&wd_data->timer, -ktime_sub (earliest_keepalive, now), +ktime_t t =ktime_sub (earliest_keepalive, now); +hrtimer_start (&wd_data->timer, t,HRTIMER_MODE_REL_HARD ); +trace_watchdog_set_keep_alive (wdd,ktime_to_ms (t));return 0 ; } wd_data->last_hw_keepalive = now; +trace_watchdog_ping (wdd);if (wdd->ops->ping) err = wdd->ops->ping (wdd);/* ping the watchdog */ else @@ -215,6 +222,7 @@ static void watchdog_ping_work(struct kthread_work *work) wd_data = container_of(work, struct watchdog_core_data, work);mutex_lock (&wd_data->lock); +trace_watchdog_keep_alive (wd_data->wdd);if (watchdog_worker_should_ping (wd_data))__watchdog_ping (wd_data->wdd);mutex_unlock (&wd_data->lock);@@ -252,6 +260,8 @@ static int watchdog_start(struct watchdog_device *wdd)set_bit (_WDOG_KEEPALIVE, &wd_data->status); +trace_watchdog_start (wdd); + started_at =ktime_get ();if (watchdog_hw_running (wdd) && wdd->ops->ping) { err =__watchdog_ping (wdd);@@ -298,6 +308,7 @@ static int watchdog_stop(struct watchdog_device *wdd)return -EBUSY ; } +trace_watchdog_stop (wdd);if (wdd->ops->stop) {clear_bit (WDOG_HW_RUNNING , &wdd->status); err = wdd->ops->stop (wdd);@@ -370,6 +381,7 @@ static int watchdog_set_timeout(struct watchdog_device *wdd,if (watchdog_timeout_invalid (wdd, timeout))return -EINVAL ; +trace_watchdog_set_timeout (wdd, timeout);if (wdd->ops->set_timeout) { err = wdd->ops->set_timeout (wdd, timeout); }else {@@ -432,6 +444,23 @@ static int watchdog_get_timeleft(struct watchdog_device *wdd,return 0 ; } +/* +* watchdog_set_nowayout - set nowaout bit +* @wdd: The watchdog device to set nowayoutbit +* @nowayout A boolean on/off switcher +* +* If nowayout boolean is true, the nowayout option is set. No action is +* taken if nowayout is false. +*/ +void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout) +{ +if (nowayout) { +set_bit (WDOG_NO_WAY_OUT , &wdd->status); +trace_watchdog_nowayout (wdd); + } +} +EXPORT_SYMBOL (watchdog_set_nowayout); +#ifdef CONFIG_WATCHDOG_SYSFS static ssize_t nowayout_show (struct device *dev,struct device_attribute *attr,char *buf)@@ -457,6 +486,7 @@ static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr,/* nowayout cannot be disabled once set */ if (test_bit (WDOG_NO_WAY_OUT , &wdd->status) && !value)return -EPERM ; +watchdog_set_nowayout (wdd, value);return len; }@@ -858,6 +888,8 @@ static int watchdog_open(struct inode *inode, struct file *file) goto out_clear; } +trace_watchdog_open (wdd); + err =watchdog_start (wdd);if (err <0 ) goto out_mod;@@ -880,6 +912,7 @@ static int watchdog_open(struct inode *inode, struct file *file)return stream_open (inode, file); out_mod: +trace_watchdog_close (wdd);module_put (wd_data->wdd->ops->owner); out_clear:clear_bit (_WDOG_DEV_OPEN, &wd_data->status);@@ -940,6 +973,7 @@ static int watchdog_release(struct inode *inode, struct file *file)/* make sure that /dev/watchdog can be re-opened */ clear_bit (_WDOG_DEV_OPEN, &wd_data->status); +trace_watchdog_close (wdd); done: running = wdd &&watchdog_hw_running (wdd);mutex_unlock (&wd_data->lock);@@ -952,6 +986,7 @@ static int watchdog_release(struct inode *inode, struct file *file)module_put (wd_data->cdev.owner);put_device (&wd_data->dev); } +return 0 ; }include/linux/watchdog.h +1
-6@@ -139,12 +139,7 @@ static inline bool watchdog_hw_running(struct watchdog_device *wdd)return test_bit (WDOG_HW_RUNNING , &wdd->status); } -/* Use the following function to set the nowayout feature */ -static inline void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout) -{ -if (nowayout) -set_bit (WDOG_NO_WAY_OUT , &wdd->status); -} +void watchdog_set_nowayout (struct watchdog_device *wdd,bool nowayout);/* Use the following function to stop the watchdog on reboot */ static inline void watchdog_stop_on_reboot (struct watchdog_device *wdd)include/trace/events/watchdog.h new file +103
-0@@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM watchdog + +#if !defined(_TRACE_WATCHDOG_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_WATCHDOG_H + +#include <linux/tracepoint.h> + +DECLARE_EVENT_CLASS (dev_operations_template, + + TP_PROTO(struct watchdog_device *wdd), + +TP_ARGS (wdd), + +TP_STRUCT__entry ( +__field (__u32, id) + ), + +TP_fast_assign ( + __entry->id = wdd->id; + ), + +TP_printk ("id=%d" , + __entry->id) +); + +/* +* Add a comment +*/ +DEFINE_EVENT (dev_operations_template, watchdog_open, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_close, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_start, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_stop, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_ping, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_keep_alive, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + +DEFINE_EVENT (dev_operations_template, watchdog_nowayout, + TP_PROTO(struct watchdog_device *wdd), +TP_ARGS (wdd)); + + +TRACE_EVENT (watchdog_set_timeout, + + TP_PROTO(struct watchdog_device *wdd, u64 timeout), + +TP_ARGS (wdd, timeout), + +TP_STRUCT__entry ( + __field(__u32, id) +__field (__u64, timeout) + ), + +TP_fast_assign ( + __entry->id = wdd->id; + __entry->timeout = timeout; + ), + +TP_printk ("id=%d timeout=%llus" , + __entry->id, __entry->timeout) +); + +TRACE_EVENT (watchdog_set_keep_alive, + + TP_PROTO(struct watchdog_device *wdd, u64 timeout), + +TP_ARGS (wdd, timeout), + +TP_STRUCT__entry ( + __field(__u32, id) +__field (__u64, timeout) + ), + +TP_fast_assign ( + __entry->id = wdd->id; + __entry->timeout = timeout; + ), + +TP_printk ("id=%d keep_alive=%llums" , + __entry->id, __entry->timeout) +); + +#endif /* _TRACE_WATCHDOG_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h>
Re: [RFC V2 17/21] watchdog/dev: Add tracepoints
Hi Peter
Quoted 15 lines · On 2/16/22 17:01, [email protected] wrote:
Quoted 13 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_alive
Quoted 2 lines
Some watchdogs have a bark functionality, I think it should be event for that too.
I understand. The problems is that I do not see the bark abstraction in the watchdog_dev layer.
In the case I am investigating (the safety_monitor/safety_app) the bark is outside of the "OS" view, it is an hardware action - like. shutdown.
Am I missing something? Thoughts?
-- Daniel
Guenter Roeck
maintainerRe: [RFC V2 17/21] watchdog/dev: Add tracepoints
Quoted 18 lines · Daniel Bristot de Oliveira
Hi Peter
Quoted 15 lines · On 2/16/22 17:01, [email protected] wrote:
Quoted 13 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_alive
Quoted 6 lines
Quoted 2 lines
Some watchdogs have a bark functionality, I think it should be event for that too.
I understand. The problems is that I do not see the bark abstraction in the
watchdog_devlayer.
I don't even know what "bark functionality" means. A new term for pretimeout ? Something else ?
Guenter
Quoted 6 lines
In the case I am investigating (the safety_monitor/safety_app) the bark is outside of the "OS" view, it is an hardware action - like. shutdown.
Am I missing something? Thoughts?
-- Daniel
Re: [RFC V2 17/21] watchdog/dev: Add tracepoints
Quoted 23 lines · Guenter Roeck
Quoted 22 lines · Daniel Bristot de Oliveira
Hi Peter
Quoted 18 lines · On 2/16/22 17:01, [email protected] wrote:
Quoted 13 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_aliveSome watchdogs have a bark functionality, I think it should be event for that too.
Quoted 8 lines
Quoted 4 lines
I understand. The problems is that I do not see the bark abstraction in the
watchdog_devlayer.I don't even know what "bark functionality" means. A new term for pretimeout ?
Something else ?
From my understanding the bark timeout is actually the pretimeout whereas the bite timeout is the actual timeout.
I think in the Kernel ftwdt010_wdt and qcom-wdt are bark/bite WTDs
Gab
Quoted 11 lines
Guenter
Quoted 7 lines
In the case I am investigating (the safety_monitor/safety_app) the bark is
outside of the "OS" view, it is an hardware action - like. shutdown.Am I missing something? Thoughts?
-- Daniel
Re: [RFC V2 17/21] watchdog/dev: Add tracepoints
Quoted 27 lines · Gabriele Paoloni
Quoted 25 lines · Guenter Roeck
Quoted 24 lines · Daniel Bristot de Oliveira
Hi Peter
Quoted 14 lines · On 2/16/22 17:01, [email protected] wrote:
Quoted 13 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_aliveQuoted 3 lines
Some watchdogs have a bark functionality, I think it should be event for that too.
I understand. The problems is that I do not see the bark abstraction in the
watchdog_devlayer.
Quoted 5 lines
Quoted 3 lines
I don't even know what "bark functionality" means. A new term for pretimeout ?
Something else ?From my understanding the bark timeout is actually the pretimeout whereas the bite timeout is the actual timeout.
So, what Peter wants is tracepoints for the pretimeout actions?
-- Daniel
Guenter Roeck
maintainerRe: [RFC V2 17/21] watchdog/dev: Add tracepoints
In reply to Gabriele PaoloniQuoted 31 lines · Gabriele Paoloni
Quoted 28 lines · Guenter Roeck
Quoted 26 lines · Daniel Bristot de Oliveira
Hi Peter
Quoted 15 lines · On 2/16/22 17:01, [email protected] wrote:
Quoted 13 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_aliveQuoted 3 lines
Some watchdogs have a bark functionality, I think it should be event for that too.
I understand. The problems is that I do not see the bark abstraction in the
watchdog_devlayer.
Quoted 8 lines
Quoted 5 lines
I don't even know what "bark functionality" means. A new term for pretimeout ?
Something else ?From my understanding the bark timeout is actually the pretimeout
whereas the bite timeout is the actual timeout.
I think in the Kernelftwdt010_wdtand qcom-wdt are bark/bite WTDs
If that is the case, I would prefer if we could stick to existing terminology to avoid issues like "I do not see the bark abstraction".
Thanks,
Guenter
Re: [RFC V2 17/21] watchdog/dev: Add tracepoints
Quoted 36 lines · Guenter Roeck
Quoted 35 lines · Gabriele Paoloni
Quoted 31 lines · Guenter Roeck
Quoted 18 lines · Daniel Bristot de Oliveira
Hi Peter
Quoted 15 lines · On 2/16/22 17:01, [email protected] wrote:
Quoted 13 lines · Daniel Bristot de Oliveira
Add a set of tracepoints, enabling the observability of the watchdog device interactions with user-space.
The events are:
watchdog:watchdog_open
watchdog:watchdog_close
watchdog:watchdog_start
watchdog:watchdog_stop
watchdog:watchdog_set_timeout
watchdog:watchdog_ping
watchdog:watchdog_nowayout
watchdog:watchdog_set_keep_alive
watchdog:watchdog_keep_aliveQuoted 8 lines
Quoted 3 lines
Some watchdogs have a bark functionality, I think it should be event for that too.
I understand. The problems is that I do not see the bark abstraction in the
watchdog_dev layer.I don't even know what "bark functionality" means. A new term for pretimeout ?
Something else ?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
From my understanding the bark timeout is actually the pretimeout
whereas the bite timeout is the actual timeout.
I think in the Kernel ftwdt010_wdt and qcom-wdt are bark/bite WTDsIf that is the case, I would prefer if we could stick to existing terminology to avoid issues like "I do not see the bark abstraction".
I agree! I am using the terminology from watchdog dev. Like, I hear the term "pet" for the "ping", I used "ping."
-- Daniel
RFC v2 18/21 rv/monitor: Add safe watchdog monitor
In reply to Daniel Bristot de OliveiraThe watchdog is an essential building block for the usage of Linux in safety-critical systems because it allows the system to be monitored from an external element - the watchdog hardware, acting as a safety-monitor.
A user-space application controls the watchdog device via the watchdog interface. This application, hereafter safety_app, enables the watchdog and periodically pets the watchdog upon correct completion of the safety related processing.
If the safety_app, for any reason, stops pinging the watchdog, the watchdog hardware can set the system in a fail-safe state. For example, shutting the system down.
Given the importance of the safety_app / watchdog hardware couple, the interaction between these software pieces also needs some sort of monitoring. In other words, "who monitors the monitor?"
The safe watchdog (safe_wtd) RV monitor monitors the interaction between the safety_app and the watchdog device, enforcing the correct sequence of events that leads the system to a safe state.
Furthermore, the safety_app can monitor the RV monitor by collecting the events generated by the RV monitor itself via tracing interface. In this way, closing the monitoring loop with the safety_app.
To reach a safe state, the safe_wtd RV monitor requires the safety_app to:
- Open the watchdog device
- Start the watchdog
- Set a timeout
- ping at least once
The RV monitor also avoids some undesired actions. For example, to have other threads to touch the watchdog.
The monitor also has a set of options, enabled via kernel command line/module options. They are:
- watchdog_id: the device id to monitor (default 0).
- dont_stop: once enabled, do not allow the RV monitor to be stopped (default off);
- safe_timeout: define a maximum safe value that an user-space application can set as the watchdog timeout (default unlimited).
- check_timeout: After every ping, check if the time left in the watchdog is less than or equal to the last timeout set for the watchdog. It only works for watchdog devices that provide the get_timeleft() function (default off).
For further information, please refer to:
Documentation/trace/rv/watchdog-monitor.rst
The monitor specification was developed together with Gabriele Paoloni, in the context of the Linux Foundation Elisa Project.
--- kernel/trace/rv/Kconfig | 9 + kernel/trace/rv/Makefile | 1 + kernel/trace/rv/monitor_safe_wtd/model.h | 84 +++++ kernel/trace/rv/monitor_safe_wtd/safe_wtd.c | 322 ++++++++++++++++++++ kernel/trace/rv/monitor_safe_wtd/safe_wtd.h | 64 ++++ 5 files changed, 480 insertions(+) create mode 100644 kernel/trace/rv/monitor_safe_wtd/model.h create mode 100644 kernel/trace/rv/monitor_safe_wtd/safe_wtd.c create mode 100644 kernel/trace/rv/monitor_safe_wtd/safe_wtd.h
kernel/trace/rv/Kconfig +9 -0
@@ -30,6 +30,15 @@ config RV_MON_WWNR illustrates the usage of per-task monitor. The model is broken on purpose: it serves to test reactors. +config RV_MON_SAFE_WTD + tristate "Safety watchdog" + help + Enable safe_wtd, this monitor observes the interaction + between a user-space safety monitor and a watchdog device. + + For futher information see: + Documentation/trace/rv/safety-monitor.rst + config RV_REACTORS bool "Runtime verification reactors" default y if RV
kernel/trace/rv/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_RV) += rv.o obj-$(CONFIG_RV_MON_WIP) += monitor_wip/wip.o obj-$(CONFIG_RV_MON_WWNR) += monitor_wwnr/wwnr.o +obj-$(CONFIG_RV_MON_SAFE_WTD) += monitor_safe_wtd/safe_wtd.o obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o obj-$(CONFIG_RV_REACT_PANIC) += reactor_panic.o
kernel/trace/rv/monitor_safe_wtd/model.h new file +84 -0
85 lines not on this page · raw message
kernel/trace/rv/monitor_safe_wtd/safe_wtd.c new file +322 -0
322 lines not on this page · raw message
kernel/trace/rv/monitor_safe_wtd/safe_wtd.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.33.1
kernel test robot
build botRe: [RFC V2 18/21] rv/monitor: Add safe watchdog monitor
[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]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on rostedt-trace/for-next]
[also build test ERROR on lwn/docs-next linus/master v5.17-rc4 next-20220214] [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]
url: https://github.com/0day-ci/linux/commits/Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next config: openrisc-randconfig-r033-20220214 (https://download.01.org/0day-ci/archive/20220215/202202150336.KeANrcMi-lkp(a)intel.com/config) compiler: or1k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/4f1503ea00e1acc20ca50288f9493c562133a6e8
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Bristot-de-Oliveira/The-Runtime-Verification-RV-interface/20220214-193144 git checkout 4f1503ea00e1acc20ca50288f9493c562133a6e8
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
or1k-linux-ld: kernel/trace/rv/monitor_safe_wtd/safe_wtd.o: in function `__da_handle_event_safe_wtd.constprop.0':
>> safe_wtd.c:(.text+0xa9c): undefined reference to `reacting_on' >> or1k-linux-ld: safe_wtd.c:(.text+0xaa0): undefined reference to `reacting_on'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 19/21 rv/monitor: Add safe watchdog nowayout monitor
In reply to Daniel Bristot de OliveiraThis is a simplification of the safe_wtd monitor, named safe_wtd_nwo. The difference between these two monitors is that the latter enforces the nowayout watchdog device option before opening the watchdog.
In this way, once the watchdog is starts, the watchdog hardware will serve as an safety-monitor until the system shutdown.
For further information, please refer to:
Documentation/trace/rv/watchdog-monitor.rst
The monitor specification was developed together with Gabriele Paoloni, in the context of the Linux Foundation Elisa Project.
--- kernel/trace/rv/Kconfig | 10 + kernel/trace/rv/Makefile | 1 + kernel/trace/rv/monitor_safe_wtd_nwo/model.h | 61 ++++ .../rv/monitor_safe_wtd_nwo/safe_wtd_nwo.c | 309 ++++++++++++++++++ .../rv/monitor_safe_wtd_nwo/safe_wtd_nwo.h | 64 ++++ 5 files changed, 445 insertions(+) create mode 100644 kernel/trace/rv/monitor_safe_wtd_nwo/model.h create mode 100644 kernel/trace/rv/monitor_safe_wtd_nwo/safe_wtd_nwo.c create mode 100644 kernel/trace/rv/monitor_safe_wtd_nwo/safe_wtd_nwo.h
kernel/trace/rv/Kconfig +10 -0
@@ -39,6 +39,16 @@ config RV_MON_SAFE_WTD For futher information see: Documentation/trace/rv/safety-monitor.rst +config RV_MON_SAFE_WTD_NWO + tristate "Safety watchdog nowayout" + help + Enable safe_wtd_nwo, this monitor observes the interaction + between a user-space safety monitor and a watchdog device. It + enforces the usage of watchdog's nowayout config. + + For futher information see: + Documentation/trace/rv/safety-monitor.rst + config RV_REACTORS bool "Runtime verification reactors" default y if RV
kernel/trace/rv/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_RV) += rv.o obj-$(CONFIG_RV_MON_WIP) += monitor_wip/wip.o obj-$(CONFIG_RV_MON_WWNR) += monitor_wwnr/wwnr.o obj-$(CONFIG_RV_MON_SAFE_WTD) += monitor_safe_wtd/safe_wtd.o +obj-$(CONFIG_RV_MON_SAFE_WTD_NWO) += monitor_safe_wtd_nwo/safe_wtd_nwo.o obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o obj-$(CONFIG_RV_REACT_PANIC) += reactor_panic.o
kernel/trace/rv/monitor_safe_wtd_nwo/model.h new file +61 -0
61 lines not on this page · raw message
kernel/trace/rv/monitor_safe_wtd_nwo/safe_wtd_nwo.c new file +309 -0
309 lines not on this page · raw message
kernel/trace/rv/monitor_safe_wtd_nwo/safe_wtd_nwo.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC v2 20/21 rv/safety_app: Add an safety_app sample
In reply to Daniel Bristot de OliveiraThis is the sample code of a safety application that uses the watchdog as a safety monitor and the RV monitors to monitor this interaction/get feedback from kernel about the watchdog states.
This tool first creates a trace instance to follow the RV events and then enables RV monitor. After that, the tool configures the watchdog and starts running the main loop.
The main loop runs a use-case-specific function, like checking the system. If the system is running as expected, it pings the watchdog. After pinging the watchdog, the tool then collects trace information to see if the RV monitor received the expected events and is in a safe/safe_nwo state.
For further information, run safety_app --help
The safety-app specification was developed together with Gabriele Paoloni, in the context of the Linux Foundation Elisa Project.
--- tools/tracing/rv/safety_app/Makefile | 51 ++ tools/tracing/rv/safety_app/safety_app.c | 713 +++++++++++++++++++++++ 2 files changed, 764 insertions(+) create mode 100644 tools/tracing/rv/safety_app/Makefile create mode 100644 tools/tracing/rv/safety_app/safety_app.c
tools/tracing/rv/safety_app/Makefile new file +51 -0
@@ -0,0 +1,51 @@ +NAME := safety_app +VERSION := 0.1 + +# From libtracefs: +# Makefiles suck: This macro sets a default value of $(2) for the +# variable named by $(1), unless the variable has been set by +# environment or command line. This is necessary for CC and AR +# because make sets default values, so the simpler ?= approach +# won't work as expected. +define allow-override + $(if $(or $(findstring environment,$(origin $(1))),\ + $(findstring command line,$(origin $(1)))),,\ + $(eval $(1) = $(2))) +endef + +# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. +$(call allow-override,CC,$(CROSS_COMPILE)gcc) +$(call allow-override,AR,$(CROSS_COMPILE)ar) +$(call allow-override,STRIP,$(CROSS_COMPILE)strip) +$(call allow-override,PKG_CONFIG,pkg-config) +$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/) +$(call allow-override,LDCONFIG,ldconfig) + +INSTALL = install +FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ + -fasynchronous-unwind-tables -fstack-clash-protection +WOPTS := -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized + +TRACEFS_HEADERS := $$($(PKG_CONFIG) --cflags libtracefs) + +CFLAGS := -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(WOPTS) $(TRACEFS_HEADERS) +LDFLAGS := -ggdb +LIBS := $$($(PKG_CONFIG) --libs libtracefs) +FILES := Makefile +BINDIR := /usr/bin + +OBJ := $(NAME).o + +.PHONY: all +all: $(OBJ) + $(CC) -o $(NAME) $(LDFLAGS) $(OBJ) $(LIBS) + +.PHONY: install +install: + $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) + $(INSTALL) $(NAME) -m 755 $(DESTDIR)$(BINDIR) + $(STRIP) $(DESTDIR)$(BINDIR)/$(NAME) + +.PHONY: clean +clean: + @rm -rf *~ $(OBJ) $(NAME)
tools/tracing/rv/safety_app/safety_app.c new file +713 -0
713 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC v2 21/21 Documentation/rv: Add watchdog-monitor documentation
In reply to Daniel Bristot de OliveiraAdds documentation about the safe_wtd and safe_wtd_nwo RV monitors, and their usage via a safety application.
--- Documentation/trace/rv/watchdog-monitor.rst | 307 ++++++++++++++++++++ 1 file changed, 307 insertions(+) create mode 100644 Documentation/trace/rv/watchdog-monitor.rst
Documentation/trace/rv/watchdog-monitor.rst new file +307 -0
@@ -0,0 +1,307 @@ +Watchdog monitor +---------------- + +The watchdog is an essential building block for the usage of Linux in +safety-critical systems because it allows the system to be monitored from +an external element - the watchdog hardware, acting as a safety-monitor. + +A user-space application controls the watchdog device via the watchdog +interface. This application, hereafter safety_app, enables the watchdog +and periodically pets the watchdog upon correct completion of the safety +related processing. + +If the safety_app, for any reason, stops pinging the watchdog, +the watchdog hardware can set the system in a fail-safe state. For +example, shutting the system down. + +Given the importance of the safety_app / watchdog hardware couple, +the interaction between these software pieces also needs some +sort of monitoring. In other words, "who monitors the monitor?" + +The safe watchdog (safe_wtd) RV monitor monitors the interaction between +the safety_app and the watchdog device, enforcing the correct sequence of +events that leads the system to a safe state. + +Furthermore, the safety_app can monitor the RV monitor by collecting the +events generated by the RV monitor itself via tracing interface. In this way, +closing the monitoring loop with the safety_app. + +A diagram of the components and their interactions is:: + + user-space: + +--------------------------------+ + | safety_app |-----------+ + +--------------------------------+ | + | ^ | + | Configure | Enable and | + | | check data | + ===================+====================+=============== | + kernel-space: | | | + v v | + +----------+ instr. +-------------+ | + | watchdog | ----------->| RV Monitor |----+ | + | device | +-------------+ | | + +----------+ | | + | | | + | | | + ================+====================================== | | + hardware: | | | + v | +-> Bring the system + +--------------------+ +----> to a safe state, + | watchdog hardware |---------------------------> e.g., halt. + +--------------------+ + +Sample safety_app +----------------- + +The user-space safety_app sample code in ``tools/tracing/rv/safety_app/`` +serves to illustrate the usage of the RV monitors for this use-case, as +well as the starting point to the development of a user-specific safety_app. + +Watchdog events +--------------- + +The RV monitor observes the watchdog by using instrumentation to +process the events generated by the interaction between the +safety_app and the watchdog device layer in kernel. + +The monitored events are: + + - watchdog:watchdog_open: open the watchdog device; + - watchdog:watchdog_close: close the watchdog device; + - watchdog:watchdog_start: start the watchdog; + - watchdog:watchdog_stop: stop the watchdog; + - watchdog:watchdog_set_timeout: set the watchdog timeout; + - watchdog:watchdog_ping: reprogram the watchdog with the previously set + timeout; + - watchdog:watchdog_nowayout: prevents the watchdog from stopping; + - watchdog:watchdog_set_keep_alive: set an intermediary ping to overcome + the limitation of a hardware watchdog maximum timeout being shorter than + the timeout set by the user-space tool; + - watchdog:watchdog_keep_alive: the execution of the function that runs the + intermediary keep alive ping; + +RV monitor events +----------------- + +The RV monitor monitors the relevant events as an outside observer, +interpreting all the components (the hardware; the watchdog device +interface; and the safety monitor) as an integrated component. + +The events selected for the monitor are: + + - other_threads: an event generated by any thread other than the + one that set nowayout or open the watchdog the last time. + - open: a thread opens the watchdog to manipulate it; + - close: a thread closes the watchdog; + - start: starts the watchdog countdown; + - stop: stops the watchdog; + - set_safe_timeout: configures the watchdog with a given timeout; + - ping: resets the watchdog countdown with the previously configured timeout; + - nowayout: prevents the watchdog to be stopped until the system's shutdown; + - sched_keep_alive: schedules a kernel worker to ping the watchdog if the + timeout is longer than the watchdog hardware can handle. + - keep_alive: executes the previously scheduled watchdog ping; + +Noting that the events that does not appear in the automata models are +considered blocked events, and their execution will always cause the +RV monitor to react to an unexpected event. + +RV monitor specification +------------------------ + +The monitor's goal is to assess a set of specifications that conducts the +system to a safe state. + +These specifications are: + + - 1: Once open, only one process manipulates the watchdog; + - 2: Following 1, the keep-alive mechanisms will not be used; + - 3: If required, nowayout will be set before opening the watchdog; + - 4: A safe timeout must be set; + - 5: At least one ping must be made before entering the safe/safe_nwo states + - 6: The The RV monitor does not react if the watchdog is closed without stopping. + But the hardware watchdog is expected to react. + +Deterministic automata monitors +------------------------------- + +Following the specifications, two deterministic automata monitors +were developed. The are the safe_wtd and the safe_wtd_nwo monitors. +The monitors are modeled as Deterministic Automata models. + +The difference between the safe_wtd and the safe_wtd_nwo is that +the latter enforces the usage of the watchdog's nowayout option +to reach the safe state. + +The deterministic automata model for safe_wtd is:: + + #==================================# other_threads + H H ----------------+ + -----------> H init H | + H H <---------------+ + #==================================# + | | ^ + | | | close + | | +----------------------------------------------------+ + | | | + | | open | + | +------------------------------------------------------+ | + | | | + | nowayout | | + v | | + nowayout +-------------------+ | | + other_threads | | nowayout | | + +---------------- | nwo |<-------------------------------------+ | | + | | | | | | + +---------------> | | <+ | | | + +-------------------+ | | | | + | | | | | + | open | close | | | + v | | | | + +-------------------+ | | | | + | opened_nwo | -+ | | | + +-------------------+ | | | + | | | | + | start | | | + v | | | + +-------------------+ | | | + +---------------> | started_nwo | -+ | | | + | +-------------------+ | | | | + | | | | | | + | open | set_safe_timeout | | | | + | v | | | | + | +-------------------+ | | | | + | | set_nwo | | | | | + | +-------------------+ | | | | + | | | | | | + | +-------------+ | ping | | | | + | | | | | | | | + | | ping v v | | | | + | | +-------------------+ | | | | + | +-----------| safe_nwo | | | | | + | +-------------------+ | | | | + | | | | | | + | | close | close | | | + | v v | | | + | +----------------------------------+ nowayout | | | + | | | other_threads | | | + | | closed_running_nwo | ----------------+ | | | + | | | | | | | + +---------------- | | <---------------+ | | | + +----------------------------------+ | | | + | nowayout ^ | | | + +-----------------------------+ | | | + | | | + | | | + +-------------------+ +--------+ | | | + | | | |------+---+ | + | started | start | opened | | | + +---------------- | | <-------- | |>-----+-------+ + | +-------------------+ +--------+ | ^ + | | | | + | | set_safe_timeout +-------------+-------+ + | v | | + | +-------------------+ | | + | | | | | + | | set | | | + +----------+---------------> | | | | + | | +-------------------+ | | + | | | | | + | | | ping | | + | | v | | + | | +-------------------+ ping | | + | | | | -------+ | | + | | +---- | safe | | | | + | | | | | <------+ | | + | | | +-------------------+ | | + | | | | | | + | | stop | | stop | | + | | | v | | + | | | +-------------------+ close | | + | +-----------+---> | stopped |-------------+ | + | | +-------------------+ | + | +---+ | + | | close | + | v | + | other_threads +----------------------------------------+ | + | +--------------> | | | + | | | closed_running | | + | +--------------- | |--------------+ + | +----------------------------------------+ + | | ^ + | open | | close + | v | + | set_safe_timeout +-------------------+ + +-------------------------> | reopened | + +-------------------+ + +The deterministic automata model for safe_wtd_nwo is:: + + | + | + v + #===================# + H init H + #===================# + | + | nowayout + v + nowayout +-------------------+ + other_threads | | + +---------------- | nwo | + | | | + +---------------> | | <---+ + +-------------------+ | + | | + | open | close + v | + +-------------------+ | + | opened | ----+ + +-------------------+ + | + | start + v + +-------------------+ + +---------------> | started | ---+ + | +-------------------+ | + | | | + | open | set_safe_timeout | + | v | + | +-------------------+ | + | | set | | + | +-------------------+ | + | | | + | +------------+ | ping | + | | v v | + | | ping +-------------------+ | + | +---------| safe | | + | +-------------------+ | + | | | + | | close | close + | v | + | +-------------------+ | + +---------------- | closed_running | <--+ + +-------------------+ + ^ | + | nowayout | + | other_threads | + +---------------+ + +It is important to note that the events sched_keep_alive and keep_alive +are not allowed on any of the present monitors (they are said to be blocked +events). The execution of any blocked events leads the RV monitor to react. + +Additional options +------------------ + +The RV monitor also has a set of options enabled via kernel command +line/module options. They are: + + - watchdog_id: the device id to monitor (default 0); + - dont_stop: once enabled, do not allow the RV monitor to be stopped (default off); + - safe_timeout: define a maximum safe value that a user-space application can + set as the watchdog timeout (default unlimited); + - check_timeout: After every ping, check if the time left in the watchdog is less + than or equal to the last timeout set for the watchdog. It only works for watchdog + devices that provide the get_timeleft() function (default off);
Signature · 1 line
2.33.1