linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Cong Wang <xiyou.wangcong@gmail.com>, linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH 1/2] module: use rcu to protect module list read
Date: Tue, 13 Mar 2012 11:02:44 +1030	[thread overview]
Message-ID: <87mx7lz6fn.fsf@rustcorp.com.au> (raw)
In-Reply-To: <1331389203-3309-1-git-send-email-xiyou.wangcong@gmail.com>

On Sat, 10 Mar 2012 22:20:02 +0800, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> Now the read of module list is protected by preempt disable + *_rcu
> list operations, this is odd, as RCU read lock should be able to
> protect it directly. This patch makes the read of module list
> protected by RCU read lock and the write still protected by
> module_mutex.

OK, please split these patches further.  Locking is subtle, so it's
great to be able to bisect more finely if we catch a problem.

eg.  First replace all the preempt_disable()/enable with
rcu_read_lock()/unlock.  Then replace lock in set_all_modules_text.
And so on...
 
> @@ -1810,11 +1810,11 @@ void *__symbol_get(const char *symbol)
> 	struct module *owner;
> 	const struct kernel_symbol *sym;
> 
> -	preempt_disable();
> +	rcu_read_lock();
> 	sym = find_symbol(symbol, &owner, NULL, true, true);
> +	rcu_read_unlock();
> 	if (sym && strong_try_module_get(owner))
> 		sym = NULL;
> -	preempt_enable();
> 
> 	return sym ? (void *)sym->value : NULL;
>  }

This is wrong: the symbol can vanish between find_symbol() and
strong_try_module_get().  We need protection around the whole thing.

> @@ -3302,7 +3309,7 @@ static char *module_flags(struct module *mod, char *buf)
>  /* Called by the /proc file system to return a list of modules. */
>  static void *m_start(struct seq_file *m, loff_t *pos)
>  {
> -	mutex_lock(&module_mutex);
> +	rcu_read_lock();
>  	return seq_list_start(&modules, *pos);
>  }
>  
> @@ -3313,7 +3320,7 @@ static void *m_next(struct seq_file *m, void *p, loff_t *pos)
>  
>  static void m_stop(struct seq_file *m, void *p)
>  {
> -	mutex_unlock(&module_mutex);
> +	rcu_read_unlock();
>  }
>  
>  static int m_show(struct seq_file *m, void *p)

Interesting.  I assume that these functions needed to sleep.  But it
looks like I was wrong.

But the rest looks fine,
Rusty.
-- 
  How could I marry someone with more hair than me?  http://baldalex.org

  parent reply	other threads:[~2012-03-13  2:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-10 14:20 [PATCH 1/2] module: use rcu to protect module list read Cong Wang
2012-03-10 14:20 ` [PATCH 2/2] module: avoid exporting module_mutex Cong Wang
2012-03-10 15:25 ` [PATCH 1/2] module: use rcu to protect module list read Eric Dumazet
2012-03-11 10:53   ` Cong Wang
2012-03-13  0:37   ` Rusty Russell
2012-03-13 10:09     ` Cong Wang
2012-03-13  0:32 ` Rusty Russell [this message]
2012-03-13 10:12   ` Cong Wang

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=87mx7lz6fn.fsf@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).