^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/memory.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "notifier-error-inject.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) static int priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) module_param(priority, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) MODULE_PARM_DESC(priority, "specify memory notifier priority");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static struct notifier_err_inject memory_notifier_err_inject = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) .actions = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) { NOTIFIER_ERR_INJECT_ACTION(MEM_GOING_ONLINE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) { NOTIFIER_ERR_INJECT_ACTION(MEM_GOING_OFFLINE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static struct dentry *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int err_inject_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) dir = notifier_err_inject_init("memory", notifier_err_inject_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) &memory_notifier_err_inject, priority);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (IS_ERR(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return PTR_ERR(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) err = register_memory_notifier(&memory_notifier_err_inject.nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) debugfs_remove_recursive(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void err_inject_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unregister_memory_notifier(&memory_notifier_err_inject.nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) debugfs_remove_recursive(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) module_init(err_inject_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) module_exit(err_inject_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) MODULE_DESCRIPTION("memory notifier error injection module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");