Skip to contentSkip to conversation

padata: Reset next CPU when reorder sequence wraps around

PATCH Superseded Xiao Liang 2 participants 3 messages Jul 15, 2025 – Aug 16, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xiao Liang

author
#0 lore raw

PATCH 1/1 padata: Reset next CPU when reorder sequence wraps around

When seq_nr wraps around, the next reorder job with seq 0 is hashed to the first CPU in padata_do_serial(). Correspondingly, need reset pd->cpu to the first one when pd->processed wraps around. Otherwise, if the number of used CPUs is not a power of 2, padata_find_next() will be checking a wrong list, hence deadlock.

Fixes 6fc4dbcf0276 ("padata: Replace delayed timer with immediate workqueue in padata_reorder")
---
 kernel/padata.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/padata.c +5 -1
index 7eee94166357..ebb52c6db637 100644
@@ -290,7 +290,11 @@ static struct padata_priv *padata_find_next(struct parallel_data *pd,
 	if (remove_object) {
 		list_del_init(&padata->list);
 		++pd->processed;
-		pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu);
+		/* When sequence wraps around, reset to the first CPU. */
+		if (unlikely(pd->processed == 0))
+			pd->cpu = cpumask_first(pd->cpumask.pcpu);
+		else
+			pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu);
 	}
 
 	spin_unlock(&reorder->lock);
Signature · 1 line
2.50.0
author
#1 lore raw
Quoted 18 lines
kernel/padata.c +5 -2
index 7eee94166357..ebb52c6db637 100644
@@ -290,7 +290,11 @@ static struct padata_priv *padata_find_next(struct parallel_data *pd,
        if (remove_object) {
                list_del_init(&padata->list);
                ++pd->processed;
-               pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu);
+               /* When sequence wraps around, reset to the first CPU. */
+               if (unlikely(pd->processed == 0))
+                       pd->cpu = cpumask_first(pd->cpumask.pcpu);
+               else
+                       pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu);
        }
 
        spin_unlock(&reorder->lock);
--
Quoted 2 lines

2.50.0

Another question:
Do we even need a per-CPU reorder_list? It's always used with a remote CPU id and spin-lock. Would a plain array of struct padata_list be sufficient?

maintainer
#2 lore raw
In reply to Xiao Liang
Quoted 17 lines · Xiao Liang

When seq_nr wraps around, the next reorder job with seq 0 is hashed to the first CPU in padata_do_serial(). Correspondingly, need reset pd->cpu to the first one when pd->processed wraps around. Otherwise, if the number of used CPUs is not a power of 2, padata_find_next() will be checking a wrong list, hence deadlock.

Fixes 6fc4dbcf0276 ("padata: Replace delayed timer with immediate workqueue in padata_reorder")
---
 kernel/padata.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/padata.c +0 -0
index 7eee94166357..ebb52c6db637 100644

kernel/padata.c static struct padata_priv *padata_find_next(struct parallel_data *pd, · line 297

Quoted 9 lines
kernel/padata.c +5 -1
@@ -290,7 +290,11 @@ static struct padata_priv *padata_find_next(struct parallel_data *pd,
 	if (remove_object) {
 		list_del_init(&padata->list);
 		++pd->processed;
-		pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu);
+		/* When sequence wraps around, reset to the first CPU. */
+		if (unlikely(pd->processed == 0))
+			pd->cpu = cpumask_first(pd->cpumask.pcpu);
+		else
+			pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu);

This patch does not apply to the current mainline kernel.

Please check whether it is still needed.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt