Re: [PATCH] RDMA/mlx5: reduce stack usage in mlx5_ib_ufile_hw_cleanup

From: Leon Romanovsky
Date: Thu Jun 12 2025 - 05:17:20 EST


On Tue, Jun 10, 2025 at 11:28:42AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> This function has an array of eight mlx5_async_cmd structures, which
> often fits on the stack, but depending on the configuration can
> end up blowing the stack frame warning limit:
>
> drivers/infiniband/hw/mlx5/devx.c:2670:6: error: stack frame size (1392) exceeds limit (1280) in 'mlx5_ib_ufile_hw_cleanup' [-Werror,-Wframe-larger-than]
>
> Change this to a dynamic allocation instead. While a kmalloc()
> can theoretically fail, a GFP_KERNEL allocation under a page will
> block until memory has been freed up, so in the worst case, this
> only adds extra time in an already constrained environment.
>
> Fixes: 7c891a4dbcc1 ("RDMA/mlx5: Add implementation for ufile_hw_cleanup device operation")
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> drivers/infiniband/hw/mlx5/devx.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)

<...>

> + async_cmd = kcalloc(MAX_ASYNC_CMDS, sizeof(*async_cmd), GFP_KERNEL);
> + if (WARN_ON(!async_cmd))
> + return;

Patrisious,

I took this patch for now (without WARN_ON) as it fixes Arnd's issue.
We can provide followup patch if kcalloc() implementation hurts us.

Thanks