Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3365629pxb; Mon, 17 Jan 2022 18:42:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7edpCNlkSkntEx4T5voFHUMXnGHg45rVE3aZh0zUERhfKQzLzvN7TVxQ9fyH99fp76H5f X-Received: by 2002:a05:6a00:1407:b0:4c3:3ab:1467 with SMTP id l7-20020a056a00140700b004c303ab1467mr15587529pfu.22.1642473770768; Mon, 17 Jan 2022 18:42:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642473770; cv=none; d=google.com; s=arc-20160816; b=LMTzBEtqiJAa9+WI0xllEW737RDYZOoBc8S3youE6wcRiqZZk2HraIElA8uLfUNUl+ tHuscfuzT3YRZtgt+4y3BY0MG7GstCLvWOzeNF7o8Km2RfXFB317bgToUlecGIIj9QNS ILqurx/8EPJVmvn6AJ+7CIZB1qKya1VgbIu6FXkBFd67Q7M9xWkQifL882VWn5zVoZVN tpLTJwD79LUY5Oasf/clUrgDmm5GYqw7285RMCazqNsNB8LWNqZKz7tmkKTPBZMOnBuA wf/9ppxBt/QX/AiGPG69YvvqShK7B7g+3qCzW15fJybf75lb3eXn4cBZoZNCBDtDglLV BlOA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xK8EZn5OeN+potbbmJ4xyQdy1aR38COr64tPfRizLmI=; b=UVMny74iIVbnoRvpatljErirEUegcO+FhX5KtUcbpjQBUQ7KLucW8Dol6aBqaXdJN5 8kgGVoDHCOf8h7FO0o/v87XAnFxViCLg9I2An14eAlUZ8jhm+j/Es21J5heQKi8X0wNW mWei7oAsW6XGK+yBjRgpNp8W9ZClOQxlTL7/ABhXnqN7xzGQkg2u5ihLJy4WjWUTjLCu hoVsnVWgugZ0HK3BTF6kNrahYMoXZicSDKSuvuMCRizrRmViJHsl2ttkeiruj96wWz9t 4w8m4MUF8BFzV2g4LuJW4HHBhPZNBqdHntxfKq9aj8oLOJ8D0qa3/99WZ0K0SMBlwLyA VGsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OoSHwtdS; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t2si14152975pfh.344.2022.01.17.18.42.38; Mon, 17 Jan 2022 18:42:50 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=OoSHwtdS; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241599AbiAQRAT (ORCPT + 99 others); Mon, 17 Jan 2022 12:00:19 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47802 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241229AbiAQQ7y (ORCPT ); Mon, 17 Jan 2022 11:59:54 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 746D4B81131; Mon, 17 Jan 2022 16:59:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 149A5C36AEF; Mon, 17 Jan 2022 16:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642438792; bh=PVz8ZLaocFB/t0tWMTtejzI8NBaFzsQAP49wgSYBZck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OoSHwtdSrwyJsYwCYHweRjqyoA6FqM69CxVXnnJxk3rr7rDccYoLnI0yWRYYxTto7 mLmjK69AQts4s/LQ+VQ0+S78dTyx/S73XYsVsAluV2fjO47SuP+JJqBsCqjnT24sdx psXKo5AVfhKM/WJRAnWQ4pWERKN55bIrZu4CdS4lQBrMApvj9MdnUBk225G77ieBZL /pY0tx/RolmSlpk6bGPKqcslp6wXYhRJHAWTz10yFe88BVzkcN+Eov/xIsN54Rj6e/ MhbRjW33Gy9l32HofDFLCZCzySArJwFfJK8c85yqBkUAC0j645iNHiHyV//REN1AV2 yy44OJlBi6vSQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: James Smart , Justin Tee , "Martin K . Petersen" , Sasha Levin , james.smart@broadcom.com, dick.kennedy@broadcom.com, jejb@linux.ibm.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 23/52] scsi: lpfc: Fix leaked lpfc_dmabuf mbox allocations with NPIV Date: Mon, 17 Jan 2022 11:58:24 -0500 Message-Id: <20220117165853.1470420-23-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220117165853.1470420-1-sashal@kernel.org> References: <20220117165853.1470420-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Smart [ Upstream commit f0d3919697492950f57a26a1093aee53880d669d ] During rmmod testing, messages appeared indicating lpfc_mbuf_pool entries were still busy. This situation was only seen doing rmmod after at least 1 vport (NPIV) instance was created and destroyed. The number of messages scaled with the number of vports created. When a vport is created, it can receive a PLOGI from another initiator Nport. When this happens, the driver prepares to ack the PLOGI and prepares an RPI for registration (via mbx cmd) which includes an mbuf allocation. During the unsolicited PLOGI processing and after the RPI preparation, the driver recognizes it is one of the vport instances and decides to reject the PLOGI. During the LS_RJT preparation for the PLOGI, the mailbox struct allocated for RPI registration is freed, but the mbuf that was also allocated is not released. Fix by freeing the mbuf with the mailbox struct in the LS_RJT path. As part of the code review to figure the issue out a couple of other areas where found that also would not have released the mbuf. Those are cleaned up as well. Link: https://lore.kernel.org/r/20211204002644.116455-2-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 | 6 +++++- drivers/scsi/lpfc/lpfc_init.c | 8 ++++++-- drivers/scsi/lpfc/lpfc_nportdisc.c | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c index e83453bea2aee..5c10416c1c75a 100644 --- a/drivers/scsi/lpfc/lpfc_els.c +++ b/drivers/scsi/lpfc/lpfc_els.c @@ -6899,6 +6899,7 @@ static int lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) { LPFC_MBOXQ_t *mbox = NULL; + struct lpfc_dmabuf *mp; int rc; mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); @@ -6914,8 +6915,11 @@ lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context; rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); - if (rc == MBX_NOT_FINISHED) + if (rc == MBX_NOT_FINISHED) { + mp = (struct lpfc_dmabuf *)mbox->ctx_buf; + lpfc_mbuf_free(phba, mp->virt, mp->phys); goto issue_mbox_fail; + } return 0; diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index ba17a8f740a95..7628b0634c57a 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -5373,8 +5373,10 @@ lpfc_sli4_async_link_evt(struct lpfc_hba *phba, */ if (!(phba->hba_flag & HBA_FCOE_MODE)) { rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); - if (rc == MBX_NOT_FINISHED) + if (rc == MBX_NOT_FINISHED) { + lpfc_mbuf_free(phba, mp->virt, mp->phys); goto out_free_dmabuf; + } return; } /* @@ -6337,8 +6339,10 @@ lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) } rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); - if (rc == MBX_NOT_FINISHED) + if (rc == MBX_NOT_FINISHED) { + lpfc_mbuf_free(phba, mp->virt, mp->phys); goto out_free_dmabuf; + } return; out_free_dmabuf: diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c index 27263f02ab9f6..7d717a4ac14d1 100644 --- a/drivers/scsi/lpfc/lpfc_nportdisc.c +++ b/drivers/scsi/lpfc/lpfc_nportdisc.c @@ -322,6 +322,7 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, { struct lpfc_hba *phba = vport->phba; struct lpfc_dmabuf *pcmd; + struct lpfc_dmabuf *mp; uint64_t nlp_portwwn = 0; uint32_t *lp; IOCB_t *icmd; @@ -571,6 +572,11 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, * a default RPI. */ if (phba->sli_rev == LPFC_SLI_REV4) { + mp = (struct lpfc_dmabuf *)login_mbox->ctx_buf; + if (mp) { + lpfc_mbuf_free(phba, mp->virt, mp->phys); + kfree(mp); + } mempool_free(login_mbox, phba->mbox_mem_pool); login_mbox = NULL; } else { -- 2.34.1