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: 10434015 X-Patchwork-Delegate: agross@codeaurora.org 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 B08C160249 for ; Mon, 28 May 2018 21:21:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93FDC2852A for ; Mon, 28 May 2018 21:21:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 873202852C; Mon, 28 May 2018 21:21:34 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F224A2852A for ; Mon, 28 May 2018 21:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934154AbeE1VVV (ORCPT ); Mon, 28 May 2018 17:21:21 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:32806 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934151AbeE1VVS (ORCPT ); Mon, 28 May 2018 17:21:18 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6784A60591; 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 Cc: linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sinan Kaya , stable@vger.kernel.org, Bjorn Helgaas , linux-kernel@vger.kernel.org (open list) 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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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