Re: [PATCH] powerpc/irq: Modernise inline assembly in irq_soft_mask_{set,return}

From: Segher Boessenkool
Date: Fri Sep 23 2022 - 18:20:12 EST


On Sat, Sep 24, 2022 at 02:26:52AM +1000, Nicholas Piggin wrote:
> I still don't see what clauses guarantees asm("%0" ::"r"(foo)) to give
> 13. It doesn't say access via inline assembly is special,

But it is. It is for all register variables, local and global. I agree
this isn't documented clearly. For local register variables this is the
*only* thing guaranteed; for global register vars there is more (it
changes the ABI, there are safe/restore effects, that kind of thing).

Never it is guaranteed that all accesses through this variable will use
the register directly: this fundamentally cannot work on all archs, and
also not at -O0. More in general it doesn't work if some basic
optimisations are not done, be it because of a compiler deficiency, or a
straight out bug, or maybe it is a conscious choice in some cases.

> I think if it was obviously guaranteed then this might be marginally
> better than explicit r13 in the asm
>
> asm volatile(
> "stb %0,%2(%1)"
> :
> : "r" (mask),
> "r" (local_paca),
> "i" (offsetof(struct paca_struct, irq_soft_mask))
> : "memory");

(Please use "n" instead of "i". Doesn't matter here, but it does in
many other places.)


Segher