blob: 0e2c9a1e958a490cdbbaae732f379c5ee3b26d87 [file] [log] [blame]
Akinobu Mitac9d221f2010-05-26 14:43:36 -07001#include <linux/kernel.h>
Akinobu Mitac9d221f2010-05-26 14:43:36 -07002#include <linux/module.h>
Akinobu Mitaf5a9f522012-07-30 14:43:03 -07003#include <linux/cpu.h>
4
5#include "notifier-error-inject.h"
Akinobu Mitac9d221f2010-05-26 14:43:36 -07006
7static int priority;
Akinobu Mitac9d221f2010-05-26 14:43:36 -07008module_param(priority, int, 0);
9MODULE_PARM_DESC(priority, "specify cpu notifier priority");
10
Sebastian Andrzej Siewior8c588982016-09-06 19:04:50 +020011#define UP_PREPARE 0
12#define UP_PREPARE_FROZEN 0
13#define DOWN_PREPARE 0
14#define DOWN_PREPARE_FROZEN 0
15
Akinobu Mitaf5a9f522012-07-30 14:43:03 -070016static struct notifier_err_inject cpu_notifier_err_inject = {
17 .actions = {
Sebastian Andrzej Siewior8c588982016-09-06 19:04:50 +020018 { NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE) },
19 { NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE_FROZEN) },
20 { NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE) },
21 { NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE_FROZEN) },
Akinobu Mitaf5a9f522012-07-30 14:43:03 -070022 {}
Akinobu Mitac9d221f2010-05-26 14:43:36 -070023 }
Akinobu Mitac9d221f2010-05-26 14:43:36 -070024};
25
Sebastian Andrzej Siewior8c588982016-09-06 19:04:50 +020026static int notf_err_handle(struct notifier_err_inject_action *action)
27{
28 int ret;
29
30 ret = action->error;
31 if (ret)
32 pr_info("Injecting error (%d) to %s\n", ret, action->name);
33 return ret;
34}
35
36static int notf_err_inj_up_prepare(unsigned int cpu)
37{
38 if (!cpuhp_tasks_frozen)
39 return notf_err_handle(&cpu_notifier_err_inject.actions[0]);
40 else
41 return notf_err_handle(&cpu_notifier_err_inject.actions[1]);
42}
43
44static int notf_err_inj_dead(unsigned int cpu)
45{
46 if (!cpuhp_tasks_frozen)
47 return notf_err_handle(&cpu_notifier_err_inject.actions[2]);
48 else
49 return notf_err_handle(&cpu_notifier_err_inject.actions[3]);
50}
51
Akinobu Mitaf5a9f522012-07-30 14:43:03 -070052static struct dentry *dir;
53
Akinobu Mitac9d221f2010-05-26 14:43:36 -070054static int err_inject_init(void)
55{
Akinobu Mitaf5a9f522012-07-30 14:43:03 -070056 int err;
Akinobu Mitac9d221f2010-05-26 14:43:36 -070057
Akinobu Mitaf5a9f522012-07-30 14:43:03 -070058 dir = notifier_err_inject_init("cpu", notifier_err_inject_dir,
59 &cpu_notifier_err_inject, priority);
60 if (IS_ERR(dir))
61 return PTR_ERR(dir);
62
Sebastian Andrzej Siewior8c588982016-09-06 19:04:50 +020063 err = cpuhp_setup_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE,
64 "cpu-err-notif:prepare",
65 notf_err_inj_up_prepare,
66 notf_err_inj_dead);
Akinobu Mitaf5a9f522012-07-30 14:43:03 -070067 if (err)
68 debugfs_remove_recursive(dir);
69
70 return err;
Akinobu Mitac9d221f2010-05-26 14:43:36 -070071}
72
73static void err_inject_exit(void)
74{
Sebastian Andrzej Siewior8c588982016-09-06 19:04:50 +020075 cpuhp_remove_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE);
Akinobu Mitaf5a9f522012-07-30 14:43:03 -070076 debugfs_remove_recursive(dir);
Akinobu Mitac9d221f2010-05-26 14:43:36 -070077}
78
79module_init(err_inject_init);
80module_exit(err_inject_exit);
81
82MODULE_DESCRIPTION("CPU notifier error injection module");
83MODULE_LICENSE("GPL");
84MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");