Re: [PATCH] Fix a race in pid generation that causes pids to bereused immediately.

From: Kyle McMartin
Date: Tue Jun 15 2010 - 09:06:50 EST


On Tue, Jun 15, 2010 at 08:56:50AM -0400, tytso@xxxxxxx wrote:
> > I think you're probably right, as long as one sticks with 4-byte
> > scalars. The cmpxchg-is-now-generic change snuck in under the radar
> > (mine, at least).
>
> Hmmm, what about unsigned longs? (Which might be 8 bytes on some
> architectures....)
>

Longs are fine, since Linux only supports LP64 (and would need major work
to support anything else.)

The problem documented above is that on 32-bit, a 64-bit read is
non-atomic, so even if you use a hashed spinlock to protect a u64
variable on 32-bit, reads will be non-atomic, and so must take the same
lock in order to be safe. Hence, you need accessor functions.

This is what the generic atomic code does, perhaps we could add a new
API that gives us hooks to do proper hashed spinlocks on crap
architectures but falls back to simple assignment and real cmpxchg on
real platforms.

--Kyle

--
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/