Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Jeffery" <djeffery@redhat.com>
Cc: linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [PATCH 8/9] PCI: Enable async shutdown support
Date: Fri, 21 Aug 2026 14:39:27 +0000	[thread overview]
Message-ID: <20260821143927.A69441F00ACF@smtp.kernel.org> (raw)
In-Reply-To: <20260821142414.150892-9-djeffery@redhat.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [Medium] Setting the device async shutdown flag after exposing the device via device_add() creates a race condition.

Pre-existing issues:
- [High] Double put_device() on error path leads to premature freeing and subsequent use-after-free of the host bridge device.
- [High] Unhandled device_add() failure leaves PCI device in an indeterminate state and globally visible in the bus list.
- [High] Modifying PM bitfields without locking after a device is exposed causes data corruption if the PM core is active.
--

--- Patch [8]: [PATCH 8/9] PCI: Enable async shutdown support ---
commit f9f4c656f43f8b78ec5f8dac98964decb5920b89
Author: David Jeffery <djeffery@redhat.com>
Subject: PCI: Enable async shutdown support

Like its async suspend support, allow PCI device shutdown to be performed
asynchronously to reduce shutdown time.

> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index dd0abbc63e18d..af23814464060 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1046,6 +1046,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
>  
>  	bus->bridge = get_device(&bridge->dev);
>  	device_enable_async_suspend(bus->bridge);

[Severity: High]
This is a pre-existing issue, but does calling device_enable_async_suspend()
here after the device is exposed to the PM core cause a data corruption race?

Since this performs an unlocked read-modify-write on the PM bitfields,
concurrent PM operations like dpm_prepare() could clobber these flags.

> +	dev_set_async_shutdown(bus->bridge);

[Severity: Medium]
Since this is called right after device_add() exposed the bridge device, could
this create a race condition where a concurrent system shutdown observes the
device before the async_shutdown flag is set?

>  	pci_set_bus_of_node(bus);
>  	pci_set_bus_msi_domain(bus);
>  	if (bridge->msi_domain && !dev_get_msi_domain(&bus->dev) &&

[Severity: High]
This isn't a bug introduced by this patch, but looking further down in the
error path of pci_register_host_bridge(), does the code introduce a
use-after-free?

If device_register() fails, the unregister path calls
put_device(&bridge->dev) and then falls through to the free path which
calls put_device(&bus->dev).

Since release_pcibus_dev() internally drops a reference to
pci_bus->bridge, this would drop a second reference to bridge->dev,
improperly consuming the caller's initial reference.

[ ... ]

> @@ -2748,6 +2749,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
>  	pci_reassigndev_resource_alignment(dev);
>  
>  	pci_init_capabilities(dev);
> +	dev_set_async_shutdown(&dev->dev);
>  
>  	/*
>  	 * Add the device to our list of discovered devices

[Severity: High]
This isn't a bug introduced by this patch, but looking further down in
pci_device_add(), does ignoring a failure from device_add() leave the PCI
device in an indeterminate state?

If device_add() fails, it only logs a WARN_ON and returns without cleaning
up the device from bus->devices, which could crash subsystems iterating over
the global bus list.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260821142414.150892-1-djeffery@redhat.com?part=8

  reply	other threads:[~2026-08-21 14:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 14:24 [PATCH v20 0/9] shut down devices asynchronously David Jeffery
2026-08-21 14:24 ` [PATCH 1/9] driver core: rely on put_device to free dev->p David Jeffery
2026-08-21 14:32   ` sashiko-bot
2026-08-21 14:24 ` [PATCH 2/9] driver core: prevent device_add() during system shutdown David Jeffery
2026-08-21 14:43   ` sashiko-bot
2026-08-21 14:24 ` [PATCH 3/9] driver core: warn should device_move try to move a need_parent_lock device David Jeffery
2026-08-21 14:34   ` sashiko-bot
2026-08-21 14:24 ` [PATCH 4/9] driver core: separate function to shutdown one device David Jeffery
2026-08-21 14:29   ` sashiko-bot
2026-08-21 14:24 ` [PATCH 5/9] driver core: do not always lock parent in shutdown David Jeffery
2026-08-21 14:33   ` sashiko-bot
2026-08-21 14:24 ` [PATCH 6/9] driver core: async device shutdown infrastructure David Jeffery
2026-08-21 14:38   ` sashiko-bot
2026-08-21 14:24 ` [PATCH 7/9] PCI: Link a virtual function to its physical function David Jeffery
2026-08-21 14:34   ` sashiko-bot
2026-08-21 14:24 ` [PATCH 8/9] PCI: Enable async shutdown support David Jeffery
2026-08-21 14:39   ` sashiko-bot [this message]
2026-08-21 14:24 ` [PATCH 9/9] scsi: " David Jeffery
2026-08-21 14:38   ` 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=20260821143927.A69441F00ACF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=djeffery@redhat.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox