Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1718408pxk; Sun, 13 Sep 2020 13:33:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzVJkdcF5bWUoiQc5zgEODqtotq+ER6Nd25sU0fGvH/UbPvgj6cExjSqEoToerODZSnU+8 X-Received: by 2002:a50:e3c4:: with SMTP id c4mr14592646edm.90.1600029183680; Sun, 13 Sep 2020 13:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600029183; cv=none; d=google.com; s=arc-20160816; b=pHWE7LhJx0pDzhvaikKMy+JqzHDg+9z+Y7eEvU/Jx7lHmMLqW96+zaSOQ01eiBdCe3 8dfNr8+b3nhVUcUiq5F2v/1i0OIL58lRSoloeaUKXfbkX639HmRsWd2DHMpay3P9Jj3B wJU/0zimlECw4Pn17a8WKojuYKkXQwKHMXGT7FykiGG2xM9FlzxKq1Sz9V9Rr3kDh4gr rp6pbHLvl0Jky1Thu4ZAQBD1ymOr1kvVfeAFIsjlDDvp6tUzFvnquMVLRLuK8W6N48iZ +e/oIfXk2Q/bT9lYX00B0rekDxab466IKoTzLoUB/sYftxdfCSxsvGu6M19Q7l1OEcBo Lfhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=Qk1tyCquhY/KeDCIL3eqSdF+GwpR2frVw5qM/QqLFoE=; b=EUAN4hfnMDwnkg5ciLo0A3yCmgK9SMvZOnDtFloV1IOln3TIWcT76uzo2gMlX3UhqG tEdDQ9bEPm9sTIcoKV1dtqnn6d7QLru1+2zkrq21GQO10n8FWeduwgjR+KBFfnkm13ym kYM4p+MH+oKWHQsn4XGF/G8t5QvVNN3iM9u0aNzxlNNUTk8iNOsZ9zbVV8eMS6tK65KW QB0fH3lfbAFegbTdnlmKk0FDV40h+MQWmnwzfu26kRpUVe/nyVTM0EuuDt2uQPDdbgvZ hjXf7SrqIJBHHEnEQ3axRPwlbReiSB4BaIyyO+ZbB+DOMo1/qrbmN2OSkZRwSCQ6hGo/ v5RQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si5636889ejr.561.2020.09.13.13.32.41; Sun, 13 Sep 2020 13:33:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725977AbgIMU30 (ORCPT + 99 others); Sun, 13 Sep 2020 16:29:26 -0400 Received: from mail.loongson.cn ([114.242.206.163]:43988 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725940AbgIMU3Y (ORCPT ); Sun, 13 Sep 2020 16:29:24 -0400 Received: from linux.localdomain (unknown [117.136.50.205]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx78cQgV5fOgYVAA--.4954S2; Mon, 14 Sep 2020 04:29:07 +0800 (CST) From: Tiezhu Yang To: Bjorn Helgaas Cc: Konstantin Khlebnikov , Khalid Aziz , Vivek Goyal , Lukas Wunner , oohall@gmail.com, rafael.j.wysocki@intel.com, Xuefeng Li , Huacai Chen , Jiaxun Yang , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices Date: Mon, 14 Sep 2020 04:29:10 +0800 Message-Id: <1600028950-10644-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: AQA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qw3xlh2x3gn0dqz5rrqw2lrqou0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After commit 745be2e700cd ("PCIe: portdrv: call pci_disable_device during remove") and commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown"), it also calls pci_disable_device() during shutdown, this leads to shutdown or reboot failure occasionally due to clear PCI_COMMAND_MASTER on the device in do_pci_disable_device(). drivers/pci/pci.c static void do_pci_disable_device(struct pci_dev *dev) { u16 pci_command; pci_read_config_word(dev, PCI_COMMAND, &pci_command); if (pci_command & PCI_COMMAND_MASTER) { pci_command &= ~PCI_COMMAND_MASTER; pci_write_config_word(dev, PCI_COMMAND, pci_command); } pcibios_disable_device(dev); } When remove "pci_command &= ~PCI_COMMAND_MASTER;", it can work well. As Oliver O'Halloran said, no need to call pci_disable_device() when actually shutting down, but we should call pci_disable_device() before handing over to the new kernel on kexec reboot, so we can do some condition checks which are similar with pci_device_shutdown(), this is done by commit 4fc9bbf98fd6 ("PCI: Disable Bus Master only on kexec reboot") and commit 6e0eda3c3898 ("PCI: Don't try to disable Bus Master on disconnected PCI devices"). drivers/pci/pci-driver.c static void pci_device_shutdown(struct device *dev) { ... /* * If this is a kexec reboot, turn off Bus Master bit on the * device to tell it to not continue to do DMA. Don't touch * devices in D3cold or unknown states. * If it is not a kexec reboot, firmware will hit the PCI * devices with big hammer and stop their DMA any way. */ if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot)) pci_clear_master(pci_dev); } Signed-off-by: Tiezhu Yang --- drivers/pci/pcie/portdrv_core.c | 1 - drivers/pci/pcie/portdrv_pci.c | 25 ++++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c index 50a9522..1991aca 100644 --- a/drivers/pci/pcie/portdrv_core.c +++ b/drivers/pci/pcie/portdrv_core.c @@ -491,7 +491,6 @@ void pcie_port_device_remove(struct pci_dev *dev) { device_for_each_child(&dev->dev, NULL, remove_iter); pci_free_irq_vectors(dev); - pci_disable_device(dev); } /** diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c index 3a3ce40..ce89a9e8 100644 --- a/drivers/pci/pcie/portdrv_pci.c +++ b/drivers/pci/pcie/portdrv_pci.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "../pci.h" #include "portdrv.h" @@ -143,6 +144,28 @@ static void pcie_portdrv_remove(struct pci_dev *dev) } pcie_port_device_remove(dev); + pci_disable_device(dev); +} + +static void pcie_portdrv_shutdown(struct pci_dev *dev) +{ + if (pci_bridge_d3_possible(dev)) { + pm_runtime_forbid(&dev->dev); + pm_runtime_get_noresume(&dev->dev); + pm_runtime_dont_use_autosuspend(&dev->dev); + } + + pcie_port_device_remove(dev); + + /* + * If this is a kexec reboot, turn off Bus Master bit on the + * device to tell it to not continue to do DMA. Don't touch + * devices in D3cold or unknown states. + * If it is not a kexec reboot, firmware will hit the PCI + * devices with big hammer and stop their DMA any way. + */ + if (kexec_in_progress && (dev->current_state <= PCI_D3hot)) + pci_disable_device(dev); } static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev, @@ -211,7 +234,7 @@ static void pcie_portdrv_err_resume(struct pci_dev *dev) .probe = pcie_portdrv_probe, .remove = pcie_portdrv_remove, - .shutdown = pcie_portdrv_remove, + .shutdown = pcie_portdrv_shutdown, .err_handler = &pcie_portdrv_err_handler, -- 1.8.3.1