From patchwork Fri May 25 14:04:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10427505 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 B2945602D8 for ; Fri, 25 May 2018 14:04:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A423B2966F for ; Fri, 25 May 2018 14:04:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 987B82970C; Fri, 25 May 2018 14:04:50 +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 11EE02966F for ; Fri, 25 May 2018 14:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936133AbeEYOEg (ORCPT ); Fri, 25 May 2018 10:04:36 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:54356 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936046AbeEYOEf (ORCPT ); Fri, 25 May 2018 10:04:35 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0905D60618; Fri, 25 May 2018 14:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527257075; bh=vMC9+7Kmqdozio/mHWCCOdd0cJ4U8nEi1ofvs149E58=; h=From:To:Cc:Subject:Date:From; b=EZNfCCOXIa/NGARLRS/kNY6yHiq/mTBzaVXxgxwC/XZM8emGSXmTxyVmOTJdDjEhj wIge+yABzdCve+sMpwbIO/X6aPzF1rZkC0EkZwRsJBHFOUqv9ssIW7VhacQVw9YY7i r4VpfdOmhjcVCu+94rHVOmWN/Rdfw2vgtIjiLzIc= 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 E9839601E8; Fri, 25 May 2018 14:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527257074; bh=vMC9+7Kmqdozio/mHWCCOdd0cJ4U8nEi1ofvs149E58=; h=From:To:Cc:Subject:Date:From; b=nQkx7ScACnoYtVXdvjCQp2WPXYqEFs/tw4UMo9mQBkxwLVujLECxTaMBqS3+41Y4I d6beWQrm444whuhaI1buccmds0GQ6A1C8i5N4YT1OjeXXyUwXp2yK+0fiAwRq2/K94 bkWCFlq8cA6sYVKlZWloKsO0P8oQ/L/JR811Eb3c= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E9839601E8 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, timur@codeaurora.org Cc: linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sinan Kaya , Bjorn Helgaas , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] PCI: Try to clean up resources via remove if shutdown doesn't exist Date: Fri, 25 May 2018 10:04:23 -0400 Message-Id: <1527257063-15843-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 --- 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 6ace470..4ac72e3 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -475,8 +475,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