]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/uaccess: Optimize raw_copy_from_user() / raw_copy_to_user() for constant sizes
authorHeiko Carstens <hca@linux.ibm.com>
Tue, 11 Feb 2025 19:19:29 +0000 (20:19 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 4 Mar 2025 16:18:03 +0000 (17:18 +0100)
Avoid that the compiler generates an mvcos loop for constant sizes
smaller than 4096 bytes. The mvcos instruction copies between zero and
4096 bytes (effective length) with one operation. Therefore it is not
necessary to implement a loop for sizes smaller or equal to 4096
bytes.

This reduces the kernel text size by ~50kb (defconfig, gcc 14.2.0):
add/remove: 4/5 grow/shrink: 6/471 up/down: 2294/-51700 (-49406)

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/include/asm/uaccess.h

index 333a2afc0d6f10a1ccc155684ec857afe9efdbf7..b5712d690a93dbe618865c2a35f9caa9439d31c1 100644 (file)
@@ -49,6 +49,8 @@ raw_copy_from_user(void *to, const void __user *from, unsigned long size)
                        : CC_OUT(cc, cc), [size] "+d" (size), [to] "=Q" (*(char *)to)
                        : [spec] "I" (0x81), [from] "Q" (*(const char __user *)from)
                        : CC_CLOBBER_LIST("memory", "0"));
+               if (__builtin_constant_p(osize) && osize <= 4096)
+                       return osize - size;
                if (likely(CC_TRANSFORM(cc) == 0))
                        return osize - size;
                size -= 4096;
@@ -75,6 +77,8 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long size)
                        : CC_OUT(cc, cc), [size] "+d" (size), [to] "=Q" (*(char __user *)to)
                        : [spec] "I" (0x81), [from] "Q" (*(const char *)from)
                        : CC_CLOBBER_LIST("memory", "0"));
+               if (__builtin_constant_p(osize) && osize <= 4096)
+                       return osize - size;
                if (likely(CC_TRANSFORM(cc) == 0))
                        return osize - size;
                size -= 4096;