2019-05-27 09:55:01 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
|
|
|
* PowerPC version
|
|
|
|
* Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
|
|
|
|
* Rewritten by Cort Dougan (cort@fsmlabs.com) for PReP
|
|
|
|
* Copyright (C) 1996 Cort Dougan <cort@fsmlabs.com>
|
|
|
|
* Adapted for Power Macintosh by Paul Mackerras.
|
|
|
|
* Low-level exception handlers and MMU support
|
|
|
|
* rewritten by Paul Mackerras.
|
|
|
|
* Copyright (C) 1996 Paul Mackerras.
|
|
|
|
* MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
|
|
|
|
*
|
|
|
|
* This file contains the system call entry code, context switch
|
|
|
|
* code, and exception/interrupt return code for PowerPC.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
powerpc/kernel: Switch to using MAX_ERRNO
Currently on powerpc we have our own #define for the highest (negative)
errno value, called _LAST_ERRNO. This is defined to be 516, for reasons
which are not clear.
The generic code, and x86, use MAX_ERRNO, which is defined to be 4095.
In particular seccomp uses MAX_ERRNO to restrict the value that a
seccomp filter can return.
Currently with the mismatch between _LAST_ERRNO and MAX_ERRNO, a seccomp
tracer wanting to return 600, expecting it to be seen as an error, would
instead find on powerpc that userspace sees a successful syscall with a
return value of 600.
To avoid this inconsistency, switch powerpc to use MAX_ERRNO.
We are somewhat confident that generic syscalls that can return a
non-error value above negative MAX_ERRNO have already been updated to
use force_successful_syscall_return().
I have also checked all the powerpc specific syscalls, and believe that
none of them expect to return a non-error value between -MAX_ERRNO and
-516. So this change should be safe ...
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>
2015-07-23 13:21:01 +03:00
|
|
|
#include <linux/err.h>
|
2005-10-10 16:36:14 +04:00
|
|
|
#include <linux/sys.h>
|
|
|
|
#include <linux/threads.h>
|
|
|
|
#include <asm/reg.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/mmu.h>
|
|
|
|
#include <asm/cputable.h>
|
|
|
|
#include <asm/thread_info.h>
|
|
|
|
#include <asm/ppc_asm.h>
|
|
|
|
#include <asm/asm-offsets.h>
|
|
|
|
#include <asm/unistd.h>
|
2010-11-18 18:06:17 +03:00
|
|
|
#include <asm/ptrace.h>
|
2016-01-14 07:33:46 +03:00
|
|
|
#include <asm/export.h>
|
2018-07-05 19:25:01 +03:00
|
|
|
#include <asm/feature-fixups.h>
|
2018-07-28 02:06:38 +03:00
|
|
|
#include <asm/barrier.h>
|
2019-03-11 11:30:31 +03:00
|
|
|
#include <asm/kup.h>
|
2019-04-30 15:39:01 +03:00
|
|
|
#include <asm/bug.h>
|
2005-10-10 16:36:14 +04:00
|
|
|
|
2019-04-30 15:38:51 +03:00
|
|
|
#include "head_32.h"
|
2005-10-10 16:36:14 +04:00
|
|
|
|
2017-07-12 13:08:49 +03:00
|
|
|
/*
|
|
|
|
* Align to 4k in order to ensure that all functions modyfing srr0/srr1
|
|
|
|
* fit into one page in order to not encounter a TLB miss between the
|
|
|
|
* modification of srr0/srr1 and the associated rfi.
|
|
|
|
*/
|
|
|
|
.align 12
|
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
#ifdef CONFIG_BOOKE
|
|
|
|
.globl mcheck_transfer_to_handler
|
|
|
|
mcheck_transfer_to_handler:
|
2008-04-30 14:23:21 +04:00
|
|
|
mfspr r0,SPRN_DSRR0
|
|
|
|
stw r0,_DSRR0(r11)
|
|
|
|
mfspr r0,SPRN_DSRR1
|
|
|
|
stw r0,_DSRR1(r11)
|
|
|
|
/* fall through */
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
.globl debug_transfer_to_handler
|
|
|
|
debug_transfer_to_handler:
|
2008-04-30 14:23:21 +04:00
|
|
|
mfspr r0,SPRN_CSRR0
|
|
|
|
stw r0,_CSRR0(r11)
|
|
|
|
mfspr r0,SPRN_CSRR1
|
|
|
|
stw r0,_CSRR1(r11)
|
|
|
|
/* fall through */
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
.globl crit_transfer_to_handler
|
|
|
|
crit_transfer_to_handler:
|
2009-02-13 01:12:40 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3E_MMU
|
2008-04-30 14:23:21 +04:00
|
|
|
mfspr r0,SPRN_MAS0
|
|
|
|
stw r0,MAS0(r11)
|
|
|
|
mfspr r0,SPRN_MAS1
|
|
|
|
stw r0,MAS1(r11)
|
|
|
|
mfspr r0,SPRN_MAS2
|
|
|
|
stw r0,MAS2(r11)
|
|
|
|
mfspr r0,SPRN_MAS3
|
|
|
|
stw r0,MAS3(r11)
|
|
|
|
mfspr r0,SPRN_MAS6
|
|
|
|
stw r0,MAS6(r11)
|
|
|
|
#ifdef CONFIG_PHYS_64BIT
|
|
|
|
mfspr r0,SPRN_MAS7
|
|
|
|
stw r0,MAS7(r11)
|
|
|
|
#endif /* CONFIG_PHYS_64BIT */
|
2009-02-13 01:12:40 +03:00
|
|
|
#endif /* CONFIG_PPC_BOOK3E_MMU */
|
2008-04-30 14:23:21 +04:00
|
|
|
#ifdef CONFIG_44x
|
|
|
|
mfspr r0,SPRN_MMUCR
|
|
|
|
stw r0,MMUCR(r11)
|
|
|
|
#endif
|
|
|
|
mfspr r0,SPRN_SRR0
|
|
|
|
stw r0,_SRR0(r11)
|
|
|
|
mfspr r0,SPRN_SRR1
|
|
|
|
stw r0,_SRR1(r11)
|
|
|
|
|
2019-01-31 13:09:00 +03:00
|
|
|
/* set the stack limit to the current stack */
|
2009-07-15 00:52:54 +04:00
|
|
|
mfspr r8,SPRN_SPRG_THREAD
|
2008-04-30 14:23:21 +04:00
|
|
|
lwz r0,KSP_LIMIT(r8)
|
|
|
|
stw r0,SAVED_KSP_LIMIT(r11)
|
2019-01-31 13:09:00 +03:00
|
|
|
rlwinm r0,r1,0,0,(31 - THREAD_SHIFT)
|
2008-04-30 14:23:21 +04:00
|
|
|
stw r0,KSP_LIMIT(r8)
|
2005-10-10 16:36:14 +04:00
|
|
|
/* fall through */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_40x
|
|
|
|
.globl crit_transfer_to_handler
|
|
|
|
crit_transfer_to_handler:
|
|
|
|
lwz r0,crit_r10@l(0)
|
|
|
|
stw r0,GPR10(r11)
|
|
|
|
lwz r0,crit_r11@l(0)
|
|
|
|
stw r0,GPR11(r11)
|
2008-04-30 14:23:21 +04:00
|
|
|
mfspr r0,SPRN_SRR0
|
|
|
|
stw r0,crit_srr0@l(0)
|
|
|
|
mfspr r0,SPRN_SRR1
|
|
|
|
stw r0,crit_srr1@l(0)
|
|
|
|
|
2019-01-31 13:09:00 +03:00
|
|
|
/* set the stack limit to the current stack */
|
2009-07-15 00:52:54 +04:00
|
|
|
mfspr r8,SPRN_SPRG_THREAD
|
2008-04-30 14:23:21 +04:00
|
|
|
lwz r0,KSP_LIMIT(r8)
|
|
|
|
stw r0,saved_ksp_limit@l(0)
|
2019-01-31 13:09:00 +03:00
|
|
|
rlwinm r0,r1,0,0,(31 - THREAD_SHIFT)
|
2008-04-30 14:23:21 +04:00
|
|
|
stw r0,KSP_LIMIT(r8)
|
2005-10-10 16:36:14 +04:00
|
|
|
/* fall through */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code finishes saving the registers to the exception frame
|
|
|
|
* and jumps to the appropriate handler for the exception, turning
|
|
|
|
* on address translation.
|
|
|
|
* Note that we rely on the caller having set cr0.eq iff the exception
|
|
|
|
* occurred in kernel mode (i.e. MSR:PR = 0).
|
|
|
|
*/
|
|
|
|
.globl transfer_to_handler_full
|
|
|
|
transfer_to_handler_full:
|
|
|
|
SAVE_NVGPRS(r11)
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
.globl transfer_to_handler
|
|
|
|
transfer_to_handler:
|
|
|
|
stw r2,GPR2(r11)
|
|
|
|
stw r12,_NIP(r11)
|
|
|
|
stw r9,_MSR(r11)
|
|
|
|
andi. r2,r9,MSR_PR
|
|
|
|
mfctr r12
|
|
|
|
mfspr r2,SPRN_XER
|
|
|
|
stw r12,_CTR(r11)
|
|
|
|
stw r2,_XER(r11)
|
2009-07-15 00:52:54 +04:00
|
|
|
mfspr r12,SPRN_SPRG_THREAD
|
2019-12-21 11:32:27 +03:00
|
|
|
tovirt_vmstack r12, r12
|
2005-10-10 16:36:14 +04:00
|
|
|
beq 2f /* if from user, fix up THREAD.regs */
|
2019-03-11 11:30:31 +03:00
|
|
|
addi r2, r12, -THREAD
|
2005-10-10 16:36:14 +04:00
|
|
|
addi r11,r1,STACK_FRAME_OVERHEAD
|
|
|
|
stw r11,PT_REGS(r12)
|
|
|
|
#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
|
|
|
|
/* Check to see if the dbcr0 register is set up to debug. Use the
|
2008-04-10 01:15:40 +04:00
|
|
|
internal debug mode bit to do this. */
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r12,THREAD_DBCR0(r12)
|
2008-07-25 23:27:33 +04:00
|
|
|
andis. r12,r12,DBCR0_IDM@h
|
2019-01-31 13:10:31 +03:00
|
|
|
#endif
|
2019-01-31 13:09:04 +03:00
|
|
|
ACCOUNT_CPU_USER_ENTRY(r2, r11, r12)
|
2019-03-11 11:30:35 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_32
|
|
|
|
kuep_lock r11, r12
|
|
|
|
#endif
|
2019-01-31 13:10:31 +03:00
|
|
|
#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
|
2005-10-10 16:36:14 +04:00
|
|
|
beq+ 3f
|
|
|
|
/* From user and task is ptraced - load up global dbcr0 */
|
|
|
|
li r12,-1 /* clear all pending debug events */
|
|
|
|
mtspr SPRN_DBSR,r12
|
|
|
|
lis r11,global_dbcr0@ha
|
|
|
|
tophys(r11,r11)
|
|
|
|
addi r11,r11,global_dbcr0@l
|
2008-04-10 01:15:40 +04:00
|
|
|
#ifdef CONFIG_SMP
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r9,TASK_CPU(r2)
|
2008-04-10 01:15:40 +04:00
|
|
|
slwi r9,r9,3
|
|
|
|
add r11,r11,r9
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r12,0(r11)
|
|
|
|
mtspr SPRN_DBCR0,r12
|
|
|
|
lwz r12,4(r11)
|
|
|
|
addi r12,r12,-1
|
|
|
|
stw r12,4(r11)
|
|
|
|
#endif
|
2016-05-17 09:33:46 +03:00
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
b 3f
|
2006-04-18 15:49:11 +04:00
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
2: /* if from kernel, check interrupted DOZE/NAP mode and
|
|
|
|
* check for stack overflow
|
|
|
|
*/
|
2020-01-27 13:42:04 +03:00
|
|
|
kuap_save_and_lock r11, r12, r9, r2, r6
|
2019-03-11 11:30:31 +03:00
|
|
|
addi r2, r12, -THREAD
|
powerpc/32: Add early stack overflow detection with VMAP stack.
To avoid recursive faults, stack overflow detection has to be
performed before writing in the stack in exception prologs.
Do it by checking the alignment. If the stack pointer alignment is
wrong, it means it is pointing to the following or preceding page.
Without VMAP stack, a stack overflow is catastrophic. With VMAP
stack, a stack overflow isn't destructive, so don't panic. Kill
the task with SIGSEGV instead.
A dedicated overflow stack is set up for each CPU.
lkdtm: Performing direct entry EXHAUST_STACK
lkdtm: Calling function with 512 frame size to depth 32 ...
lkdtm: loop 32/32 ...
lkdtm: loop 31/32 ...
lkdtm: loop 30/32 ...
lkdtm: loop 29/32 ...
lkdtm: loop 28/32 ...
lkdtm: loop 27/32 ...
lkdtm: loop 26/32 ...
lkdtm: loop 25/32 ...
lkdtm: loop 24/32 ...
lkdtm: loop 23/32 ...
lkdtm: loop 22/32 ...
lkdtm: loop 21/32 ...
lkdtm: loop 20/32 ...
Kernel stack overflow in process test[359], r1=c900c008
Oops: Kernel stack overflow, sig: 6 [#1]
BE PAGE_SIZE=4K MMU=Hash PowerMac
Modules linked in:
CPU: 0 PID: 359 Comm: test Not tainted 5.3.0-rc7+ #2225
NIP: c0622060 LR: c0626710 CTR: 00000000
REGS: c0895f48 TRAP: 0000 Not tainted (5.3.0-rc7+)
MSR: 00001032 <ME,IR,DR,RI> CR: 28004224 XER: 00000000
GPR00: c0626ca4 c900c008 c783c000 c07335cc c900c010 c07335cc c900c0f0 c07335cc
GPR08: c900c0f0 00000001 00000000 00000000 28008222 00000000 00000000 00000000
GPR16: 00000000 00000000 10010128 10010000 b799c245 10010158 c07335cc 00000025
GPR24: c0690000 c08b91d4 c068f688 00000020 c900c0f0 c068f668 c08b95b4 c08b91d4
NIP [c0622060] format_decode+0x0/0x4d4
LR [c0626710] vsnprintf+0x80/0x5fc
Call Trace:
[c900c068] [c0626ca4] vscnprintf+0x18/0x48
[c900c078] [c007b944] vprintk_store+0x40/0x214
[c900c0b8] [c007bf50] vprintk_emit+0x90/0x1dc
[c900c0e8] [c007c5cc] printk+0x50/0x60
[c900c128] [c03da5b0] recursive_loop+0x44/0x6c
[c900c338] [c03da5c4] recursive_loop+0x58/0x6c
[c900c548] [c03da5c4] recursive_loop+0x58/0x6c
[c900c758] [c03da5c4] recursive_loop+0x58/0x6c
[c900c968] [c03da5c4] recursive_loop+0x58/0x6c
[c900cb78] [c03da5c4] recursive_loop+0x58/0x6c
[c900cd88] [c03da5c4] recursive_loop+0x58/0x6c
[c900cf98] [c03da5c4] recursive_loop+0x58/0x6c
[c900d1a8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d3b8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d5c8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d7d8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d9e8] [c03da5c4] recursive_loop+0x58/0x6c
[c900dbf8] [c03da5c4] recursive_loop+0x58/0x6c
[c900de08] [c03da67c] lkdtm_EXHAUST_STACK+0x30/0x4c
[c900de18] [c03da3e8] direct_entry+0xc8/0x140
[c900de48] [c029fb40] full_proxy_write+0x64/0xcc
[c900de68] [c01500f8] __vfs_write+0x30/0x1d0
[c900dee8] [c0152cb8] vfs_write+0xb8/0x1d4
[c900df08] [c0152f7c] ksys_write+0x58/0xe8
[c900df38] [c0014208] ret_from_syscall+0x0/0x34
--- interrupt: c01 at 0xf806664
LR = 0x1000c868
Instruction dump:
4bffff91 80010014 7c832378 7c0803a6 38210010 4e800020 3d20c08a 3ca0c089
8089a0cc 38a58f0c 38600001 4ba2d494 <9421ffe0> 7c0802a6 bfc10018 7c9f2378
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1b89c121b4070c7ee99e4f22cc178f15a736b07b.1576916812.git.christophe.leroy@c-s.fr
2019-12-21 11:32:29 +03:00
|
|
|
#ifndef CONFIG_VMAP_STACK
|
2008-04-28 10:21:22 +04:00
|
|
|
lwz r9,KSP_LIMIT(r12)
|
|
|
|
cmplw r1,r9 /* if r1 <= ksp_limit */
|
2006-04-18 15:49:11 +04:00
|
|
|
ble- stack_ovf /* then the kernel stack overflowed */
|
powerpc/32: Add early stack overflow detection with VMAP stack.
To avoid recursive faults, stack overflow detection has to be
performed before writing in the stack in exception prologs.
Do it by checking the alignment. If the stack pointer alignment is
wrong, it means it is pointing to the following or preceding page.
Without VMAP stack, a stack overflow is catastrophic. With VMAP
stack, a stack overflow isn't destructive, so don't panic. Kill
the task with SIGSEGV instead.
A dedicated overflow stack is set up for each CPU.
lkdtm: Performing direct entry EXHAUST_STACK
lkdtm: Calling function with 512 frame size to depth 32 ...
lkdtm: loop 32/32 ...
lkdtm: loop 31/32 ...
lkdtm: loop 30/32 ...
lkdtm: loop 29/32 ...
lkdtm: loop 28/32 ...
lkdtm: loop 27/32 ...
lkdtm: loop 26/32 ...
lkdtm: loop 25/32 ...
lkdtm: loop 24/32 ...
lkdtm: loop 23/32 ...
lkdtm: loop 22/32 ...
lkdtm: loop 21/32 ...
lkdtm: loop 20/32 ...
Kernel stack overflow in process test[359], r1=c900c008
Oops: Kernel stack overflow, sig: 6 [#1]
BE PAGE_SIZE=4K MMU=Hash PowerMac
Modules linked in:
CPU: 0 PID: 359 Comm: test Not tainted 5.3.0-rc7+ #2225
NIP: c0622060 LR: c0626710 CTR: 00000000
REGS: c0895f48 TRAP: 0000 Not tainted (5.3.0-rc7+)
MSR: 00001032 <ME,IR,DR,RI> CR: 28004224 XER: 00000000
GPR00: c0626ca4 c900c008 c783c000 c07335cc c900c010 c07335cc c900c0f0 c07335cc
GPR08: c900c0f0 00000001 00000000 00000000 28008222 00000000 00000000 00000000
GPR16: 00000000 00000000 10010128 10010000 b799c245 10010158 c07335cc 00000025
GPR24: c0690000 c08b91d4 c068f688 00000020 c900c0f0 c068f668 c08b95b4 c08b91d4
NIP [c0622060] format_decode+0x0/0x4d4
LR [c0626710] vsnprintf+0x80/0x5fc
Call Trace:
[c900c068] [c0626ca4] vscnprintf+0x18/0x48
[c900c078] [c007b944] vprintk_store+0x40/0x214
[c900c0b8] [c007bf50] vprintk_emit+0x90/0x1dc
[c900c0e8] [c007c5cc] printk+0x50/0x60
[c900c128] [c03da5b0] recursive_loop+0x44/0x6c
[c900c338] [c03da5c4] recursive_loop+0x58/0x6c
[c900c548] [c03da5c4] recursive_loop+0x58/0x6c
[c900c758] [c03da5c4] recursive_loop+0x58/0x6c
[c900c968] [c03da5c4] recursive_loop+0x58/0x6c
[c900cb78] [c03da5c4] recursive_loop+0x58/0x6c
[c900cd88] [c03da5c4] recursive_loop+0x58/0x6c
[c900cf98] [c03da5c4] recursive_loop+0x58/0x6c
[c900d1a8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d3b8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d5c8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d7d8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d9e8] [c03da5c4] recursive_loop+0x58/0x6c
[c900dbf8] [c03da5c4] recursive_loop+0x58/0x6c
[c900de08] [c03da67c] lkdtm_EXHAUST_STACK+0x30/0x4c
[c900de18] [c03da3e8] direct_entry+0xc8/0x140
[c900de48] [c029fb40] full_proxy_write+0x64/0xcc
[c900de68] [c01500f8] __vfs_write+0x30/0x1d0
[c900dee8] [c0152cb8] vfs_write+0xb8/0x1d4
[c900df08] [c0152f7c] ksys_write+0x58/0xe8
[c900df38] [c0014208] ret_from_syscall+0x0/0x34
--- interrupt: c01 at 0xf806664
LR = 0x1000c868
Instruction dump:
4bffff91 80010014 7c832378 7c0803a6 38210010 4e800020 3d20c08a 3ca0c089
8089a0cc 38a58f0c 38600001 4ba2d494 <9421ffe0> 7c0802a6 bfc10018 7c9f2378
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1b89c121b4070c7ee99e4f22cc178f15a736b07b.1576916812.git.christophe.leroy@c-s.fr
2019-12-21 11:32:29 +03:00
|
|
|
#endif
|
2006-04-18 15:49:11 +04:00
|
|
|
5:
|
2018-11-17 13:24:56 +03:00
|
|
|
#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r12,TI_LOCAL_FLAGS(r2)
|
2006-04-18 15:49:11 +04:00
|
|
|
mtcrf 0x01,r12
|
|
|
|
bt- 31-TLF_NAPPING,4f
|
2008-05-14 08:30:48 +04:00
|
|
|
bt- 31-TLF_SLEEPING,7f
|
2018-11-17 13:24:56 +03:00
|
|
|
#endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_E500 */
|
2005-10-10 16:36:14 +04:00
|
|
|
.globl transfer_to_handler_cont
|
|
|
|
transfer_to_handler_cont:
|
|
|
|
3:
|
|
|
|
mflr r9
|
2019-12-21 11:32:27 +03:00
|
|
|
tovirt_novmstack r2, r2 /* set r2 to current */
|
|
|
|
tovirt_vmstack r9, r9
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r11,0(r9) /* virtual address of handler */
|
|
|
|
lwz r9,4(r9) /* where to go when done */
|
2018-01-12 15:45:23 +03:00
|
|
|
#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
|
powerpc/8xx: Perf events on PPC 8xx
This patch has been reworked since RFC version. In the RFC, this patch
was preceded by a patch clearing MSR RI for all PPC32 at all time at
exception prologs. Now MSR RI clearing is done only when this 8xx perf
events functionality is compiled in, it is therefore limited to 8xx
and merged inside this patch.
Other main changes have been to take into account detailed review from
Peter Zijlstra. The instructions counter has been reworked to behave
as a free running counter like the three other counters.
The 8xx has no PMU, however some events can be emulated by other means.
This patch implements the following events (as reported by 'perf list'):
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
dTLB-load-misses [Hardware cache event]
iTLB-load-misses [Hardware cache event]
'cycles' event is implemented using the timebase clock. Timebase clock
corresponds to CPU clock divided by 16, so number of cycles is
approximatly 16 times the number of TB ticks
On the 8xx, TLB misses are handled by software. It is therefore
easy to count all TLB misses each time the TLB miss exception is
called.
'instructions' is calculated by using instruction watchpoint counter.
This patch sets counter A to count instructions at address greater
than 0, hence we count all instructions executed while MSR RI bit is
set. The counter is set to the maximum which is 0xffff. Every 65535
instructions, debug instruction breakpoint exception fires. The
exception handler increments a counter in memory which then
represent the upper part of the instruction counter. We therefore
end up with a 48 bits counter. In order to avoid unnecessary overhead
while no perf event is active, this counter is started when the first
event referring to this counter is added, and the counter is stopped
when the last event referring to it is deleted. In order to properly
support breakpoint exceptions, MSR RI bit has to be unset in exception
epilogs in order to avoid breakpoint exceptions during critical
sections during changes to SRR0 and SRR1 would be problematic.
All counters are handled as free running counters.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-12-15 15:42:18 +03:00
|
|
|
mtspr SPRN_NRI, r0
|
|
|
|
#endif
|
2009-06-17 21:43:59 +04:00
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
2019-04-30 15:39:01 +03:00
|
|
|
/*
|
|
|
|
* When tracing IRQ state (lockdep) we enable the MMU before we call
|
|
|
|
* the IRQ tracing functions as they might access vmalloc space or
|
|
|
|
* perform IOs for console output.
|
|
|
|
*
|
|
|
|
* To speed up the syscall path where interrupts stay on, let's check
|
|
|
|
* first if we are changing the MSR value at all.
|
|
|
|
*/
|
2020-02-07 20:20:57 +03:00
|
|
|
tophys_novmstack r12, r1
|
2019-04-30 15:39:01 +03:00
|
|
|
lwz r12,_MSR(r12)
|
|
|
|
andi. r12,r12,MSR_EE
|
|
|
|
bne 1f
|
|
|
|
|
|
|
|
/* MSR isn't changing, just transition directly */
|
|
|
|
#endif
|
|
|
|
mtspr SPRN_SRR0,r11
|
|
|
|
mtspr SPRN_SRR1,r10
|
|
|
|
mtlr r9
|
|
|
|
SYNC
|
|
|
|
RFI /* jump to handler, enable MMU */
|
|
|
|
|
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
1: /* MSR is changing, re-enable MMU so we can notify lockdep. We need to
|
|
|
|
* keep interrupts disabled at this point otherwise we might risk
|
|
|
|
* taking an interrupt before we tell lockdep they are enabled.
|
|
|
|
*/
|
2009-06-17 21:43:59 +04:00
|
|
|
lis r12,reenable_mmu@h
|
|
|
|
ori r12,r12,reenable_mmu@l
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r0, MSR_KERNEL)
|
2009-06-17 21:43:59 +04:00
|
|
|
mtspr SPRN_SRR0,r12
|
2019-04-30 15:39:01 +03:00
|
|
|
mtspr SPRN_SRR1,r0
|
2009-06-17 21:43:59 +04:00
|
|
|
SYNC
|
|
|
|
RFI
|
|
|
|
|
2019-04-30 15:39:01 +03:00
|
|
|
reenable_mmu:
|
2011-11-10 20:04:17 +04:00
|
|
|
/*
|
2019-04-30 15:39:05 +03:00
|
|
|
* We save a bunch of GPRs,
|
2012-04-10 11:21:35 +04:00
|
|
|
* r3 can be different from GPR3(r1) at this point, r9 and r11
|
|
|
|
* contains the old MSR and handler address respectively,
|
|
|
|
* r4 & r5 can contain page fault arguments that need to be passed
|
2020-01-07 12:16:40 +03:00
|
|
|
* along as well. r0, r6-r8, r12, CCR, CTR, XER etc... are left
|
|
|
|
* clobbered as they aren't useful past this point.
|
2011-11-10 20:04:17 +04:00
|
|
|
*/
|
2019-04-30 15:39:01 +03:00
|
|
|
|
2012-04-10 11:21:35 +04:00
|
|
|
stwu r1,-32(r1)
|
|
|
|
stw r9,8(r1)
|
|
|
|
stw r11,12(r1)
|
|
|
|
stw r3,16(r1)
|
|
|
|
stw r4,20(r1)
|
|
|
|
stw r5,24(r1)
|
2019-04-30 15:39:01 +03:00
|
|
|
|
|
|
|
/* If we are disabling interrupts (normal case), simply log it with
|
|
|
|
* lockdep
|
|
|
|
*/
|
|
|
|
1: bl trace_hardirqs_off
|
2020-01-07 12:16:40 +03:00
|
|
|
lwz r5,24(r1)
|
2012-04-10 11:21:35 +04:00
|
|
|
lwz r4,20(r1)
|
|
|
|
lwz r3,16(r1)
|
|
|
|
lwz r11,12(r1)
|
|
|
|
lwz r9,8(r1)
|
|
|
|
addi r1,r1,32
|
2019-04-30 15:39:01 +03:00
|
|
|
mtctr r11
|
2009-06-17 21:43:59 +04:00
|
|
|
mtlr r9
|
|
|
|
bctr /* jump to handler */
|
|
|
|
#endif /* CONFIG_TRACE_IRQFLAGS */
|
2005-10-10 16:36:14 +04:00
|
|
|
|
2018-11-17 13:24:56 +03:00
|
|
|
#if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
|
2006-04-18 15:49:11 +04:00
|
|
|
4: rlwinm r12,r12,0,~_TLF_NAPPING
|
2019-01-31 13:09:04 +03:00
|
|
|
stw r12,TI_LOCAL_FLAGS(r2)
|
2008-06-19 01:26:52 +04:00
|
|
|
b power_save_ppc32_restore
|
2008-05-14 08:30:48 +04:00
|
|
|
|
|
|
|
7: rlwinm r12,r12,0,~_TLF_SLEEPING
|
2019-01-31 13:09:04 +03:00
|
|
|
stw r12,TI_LOCAL_FLAGS(r2)
|
2008-05-14 08:30:48 +04:00
|
|
|
lwz r9,_MSR(r11) /* if sleeping, clear MSR.EE */
|
|
|
|
rlwinm r9,r9,0,~MSR_EE
|
|
|
|
lwz r12,_LINK(r11) /* and return to address in LR */
|
2019-03-11 11:30:31 +03:00
|
|
|
kuap_restore r11, r2, r3, r4, r5
|
2020-01-27 13:42:04 +03:00
|
|
|
lwz r2, GPR2(r11)
|
2008-05-14 08:30:48 +04:00
|
|
|
b fast_exception_return
|
2006-03-27 08:03:03 +04:00
|
|
|
#endif
|
|
|
|
|
powerpc/32: Add early stack overflow detection with VMAP stack.
To avoid recursive faults, stack overflow detection has to be
performed before writing in the stack in exception prologs.
Do it by checking the alignment. If the stack pointer alignment is
wrong, it means it is pointing to the following or preceding page.
Without VMAP stack, a stack overflow is catastrophic. With VMAP
stack, a stack overflow isn't destructive, so don't panic. Kill
the task with SIGSEGV instead.
A dedicated overflow stack is set up for each CPU.
lkdtm: Performing direct entry EXHAUST_STACK
lkdtm: Calling function with 512 frame size to depth 32 ...
lkdtm: loop 32/32 ...
lkdtm: loop 31/32 ...
lkdtm: loop 30/32 ...
lkdtm: loop 29/32 ...
lkdtm: loop 28/32 ...
lkdtm: loop 27/32 ...
lkdtm: loop 26/32 ...
lkdtm: loop 25/32 ...
lkdtm: loop 24/32 ...
lkdtm: loop 23/32 ...
lkdtm: loop 22/32 ...
lkdtm: loop 21/32 ...
lkdtm: loop 20/32 ...
Kernel stack overflow in process test[359], r1=c900c008
Oops: Kernel stack overflow, sig: 6 [#1]
BE PAGE_SIZE=4K MMU=Hash PowerMac
Modules linked in:
CPU: 0 PID: 359 Comm: test Not tainted 5.3.0-rc7+ #2225
NIP: c0622060 LR: c0626710 CTR: 00000000
REGS: c0895f48 TRAP: 0000 Not tainted (5.3.0-rc7+)
MSR: 00001032 <ME,IR,DR,RI> CR: 28004224 XER: 00000000
GPR00: c0626ca4 c900c008 c783c000 c07335cc c900c010 c07335cc c900c0f0 c07335cc
GPR08: c900c0f0 00000001 00000000 00000000 28008222 00000000 00000000 00000000
GPR16: 00000000 00000000 10010128 10010000 b799c245 10010158 c07335cc 00000025
GPR24: c0690000 c08b91d4 c068f688 00000020 c900c0f0 c068f668 c08b95b4 c08b91d4
NIP [c0622060] format_decode+0x0/0x4d4
LR [c0626710] vsnprintf+0x80/0x5fc
Call Trace:
[c900c068] [c0626ca4] vscnprintf+0x18/0x48
[c900c078] [c007b944] vprintk_store+0x40/0x214
[c900c0b8] [c007bf50] vprintk_emit+0x90/0x1dc
[c900c0e8] [c007c5cc] printk+0x50/0x60
[c900c128] [c03da5b0] recursive_loop+0x44/0x6c
[c900c338] [c03da5c4] recursive_loop+0x58/0x6c
[c900c548] [c03da5c4] recursive_loop+0x58/0x6c
[c900c758] [c03da5c4] recursive_loop+0x58/0x6c
[c900c968] [c03da5c4] recursive_loop+0x58/0x6c
[c900cb78] [c03da5c4] recursive_loop+0x58/0x6c
[c900cd88] [c03da5c4] recursive_loop+0x58/0x6c
[c900cf98] [c03da5c4] recursive_loop+0x58/0x6c
[c900d1a8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d3b8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d5c8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d7d8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d9e8] [c03da5c4] recursive_loop+0x58/0x6c
[c900dbf8] [c03da5c4] recursive_loop+0x58/0x6c
[c900de08] [c03da67c] lkdtm_EXHAUST_STACK+0x30/0x4c
[c900de18] [c03da3e8] direct_entry+0xc8/0x140
[c900de48] [c029fb40] full_proxy_write+0x64/0xcc
[c900de68] [c01500f8] __vfs_write+0x30/0x1d0
[c900dee8] [c0152cb8] vfs_write+0xb8/0x1d4
[c900df08] [c0152f7c] ksys_write+0x58/0xe8
[c900df38] [c0014208] ret_from_syscall+0x0/0x34
--- interrupt: c01 at 0xf806664
LR = 0x1000c868
Instruction dump:
4bffff91 80010014 7c832378 7c0803a6 38210010 4e800020 3d20c08a 3ca0c089
8089a0cc 38a58f0c 38600001 4ba2d494 <9421ffe0> 7c0802a6 bfc10018 7c9f2378
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1b89c121b4070c7ee99e4f22cc178f15a736b07b.1576916812.git.christophe.leroy@c-s.fr
2019-12-21 11:32:29 +03:00
|
|
|
#ifndef CONFIG_VMAP_STACK
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
|
|
|
* On kernel stack overflow, load up an initial stack pointer
|
|
|
|
* and call StackOverflow(regs), which should not return.
|
|
|
|
*/
|
|
|
|
stack_ovf:
|
|
|
|
/* sometimes we use a statically-allocated stack, which is OK. */
|
2006-04-18 15:49:11 +04:00
|
|
|
lis r12,_end@h
|
|
|
|
ori r12,r12,_end@l
|
|
|
|
cmplw r1,r12
|
|
|
|
ble 5b /* r1 <= &_end is OK */
|
2005-10-10 16:36:14 +04:00
|
|
|
SAVE_NVGPRS(r11)
|
|
|
|
addi r3,r1,STACK_FRAME_OVERHEAD
|
|
|
|
lis r1,init_thread_union@ha
|
|
|
|
addi r1,r1,init_thread_union@l
|
|
|
|
addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
|
|
|
|
lis r9,StackOverflow@ha
|
|
|
|
addi r9,r9,StackOverflow@l
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL)
|
2018-01-12 15:45:23 +03:00
|
|
|
#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
|
powerpc/8xx: Perf events on PPC 8xx
This patch has been reworked since RFC version. In the RFC, this patch
was preceded by a patch clearing MSR RI for all PPC32 at all time at
exception prologs. Now MSR RI clearing is done only when this 8xx perf
events functionality is compiled in, it is therefore limited to 8xx
and merged inside this patch.
Other main changes have been to take into account detailed review from
Peter Zijlstra. The instructions counter has been reworked to behave
as a free running counter like the three other counters.
The 8xx has no PMU, however some events can be emulated by other means.
This patch implements the following events (as reported by 'perf list'):
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
dTLB-load-misses [Hardware cache event]
iTLB-load-misses [Hardware cache event]
'cycles' event is implemented using the timebase clock. Timebase clock
corresponds to CPU clock divided by 16, so number of cycles is
approximatly 16 times the number of TB ticks
On the 8xx, TLB misses are handled by software. It is therefore
easy to count all TLB misses each time the TLB miss exception is
called.
'instructions' is calculated by using instruction watchpoint counter.
This patch sets counter A to count instructions at address greater
than 0, hence we count all instructions executed while MSR RI bit is
set. The counter is set to the maximum which is 0xffff. Every 65535
instructions, debug instruction breakpoint exception fires. The
exception handler increments a counter in memory which then
represent the upper part of the instruction counter. We therefore
end up with a 48 bits counter. In order to avoid unnecessary overhead
while no perf event is active, this counter is started when the first
event referring to this counter is added, and the counter is stopped
when the last event referring to it is deleted. In order to properly
support breakpoint exceptions, MSR RI bit has to be unset in exception
epilogs in order to avoid breakpoint exceptions during critical
sections during changes to SRR0 and SRR1 would be problematic.
All counters are handled as free running counters.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-12-15 15:42:18 +03:00
|
|
|
mtspr SPRN_NRI, r0
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
mtspr SPRN_SRR0,r9
|
|
|
|
mtspr SPRN_SRR1,r10
|
|
|
|
SYNC
|
|
|
|
RFI
|
2020-03-31 19:03:44 +03:00
|
|
|
_ASM_NOKPROBE_SYMBOL(stack_ovf)
|
powerpc/32: Add early stack overflow detection with VMAP stack.
To avoid recursive faults, stack overflow detection has to be
performed before writing in the stack in exception prologs.
Do it by checking the alignment. If the stack pointer alignment is
wrong, it means it is pointing to the following or preceding page.
Without VMAP stack, a stack overflow is catastrophic. With VMAP
stack, a stack overflow isn't destructive, so don't panic. Kill
the task with SIGSEGV instead.
A dedicated overflow stack is set up for each CPU.
lkdtm: Performing direct entry EXHAUST_STACK
lkdtm: Calling function with 512 frame size to depth 32 ...
lkdtm: loop 32/32 ...
lkdtm: loop 31/32 ...
lkdtm: loop 30/32 ...
lkdtm: loop 29/32 ...
lkdtm: loop 28/32 ...
lkdtm: loop 27/32 ...
lkdtm: loop 26/32 ...
lkdtm: loop 25/32 ...
lkdtm: loop 24/32 ...
lkdtm: loop 23/32 ...
lkdtm: loop 22/32 ...
lkdtm: loop 21/32 ...
lkdtm: loop 20/32 ...
Kernel stack overflow in process test[359], r1=c900c008
Oops: Kernel stack overflow, sig: 6 [#1]
BE PAGE_SIZE=4K MMU=Hash PowerMac
Modules linked in:
CPU: 0 PID: 359 Comm: test Not tainted 5.3.0-rc7+ #2225
NIP: c0622060 LR: c0626710 CTR: 00000000
REGS: c0895f48 TRAP: 0000 Not tainted (5.3.0-rc7+)
MSR: 00001032 <ME,IR,DR,RI> CR: 28004224 XER: 00000000
GPR00: c0626ca4 c900c008 c783c000 c07335cc c900c010 c07335cc c900c0f0 c07335cc
GPR08: c900c0f0 00000001 00000000 00000000 28008222 00000000 00000000 00000000
GPR16: 00000000 00000000 10010128 10010000 b799c245 10010158 c07335cc 00000025
GPR24: c0690000 c08b91d4 c068f688 00000020 c900c0f0 c068f668 c08b95b4 c08b91d4
NIP [c0622060] format_decode+0x0/0x4d4
LR [c0626710] vsnprintf+0x80/0x5fc
Call Trace:
[c900c068] [c0626ca4] vscnprintf+0x18/0x48
[c900c078] [c007b944] vprintk_store+0x40/0x214
[c900c0b8] [c007bf50] vprintk_emit+0x90/0x1dc
[c900c0e8] [c007c5cc] printk+0x50/0x60
[c900c128] [c03da5b0] recursive_loop+0x44/0x6c
[c900c338] [c03da5c4] recursive_loop+0x58/0x6c
[c900c548] [c03da5c4] recursive_loop+0x58/0x6c
[c900c758] [c03da5c4] recursive_loop+0x58/0x6c
[c900c968] [c03da5c4] recursive_loop+0x58/0x6c
[c900cb78] [c03da5c4] recursive_loop+0x58/0x6c
[c900cd88] [c03da5c4] recursive_loop+0x58/0x6c
[c900cf98] [c03da5c4] recursive_loop+0x58/0x6c
[c900d1a8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d3b8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d5c8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d7d8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d9e8] [c03da5c4] recursive_loop+0x58/0x6c
[c900dbf8] [c03da5c4] recursive_loop+0x58/0x6c
[c900de08] [c03da67c] lkdtm_EXHAUST_STACK+0x30/0x4c
[c900de18] [c03da3e8] direct_entry+0xc8/0x140
[c900de48] [c029fb40] full_proxy_write+0x64/0xcc
[c900de68] [c01500f8] __vfs_write+0x30/0x1d0
[c900dee8] [c0152cb8] vfs_write+0xb8/0x1d4
[c900df08] [c0152f7c] ksys_write+0x58/0xe8
[c900df38] [c0014208] ret_from_syscall+0x0/0x34
--- interrupt: c01 at 0xf806664
LR = 0x1000c868
Instruction dump:
4bffff91 80010014 7c832378 7c0803a6 38210010 4e800020 3d20c08a 3ca0c089
8089a0cc 38a58f0c 38600001 4ba2d494 <9421ffe0> 7c0802a6 bfc10018 7c9f2378
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1b89c121b4070c7ee99e4f22cc178f15a736b07b.1576916812.git.christophe.leroy@c-s.fr
2019-12-21 11:32:29 +03:00
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
|
2019-04-30 15:39:02 +03:00
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
trace_syscall_entry_irq_off:
|
|
|
|
/*
|
|
|
|
* Syscall shouldn't happen while interrupts are disabled,
|
|
|
|
* so let's do a warning here.
|
|
|
|
*/
|
|
|
|
0: trap
|
|
|
|
EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
|
|
|
|
bl trace_hardirqs_on
|
|
|
|
|
|
|
|
/* Now enable for real */
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r10, MSR_KERNEL | MSR_EE)
|
2019-04-30 15:39:02 +03:00
|
|
|
mtmsr r10
|
|
|
|
|
|
|
|
REST_GPR(0, r1)
|
|
|
|
REST_4GPRS(3, r1)
|
|
|
|
REST_2GPRS(7, r1)
|
|
|
|
b DoSyscall
|
|
|
|
#endif /* CONFIG_TRACE_IRQFLAGS */
|
|
|
|
|
|
|
|
.globl transfer_to_syscall
|
|
|
|
transfer_to_syscall:
|
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
andi. r12,r9,MSR_EE
|
|
|
|
beq- trace_syscall_entry_irq_off
|
|
|
|
#endif /* CONFIG_TRACE_IRQFLAGS */
|
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
|
|
|
* Handle a system call.
|
|
|
|
*/
|
|
|
|
.stabs "arch/powerpc/kernel/",N_SO,0,0,0f
|
|
|
|
.stabs "entry_32.S",N_SO,0,0,0f
|
|
|
|
0:
|
|
|
|
|
|
|
|
_GLOBAL(DoSyscall)
|
|
|
|
stw r3,ORIG_GPR3(r1)
|
|
|
|
li r12,0
|
|
|
|
stw r12,RESULT(r1)
|
2009-06-17 21:43:59 +04:00
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
2019-04-30 15:39:01 +03:00
|
|
|
/* Make sure interrupts are enabled */
|
2009-06-17 21:43:59 +04:00
|
|
|
mfmsr r11
|
|
|
|
andi. r12,r11,MSR_EE
|
2019-04-30 15:39:01 +03:00
|
|
|
/* We came in with interrupts disabled, we WARN and mark them enabled
|
|
|
|
* for lockdep now */
|
|
|
|
0: tweqi r12, 0
|
|
|
|
EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
|
2009-06-17 21:43:59 +04:00
|
|
|
#endif /* CONFIG_TRACE_IRQFLAGS */
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r11,TI_FLAGS(r2)
|
2015-01-15 04:01:42 +03:00
|
|
|
andi. r11,r11,_TIF_SYSCALL_DOTRACE
|
2005-10-10 16:36:14 +04:00
|
|
|
bne- syscall_dotrace
|
|
|
|
syscall_dotrace_cont:
|
|
|
|
cmplwi 0,r0,NR_syscalls
|
|
|
|
lis r10,sys_call_table@h
|
|
|
|
ori r10,r10,sys_call_table@l
|
|
|
|
slwi r0,r0,2
|
|
|
|
bge- 66f
|
2018-07-28 02:06:38 +03:00
|
|
|
|
|
|
|
barrier_nospec_asm
|
|
|
|
/*
|
|
|
|
* Prevent the load of the handler below (based on the user-passed
|
|
|
|
* system call number) being speculatively executed until the test
|
|
|
|
* against NR_syscalls and branch to .66f above has
|
|
|
|
* committed.
|
|
|
|
*/
|
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
lwzx r10,r10,r0 /* Fetch system call handler [ptr] */
|
|
|
|
mtlr r10
|
|
|
|
addi r9,r1,STACK_FRAME_OVERHEAD
|
|
|
|
PPC440EP_ERR42
|
|
|
|
blrl /* Call handler */
|
|
|
|
.globl ret_from_syscall
|
|
|
|
ret_from_syscall:
|
2018-06-02 15:44:01 +03:00
|
|
|
#ifdef CONFIG_DEBUG_RSEQ
|
|
|
|
/* Check whether the syscall is issued inside a restartable sequence */
|
|
|
|
stw r3,GPR3(r1)
|
|
|
|
addi r3,r1,STACK_FRAME_OVERHEAD
|
|
|
|
bl rseq_syscall
|
|
|
|
lwz r3,GPR3(r1)
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
mr r6,r3
|
|
|
|
/* disable interrupts so current_thread_info()->flags can't change */
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL) /* doesn't include MSR_EE */
|
2009-06-17 21:43:59 +04:00
|
|
|
/* Note: We don't bother telling lockdep about it */
|
2005-10-10 16:36:14 +04:00
|
|
|
SYNC
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r10
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r9,TI_FLAGS(r2)
|
powerpc/kernel: Switch to using MAX_ERRNO
Currently on powerpc we have our own #define for the highest (negative)
errno value, called _LAST_ERRNO. This is defined to be 516, for reasons
which are not clear.
The generic code, and x86, use MAX_ERRNO, which is defined to be 4095.
In particular seccomp uses MAX_ERRNO to restrict the value that a
seccomp filter can return.
Currently with the mismatch between _LAST_ERRNO and MAX_ERRNO, a seccomp
tracer wanting to return 600, expecting it to be seen as an error, would
instead find on powerpc that userspace sees a successful syscall with a
return value of 600.
To avoid this inconsistency, switch powerpc to use MAX_ERRNO.
We are somewhat confident that generic syscalls that can return a
non-error value above negative MAX_ERRNO have already been updated to
use force_successful_syscall_return().
I have also checked all the powerpc specific syscalls, and believe that
none of them expect to return a non-error value between -MAX_ERRNO and
-516. So this change should be safe ...
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>
2015-07-23 13:21:01 +03:00
|
|
|
li r8,-MAX_ERRNO
|
2015-01-15 04:01:42 +03:00
|
|
|
andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
|
2005-10-10 16:36:14 +04:00
|
|
|
bne- syscall_exit_work
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
cmplw 0,r3,r8
|
|
|
|
blt+ syscall_exit_cont
|
|
|
|
lwz r11,_CCR(r1) /* Load CR */
|
|
|
|
neg r3,r3
|
|
|
|
oris r11,r11,0x1000 /* Set SO bit in CR */
|
|
|
|
stw r11,_CCR(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
syscall_exit_cont:
|
2009-06-17 21:43:59 +04:00
|
|
|
lwz r8,_MSR(r1)
|
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
/* If we are going to return from the syscall with interrupts
|
2019-04-30 15:39:01 +03:00
|
|
|
* off, we trace that here. It shouldn't normally happen.
|
2009-06-17 21:43:59 +04:00
|
|
|
*/
|
|
|
|
andi. r10,r8,MSR_EE
|
|
|
|
bne+ 1f
|
|
|
|
stw r3,GPR3(r1)
|
|
|
|
bl trace_hardirqs_off
|
|
|
|
lwz r3,GPR3(r1)
|
|
|
|
1:
|
|
|
|
#endif /* CONFIG_TRACE_IRQFLAGS */
|
2005-10-10 16:36:14 +04:00
|
|
|
#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
|
2008-04-10 01:15:40 +04:00
|
|
|
/* If the process has its own DBCR0 value, load it up. The internal
|
|
|
|
debug mode bit tells us that dbcr0 should be loaded. */
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r0,THREAD+THREAD_DBCR0(r2)
|
2008-07-25 23:27:33 +04:00
|
|
|
andis. r10,r0,DBCR0_IDM@h
|
2005-10-10 16:36:14 +04:00
|
|
|
bnel- load_dbcr0
|
|
|
|
#endif
|
2007-10-31 08:42:19 +03:00
|
|
|
#ifdef CONFIG_44x
|
2010-03-05 13:43:12 +03:00
|
|
|
BEGIN_MMU_FTR_SECTION
|
2007-10-31 08:42:19 +03:00
|
|
|
lis r4,icache_44x_need_flush@ha
|
|
|
|
lwz r5,icache_44x_need_flush@l(r4)
|
|
|
|
cmplwi cr0,r5,0
|
|
|
|
bne- 2f
|
|
|
|
1:
|
2010-03-05 13:43:12 +03:00
|
|
|
END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_47x)
|
2007-10-31 08:42:19 +03:00
|
|
|
#endif /* CONFIG_44x */
|
2007-11-10 01:17:49 +03:00
|
|
|
BEGIN_FTR_SECTION
|
|
|
|
lwarx r7,0,r1
|
|
|
|
END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
|
2005-10-10 16:36:14 +04:00
|
|
|
stwcx. r0,0,r1 /* to clear the reservation */
|
2019-01-31 13:09:04 +03:00
|
|
|
ACCOUNT_CPU_USER_EXIT(r2, r5, r7)
|
2019-03-11 11:30:35 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_32
|
|
|
|
kuep_unlock r5, r7
|
|
|
|
#endif
|
2019-03-11 11:30:31 +03:00
|
|
|
kuap_check r2, r4
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r4,_LINK(r1)
|
|
|
|
lwz r5,_CCR(r1)
|
|
|
|
mtlr r4
|
|
|
|
mtcr r5
|
|
|
|
lwz r7,_NIP(r1)
|
|
|
|
lwz r2,GPR2(r1)
|
|
|
|
lwz r1,GPR1(r1)
|
2018-01-12 15:45:23 +03:00
|
|
|
#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
|
powerpc/8xx: Perf events on PPC 8xx
This patch has been reworked since RFC version. In the RFC, this patch
was preceded by a patch clearing MSR RI for all PPC32 at all time at
exception prologs. Now MSR RI clearing is done only when this 8xx perf
events functionality is compiled in, it is therefore limited to 8xx
and merged inside this patch.
Other main changes have been to take into account detailed review from
Peter Zijlstra. The instructions counter has been reworked to behave
as a free running counter like the three other counters.
The 8xx has no PMU, however some events can be emulated by other means.
This patch implements the following events (as reported by 'perf list'):
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
dTLB-load-misses [Hardware cache event]
iTLB-load-misses [Hardware cache event]
'cycles' event is implemented using the timebase clock. Timebase clock
corresponds to CPU clock divided by 16, so number of cycles is
approximatly 16 times the number of TB ticks
On the 8xx, TLB misses are handled by software. It is therefore
easy to count all TLB misses each time the TLB miss exception is
called.
'instructions' is calculated by using instruction watchpoint counter.
This patch sets counter A to count instructions at address greater
than 0, hence we count all instructions executed while MSR RI bit is
set. The counter is set to the maximum which is 0xffff. Every 65535
instructions, debug instruction breakpoint exception fires. The
exception handler increments a counter in memory which then
represent the upper part of the instruction counter. We therefore
end up with a 48 bits counter. In order to avoid unnecessary overhead
while no perf event is active, this counter is started when the first
event referring to this counter is added, and the counter is stopped
when the last event referring to it is deleted. In order to properly
support breakpoint exceptions, MSR RI bit has to be unset in exception
epilogs in order to avoid breakpoint exceptions during critical
sections during changes to SRR0 and SRR1 would be problematic.
All counters are handled as free running counters.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-12-15 15:42:18 +03:00
|
|
|
mtspr SPRN_NRI, r0
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
mtspr SPRN_SRR0,r7
|
|
|
|
mtspr SPRN_SRR1,r8
|
|
|
|
SYNC
|
|
|
|
RFI
|
2007-10-31 08:42:19 +03:00
|
|
|
#ifdef CONFIG_44x
|
|
|
|
2: li r7,0
|
|
|
|
iccci r0,r0
|
|
|
|
stw r7,icache_44x_need_flush@l(r4)
|
|
|
|
b 1b
|
|
|
|
#endif /* CONFIG_44x */
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
66: li r3,-ENOSYS
|
|
|
|
b ret_from_syscall
|
|
|
|
|
|
|
|
.globl ret_from_fork
|
|
|
|
ret_from_fork:
|
|
|
|
REST_NVGPRS(r1)
|
|
|
|
bl schedule_tail
|
|
|
|
li r3,0
|
|
|
|
b ret_from_syscall
|
|
|
|
|
2012-09-13 02:32:42 +04:00
|
|
|
.globl ret_from_kernel_thread
|
|
|
|
ret_from_kernel_thread:
|
|
|
|
REST_NVGPRS(r1)
|
|
|
|
bl schedule_tail
|
|
|
|
mtlr r14
|
|
|
|
mr r3,r15
|
|
|
|
PPC440EP_ERR42
|
|
|
|
blrl
|
|
|
|
li r3,0
|
2012-08-31 23:48:05 +04:00
|
|
|
b ret_from_syscall
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
/* Traced system call support */
|
|
|
|
syscall_dotrace:
|
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
li r0,0xc00
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r0,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
addi r3,r1,STACK_FRAME_OVERHEAD
|
|
|
|
bl do_syscall_trace_enter
|
2008-07-27 10:51:03 +04:00
|
|
|
/*
|
|
|
|
* Restore argument registers possibly just changed.
|
|
|
|
* We use the return value of do_syscall_trace_enter
|
|
|
|
* for call number to look up in the table (r0).
|
|
|
|
*/
|
|
|
|
mr r0,r3
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r3,GPR3(r1)
|
|
|
|
lwz r4,GPR4(r1)
|
|
|
|
lwz r5,GPR5(r1)
|
|
|
|
lwz r6,GPR6(r1)
|
|
|
|
lwz r7,GPR7(r1)
|
|
|
|
lwz r8,GPR8(r1)
|
|
|
|
REST_NVGPRS(r1)
|
2015-07-23 13:21:02 +03:00
|
|
|
|
|
|
|
cmplwi r0,NR_syscalls
|
|
|
|
/* Return code is already in r3 thanks to do_syscall_trace_enter() */
|
|
|
|
bge- ret_from_syscall
|
2005-10-10 16:36:14 +04:00
|
|
|
b syscall_dotrace_cont
|
|
|
|
|
|
|
|
syscall_exit_work:
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
andi. r0,r9,_TIF_RESTOREALL
|
2006-03-08 05:24:22 +03:00
|
|
|
beq+ 0f
|
|
|
|
REST_NVGPRS(r1)
|
|
|
|
b 2f
|
|
|
|
0: cmplw 0,r3,r8
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
blt+ 1f
|
|
|
|
andi. r0,r9,_TIF_NOERROR
|
|
|
|
bne- 1f
|
|
|
|
lwz r11,_CCR(r1) /* Load CR */
|
|
|
|
neg r3,r3
|
|
|
|
oris r11,r11,0x1000 /* Set SO bit in CR */
|
|
|
|
stw r11,_CCR(r1)
|
|
|
|
|
|
|
|
1: stw r6,RESULT(r1) /* Save result */
|
2005-10-10 16:36:14 +04:00
|
|
|
stw r3,GPR3(r1) /* Update return value */
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
|
|
|
|
beq 4f
|
|
|
|
|
2006-03-08 05:24:22 +03:00
|
|
|
/* Clear per-syscall TIF flags if any are set. */
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
|
|
|
|
li r11,_TIF_PERSYSCALL_MASK
|
2019-01-31 13:09:04 +03:00
|
|
|
addi r12,r2,TI_FLAGS
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
3: lwarx r8,0,r12
|
|
|
|
andc r8,r8,r11
|
|
|
|
stwcx. r8,0,r12
|
|
|
|
bne- 3b
|
|
|
|
|
|
|
|
4: /* Anything which requires enabling interrupts? */
|
2015-01-15 04:01:42 +03:00
|
|
|
andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP)
|
2006-03-08 05:24:22 +03:00
|
|
|
beq ret_from_except
|
|
|
|
|
2009-06-17 21:43:59 +04:00
|
|
|
/* Re-enable interrupts. There is no need to trace that with
|
|
|
|
* lockdep as we are supposed to have IRQs on at this point
|
|
|
|
*/
|
2006-03-08 05:24:22 +03:00
|
|
|
ori r10,r10,MSR_EE
|
|
|
|
SYNC
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r10
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
|
|
|
|
/* Save NVGPRS if they're not saved already */
|
2005-10-28 16:45:25 +04:00
|
|
|
lwz r4,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
andi. r4,r4,1
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
beq 5f
|
2005-10-10 16:36:14 +04:00
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
li r4,0xc00
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r4,_TRAP(r1)
|
2006-03-08 05:24:22 +03:00
|
|
|
5:
|
2005-10-10 16:36:14 +04:00
|
|
|
addi r3,r1,STACK_FRAME_OVERHEAD
|
|
|
|
bl do_syscall_trace_leave
|
2006-03-08 05:24:22 +03:00
|
|
|
b ret_from_except_full
|
2005-10-10 16:36:14 +04:00
|
|
|
|
2020-01-31 14:34:54 +03:00
|
|
|
/*
|
|
|
|
* System call was called from kernel. We get here with SRR1 in r9.
|
|
|
|
* Mark the exception as recoverable once we have retrieved SRR0,
|
|
|
|
* trap a warning and return ENOSYS with CR[SO] set.
|
|
|
|
*/
|
|
|
|
.globl ret_from_kernel_syscall
|
|
|
|
ret_from_kernel_syscall:
|
|
|
|
mfspr r9, SPRN_SRR0
|
|
|
|
mfspr r10, SPRN_SRR1
|
|
|
|
#if !defined(CONFIG_4xx) && !defined(CONFIG_BOOKE)
|
|
|
|
LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~(MSR_IR|MSR_DR))
|
|
|
|
mtmsr r11
|
|
|
|
#endif
|
|
|
|
|
|
|
|
0: trap
|
|
|
|
EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
|
|
|
|
|
|
|
|
li r3, ENOSYS
|
|
|
|
crset so
|
|
|
|
#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
|
|
|
|
mtspr SPRN_NRI, r0
|
|
|
|
#endif
|
|
|
|
mtspr SPRN_SRR0, r9
|
|
|
|
mtspr SPRN_SRR1, r10
|
|
|
|
SYNC
|
|
|
|
RFI
|
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
[PATCH] syscall entry/exit revamp
This cleanup patch speeds up the null syscall path on ppc64 by about 3%,
and brings the ppc32 and ppc64 code slightly closer together.
The ppc64 code was checking current_thread_info()->flags twice in the
syscall exit path; once for TIF_SYSCALL_T_OR_A before disabling
interrupts, and then again for TIF_SIGPENDING|TIF_NEED_RESCHED etc after
disabling interrupts. Now we do the same as ppc32 -- check the flags
only once in the fast path, and re-enable interrupts if necessary in the
ptrace case.
The patch abolishes the 'syscall_noerror' member of struct thread_info
and replaces it with a TIF_NOERROR bit in the flags, which is handled in
the slow path. This shortens the syscall entry code, which no longer
needs to clear syscall_noerror.
The patch adds a TIF_SAVE_NVGPRS flag which causes the syscall exit slow
path to save the non-volatile GPRs into a signal frame. This removes the
need for the assembly wrappers around sys_sigsuspend(),
sys_rt_sigsuspend(), et al which existed solely to save those registers
in advance. It also means I don't have to add new wrappers for ppoll()
and pselect(), which is what I was supposed to be doing when I got
distracted into this...
Finally, it unifies the ppc64 and ppc32 methods of handling syscall exit
directly into a signal handler (as required by sigsuspend et al) by
introducing a TIF_RESTOREALL flag which causes _all_ the registers to be
reloaded from the pt_regs by taking the ret_from_exception path, instead
of the normal syscall exit path which stomps on the callee-saved GPRs.
It appears to pass an LTP test run on ppc64, and passes basic testing on
ppc32 too. Brief tests of ptrace functionality with strace and gdb also
appear OK. I wouldn't send it to Linus for 2.6.15 just yet though :)
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-15 21:52:18 +03:00
|
|
|
* The fork/clone functions need to copy the full register set into
|
|
|
|
* the child process. Therefore we need to save all the nonvolatile
|
|
|
|
* registers (r13 - r31) before calling the C code.
|
2005-10-10 16:36:14 +04:00
|
|
|
*/
|
|
|
|
.globl ppc_fork
|
|
|
|
ppc_fork:
|
|
|
|
SAVE_NVGPRS(r1)
|
2005-10-28 16:45:25 +04:00
|
|
|
lwz r0,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r0,_TRAP(r1) /* register set saved */
|
2005-10-10 16:36:14 +04:00
|
|
|
b sys_fork
|
|
|
|
|
|
|
|
.globl ppc_vfork
|
|
|
|
ppc_vfork:
|
|
|
|
SAVE_NVGPRS(r1)
|
2005-10-28 16:45:25 +04:00
|
|
|
lwz r0,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r0,_TRAP(r1) /* register set saved */
|
2005-10-10 16:36:14 +04:00
|
|
|
b sys_vfork
|
|
|
|
|
|
|
|
.globl ppc_clone
|
|
|
|
ppc_clone:
|
|
|
|
SAVE_NVGPRS(r1)
|
2005-10-28 16:45:25 +04:00
|
|
|
lwz r0,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r0,_TRAP(r1) /* register set saved */
|
2005-10-10 16:36:14 +04:00
|
|
|
b sys_clone
|
|
|
|
|
2019-07-22 15:26:56 +03:00
|
|
|
.globl ppc_clone3
|
|
|
|
ppc_clone3:
|
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
lwz r0,_TRAP(r1)
|
|
|
|
rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
|
|
|
|
stw r0,_TRAP(r1) /* register set saved */
|
|
|
|
b sys_clone3
|
|
|
|
|
2006-03-08 05:24:22 +03:00
|
|
|
.globl ppc_swapcontext
|
|
|
|
ppc_swapcontext:
|
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
lwz r0,_TRAP(r1)
|
|
|
|
rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
|
|
|
|
stw r0,_TRAP(r1) /* register set saved */
|
|
|
|
b sys_swapcontext
|
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
|
|
|
* Top-level page fault handling.
|
|
|
|
* This is in assembler because if do_page_fault tells us that
|
|
|
|
* it is a bad kernel page fault, we want to save the non-volatile
|
|
|
|
* registers before calling bad_page_fault.
|
|
|
|
*/
|
|
|
|
.globl handle_page_fault
|
|
|
|
handle_page_fault:
|
|
|
|
addi r3,r1,STACK_FRAME_OVERHEAD
|
2018-11-17 13:24:56 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_32
|
2017-08-08 09:37:24 +03:00
|
|
|
andis. r0,r5,DSISR_DABRMATCH@h
|
2017-07-19 07:49:25 +03:00
|
|
|
bne- handle_dabr_fault
|
|
|
|
#endif
|
2017-08-08 09:37:24 +03:00
|
|
|
bl do_page_fault
|
2005-10-10 16:36:14 +04:00
|
|
|
cmpwi r3,0
|
|
|
|
beq+ ret_from_except
|
|
|
|
SAVE_NVGPRS(r1)
|
2005-10-28 16:45:25 +04:00
|
|
|
lwz r0,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
clrrwi r0,r0,1
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r0,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
mr r5,r3
|
|
|
|
addi r3,r1,STACK_FRAME_OVERHEAD
|
|
|
|
lwz r4,_DAR(r1)
|
|
|
|
bl bad_page_fault
|
|
|
|
b ret_from_except_full
|
|
|
|
|
2018-11-17 13:24:56 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_32
|
2017-07-19 07:49:25 +03:00
|
|
|
/* We have a data breakpoint exception - handle it */
|
|
|
|
handle_dabr_fault:
|
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
lwz r0,_TRAP(r1)
|
|
|
|
clrrwi r0,r0,1
|
|
|
|
stw r0,_TRAP(r1)
|
|
|
|
bl do_break
|
|
|
|
b ret_from_except_full
|
|
|
|
#endif
|
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
|
|
|
* This routine switches between two different tasks. The process
|
|
|
|
* state of one is saved on its kernel stack. Then the state
|
|
|
|
* of the other is restored from its kernel stack. The memory
|
|
|
|
* management hardware is updated to the second process's state.
|
|
|
|
* Finally, we can return to the second process.
|
|
|
|
* On entry, r3 points to the THREAD for the current task, r4
|
|
|
|
* points to the THREAD for the new task.
|
|
|
|
*
|
|
|
|
* This routine is always called with interrupts disabled.
|
|
|
|
*
|
|
|
|
* Note: there are two ways to get to the "going out" portion
|
|
|
|
* of this code; either by coming in via the entry (_switch)
|
|
|
|
* or via "fork" which must set up an environment equivalent
|
|
|
|
* to the "_switch" path. If you change this , you'll have to
|
|
|
|
* change the fork code also.
|
|
|
|
*
|
|
|
|
* The code which creates the new task context is in 'copy_thread'
|
|
|
|
* in arch/ppc/kernel/process.c
|
|
|
|
*/
|
|
|
|
_GLOBAL(_switch)
|
|
|
|
stwu r1,-INT_FRAME_SIZE(r1)
|
|
|
|
mflr r0
|
|
|
|
stw r0,INT_FRAME_SIZE+4(r1)
|
|
|
|
/* r3-r12 are caller saved -- Cort */
|
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
stw r0,_NIP(r1) /* Return to switch caller */
|
|
|
|
mfmsr r11
|
|
|
|
li r0,MSR_FP /* Disable floating-point */
|
|
|
|
#ifdef CONFIG_ALTIVEC
|
|
|
|
BEGIN_FTR_SECTION
|
|
|
|
oris r0,r0,MSR_VEC@h /* Disable altivec */
|
|
|
|
mfspr r12,SPRN_VRSAVE /* save vrsave register value */
|
|
|
|
stw r12,THREAD+THREAD_VRSAVE(r2)
|
|
|
|
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
|
|
|
|
#endif /* CONFIG_ALTIVEC */
|
|
|
|
#ifdef CONFIG_SPE
|
2007-09-13 10:44:20 +04:00
|
|
|
BEGIN_FTR_SECTION
|
2005-10-10 16:36:14 +04:00
|
|
|
oris r0,r0,MSR_SPE@h /* Disable SPE */
|
|
|
|
mfspr r12,SPRN_SPEFSCR /* save spefscr register value */
|
|
|
|
stw r12,THREAD+THREAD_SPEFSCR(r2)
|
2007-09-13 10:44:20 +04:00
|
|
|
END_FTR_SECTION_IFSET(CPU_FTR_SPE)
|
2005-10-10 16:36:14 +04:00
|
|
|
#endif /* CONFIG_SPE */
|
|
|
|
and. r0,r0,r11 /* FP or altivec or SPE enabled? */
|
|
|
|
beq+ 1f
|
|
|
|
andc r11,r11,r0
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r11
|
2005-10-10 16:36:14 +04:00
|
|
|
isync
|
|
|
|
1: stw r11,_MSR(r1)
|
|
|
|
mfcr r10
|
|
|
|
stw r10,_CCR(r1)
|
|
|
|
stw r1,KSP(r3) /* Set old stack pointer */
|
|
|
|
|
2020-04-17 14:58:36 +03:00
|
|
|
kuap_check r2, r0
|
2005-10-10 16:36:14 +04:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* We need a sync somewhere here to make sure that if the
|
|
|
|
* previous task gets rescheduled on another CPU, it sees all
|
|
|
|
* stores it has performed on this one.
|
|
|
|
*/
|
|
|
|
sync
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
|
|
|
tophys(r0,r4)
|
2009-07-15 00:52:54 +04:00
|
|
|
mtspr SPRN_SPRG_THREAD,r0 /* Update current THREAD phys addr */
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r1,KSP(r4) /* Load new stack pointer */
|
|
|
|
|
|
|
|
/* save the old current 'last' for return value */
|
|
|
|
mr r3,r2
|
|
|
|
addi r2,r4,-THREAD /* Update current */
|
|
|
|
|
|
|
|
#ifdef CONFIG_ALTIVEC
|
|
|
|
BEGIN_FTR_SECTION
|
|
|
|
lwz r0,THREAD+THREAD_VRSAVE(r2)
|
|
|
|
mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
|
|
|
|
END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
|
|
|
|
#endif /* CONFIG_ALTIVEC */
|
|
|
|
#ifdef CONFIG_SPE
|
2007-09-13 10:44:20 +04:00
|
|
|
BEGIN_FTR_SECTION
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r0,THREAD+THREAD_SPEFSCR(r2)
|
|
|
|
mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */
|
2007-09-13 10:44:20 +04:00
|
|
|
END_FTR_SECTION_IFSET(CPU_FTR_SPE)
|
2005-10-10 16:36:14 +04:00
|
|
|
#endif /* CONFIG_SPE */
|
2017-01-24 13:37:20 +03:00
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r0,_CCR(r1)
|
|
|
|
mtcrf 0xFF,r0
|
|
|
|
/* r3-r12 are destroyed -- Cort */
|
|
|
|
REST_NVGPRS(r1)
|
|
|
|
|
|
|
|
lwz r4,_NIP(r1) /* Return to _switch caller in new task */
|
|
|
|
mtlr r4
|
|
|
|
addi r1,r1,INT_FRAME_SIZE
|
|
|
|
blr
|
|
|
|
|
|
|
|
.globl fast_exception_return
|
|
|
|
fast_exception_return:
|
|
|
|
#if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
|
|
|
|
andi. r10,r9,MSR_RI /* check for recoverable interrupt */
|
|
|
|
beq 1f /* if not, we've got problems */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
2: REST_4GPRS(3, r11)
|
|
|
|
lwz r10,_CCR(r11)
|
|
|
|
REST_GPR(1, r11)
|
|
|
|
mtcr r10
|
|
|
|
lwz r10,_LINK(r11)
|
|
|
|
mtlr r10
|
2019-02-27 14:45:30 +03:00
|
|
|
/* Clear the exception_marker on the stack to avoid confusing stacktrace */
|
|
|
|
li r10, 0
|
|
|
|
stw r10, 8(r11)
|
2005-10-10 16:36:14 +04:00
|
|
|
REST_GPR(10, r11)
|
2018-01-12 15:45:23 +03:00
|
|
|
#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
|
powerpc/8xx: Perf events on PPC 8xx
This patch has been reworked since RFC version. In the RFC, this patch
was preceded by a patch clearing MSR RI for all PPC32 at all time at
exception prologs. Now MSR RI clearing is done only when this 8xx perf
events functionality is compiled in, it is therefore limited to 8xx
and merged inside this patch.
Other main changes have been to take into account detailed review from
Peter Zijlstra. The instructions counter has been reworked to behave
as a free running counter like the three other counters.
The 8xx has no PMU, however some events can be emulated by other means.
This patch implements the following events (as reported by 'perf list'):
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
dTLB-load-misses [Hardware cache event]
iTLB-load-misses [Hardware cache event]
'cycles' event is implemented using the timebase clock. Timebase clock
corresponds to CPU clock divided by 16, so number of cycles is
approximatly 16 times the number of TB ticks
On the 8xx, TLB misses are handled by software. It is therefore
easy to count all TLB misses each time the TLB miss exception is
called.
'instructions' is calculated by using instruction watchpoint counter.
This patch sets counter A to count instructions at address greater
than 0, hence we count all instructions executed while MSR RI bit is
set. The counter is set to the maximum which is 0xffff. Every 65535
instructions, debug instruction breakpoint exception fires. The
exception handler increments a counter in memory which then
represent the upper part of the instruction counter. We therefore
end up with a 48 bits counter. In order to avoid unnecessary overhead
while no perf event is active, this counter is started when the first
event referring to this counter is added, and the counter is stopped
when the last event referring to it is deleted. In order to properly
support breakpoint exceptions, MSR RI bit has to be unset in exception
epilogs in order to avoid breakpoint exceptions during critical
sections during changes to SRR0 and SRR1 would be problematic.
All counters are handled as free running counters.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-12-15 15:42:18 +03:00
|
|
|
mtspr SPRN_NRI, r0
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
mtspr SPRN_SRR1,r9
|
|
|
|
mtspr SPRN_SRR0,r12
|
|
|
|
REST_GPR(9, r11)
|
|
|
|
REST_GPR(12, r11)
|
|
|
|
lwz r11,GPR11(r11)
|
|
|
|
SYNC
|
|
|
|
RFI
|
|
|
|
|
|
|
|
#if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
|
|
|
|
/* check if the exception happened in a restartable section */
|
|
|
|
1: lis r3,exc_exit_restart_end@ha
|
|
|
|
addi r3,r3,exc_exit_restart_end@l
|
|
|
|
cmplw r12,r3
|
2020-02-18 17:09:29 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_601
|
2019-08-26 18:52:14 +03:00
|
|
|
bge 2b
|
|
|
|
#else
|
2005-10-10 16:36:14 +04:00
|
|
|
bge 3f
|
2019-08-26 18:52:14 +03:00
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
lis r4,exc_exit_restart@ha
|
|
|
|
addi r4,r4,exc_exit_restart@l
|
|
|
|
cmplw r12,r4
|
2020-02-18 17:09:29 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_601
|
2019-08-26 18:52:14 +03:00
|
|
|
blt 2b
|
|
|
|
#else
|
2005-10-10 16:36:14 +04:00
|
|
|
blt 3f
|
2019-08-26 18:52:14 +03:00
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
lis r3,fee_restarts@ha
|
|
|
|
tophys(r3,r3)
|
|
|
|
lwz r5,fee_restarts@l(r3)
|
|
|
|
addi r5,r5,1
|
|
|
|
stw r5,fee_restarts@l(r3)
|
|
|
|
mr r12,r4 /* restart at exc_exit_restart */
|
|
|
|
b 2b
|
|
|
|
|
2007-05-15 02:11:58 +04:00
|
|
|
.section .bss
|
|
|
|
.align 2
|
|
|
|
fee_restarts:
|
|
|
|
.space 4
|
|
|
|
.previous
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
/* aargh, a nonrecoverable interrupt, panic */
|
|
|
|
/* aargh, we don't know which trap this is */
|
|
|
|
/* but the 601 doesn't implement the RI bit, so assume it's OK */
|
|
|
|
3:
|
|
|
|
li r10,-1
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r10,_TRAP(r11)
|
2005-10-10 16:36:14 +04:00
|
|
|
addi r3,r1,STACK_FRAME_OVERHEAD
|
|
|
|
lis r10,MSR_KERNEL@h
|
|
|
|
ori r10,r10,MSR_KERNEL@l
|
|
|
|
bl transfer_to_handler_full
|
2018-09-25 17:10:04 +03:00
|
|
|
.long unrecoverable_exception
|
2005-10-10 16:36:14 +04:00
|
|
|
.long ret_from_except
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.globl ret_from_except_full
|
|
|
|
ret_from_except_full:
|
|
|
|
REST_NVGPRS(r1)
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
.globl ret_from_except
|
|
|
|
ret_from_except:
|
|
|
|
/* Hard-disable interrupts so that current_thread_info()->flags
|
|
|
|
* can't change between when we test it and when we return
|
|
|
|
* from the interrupt. */
|
2009-06-17 21:43:59 +04:00
|
|
|
/* Note: We don't bother telling lockdep about it */
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL)
|
2005-10-10 16:36:14 +04:00
|
|
|
SYNC /* Some chip revs have problems here... */
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r10 /* disable interrupts */
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
lwz r3,_MSR(r1) /* Returning to user mode? */
|
|
|
|
andi. r0,r3,MSR_PR
|
|
|
|
beq resume_kernel
|
|
|
|
|
|
|
|
user_exc_return: /* r10 contains MSR_KERNEL here */
|
|
|
|
/* Check current_thread_info()->flags */
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r9,TI_FLAGS(r2)
|
2008-04-28 11:30:37 +04:00
|
|
|
andi. r0,r9,_TIF_USER_WORK_MASK
|
2005-10-10 16:36:14 +04:00
|
|
|
bne do_work
|
|
|
|
|
|
|
|
restore_user:
|
|
|
|
#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
|
2008-04-10 01:15:40 +04:00
|
|
|
/* Check whether this process has its own DBCR0 value. The internal
|
|
|
|
debug mode bit tells us that dbcr0 should be loaded. */
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r0,THREAD+THREAD_DBCR0(r2)
|
2008-07-25 23:27:33 +04:00
|
|
|
andis. r10,r0,DBCR0_IDM@h
|
2005-10-10 16:36:14 +04:00
|
|
|
bnel- load_dbcr0
|
|
|
|
#endif
|
2019-01-31 13:09:04 +03:00
|
|
|
ACCOUNT_CPU_USER_EXIT(r2, r10, r11)
|
2019-03-11 11:30:35 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_32
|
|
|
|
kuep_unlock r10, r11
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
b restore
|
|
|
|
|
|
|
|
/* N.B. the only way to get here is from the beq following ret_from_except. */
|
|
|
|
resume_kernel:
|
2012-09-17 03:54:30 +04:00
|
|
|
/* check current_thread_info, _TIF_EMULATE_STACK_STORE */
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r8,TI_FLAGS(r2)
|
2013-05-31 05:20:02 +04:00
|
|
|
andis. r0,r8,_TIF_EMULATE_STACK_STORE@h
|
2012-09-17 03:54:30 +04:00
|
|
|
beq+ 1f
|
|
|
|
|
|
|
|
addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
|
|
|
|
|
|
|
|
lwz r3,GPR1(r1)
|
|
|
|
subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
|
|
|
|
mr r4,r1 /* src: current exception frame */
|
|
|
|
mr r1,r3 /* Reroute the trampoline frame to r1 */
|
|
|
|
|
|
|
|
/* Copy from the original to the trampoline. */
|
|
|
|
li r5,INT_FRAME_SIZE/4 /* size: INT_FRAME_SIZE */
|
|
|
|
li r6,0 /* start offset: 0 */
|
|
|
|
mtctr r5
|
|
|
|
2: lwzx r0,r6,r4
|
|
|
|
stwx r0,r6,r3
|
|
|
|
addi r6,r6,4
|
|
|
|
bdnz 2b
|
|
|
|
|
|
|
|
/* Do real store operation to complete stwu */
|
|
|
|
lwz r5,GPR1(r1)
|
|
|
|
stw r8,0(r5)
|
|
|
|
|
|
|
|
/* Clear _TIF_EMULATE_STACK_STORE flag */
|
|
|
|
lis r11,_TIF_EMULATE_STACK_STORE@h
|
2019-01-31 13:09:04 +03:00
|
|
|
addi r5,r2,TI_FLAGS
|
2012-09-17 03:54:30 +04:00
|
|
|
0: lwarx r8,0,r5
|
|
|
|
andc r8,r8,r11
|
|
|
|
stwcx. r8,0,r5
|
|
|
|
bne- 0b
|
|
|
|
1:
|
|
|
|
|
2019-10-24 19:04:58 +03:00
|
|
|
#ifdef CONFIG_PREEMPTION
|
2012-09-17 03:54:30 +04:00
|
|
|
/* check current_thread_info->preempt_count */
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r0,TI_PREEMPT(r2)
|
2005-10-10 16:36:14 +04:00
|
|
|
cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
|
2019-03-11 11:30:31 +03:00
|
|
|
bne restore_kuap
|
2012-09-17 03:54:30 +04:00
|
|
|
andi. r8,r8,_TIF_NEED_RESCHED
|
2019-03-11 11:30:31 +03:00
|
|
|
beq+ restore_kuap
|
2012-09-17 03:54:30 +04:00
|
|
|
lwz r3,_MSR(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
andi. r0,r3,MSR_EE /* interrupts off? */
|
2019-03-11 11:30:31 +03:00
|
|
|
beq restore_kuap /* don't schedule if so */
|
2009-06-17 21:43:59 +04:00
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
/* Lockdep thinks irqs are enabled, we need to call
|
|
|
|
* preempt_schedule_irq with IRQs off, so we inform lockdep
|
|
|
|
* now that we -did- turn them off already
|
|
|
|
*/
|
|
|
|
bl trace_hardirqs_off
|
|
|
|
#endif
|
2019-03-12 01:47:46 +03:00
|
|
|
bl preempt_schedule_irq
|
2009-06-17 21:43:59 +04:00
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
/* And now, to properly rebalance the above, we tell lockdep they
|
|
|
|
* are being turned back on, which will happen when we return
|
|
|
|
*/
|
|
|
|
bl trace_hardirqs_on
|
|
|
|
#endif
|
2019-10-24 19:04:58 +03:00
|
|
|
#endif /* CONFIG_PREEMPTION */
|
2019-03-11 11:30:31 +03:00
|
|
|
restore_kuap:
|
|
|
|
kuap_restore r1, r2, r9, r10, r0
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
/* interrupts are hard-disabled at this point */
|
|
|
|
restore:
|
2007-10-31 08:42:19 +03:00
|
|
|
#ifdef CONFIG_44x
|
2010-03-05 13:43:12 +03:00
|
|
|
BEGIN_MMU_FTR_SECTION
|
|
|
|
b 1f
|
|
|
|
END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
|
2007-10-31 08:42:19 +03:00
|
|
|
lis r4,icache_44x_need_flush@ha
|
|
|
|
lwz r5,icache_44x_need_flush@l(r4)
|
|
|
|
cmplwi cr0,r5,0
|
|
|
|
beq+ 1f
|
|
|
|
li r6,0
|
|
|
|
iccci r0,r0
|
|
|
|
stw r6,icache_44x_need_flush@l(r4)
|
|
|
|
1:
|
|
|
|
#endif /* CONFIG_44x */
|
2009-06-17 21:43:59 +04:00
|
|
|
|
|
|
|
lwz r9,_MSR(r1)
|
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
/* Lockdep doesn't know about the fact that IRQs are temporarily turned
|
|
|
|
* off in this assembly code while peeking at TI_FLAGS() and such. However
|
|
|
|
* we need to inform it if the exception turned interrupts off, and we
|
|
|
|
* are about to trun them back on.
|
|
|
|
*/
|
|
|
|
andi. r10,r9,MSR_EE
|
|
|
|
beq 1f
|
2010-12-22 19:42:56 +03:00
|
|
|
stwu r1,-32(r1)
|
|
|
|
mflr r0
|
|
|
|
stw r0,4(r1)
|
2009-06-17 21:43:59 +04:00
|
|
|
bl trace_hardirqs_on
|
2019-04-30 15:39:05 +03:00
|
|
|
addi r1, r1, 32
|
2009-06-17 21:43:59 +04:00
|
|
|
lwz r9,_MSR(r1)
|
|
|
|
1:
|
|
|
|
#endif /* CONFIG_TRACE_IRQFLAGS */
|
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r0,GPR0(r1)
|
|
|
|
lwz r2,GPR2(r1)
|
|
|
|
REST_4GPRS(3, r1)
|
|
|
|
REST_2GPRS(7, r1)
|
|
|
|
|
|
|
|
lwz r10,_XER(r1)
|
|
|
|
lwz r11,_CTR(r1)
|
|
|
|
mtspr SPRN_XER,r10
|
|
|
|
mtctr r11
|
|
|
|
|
2007-11-10 01:17:49 +03:00
|
|
|
BEGIN_FTR_SECTION
|
|
|
|
lwarx r11,0,r1
|
|
|
|
END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
|
2005-10-10 16:36:14 +04:00
|
|
|
stwcx. r0,0,r1 /* to clear the reservation */
|
|
|
|
|
|
|
|
#if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
|
|
|
|
andi. r10,r9,MSR_RI /* check if this exception occurred */
|
|
|
|
beql nonrecoverable /* at a bad place (MSR:RI = 0) */
|
|
|
|
|
|
|
|
lwz r10,_CCR(r1)
|
|
|
|
lwz r11,_LINK(r1)
|
|
|
|
mtcrf 0xFF,r10
|
|
|
|
mtlr r11
|
|
|
|
|
2019-02-27 14:45:30 +03:00
|
|
|
/* Clear the exception_marker on the stack to avoid confusing stacktrace */
|
|
|
|
li r10, 0
|
|
|
|
stw r10, 8(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
|
|
|
* Once we put values in SRR0 and SRR1, we are in a state
|
|
|
|
* where exceptions are not recoverable, since taking an
|
|
|
|
* exception will trash SRR0 and SRR1. Therefore we clear the
|
|
|
|
* MSR:RI bit to indicate this. If we do take an exception,
|
|
|
|
* we can't return to the point of the exception but we
|
|
|
|
* can restart the exception exit path at the label
|
|
|
|
* exc_exit_restart below. -- paulus
|
|
|
|
*/
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL & ~MSR_RI)
|
2005-10-10 16:36:14 +04:00
|
|
|
SYNC
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r10 /* clear the RI bit */
|
2005-10-10 16:36:14 +04:00
|
|
|
.globl exc_exit_restart
|
|
|
|
exc_exit_restart:
|
|
|
|
lwz r12,_NIP(r1)
|
|
|
|
mtspr SPRN_SRR0,r12
|
|
|
|
mtspr SPRN_SRR1,r9
|
|
|
|
REST_4GPRS(9, r1)
|
|
|
|
lwz r1,GPR1(r1)
|
|
|
|
.globl exc_exit_restart_end
|
|
|
|
exc_exit_restart_end:
|
|
|
|
SYNC
|
|
|
|
RFI
|
|
|
|
|
|
|
|
#else /* !(CONFIG_4xx || CONFIG_BOOKE) */
|
|
|
|
/*
|
|
|
|
* This is a bit different on 4xx/Book-E because it doesn't have
|
|
|
|
* the RI bit in the MSR.
|
|
|
|
* The TLB miss handler checks if we have interrupted
|
|
|
|
* the exception exit path and restarts it if so
|
|
|
|
* (well maybe one day it will... :).
|
|
|
|
*/
|
|
|
|
lwz r11,_LINK(r1)
|
|
|
|
mtlr r11
|
|
|
|
lwz r10,_CCR(r1)
|
|
|
|
mtcrf 0xff,r10
|
2019-02-27 14:45:30 +03:00
|
|
|
/* Clear the exception_marker on the stack to avoid confusing stacktrace */
|
|
|
|
li r10, 0
|
|
|
|
stw r10, 8(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
REST_2GPRS(9, r1)
|
|
|
|
.globl exc_exit_restart
|
|
|
|
exc_exit_restart:
|
|
|
|
lwz r11,_NIP(r1)
|
|
|
|
lwz r12,_MSR(r1)
|
|
|
|
exc_exit_start:
|
|
|
|
mtspr SPRN_SRR0,r11
|
|
|
|
mtspr SPRN_SRR1,r12
|
|
|
|
REST_2GPRS(11, r1)
|
|
|
|
lwz r1,GPR1(r1)
|
|
|
|
.globl exc_exit_restart_end
|
|
|
|
exc_exit_restart_end:
|
|
|
|
rfi
|
|
|
|
b . /* prevent prefetch past rfi */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returning from a critical interrupt in user mode doesn't need
|
|
|
|
* to be any different from a normal exception. For a critical
|
|
|
|
* interrupt in the kernel, we just return (without checking for
|
|
|
|
* preemption) since the interrupt may have happened at some crucial
|
|
|
|
* place (e.g. inside the TLB miss handler), and because we will be
|
|
|
|
* running with r1 pointing into critical_stack, not the current
|
|
|
|
* process's kernel stack (and therefore current_thread_info() will
|
|
|
|
* give the wrong answer).
|
|
|
|
* We have to restore various SPRs that may have been in use at the
|
|
|
|
* time of the critical interrupt.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_40x
|
|
|
|
#define PPC_40x_TURN_OFF_MSR_DR \
|
|
|
|
/* avoid any possible TLB misses here by turning off MSR.DR, we \
|
|
|
|
* assume the instructions here are mapped by a pinned TLB entry */ \
|
|
|
|
li r10,MSR_IR; \
|
|
|
|
mtmsr r10; \
|
|
|
|
isync; \
|
|
|
|
tophys(r1, r1);
|
|
|
|
#else
|
|
|
|
#define PPC_40x_TURN_OFF_MSR_DR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RET_FROM_EXC_LEVEL(exc_lvl_srr0, exc_lvl_srr1, exc_lvl_rfi) \
|
|
|
|
REST_NVGPRS(r1); \
|
|
|
|
lwz r3,_MSR(r1); \
|
|
|
|
andi. r3,r3,MSR_PR; \
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL); \
|
2005-10-10 16:36:14 +04:00
|
|
|
bne user_exc_return; \
|
|
|
|
lwz r0,GPR0(r1); \
|
|
|
|
lwz r2,GPR2(r1); \
|
|
|
|
REST_4GPRS(3, r1); \
|
|
|
|
REST_2GPRS(7, r1); \
|
|
|
|
lwz r10,_XER(r1); \
|
|
|
|
lwz r11,_CTR(r1); \
|
|
|
|
mtspr SPRN_XER,r10; \
|
|
|
|
mtctr r11; \
|
|
|
|
stwcx. r0,0,r1; /* to clear the reservation */ \
|
|
|
|
lwz r11,_LINK(r1); \
|
|
|
|
mtlr r11; \
|
|
|
|
lwz r10,_CCR(r1); \
|
|
|
|
mtcrf 0xff,r10; \
|
|
|
|
PPC_40x_TURN_OFF_MSR_DR; \
|
|
|
|
lwz r9,_DEAR(r1); \
|
|
|
|
lwz r10,_ESR(r1); \
|
|
|
|
mtspr SPRN_DEAR,r9; \
|
|
|
|
mtspr SPRN_ESR,r10; \
|
|
|
|
lwz r11,_NIP(r1); \
|
|
|
|
lwz r12,_MSR(r1); \
|
|
|
|
mtspr exc_lvl_srr0,r11; \
|
|
|
|
mtspr exc_lvl_srr1,r12; \
|
|
|
|
lwz r9,GPR9(r1); \
|
|
|
|
lwz r12,GPR12(r1); \
|
|
|
|
lwz r10,GPR10(r1); \
|
|
|
|
lwz r11,GPR11(r1); \
|
|
|
|
lwz r1,GPR1(r1); \
|
|
|
|
exc_lvl_rfi; \
|
|
|
|
b .; /* prevent prefetch past exc_lvl_rfi */
|
|
|
|
|
2008-04-30 14:23:21 +04:00
|
|
|
#define RESTORE_xSRR(exc_lvl_srr0, exc_lvl_srr1) \
|
|
|
|
lwz r9,_##exc_lvl_srr0(r1); \
|
|
|
|
lwz r10,_##exc_lvl_srr1(r1); \
|
|
|
|
mtspr SPRN_##exc_lvl_srr0,r9; \
|
|
|
|
mtspr SPRN_##exc_lvl_srr1,r10;
|
|
|
|
|
2009-02-13 01:12:40 +03:00
|
|
|
#if defined(CONFIG_PPC_BOOK3E_MMU)
|
2008-04-30 14:23:21 +04:00
|
|
|
#ifdef CONFIG_PHYS_64BIT
|
|
|
|
#define RESTORE_MAS7 \
|
|
|
|
lwz r11,MAS7(r1); \
|
|
|
|
mtspr SPRN_MAS7,r11;
|
|
|
|
#else
|
|
|
|
#define RESTORE_MAS7
|
|
|
|
#endif /* CONFIG_PHYS_64BIT */
|
|
|
|
#define RESTORE_MMU_REGS \
|
|
|
|
lwz r9,MAS0(r1); \
|
|
|
|
lwz r10,MAS1(r1); \
|
|
|
|
lwz r11,MAS2(r1); \
|
|
|
|
mtspr SPRN_MAS0,r9; \
|
|
|
|
lwz r9,MAS3(r1); \
|
|
|
|
mtspr SPRN_MAS1,r10; \
|
|
|
|
lwz r10,MAS6(r1); \
|
|
|
|
mtspr SPRN_MAS2,r11; \
|
|
|
|
mtspr SPRN_MAS3,r9; \
|
|
|
|
mtspr SPRN_MAS6,r10; \
|
|
|
|
RESTORE_MAS7;
|
|
|
|
#elif defined(CONFIG_44x)
|
|
|
|
#define RESTORE_MMU_REGS \
|
|
|
|
lwz r9,MMUCR(r1); \
|
|
|
|
mtspr SPRN_MMUCR,r9;
|
|
|
|
#else
|
|
|
|
#define RESTORE_MMU_REGS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_40x
|
2005-10-10 16:36:14 +04:00
|
|
|
.globl ret_from_crit_exc
|
|
|
|
ret_from_crit_exc:
|
2009-07-15 00:52:54 +04:00
|
|
|
mfspr r9,SPRN_SPRG_THREAD
|
2008-04-30 14:23:21 +04:00
|
|
|
lis r10,saved_ksp_limit@ha;
|
|
|
|
lwz r10,saved_ksp_limit@l(r10);
|
|
|
|
tovirt(r9,r9);
|
|
|
|
stw r10,KSP_LIMIT(r9)
|
|
|
|
lis r9,crit_srr0@ha;
|
|
|
|
lwz r9,crit_srr0@l(r9);
|
|
|
|
lis r10,crit_srr1@ha;
|
|
|
|
lwz r10,crit_srr1@l(r10);
|
|
|
|
mtspr SPRN_SRR0,r9;
|
|
|
|
mtspr SPRN_SRR1,r10;
|
2009-02-10 23:10:44 +03:00
|
|
|
RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
|
2008-04-30 14:23:21 +04:00
|
|
|
#endif /* CONFIG_40x */
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_BOOKE
|
2008-04-30 14:23:21 +04:00
|
|
|
.globl ret_from_crit_exc
|
|
|
|
ret_from_crit_exc:
|
2009-07-15 00:52:54 +04:00
|
|
|
mfspr r9,SPRN_SPRG_THREAD
|
2008-04-30 14:23:21 +04:00
|
|
|
lwz r10,SAVED_KSP_LIMIT(r1)
|
|
|
|
stw r10,KSP_LIMIT(r9)
|
|
|
|
RESTORE_xSRR(SRR0,SRR1);
|
|
|
|
RESTORE_MMU_REGS;
|
2009-02-10 23:10:44 +03:00
|
|
|
RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
|
2008-04-30 14:23:21 +04:00
|
|
|
|
2005-10-10 16:36:14 +04:00
|
|
|
.globl ret_from_debug_exc
|
|
|
|
ret_from_debug_exc:
|
2009-07-15 00:52:54 +04:00
|
|
|
mfspr r9,SPRN_SPRG_THREAD
|
2008-04-30 14:23:21 +04:00
|
|
|
lwz r10,SAVED_KSP_LIMIT(r1)
|
|
|
|
stw r10,KSP_LIMIT(r9)
|
|
|
|
RESTORE_xSRR(SRR0,SRR1);
|
|
|
|
RESTORE_xSRR(CSRR0,CSRR1);
|
|
|
|
RESTORE_MMU_REGS;
|
2009-02-10 23:10:44 +03:00
|
|
|
RET_FROM_EXC_LEVEL(SPRN_DSRR0, SPRN_DSRR1, PPC_RFDI)
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
.globl ret_from_mcheck_exc
|
|
|
|
ret_from_mcheck_exc:
|
2009-07-15 00:52:54 +04:00
|
|
|
mfspr r9,SPRN_SPRG_THREAD
|
2008-04-30 14:23:21 +04:00
|
|
|
lwz r10,SAVED_KSP_LIMIT(r1)
|
|
|
|
stw r10,KSP_LIMIT(r9)
|
|
|
|
RESTORE_xSRR(SRR0,SRR1);
|
|
|
|
RESTORE_xSRR(CSRR0,CSRR1);
|
|
|
|
RESTORE_xSRR(DSRR0,DSRR1);
|
|
|
|
RESTORE_MMU_REGS;
|
2009-02-10 23:10:44 +03:00
|
|
|
RET_FROM_EXC_LEVEL(SPRN_MCSRR0, SPRN_MCSRR1, PPC_RFMCI)
|
2005-10-10 16:36:14 +04:00
|
|
|
#endif /* CONFIG_BOOKE */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the DBCR0 value for a task that is being ptraced,
|
|
|
|
* having first saved away the global DBCR0. Note that r0
|
|
|
|
* has the dbcr0 value to set upon entry to this.
|
|
|
|
*/
|
|
|
|
load_dbcr0:
|
|
|
|
mfmsr r10 /* first disable debug exceptions */
|
|
|
|
rlwinm r10,r10,0,~MSR_DE
|
|
|
|
mtmsr r10
|
|
|
|
isync
|
|
|
|
mfspr r10,SPRN_DBCR0
|
|
|
|
lis r11,global_dbcr0@ha
|
|
|
|
addi r11,r11,global_dbcr0@l
|
2008-04-10 01:15:40 +04:00
|
|
|
#ifdef CONFIG_SMP
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r9,TASK_CPU(r2)
|
2008-04-10 01:15:40 +04:00
|
|
|
slwi r9,r9,3
|
|
|
|
add r11,r11,r9
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
stw r10,0(r11)
|
|
|
|
mtspr SPRN_DBCR0,r0
|
|
|
|
lwz r10,4(r11)
|
|
|
|
addi r10,r10,1
|
|
|
|
stw r10,4(r11)
|
|
|
|
li r11,-1
|
|
|
|
mtspr SPRN_DBSR,r11 /* clear all pending debug events */
|
|
|
|
blr
|
|
|
|
|
2007-05-15 02:11:58 +04:00
|
|
|
.section .bss
|
|
|
|
.align 4
|
2019-04-30 15:39:02 +03:00
|
|
|
.global global_dbcr0
|
2007-05-15 02:11:58 +04:00
|
|
|
global_dbcr0:
|
2008-04-10 01:15:40 +04:00
|
|
|
.space 8*NR_CPUS
|
2007-05-15 02:11:58 +04:00
|
|
|
.previous
|
2005-10-10 16:36:14 +04:00
|
|
|
#endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
|
|
|
|
|
|
|
|
do_work: /* r10 contains MSR_KERNEL here */
|
|
|
|
andi. r0,r9,_TIF_NEED_RESCHED
|
|
|
|
beq do_user_signal
|
|
|
|
|
|
|
|
do_resched: /* r10 contains MSR_KERNEL here */
|
2019-04-30 15:39:01 +03:00
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
bl trace_hardirqs_on
|
|
|
|
mfmsr r10
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
ori r10,r10,MSR_EE
|
|
|
|
SYNC
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r10 /* hard-enable interrupts */
|
2005-10-10 16:36:14 +04:00
|
|
|
bl schedule
|
|
|
|
recheck:
|
2009-06-17 21:43:59 +04:00
|
|
|
/* Note: And we don't tell it we are disabling them again
|
|
|
|
* neither. Those disable/enable cycles used to peek at
|
|
|
|
* TI_FLAGS aren't advertised.
|
|
|
|
*/
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL)
|
2005-10-10 16:36:14 +04:00
|
|
|
SYNC
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r10 /* disable interrupts */
|
2019-01-31 13:09:04 +03:00
|
|
|
lwz r9,TI_FLAGS(r2)
|
2005-10-10 16:36:14 +04:00
|
|
|
andi. r0,r9,_TIF_NEED_RESCHED
|
|
|
|
bne- do_resched
|
2008-04-28 11:30:37 +04:00
|
|
|
andi. r0,r9,_TIF_USER_WORK_MASK
|
2005-10-10 16:36:14 +04:00
|
|
|
beq restore_user
|
|
|
|
do_user_signal: /* r10 contains MSR_KERNEL here */
|
|
|
|
ori r10,r10,MSR_EE
|
|
|
|
SYNC
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r10 /* hard-enable interrupts */
|
2005-10-10 16:36:14 +04:00
|
|
|
/* save r13-r31 in the exception frame, if not already done */
|
2005-10-28 16:45:25 +04:00
|
|
|
lwz r3,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
andi. r0,r3,1
|
|
|
|
beq 2f
|
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
rlwinm r3,r3,0,0,30
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r3,_TRAP(r1)
|
2008-07-27 10:52:52 +04:00
|
|
|
2: addi r3,r1,STACK_FRAME_OVERHEAD
|
|
|
|
mr r4,r9
|
2012-02-22 09:48:32 +04:00
|
|
|
bl do_notify_resume
|
2005-10-10 16:36:14 +04:00
|
|
|
REST_NVGPRS(r1)
|
|
|
|
b recheck
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We come here when we are at the end of handling an exception
|
|
|
|
* that occurred at a place where taking an exception will lose
|
|
|
|
* state information, such as the contents of SRR0 and SRR1.
|
|
|
|
*/
|
|
|
|
nonrecoverable:
|
|
|
|
lis r10,exc_exit_restart_end@ha
|
|
|
|
addi r10,r10,exc_exit_restart_end@l
|
|
|
|
cmplw r12,r10
|
2019-08-26 18:52:14 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_601
|
|
|
|
bgelr
|
|
|
|
#else
|
2005-10-10 16:36:14 +04:00
|
|
|
bge 3f
|
2019-08-26 18:52:14 +03:00
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
lis r11,exc_exit_restart@ha
|
|
|
|
addi r11,r11,exc_exit_restart@l
|
|
|
|
cmplw r12,r11
|
2019-08-26 18:52:14 +03:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_601
|
|
|
|
bltlr
|
|
|
|
#else
|
2005-10-10 16:36:14 +04:00
|
|
|
blt 3f
|
2019-08-26 18:52:14 +03:00
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
lis r10,ee_restarts@ha
|
|
|
|
lwz r12,ee_restarts@l(r10)
|
|
|
|
addi r12,r12,1
|
|
|
|
stw r12,ee_restarts@l(r10)
|
|
|
|
mr r12,r11 /* restart at exc_exit_restart */
|
|
|
|
blr
|
|
|
|
3: /* OK, we can't recover, kill this process */
|
|
|
|
/* but the 601 doesn't implement the RI bit, so assume it's OK */
|
2005-10-28 16:45:25 +04:00
|
|
|
lwz r3,_TRAP(r1)
|
2005-10-10 16:36:14 +04:00
|
|
|
andi. r0,r3,1
|
2019-01-31 13:08:58 +03:00
|
|
|
beq 5f
|
2005-10-10 16:36:14 +04:00
|
|
|
SAVE_NVGPRS(r1)
|
|
|
|
rlwinm r3,r3,0,0,30
|
2005-10-28 16:45:25 +04:00
|
|
|
stw r3,_TRAP(r1)
|
2019-01-31 13:08:58 +03:00
|
|
|
5: mfspr r2,SPRN_SPRG_THREAD
|
|
|
|
addi r2,r2,-THREAD
|
|
|
|
tovirt(r2,r2) /* set back r2 to current */
|
2005-10-10 16:36:14 +04:00
|
|
|
4: addi r3,r1,STACK_FRAME_OVERHEAD
|
2018-09-25 17:10:04 +03:00
|
|
|
bl unrecoverable_exception
|
2005-10-10 16:36:14 +04:00
|
|
|
/* shouldn't return */
|
|
|
|
b 4b
|
2020-03-31 19:03:44 +03:00
|
|
|
_ASM_NOKPROBE_SYMBOL(nonrecoverable)
|
2005-10-10 16:36:14 +04:00
|
|
|
|
2007-05-15 02:11:58 +04:00
|
|
|
.section .bss
|
|
|
|
.align 2
|
|
|
|
ee_restarts:
|
|
|
|
.space 4
|
|
|
|
.previous
|
2005-10-10 16:36:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PROM code for specific machines follows. Put it
|
|
|
|
* here so it's easy to add arch-specific sections later.
|
|
|
|
* -- Cort
|
|
|
|
*/
|
2005-10-26 11:05:24 +04:00
|
|
|
#ifdef CONFIG_PPC_RTAS
|
2005-10-10 16:36:14 +04:00
|
|
|
/*
|
|
|
|
* On CHRP, the Run-Time Abstraction Services (RTAS) have to be
|
|
|
|
* called with the MMU off.
|
|
|
|
*/
|
|
|
|
_GLOBAL(enter_rtas)
|
|
|
|
stwu r1,-INT_FRAME_SIZE(r1)
|
|
|
|
mflr r0
|
|
|
|
stw r0,INT_FRAME_SIZE+4(r1)
|
2006-01-13 06:56:25 +03:00
|
|
|
LOAD_REG_ADDR(r4, rtas)
|
2005-10-10 16:36:14 +04:00
|
|
|
lis r6,1f@ha /* physical return address for rtas */
|
|
|
|
addi r6,r6,1f@l
|
|
|
|
tophys(r6,r6)
|
2019-12-21 11:32:38 +03:00
|
|
|
tophys_novmstack r7, r1
|
2005-10-26 11:05:24 +04:00
|
|
|
lwz r8,RTASENTRY(r4)
|
|
|
|
lwz r4,RTASBASE(r4)
|
2005-10-10 16:36:14 +04:00
|
|
|
mfmsr r9
|
|
|
|
stw r9,8(r1)
|
2019-08-20 17:34:13 +03:00
|
|
|
LOAD_REG_IMMEDIATE(r0,MSR_KERNEL)
|
2005-10-10 16:36:14 +04:00
|
|
|
SYNC /* disable interrupts so SRR0/1 */
|
2019-12-21 11:32:22 +03:00
|
|
|
mtmsr r0 /* don't get trashed */
|
2005-10-10 16:36:14 +04:00
|
|
|
li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
|
|
|
|
mtlr r6
|
2019-02-21 13:37:54 +03:00
|
|
|
stw r7, THREAD + RTAS_SP(r2)
|
2005-10-10 16:36:14 +04:00
|
|
|
mtspr SPRN_SRR0,r8
|
|
|
|
mtspr SPRN_SRR1,r9
|
|
|
|
RFI
|
2020-02-14 11:39:50 +03:00
|
|
|
1: tophys_novmstack r9, r1
|
|
|
|
#ifdef CONFIG_VMAP_STACK
|
|
|
|
li r0, MSR_KERNEL & ~MSR_IR /* can take DTLB miss */
|
|
|
|
mtmsr r0
|
|
|
|
isync
|
|
|
|
#endif
|
2005-10-10 16:36:14 +04:00
|
|
|
lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */
|
|
|
|
lwz r9,8(r9) /* original msr value */
|
|
|
|
addi r1,r1,INT_FRAME_SIZE
|
|
|
|
li r0,0
|
2020-02-14 11:39:50 +03:00
|
|
|
tophys_novmstack r7, r2
|
2019-02-21 13:37:54 +03:00
|
|
|
stw r0, THREAD + RTAS_SP(r7)
|
2005-10-10 16:36:14 +04:00
|
|
|
mtspr SPRN_SRR0,r8
|
|
|
|
mtspr SPRN_SRR1,r9
|
|
|
|
RFI /* return to caller */
|
2020-03-31 19:03:44 +03:00
|
|
|
_ASM_NOKPROBE_SYMBOL(enter_rtas)
|
2005-10-26 11:05:24 +04:00
|
|
|
#endif /* CONFIG_PPC_RTAS */
|