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