From patchwork Mon May 28 21:21:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10434027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C64C60249 for ; Mon, 28 May 2018 21:22:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A4AC2851B for ; Mon, 28 May 2018 21:22:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DA862852B; Mon, 28 May 2018 21:22:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 284F82851B for ; Mon, 28 May 2018 21:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=2R/6S31iyXy2FsvADEO1wA0jmJtzV/iJLIHIqHHDOT0=; b=tMdhoISvHoG/II 7XZMLl8ntiJ0Go4rMAgrIDyaMHaP1t7H2k5BP2CkAn6wwzJO+cPR6xXDUvBzaK49vnjvkV5n60iGu FuEAipFMj1ukkuIDNSK/P29+K9GksV0i+eUe4AXT9devVkyVMeem9EqiPn0OVXVNMfgHhe1unoFwG YQJVog38lLoTh6S9uqud2ibcx2iQ0MTJQyqNhllt9AZwtGsTuq6Zkd6lzvM36xCaBZy8nYlyRJn+y Mn9xmwuOcCd6GUA926LIDpPleK9RSH/1QFlzXNTPGPMh6cwesgp4dSmGcJ/i24NykFRY77TOCTFqu 17dSqnyAOO15O14GfvxQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fNPag-0003Tq-5I; Mon, 28 May 2018 21:22:06 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fNPa5-0003CG-Ra for linux-arm-kernel@lists.infradead.org; Mon, 28 May 2018 21:21:31 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 77E5E606FC; Mon, 28 May 2018 21:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527542478; bh=J3YUQblI7jH9b8qOQWBFxZTFZcLj0oMkcDxzgwfABwI=; h=From:To:Cc:Subject:Date:From; b=IB1VencNJlLlFhfCY5g6kRTa60PakHAnf0IOJZTcOO61tVZV6Xk/e9WFbuum5IB8v 5Z2It8591wVglbSugM+xS5YPI/lbXYlPtsnTh8ha72LPJWhiU5YKGLjNpnEeTj75Rx Vbj3drxN/YDH3eKS57R12HD0d9kC4350vUaMiDjc= Received: from drakthul.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C36C16044B; Mon, 28 May 2018 21:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527542477; bh=J3YUQblI7jH9b8qOQWBFxZTFZcLj0oMkcDxzgwfABwI=; h=From:To:Cc:Subject:Date:From; b=AviuFW8/2DZoveCFg+UDwwyzEcI7IkP77a5XligPAyu3kn9QPUBuOnRjp3ZAXbEOU bGb67b7u8X/JqmVq5Eg4uxq4l1NosHFhTPPmt+SwinlJGgxgqAj9MYMQTT7xTPdI2q JerxTKBZxkg0+qcbRphXwOlgJunOiCnDbo+M2Hjg= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C36C16044B Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=okaya@codeaurora.org From: Sinan Kaya To: linux-pci@vger.kernel.org, ryan@finnie.org, timur@codeaurora.org Subject: [PATCH V3 1/2] PCI: Try to clean up resources via remove if shutdown doesn't exist Date: Mon, 28 May 2018 17:21:10 -0400 Message-Id: <1527542471-10316-1-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180528_142129_909888_E03F18B1 X-CRM114-Status: GOOD ( 12.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-msm@vger.kernel.org, open list , stable@vger.kernel.org, Sinan Kaya , Bjorn Helgaas , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP It is up to a driver to implement shutdown() callback. If shutdown() callback is not implemented, PCI device can have pending interrupt and even do DMA transactions while the system is going down. If kexec is in use, this can damage the newly booting kexec kernel or even prevent it from booting altogether. Fallback to calling the remove() callback if shutdown() isn't implemented for a given driver. Signed-off-by: Sinan Kaya Link: https://bugzilla.kernel.org/show_bug.cgi?id=199779 Fixes: cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown") Cc: stable@vger.kernel.org Reported-by: Ryan Finnie Tested-by: Ryan Finnie --- drivers/pci/pci-driver.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index cbda0e6..75a00fe 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -477,8 +477,17 @@ static void pci_device_shutdown(struct device *dev) pm_runtime_resume(dev); + /* + * Try shutdown callback if it exists, otherwise fallback to remove + * callback. PCI drivers can do DMA and have pending interrupts. + * Leaving the DMA and interrupts pending could damage the newly + * booting kexec kernel as well as prevent it from booting altogether + * if the pending interrupt is level. + */ if (drv && drv->shutdown) drv->shutdown(pci_dev); + else if (drv && drv->remove) + drv->remove(pci_dev); /* * If this is a kexec reboot, turn off Bus Master bit on the