On Tue, 21 Sept 2021 at 17:46, Linus Walleij [off-list ref] wrote:
On Sat, Sep 18, 2021 at 10:44 AM Ard Biesheuvel [off-list ref] wrote:
quoted
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 <redacted>
Signed-off-by: Keith Packard <redacted>
Signed-off-by: Ard Biesheuvel <ardb@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.
Yes. Note that patch #1 adds a call to gen_load_tp_hard() to the GCC
plugin, which is what backs __builtin_thread_pointer() when -mtp=cp15
is used. This is what permits GCC to infer that it can reuse the
value. (Inline asm is completely opaque to the compiler so it lacks
the implicit connotation that the thread pointer cannot change values
halfway through a function)
Reviewed-by: Linus Walleij <redacted>
Thanks!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel