From: Brian Norris <computersforpeace@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: David Woodhouse <dwmw2@infradead.org>,
linux-arm-kernel@lists.infradead.org,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mtd: avoid stack overflow in MTD CFI code
Date: Fri, 4 Mar 2016 13:21:59 -0800 [thread overview]
Message-ID: <20160304212159.GA55664@google.com> (raw)
In-Reply-To: <1456748436-522413-1-git-send-email-arnd@arndb.de>
On Mon, Feb 29, 2016 at 01:20:28PM +0100, Arnd Bergmann wrote:
> When map_word gets too large, we use a lot of kernel stack, and for
> MTD_MAP_BANK_WIDTH_32, this means we use more than the recommended
> 1024 bytes in a number of functions:
>
> drivers/mtd/chips/cfi_cmdset_0020.c: In function 'cfi_staa_write_buffers':
> drivers/mtd/chips/cfi_cmdset_0020.c:651:1: warning: the frame size of 1336 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> drivers/mtd/chips/cfi_cmdset_0020.c: In function 'cfi_staa_erase_varsize':
> drivers/mtd/chips/cfi_cmdset_0020.c:972:1: warning: the frame size of 1208 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> drivers/mtd/chips/cfi_cmdset_0001.c: In function 'do_write_buffer':
> drivers/mtd/chips/cfi_cmdset_0001.c:1835:1: warning: the frame size of 1240 bytes is larger than 1024 bytes [-Wframe-larger-than=]
>
> This can be avoided if all operations on the map word are done
> indirectly and the stack gets reused between the calls. We can
> mostly achieve this by selecting MTD_COMPLEX_MAPPINGS whenever
> MTD_MAP_BANK_WIDTH_32 is set, but for the case that no other
> bank width is enabled, we also need to use a non-constant
> map_bankwidth() to convince the compiler to use less stack.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2: added 'if HAS_IOMEM' to avoid a Kconfig warning on user-mode-linux.
>
> Originally sent out on Jan 1, sorry for taking my time to follow
> up with a new version.
>
> drivers/mtd/chips/Kconfig | 1 +
> include/linux/mtd/map.h | 19 +++++++------------
> 2 files changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
> index 741ec69e0b46..cd162cbc3746 100644
> --- a/drivers/mtd/chips/Kconfig
> +++ b/drivers/mtd/chips/Kconfig
> @@ -117,6 +117,7 @@ config MTD_MAP_BANK_WIDTH_16
>
> config MTD_MAP_BANK_WIDTH_32
> bool "Support 256-bit buswidth" if MTD_CFI_GEOMETRY
> + select MTD_COMPLEX_MAPPINGS if HAS_IOMEM
> default n
> help
> If you wish to support CFI devices on a physical bus which is
> diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
> index 5e0eb7ccabd4..3aa56e3104bb 100644
> --- a/include/linux/mtd/map.h
> +++ b/include/linux/mtd/map.h
> @@ -122,18 +122,13 @@
> #endif
>
> #ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
> -# ifdef map_bankwidth
> -# undef map_bankwidth
> -# define map_bankwidth(map) ((map)->bankwidth)
> -# undef map_bankwidth_is_large
> -# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
> -# undef map_words
> -# define map_words(map) map_calc_words(map)
> -# else
> -# define map_bankwidth(map) 32
> -# define map_bankwidth_is_large(map) (1)
> -# define map_words(map) map_calc_words(map)
> -# endif
> +/* always use indirect access for 256-bit to preserve kernel stack */
> +# undef map_bankwidth
> +# define map_bankwidth(map) ((map)->bankwidth)
> +# undef map_bankwidth_is_large
> +# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
> +# undef map_words
> +# define map_words(map) map_calc_words(map)
> #define map_bankwidth_is_32(map) (map_bankwidth(map) == 32)
> #undef MAX_MAP_BANKWIDTH
> #define MAX_MAP_BANKWIDTH 32
Looking a little closer at this... why do we need the changes to
include/linux/mtd/map.h again? It should be fine to leave these
definitions as-is, right? They don't contribute to the large stack
usage, do they?
Maybe I'm just missing something obvious, so please do enlighten :)
Brian
WARNING: multiple messages have this Message-ID (diff)
From: computersforpeace@gmail.com (Brian Norris)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] mtd: avoid stack overflow in MTD CFI code
Date: Fri, 4 Mar 2016 13:21:59 -0800 [thread overview]
Message-ID: <20160304212159.GA55664@google.com> (raw)
In-Reply-To: <1456748436-522413-1-git-send-email-arnd@arndb.de>
On Mon, Feb 29, 2016 at 01:20:28PM +0100, Arnd Bergmann wrote:
> When map_word gets too large, we use a lot of kernel stack, and for
> MTD_MAP_BANK_WIDTH_32, this means we use more than the recommended
> 1024 bytes in a number of functions:
>
> drivers/mtd/chips/cfi_cmdset_0020.c: In function 'cfi_staa_write_buffers':
> drivers/mtd/chips/cfi_cmdset_0020.c:651:1: warning: the frame size of 1336 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> drivers/mtd/chips/cfi_cmdset_0020.c: In function 'cfi_staa_erase_varsize':
> drivers/mtd/chips/cfi_cmdset_0020.c:972:1: warning: the frame size of 1208 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> drivers/mtd/chips/cfi_cmdset_0001.c: In function 'do_write_buffer':
> drivers/mtd/chips/cfi_cmdset_0001.c:1835:1: warning: the frame size of 1240 bytes is larger than 1024 bytes [-Wframe-larger-than=]
>
> This can be avoided if all operations on the map word are done
> indirectly and the stack gets reused between the calls. We can
> mostly achieve this by selecting MTD_COMPLEX_MAPPINGS whenever
> MTD_MAP_BANK_WIDTH_32 is set, but for the case that no other
> bank width is enabled, we also need to use a non-constant
> map_bankwidth() to convince the compiler to use less stack.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2: added 'if HAS_IOMEM' to avoid a Kconfig warning on user-mode-linux.
>
> Originally sent out on Jan 1, sorry for taking my time to follow
> up with a new version.
>
> drivers/mtd/chips/Kconfig | 1 +
> include/linux/mtd/map.h | 19 +++++++------------
> 2 files changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
> index 741ec69e0b46..cd162cbc3746 100644
> --- a/drivers/mtd/chips/Kconfig
> +++ b/drivers/mtd/chips/Kconfig
> @@ -117,6 +117,7 @@ config MTD_MAP_BANK_WIDTH_16
>
> config MTD_MAP_BANK_WIDTH_32
> bool "Support 256-bit buswidth" if MTD_CFI_GEOMETRY
> + select MTD_COMPLEX_MAPPINGS if HAS_IOMEM
> default n
> help
> If you wish to support CFI devices on a physical bus which is
> diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
> index 5e0eb7ccabd4..3aa56e3104bb 100644
> --- a/include/linux/mtd/map.h
> +++ b/include/linux/mtd/map.h
> @@ -122,18 +122,13 @@
> #endif
>
> #ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
> -# ifdef map_bankwidth
> -# undef map_bankwidth
> -# define map_bankwidth(map) ((map)->bankwidth)
> -# undef map_bankwidth_is_large
> -# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
> -# undef map_words
> -# define map_words(map) map_calc_words(map)
> -# else
> -# define map_bankwidth(map) 32
> -# define map_bankwidth_is_large(map) (1)
> -# define map_words(map) map_calc_words(map)
> -# endif
> +/* always use indirect access for 256-bit to preserve kernel stack */
> +# undef map_bankwidth
> +# define map_bankwidth(map) ((map)->bankwidth)
> +# undef map_bankwidth_is_large
> +# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
> +# undef map_words
> +# define map_words(map) map_calc_words(map)
> #define map_bankwidth_is_32(map) (map_bankwidth(map) == 32)
> #undef MAX_MAP_BANKWIDTH
> #define MAX_MAP_BANKWIDTH 32
Looking a little closer at this... why do we need the changes to
include/linux/mtd/map.h again? It should be fine to leave these
definitions as-is, right? They don't contribute to the large stack
usage, do they?
Maybe I'm just missing something obvious, so please do enlighten :)
Brian
next prev parent reply other threads:[~2016-03-04 21:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 12:20 [PATCH v2] mtd: avoid stack overflow in MTD CFI code Arnd Bergmann
2016-02-29 12:20 ` Arnd Bergmann
2016-03-04 21:21 ` Brian Norris [this message]
2016-03-04 21:21 ` Brian Norris
2016-03-04 23:25 ` Arnd Bergmann
2016-03-04 23:25 ` Arnd Bergmann
2016-03-18 17:44 ` Brian Norris
2016-03-18 17:44 ` Brian Norris
2016-03-18 20:25 ` Arnd Bergmann
2016-03-18 20:25 ` Arnd Bergmann
2016-04-04 6:51 ` Brian Norris
2016-04-04 6:51 ` Brian Norris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160304212159.GA55664@google.com \
--to=computersforpeace@gmail.com \
--cc=arnd@arndb.de \
--cc=dwmw2@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.