2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* PARISC Architecture-dependent parts of process handling
|
|
|
|
* based on the work for i386
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
|
|
|
|
* Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
|
|
|
|
* Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
|
|
|
|
* Copyright (C) 2000 David Huggins-Daines <dhd with pobox.org>
|
|
|
|
* Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
|
|
|
|
* Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
|
|
|
|
* Copyright (C) 2000 David Kennedy <dkennedy with linuxcare.com>
|
2005-10-22 10:53:04 +08:00
|
|
|
* Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
|
|
|
|
* Copyright (C) 2001 Alan Modra <amodra at parisc-linux.org>
|
|
|
|
* Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
|
2014-02-01 05:19:52 +08:00
|
|
|
* Copyright (C) 2001-2014 Helge Deller <deller@gmx.de>
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include <linux/elf.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
2007-07-30 06:36:13 +08:00
|
|
|
#include <linux/fs.h>
|
2018-01-06 04:55:38 +08:00
|
|
|
#include <linux/cpu.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/personality.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/sched.h>
|
2017-02-09 01:51:35 +08:00
|
|
|
#include <linux/sched/debug.h>
|
2017-02-09 01:51:36 +08:00
|
|
|
#include <linux/sched/task.h>
|
2017-02-09 01:51:37 +08:00
|
|
|
#include <linux/sched/task_stack.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/stddef.h>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/kallsyms.h>
|
2009-03-16 04:49:55 +08:00
|
|
|
#include <linux/uaccess.h>
|
2012-08-22 23:27:34 +08:00
|
|
|
#include <linux/rcupdate.h>
|
2014-02-01 05:19:52 +08:00
|
|
|
#include <linux/random.h>
|
2017-07-26 03:41:41 +08:00
|
|
|
#include <linux/nmi.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
2005-09-10 02:57:26 +08:00
|
|
|
#include <asm/asm-offsets.h>
|
2012-10-06 06:55:57 +08:00
|
|
|
#include <asm/assembly.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/pdc.h>
|
|
|
|
#include <asm/pdc_chassis.h>
|
|
|
|
#include <asm/unwind.h>
|
2009-03-16 04:49:55 +08:00
|
|
|
#include <asm/sections.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-14 13:05:21 +08:00
|
|
|
#define COMMAND_GLOBAL F_EXTEND(0xfffe0030)
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CMD_RESET 5 /* reset any module */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The Wright Brothers and Gecko systems have a H/W problem
|
|
|
|
** (Lasi...'nuf said) may cause a broadcast reset to lockup
|
|
|
|
** the system. An HVERSION dependent PDC call was developed
|
|
|
|
** to perform a "safe", platform specific broadcast reset instead
|
|
|
|
** of kludging up all the code.
|
|
|
|
**
|
|
|
|
** Older machines which do not implement PDC_BROADCAST_RESET will
|
|
|
|
** return (with an error) and the regular broadcast reset can be
|
|
|
|
** issued. Obviously, if the PDC does implement PDC_BROADCAST_RESET
|
|
|
|
** the PDC call will not return (the system will be reset).
|
|
|
|
*/
|
|
|
|
void machine_restart(char *cmd)
|
|
|
|
{
|
|
|
|
#ifdef FASTBOOT_SELFTEST_SUPPORT
|
|
|
|
/*
|
|
|
|
** If user has modified the Firmware Selftest Bitmap,
|
|
|
|
** run the tests specified in the bitmap after the
|
|
|
|
** system is rebooted w/PDC_DO_RESET.
|
|
|
|
**
|
|
|
|
** ftc_bitmap = 0x1AUL "Skip destructive memory tests"
|
|
|
|
**
|
|
|
|
** Using "directed resets" at each processor with the MEM_TOC
|
|
|
|
** vector cleared will also avoid running destructive
|
|
|
|
** memory self tests. (Not implemented yet)
|
|
|
|
*/
|
|
|
|
if (ftc_bitmap) {
|
|
|
|
pdc_do_firm_test_reset(ftc_bitmap);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* set up a new led state on systems shipped with a LED State panel */
|
|
|
|
pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
|
|
|
|
|
|
|
|
/* "Normal" system reset */
|
|
|
|
pdc_do_reset();
|
|
|
|
|
|
|
|
/* Nope...box should reset with just CMD_RESET now */
|
|
|
|
gsc_writel(CMD_RESET, COMMAND_GLOBAL);
|
|
|
|
|
|
|
|
/* Wait for RESET to lay us to rest. */
|
|
|
|
while (1) ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-01-18 13:33:32 +08:00
|
|
|
void (*chassis_power_off)(void);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called from sys_reboot to actually turn off the
|
|
|
|
* machine
|
|
|
|
*/
|
|
|
|
void machine_power_off(void)
|
|
|
|
{
|
|
|
|
/* If there is a registered power off handler, call it. */
|
2006-01-18 13:33:32 +08:00
|
|
|
if (chassis_power_off)
|
|
|
|
chassis_power_off();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Put the soft power button back under hardware control.
|
|
|
|
* If the user had already pressed the power button, the
|
|
|
|
* following call will immediately power off. */
|
|
|
|
pdc_soft_power_button(0);
|
|
|
|
|
|
|
|
pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
|
2018-03-25 03:49:39 +08:00
|
|
|
|
|
|
|
/* ipmi_poweroff may have been installed. */
|
|
|
|
if (pm_power_off)
|
|
|
|
pm_power_off();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* It seems we have no way to power the system off via
|
|
|
|
* software. The user has to press the button himself. */
|
|
|
|
|
|
|
|
printk(KERN_EMERG "System shut down completed.\n"
|
2009-07-07 04:05:40 +08:00
|
|
|
"Please power this system off now.");
|
2017-03-19 00:13:27 +08:00
|
|
|
|
2017-03-29 14:25:30 +08:00
|
|
|
/* prevent soft lockup/stalled CPU messages for endless loop. */
|
|
|
|
rcu_sysrq_start();
|
2017-09-13 03:36:58 +08:00
|
|
|
lockup_detector_soft_poweroff();
|
2017-03-19 00:13:27 +08:00
|
|
|
for (;;);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 03:49:39 +08:00
|
|
|
void (*pm_power_off)(void);
|
2006-01-18 13:33:32 +08:00
|
|
|
EXPORT_SYMBOL(pm_power_off);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-04-12 04:27:07 +08:00
|
|
|
void machine_halt(void)
|
|
|
|
{
|
|
|
|
machine_power_off();
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void flush_thread(void)
|
|
|
|
{
|
|
|
|
/* Only needs to handle fpu stuff or perf monitors.
|
|
|
|
** REVISIT: several arches implement a "lazy fpu state".
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_thread(struct task_struct *dead_task)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-06 04:55:38 +08:00
|
|
|
/*
|
|
|
|
* Idle thread support
|
|
|
|
*
|
|
|
|
* Detect when running on QEMU with SeaBIOS PDC Firmware and let
|
|
|
|
* QEMU idle the host too.
|
|
|
|
*/
|
|
|
|
|
2019-05-11 02:54:31 +08:00
|
|
|
int running_on_qemu __ro_after_init;
|
2019-04-06 22:45:14 +08:00
|
|
|
EXPORT_SYMBOL(running_on_qemu);
|
2018-01-06 04:55:38 +08:00
|
|
|
|
|
|
|
void __cpuidle arch_cpu_idle_dead(void)
|
|
|
|
{
|
|
|
|
/* nop on real hardware, qemu will offline CPU. */
|
|
|
|
asm volatile("or %%r31,%%r31,%%r31\n":::);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __cpuidle arch_cpu_idle(void)
|
|
|
|
{
|
|
|
|
local_irq_enable();
|
|
|
|
|
|
|
|
/* nop on real hardware, qemu will idle sleep. */
|
|
|
|
asm volatile("or %%r10,%%r10,%%r10\n":::);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init parisc_idle_init(void)
|
|
|
|
{
|
|
|
|
if (!running_on_qemu)
|
|
|
|
cpu_idle_poll_ctrl(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
arch_initcall(parisc_idle_init);
|
|
|
|
|
2015-03-14 02:14:45 +08:00
|
|
|
/*
|
|
|
|
* Copy architecture-specific thread state
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int
|
2020-06-11 17:04:15 +08:00
|
|
|
copy_thread(unsigned long clone_flags, unsigned long usp,
|
2020-01-03 01:24:10 +08:00
|
|
|
unsigned long kthread_arg, struct task_struct *p, unsigned long tls)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-10-23 10:51:14 +08:00
|
|
|
struct pt_regs *cregs = &(p->thread.regs);
|
2006-01-12 17:05:55 +08:00
|
|
|
void *stack = task_stack_page(p);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We have to use void * instead of a function pointer, because
|
|
|
|
* function pointers aren't a pointer to the function on 64-bit.
|
|
|
|
* Make them const so the compiler knows they live in .text */
|
|
|
|
extern void * const ret_from_kernel_thread;
|
|
|
|
extern void * const child_return;
|
2015-02-17 05:21:00 +08:00
|
|
|
|
2012-10-06 06:55:57 +08:00
|
|
|
if (unlikely(p->flags & PF_KTHREAD)) {
|
2015-03-14 02:14:45 +08:00
|
|
|
/* kernel thread */
|
2012-10-04 11:28:08 +08:00
|
|
|
memset(cregs, 0, sizeof(struct pt_regs));
|
2012-10-06 06:55:57 +08:00
|
|
|
if (!usp) /* idle thread */
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Must exit via ret_from_kernel_thread in order
|
|
|
|
* to call schedule_tail()
|
|
|
|
*/
|
2012-10-06 06:55:57 +08:00
|
|
|
cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
|
2005-04-17 06:20:36 +08:00
|
|
|
cregs->kpc = (unsigned long) &ret_from_kernel_thread;
|
|
|
|
/*
|
|
|
|
* Copy function and argument to be called from
|
|
|
|
* ret_from_kernel_thread.
|
|
|
|
*/
|
2007-01-28 21:58:52 +08:00
|
|
|
#ifdef CONFIG_64BIT
|
2012-10-04 11:28:08 +08:00
|
|
|
cregs->gr[27] = ((unsigned long *)usp)[3];
|
|
|
|
cregs->gr[26] = ((unsigned long *)usp)[2];
|
|
|
|
#else
|
|
|
|
cregs->gr[26] = usp;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2015-03-14 02:14:45 +08:00
|
|
|
cregs->gr[25] = kthread_arg;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
/* user thread */
|
2012-10-27 07:59:16 +08:00
|
|
|
/* usp must be word aligned. This also prevents users from
|
|
|
|
* passing in the value 1 (which is the signal for a special
|
|
|
|
* return for a kernel thread) */
|
|
|
|
if (usp) {
|
|
|
|
usp = ALIGN(usp, 4);
|
|
|
|
if (likely(usp))
|
|
|
|
cregs->gr[30] = usp;
|
|
|
|
}
|
2012-10-06 06:55:57 +08:00
|
|
|
cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
|
2015-02-17 05:21:00 +08:00
|
|
|
cregs->kpc = (unsigned long) &child_return;
|
|
|
|
|
2020-01-03 01:24:10 +08:00
|
|
|
/* Setup thread TLS area */
|
2005-10-22 10:53:04 +08:00
|
|
|
if (clone_flags & CLONE_SETTLS)
|
2020-01-03 01:24:10 +08:00
|
|
|
cregs->cr27 = tls;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-02 17:18:31 +08:00
|
|
|
unsigned long
|
2005-04-17 06:20:36 +08:00
|
|
|
get_wchan(struct task_struct *p)
|
|
|
|
{
|
|
|
|
struct unwind_frame_info info;
|
|
|
|
unsigned long ip;
|
|
|
|
int count = 0;
|
2007-05-30 14:36:00 +08:00
|
|
|
|
|
|
|
if (!p || p == current || p->state == TASK_RUNNING)
|
|
|
|
return 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* These bracket the sleeping functions..
|
|
|
|
*/
|
|
|
|
|
|
|
|
unwind_frame_init_from_blocked_task(&info, p);
|
|
|
|
do {
|
|
|
|
if (unwind_once(&info) < 0)
|
|
|
|
return 0;
|
|
|
|
ip = info.ip;
|
|
|
|
if (!in_sched_functions(ip))
|
|
|
|
return ip;
|
2018-08-05 06:03:29 +08:00
|
|
|
} while (count++ < MAX_UNWIND_ENTRIES);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-16 04:49:55 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
void *dereference_function_descriptor(void *ptr)
|
|
|
|
{
|
|
|
|
Elf64_Fdesc *desc = ptr;
|
|
|
|
void *p;
|
|
|
|
|
maccess: make get_kernel_nofault() check for minimal type compatibility
Now that we've renamed probe_kernel_address() to get_kernel_nofault()
and made it look and behave more in line with get_user(), some of the
subtle type behavior differences end up being more obvious and possibly
dangerous.
When you do
get_user(val, user_ptr);
the type of the access comes from the "user_ptr" part, and the above
basically acts as
val = *user_ptr;
by design (except, of course, for the fact that the actual dereference
is done with a user access).
Note how in the above case, the type of the end result comes from the
pointer argument, and then the value is cast to the type of 'val' as
part of the assignment.
So the type of the pointer is ultimately the more important type both
for the access itself.
But 'get_kernel_nofault()' may now _look_ similar, but it behaves very
differently. When you do
get_kernel_nofault(val, kernel_ptr);
it behaves like
val = *(typeof(val) *)kernel_ptr;
except, of course, for the fact that the actual dereference is done with
exception handling so that a faulting access is suppressed and returned
as the error code.
But note how different the casting behavior of the two superficially
similar accesses are: one does the actual access in the size of the type
the pointer points to, while the other does the access in the size of
the target, and ignores the pointer type entirely.
Actually changing get_kernel_nofault() to act like get_user() is almost
certainly the right thing to do eventually, but in the meantime this
patch adds logit to at least verify that the pointer type is compatible
with the type of the result.
In many cases, this involves just casting the pointer to 'void *' to
make it obvious that the type of the pointer is not the important part.
It's not how 'get_user()' acts, but at least the behavioral difference
is now obvious and explicit.
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-19 03:10:37 +08:00
|
|
|
if (!get_kernel_nofault(p, (void *)&desc->addr))
|
2009-03-16 04:49:55 +08:00
|
|
|
ptr = p;
|
|
|
|
return ptr;
|
|
|
|
}
|
2017-11-10 07:48:28 +08:00
|
|
|
|
|
|
|
void *dereference_kernel_function_descriptor(void *ptr)
|
|
|
|
{
|
|
|
|
if (ptr < (void *)__start_opd ||
|
|
|
|
ptr >= (void *)__end_opd)
|
|
|
|
return ptr;
|
|
|
|
|
|
|
|
return dereference_function_descriptor(ptr);
|
|
|
|
}
|
2009-03-16 04:49:55 +08:00
|
|
|
#endif
|
2014-02-01 05:19:52 +08:00
|
|
|
|
|
|
|
static inline unsigned long brk_rnd(void)
|
|
|
|
{
|
2016-10-16 06:02:27 +08:00
|
|
|
return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
|
2014-02-01 05:19:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long arch_randomize_brk(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
|
|
|
|
|
|
|
|
if (ret < mm->brk)
|
|
|
|
return mm->brk;
|
|
|
|
return ret;
|
|
|
|
}
|