linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: viro@zeniv.linux.org.uk, brauner@kernel.org,
	linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>
Subject: [PATCH 1/2] fs: select: reduce stack usage in do_select()
Date: Sun, 16 Jul 2023 09:07:13 +0800	[thread overview]
Message-ID: <20230716010714.3009192-1-chao@kernel.org> (raw)

struct poll_wqueues table caused the stack usage of do_select() to
grow beyond the warning limit on 32-bit architectures w/ gcc.

fs/select.c: In function ‘do_select’:
fs/select.c:615:1: warning: the frame size of 1152 bytes is larger than 1024 bytes [-Wframe-larger-than=]

Allocating dynamic memory in do_select() to fix this issue.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/select.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/fs/select.c b/fs/select.c
index 0ee55af1a55c..1b729494b4e9 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -479,23 +479,29 @@ static inline void wait_key_set(poll_table *wait, unsigned long in,
 static int do_select(int n, fd_set_bits *fds, struct timespec64 *end_time)
 {
 	ktime_t expire, *to = NULL;
-	struct poll_wqueues table;
+	struct poll_wqueues *table;
 	poll_table *wait;
 	int retval, i, timed_out = 0;
 	u64 slack = 0;
 	__poll_t busy_flag = net_busy_loop_on() ? POLL_BUSY_LOOP : 0;
 	unsigned long busy_start = 0;
 
+	table = kmalloc(sizeof(struct poll_wqueues), GFP_KERNEL);
+	if (!table)
+		return -ENOMEM;
+
 	rcu_read_lock();
 	retval = max_select_fd(n, fds);
 	rcu_read_unlock();
 
-	if (retval < 0)
+	if (retval < 0) {
+		kfree(table);
 		return retval;
+	}
 	n = retval;
 
-	poll_initwait(&table);
-	wait = &table.pt;
+	poll_initwait(table);
+	wait = &table->pt;
 	if (end_time && !end_time->tv_sec && !end_time->tv_nsec) {
 		wait->_qproc = NULL;
 		timed_out = 1;
@@ -578,8 +584,8 @@ static int do_select(int n, fd_set_bits *fds, struct timespec64 *end_time)
 		wait->_qproc = NULL;
 		if (retval || timed_out || signal_pending(current))
 			break;
-		if (table.error) {
-			retval = table.error;
+		if (table->error) {
+			retval = table->error;
 			break;
 		}
 
@@ -604,12 +610,14 @@ static int do_select(int n, fd_set_bits *fds, struct timespec64 *end_time)
 			to = &expire;
 		}
 
-		if (!poll_schedule_timeout(&table, TASK_INTERRUPTIBLE,
+		if (!poll_schedule_timeout(table, TASK_INTERRUPTIBLE,
 					   to, slack))
 			timed_out = 1;
 	}
 
-	poll_freewait(&table);
+	poll_freewait(table);
+
+	kfree(table);
 
 	return retval;
 }
-- 
2.40.1


             reply	other threads:[~2023-07-16  1:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-16  1:07 Chao Yu [this message]
2023-07-16  1:07 ` [PATCH 2/2] fs: select: reduce stack usage in do_sys_poll() Chao Yu
2023-07-16  1:49   ` Matthew Wilcox

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=20230716010714.3009192-1-chao@kernel.org \
    --to=chao@kernel.org \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).