Re: Writable module parameters - should be volatile?

From: Arnd Bergmann
Date: Sun Sep 12 2004 - 07:55:17 EST


On Sonntag, 12. September 2004 13:57, Duncan Sands wrote:
> I declare a writable module parameter as follows:
>
> static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
>
> module_param (num_rcv_urbs, uint, S_IRUGO | S_IWUSR);
>
> Shouldn't I declare num_rcv_urbs volatile? Otherwise compiler
> optimizations could (for example) stick it in a register and miss
> any changes made by someone writing to it...

Even worse, AFAICS there is no guarantee that writes are atomic,
which can give unpredictable results in case of strings or arrays.
Both problems can be solved by serializing access to writable
module parameters.

Maybe we could have a global module_param_rwsem. Making the
parameter volatile does not sound like the right solution, in
fact volatile is almost always a bad idea.

Arnd <><

Attachment: pgp00000.pgp
Description: signature