Re: [PATCH 1/2] smp: Non busy-waiting IPI queue
From: Frederic Weisbecker
Date: Wed Apr 02 2014 - 14:30:35 EST
2014-04-02 20:05 GMT+02:00 Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>:
> On Wed, Apr 02, 2014 at 06:26:05PM +0200, Frederic Weisbecker wrote:
>> diff --git a/kernel/smp.c b/kernel/smp.c
>> index 06d574e..bfe7b36 100644
>> --- a/kernel/smp.c
>> +++ b/kernel/smp.c
>> @@ -265,6 +265,50 @@ int smp_call_function_single_async(int cpu, struct call_single_data *csd)
>> +void generic_smp_queue_function_single_interrupt(void *info)
>> + struct queue_single_data *qsd = info;
>> + WARN_ON_ONCE(xchg(&qsd->pending, 0) != 1);
> I am probably missing something here, but shouldn't this function copy
> *qsd to a local on-stack variable before doing the above xchg()? What
> prevents the following from happening?
> o CPU 0 does smp_queue_function_single(), which sets ->pending
> and fills in ->func and ->data.
> o CPU 1 takes IPI, invoking generic_smp_queue_function_single_interrupt().
> o CPU 1 does xchg(), so that ->pending is now zero.
> o An attempt to reuse the queue_single_data sees ->pending equal
> to zero, so the ->func and ->data is overwritten.
> o CPU 1 calls the new ->func with the new ->data (or any of the other
> two possible unexpected outcomes), which might not be helpful to
> the kernel's actuarial statistics.
> So what am I missing?
Ah, I forgot to precise that the function must remain the same for all
calls on a single qsd. And the data is always the qsd so this one can
only stay stable. So that shouldn't be a problem.
But you're right. The fact that we pass the function as an argument of
smp_queue_function_single() suggests that we can pass a different
function across various calls on a same qsd. So that's confusing.
Perhaps changing smp_queue_function_single() such that it only takes
the qsd as an argument would make that clearer? Then it's up to the
caller to initialize the qsd with the constant function. I could
define smp_queue_function_init() for that purpose. Or
DEFINE_QUEUE_FUNCTION_DATA() for static initializers.
How does that sound?
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/