Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/uaccess: Tell the compiler that uaccess is unlikely to fault

GCC doesn't realize that get_user(), put_user(), and their __
variants are unlikely to fail. Tell it.

I noticed this while playing with the C entry code.

Before:
text data bss dec filename
21828763 5194760 1277952 28301475 vmlinux.baseline

After:
text data bss dec filename
21828379 5194760 1277952 28301091 vmlinux.new

The generated code shrunk by 384 bytes.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/dc37bed7024319c3004d950d57151fca6aeacf97.1444091584.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
a76cf66e 25a9a924

+4 -4
+4 -4
arch/x86/include/asm/uaccess.h
··· 182 182 : "=a" (__ret_gu), "=r" (__val_gu) \ 183 183 : "0" (ptr), "i" (sizeof(*(ptr)))); \ 184 184 (x) = (__force __typeof__(*(ptr))) __val_gu; \ 185 - __ret_gu; \ 185 + __builtin_expect(__ret_gu, 0); \ 186 186 }) 187 187 188 188 #define __put_user_x(size, x, ptr, __ret_pu) \ ··· 278 278 __put_user_x(X, __pu_val, ptr, __ret_pu); \ 279 279 break; \ 280 280 } \ 281 - __ret_pu; \ 281 + __builtin_expect(__ret_pu, 0); \ 282 282 }) 283 283 284 284 #define __put_user_size(x, ptr, size, retval, errret) \ ··· 401 401 ({ \ 402 402 int __pu_err; \ 403 403 __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \ 404 - __pu_err; \ 404 + __builtin_expect(__pu_err, 0); \ 405 405 }) 406 406 407 407 #define __get_user_nocheck(x, ptr, size) \ ··· 410 410 unsigned long __gu_val; \ 411 411 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \ 412 412 (x) = (__force __typeof__(*(ptr)))__gu_val; \ 413 - __gu_err; \ 413 + __builtin_expect(__gu_err, 0); \ 414 414 }) 415 415 416 416 /* FIXME: this hack is definitely wrong -AK */