Re: [PATCH v4 2/2] powerpc/irq: inline call_do_irq() and call_do_softirq()

From: Christophe Leroy
Date: Tue Dec 03 2019 - 23:32:58 EST


Hi,

Le 29/11/2019 Ã 19:46, Segher Boessenkool a ÃcritÂ:
Hi!

On Wed, Nov 27, 2019 at 04:15:15PM +0100, Christophe Leroy wrote:
Le 27/11/2019 Ã 15:59, Segher Boessenkool a ÃcritÂ:
On Wed, Nov 27, 2019 at 02:50:30PM +0100, Christophe Leroy wrote:
So what do we do ? We just drop the "r2" clobber ?

You have to make sure your asm code works for all ABIs. This is quite
involved if you do a call to an external function. The compiler does
*not* see this call, so you will have to make sure that all that the
compiler and linker do will work, or prevent some of those things (say,
inlining of the function containing the call).

But the whole purpose of the patch is to inline the call to __do_irq()
in order to avoid the trampoline function.

Yes, so you call __do_irq. You have to make sure that what you tell the
compiler -- and what you *don't tell the compiler -- works with what the
ABIs require, and what the called function expects and provides.

That does not fix everything. The called function requires a specific
value in r2 on entry.

Euh ... but there is nothing like that when using existing
call_do_irq().

How does GCC know that call_do_irq() has same TOC as __do_irq() ?

The existing call_do_irq isn't C code. It doesn't do anything with r2,
as far as I can see; __do_irq just gets whatever the caller of call_do_irq
has.

So I guess all the callers of call_do_irq have the correct r2 value always
already? In that case everything Just Works.

Indeed, there is only one caller for call_do_irq() which is do_IRQ().
And do_IRQ() is also calling __do_irq() directly (when the stack pointer is already set to IRQ stack). do_IRQ() and __do_irq() are both in arch/powerpc/kernel/irq.c

As far as I can see when replacing the call to call_do_irq() by a call to __do_irq(), the compiler doesn't do anything special with r2, and doesn't add any nop after the bl either, whereas for all calls outside irq.c, there is a nop added. So I guess that's ok ?

Now that call_do_irq() is inlined, we can even define __do_irq() as static.

And that's the same for do_softirq_own_stack(), it is only called from do_softirq() which is defined in the same file as __do_softirq() (kernel/softirq.c)

Christophe