mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juri Lelli <juri.lelli@redhat.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: syzbot <syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com>,
	linux-kernel@vger.kernel.org, Thomas Gleixner <tglx@kernel.org>,
	Radu Rendec <radu@rendec.net>, Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>
Subject: Re: [RFC PATCH v2] sched: irq: cpu-hotplug race vs set_cpus_allowed_ptr()
Date: Mon, 12 Oct 2026 16:19:16 +0200	[thread overview]
Message-ID: <aszsZMSo9csAHNJu@jlelli-thinkpadt14gen4.remote.csb> (raw)
In-Reply-To: <20261012103946.aOSAmrRe@linutronix.de>

Hello,

On 12/10/26 12:39, Sebastian Andrzej Siewior wrote:
> syzbot reported a race of assigning a CPU affinity during CPU hotplug
> operation.
> After the affinity of an IRQ has been changed, the IRQ-core sets
> IRQTF_AFFINITY and wakes the relevant interrupt threads which need to
> adjust their affinity mask. The thread will then invoke
> set_cpus_allowed_ptr() to update the mask. Based on the new mask a CPU
> is chosen on which the thread should run.
> 
> It is verified that this CPU is online however there is no guarantee
> that this CPU remains online while affine_move_task() is moving _this_
> task. Since the current task requests the migration the stopper/
> migration_cpu_stop() is involved at which point the task pauses for a
> while. If the CPU goes offline (or is no longer cpu_online_mask) then
> __migrate_task() (due to is_cpu_allowed() reject) will return the rq of
> the CPU on which the task is currently running (which does not match
> it's task_struct::cpus_mask).
> 
> The aftermath:
> The IRQ-thread's CPU and task's cpus_mask do not match. A
> migrate_disable()-> schedule() will change task_struct::cpus_ptr
> ensuring that the following migrate_enable() will update the task to the
> requested affinity mask. At this point, affine_move_task() expects
> task_struct::migration_pending set but it is NULL because no one
> requested an affinity change while the task was in migrate-disable
> section.
> 
> I see two ways of fixing this:
> - Holding the cpus_read_lock while set_cpus_allowed_ptr() is invoked.
>   This ensure that the CPU remains in the cpu_online_mask while the
>   migration task moving the task over. Should the mask be already
>   invalid, then it is rejected otherwise the operation completes.
> 
>   sashiko complains about deadlock of cpus_write_lock() in the CPU down
>   path and calling irq_migrate_all_off_this_cpu() vs
>   irq_thread_check_affinity() doing cpus_read_lock().
>   As far as I see, there is no deadlock because the mask is updated, the
>   tread is woken, the tread blocks with cpus_read_lock() until the CPU is
>   down.
>   There is nothing that waits for the interrupt thread to complete,
>   there is no synchronize_irq() invocation which would be required for
>   the deadlock to happen.

I would agree with your assessment here. Can't see how a deadlock is
possible.

> - Should __migrate_task() fail to return the requested rq make sure its
>   CPU is part task_struct::cpus_mask. This ensures that the current CPU
>   is still part of mask avoiding a possible push by migrate_enable().
>   sched_class::set_cpus_allowed did not see this mask. It might be a bit
>   inconsistent and feels a bit like select_fallback_rq() without the
>   printk.
> 
>   Sashiko complains:
> | If __migrate_task() fails (e.g., due to a concurrent CPU offline event), this
> | fallback code forcibly modifies p->cpus_mask with cpumask_set_cpu(). This
> | skips the required p->sched_class->set_cpus_allowed() callback and fails to
> | update p->nr_cpus_allowed.
> | Can this bypass global EDF real-time invariants for SCHED_DEADLINE (as
> | set_cpus_allowed_dl() is skipped), and allow unprivileged tasks to escape
> | affinity boundaries, giving them access to CPUs outside their cpusets?

And not going via set_cpus_allowed_dl() might indeed create problems.

So, I would vote for option 1.

Thanks,
Juri


  reply	other threads:[~2026-10-12 14:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 10:39 Sebastian Andrzej Siewior
2026-10-12 14:19 ` Juri Lelli [this message]
2026-10-12 14:30 ` Peter Zijlstra

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=aszsZMSo9csAHNJu@jlelli-thinkpadt14gen4.remote.csb \
    --to=juri.lelli@redhat.com \
    --cc=bigeasy@linutronix.de \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.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 \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®