Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965440AbcCJFIm (ORCPT ); Thu, 10 Mar 2016 00:08:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43943 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965262AbcCJFIk (ORCPT ); Thu, 10 Mar 2016 00:08:40 -0500 Date: Thu, 10 Mar 2016 00:08:31 -0500 From: Jessica Yu To: Rusty Russell Cc: Josh Poimboeuf , Seth Jennings , Jiri Kosina , Vojtech Pavlik , Miroslav Benes , Petr Mladek , Steven Rostedt , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: modules: set mod->state to GOING before going notifiers are called Message-ID: <20160310050830.GA31620@packer-debian-8-amd64.digitalocean.com> References: <1457561637-24770-1-git-send-email-jeyu@redhat.com> <1457561637-24770-3-git-send-email-jeyu@redhat.com> <87a8m7ko6j.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <87a8m7ko6j.fsf@rustcorp.com.au> X-OS: Linux eisen.io 3.16.0-4-amd64 x86_64 User-Agent: Mutt/1.5.23 (2014-03-12) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 10 Mar 2016 05:08:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1973 Lines: 49 +++ Rusty Russell [10/03/16 13:57 +1030]: >Jessica Yu writes: >> In load_module(), the going notifiers are called during error handling >> when an error occurs after the coming notifiers have already been called. >> However, a module's state is still MODULE_STATE_COMING when the going >> notifiers are called in the error path. To be consistent, also set >> mod->state to MODULE_STATE_GOING before calling the going notifiers. >> >> Signed-off-by: Jessica Yu >> --- >> kernel/module.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/kernel/module.c b/kernel/module.c >> index 1981ae0..9e80576 100644 >> --- a/kernel/module.c >> +++ b/kernel/module.c >> @@ -3494,6 +3494,9 @@ static int load_module(struct load_info *info, const char __user *uargs, >> return do_init_module(mod); >> >> coming_cleanup: >> + mutex_lock(&module_mutex); >> + mod->state = MODULE_STATE_GOING; >> + mutex_unlock(&module_mutex); >> blocking_notifier_call_chain(&module_notify_list, >> MODULE_STATE_GOING, mod); > >Actually, reviewing this patch makes me realize it is wrong. > >We rely on the state of the module being MODULE_STATE_COMING here: > > static inline int strong_try_module_get(struct module *mod) > { > BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED); > if (mod && mod->state == MODULE_STATE_COMING) > return -EBUSY; > >We will just have to document that the notifier can be called with >a module in MODULE_STATE_COMING if it never succeeded its >initialization. Ah, thanks for catching that. I think I remember seeing this conditional and assuming it wouldn't be a problem since GOING modules would fail in try_module_get() (as it is does not pass the module_is_live() test) and subsequently strong_try_module_get() would also fail.. But, I think I ought to review how module states interact before making a change like this, so, please ignore this patch. Jessica