]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
padata: Reset next CPU when reorder sequence wraps around
authorXiao Liang <shaw.leon@gmail.com>
Mon, 20 Oct 2025 15:41:31 +0000 (11:41 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2025 13:00:01 +0000 (14:00 +0100)
[ Upstream commit 501302d5cee0d8e8ec2c4a5919c37e0df9abc99b ]

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")
Cc: <stable@vger.kernel.org>
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ moved from padata_reorder() to padata_find_next() function ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/padata.c

index 47aebcda65d5d308a7f2a17ea6e74bf3dce35312..409d2422843971b83fb9e18704dfc053b2270caf 100644 (file)
@@ -204,7 +204,11 @@ static struct padata_priv *padata_find_next(struct parallel_data *pd,
                list_del_init(&padata->list);
                atomic_dec(&pd->reorder_objects);
                ++pd->processed;
-               pd->cpu = cpumask_next_wrap(cpu, pd->cpumask.pcpu, -1, false);
+               /* 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, -1, false);
        }
 
        spin_unlock(&reorder->lock);