Re: x86-32: clean up rwsem inline asm statements

From: George Spelvin
Date: Wed Jan 13 2010 - 19:27:21 EST


> There are a number of things that can be done better... for one thing,
> "+m" (sem->count) and "a" (sem) is just bloody wrong. The right thing
> would be "a" (&sem->count) for proper robustness.

Actually, no. The "+m" (sem->count) is telling GCC that sem->count is
updated; "a" (&sem->count) does *not* tell it to invalidate cached
copies of sem->count that it may have lying around.

However, we can't just use "+m" (sem->count) because GCC has a poor
grasp on the concept of atomic operations; as far as it is concerned,
it is exactly equivalent to copying the value into a stack slot, do the
operation there, and copy it back.

(It's much more likely to do that with "g" operand constraints, but it has
been known to point to a stack copy that it's made for some other reason.)

The current situation is, as far as I can remember the previous discussion
on the subject, the simplest way to explain to GCC just what it needs to do.

> There is no real point in being concerned about the type of immediates,
> because the immediate type isn't really used... it shows up as a literal
> in the assembly language. However, if you're really concerned, the
> right thing to do is to do a cast in C, not playing games with the assembly.

Ah, right, sorry; I remembered having this problem, but it was with
register operands.
--
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/