On Thu, 4 Feb 2016, Petr Mladek wrote: > On Mon 2016-02-01 20:17:36, Jessica Yu wrote: > > > > > > - if (patch->state == KLP_DISABLED) > > - goto disabled; > > + ret = klp_init_object_loaded(patch, obj); > > + if (ret) { > > + pr_warn("failed to initialize patch '%s' for module '%s' (%d)\n", > > + patch->mod->name, obj->mod->name, ret); > > + goto err; > > + } > > + > > + if (patch->state == KLP_DISABLED) > > + break; > > > > - pr_notice("reverting patch '%s' on unloading module '%s'\n", > > - pmod->name, mod->name); > > + pr_notice("applying patch '%s' to loading module '%s'\n", > > + patch->mod->name, obj->mod->name); > > > > - klp_disable_object(obj); > > + ret = klp_enable_object(obj); > > + if (ret) { > > + pr_warn("failed to apply patch '%s' to module '%s' (%d)\n", > > + patch->mod->name, obj->mod->name, ret); > > + goto err; > > + } > > + > > + break; > > + } > > + } > > + > > + mutex_unlock(&klp_mutex); > > > > -disabled: > > - klp_free_object_loaded(obj); > > + return 0; > > + > > +err: > > + /* > > + * If a patch is unsuccessfully applied, return > > + * error to the module loader. > > + */ > > + obj->mod = NULL; > > + pr_warn("patch '%s' is in an inconsistent state!\n", patch->mod->name); > > This message is not correct. The module will not get loaded > when the patch is not applied. Yes, because we are in a better situation with this patch. We actually return an error and refuse to load the module. Message should take that into account. > Instead, we need to revert all the operations that has already > been done for this module. Note that the module stayed loaded > before, so we did not need to release any memory or revert > any ftrace call registration but we need to do so now! Actually, I think the code is correct. If klp_init_object_loaded() there is no problem because we only write relocations there (which are written to the module being loaded) and resolve symbols via kallsyms. Nothing to revert there and it could be done again. If klp_enable_object() fails, all the relevant error handling was already done there. See the call to klp_disable_object() if klp_enable_function() fails there. Miroslav -- To unsubscribe from this list: send the line "unsubscribe live-patching" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html