include/linux/thread_info.h | 5 +---- mm/maccess.c | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-)
While building a small config with CONFIG_CC_OPTIMISE_FOR_SIZE,
I ended up with more than 50 times the following function in vmlinux:
c00243bc <copy_overflow>:
c00243bc: 94 21 ff f0 stwu r1,-16(r1)
c00243c0: 7c 85 23 78 mr r5,r4
c00243c4: 7c 64 1b 78 mr r4,r3
c00243c8: 3c 60 c0 62 lis r3,-16286
c00243cc: 7c 08 02 a6 mflr r0
c00243d0: 38 63 5e e5 addi r3,r3,24293
c00243d4: 90 01 00 14 stw r0,20(r1)
c00243d8: 4b ff 82 45 bl c001c61c <__warn_printk>
c00243dc: 0f e0 00 00 twui r0,0
c00243e0: 80 01 00 14 lwz r0,20(r1)
c00243e4: 38 21 00 10 addi r1,r1,16
c00243e8: 7c 08 03 a6 mtlr r0
c00243ec: 4e 80 00 20 blr
That function being a non conditional warning on an error path,
it is not worth inlining.
Outline it.
This reduces the size of vmlinux by almost 4kbytes.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
include/linux/thread_info.h | 5 +----
mm/maccess.c | 5 +++++
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 73a6f34b3847..1087d1e2be5c 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -209,10 +209,7 @@ __bad_copy_from(void);
extern void __compiletime_error("copy destination size is too small")
__bad_copy_to(void);
-static inline void copy_overflow(int size, unsigned long count)
-{
- WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
-}
+void copy_overflow(int size, unsigned long count);
static __always_inline __must_check bool
check_copy_size(const void *addr, size_t bytes, bool is_source)
diff --git a/mm/maccess.c b/mm/maccess.c
index d3f1a1f0b1c1..d15c7b2324b4 100644
--- a/mm/maccess.c
+++ b/mm/maccess.c
@@ -335,3 +335,8 @@ long strnlen_user_nofault(const void __user *unsafe_addr, long count)
return ret;
}
+
+void copy_overflow(int size, unsigned long count)
+{
+ WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
+}
--
2.33.1
Hi Christophe,
I love your patch! Yet something to improve:
[auto build test ERROR on hnaz-mm/master]
url: https://github.com/0day-ci/linux/commits/Christophe-Leroy/mm-Outline-copy_overflow/20220207-190441
base: https://github.com/hnaz/linux-mm master
config: i386-randconfig-a013-20220207 (https://download.01.org/0day-ci/archive/20220207/202202072148.OAzMGrDo-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/2ae7547d08e23e529db61b3de0cb93879630a102
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christophe-Leroy/mm-Outline-copy_overflow/20220207-190441
git checkout 2ae7547d08e23e529db61b3de0cb93879630a102
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "copy_overflow" [drivers/usb/gadget/function/usb_f_fs.ko] undefined!
>> ERROR: modpost: "copy_overflow" [drivers/scsi/sg.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
On Mon, 7 Feb 2022 11:55:18 +0100 Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > While building a small config with CONFIG_CC_OPTIMISE_FOR_SIZE, > I ended up with more than 50 times the following function in vmlinux: > > c00243bc <copy_overflow>: > c00243bc: 94 21 ff f0 stwu r1,-16(r1) > c00243c0: 7c 85 23 78 mr r5,r4 > c00243c4: 7c 64 1b 78 mr r4,r3 > c00243c8: 3c 60 c0 62 lis r3,-16286 > c00243cc: 7c 08 02 a6 mflr r0 > c00243d0: 38 63 5e e5 addi r3,r3,24293 > c00243d4: 90 01 00 14 stw r0,20(r1) > c00243d8: 4b ff 82 45 bl c001c61c <__warn_printk> > c00243dc: 0f e0 00 00 twui r0,0 > c00243e0: 80 01 00 14 lwz r0,20(r1) > c00243e4: 38 21 00 10 addi r1,r1,16 > c00243e8: 7c 08 03 a6 mtlr r0 > c00243ec: 4e 80 00 20 blr > > That function being a non conditional warning on an error path, > it is not worth inlining. > > Outline it. "uninline" is the conventional term for this. > This reduces the size of vmlinux by almost 4kbytes. Did you consider uninlining check_copy_size() instead?
Le 07/02/2022 à 21:40, Andrew Morton a écrit : > On Mon, 7 Feb 2022 11:55:18 +0100 Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > >> While building a small config with CONFIG_CC_OPTIMISE_FOR_SIZE, >> I ended up with more than 50 times the following function in vmlinux: >> >> c00243bc <copy_overflow>: >> c00243bc: 94 21 ff f0 stwu r1,-16(r1) >> c00243c0: 7c 85 23 78 mr r5,r4 >> c00243c4: 7c 64 1b 78 mr r4,r3 >> c00243c8: 3c 60 c0 62 lis r3,-16286 >> c00243cc: 7c 08 02 a6 mflr r0 >> c00243d0: 38 63 5e e5 addi r3,r3,24293 >> c00243d4: 90 01 00 14 stw r0,20(r1) >> c00243d8: 4b ff 82 45 bl c001c61c <__warn_printk> >> c00243dc: 0f e0 00 00 twui r0,0 >> c00243e0: 80 01 00 14 lwz r0,20(r1) >> c00243e4: 38 21 00 10 addi r1,r1,16 >> c00243e8: 7c 08 03 a6 mtlr r0 >> c00243ec: 4e 80 00 20 blr >> >> That function being a non conditional warning on an error path, >> it is not worth inlining. >> >> Outline it. > > "uninline" is the conventional term for this. > >> This reduces the size of vmlinux by almost 4kbytes. > > Did you consider uninlining check_copy_size() instead? > If you uninline check_copy_size() you loose the benefit of constant folding and build time overflow detection for constant sizes, and I'm not sure __builtin_object_size() works at all if uninlined. Christophe
© 2016 - 2026 Red Hat, Inc.