| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* S390 version |
| 4 |
* Copyright IBM Corp. 1999, 2000 |
| 5 |
* Author(s): Martin Schwidefsky ([email protected]), |
| 6 |
* Thomas Spatzier ([email protected]) |
| 7 |
* |
| 8 |
* Derived from "arch/i386/kernel/sys_i386.c" |
| 9 |
* |
| 10 |
* This file contains various random system calls that |
| 11 |
* have a non-standard calling sequence on the Linux/s390 |
| 12 |
* platform. |
| 13 |
*/ |
| 14 |
|
| 15 |
#include <linux/cpufeature.h> |
| 16 |
#include <linux/nospec.h> |
| 17 |
#include <linux/errno.h> |
| 18 |
#include <linux/sched.h> |
| 19 |
#include <linux/mm.h> |
| 20 |
#include <linux/fs.h> |
| 21 |
#include <linux/smp.h> |
| 22 |
#include <linux/sem.h> |
| 23 |
#include <linux/msg.h> |
| 24 |
#include <linux/shm.h> |
| 25 |
#include <linux/stat.h> |
| 26 |
#include <linux/syscalls.h> |
| 27 |
#include <linux/mman.h> |
| 28 |
#include <linux/file.h> |
| 29 |
#include <linux/utsname.h> |
| 30 |
#include <linux/personality.h> |
| 31 |
#include <linux/unistd.h> |
| 32 |
#include <linux/ipc.h> |
| 33 |
#include <linux/uaccess.h> |
| 34 |
#include <linux/string.h> |
| 35 |
#include <linux/thread_info.h> |
| 36 |
#include <linux/entry-common.h> |
| 37 |
|
| 38 |
#include <asm/ptrace.h> |
| 39 |
#include <asm/vtime.h> |
| 40 |
|
| 41 |
#include "entry.h" |
| 42 |
|
| 43 |
#define __SYSCALL(nr, sym) long __s390x_##sym(struct pt_regs *); |
| 44 |
#include <asm/syscall_table.h> |
| 45 |
#undef __SYSCALL |
| 46 |
|
| 47 |
#define __SYSCALL(nr, sym) [nr] = (__s390x_##sym), |
| 48 |
const sys_call_ptr_t sys_call_table[__NR_syscalls] = { |
| 49 |
#include <asm/syscall_table.h> |
| 50 |
}; |
| 51 |
#undef __SYSCALL |
| 52 |
|
| 53 |
#ifdef CONFIG_SYSVIPC |
| 54 |
/* |
| 55 |
* sys_ipc() is the de-multiplexer for the SysV IPC calls. |
| 56 |
*/ |
| 57 |
SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second, |
| 58 |
unsigned long, third, void __user *, ptr) |
| 59 |
{ |
| 60 |
if (call >> 16) |
| 61 |
return -EINVAL; |
| 62 |
/* The s390 sys_ipc variant has only five parameters instead of six |
| 63 |
* like the generic variant. The only difference is the handling of |
| 64 |
* the SEMTIMEDOP subcall where on s390 the third parameter is used |
| 65 |
* as a pointer to a struct timespec where the generic variant uses |
| 66 |
* the fifth parameter. |
| 67 |
* Therefore we can call the generic variant by simply passing the |
| 68 |
* third parameter also as fifth parameter. |
| 69 |
*/ |
| 70 |
return ksys_ipc(call, first, second, third, ptr, third); |
| 71 |
} |
| 72 |
#endif /* CONFIG_SYSVIPC */ |
| 73 |
|
| 74 |
SYSCALL_DEFINE1(s390_personality, unsigned int, personality) |
| 75 |
{ |
| 76 |
unsigned int ret = current->personality; |
| 77 |
|
| 78 |
if (personality(current->personality) == PER_LINUX32 && |
| 79 |
personality(personality) == PER_LINUX) |
| 80 |
personality |= PER_LINUX32; |
| 81 |
|
| 82 |
if (personality != 0xffffffff) |
| 83 |
set_personality(personality); |
| 84 |
|
| 85 |
if (personality(ret) == PER_LINUX32) |
| 86 |
ret &= ~PER_LINUX32; |
| 87 |
|
| 88 |
return ret; |
| 89 |
} |
| 90 |
|
| 91 |
SYSCALL_DEFINE0(ni_syscall) |
| 92 |
{ |
| 93 |
return -ENOSYS; |
| 94 |
} |
| 95 |
|
| 96 |
void noinstr __do_syscall(struct pt_regs *regs, int per_trap) |
| 97 |
{ |
| 98 |
unsigned long nr; |
| 99 |
|
| 100 |
add_random_kstack_offset(); |
| 101 |
enter_from_user_mode(regs); |
| 102 |
regs->psw = get_lowcore()->svc_old_psw; |
| 103 |
regs->int_code = get_lowcore()->svc_int_code; |
| 104 |
update_timer_sys(); |
| 105 |
if (cpu_has_bear()) |
| 106 |
current->thread.last_break = regs->last_break; |
| 107 |
local_irq_enable(); |
| 108 |
regs->orig_gpr2 = regs->gprs[2]; |
| 109 |
if (unlikely(per_trap)) |
| 110 |
set_thread_flag(TIF_PER_TRAP); |
| 111 |
regs->flags = 0; |
| 112 |
set_pt_regs_flag(regs, PIF_SYSCALL); |
| 113 |
nr = regs->int_code & 0xffff; |
| 114 |
if (likely(!nr)) { |
| 115 |
nr = regs->gprs[1] & 0xffff; |
| 116 |
regs->int_code &= ~0xffffUL; |
| 117 |
regs->int_code |= nr; |
| 118 |
} |
| 119 |
regs->gprs[2] = nr; |
| 120 |
if (nr == __NR_restart_syscall && !(current->restart_block.arch_data & 1)) { |
| 121 |
regs->psw.addr = current->restart_block.arch_data; |
| 122 |
current->restart_block.arch_data = 1; |
| 123 |
} |
| 124 |
nr = syscall_enter_from_user_mode_work(regs, nr); |
| 125 |
/* |
| 126 |
* In the s390 ptrace ABI, both the syscall number and the return value |
| 127 |
* use gpr2. However, userspace puts the syscall number either in the |
| 128 |
* svc instruction itself, or uses gpr1. To make at least skipping syscalls |
| 129 |
* work, the ptrace code sets PIF_SYSCALL_RET_SET, which is checked here |
| 130 |
* and if set, the syscall will be skipped. |
| 131 |
*/ |
| 132 |
if (unlikely(test_and_clear_pt_regs_flag(regs, PIF_SYSCALL_RET_SET))) |
| 133 |
goto out; |
| 134 |
regs->gprs[2] = -ENOSYS; |
| 135 |
if (likely(nr < NR_syscalls)) { |
| 136 |
nr = array_index_nospec(nr, NR_syscalls); |
| 137 |
regs->gprs[2] = sys_call_table[nr](regs); |
| 138 |
} |
| 139 |
out: |
| 140 |
syscall_exit_to_user_mode(regs); |
| 141 |
} |