public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Huacai Chen <chenhuacai@loongson.cn>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Sasha Levin <sashal@kernel.org>,
	kbusch@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com,
	sr@denx.de, pali@kernel.org, chenhuacai@kernel.org,
	linux-pci@vger.kernel.org
Subject: [PATCH AUTOSEL 6.2 27/64] PCI/portdrv: Prevent LS7A Bus Master clearing on shutdown
Date: Fri,  3 Mar 2023 16:40:29 -0500	[thread overview]
Message-ID: <20230303214106.1446460-27-sashal@kernel.org> (raw)
In-Reply-To: <20230303214106.1446460-1-sashal@kernel.org>

From: Huacai Chen <chenhuacai@loongson.cn>

[ Upstream commit 62b6dee1b44aa23b3935543aff7df80399ec726b ]

After cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")
we observe hangs during poweroff/reboot on systems with LS7A chipset.

This happens because the portdrv .shutdown() method (pcie_portdrv_remove())
clears PCI_COMMAND_MASTER via pci_disable_device(), which prevents bridges
from forwarding memory or I/O Requests in the upstream direction (PCIe
r6.0, sec 7.5.1.1.3).

LS7A Root Ports have a hardware defect: clearing PCI_COMMAND_MASTER *also*
prevents the bridge from forwarding CPU MMIO requests in the downstream
direction, and these MMIO accesses to devices below the bridge happen even
after .shutdown(), e.g., to print console messages.  LS7A neither forwards
the requests nor sends an unsuccessful completion to the CPU, so the CPU
waits forever, resulting in the hang.

The purpose of .shutdown() is to disable interrupts and DMA from the
device.  PCIe ports may generate interrupts (either MSI/MSI-X or INTx) for
AER, DPC, PME, hotplug, etc., but they never perform DMA except MSI/MSI-X.
Clearing PCI_COMMAND_MASTER effectively disables MSI/MSI-X, but not INTx.

The port service driver .remove() methods clear the interrupt enables in
PCI_ERR_ROOT_COMMAND, PCI_EXP_DPC_CTL, PCI_EXP_SLTCTL, and PCI_EXP_RTCTL,
etc., which disables interrupts regardless of whether they are MSI/MSI-X or
INTx.

Add a pcie_portdrv_shutdown() method that calls all the port service driver
.remove() methods to clear the interrupt enables for each service but does
not clear Bus Mastering on the port itself.

[bhelgaas: commit log]
Link: https://lore.kernel.org/r/20230201043018.778499-2-chenhuacai@loongson.cn
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/pci/pcie/portdrv.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pcie/portdrv.c b/drivers/pci/pcie/portdrv.c
index 2cc2e60bcb396..46fad0d813b2b 100644
--- a/drivers/pci/pcie/portdrv.c
+++ b/drivers/pci/pcie/portdrv.c
@@ -501,7 +501,6 @@ static 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);
 }
 
 /**
@@ -727,6 +726,19 @@ 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,
@@ -777,7 +789,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.39.2


  parent reply	other threads:[~2023-03-03 21:44 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-03 21:40 [PATCH AUTOSEL 6.2 01/64] IB/hfi1: Update RMT size calculation Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 02/64] iommu: Remove deferred attach check from __iommu_detach_device() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 03/64] iommu/amd: Fix error handling for pdev_pri_ats_enable() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 04/64] PCI/ACPI: Account for _S0W of the target bridge in acpi_pci_bridge_d3() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 05/64] media: uvcvideo: Remove format descriptions Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 06/64] media: uvcvideo: Handle cameras with invalid descriptors Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 07/64] media: uvcvideo: Handle errors from calls to usb_string Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 08/64] media: uvcvideo: Quirk for autosuspend in Logitech B910 and C910 Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 09/64] media: uvcvideo: Silence memcpy() run-time false positive warnings Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 10/64] USB: fix memory leak with using debugfs_lookup() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 11/64] cacheinfo: Fix shared_cpu_map to handle shared caches at different levels Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 12/64] usb: fotg210: List different variants Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 13/64] dt-bindings: usb: Add device id for Genesys Logic hub controller Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 14/64] staging: emxx_udc: Add checks for dma_alloc_coherent() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 15/64] tty: fix out-of-bounds access in tty_driver_lookup_tty() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 16/64] tty: serial: fsl_lpuart: disable the CTS when send break signal Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 17/64] serial: sc16is7xx: setup GPIO controller later in probe Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 18/64] mei: bus-fixup:upon error print return values of send and receive Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 19/64] parport_pc: Set up mode and ECR masks for Oxford Semiconductor devices Sasha Levin
2023-03-22 23:16   ` Maciej W. Rozycki
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 20/64] tools/iio/iio_utils:fix memory leak Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 21/64] bus: mhi: ep: Fix the debug message for MHI_PKT_TYPE_RESET_CHAN_CMD cmd Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 22/64] iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_status_word() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 23/64] iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_config_word() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 24/64] media: uvcvideo: Add GUID for BGRA/X 8:8:8:8 Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 25/64] firmware: coreboot: framebuffer: Ignore reserved pixel color bits Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 26/64] soundwire: bus_type: Avoid lockdep assert in sdw_drv_probe() Sasha Levin
2023-03-03 21:40 ` Sasha Levin [this message]
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 28/64] PCI: loongson: Prevent LS7A MRRS increases Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 29/64] staging: pi433: fix memory leak with using debugfs_lookup() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 30/64] USB: dwc3: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 31/64] USB: chipidea: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 32/64] USB: ULPI: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 33/64] USB: uhci: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 34/64] USB: sl811: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 35/64] USB: fotg210: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 36/64] USB: isp116x: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 37/64] USB: isp1362: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 38/64] USB: gadget: gr_udc: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 39/64] USB: gadget: bcm63xx_udc: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 40/64] USB: gadget: lpc32xx_udc: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 41/64] USB: gadget: pxa25x_udc: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 42/64] USB: gadget: pxa27x_udc: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 43/64] usb: host: xhci: mvebu: Iterate over array indexes instead of using pointer math Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 44/64] USB: ene_usb6250: Allocate enough memory for full object Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 45/64] usb: uvc: Enumerate valid values for color matching Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 46/64] usb: gadget: uvc: Make bSourceID read/write Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 47/64] PCI: Align extra resources for hotplug bridges properly Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 48/64] PCI: Take other bus devices into account when distributing resources Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 49/64] PCI: Distribute available resources for root buses, too Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 50/64] tty: pcn_uart: fix memory leak with using debugfs_lookup() Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 51/64] misc: vmw_balloon: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 52/64] drivers: base: component: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 53/64] drivers: base: dd: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 54/64] kernel/time/test_udelay.c: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 55/64] kernel/power/energy_model.c: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 56/64] kernel/fail_function: " Sasha Levin
2023-03-03 21:40 ` [PATCH AUTOSEL 6.2 57/64] PCI: loongson: Add more devices that need MRRS quirk Sasha Levin
2023-03-03 21:41 ` [PATCH AUTOSEL 6.2 58/64] PCI: Add ACS quirk for Wangxun NICs Sasha Levin
2023-03-03 21:41 ` [PATCH AUTOSEL 6.2 59/64] PCI: pciehp: Add Qualcomm quirk for Command Completed erratum Sasha Levin
2023-03-03 21:41 ` [PATCH AUTOSEL 6.2 60/64] phy: rockchip-typec: Fix unsigned comparison with less than zero Sasha Levin
2023-03-03 21:41 ` [PATCH AUTOSEL 6.2 61/64] RDMA/cma: Distinguish between sockaddr_in and sockaddr_in6 by size Sasha Levin
2023-03-03 21:41 ` [PATCH AUTOSEL 6.2 62/64] iommu: Attach device group to old domain in error path Sasha Levin
2023-03-03 21:41 ` [PATCH AUTOSEL 6.2 63/64] soundwire: cadence: Remove wasted space in response_buf Sasha Levin
2023-03-03 21:41 ` [PATCH AUTOSEL 6.2 64/64] soundwire: cadence: Drain the RX FIFO after an IO timeout Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230303214106.1446460-27-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=sr@denx.de \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox