All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: missing locking in sched_domains code
@ 2008-04-27 21:12 Heiko Carstens
  2008-04-28  1:39 ` Andrew Morton
  0 siblings, 1 reply; 15+ messages in thread
From: Heiko Carstens @ 2008-04-27 21:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Gautham R Shenoy, Ingo Molnar, Paul Jackson, linux-kernel

From: Heiko Carstens <heiko.carstens@de.ibm.com>

Concurrent calls to detach_destroy_domains and arch_init_sched_domains
were prevented by the old scheduler subsystem cpu hotplug mutex. When
this got converted to get_online_cpus() the locking got broken.
Unlike before now several processes can concurrently enter the critical
sections that were protected by the old lock.

So add a new sched_domains_mutex which protects these sections again.

Cc: Gautham R Shenoy <ego@in.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Jackson <pj@sgi.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
---
 include/linux/sched.h |    2 ++
 kernel/cpuset.c       |    2 ++
 kernel/sched.c        |   11 +++++++++++
 3 files changed, 15 insertions(+)

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -7807,14 +7807,23 @@ match2:
 	unlock_doms_cur();
 }
 
+/*
+ * Protects against concurrent calls to detach_destroy_domains
+ * and arch_init_sched_domains.
+ */
+DEFINE_MUTEX(sched_domains_mutex);
+
 #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
 int arch_reinit_sched_domains(void)
 {
+	static DEFINE_MUTEX(arch_reinit_sched_domains_mutex);
 	int err;
 
 	get_online_cpus();
+	mutex_lock(&sched_domains_mutex);
 	detach_destroy_domains(&cpu_online_map);
 	err = arch_init_sched_domains(&cpu_online_map);
+	mutex_unlock(&sched_domains_mutex);
 	put_online_cpus();
 
 	return err;
@@ -7932,10 +7941,12 @@ void __init sched_init_smp(void)
 	BUG_ON(sched_group_nodes_bycpu == NULL);
 #endif
 	get_online_cpus();
+	mutex_lock(&sched_domains_mutex);
 	arch_init_sched_domains(&cpu_online_map);
 	cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map);
 	if (cpus_empty(non_isolated_cpus))
 		cpu_set(smp_processor_id(), non_isolated_cpus);
+	mutex_unlock(&sched_domains_mutex);
 	put_online_cpus();
 	/* XXX: Theoretical race here - CPU may be hotplugged now */
 	hotcpu_notifier(update_sched_domains, 0);
Index: linux-2.6/include/linux/sched.h
===================================================================
--- linux-2.6.orig/include/linux/sched.h
+++ linux-2.6/include/linux/sched.h
@@ -809,6 +809,8 @@ struct sched_domain {
 #endif
 };
 
+extern struct mutex sched_domains_mutex;
+
 extern void partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
 				    struct sched_domain_attr *dattr_new);
 extern int arch_reinit_sched_domains(void);
Index: linux-2.6/kernel/cpuset.c
===================================================================
--- linux-2.6.orig/kernel/cpuset.c
+++ linux-2.6/kernel/cpuset.c
@@ -684,7 +684,9 @@ restart:
 rebuild:
 	/* Have scheduler rebuild sched domains */
 	get_online_cpus();
+	mutex_lock(&sched_domains_mutex);
 	partition_sched_domains(ndoms, doms, dattr);
+	mutex_unlock(&sched_domains_mutex);
 	put_online_cpus();
 
 done:

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-04-28 13:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-27 21:12 [PATCH] sched: missing locking in sched_domains code Heiko Carstens
2008-04-28  1:39 ` Andrew Morton
2008-04-28  7:09   ` Heiko Carstens
2008-04-28  7:24     ` Ingo Molnar
2008-04-28  7:28     ` Andrew Morton
2008-04-28  7:52       ` Heiko Carstens
2008-04-28  8:11         ` Heiko Carstens
2008-04-28  8:32           ` Ingo Molnar
2008-04-28  8:49             ` Heiko Carstens
2008-04-28  8:57               ` Andrew Morton
2008-04-28  9:17                 ` Heiko Carstens
2008-04-28  9:31                   ` Andrew Morton
2008-04-28  9:33                   ` Heiko Carstens
2008-04-28 12:27                     ` Ingo Molnar
2008-04-28 13:13                     ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.