1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org>
4  *
5  * Printk RV reactor:
6  *   Prints the exception msg to the kernel message log.
7  */
8 #include <linux/ftrace.h>
9 #include <linux/tracepoint.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/rv.h>
14 
rv_printk_reaction(const char * msg,...)15 __printf(1, 2) static void rv_printk_reaction(const char *msg, ...)
16 {
17 	va_list args;
18 
19 	va_start(args, msg);
20 	vprintk_deferred(msg, args);
21 	va_end(args);
22 }
23 
24 static struct rv_reactor rv_printk = {
25 	.name = "printk",
26 	.description = "prints the exception msg to the kernel message log.",
27 	.react = rv_printk_reaction
28 };
29 
register_react_printk(void)30 static int __init register_react_printk(void)
31 {
32 	rv_register_reactor(&rv_printk);
33 	return 0;
34 }
35 
unregister_react_printk(void)36 static void __exit unregister_react_printk(void)
37 {
38 	rv_unregister_reactor(&rv_printk);
39 }
40 
41 module_init(register_react_printk);
42 module_exit(unregister_react_printk);
43 
44 MODULE_AUTHOR("Daniel Bristot de Oliveira");
45 MODULE_DESCRIPTION("printk rv reactor: printk if an exception is hit.");
46