chengshan / rpms / kernel

Forked from rpms/kernel 2 years ago
Clone
Justin Vreeland 794d92
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Justin Vreeland 794d92
From: Masahiro Yamada <yamada.masahiro@socionext.com>
Justin Vreeland 794d92
Date: Mon, 30 Sep 2019 14:59:25 +0900
Justin Vreeland 794d92
Subject: [PATCH] ARM: fix __get_user_check() in case uaccess_* calls are not
Justin Vreeland 794d92
 inlined
Justin Vreeland 794d92
Justin Vreeland 794d92
KernelCI reports that bcm2835_defconfig is no longer booting since
Justin Vreeland 794d92
commit ac7c3e4ff401 ("compiler: enable CONFIG_OPTIMIZE_INLINING
Justin Vreeland 794d92
forcibly"):
Justin Vreeland 794d92
Justin Vreeland 794d92
  https://lkml.org/lkml/2019/9/26/825
Justin Vreeland 794d92
Justin Vreeland 794d92
I also received a regression report from Nicolas Saenz Julienne:
Justin Vreeland 794d92
Justin Vreeland 794d92
  https://lkml.org/lkml/2019/9/27/263
Justin Vreeland 794d92
Justin Vreeland 794d92
This problem has cropped up on arch/arm/config/bcm2835_defconfig
Justin Vreeland 794d92
because it enables CONFIG_CC_OPTIMIZE_FOR_SIZE. The compiler tends
Justin Vreeland 794d92
to prefer not inlining functions with -Os. I was able to reproduce
Justin Vreeland 794d92
it with other boards and defconfig files by manually enabling
Justin Vreeland 794d92
CONFIG_CC_OPTIMIZE_FOR_SIZE.
Justin Vreeland 794d92
Justin Vreeland 794d92
The __get_user_check() specifically uses r0, r1, r2 registers.
Justin Vreeland 794d92
So, uaccess_save_and_enable() and uaccess_restore() must be inlined
Justin Vreeland 794d92
in order to avoid those registers being overwritten in the callees.
Justin Vreeland 794d92
Justin Vreeland 794d92
Prior to commit 9012d011660e ("compiler: allow all arches to enable
Justin Vreeland 794d92
CONFIG_OPTIMIZE_INLINING"), the 'inline' marker was always enough for
Justin Vreeland 794d92
inlining functions, except on x86.
Justin Vreeland 794d92
Justin Vreeland 794d92
Since that commit, all architectures can enable CONFIG_OPTIMIZE_INLINING.
Justin Vreeland 794d92
So, __always_inline is now the only guaranteed way of forcible inlining.
Justin Vreeland 794d92
Justin Vreeland 794d92
I want to keep as much compiler's freedom as possible about the inlining
Justin Vreeland 794d92
decision. So, I changed the function call order instead of adding
Justin Vreeland 794d92
__always_inline around.
Justin Vreeland 794d92
Justin Vreeland 794d92
Call uaccess_save_and_enable() before assigning the __p ("r0"), and
Justin Vreeland 794d92
uaccess_restore() after evacuating the __e ("r0").
Justin Vreeland 794d92
Justin Vreeland 794d92
Fixes: 9012d011660e ("compiler: allow all arches to enable CONFIG_OPTIMIZE_INLINING")
Justin Vreeland 794d92
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Justin Vreeland 794d92
Reported-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Justin Vreeland 794d92
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Justin Vreeland 794d92
Acked-by: Arnd Bergmann <arnd@arndb.de>
Justin Vreeland 794d92
Tested-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Justin Vreeland 794d92
Tested-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
Justin Vreeland 794d92
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Justin Vreeland 794d92
---
Justin Vreeland 794d92
 arch/arm/include/asm/uaccess.h | 8 +++++---
Justin Vreeland 794d92
 1 file changed, 5 insertions(+), 3 deletions(-)
Justin Vreeland 794d92
Justin Vreeland 794d92
diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
Justin Vreeland 794d92
index b5fdd30252f8..d43ceaa78269 100644
Justin Vreeland 794d92
--- a/arch/arm/include/asm/uaccess.h
Justin Vreeland 794d92
+++ b/arch/arm/include/asm/uaccess.h
Justin Vreeland 794d92
@@ -195,11 +195,12 @@ extern int __get_user_64t_4(void *);
Justin Vreeland 794d92
 #define __get_user_check(x, p)						\
Justin Vreeland 794d92
 	({								\
Justin Vreeland 794d92
 		unsigned long __limit = current_thread_info()->addr_limit - 1; \
Justin Vreeland 794d92
+		unsigned int __ua_flags = uaccess_save_and_enable();	\
Justin Vreeland 794d92
 		register typeof(*(p)) __user *__p asm("r0") = (p);	\
Justin Vreeland 794d92
 		register __inttype(x) __r2 asm("r2");			\
Justin Vreeland 794d92
 		register unsigned long __l asm("r1") = __limit;		\
Justin Vreeland 794d92
 		register int __e asm("r0");				\
Justin Vreeland 794d92
-		unsigned int __ua_flags = uaccess_save_and_enable();	\
Justin Vreeland 794d92
+		unsigned int __err;					\
Justin Vreeland 794d92
 		switch (sizeof(*(__p))) {				\
Justin Vreeland 794d92
 		case 1:							\
Justin Vreeland 794d92
 			if (sizeof((x)) >= 8)				\
Justin Vreeland 794d92
@@ -227,9 +228,10 @@ extern int __get_user_64t_4(void *);
Justin Vreeland 794d92
 			break;						\
Justin Vreeland 794d92
 		default: __e = __get_user_bad(); break;			\
Justin Vreeland 794d92
 		}							\
Justin Vreeland 794d92
-		uaccess_restore(__ua_flags);				\
Justin Vreeland 794d92
+		__err = __e;						\
Justin Vreeland 794d92
 		x = (typeof(*(p))) __r2;				\
Justin Vreeland 794d92
-		__e;							\
Justin Vreeland 794d92
+		uaccess_restore(__ua_flags);				\
Justin Vreeland 794d92
+		__err;							\
Justin Vreeland 794d92
 	})
Justin Vreeland 794d92
Justin Vreeland 794d92
 #define get_user(x, p)							\
Justin Vreeland 794d92
-- 
Justin Vreeland 794d92
2.28.0
Justin Vreeland 794d92