Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp371225pxa; Fri, 21 Aug 2020 09:20:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1MVU0ubvLtAh0z1vMw6bi8NgVXbi1UDxAXzs7N+2rTBEJ/5Q6nU9vb81Pegf0LbJ1RHi5 X-Received: by 2002:a05:6402:1430:: with SMTP id c16mr3533468edx.144.1598026829512; Fri, 21 Aug 2020 09:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598026829; cv=none; d=google.com; s=arc-20160816; b=o8mg7SuNLmb2ZG5IRjP0svUd+3Ufr+tTOyEZxFn14RWmQVYPMEBoTIyHh9pv6+rRsH UL/IMXCa2M4VAD4sPnc78g4Wdwdw5ovnazhcjSuvCZ5hJ1DjlaRX/2F83mDtdbW32rsF 3m/z6hni95usaN3N7MXIO14TD/khUy+WpeuhoVJ3tmPkhw+K8dtUqqd5B854xEBmnP2R XFA6jc1lhG+ufvIJYV+mPWEddVbUEOE97Sbs+sqf35nxIW8akFtOnK4VmLJn/tjnS8ee TQ+JZcGcXDjG2r1iL1+A/TFjus/gCg8W9xcQ7ZYErk3pu6qWVHIn1WZSSSNKy0J+DEdz TaXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/MbUZdNBG0g5R6eaqHukbMYJNJ5eVcw54yhMIJnoz2M=; b=ZRjSSe3N/8K4pcK2pj727QH2DH9kzLhjz8pQGtNhZMitllrDDbz1znI3H2q4cOkhd3 u+gtLbf+S0HW/FfiWNj7/W4EoCMPo67kPAmEM8y9rxXeXqzhe23dr6XkNOO5uUTYgjPp kBYMADdT3WmrA1iRtcgprUemWuJ8nHycPUJRSBmqFDX5EZbyvKyyHIY0IbPW04W0tXiu SjD5FcqtCeypoz1zqtv8aufo+PQnWZ2lDRhC7iWNGzdwL+pyUyXMmstyDjMh4jfLrd6U vA/RuP3JS09YXUWxu2NndlMRc85cqlads+0u81t91zfNw5DotrkEpoVZ+T37uph36DSc KBKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qbt8lIMM; 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 dg23si1532837edb.12.2020.08.21.09.20.06; Fri, 21 Aug 2020 09:20:29 -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=@kernel.org header.s=default header.b=Qbt8lIMM; 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 S1728109AbgHUQQk (ORCPT + 99 others); Fri, 21 Aug 2020 12:16:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:47142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727769AbgHUQPB (ORCPT ); Fri, 21 Aug 2020 12:15:01 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 40EBA21741; Fri, 21 Aug 2020 16:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598026501; bh=l8A2krO7X5bmyZWqfJPn18y+U9YtDtgV6LKcbdwCpdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qbt8lIMMGBR08EDD7MaA+49J9ekzqpQ5LChjHWPYPSSlhEx/nBywUklwK9BLO39X1 0Muw4HeGCozrv3IX2lQNqV2DF5DBedXr7yYlKIv7Yo1nYA7I8gMB/1/FW4eLg4flro +mDLh39tg1BVHuoho88MySNlBEq+dCbgVcqHiyck= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dick Kennedy , James Smart , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.8 30/62] scsi: lpfc: Fix shost refcount mismatch when deleting vport Date: Fri, 21 Aug 2020 12:13:51 -0400 Message-Id: <20200821161423.347071-30-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200821161423.347071-1-sashal@kernel.org> References: <20200821161423.347071-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dick Kennedy [ Upstream commit 03dbfe0668e6692917ac278883e0586cd7f7d753 ] When vports are deleted, it is observed that there is memory/kthread leakage as the vport isn't fully being released. There is a shost reference taken in scsi_add_host_dma that is not released during scsi_remove_host. It was noticed that other drivers resolve this by doing a scsi_host_put after calling scsi_remove_host. The vport_delete routine is taking two references one that corresponds to an access to the scsi_host in the vport_delete routine and another that is released after the adapter mailbox command completes that destroys the VPI that corresponds to the vport. Remove one of the references taken such that the second reference that is put will complete the missing scsi_add_host_dma reference and the shost will be terminated. Link: https://lore.kernel.org/r/20200630215001.70793-8-jsmart2021@gmail.com Signed-off-by: Dick Kennedy Signed-off-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_vport.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_vport.c b/drivers/scsi/lpfc/lpfc_vport.c index b766463579800..d0296f7cf45fc 100644 --- a/drivers/scsi/lpfc/lpfc_vport.c +++ b/drivers/scsi/lpfc/lpfc_vport.c @@ -642,27 +642,16 @@ lpfc_vport_delete(struct fc_vport *fc_vport) vport->port_state < LPFC_VPORT_READY) return -EAGAIN; } + /* - * This is a bit of a mess. We want to ensure the shost doesn't get - * torn down until we're done with the embedded lpfc_vport structure. - * - * Beyond holding a reference for this function, we also need a - * reference for outstanding I/O requests we schedule during delete - * processing. But once we scsi_remove_host() we can no longer obtain - * a reference through scsi_host_get(). - * - * So we take two references here. We release one reference at the - * bottom of the function -- after delinking the vport. And we - * release the other at the completion of the unreg_vpi that get's - * initiated after we've disposed of all other resources associated - * with the port. + * Take early refcount for outstanding I/O requests we schedule during + * delete processing for unreg_vpi. Always keep this before + * scsi_remove_host() as we can no longer obtain a reference through + * scsi_host_get() after scsi_host_remove as shost is set to SHOST_DEL. */ if (!scsi_host_get(shost)) return VPORT_INVAL; - if (!scsi_host_get(shost)) { - scsi_host_put(shost); - return VPORT_INVAL; - } + lpfc_free_sysfs_attr(vport); lpfc_debugfs_terminate(vport); @@ -809,8 +798,9 @@ lpfc_vport_delete(struct fc_vport *fc_vport) if (!(vport->vpi_state & LPFC_VPI_REGISTERED) || lpfc_mbx_unreg_vpi(vport)) scsi_host_put(shost); - } else + } else { scsi_host_put(shost); + } lpfc_free_vpi(phba, vport->vpi); vport->work_port_events = 0; -- 2.25.1