From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Nathan Chancellor <natechancellor@gmail.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>,
Arnd Bergmann <arnd@arndb.de>,
clang-built-linux@googlegroups.com,
Richard Weinberger <richard@nod.at>,
linux-kernel@vger.kernel.org,
Richard Fontana <rfontana@redhat.com>,
linux-mtd@lists.infradead.org,
Vincenzo Aliberti <vincenzo.aliberti@gmail.com>,
Brian Norris <computersforpeace@gmail.com>
Subject: Re: [PATCH] mtd: lpddr: fix excessive stack usage with clang
Date: Thu, 7 May 2020 12:21:10 +0200 [thread overview]
Message-ID: <20200507122110.50ccce48@xps13> (raw)
In-Reply-To: <20200506023828.GA415100@ubuntu-s3-xlarge-x86>
Nathan Chancellor <natechancellor@gmail.com> wrote on Tue, 5 May 2020
19:38:28 -0700:
> On Tue, May 05, 2020 at 04:01:16PM +0200, Arnd Bergmann wrote:
> > Building lpddr2_nvm with clang can result in a giant stack usage
> > in one function:
> >
> > drivers/mtd/lpddr/lpddr2_nvm.c:399:12: error: stack frame size of 1144 bytes in function 'lpddr2_nvm_probe' [-Werror,-Wframe-larger-than=]
> >
> > The problem is that clang decides to build a copy of the mtd_info
> > structure on the stack and then do a memcpy() into the actual version. It
> > shouldn't really do it that way, but it's not strictly a bug either.
> >
> > As a workaround, use a static const version of the structure to assign
> > most of the members upfront and then only set the few members that
> > require runtime knowledge at probe time.
> >
> > Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
>
> > ---
> > drivers/mtd/lpddr/lpddr2_nvm.c | 35 ++++++++++++++++++----------------
> > 1 file changed, 19 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c
> > index 0f1547f09d08..72f5c7b30079 100644
> > --- a/drivers/mtd/lpddr/lpddr2_nvm.c
> > +++ b/drivers/mtd/lpddr/lpddr2_nvm.c
> > @@ -393,6 +393,17 @@ static int lpddr2_nvm_lock(struct mtd_info *mtd, loff_t start_add,
> > return lpddr2_nvm_do_block_op(mtd, start_add, len, LPDDR2_NVM_LOCK);
> > }
> >
> > +static const struct mtd_info lpddr2_nvm_mtd_info = {
> > + .type = MTD_RAM,
> > + .writesize = 1,
> > + .flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK),
> > + ._read = lpddr2_nvm_read,
> > + ._write = lpddr2_nvm_write,
> > + ._erase = lpddr2_nvm_erase,
> > + ._unlock = lpddr2_nvm_unlock,
> > + ._lock = lpddr2_nvm_lock,
> > +};
> > +
> > /*
> > * lpddr2_nvm driver probe method
> > */
> > @@ -433,6 +444,7 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
> > .pfow_base = OW_BASE_ADDRESS,
> > .fldrv_priv = pcm_data,
> > };
> > +
> > if (IS_ERR(map->virt))
> > return PTR_ERR(map->virt);
> >
> > @@ -444,22 +456,13 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
> > return PTR_ERR(pcm_data->ctl_regs);
> >
> > /* Populate mtd_info data structure */
> > - *mtd = (struct mtd_info) {
> > - .dev = { .parent = &pdev->dev },
> > - .name = pdev->dev.init_name,
> > - .type = MTD_RAM,
> > - .priv = map,
> > - .size = resource_size(add_range),
> > - .erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width,
> > - .writesize = 1,
> > - .writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width,
> > - .flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK),
> > - ._read = lpddr2_nvm_read,
> > - ._write = lpddr2_nvm_write,
> > - ._erase = lpddr2_nvm_erase,
> > - ._unlock = lpddr2_nvm_unlock,
> > - ._lock = lpddr2_nvm_lock,
> > - };
> > + *mtd = lpddr2_nvm_mtd_info;
> > + mtd->dev.parent = &pdev->dev;
> > + mtd->name = pdev->dev.init_name;
> > + mtd->priv = map;
> > + mtd->size = resource_size(add_range);
> > + mtd->erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width;
> > + mtd->writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width;
> >
> > /* Verify the presence of the device looking for PFOW string */
> > if (!lpddr2_nvm_pfow_present(map)) {
> > --
> > 2.26.0
> >
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Nathan Chancellor <natechancellor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Vincenzo Aliberti <vincenzo.aliberti@gmail.com>,
Brian Norris <computersforpeace@gmail.com>,
Richard Fontana <rfontana@redhat.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
clang-built-linux@googlegroups.com
Subject: Re: [PATCH] mtd: lpddr: fix excessive stack usage with clang
Date: Thu, 7 May 2020 12:21:10 +0200 [thread overview]
Message-ID: <20200507122110.50ccce48@xps13> (raw)
In-Reply-To: <20200506023828.GA415100@ubuntu-s3-xlarge-x86>
Nathan Chancellor <natechancellor@gmail.com> wrote on Tue, 5 May 2020
19:38:28 -0700:
> On Tue, May 05, 2020 at 04:01:16PM +0200, Arnd Bergmann wrote:
> > Building lpddr2_nvm with clang can result in a giant stack usage
> > in one function:
> >
> > drivers/mtd/lpddr/lpddr2_nvm.c:399:12: error: stack frame size of 1144 bytes in function 'lpddr2_nvm_probe' [-Werror,-Wframe-larger-than=]
> >
> > The problem is that clang decides to build a copy of the mtd_info
> > structure on the stack and then do a memcpy() into the actual version. It
> > shouldn't really do it that way, but it's not strictly a bug either.
> >
> > As a workaround, use a static const version of the structure to assign
> > most of the members upfront and then only set the few members that
> > require runtime knowledge at probe time.
> >
> > Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
>
> > ---
> > drivers/mtd/lpddr/lpddr2_nvm.c | 35 ++++++++++++++++++----------------
> > 1 file changed, 19 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c
> > index 0f1547f09d08..72f5c7b30079 100644
> > --- a/drivers/mtd/lpddr/lpddr2_nvm.c
> > +++ b/drivers/mtd/lpddr/lpddr2_nvm.c
> > @@ -393,6 +393,17 @@ static int lpddr2_nvm_lock(struct mtd_info *mtd, loff_t start_add,
> > return lpddr2_nvm_do_block_op(mtd, start_add, len, LPDDR2_NVM_LOCK);
> > }
> >
> > +static const struct mtd_info lpddr2_nvm_mtd_info = {
> > + .type = MTD_RAM,
> > + .writesize = 1,
> > + .flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK),
> > + ._read = lpddr2_nvm_read,
> > + ._write = lpddr2_nvm_write,
> > + ._erase = lpddr2_nvm_erase,
> > + ._unlock = lpddr2_nvm_unlock,
> > + ._lock = lpddr2_nvm_lock,
> > +};
> > +
> > /*
> > * lpddr2_nvm driver probe method
> > */
> > @@ -433,6 +444,7 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
> > .pfow_base = OW_BASE_ADDRESS,
> > .fldrv_priv = pcm_data,
> > };
> > +
> > if (IS_ERR(map->virt))
> > return PTR_ERR(map->virt);
> >
> > @@ -444,22 +456,13 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
> > return PTR_ERR(pcm_data->ctl_regs);
> >
> > /* Populate mtd_info data structure */
> > - *mtd = (struct mtd_info) {
> > - .dev = { .parent = &pdev->dev },
> > - .name = pdev->dev.init_name,
> > - .type = MTD_RAM,
> > - .priv = map,
> > - .size = resource_size(add_range),
> > - .erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width,
> > - .writesize = 1,
> > - .writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width,
> > - .flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK),
> > - ._read = lpddr2_nvm_read,
> > - ._write = lpddr2_nvm_write,
> > - ._erase = lpddr2_nvm_erase,
> > - ._unlock = lpddr2_nvm_unlock,
> > - ._lock = lpddr2_nvm_lock,
> > - };
> > + *mtd = lpddr2_nvm_mtd_info;
> > + mtd->dev.parent = &pdev->dev;
> > + mtd->name = pdev->dev.init_name;
> > + mtd->priv = map;
> > + mtd->size = resource_size(add_range);
> > + mtd->erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width;
> > + mtd->writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width;
> >
> > /* Verify the presence of the device looking for PFOW string */
> > if (!lpddr2_nvm_pfow_present(map)) {
> > --
> > 2.26.0
> >
next prev parent reply other threads:[~2020-05-07 10:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 14:01 [PATCH] mtd: lpddr: fix excessive stack usage with clang Arnd Bergmann
2020-05-05 14:01 ` Arnd Bergmann
2020-05-06 2:38 ` Nathan Chancellor
2020-05-06 2:38 ` Nathan Chancellor
2020-05-07 10:21 ` Miquel Raynal [this message]
2020-05-07 10:21 ` Miquel Raynal
2020-09-07 7:34 ` Miquel Raynal
2020-09-07 7:34 ` Miquel Raynal
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=20200507122110.50ccce48@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=arnd@arndb.de \
--cc=clang-built-linux@googlegroups.com \
--cc=computersforpeace@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=natechancellor@gmail.com \
--cc=rfontana@redhat.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=vincenzo.aliberti@gmail.com \
/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.