s390/sthyi: add s390_sthyi system call
authorQingFeng Hao <haoqf@linux.vnet.ibm.com>
Fri, 29 Sep 2017 10:41:52 +0000 (12:41 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 9 Oct 2017 09:15:36 +0000 (11:15 +0200)
Add a syscall of s390_sthyi to implement STHYI instruction in LPAR
which reuses the implementation for KVM by Janosch Frank -
commit 95ca2cb57985 ("KVM: s390: Add sthyi emulation").

STHYI(Store Hypervisor Information) is an emulated z/VM instruction that
provides a guest with basic information about the layers it is running
on. This includes information about the cpu configuration of both the
machine and the lpar, as well as their names, machine model and
machine type. This information enables an application to determine the
maximum capacity of CPs and IFLs available to software.

For the arguments of s390_sthyi, code shall be 0 and flags is reserved for
future use, info is the output argument to store the required hypervisor
info.

Signed-off-by: QingFeng Hao <haoqf@linux.vnet.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/s390/include/uapi/asm/sthyi.h [new file with mode: 0644]
arch/s390/include/uapi/asm/unistd.h
arch/s390/kernel/compat_wrapper.c
arch/s390/kernel/entry.h
arch/s390/kernel/sthyi.c
arch/s390/kernel/syscalls.S

diff --git a/arch/s390/include/uapi/asm/sthyi.h b/arch/s390/include/uapi/asm/sthyi.h
new file mode 100644 (file)
index 0000000..ec113db
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _UAPI_ASM_STHYI_H
+#define _UAPI_ASM_STHYI_H
+
+#define STHYI_FC_CP_IFL_CAP    0
+
+#endif /* _UAPI_ASM_STHYI_H */
index ea42290e7d51f7673b194c32ebda31c2158b21e2..61c64f5437696c353923931b15668c47ffa4fd79 100644 (file)
 #define __NR_pwritev2          377
 #define __NR_s390_guarded_storage      378
 #define __NR_statx             379
-#define NR_syscalls 380
+#define __NR_s390_sthyi                380
+#define NR_syscalls 381
 
 /* 
  * There are some system calls that are not present on 64 bit, some
index 986642a3543bb0a1e670613ccc50a3804d452480..eb0b17ed95b62d58ad86b0e3ba80363c1ca91774 100644 (file)
@@ -180,3 +180,4 @@ COMPAT_SYSCALL_WRAP3(mlock2, unsigned long, start, size_t, len, int, flags);
 COMPAT_SYSCALL_WRAP6(copy_file_range, int, fd_in, loff_t __user *, off_in, int, fd_out, loff_t __user *, off_out, size_t, len, unsigned int, flags);
 COMPAT_SYSCALL_WRAP2(s390_guarded_storage, int, command, struct gs_cb *, gs_cb);
 COMPAT_SYSCALL_WRAP5(statx, int, dfd, const char __user *, path, unsigned, flags, unsigned, mask, struct statx __user *, buffer);
+COMPAT_SYSCALL_WRAP4(s390_sthyi, unsigned long, code, void __user *, info, u64 __user *, rc, unsigned long, flags);
index dbf5f7e182469da8754b6c407396798938bd839c..bb5301eeb4f4d1fcb800d4ee03300e5ee84e0525 100644 (file)
@@ -77,6 +77,7 @@ long sys_s390_runtime_instr(int command, int signum);
 long sys_s390_guarded_storage(int command, struct gs_cb __user *);
 long sys_s390_pci_mmio_write(unsigned long, const void __user *, size_t);
 long sys_s390_pci_mmio_read(unsigned long, void __user *, size_t);
+long sys_s390_sthyi(unsigned long function_code, void __user *buffer, u64 __user *return_code, unsigned long flags);
 
 DECLARE_PER_CPU(u64, mt_cycles[8]);
 
index 27e3c3d87379932b1bac96dab01616d3bdfbbf31..12981e197f0125dcaea9f0bcb13f49207be00cec 100644 (file)
 #include <linux/errno.h>
 #include <linux/pagemap.h>
 #include <linux/vmalloc.h>
-
+#include <linux/syscalls.h>
+#include <linux/mutex.h>
 #include <asm/asm-offsets.h>
 #include <asm/sclp.h>
 #include <asm/diag.h>
 #include <asm/sysinfo.h>
 #include <asm/ebcdic.h>
 #include <asm/facility.h>
+#include <asm/sthyi.h>
+#include "entry.h"
 
 #define DED_WEIGHT 0xffff
 /*
@@ -484,3 +487,31 @@ out:
        return r;
 }
 EXPORT_SYMBOL_GPL(sthyi_fill);
+
+SYSCALL_DEFINE4(s390_sthyi, unsigned long, function_code, void __user *, buffer,
+               u64 __user *, return_code, unsigned long, flags)
+{
+       u64 sthyi_rc;
+       void *info;
+       int r;
+
+       if (flags)
+               return -EINVAL;
+       if (function_code != STHYI_FC_CP_IFL_CAP)
+               return -EOPNOTSUPP;
+       info = (void *)get_zeroed_page(GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+       r = sthyi_fill(info, &sthyi_rc);
+       if (r < 0)
+               goto out;
+       if (return_code && put_user(sthyi_rc, return_code)) {
+               r = -EFAULT;
+               goto out;
+       }
+       if (copy_to_user(buffer, info, PAGE_SIZE))
+               r = -EFAULT;
+out:
+       free_page((unsigned long)info);
+       return r;
+}
index 54fce7b065de2610c762763764cf1b97f7805b02..0fb407ebbf468d20fc5dee64ce9380c07f64c972 100644 (file)
@@ -388,3 +388,4 @@ SYSCALL(sys_preadv2,compat_sys_preadv2)
 SYSCALL(sys_pwritev2,compat_sys_pwritev2)
 SYSCALL(sys_s390_guarded_storage,compat_sys_s390_guarded_storage) /* 378 */
 SYSCALL(sys_statx,compat_sys_statx)
+SYSCALL(sys_s390_sthyi,compat_sys_s390_sthyi)