All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Jeffery" <djeffery@redhat.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org,
	"Tarun Sahu" <tarunsahu@google.com>,
	"Stuart Hayes" <stuart.w.hayes@gmail.com>,
	"Laurence Oberman" <loberman@redhat.com>,
	"Bjorn Helgaas" <helgaas@kernel.org>,
	kexec@lists.infradead.org, "Ewan Milne" <emilne@redhat.com>,
	"John Meneghini" <jmeneghi@redhat.com>,
	"Lombardi, Maurizio" <mlombard@redhat.com>,
	"Bart Van Assche" <bvanassche@acm.org>,
	"John Garry" <john.g.garry@oracle.com>,
	"Jeremy Allison" <jallison@ciq.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	"Pasha Tatashin" <tatashin@google.com>
Subject: Re: [PATCH 6/9] driver core: async device shutdown infrastructure
Date: Tue, 20 Oct 2026 17:19:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-179411@kernel.org> (raw)
In-Reply-To: <20261020164435.80499-7-djeffery@redhat.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] driver core: premature completion in kill_device() races with device_del()
- [Low] driver core: missing kernel-doc for DEV_FLAG_ASYNC_SHUTDOWN
--

commit 82979b053d4cad6e7ae5134feb8f79f9f979e23e
Author: David Jeffery <djeffery@redhat.com>

driver core: async device shutdown infrastructure

This commit introduces asynchronous device shutdown support, allowing
devices flagged with DEV_FLAG_ASYNC_SHUTDOWN to execute their shutdown
callbacks in parallel after waiting for their child and consumer
dependencies to finish shutting down.

> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 93605698affcc..7fee6043dd375 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c

[ ... ]

> @@ -3925,6 +3932,7 @@ bool kill_device(struct device *dev)
>  	if (dev->p->dead)
>  		return false;
>  	dev->p->dead = true;
> +	complete_all(&dev->p->complete);
>  	return true;
>  }
>  EXPORT_SYMBOL_GPL(kill_device);

[Severity: High]
Does signaling dev->p->complete in kill_device() wake parent and supplier
devices too early when a child or consumer device is concurrently removed
via device_del()?

In device_del(), kill_device() is called right at the start before dropping
device_lock(dev), while the actual driver unbinding and resource release
happen later:

drivers/base/core.c:device_del() {
	device_lock(dev);
	kill_device(dev);
	device_unlock(dev);
	...
		list_for_each_entry(class_intf, &sp->interfaces, node)
			if (class_intf->remove_dev)
				class_intf->remove_dev(dev);
	...
	bus_remove_device(dev);
	device_pm_remove(dev);
	...
	devres_release_all(dev);
}

During device_shutdown(), parent and supplier devices wait for child and
consumer devices in wait_for_shutdown_dependencies() ->
wait_for_device_shutdown(), which only waits on dev->p->complete:

	if (async || wants_async_shutdown(dev))
		wait_for_completion(&dev->p->complete);

Meanwhile, __shutdown_one_device() returns immediately without waiting if
dev->p->dead is set:

	if (!dev->p || dev->p->dead)
		return;

Before this change, a deleting child or consumer stayed on
devices_kset->list until kobject_del() at the end of device_del(), and
shutdown_one_device() serialized on device_lock(dev) against
bus_remove_device() -> device_release_driver() before device_shutdown()
moved on to the parent or supplier. Similarly, for async suspend,
device_pm_remove() does not call complete_all(&dev->power.completion) until
after bus_remove_device() has completed.

By completing dev->p->complete inside kill_device(), can a parent or
supplier proceed with its ->shutdown() callback and shut down a bus or
controller while its child or consumer is still executing
class_intf->remove_dev(), ->remove(), or devres_release_all()?

[ ... ]

> diff --git a/include/linux/device.h b/include/linux/device.h
> index aee79fd6b32b4..1ebafa7984621 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -612,6 +612,7 @@ enum struct_device_flags {
>  	DEV_FLAG_OF_NODE_REUSED = 7,
>  	DEV_FLAG_OFFLINE_DISABLED = 8,
>  	DEV_FLAG_OFFLINE = 9,
> +	DEV_FLAG_ASYNC_SHUTDOWN = 10,
>  
>  	DEV_FLAG_COUNT
>  };

[Severity: Low]
enum struct_device_flags has a kernel-doc comment immediately above it (which
is parsed via the :internal: directive in
Documentation/driver-api/infrastructure.rst). Should an entry for
@DEV_FLAG_ASYNC_SHUTDOWN be added to that comment to avoid a kernel-doc
warning?

[ ... ]

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


  reply	other threads:[~2026-10-20 17:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 16:44 [PATCH RESEND v22 0/9] shut down devices asynchronously David Jeffery
2026-10-20 16:44 ` [PATCH 1/9] driver core: rely on put_device to free dev->p David Jeffery
2026-10-20 16:56   ` sashiko-bot
2026-10-20 16:44 ` [PATCH 2/9] driver core: prevent device_add() during system shutdown David Jeffery
2026-10-20 17:03   ` sashiko-bot
2026-10-20 16:44 ` [PATCH 3/9] driver core: warn should device_move try to move a need_parent_lock device David Jeffery
2026-10-20 16:48   ` sashiko-bot
2026-10-20 16:44 ` [PATCH 4/9] driver core: separate function to shutdown one device David Jeffery
2026-10-20 16:47   ` sashiko-bot
2026-10-20 16:44 ` [PATCH 5/9] driver core: do not always lock parent in shutdown David Jeffery
2026-10-20 17:02   ` sashiko-bot
2026-10-20 16:44 ` [PATCH 6/9] driver core: async device shutdown infrastructure David Jeffery
2026-10-20 17:19   ` sashiko-bot [this message]
2026-10-20 16:44 ` [PATCH 7/9] PCI: Link a virtual function to its physical function David Jeffery
2026-10-20 16:52   ` sashiko-bot
2026-10-20 16:44 ` [PATCH 8/9] PCI: Enable async shutdown support David Jeffery
2026-10-20 16:54   ` sashiko-bot
2026-10-20 16:44 ` [PATCH 9/9] scsi: " David Jeffery
2026-10-20 17:01   ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-09-17 16:37 [PATCH v22 0/9] shut down devices asynchronously David Jeffery
2026-09-17 16:37 ` [PATCH 6/9] driver core: async device shutdown infrastructure David Jeffery
2026-09-17 16:47   ` sashiko-bot
2026-09-02 17:07 [PATCH v21 0/9] shut down devices asynchronously David Jeffery
2026-09-02 17:07 ` [PATCH 6/9] driver core: async device shutdown infrastructure David Jeffery
2026-09-02 17:17   ` sashiko-bot
2026-08-21 14:24 [PATCH v20 0/9] shut down devices asynchronously David Jeffery
2026-08-21 14:24 ` [PATCH 6/9] driver core: async device shutdown infrastructure 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=sashiko-outbox-179411@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=dakr@kernel.org \
    --cc=djeffery@redhat.com \
    --cc=emilne@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=helgaas@kernel.org \
    --cc=jallison@ciq.com \
    --cc=jmeneghi@redhat.com \
    --cc=john.g.garry@oracle.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=loberman@redhat.com \
    --cc=martin.petersen@oracle.com \
    --cc=mlombard@redhat.com \
    --cc=rafael@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stuart.w.hayes@gmail.com \
    --cc=tarunsahu@google.com \
    --cc=tatashin@google.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.