Skip to content

Commit f5c8b96

Browse files
heicarstMartin Schwidefsky
authored andcommitted
s390/uaccess: use sane length for __strncpy_from_user()
The average string that is copied from user space to kernel space is rather short. E.g. booting a system involves about 50.000 strncpy_from_user() calls where the NULL terminated string has an average size of 27 bytes. By default our s390 specific strncpy_from_user() implementation however copies up to 4096 bytes, which is a waste of cpu cycles and cache lines. Therefore reduce the default length to L1_CACHE_BYTES (256 bytes), which also reduces the average execution time of strncpy_from_user() by 30-40%. Alternatively we could have switched to the generic strncpy_from_user() implementation, however it turned out that that variant would be slower than the now optimized s390 variant. Reported-by: Al Viro <viro@ZenIV.linux.org.uk> Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent db55947 commit f5c8b96

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎arch/s390/lib/uaccess.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ long __strncpy_from_user(char *dst, const char __user *src, long size)
337337
return 0;
338338
done = 0;
339339
do {
340-
offset = (size_t)src & ~PAGE_MASK;
341-
len = min(size - done, PAGE_SIZE - offset);
340+
offset = (size_t)src & (L1_CACHE_BYTES - 1);
341+
len = min(size - done, L1_CACHE_BYTES - offset);
342342
if (copy_from_user(dst, src, len))
343343
return -EFAULT;
344344
len_str = strnlen(dst, len);

0 commit comments

Comments
 (0)