Skip to content

Commit e0348c1

Browse files
committed
Merge tag 'wq-for-6.7-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
Pull workqueue fix from Tejun Heo: "Just one patch to fix a bug which can crash the kernel if the housekeeping and wq_unbound_cpu cpumask configuration combination leaves the latter empty" * tag 'wq-for-6.7-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: Make sure that wq_unbound_cpumask is never empty
2 parents 4388ae2 + 4a6c560 commit e0348c1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

kernel/workqueue.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,9 +1684,6 @@ static int wq_select_unbound_cpu(int cpu)
16841684
pr_warn_once("workqueue: round-robin CPU selection forced, expect performance impact\n");
16851685
}
16861686

1687-
if (cpumask_empty(wq_unbound_cpumask))
1688-
return cpu;
1689-
16901687
new_cpu = __this_cpu_read(wq_rr_cpu_last);
16911688
new_cpu = cpumask_next_and(new_cpu, wq_unbound_cpumask, cpu_online_mask);
16921689
if (unlikely(new_cpu >= nr_cpu_ids)) {
@@ -6515,6 +6512,17 @@ static inline void wq_watchdog_init(void) { }
65156512

65166513
#endif /* CONFIG_WQ_WATCHDOG */
65176514

6515+
static void __init restrict_unbound_cpumask(const char *name, const struct cpumask *mask)
6516+
{
6517+
if (!cpumask_intersects(wq_unbound_cpumask, mask)) {
6518+
pr_warn("workqueue: Restricting unbound_cpumask (%*pb) with %s (%*pb) leaves no CPU, ignoring\n",
6519+
cpumask_pr_args(wq_unbound_cpumask), name, cpumask_pr_args(mask));
6520+
return;
6521+
}
6522+
6523+
cpumask_and(wq_unbound_cpumask, wq_unbound_cpumask, mask);
6524+
}
6525+
65186526
/**
65196527
* workqueue_init_early - early init for workqueue subsystem
65206528
*
@@ -6534,11 +6542,11 @@ void __init workqueue_init_early(void)
65346542
BUILD_BUG_ON(__alignof__(struct pool_workqueue) < __alignof__(long long));
65356543

65366544
BUG_ON(!alloc_cpumask_var(&wq_unbound_cpumask, GFP_KERNEL));
6537-
cpumask_copy(wq_unbound_cpumask, housekeeping_cpumask(HK_TYPE_WQ));
6538-
cpumask_and(wq_unbound_cpumask, wq_unbound_cpumask, housekeeping_cpumask(HK_TYPE_DOMAIN));
6539-
6545+
cpumask_copy(wq_unbound_cpumask, cpu_possible_mask);
6546+
restrict_unbound_cpumask("HK_TYPE_WQ", housekeeping_cpumask(HK_TYPE_WQ));
6547+
restrict_unbound_cpumask("HK_TYPE_DOMAIN", housekeeping_cpumask(HK_TYPE_DOMAIN));
65406548
if (!cpumask_empty(&wq_cmdline_cpumask))
6541-
cpumask_and(wq_unbound_cpumask, wq_unbound_cpumask, &wq_cmdline_cpumask);
6549+
restrict_unbound_cpumask("workqueue.unbound_cpus", &wq_cmdline_cpumask);
65426550

65436551
pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC);
65446552

0 commit comments

Comments
 (0)