Skip to contentSkip to conversation

Hot unplug CPU 3/4

PATCH New Rusty Russell 1 participant 1 message Sep 13, 2002 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Hot unplug CPU 3/4

Name: set_cpus_allowed can fail
Author: Rusty Russell
Status: Tested on 2.5.30 SMP
Depends: Hotcpu/cpumask.patch.gz

D: Simply moves the "is this mask valid?" check inside set_cpus_allowed,
D: since it might be racy otherwise in the context of adding/removing
D: CPUs. This also introduces the CPU brlock.

arch/i386/kernel/smpboot.c +4 -2
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .32767-linux-2.5.33/arch/i386/kernel/smpboot.c .32767-linux-2.5.33.updated/arch/i386/kernel/smpboot.c
@@ -45,6 +45,7 @@
 
 #include <linux/delay.h>
 #include <linux/mc146818rtc.h>
+#include <linux/brlock.h>
 #include <asm/mtrr.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
@@ -458,8 +459,9 @@ int __init start_secondary(void *unused)
 	 * the local TLBs too.
 	 */
 	local_flush_tlb();
-	set_bit(smp_processor_id(), cpu_online_map);
-	wmb();
+	br_write_lock_irq(BR_CPU_LOCK);
+  	set_bit(smp_processor_id(), cpu_online_map);
+	br_write_unlock_irq(BR_CPU_LOCK);
 	return cpu_idle();
 }
 
arch/ppc/kernel/smp.c +3 -1
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .32767-linux-2.5.33/arch/ppc/kernel/smp.c .32767-linux-2.5.33.updated/arch/ppc/kernel/smp.c
@@ -432,7 +432,9 @@ int __cpu_up(unsigned int cpu)
 	printk("Processor %d found.\n", cpu);
 
 	smp_ops->give_timebase();
-	set_bit(cpu, cpu_online_map);
+	br_write_lock_irq(BR_CPU_LOCK);
+	set_bit(cpu, &cpu_online_map);
+	br_write_unlock_irq(BR_CPU_LOCK);
 	return 0;
 }
 
include/linux/brlock.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .32767-linux-2.5.33/include/linux/brlock.h .32767-linux-2.5.33.updated/include/linux/brlock.h
@@ -34,6 +34,7 @@
 /* Register bigreader lock indices here. */
 enum brlock_indices {
 	BR_NETPROTO_LOCK,
+	BR_CPU_LOCK,
 	__BR_END
 };
 
include/linux/sched.h +9 -4
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .32767-linux-2.5.33/include/linux/sched.h .32767-linux-2.5.33.updated/include/linux/sched.h
@@ -425,9 +425,14 @@ do { if (atomic_dec_and_test(&(tsk)->usa
 #define _STK_LIM	(8*1024*1024)
 
 #if CONFIG_SMP
-extern void set_cpus_allowed(task_t *p, const unsigned long new_mask[]);
+extern int set_cpus_allowed(task_t *p, const unsigned long new_mask[]);
 #else
-# define set_cpus_allowed(p, new_mask) do { } while (0)
+static inline int set_cpus_allowed(struct task_struct *p,
+				   const unsigned long *new_mask)
+{
+	if (!(*new_mask & 1)) return -EINVAL;
+	return 0;
+}
 #endif
 #define CPU_MASK_NONE { 0 }
 #define CPU_MASK_ALL { [0 ... BITS_TO_LONG(NR_CPUS)-1 ] = ~0UL }
@@ -435,9 +440,9 @@ extern void set_cpus_allowed(task_t *p, 
 static inline void migrate_to_cpu(unsigned int cpu)
 {
 	DECLARE_BITMAP(mask, NR_CPUS) = CPU_MASK_NONE;
-	BUG_ON(!cpu_online(cpu));
 	__set_bit(cpu, mask);
-	set_cpus_allowed(current, mask);
+	if (set_cpus_allowed(current, mask) != 0)
+		BUG();
 }
 
 extern void set_user_nice(task_t *p, long nice);
kernel/sched.c +23 -18

92 lines not on this page · raw message

--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.