From patchwork Thu May 18 13:16:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Neyelov X-Patchwork-Id: 9734231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 978B6600CC for ; Thu, 18 May 2017 13:16:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83390286B7 for ; Thu, 18 May 2017 13:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77FC2287A3; Thu, 18 May 2017 13:16:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AE6D286B7 for ; Thu, 18 May 2017 13:16:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756290AbdERNQr (ORCPT ); Thu, 18 May 2017 09:16:47 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:33416 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755433AbdERNQq (ORCPT ); Thu, 18 May 2017 09:16:46 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from vladimirn@mellanox.com) with ESMTPS (AES256-SHA encrypted); 18 May 2017 16:16:27 +0300 Received: from dev-r-vrt-007.mtr.labs.mlnx (dev-r-vrt-007.mtr.labs.mlnx [10.212.7.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v4IDGNLv021545; Thu, 18 May 2017 16:16:27 +0300 From: Vladimir Neyelov To: linux-rdma@vger.kernel.org Cc: root Subject: [PATCH] IB/iser: fix connection teardown race condition Date: Thu, 18 May 2017 16:16:21 +0300 Message-Id: <1495113381-15564-2-git-send-email-vladimirn@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1495113381-15564-1-git-send-email-vladimirn@mellanox.com> References: <1495113381-15564-1-git-send-email-vladimirn@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: root Under heavy iser target(scst) start/stop stress on iser intitiator side found race condition. When called function iscsi_iser_slave_alloc iser_conn pointer could be NULL. Because function iscsi_iser_conn_stop can be called before and free iser connection. Addition global mutex help to avoid this race. Signed-off-by: Vladimir Neyelov --- drivers/infiniband/ulp/iser/iscsi_iser.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index 5a887ef..62fff2a 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c @@ -83,6 +83,7 @@ static struct iscsi_transport iscsi_iser_transport; static struct scsi_transport_template *iscsi_iser_scsi_transport; static struct workqueue_struct *release_wq; +static DEFINE_MUTEX(unbind_iser_conn_mutex); struct iser_global ig; int iser_debug_level = 0; @@ -550,12 +551,14 @@ static void iscsi_iser_cleanup_task(struct iscsi_task *task) */ if (iser_conn) { mutex_lock(&iser_conn->state_mutex); + mutex_lock(&unbind_iser_conn_mutex); iser_conn_terminate(iser_conn); iscsi_conn_stop(cls_conn, flag); /* unbind */ iser_conn->iscsi_conn = NULL; conn->dd_data = NULL; + mutex_unlock(&unbind_iser_conn_mutex); complete(&iser_conn->stop_completion); mutex_unlock(&iser_conn->state_mutex); @@ -977,13 +980,20 @@ static int iscsi_iser_slave_alloc(struct scsi_device *sdev) struct iser_conn *iser_conn; struct ib_device *ib_dev; + mutex_lock(&unbind_iser_conn_mutex); + session = starget_to_session(scsi_target(sdev))->dd_data; iser_conn = session->leadconn->dd_data; + if(!iser_conn) { + mutex_unlock(&unbind_iser_conn_mutex); + return -EFAULT; + } ib_dev = iser_conn->ib_conn.device->ib_device; if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG)) blk_queue_virt_boundary(sdev->request_queue, ~MASK_4K); + mutex_unlock(&unbind_iser_conn_mutex); return 0; }