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

Christophe Leroy
2019-12-19T06:57:29Z

Le 09/12/2019 à 11:53, Michael Ellerman a écrit :
> Segher Boessenkool <segher@kernel.crashing.org> writes:
>> On Sat, Dec 07, 2019 at 10:42:28AM +0100, Christophe Leroy wrote:
>>> Le 06/12/2019 à 21:59, Segher Boessenkool a écrit :
>>>> If the compiler can see the callee wants the same TOC as the caller has,
>>>> it does not arrange to set (and restore) it, no. If it sees it may be
>>>> different, it does arrange for that (and the linker then will check if
>>>> it actually needs to do anything, and do that if needed).
>>>>
>>>> In this case, the compiler cannot know the callee wants the same TOC,
>>>> which complicates thing a lot -- but it all works out.
>>>
>>> Do we have a way to make sure which TOC the functions are using ? Is
>>> there several TOC at all in kernel code ?
>>
>> Kernel modules have their own TOC, I think?
>
> Yes.

Yes, this means that exported functions have to care about that, right ?
And that's the reason why exported assembly functions like copy_page()
use _GLOBAL_TOC() and not _GLOBAL()

But main part of the kernel only has one TOC, so r2 can be assumed
constant for non exported functions, can't it ?

>
>>>> I think things can still go wrong if any of this is inlined into a kernel
>>>> module? Is there anything that prevents this / can this not happen for
>>>> some fundamental reason I don't see?
>>>
>>> This can't happen can it ?
>>> do_softirq_own_stack() is an outline function, defined in powerpc irq.c
>>> Its only caller is do_softirq() which is an outline function defined in
>>> kernel/softirq.c
>>>
>>> That prevents inlining, doesn't it ?
>>
>> Hopefully, sure. Would be nice if it was clearer that this works... It
>> is too much like working by chance, the way it is :-(
>
> There's no way any of that code can end up in a module. Or at least if
> there is, that's a bug.

That's my conclusion as well. So I guess we can consider r2 as constant
over those functions.

>
>>> Anyway, until we clarify all this I'll limit my patch to PPC32 which is
>>> where the real benefit is I guess.
>>>
>>> At the end, maybe the solution should be to switch to IRQ stack
>>> immediately in the exception entry as x86_64 do ?
>
> Yeah that might be cleaner.
>

I prepared a patch for that on PPC32, but it doesn't get rid of the IRQ
stack switch completely because do_IRQ() is also called from other
places like the timer interrupt.

And we will still have the switch for softirqs. We could move
do_softirq_own_stack() to assembly and merge it with call_do_softirq(),
but a find it cleaner to inline call_do_softirq() instead, now that we
have demonstrated that r2 can't change.

Christophe