* [PATCH] [RESEND] firmware: tegra: reduce stack usage
@ 2021-09-27 12:41 Arnd Bergmann
2021-10-07 18:11 ` Thierry Reding
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2021-09-27 12:41 UTC (permalink / raw)
To: Thierry Reding, Jonathan Hunter; +Cc: Arnd Bergmann, linux-tegra, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
Building the bpmp-debugfs driver for Arm results in a warning for stack usage:
drivers/firmware/tegra/bpmp-debugfs.c:321:16: error: stack frame size of 1224 bytes in function 'bpmp_debug_store' [-Werror,-Wframe-larger-than=]
static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
It should be possible to rearrange the code to not require two separate
buffers for the file name, but the easiest workaround is to use dynamic
allocation.
Fixes: 5e37b9c137ee ("firmware: tegra: Add support for in-band debug")
Link: https://lore.kernel.org/all/20201204193714.3134651-1-arnd@kernel.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I sent this one in 2020 but got no reply. It still appears to be
required, please have a look.
---
drivers/firmware/tegra/bpmp-debugfs.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
index 3e9fa4b54358..f6888cee83ee 100644
--- a/drivers/firmware/tegra/bpmp-debugfs.c
+++ b/drivers/firmware/tegra/bpmp-debugfs.c
@@ -74,28 +74,34 @@ static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset)
static const char *get_filename(struct tegra_bpmp *bpmp,
const struct file *file, char *buf, int size)
{
- char root_path_buf[512];
+ char *root_path_buf;
const char *root_path;
- const char *filename;
+ const char *filename = NULL;
size_t root_len;
+ root_path_buf = kzalloc(512, GFP_KERNEL);
+ if (!root_path_buf)
+ goto out;
+
root_path = dentry_path(bpmp->debugfs_mirror, root_path_buf,
sizeof(root_path_buf));
if (IS_ERR(root_path))
- return NULL;
+ goto out;
root_len = strlen(root_path);
filename = dentry_path(file->f_path.dentry, buf, size);
if (IS_ERR(filename))
- return NULL;
+ goto out;
if (strlen(filename) < root_len ||
strncmp(filename, root_path, root_len))
- return NULL;
+ goto out;
filename += root_len;
+out:
+ kfree(root_path_buf);
return filename;
}
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] [RESEND] firmware: tegra: reduce stack usage
2021-09-27 12:41 [PATCH] [RESEND] firmware: tegra: reduce stack usage Arnd Bergmann
@ 2021-10-07 18:11 ` Thierry Reding
2021-10-08 14:43 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Thierry Reding @ 2021-10-07 18:11 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Jonathan Hunter, Arnd Bergmann, linux-tegra, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2721 bytes --]
On Mon, Sep 27, 2021 at 02:41:40PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Building the bpmp-debugfs driver for Arm results in a warning for stack usage:
>
> drivers/firmware/tegra/bpmp-debugfs.c:321:16: error: stack frame size of 1224 bytes in function 'bpmp_debug_store' [-Werror,-Wframe-larger-than=]
> static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
>
> It should be possible to rearrange the code to not require two separate
> buffers for the file name, but the easiest workaround is to use dynamic
> allocation.
>
> Fixes: 5e37b9c137ee ("firmware: tegra: Add support for in-band debug")
> Link: https://lore.kernel.org/all/20201204193714.3134651-1-arnd@kernel.org/
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> I sent this one in 2020 but got no reply. It still appears to be
> required, please have a look.
> ---
> drivers/firmware/tegra/bpmp-debugfs.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
If this is not a problem on 64-bit ARM, then perhaps we should add that
as a dependency. BPMP is only available in Tegra210 and later, all of
which are 64-bit.
But dynamic allocation also doesn't sound that bad. This is debugfs
support, after all, so shouldn't be in any fast path.
>
> diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
> index 3e9fa4b54358..f6888cee83ee 100644
> --- a/drivers/firmware/tegra/bpmp-debugfs.c
> +++ b/drivers/firmware/tegra/bpmp-debugfs.c
> @@ -74,28 +74,34 @@ static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset)
> static const char *get_filename(struct tegra_bpmp *bpmp,
> const struct file *file, char *buf, int size)
> {
> - char root_path_buf[512];
> + char *root_path_buf;
> const char *root_path;
> - const char *filename;
> + const char *filename = NULL;
> size_t root_len;
>
> + root_path_buf = kzalloc(512, GFP_KERNEL);
> + if (!root_path_buf)
> + goto out;
> +
> root_path = dentry_path(bpmp->debugfs_mirror, root_path_buf,
> sizeof(root_path_buf));
> if (IS_ERR(root_path))
> - return NULL;
> + goto out;
>
> root_len = strlen(root_path);
>
> filename = dentry_path(file->f_path.dentry, buf, size);
> if (IS_ERR(filename))
> - return NULL;
> + goto out;
Shouldn't this and...
> if (strlen(filename) < root_len ||
> strncmp(filename, root_path, root_len))
> - return NULL;
> + goto out;
this reset filename to NULL? All callers check for !filename as their
error condition.
I can fix that up as I apply this, but perhaps shout if you did this on
purpose and it needs to stay this way.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [RESEND] firmware: tegra: reduce stack usage
2021-10-07 18:11 ` Thierry Reding
@ 2021-10-08 14:43 ` Arnd Bergmann
0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2021-10-08 14:43 UTC (permalink / raw)
To: Thierry Reding
Cc: Jonathan Hunter, Arnd Bergmann,
open list:TEGRA ARCHITECTURE SUPPORT, Linux Kernel Mailing List
On Thu, Oct 7, 2021 at 8:11 PM Thierry Reding <thierry.reding@gmail.com> wrote:
>
> On Mon, Sep 27, 2021 at 02:41:40PM +0200, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > Building the bpmp-debugfs driver for Arm results in a warning for stack usage:
> >
> > drivers/firmware/tegra/bpmp-debugfs.c:321:16: error: stack frame size of 1224 bytes in function 'bpmp_debug_store' [-Werror,-Wframe-larger-than=]
> > static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
> >
> > It should be possible to rearrange the code to not require two separate
> > buffers for the file name, but the easiest workaround is to use dynamic
> > allocation.
> >
> > Fixes: 5e37b9c137ee ("firmware: tegra: Add support for in-band debug")
> > Link: https://lore.kernel.org/all/20201204193714.3134651-1-arnd@kernel.org/
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> > I sent this one in 2020 but got no reply. It still appears to be
> > required, please have a look.
> > ---
> > drivers/firmware/tegra/bpmp-debugfs.c | 16 +++++++++++-----
> > 1 file changed, 11 insertions(+), 5 deletions(-)
>
> If this is not a problem on 64-bit ARM, then perhaps we should add that
> as a dependency. BPMP is only available in Tegra210 and later, all of
> which are 64-bit.
>
> But dynamic allocation also doesn't sound that bad. This is debugfs
> support, after all, so shouldn't be in any fast path.
Right, it stays below the warning threshold on 64-bit kernels, but using this
much stack is still a bad idea, so fixing it in the driver seems better than
hiding it in Kconfig.
> > diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
> > index 3e9fa4b54358..f6888cee83ee 100644
> > --- a/drivers/firmware/tegra/bpmp-debugfs.c
> > +++ b/drivers/firmware/tegra/bpmp-debugfs.c
> > @@ -74,28 +74,34 @@ static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset)
> > static const char *get_filename(struct tegra_bpmp *bpmp,
> > const struct file *file, char *buf, int size)
> > {
> > - char root_path_buf[512];
> > + char *root_path_buf;
> > const char *root_path;
> > - const char *filename;
> > + const char *filename = NULL;
> > size_t root_len;
> >
> > + root_path_buf = kzalloc(512, GFP_KERNEL);
> > + if (!root_path_buf)
> > + goto out;
> > +
> > root_path = dentry_path(bpmp->debugfs_mirror, root_path_buf,
> > sizeof(root_path_buf));
> > if (IS_ERR(root_path))
> > - return NULL;
> > + goto out;
> >
> > root_len = strlen(root_path);
> >
> > filename = dentry_path(file->f_path.dentry, buf, size);
> > if (IS_ERR(filename))
> > - return NULL;
> > + goto out;
>
> Shouldn't this and...
>
> > if (strlen(filename) < root_len ||
> > strncmp(filename, root_path, root_len))
> > - return NULL;
> > + goto out;
>
> this reset filename to NULL? All callers check for !filename as their
> error condition.
>
> I can fix that up as I apply this, but perhaps shout if you did this on
> purpose and it needs to stay this way.
Indeed, you are absolutely correct. Thanks for finding the bug
and offering to fix it.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-08 14:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 12:41 [PATCH] [RESEND] firmware: tegra: reduce stack usage Arnd Bergmann
2021-10-07 18:11 ` Thierry Reding
2021-10-08 14:43 ` Arnd Bergmann
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.