From: sashiko-bot@kernel.org
To: "Zhang Hongtao" <zhanghongtao35@huawei.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: PCI: Prevent device lock leak during bus reset
Date: Fri, 21 Aug 2026 02:10:05 +0000 [thread overview]
Message-ID: <20260821021006.3AC3F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260821021626.1874602-1-zhanghongtao35@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch fixes pci_bus_reset while leaving identical lock leak and Use-After-Free races unmitigated in pci_try_reset_bus, pci_slot_reset, and pci_try_reset_slot.
--
--- Patch [1]: PCI: Prevent device lock leak during bus reset ---
commit 0d6c89d5cec5eebb33879246fbc7b446f026613a
Author: Zhang Hongtao <zhanghongtao35@huawei.com>
PCI: Prevent device lock leak during bus reset
This patch fixes a device lock leak in pci_bus_reset() caused by
concurrent device removal. It takes a topology snapshot under pci_bus_sem
to guarantee that all locked devices are unlocked during a secondary bus reset.
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 77b17b13ee615..25a1e44263c32 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
[ ... ]
> @@ -5585,21 +5667,31 @@ static int pci_try_reset_slot(struct pci_slot *slot)
>
> static int pci_bus_reset(struct pci_bus *bus, bool probe)
> {
> + struct pci_bus_lock_context context;
> int ret;
>
> + down_read(&pci_bus_sem);
> +
> if (!bus->self || !pci_bus_resettable(bus))
> - return -ENOTTY;
> + ret = -ENOTTY;
> + else if (probe)
> + ret = 0;
> + else
> + ret = pci_bus_lock_snapshot_init(bus, &context);
>
> - if (probe)
> - return 0;
> + up_read(&pci_bus_sem);
> +
> + if (ret || probe)
> + return ret;
>
> - pci_bus_lock(bus);
> + pci_bus_lock_snapshot(&context);
>
> might_sleep();
>
> ret = pci_bridge_secondary_bus_reset(bus->self);
>
> - pci_bus_unlock(bus);
> + pci_bus_unlock_snapshot(&context);
> + pci_bus_lock_snapshot_release(&context);
>
> return ret;
> }
[Severity: High]
This is a pre-existing issue, but regarding the RFC question in the commit
message about extending this fix:
The identical lock leaks and use-after-free races remain in the slot and
try-reset paths, as they rely on __pci_bus_lock(), __pci_bus_unlock(), and
__pci_bus_trylock().
For example, __pci_bus_trylock() iterates over bus->devices without
holding pci_bus_sem:
drivers/pci/pci.c:__pci_bus_trylock() {
...
list_for_each_entry(dev, &bus->devices, bus_list) {
if (slot && (!dev->slot || dev->slot != slot))
continue;
...
}
If a concurrent device removal executes list_del(&dev->bus_list) during
pci_try_reset_bus(), pci_slot_reset(), or pci_try_reset_slot(), the unlock
loop fails to find the device. This leaves the device permanently locked,
causing the same system hangs in driver bind/unbind paths.
Since these paths are reachable via PCIe AER recovery or hotplug events,
would it be safer to extend this snapshot mechanism to the slot and
try-reset paths to fully close this race condition?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260821021626.1874602-1-zhanghongtao35@huawei.com?part=1
prev parent reply other threads:[~2026-08-21 2:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 2:16 PCI: Prevent device lock leak during bus reset Zhang Hongtao
2026-08-21 2:10 ` sashiko-bot [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=20260821021006.3AC3F1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhanghongtao35@huawei.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 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.