From: Lukas Wunner <lukas@wunner.de>
To: AceLan Kao <acelan.kao@canonical.com>
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI: pciehp: Fix system hang on resume after hot-unplug during suspend
Date: Sat, 28 Sep 2024 14:51:17 +0200 [thread overview]
Message-ID: <Zvf7xYEA32VgLRJ6@wunner.de> (raw)
In-Reply-To: <ZvZ61srt3QAca2AI@wunner.de>
On Fri, Sep 27, 2024 at 11:28:54AM +0200, Lukas Wunner wrote:
> I realize now that commit 9d573d19547b ("PCI: pciehp: Detect device
> replacement during system sleep") is a little overzealous because it
> not only reacts to *replaced* devices but also to *unplugged* devices:
> If the device was unplugged, reading the vendor and device ID returns
> 0xffff, which is different from the cached value, so the device is
> assumed to have been replaced even though it's actually been unplugged.
>
> The device replacement check runs in the ->resume_noirq phase. Later on
> in the ->resume phase, pciehp_resume() calls pciehp_check_presence() to
> check for unplugged devices. Commit 9d573d19547b inadvertantly reacts
> before pciehp_check_presence() gets a chance to react. So that's something
> that we should probably change.
FWIW, below is a (compile-tested only) patch which modifies
pciehp_device_replaced() to return false if the device was
*unplugged* during system sleep. It continues to return
true if it was *replaced* during system sleep.
This might avoid the issue you're seeing, though it would
be good if you could also try Keith's deadlock prevention
patch (without any other patch) to determine if the deadlock
is the actual root cause (as I suspect).
Thanks!
-- >8 --
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index ff458e6..174832b 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -287,24 +287,32 @@ static int pciehp_suspend(struct pcie_device *dev)
static bool pciehp_device_replaced(struct controller *ctrl)
{
struct pci_dev *pdev __free(pci_dev_put);
+ u64 dsn;
u32 reg;
pdev = pci_get_slot(ctrl->pcie->port->subordinate, PCI_DEVFN(0, 0));
if (!pdev)
+ return false;
+
+ if (pci_read_config_dword(pdev, PCI_VENDOR_ID, ®) == 0 &&
+ !PCI_POSSIBLE_ERROR(reg) &&
+ reg != (pdev->vendor | (pdev->device << 16)))
return true;
- if (pci_read_config_dword(pdev, PCI_VENDOR_ID, ®) ||
- reg != (pdev->vendor | (pdev->device << 16)) ||
- pci_read_config_dword(pdev, PCI_CLASS_REVISION, ®) ||
+ if (pci_read_config_dword(pdev, PCI_CLASS_REVISION, ®) == 0 &&
+ !PCI_POSSIBLE_ERROR(reg) &&
reg != (pdev->revision | (pdev->class << 8)))
return true;
if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL &&
- (pci_read_config_dword(pdev, PCI_SUBSYSTEM_VENDOR_ID, ®) ||
- reg != (pdev->subsystem_vendor | (pdev->subsystem_device << 16))))
+ pci_read_config_dword(pdev, PCI_SUBSYSTEM_VENDOR_ID, ®) == 0 &&
+ !PCI_POSSIBLE_ERROR(reg) &&
+ reg != (pdev->subsystem_vendor | (pdev->subsystem_device << 16)))
return true;
- if (pci_get_dsn(pdev) != ctrl->dsn)
+ dsn = pci_get_dsn(pdev);
+ if (!PCI_POSSIBLE_ERROR(dsn) &&
+ dsn != ctrl->dsn)
return true;
return false;
next prev parent reply other threads:[~2024-09-28 12:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-26 12:59 [PATCH] PCI: pciehp: Fix system hang on resume after hot-unplug during suspend Chia-Lin Kao (AceLan)
2024-09-26 13:23 ` Lukas Wunner
2024-09-27 7:33 ` AceLan Kao
2024-09-27 9:28 ` Lukas Wunner
2024-09-28 12:51 ` Lukas Wunner [this message]
2024-09-30 1:31 ` AceLan Kao
2024-10-01 11:02 ` Lukas Wunner
2024-10-01 11:03 ` Lukas Wunner
2024-10-07 4:34 ` AceLan Kao
2024-10-17 2:40 ` AceLan Kao
2024-10-22 13:05 ` AceLan Kao
2024-10-23 4:23 ` Ethan Zhao
2024-09-30 3:27 ` AceLan Kao
2024-10-01 11:07 ` Lukas Wunner
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=Zvf7xYEA32VgLRJ6@wunner.de \
--to=lukas@wunner.de \
--cc=acelan.kao@canonical.com \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.