[POC 16/23] livepatch: Add patch into the global list early

Petr Mladek
2020-01-17T15:04:38Z

The objects for livepatched modules need to be loaded before the livepatch
gets enabled. klp_add_module() has to find the patch. The code is easier
when the being-enabled patch can be found in the global list.

Fortunately, there is no problem to add patch into the list already
in the early init. klp_free_patch_start() will remove it in case
of any later error.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
kernel/livepatch/core.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 688ad81def14..06676ec63ba7 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -852,6 +852,7 @@ static int klp_init_object_early(struct klp_patch *patch,
static int klp_init_patch_early(struct klp_patch *patch)
{
struct klp_object *obj = patch->obj;
+ int ret;

/* Main patch module is always for vmlinux */
if (obj->name)
@@ -865,7 +866,11 @@ static int klp_init_patch_early(struct klp_patch *patch)
INIT_WORK(&patch->free_work, klp_free_patch_work_fn);
init_completion(&patch->finish);

- return klp_init_object_early(patch, obj);
+ ret = klp_init_object_early(patch, obj);
+ if (!ret)
+ list_add_tail(&patch->list, &klp_patches);
+
+ return ret;
}

static int klp_init_patch(struct klp_patch *patch)
@@ -889,8 +894,6 @@ static int klp_init_patch(struct klp_patch *patch)
return ret;
}

- list_add_tail(&patch->list, &klp_patches);
-
return 0;
}

--
2.16.4