From 7caed6e7c41e66a66f739e9a4cdfc89f98150565 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 23 May 2017 03:50:43 +0000 Subject: [PATCH 1/2] scst: prevent possible memory reclaim deadlock Reported by lockdep: [ 415.813281] ================================= [ 415.817626] [ INFO: inconsistent lock state ] [ 415.821974] 4.10.12-scst-dbg #4 Tainted: G O [ 415.827360] --------------------------------- [ 415.831705] inconsistent {RECLAIM_FS-ON-W} -> {IN-RECLAIM_FS-W} usage. [ 415.838217] kswapd0/558 [HC0[0]:SC0[0]:HE1:SE1] takes: [ 415.843342] (sgv_pools_mutex){+.+.?.}, at: [] __sgv_shrink+0x90/0x1d0 [scst] [ 415.852075] {RECLAIM_FS-ON-W} state was registered at: [ 415.857208] mark_held_locks+0x6c/0x90 [ 415.861034] lockdep_trace_alloc+0x8a/0xd0 [ 415.865210] kmem_cache_alloc_node+0x32/0x2f0 [ 415.869670] sgv_pool_create_node+0x186/0x2e0 [scst] [ 415.874735] sgv_pool_create+0x12/0x20 [scst] [ 415.879194] scst_sgv_pools_init+0xb9/0x3c0 [scst] [ 415.884065] __dev_user_set_opt+0x152/0x5f0 [scst_user] [ 415.889367] do_one_initcall+0x59/0x190 [ 415.893280] do_init_module+0x6a/0x230 [ 415.897106] load_module+0x591/0x830 [ 415.900758] SYSC_init_module+0xd3/0x120 [ 415.904758] SyS_init_module+0xe/0x10 [ 415.908501] entry_SYSCALL_64_fastpath+0x18/0xad [ 415.913193] irq event stamp: 3831137 [ 415.916763] hardirqs last enabled at (3831137): [] __local_bh_enable_ip+0x67/0xd0 [ 415.925878] hardirqs last disabled at (3831135): [] __local_bh_enable_ip+0x2e/0xd0 [ 415.935018] softirqs last enabled at (3831136): [] __sgv_can_be_shrunk+0x9d/0x180 [scst] [ 415.944764] softirqs last disabled at (3831134): [] __sgv_can_be_shrunk+0x53/0x180 [scst] [ 415.954481] [ 415.954481] other info that might help us debug this: [ 415.960994] Possible unsafe locking scenario: [ 415.960994] [ 415.966899] CPU0 [ 415.969336] ---- [ 415.971774] lock(sgv_pools_mutex); [ 415.975339] [ 415.977950] lock(sgv_pools_mutex); [ 415.981691] [ 415.981691] *** DEADLOCK *** [ 415.981691] [ 415.987599] 1 lock held by kswapd0/558: [ 415.991424] #0: (shrinker_rwsem){++++..}, at: [] T.1898+0x4c/0x100 [ 415.999329] [ 415.999329] stack backtrace: [ 416.003677] CPU: 2 PID: 558 Comm: kswapd0 Tainted: G O 4.10.12-scst-dbg #4 [ 416.011663] Hardware name: Dell Inc. PowerEdge R710/00NH4P, BIOS 2.2.10 11/09/2010 [ 416.019216] Call Trace: [ 416.021661] dump_stack+0x6b/0xa0 [ 416.024968] print_usage_bug+0x182/0x190 [ 416.028881] ? print_circular_bug+0x110/0x110 [ 416.033226] mark_lock_irq+0xee/0x290 [ 416.036879] mark_lock+0x113/0x1a0 [ 416.040271] mark_irqflags+0xb0/0x180 [ 416.043924] __lock_acquire+0x245/0x610 [ 416.047750] ? __lock_release+0x408/0x470 [ 416.051750] lock_acquire+0xce/0x2b0 [ 416.055343] ? __sgv_shrink+0x90/0x1d0 [scst] [ 416.059689] ? mutex_lock_nested+0x47/0x750 [ 416.063863] mutex_lock_nested+0x82/0x750 [ 416.067888] ? __sgv_shrink+0x90/0x1d0 [scst] [ 416.072236] ? put_lock_stats+0xe/0x30 [ 416.075975] ? __lock_release+0x408/0x470 [ 416.080001] ? __sgv_shrink+0x90/0x1d0 [scst] [ 416.084349] ? debug_smp_processor_id+0x17/0x20 [ 416.088868] ? put_lock_stats+0xe/0x30 [ 416.092633] ? __sgv_can_be_shrunk+0x9d/0x180 [scst] [ 416.097588] ? mark_held_locks+0x6c/0x90 [ 416.101500] ? __local_bh_enable_ip+0x67/0xd0 [ 416.105873] __sgv_shrink+0x90/0x1d0 [scst] [ 416.110047] ? __local_bh_enable_ip+0x67/0xd0 [ 416.114420] sgv_scan_shrink+0x5d/0x120 [scst] [ 416.118853] do_shrink_slab+0x19b/0x5f0 [ 416.122678] ? T.1898+0x4c/0x100 [ 416.125899] ? down_read_trylock+0x60/0x80 [ 416.129985] T.1898+0xb4/0x100 [ 416.133031] shrink_node+0x62/0xa0 [ 416.136424] balance_pgdat+0x1c8/0x2c0 [ 416.140164] kswapd+0xa0/0x2b0 [ 416.143211] ? preempt_count_sub+0x9f/0xe0 [ 416.147409] ? schedule+0x4e/0xc0 [ 416.150715] ? balance_pgdat+0x2c0/0x2c0 [ 416.154627] kthread+0x111/0x150 [ 416.157849] ? call_usermodehelper_exec_work+0xa0/0xa0 [ 416.162974] ? __kthread_init_worker+0x80/0x80 [ 416.167407] ? call_usermodehelper_exec_work+0xa0/0xa0 [ 416.172534] ? call_usermodehelper_exec_work+0xa0/0xa0 [ 416.177660] ret_from_fork+0x2e/0x40 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7194 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_mem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index 8d18cd1e7..6a7c773c1 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -1645,7 +1645,12 @@ struct sgv_pool *sgv_pool_create_node(const char *name, } } - pool = kmem_cache_alloc_node(sgv_pool_cachep, GFP_KERNEL, nodeid); + /* + * __sgv_shrink() takes sgv_pools_mutex, so, to prevent deadlock with it + * if this allocation will try to reclaim memory, GFP_NOFS has to be used + * here. + */ + pool = kmem_cache_alloc_node(sgv_pool_cachep, GFP_KERNEL|GFP_NOFS, nodeid); if (pool == NULL) { PRINT_ERROR("Allocation of sgv_pool failed (size %zd)", sizeof(*pool)); From e5e4531049c98b139aa963051083d45476a3983c Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 25 May 2017 02:11:06 +0000 Subject: [PATCH 2/2] iscsi-scst: cleanup There's no need to end-align the padding. Plus, it's not optimal to access front misaligned memory Reported-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7195 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/nthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index 5e0bf81b8..082418e74 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -1695,7 +1695,7 @@ static int tx_padding(struct iscsi_cmnd *cmnd, int state) TRACE_DBG("Sending %d padding bytes (cmd %p)", rest, cmnd); - iov.iov_base = (char *)(&padding) + (sizeof(uint32_t) - rest); + iov.iov_base = (char *)&padding; iov.iov_len = rest; res = kernel_sendmsg(cmnd->conn->sock, &msg, &iov, 1, rest);