firmware: tegra: reduce stack usage
PATCH RESEND 1/1 firmware: tegra: reduce stack usage
From: Arnd Bergmann <[email protected]>
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.
---
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(-)
drivers/firmware/tegra/bpmp-debugfs.c +11 -5
@@ -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; }
Signature · 1 line
2.29.2
Quoted 14 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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=] staticssize_tbpmp_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")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 6 lines
---
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.
Quoted 22 lines
drivers/firmware/tegra/bpmp-debugfs.c +6
-2@@ -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));
drivers/firmware/tegra/bpmp-debugfs.c static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset) · line 95
Quoted 10 lines
drivers/firmware/tegra/bpmp-debugfs.c +2
-2if (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...
drivers/firmware/tegra/bpmp-debugfs.c static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset) · line 99
Quoted 4 lines
drivers/firmware/tegra/bpmp-debugfs.c +1
-1if (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
Quoted 23 lines · Thierry Reding
Quoted 14 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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=] staticssize_tbpmp_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")Signed-off-by Arnd Bergmann <[email protected]>Quoted 6 lines
---
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(-)
Quoted 6 lines
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.
Quoted 39 lines
Quoted 21 lines
drivers/firmware/tegra/bpmp-debugfs.c +6
-2@@ -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));drivers/firmware/tegra/bpmp-debugfs.c static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset) · line 95
Quoted 10 lines
drivers/firmware/tegra/bpmp-debugfs.c +2
-2if (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...
drivers/firmware/tegra/bpmp-debugfs.c static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset) · line 99
Quoted 4 lines
drivers/firmware/tegra/bpmp-debugfs.c +1
-1if (strlen (filename) < root_len ||strncmp (filename, root_path, root_len)) -return NULL ; + goto out;
Quoted 5 lines
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