From: sashiko-bot@kernel.org
To: "Abhin Parekadan Jose" <abhinjoses@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH RFC v2 1/5] PCI: Report surprise removal event
Date: Sun, 27 Sep 2026 17:07:07 +0000 [thread overview]
Message-ID: <20260927170707.6F9241F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260927165459.829900-2-abhinjoses@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pci: workqueue list corruption via TOCTTOU in pci_dev_set_disconnected
--
commit 95014e29e88ff3b1020861e3c7351ac0913e2410
Author: Michael S. Tsirkin <mst@redhat.com>
PCI: Report surprise removal event
This commit introduces a mechanism to notify drivers about surprise device
disconnects via a work struct. It allows drivers to perform necessary cleanup
knowing the device is inactive, preventing the remove callback from hanging
forever when waiting for interrupts.
Link: https://lore.kernel.org/all/fba3d235e38c1c6fcef2a30ed083ad9e25b20fa3.1752094439.git.mst@redhat.com/
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index ba3c3fddddc23..23b1605e783a3 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -805,6 +805,12 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
> pci_dev_set_io_state(dev, pci_channel_io_perm_failure);
> pci_doe_disconnected(dev);
>
> + if (READ_ONCE(dev->disconnect_work_enable)) {
> + /* Make sure work is up to date. */
> + smp_rmb();
> + schedule_work(&dev->disconnect_work);
> + }
[Severity: High]
Can this lockless check cause a race condition if the CPU is preempted right
after the READ_ONCE(), but before schedule_work() executes?
If preemption occurs here, the driver could be concurrently unbound, calling
pci_clear_disconnect_work().
If a new driver then binds and initializes the work item via
INIT_WORK(&dev->disconnect_work, ...) during its probe, the delayed
schedule_work() from the preempted CPU might execute concurrently with the
new initialization.
[ ... ]
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index d31a8d107b1ef..f4c0240b62dc8 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
[ ... ]
> @@ -2123,6 +2126,49 @@ pci_release_mem_regions(struct pci_dev *pdev)
[ ... ]
> +static inline void pci_clear_disconnect_work(struct pci_dev *pdev)
> +{
> + WRITE_ONCE(pdev->disconnect_work_enable, 0x0);
> +
> + /* Make sure to stop using work from now on. */
> + smp_wmb();
> +
> + /* Leaves the work disabled, so a racing schedule_work() is a no-op. */
> + disable_work_sync(&pdev->disconnect_work);
> +}
[Severity: High]
Does this function provide enough protection against the delayed
schedule_work() scenario mentioned above?
While disable_work_sync() prevents immediate races by setting disable bits on
the work item, a subsequent driver probe calling INIT_WORK() will
non-atomically reset work->data.
This reset clears all flags, including the WORK_OFFQ_DISABLE_BITS. If
INIT_WORK() executes INIT_LIST_HEAD() concurrently with the delayed
schedule_work() insertion, couldn't this overwrite the next and prev pointers
of the queued work item and corrupt the workqueue linked list?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260927165459.829900-1-abhinjoses@gmail.com?part=1
next prev parent reply other threads:[~2026-09-27 17:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-27 16:54 [PATCH RFC v2 0/5] PCI: pciehp: Report surprise removal during safe removal Abhin Parekadan Jose
2026-09-27 16:54 ` [PATCH RFC v2 1/5] PCI: Report surprise removal event Abhin Parekadan Jose
2026-09-27 17:07 ` sashiko-bot [this message]
2026-09-27 16:54 ` [PATCH RFC v2 2/5] PCI: pciehp: Add pci_hp_wait_link_change() Abhin Parekadan Jose
2026-09-27 17:03 ` sashiko-bot
2026-09-27 16:54 ` [PATCH RFC v2 3/5] PCI/DPC: Add pci_dpc_wait_recovery() Abhin Parekadan Jose
2026-09-27 16:59 ` sashiko-bot
2026-09-27 16:54 ` [PATCH RFC v2 4/5] PCI: pciehp: Report surprise removal from pciehp_isr() Abhin Parekadan Jose
2026-09-27 17:02 ` sashiko-bot
2026-09-27 16:54 ` [PATCH RFC v2 5/5] misc: Add edu_srpoc surprise removal POC driver Abhin Parekadan Jose
2026-09-27 17:00 ` sashiko-bot
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=20260927170707.6F9241F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=abhinjoses@gmail.com \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.