[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1612922312.mnpowzgd0r.astroid@bobo.none>
Date: Wed, 10 Feb 2021 12:00:20 +1000
From: Nicholas Piggin <npiggin@...il.com>
To: Christophe Leroy <christophe.leroy@...roup.eu>,
David Laight <David.Laight@...LAB.COM>,
'Segher Boessenkool' <segher@...nel.crashing.org>
Cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linuxppc-dev@...ts.ozlabs.org" <linuxppc-dev@...ts.ozlabs.org>,
"msuchanek@...e.de" <msuchanek@...e.de>,
Paul Mackerras <paulus@...ba.org>
Subject: Re: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in
another pointer
Excerpts from Christophe Leroy's message of February 10, 2021 3:03 am:
>
>
> Le 09/02/2021 à 15:31, David Laight a écrit :
>> From: Segher Boessenkool
>>> Sent: 09 February 2021 13:51
>>>
>>> On Tue, Feb 09, 2021 at 12:36:20PM +1000, Nicholas Piggin wrote:
>>>> What if you did this?
>>>
>>>> +static inline struct task_struct *get_current(void)
>>>> +{
>>>> + register struct task_struct *task asm ("r2");
>>>> +
>>>> + return task;
>>>> +}
>>>
>>> Local register asm variables are *only* guaranteed to live in that
>>> register as operands to an asm. See
>>> https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables
>>> ("The only supported use" etc.)
>>>
>>> You can do something like
>>>
>>> static inline struct task_struct *get_current(void)
>>> {
>>> register struct task_struct *task asm ("r2");
>>>
>>> asm("" : "+r"(task));
>>>
>>> return task;
>>> }
>>>
>>> which makes sure that "task" actually is in r2 at the point of that asm.
>>
>> If "r2" always contains current (and is never assigned by the compiler)
>> why not use a global register variable for it?
>>
>
>
> The change proposed by Nick doesn't solve the issue.
It seemed to change code generation in a simple test case, oh well.
>
> The problem is that at the begining of the function we have:
>
> unsigned long *ti_flagsp = ¤t_thread_info()->flags;
>
> When the function uses ti_flagsp for the first time, it does use 112(r2)
>
> Then the function calls some other functions.
>
> Most likely because the function could update 'current', GCC copies r2 into r30, so that if r2 get
> changed by the called function, ti_flagsp is still based on the previous value of current.
>
> Allthough we know r2 wont change, GCC doesn't know it. And in order to save r2 into r30, it needs to
> save r30 in the stack.
>
>
> By using ¤t_thread_info()->flags directly instead of this intermediaite ti_flagsp pointer, GCC
> uses r2 instead instead of doing a copy.
>
>
> Nick, I don't understand the reason why you need that 'ti_flagsp' local var.
Just to save typing, I don't mind your patch I was just wondering if
current could be improved in general.
Thanks,
Nick
Powered by blists - more mailing lists