powerpc/40x: Prepare for enabling MMU in critical exception prolog
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Fri, 12 Mar 2021 12:50:15 +0000 (12:50 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 29 Mar 2021 02:22:03 +0000 (13:22 +1100)
In order the enable MMU early in exception prolog, implement
CONFIG_VMAP_STACK principles in critical exception prolog.

There is no intention to use CONFIG_VMAP_STACK on 40x,
but related code will be used to enable MMU early in exception
in a later patch.

Also address (critirq_ctx - PAGE_OFFSET) directly instead of
using tophys() in order to win one instruction.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/3fd75ee54c48307119acdbf66cfea966c1463bbd.1615552866.git.christophe.leroy@csgroup.eu
arch/powerpc/kernel/head_40x.S

index 5b337bf..1468f38 100644 (file)
@@ -89,6 +89,12 @@ _ENTRY(crit_srr0)
        .space  4
 _ENTRY(crit_srr1)
        .space  4
+_ENTRY(crit_r1)
+       .space  4
+_ENTRY(crit_dear)
+       .space  4
+_ENTRY(crit_esr)
+       .space  4
 _ENTRY(saved_ksp_limit)
        .space  4
 
@@ -107,32 +113,60 @@ _ENTRY(saved_ksp_limit)
        mfspr   r11,SPRN_SRR1
        stw     r10,crit_srr0@l(0)
        stw     r11,crit_srr1@l(0)
+#ifdef CONFIG_VMAP_STACK
+       mfspr   r10,SPRN_DEAR
+       mfspr   r11,SPRN_ESR
+       stw     r10,crit_dear@l(0)
+       stw     r11,crit_esr@l(0)
+#endif
        mfcr    r10                     /* save CR in r10 for now          */
        mfspr   r11,SPRN_SRR3           /* check whether user or kernel    */
        andi.   r11,r11,MSR_PR
-       lis     r11,critirq_ctx@ha
-       tophys(r11,r11)
-       lwz     r11,critirq_ctx@l(r11)
+       lis     r11,(critirq_ctx-PAGE_OFFSET)@ha
+       lwz     r11,(critirq_ctx-PAGE_OFFSET)@l(r11)
        beq     1f
        /* COMING FROM USER MODE */
        mfspr   r11,SPRN_SPRG_THREAD    /* if from user, start at top of   */
        lwz     r11,TASK_STACK-THREAD(r11) /* this thread's kernel stack */
+#ifdef CONFIG_VMAP_STACK
+1:     stw     r1,crit_r1@l(0)
+       addi    r1,r11,THREAD_SIZE-INT_FRAME_SIZE /* Alloc an excpt frm  */
+       LOAD_REG_IMMEDIATE(r11,MSR_KERNEL & ~(MSR_IR | MSR_RI))
+       mtmsr   r11
+       isync
+       lwz     r11,crit_r1@l(0)
+       stw     r11,GPR1(r1)
+       stw     r11,0(r1)
+       mr      r11,r1
+#else
 1:     addi    r11,r11,THREAD_SIZE-INT_FRAME_SIZE /* Alloc an excpt frm  */
        tophys(r11,r11)
        stw     r1,GPR1(r11)
        stw     r1,0(r11)
        tovirt(r1,r11)
+#endif
        stw     r10,_CCR(r11)           /* save various registers          */
        stw     r12,GPR12(r11)
        stw     r9,GPR9(r11)
        mflr    r10
        stw     r10,_LINK(r11)
+#ifdef CONFIG_VMAP_STACK
+       lis     r9,PAGE_OFFSET@ha
+       lwz     r10,crit_r10@l(r9)
+       lwz     r12,crit_r11@l(r9)
+#else
        lwz     r10,crit_r10@l(0)
        lwz     r12,crit_r11@l(0)
+#endif
        stw     r10,GPR10(r11)
        stw     r12,GPR11(r11)
+#ifdef CONFIG_VMAP_STACK
+       lwz     r12,crit_dear@l(r9)
+       lwz     r9,crit_esr@l(r9)
+#else
        mfspr   r12,SPRN_DEAR           /* save DEAR and ESR in the frame  */
        mfspr   r9,SPRN_ESR             /* in them at the point where the  */
+#endif
        stw     r12,_DEAR(r11)          /* since they may have had stuff   */
        stw     r9,_ESR(r11)            /* exception was taken             */
        mfspr   r12,SPRN_SRR2