iscsi-target: Fix race with thread_pre_handler flush_signals + ISCSI_THREAD_SET_DIE
authorNicholas Bellinger <nab@linux-iscsi.org>
Sat, 7 Sep 2013 03:46:50 +0000 (20:46 -0700)
committerNicholas Bellinger <nab@linux-iscsi.org>
Tue, 10 Sep 2013 23:48:54 +0000 (16:48 -0700)
commitd5705c4ab5035be618a34c95505727acac2e70ec
tree512bd3f2a432db2e1ae147a46950927ce2cb0502
parent0105c257be8bfb7370631e442eff3213adbfdcb7
iscsi-target: Fix race with thread_pre_handler flush_signals + ISCSI_THREAD_SET_DIE

This patch addresses an long standing race in iscsi_[rx,tx]_thread_pre_handler()
use of flush_signals(), and between iscsi_deallocate_extra_thread_sets() setting
ISCSI_THREAD_SET_DIE before calling kthread_stop().

It addresses the issue by both holding ts_state_lock before calling send_sig()
in iscsi_deallocate_extra_thread_sets(), as well as only calling flush_signals()
when ts->status != ISCSI_THREAD_SET_DIE within iscsi_[rx,tx]_thread_pre_handler()
code.

v2 changes:
  - Add explicit complete(&ts->[rx,tx]_start_comp); before kthread_stop() in
    iscsi_deallocate_extra_thread_sets()
  - Drop left-over send_sig() calls in iscsi_deallocate_extra_thread_sets()
  - Add kthread_should_stop() check in iscsi_signal_thread_pre_handler()

Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/iscsi/iscsi_target_tq.c