Re: [PATCH v4 20/20] sched/core: Add a few check for valid CPU in inc/dec of preferred CPUs

From: Yury Norov

Date: Thu Jun 18 2026 - 00:22:00 EST


On Wed, Jun 17, 2026 at 11:11:39PM +0530, Shrikanth Hegde wrote:
> Add few cpumask_check where cpu is expected to be a a valid one.

This should be embedded in the corresponding patches, no need to make
it a separate patch.

> Signed-off-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
> ---
> v3->v4:
> - new patch.
>
> kernel/sched/core.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 57d52973ef0d..9342aae315ca 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -11417,6 +11417,9 @@ void arch_dec_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio)
>
> last_cpu = cpumask_last(cpu_preferred_mask);
>
> + /* mask can't be null */
> + cpumask_check(last_cpu);

cpumask_check() is disabled by default. If you need to enforce the
code, use WARN_ON().

> +
> /*
> * If the core belongs to the housekeeping CPUs, no action is
> * taken. This leaves at least one core preferred always.
> @@ -11505,6 +11508,9 @@ void sched_trigger_steal_computation(int cpu)
> cpu_active_mask);
> ktime_t now;
>
> + /* at least one housekeeping CPU must be active */
> + cpumask_check(first_hk_cpu);
> +
> /* Done by first active housekeeping CPU only */
> if (likely(cpu != first_hk_cpu))
> return;
> --
> 2.47.3