[repost PATCH] Fix SMP alternatives : use mutex instead of spinlock, text_poke is sleepable

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Pekka Paalanen
Date: Tuesday, April 22, 2008 - 11:42 am

From 58390e93507669d860ef2d178b60ad447d5260c4 Mon Sep 17 00:00:00 2001
From: Pekka Paalanen <pq@iki.fi>
Date: Sat, 19 Apr 2008 23:22:11 +0300
Subject: [PATCH] x86: Fix SMP alternatives: use mutex instead of spinlock.

text_poke is sleepable.
The original fix by Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>.

Signed-off-by: Pekka Paalanen <pq@iki.fi>
---


Ingo,

I see you applied the NX fix. This patch is the other one needed to make
CPU hotplug working. Could you apply this, unless Mathieu has something
against it?

After this one I can resubmit the mmiotrace CPU auto-disable patch
(modified a bit). Though it will be a couple of days before I can get
back to coding.


Thanks.

 arch/x86/kernel/alternative.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 5412fd7..7ce0939 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -1,6 +1,6 @@
 #include <linux/module.h>
 #include <linux/sched.h>
-#include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/list.h>
 #include <linux/kprobes.h>
 #include <linux/mm.h>
@@ -279,7 +279,7 @@ struct smp_alt_module {
 	struct list_head next;
 };
 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 */
 
 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,
 		smp->text, smp->text_end, smp->name);
 
-	spin_lock(&smp_alt);
+	mutex_lock(&smp_alt);
 	list_add_tail(&smp->next, &smp_alt_modules);
 	if (boot_cpu_has(X86_FEATURE_UP))
 		alternatives_smp_unlock(smp->locks, smp->locks_end,
 					smp->text, smp->text_end);
-	spin_unlock(&smp_alt);
+	mutex_unlock(&smp_alt);
 }
 
 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)
 		return;
 
-	spin_lock(&smp_alt);
+	mutex_lock(&smp_alt);
 	list_for_each_entry(item, &smp_alt_modules, next) {
 		if (mod != item->mod)
 			continue;
 		list_del(&item->next);
-		spin_unlock(&smp_alt);
+		mutex_unlock(&smp_alt);
 		DPRINTK("%s: %s\n", __func__, item->name);
 		kfree(item);
 		return;
 	}
-	spin_unlock(&smp_alt);
+	mutex_unlock(&smp_alt);
 }
 
 void alternatives_smp_switch(int smp)
@@ -359,7 +359,7 @@ void alternatives_smp_switch(int smp)
 		return;
 	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
@@ -383,7 +383,7 @@ void alternatives_smp_switch(int smp)
 						mod->text, mod->text_end);
 	}
 	smp_mode = smp;
-	spin_unlock(&smp_alt);
+	mutex_unlock(&smp_alt);
 }
 
 #endif
-- 
1.5.3.7

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[BUG] kmalloc_node(GFP_KERNEL) while smp_alt spinlocked, Pekka Paalanen, (Sat Apr 19, 8:41 am)
[PATCH] Fix SMP alternatives : use mutex instead of spinlo ..., Mathieu Desnoyers, (Sat Apr 19, 9:19 am)
[PATCH] Check for breakpoint in text_poke to eliminate bug_on, Mathieu Desnoyers, (Sat Apr 19, 2:58 pm)
Re: [PATCH] Check for breakpoint in text_poke to eliminate ..., Mathieu Desnoyers, (Sat Apr 19, 5:05 pm)
Re: [PATCH] Check for breakpoint in text_poke to eliminate ..., Mathieu Desnoyers, (Sun Apr 20, 12:44 pm)
Re: [PATCH] Check for breakpoint in text_poke to eliminate ..., Mathieu Desnoyers, (Sun Apr 20, 1:25 pm)
[PATCH] x86_64: fix kernel rodata NX setting, Pekka Paalanen, (Mon Apr 21, 11:48 am)
Re: [PATCH] x86_64: fix kernel rodata NX setting, Steven Rostedt, (Mon Apr 21, 11:57 am)
Re: [PATCH] x86_64: fix kernel rodata NX setting, Ingo Molnar, (Mon Apr 21, 12:03 pm)
[repost PATCH] Fix SMP alternatives : use mutex instead of ..., Pekka Paalanen, (Tue Apr 22, 11:42 am)
Re: [repost PATCH] Fix SMP alternatives : use mutex instea ..., Mathieu Desnoyers, (Tue Apr 22, 1:22 pm)
[PATCH v2] x86 mmiotrace: dynamically disable non-boot CPUs, Pekka Paalanen, (Thu Apr 24, 12:39 pm)
Re: [Nouveau] [BUG/PATCH] x86 mmiotrace: dynamically disab ..., Stephane Marchesin, (Thu Jul 24, 8:34 am)