[Devel] [PATCH RH9 01/30] livepatch: added minimal support for failure injection

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Tue Sep 28 21:48:52 MSK 2021


From: Evgenii Shatokhin <eshatokhin at virtuozzo.com>

It can be useful when testing loading and replacement of live kernel
patches. It may be needed to check that, if loading of a patch fails,
the system remains in a consistent state.

Livepatch subsystem will now create file 'livepatch/fail_apply' in
debugfs. If one writes 1 (or whatever else kstrtobool() takes as "yes")
to it, the attempts to apply live patches will fail with -EBUSY. The
currently loaded patches remain loaded.

Writing 0 to livepatch/fail_apply disables injection of such failures.

Livepatch is more likely to apply a patch successfully than the old
KPatch core used in VZ7. However, it can still refuse to load a valid
patch with -EBUSY if another patch is currently being processed.

Failure injection added here mimics that behaviour.

Done in the scope of https://jira.sw.ru/browse/PSBM-102582.

Signed-off-by: Evgenii Shatokhin <eshatokhin at virtuozzo.com>

(cherry picked from vz8 commit 19d7df1e5402e06ff3ccc06566331bd023c7f8c3)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 kernel/livepatch/core.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 335d988..52911a1 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -20,6 +20,7 @@
 #include <linux/completion.h>
 #include <linux/memory.h>
 #include <linux/rcupdate.h>
+#include <linux/debugfs.h>
 #include <asm/cacheflush.h>
 #include "core.h"
 #include "patch.h"
@@ -45,6 +46,13 @@
 
 static struct kobject *klp_root_kobj;
 
+/*
+ * Can be set via livepatch/fail_apply file in debugfs.
+ * If set, livepatch will fail with -EBUSY when requested to apply a patch.
+ * Might be useful for testing and debugging livepatch.
+ */
+static bool fail_apply;
+
 static bool klp_is_module(struct klp_object *obj)
 {
 	return obj->name;
@@ -961,6 +969,9 @@ static int __klp_enable_patch(struct klp_patch *patch)
 	if (klp_transition_patch)
 		return -EBUSY;
 
+	if (fail_apply)
+		return -EBUSY;
+
 	if (WARN_ON(patch->enabled))
 		return -EINVAL;
 
@@ -1266,10 +1277,16 @@ void klp_module_going(struct module *mod)
 
 static int __init klp_init(void)
 {
+	struct dentry *d;
+
 	klp_root_kobj = kobject_create_and_add("livepatch", kernel_kobj);
 	if (!klp_root_kobj)
 		return -ENOMEM;
 
+	d = debugfs_create_dir("livepatch", NULL);
+	if (d)
+		debugfs_create_bool("fail_apply", 0644, d, &fail_apply);
+
 	return 0;
 }
 
-- 
1.8.3.1



More information about the Devel mailing list