aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorWang YanQing <udknight@gmail.com>2013-01-26 02:53:57 -0500
committerIngo Molnar <mingo@kernel.org>2013-01-28 05:21:57 -0500
commitf44310b98ddb7f0d06550d73ed67df5865e3eda5 (patch)
tree77696b4312a7450afcc24c478df4721eda2f777f /kernel
parentc903f0456bc69176912dee6dd25c6a66ee1aed00 (diff)
smp: Fix SMP function call empty cpu mask race
I get the following warning every day with v3.7, once or twice a day: [ 2235.186027] WARNING: at /mnt/sda7/kernel/linux/arch/x86/kernel/apic/ipi.c:109 default_send_IPI_mask_logical+0x2f/0xb8() As explained by Linus as well: | | Once we've done the "list_add_rcu()" to add it to the | queue, we can have (another) IPI to the target CPU that can | now see it and clear the mask. | | So by the time we get to actually send the IPI, the mask might | have been cleared by another IPI. | This patch also fixes a system hang problem, if the data->cpumask gets cleared after passing this point: if (WARN_ONCE(!mask, "empty IPI mask")) return; then the problem in commit 83d349f35e1a ("x86: don't send an IPI to the empty set of CPU's") will happen again. Signed-off-by: Wang YanQing <udknight@gmail.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Jan Beulich <jbeulich@suse.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: peterz@infradead.org Cc: mina86@mina86.org Cc: srivatsa.bhat@linux.vnet.ibm.com Cc: <stable@kernel.org> Link: http://lkml.kernel.org/r/20130126075357.GA3205@udknight [ Tidied up the changelog and the comment in the code. ] Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/smp.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/kernel/smp.c b/kernel/smp.c
index 29dd40a9f2f4..69f38bd98b42 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -33,6 +33,7 @@ struct call_function_data {
33 struct call_single_data csd; 33 struct call_single_data csd;
34 atomic_t refs; 34 atomic_t refs;
35 cpumask_var_t cpumask; 35 cpumask_var_t cpumask;
36 cpumask_var_t cpumask_ipi;
36}; 37};
37 38
38static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_function_data, cfd_data); 39static DEFINE_PER_CPU_SHARED_ALIGNED(struct call_function_data, cfd_data);
@@ -56,6 +57,9 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
56 if (!zalloc_cpumask_var_node(&cfd->cpumask, GFP_KERNEL, 57 if (!zalloc_cpumask_var_node(&cfd->cpumask, GFP_KERNEL,
57 cpu_to_node(cpu))) 58 cpu_to_node(cpu)))
58 return notifier_from_errno(-ENOMEM); 59 return notifier_from_errno(-ENOMEM);
60 if (!zalloc_cpumask_var_node(&cfd->cpumask_ipi, GFP_KERNEL,
61 cpu_to_node(cpu)))
62 return notifier_from_errno(-ENOMEM);
59 break; 63 break;
60 64
61#ifdef CONFIG_HOTPLUG_CPU 65#ifdef CONFIG_HOTPLUG_CPU
@@ -65,6 +69,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
65 case CPU_DEAD: 69 case CPU_DEAD:
66 case CPU_DEAD_FROZEN: 70 case CPU_DEAD_FROZEN:
67 free_cpumask_var(cfd->cpumask); 71 free_cpumask_var(cfd->cpumask);
72 free_cpumask_var(cfd->cpumask_ipi);
68 break; 73 break;
69#endif 74#endif
70 }; 75 };
@@ -526,6 +531,12 @@ void smp_call_function_many(const struct cpumask *mask,
526 return; 531 return;
527 } 532 }
528 533
534 /*
535 * After we put an entry into the list, data->cpumask
536 * may be cleared again when another CPU sends another IPI for
537 * a SMP function call, so data->cpumask will be zero.
538 */
539 cpumask_copy(data->cpumask_ipi, data->cpumask);
529 raw_spin_lock_irqsave(&call_function.lock, flags); 540 raw_spin_lock_irqsave(&call_function.lock, flags);
530 /* 541 /*
531 * Place entry at the _HEAD_ of the list, so that any cpu still 542 * Place entry at the _HEAD_ of the list, so that any cpu still
@@ -549,7 +560,7 @@ void smp_call_function_many(const struct cpumask *mask,
549 smp_mb(); 560 smp_mb();
550 561
551 /* Send a message to all CPUs in the map */ 562 /* Send a message to all CPUs in the map */
552 arch_send_call_function_ipi_mask(data->cpumask); 563 arch_send_call_function_ipi_mask(data->cpumask_ipi);
553 564
554 /* Optionally wait for the CPUs to complete */ 565 /* Optionally wait for the CPUs to complete */
555 if (wait) 566 if (wait)