Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3178900imw; Mon, 11 Jul 2022 03:39:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sNlXaZ9WUc9XPsLNZgoCNVE4IP9IukxjnqdeH7MNPdpRIsbgvBIHelK/aPniS9LXzJ/8VO X-Received: by 2002:a05:6402:f12:b0:43a:7eac:296e with SMTP id i18-20020a0564020f1200b0043a7eac296emr23913486eda.115.1657535999437; Mon, 11 Jul 2022 03:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657535999; cv=none; d=google.com; s=arc-20160816; b=hrBj0EyE5wjFioXvLjQD1v8NJ5oTTAGJc1u3vCW5XV6pJi7GVQ1fj+l3MXV3WNQlKG keCsc0kimVNBRghCiXocpKs6KeNX9DMfqIKF2vQmaOiX+8aszKbrDyg/LCAGVhony4Zc +jZNAT+KIbcUQ/1ehNGZuoLGe1412ry0WCjEgJto+6Mj1anM0FWvbY2wvgFJHJOnXhF8 BkVSEz/YJDfxYgBd0vatjrG3D9OwWSCiHrv3h6As5OiI8j99WI6yfiFPqqZd/IBLWQe4 ZErmTNf/cr6wjS8chi5Z6xzNa4vbc8kgtiIpr1w3yyvFmqYRwG/ZXfSWQSB8IVu/UTAk Q1/A== 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=G/tmiIS6qbEVWyx+b+XxKNbN+6Mmv8wM4/fcvLb0Sew=; b=hjdGrUyonsMoWbQ7wa8N7nyaOeoXkIOj87Oi+QtPgT/CqeSVNPDnJgYu5tt2LzWelU Wi0Re7pph386AXFlu+Ish2oTkx6CYBbgoW6D3ZaDKZ46fQu2YphZLFM18D8F7XHi/Uls cbV6RjzC5yBlAssGfPEUX1wuIDkcjzc10cb+inZQajhNKTgUnOeCi5XOc1tkTp9rzjMt hNkwOz+jxv3Y6S25NDKslAEuhufpqKN8hzzHmaOBcLYLX1yd8WRs2GSKfpfByWjlvxJl ba+64Wki6lLrjQ+s1IZSZhBzco3PUyJ25doVIpINQR4dHsittCyoybra0W/MKmm2GTTC H34w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vMnf0XQb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a05640202c500b0043a26f522f7si8842461edx.67.2022.07.11.03.39.32; Mon, 11 Jul 2022 03:39:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vMnf0XQb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233719AbiGKJuE (ORCPT + 99 others); Mon, 11 Jul 2022 05:50:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233791AbiGKJtP (ORCPT ); Mon, 11 Jul 2022 05:49:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FFFC7AB23; Mon, 11 Jul 2022 02:23:56 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 129FD6134C; Mon, 11 Jul 2022 09:23:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11106C34115; Mon, 11 Jul 2022 09:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657531435; bh=3I3gg384dMTs0wQ0ZdufSMp00jh+Tq4Oo6AjInUC+LE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vMnf0XQbh2ccrstp3v/SOgVnSvcgCtfjqcQh3PcTcx4cROfOC9IwseNA4n+LzctAz I8vLdWhxrSfsrnP6jiuNLQYOgqO4OPWaQoWLggLfwKganiNi3pOjU5Xg0Y4RIiXHmq Ywzl7B7yMljvRybram6pMWYHRa927HVQiZwb+PO0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marco Patalano , Himanshu Madhani , Arun Easi , Nilesh Javali , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.15 105/230] scsi: qla2xxx: Fix loss of NVMe namespaces after driver reload test Date: Mon, 11 Jul 2022 11:06:01 +0200 Message-Id: <20220711090607.046745625@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090604.055883544@linuxfoundation.org> References: <20220711090604.055883544@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arun Easi [ Upstream commit db212f2eb3fb7f546366777e93c8f54614d39269 ] Driver registration of localport can race when it happens at the remote port discovery time. Fix this by calling the registration under a mutex. Link: https://lore.kernel.org/r/20220310092604.22950-4-njavali@marvell.com Fixes: e84067d74301 ("scsi: qla2xxx: Add FC-NVMe F/W initialization and transport registration") Cc: stable@vger.kernel.org Reported-by: Marco Patalano Tested-by: Marco Patalano Reviewed-by: Himanshu Madhani Signed-off-by: Arun Easi Signed-off-by: Nilesh Javali Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/qla2xxx/qla_nvme.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c index 42b29f4fd937..1bf3ab10846a 100644 --- a/drivers/scsi/qla2xxx/qla_nvme.c +++ b/drivers/scsi/qla2xxx/qla_nvme.c @@ -775,7 +775,6 @@ int qla_nvme_register_hba(struct scsi_qla_host *vha) ha = vha->hw; tmpl = &qla_nvme_fc_transport; - WARN_ON(vha->nvme_local_port); qla_nvme_fc_transport.max_hw_queues = min((uint8_t)(qla_nvme_fc_transport.max_hw_queues), @@ -786,13 +785,25 @@ int qla_nvme_register_hba(struct scsi_qla_host *vha) pinfo.port_role = FC_PORT_ROLE_NVME_INITIATOR; pinfo.port_id = vha->d_id.b24; - ql_log(ql_log_info, vha, 0xffff, - "register_localport: host-traddr=nn-0x%llx:pn-0x%llx on portID:%x\n", - pinfo.node_name, pinfo.port_name, pinfo.port_id); - qla_nvme_fc_transport.dma_boundary = vha->host->dma_boundary; - - ret = nvme_fc_register_localport(&pinfo, tmpl, - get_device(&ha->pdev->dev), &vha->nvme_local_port); + mutex_lock(&ha->vport_lock); + /* + * Check again for nvme_local_port to see if any other thread raced + * with this one and finished registration. + */ + if (!vha->nvme_local_port) { + ql_log(ql_log_info, vha, 0xffff, + "register_localport: host-traddr=nn-0x%llx:pn-0x%llx on portID:%x\n", + pinfo.node_name, pinfo.port_name, pinfo.port_id); + qla_nvme_fc_transport.dma_boundary = vha->host->dma_boundary; + + ret = nvme_fc_register_localport(&pinfo, tmpl, + get_device(&ha->pdev->dev), + &vha->nvme_local_port); + mutex_unlock(&ha->vport_lock); + } else { + mutex_unlock(&ha->vport_lock); + return 0; + } if (ret) { ql_log(ql_log_warn, vha, 0xffff, "register_localport failed: ret=%x\n", ret); -- 2.35.1