Skip to content

Commit cf144f8

Browse files
danieljordan10herbertx
authored andcommitted
padata: use smp_mb in padata_reorder to avoid orphaned padata jobs
Testing padata with the tcrypt module on a 5.2 kernel... # modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3 # modprobe tcrypt mode=211 sec=1 ...produces this splat: INFO: task modprobe:10075 blocked for more than 120 seconds. Not tainted 5.2.0-base+ #16 modprobe D 0 10075 10064 0x80004080 Call Trace: ? __schedule+0x4dd/0x610 ? ring_buffer_unlock_commit+0x23/0x100 schedule+0x6c/0x90 schedule_timeout+0x3b/0x320 ? trace_buffer_unlock_commit_regs+0x4f/0x1f0 wait_for_common+0x160/0x1a0 ? wake_up_q+0x80/0x80 { crypto_wait_req } # entries in braces added by hand { do_one_aead_op } { test_aead_jiffies } test_aead_speed.constprop.17+0x681/0xf30 [tcrypt] do_test+0x4053/0x6a2b [tcrypt] ? 0xffffffffa00f4000 tcrypt_mod_init+0x50/0x1000 [tcrypt] ... The second modprobe command never finishes because in padata_reorder, CPU0's load of reorder_objects is executed before the unlocking store in spin_unlock_bh(pd->lock), causing CPU0 to miss CPU1's increment: CPU0 CPU1 padata_reorder padata_do_serial LOAD reorder_objects // 0 INC reorder_objects // 1 padata_reorder TRYLOCK pd->lock // failed UNLOCK pd->lock CPU0 deletes the timer before returning from padata_reorder and since no other job is submitted to padata, modprobe waits indefinitely. Add a pair of full barriers to guarantee proper ordering: CPU0 CPU1 padata_reorder padata_do_serial UNLOCK pd->lock smp_mb() LOAD reorder_objects INC reorder_objects smp_mb__after_atomic() padata_reorder TRYLOCK pd->lock smp_mb__after_atomic is needed so the read part of the trylock operation comes after the INC, as Andrea points out. Thanks also to Andrea for help with writing a litmus test. Fixes: 16295be ("padata: Generic parallelization/serialization interface") Signed-off-by: Daniel Jordan <[email protected]> Cc: <[email protected]> Cc: Andrea Parri <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steffen Klassert <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Herbert Xu <[email protected]>
1 parent 83bf425 commit cf144f8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kernel/padata.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ static void padata_reorder(struct parallel_data *pd)
267267
* The next object that needs serialization might have arrived to
268268
* the reorder queues in the meantime, we will be called again
269269
* from the timer function if no one else cares for it.
270+
*
271+
* Ensure reorder_objects is read after pd->lock is dropped so we see
272+
* an increment from another task in padata_do_serial. Pairs with
273+
* smp_mb__after_atomic in padata_do_serial.
270274
*/
275+
smp_mb();
271276
if (atomic_read(&pd->reorder_objects)
272277
&& !(pinst->flags & PADATA_RESET))
273278
mod_timer(&pd->timer, jiffies + HZ);
@@ -387,6 +392,13 @@ void padata_do_serial(struct padata_priv *padata)
387392
list_add_tail(&padata->list, &pqueue->reorder.list);
388393
spin_unlock(&pqueue->reorder.lock);
389394

395+
/*
396+
* Ensure the atomic_inc of reorder_objects above is ordered correctly
397+
* with the trylock of pd->lock in padata_reorder. Pairs with smp_mb
398+
* in padata_reorder.
399+
*/
400+
smp_mb__after_atomic();
401+
390402
put_cpu();
391403

392404
/* If we're running on the wrong CPU, call padata_reorder() via a

0 commit comments

Comments
 (0)