mtdchar: mark bits of ioctl handler noinline

Message ID 20230417205654.1982368-1-arnd@kernel.org
State New
Headers
Series mtdchar: mark bits of ioctl handler noinline |

Commit Message

Arnd Bergmann April 17, 2023, 8:56 p.m. UTC
  From: Arnd Bergmann <arnd@arndb.de>

The addition of the mtdchar_read_ioctl() function caused the stack usage
of mtdchar_ioctl() to grow beyond the warning limit on 32-bit architectures
with gcc-13:

drivers/mtd/mtdchar.c: In function 'mtdchar_ioctl':
drivers/mtd/mtdchar.c:1229:1: error: the frame size of 1488 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]

Mark both the read and write portions as noinline_for_stack to ensure
they don't get inlined and use separate stack slots to reduce the
maximum usage, both in the mtdchar_ioctl() and combined with any
of its callees.

Fixes: 095bb6e44eb1 ("mtdchar: add MEMREAD ioctl")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/mtd/mtdchar.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Richard Weinberger April 17, 2023, 9:20 p.m. UTC | #1
----- Ursprüngliche Mail -----
> Von: "Arnd Bergmann" <arnd@kernel.org>
> The addition of the mtdchar_read_ioctl() function caused the stack usage
> of mtdchar_ioctl() to grow beyond the warning limit on 32-bit architectures
> with gcc-13:
> 
> drivers/mtd/mtdchar.c: In function 'mtdchar_ioctl':
> drivers/mtd/mtdchar.c:1229:1: error: the frame size of 1488 bytes is larger than
> 1024 bytes [-Werror=frame-larger-than=]
> 
> Mark both the read and write portions as noinline_for_stack to ensure
> they don't get inlined and use separate stack slots to reduce the
> maximum usage, both in the mtdchar_ioctl() and combined with any
> of its callees.
> 
> Fixes: 095bb6e44eb1 ("mtdchar: add MEMREAD ioctl")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard
  
Miquel Raynal May 22, 2023, 3:46 p.m. UTC | #2
Hi Arnd,

arnd@kernel.org wrote on Mon, 17 Apr 2023 22:56:50 +0200:

> From: Arnd Bergmann <arnd@arndb.de>
> 
> The addition of the mtdchar_read_ioctl() function caused the stack usage
> of mtdchar_ioctl() to grow beyond the warning limit on 32-bit architectures
> with gcc-13:
> 
> drivers/mtd/mtdchar.c: In function 'mtdchar_ioctl':
> drivers/mtd/mtdchar.c:1229:1: error: the frame size of 1488 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
> 
> Mark both the read and write portions as noinline_for_stack to ensure
> they don't get inlined and use separate stack slots to reduce the
> maximum usage, both in the mtdchar_ioctl() and combined with any
> of its callees.
> 
> Fixes: 095bb6e44eb1 ("mtdchar: add MEMREAD ioctl")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

I am about to take this as part of my next fixes PR, should we Cc:
stable? What is the current policy wrt gcc version issues?

> ---
>  drivers/mtd/mtdchar.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
> index 01f1c6792df9..8dc4f5c493fc 100644
> --- a/drivers/mtd/mtdchar.c
> +++ b/drivers/mtd/mtdchar.c
> @@ -590,8 +590,8 @@ static void adjust_oob_length(struct mtd_info *mtd, uint64_t start,
>  			    (end_page - start_page + 1) * oob_per_page);
>  }
>  
> -static int mtdchar_write_ioctl(struct mtd_info *mtd,
> -		struct mtd_write_req __user *argp)
> +static noinline_for_stack int
> +mtdchar_write_ioctl(struct mtd_info *mtd, struct mtd_write_req __user *argp)
>  {
>  	struct mtd_info *master = mtd_get_master(mtd);
>  	struct mtd_write_req req;
> @@ -688,8 +688,8 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd,
>  	return ret;
>  }
>  
> -static int mtdchar_read_ioctl(struct mtd_info *mtd,
> -		struct mtd_read_req __user *argp)
> +static noinline_for_stack int
> +mtdchar_read_ioctl(struct mtd_info *mtd, struct mtd_read_req __user *argp)
>  {
>  	struct mtd_info *master = mtd_get_master(mtd);
>  	struct mtd_read_req req;


Thanks,
Miquèl
  
Arnd Bergmann May 23, 2023, 12:14 p.m. UTC | #3
On Mon, May 22, 2023, at 17:46, Miquel Raynal wrote:
>
> I am about to take this as part of my next fixes PR, should we Cc:
> stable? What is the current policy wrt gcc version issues?

I think in general we do want stable kernels to work with the latest
gcc, so please add the Cc:stable annotation.

      Arnd
  
Miquel Raynal May 23, 2023, 1:43 p.m. UTC | #4
On Mon, 2023-04-17 at 20:56:50 UTC, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> The addition of the mtdchar_read_ioctl() function caused the stack usage
> of mtdchar_ioctl() to grow beyond the warning limit on 32-bit architectures
> with gcc-13:
> 
> drivers/mtd/mtdchar.c: In function 'mtdchar_ioctl':
> drivers/mtd/mtdchar.c:1229:1: error: the frame size of 1488 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
> 
> Mark both the read and write portions as noinline_for_stack to ensure
> they don't get inlined and use separate stack slots to reduce the
> maximum usage, both in the mtdchar_ioctl() and combined with any
> of its callees.
> 
> Fixes: 095bb6e44eb1 ("mtdchar: add MEMREAD ioctl")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Reviewed-by: Richard Weinberger <richard@nod.at>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks.

Miquel
  

Patch

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 01f1c6792df9..8dc4f5c493fc 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -590,8 +590,8 @@  static void adjust_oob_length(struct mtd_info *mtd, uint64_t start,
 			    (end_page - start_page + 1) * oob_per_page);
 }
 
-static int mtdchar_write_ioctl(struct mtd_info *mtd,
-		struct mtd_write_req __user *argp)
+static noinline_for_stack int
+mtdchar_write_ioctl(struct mtd_info *mtd, struct mtd_write_req __user *argp)
 {
 	struct mtd_info *master = mtd_get_master(mtd);
 	struct mtd_write_req req;
@@ -688,8 +688,8 @@  static int mtdchar_write_ioctl(struct mtd_info *mtd,
 	return ret;
 }
 
-static int mtdchar_read_ioctl(struct mtd_info *mtd,
-		struct mtd_read_req __user *argp)
+static noinline_for_stack int
+mtdchar_read_ioctl(struct mtd_info *mtd, struct mtd_read_req __user *argp)
 {
 	struct mtd_info *master = mtd_get_master(mtd);
 	struct mtd_read_req req;