s390: use generic strncpy/strnlen from_user
authorHeiko Carstens <hca@linux.ibm.com>
Thu, 22 Jul 2021 20:07:30 +0000 (22:07 +0200)
committerArnd Bergmann <arnd@arndb.de>
Tue, 27 Jul 2021 21:01:13 +0000 (23:01 +0200)
The s390 variant of strncpy_from_user() is slightly faster than the
generic variant, however convert to the generic variant now to follow
most if not all other architectures.

Converting to the generic variant was already considered a couple of
years ago. See commit f5c8b9601036 ("s390/uaccess: use sane length for
__strncpy_from_user()").

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/s390/Kconfig
arch/s390/include/asm/uaccess.h
arch/s390/lib/uaccess.c

index a0e2130f0100ca4ad8420d6cfbc826d724716517..e3988b538a0c71d5ed0d19511dd8687e9beb6b94 100644 (file)
@@ -130,6 +130,8 @@ config S390
        select GENERIC_GETTIMEOFDAY
        select GENERIC_PTDUMP
        select GENERIC_SMP_IDLE_THREAD
+       select GENERIC_STRNCPY_FROM_USER
+       select GENERIC_STRNLEN_USER
        select GENERIC_TIME_VSYSCALL
        select GENERIC_VDSO_TIME_NS
        select HAVE_ALIGNED_STRUCT_PAGE if SLUB
index 2316f2440881ae814028382cd675962818d2ebfe..9ed9aa37e836b649bbba69ab7e23ad6ea9a1457e 100644 (file)
@@ -233,23 +233,9 @@ raw_copy_in_user(void __user *to, const void __user *from, unsigned long n);
 /*
  * Copy a null terminated string from userspace.
  */
+long __must_check strncpy_from_user(char *dst, const char __user *src, long count);
 
-long __strncpy_from_user(char *dst, const char __user *src, long count);
-
-static inline long __must_check
-strncpy_from_user(char *dst, const char __user *src, long count)
-{
-       might_fault();
-       return __strncpy_from_user(dst, src, count);
-}
-
-unsigned long __must_check __strnlen_user(const char __user *src, unsigned long count);
-
-static inline unsigned long strnlen_user(const char __user *src, unsigned long n)
-{
-       might_fault();
-       return __strnlen_user(src, n);
-}
+long __must_check strnlen_user(const char __user *src, long count);
 
 /*
  * Zero Userspace
index 7ec8b1fa0f089156ff62b2c2e1a02f0a6de110e9..94ca99bde59dfb3e9d0a348a2cf6cfe79f059792 100644 (file)
@@ -338,55 +338,3 @@ unsigned long __clear_user(void __user *to, unsigned long size)
        return clear_user_xc(to, size);
 }
 EXPORT_SYMBOL(__clear_user);
-
-static inline unsigned long strnlen_user_srst(const char __user *src,
-                                             unsigned long size)
-{
-       unsigned long tmp1, tmp2;
-
-       asm volatile(
-               "   lghi  0,0\n"
-               "   la    %2,0(%1)\n"
-               "   la    %3,0(%0,%1)\n"
-               "   slgr  %0,%0\n"
-               "   sacf  256\n"
-               "0: srst  %3,%2\n"
-               "   jo    0b\n"
-               "   la    %0,1(%3)\n"   /* strnlen_user results includes \0 */
-               "   slgr  %0,%1\n"
-               "1: sacf  768\n"
-               EX_TABLE(0b,1b)
-               : "+a" (size), "+a" (src), "=a" (tmp1), "=a" (tmp2)
-               :
-               : "cc", "memory", "0");
-       return size;
-}
-
-unsigned long __strnlen_user(const char __user *src, unsigned long size)
-{
-       if (unlikely(!size))
-               return 0;
-       return strnlen_user_srst(src, size);
-}
-EXPORT_SYMBOL(__strnlen_user);
-
-long __strncpy_from_user(char *dst, const char __user *src, long size)
-{
-       size_t done, len, offset, len_str;
-
-       if (unlikely(size <= 0))
-               return 0;
-       done = 0;
-       do {
-               offset = (size_t)src & (L1_CACHE_BYTES - 1);
-               len = min(size - done, L1_CACHE_BYTES - offset);
-               if (copy_from_user(dst, src, len))
-                       return -EFAULT;
-               len_str = strnlen(dst, len);
-               done += len_str;
-               src += len_str;
-               dst += len_str;
-       } while ((len_str == len) && (done < size));
-       return done;
-}
-EXPORT_SYMBOL(__strncpy_from_user);