mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [syzbot] [kernel?] WARNING in __set_cpus_allowed_ptr_locked
@ 2026-09-03  6:54 syzbot
  2026-09-07  8:58 ` [RFC PATCH] sched: irq: cpu-hotplug race vs set_cpus_allowed_ptr() Sebastian Andrzej Siewior
  0 siblings, 1 reply; 2+ messages in thread
From: syzbot @ 2026-09-03  6:54 UTC (permalink / raw)
  To: linux-kernel, radu, syzkaller-bugs, tglx

Hello,

syzbot found the following issue on:

HEAD commit:    08dbfad3f504 Merge tag 'for-linus' of git://git.kernel.org..
git tree:       upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=14970349580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=b454dc6b1b7acd30
dashboard link: https://syzkaller.appspot.com/bug?extid=6835d5c11145e4f77057
compiler:       Debian clang version 22.1.8 (++20260613092233+e80beda6e255-1~exp1~20260613092250.77), Debian LLD 22.1.8
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=13221e25580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17221e25580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/8aa9167f616f/disk-08dbfad3.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/9ec932d59de3/vmlinux-08dbfad3.xz
kernel image: https://storage.googleapis.com/syzbot-assets/86e2243e886e/bzImage-08dbfad3.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com

------------[ cut here ]------------
!pending
WARNING: kernel/sched/core.c:3057 at affine_move_task kernel/sched/core.c:3057 [inline], CPU#0: irq/33-virtio1-/1195
WARNING: kernel/sched/core.c:3057 at __set_cpus_allowed_ptr_locked+0x10ff/0x19c0 kernel/sched/core.c:3190, CPU#0: irq/33-virtio1-/1195
Modules linked in:
CPU: 0 UID: 0 PID: 1195 Comm: irq/33-virtio1- Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
RIP: 0010:affine_move_task kernel/sched/core.c:3057 [inline]
RIP: 0010:__set_cpus_allowed_ptr_locked+0x10ff/0x19c0 kernel/sched/core.c:3190
Code: cf ff ff 48 8b 5c 24 18 48 8d 7b 08 e8 9a 93 09 00 e9 2e fe ff ff 90 0f 0b 90 e9 74 f3 ff ff e8 b7 ee 9d ff e9 dd f8 ff ff 90 <0f> 0b 90 48 8b 3c 24 48 8b 74 24 08 48 8b 54 24 10 e8 2b cf ff ff
RSP: 0018:ffffc9000681f900 EFLAGS: 00010046
RAX: 0000000000000000 RBX: ffff8880267a84b8 RCX: ffffffff81950a2b
RDX: dffffc0000000000 RSI: 0000000000000008 RDI: ffff8880267a84b0
RBP: ffffc9000681fb10 R08: ffff8880267a84b7 R09: 1ffff11004cf5096
R10: dffffc0000000000 R11: ffffed1004cf5097 R12: 1ffff11004cf5097
R13: 1ffff92000d03f28 R14: ffff8880267a84b0 R15: 0000000000000004
FS:  0000000000000000(0000) GS:ffff888125bd6000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000555581c3f6d0 CR3: 0000000043f1e000 CR4: 00000000003526f0
Call Trace:
 <TASK>
 __set_cpus_allowed_ptr kernel/sched/core.c:3222 [inline]
 ___migrate_enable+0x19c/0x1f0 kernel/sched/core.c:2486
 __migrate_enable include/linux/sched.h:2471 [inline]
 migrate_enable include/linux/sched.h:2520 [inline]
 __local_bh_enable+0x21c/0x2f0 kernel/softirq.c:273
 __local_bh_enable_ip+0x19f/0x2b0 kernel/softirq.c:328
 local_bh_enable include/linux/bottom_half.h:33 [inline]
 irq_forced_thread_fn+0xe9/0x120 kernel/irq/manage.c:1169
 irq_thread+0x455/0x690 kernel/irq/manage.c:1272
 kthread+0x38b/0x470 kernel/kthread.c:436
 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [RFC PATCH] sched: irq: cpu-hotplug race vs set_cpus_allowed_ptr()
  2026-09-03  6:54 [syzbot] [kernel?] WARNING in __set_cpus_allowed_ptr_locked syzbot
@ 2026-09-07  8:58 ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-09-07  8:58 UTC (permalink / raw)
  To: syzbot, linux-kernel
  Cc: syzkaller-bugs, Thomas Gleixner, Radu Rendec, Ingo Molnar,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak

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 noone
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 operaton completes.
  Maybe we should also check if cpus_read_lock is held during the
  invocation of set_cpus_allowed_ptr() so we don't get this problem from
  other callers.

- 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.

Both changes are implemented to illustrate, one is enough.
I can reproduce this back on v6.8, therefore I assume we have this since
day #1 of migrate-disable.

Reported-by: syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6a9919ac.94649fcc.25487e.0005.GAE@google.com/
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/irq/manage.c | 6 ++++--
 kernel/sched/core.c | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 57eff26fa646a..75b6798c1d97c 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) "genirq: " fmt
 
+#include <linux/cpuhplock.h>
 #include <linux/irq.h>
 #include <linux/kthread.h>
 #include <linux/module.h>
@@ -1044,8 +1045,9 @@ static void irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *a
 		m = irq_data_get_effective_affinity_mask(&desc->irq_data);
 		cpumask_copy(mask, m);
 	}
-
-	set_cpus_allowed_ptr(current, mask);
+	scoped_guard(cpus_read_lock) {
+		set_cpus_allowed_ptr(current, mask);
+	}
 	free_cpumask_var(mask);
 }
 #else
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b998ef6b87af4..b090a374fa728 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2674,6 +2674,8 @@ static int migration_cpu_stop(void *data)
 		if (task_on_rq_queued(p)) {
 			update_rq_clock(rq);
 			rq = __migrate_task(rq, &rf, p, arg->dest_cpu);
+			if (rq != cpu_rq(arg->dest_cpu))
+				cpumask_set_cpu(rq->cpu, &p->cpus_mask);
 		} else {
 			p->wake_cpu = arg->dest_cpu;
 		}
-- 
2.55.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-07  8:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-03  6:54 [syzbot] [kernel?] WARNING in __set_cpus_allowed_ptr_locked syzbot
2026-09-07  8:58 ` [RFC PATCH] sched: irq: cpu-hotplug race vs set_cpus_allowed_ptr() Sebastian Andrzej Siewior

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®