Commit 2f1dafe5 authored by Pekka Paalanen's avatar Pekka Paalanen Committed by Thomas Gleixner

x86: fix SMP alternatives: use mutex instead of spinlock, text_poke is sleepable

text_poke is sleepable.
The original fix by Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>.
Signed-off-by: default avatarPekka Paalanen <pq@iki.fi>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 107bad8b
#include <linux/module.h> #include <linux/module.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/spinlock.h> #include <linux/mutex.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/mm.h> #include <linux/mm.h>
...@@ -279,7 +279,7 @@ struct smp_alt_module { ...@@ -279,7 +279,7 @@ struct smp_alt_module {
struct list_head next; struct list_head next;
}; };
static LIST_HEAD(smp_alt_modules); static LIST_HEAD(smp_alt_modules);
static DEFINE_SPINLOCK(smp_alt); static DEFINE_MUTEX(smp_alt);
static int smp_mode = 1; /* protected by smp_alt */ static int smp_mode = 1; /* protected by smp_alt */
void alternatives_smp_module_add(struct module *mod, char *name, void alternatives_smp_module_add(struct module *mod, char *name,
...@@ -312,12 +312,12 @@ void alternatives_smp_module_add(struct module *mod, char *name, ...@@ -312,12 +312,12 @@ void alternatives_smp_module_add(struct module *mod, char *name,
__func__, smp->locks, smp->locks_end, __func__, smp->locks, smp->locks_end,
smp->text, smp->text_end, smp->name); smp->text, smp->text_end, smp->name);
spin_lock(&smp_alt); mutex_lock(&smp_alt);
list_add_tail(&smp->next, &smp_alt_modules); list_add_tail(&smp->next, &smp_alt_modules);
if (boot_cpu_has(X86_FEATURE_UP)) if (boot_cpu_has(X86_FEATURE_UP))
alternatives_smp_unlock(smp->locks, smp->locks_end, alternatives_smp_unlock(smp->locks, smp->locks_end,
smp->text, smp->text_end); smp->text, smp->text_end);
spin_unlock(&smp_alt); mutex_unlock(&smp_alt);
} }
void alternatives_smp_module_del(struct module *mod) void alternatives_smp_module_del(struct module *mod)
...@@ -327,17 +327,17 @@ void alternatives_smp_module_del(struct module *mod) ...@@ -327,17 +327,17 @@ void alternatives_smp_module_del(struct module *mod)
if (smp_alt_once || noreplace_smp) if (smp_alt_once || noreplace_smp)
return; return;
spin_lock(&smp_alt); mutex_lock(&smp_alt);
list_for_each_entry(item, &smp_alt_modules, next) { list_for_each_entry(item, &smp_alt_modules, next) {
if (mod != item->mod) if (mod != item->mod)
continue; continue;
list_del(&item->next); list_del(&item->next);
spin_unlock(&smp_alt); mutex_unlock(&smp_alt);
DPRINTK("%s: %s\n", __func__, item->name); DPRINTK("%s: %s\n", __func__, item->name);
kfree(item); kfree(item);
return; return;
} }
spin_unlock(&smp_alt); mutex_unlock(&smp_alt);
} }
void alternatives_smp_switch(int smp) void alternatives_smp_switch(int smp)
...@@ -359,7 +359,7 @@ void alternatives_smp_switch(int smp) ...@@ -359,7 +359,7 @@ void alternatives_smp_switch(int smp)
return; return;
BUG_ON(!smp && (num_online_cpus() > 1)); BUG_ON(!smp && (num_online_cpus() > 1));
spin_lock(&smp_alt); mutex_lock(&smp_alt);
/* /*
* Avoid unnecessary switches because it forces JIT based VMs to * Avoid unnecessary switches because it forces JIT based VMs to
...@@ -383,7 +383,7 @@ void alternatives_smp_switch(int smp) ...@@ -383,7 +383,7 @@ void alternatives_smp_switch(int smp)
mod->text, mod->text_end); mod->text, mod->text_end);
} }
smp_mode = smp; smp_mode = smp;
spin_unlock(&smp_alt); mutex_unlock(&smp_alt);
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment