Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3517659imm; Fri, 25 May 2018 07:05:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq15+w9j+P6LU8lMfwpXh5D9xBRFSR1uNM1v/3S46vHqrlg+G8I7wp79CX+0t6VL4shZDOS X-Received: by 2002:a65:661a:: with SMTP id w26-v6mr2137629pgv.151.1527257145075; Fri, 25 May 2018 07:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527257145; cv=none; d=google.com; s=arc-20160816; b=doy29E+oVWB3T7XjozT51Wb+GSi4oHlkPXdcRQwsjVoPVgPwRg0sSB+mYsO9H6FXPL bwvyi5BGYOHULtrLS04kT0VScjgJpinic2sukqvx25uHOwr8eU59Ue6WdAeDSzJUY3hJ RadXsLm74rSmd3cmJuEDSU2GcFzNptOb8EAP8KaztB7sUMmz67/odO69LKHD4+1kwIby dCAwwnPtAuJUs5xvgXBriS+nQPA3AqKqre9/MFhKdARAUReWrJw7M3Mf99w9d/o42xf1 1rPzjl/vSZEWsaXMRquxaR64G/aaMJ2KRsLytL8qrjdVOS3kXnF1ci9QF7BY0UZJ4sQP 1URw== 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 :message-id:date:subject:cc:to:from:dmarc-filter:dkim-signature :dkim-signature:arc-authentication-results; bh=xz4miAkKmw0yt6doyDT953jflJoBqBD+vZ77W3v9KWk=; b=Gyb3qqFHuDrNl63m+Y7x6yngRM76mKGIf6mQX2Mxp8KSShqwtgjPA09MQ6fObDuXph UZwd49IFEgDYi9yo4uZXHL+rbKbLPxN1UIxP9v5N9WVRzO5xFwLl6Ocb+hk6vkwwWtGS nqrCQeTiK2dy31FDaeGDJE4i+NCzeipAfXdnNevHaQAoDVR5UXuFbPGYyL2Tp8jw4040 vlOGphFXJZuwjqzNN/A6hCJ/K1ERnoXSWf6zPTg2C3t0oX1IDwrMJ3LfBpRD22omr5fi ZGXctYBm4hmt0RhPpA4kaxuoORhuhBioa/rrQZcwf7mQDVSQprTRqCnReJLHPx0LcvxW N3Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=EZNfCCOX; dkim=pass header.i=@codeaurora.org header.s=default header.b=nQkx7ScA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si23799681plx.236.2018.05.25.07.05.17; Fri, 25 May 2018 07:05:45 -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=@codeaurora.org header.s=default header.b=EZNfCCOX; dkim=pass header.i=@codeaurora.org header.s=default header.b=nQkx7ScA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936175AbeEYOEh (ORCPT + 99 others); Fri, 25 May 2018 10:04:37 -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= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.7.4