Re: [RFC PATCH 02/10] smp, cpu hotplug: Fix smp_call_function_*()to prevent CPU offline properly

From: Srivatsa S. Bhat
Date: Wed Dec 05 2012 - 07:43:10 EST


On 12/05/2012 03:47 AM, Andrew Morton wrote:
> On Tue, 04 Dec 2012 14:24:28 +0530
> "Srivatsa S. Bhat" <srivatsa.bhat@xxxxxxxxxxxxxxxxxx> wrote:
>
>> From: Michael Wang <wangyun@xxxxxxxxxxxxxxxxxx>
>>
>> With stop_machine() gone from the CPU offline path, we can't depend on
>> preempt_disable() to prevent CPUs from going offline from under us.
>>
>> Use the get/put_online_cpus_stable_atomic() APIs to prevent CPUs from going
>> offline, while invoking from atomic context.
>>
>> ...
>>
>> */
>> - this_cpu = get_cpu();
>> + get_online_cpus_stable_atomic();
>> + this_cpu = smp_processor_id();
>
> I wonder if get_online_cpus_stable_atomic() should return the local CPU
> ID. Just as a little convenience thing. Time will tell.
>

With the new version which doesn't use extra cpumasks, we won't have to
bother about this..

>> /*
>> * Can deadlock when called with interrupts disabled.
>>
>> ...
>>
>> @@ -380,15 +383,15 @@ int smp_call_function_any(const struct cpumask *mask,
>> nodemask = cpumask_of_node(cpu_to_node(cpu));
>> for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids;
>> cpu = cpumask_next_and(cpu, nodemask, mask)) {
>> - if (cpu_online(cpu))
>> + if (cpu_online_stable(cpu))
>> goto call;
>> }
>>
>> /* Any online will do: smp_call_function_single handles nr_cpu_ids. */
>> - cpu = cpumask_any_and(mask, cpu_online_mask);
>> + cpu = cpumask_any_and(mask, cpu_online_stable_mask);
>> call:
>> ret = smp_call_function_single(cpu, func, info, wait);
>> - put_cpu();
>> + put_online_cpus_stable_atomic();
>> return ret;
>> }
>> EXPORT_SYMBOL_GPL(smp_call_function_any);
>
> So smp_call_function_any() has no synchronization against CPUs coming
> online. Hence callers of smp_call_function_any() are responsible for
> ensuring that CPUs which are concurrently coming online will adopt the
> required state?
>

Yes.

> I guess that has always been the case...
>

Right.

Regards,
Srivatsa S. Bhat

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/