All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: "Chen, Dennis (SRDC SW)" <Dennis1.Chen@amd.com>,
	Rusty Russell <rusty@ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] Refine mutex and rcu method in module.c, kernel<3.2.9>
Date: Sun, 11 Mar 2012 07:56:27 -0700	[thread overview]
Message-ID: <20120311145627.GD2404@linux.vnet.ibm.com> (raw)
In-Reply-To: <4F5AD7F6.2000509@gmail.com>

On Sat, Mar 10, 2012 at 12:26:30PM +0800, Cong Wang wrote:
> 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.

I believe that these use either stop-machine or synchronize_sched()
for updates, so disabling preemption will work for readers.

							Thanx, Paul


      reply	other threads:[~2012-03-11 14:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-07 14:51 [PATCH 1/2] Refine mutex and rcu method in module.c, kernel<3.2.9> 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
2012-03-11 14:56         ` Paul E. McKenney [this message]

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=20120311145627.GD2404@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Dennis1.Chen@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@ozlabs.org \
    --cc=xiyou.wangcong@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.