Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2510711pxj; Mon, 10 May 2021 04:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY4phlJPi0JZbtHTePOeGvQadpGSUEl6iyRJo/9i4lr6IEMwnbbh5TXVwz5RID3HTo2hqA X-Received: by 2002:a17:907:1b06:: with SMTP id mp6mr25682647ejc.292.1620647464535; Mon, 10 May 2021 04:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620647464; cv=none; d=google.com; s=arc-20160816; b=N+zBcflruv5SxRdvJzvbYjdnHwvetuCHxguYD7gKOD1GK+aOBhfqraIMcIQMAaTK9d 1doKGFqXbPEMnWk733XlalgN34PYIB/ajDeR/APg+72ckvib/ExXvYtSZA/dBYSshG2s Z6oHeSsGu3c5hdrzuxgCDuA4veGI/h6bK/Jrz9HWOloqHPkY9+K3gHA1ERkFETH1UfUr 0718ym626L0Gvy6/oy34IT5mOzwkvJCC74A5tO8b08AzAkAWscjaSjo9sCYyfuzdsliu isSQrICL9gL316xWwRDzqVCLqMwlxqVRkc4TOPbAd6HkrJSGmVAgSkG5ZDHnvDRDZh71 cK3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zUFTs6zFjon9EBlfhb8Loq75jFPA8/gI8cjdU0tWEk4=; b=r+k1zqAsDBz+50NTSPpml7bxFzNNODSrssnEZQHN/oJqb6p/VkiY7g7cLu9RMtEOyN e0sVaMuYqFBidkZV4fY0Gs2tji8FSLPkPHxTDz4l67hLwK5/nhFR+RRmly86vk1exbmL cQrtBxaUrlI/H/2W3+gOWSiV15DMoGZZjkTuChYop0Pd1uu/cH5TYj7Zntfw0nz5Inq9 NfzL2DYh7VVERVMHcXnqTRRz0BSrBgGfCB59a7I1VmMrYYG3uxI2PWfiIivsHYJJtZOX XuWBhnxdtoLA4HVpoWB9bxyk8CUcghk6Qbytg8bzi7CU/hyJrepVDdVkVh65KMp7qAxF H/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mWlclV20; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a17si12380035edy.344.2021.05.10.04.50.37; Mon, 10 May 2021 04:51:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mWlclV20; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237264AbhEJLqT (ORCPT + 99 others); Mon, 10 May 2021 07:46:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:52738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233014AbhEJK6e (ORCPT ); Mon, 10 May 2021 06:58:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F380461C42; Mon, 10 May 2021 10:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643947; bh=VK4TKkdLCyYB2jolGzA6DvbjK23JzRWc8QEp68JjztE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mWlclV20F8q2L9TebYFN2bpn6ppCrE4hMRyOlGCt5BbjtgetLzhecbmE+oMJjq3J8 B87MtpI/l+4JL9oR70xxuOmuquYYThdj6XdIsB8OX4Qff4oHrOGkBo0jm4sDnmwghP 6+YYbCgqMOm2VFgu8VMwvMz2VGYhkwi2vAzO9qPQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Justin Tee , James Smart , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.11 226/342] scsi: lpfc: Fix reference counting errors in lpfc_cmpl_els_rsp() Date: Mon, 10 May 2021 12:20:16 +0200 Message-Id: <20210510102017.557144953@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Smart [ Upstream commit f866eb06c087125619457b53e9211a9e758f64f7 ] Call traces are being seen that result from a nodelist structure ref counting error. They are typically seen after transmission of an LS_RJT ELS response. Aged code in lpfc_cmpl_els_rsp() calls lpfc_nlp_not_used() which, if the ndlp reference count is exactly 1, will decrement the reference count. Previously lpfc_nlp_put() was within lpfc_els_free_iocb(), and the 'put' within the free would only be invoked if cmdiocb->context1 was not NULL. Since the nodelist structure reference count is decremented when exiting lpfc_cmpl_els_rsp() the lpfc_nlp_not_used() calls are no longer required. Calling them is causing the reference count issue. Fix by removing the lpfc_nlp_not_used() calls. Link: https://lore.kernel.org/r/20210412013127.2387-4-jsmart2021@gmail.com Co-developed-by: Justin Tee Signed-off-by: Justin Tee Signed-off-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_els.c | 64 +----------------------------------- 1 file changed, 1 insertion(+), 63 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c index 69e8a127b44f..2dce17827504 100644 --- a/drivers/scsi/lpfc/lpfc_els.c +++ b/drivers/scsi/lpfc/lpfc_els.c @@ -4465,10 +4465,7 @@ lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) * nlp_flag bitmap in the ndlp data structure, if the mbox command reference * field in the command IOCB is not NULL, the referred mailbox command will * be send out, and then invokes the lpfc_els_free_iocb() routine to release - * the IOCB. Under error conditions, such as when a LS_RJT is returned or a - * link down event occurred during the discovery, the lpfc_nlp_not_used() - * routine shall be invoked trying to release the ndlp if no other threads - * are currently referring it. + * the IOCB. **/ static void lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, @@ -4478,10 +4475,8 @@ lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; IOCB_t *irsp; - uint8_t *pcmd; LPFC_MBOXQ_t *mbox = NULL; struct lpfc_dmabuf *mp = NULL; - uint32_t ls_rjt = 0; irsp = &rspiocb->iocb; @@ -4493,18 +4488,6 @@ lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, if (cmdiocb->context_un.mbox) mbox = cmdiocb->context_un.mbox; - /* First determine if this is a LS_RJT cmpl. Note, this callback - * function can have cmdiocb->contest1 (ndlp) field set to NULL. - */ - pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); - if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { - /* A LS_RJT associated with Default RPI cleanup has its own - * separate code path. - */ - if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) - ls_rjt = 1; - } - /* Check to see if link went down during discovery */ if (!ndlp || lpfc_els_chk_latt(vport)) { if (mbox) { @@ -4515,15 +4498,6 @@ lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, } mempool_free(mbox, phba->mbox_mem_pool); } - if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) - if (lpfc_nlp_not_used(ndlp)) { - ndlp = NULL; - /* Indicate the node has already released, - * should not reference to it from within - * the routine lpfc_els_free_iocb. - */ - cmdiocb->context1 = NULL; - } goto out; } @@ -4601,29 +4575,6 @@ lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, "Data: x%x x%x x%x\n", ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); - - if (lpfc_nlp_not_used(ndlp)) { - ndlp = NULL; - /* Indicate node has already been released, - * should not reference to it from within - * the routine lpfc_els_free_iocb. - */ - cmdiocb->context1 = NULL; - } - } else { - /* Do not drop node for lpfc_els_abort'ed ELS cmds */ - if (!lpfc_error_lost_link(irsp) && - ndlp->nlp_flag & NLP_ACC_REGLOGIN) { - if (lpfc_nlp_not_used(ndlp)) { - ndlp = NULL; - /* Indicate node has already been - * released, should not reference - * to it from within the routine - * lpfc_els_free_iocb. - */ - cmdiocb->context1 = NULL; - } - } } mp = (struct lpfc_dmabuf *)mbox->ctx_buf; if (mp) { @@ -4639,19 +4590,6 @@ out: ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN; ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI; spin_unlock_irq(&ndlp->lock); - - /* If the node is not being used by another discovery thread, - * and we are sending a reject, we are done with it. - * Release driver reference count here and free associated - * resources. - */ - if (ls_rjt) - if (lpfc_nlp_not_used(ndlp)) - /* Indicate node has already been released, - * should not reference to it from within - * the routine lpfc_els_free_iocb. - */ - cmdiocb->context1 = NULL; } /* Release the originating I/O reference. */ -- 2.30.2