From: Abhin Parekadan Jose <abhinjoses@gmail.com>
To: lukas@wunner.de, mst@redhat.com
Cc: virtualization@lists.linux.dev, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, bhelgaas@google.com,
kbusch@kernel.org, stefanha@redhat.com, parav@nvidia.com,
axboe@kernel.dk, kees@kernel.org, ilpo.jarvinen@linux.intel.com,
xueshuai@linux.alibaba.com,
Abhin Parekadan Jose <abhinjoses@gmail.com>
Subject: [PATCH RFC 3/3] pciehp_hpc: workaround to not wait in pciehp_isr on surprise removal
Date: Sun, 23 Aug 2026 18:34:55 +0000 [thread overview]
Message-ID: <20260823183458.982699-4-abhinjoses@gmail.com> (raw)
In-Reply-To: <20260823183458.982699-1-abhinjoses@gmail.com>
- Add pciehp_disconnect_work() , this function is used using schedule_work from pciehp_isr allowing us to not wait in pciehp_isr()
- pciehp_disconnect_work() is scheduled only if the card is not detected (PDS bit = 0).
The PDS bit can be used to differentiate between a safe and surprise removal.
Signed-off-by: Abhin Parekadan Jose <abhinjoses@gmail.com>
---
drivers/pci/hotplug/pciehp_hpc.c | 47 ++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 4c62140a3cb4..69ed6b060e9d 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -620,6 +620,40 @@ static void pciehp_ignore_link_change(struct controller *ctrl,
up_read(&ctrl->reset_lock);
}
+/*
+ * Workaround to not wait in the isr.
+ */
+static void pciehp_disconnect_work(struct work_struct *work)
+{
+ struct controller *ctrl = container_of(work, struct controller,
+ disconnect_work);
+ struct pci_dev *pdev = ctrl_dev(ctrl);
+ int events;
+
+ events = atomic_read(&ctrl->pending_events);
+
+ /*
+ * Ignore Link Down/Up events caused by Downstream Port Containment
+ * if recovery succeeded, or caused by Secondary Bus Reset,
+ * suspend to D3cold, firmware update, FPGA reconfiguration, etc.
+ */
+ if ((events & (PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_DLLSC)) &&
+ (pci_dpc_recovered(pdev) || pci_hp_spurious_link_change(pdev)) &&
+ ctrl->state == ON_STATE) {
+ // Ignore the link change events and return to normal operation.
+ // Could also wait here if needed.
+ return;
+ }
+
+ struct pci_bus *bus = ctrl->pcie->port->subordinate;
+
+ /* the card may have returned. */
+ if (!bus || pciehp_card_present(ctrl) != 0)
+ return;
+
+ pci_walk_bus(bus, pci_dev_set_disconnected, NULL);
+}
+
static irqreturn_t pciehp_isr(int irq, void *dev_id)
{
struct controller *ctrl = (struct controller *)dev_id;
@@ -722,6 +756,17 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id)
/* Save pending events for consumption by IRQ thread. */
atomic_or(events, &ctrl->pending_events);
+
+ // presence change events
+ if (events & (PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_DLLSC)) {
+ // Get PDS bit to determine if card is present or not
+ int present = pciehp_card_present(ctrl);
+ if (!present) { // for sure the card is not present
+ schedule_work(&ctrl->disconnect_work);
+ // After this we are no longer in isr and can wait.
+ }
+ }
+
return IRQ_WAKE_THREAD;
}
@@ -1036,6 +1081,7 @@ struct controller *pcie_init(struct pcie_device *dev)
init_waitqueue_head(&ctrl->requester);
init_waitqueue_head(&ctrl->queue);
INIT_DELAYED_WORK(&ctrl->button_work, pciehp_queue_pushbutton_work);
+ INIT_WORK(&ctrl->disconnect_work, pciehp_disconnect_work);
dbg_ctrl(ctrl);
down_read(&pci_bus_sem);
@@ -1096,6 +1142,7 @@ struct controller *pcie_init(struct pcie_device *dev)
void pciehp_release_ctrl(struct controller *ctrl)
{
cancel_delayed_work_sync(&ctrl->button_work);
+ cancel_work_sync(&ctrl->disconnect_work);
kfree(ctrl);
}
--
2.51.1
prev parent reply other threads:[~2026-08-23 18:35 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 20:55 [PATCH RFC v5 0/5] pci,virtio: report surprise removal event Michael S. Tsirkin
2025-07-09 20:55 ` [PATCH RFC v5 1/5] pci: " Michael S. Tsirkin
2025-07-09 23:38 ` Bjorn Helgaas
2025-07-09 23:55 ` Keith Busch
2025-07-14 6:17 ` Michael S. Tsirkin
2025-07-14 6:26 ` Michael S. Tsirkin
2025-07-14 21:13 ` Bjorn Helgaas
2025-07-15 6:28 ` Michael S. Tsirkin
2025-07-16 22:29 ` Bjorn Helgaas
2025-07-17 15:15 ` Michael S. Tsirkin
2025-07-14 6:11 ` Lukas Wunner
2025-07-14 6:18 ` Michael S. Tsirkin
2025-07-14 6:54 ` Michael S. Tsirkin
2025-07-17 15:11 ` Michael S. Tsirkin
2025-07-17 20:12 ` Lukas Wunner
2025-07-17 23:31 ` Michael S. Tsirkin
2025-07-18 4:35 ` Lukas Wunner
2025-07-18 8:40 ` Michael S. Tsirkin
2025-07-09 20:55 ` [PATCH RFC v5 2/5] virtio: fix comments, readability Michael S. Tsirkin
2025-07-09 20:55 ` [PATCH RFC v5 3/5] virtio: pack config changed flags Michael S. Tsirkin
2025-07-09 20:55 ` [PATCH RFC v5 4/5] virtio: allow transports to suppress config change Michael S. Tsirkin
2025-07-09 20:55 ` [PATCH RFC v5 5/5] virtio: support device disconnect Michael S. Tsirkin
2026-08-23 18:34 ` [PATCH RFC 0/3] pci_hp: fix surprise removal hang during safe removal Abhin Parekadan Jose
2026-08-23 18:34 ` [PATCH RFC 1/3] misc: add edu_srpoc surprise removal POC driver Abhin Parekadan Jose
2026-08-23 18:34 ` [PATCH RFC 2/3] pciehp: add disconnect_work work_struct Abhin Parekadan Jose
2026-08-23 18:34 ` Abhin Parekadan Jose [this message]
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=20260823183458.982699-4-abhinjoses@gmail.com \
--to=abhinjoses@gmail.com \
--cc=axboe@kernel.dk \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kbusch@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=mst@redhat.com \
--cc=parav@nvidia.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xueshuai@linux.alibaba.com \
/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
all inboxes | Powered by JetHome®