lkml.org 
[lkml]   [2012]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] Refine mutex and rcu method in module.c, kernel<3.2.9>
Date
1. Add protection code for module_bug_list readers
2. Add a new module_bug_mutex as the mutex of the module_bug_list writers

--- bug.ori.c 2012-03-07 20:42:56.454850872 +0800
+++ bug.c 2012-03-07 20:58:48.562825887 +0800
@@ -42,6 +42,7 @@
#include <linux/kernel.h>
#include <linux/bug.h>
#include <linux/sched.h>
+#include <linux/rcupdate.h>

extern const struct bug_entry __start___bug_table[], __stop___bug_table[];

@@ -56,19 +57,24 @@

#ifdef CONFIG_MODULES
static LIST_HEAD(module_bug_list);
+static DEFINE_MUTEX(module_bug_mutex);

static const struct bug_entry *module_find_bug(unsigned long bugaddr)
{
struct module *mod;

- list_for_each_entry(mod, &module_bug_list, bug_list) {
+ rcu_read_lock();
+ list_for_each_entry_rcu(mod, &module_bug_list, bug_list) {
const struct bug_entry *bug = mod->bug_table;
unsigned i;

for (i = 0; i < mod->num_bugs; ++i, ++bug)
- if (bugaddr == bug_addr(bug))
+ if (bugaddr == bug_addr(bug)){
+ rcu_read_unlock();
return bug;
+ }
}
+ rcu_read_unlock();
return NULL;
}

@@ -96,7 +102,9 @@
* traversals, but since we only traverse on BUG()s, a spinlock
* could potentially lead to deadlock and thus be counter-productive.
*/
- list_add(&mod->bug_list, &module_bug_list);
+ mutex_lock(&module_bug_mutex);
+ list_add_rcu(&mod->bug_list, &module_bug_list);
+ mutex_unlock(&module_bug_mutex);
}

void module_bug_cleanup(struct module *mod)


\
 
 \ /
  Last update: 2012-03-07 16:11    [W:0.132 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site