Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1975634pxk; Mon, 14 Sep 2020 00:59:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoFZzUFUAwcsmu0zKawXDiG6RqITmgsbIx11IxkWyVVSwOANa7F/HyGoZy1Gyk/jgSo8NL X-Received: by 2002:a17:907:432b:: with SMTP id ob19mr13511450ejb.400.1600070363827; Mon, 14 Sep 2020 00:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600070363; cv=none; d=google.com; s=arc-20160816; b=wQt5OVp6z13oNNWNtdQgC2lTPpVL1D97r2xNHeACKAIMGeHMgKGPKUWszuFrpef3F0 w+9OL1Fdz+H/FRBpN2l+Slc6l+0FrZba/NMlKq3GzV6ah8I0W9H+g7vXh85rXbOqdgtP KUxdhscK63GujS6teIJ5YbxoY3qXsrHoaXg1Ew5fbupmOcHBiw76timnSFYCANz7XWZJ ZLiMgD0/p0Fhquc2Egu34iX3TO+jHUwUzsNQCzVu2ONI5Eqx2awStExSVulplaldzIgq 6J58lCiXgK1dTantvbw8TO1Ce0k7GhbRPMqOf9ZowB4/2JwLxjf5LAtFzeCII7RqJglE /ALA== 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=e5yxb5KJiZ20J3X9Lr9PHJCnjkSBPFzPUQHxg2g9F2M=; b=VcRWsyIbCLQUf/aboMlEdmgeazdinEF8qmO2ndhIc7pLjnwKJF5qALgTpdh+b90C9t yPrLEu76ryqMSQtWwW4fo55J3tI/E2L5N3fgu31G5OJo0BvQl7Qcm3Yp47nT0V5SBH6l pFnre6Q5q15hHlvUMCaAwrY4lmMojlmmDkrOz7wU3VaHqW+sdU7NLNeWcC0aMBwFJ5Um BqIglp/iviOZTumQVKDzogZ7cFcV9bHCWaVErUqS0qlUHhTwVJ/T2mGTdH3aTbUqMD8s OCn0wvEjXvc7J0o4O/DPsxGOmyFxplI1zgDjhwnn+VE/1/eMKsD2+I/gAVf9ZOGqcyxY b+Eg== 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 w2si6893316edt.253.2020.09.14.00.59.01; Mon, 14 Sep 2020 00:59:23 -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 S1726023AbgINH5U (ORCPT + 99 others); Mon, 14 Sep 2020 03:57:20 -0400 Received: from mail.loongson.cn ([114.242.206.163]:40826 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726068AbgINH5S (ORCPT ); Mon, 14 Sep 2020 03:57:18 -0400 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxz99IIl9fbiUVAA--.4831S2; Mon, 14 Sep 2020 15:56:56 +0800 (CST) From: Tiezhu Yang To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Konstantin Khlebnikov , Khalid Aziz , Vivek Goyal , Lukas Wunner , Oliver O'Halloran , Huacai Chen , Jiaxun Yang , Xuefeng Li Subject: [RFC PATCH v3] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices Date: Mon, 14 Sep 2020 15:56:55 +0800 Message-Id: <1600070215-3901-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dxz99IIl9fbi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UUU X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ 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 when shutdown or reboot. 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 already executed afterwards by the function 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 (drv && drv->shutdown) drv->shutdown(pci_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); } [ 36.159446] Call Trace: [ 36.241688] [] show_stack+0x9c/0x130 [ 36.326619] [] dump_stack+0xb0/0xf0 [ 36.410403] [] pcie_portdrv_shutdown+0x18/0x78 [ 36.495302] [] pci_device_shutdown+0x44/0x90 [ 36.580027] [] device_shutdown+0x130/0x290 [ 36.664486] [] kernel_power_off+0x38/0x80 [ 36.748272] [] __do_sys_reboot+0x1a4/0x258 [ 36.831985] [] syscall_common+0x34/0x58 Signed-off-by: Tiezhu Yang --- drivers/pci/pcie/portdrv_core.c | 1 - drivers/pci/pcie/portdrv_pci.c | 14 +++++++++++++- 2 files changed, 13 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..cab37a8 100644 --- a/drivers/pci/pcie/portdrv_pci.c +++ b/drivers/pci/pcie/portdrv_pci.c @@ -143,6 +143,18 @@ 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); } static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev, @@ -211,7 +223,7 @@ static struct pci_driver pcie_portdriver = { .probe = pcie_portdrv_probe, .remove = pcie_portdrv_remove, - .shutdown = pcie_portdrv_remove, + .shutdown = pcie_portdrv_shutdown, .err_handler = &pcie_portdrv_err_handler, -- 2.1.0