Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3432910imu; Sun, 11 Nov 2018 15:00:34 -0800 (PST) X-Google-Smtp-Source: AJdET5fcHVgsesiEFUjuOncAC1KlizG4oCy1QUGrvYVL9NLARltC96DUiToaPVoECCIGQFXJSWz8 X-Received: by 2002:aa7:814f:: with SMTP id d15-v6mr18021990pfn.78.1541977234391; Sun, 11 Nov 2018 15:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977234; cv=none; d=google.com; s=arc-20160816; b=mHUDlzrr53BhP96IFyuIxtwWs3BUCl4tfXCE2p4yKPzy1erTQpwVAq7TIw9p0GUj4L 5Y/dDmCsQwpmWa2Xgzgy5ulC3xIPtNGOIHzlv4RhZZIpIpAyKRodHmthZVsCWEG8oMPR cOwS8plrpBsR0QR8YpAg2VnU/cTaC7jb6JAsSTNiCjaJhXxY8I53z0x1jBUrVPNi35B7 9RHq8srWIZyFM8ARP+jYj/4BgY4k69lBXdyRB56jBE/sRHoHGuaV8LocxlJ+VwHJvpuF l38botu4q0v1/TOjjyuv7KKHylQlTdsMQZnoEJzblKVUwshZu1vCo1j3rKtbsonYwFJe JIag== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W9u3NQPW0YWPo0sc1col13cPvYti3M4iEHGWTTQigBk=; b=pArm0ufHfIBX8xj5ELm6ZA/tZNNwghwlRUvboMc0dkKKQfQ5Wh0qWo/dlNXms2GIuc 5gxTqgraGYorrsGWcklyYZaqv6tH/At1Qxh/9UMKZG6PIQmlFhlRSg5kBd0R1uQo7PoE JsV8qjQCWwQx9r28ZeYxV1EWmBdLCDiUAHLEoMX7va/5Zgqv65A8N4OzlncJisDME/Iv O5cr+8Ku6EZ13rUBtoAfbg4GNtFm0Vg71qjyxnnN1YEnCMs/FSntBomclb2R5mKHgaJ+ 9DRy+Zm23gekT0KxWDMvdLGE5tbnx6GCsf3Lhk4j441Yje0A1b6qTzi3LadBAF+5q6ae uEwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pPPudz4H; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 65-v6si16702796pfl.220.2018.11.11.15.00.19; Sun, 11 Nov 2018 15:00:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pPPudz4H; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390843AbeKLIse (ORCPT + 99 others); Mon, 12 Nov 2018 03:48:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:52752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403761AbeKLIWk (ORCPT ); Mon, 12 Nov 2018 03:22:40 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1D74A224B3; Sun, 11 Nov 2018 22:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975563; bh=whBubtctHN0XzGkrB9oquC7z6UDi+Qk+HBPwW0+Ecig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPPudz4HY7LQLKBxlPpBe3QA39dT85k6t3Da/dGz/fdy+tWkLxW5qzAG1pUKxbINK g4BWHRrE241HZXlK0q9G/DeZY+l/nEp3mbtpFRxW5QndjCistIEafbrjILgUU1AxqN tVmespqNabQ6LXXuAYm5ko97V1bEQGBzprzq29G8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dick Kennedy , James Smart , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 102/222] scsi: lpfc: Correct race with abort on completion path Date: Sun, 11 Nov 2018 14:23:19 -0800 Message-Id: <20181111221657.031781487@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: James Smart [ Upstream commit ca7fb76e091f889cfda1287c07a9358f73832b39 ] On io completion, the driver is taking an adapter wide lock and nulling the scsi command back pointer. The nulling of the back pointer is to signify the io was completed and the scsi_done() routine was called. However, the routine makes no check to see if the abort routine had done the same thing and possibly nulled the pointer. Thus it may doubly-complete the io. Make the following mods: - Check to make sure forward progress (call scsi_done()) only happens if the command pointer was non-null. - As the taking of the lock, which is adapter wide, is very costly on a system under load, null the pointer using an xchg operation rather than under lock. Signed-off-by: Dick Kennedy Signed-off-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/lpfc/lpfc_scsi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/scsi/lpfc/lpfc_scsi.c +++ b/drivers/scsi/lpfc/lpfc_scsi.c @@ -4149,9 +4149,17 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); - spin_lock_irqsave(&phba->hbalock, flags); - lpfc_cmd->pCmd = NULL; - spin_unlock_irqrestore(&phba->hbalock, flags); + /* If pCmd was set to NULL from abort path, do not call scsi_done */ + if (xchg(&lpfc_cmd->pCmd, NULL) == NULL) { + lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, + "0711 FCP cmd already NULL, sid: 0x%06x, " + "did: 0x%06x, oxid: 0x%04x\n", + vport->fc_myDID, + (pnode) ? pnode->nlp_DID : 0, + phba->sli_rev == LPFC_SLI_REV4 ? + lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff); + return; + } /* The sdev is not guaranteed to be valid post scsi_done upcall. */ cmd->scsi_done(cmd);