From: Petr Mladek <pmladek@suse.com> To: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>, Jason Baron <jbaron@akamai.com>, Joe Lawrence <joe.lawrence@redhat.com>, Evgenii Shatokhin <eshatokhin@virtuozzo.com>, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v13 06/12] livepatch: Simplify API by removing registration step Date: Thu, 18 Oct 2018 14:33:29 +0200 Message-ID: <20181018123329.5xvo5hjtqpbih4d2@pathway.suse.cz> (raw) In-Reply-To: <20181017190657.dv3kwx467brzhdnz@treble> On Wed 2018-10-17 14:06:57, Josh Poimboeuf wrote: > On Mon, Oct 15, 2018 at 02:37:07PM +0200, Petr Mladek wrote: > > @@ -319,96 +316,66 @@ forced it is guaranteed that no task sleeps or runs in the old code. > > 5. Livepatch life-cycle > > ======================= > > > > -Livepatching defines four basic operations that define the life cycle of each > > -live patch: registration, enabling, disabling and unregistration. There are > > -several reasons why it is done this way. > > +Livepatches get automatically enabled when the respective module is loaded. > > (only true if the module enables the patch in its init function) Great catch! Will fix it. > > @@ -502,6 +483,9 @@ static void klp_free_objects(struct klp_patch *patch) > > } > > > > /* > > + * The synchronous variant is needed when the patch is freed in > > + * the klp_enable_patch() error paths. > > + * > > Hm? This comment seems confusingly out of context. Ah, the comment is just a left over from the previous version. It does not longer make sense. I'll remove it. > > @@ -528,6 +512,23 @@ static void klp_free_patch_finish(struct klp_patch *patch) > > kobject_put(&patch->kobj); > > wait_for_completion(&patch->finish); > > } > > + > > + /* Put the module after the last access to struct klp_patch. */ > > + if (patch->module_put) > > + module_put(patch->mod); > > +} > > + > > +/* > > + * The livepatch might be freed from sysfs interface created by the patch. > > + * This work allows to wait until the interface is destroyed in a separate > > + * context. > > + */ > > +static void klp_free_patch_fn(struct work_struct *work) > > To clarify that it's a work function, how about calling it > "klp_free_patch_work_fn"? OK > > static int klp_init_func(struct klp_object *obj, struct klp_func *func) > > @@ -642,116 +643,38 @@ static int klp_init_patch(struct klp_patch *patch) > > struct klp_object *obj; > > int ret; > > > > - if (!patch->objs) > > - return -EINVAL; > > - > > - mutex_lock(&klp_mutex); > > - > > patch->enabled = false; > > - patch->forced = false; > > + patch->module_put = false; > > INIT_LIST_HEAD(&patch->list); > > + INIT_WORK(&patch->free_work, klp_free_patch_fn); > > init_completion(&patch->finish); > > > > + if (!patch->objs) > > + return -EINVAL; > > + > > + /* > > + * A reference is taken on the patch module to prevent it from being > > + * unloaded. > > + */ > > + if (!try_module_get(patch->mod)) > > + return -ENODEV; > > This comment isn't needed. It describes what try_module_get() does, > which is common kernel knowledge. Yup. I'll remove it. Note that it was there even before. I have just moved it with the code. > > + patch->module_put = true; > > The naming and semantics of the 'module_put' field are a little > confusing. It's false in two cases: > > 1) try_module_get() failure > 2) forced patch > > Maybe we can get rid of the need for the first case by moving the > try_module_get() call to klp_enable_patch(), before calling > klp_init_lists(). Then klp_free_patch_finish() will always be called > with a module reference, so it doesn't have to check the 'module_put' > field. > > We'd still need it for the force case, but then it can just be called > 'forced' again. Great idea! I'll do it in v14. > > --- a/samples/livepatch/livepatch-callbacks-demo.c > > +++ b/samples/livepatch/livepatch-callbacks-demo.c > > @@ -184,22 +184,11 @@ static struct klp_patch patch = { > > > > static int livepatch_callbacks_demo_init(void) > > { > > - int ret; > > - > > - ret = klp_register_patch(&patch); > > - if (ret) > > - return ret; > > - ret = klp_enable_patch(&patch); > > - if (ret) { > > - WARN_ON(klp_unregister_patch(&patch)); > > - return ret; > > - } > > - return 0; > > + return klp_enable_patch(&patch); > > } > > > > static void livepatch_callbacks_demo_exit(void) > > { > > - WARN_ON(klp_unregister_patch(&patch)); > > } > > This module exit function is no longer needed. I have been there ;-) It is required. Otherewise the module can't get removed. See the following code in kernel/module.c: SYSCALL_DEFINE2(delete_module, const char __user *, name_user, unsigned int, flags) { [...] /* If it has an init func, it must have an exit func to unload */ if (mod->init && !mod->exit) { forced = try_force_unload(flags); if (!forced) { /* This module can't be removed */ ret = -EBUSY; goto out; } } Best Regards, Petr
next prev parent reply index Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-10-15 12:37 [PATCH v13 00/12] livepatch: Atomic replace feature Petr Mladek 2018-10-15 12:37 ` [PATCH v13 01/12] livepatch: Change void *new_func -> unsigned long new_addr in struct klp_func Petr Mladek 2018-10-15 12:37 ` [PATCH v13 02/12] livepatch: Helper macros to define livepatch structures Petr Mladek 2018-10-17 18:17 ` Josh Poimboeuf 2018-10-18 11:11 ` Petr Mladek 2018-10-18 12:58 ` Josh Poimboeuf 2018-10-24 11:28 ` Petr Mladek 2018-11-21 12:17 ` Miroslav Benes 2018-10-15 12:37 ` [PATCH v13 03/12] livepatch: Shuffle klp_enable_patch()/klp_disable_patch() code Petr Mladek 2018-10-15 12:37 ` [PATCH v13 04/12] livepatch: Consolidate klp_free functions Petr Mladek 2018-10-17 18:22 ` Josh Poimboeuf 2018-10-18 11:40 ` Petr Mladek 2018-11-21 13:59 ` Miroslav Benes 2018-11-21 14:40 ` Petr Mladek 2018-10-15 12:37 ` [PATCH v13 05/12] livepatch: Refuse to unload only livepatches available during a forced transition Petr Mladek 2018-10-17 18:35 ` Josh Poimboeuf 2018-10-18 12:09 ` Petr Mladek 2018-10-18 13:00 ` Josh Poimboeuf 2018-10-15 12:37 ` [PATCH v13 06/12] livepatch: Simplify API by removing registration step Petr Mladek 2018-10-17 19:06 ` Josh Poimboeuf 2018-10-18 12:33 ` Petr Mladek [this message] 2018-10-15 12:37 ` [PATCH v13 07/12] livepatch: Use lists to manage patches, objects and functions Petr Mladek 2018-10-17 20:31 ` Josh Poimboeuf 2018-10-18 12:34 ` Petr Mladek 2018-10-15 12:37 ` [PATCH v13 08/12] livepatch: Add atomic replace Petr Mladek 2018-11-23 12:00 ` Miroslav Benes 2018-10-15 12:37 ` [PATCH v13 09/12] livepatch: Remove Nop structures when unused Petr Mladek 2018-10-17 20:48 ` Josh Poimboeuf 2018-10-18 12:40 ` Petr Mladek 2018-10-15 12:37 ` [PATCH v13 10/12] livepatch: Atomic replace and cumulative patches documentation Petr Mladek 2018-10-15 12:37 ` [PATCH v13 11/12] livepatch: Remove ordering and refuse loading conflicting patches Petr Mladek 2018-10-15 12:37 ` [PATCH v13 12/12] selftests/livepatch: introduce tests Petr Mladek 2018-10-15 19:46 ` Joe Lawrence 2018-10-17 20:48 ` Josh Poimboeuf 2018-10-18 13:34 ` [PATCH v13 00/12] livepatch: Atomic replace feature Josh Poimboeuf
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20181018123329.5xvo5hjtqpbih4d2@pathway.suse.cz \ --to=pmladek@suse.com \ --cc=eshatokhin@virtuozzo.com \ --cc=jbaron@akamai.com \ --cc=jikos@kernel.org \ --cc=joe.lawrence@redhat.com \ --cc=jpoimboe@redhat.com \ --cc=linux-kernel@vger.kernel.org \ --cc=live-patching@vger.kernel.org \ --cc=mbenes@suse.cz \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
LKML Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \ linux-kernel@vger.kernel.org public-inbox-index lkml Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel AGPL code for this site: git clone https://public-inbox.org/public-inbox.git