e13c67be600e1a8d5037b04dea2793c92aa5b2d2
[openwrt/openwrt.git] / target / linux / generic / patches-4.9 / 040-03-MIPS-Only-change-28-to-thread_info-if-coming-from-us.patch
1 From: Matt Redfearn <matt.redfearn@imgtec.com>
2 Date: Mon, 19 Dec 2016 14:20:58 +0000
3 Subject: [PATCH] MIPS: Only change $28 to thread_info if coming from user
4 mode
5
6 The SAVE_SOME macro is used to save the execution context on all
7 exceptions.
8 If an exception occurs while executing user code, the stack is switched
9 to the kernel's stack for the current task, and register $28 is switched
10 to point to the current_thread_info, which is at the bottom of the stack
11 region.
12 If the exception occurs while executing kernel code, the stack is left,
13 and this change ensures that register $28 is not updated. This is the
14 correct behaviour when the kernel can be executing on the separate irq
15 stack, because the thread_info will not be at the base of it.
16
17 With this change, register $28 is only switched to it's kernel
18 conventional usage of the currrent thread info pointer at the point at
19 which execution enters kernel space. Doing it on every exception was
20 redundant, but OK without an IRQ stack, but will be erroneous once that
21 is introduced.
22
23 Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>
24 Reviewed-by: Maciej W. Rozycki <macro@imgtec.com>
25 ---
26
27 --- a/arch/mips/include/asm/stackframe.h
28 +++ b/arch/mips/include/asm/stackframe.h
29 @@ -216,12 +216,19 @@
30 LONG_S $25, PT_R25(sp)
31 LONG_S $28, PT_R28(sp)
32 LONG_S $31, PT_R31(sp)
33 +
34 + /* Set thread_info if we're coming from user mode */
35 + mfc0 k0, CP0_STATUS
36 + sll k0, 3 /* extract cu0 bit */
37 + bltz k0, 9f
38 +
39 ori $28, sp, _THREAD_MASK
40 xori $28, _THREAD_MASK
41 #ifdef CONFIG_CPU_CAVIUM_OCTEON
42 .set mips64
43 pref 0, 0($28) /* Prefetch the current pointer */
44 #endif
45 +9:
46 .set pop
47 .endm
48