2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, 2000, 2001, 05 by Ralf Baechle
|
|
|
|
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
|
|
|
|
* Copyright (C) 2001 MIPS Technologies, Inc.
|
|
|
|
*/
|
2006-01-12 03:17:48 +07:00
|
|
|
#include <linux/capability.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/linkage.h>
|
2007-07-30 05:36:13 +07:00
|
|
|
#include <linux/fs.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/syscalls.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/utsname.h>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/sem.h>
|
|
|
|
#include <linux/msg.h>
|
|
|
|
#include <linux/shm.h>
|
|
|
|
#include <linux/compiler.h>
|
2007-10-17 13:29:24 +07:00
|
|
|
#include <linux/ipc.h>
|
2009-09-17 07:25:05 +07:00
|
|
|
#include <linux/uaccess.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2010-07-20 03:14:57 +07:00
|
|
|
#include <linux/elf.h>
|
2017-02-09 00:51:37 +07:00
|
|
|
#include <linux/sched/task_stack.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-09-17 07:25:05 +07:00
|
|
|
#include <asm/asm.h>
|
2017-05-31 22:19:49 +07:00
|
|
|
#include <asm/asm-eva.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/branch.h>
|
|
|
|
#include <asm/cachectl.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2005-09-10 03:32:31 +07:00
|
|
|
#include <asm/asm-offsets.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/signal.h>
|
|
|
|
#include <asm/sim.h>
|
|
|
|
#include <asm/shmparam.h>
|
2019-10-02 04:53:39 +07:00
|
|
|
#include <asm/sync.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/sysmips.h>
|
2012-03-29 00:30:02 +07:00
|
|
|
#include <asm/switch_to.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-07-20 19:16:46 +07:00
|
|
|
/*
|
|
|
|
* For historic reasons the pipe(2) syscall on MIPS has an unusual calling
|
2013-01-22 18:59:30 +07:00
|
|
|
* convention. It returns results in registers $v0 / $v1 which means there
|
2008-07-20 19:16:46 +07:00
|
|
|
* is no need for it to do verify the validity of a userspace pointer
|
2013-01-22 18:59:30 +07:00
|
|
|
* argument. Historically that used to be expensive in Linux. These days
|
2008-07-20 19:16:46 +07:00
|
|
|
* the performance advantage is negligible.
|
|
|
|
*/
|
2012-12-24 08:18:28 +07:00
|
|
|
asmlinkage int sysm_pipe(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int fd[2];
|
2012-12-24 08:18:28 +07:00
|
|
|
int error = do_pipe_flags(fd, 0);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
current_pt_regs()->regs[3] = fd[1];
|
|
|
|
return fd[0];
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-02-08 23:00:26 +07:00
|
|
|
SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
|
|
|
|
unsigned long, prot, unsigned long, flags, unsigned long,
|
|
|
|
fd, off_t, offset)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
if (offset & ~PAGE_MASK)
|
2017-01-19 01:30:47 +07:00
|
|
|
return -EINVAL;
|
2018-03-11 17:34:46 +07:00
|
|
|
return ksys_mmap_pgoff(addr, len, prot, flags, fd,
|
|
|
|
offset >> PAGE_SHIFT);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-02-08 23:00:26 +07:00
|
|
|
SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
|
|
|
|
unsigned long, prot, unsigned long, flags, unsigned long, fd,
|
|
|
|
unsigned long, pgoff)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-02-25 12:20:29 +07:00
|
|
|
if (pgoff & (~PAGE_MASK >> 12))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-03-11 17:34:46 +07:00
|
|
|
return ksys_mmap_pgoff(addr, len, prot, flags, fd,
|
|
|
|
pgoff >> (PAGE_SHIFT - 12));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
save_static_function(sys_fork);
|
|
|
|
save_static_function(sys_clone);
|
2019-10-03 01:59:49 +07:00
|
|
|
save_static_function(sys_clone3);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-02-08 23:00:26 +07:00
|
|
|
SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
|
2005-04-14 00:43:59 +07:00
|
|
|
{
|
2006-01-12 16:06:07 +07:00
|
|
|
struct thread_info *ti = task_thread_info(current);
|
2005-04-14 00:43:59 +07:00
|
|
|
|
|
|
|
ti->tp_value = addr;
|
2007-07-10 23:33:02 +07:00
|
|
|
if (cpu_has_userlocal)
|
|
|
|
write_c0_userlocal(addr);
|
2006-09-19 23:18:53 +07:00
|
|
|
|
|
|
|
return 0;
|
2005-04-14 00:43:59 +07:00
|
|
|
}
|
|
|
|
|
2012-12-27 22:23:12 +07:00
|
|
|
static inline int mips_atomic_set(unsigned long addr, unsigned long new)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-09-17 07:25:05 +07:00
|
|
|
unsigned long old, tmp;
|
2012-12-27 22:23:12 +07:00
|
|
|
struct pt_regs *regs;
|
2009-09-17 07:25:05 +07:00
|
|
|
unsigned int err;
|
|
|
|
|
|
|
|
if (unlikely(addr & 3))
|
|
|
|
return -EINVAL;
|
|
|
|
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 09:57:57 +07:00
|
|
|
if (unlikely(!access_ok((const void __user *)addr, 4)))
|
2009-09-17 07:25:05 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (cpu_has_llsc && R10000_LLSC_WAR) {
|
|
|
|
__asm__ __volatile__ (
|
2018-11-09 03:14:38 +07:00
|
|
|
" .set push \n"
|
2014-03-30 18:20:10 +07:00
|
|
|
" .set arch=r4000 \n"
|
2009-09-17 07:25:05 +07:00
|
|
|
" li %[err], 0 \n"
|
|
|
|
"1: ll %[old], (%[addr]) \n"
|
|
|
|
" move %[tmp], %[new] \n"
|
|
|
|
"2: sc %[tmp], (%[addr]) \n"
|
|
|
|
" beqzl %[tmp], 1b \n"
|
|
|
|
"3: \n"
|
2014-11-16 05:09:31 +07:00
|
|
|
" .insn \n"
|
2009-09-17 07:25:05 +07:00
|
|
|
" .section .fixup,\"ax\" \n"
|
|
|
|
"4: li %[err], %[efault] \n"
|
|
|
|
" j 3b \n"
|
|
|
|
" .previous \n"
|
|
|
|
" .section __ex_table,\"a\" \n"
|
|
|
|
" "STR(PTR)" 1b, 4b \n"
|
|
|
|
" "STR(PTR)" 2b, 4b \n"
|
|
|
|
" .previous \n"
|
2018-11-09 03:14:38 +07:00
|
|
|
" .set pop \n"
|
2009-09-17 07:25:05 +07:00
|
|
|
: [old] "=&r" (old),
|
|
|
|
[err] "=&r" (err),
|
|
|
|
[tmp] "=&r" (tmp)
|
|
|
|
: [addr] "r" (addr),
|
|
|
|
[new] "r" (new),
|
|
|
|
[efault] "i" (-EFAULT)
|
|
|
|
: "memory");
|
|
|
|
} else if (cpu_has_llsc) {
|
|
|
|
__asm__ __volatile__ (
|
2018-11-09 03:14:38 +07:00
|
|
|
" .set push \n"
|
2015-01-15 17:34:00 +07:00
|
|
|
" .set "MIPS_ISA_ARCH_LEVEL" \n"
|
2009-09-17 07:25:05 +07:00
|
|
|
" li %[err], 0 \n"
|
2017-05-31 22:19:49 +07:00
|
|
|
"1: \n"
|
2019-10-02 04:53:39 +07:00
|
|
|
" " __SYNC(full, loongson3_war) " \n"
|
2017-05-31 22:19:49 +07:00
|
|
|
user_ll("%[old]", "(%[addr])")
|
2009-09-17 07:25:05 +07:00
|
|
|
" move %[tmp], %[new] \n"
|
2017-05-31 22:19:49 +07:00
|
|
|
"2: \n"
|
|
|
|
user_sc("%[tmp]", "(%[addr])")
|
2017-05-31 22:19:50 +07:00
|
|
|
" beqz %[tmp], 1b \n"
|
2009-09-17 07:25:05 +07:00
|
|
|
"3: \n"
|
2014-11-16 05:09:31 +07:00
|
|
|
" .insn \n"
|
2009-09-17 07:25:05 +07:00
|
|
|
" .section .fixup,\"ax\" \n"
|
|
|
|
"5: li %[err], %[efault] \n"
|
|
|
|
" j 3b \n"
|
|
|
|
" .previous \n"
|
|
|
|
" .section __ex_table,\"a\" \n"
|
|
|
|
" "STR(PTR)" 1b, 5b \n"
|
|
|
|
" "STR(PTR)" 2b, 5b \n"
|
|
|
|
" .previous \n"
|
2018-11-09 03:14:38 +07:00
|
|
|
" .set pop \n"
|
2009-09-17 07:25:05 +07:00
|
|
|
: [old] "=&r" (old),
|
|
|
|
[err] "=&r" (err),
|
|
|
|
[tmp] "=&r" (tmp)
|
|
|
|
: [addr] "r" (addr),
|
|
|
|
[new] "r" (new),
|
|
|
|
[efault] "i" (-EFAULT)
|
|
|
|
: "memory");
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
preempt_disable();
|
|
|
|
ll_bit = 1;
|
|
|
|
ll_task = current;
|
|
|
|
preempt_enable();
|
|
|
|
|
|
|
|
err = __get_user(old, (unsigned int *) addr);
|
|
|
|
err |= __put_user(new, (unsigned int *) addr);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
rmb();
|
|
|
|
} while (!ll_bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(err))
|
|
|
|
return err;
|
|
|
|
|
2012-12-27 22:23:12 +07:00
|
|
|
regs = current_pt_regs();
|
2009-09-17 07:25:05 +07:00
|
|
|
regs->regs[2] = old;
|
|
|
|
regs->regs[7] = 0; /* No error */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't let your children do this ...
|
|
|
|
*/
|
|
|
|
__asm__ __volatile__(
|
|
|
|
" move $29, %0 \n"
|
|
|
|
" j syscall_exit \n"
|
|
|
|
: /* no outputs */
|
|
|
|
: "r" (regs));
|
|
|
|
|
|
|
|
/* unreached. Honestly. */
|
2012-12-27 19:37:40 +07:00
|
|
|
unreachable();
|
2009-09-17 07:25:05 +07:00
|
|
|
}
|
|
|
|
|
2017-05-31 22:19:48 +07:00
|
|
|
/*
|
|
|
|
* mips_atomic_set() normally returns directly via syscall_exit potentially
|
|
|
|
* clobbering static registers, so be sure to preserve them.
|
|
|
|
*/
|
|
|
|
save_static_function(sys_sysmips);
|
|
|
|
|
2012-12-27 22:23:12 +07:00
|
|
|
SYSCALL_DEFINE3(sysmips, long, cmd, long, arg1, long, arg2)
|
2009-09-17 07:25:05 +07:00
|
|
|
{
|
2007-07-25 22:19:33 +07:00
|
|
|
switch (cmd) {
|
2005-04-17 05:20:36 +07:00
|
|
|
case MIPS_ATOMIC_SET:
|
2012-12-27 22:23:12 +07:00
|
|
|
return mips_atomic_set(arg1, arg2);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
case MIPS_FIXADE:
|
2007-07-25 22:19:33 +07:00
|
|
|
if (arg1 & ~3)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (arg1 & 1)
|
|
|
|
set_thread_flag(TIF_FIXADE);
|
|
|
|
else
|
|
|
|
clear_thread_flag(TIF_FIXADE);
|
|
|
|
if (arg1 & 2)
|
|
|
|
set_thread_flag(TIF_LOGADE);
|
|
|
|
else
|
2011-01-17 15:19:53 +07:00
|
|
|
clear_thread_flag(TIF_LOGADE);
|
2007-07-25 22:19:33 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case FLUSH_CACHE:
|
|
|
|
__flush_cache_all();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No implemented yet ...
|
|
|
|
*/
|
2009-02-08 23:00:26 +07:00
|
|
|
SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we ever come here the user sp is bad. Zap the process right away.
|
|
|
|
* Due to the bad stack signaling wouldn't work.
|
|
|
|
*/
|
|
|
|
asmlinkage void bad_stack(void)
|
|
|
|
{
|
|
|
|
do_exit(SIGSEGV);
|
|
|
|
}
|