From patchwork Tue Dec 1 21:29:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB098C71155 for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49F0820709 for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="H+0qOift" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389350AbgLAVbN (ORCPT ); Tue, 1 Dec 2020 16:31:13 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:46736 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729366AbgLAVbD (ORCPT ); Tue, 1 Dec 2020 16:31:03 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LTIg5018593; Tue, 1 Dec 2020 21:30:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=dfz/y3M+AxWI119IptFOTGZEGinRix7lScyzhN3sP2w=; b=H+0qOiftpIfYTGuBLuywYZsik0KKendBJAN+Knu5fM685NQiJ9ukSA5Y+BLzxK4NJvOg xju9unce99++6tRDzDIGG9o/vsEExUmrvhfTayULgBRxwf+wZEiRZly2YyTMSMgmK7CN LA3dmfBDYmDMWhxudDvR9cSjsSwdPzbrzN2ve25dq5X7O3cs2huXngCGdUnJzTRooywy fgMICu7CC6AkdMqjH499N1Vpka+LKA2egRRA8XDFC9CLzfzKL60r0r7VQpaSJNI81xLe F7qPEFT7H4cs8N1UxNYFC5/mp8wz5otErqdCm3EMXvrxvJqtVmBD4QjgQYwxy48wyQpO ig== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 353dyqmy24-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:12 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LU6ZQ105683; Tue, 1 Dec 2020 21:30:11 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 3540eyh8sn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:11 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LU5X0020958; Tue, 1 Dec 2020 21:30:07 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:04 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 01/15] libiscsi: fix iscsi_prep_scsi_cmd_pdu error handling Date: Tue, 1 Dec 2020 15:29:42 -0600 Message-Id: <1606858196-5421-2-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 bulkscore=0 spamscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If iscsi_prep_scsi_cmd_pdu fails we try to add it back to the cmdqueue, but we leave it partially setup. We don't have functions that can undo the pdu and init task setup. We only have cleanup_task which can cleanup both parts. So this has us just fail the cmd and go through the standard cleanup routine and then have scsi-ml retry it like is done when it fails in the queuecommand path. Signed-off-by: Mike Christie Reviewed-by: Lee Duncan --- drivers/scsi/libiscsi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index f9314f1..ee0786b 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -1532,14 +1532,9 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) } rc = iscsi_prep_scsi_cmd_pdu(conn->task); if (rc) { - if (rc == -ENOMEM || rc == -EACCES) { - spin_lock_bh(&conn->taskqueuelock); - list_add_tail(&conn->task->running, - &conn->cmdqueue); - conn->task = NULL; - spin_unlock_bh(&conn->taskqueuelock); - goto done; - } else + if (rc == -ENOMEM || rc == -EACCES) + fail_scsi_task(conn->task, DID_IMM_RETRY); + else fail_scsi_task(conn->task, DID_ABORT); spin_lock_bh(&conn->taskqueuelock); continue; From patchwork Tue Dec 1 21:29:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF2E8C8301A for ; Tue, 1 Dec 2020 21:31:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 858A52084C for ; Tue, 1 Dec 2020 21:31:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="JhsUihfg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389341AbgLAVbM (ORCPT ); Tue, 1 Dec 2020 16:31:12 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:40894 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725912AbgLAVbE (ORCPT ); Tue, 1 Dec 2020 16:31:04 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSvmG117418; Tue, 1 Dec 2020 21:30:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=BK+bW55ENwh03wueTI7TTrkz9blxdRMiWoAfAUvp6Ak=; b=JhsUihfg16kThkB88L64dm3t3Z3hUTh86hTZ9reDMA2pVqYL9aAjhbMAfJ9d/GXSKWJe sFMfInepssXXGdkk8G85jSwVR1cSrfb5ehykGAyFi1InQRUQeSqZBuxqW4WYH5eymB6x 8vq1Z8RuCL0hBZOx/O7NOJqMrKofVdkdRtRw+62u8ZwFbE2uQT3Ko5mGrRmL+wri7FBk 8FLg70LXydEmw0k2moMpq+VU3qqFb9B30/OhPUUWs89ucqPwZrUwhUQURwzb19YxBsra HrBLVt1BmywukWaWXk1PewlCb6G+TJjYGqpkBU24qIsV6CZkS+LAzsnyOwhmF3rvRzbM jA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 353c2aw2uc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:10 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LBKfv163787; Tue, 1 Dec 2020 21:30:09 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 3540fxkwm3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:09 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LU5GM020958; Tue, 1 Dec 2020 21:30:07 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:05 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 02/15] libiscsi: drop taskqueuelock Date: Tue, 1 Dec 2020 15:29:43 -0600 Message-Id: <1606858196-5421-3-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=2 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 lowpriorityscore=0 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The purpose of the taskqueuelock was to handle the issue where a bad target decides to send a R2T and before it's data has been sent decides to send a cmd response to complete the cmd. The following patches fix up the frwd/back locks so they are taken from the queue/xmit (frwd) and completion (back) paths again. To get there this patch removes the taskqueuelock which for iscsi xmit wq based drivers was taken in the queue, xmit and completion paths. Instead of the lock, we just make sure we have a ref to the task when we queue a R2T, and then we always remove the task from the requeue list in the xmit path or the forced cleanup paths. Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 170 +++++++++++++++++++++++++++----------------- drivers/scsi/libiscsi_tcp.c | 84 ++++++++++++++-------- include/scsi/libiscsi.h | 4 +- 3 files changed, 163 insertions(+), 95 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index ee0786b..7983281 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -523,16 +523,6 @@ static void iscsi_complete_task(struct iscsi_task *task, int state) WARN_ON_ONCE(task->state == ISCSI_TASK_FREE); task->state = state; - spin_lock_bh(&conn->taskqueuelock); - if (!list_empty(&task->running)) { - pr_debug_once("%s while task on list", __func__); - list_del_init(&task->running); - } - spin_unlock_bh(&conn->taskqueuelock); - - if (conn->task == task) - conn->task = NULL; - if (READ_ONCE(conn->ping_task) == task) WRITE_ONCE(conn->ping_task, NULL); @@ -564,9 +554,39 @@ void iscsi_complete_scsi_task(struct iscsi_task *task, } EXPORT_SYMBOL_GPL(iscsi_complete_scsi_task); +/* + * Must be called with back and frwd lock + */ +static bool cleanup_queued_task(struct iscsi_task *task) +{ + struct iscsi_conn *conn = task->conn; + bool early_complete = false; + + /* Bad target might have completed task while it was still running */ + if (task->state == ISCSI_TASK_COMPLETED) + early_complete = true; + + if (!list_empty(&task->running)) { + list_del_init(&task->running); + + /* + * If it's on a list and running then it must be on the requeue + * list + */ + if (task->state == ISCSI_TASK_RUNNING) + __iscsi_put_task(task); + } + + if (conn->task == task) { + conn->task = NULL; + __iscsi_put_task(task); + } + + return early_complete; +} /* - * session back_lock must be held and if not called for a task that is + * session frwd_lock must be held and if not called for a task that is * still pending or from the xmit thread, then xmit thread must * be suspended. */ @@ -585,6 +605,13 @@ static void fail_scsi_task(struct iscsi_task *task, int err) if (!sc) return; + /* regular RX path uses back_lock */ + spin_lock_bh(&conn->session->back_lock); + if (cleanup_queued_task(task)) { + spin_unlock_bh(&conn->session->back_lock); + return; + } + if (task->state == ISCSI_TASK_PENDING) { /* * cmd never made it to the xmit thread, so we should not count @@ -600,9 +627,6 @@ static void fail_scsi_task(struct iscsi_task *task, int err) sc->result = err << 16; scsi_set_resid(sc, scsi_bufflen(sc)); - - /* regular RX path uses back_lock */ - spin_lock_bh(&conn->session->back_lock); iscsi_complete_task(task, state); spin_unlock_bh(&conn->session->back_lock); } @@ -748,9 +772,7 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, if (session->tt->xmit_task(task)) goto free_task; } else { - spin_lock_bh(&conn->taskqueuelock); list_add_tail(&task->running, &conn->mgmtqueue); - spin_unlock_bh(&conn->taskqueuelock); iscsi_conn_queue_work(conn); } @@ -1411,31 +1433,51 @@ static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn) return 0; } -static int iscsi_xmit_task(struct iscsi_conn *conn) +static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref) { struct iscsi_task *task = conn->task; int rc; - if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) - return -ENODATA; - + /* Take a ref so we can access it after xmit_task() */ + __iscsi_get_task(task); + conn->task = NULL; spin_lock_bh(&conn->session->back_lock); - if (conn->task == NULL) { - spin_unlock_bh(&conn->session->back_lock); - return -ENODATA; + /* + * If this was a requeue for a R2T or we were in the middle of sending + * the task, we have an extra ref on the task in case a bad target + * sends a cmd rsp before we have handled the task. + */ + if (has_extra_ref) + __iscsi_put_task(task); + + /* + * Do this after dropping the extra ref because the forced dequeue + * helper will miss the ref taken during requeue list check. + */ + if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) { + rc = -ENODATA; + goto put_task; } - __iscsi_get_task(task); spin_unlock_bh(&conn->session->back_lock); + spin_unlock_bh(&conn->session->frwd_lock); rc = conn->session->tt->xmit_task(task); spin_lock_bh(&conn->session->frwd_lock); if (!rc) { /* done with this task */ task->last_xfer = jiffies; - conn->task = NULL; } /* regular RX path uses back_lock */ spin_lock(&conn->session->back_lock); + if (rc && task->state == ISCSI_TASK_RUNNING) { + /* + * get an extra ref that is released next time we access it + * as conn->task above. + */ + __iscsi_get_task(task); + conn->task = task; + } +put_task: __iscsi_put_task(task); spin_unlock(&conn->session->back_lock); return rc; @@ -1445,9 +1487,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn) * iscsi_requeue_task - requeue task to run from session workqueue * @task: task to requeue * - * LLDs that need to run a task from the session workqueue should call - * this. The session frwd_lock must be held. This should only be called - * by software drivers. + * Callers must have taken a ref to the task that is going to be requeued. */ void iscsi_requeue_task(struct iscsi_task *task) { @@ -1457,11 +1497,18 @@ void iscsi_requeue_task(struct iscsi_task *task) * this may be on the requeue list already if the xmit_task callout * is handling the r2ts while we are adding new ones */ - spin_lock_bh(&conn->taskqueuelock); - if (list_empty(&task->running)) + spin_lock_bh(&conn->session->frwd_lock); + if (list_empty(&task->running)) { list_add_tail(&task->running, &conn->requeue); - spin_unlock_bh(&conn->taskqueuelock); + } else { + /* + * Don't need the extra ref since it's already requeued and + * has a ref. + */ + iscsi_put_task(task); + } iscsi_conn_queue_work(conn); + spin_unlock_bh(&conn->session->frwd_lock); } EXPORT_SYMBOL_GPL(iscsi_requeue_task); @@ -1487,7 +1534,7 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) } if (conn->task) { - rc = iscsi_xmit_task(conn); + rc = iscsi_xmit_task(conn, true); if (rc) goto done; } @@ -1497,49 +1544,43 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) * only have one nop-out as a ping from us and targets should not * overflow us with nop-ins */ - spin_lock_bh(&conn->taskqueuelock); check_mgmt: while (!list_empty(&conn->mgmtqueue)) { - conn->task = list_entry(conn->mgmtqueue.next, - struct iscsi_task, running); - list_del_init(&conn->task->running); - spin_unlock_bh(&conn->taskqueuelock); - if (iscsi_prep_mgmt_task(conn, conn->task)) { + task = list_entry(conn->mgmtqueue.next, struct iscsi_task, + running); + list_del_init(&task->running); + if (iscsi_prep_mgmt_task(conn, task)) { /* regular RX path uses back_lock */ spin_lock_bh(&conn->session->back_lock); - __iscsi_put_task(conn->task); + __iscsi_put_task(task); spin_unlock_bh(&conn->session->back_lock); - conn->task = NULL; - spin_lock_bh(&conn->taskqueuelock); continue; } - rc = iscsi_xmit_task(conn); + conn->task = task; + rc = iscsi_xmit_task(conn, false); if (rc) goto done; - spin_lock_bh(&conn->taskqueuelock); } /* process pending command queue */ while (!list_empty(&conn->cmdqueue)) { - conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task, - running); - list_del_init(&conn->task->running); - spin_unlock_bh(&conn->taskqueuelock); + task = list_entry(conn->cmdqueue.next, struct iscsi_task, + running); + list_del_init(&task->running); if (conn->session->state == ISCSI_STATE_LOGGING_OUT) { - fail_scsi_task(conn->task, DID_IMM_RETRY); - spin_lock_bh(&conn->taskqueuelock); + fail_scsi_task(task, DID_IMM_RETRY); continue; } - rc = iscsi_prep_scsi_cmd_pdu(conn->task); + rc = iscsi_prep_scsi_cmd_pdu(task); if (rc) { if (rc == -ENOMEM || rc == -EACCES) - fail_scsi_task(conn->task, DID_IMM_RETRY); + fail_scsi_task(task, DID_IMM_RETRY); else - fail_scsi_task(conn->task, DID_ABORT); - spin_lock_bh(&conn->taskqueuelock); + fail_scsi_task(task, DID_ABORT); continue; } - rc = iscsi_xmit_task(conn); + conn->task = task; + rc = iscsi_xmit_task(conn, false); if (rc) goto done; /* @@ -1547,7 +1588,6 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) * we need to check the mgmt queue for nops that need to * be sent to aviod starvation */ - spin_lock_bh(&conn->taskqueuelock); if (!list_empty(&conn->mgmtqueue)) goto check_mgmt; } @@ -1561,21 +1601,18 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) task = list_entry(conn->requeue.next, struct iscsi_task, running); + if (iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_DATA_OUT)) break; + list_del_init(&task->running); conn->task = task; - list_del_init(&conn->task->running); - conn->task->state = ISCSI_TASK_RUNNING; - spin_unlock_bh(&conn->taskqueuelock); - rc = iscsi_xmit_task(conn); + rc = iscsi_xmit_task(conn, true); if (rc) goto done; - spin_lock_bh(&conn->taskqueuelock); if (!list_empty(&conn->mgmtqueue)) goto check_mgmt; } - spin_unlock_bh(&conn->taskqueuelock); spin_unlock_bh(&conn->session->frwd_lock); return -ENODATA; @@ -1741,9 +1778,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto prepd_reject; } } else { - spin_lock_bh(&conn->taskqueuelock); list_add_tail(&task->running, &conn->cmdqueue); - spin_unlock_bh(&conn->taskqueuelock); iscsi_conn_queue_work(conn); } @@ -2914,7 +2949,6 @@ struct iscsi_cls_conn * INIT_LIST_HEAD(&conn->mgmtqueue); INIT_LIST_HEAD(&conn->cmdqueue); INIT_LIST_HEAD(&conn->requeue); - spin_lock_init(&conn->taskqueuelock); INIT_WORK(&conn->xmitwork, iscsi_xmitworker); /* allocate login_task used for the login/text sequences */ @@ -3080,10 +3114,16 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn) ISCSI_DBG_SESSION(conn->session, "failing mgmt itt 0x%x state %d\n", task->itt, task->state); + + spin_lock_bh(&session->back_lock); + if (cleanup_queued_task(task)) { + spin_unlock_bh(&session->back_lock); + continue; + } + state = ISCSI_TASK_ABRT_SESS_RECOV; if (task->state == ISCSI_TASK_PENDING) state = ISCSI_TASK_COMPLETED; - spin_lock_bh(&session->back_lock); iscsi_complete_task(task, state); spin_unlock_bh(&session->back_lock); } diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c index 83f14b2..73b7556 100644 --- a/drivers/scsi/libiscsi_tcp.c +++ b/drivers/scsi/libiscsi_tcp.c @@ -524,48 +524,79 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, struct iscsi_task *task) /** * iscsi_tcp_r2t_rsp - iSCSI R2T Response processing * @conn: iscsi connection - * @task: scsi command task + * @hdr: PDU header */ -static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) +static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr) { struct iscsi_session *session = conn->session; - struct iscsi_tcp_task *tcp_task = task->dd_data; - struct iscsi_tcp_conn *tcp_conn = conn->dd_data; - struct iscsi_r2t_rsp *rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr; + struct iscsi_tcp_task *tcp_task; + struct iscsi_tcp_conn *tcp_conn; + struct iscsi_r2t_rsp *rhdr; struct iscsi_r2t_info *r2t; - int r2tsn = be32_to_cpu(rhdr->r2tsn); + struct iscsi_task *task; u32 data_length; u32 data_offset; + int r2tsn; int rc; + spin_lock(&session->back_lock); + task = iscsi_itt_to_ctask(conn, hdr->itt); + if (!task) { + spin_unlock(&session->back_lock); + return ISCSI_ERR_BAD_ITT; + } else if (task->sc->sc_data_direction != DMA_TO_DEVICE) { + spin_unlock(&session->back_lock); + return ISCSI_ERR_PROTO; + } + /* + * A bad target might complete the cmd before we have handled R2Ts + * so get a ref to the task that will be dropped in the xmit path. + */ + if (task->state != ISCSI_TASK_RUNNING) { + spin_unlock(&session->back_lock); + /* Let the path that got the early rsp complete it */ + return 0; + } + task->last_xfer = jiffies; + __iscsi_get_task(task); + + tcp_conn = conn->dd_data; + rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr; + /* fill-in new R2T associated with the task */ + iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); + spin_unlock(&session->back_lock); + if (tcp_conn->in.datalen) { iscsi_conn_printk(KERN_ERR, conn, "invalid R2t with datalen %d\n", tcp_conn->in.datalen); - return ISCSI_ERR_DATALEN; + rc = ISCSI_ERR_DATALEN; + goto put_task; } + tcp_task = task->dd_data; + r2tsn = be32_to_cpu(rhdr->r2tsn); if (tcp_task->exp_datasn != r2tsn){ ISCSI_DBG_TCP(conn, "task->exp_datasn(%d) != rhdr->r2tsn(%d)\n", tcp_task->exp_datasn, r2tsn); - return ISCSI_ERR_R2TSN; + rc = ISCSI_ERR_R2TSN; + goto put_task; } - /* fill-in new R2T associated with the task */ - iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); - if (!task->sc || session->state != ISCSI_STATE_LOGGED_IN) { iscsi_conn_printk(KERN_INFO, conn, "dropping R2T itt %d in recovery.\n", task->itt); - return 0; + rc = 0; + goto put_task; } data_length = be32_to_cpu(rhdr->data_length); if (data_length == 0) { iscsi_conn_printk(KERN_ERR, conn, "invalid R2T with zero data len\n"); - return ISCSI_ERR_DATALEN; + rc = ISCSI_ERR_DATALEN; + goto put_task; } if (data_length > session->max_burst) @@ -579,7 +610,8 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) "invalid R2T with data len %u at offset %u " "and total length %d\n", data_length, data_offset, task->sc->sdb.length); - return ISCSI_ERR_DATALEN; + rc = ISCSI_ERR_DATALEN; + goto put_task; } spin_lock(&tcp_task->pool2queue); @@ -589,7 +621,8 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) "Target has sent more R2Ts than it " "negotiated for or driver has leaked.\n"); spin_unlock(&tcp_task->pool2queue); - return ISCSI_ERR_PROTO; + rc = ISCSI_ERR_PROTO; + goto put_task; } r2t->exp_statsn = rhdr->statsn; @@ -607,6 +640,10 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) iscsi_requeue_task(task); return 0; + +put_task: + iscsi_put_task(task); + return rc; } /* @@ -730,20 +767,11 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) rc = iscsi_complete_pdu(conn, hdr, NULL, 0); break; case ISCSI_OP_R2T: - spin_lock(&conn->session->back_lock); - task = iscsi_itt_to_ctask(conn, hdr->itt); - spin_unlock(&conn->session->back_lock); - if (!task) - rc = ISCSI_ERR_BAD_ITT; - else if (ahslen) + if (ahslen) { rc = ISCSI_ERR_AHSLEN; - else if (task->sc->sc_data_direction == DMA_TO_DEVICE) { - task->last_xfer = jiffies; - spin_lock(&conn->session->frwd_lock); - rc = iscsi_tcp_r2t_rsp(conn, task); - spin_unlock(&conn->session->frwd_lock); - } else - rc = ISCSI_ERR_PROTO; + break; + } + rc = iscsi_tcp_r2t_rsp(conn, hdr); break; case ISCSI_OP_LOGIN_RSP: case ISCSI_OP_TEXT_RSP: diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index b3bbd10..44a9554 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -187,7 +187,7 @@ struct iscsi_conn { struct iscsi_task *task; /* xmit task in progress */ /* xmit */ - spinlock_t taskqueuelock; /* protects the next three lists */ + /* items must be added/deleted under frwd lock */ struct list_head mgmtqueue; /* mgmt (control) xmit queue */ struct list_head cmdqueue; /* data-path cmd queue */ struct list_head requeue; /* tasks needing another run */ @@ -332,7 +332,7 @@ struct iscsi_session { * cmdsn, queued_cmdsn * * session resources: * * - cmdpool kfifo_out , * - * - mgmtpool, */ + * - mgmtpool, queues */ spinlock_t back_lock; /* protects cmdsn_exp * * cmdsn_max, * * cmdpool kfifo_in */ From patchwork Tue Dec 1 21:29:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1124DC64E7A for ; Tue, 1 Dec 2020 21:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DD872084C for ; Tue, 1 Dec 2020 21:31:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="A29tsKw+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729508AbgLAVbE (ORCPT ); Tue, 1 Dec 2020 16:31:04 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:57258 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729351AbgLAVbD (ORCPT ); Tue, 1 Dec 2020 16:31:03 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSuss081083; Tue, 1 Dec 2020 21:30:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=ehXQMCb33ycHbj70uDNCqe5LWeC6VOCS4FYPjnFs0Bs=; b=A29tsKw+ccZaJZH2uN0m8sYWcqn4frR9S+12bnl7yn247eOGLL+N/AfsmYoFyIgszCng Z2FBHq7B0xJZ33A6yTDpn4KxYV8Ggd8zFMk0A/PEl0u3+052Y8DrPvuNH90e+SRxheDf 30CGmGwNflzxMKwMCwvH+f5g9ENQhoydCslTvTARd0L3PCh61Hz4BYri35aGBi0lTU/u 82PYK7uMuScieV5vCyULMgiQEfi8NuIpk8ysn9sRtp6ZLDb/CmajmqitV3j2Eml+sG/E Wpf9VjZ/1YdLf4XiEadxtLYtt+70Y+a59MYWiVKziJSrS7awW5EYUbQKf9jpWvpGHBQL vQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 353egkmw5c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:12 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LU7kC105739; Tue, 1 Dec 2020 21:30:11 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 3540eyh8ss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:11 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LU6or020966; Tue, 1 Dec 2020 21:30:08 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:06 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 03/15] qla4xxx: use iscsi_is_session_online Date: Tue, 1 Dec 2020 15:29:44 -0600 Message-Id: <1606858196-5421-4-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 bulkscore=0 spamscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org __qla4xxx_is_chap_active just wants to know if a session is online and does not care about why it's not, so this has it use iscsi_is_session_online. This is not a bug now, but the next patch changes the behavior of iscsi_session_chkready so this patch just prepares the driver for that change. Signed-off-by: Mike Christie Reviewed-by: Lee Duncan --- drivers/scsi/qla4xxx/ql4_os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 2c23b69..6996942 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -844,7 +844,7 @@ static int __qla4xxx_is_chap_active(struct device *dev, void *data) sess = cls_session->dd_data; ddb_entry = sess->dd_data; - if (iscsi_session_chkready(cls_session)) + if (iscsi_is_session_online(cls_session)) goto exit_is_chap_active; if (ddb_entry->chap_tbl_idx == *chap_tbl_idx) From patchwork Tue Dec 1 21:29:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A407C64E7B for ; Tue, 1 Dec 2020 21:31:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2569C2084C for ; Tue, 1 Dec 2020 21:31:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="BmEbJHmf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388076AbgLAVbD (ORCPT ); Tue, 1 Dec 2020 16:31:03 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:46688 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727156AbgLAVbC (ORCPT ); Tue, 1 Dec 2020 16:31:02 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LTILo018671; Tue, 1 Dec 2020 21:30:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=00Zr2SVzXyr2MZpcZ6QDW2xtDcP75Hl+13WArqet4o0=; b=BmEbJHmfuhsKsAsVgK4WMX/hGJz11ctHTx9af/m1T5n1bJ4OH+9zjH0T8Gcm2G7mAfgz QkXk6JttUrdeSaS3P/DBsR411CJ43hF0wtH+GGEAtZ3gyUfzKK2h4YP04mlqHfS+0cq2 BL1AWgknSblChu5/vf28wjnztPqzdYUAbzYHjiDP1aT9jlfkwzDsf6ZCEwIeQVYu5PPe iCKJimMp7oL7p45r5IRUMzD5Z4aqxyz+TrWW+H4Zhfekr5KS1Pnfk5J6bFYrsrxHyIsd rkxOdwpRXE1KC6fKFaspRI+0DTvfVmVCEyAIZEpUE4KMM+eHuDbUwknPEabkR7SCMwkh gA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 353dyqmy1y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:10 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LBKsZ163974; Tue, 1 Dec 2020 21:30:09 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 3540fxkwky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:09 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LU7Yd021021; Tue, 1 Dec 2020 21:30:07 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:07 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 04/15] iscsi class: drop session lock in iscsi_session_chkready Date: Tue, 1 Dec 2020 15:29:45 -0600 Message-Id: <1606858196-5421-5-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The session lock in iscsi_session_chkready is not needed because when we transition from logged into to another state we will blocked and/or remove the devices under the session, so no new IO will be sent the drivers after the block/remove. IO that races with the block/removal is cleaned up by the drivers when it handles all outstanding IO, so this just added an extra lock in the main IO path. This patch removes the lock like other transport classes. Signed-off-by: Mike Christie Reviewed-by: Lee Duncan --- drivers/scsi/scsi_transport_iscsi.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 2eb3e4f..e9ad04a 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -1701,10 +1701,8 @@ static const char *iscsi_session_state_name(int state) int iscsi_session_chkready(struct iscsi_cls_session *session) { - unsigned long flags; int err; - spin_lock_irqsave(&session->lock, flags); switch (session->state) { case ISCSI_SESSION_LOGGED_IN: err = 0; @@ -1719,7 +1717,6 @@ int iscsi_session_chkready(struct iscsi_cls_session *session) err = DID_NO_CONNECT << 16; break; } - spin_unlock_irqrestore(&session->lock, flags); return err; } EXPORT_SYMBOL_GPL(iscsi_session_chkready); From patchwork Tue Dec 1 21:29:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B765C83018 for ; Tue, 1 Dec 2020 21:31:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 494592085B for ; Tue, 1 Dec 2020 21:31:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="F3zoV6aT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389283AbgLAVbL (ORCPT ); Tue, 1 Dec 2020 16:31:11 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:40928 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729327AbgLAVbF (ORCPT ); Tue, 1 Dec 2020 16:31:05 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSv9T117396; Tue, 1 Dec 2020 21:30:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=TuSMyR06AJngaYQEVLcVZ1uwHTgOjYsvkm1NtWkIBV0=; b=F3zoV6aTgCfGm6gS8dFfTHFlXxmwjfBS+swQpId+UnLq7+vl1bZH/DKkd9zc4iGTPvcu uwrchGJRWA051wtcZqKwooxfBcJwBeDJsr8ED1kKyieCcvq59FXO7q6FBSoOsxF5P4jy hk2ibcVHsnD+bwVaBZ/WK+sXZm3BGI9XDiC6VbzRsFohxGoDZ9es+Wzi85bRVTEhBDKG Ssd5R539ytabd/pu0xxQfbJkS+7l/Siwl7SFM+T927sq5WnCbWSL0uRc0nmdRx3Pysq0 1NfrWfRaqPrumcDtw1ax6rCXmbTXj6yVUlByqUvvO2iP1i6sdjzvPhafwIXEJSWjeNpj vQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 353c2aw2ub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:09 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LAPgL068020; Tue, 1 Dec 2020 21:30:09 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 35404ndkhd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:09 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0B1LU8Iv018319; Tue, 1 Dec 2020 21:30:08 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:08 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 05/15] libiscsi: remove queued_cmdsn Date: Tue, 1 Dec 2020 15:29:46 -0600 Message-Id: <1606858196-5421-6-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 lowpriorityscore=0 clxscore=1011 bulkscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org queue_cmdsn was meant to prevent cmds from sitting in the cmdqueue too long, but iscsi_eh_cmd_timed_out already handles this. By dropping it and moving the window check to iscsi_data_xmit we will no longer need the frwd lock for the cmdsn for the iscsi xmit wq based drivers. This will be more useful for future patches where we drop the frwd lock from queuecommand for these drivers, but today it only has the benefit that we can now detect when a nop carries the cmdsn info that opens a window. Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 111 +++++++++++++++++++++++++------------------- drivers/scsi/libiscsi_tcp.c | 4 +- include/scsi/libiscsi.h | 10 ++-- 3 files changed, 69 insertions(+), 56 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 7983281..1296a10 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -93,9 +93,31 @@ inline void iscsi_conn_queue_work(struct iscsi_conn *conn) } EXPORT_SYMBOL_GPL(iscsi_conn_queue_work); -static void __iscsi_update_cmdsn(struct iscsi_session *session, - uint32_t exp_cmdsn, uint32_t max_cmdsn) +static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn) +{ + struct iscsi_session *session = conn->session; + + /* make sure we see the updated SNs */ + smp_rmb(); + /* + * Check for iSCSI window and take care of CmdSN wrap-around + */ + if (!iscsi_sna_lte(session->cmdsn, session->max_cmdsn)) { + ISCSI_DBG_SESSION(session, "iSCSI CmdSN closed. ExpCmdSn " + "%u MaxCmdSN %u CmdSN %u\n", + session->exp_cmdsn, session->max_cmdsn, + session->cmdsn); + return -ENOSPC; + } + return 0; +} + +static void __iscsi_update_cmdsn(struct iscsi_conn *conn, uint32_t exp_cmdsn, + uint32_t max_cmdsn) { + struct iscsi_session *session = conn->session; + bool win_closed = false; + /* * standard specifies this check for when to update expected and * max sequence numbers @@ -108,13 +130,22 @@ static void __iscsi_update_cmdsn(struct iscsi_session *session, session->exp_cmdsn = exp_cmdsn; if (max_cmdsn != session->max_cmdsn && - !iscsi_sna_lt(max_cmdsn, session->max_cmdsn)) + !iscsi_sna_lt(max_cmdsn, session->max_cmdsn)) { + + if (iscsi_check_cmdsn_window_closed(conn)) + win_closed = true; + session->max_cmdsn = max_cmdsn; + /* make sure we see the open window from the xmit/queue path */ + smp_wmb(); + if (win_closed) + session->win_opened = true; + } } -void iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr) +void iscsi_update_cmdsn(struct iscsi_conn *conn, struct iscsi_nopin *hdr) { - __iscsi_update_cmdsn(session, be32_to_cpu(hdr->exp_cmdsn), + __iscsi_update_cmdsn(conn, be32_to_cpu(hdr->exp_cmdsn), be32_to_cpu(hdr->max_cmdsn)); } EXPORT_SYMBOL_GPL(iscsi_update_cmdsn); @@ -424,14 +455,15 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) task->state = ISCSI_TASK_RUNNING; session->cmdsn++; + /* make sure window checkers see the update */ + smp_wmb(); conn->scsicmd_pdus_cnt++; ISCSI_DBG_SESSION(session, "iscsi prep [%s cid %d sc %p cdb 0x%x " "itt 0x%x len %d cmdsn %d win %d]\n", sc->sc_data_direction == DMA_TO_DEVICE ? "write" : "read", conn->id, sc, sc->cmnd[0], - task->itt, transfer_length, - session->cmdsn, + task->itt, transfer_length, session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1); return 0; } @@ -465,6 +497,11 @@ static void iscsi_free_task(struct iscsi_task *task) kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*)); + if (session->win_opened && !work_pending(&conn->xmitwork)) { + session->win_opened = false; + iscsi_conn_queue_work(conn); + } + if (sc) { /* SCSI eh reuses commands to verify us */ sc->SCp.ptr = NULL; @@ -549,7 +586,7 @@ void iscsi_complete_scsi_task(struct iscsi_task *task, ISCSI_DBG_SESSION(conn->session, "[itt 0x%x]\n", task->itt); conn->last_recv = jiffies; - __iscsi_update_cmdsn(conn->session, exp_cmdsn, max_cmdsn); + __iscsi_update_cmdsn(conn, exp_cmdsn, max_cmdsn); iscsi_complete_task(task, ISCSI_TASK_COMPLETED); } EXPORT_SYMBOL_GPL(iscsi_complete_scsi_task); @@ -613,11 +650,6 @@ static void fail_scsi_task(struct iscsi_task *task, int err) } if (task->state == ISCSI_TASK_PENDING) { - /* - * cmd never made it to the xmit thread, so we should not count - * the cmd in the sequencing - */ - conn->session->queued_cmdsn--; /* it was never sent so just complete like normal */ state = ISCSI_TASK_COMPLETED; } else if (err == DID_TRANSPORT_DISRUPTED) @@ -658,10 +690,8 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, * but we always only send one PDU at a time. */ if (conn->c_stage == ISCSI_CONN_STARTED && - !(hdr->opcode & ISCSI_OP_IMMEDIATE)) { - session->queued_cmdsn++; + !(hdr->opcode & ISCSI_OP_IMMEDIATE)) session->cmdsn++; - } } if (session->tt->init_task && session->tt->init_task(task)) @@ -820,7 +850,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, struct iscsi_session *session = conn->session; struct scsi_cmnd *sc = task->sc; - iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)rhdr); conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; sc->result = (DID_OK << 16) | rhdr->cmd_status; @@ -920,7 +950,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, if (!(rhdr->flags & ISCSI_FLAG_DATA_STATUS)) return; - iscsi_update_cmdsn(conn->session, (struct iscsi_nopin *)hdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin *)hdr); sc->result = (DID_OK << 16) | rhdr->cmd_status; conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; if (rhdr->flags & (ISCSI_FLAG_DATA_UNDERFLOW | @@ -1172,7 +1202,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, opcode, conn->id, itt, datalen); if (itt == ~0U) { - iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)hdr); switch(opcode) { case ISCSI_OP_NOOP_IN: @@ -1240,7 +1270,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, iscsi_data_in_rsp(conn, hdr, task); break; case ISCSI_OP_LOGOUT_RSP: - iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)hdr); if (datalen) { rc = ISCSI_ERR_PROTO; break; @@ -1249,14 +1279,14 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, goto recv_pdu; case ISCSI_OP_LOGIN_RSP: case ISCSI_OP_TEXT_RSP: - iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)hdr); /* * login related PDU's exp_statsn is handled in * userspace */ goto recv_pdu; case ISCSI_OP_SCSI_TMFUNC_RSP: - iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)hdr); if (datalen) { rc = ISCSI_ERR_PROTO; break; @@ -1266,7 +1296,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, iscsi_complete_task(task, ISCSI_TASK_COMPLETED); break; case ISCSI_OP_NOOP_IN: - iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)hdr); if (hdr->ttt != cpu_to_be32(ISCSI_RESERVED_TAG) || datalen) { rc = ISCSI_ERR_PROTO; break; @@ -1416,23 +1446,6 @@ void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err) } EXPORT_SYMBOL_GPL(iscsi_conn_failure); -static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn) -{ - struct iscsi_session *session = conn->session; - - /* - * Check for iSCSI window and take care of CmdSN wrap-around - */ - if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) { - ISCSI_DBG_SESSION(session, "iSCSI CmdSN closed. ExpCmdSn " - "%u MaxCmdSN %u CmdSN %u/%u\n", - session->exp_cmdsn, session->max_cmdsn, - session->cmdsn, session->queued_cmdsn); - return -ENOSPC; - } - return 0; -} - static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref) { struct iscsi_task *task = conn->task; @@ -1564,6 +1577,10 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) /* process pending command queue */ while (!list_empty(&conn->cmdqueue)) { + rc = iscsi_check_cmdsn_window_closed(conn); + if (rc) + goto done; + task = list_entry(conn->cmdqueue.next, struct iscsi_task, running); list_del_init(&task->running); @@ -1750,11 +1767,6 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto fault; } - if (iscsi_check_cmdsn_window_closed(conn)) { - reason = FAILURE_WINDOW_CLOSED; - goto reject; - } - task = iscsi_alloc_task(conn, sc); if (!task) { reason = FAILURE_OOM; @@ -1762,6 +1774,11 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) } if (!ihost->workq) { + if (iscsi_check_cmdsn_window_closed(conn)) { + reason = FAILURE_WINDOW_CLOSED; + goto prepd_reject; + } + reason = iscsi_prep_scsi_cmd_pdu(task); if (reason) { if (reason == -ENOMEM || reason == -EACCES) { @@ -1782,7 +1799,6 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) iscsi_conn_queue_work(conn); } - session->queued_cmdsn++; spin_unlock_bh(&session->frwd_lock); return 0; @@ -2831,7 +2847,7 @@ struct iscsi_cls_session * session->abort_timeout = 10; session->scsi_cmds_max = scsi_cmds; session->cmds_max = total_cmds; - session->queued_cmdsn = session->cmdsn = initial_cmdsn; + session->cmdsn = initial_cmdsn; session->exp_cmdsn = initial_cmdsn + 1; session->max_cmdsn = initial_cmdsn + 1; session->max_r2t = 1; @@ -3063,7 +3079,6 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn) spin_lock_bh(&session->frwd_lock); conn->c_stage = ISCSI_CONN_STARTED; session->state = ISCSI_STATE_LOGGED_IN; - session->queued_cmdsn = session->cmdsn; conn->last_recv = jiffies; conn->last_ping = jiffies; diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c index 73b7556..916148c 100644 --- a/drivers/scsi/libiscsi_tcp.c +++ b/drivers/scsi/libiscsi_tcp.c @@ -496,7 +496,7 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, struct iscsi_task *task) * is status. */ if (!(rhdr->flags & ISCSI_FLAG_DATA_STATUS)) - iscsi_update_cmdsn(conn->session, (struct iscsi_nopin*)rhdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)rhdr); if (tcp_conn->in.datalen == 0) return 0; @@ -563,7 +563,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr) tcp_conn = conn->dd_data; rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr; /* fill-in new R2T associated with the task */ - iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); + iscsi_update_cmdsn(conn, (struct iscsi_nopin*)rhdr); spin_unlock(&session->back_lock); if (tcp_conn->in.datalen) { diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 44a9554..b649ec5 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -275,9 +275,7 @@ struct iscsi_session { uint32_t cmdsn; uint32_t exp_cmdsn; uint32_t max_cmdsn; - - /* This tracks the reqs queued into the initiator */ - uint32_t queued_cmdsn; + bool win_opened; /* configuration */ int abort_timeout; @@ -329,8 +327,8 @@ struct iscsi_session { * but not vice versa. */ spinlock_t frwd_lock; /* protects session state, * - * cmdsn, queued_cmdsn * - * session resources: * + * cmdsn and session * + * resources: * * - cmdpool kfifo_out , * * - mgmtpool, queues */ spinlock_t back_lock; /* protects cmdsn_exp * @@ -440,7 +438,7 @@ extern int iscsi_conn_get_addr_param(struct sockaddr_storage *addr, /* * pdu and task processing */ -extern void iscsi_update_cmdsn(struct iscsi_session *, struct iscsi_nopin *); +extern void iscsi_update_cmdsn(struct iscsi_conn *, struct iscsi_nopin *); extern void iscsi_prep_data_out_pdu(struct iscsi_task *task, struct iscsi_r2t_info *r2t, struct iscsi_data *hdr); From patchwork Tue Dec 1 21:29:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2BFDC71155 for ; Tue, 1 Dec 2020 21:31:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62B172086A for ; Tue, 1 Dec 2020 21:31:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="pOZbGUaJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388128AbgLAVbD (ORCPT ); Tue, 1 Dec 2020 16:31:03 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:57246 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729335AbgLAVbC (ORCPT ); Tue, 1 Dec 2020 16:31:02 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSuTP081049; Tue, 1 Dec 2020 21:30:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=fkRovDNiYxLoydWfMZ9RPNbtQ5bCCtqKzQ4tk6IreQM=; b=pOZbGUaJVzWYWZk7mE2nbk4UyJzSJ5HDRpr6mH74dGG0Y6LDwXOGrUwoS4XVJAC3Dxcm JTFFgYbihJSJrgvPfNvvMixTCnlIThu1lYZgEZA+w+D63ku2+v5ayVJR9wGhdbmutBXT Yon4zhx9Vi+0stCGzhZrVoF9sDRUXLrgjOvVbj/lLgzJ5AlPY5x73TD7kafXTyTlqVEO dX9Z4LFA8WeB9b+LU5OXGnou8vwp62rZkzPQ1H48CEHuAqP2p1nkpRPOUVR8rhEL8emy Lcmcu+p567jthBWQEJ+cgUtNYLl/FK1jN7UsyZ2d8zgMmg1RY4dIyZSAA1CtmWFtph4Q iQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 353egkmw5d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:13 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LBL7C164011; Tue, 1 Dec 2020 21:30:12 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 3540fxkwpr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:12 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LU9qU021009; Tue, 1 Dec 2020 21:30:11 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:08 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 06/15] libiscsi: drop frwd lock for session state Date: Tue, 1 Dec 2020 15:29:47 -0600 Message-Id: <1606858196-5421-7-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This drops the frwd lock for the session state checks in queuecommand. Like with the transport class case, we only need it as a hint since when the session is cleaned up we will block the session which flushes the queues, and then we clean up all running IO. So the locking just prevents cleaning up extra cmds. It is still needed: 1. when accessing suspend_tx in queuecomand because drivers that implement ep_disconnect will set that bit from disconnect (called before stop) and expect that no new commands will be queued to it. Note that the comment for this was wrong and that is fixed in this patch. 2. the list addition for the drivers that use the iscsi xmit wq. Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 10 +++++++--- include/scsi/libiscsi.h | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 1296a10..12bfb5a 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -1704,7 +1704,6 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) cls_session = starget_to_session(scsi_target(sc->device)); session = cls_session->dd_data; - spin_lock_bh(&session->frwd_lock); reason = iscsi_session_chkready(cls_session); if (reason) { @@ -1761,7 +1760,9 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto fault; } + spin_lock_bh(&session->frwd_lock); if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) { + spin_unlock_bh(&session->frwd_lock); reason = FAILURE_SESSION_IN_RECOVERY; sc->result = DID_REQUEUE << 16; goto fault; @@ -1769,6 +1770,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) task = iscsi_alloc_task(conn, sc); if (!task) { + spin_unlock_bh(&session->frwd_lock); reason = FAILURE_OOM; goto reject; } @@ -1803,21 +1805,23 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) return 0; prepd_reject: + spin_unlock_bh(&session->frwd_lock); + spin_lock_bh(&session->back_lock); iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ); spin_unlock_bh(&session->back_lock); reject: - spin_unlock_bh(&session->frwd_lock); ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n", sc->cmnd[0], reason); return SCSI_MLQUEUE_TARGET_BUSY; prepd_fault: + spin_unlock_bh(&session->frwd_lock); + spin_lock_bh(&session->back_lock); iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ); spin_unlock_bh(&session->back_lock); fault: - spin_unlock_bh(&session->frwd_lock); ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n", sc->cmnd[0], reason); scsi_set_resid(sc, scsi_bufflen(sc)); diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index b649ec5..25dbc5d 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -326,8 +326,9 @@ struct iscsi_session { * can enclose the mutual exclusion zone protected by the backward lock * but not vice versa. */ - spinlock_t frwd_lock; /* protects session state, * - * cmdsn and session * + spinlock_t frwd_lock; /* protects session state * + * in the eh paths, cmdsn * + * suspend bit and session * * resources: * * - cmdpool kfifo_out , * * - mgmtpool, queues */ From patchwork Tue Dec 1 21:29:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 638FAC83019 for ; Tue, 1 Dec 2020 21:31:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BAA920870 for ; Tue, 1 Dec 2020 21:31:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="qd0KafeC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389080AbgLAVbL (ORCPT ); Tue, 1 Dec 2020 16:31:11 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:40964 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727156AbgLAVbG (ORCPT ); Tue, 1 Dec 2020 16:31:06 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSxw7117496; Tue, 1 Dec 2020 21:30:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=TTQ2l6JpeRTEZsc0JSxNF1TB5mKjyLCqrKgLCkDxZd4=; b=qd0KafeCWmvSjGhxmFDHMU+6v26ffd8wMgH6I75LVb0vDnsBvLMH7FgezW+Vih06q/1o RF/a0N/4fTF2ay7ytXQc8Rd1PdWfgQ5ew3S+gBTToyZdyUAbq25tmmB0+lNpaMDjN4jD fSR0PVEqB7PcAtJvip3xdwb08rLg1vMYwKlkTNn4d0XzA15mTXWY9dXECAocsPK2NDlD cUqr0Zlu+4qw0t3dMl8jj4QMNrA6KUkYePm75OEpGfwdyX9fVs21/7oZiCMxmVOYF9qZ +5USeohxUJ7mCMoHhyyiUmIlbTUGNKhKmykg+/C7xN80F6BWE9Brn4nS0P/n7hJ6OzfX 0g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 353c2aw2uk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:11 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LBKkk163781; Tue, 1 Dec 2020 21:30:11 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 3540fxkwnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:10 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0B1LU9r4018335; Tue, 1 Dec 2020 21:30:09 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:09 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 07/15] libiscsi: separate itt from task allocation Date: Tue, 1 Dec 2020 15:29:48 -0600 Message-Id: <1606858196-5421-8-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=2 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 lowpriorityscore=0 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The next patches has libiscsi use the blk/scsi mq scsi cmd preallocation callouts to allocate the iscsi_task and the LLD's per task data so libiscsi does not have to add extra locking to manage it's cmd pool for scsi cmds. This means we need to separate the itt allocation and lookup from the task allocation. In this patch we just use a sbitmap. Signed-off-by: Mike Christie --- drivers/scsi/be2iscsi/be_main.c | 2 +- drivers/scsi/libiscsi.c | 131 ++++++++++++++++++++++++++++++++++------ include/scsi/libiscsi.h | 2 + 3 files changed, 115 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c index 202ba92..cd3189b 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -306,7 +306,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) spin_lock(&session->back_lock); for (i = 0; i < conn->session->cmds_max; i++) { task = conn->session->cmds[i]; - if (!task->sc) + if (!task || !task->sc) continue; if (sc->device->lun != task->sc->device->lun) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 12bfb5a..5942d2a 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -328,6 +328,43 @@ static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode) return 0; } +static int iscsi_alloc_itt(struct iscsi_session *session, + struct iscsi_task *task) +{ + int itt; + + itt = sbitmap_get(&session->itts, 0, false); + if (itt < 0) { + iscsi_session_printk(KERN_ERR, session, + "Could not allocate ITT\n"); + return -ENOMEM; + } + + task->itt = itt; + session->cmds[itt] = task; + /* + * If the code path is not holding the frwd and back locks and doing + * a lookup make sure it sees the update. + */ + smp_wmb(); + return 0; +} + +static void iscsi_free_itt(struct iscsi_session *session, + struct iscsi_task *task) +{ + /* + * We don't need a barrier in this path because it's run from the + * itt alloc path or from lookup which has the barrier already. + */ + if (task->itt == ISCSI_RESERVED_TAG) + return; + + session->cmds[task->itt] = NULL; + sbitmap_clear_bit(&session->itts, task->itt); + task->itt = ISCSI_RESERVED_TAG; +} + /** * iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu * @task: iscsi task @@ -349,10 +386,14 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) if (rc) return rc; + rc = iscsi_alloc_itt(session, task); + if (rc) + return rc; + if (conn->session->tt->alloc_pdu) { rc = conn->session->tt->alloc_pdu(task, ISCSI_OP_SCSI_CMD); if (rc) - return rc; + goto free_itt; } hdr = (struct iscsi_scsi_req *)task->hdr; itt = hdr->itt; @@ -366,7 +407,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) task->hdr_len = 0; rc = iscsi_add_hdr(task, sizeof(*hdr)); if (rc) - return rc; + goto free_itt; hdr->opcode = ISCSI_OP_SCSI_CMD; hdr->flags = ISCSI_ATTR_SIMPLE; int_to_scsilun(sc->device->lun, &hdr->lun); @@ -378,7 +419,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) else if (cmd_len > ISCSI_CDB_SIZE) { rc = iscsi_prep_ecdb_ahs(task); if (rc) - return rc; + goto free_itt; cmd_len = ISCSI_CDB_SIZE; } memcpy(hdr->cdb, sc->cmnd, cmd_len); @@ -450,8 +491,10 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) hdr->hlength = hdrlength & 0xFF; hdr->cmdsn = task->cmdsn = cpu_to_be32(session->cmdsn); - if (session->tt->init_task && session->tt->init_task(task)) - return -EIO; + if (session->tt->init_task && session->tt->init_task(task)) { + rc = -EIO; + goto free_itt; + } task->state = ISCSI_TASK_RUNNING; session->cmdsn++; @@ -466,6 +509,14 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) task->itt, transfer_length, session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1); return 0; + +free_itt: + iscsi_free_itt(session, task); + /* + * The resources allocated in the LLD callouts will be freed by + * the caller's cleanup_task call. + */ + return rc; } /** @@ -495,6 +546,7 @@ static void iscsi_free_task(struct iscsi_task *task) if (conn->login_task == task) return; + iscsi_free_itt(session, task); kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*)); if (session->win_opened && !work_pending(&conn->xmitwork)) { @@ -754,6 +806,14 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, if (!kfifo_out(&session->cmdpool.queue, (void*)&task, sizeof(void*))) return NULL; + + if (iscsi_alloc_itt(session, task)) { + spin_lock(&session->back_lock); + kfifo_in(&session->cmdpool.queue, (void*)&task, + sizeof(void*)); + spin_unlock(&session->back_lock); + return NULL; + } } /* * released in complete pdu for task we expect a response for, and @@ -1164,8 +1224,9 @@ struct iscsi_task *iscsi_itt_to_task(struct iscsi_conn *conn, itt_t itt) i = get_itt(itt); if (i >= session->cmds_max) return NULL; - - return session->cmds[i]; + /* make sure we see the map addition */ + smp_rmb(); + return (session->cmds[i]); } EXPORT_SYMBOL_GPL(iscsi_itt_to_task); @@ -1664,6 +1725,7 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn, sc->SCp.ptr = (char *) task; refcount_set(&task->refcount, 1); + task->itt = ISCSI_RESERVED_TAG; task->state = ISCSI_TASK_PENDING; task->conn = conn; task->sc = sc; @@ -1915,7 +1977,7 @@ static void fail_scsi_tasks(struct iscsi_conn *conn, u64 lun, int error) for (i = 0; i < conn->session->cmds_max; i++) { task = conn->session->cmds[i]; - if (!task->sc || task->state == ISCSI_TASK_FREE) + if (!task || !task->sc || task->state == ISCSI_TASK_FREE) continue; if (lun != -1 && lun != task->sc->device->lun) @@ -2072,7 +2134,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc) for (i = 0; i < conn->session->cmds_max; i++) { running_task = conn->session->cmds[i]; - if (!running_task->sc || running_task == task || + if (!running_task || !running_task->sc || running_task == task || running_task->state != ISCSI_TASK_RUNNING) continue; @@ -2794,6 +2856,7 @@ struct iscsi_cls_session * struct iscsi_session *session; struct iscsi_cls_session *cls_session; int cmd_i, scsi_cmds, total_cmds = cmds_max; + struct iscsi_task *task; unsigned long flags; spin_lock_irqsave(&ihost->lock, flags); @@ -2862,23 +2925,41 @@ struct iscsi_cls_session * spin_lock_init(&session->frwd_lock); spin_lock_init(&session->back_lock); + if (sbitmap_init_node(&session->itts, session->cmds_max, -1, + GFP_KERNEL, NUMA_NO_NODE)) + goto itts_fail; + + session->cmds = kcalloc(session->cmds_max, sizeof(struct iscsi_task *), + GFP_KERNEL); + if (!session->cmds) + goto cmds_alloc_fail; + /* initialize SCSI PDU commands pool */ - if (iscsi_pool_init(&session->cmdpool, session->cmds_max, - (void***)&session->cmds, + if (iscsi_pool_init(&session->cmdpool, session->cmds_max, NULL, cmd_task_size + sizeof(struct iscsi_task))) goto cmdpool_alloc_fail; - /* pre-format cmds pool with ITT */ - for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { - struct iscsi_task *task = session->cmds[cmd_i]; + /* + * This is a temp change to allow drivers that prealloc task resources + * during session setup to continue to work. The next patches convert + * the drivers to use the blk/scsi-ml init/exit callouts then this + * will be removed. + */ + while (kfifo_out(&session->cmdpool.queue, (void *) &task, + sizeof(void *))) { + session->cmds[cmd_i++] = task; if (cmd_task_size) task->dd_data = &task[1]; - task->itt = cmd_i; task->state = ISCSI_TASK_FREE; INIT_LIST_HEAD(&task->running); } + for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { + task = session->cmds[cmd_i]; + kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*)); + } + if (!try_module_get(iscsit->owner)) goto module_get_fail; @@ -2892,6 +2973,10 @@ struct iscsi_cls_session * module_get_fail: iscsi_pool_free(&session->cmdpool); cmdpool_alloc_fail: + kfree(session->cmds); +cmds_alloc_fail: + sbitmap_free(&session->itts); +itts_fail: iscsi_free_session(cls_session); dec_session_count: iscsi_host_dec_session_cnt(shost); @@ -2927,6 +3012,9 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session) kfree(session->portal_type); kfree(session->discovery_parent_type); + kfree(session->cmds); + sbitmap_free(&session->itts); + iscsi_free_session(cls_session); iscsi_host_dec_session_cnt(shost); @@ -2981,6 +3069,9 @@ struct iscsi_cls_conn * } spin_unlock_bh(&session->frwd_lock); + if (iscsi_alloc_itt(session, conn->login_task)) + goto login_itt_fail; + data = (char *) __get_free_pages(GFP_KERNEL, get_order(ISCSI_DEF_MAX_RECV_SEG_LEN)); if (!data) @@ -2993,8 +3084,12 @@ struct iscsi_cls_conn * return cls_conn; login_task_data_alloc_fail: + iscsi_free_itt(session, conn->login_task); +login_itt_fail: + spin_lock_bh(&session->frwd_lock); kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, sizeof(void*)); + spin_unlock_bh(&session->frwd_lock); login_task_alloc_fail: iscsi_destroy_conn(cls_conn); return NULL; @@ -3040,6 +3135,7 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn) kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, sizeof(void*)); spin_unlock_bh(&session->back_lock); + iscsi_free_itt(session, conn->login_task); if (session->leadconn == conn) session->leadconn = NULL; spin_unlock_bh(&session->frwd_lock); @@ -3124,10 +3220,7 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn) for (i = 0; i < conn->session->cmds_max; i++) { task = conn->session->cmds[i]; - if (task->sc) - continue; - - if (task->state == ISCSI_TASK_FREE) + if (!task || task->sc || task->state == ISCSI_TASK_FREE) continue; ISCSI_DBG_SESSION(conn->session, diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 25dbc5d..e918af7 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -342,6 +343,7 @@ struct iscsi_session { int cmds_max; /* size of cmds array */ struct iscsi_task **cmds; /* Original Cmds arr */ struct iscsi_pool cmdpool; /* PDU's pool */ + struct sbitmap itts; void *dd_data; /* LLD private data */ }; From patchwork Tue Dec 1 21:29:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D823FC83014 for ; Tue, 1 Dec 2020 21:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AC4B2084C for ; Tue, 1 Dec 2020 21:31:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="va1tVhGK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388547AbgLAVbE (ORCPT ); Tue, 1 Dec 2020 16:31:04 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:46690 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729276AbgLAVbC (ORCPT ); Tue, 1 Dec 2020 16:31:02 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LTSZL019066; Tue, 1 Dec 2020 21:30:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=WXTJyZ7YhzW2sn1TTiainNRd9+fFo7YBpgxjXDod+nI=; b=va1tVhGKfYUGYZ9xE3AoNrZvkPMsoQRGo5K6crs9mi31AElTDHqZvBwqcjTgUZDsVWmh iqRqX4/BYsryu6o79jLUOzwvzKjpUwcl3sfMaTe1R/DwRjl/df5vfXICiGnAt5CJzIdL Zn/R49VyIA2KEDlwnqnwLSkNao1MYdE96r6YkaZyMQngknlDP+taxNAKdqdrOZpo2y4j xODtIl6AkWsI3+U4qNXOi8YcQZJPK8JvBIDwzNLv+093nqHnQag8mMWNzK58iHBzye9j tnhvTdztS8C7teAIg3K9aBn3wwLzzXm7VNmeIeyMpPFzuOCQaZa8aZSBKdUF/pEwX8Gk qg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 353dyqmy26-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:12 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LAP5g068034; Tue, 1 Dec 2020 21:30:11 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 35404ndkkt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:11 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0B1LUA6c018348; Tue, 1 Dec 2020 21:30:10 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:10 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 08/15] iser, be2iscsi, qla4xxx: set scsi_host_template cmd_size Date: Tue, 1 Dec 2020 15:29:49 -0600 Message-Id: <1606858196-5421-9-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=2 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver. This patch includes the easy drivers that just needed to set the size and a helper to init the iscsi task. Signed-off-by: Mike Christie --- drivers/infiniband/ulp/iser/iscsi_iser.c | 3 +++ drivers/scsi/be2iscsi/be_main.c | 2 ++ drivers/scsi/libiscsi.c | 17 +++++++++++++++++ drivers/scsi/qla4xxx/ql4_os.c | 3 +++ include/scsi/libiscsi.h | 1 + 5 files changed, 26 insertions(+) diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index 3690e28..96f44eb 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c @@ -976,6 +976,9 @@ static umode_t iser_attr_is_visible(int param_type, int param) .proc_name = "iscsi_iser", .this_id = -1, .track_queue_depth = 1, + .cmd_size = sizeof(struct iscsi_iser_task) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_init_cmd_priv, }; static struct iscsi_transport iscsi_iser_transport = { diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c index cd3189b..91bc822 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -401,6 +401,8 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) .cmd_per_lun = BEISCSI_CMD_PER_LUN, .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, .track_queue_depth = 1, + .cmd_size = sizeof(struct beiscsi_io_task) + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_init_cmd_priv, }; static struct scsi_transport_template *beiscsi_scsi_transport; diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 5942d2a..ea1ef77 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -2830,6 +2830,23 @@ static void iscsi_host_dec_session_cnt(struct Scsi_Host *shost) scsi_host_put(shost); } +static void iscsi_init_task(struct iscsi_task *task) +{ + task->dd_data = &task[1]; + task->itt = ISCSI_RESERVED_TAG; + task->state = ISCSI_TASK_FREE; + INIT_LIST_HEAD(&task->running); +} + +int iscsi_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc) +{ + struct iscsi_task *task = scsi_cmd_priv(sc); + + iscsi_init_task(task); + return 0; +} +EXPORT_SYMBOL_GPL(iscsi_init_cmd_priv); + /** * iscsi_session_setup - create iscsi cls session and host and session * @iscsit: iscsi transport template diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 6996942..c20b7c3 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -239,6 +239,9 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, .this_id = -1, .cmd_per_lun = 3, .sg_tablesize = SG_ALL, + .cmd_size = sizeof(struct ql4_task_data) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_init_cmd_priv, .max_sectors = 0xFFFF, .shost_attrs = qla4xxx_host_attrs, diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index e918af7..c2283f9 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -460,6 +460,7 @@ extern int __iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *, extern void __iscsi_get_task(struct iscsi_task *task); extern void iscsi_complete_scsi_task(struct iscsi_task *task, uint32_t exp_cmdsn, uint32_t max_cmdsn); +extern int iscsi_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd); /* * generic helpers From patchwork Tue Dec 1 21:29:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B688C71156 for ; Tue, 1 Dec 2020 21:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 210AE2084C for ; Tue, 1 Dec 2020 21:31:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FUqTY0Wl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389005AbgLAVbH (ORCPT ); Tue, 1 Dec 2020 16:31:07 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:40954 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729391AbgLAVbE (ORCPT ); Tue, 1 Dec 2020 16:31:04 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSvHX117414; Tue, 1 Dec 2020 21:30:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=HjkZFHCL97gQAaLadNeOxv8/FepV0n+q0a+Z+yEywL0=; b=FUqTY0Wl/9KHZ3TLtu43RCkJy+gPlF04qzKYbLCPEe6iUL4tljFQUPBPLiuEdSQCu3k0 umhSSxI/3LPjOXcvXLbz1lLqCoJ9ABWoXXyURmEqSLAKDtY55uCwhy1jjTfziuGQ2GEV hf75EeeGVl/qGRBHCdXt5ib+Tb11BokvqSfUKECR3Xf8nOEkErNha6tO7dWoA0/XPQQT Sc2BVOMgYZD3aWI9i2uG2cHJRQl30NSydfAmBzg/72CMEamhD8YwzuW7+coldw62AzIr ULjB7XOpeWwuOewR4np+bjewfqBQ2xY/2hrFnjcFP5GVdeRovoW8GXgvYf+Q9lYJ+ZzU OQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 353c2aw2ur-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:13 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LAOSB067967; Tue, 1 Dec 2020 21:30:13 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 35404ndkn4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:13 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LUBHl021073; Tue, 1 Dec 2020 21:30:11 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:11 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 09/15] bnx2i: set scsi_host_template cmd_size Date: Tue, 1 Dec 2020 15:29:50 -0600 Message-Id: <1606858196-5421-10-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 lowpriorityscore=0 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver. Signed-off-by: Mike Christie --- drivers/scsi/bnx2i/bnx2i_iscsi.c | 112 +++++++++++---------------------------- 1 file changed, 30 insertions(+), 82 deletions(-) diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c index fdd4467..d523382 100644 --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c @@ -438,11 +438,9 @@ static void bnx2i_free_ep(struct iscsi_endpoint *ep) /** * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command * @hba: adapter instance pointer - * @session: iscsi session pointer * @cmd: iscsi command structure */ -static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct iscsi_session *session, - struct bnx2i_cmd *cmd) +static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd) { struct io_bdt *io = &cmd->io_tbl; struct iscsi_bd *bd; @@ -451,68 +449,44 @@ static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct iscsi_session *session, ISCSI_MAX_BDS_PER_CMD * sizeof(*bd), &io->bd_tbl_dma, GFP_KERNEL); if (!io->bd_tbl) { - iscsi_session_printk(KERN_ERR, session, "Could not " - "allocate bdt.\n"); + shost_printk(KERN_ERR, hba->shost, "Could not allocate bdt.\n"); return -ENOMEM; } io->bd_valid = 0; return 0; } -/** - * bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table - * @hba: adapter instance pointer - * @session: iscsi session pointer - */ -static void bnx2i_destroy_cmd_pool(struct bnx2i_hba *hba, - struct iscsi_session *session) +static int bnx2i_exit_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc) { - int i; - - for (i = 0; i < session->cmds_max; i++) { - struct iscsi_task *task = session->cmds[i]; - struct bnx2i_cmd *cmd = task->dd_data; + struct bnx2i_hba *hba = iscsi_host_priv(shost); + struct iscsi_task *task = scsi_cmd_priv(sc); + struct bnx2i_cmd *cmd = task->dd_data; - if (cmd->io_tbl.bd_tbl) - dma_free_coherent(&hba->pcidev->dev, - ISCSI_MAX_BDS_PER_CMD * - sizeof(struct iscsi_bd), - cmd->io_tbl.bd_tbl, - cmd->io_tbl.bd_tbl_dma); - } + if (!cmd->io_tbl.bd_tbl) + return 0; + dma_free_coherent(&hba->pcidev->dev, + ISCSI_MAX_BDS_PER_CMD * sizeof(struct iscsi_bd), + cmd->io_tbl.bd_tbl, cmd->io_tbl.bd_tbl_dma); + return 0; } - -/** - * bnx2i_setup_cmd_pool - sets up iscsi command pool for the session - * @hba: adapter instance pointer - * @session: iscsi session pointer - */ -static int bnx2i_setup_cmd_pool(struct bnx2i_hba *hba, - struct iscsi_session *session) +static int bnx2i_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc) { - int i; - - for (i = 0; i < session->cmds_max; i++) { - struct iscsi_task *task = session->cmds[i]; - struct bnx2i_cmd *cmd = task->dd_data; - - task->hdr = &cmd->hdr; - task->hdr_max = sizeof(struct iscsi_hdr); + struct bnx2i_hba *hba = iscsi_host_priv(shost); + struct iscsi_task *task; + struct bnx2i_cmd *cmd; - if (bnx2i_alloc_bdt(hba, session, cmd)) - goto free_bdts; - } + iscsi_init_cmd_priv(shost, sc); - return 0; + task = scsi_cmd_priv(sc); + cmd = task->dd_data; + task->hdr = &cmd->hdr; + task->hdr_max = sizeof(struct iscsi_hdr); -free_bdts: - bnx2i_destroy_cmd_pool(hba, session); - return -ENOMEM; + return bnx2i_alloc_bdt(hba, cmd); } - /** * bnx2i_setup_mp_bdt - allocate BD table resources * @hba: pointer to adapter structure @@ -1288,7 +1262,6 @@ static int bnx2i_task_xmit(struct iscsi_task *task) uint32_t initial_cmdsn) { struct Scsi_Host *shost; - struct iscsi_cls_session *cls_session; struct bnx2i_hba *hba; struct bnx2i_endpoint *bnx2i_ep; @@ -1312,40 +1285,11 @@ static int bnx2i_task_xmit(struct iscsi_task *task) else if (cmds_max < BNX2I_SQ_WQES_MIN) cmds_max = BNX2I_SQ_WQES_MIN; - cls_session = iscsi_session_setup(&bnx2i_iscsi_transport, shost, - cmds_max, 0, sizeof(struct bnx2i_cmd), - initial_cmdsn, ISCSI_MAX_TARGET); - if (!cls_session) - return NULL; - - if (bnx2i_setup_cmd_pool(hba, cls_session->dd_data)) - goto session_teardown; - return cls_session; - -session_teardown: - iscsi_session_teardown(cls_session); - return NULL; + return iscsi_session_setup(&bnx2i_iscsi_transport, shost, + cmds_max, 0, sizeof(struct bnx2i_cmd), + initial_cmdsn, ISCSI_MAX_TARGET); } - -/** - * bnx2i_session_destroy - destroys iscsi session - * @cls_session: pointer to iscsi cls session - * - * Destroys previously created iSCSI session instance and releases - * all resources held by it - */ -static void bnx2i_session_destroy(struct iscsi_cls_session *cls_session) -{ - struct iscsi_session *session = cls_session->dd_data; - struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); - struct bnx2i_hba *hba = iscsi_host_priv(shost); - - bnx2i_destroy_cmd_pool(hba, session); - iscsi_session_teardown(cls_session); -} - - /** * bnx2i_conn_create - create iscsi connection instance * @cls_session: pointer to iscsi cls session @@ -2265,6 +2209,10 @@ static umode_t bnx2i_attr_is_visible(int param_type, int param) .sg_tablesize = ISCSI_MAX_BDS_PER_CMD, .shost_attrs = bnx2i_dev_attributes, .track_queue_depth = 1, + .cmd_size = sizeof(struct bnx2i_cmd) + + sizeof(struct iscsi_task), + .init_cmd_priv = bnx2i_init_cmd_priv, + .exit_cmd_priv = bnx2i_exit_cmd_priv, }; struct iscsi_transport bnx2i_iscsi_transport = { @@ -2275,7 +2223,7 @@ struct iscsi_transport bnx2i_iscsi_transport = { CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO, .create_session = bnx2i_session_create, - .destroy_session = bnx2i_session_destroy, + .destroy_session = iscsi_session_teardown, .create_conn = bnx2i_conn_create, .bind_conn = bnx2i_conn_bind, .destroy_conn = bnx2i_conn_destroy, From patchwork Tue Dec 1 21:29:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A16AC64E7B for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C72272085B for ; Tue, 1 Dec 2020 21:31:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="e34+j3qS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389227AbgLAVbL (ORCPT ); Tue, 1 Dec 2020 16:31:11 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:40968 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729472AbgLAVbF (ORCPT ); Tue, 1 Dec 2020 16:31:05 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LT9tg117612; Tue, 1 Dec 2020 21:30:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=TyqXj4g0FspgEeOkJE0RW16vFjueHMTTmBOgj4GRMCA=; b=e34+j3qSoE3eKapDMPWzoNJ0C+o6GXe9qGxFmRE+x8sUYDiQB1Izz8R81X0HbHz4Fro3 8SKKGNNnCOToGPSFUcNPfFbkRIhuJ2i0X9VULY7Nalu60d9y9oAfUekuFVxveSWmur+S Bfkx6ZPwCAMvbwPxhtP3FMRoianpzLCm0DedWBdGvLYH2BH/yCGC2Y8E8/t2Sco7W4v3 uuw9d6dvrOMU2Ua2wFLsMNF3oIwT+HR63AKBYrrPKWsblc2cqZGfZhHfvCvcuEXKt4dh QvT2LXkvnpU2APa8Oic10aJgbKaDO/OUXh+sx5bHQhJDBj1e+GCgVI7dUDFHsDr4FSjA 2w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 353c2aw2uw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:14 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LU88v105833; Tue, 1 Dec 2020 21:30:14 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 3540eyh8xp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:13 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LUCJx021080; Tue, 1 Dec 2020 21:30:12 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:11 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 10/15] qedi: set scsi_host_template cmd_size Date: Tue, 1 Dec 2020 15:29:51 -0600 Message-Id: <1606858196-5421-11-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=2 bulkscore=0 spamscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 lowpriorityscore=0 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver. Signed-off-by: Mike Christie --- drivers/scsi/qedi/qedi_iscsi.c | 113 ++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 64 deletions(-) diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c index 08c0540..979b875 100644 --- a/drivers/scsi/qedi/qedi_iscsi.c +++ b/drivers/scsi/qedi/qedi_iscsi.c @@ -14,6 +14,9 @@ #include "qedi_iscsi.h" #include "qedi_gbl.h" +static int qedi_exit_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc); +static int qedi_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc); + int qedi_recover_all_conns(struct qedi_ctx *qedi) { struct qedi_conn *qedi_conn; @@ -59,6 +62,9 @@ struct scsi_host_template qedi_host_template = { .dma_boundary = QEDI_HW_DMA_BOUNDARY, .cmd_per_lun = 128, .shost_attrs = qedi_shost_attrs, + .cmd_size = sizeof(struct qedi_cmd) + sizeof(struct iscsi_task), + .init_cmd_priv = qedi_init_cmd_priv, + .exit_cmd_priv = qedi_exit_cmd_priv, }; static void qedi_conn_free_login_resources(struct qedi_ctx *qedi, @@ -160,32 +166,17 @@ static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi, return -ENOMEM; } -static void qedi_destroy_cmd_pool(struct qedi_ctx *qedi, - struct iscsi_session *session) +static void qedi_free_sget(struct qedi_ctx *qedi, struct qedi_cmd *cmd) { - int i; + if (!cmd->io_tbl.sge_tbl) + return; - for (i = 0; i < session->cmds_max; i++) { - struct iscsi_task *task = session->cmds[i]; - struct qedi_cmd *cmd = task->dd_data; - - if (cmd->io_tbl.sge_tbl) - dma_free_coherent(&qedi->pdev->dev, - QEDI_ISCSI_MAX_BDS_PER_CMD * - sizeof(struct scsi_sge), - cmd->io_tbl.sge_tbl, - cmd->io_tbl.sge_tbl_dma); - - if (cmd->sense_buffer) - dma_free_coherent(&qedi->pdev->dev, - SCSI_SENSE_BUFFERSIZE, - cmd->sense_buffer, - cmd->sense_buffer_dma); - } + dma_free_coherent(&qedi->pdev->dev, + QEDI_ISCSI_MAX_BDS_PER_CMD * sizeof(struct scsi_sge), + cmd->io_tbl.sge_tbl, cmd->io_tbl.sge_tbl_dma); } -static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session, - struct qedi_cmd *cmd) +static int qedi_alloc_sget(struct qedi_ctx *qedi, struct qedi_cmd *cmd) { struct qedi_io_bdt *io = &cmd->io_tbl; struct scsi_sge *sge; @@ -195,8 +186,8 @@ static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session, sizeof(*sge), &io->sge_tbl_dma, GFP_KERNEL); if (!io->sge_tbl) { - iscsi_session_printk(KERN_ERR, session, - "Could not allocate BD table.\n"); + shost_printk(KERN_ERR, qedi->shost, + "Could not allocate BD table.\n"); return -ENOMEM; } @@ -204,33 +195,47 @@ static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session, return 0; } -static int qedi_setup_cmd_pool(struct qedi_ctx *qedi, - struct iscsi_session *session) +static int qedi_exit_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc) { - int i; + struct qedi_ctx *qedi = iscsi_host_priv(shost); + struct iscsi_task *task = scsi_cmd_priv(sc); + struct qedi_cmd *cmd = task->dd_data; - for (i = 0; i < session->cmds_max; i++) { - struct iscsi_task *task = session->cmds[i]; - struct qedi_cmd *cmd = task->dd_data; + qedi_free_sget(qedi, cmd); - task->hdr = &cmd->hdr; - task->hdr_max = sizeof(struct iscsi_hdr); + if (cmd->sense_buffer) + dma_free_coherent(&qedi->pdev->dev, SCSI_SENSE_BUFFERSIZE, + cmd->sense_buffer, cmd->sense_buffer_dma); + return 0; +} + +static int qedi_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc) +{ + struct qedi_ctx *qedi = iscsi_host_priv(shost); + struct iscsi_task *task; + struct qedi_cmd *cmd; - if (qedi_alloc_sget(qedi, session, cmd)) - goto free_sgets; + iscsi_init_cmd_priv(shost, sc); - cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev, - SCSI_SENSE_BUFFERSIZE, - &cmd->sense_buffer_dma, - GFP_KERNEL); - if (!cmd->sense_buffer) - goto free_sgets; - } + task = scsi_cmd_priv(sc); + cmd = task->dd_data; + task->hdr = &cmd->hdr; + task->hdr_max = sizeof(struct iscsi_hdr); + + if (qedi_alloc_sget(qedi, cmd)) + goto free_sgets; + + cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev, + SCSI_SENSE_BUFFERSIZE, + &cmd->sense_buffer_dma, + GFP_KERNEL); + if (!cmd->sense_buffer) + goto free_sgets; return 0; free_sgets: - qedi_destroy_cmd_pool(qedi, session); + qedi_free_sget(qedi, cmd); return -ENOMEM; } @@ -264,27 +269,7 @@ static int qedi_setup_cmd_pool(struct qedi_ctx *qedi, return NULL; } - if (qedi_setup_cmd_pool(qedi, cls_session->dd_data)) { - QEDI_ERR(&qedi->dbg_ctx, - "Failed to setup cmd pool for ep=%p\n", qedi_ep); - goto session_teardown; - } - return cls_session; - -session_teardown: - iscsi_session_teardown(cls_session); - return NULL; -} - -static void qedi_session_destroy(struct iscsi_cls_session *cls_session) -{ - struct iscsi_session *session = cls_session->dd_data; - struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); - struct qedi_ctx *qedi = iscsi_host_priv(shost); - - qedi_destroy_cmd_pool(qedi, session); - iscsi_session_teardown(cls_session); } static struct iscsi_cls_conn * @@ -1398,7 +1383,7 @@ struct iscsi_transport qedi_iscsi_transport = { .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO, .create_session = qedi_session_create, - .destroy_session = qedi_session_destroy, + .destroy_session = iscsi_session_teardown, .create_conn = qedi_conn_create, .bind_conn = qedi_conn_bind, .start_conn = qedi_conn_start, @@ -1625,7 +1610,7 @@ void qedi_clear_session_ctx(struct iscsi_cls_session *cls_sess) qedi_conn_destroy(qedi_conn->cls_conn); - qedi_session_destroy(cls_sess); + iscsi_session_teardown(cls_sess); } void qedi_process_tcp_error(struct qedi_endpoint *ep, From patchwork Tue Dec 1 21:29:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D805C8301B for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F9AB2086A for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="SXZMAP2q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389173AbgLAVbK (ORCPT ); Tue, 1 Dec 2020 16:31:10 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:41046 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389078AbgLAVbK (ORCPT ); Tue, 1 Dec 2020 16:31:10 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSv9V117396; Tue, 1 Dec 2020 21:30:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=qF+9krZt81X9hC9OOaLA1KxgNYEdQ9zLq1PrZESbBr0=; b=SXZMAP2qvxCK4RxMWHWxfqeyGZ2zS5fIeEja+TkB6+16RL1gPeWWFUERtm8HY4aTrRjJ +LMZEbygawMW4I8O9RIq/L8Ys+gR5rKnm/xQTjKktGg3IQqtdtSHgJpEq9UtFPunz3T4 +wIReI+8cW2whhSkaRdF4T3h+aFhQyfn/ai2b/uFuui0+VgcOekUQN7oja4XRVeVrvSZ epxEkmyFJKesu6X3QrDesjv6KOm7FuRC0jWtm7Y3PXi+jqvm0lSzdI08wtzgsi1Hr/Ot LCgsIAMa13seguk47G2Mo3qoEfMqEfdG/iIr9Hw49/Vs1jLr4YZNv3Wu2mdOBuDFnOwE hA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 353c2aw2v2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:16 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LBKkK163920; Tue, 1 Dec 2020 21:30:16 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 3540fxkwsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:16 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LUCWr021053; Tue, 1 Dec 2020 21:30:14 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:12 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 11/15] iscsi_tcp, libcxgbi: set scsi_host_template cmd_size Date: Tue, 1 Dec 2020 15:29:52 -0600 Message-Id: <1606858196-5421-12-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=2 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 lowpriorityscore=0 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver. Note: Because for cxgbi we do not have access to the specific session we are creating cmds for, all sessions get the max of what is on the host but this is normally going to one so it should not be any different. Signed-off-by: Mike Christie --- drivers/scsi/cxgbi/cxgb3i/cxgb3i.c | 5 ++ drivers/scsi/cxgbi/cxgb4i/cxgb4i.c | 5 ++ drivers/scsi/cxgbi/libcxgbi.c | 10 ---- drivers/scsi/iscsi_tcp.c | 10 ++-- drivers/scsi/libiscsi_tcp.c | 102 ++++++++++++++++++++----------------- include/scsi/libiscsi_tcp.h | 5 +- 6 files changed, 72 insertions(+), 65 deletions(-) diff --git a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c index 37d9935..d45babc 100644 --- a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c +++ b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c @@ -98,6 +98,11 @@ .dma_boundary = PAGE_SIZE - 1, .this_id = -1, .track_queue_depth = 1, + .cmd_size = sizeof(struct iscsi_tcp_task) + + sizeof(struct cxgbi_task_data) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_tcp_init_cmd_priv, + .exit_cmd_priv = iscsi_tcp_exit_cmd_priv, }; static struct iscsi_transport cxgb3i_iscsi_transport = { diff --git a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c index 2c34915..d6647fa 100644 --- a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c +++ b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c @@ -116,6 +116,11 @@ .dma_boundary = PAGE_SIZE - 1, .this_id = -1, .track_queue_depth = 1, + .cmd_size = sizeof(struct iscsi_tcp_task) + + sizeof(struct cxgbi_task_data) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_tcp_init_cmd_priv, + .exit_cmd_priv = iscsi_tcp_exit_cmd_priv, }; static struct iscsi_transport cxgb4i_iscsi_transport = { diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index f078b3c..e45989c 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -2727,7 +2727,6 @@ struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *ep, struct cxgbi_hba *chba; struct Scsi_Host *shost; struct iscsi_cls_session *cls_session; - struct iscsi_session *session; if (!ep) { pr_err("missing endpoint.\n"); @@ -2748,17 +2747,9 @@ struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *ep, if (!cls_session) return NULL; - session = cls_session->dd_data; - if (iscsi_tcp_r2tpool_alloc(session)) - goto remove_session; - log_debug(1 << CXGBI_DBG_ISCSI, "ep 0x%p, cls sess 0x%p.\n", ep, cls_session); return cls_session; - -remove_session: - iscsi_session_teardown(cls_session); - return NULL; } EXPORT_SYMBOL_GPL(cxgbi_create_session); @@ -2767,7 +2758,6 @@ void cxgbi_destroy_session(struct iscsi_cls_session *cls_session) log_debug(1 << CXGBI_DBG_ISCSI, "cls sess 0x%p.\n", cls_session); - iscsi_tcp_r2tpool_free(cls_session->dd_data); iscsi_session_teardown(cls_session); } EXPORT_SYMBOL_GPL(cxgbi_destroy_session); diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index df47557..185110d1 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -879,12 +879,8 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost, tcp_sw_host->session = session; shost->can_queue = session->scsi_cmds_max; - if (iscsi_tcp_r2tpool_alloc(session)) - goto remove_session; return cls_session; -remove_session: - iscsi_session_teardown(cls_session); remove_host: iscsi_host_remove(shost); free_host: @@ -900,7 +896,6 @@ static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session) if (WARN_ON_ONCE(session->leadconn)) return; - iscsi_tcp_r2tpool_free(cls_session->dd_data); iscsi_session_teardown(cls_session); iscsi_host_remove(shost); @@ -995,6 +990,11 @@ static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev) .proc_name = "iscsi_tcp", .this_id = -1, .track_queue_depth = 1, + .cmd_size = sizeof(struct iscsi_tcp_task) + + sizeof(struct iscsi_sw_tcp_hdrbuf) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_tcp_init_cmd_priv, + .exit_cmd_priv = iscsi_tcp_exit_cmd_priv, }; static struct iscsi_transport iscsi_sw_tcp_transport = { diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c index 916148c..081b2b6 100644 --- a/drivers/scsi/libiscsi_tcp.c +++ b/drivers/scsi/libiscsi_tcp.c @@ -1147,68 +1147,75 @@ void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn) } EXPORT_SYMBOL_GPL(iscsi_tcp_conn_teardown); -int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session) +static int iscsi_tcp_calc_max_r2t(struct device *dev, void *data) { - int i; - int cmd_i; + struct iscsi_cls_session *cls_session; + struct iscsi_session *session; + int *max_r2t = data; - /* - * initialize per-task: R2T pool and xmit queue - */ - for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { - struct iscsi_task *task = session->cmds[cmd_i]; - struct iscsi_tcp_task *tcp_task = task->dd_data; + if (!iscsi_is_session_dev(dev)) + return 0; - /* - * pre-allocated x2 as much r2ts to handle race when - * target acks DataOut faster than we data_xmit() queues - * could replenish r2tqueue. - */ + cls_session = iscsi_dev_to_session(dev); + session = cls_session->dd_data; + if (session->max_r2t > *max_r2t) + *max_r2t = session->max_r2t; + return 0; +} - /* R2T pool */ - if (iscsi_pool_init(&tcp_task->r2tpool, - session->max_r2t * 2, NULL, - sizeof(struct iscsi_r2t_info))) { - goto r2t_alloc_fail; - } +int iscsi_tcp_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc) +{ + struct iscsi_task *task; + struct iscsi_tcp_task *tcp_task; + int max_r2t = 1; - /* R2T xmit queue */ - if (kfifo_alloc(&tcp_task->r2tqueue, - session->max_r2t * 4 * sizeof(void*), GFP_KERNEL)) { - iscsi_pool_free(&tcp_task->r2tpool); - goto r2t_alloc_fail; - } - spin_lock_init(&tcp_task->pool2queue); - spin_lock_init(&tcp_task->queue2pool); - } + iscsi_init_cmd_priv(shost, sc); - return 0; + /* + * cxgbi does not have access to the session so we use the max of all + * sessions on the host. + */ + device_for_each_child(&shost->shost_gendev, &max_r2t, + iscsi_tcp_calc_max_r2t); -r2t_alloc_fail: - for (i = 0; i < cmd_i; i++) { - struct iscsi_task *task = session->cmds[i]; - struct iscsi_tcp_task *tcp_task = task->dd_data; + task = scsi_cmd_priv(sc); + tcp_task = task->dd_data; - kfifo_free(&tcp_task->r2tqueue); + /* + * pre-allocated x2 as much r2ts to handle race when + * target acks DataOut faster than we data_xmit() queues + * could replenish r2tqueue. + */ + if (iscsi_pool_init(&tcp_task->r2tpool, max_r2t * 2, NULL, + sizeof(struct iscsi_r2t_info))) + return -ENOMEM; + + /* R2T xmit queue */ + if (kfifo_alloc(&tcp_task->r2tqueue, max_r2t * 4 * sizeof(void *), + GFP_KERNEL)) { iscsi_pool_free(&tcp_task->r2tpool); + goto r2t_queue_alloc_fail; } + spin_lock_init(&tcp_task->pool2queue); + spin_lock_init(&tcp_task->queue2pool); + return 0; + +r2t_queue_alloc_fail: + iscsi_pool_free(&tcp_task->r2tpool); return -ENOMEM; } -EXPORT_SYMBOL_GPL(iscsi_tcp_r2tpool_alloc); +EXPORT_SYMBOL_GPL(iscsi_tcp_init_cmd_priv); -void iscsi_tcp_r2tpool_free(struct iscsi_session *session) +int iscsi_tcp_exit_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc) { - int i; - - for (i = 0; i < session->cmds_max; i++) { - struct iscsi_task *task = session->cmds[i]; - struct iscsi_tcp_task *tcp_task = task->dd_data; + struct iscsi_task *task = scsi_cmd_priv(sc); + struct iscsi_tcp_task *tcp_task = task->dd_data; - kfifo_free(&tcp_task->r2tqueue); - iscsi_pool_free(&tcp_task->r2tpool); - } + kfifo_free(&tcp_task->r2tqueue); + iscsi_pool_free(&tcp_task->r2tpool); + return 0; } -EXPORT_SYMBOL_GPL(iscsi_tcp_r2tpool_free); +EXPORT_SYMBOL_GPL(iscsi_tcp_exit_cmd_priv); int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf) { @@ -1223,8 +1230,7 @@ int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf) return -EINVAL; session->max_r2t = r2ts; - iscsi_tcp_r2tpool_free(session); - return iscsi_tcp_r2tpool_alloc(session); + return 0; } EXPORT_SYMBOL_GPL(iscsi_tcp_set_max_r2t); diff --git a/include/scsi/libiscsi_tcp.h b/include/scsi/libiscsi_tcp.h index 7c8ba9d..4d502f6 100644 --- a/include/scsi/libiscsi_tcp.h +++ b/include/scsi/libiscsi_tcp.h @@ -89,6 +89,9 @@ extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb, extern void iscsi_tcp_cleanup_task(struct iscsi_task *task); extern int iscsi_tcp_task_init(struct iscsi_task *task); extern int iscsi_tcp_task_xmit(struct iscsi_task *task); +extern int iscsi_tcp_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc); +extern int iscsi_tcp_exit_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *sc); + /* segment helpers */ extern int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn); @@ -118,8 +121,6 @@ extern void iscsi_tcp_dgst_header(struct ahash_request *hash, const void *hdr, extern void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn); /* misc helpers */ -extern int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session); -extern void iscsi_tcp_r2tpool_free(struct iscsi_session *session); extern int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf); extern void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats); From patchwork Tue Dec 1 21:29:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AD13C8301D for ; Tue, 1 Dec 2020 21:31:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1E8A2085B for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ozv2Q0fP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389412AbgLAVbP (ORCPT ); Tue, 1 Dec 2020 16:31:15 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:46958 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389212AbgLAVbN (ORCPT ); Tue, 1 Dec 2020 16:31:13 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LTIvS018605; Tue, 1 Dec 2020 21:30:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=QpEbBTHxGM5ChernpIqnG9oejAbMYwibJ3pf0y/zn4k=; b=ozv2Q0fPkfJXrbVtMLizdpeJ/5AP51ea9n7U69nfyYpSUunpTkPzyXDIIbpM8tkYUy5E EcBSIiKGXPIa6JkmMLx1/cnAPEzq5e+yjX038gjPOrHxHvxzNJ8e3Yk0ePdxMF8FwaeN 5+C96Ss1DsbFpHSUU8jkJMbvpLnDFSP+gelrJH9EpMxYNfvrPyJTXs/a8EtL91fWS1wY HEtScbt5ldkgCVvtC4hfXPYZ7olGJ3LvGg6JNDXbP1BuCz6yyPohwThQS41BJRlBWMJn qWH1xU69DKQR6Bz9WYn5R+tlMeDPJF3vure2kw4p1o2H2lVwp9rki56qAEnaMWb+0jSM nw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 353dyqmy2u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:21 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LUIqK131146; Tue, 1 Dec 2020 21:30:20 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 3540at23ra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:20 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LUDgS021087; Tue, 1 Dec 2020 21:30:13 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:13 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 12/15] libiscsi: use blk/scsi-ml mq cmd pre-allocator Date: Tue, 1 Dec 2020 15:29:53 -0600 Message-Id: <1606858196-5421-13-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 suspectscore=2 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 clxscore=1015 mlxscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=2 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This has us use the blk/scsi-ml mq cmd pre-allocator for scsi tasks. We now do not need the back/frwd locks for scsi task allocation. We still need it for mgmt tasks, but that will be fixed in the next patch. Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 84 ++++++++++++++++++------------------------------- include/scsi/libiscsi.h | 13 +++++--- 2 files changed, 38 insertions(+), 59 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index ea1ef77..85c6730 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -547,14 +547,15 @@ static void iscsi_free_task(struct iscsi_task *task) return; iscsi_free_itt(session, task); - kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*)); if (session->win_opened && !work_pending(&conn->xmitwork)) { session->win_opened = false; iscsi_conn_queue_work(conn); } - if (sc) { + if (!sc) { + kfifo_in(&session->mgmt_pool.queue, (void*)&task, sizeof(void*)); + } else { /* SCSI eh reuses commands to verify us */ sc->SCp.ptr = NULL; /* @@ -803,13 +804,13 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE); BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED); - if (!kfifo_out(&session->cmdpool.queue, + if (!kfifo_out(&session->mgmt_pool.queue, (void*)&task, sizeof(void*))) return NULL; if (iscsi_alloc_itt(session, task)) { spin_lock(&session->back_lock); - kfifo_in(&session->cmdpool.queue, (void*)&task, + kfifo_in(&session->mgmt_pool.queue, (void*)&task, sizeof(void*)); spin_unlock(&session->back_lock); return NULL; @@ -1712,14 +1713,10 @@ static void iscsi_xmitworker(struct work_struct *work) } while (rc >= 0 || rc == -EAGAIN); } -static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn, - struct scsi_cmnd *sc) +static struct iscsi_task *iscsi_init_scsi_task(struct iscsi_conn *conn, + struct scsi_cmnd *sc) { - struct iscsi_task *task; - - if (!kfifo_out(&conn->session->cmdpool.queue, - (void *) &task, sizeof(void *))) - return NULL; + struct iscsi_task *task = scsi_cmd_priv(sc); sc->SCp.phase = conn->session->age; sc->SCp.ptr = (char *) task; @@ -1822,22 +1819,16 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto fault; } - spin_lock_bh(&session->frwd_lock); - if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) { - spin_unlock_bh(&session->frwd_lock); - reason = FAILURE_SESSION_IN_RECOVERY; - sc->result = DID_REQUEUE << 16; - goto fault; - } - - task = iscsi_alloc_task(conn, sc); - if (!task) { - spin_unlock_bh(&session->frwd_lock); - reason = FAILURE_OOM; - goto reject; - } + task = iscsi_init_scsi_task(conn, sc); + spin_lock_bh(&session->frwd_lock); if (!ihost->workq) { + if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) { + reason = FAILURE_SESSION_IN_RECOVERY; + sc->result = DID_REQUEUE << 16; + goto prepd_fault; + } + if (iscsi_check_cmdsn_window_closed(conn)) { reason = FAILURE_WINDOW_CLOSED; goto prepd_reject; @@ -1872,7 +1863,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) spin_lock_bh(&session->back_lock); iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ); spin_unlock_bh(&session->back_lock); -reject: + ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n", sc->cmnd[0], reason); return SCSI_MLQUEUE_TARGET_BUSY; @@ -2873,7 +2864,6 @@ struct iscsi_cls_session * struct iscsi_session *session; struct iscsi_cls_session *cls_session; int cmd_i, scsi_cmds, total_cmds = cmds_max; - struct iscsi_task *task; unsigned long flags; spin_lock_irqsave(&ihost->lock, flags); @@ -2951,30 +2941,16 @@ struct iscsi_cls_session * if (!session->cmds) goto cmds_alloc_fail; - /* initialize SCSI PDU commands pool */ - if (iscsi_pool_init(&session->cmdpool, session->cmds_max, NULL, + /* initialize mgmt PDU pool */ + if (iscsi_pool_init(&session->mgmt_pool, ISCSI_MGMT_CMDS_MAX, + (void***)&session->mgmt_cmds, cmd_task_size + sizeof(struct iscsi_task))) - goto cmdpool_alloc_fail; - - /* - * This is a temp change to allow drivers that prealloc task resources - * during session setup to continue to work. The next patches convert - * the drivers to use the blk/scsi-ml init/exit callouts then this - * will be removed. - */ - while (kfifo_out(&session->cmdpool.queue, (void *) &task, - sizeof(void *))) { - session->cmds[cmd_i++] = task; + goto mgmt_pool_alloc_fail; - if (cmd_task_size) - task->dd_data = &task[1]; - task->state = ISCSI_TASK_FREE; - INIT_LIST_HEAD(&task->running); - } + for (cmd_i = 0; cmd_i < ISCSI_MGMT_CMDS_MAX; cmd_i++) { + struct iscsi_task *task = session->mgmt_cmds[cmd_i]; - for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { - task = session->cmds[cmd_i]; - kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*)); + iscsi_init_task(task); } if (!try_module_get(iscsit->owner)) @@ -2988,8 +2964,8 @@ struct iscsi_cls_session * cls_session_fail: module_put(iscsit->owner); module_get_fail: - iscsi_pool_free(&session->cmdpool); -cmdpool_alloc_fail: + iscsi_pool_free(&session->mgmt_pool); +mgmt_pool_alloc_fail: kfree(session->cmds); cmds_alloc_fail: sbitmap_free(&session->itts); @@ -3011,7 +2987,7 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session) struct module *owner = cls_session->transport->owner; struct Scsi_Host *shost = session->host; - iscsi_pool_free(&session->cmdpool); + iscsi_pool_free(&session->mgmt_pool); iscsi_remove_session(cls_session); @@ -3078,7 +3054,7 @@ struct iscsi_cls_conn * /* allocate login_task used for the login/text sequences */ spin_lock_bh(&session->frwd_lock); - if (!kfifo_out(&session->cmdpool.queue, + if (!kfifo_out(&session->mgmt_pool.queue, (void*)&conn->login_task, sizeof(void*))) { spin_unlock_bh(&session->frwd_lock); @@ -3104,7 +3080,7 @@ struct iscsi_cls_conn * iscsi_free_itt(session, conn->login_task); login_itt_fail: spin_lock_bh(&session->frwd_lock); - kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, + kfifo_in(&session->mgmt_pool.queue, (void*)&conn->login_task, sizeof(void*)); spin_unlock_bh(&session->frwd_lock); login_task_alloc_fail: @@ -3149,7 +3125,7 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn) kfree(conn->local_ipaddr); /* regular RX path uses back_lock */ spin_lock_bh(&session->back_lock); - kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, + kfifo_in(&session->mgmt_pool.queue, (void*)&conn->login_task, sizeof(void*)); spin_unlock_bh(&session->back_lock); iscsi_free_itt(session, conn->login_task); diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index c2283f9..1c851b6 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -331,19 +331,22 @@ struct iscsi_session { * in the eh paths, cmdsn * * suspend bit and session * * resources: * - * - cmdpool kfifo_out , * - * - mgmtpool, queues */ + * - kfifo_out mgmt_pool, * + * - queues */ spinlock_t back_lock; /* protects cmdsn_exp * * cmdsn_max, * - * cmdpool kfifo_in */ + * mgmt_pool kfifo_in */ int state; /* session state */ int age; /* counts session re-opens */ int scsi_cmds_max; /* max scsi commands */ int cmds_max; /* size of cmds array */ - struct iscsi_task **cmds; /* Original Cmds arr */ - struct iscsi_pool cmdpool; /* PDU's pool */ + struct iscsi_task **cmds; /* Lookup map of all tasks */ struct sbitmap itts; + + struct iscsi_task **mgmt_cmds; + struct iscsi_pool mgmt_pool; + void *dd_data; /* LLD private data */ }; From patchwork Tue Dec 1 21:29:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1EEDC8301C for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 838362084C for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Ubk6P44L" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389385AbgLAVbP (ORCPT ); Tue, 1 Dec 2020 16:31:15 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:57500 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388565AbgLAVbN (ORCPT ); Tue, 1 Dec 2020 16:31:13 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSubc081048; Tue, 1 Dec 2020 21:30:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=lvRh++FeI7AFla60Q2AZ1FT88NOlWljp1JQgFJbGBug=; b=Ubk6P44LkY57QfFmty/YdQF4lFKdk/FLtb/2JCogUcipCmOGMjy9Rd0xViBTXOcl4pOK pvTsvQI6DjQ0ErX2RfBO7U91yoxZY5BOy8MiqG+UNWeZR113mY/PqVPUwypeNW10wHGB 06aVuC9EoX4gytJHkAVZ80LS8AvfRyNUUF48S6FAod0dq0sIg9eN9XXTIBcv2v40SA6H jjAdxAHFLkLut+KcHt665/ly1TDuAjJpdQeWOY3VOYk0Px2t7ecmf0clBpWfxiPKoQdC JXDjEVW+Q2hC8Csln/Z+hW6snF9e2Qd6Qys18K1kLkKn2KZqxCGlco/2mSz2AwVUJs9a 5Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 353egkmw5s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:21 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LUIqL131146; Tue, 1 Dec 2020 21:30:20 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 3540at23r1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:20 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0B1LUETY018430; Tue, 1 Dec 2020 21:30:14 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:14 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 13/15] libiscsi: drop back_lock requirement for iscsi_put_task Date: Tue, 1 Dec 2020 15:29:54 -0600 Message-Id: <1606858196-5421-14-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 suspectscore=2 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 suspectscore=2 phishscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch adds a new lock around the mgmt pool, so we no longer need the back lock when calling iscsi_put_task. This helps in the xmit path where we are taking it to drop the refcount. The next patch will allow us to completely remove the back lock from the xmit path. Signed-off-by: Mike Christie --- drivers/scsi/be2iscsi/be_main.c | 6 +-- drivers/scsi/bnx2i/bnx2i_hwi.c | 2 +- drivers/scsi/libiscsi.c | 84 +++++++++++++++++------------------------ drivers/scsi/libiscsi_tcp.c | 2 +- drivers/scsi/qedi/qedi_fw.c | 11 ++---- include/scsi/libiscsi.h | 4 +- 6 files changed, 45 insertions(+), 64 deletions(-) diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c index 91bc822..cb86aec 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -236,7 +236,7 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc) return SUCCESS; } /* get a task ref till FW processes the req for the ICD used */ - __iscsi_get_task(abrt_task); + iscsi_get_task(abrt_task); abrt_io_task = abrt_task->dd_data; conn = abrt_task->conn; beiscsi_conn = conn->dd_data; @@ -321,7 +321,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) } /* get a task ref till FW processes the req for the ICD used */ - __iscsi_get_task(task); + iscsi_get_task(task); io_task = task->dd_data; /* mark WRB invalid which have been not processed by FW yet */ if (is_chip_be2_be3r(phba)) { @@ -1245,7 +1245,7 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) spin_lock_bh(&session->back_lock); task = pwrb_handle->pio_handle; if (task) - __iscsi_put_task(task); + iscsi_put_task(task); spin_unlock_bh(&session->back_lock); } diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c index bad396e..54b9c40 100644 --- a/drivers/scsi/bnx2i/bnx2i_hwi.c +++ b/drivers/scsi/bnx2i/bnx2i_hwi.c @@ -1657,7 +1657,7 @@ static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session, task = iscsi_itt_to_task(conn, nop_in->itt & ISCSI_NOP_IN_MSG_INDEX); if (task) - __iscsi_put_task(task); + iscsi_put_task(task); spin_unlock(&session->back_lock); } diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 85c6730..0643156 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -523,7 +523,6 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) * iscsi_free_task - free a task * @task: iscsi cmd task * - * Must be called with session back_lock. * This function returns the scsi command to scsi-ml or cleans * up mgmt tasks then returns the task to the pool. */ @@ -554,7 +553,9 @@ static void iscsi_free_task(struct iscsi_task *task) } if (!sc) { + spin_lock_bh(&session->mgmt_lock); kfifo_in(&session->mgmt_pool.queue, (void*)&task, sizeof(void*)); + spin_unlock_bh(&session->mgmt_lock); } else { /* SCSI eh reuses commands to verify us */ sc->SCp.ptr = NULL; @@ -567,28 +568,17 @@ static void iscsi_free_task(struct iscsi_task *task) } } -void __iscsi_get_task(struct iscsi_task *task) +void iscsi_get_task(struct iscsi_task *task) { refcount_inc(&task->refcount); } -EXPORT_SYMBOL_GPL(__iscsi_get_task); +EXPORT_SYMBOL_GPL(iscsi_get_task); -void __iscsi_put_task(struct iscsi_task *task) +void iscsi_put_task(struct iscsi_task *task) { if (refcount_dec_and_test(&task->refcount)) iscsi_free_task(task); } -EXPORT_SYMBOL_GPL(__iscsi_put_task); - -void iscsi_put_task(struct iscsi_task *task) -{ - struct iscsi_session *session = task->conn->session; - - /* regular RX path uses back_lock */ - spin_lock_bh(&session->back_lock); - __iscsi_put_task(task); - spin_unlock_bh(&session->back_lock); -} EXPORT_SYMBOL_GPL(iscsi_put_task); /** @@ -617,7 +607,7 @@ static void iscsi_complete_task(struct iscsi_task *task, int state) WRITE_ONCE(conn->ping_task, NULL); /* release get from queueing */ - __iscsi_put_task(task); + iscsi_put_task(task); } /** @@ -664,12 +654,12 @@ static bool cleanup_queued_task(struct iscsi_task *task) * list */ if (task->state == ISCSI_TASK_RUNNING) - __iscsi_put_task(task); + iscsi_put_task(task); } if (conn->task == task) { conn->task = NULL; - __iscsi_put_task(task); + iscsi_put_task(task); } return early_complete; @@ -804,17 +794,20 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE); BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED); - if (!kfifo_out(&session->mgmt_pool.queue, - (void*)&task, sizeof(void*))) + spin_lock(&session->mgmt_lock); + if (!kfifo_out(&session->mgmt_pool.queue, (void *)&task, + sizeof(void *))) { + spin_unlock(&session->mgmt_lock); return NULL; + } if (iscsi_alloc_itt(session, task)) { - spin_lock(&session->back_lock); kfifo_in(&session->mgmt_pool.queue, (void*)&task, sizeof(void*)); - spin_unlock(&session->back_lock); + spin_unlock(&session->mgmt_lock); return NULL; } + spin_unlock(&session->mgmt_lock); } /* * released in complete pdu for task we expect a response for, and @@ -870,10 +863,7 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, return task; free_task: - /* regular RX path uses back_lock */ - spin_lock(&session->back_lock); - __iscsi_put_task(task); - spin_unlock(&session->back_lock); + iscsi_put_task(task); return NULL; } @@ -1514,16 +1504,15 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref) int rc; /* Take a ref so we can access it after xmit_task() */ - __iscsi_get_task(task); + iscsi_get_task(task); conn->task = NULL; - spin_lock_bh(&conn->session->back_lock); /* * If this was a requeue for a R2T or we were in the middle of sending * the task, we have an extra ref on the task in case a bad target * sends a cmd rsp before we have handled the task. */ if (has_extra_ref) - __iscsi_put_task(task); + iscsi_put_task(task); /* * Do this after dropping the extra ref because the forced dequeue @@ -1533,8 +1522,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref) rc = -ENODATA; goto put_task; } - spin_unlock_bh(&conn->session->back_lock); - spin_unlock_bh(&conn->session->frwd_lock); rc = conn->session->tt->xmit_task(task); spin_lock_bh(&conn->session->frwd_lock); @@ -1549,12 +1536,13 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref) * get an extra ref that is released next time we access it * as conn->task above. */ - __iscsi_get_task(task); + iscsi_get_task(task); conn->task = task; } -put_task: - __iscsi_put_task(task); spin_unlock(&conn->session->back_lock); + +put_task: + iscsi_put_task(task); return rc; } @@ -1625,10 +1613,7 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) running); list_del_init(&task->running); if (iscsi_prep_mgmt_task(conn, task)) { - /* regular RX path uses back_lock */ - spin_lock_bh(&conn->session->back_lock); - __iscsi_put_task(task); - spin_unlock_bh(&conn->session->back_lock); + iscsi_put_task(task); continue; } conn->task = task; @@ -2929,6 +2914,7 @@ struct iscsi_cls_session * session->dd_data = cls_session->dd_data + sizeof(*session); mutex_init(&session->eh_mutex); + spin_lock_init(&session->mgmt_lock); spin_lock_init(&session->frwd_lock); spin_lock_init(&session->back_lock); @@ -3053,14 +3039,13 @@ struct iscsi_cls_conn * INIT_WORK(&conn->xmitwork, iscsi_xmitworker); /* allocate login_task used for the login/text sequences */ - spin_lock_bh(&session->frwd_lock); - if (!kfifo_out(&session->mgmt_pool.queue, - (void*)&conn->login_task, - sizeof(void*))) { - spin_unlock_bh(&session->frwd_lock); + spin_lock_bh(&session->mgmt_lock); + if (!kfifo_out(&session->mgmt_pool.queue, (void*)&conn->login_task, + sizeof(void*))) { + spin_unlock_bh(&session->mgmt_lock); goto login_task_alloc_fail; } - spin_unlock_bh(&session->frwd_lock); + spin_unlock_bh(&session->mgmt_lock); if (iscsi_alloc_itt(session, conn->login_task)) goto login_itt_fail; @@ -3079,10 +3064,10 @@ struct iscsi_cls_conn * login_task_data_alloc_fail: iscsi_free_itt(session, conn->login_task); login_itt_fail: - spin_lock_bh(&session->frwd_lock); + spin_lock_bh(&session->mgmt_lock); kfifo_in(&session->mgmt_pool.queue, (void*)&conn->login_task, sizeof(void*)); - spin_unlock_bh(&session->frwd_lock); + spin_unlock_bh(&session->mgmt_lock); login_task_alloc_fail: iscsi_destroy_conn(cls_conn); return NULL; @@ -3123,12 +3108,13 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn) get_order(ISCSI_DEF_MAX_RECV_SEG_LEN)); kfree(conn->persistent_address); kfree(conn->local_ipaddr); - /* regular RX path uses back_lock */ - spin_lock_bh(&session->back_lock); + + spin_lock_bh(&session->mgmt_lock); kfifo_in(&session->mgmt_pool.queue, (void*)&conn->login_task, sizeof(void*)); - spin_unlock_bh(&session->back_lock); + spin_unlock_bh(&session->mgmt_lock); iscsi_free_itt(session, conn->login_task); + if (session->leadconn == conn) session->leadconn = NULL; spin_unlock_bh(&session->frwd_lock); diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c index 081b2b6..cada8b8 100644 --- a/drivers/scsi/libiscsi_tcp.c +++ b/drivers/scsi/libiscsi_tcp.c @@ -558,7 +558,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr) return 0; } task->last_xfer = jiffies; - __iscsi_get_task(task); + iscsi_get_task(task); tcp_conn = conn->dd_data; rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr; diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c index 440ddd2..4f4e089 100644 --- a/drivers/scsi/qedi/qedi_fw.c +++ b/drivers/scsi/qedi/qedi_fw.c @@ -718,11 +718,8 @@ static void qedi_mtask_completion(struct qedi_ctx *qedi, static void qedi_process_nopin_local_cmpl(struct qedi_ctx *qedi, struct iscsi_cqe_solicited *cqe, - struct iscsi_task *task, - struct qedi_conn *qedi_conn) + struct iscsi_task *task) { - struct iscsi_conn *conn = qedi_conn->cls_conn->dd_data; - struct iscsi_session *session = conn->session; struct qedi_cmd *cmd = task->dd_data; QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_UNSOL, @@ -732,9 +729,7 @@ static void qedi_process_nopin_local_cmpl(struct qedi_ctx *qedi, cmd->state = RESPONSE_RECEIVED; qedi_clear_task_idx(qedi, cmd->task_id); - spin_lock_bh(&session->back_lock); - __iscsi_put_task(task); - spin_unlock_bh(&session->back_lock); + iscsi_put_task(task); } static void qedi_process_cmd_cleanup_resp(struct qedi_ctx *qedi, @@ -930,7 +925,7 @@ void qedi_fp_process_cqes(struct qedi_work *work) if ((nopout_hdr->itt == RESERVED_ITT) && (cqe->cqe_solicited.itid != (u16)RESERVED_ITT)) { qedi_process_nopin_local_cmpl(qedi, &cqe->cqe_solicited, - task, q_conn); + task); } else { cqe->cqe_solicited.itid = qedi_get_itt(cqe->cqe_solicited); diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 1c851b6..d0a6834 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -336,6 +336,7 @@ struct iscsi_session { spinlock_t back_lock; /* protects cmdsn_exp * * cmdsn_max, * * mgmt_pool kfifo_in */ + spinlock_t mgmt_lock; /* mgmt pool/cmds lock */ int state; /* session state */ int age; /* counts session re-opens */ @@ -459,8 +460,7 @@ extern int __iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *, extern struct iscsi_task *iscsi_itt_to_task(struct iscsi_conn *, itt_t); extern void iscsi_requeue_task(struct iscsi_task *task); extern void iscsi_put_task(struct iscsi_task *task); -extern void __iscsi_put_task(struct iscsi_task *task); -extern void __iscsi_get_task(struct iscsi_task *task); +extern void iscsi_get_task(struct iscsi_task *task); extern void iscsi_complete_scsi_task(struct iscsi_task *task, uint32_t exp_cmdsn, uint32_t max_cmdsn); extern int iscsi_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd); From patchwork Tue Dec 1 21:29:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 651AFC8301F for ; Tue, 1 Dec 2020 21:31:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 035E02084C for ; Tue, 1 Dec 2020 21:31:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="IzVjYdWv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389431AbgLAVbR (ORCPT ); Tue, 1 Dec 2020 16:31:17 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:57664 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389212AbgLAVbR (ORCPT ); Tue, 1 Dec 2020 16:31:17 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSuFn081051; Tue, 1 Dec 2020 21:30:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=N0YnQBKlJajllbONjcZL6EQUDDZahTbINdKQ+U4dROU=; b=IzVjYdWvweOJm/fnbCyjF6KMyxkUEjFdgTFTGw4XzenA6uzh41a+rGLm6v4BFfs8lceb dHszfCmtB9+k/LAwM9ShGlPswRK1X9U9EvPFQ0TOWnrxradK7/MLOPGMVK+7P1vqZ5Of 7SEaK6x1EOGHbqnBj0qcrlHP4p+B5fDPOyCcMqJ4Vd+MM4N0n6uoYUCMdpsM8xqeddan IG47g9ZPJFr+K2Elii+FHcC/B2EZn1NL4TkED0YiIwqLtKXind3Guwi+xlHtoCc07DMB d7ZwdLKsIpBj/cb+mH0i4bpUx+BREJstS/lRESWQAaNikdCvVk8JItDccYYcSOVMH8hs Lw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 353egkmw65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:30:27 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LUP5L121460; Tue, 1 Dec 2020 21:30:27 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 35404ndkqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:26 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1LUFee021142; Tue, 1 Dec 2020 21:30:15 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:14 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 14/15] libiscsi: drop back_lock from xmit path Date: Tue, 1 Dec 2020 15:29:55 -0600 Message-Id: <1606858196-5421-15-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=933 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 suspectscore=2 phishscore=0 mlxlogscore=966 lowpriorityscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We have a proper refcount on the task so if we get a rsp while R2Ts are queued then we will not crash. We only need to check if a rsp has been processed and if we race it's ok since with a bad target we could get this rsp at any time like after dropping the lock and starting to send data so the lock use doesn't matter. This patch just drops the lock since we will eventually either see the updated state or we will send all the data and free the task. I'm not 100% sure though and am thinking we might want to use READ/ WRITE_ONCE or use a barrier? Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 0643156..e020fba 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -1529,8 +1529,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref) /* done with this task */ task->last_xfer = jiffies; } - /* regular RX path uses back_lock */ - spin_lock(&conn->session->back_lock); if (rc && task->state == ISCSI_TASK_RUNNING) { /* * get an extra ref that is released next time we access it @@ -1539,7 +1537,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref) iscsi_get_task(task); conn->task = task; } - spin_unlock(&conn->session->back_lock); put_task: iscsi_put_task(task); From patchwork Tue Dec 1 21:29:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 11943859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D80BC64E7A for ; Tue, 1 Dec 2020 21:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9932420870 for ; Tue, 1 Dec 2020 21:33:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="L/LLEoKO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729198AbgLAVdK (ORCPT ); Tue, 1 Dec 2020 16:33:10 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:59484 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728548AbgLAVdJ (ORCPT ); Tue, 1 Dec 2020 16:33:09 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LSx7G081112; Tue, 1 Dec 2020 21:32:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=gUJQhfOD6F5BbtI4YaUIpIDrmKr6VtxIjpNoQYugrTw=; b=L/LLEoKO+Q3NfqU5m74noRRnMFsqthLy1vZifkJiBMmuluAyI1XHKOK0kIb6qupqQPDR 7MEw/FMbC3qOv7kULQNPnUh52mXYJcsV+m48tg0AtOpUw2yxlfgSoAcPj2PN5Iywi3NL oDps5pIWYnmamJgmaN3gxTzE0XnPfJeNa2gfcgdw2DkgXldiNLMLNRIgHdNwnihO7mcW H4VvfG+iVtekVUp2IOApSI+4MxqXMstwjpNiPmMcW+VgLGIG5FX7n7MO/HuOID1KMk7z W+NYoh3Vanor+PGSQm8jHVkpkCcfhTQfq1HXbLMpj7Md1r0E8QR0M6jzDTc2C/vuNlxH DQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 353egkmwf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 21:32:20 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LUIqd131117; Tue, 1 Dec 2020 21:30:19 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 3540at23sg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 21:30:19 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0B1LUFsO018440; Tue, 1 Dec 2020 21:30:15 GMT Received: from ol2.localdomain (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 13:30:15 -0800 From: Mike Christie To: subbu.seetharaman@broadcom.com, ketan.mukadam@broadcom.com, jitendra.bhivare@broadcom.com, lduncan@suse.com, cleech@redhat.com, njavali@marvell.com, mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, varun@chelsio.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, james.bottomley@hansenpartnership.com Subject: [PATCH 15/15] libiscsi: convert ping_task to refcount handler Date: Tue, 1 Dec 2020 15:29:56 -0600 Message-Id: <1606858196-5421-16-git-send-email-michael.christie@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> References: <1606858196-5421-1-git-send-email-michael.christie@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 suspectscore=2 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 suspectscore=2 phishscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010130 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The conn_send_pdu API is evil in that it returns a pointer to a iscsi_task, but that task might have been freed already. This would happen with the ping_task code. To fix up the API so the caller can access the task if it needs to like in the ping_task case, this has conn_send_pdu grab a ref to the task for the caller. We then move the ping_task clearing to when all the refcounts are dropped, so we know the caller and a completion do not race. Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 39 +++++++++++++++++++++------------------ include/scsi/libiscsi.h | 3 --- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index e020fba..79cec93 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -546,13 +546,16 @@ static void iscsi_free_task(struct iscsi_task *task) return; iscsi_free_itt(session, task); - + if (session->win_opened && !work_pending(&conn->xmitwork)) { session->win_opened = false; iscsi_conn_queue_work(conn); } if (!sc) { + if (READ_ONCE(conn->ping_task) == task) + WRITE_ONCE(conn->ping_task, NULL); + spin_lock_bh(&session->mgmt_lock); kfifo_in(&session->mgmt_pool.queue, (void*)&task, sizeof(void*)); spin_unlock_bh(&session->mgmt_lock); @@ -603,9 +606,6 @@ static void iscsi_complete_task(struct iscsi_task *task, int state) WARN_ON_ONCE(task->state == ISCSI_TASK_FREE); task->state = state; - if (READ_ONCE(conn->ping_task) == task) - WRITE_ONCE(conn->ping_task, NULL); - /* release get from queueing */ iscsi_put_task(task); } @@ -819,6 +819,8 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, task->sc = NULL; INIT_LIST_HEAD(&task->running); task->state = ISCSI_TASK_PENDING; + /* Take an extra ref so the caller can access the task */ + iscsi_get_task(task); if (data_size) { memcpy(task->data, data, data_size); @@ -846,9 +848,6 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, task->conn->session->age); } - if (unlikely(READ_ONCE(conn->ping_task) == INVALID_SCSI_TASK)) - WRITE_ONCE(conn->ping_task, task); - if (!ihost->workq) { if (iscsi_prep_mgmt_task(conn, task)) goto free_task; @@ -863,6 +862,8 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, return task; free_task: + /* drop extra count taken for caller and count from allocation */ + iscsi_put_task(task); iscsi_put_task(task); return NULL; } @@ -872,11 +873,15 @@ int iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr, { struct iscsi_conn *conn = cls_conn->dd_data; struct iscsi_session *session = conn->session; + struct iscsi_task *task; int err = 0; spin_lock_bh(&session->frwd_lock); - if (!__iscsi_conn_send_pdu(conn, hdr, data, data_size)) + task = __iscsi_conn_send_pdu(conn, hdr, data, data_size); + if (!task) err = -EPERM; + else + iscsi_put_task(task); spin_unlock_bh(&session->frwd_lock); return err; } @@ -1047,12 +1052,6 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr) struct iscsi_nopout hdr; struct iscsi_task *task; - if (!rhdr) { - if (READ_ONCE(conn->ping_task)) - return -EINVAL; - WRITE_ONCE(conn->ping_task, INVALID_SCSI_TASK); - } - memset(&hdr, 0, sizeof(struct iscsi_nopout)); hdr.opcode = ISCSI_OP_NOOP_OUT | ISCSI_OP_IMMEDIATE; hdr.flags = ISCSI_FLAG_CMD_FINAL; @@ -1061,20 +1060,23 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr) hdr.lun = rhdr->lun; hdr.ttt = rhdr->ttt; hdr.itt = RESERVED_ITT; - } else + } else { + if (READ_ONCE(conn->ping_task)) + return -EINVAL; + hdr.ttt = RESERVED_ITT; + } task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0); if (!task) { - if (!rhdr) - WRITE_ONCE(conn->ping_task, NULL); iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n"); return -EIO; } else if (!rhdr) { /* only track our nops */ conn->last_ping = jiffies; + WRITE_ONCE(conn->ping_task, task); } - + iscsi_put_task(task); return 0; } @@ -1907,6 +1909,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn, spin_lock_bh(&session->frwd_lock); return -EPERM; } + iscsi_put_task(task); conn->tmfcmd_pdus_cnt++; conn->tmf_timer.expires = timeout * HZ + jiffies; add_timer(&conn->tmf_timer); diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index d0a6834..a17c551 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -133,9 +133,6 @@ struct iscsi_task { void *dd_data; /* driver/transport data */ }; -/* invalid scsi_task pointer */ -#define INVALID_SCSI_TASK (struct iscsi_task *)-1l - static inline int iscsi_task_has_unsol_data(struct iscsi_task *task) { return task->unsol_r2t.data_length > task->unsol_r2t.sent;