mirror of https://gitee.com/openkylin/linux.git
livepatch: Don't block the removal of patches loaded after a forced transition
module_put() is currently never called in klp_complete_transition() when klp_force is set. As a result, we might keep the reference count even when klp_enable_patch() fails and klp_cancel_transition() is called. This might give the impression that a module might get blocked in some strange init state. Fortunately, it is not the case. The reference count is ignored when mod->init fails and erroneous modules are always removed. Anyway, this might be confusing. Instead, this patch moves the global klp_forced flag into struct klp_patch. As a result, we block only modules that might still be in use after a forced transition. Newly loaded livepatches might be eventually completely removed later. It is not a big deal. But the code is at least consistent with the reality. Signed-off-by: Petr Mladek <pmladek@suse.com> Acked-by: Joe Lawrence <joe.lawrence@redhat.com> Acked-by: Miroslav Benes <mbenes@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
0430f78bf3
commit
68007289bf
|
@ -143,6 +143,7 @@ struct klp_object {
|
|||
* @kobj: kobject for sysfs resources
|
||||
* @kobj_added: @kobj has been added and needs freeing
|
||||
* @enabled: the patch is enabled (but operation may be incomplete)
|
||||
* @forced: was involved in a forced transition
|
||||
* @finish: for waiting till it is safe to remove the patch module
|
||||
*/
|
||||
struct klp_patch {
|
||||
|
@ -155,6 +156,7 @@ struct klp_patch {
|
|||
struct kobject kobj;
|
||||
bool kobj_added;
|
||||
bool enabled;
|
||||
bool forced;
|
||||
struct completion finish;
|
||||
};
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
*/
|
||||
DEFINE_MUTEX(klp_mutex);
|
||||
|
||||
static LIST_HEAD(klp_patches);
|
||||
/* Registered patches */
|
||||
LIST_HEAD(klp_patches);
|
||||
|
||||
static struct kobject *klp_root_kobj;
|
||||
|
||||
|
@ -659,6 +660,7 @@ static int klp_init_patch_early(struct klp_patch *patch)
|
|||
INIT_LIST_HEAD(&patch->list);
|
||||
patch->kobj_added = false;
|
||||
patch->enabled = false;
|
||||
patch->forced = false;
|
||||
init_completion(&patch->finish);
|
||||
|
||||
klp_for_each_object(patch, obj) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <linux/livepatch.h>
|
||||
|
||||
extern struct mutex klp_mutex;
|
||||
extern struct list_head klp_patches;
|
||||
|
||||
static inline bool klp_is_object_loaded(struct klp_object *obj)
|
||||
{
|
||||
|
|
|
@ -33,8 +33,6 @@ struct klp_patch *klp_transition_patch;
|
|||
|
||||
static int klp_target_state = KLP_UNDEFINED;
|
||||
|
||||
static bool klp_forced = false;
|
||||
|
||||
/*
|
||||
* This work can be performed periodically to finish patching or unpatching any
|
||||
* "straggler" tasks which failed to transition in the first attempt.
|
||||
|
@ -137,10 +135,10 @@ static void klp_complete_transition(void)
|
|||
klp_target_state == KLP_PATCHED ? "patching" : "unpatching");
|
||||
|
||||
/*
|
||||
* klp_forced set implies unbounded increase of module's ref count if
|
||||
* patch->forced set implies unbounded increase of module's ref count if
|
||||
* the module is disabled/enabled in a loop.
|
||||
*/
|
||||
if (!klp_forced && klp_target_state == KLP_UNPATCHED)
|
||||
if (!klp_transition_patch->forced && klp_target_state == KLP_UNPATCHED)
|
||||
module_put(klp_transition_patch->mod);
|
||||
|
||||
klp_target_state = KLP_UNDEFINED;
|
||||
|
@ -620,6 +618,7 @@ void klp_send_signals(void)
|
|||
*/
|
||||
void klp_force_transition(void)
|
||||
{
|
||||
struct klp_patch *patch;
|
||||
struct task_struct *g, *task;
|
||||
unsigned int cpu;
|
||||
|
||||
|
@ -633,5 +632,6 @@ void klp_force_transition(void)
|
|||
for_each_possible_cpu(cpu)
|
||||
klp_update_patch_state(idle_task(cpu));
|
||||
|
||||
klp_forced = true;
|
||||
list_for_each_entry(patch, &klp_patches, list)
|
||||
patch->forced = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue