RFC on writel and writel_relaxed
Linus Torvalds
torvalds at linux-foundation.org
Wed Mar 28 11:39:13 AEDT 2018
On Tue, Mar 27, 2018 at 11:33 AM, Benjamin Herrenschmidt
<benh at kernel.crashing.org> wrote:
>
> Well, we need to clarify that once and for all, because as I wrote
> earlier, it was decreed by Linus more than a decade ago that writel
> would be fully ordered by itself vs. previous memory stores (at least
> on UC memory).
Yes.
So "writel()" needs to be ordered with respect to other writel() uses
on the same thread. Anything else *will* break drivers. Obviously, the
drivers may then do magic to say "do write combining etc", but that
magic will be architecture-specific.
The other issue is that "writel()" needs to be ordered wrt other CPU's
doing "writel()" if those writel's are in a spinlocked region.
So it's not that "writel()" needs to be ordered wrt the spinlock
itself, but you *do* need to honor ordering if you have something like
this:
spin_lock(&somelock);
writel(a);
writel(b);
spin_unlock(&somelock);
and if two CPU's run the above code "at the same time", then the
*ONLY* acceptable sequence is abab.
You cannot, and must not, ever see "aabb" at the device, for example,
because of how the writel would basically leak out of the spinlock.
That sounds "obvious", but dammit, a lot of architectures got that
wrong, afaik.
Linus
More information about the Linuxppc-dev
mailing list