Re: [PATCH v3 02/22] netconsole: Introduce locking over the netpoll fields

From: Mike Waychison
Date: Tue Dec 14 2010 - 18:30:53 EST


2010/12/14 MichaÅ MirosÅaw <mirqus@xxxxxxxxx>:
> 2010/12/14 Mike Waychison <mikew@xxxxxxxxxx>:
>> The netconsole driver currently doesn't do any locking over its
>> configuration fields. ÂThis can cause problems if we were to ever have
>> concurrent writing to fields while somebody is enabling the service.
>>
>> For simplicity, this patch extends targets_list_lock to cover all
>> configuration fields within the targets. ÂMacros are also added here to
>> wrap accessors so that we check whether the target has been enabled with
>> locking handled.
>>
>> Signed-off-by: Mike Waychison <mikew@xxxxxxxxxx>
>> Acked-by: Matt Mackall <mpm@xxxxxxxxxxx>
>> ---
>> Âdrivers/net/netconsole.c | Â114 ++++++++++++++++++++++++++--------------------
>> Â1 files changed, 64 insertions(+), 50 deletions(-)
>>
>> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
>> index c87a49e..6e16888 100644
>> --- a/drivers/net/netconsole.c
>> +++ b/drivers/net/netconsole.c
>> @@ -327,6 +327,7 @@ static ssize_t store_enabled(struct netconsole_target *nt,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â const char *buf,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â size_t count)
>> Â{
>> + Â Â Â unsigned long flags;
>> Â Â Â Âint err;
>> Â Â Â Âlong enabled;
>>
>> @@ -335,6 +336,10 @@ static ssize_t store_enabled(struct netconsole_target *nt,
>> Â Â Â Â Â Â Â Âreturn enabled;
>>
>> Â Â Â Âif (enabled) { Â/* 1 */
>> + Â Â Â Â Â Â Â spin_lock_irqsave(&target_list_lock, flags);
>> + Â Â Â Â Â Â Â if (nt->enabled)
>> + Â Â Â Â Â Â Â Â Â Â Â goto busy;
>> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&target_list_lock, flags);
>>
>
> This looks wrong. Unless there is another lock or mutex covering this
> function, at this point (after spin_unlock_irqrestore()) another
> thread might set nt->enabled = 1.
>

Agreed that this looks wrong :)

It is fixed in the next patch where a state machine is introduced to
replace the binary flag nt->enabled. The code before this patch had
the a very similar problem in that a target could be enabled twice.
store_enabled() would call netpoll_setup() the second time without
checking to see if it was already enabled.
--
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/