From: Mario Limonciello <superm1@kernel.org>
To: Bjorn Helgaas <bhelgaas@google.com>,
linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM)
Cc: linux-pm@vger.kernel.org,
"Rafael J . Wysocki" <rjw@rjwysocki.net>,
Mario Limonciello <mario.limonciello@amd.com>
Subject: [PATCH v3 2/2] PCI: Fix runtime PM usage count underflow on device unplug
Date: Thu, 19 Jun 2025 21:55:35 -0500 [thread overview]
Message-ID: <20250620025535.3425049-3-superm1@kernel.org> (raw)
In-Reply-To: <20250620025535.3425049-1-superm1@kernel.org>
From: Mario Limonciello <mario.limonciello@amd.com>
When a USB4 dock is unplugged the PCIe bridge it's connected to will
remove issue a "Link Down" and "Card not detected event". The PCI core
will treat this as a surprise hotplug event and unconfigure all downstream
devices.
pci_stop_bus_device() will call device_release_driver(). As part of device
release sequence pm_runtime_put_sync() is called for the device which will
decrement the runtime counter to 0. After this, the device remove callback
(pci_device_remove()) will be called which again calls pm_runtime_put_sync()
but as the counter is already 0 will cause an underflow.
This behavior was introduced in commit 967577b062417 ("PCI/PM: Keep runtime
PM enabled for unbound PCI devices") to prevent asymmetrical get/put from
probe/remove, but this misses out on the point that when releasing a driver
the usage count is decremented from the device core.
Drop the extra call from pci_device_remove().
Fixes: 967577b062417 ("PCI/PM: Keep runtime PM enabled for unbound PCI devices")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v3:
* git archeaology
* Drop call alltogether, not just for the device disconnected case
v2:
* Use pci_dev_is_disconnected()
v1: https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
---
drivers/pci/pci-driver.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index b78b98133e7df..63f1cb11906ad 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -478,9 +478,6 @@ static void pci_device_remove(struct device *dev)
pci_dev->driver = NULL;
pci_iov_remove(pci_dev);
- /* Undo the runtime PM settings in local_pci_probe() */
- pm_runtime_put_sync(dev);
-
/*
* If the device is still on, set the power state as "unknown",
* since it might change by the next time we load the driver.
--
2.43.0
next prev parent reply other threads:[~2025-06-20 2:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 2:55 [PATCH v3 0/2] Don't make noise about disconnected USB4 devices Mario Limonciello
2025-06-20 2:55 ` [PATCH v3 1/2] PCI/PM: Skip resuming to D0 if disconnected Mario Limonciello
2025-06-23 17:48 ` Lukas Wunner
2025-06-20 2:55 ` Mario Limonciello [this message]
2025-06-21 19:05 ` [PATCH v3 2/2] PCI: Fix runtime PM usage count underflow on device unplug Lukas Wunner
2025-06-21 19:56 ` Mario Limonciello
2025-06-22 4:43 ` Lukas Wunner
2025-06-22 18:39 ` Mario Limonciello
2025-06-23 1:47 ` Mario Limonciello
2025-06-23 6:53 ` Lukas Wunner
2025-06-23 6:43 ` Lukas Wunner
2025-06-23 7:37 ` Lukas Wunner
2025-06-23 10:05 ` Lukas Wunner
2025-06-23 10:11 ` Rafael J. Wysocki
2025-06-23 11:37 ` Mario Limonciello
2025-06-23 12:19 ` Lukas Wunner
2025-06-23 12:45 ` Mario Limonciello
2025-06-23 17:23 ` Lukas Wunner
2025-06-23 17:25 ` Mario Limonciello
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=20250620025535.3425049-3-superm1@kernel.org \
--to=superm1@kernel.org \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=rjw@rjwysocki.net \
/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.