Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp168838imd; Wed, 31 Oct 2018 16:42:25 -0700 (PDT) X-Google-Smtp-Source: AJdET5dDFNYU+yiDf5LylN61QZ2YD4gVjmLqATR+8Dwyq1UtIN7WJM1aQzgxILy4rt8vybpcJGYt X-Received: by 2002:a65:4683:: with SMTP id h3mr4772608pgr.225.1541029345131; Wed, 31 Oct 2018 16:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029345; cv=none; d=google.com; s=arc-20160816; b=TwlJnBR5eZr0d7EbO3IzZ09FQDcfreOVKAeiQ+vCN4twXb1LBJava6tg4CG6hlfCPd qOYMtAktLnsCZYvF6sjHx3ZqZJHTlziCuPPgyfh74+k0yPkmCczHuiH7j5tXlqwKnXvG YRZf/HSNhtv3ucSX6H84R+/iowLSZO21lW12nCUivHxod6zXDxd5jDnL8Q0rEyL8AseT 3dt5sM+Uvp7AcKed5dUpbostVDrLD/x9ulYVT/AxHJhHnpneD7ychhaH93ZsB1+fBrM6 5URAhXgqXjXr2Bil2yMoNW4qXpQja5OeGr7viuQdZ7DXhOtLpmfWCysWo7H9pkm7eikx 4UlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=ftcSusMp+/6EoEORSjp4100RzIQrkKf8xRynpL1kj0c=; b=fMSJXxh4VL0MBb3P8hNWc1CW1BJb1uGtFubz6T+ddTNeRJj8ehJFMs5ETMv2WH8aUd VvIbHdfBzMDr0NuJCW6JBL8hcbSYcKK3DVhb+tLgz0Bc3jrFQxKJXfG5ObPTDJsi0Nkz dVLCwQInJ1ERcSz2nWafO9/+teSEWPin2lX7JKfDMDO/zLrwj/MyhwU5QyRHCGHGTBWp yAtXiHX5uVGLT2ghP7iQtgM2Lt6XiPpDamwHOVuVK8B+MN81rcCuVhBKCEcSMcsJoAP9 eRIMnNoL0wy7Wo79wetmw24X8X8SFwfVZJi2Jx+8GcL5Aek5aZRjnLfxVy6Kmvr8nuNr wvuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bysH2Gzt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4-v6si18679701pfb.43.2018.10.31.16.42.10; Wed, 31 Oct 2018 16:42:25 -0700 (PDT) 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=bysH2Gzt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729381AbeKAIIB (ORCPT + 99 others); Thu, 1 Nov 2018 04:08:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:56276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729304AbeKAIH5 (ORCPT ); Thu, 1 Nov 2018 04:07:57 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D6BF520821; Wed, 31 Oct 2018 23:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027266; bh=5cwcGzsybiNvs/5TCc1pXlxTIHGp7BYMnmaalh9DHJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bysH2GztiEyu6KTo9Hv1tqn7KP6otf1BxFeyJpB636ZMzuU0ONhwxPvzXuSMsJLDc NOm7xCLrI9e+84GMSFgcPh+Afi7wmNmWlvqHMmUQ5FdgcmO85ajiWSGri6cpnlVbsz vkDxcgxMSIQW5j7MZIR5tkBeT0cM8LGtSxAoudWQ= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: James Smart , Dick Kennedy , James Smart , "Martin K . Petersen" , Sasha Levin Subject: [PATCH AUTOSEL 4.19 138/146] scsi: lpfc: Correct race with abort on completion path Date: Wed, 31 Oct 2018 19:05:33 -0400 Message-Id: <20181031230541.28822-138-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/scsi/lpfc/lpfc_scsi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c index 5c7858e735c9..200b5bca1f5f 100644 --- 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 *phba, struct lpfc_iocbq *pIocbIn, } 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); -- 2.17.1