All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@c-s.fr>
To: Michael Ellerman <mpe@ellerman.id.au>,
	Segher Boessenkool <segher@kernel.crashing.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v4 2/2] powerpc/irq: inline call_do_irq() and call_do_softirq()
Date: Thu, 19 Dec 2019 07:57:24 +0100	[thread overview]
Message-ID: <4668c204-3064-0e9e-5216-e7853f732821@c-s.fr> (raw)
In-Reply-To: <878snlrcrs.fsf@mpe.ellerman.id.au>



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

WARNING: multiple messages have this Message-ID (diff)
From: Christophe Leroy <christophe.leroy@c-s.fr>
To: Michael Ellerman <mpe@ellerman.id.au>,
	Segher Boessenkool <segher@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org, Paul Mackerras <paulus@samba.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] powerpc/irq: inline call_do_irq() and call_do_softirq()
Date: Thu, 19 Dec 2019 07:57:24 +0100	[thread overview]
Message-ID: <4668c204-3064-0e9e-5216-e7853f732821@c-s.fr> (raw)
In-Reply-To: <878snlrcrs.fsf@mpe.ellerman.id.au>



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

  reply	other threads:[~2019-12-19  6:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10  5:36 [PATCH v4 1/2] powerpc/irq: bring back ksp_limit management in C functions Christophe Leroy
2019-10-10  5:36 ` Christophe Leroy
2019-10-10  5:36 ` [PATCH v4 2/2] powerpc/irq: inline call_do_irq() and call_do_softirq() Christophe Leroy
2019-10-10  5:36   ` Christophe Leroy
2019-11-21  6:14   ` Michael Ellerman
2019-11-21  6:14     ` Michael Ellerman
2019-11-21 10:15     ` Segher Boessenkool
2019-11-21 10:15       ` Segher Boessenkool
2019-11-25 10:32       ` Michael Ellerman
2019-11-25 10:32         ` Michael Ellerman
2019-11-25 14:25         ` Segher Boessenkool
2019-11-25 14:25           ` Segher Boessenkool
2019-11-27 13:50           ` Christophe Leroy
2019-11-27 13:50             ` Christophe Leroy
2019-11-27 14:59             ` Segher Boessenkool
2019-11-27 14:59               ` Segher Boessenkool
2019-11-27 15:15               ` Christophe Leroy
2019-11-27 15:15                 ` Christophe Leroy
2019-11-29 18:46                 ` Segher Boessenkool
2019-11-29 18:46                   ` Segher Boessenkool
2019-12-04  4:32                   ` Christophe Leroy
2019-12-04  4:32                     ` Christophe Leroy
2019-12-06 20:59                     ` Segher Boessenkool
2019-12-06 20:59                       ` Segher Boessenkool
2019-12-07  9:42                       ` Christophe Leroy
2019-12-07  9:42                         ` Christophe Leroy
2019-12-07 17:40                         ` Segher Boessenkool
2019-12-07 17:40                           ` Segher Boessenkool
2019-12-09 10:53                           ` Michael Ellerman
2019-12-09 10:53                             ` Michael Ellerman
2019-12-19  6:57                             ` Christophe Leroy [this message]
2019-12-19  6:57                               ` Christophe Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4668c204-3064-0e9e-5216-e7853f732821@c-s.fr \
    --to=christophe.leroy@c-s.fr \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.