From: sashiko-bot@kernel.org
To: "Shrikanth Hegde" <sshegde@linux.ibm.com>
Cc: "Eugenio Perez" <eperezma@redhat.com>,
virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v14 08/13] sched/core: Push current task from non preferred CPU
Date: Mon, 28 Sep 2026 05:56:25 +0000 [thread overview]
Message-ID: <20260928055626.2C4681F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928053728.797539-9-sshegde@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] sched/core: FAIR kthreads cause stopper thread livelock on non-preferred CPUs
--
commit a6718dc77694942ae8b63a9eb25ace9c01b3c5ef
Author: Shrikanth Hegde <sshegde@linux.ibm.com>
sched/core: Push current task from non preferred CPU
This patch actively pushes the currently running task off a non-preferred
CPU using a stopper thread, specifically targeting tasks in the FAIR
scheduling class. It adds the npc_push_work_pending flag to avoid queueing
multiple stopper threads.
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
[ ... ]
> +static int sched_non_preferred_cpu_push_stop(void *arg)
> +{
> + struct task_struct *p = arg;
> + struct rq *rq = this_rq();
> + struct rq_flags rf;
> + int cpu;
> +
> + if (cpu_preferred(rq->cpu)) {
> + scoped_guard(rq_lock_irqsave, rq)
> + rq->npc_push_work_pending = false;
> + put_task_struct(p);
> + return 0;
> + }
> +
> + scoped_guard (raw_spinlock_irq, &p->pi_lock) {
> + /*
> + * select_fallback_rq() may acquire the rq lock in case of
> + * fallback. So call it before grabbing rq lock. If the task
> + * migrates to another CPU before the rq lock is acquired,
> + * subsequent validation of task's current rq will help to
> + * safely bail out.
> + */
> + cpu = select_fallback_rq(rq->cpu, p);
[ ... ]
> +void sched_push_current_non_preferred_cpu(struct rq *rq)
> +{
> + struct task_struct *push_task = rq->curr;
> +
> + scoped_guard(rq_lock, rq) {
> + /* Push the task if its explicit affinity allows */
> + if (!task_can_migrate_to_preferred(push_task, rq->cpu))
> + return;
[Severity: High]
Can this result in a livelock with endless stopper thread preemptions when
the task being pushed is a FAIR kthread (such as an unbound kworker)?
When task_can_migrate_to_preferred() returns true for a FAIR kthread,
this function successfully queues a stopper thread. However, when the
stopper thread runs sched_non_preferred_cpu_push_stop() and calls
select_fallback_rq(), it ultimately evaluates is_cpu_allowed(), which
skips the preferred-CPU check for kthreads:
kernel/sched/core.c:is_cpu_allowed() {
...
/* Non kernel threads are not allowed during either online or offline. */
if (!(p->flags & PF_KTHREAD)) {
/* Try to use preferred CPU if task's affinity allows */
if (task_can_migrate_to_preferred(p, cpu))
return false;
return cpu_active(cpu);
}
...
}
Because the kthread bypasses the preferred-CPU enforcement,
select_fallback_rq() can pick the first online CPU in the local node,
which might be the exact same non-preferred CPU we are trying to push it
away from.
If that happens, the migration becomes a no-op, npc_push_work_pending gets
cleared, and sched_tick() will just restart the same sequence on the next
tick, wasting CPU cycles in an endless loop.
> +
> + /* There is already a stopper thread. Don't race with it. */
> + if (rq->npc_push_work_pending)
> + return;
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260928053728.797539-1-sshegde@linux.ibm.com?part=8
next prev parent reply other threads:[~2026-09-28 5:56 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 5:37 [PATCH v14 00/13] sched, steal_governor: Introduce preferred CPUs and steal-driven vCPU backoff Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 01/13] sched/cputime: Add kcpustat_field_total helper Shrikanth Hegde
2026-09-28 5:54 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 02/13] cpumask: Introduce cpumask_intersects_and Shrikanth Hegde
2026-09-28 5:44 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 03/13] sched/docs: Document cpu_preferred_mask and Preferred CPU concept Shrikanth Hegde
2026-09-28 5:42 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 04/13] cpumask: Introduce cpu_preferred_mask Shrikanth Hegde
2026-09-28 5:46 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 05/13] sysfs: Add preferred CPU file Shrikanth Hegde
2026-09-28 5:47 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 06/13] sched/core: Try to use a preferred CPU in is_cpu_allowed Shrikanth Hegde
2026-09-28 6:00 ` sashiko-bot
2026-09-28 6:48 ` Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 07/13] sched/fair: Load balance only among preferred CPUs Shrikanth Hegde
2026-09-28 5:55 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 08/13] sched/core: Push current task from non preferred CPU Shrikanth Hegde
2026-09-28 5:56 ` sashiko-bot [this message]
2026-09-28 5:37 ` [PATCH v14 09/13] sched/debug: Add migration stats due to non preferred CPUs Shrikanth Hegde
2026-09-28 5:48 ` sashiko-bot
2026-09-29 12:18 ` Nathan Chancellor
2026-09-29 12:43 ` Shrikanth Hegde
2026-09-29 14:57 ` Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 10/13] virt: Introduce steal governor driver Shrikanth Hegde
2026-09-28 5:47 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 11/13] virt/steal_governor: Add control knobs for handling steal values Shrikanth Hegde
2026-09-28 5:46 ` sashiko-bot
2026-09-28 5:37 ` [PATCH v14 12/13] virt/steal_governor: Implement steal_governor policy loop Shrikanth Hegde
2026-09-28 5:51 ` sashiko-bot
2026-09-28 6:52 ` Shrikanth Hegde
2026-09-28 5:37 ` [PATCH v14 13/13] virt/steal_governor: Enable the driver Shrikanth Hegde
2026-09-28 5:48 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260928055626.2C4681F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sshegde@linux.ibm.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.