Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1753208ybz; Sat, 18 Apr 2020 07:47:41 -0700 (PDT) X-Google-Smtp-Source: APiQypIkIi49jGxp/8DdggWaXi2MG6Sw2f5JVYAGodLAFMBHYB9BOu6dO2Z3/FvQZwob0I+ayx8E X-Received: by 2002:a05:6402:558:: with SMTP id i24mr7152643edx.347.1587221261804; Sat, 18 Apr 2020 07:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587221261; cv=none; d=google.com; s=arc-20160816; b=PE4YzTzx+Q1AK7AgIPMtXNnizp/y7YvRJi4yGcayQopvKqYXIctiSCd0N9kaDVerd4 iBZx0HW55YdY4Zy+D5//AfdgmeG3P0eP7jVTKZyfJBkjN/siCmgaf855PJhxzULp+iDQ YGTyCax3xPZjDqwjZfG3TlwpSbokxJcI9HymQSCdRcSYXcNR1sAim2PKvTcYTBisft6i RtB2G0eFYWwsz1b2hG95w1mpn6kIvef7Qu5/abBJUp7ZJVJF9g9vH/XzGRRBS6gLQ+9y 1Q3uYBonuB/xo2xHzvEHNEY8Jh3PF5L+YradjCFC3MkURB0l4LBL+q2fcXNkVY2eM976 mP7w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PzMxcbpm7FyCtAAqUw7kvhz41WrSW7x7bbpz9/maGO0=; b=hf3XY1e2A65NXWQ1bSbJirVhrHkZmMjAjtREOyflF3lv2/dE6UE4CcHM9FbM0XdoDV 7kQP68d8LrMy+aTJEN5gbyUKab+cT7t05H8mK0GH6Ug+nLbHz1uLur0nIRa0Z/wMYUMo O5eObjb5Ye4Cy7Fr6/BTGl4zRNmiPm6Y5w6sH19h29PXsYIDBOCrrClThQnyhi9x78Hz Bo5adwyTlDcEjc2s+4qEa/YpHeV8uw/18/ZfMtfUqCdDIhHAIZbodrlbMAOAOFYuXzdN aWsFIu4KMTs8NfdVgj5Gn3sjPjec2mEcwjD3CSZQhJmyygqkQNe559pCLKTJhV7SHpOK 2a6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tl46rJbf; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si15589883eds.587.2020.04.18.07.47.19; Sat, 18 Apr 2020 07:47:41 -0700 (PDT) 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=@kernel.org header.s=default header.b=tl46rJbf; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728562AbgDROnW (ORCPT + 99 others); Sat, 18 Apr 2020 10:43:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:54150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728526AbgDROnQ (ORCPT ); Sat, 18 Apr 2020 10:43:16 -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 CD50A22252; Sat, 18 Apr 2020 14:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587220995; bh=PqxfRo3S7O7cb2pVeZtRdeQxVAfzEQvCA3RDsdW1uqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tl46rJbf6EqhpIgAJ3RdXa/vCGZJYZW+InXa6zLA5s5kcqAdZz+vi+QfxfokVKdSR wEqAZGoDJn9QD/+lwe/LYj1xGX9js/gFeyJkLzFrxpll4f8RrHWdC5voSEws2SW8PB TXiWfSwk3K3Zdm8REOHOP3QiqWsoI3QihYMGCnhw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sreekanth Reddy , "Martin K . Petersen" , Sasha Levin , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 38/47] scsi: mpt3sas: Fix kernel panic observed on soft HBA unplug Date: Sat, 18 Apr 2020 10:42:18 -0400 Message-Id: <20200418144227.9802-38-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200418144227.9802-1-sashal@kernel.org> References: <20200418144227.9802-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sreekanth Reddy [ Upstream commit cc41f11a21a51d6869d71e525a7264c748d7c0d7 ] Generic protection fault type kernel panic is observed when user performs soft (ordered) HBA unplug operation while IOs are running on drives connected to HBA. When user performs ordered HBA removal operation, the kernel calls PCI device's .remove() call back function where driver is flushing out all the outstanding SCSI IO commands with DID_NO_CONNECT host byte and also unmaps sg buffers allocated for these IO commands. However, in the ordered HBA removal case (unlike of real HBA hot removal), HBA device is still alive and hence HBA hardware is performing the DMA operations to those buffers on the system memory which are already unmapped while flushing out the outstanding SCSI IO commands and this leads to kernel panic. Don't flush out the outstanding IOs from .remove() path in case of ordered removal since HBA will be still alive in this case and it can complete the outstanding IOs. Flush out the outstanding IOs only in case of 'physical HBA hot unplug' where there won't be any communication with the HBA. During shutdown also it is possible that HBA hardware can perform DMA operations on those outstanding IO buffers which are completed with DID_NO_CONNECT by the driver from .shutdown(). So same above fix is applied in shutdown path as well. It is safe to drop the outstanding commands when HBA is inaccessible such as when permanent PCI failure happens, when HBA is in non-operational state, or when someone does a real HBA hot unplug operation. Since driver knows that HBA is inaccessible during these cases, it is safe to drop the outstanding commands instead of waiting for SCSI error recovery to kick in and clear these outstanding commands. Link: https://lore.kernel.org/r/1585302763-23007-1-git-send-email-sreekanth.reddy@broadcom.com Fixes: c666d3be99c0 ("scsi: mpt3sas: wait for and flush running commands on shutdown/unload") Cc: stable@vger.kernel.org #v4.14.174+ Signed-off-by: Sreekanth Reddy Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index d3c944d997039..5a5e5c3da6571 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -9841,8 +9841,8 @@ static void scsih_remove(struct pci_dev *pdev) ioc->remove_host = 1; - mpt3sas_wait_for_commands_to_complete(ioc); - _scsih_flush_running_cmds(ioc); + if (!pci_device_is_present(pdev)) + _scsih_flush_running_cmds(ioc); _scsih_fw_event_cleanup_queue(ioc); @@ -9919,8 +9919,8 @@ scsih_shutdown(struct pci_dev *pdev) ioc->remove_host = 1; - mpt3sas_wait_for_commands_to_complete(ioc); - _scsih_flush_running_cmds(ioc); + if (!pci_device_is_present(pdev)) + _scsih_flush_running_cmds(ioc); _scsih_fw_event_cleanup_queue(ioc); -- 2.20.1