Skip to content

Commit ddb9fd7

Browse files
arndbbrauner
authored andcommitted
fs/select: rework stack allocation hack for clang
A while ago, we changed the way that select() and poll() preallocate a temporary buffer just under the size of the static warning limit of 1024 bytes, as clang was frequently going slightly above that limit. The warnings have recently returned and I took another look. As it turns out, clang is not actually inherently worse at reserving stack space, it just happens to inline do_select() into core_sys_select(), while gcc never inlines it. Annotate do_select() to never be inlined and in turn remove the special case for the allocation size. This should give the same behavior for both clang and gcc all the time and once more avoids those warnings. Fixes: ad312f9 ("fs/select: avoid clang stack usage warning") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20240216202352.2492798-1-arnd@kernel.org Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Andi Kleen <ak@linux.intel.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent cf12445 commit ddb9fd7

2 files changed

Lines changed: 1 addition & 5 deletions

File tree

fs/select.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static inline void wait_key_set(poll_table *wait, unsigned long in,
476476
wait->_key |= POLLOUT_SET;
477477
}
478478

479-
static int do_select(int n, fd_set_bits *fds, struct timespec64 *end_time)
479+
static noinline_for_stack int do_select(int n, fd_set_bits *fds, struct timespec64 *end_time)
480480
{
481481
ktime_t expire, *to = NULL;
482482
struct poll_wqueues table;

include/linux/poll.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
/* ~832 bytes of stack space used max in sys_select/sys_poll before allocating
1616
additional memory. */
17-
#ifdef __clang__
18-
#define MAX_STACK_ALLOC 768
19-
#else
2017
#define MAX_STACK_ALLOC 832
21-
#endif
2218
#define FRONTEND_STACK_ALLOC 256
2319
#define SELECT_STACK_ALLOC FRONTEND_STACK_ALLOC
2420
#define POLL_STACK_ALLOC FRONTEND_STACK_ALLOC

0 commit comments

Comments
 (0)