Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2138856pxb; Fri, 5 Feb 2021 09:49:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxB/6HVSRWGi6s/GC+1M/yOct3MW9CPASjmkFFxkBjJvM5u01wd2cy6yFs4xiKDtQOm9RJ X-Received: by 2002:a17:906:a57:: with SMTP id x23mr5057007ejf.40.1612547364407; Fri, 05 Feb 2021 09:49:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612547364; cv=none; d=google.com; s=arc-20160816; b=Z2B2qJYvhvWcTDxV+AQJX0itHlaa0KqgECavcKiD2o2QRrvbjl7ai5Q/mfNkpqVLpb i5sn8BFVQexHvvkwyZCWXCpBHEwjq5KZQuKcd6Kf/rSaMO2JYd+/iXENRHNv6K+R5GHT qma+0XnjK1NVHNle/8G4/VCQNq7OCoXwqLyw5ngD7a7A4rjSN+HJ1P70F3z9PTX08tw3 yVURd9OlU0FRcYCErKsQKytIhRnISCe8jwYfZ5bMn4r2nboHkLnQbNQVVgwzLhZ3QhmY FB4mB2uSHOJda6bfbt7yKG6TEHzYI9seAMYolqyVc+VlCinoLdPl3rLhWB7xDId4xcke f/yw== 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=EsQNdjJw12Usq5QQ0gMNPUDmg4g2pBKhv3oGed6QQi8=; b=Qieaiv3z4uT3fnJW/Syr9UwhnKOrOwcNoNG84uigpaNNZ93cIYcyfkYivjDiA8eUru Ssc/CD6v/yvlezjmBAdjER7RnNn+T7WDyjntBFFKffU/1PLIshw42wSnzQzxCwF71VPc jMsc+HDTPKV8b9ic/UspaJZS9fROHYrh+66Z55I3cN5cCckncaqM43rXV9O94All9uLW yhLoOpujtqOkIpASWaMn4sBIMyTcbexMrW1Lrd/u4+7dHIkuH9KNEh8eU+NOB3dD8JvF bQ7Bv7Q18txLOUbAe+bMMfm4Q7maFP/Zhh4Ai7jGfal6PswJfUNW60vFGPmoT5M3zPXl fZGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E+YAy6fM; 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 c10si5880482ejf.281.2021.02.05.09.48.58; Fri, 05 Feb 2021 09:49:24 -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=@linuxfoundation.org header.s=korg header.b=E+YAy6fM; 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 S233382AbhBEQFo (ORCPT + 99 others); Fri, 5 Feb 2021 11:05:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:54422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233461AbhBEP7b (ORCPT ); Fri, 5 Feb 2021 10:59:31 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3FDA065071; Fri, 5 Feb 2021 14:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534388; bh=Bmz+88J6KbyvxEg5Rr1e3c7ZoiMhZVsQRiznE0tpD5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E+YAy6fMnLKyEHZ6+r+uKMNfpP0qWvaZMjHB1ppSpoRXcAAAB670+Z9pojTZ6yURt OCJhVBKH76CyYocmO81ek0r6TNrjS18w+Ajozj0bYCyAI+J+unhl6TZVUWIq3dN2Ya hYnq+YPQMfZ2PU3gPiVZeENFT9mEmzzSC4iUbNIU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Javed Hasan , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 19/32] scsi: libfc: Avoid invoking response handler twice if ep is already completed Date: Fri, 5 Feb 2021 15:07:34 +0100 Message-Id: <20210205140653.164018254@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140652.348864025@linuxfoundation.org> References: <20210205140652.348864025@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: Javed Hasan [ Upstream commit b2b0f16fa65e910a3ec8771206bb49ee87a54ac5 ] A race condition exists between the response handler getting called because of exchange_mgr_reset() (which clears out all the active XIDs) and the response we get via an interrupt. Sequence of events: rport ba0200: Port timeout, state PLOGI rport ba0200: Port entered PLOGI state from PLOGI state xid 1052: Exchange timer armed : 20000 msecs  xid timer armed here rport ba0200: Received LOGO request while in state PLOGI rport ba0200: Delete port rport ba0200: work event 3 rport ba0200: lld callback ev 3 bnx2fc: rport_event_hdlr: event = 3, port_id = 0xba0200 bnx2fc: ba0200 - rport not created Yet!! /* Here we reset any outstanding exchanges before freeing rport using the exch_mgr_reset() */ xid 1052: Exchange timer canceled /* Here we got two responses for one xid */ xid 1052: invoking resp(), esb 20000000 state 3 xid 1052: invoking resp(), esb 20000000 state 3 xid 1052: fc_rport_plogi_resp() : ep->resp_active 2 xid 1052: fc_rport_plogi_resp() : ep->resp_active 2 Skip the response if the exchange is already completed. Link: https://lore.kernel.org/r/20201215194731.2326-1-jhasan@marvell.com Signed-off-by: Javed Hasan Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/libfc/fc_exch.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c index 52e8666598531..e5b18e5d46dac 100644 --- a/drivers/scsi/libfc/fc_exch.c +++ b/drivers/scsi/libfc/fc_exch.c @@ -1619,8 +1619,13 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) rc = fc_exch_done_locked(ep); WARN_ON(fc_seq_exch(sp) != ep); spin_unlock_bh(&ep->ex_lock); - if (!rc) + if (!rc) { fc_exch_delete(ep); + } else { + FC_EXCH_DBG(ep, "ep is completed already," + "hence skip calling the resp\n"); + goto skip_resp; + } } /* @@ -1639,6 +1644,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) if (!fc_invoke_resp(ep, sp, fp)) fc_frame_free(fp); +skip_resp: fc_exch_release(ep); return; rel: @@ -1895,10 +1901,16 @@ static void fc_exch_reset(struct fc_exch *ep) fc_exch_hold(ep); - if (!rc) + if (!rc) { fc_exch_delete(ep); + } else { + FC_EXCH_DBG(ep, "ep is completed already," + "hence skip calling the resp\n"); + goto skip_resp; + } fc_invoke_resp(ep, sp, ERR_PTR(-FC_EX_CLOSED)); +skip_resp: fc_seq_set_resp(sp, NULL, ep->arg); fc_exch_release(ep); } -- 2.27.0