From patchwork Mon Dec 5 08:06:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jitendra Bhivare X-Patchwork-Id: 9460581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DBAD96071F for ; Mon, 5 Dec 2016 08:07:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD2CB20009 for ; Mon, 5 Dec 2016 08:07:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C157624DA2; Mon, 5 Dec 2016 08:07:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7733124B5B for ; Mon, 5 Dec 2016 08:07:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751388AbcLEIHR (ORCPT ); Mon, 5 Dec 2016 03:07:17 -0500 Received: from mail-qt0-f182.google.com ([209.85.216.182]:33645 "EHLO mail-qt0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750849AbcLEIHQ (ORCPT ); Mon, 5 Dec 2016 03:07:16 -0500 Received: by mail-qt0-f182.google.com with SMTP id p16so305896694qta.0 for ; Mon, 05 Dec 2016 00:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=opvklqDWh35wjVsEIe9LJK+2fa/Zdkc5A7NsRr51Kjg=; b=AXsvox+vhaDAauwAf4nW7R9/r4772FCb0FHK7xpLSlPJ/clxkPdgZyVN0itGC/k61W wp1seX0RRFGMjJCuyDPEZMRcTkvdulEyKKvXi6Di406N3J0Hmj9tsBS0XH/Qzgti7nEo GSAaxM3ky1vk/grPo5BUgTMJLZBJ29ls0sSyE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=opvklqDWh35wjVsEIe9LJK+2fa/Zdkc5A7NsRr51Kjg=; b=mPO1jyt3z3sgSN3bDIpkGMZjLx8sJ1IuMcUI5ES+/Pc8UYHiQA14fQ2vIADA/6ohx4 6jHCtcJ0wgVDjzvnFd/9R7SbSip97jpr5gCON/MGBw+JyOxUpE2mvz7yhaaEtkWGqVPH 4l19yBOD7yEhcYqAJkINxDuMdYF6rbzm7vUwoTZgCxfq9y/M+E+Ob/ZTBsY3PZiOnriF rnmQ3TLXCxF20F2Yfchn0GRPKdTYJwE2DTiFyzoDaLOUwWMH1xu/05wB2oFEV8LpCCry X+M9BR03dYn+oZFDZeH4lH36DORnO+/diVfPgdpQlAykzldlbUCS1X8dUkn1tHB1R1hk udlA== X-Gm-Message-State: AKaTC01aHynTRCFumjTKQH+LN2caLKI4keUmmdPFV/3HRf+PYgvOhIsytanog7SaNHYdH13A X-Received: by 10.237.33.69 with SMTP id 63mr47891269qtc.182.1480925235641; Mon, 05 Dec 2016 00:07:15 -0800 (PST) Received: from android.dhcp.avagotech.net ([192.19.239.250]) by smtp.gmail.com with ESMTPSA id i19sm8890519qte.8.2016.12.05.00.07.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Dec 2016 00:07:15 -0800 (PST) From: Jitendra Bhivare To: cleech@redhat.com, lduncan@suse.com Cc: linux-scsi@vger.kernel.org, Jitendra Bhivare Subject: [PATCH 05/12] be2iscsi: Add checks to validate completions Date: Mon, 5 Dec 2016 13:36:44 +0530 Message-Id: <1480925211-13223-6-git-send-email-jitendra.bhivare@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480925211-13223-1-git-send-email-jitendra.bhivare@broadcom.com> References: <1480925211-13223-1-git-send-email-jitendra.bhivare@broadcom.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Added check in beiscsi_process_cq for pio_handle. pio_handle is cleared in beiscsi_put_wrb_handle. This catches any case where task gets cleaned up just before completion. Use back_lock before accessing pio_handle. Signed-off-by: Jitendra Bhivare --- drivers/scsi/be2iscsi/be_main.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c index 948384c..bd5e10e 100644 --- a/drivers/scsi/be2iscsi/be_main.c +++ b/drivers/scsi/be2iscsi/be_main.c @@ -960,6 +960,10 @@ static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) unsigned long flags; spin_lock_irqsave(&pwrb_context->wrb_lock, flags); + if (!pwrb_context->wrb_handles_available) { + spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); + return NULL; + } pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; pwrb_context->wrb_handles_available--; if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) @@ -1010,6 +1014,7 @@ struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid, pwrb_context->free_index = 0; else pwrb_context->free_index++; + pwrb_handle->pio_handle = NULL; spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); } @@ -1220,6 +1225,7 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) uint16_t wrb_index, cid, cri_index; struct hwi_controller *phwi_ctrlr; struct wrb_handle *pwrb_handle; + struct iscsi_session *session; struct iscsi_task *task; phwi_ctrlr = phba->phwi_ctrlr; @@ -1238,8 +1244,12 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) cri_index = BE_GET_CRI_FROM_CID(cid); pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index]; + session = beiscsi_conn->conn->session; + spin_lock_bh(&session->back_lock); task = pwrb_handle->pio_handle; - iscsi_put_task(task); + if (task) + __iscsi_put_task(task); + spin_unlock_bh(&session->back_lock); } static void @@ -1319,16 +1329,16 @@ static void adapter_get_sol_cqe(struct beiscsi_hba *phba, static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, struct beiscsi_hba *phba, struct sol_cqe *psol) { + struct iscsi_conn *conn = beiscsi_conn->conn; + struct iscsi_session *session = conn->session; + struct common_sol_cqe csol_cqe = {0}; struct hwi_wrb_context *pwrb_context; + struct hwi_controller *phwi_ctrlr; struct wrb_handle *pwrb_handle; struct iscsi_wrb *pwrb = NULL; - struct hwi_controller *phwi_ctrlr; struct iscsi_task *task; - unsigned int type; - struct iscsi_conn *conn = beiscsi_conn->conn; - struct iscsi_session *session = conn->session; - struct common_sol_cqe csol_cqe = {0}; uint16_t cri_index = 0; + uint8_t type; phwi_ctrlr = phba->phwi_ctrlr; @@ -1341,11 +1351,15 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, pwrb_handle = pwrb_context->pwrb_handle_basestd[ csol_cqe.wrb_index]; + spin_lock_bh(&session->back_lock); task = pwrb_handle->pio_handle; + if (!task) { + spin_unlock_bh(&session->back_lock); + return; + } pwrb = pwrb_handle->pwrb; type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; - spin_lock_bh(&session->back_lock); switch (type) { case HWH_TYPE_IO: case HWH_TYPE_IO_RD: