]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ARM: entry: preserve thread_info pointer in switch_to
authorArd Biesheuvel <ardb@kernel.org>
Wed, 24 Nov 2021 11:09:48 +0000 (12:09 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Mon, 6 Dec 2021 11:49:16 +0000 (12:49 +0100)
Tweak the UP stack protector handling code so that the thread info
pointer is preserved in R7 until set_current is called. This is needed
for a subsequent patch that implements THREAD_INFO_IN_TASK and
set_current for UP as well.

This also means we will prefer the per-task protector on UP systems that
implement the thread ID registers, so tweak the preprocessor
conditionals to reflect this.

Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
arch/arm/kernel/entry-armv.S

index 9744d087ee9ff2466ac939651b393e38813a4ba5..1a6cf711a3b47e76243b9a79685c1b7450ffd5d3 100644 (file)
@@ -806,16 +806,16 @@ ENTRY(__switch_to)
        ldr     r6, [r2, #TI_CPU_DOMAIN]
 #endif
        switch_tls r1, r4, r5, r3, r7
-#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)
-       ldr     r7, [r2, #TI_TASK]
+#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \
+    !defined(CONFIG_STACKPROTECTOR_PER_TASK)
+       ldr     r9, [r2, #TI_TASK]
        ldr     r8, =__stack_chk_guard
        .if (TSK_STACK_CANARY > IMM12_MASK)
-       add     r7, r7, #TSK_STACK_CANARY & ~IMM12_MASK
+       add     r9, r9, #TSK_STACK_CANARY & ~IMM12_MASK
        .endif
-       ldr     r7, [r7, #TSK_STACK_CANARY & IMM12_MASK]
-#elif defined(CONFIG_CURRENT_POINTER_IN_TPIDRURO)
-       mov     r7, r2                          @ Preserve 'next'
+       ldr     r9, [r9, #TSK_STACK_CANARY & IMM12_MASK]
 #endif
+       mov     r7, r2                          @ Preserve 'next'
 #ifdef CONFIG_CPU_USE_DOMAINS
        mcr     p15, 0, r6, c3, c0, 0           @ Set domain register
 #endif
@@ -824,8 +824,9 @@ ENTRY(__switch_to)
        ldr     r0, =thread_notify_head
        mov     r1, #THREAD_NOTIFY_SWITCH
        bl      atomic_notifier_call_chain
-#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)
-       str     r7, [r8]
+#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \
+    !defined(CONFIG_STACKPROTECTOR_PER_TASK)
+       str     r9, [r8]
 #endif
        mov     r0, r5
 #if !defined(CONFIG_THUMB2_KERNEL) && !defined(CONFIG_VMAP_STACK)