Commit 48da967d authored by Vladislav Fedyaev's avatar Vladislav Fedyaev Committed by Tomasz Zawadzki
Browse files

lib/thread: Fixed data race on thread exit/for_each_channel call



There is a data race condition, with spdk_thread, waiting on
g_devlist_mutex inside put_io_channel() to close channel and exit
on one side, and spdk_for_each_channel() holding this mutex while
iterating channels. Because spdk_for_each_channel() releases mutex
BEFORE calling spdk_thread_send_msg() to that thread, there is a
possibility, that exiting spdk_thread will be executed prior to
this message being received, resulting in
spdk_for_each_channel_continue() never being called, which in turn
means spdk_for_each_channel() completion callback won't be called.

Change-Id: I6ab14b7959e73689534b7127b1a6a0c5420a7185
Signed-off-by: default avatarVladislav Fedyaev <a37206@gmail.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26175


Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarVasilii Ivanov <iwanovvvasilij@gmail.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarTomasz Zawadzki <tomasz@tzawadzki.com>
parent 54423bca
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2670,8 +2670,8 @@ spdk_for_each_channel(void *io_device, spdk_channel_msg fn, void *ctx,
			ch->dev->for_each_count++;
			i->cur_thread = thread;
			i->ch = ch;
			pthread_mutex_unlock(&g_devlist_mutex);
			rc = spdk_thread_send_msg(thread, _call_channel, i);
			pthread_mutex_unlock(&g_devlist_mutex);
			assert(rc == 0);
			return;
		}
@@ -2718,8 +2718,8 @@ spdk_for_each_channel_continue(struct spdk_io_channel_iter *i, int status)
		if (ch != NULL) {
			i->cur_thread = thread;
			i->ch = ch;
			pthread_mutex_unlock(&g_devlist_mutex);
			rc = spdk_thread_send_msg(thread, _call_channel, i);
			pthread_mutex_unlock(&g_devlist_mutex);
			assert(rc == 0);
			return;
		}