Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3480246imu; Sun, 11 Nov 2018 16:04:04 -0800 (PST) X-Google-Smtp-Source: AJdET5dqyVikB457v3JabpOsqeXg9CI36g8NRsL4be6yW88+xCHLo+2f4NJdL7vSFh9NsPp67pif X-Received: by 2002:a63:2849:: with SMTP id o70mr15190684pgo.155.1541981044618; Sun, 11 Nov 2018 16:04:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981044; cv=none; d=google.com; s=arc-20160816; b=i0c/oCz7okenOFI601ObAFB1zNyVRU4h/14gYwQ2CZGTO+EBhJpbCVPYLcDCVmZTGz bV5zoGLYJBQyf8ZECKIeUfFoVH0JU935zdQYrGPByKLuwqQuCqwAXkksrWHbx3Jjht2+ ySFMoZEfXi7VsPQOPAm39hARmfOZOkTvGFoCeA61fU56yQXwfe2srKOXeDPjkj/wvs7b WJzzTWz0/SK8IdUEis7pw0aBrLob6ltvYHhNqXe7Q1iqrs3J3SMt/oh4Ij6oqc999aqE kOqtQfAa+OUW67Zmz2QAwKdM09bD90ewzzh4UErCxjkzoLZdX9FGwDs123hESVidJ5mD 2Zag== 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=OCSkjzDhoJ56RNJshaKyzNhop5AuFpNYfBvMc6U3esM=; b=p6MXD1Nldy/xBZZWRjWqHbdehR4hm+ArlNJb835mqUPKtouEB0aZoUz9IcanxseCXz TYa5S0RQSCW9muf4ne9dIkeLijavSlL788FwrPSvxONDsgKAbvNF3VV0JjiQI8o8V1Xu cPMO7gUXWigRJJK9NUb2aKFhMn/cq0PG3jdk0fRFucEcz/ZEOBl2QLrT75LVVpGlUKrL xoA9kOeL97zbAVFlcdeGC29XmLdi1iZB/TLf8w32uH8qnpk/loEsyFrvJ+Ri354nSdAf FFuaWFtYABPf1Giaoliz1uxlzC7Eyioou2Flvc4lEYvDX/dfLFr4EeRgqc1+nvtYr4mu +Rjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vKQ0NOq4; 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 a17-v6si14756485pgf.443.2018.11.11.16.03.49; Sun, 11 Nov 2018 16:04:04 -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=vKQ0NOq4; 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 S1732122AbeKLIRv (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:34236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732056AbeKLIRu (ORCPT ); Mon, 12 Nov 2018 03:17:50 -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 8EA6C215EA; Sun, 11 Nov 2018 22:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975274; bh=2dDIH2CKpijO4x5/ZhBNKUvGgWRJTqRerRuZqiQCXck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vKQ0NOq4Np6medBykwhxXvMecHgPJr/QbW2YtjGQ+Qdg0H9gZyD6M8H4n+45/xVts Hs0fBldZMLmmcAoLOii2PhwEbsDuQ9/2yO8rz4yaewe95jPXV+C+1/yY71lJ9ipd5P 4ON6INSQCav1EOQ9HHFI6PWwPB3CUR7/Rc+eejXM= 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.19 182/361] scsi: lpfc: Correct race with abort on completion path Date: Sun, 11 Nov 2018 14:18:49 -0800 Message-Id: <20181111221645.812862248@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -4158,9 +4158,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);