From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934559AbcBDQsE (ORCPT ); Thu, 4 Feb 2016 11:48:04 -0500 Received: from mx2.suse.de ([195.135.220.15]:58971 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934466AbcBDQsB (ORCPT ); Thu, 4 Feb 2016 11:48:01 -0500 Date: Thu, 4 Feb 2016 17:47:57 +0100 (CET) From: Miroslav Benes To: Petr Mladek cc: Jessica Yu , Josh Poimboeuf , Seth Jennings , Jiri Kosina , Vojtech Pavlik , Rusty Russell , Steven Rostedt , Ingo Molnar , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] livepatch/module: remove livepatch module notifier In-Reply-To: <20160204143934.GZ3305@pathway.suse.cz> Message-ID: References: <1454375856-27757-1-git-send-email-jeyu@redhat.com> <1454375856-27757-3-git-send-email-jeyu@redhat.com> <20160204143934.GZ3305@pathway.suse.cz> User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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