linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] drm: panel: fix excessive stack usage in td028ttec1_prepare
@ 2020-01-08 13:51 Arnd Bergmann
  2020-01-12 20:19 ` Sam Ravnborg
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2020-01-08 13:51 UTC (permalink / raw)
  To: Thierry Reding, David Airlie, Daniel Vetter
  Cc: Oleksandr Natalenko, Arnd Bergmann, Sam Ravnborg,
	Laurent Pinchart, Linus Walleij, Tomi Valkeinen, Boris Brezillon,
	dri-devel, linux-kernel

With gcc -O3 in combination with the structleak plug, the compiler can
inline very aggressively, leading to rather large stack usage:

drivers/gpu/drm/panel/panel-tpo-td028ttec1.c: In function 'td028ttec1_prepare':
drivers/gpu/drm/panel/panel-tpo-td028ttec1.c:233:1: error: the frame size of 2768 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]
 }

Marking jbt_reg_write_*() as noinline avoids the case where
multiple instances of this function get inlined into the same
stack frame and each one adds a copy of 'tx_buf'.

The compiler is clearly making some bad decisions here, but I
did not open a new bug report as this only happens in combination
with the structleak plugin.

Link: https://lore.kernel.org/lkml/CAK8P3a3jAnFZA3GFRtdYdg1-i-oih3pOQzkkrK-X3BGsFrMiZQ@mail.gmail.com/
Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2:
- mark all three functions as noinlien
- add code comment
- add link to more detailed analysis
---
 drivers/gpu/drm/panel/panel-tpo-td028ttec1.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c b/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
index cf29405a2dbe..5034db8b55de 100644
--- a/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
+++ b/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
@@ -86,7 +86,12 @@ struct td028ttec1_panel {
 
 #define to_td028ttec1_device(p) container_of(p, struct td028ttec1_panel, panel)
 
-static int jbt_ret_write_0(struct td028ttec1_panel *lcd, u8 reg, int *err)
+/*
+ * noinline_for_stack so we don't get multiple copies of tx_buf
+ * on the stack in case of gcc-plugin-structleak
+ */
+static int noinline_for_stack
+jbt_ret_write_0(struct td028ttec1_panel *lcd, u8 reg, int *err)
 {
 	struct spi_device *spi = lcd->spi;
 	u16 tx_buf = JBT_COMMAND | reg;
@@ -105,7 +110,8 @@ static int jbt_ret_write_0(struct td028ttec1_panel *lcd, u8 reg, int *err)
 	return ret;
 }
 
-static int jbt_reg_write_1(struct td028ttec1_panel *lcd,
+static int noinline_for_stack
+jbt_reg_write_1(struct td028ttec1_panel *lcd,
 			   u8 reg, u8 data, int *err)
 {
 	struct spi_device *spi = lcd->spi;
@@ -128,7 +134,8 @@ static int jbt_reg_write_1(struct td028ttec1_panel *lcd,
 	return ret;
 }
 
-static int jbt_reg_write_2(struct td028ttec1_panel *lcd,
+static int noinline_for_stack
+jbt_reg_write_2(struct td028ttec1_panel *lcd,
 			   u8 reg, u16 data, int *err)
 {
 	struct spi_device *spi = lcd->spi;
-- 
2.20.0


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

* Re: [PATCH] [v2] drm: panel: fix excessive stack usage in td028ttec1_prepare
  2020-01-08 13:51 [PATCH] [v2] drm: panel: fix excessive stack usage in td028ttec1_prepare Arnd Bergmann
@ 2020-01-12 20:19 ` Sam Ravnborg
  0 siblings, 0 replies; 2+ messages in thread
From: Sam Ravnborg @ 2020-01-12 20:19 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Thierry Reding, David Airlie, Daniel Vetter, Oleksandr Natalenko,
	Laurent Pinchart, Linus Walleij, Tomi Valkeinen, Boris Brezillon,
	dri-devel, linux-kernel

Hi Arnd.

On Wed, Jan 08, 2020 at 02:51:05PM +0100, Arnd Bergmann wrote:
> With gcc -O3 in combination with the structleak plug, the compiler can
> inline very aggressively, leading to rather large stack usage:
> 
> drivers/gpu/drm/panel/panel-tpo-td028ttec1.c: In function 'td028ttec1_prepare':
> drivers/gpu/drm/panel/panel-tpo-td028ttec1.c:233:1: error: the frame size of 2768 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]
>  }
> 
> Marking jbt_reg_write_*() as noinline avoids the case where
> multiple instances of this function get inlined into the same
> stack frame and each one adds a copy of 'tx_buf'.
> 
> The compiler is clearly making some bad decisions here, but I
> did not open a new bug report as this only happens in combination
> with the structleak plugin.
> 
> Link: https://lore.kernel.org/lkml/CAK8P3a3jAnFZA3GFRtdYdg1-i-oih3pOQzkkrK-X3BGsFrMiZQ@mail.gmail.com/
> Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2:
> - mark all three functions as noinlien
> - add code comment
> - add link to more detailed analysis

Thanks for the updated patch.
Applied to drm-misc-next.

	Sam

> ---
>  drivers/gpu/drm/panel/panel-tpo-td028ttec1.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c b/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
> index cf29405a2dbe..5034db8b55de 100644
> --- a/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
> +++ b/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
> @@ -86,7 +86,12 @@ struct td028ttec1_panel {
>  
>  #define to_td028ttec1_device(p) container_of(p, struct td028ttec1_panel, panel)
>  
> -static int jbt_ret_write_0(struct td028ttec1_panel *lcd, u8 reg, int *err)
> +/*
> + * noinline_for_stack so we don't get multiple copies of tx_buf
> + * on the stack in case of gcc-plugin-structleak
> + */
> +static int noinline_for_stack
> +jbt_ret_write_0(struct td028ttec1_panel *lcd, u8 reg, int *err)
>  {
>  	struct spi_device *spi = lcd->spi;
>  	u16 tx_buf = JBT_COMMAND | reg;
> @@ -105,7 +110,8 @@ static int jbt_ret_write_0(struct td028ttec1_panel *lcd, u8 reg, int *err)
>  	return ret;
>  }
>  
> -static int jbt_reg_write_1(struct td028ttec1_panel *lcd,
> +static int noinline_for_stack
> +jbt_reg_write_1(struct td028ttec1_panel *lcd,
>  			   u8 reg, u8 data, int *err)
>  {
>  	struct spi_device *spi = lcd->spi;
> @@ -128,7 +134,8 @@ static int jbt_reg_write_1(struct td028ttec1_panel *lcd,
>  	return ret;
>  }
>  
> -static int jbt_reg_write_2(struct td028ttec1_panel *lcd,
> +static int noinline_for_stack
> +jbt_reg_write_2(struct td028ttec1_panel *lcd,
>  			   u8 reg, u16 data, int *err)
>  {
>  	struct spi_device *spi = lcd->spi;
> -- 
> 2.20.0

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

end of thread, other threads:[~2020-01-12 20:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08 13:51 [PATCH] [v2] drm: panel: fix excessive stack usage in td028ttec1_prepare Arnd Bergmann
2020-01-12 20:19 ` Sam Ravnborg

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).