mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: "Chen, Dennis (SRDC SW)" <Dennis1.Chen@amd.com>
Cc: Rusty Russell <rusty@ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH 1/2] Refine mutex and rcu method in module.c, kernel<3.2.9>
Date: Sat, 10 Mar 2012 12:26:30 +0800	[thread overview]
Message-ID: <4F5AD7F6.2000509@gmail.com> (raw)
In-Reply-To: <491D6B4EAD0A714894D8AD22F4BDE043032A5E@SCYBEXDAG04.amd.com>

On 03/09/2012 12:13 AM, Chen, Dennis (SRDC SW) wrote:
> Hi Rusty,
>
> Pls notice the following change in the patch (in set_all_modules_text_ro function):
>
> /* Iterate through all modules and set each module's text as RO */
> @@ -1693,7 +1699,7 @@
>   {
>          struct module *mod;
>
> -       mutex_lock(&module_mutex);
> +       rcu_read_lock();
>          list_for_each_entry_rcu(mod,&modules, list) {
>                  if ((mod->module_core)&&  (mod->core_text_size)) {
>                          set_page_attributes(mod->module_core,
> @@ -1706,7 +1712,7 @@
>                                                  set_memory_ro);
>                  }
>          }
> -       mutex_unlock(&module_mutex);
> +       rcu_read_unlock();
>   }
>
> This function just needs to iterate the modules list, but now it holds a unnecessary lock when it does that,
> The other module can't be inserted during this operation, also can you make sure the set_page_attributes will
> run smoothly all the time, if not it's a risk action to hold a lock.
> So summary--
> I think the idea for kernel module protection is simple:
> Writers to modules, use mutex_lock
> Readers, use rcu. __ALL__ codes here should be with a unified style! This will make our kernel gracefully.
>
> PS: my comments in the patch " /* Concurrent writers for the global modules list are protected by RCU*/" is not right, RCU
> Should be mutex lock.

I think your change makes sense, I don't know why preempt_disable() was 
used, git blame told me the related two commits are 4 years-old...

cb2a5205 2008-01-14 00:55:03 -0800 3180
d72b3751 2008-08-30 10:09:00 +0200 3181

maybe at that time rcu was not what it is today... Cc'ing Paul.

  reply	other threads:[~2012-03-10  4:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-07 14:51 Chen, Dennis (SRDC SW)
2012-03-07 14:57 ` [PATCH 2/2] " Chen, Dennis (SRDC SW)
2012-03-07 16:48   ` Chen, Dennis (SRDC SW)
2012-03-10  3:44     ` Cong Wang
2012-03-07 15:37 ` [PATCH 1/2] " Cong Wang
2012-03-07 15:52   ` Chen, Dennis (SRDC SW)
2012-03-10  3:42     ` Cong Wang
2012-03-07 16:46 ` Chen, Dennis (SRDC SW)
2012-03-08  9:18 ` Rusty Russell
2012-03-08 12:18   ` Chen, Dennis (SRDC SW)
2012-03-08 16:13     ` Chen, Dennis (SRDC SW)
2012-03-10  4:26       ` Cong Wang [this message]
2012-03-11 14:56         ` Paul E. McKenney

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=4F5AD7F6.2000509@gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=Dennis1.Chen@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=rusty@ozlabs.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome