Commit 5be8e070 authored by Hiroya Nozaki's avatar Hiroya Nozaki Committed by Greg Kroah-Hartman

staging/lustre/ptlrpc: Race between start and stop service threads

When ptlrpc_start_thread fails to create a new thread, it will
finalize and free a struct ptlrpc_thread created and used here.
Considering this, it can be a problem when ptlrpc_svcpt_stop_thread
is driven and handles the struct ptlrpc_thread right after or right
before failure of cfs_create_thread. Because this situation let
the both of ptlrpc_start_thread and ptlrpc_svcpt_stop_threads
access the freed ptlrpc_thread and cause OS panic. Or, it may
happen that ptlrpc_svcpt_stop_threads waits forever holding an
already-freed waitq.

This patch adds an error handling into ptlrpc_start_thread to fix
this problem.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2889
Lustre-change: http://review.whamcloud.com/5552Signed-off-by: default avatarHiroya Nozaki <nozaki.hiroya@jp.fujitsu.com>
Reviewed-by: default avatarLiang Zhen <liang.zhen@intel.com>
Reviewed-by: default avatarNikitas Angelinas <nikitas_angelinas@xyratex.com>
Reviewed-by: default avatarKeith Mannthey <keith.mannthey@intel.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarPeng Tao <tao.peng@emc.com>
Signed-off-by: default avatarAndreas Dilger <andreas.dilger@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a55e0f44
...@@ -2765,11 +2765,19 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait) ...@@ -2765,11 +2765,19 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait)
CERROR("cannot start thread '%s': rc %d\n", CERROR("cannot start thread '%s': rc %d\n",
thread->t_name, rc); thread->t_name, rc);
spin_lock(&svcpt->scp_lock); spin_lock(&svcpt->scp_lock);
list_del(&thread->t_link);
--svcpt->scp_nthrs_starting; --svcpt->scp_nthrs_starting;
spin_unlock(&svcpt->scp_lock); if (thread_is_stopping(thread)) {
/* this ptlrpc_thread is being hanled
OBD_FREE(thread, sizeof(*thread)); * by ptlrpc_svcpt_stop_threads now
*/
thread_add_flags(thread, SVC_STOPPED);
wake_up(&thread->t_ctl_waitq);
spin_unlock(&svcpt->scp_lock);
} else {
list_del(&thread->t_link);
spin_unlock(&svcpt->scp_lock);
OBD_FREE_PTR(thread);
}
RETURN(rc); RETURN(rc);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment