linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm: Uninline copy_overflow()
@ 2022-02-11 10:15 Christophe Leroy
  2022-02-13  2:46 ` David Laight
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe Leroy @ 2022-02-11 10:15 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Christophe Leroy, linux-kernel, linux-mm

While building a small config with CONFIG_CC_OPTIMISE_FOR_SIZE,
I ended up with more than 50 times the following function in vmlinux
because GCC doesn't honor the 'inline' keyword:

	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

With -Winline, GCC tells:

	/include/linux/thread_info.h:212:20: warning: inlining failed in call to 'copy_overflow': call is unlikely and code size would grow [-Winline]

copy_overflow() is a non conditional warning called by
check_copy_size() on an error path.

check_copy_size() have to remain inlined in order to benefit
from constant folding, but copy_overflow() is not worth inlining.

Uninline it.

This reduces the size of vmlinux by almost 4kbytes.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
v2: Added missing EXPORT_SYMBOL() and enhanced commit message
---
 include/linux/thread_info.h | 5 +----
 mm/maccess.c                | 6 ++++++
 2 files changed, 7 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..6b11a22f4b01 100644
--- a/mm/maccess.c
+++ b/mm/maccess.c
@@ -335,3 +335,9 @@ 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);
+}
+EXPORT_SYMBOL_GPL(copy_overflow)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH v2] mm: Uninline copy_overflow()
  2022-02-11 10:15 [PATCH v2] mm: Uninline copy_overflow() Christophe Leroy
@ 2022-02-13  2:46 ` David Laight
  0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2022-02-13  2:46 UTC (permalink / raw)
  To: 'Christophe Leroy', Andrew Morton; +Cc: linux-kernel, linux-mm

From: Christophe Leroy
> Sent: 11 February 2022 10:16
...
> copy_overflow() is a non conditional warning called by
> check_copy_size() on an error path.
> 
> check_copy_size() have to remain inlined in order to benefit
> from constant folding, but copy_overflow() is not worth inlining.
> 
> Uninline it.
> 
> This reduces the size of vmlinux by almost 4kbytes.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> v2: Added missing EXPORT_SYMBOL() and enhanced commit message
> ---
>  include/linux/thread_info.h | 5 +----
>  mm/maccess.c                | 6 ++++++
>  2 files changed, 7 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..6b11a22f4b01 100644
> --- a/mm/maccess.c
> +++ b/mm/maccess.c
> @@ -335,3 +335,9 @@ 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);
> +}
> +EXPORT_SYMBOL_GPL(copy_overflow)

Can you remove the _GPL ????

I think that basically stops you compiling any non-gpl code if the
copy_protection is enabled in the kernel build.
I'm guessing that most of the inline wrappers calling this are non-FPL
functions.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-13  2:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-11 10:15 [PATCH v2] mm: Uninline copy_overflow() Christophe Leroy
2022-02-13  2:46 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).