Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1354522 > unrolled thread

[PATCH 2/3] modules: set mod->state to GOING before going notifiers are called

Started byJessica Yu <jeyu@redhat.com>
First post2016-03-09 23:20 +0100
Last post2016-03-10 06:10 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/3] modules: set mod->state to GOING before going notifiers are called Jessica Yu <jeyu@redhat.com> - 2016-03-09 23:20 +0100
    Re: [PATCH 2/3] modules: set mod->state to GOING before going notifiers are called Rusty Russell <rusty@rustcorp.com.au> - 2016-03-10 04:30 +0100
      Re: modules: set mod->state to GOING before going notifiers are  called Jessica Yu <jeyu@redhat.com> - 2016-03-10 06:10 +0100

#1354522 — [PATCH 2/3] modules: set mod->state to GOING before going notifiers are called

FromJessica Yu <jeyu@redhat.com>
Date2016-03-09 23:20 +0100
Subject[PATCH 2/3] modules: set mod->state to GOING before going notifiers are called
Message-ID<raUCt-63z-9@gated-at.bofh.it>
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 <jeyu@redhat.com>
---
 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);
 
-- 
2.4.3

[toc] | [next] | [standalone]


#1354823

FromRusty Russell <rusty@rustcorp.com.au>
Date2016-03-10 04:30 +0100
Message-ID<raZsu-Vy-13@gated-at.bofh.it>
In reply to#1354522
Jessica Yu <jeyu@redhat.com> 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 <jeyu@redhat.com>
> ---
>  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.

Sorry for the previously false lead,
Rusty.

[toc] | [prev] | [next] | [standalone]


#1354855 — Re: modules: set mod->state to GOING before going notifiers are called

FromJessica Yu <jeyu@redhat.com>
Date2016-03-10 06:10 +0100
SubjectRe: modules: set mod->state to GOING before going notifiers are called
Message-ID<rb11g-2cG-5@gated-at.bofh.it>
In reply to#1354823
+++ Rusty Russell [10/03/16 13:57 +1030]:
>Jessica Yu <jeyu@redhat.com> 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 <jeyu@redhat.com>
>> ---
>>  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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web