chengshan / rpms / kernel

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