Files
OrangePi_CM5/arch/s390/kernel/process.c
T

223 lines
5.8 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0
2005-04-16 15:20:36 -07:00
/*
* This file handles the architecture dependent parts of process handling.
2005-04-16 15:20:36 -07:00
*
* Copyright IBM Corp. 1999, 2009
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
* Hartmut Penner <hp@de.ibm.com>,
* Denis Joseph Barrow,
2005-04-16 15:20:36 -07:00
*/
2016-05-07 12:15:34 +02:00
#include <linux/elf-randomize.h>
2005-04-16 15:20:36 -07:00
#include <linux/compiler.h>
#include <linux/cpu.h>
#include <linux/sched.h>
#include <linux/sched/debug.h>
#include <linux/sched/task.h>
#include <linux/sched/task_stack.h>
2005-04-16 15:20:36 -07:00
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/elfcore.h>
2005-04-16 15:20:36 -07:00
#include <linux/smp.h>
#include <linux/slab.h>
2005-04-16 15:20:36 -07:00
#include <linux/interrupt.h>
2008-04-17 07:46:25 +02:00
#include <linux/tick.h>
#include <linux/personality.h>
#include <linux/syscalls.h>
#include <linux/compat.h>
2011-01-05 12:47:25 +01:00
#include <linux/kprobes.h>
#include <linux/random.h>
#include <linux/export.h>
#include <linux/init_task.h>
2005-04-16 15:20:36 -07:00
#include <asm/io.h>
#include <asm/processor.h>
2012-07-20 11:15:08 +02:00
#include <asm/vtimer.h>
2012-09-14 13:45:24 +02:00
#include <asm/exec.h>
2005-04-16 15:20:36 -07:00
#include <asm/irq.h>
#include <asm/nmi.h>
#include <asm/smp.h>
2012-03-28 18:30:02 +01:00
#include <asm/switch_to.h>
#include <asm/runtime_instr.h>
2008-04-17 07:46:26 +02:00
#include "entry.h"
2005-04-16 15:20:36 -07:00
2006-09-28 16:56:43 +02:00
asmlinkage void ret_from_fork(void) asm ("ret_from_fork");
2005-04-16 15:20:36 -07:00
2014-10-22 12:42:38 +02:00
extern void kernel_thread_starter(void);
2005-04-16 15:20:36 -07:00
void flush_thread(void)
{
}
void arch_release_task_struct(struct task_struct *tsk)
{
runtime_instr_release(tsk);
guarded_storage_release(tsk);
}
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
{
2015-06-10 12:53:42 +02:00
/*
* Save the floating-point or vector register state of the current
* task and set the CIF_FPU flag to lazy restore the FPU register
* state when returning to user space.
2015-06-10 12:53:42 +02:00
*/
save_fpu_regs();
memcpy(dst, src, arch_task_struct_size);
dst->thread.fpu.regs = dst->thread.fpu.fprs;
return 0;
}
2017-02-20 09:38:42 +01:00
int copy_thread_tls(unsigned long clone_flags, unsigned long new_stackp,
unsigned long arg, struct task_struct *p, unsigned long tls)
2005-04-16 15:20:36 -07: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-21 20:48:32 -04: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);
p->thread.per_flags = 0;
2012-09-21 20:48:32 -04:00
/* Initialize per thread user and system timer values */
p->thread.user_timer = 0;
p->thread.guest_timer = 0;
p->thread.system_timer = 0;
p->thread.hardirq_timer = 0;
p->thread.softirq_timer = 0;
2005-04-16 15:20:36 -07:00
2012-09-21 20:48:32 -04:00
frame->sf.back_chain = 0;
/* 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-16 15:20:36 -07:00
2012-09-21 20:48:32 -04:00
/* Store access registers to kernel stack of new process. */
2012-10-21 16:44:27 -04:00
if (unlikely(p->flags & PF_KTHREAD)) {
2012-09-21 20:48:32 -04:00
/* kernel thread */
memset(&frame->childregs, 0, sizeof(struct pt_regs));
frame->childregs.psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT |
2012-09-21 20:48:32 -04:00
PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
2016-01-18 12:49:44 +01:00
frame->childregs.psw.addr =
2012-09-21 20:48:32 -04:00
(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-21 16:44:27 -04:00
frame->childregs = *current_pt_regs();
2012-09-21 20:48:32 -04:00
frame->childregs.gprs[2] = 0; /* child returns 0 on fork. */
frame->childregs.flags = 0;
2012-10-21 16:44:27 -04:00
if (new_stackp)
frame->childregs.gprs[15] = new_stackp;
2005-04-16 15:20:36 -07:00
/* Don't copy runtime instrumentation info */
p->thread.ri_cb = NULL;
frame->childregs.psw.mask &= ~PSW_MASK_RI;
2016-01-26 14:10:34 +01:00
/* Don't copy guarded storage control block */
p->thread.gs_cb = NULL;
p->thread.gs_bc_cb = NULL;
2005-04-16 15:20:36 -07:00
/* Set a new TLS ? */
if (clone_flags & CLONE_SETTLS) {
2009-06-12 10:26:25 +02:00
if (is_compat_task()) {
2012-10-21 16:44:27 -04:00
p->thread.acrs[0] = (unsigned int)tls;
2005-04-16 15:20:36 -07:00
} else {
2012-10-21 16:44:27 -04:00
p->thread.acrs[0] = (unsigned int)(tls >> 32);
p->thread.acrs[1] = (unsigned int)tls;
2005-04-16 15:20:36 -07:00
}
}
return 0;
2005-04-16 15:20:36 -07:00
}
2007-04-27 16:01:40 +02:00
asmlinkage void execve_tail(void)
{
current->thread.fpu.fpc = 0;
2015-07-06 15:02:37 +02:00
asm volatile("sfpc %0" : : "d" (0));
2005-04-16 15:20:36 -07:00
}
/*
* fill in the FPU structure for a core dump.
*/
int dump_fpu (struct pt_regs * regs, s390_fp_regs *fpregs)
{
save_fpu_regs();
2015-06-10 12:53:42 +02:00
fpregs->fpc = current->thread.fpu.fpc;
fpregs->pad = 0;
if (MACHINE_HAS_VX)
2015-06-10 12:53:42 +02:00
convert_vx_to_fp((freg_t *)&fpregs->fprs,
current->thread.fpu.vxrs);
else
memcpy(&fpregs->fprs, current->thread.fpu.fprs,
sizeof(fpregs->fprs));
2005-04-16 15:20:36 -07:00
return 1;
}
2009-03-26 15:24:04 +01:00
EXPORT_SYMBOL(dump_fpu);
2005-04-16 15:20:36 -07:00
unsigned long get_wchan(struct task_struct *p)
{
struct stack_frame *sf, *low, *high;
unsigned long return_address;
int count;
2006-01-12 01:05:50 -08:00
if (!p || p == current || p->state == TASK_RUNNING || !task_stack_page(p))
2005-04-16 15:20:36 -07:00
return 0;
2006-01-12 01:05:50 -08:00
low = task_stack_page(p);
high = (struct stack_frame *) task_pt_regs(p);
2016-01-18 13:12:19 +01:00
sf = (struct stack_frame *) p->thread.ksp;
2005-04-16 15:20:36 -07:00
if (sf <= low || sf > high)
return 0;
for (count = 0; count < 16; count++) {
2016-01-18 13:12:19 +01:00
sf = (struct stack_frame *) sf->back_chain;
2005-04-16 15:20:36 -07:00
if (sf <= low || sf > high)
return 0;
2016-01-18 13:12:19 +01:00
return_address = sf->gprs[8];
2005-04-16 15:20:36 -07:00
if (!in_sched_functions(return_address))
return return_address;
}
return 0;
}
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 09:55:30 +01:00
static inline unsigned long brk_rnd(void)
{
return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
2011-01-12 09:55:30 +01:00
}
unsigned long arch_randomize_brk(struct mm_struct *mm)
{
unsigned long ret;
2011-01-12 09:55:30 +01:00
ret = PAGE_ALIGN(mm->brk + brk_rnd());
return (ret > mm->brk) ? ret : mm->brk;
2011-01-12 09:55:30 +01:00
}
void set_fs_fixup(void)
{
struct pt_regs *regs = current_pt_regs();
static bool warned;
set_fs(USER_DS);
if (warned)
return;
WARN(1, "Unbalanced set_fs - int code: 0x%x\n", regs->int_code);
show_registers(regs);
warned = true;
}