All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Zhen Wang <zhen.wang1@unisoc.com>
Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com, kprateek.nayak@amd.com, bristot@redhat.com,
	tglx@kernel.org, radu@rendec.net,
	syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com,
	linux-kernel@vger.kernel.org, Xuewen.Yan@unisoc.com,
	Hao_hao.Wang@unisoc.com, Ke.Wang@unisoc.com
Subject: Re: [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop()
Date: Thu, 3 Dec 2026 13:05:48 +0100	[thread overview]
Message-ID: <20261203120548.B3Sd2Vns@linutronix.de> (raw)
In-Reply-To: <20261203112514.686980-1-zhen.wang1@unisoc.com>

On 2026-12-03 19:25:14 [+0800], Zhen Wang wrote:
> On Thu, Nov 26, 2026 at 11:40:49AM +0100, Peter Zijlstra wrote:
> > Fun though; if we did hit this condition then
> > migrate_enable() would have silently failed. Also not a good thing.
> >
> > We should probably have ___migrate_enable() warn on this.
> 
> We hit exactly this condition in testing.  The difference from the
> syzbot trace: the CPU stays offline, so the task's cpus_mask contains
> no online CPU at all, and we *do* take the -EINVAL exit even with the
> migration_disabled() mitigation switching to cpu_online_mask.
> 
> Two extra consequences we see, beyond the silently ignored affinity:
> 
>  - __migrate_enable() only calls ___migrate_enable() when
>    p->cpus_ptr != &p->cpus_mask.  With a stale cpus_ptr that branch is
>    taken on every enable: each later migrate_enable() re-enters
>    __set_cpus_allowed_ptr(), re-takes task_rq_lock() and fails again.
>    A healthy task returns early without taking any lock.

Yeah.

> 
>  - That breaks migrate_enable() in constrained contexts.  We see it

what is a constrained context?

>    from a BPF program attached to trace_sched_switch that calls
>    migrate_enable(): the call takes task_rq_lock() on the runqueue
>    __schedule() already holds and deadlocks.  With an intact cpus_ptr
>    the enable takes no lock, so the same program is fine.

So the migrate_enable() didn't succeed in restoring the mask and the
balanced migrate_enable() with the scheduler does it again. And the BPF
code does migrate_en/dis so…

…
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3245,6 +3245,8 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
>          */
>         dest_cpu = cpumask_any_and_distribute(cpu_valid_mask, ctx->new_mask);
>         if (dest_cpu >= nr_cpu_ids) {
> +               if (ctx->flags & SCA_MIGRATE_ENABLE)
> +                       p->cpus_ptr = ctx->new_mask;
>                 ret = -EINVAL;
>                 goto out;
>         }

This does not make it right, it just avoids the problem on enabled. The
mask still does not match the CPU it runs on. do_set_cpus_allowed() was
not yet invoked yet so that is nice.
Do you see the printk where select_fallback_rq() fixes the mask?

Sebastian

      reply	other threads:[~2026-12-03 12:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 17:16 [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop() Sebastian Andrzej Siewior
2026-11-21 13:20 ` Karl Mehltretter
2026-11-21 14:39 ` Karl Mehltretter
2026-11-25 17:20 ` Peter Zijlstra
2026-11-25 19:37   ` Sebastian Andrzej Siewior
2026-11-26 10:40     ` Peter Zijlstra
2026-11-28 17:24       ` Karl Mehltretter
2026-12-02 14:26         ` Sebastian Andrzej Siewior
2026-12-02 14:42         ` Peter Zijlstra
2026-12-03  1:50           ` Karl Mehltretter
2026-12-03 13:05             ` Peter Zijlstra
2026-12-03 14:19               ` Sebastian Andrzej Siewior
2026-12-03 14:33                 ` Peter Zijlstra
2026-12-03 15:37                   ` Peter Zijlstra
2026-12-03 17:42                     ` Sebastian Andrzej Siewior
2026-12-04 11:04                       ` Peter Zijlstra
2026-12-04  1:44               ` Karl Mehltretter
2026-12-04 12:44                 ` Peter Zijlstra
2026-12-05  3:50                   ` Karl Mehltretter
2026-12-02 14:12       ` Sebastian Andrzej Siewior
2026-12-03 11:25 ` Zhen Wang
2026-12-03 12:05   ` Sebastian Andrzej Siewior [this message]

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=20261203120548.B3Sd2Vns@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=Hao_hao.Wang@unisoc.com \
    --cc=Ke.Wang@unisoc.com \
    --cc=Xuewen.Yan@unisoc.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=radu@rendec.net \
    --cc=rostedt@goodmis.org \
    --cc=syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com \
    --cc=tglx@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=zhen.wang1@unisoc.com \
    /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.