Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 232024
b: refs/heads/master
c: 6dc1989
h: refs/heads/master
v: v3
  • Loading branch information
Anton Blanchard authored and Linus Torvalds committed Jan 21, 2011
1 parent 4432e23 commit 98449d6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 713735b4233fad3ae35b5cad656baa41413887ca
refs/heads/master: 6dc19899958e420a931274b94019e267e2396d3e
30 changes: 30 additions & 0 deletions trunk/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,24 @@ void generic_smp_call_function_interrupt(void)
list_for_each_entry_rcu(data, &call_function.queue, csd.list) {
int refs;

/*
* Since we walk the list without any locks, we might
* see an entry that was completed, removed from the
* list and is in the process of being reused.
*
* We must check that the cpu is in the cpumask before
* checking the refs, and both must be set before
* executing the callback on this cpu.
*/

if (!cpumask_test_cpu(cpu, data->cpumask))
continue;

smp_rmb();

if (atomic_read(&data->refs) == 0)
continue;

if (!cpumask_test_and_clear_cpu(cpu, data->cpumask))
continue;

Expand All @@ -203,6 +221,8 @@ void generic_smp_call_function_interrupt(void)
refs = atomic_dec_return(&data->refs);
WARN_ON(refs < 0);
if (!refs) {
WARN_ON(!cpumask_empty(data->cpumask));

raw_spin_lock(&call_function.lock);
list_del_rcu(&data->csd.list);
raw_spin_unlock(&call_function.lock);
Expand Down Expand Up @@ -454,11 +474,21 @@ void smp_call_function_many(const struct cpumask *mask,

data = &__get_cpu_var(cfd_data);
csd_lock(&data->csd);
BUG_ON(atomic_read(&data->refs) || !cpumask_empty(data->cpumask));

data->csd.func = func;
data->csd.info = info;
cpumask_and(data->cpumask, mask, cpu_online_mask);
cpumask_clear_cpu(this_cpu, data->cpumask);

/*
* To ensure the interrupt handler gets an complete view
* we order the cpumask and refs writes and order the read
* of them in the interrupt handler. In addition we may
* only clear our own cpu bit from the mask.
*/
smp_wmb();

atomic_set(&data->refs, cpumask_weight(data->cpumask));

raw_spin_lock_irqsave(&call_function.lock, flags);
Expand Down

0 comments on commit 98449d6

Please sign in to comment.