[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210209135053.GD27854@gate.crashing.org>
Date: Tue, 9 Feb 2021 07:50:53 -0600
From: Segher Boessenkool <segher@...nel.crashing.org>
To: Nicholas Piggin <npiggin@...il.com>
Cc: Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Michael Ellerman <mpe@...erman.id.au>, msuchanek@...e.de,
Paul Mackerras <paulus@...ba.org>,
linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in another pointer
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.
Segher
Powered by blists - more mailing lists