[PATCH v5 4/5] ARM: smp: Store current pointer in TPIDRURO register if available

Linus Walleij linus.walleij at linaro.org
Tue Sep 21 08:45:43 PDT 2021


On Sat, Sep 18, 2021 at 10:44 AM Ard Biesheuvel <ardb at kernel.org> wrote:

> Now that the user space TLS register is assigned on every return to user
> space, we can use it to keep the 'current' pointer while running in the
> kernel. This removes the need to access it via thread_info, which is
> located at the base of the stack, but will be moved out of there in a
> subsequent patch.
>
> Use the __builtin_thread_pointer() helper when available - this will
> help GCC understand that reloading the value within the same function is
> not necessary, even when using the per-task stack protector (which also
> generates accesses via the TLS register). For example, the generated
> code below loads TPIDRURO only once, and uses it to access both the
> stack canary and the preempt_count fields.
>
> <do_one_initcall>:
>        e92d 41f0       stmdb   sp!, {r4, r5, r6, r7, r8, lr}
>        ee1d 4f70       mrc     15, 0, r4, cr13, cr0, {3}
>        4606            mov     r6, r0
>        b094            sub     sp, #80 ; 0x50
>        f8d4 34e8       ldr.w   r3, [r4, #1256] ; 0x4e8  <- stack canary
>        9313            str     r3, [sp, #76]   ; 0x4c
>        f8d4 8004       ldr.w   r8, [r4, #4]             <- preempt count
>
> Co-developed-by: Keith Packard <keithpac at amazon.com>
> Signed-off-by: Keith Packard <keithpac at amazon.com>
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>

I like the __builtin trick, I had to look up the patch that adds
this to GCC to understand what is going on.
Reviewed-by: Linus Walleij <linus.walleij at linaro.org>

Yours,
Linus Walleij



More information about the linux-arm-kernel mailing list