Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2925888rwb; Mon, 15 Aug 2022 14:10:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR7+3f3lGh9kj1SF684TSJVdDJfxjduw3bU5u1GEgh/JbQSUDfiLdDJHU8A+5+75PNdbyXDt X-Received: by 2002:a05:6402:3805:b0:43e:8335:3a2a with SMTP id es5-20020a056402380500b0043e83353a2amr16457166edb.296.1660597857926; Mon, 15 Aug 2022 14:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597857; cv=none; d=google.com; s=arc-20160816; b=zX5645tvhkIsLqVlS33l1PqBJmGwM/pb/sTm8hCjBVIbRQ3kfDFxrVueyFt94/VuM/ +upWg9kKw0W9ZvbUP8HpFvgxr+29kniG9ssiTqAjHIj4ftHGZy9nrwuo43eb/1Ci5SUV Uyxt8tLfP/58KQs9Lit1XPy8DEnVHeHFKPT52esKSatSdaSp/6LeEzRuRizAKyo5kcwY o8mf8jptza2upAeiDvivSEf5kvfgIZ2hjhk31T6rfSU6Dss/QHvxRqWUbZMy1G2bGnfr VZNRidgaNszewKgarzJzoZ6c/39wnFJuYUucnAQjPHTzMxU1e9EWQffoinbzkMNLcUNs hhsg== 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=qvKjbPzMtHYWHnpHIv+4bTVAxZM3UbuJ1ujP3+MCGRM=; b=n5O3Sg68h7vp1/nNGovIJmjlfgkUB74LGXc3oyr7ZwfFqcKqa8ohfop9D68e+t+cvd tFr1jrsTYq8kUH94o6SSvD4Teouw27yP0JriurmGT3lHJhos2SKtpBGZGEgi5D2/3FyQ N+0iU1nWrChTD/nLr5rlNJ4pbQ3nXUjFryARCcjImI5IvAog8yA3h9uLgnJIh9iPsIw3 y5Z8P1m9RFieS6WJP/XSga+BO2ZTyS6OgvMc7W4R5P0/0wGAcB8NCOQCIKiIs/wLg0YG qLXsrZDwbsXyCpPyR+h4z9BQnDzFjfHeSz+ClP2QMXiqWtu0BxLZh2SbOd8rwk2VNfQK OOpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pplMujBR; 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 q1-20020aa7da81000000b004420193029esi7932744eds.343.2022.08.15.14.10.32; Mon, 15 Aug 2022 14:10:57 -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=pplMujBR; 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 S1345103AbiHOTrS (ORCPT + 99 others); Mon, 15 Aug 2022 15:47:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344820AbiHOTo4 (ORCPT ); Mon, 15 Aug 2022 15:44:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FAD6C77C; Mon, 15 Aug 2022 11:48:33 -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 ams.source.kernel.org (Postfix) with ESMTPS id 07649B81085; Mon, 15 Aug 2022 18:48:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BF20C433D6; Mon, 15 Aug 2022 18:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589310; bh=za6LKnhUJdxSuV7U5K0XsjjVK4rZw9f/Aesz5mtYlSo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pplMujBReiJ/GsvOrHu+8ctGBQhBDkbAG3obKxsnImzYlsqz05QmtpYhESvzcp8iK yTuAKA1YBGpW7Lb4luHbbYrAXf+ZdtXcS38Uu/0gvZgKI5gwXeCN6gmYU4YY4vnpCh xUmriG/889kRAdsqXfJUx6/tZIvqEob64esDX+hQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arun Easi , Nilesh Javali , "Martin K. Petersen" Subject: [PATCH 5.15 679/779] scsi: qla2xxx: Fix losing target when it reappears during delete Date: Mon, 15 Aug 2022 20:05:23 +0200 Message-Id: <20220815180406.381381897@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 commit 118b0c863c8f5629cc5271fc24d72d926e0715d9 upstream. FC target disappeared during port perturbation tests due to a race that tramples target state. Fix the issue by adding state checks before proceeding. Link: https://lore.kernel.org/r/20220616053508.27186-8-njavali@marvell.com Fixes: 44c57f205876 ("scsi: qla2xxx: Changes to support FCP2 Target") Cc: stable@vger.kernel.org Signed-off-by: Arun Easi Signed-off-by: Nilesh Javali Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/qla2xxx/qla_attr.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) --- a/drivers/scsi/qla2xxx/qla_attr.c +++ b/drivers/scsi/qla2xxx/qla_attr.c @@ -2705,17 +2705,24 @@ qla2x00_dev_loss_tmo_callbk(struct fc_rp if (!fcport) return; - /* Now that the rport has been deleted, set the fcport state to - FCS_DEVICE_DEAD */ - qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD); + + /* + * Now that the rport has been deleted, set the fcport state to + * FCS_DEVICE_DEAD, if the fcport is still lost. + */ + if (fcport->scan_state != QLA_FCPORT_FOUND) + qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD); /* * Transport has effectively 'deleted' the rport, clear * all local references. */ spin_lock_irqsave(host->host_lock, flags); - fcport->rport = fcport->drport = NULL; - *((fc_port_t **)rport->dd_data) = NULL; + /* Confirm port has not reappeared before clearing pointers. */ + if (rport->port_state != FC_PORTSTATE_ONLINE) { + fcport->rport = fcport->drport = NULL; + *((fc_port_t **)rport->dd_data) = NULL; + } spin_unlock_irqrestore(host->host_lock, flags); if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags)) @@ -2748,9 +2755,12 @@ qla2x00_terminate_rport_io(struct fc_rpo /* * At this point all fcport's software-states are cleared. Perform any * final cleanup of firmware resources (PCBs and XCBs). + * + * Attempt to cleanup only lost devices. */ if (fcport->loop_id != FC_NO_LOOP_ID) { - if (IS_FWI2_CAPABLE(fcport->vha->hw)) { + if (IS_FWI2_CAPABLE(fcport->vha->hw) && + fcport->scan_state != QLA_FCPORT_FOUND) { if (fcport->loop_id != FC_NO_LOOP_ID) fcport->logout_on_delete = 1; @@ -2760,7 +2770,7 @@ qla2x00_terminate_rport_io(struct fc_rpo __LINE__); qlt_schedule_sess_for_deletion(fcport); } - } else { + } else if (!IS_FWI2_CAPABLE(fcport->vha->hw)) { qla2x00_port_logout(fcport->vha, fcport); } }