From 9b3d500276976e9f7b05fe74c6a2133fb5ae6a89 Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Fri, 5 Oct 2012 09:03:24 +0100 Subject: crypto: Convert crypto notifier chain to SRCU The crypto notifier deadlocks on RT. Though this can be a real deadlock on mainline as well due to fifo fair rwsems. The involved parties here are: [ 82.172678] swapper/0 S 0000000000000001 0 1 0 0x00000000 [ 82.172682] ffff88042f18fcf0 0000000000000046 ffff88042f18fc80 ffffffff81491238 [ 82.172685] 0000000000011cc0 0000000000011cc0 ffff88042f18c040 ffff88042f18ffd8 [ 82.172688] 0000000000011cc0 0000000000011cc0 ffff88042f18ffd8 0000000000011cc0 [ 82.172689] Call Trace: [ 82.172697] [] ? _raw_spin_unlock_irqrestore+0x6c/0x7a [ 82.172701] [] schedule+0x64/0x66 [ 82.172704] [] schedule_timeout+0x27/0xd0 [ 82.172708] [] ? unpin_current_cpu+0x1a/0x6c [ 82.172713] [] ? migrate_enable+0x12f/0x141 [ 82.172716] [] wait_for_common+0xbb/0x11f [ 82.172719] [] ? try_to_wake_up+0x182/0x182 [ 82.172722] [] wait_for_completion_interruptible+0x1d/0x2e [ 82.172726] [] crypto_wait_for_test+0x49/0x6b [ 82.172728] [] crypto_register_alg+0x53/0x5a [ 82.172730] [] crypto_register_algs+0x33/0x72 [ 82.172734] [] ? aes_init+0x12/0x12 [ 82.172737] [] aesni_init+0x64/0x66 [ 82.172741] [] do_one_initcall+0x7f/0x13b [ 82.172744] [] kernel_init+0x199/0x22c [ 82.172747] [] ? loglevel+0x31/0x31 [ 82.172752] [] kernel_thread_helper+0x4/0x10 [ 82.172755] [] ? retint_restore_args+0x13/0x13 [ 82.172759] [] ? start_kernel+0x3ca/0x3ca [ 82.172761] [] ? gs_change+0x13/0x13 [ 82.174186] cryptomgr_test S 0000000000000001 0 41 2 0x00000000 [ 82.174189] ffff88042c971980 0000000000000046 ffffffff81d74830 0000000000000292 [ 82.174192] 0000000000011cc0 0000000000011cc0 ffff88042c96eb80 ffff88042c971fd8 [ 82.174195] 0000000000011cc0 0000000000011cc0 ffff88042c971fd8 0000000000011cc0 [ 82.174195] Call Trace: [ 82.174198] [] schedule+0x64/0x66 [ 82.174201] [] schedule_timeout+0x27/0xd0 [ 82.174204] [] ? unpin_current_cpu+0x1a/0x6c [ 82.174206] [] ? migrate_enable+0x12f/0x141 [ 82.174209] [] wait_for_common+0xbb/0x11f [ 82.174212] [] ? try_to_wake_up+0x182/0x182 [ 82.174215] [] wait_for_completion_interruptible+0x1d/0x2e [ 82.174218] [] cryptomgr_notify+0x280/0x385 [ 82.174221] [] notifier_call_chain+0x6b/0x98 [ 82.174224] [] ? rt_down_read+0x10/0x12 [ 82.174227] [] __blocking_notifier_call_chain+0x70/0x8d [ 82.174230] [] blocking_notifier_call_chain+0x14/0x16 [ 82.174234] [] crypto_probing_notify+0x24/0x50 [ 82.174236] [] crypto_alg_mod_lookup+0x3e/0x74 [ 82.174238] [] crypto_alloc_base+0x36/0x8f [ 82.174241] [] cryptd_alloc_ablkcipher+0x6e/0xb5 [ 82.174243] [] ? kzalloc.clone.5+0xe/0x10 [ 82.174246] [] ablk_init_common+0x1d/0x38 [ 82.174249] [] ablk_ecb_init+0x15/0x17 [ 82.174251] [] __crypto_alloc_tfm+0xc7/0x114 [ 82.174254] [] ? crypto_lookup_skcipher+0x1f/0xe4 [ 82.174256] [] crypto_alloc_ablkcipher+0x60/0xa5 [ 82.174258] [] alg_test_skcipher+0x24/0x9b [ 82.174261] [] ? finish_task_switch+0x3f/0xfa [ 82.174263] [] alg_test+0x16f/0x1d7 [ 82.174267] [] ? cryptomgr_probe+0xac/0xac [ 82.174269] [] cryptomgr_test+0x2c/0x47 [ 82.174272] [] kthread+0x7e/0x86 [ 82.174275] [] ? finish_task_switch+0xaf/0xfa [ 82.174278] [] kernel_thread_helper+0x4/0x10 [ 82.174281] [] ? retint_restore_args+0x13/0x13 [ 82.174284] [] ? __init_kthread_worker+0x8c/0x8c [ 82.174287] [] ? gs_change+0x13/0x13 [ 82.174329] cryptomgr_probe D 0000000000000002 0 47 2 0x00000000 [ 82.174332] ffff88042c991b70 0000000000000046 ffff88042c991bb0 0000000000000006 [ 82.174335] 0000000000011cc0 0000000000011cc0 ffff88042c98ed00 ffff88042c991fd8 [ 82.174338] 0000000000011cc0 0000000000011cc0 ffff88042c991fd8 0000000000011cc0 [ 82.174338] Call Trace: [ 82.174342] [] schedule+0x64/0x66 [ 82.174344] [] __rt_mutex_slowlock+0x85/0xbe [ 82.174347] [] rt_mutex_slowlock+0xec/0x159 [ 82.174351] [] rt_mutex_fastlock.clone.8+0x29/0x2f [ 82.174353] [] rt_mutex_lock+0x33/0x37 [ 82.174356] [] __rt_down_read+0x50/0x5a [ 82.174358] [] ? rt_down_read+0x10/0x12 [ 82.174360] [] rt_down_read+0x10/0x12 [ 82.174363] [] __blocking_notifier_call_chain+0x58/0x8d [ 82.174366] [] blocking_notifier_call_chain+0x14/0x16 [ 82.174369] [] crypto_probing_notify+0x24/0x50 [ 82.174372] [] crypto_wait_for_test+0x22/0x6b [ 82.174374] [] crypto_register_instance+0xb4/0xc0 [ 82.174377] [] cryptd_create+0x378/0x3b6 [ 82.174379] [] ? __crypto_lookup_template+0x5b/0x63 [ 82.174382] [] cryptomgr_probe+0x45/0xac [ 82.174385] [] ? crypto_alloc_pcomp+0x1b/0x1b [ 82.174388] [] kthread+0x7e/0x86 [ 82.174391] [] ? finish_task_switch+0xaf/0xfa [ 82.174394] [] kernel_thread_helper+0x4/0x10 [ 82.174398] [] ? retint_restore_args+0x13/0x13 [ 82.174401] [] ? __init_kthread_worker+0x8c/0x8c [ 82.174403] [] ? gs_change+0x13/0x13 cryptomgr_test spawns the cryptomgr_probe thread from the notifier call. The probe thread fires the same notifier as the test thread and deadlocks on the rwsem on RT. Now this is a potential deadlock in mainline as well, because we have fifo fair rwsems. If another thread blocks with a down_write() on the notifier chain before the probe thread issues the down_read() it will block the probe thread and the whole party is dead locked. Signed-off-by: Peter Zijlstra Signed-off-by: Thomas Gleixner diff --git a/crypto/algapi.c b/crypto/algapi.c index 00d8d93..13d3e63 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -684,13 +684,13 @@ EXPORT_SYMBOL_GPL(crypto_spawn_tfm2); int crypto_register_notifier(struct notifier_block *nb) { - return blocking_notifier_chain_register(&crypto_chain, nb); + return srcu_notifier_chain_register(&crypto_chain, nb); } EXPORT_SYMBOL_GPL(crypto_register_notifier); int crypto_unregister_notifier(struct notifier_block *nb) { - return blocking_notifier_chain_unregister(&crypto_chain, nb); + return srcu_notifier_chain_unregister(&crypto_chain, nb); } EXPORT_SYMBOL_GPL(crypto_unregister_notifier); diff --git a/crypto/api.c b/crypto/api.c index 2a81e98..6d536b8 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -31,7 +31,7 @@ EXPORT_SYMBOL_GPL(crypto_alg_list); DECLARE_RWSEM(crypto_alg_sem); EXPORT_SYMBOL_GPL(crypto_alg_sem); -BLOCKING_NOTIFIER_HEAD(crypto_chain); +SRCU_NOTIFIER_HEAD(crypto_chain); EXPORT_SYMBOL_GPL(crypto_chain); static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg); @@ -236,10 +236,10 @@ int crypto_probing_notify(unsigned long val, void *v) { int ok; - ok = blocking_notifier_call_chain(&crypto_chain, val, v); + ok = srcu_notifier_call_chain(&crypto_chain, val, v); if (ok == NOTIFY_DONE) { request_module("cryptomgr"); - ok = blocking_notifier_call_chain(&crypto_chain, val, v); + ok = srcu_notifier_call_chain(&crypto_chain, val, v); } return ok; diff --git a/crypto/internal.h b/crypto/internal.h index bd39bfc..a5db167 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -48,7 +48,7 @@ struct crypto_larval { extern struct list_head crypto_alg_list; extern struct rw_semaphore crypto_alg_sem; -extern struct blocking_notifier_head crypto_chain; +extern struct srcu_notifier_head crypto_chain; #ifdef CONFIG_PROC_FS void __init crypto_init_proc(void); @@ -142,7 +142,7 @@ static inline int crypto_is_moribund(struct crypto_alg *alg) static inline void crypto_notify(unsigned long val, void *v) { - blocking_notifier_call_chain(&crypto_chain, val, v); + srcu_notifier_call_chain(&crypto_chain, val, v); } #endif /* _CRYPTO_INTERNAL_H */ -- cgit v0.10.2