All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait()
@ 2026-05-19 19:01 Arnd Bergmann
  2026-05-19 21:52 ` Paul E. McKenney
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Arnd Bergmann @ 2026-05-19 19:01 UTC (permalink / raw)
  To: Paul E. McKenney, Frederic Weisbecker, Neeraj Upadhyay,
	Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki
  Cc: Arnd Bergmann, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Zqiang, Ingo Molnar, Tze-nan Wu, rcu, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

When CONFIG_UBSAN_ALIGNMENT is enabled, the stack usage of nocb_gp_wait()
grows above typical warning limits:

In file included from kernel/rcu/tree.c:4930:
kernel/rcu/tree_nocb.h: In function 'rcu_nocb_gp_kthread':
kernel/rcu/tree_nocb.h:866:1: error: the frame size of 1968 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]

Apparently, the problem is passing rcu_data from a 'void *' pointer,
which gcc assumes may be misaligned. When the function is not inlined
into rcu_nocb_gp_kthread(), that is no longer visible to gcc.

Add a 'noinline_for_stack' annotation that leads to skipping a lot of
the alignment sanitizer checks and keeps the stack usage 60% lower here.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 kernel/rcu/tree_nocb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
index 1047b30cd46b..373b877cf171 100644
--- a/kernel/rcu/tree_nocb.h
+++ b/kernel/rcu/tree_nocb.h
@@ -655,7 +655,7 @@ static void nocb_gp_sleep(struct rcu_data *my_rdp, int cpu)
  * No-CBs GP kthreads come here to wait for additional callbacks to show up
  * or for grace periods to end.
  */
-static void nocb_gp_wait(struct rcu_data *my_rdp)
+static noinline_for_stack void nocb_gp_wait(struct rcu_data *my_rdp)
 {
 	bool bypass = false;
 	int __maybe_unused cpu = my_rdp->cpu;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait()
  2026-05-19 19:01 [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait() Arnd Bergmann
@ 2026-05-19 21:52 ` Paul E. McKenney
  2026-05-20 12:04 ` Frederic Weisbecker
  2026-05-27 12:07 ` Kunwu Chan
  2 siblings, 0 replies; 5+ messages in thread
From: Paul E. McKenney @ 2026-05-19 21:52 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes,
	Josh Triplett, Boqun Feng, Uladzislau Rezki, Arnd Bergmann,
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang,
	Ingo Molnar, Tze-nan Wu, rcu, linux-kernel

On Tue, May 19, 2026 at 09:01:28PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> When CONFIG_UBSAN_ALIGNMENT is enabled, the stack usage of nocb_gp_wait()
> grows above typical warning limits:
> 
> In file included from kernel/rcu/tree.c:4930:
> kernel/rcu/tree_nocb.h: In function 'rcu_nocb_gp_kthread':
> kernel/rcu/tree_nocb.h:866:1: error: the frame size of 1968 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]
> 
> Apparently, the problem is passing rcu_data from a 'void *' pointer,
> which gcc assumes may be misaligned. When the function is not inlined
> into rcu_nocb_gp_kthread(), that is no longer visible to gcc.
> 
> Add a 'noinline_for_stack' annotation that leads to skipping a lot of
> the alignment sanitizer checks and keeps the stack usage 60% lower here.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Paul E. McKenney <paulmck@kernel.org>

> ---
>  kernel/rcu/tree_nocb.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
> index 1047b30cd46b..373b877cf171 100644
> --- a/kernel/rcu/tree_nocb.h
> +++ b/kernel/rcu/tree_nocb.h
> @@ -655,7 +655,7 @@ static void nocb_gp_sleep(struct rcu_data *my_rdp, int cpu)
>   * No-CBs GP kthreads come here to wait for additional callbacks to show up
>   * or for grace periods to end.
>   */
> -static void nocb_gp_wait(struct rcu_data *my_rdp)
> +static noinline_for_stack void nocb_gp_wait(struct rcu_data *my_rdp)
>  {
>  	bool bypass = false;
>  	int __maybe_unused cpu = my_rdp->cpu;
> -- 
> 2.39.5
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait()
  2026-05-19 19:01 [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait() Arnd Bergmann
  2026-05-19 21:52 ` Paul E. McKenney
@ 2026-05-20 12:04 ` Frederic Weisbecker
  2026-05-20 14:02   ` Uladzislau Rezki
  2026-05-27 12:07 ` Kunwu Chan
  2 siblings, 1 reply; 5+ messages in thread
From: Frederic Weisbecker @ 2026-05-20 12:04 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Paul E. McKenney, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
	Boqun Feng, Uladzislau Rezki, Arnd Bergmann, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Zqiang, Ingo Molnar, Tze-nan Wu,
	rcu, linux-kernel

Le Tue, May 19, 2026 at 09:01:28PM +0200, Arnd Bergmann a écrit :
> From: Arnd Bergmann <arnd@arndb.de>
> 
> When CONFIG_UBSAN_ALIGNMENT is enabled, the stack usage of nocb_gp_wait()
> grows above typical warning limits:
> 
> In file included from kernel/rcu/tree.c:4930:
> kernel/rcu/tree_nocb.h: In function 'rcu_nocb_gp_kthread':
> kernel/rcu/tree_nocb.h:866:1: error: the frame size of 1968 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]
> 
> Apparently, the problem is passing rcu_data from a 'void *' pointer,
> which gcc assumes may be misaligned. When the function is not inlined
> into rcu_nocb_gp_kthread(), that is no longer visible to gcc.
> 
> Add a 'noinline_for_stack' annotation that leads to skipping a lot of
> the alignment sanitizer checks and keeps the stack usage 60% lower here.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  kernel/rcu/tree_nocb.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
> index 1047b30cd46b..373b877cf171 100644
> --- a/kernel/rcu/tree_nocb.h
> +++ b/kernel/rcu/tree_nocb.h
> @@ -655,7 +655,7 @@ static void nocb_gp_sleep(struct rcu_data *my_rdp, int cpu)
>   * No-CBs GP kthreads come here to wait for additional callbacks to show up
>   * or for grace periods to end.
>   */
> -static void nocb_gp_wait(struct rcu_data *my_rdp)
> +static noinline_for_stack void nocb_gp_wait(struct rcu_data *my_rdp)

This probably deserve a comment though.

Other than that:

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>


>  {
>  	bool bypass = false;
>  	int __maybe_unused cpu = my_rdp->cpu;
> -- 
> 2.39.5
> 

-- 
Frederic Weisbecker
SUSE Labs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait()
  2026-05-20 12:04 ` Frederic Weisbecker
@ 2026-05-20 14:02   ` Uladzislau Rezki
  0 siblings, 0 replies; 5+ messages in thread
From: Uladzislau Rezki @ 2026-05-20 14:02 UTC (permalink / raw)
  To: Frederic Weisbecker, Arnd Bergmann, Paul E. McKenney
  Cc: Arnd Bergmann, Paul E. McKenney, Neeraj Upadhyay, Joel Fernandes,
	Josh Triplett, Boqun Feng, Uladzislau Rezki, Arnd Bergmann,
	Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang,
	Ingo Molnar, Tze-nan Wu, rcu, linux-kernel

On Wed, May 20, 2026 at 02:04:01PM +0200, Frederic Weisbecker wrote:
> Le Tue, May 19, 2026 at 09:01:28PM +0200, Arnd Bergmann a écrit :
> > From: Arnd Bergmann <arnd@arndb.de>
> > 
> > When CONFIG_UBSAN_ALIGNMENT is enabled, the stack usage of nocb_gp_wait()
> > grows above typical warning limits:
> > 
> > In file included from kernel/rcu/tree.c:4930:
> > kernel/rcu/tree_nocb.h: In function 'rcu_nocb_gp_kthread':
> > kernel/rcu/tree_nocb.h:866:1: error: the frame size of 1968 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]
> > 
> > Apparently, the problem is passing rcu_data from a 'void *' pointer,
> > which gcc assumes may be misaligned. When the function is not inlined
> > into rcu_nocb_gp_kthread(), that is no longer visible to gcc.
> > 
> > Add a 'noinline_for_stack' annotation that leads to skipping a lot of
> > the alignment sanitizer checks and keeps the stack usage 60% lower here.
> > 
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> >  kernel/rcu/tree_nocb.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
> > index 1047b30cd46b..373b877cf171 100644
> > --- a/kernel/rcu/tree_nocb.h
> > +++ b/kernel/rcu/tree_nocb.h
> > @@ -655,7 +655,7 @@ static void nocb_gp_sleep(struct rcu_data *my_rdp, int cpu)
> >   * No-CBs GP kthreads come here to wait for additional callbacks to show up
> >   * or for grace periods to end.
> >   */
> > -static void nocb_gp_wait(struct rcu_data *my_rdp)
> > +static noinline_for_stack void nocb_gp_wait(struct rcu_data *my_rdp)
> 
> This probably deserve a comment though.
> 
> Other than that:
> 
> Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
> 
Took the patch and applied the tag from both!

--
Uladzislau Rezki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait()
  2026-05-19 19:01 [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait() Arnd Bergmann
  2026-05-19 21:52 ` Paul E. McKenney
  2026-05-20 12:04 ` Frederic Weisbecker
@ 2026-05-27 12:07 ` Kunwu Chan
  2 siblings, 0 replies; 5+ messages in thread
From: Kunwu Chan @ 2026-05-27 12:07 UTC (permalink / raw)
  To: Arnd Bergmann, Paul E. McKenney, Frederic Weisbecker,
	Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
	Uladzislau Rezki
  Cc: Arnd Bergmann, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Zqiang, Ingo Molnar, Tze-nan Wu, rcu, linux-kernel

On 5/20/26 03:01, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> When CONFIG_UBSAN_ALIGNMENT is enabled, the stack usage of nocb_gp_wait()
> grows above typical warning limits:
>
> In file included from kernel/rcu/tree.c:4930:
> kernel/rcu/tree_nocb.h: In function 'rcu_nocb_gp_kthread':
> kernel/rcu/tree_nocb.h:866:1: error: the frame size of 1968 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]
>
> Apparently, the problem is passing rcu_data from a 'void *' pointer,
> which gcc assumes may be misaligned. When the function is not inlined
> into rcu_nocb_gp_kthread(), that is no longer visible to gcc.
>
> Add a 'noinline_for_stack' annotation that leads to skipping a lot of
> the alignment sanitizer checks and keeps the stack usage 60% lower here.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  kernel/rcu/tree_nocb.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
> index 1047b30cd46b..373b877cf171 100644
> --- a/kernel/rcu/tree_nocb.h
> +++ b/kernel/rcu/tree_nocb.h
> @@ -655,7 +655,7 @@ static void nocb_gp_sleep(struct rcu_data *my_rdp, int cpu)
>   * No-CBs GP kthreads come here to wait for additional callbacks to show up
>   * or for grace periods to end.
>   */
> -static void nocb_gp_wait(struct rcu_data *my_rdp)
> +static noinline_for_stack void nocb_gp_wait(struct rcu_data *my_rdp)
>  {
>  	bool bypass = false;
>  	int __maybe_unused cpu = my_rdp->cpu;

Reviewed-by: Kunwu Chan <chentao@kylinos.cn>


-- 
Thanx, Kunwu


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-27 12:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 19:01 [PATCH] rcu/nocb: reduce stack usage in nocb_gp_wait() Arnd Bergmann
2026-05-19 21:52 ` Paul E. McKenney
2026-05-20 12:04 ` Frederic Weisbecker
2026-05-20 14:02   ` Uladzislau Rezki
2026-05-27 12:07 ` Kunwu Chan

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.