RE: [PATCH v2] sched/isolation: Fix illegal CPU value by housekeeping_any_cpu() return

From: Zhang, Qiang1
Date: Thu Feb 16 2023 - 01:08:06 EST


>
> For kernels built with CONFIG_NO_HZ_FULL=y, running the following tests:
>
[...]
> This commit therefore add checks for cpumask_any_and() return values
> in housekeeping_any_cpu(), if cpumask_any_and() returns an illegal CPU
> value, the housekeeping_any_cpu() will return current CPU number.
>
> Signed-off-by: Zqiang <qiang1.zhang@xxxxxxxxx>
> ---
> kernel/sched/isolation.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
> index 373d42c707bc..534397ab7a36 100644
> --- a/kernel/sched/isolation.c
> +++ b/kernel/sched/isolation.c
> @@ -46,7 +46,11 @@ int housekeeping_any_cpu(enum hk_type type)
> if (cpu < nr_cpu_ids)
> return cpu;
>
> - return cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask);
> + cpu = cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask);
> + if (cpu >= nr_cpu_ids)
> + return smp_processor_id();
> + else
> + return cpu;
>
>Nit: no need of "else", simply:
>
>return (cpu >= nr_cpuids ? smp_processor_id() : cpu);

Thanks Joel, I have done the same modification in v3 version, and this change is
also related to a 08ae95f4fd3b, after revert it, this calltrace will disappear.

Thanks
Zqiang


>
>or
>
>if (cpu >= nr_cpu_ids)
> return smp_processor_id();
>return cpu;
>
>Thanks.