From: Heiko Carstens Date: Tue, 11 Feb 2025 19:19:29 +0000 (+0100) Subject: s390/uaccess: Optimize raw_copy_from_user() / raw_copy_to_user() for constant sizes X-Git-Tag: v6.15-rc1~113^2~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88e87cb7b8f8afcf1776d5b8a3ddd17fe8d2a32f;p=thirdparty%2Fkernel%2Flinux.git s390/uaccess: Optimize raw_copy_from_user() / raw_copy_to_user() for constant sizes 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 Signed-off-by: Vasily Gorbik --- diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h index 333a2afc0d6f1..b5712d690a93d 100644 --- a/arch/s390/include/asm/uaccess.h +++ b/arch/s390/include/asm/uaccess.h @@ -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;