linux-mips
[Top] [All Lists]

[RFC PATCH 14/16] MIPS: Determine kernel thread stack from task_struct

To: Ralf Baechle <ralf@linux-mips.org>, James Hogan <jhogan@kernel.org>
Subject: [RFC PATCH 14/16] MIPS: Determine kernel thread stack from task_struct
From: Matt Redfearn <matt.redfearn@mips.com>
Date: Tue, 12 Dec 2017 09:58:00 +0000
Cc: <linux-mips@linux-mips.org>
In-reply-to: <1513072682-1371-1-git-send-email-matt.redfearn@mips.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1513072682-1371-1-git-send-email-matt.redfearn@mips.com>
Sender: linux-mips-bounce@linux-mips.org
The current thread info can now be found from the thread_info_ptr. That
can be used to find the task struct (indeed, a later patch will embed
the thread_info in the task struct so these are one and the same). The
kernel stack may then be determined from the value in the task struct.
Replace the get_saved_sp macro with one which operates this way.

Saving of the kernel SP on context switch etc is no longer necessary,
so remove it.

Signed-off-by: Matt Redfearn <matt.redfearn@mips.com>
---

 arch/mips/include/asm/stackframe.h | 77 ++++++++++++--------------------------
 arch/mips/kernel/head.S            |  2 -
 arch/mips/kernel/octeon_switch.S   |  3 --
 arch/mips/kernel/r2300_switch.S    |  3 --
 arch/mips/kernel/r4k_switch.S      |  2 -
 arch/mips/kernel/setup.c           |  1 -
 6 files changed, 23 insertions(+), 65 deletions(-)

diff --git a/arch/mips/include/asm/stackframe.h 
b/arch/mips/include/asm/stackframe.h
index d83d148fec28..2ba65600a8d9 100644
--- a/arch/mips/include/asm/stackframe.h
+++ b/arch/mips/include/asm/stackframe.h
@@ -210,69 +210,37 @@
 #endif
 
 /*
- * get_saved_sp returns the SP for the current CPU by looking in the
- * kernelsp array for it.  If tosp is set, it stores the current sp in
- * k0 and loads the new value in sp.  If not, it clobbers k0 and
- * stores the new value in k1, leaving sp unaffected.
+ * get_saved_sp returns the SP for the current CPU by finding the current
+ * thread_info, using get_saved_ti, finding the task_stack, and adding
+ * the kernel stack size to it.
+ * It stores the current sp in k0 and loads the new value in sp. The value
+ * in k1 is clobbered.
  */
-#ifdef CONFIG_SMP
-               /* SMP variation */
-               .macro  get_saved_sp docfi=0 tosp=0
-               ASM_CPUID_MFC0  k0, ASM_SMP_CPUID_REG
-#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
-               lui     k1, %hi(kernelsp)
-#else
-               lui     k1, %highest(kernelsp)
-               daddiu  k1, %higher(kernelsp)
-               dsll    k1, 16
-               daddiu  k1, %hi(kernelsp)
-               dsll    k1, 16
-#endif
-               LONG_SRL        k0, SMP_CPUID_PTRSHIFT
-               LONG_ADDU       k1, k0
-               .if \tosp
+               .macro  get_saved_sp docfi=0
+               /* Get current thread info into k1 */
+               get_saved_ti    k1, k0
+               /* Get task struct into k1 */
+               LONG_L          k1, TI_TASK(k1)
+               /* Get the stack into k1 */
+               LONG_L          k1, TASK_STACK(k1)
+               /* Get starting stack location */
+               .set    at=k0
+               PTR_ADDU        k1, k1, _THREAD_SIZE - 32
+               .set    noat
+
+               /* Save current SP to k0 */
                move    k0, sp
                .if \docfi
                .cfi_register sp, k0
                .endif
-               LONG_L  sp, %lo(kernelsp)(k1)
-               .else
-               LONG_L  k1, %lo(kernelsp)(k1)
-               .endif
-               .endm
 
-               .macro  set_saved_sp stackp temp temp2
-               ASM_CPUID_MFC0  \temp, ASM_SMP_CPUID_REG
-               LONG_SRL        \temp, SMP_CPUID_PTRSHIFT
-               LONG_S  \stackp, kernelsp(\temp)
-               .endm
-#else /* !CONFIG_SMP */
-               /* Uniprocessor variation */
-               .macro  get_saved_sp docfi=0 tosp=0
-#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32)
-               lui     k1, %hi(kernelsp)
-#else
-               lui     k1, %highest(kernelsp)
-               daddiu  k1, %higher(kernelsp)
-               dsll    k1, k1, 16
-               daddiu  k1, %hi(kernelsp)
-               dsll    k1, k1, 16
-#endif
-               .if \tosp
-               move    k0, sp
+               /* Activate new stack */
+               move    sp, k1
                .if \docfi
-               .cfi_register sp, k0
-               .endif
-               LONG_L  sp, %lo(kernelsp)(k1)
-               .else
-               LONG_L  k1, %lo(kernelsp)(k1)
+               .cfi_register k1, sp
                .endif
-               .endm
 
-               .macro  set_saved_sp stackp temp temp2
-               LONG_S  \stackp, kernelsp
                .endm
-#endif
 
                .macro  SAVE_SOME docfi=0
                .set    push
@@ -287,8 +255,9 @@
                .cfi_register sp, k0
                .endif
                .set    reorder
+
                /* Called from user mode, new stack. */
-               get_saved_sp docfi=\docfi tosp=1
+               get_saved_sp docfi=\docfi
 8:
 #ifdef CONFIG_CPU_DADDI_WORKAROUNDS
                .set    at=k1
diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
index c74f2e1f4b08..5a7e0dac8ada 100644
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -136,7 +136,6 @@ dtb_found:
        PTR_ADDU        sp, $28
        back_to_back_c0_hazard
        set_saved_ti    $28, t0
-       set_saved_sp    sp, t0, t1
        PTR_SUBU        sp, 4 * SZREG           # init stack pointer
 
 #ifdef CONFIG_RELOCATABLE
@@ -148,7 +147,6 @@ dtb_found:
        PTR_ADDU        sp, v0
 
        set_saved_ti    $28, t0
-       set_saved_sp    sp, t0, t1
 
        /*
         * Find start_kernel in relocated image and jump there
diff --git a/arch/mips/kernel/octeon_switch.S b/arch/mips/kernel/octeon_switch.S
index b0ef486ad6c1..8f2d80b9b8a4 100644
--- a/arch/mips/kernel/octeon_switch.S
+++ b/arch/mips/kernel/octeon_switch.S
@@ -75,9 +75,6 @@
        cpu_restore_nonscratch a1
        set_saved_ti    $28, t0
 
-       PTR_ADDU        t0, $28, _THREAD_SIZE - 32
-       set_saved_sp    t0, t1, t2
-
        mfc0    t1, CP0_STATUS          /* Do we really need this? */
        li      a3, 0xff01
        and     t1, a3
diff --git a/arch/mips/kernel/r2300_switch.S b/arch/mips/kernel/r2300_switch.S
index 6e6c012dfc5e..db8186ed9b24 100644
--- a/arch/mips/kernel/r2300_switch.S
+++ b/arch/mips/kernel/r2300_switch.S
@@ -50,9 +50,6 @@ LEAF(resume)
        cpu_restore_nonscratch a1
        set_saved_ti    $28, t0
 
-       addiu   t1, $28, _THREAD_SIZE - 32
-       sw      t1, kernelsp
-
        mfc0    t1, CP0_STATUS          /* Do we really need this? */
        li      a3, 0xff01
        and     t1, a3
diff --git a/arch/mips/kernel/r4k_switch.S b/arch/mips/kernel/r4k_switch.S
index 5afbbc1b4bd3..6428904a34c7 100644
--- a/arch/mips/kernel/r4k_switch.S
+++ b/arch/mips/kernel/r4k_switch.S
@@ -45,8 +45,6 @@
        cpu_restore_nonscratch a1
        set_saved_ti    $28, t0
 
-       PTR_ADDU        t0, $28, _THREAD_SIZE - 32
-       set_saved_sp    t0, t1, t2
        mfc0    t1, CP0_STATUS          /* Do we really need this? */
        li      a3, 0xff01
        and     t1, a3
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index d7078589a077..53fbd5faff41 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -1024,7 +1024,6 @@ void __init setup_arch(char **cmdline_p)
        paging_init();
 }
 
-unsigned long kernelsp[NR_CPUS];
 unsigned long thread_info_ptr[NR_CPUS];
 unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
 
-- 
2.7.4


<Prev in Thread] Current Thread [Next in Thread>