[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iJzuw8_ti4P4tJ_A3Fd0QCjHTBjasbm_J3N8up=gK8Aow@mail.gmail.com>
Date: Fri, 29 Mar 2024 14:21:28 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Dawei Li <dawei.li@...ngroup.cn>
Cc: davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
ioana.ciornei@....com, wintera@...ux.ibm.com, twinkler@...ux.ibm.com,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-s390@...r.kernel.org
Subject: Re: [PATCH net-next 1/2] net/iucv: Avoid explicit cpumask var
allocation on stack
On Fri, Mar 29, 2024 at 11:57 AM Dawei Li <dawei.li@...ngroup.cn> wrote:
>
> For CONFIG_CPUMASK_OFFSTACK=y kernel, explicit allocation of cpumask
> variable on stack is not recommended since it can cause potential stack
> overflow.
>
> Instead, kernel code should always use *cpumask_var API(s) to allocate
> cpumask var in config-neutral way, leaving allocation strategy to
> CONFIG_CPUMASK_OFFSTACK.
>
> Use *cpumask_var API(s) to address it.
>
> Signed-off-by: Dawei Li <dawei.li@...ngroup.cn>
> ---
> net/iucv/iucv.c | 37 ++++++++++++++++++++++++++-----------
> 1 file changed, 26 insertions(+), 11 deletions(-)
>
> diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
> index a4ab615ca3e3..b51f46ec32f9 100644
> --- a/net/iucv/iucv.c
> +++ b/net/iucv/iucv.c
> @@ -520,14 +520,19 @@ static void iucv_setmask_mp(void)
> */
> static void iucv_setmask_up(void)
> {
> - cpumask_t cpumask;
> + cpumask_var_t cpumask;
> int cpu;
>
> + if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
> + return;
This can not be right. iucv_setmask_up() is not supposed to fail.
Since iucv_setmask_up() is only called with iucv_register_mutex held,
you could simply add a 'static' for @cpumask variable.
> +
> /* Disable all cpu but the first in cpu_irq_cpumask. */
> - cpumask_copy(&cpumask, &iucv_irq_cpumask);
> - cpumask_clear_cpu(cpumask_first(&iucv_irq_cpumask), &cpumask);
> - for_each_cpu(cpu, &cpumask)
> + cpumask_copy(cpumask, &iucv_irq_cpumask);
> + cpumask_clear_cpu(cpumask_first(&iucv_irq_cpumask), cpumask);
> + for_each_cpu(cpu, cpumask)
> smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
> +
> + free_cpumask_var(cpumask);
> }
Powered by blists - more mailing lists