2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2009-03-26 22:23:52 +08:00
|
|
|
* This file handles the architecture dependent parts of process handling.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2012-07-20 17:15:04 +08:00
|
|
|
* Copyright IBM Corp. 1999, 2009
|
2009-03-26 22:23:52 +08:00
|
|
|
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
|
|
|
|
* Hartmut Penner <hp@de.ibm.com>,
|
|
|
|
* Denis Joseph Barrow,
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
2011-10-30 22:17:13 +08:00
|
|
|
#include <linux/elfcore.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/smp.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
2008-04-17 13:46:25 +08:00
|
|
|
#include <linux/tick.h>
|
2011-01-12 16:55:28 +08:00
|
|
|
#include <linux/personality.h>
|
2009-01-14 21:14:36 +08:00
|
|
|
#include <linux/syscalls.h>
|
2009-09-23 04:58:42 +08:00
|
|
|
#include <linux/compat.h>
|
2011-01-05 19:47:25 +08:00
|
|
|
#include <linux/kprobes.h>
|
2011-01-12 16:55:28 +08:00
|
|
|
#include <linux/random.h>
|
2011-05-23 16:24:44 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/processor.h>
|
2012-07-20 17:15:08 +08:00
|
|
|
#include <asm/vtimer.h>
|
2012-09-14 19:45:24 +08:00
|
|
|
#include <asm/exec.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/irq.h>
|
2009-03-26 22:24:01 +08:00
|
|
|
#include <asm/nmi.h>
|
2011-01-05 19:48:09 +08:00
|
|
|
#include <asm/smp.h>
|
2012-03-29 01:30:02 +08:00
|
|
|
#include <asm/switch_to.h>
|
2012-07-31 16:52:05 +08:00
|
|
|
#include <asm/runtime_instr.h>
|
2008-04-17 13:46:26 +08:00
|
|
|
#include "entry.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-09-28 22:56:43 +08:00
|
|
|
asmlinkage void ret_from_fork(void) asm ("ret_from_fork");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return saved PC of a blocked thread. used in kernel/sched.
|
|
|
|
* resume in entry.S does not create a new stack frame, it
|
|
|
|
* just stores the registers %r6-%r15 to the frame given by
|
|
|
|
* schedule. We want to return the address of the caller of
|
|
|
|
* schedule, so we have to walk the backchain one time to
|
|
|
|
* find the frame schedule() store its return address.
|
|
|
|
*/
|
|
|
|
unsigned long thread_saved_pc(struct task_struct *tsk)
|
|
|
|
{
|
2006-01-15 05:20:57 +08:00
|
|
|
struct stack_frame *sf, *low, *high;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-15 05:20:57 +08:00
|
|
|
if (!tsk || !task_stack_page(tsk))
|
|
|
|
return 0;
|
|
|
|
low = task_stack_page(tsk);
|
|
|
|
high = (struct stack_frame *) task_pt_regs(tsk);
|
|
|
|
sf = (struct stack_frame *) (tsk->thread.ksp & PSW_ADDR_INSN);
|
|
|
|
if (sf <= low || sf > high)
|
|
|
|
return 0;
|
|
|
|
sf = (struct stack_frame *) (sf->back_chain & PSW_ADDR_INSN);
|
|
|
|
if (sf <= low || sf > high)
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
return sf->gprs[8];
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:42:38 +08:00
|
|
|
extern void kernel_thread_starter(void);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free current thread data structures etc..
|
|
|
|
*/
|
|
|
|
void exit_thread(void)
|
|
|
|
{
|
2012-07-31 16:52:05 +08:00
|
|
|
exit_thread_runtime_instr();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void flush_thread(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_thread(struct task_struct *dead_task)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-09 23:47:00 +08:00
|
|
|
void arch_release_task_struct(struct task_struct *tsk)
|
|
|
|
{
|
2015-06-11 21:33:54 +08:00
|
|
|
if (is_vx_task(tsk))
|
|
|
|
kfree(tsk->thread.fpu.vxrs);
|
2015-02-09 23:47:00 +08:00
|
|
|
}
|
|
|
|
|
2009-04-03 07:56:59 +08:00
|
|
|
int copy_thread(unsigned long clone_flags, unsigned long new_stackp,
|
2012-10-23 10:51:14 +08:00
|
|
|
unsigned long arg, struct task_struct *p)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-26 22:23:53 +08:00
|
|
|
struct thread_info *ti;
|
2009-03-26 22:23:52 +08:00
|
|
|
struct fake_frame
|
|
|
|
{
|
|
|
|
struct stack_frame sf;
|
|
|
|
struct pt_regs childregs;
|
|
|
|
} *frame;
|
|
|
|
|
|
|
|
frame = container_of(task_pt_regs(p), struct fake_frame, childregs);
|
|
|
|
p->thread.ksp = (unsigned long) frame;
|
2012-09-22 08:48:32 +08:00
|
|
|
/* Save access registers to new thread structure. */
|
|
|
|
save_access_regs(&p->thread.acrs[0]);
|
|
|
|
/* start new process with ar4 pointing to the correct address space */
|
|
|
|
p->thread.mm_segment = get_fs();
|
|
|
|
/* Don't copy debug registers */
|
|
|
|
memset(&p->thread.per_user, 0, sizeof(p->thread.per_user));
|
|
|
|
memset(&p->thread.per_event, 0, sizeof(p->thread.per_event));
|
|
|
|
clear_tsk_thread_flag(p, TIF_SINGLE_STEP);
|
|
|
|
/* Initialize per thread user and system timer values */
|
|
|
|
ti = task_thread_info(p);
|
|
|
|
ti->user_timer = 0;
|
|
|
|
ti->system_timer = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-22 08:48:32 +08:00
|
|
|
frame->sf.back_chain = 0;
|
2009-03-26 22:23:52 +08:00
|
|
|
/* new return point is ret_from_fork */
|
|
|
|
frame->sf.gprs[8] = (unsigned long) ret_from_fork;
|
|
|
|
/* fake return stack for resume(), don't go back to schedule */
|
|
|
|
frame->sf.gprs[9] = (unsigned long) frame;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-22 08:48:32 +08:00
|
|
|
/* Store access registers to kernel stack of new process. */
|
2012-10-22 04:44:27 +08:00
|
|
|
if (unlikely(p->flags & PF_KTHREAD)) {
|
2012-09-22 08:48:32 +08:00
|
|
|
/* kernel thread */
|
|
|
|
memset(&frame->childregs, 0, sizeof(struct pt_regs));
|
2013-09-24 15:14:56 +08:00
|
|
|
frame->childregs.psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT |
|
2012-09-22 08:48:32 +08:00
|
|
|
PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
|
|
|
|
frame->childregs.psw.addr = PSW_ADDR_AMODE |
|
|
|
|
(unsigned long) kernel_thread_starter;
|
|
|
|
frame->childregs.gprs[9] = new_stackp; /* function */
|
|
|
|
frame->childregs.gprs[10] = arg;
|
|
|
|
frame->childregs.gprs[11] = (unsigned long) do_exit;
|
|
|
|
frame->childregs.orig_gpr2 = -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-22 04:44:27 +08:00
|
|
|
frame->childregs = *current_pt_regs();
|
2012-09-22 08:48:32 +08:00
|
|
|
frame->childregs.gprs[2] = 0; /* child returns 0 on fork. */
|
2014-04-15 18:55:07 +08:00
|
|
|
frame->childregs.flags = 0;
|
2012-10-22 04:44:27 +08:00
|
|
|
if (new_stackp)
|
|
|
|
frame->childregs.gprs[15] = new_stackp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-07-31 16:52:05 +08:00
|
|
|
/* Don't copy runtime instrumentation info */
|
|
|
|
p->thread.ri_cb = NULL;
|
|
|
|
p->thread.ri_signum = 0;
|
|
|
|
frame->childregs.psw.mask &= ~PSW_MASK_RI;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Save the fpu registers to new thread structure. */
|
2015-06-11 21:33:54 +08:00
|
|
|
save_fp_ctl(&p->thread.fpu.fpc);
|
|
|
|
save_fp_regs(p->thread.fpu.fprs);
|
|
|
|
p->thread.fpu.pad = 0;
|
|
|
|
p->thread.fpu.vxrs = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Set a new TLS ? */
|
|
|
|
if (clone_flags & CLONE_SETTLS) {
|
2012-10-22 04:44:27 +08:00
|
|
|
unsigned long tls = frame->childregs.gprs[6];
|
2009-06-12 16:26:25 +08:00
|
|
|
if (is_compat_task()) {
|
2012-10-22 04:44:27 +08:00
|
|
|
p->thread.acrs[0] = (unsigned int)tls;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2012-10-22 04:44:27 +08:00
|
|
|
p->thread.acrs[0] = (unsigned int)(tls >> 32);
|
|
|
|
p->thread.acrs[1] = (unsigned int)tls;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2009-03-26 22:23:52 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-04-27 22:01:40 +08:00
|
|
|
asmlinkage void execve_tail(void)
|
|
|
|
{
|
2015-06-11 21:33:54 +08:00
|
|
|
current->thread.fpu.fpc = 0;
|
2015-07-06 21:02:37 +08:00
|
|
|
asm volatile("sfpc %0" : : "d" (0));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fill in the FPU structure for a core dump.
|
|
|
|
*/
|
|
|
|
int dump_fpu (struct pt_regs * regs, s390_fp_regs *fpregs)
|
|
|
|
{
|
2013-10-15 22:08:34 +08:00
|
|
|
save_fp_ctl(&fpregs->fpc);
|
|
|
|
save_fp_regs(fpregs->fprs);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2009-03-26 22:24:04 +08:00
|
|
|
EXPORT_SYMBOL(dump_fpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
unsigned long get_wchan(struct task_struct *p)
|
|
|
|
{
|
|
|
|
struct stack_frame *sf, *low, *high;
|
|
|
|
unsigned long return_address;
|
|
|
|
int count;
|
|
|
|
|
2006-01-12 17:05:50 +08:00
|
|
|
if (!p || p == current || p->state == TASK_RUNNING || !task_stack_page(p))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2006-01-12 17:05:50 +08:00
|
|
|
low = task_stack_page(p);
|
|
|
|
high = (struct stack_frame *) task_pt_regs(p);
|
2005-04-17 06:20:36 +08:00
|
|
|
sf = (struct stack_frame *) (p->thread.ksp & PSW_ADDR_INSN);
|
|
|
|
if (sf <= low || sf > high)
|
|
|
|
return 0;
|
|
|
|
for (count = 0; count < 16; count++) {
|
|
|
|
sf = (struct stack_frame *) (sf->back_chain & PSW_ADDR_INSN);
|
|
|
|
if (sf <= low || sf > high)
|
|
|
|
return 0;
|
|
|
|
return_address = sf->gprs[8] & PSW_ADDR_INSN;
|
|
|
|
if (!in_sched_functions(return_address))
|
|
|
|
return return_address;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-12 16:55:28 +08:00
|
|
|
|
|
|
|
unsigned long arch_align_stack(unsigned long sp)
|
|
|
|
{
|
|
|
|
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
|
|
|
|
sp -= get_random_int() & ~PAGE_MASK;
|
|
|
|
return sp & ~0xf;
|
|
|
|
}
|
2011-01-12 16:55:30 +08:00
|
|
|
|
|
|
|
static inline unsigned long brk_rnd(void)
|
|
|
|
{
|
|
|
|
/* 8MB for 32bit, 1GB for 64bit */
|
|
|
|
if (is_32bit_task())
|
|
|
|
return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
|
|
|
|
else
|
|
|
|
return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long arch_randomize_brk(struct mm_struct *mm)
|
|
|
|
{
|
2013-12-17 20:41:31 +08:00
|
|
|
unsigned long ret;
|
2011-01-12 16:55:30 +08:00
|
|
|
|
2013-12-17 20:41:31 +08:00
|
|
|
ret = PAGE_ALIGN(mm->brk + brk_rnd());
|
|
|
|
return (ret > mm->brk) ? ret : mm->brk;
|
2011-01-12 16:55:30 +08:00
|
|
|
}
|