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