Re: set_bit() is broken on i386?

From: Chuck Ebbert
Date: Sat Jan 21 2006 - 02:47:01 EST


In-Reply-To: <20060120183857.188ef516.akpm@xxxxxxxx>

On Fri, 20 Jan 2006, Andrew Morton wrote:

> We need to somehow tell the compiler "this assembly statement altered
> memory and you can't cache memory contents across it". That's what
> "memory" (ie: barrier()) does. I don't think there's a way of telling gcc
> _what_ memory was clobbered - just "all of memory".

I think you can do that by specifying an output operand that you
never use in your assembler code, e.g. changing this:

| __asm__ __volatile__( "lock ; "
| "btsl %1,%0"
| :"=m" (ADDR)
| :"Ir" (nr));

to this:

| #define LONGBITS (8 * sizeof(unsigned long))
|
| __asm__ __volatile__( "lock ; "
| "btsl %2,%1"
| :"=m"(*(&ADDR + nr/LONGBITS))
| :"m" (ADDR), "Ir" (nr));

fixes my example program by telling the compiler what memory location
is altered. (Note that %0 is never used inside the asm code.)
So iff 'nr' is a constant you can clobber specific memory locations.
--
Chuck
Currently reading: _Sun Of Suns_ by Karl Schroeder
-
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/