[PATCH 1/5] driver core: Support two-pass driver shutdown.
Saravana Kannan
saravanak at google.com
Tue Feb 13 19:36:35 PST 2024
On Mon, Jan 29, 2024 at 10:19 AM Jeremy Allison <jallison at ciq.com> wrote:
>
> From: Tanjore Suresh <tansuresh at google.com>
>
> This changes the bus driver interface with an additional entry point
> to enable devices to implement two-pass shutdown. The existing
> synchronous interface to shutdown is called, and if a shutdown_wait
> method is defined the device is moved to an alternate list.
This sounds more like you need a parallelized async shutdown than a
two-pass shutdown. Similar to how async probes are done today. Why not
do that so it'll actually be useful in a more general fashion? You can
even add a flag like we have for probes so that drivers don't need to
do anything special to allow this parallelism.
-Saravana
>
> Once the shutdown method is called for all devices, the
> shutdown_wait method is then called synchronously for
> all devices on the alternate list.
>
> Signed-off-by: Tanjore Suresh <tansuresh at google.com>
> Signed-off-by: Jeremy Allison <jallison at ciq.com>
> ---
> drivers/base/core.c | 35 +++++++++++++++++++++++++++++++++++
> include/linux/device/bus.h | 6 +++++-
> 2 files changed, 40 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 14d46af40f9a..c8b0d4c9abed 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4725,6 +4725,7 @@ EXPORT_SYMBOL_GPL(device_change_owner);
> void device_shutdown(void)
> {
> struct device *dev, *parent;
> + LIST_HEAD(shutdown_wait_list);
>
> wait_for_device_probe();
> device_block_probing();
> @@ -4769,10 +4770,17 @@ void device_shutdown(void)
> dev_info(dev, "shutdown_pre\n");
> dev->class->shutdown_pre(dev);
> }
> +
> if (dev->bus && dev->bus->shutdown) {
> if (initcall_debug)
> dev_info(dev, "shutdown\n");
> dev->bus->shutdown(dev);
> + /*
> + * Only put the device on the shutdown_wait_list
> + * if a shutdown_wait() method is also defined.
> + */
> + if (dev->bus->shutdown_wait)
> + list_add(&dev->kobj.entry, &shutdown_wait_list);
> } else if (dev->driver && dev->driver->shutdown) {
> if (initcall_debug)
> dev_info(dev, "shutdown\n");
> @@ -4789,6 +4797,33 @@ void device_shutdown(void)
> spin_lock(&devices_kset->list_lock);
> }
> spin_unlock(&devices_kset->list_lock);
> +
> + /*
> + * Second pass only for devices that have configured
> + * a shutdown_wait() method.
> + */
> + while (!list_empty(&shutdown_wait_list)) {
> + dev = list_entry(shutdown_wait_list.next, struct device,
> + kobj.entry);
> + parent = get_device(dev->parent);
> + get_device(dev);
> + /*
> + * Make sure the device is off the list
> + */
> + list_del_init(&dev->kobj.entry);
> + if (parent)
> + device_lock(parent);
> + device_lock(dev);
> + if (initcall_debug)
> + dev_info(dev,
> + "shutdown_wait called\n");
> + dev->bus->shutdown_wait(dev);
> + device_unlock(dev);
> + if (parent)
> + device_unlock(parent);
> + put_device(dev);
> + put_device(parent);
> + }
> }
>
> /*
> diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
> index 5ef4ec1c36c3..a4132c44dac3 100644
> --- a/include/linux/device/bus.h
> +++ b/include/linux/device/bus.h
> @@ -48,7 +48,10 @@ struct fwnode_handle;
> * will never get called until they do.
> * @remove: Called when a device removed from this bus.
> * @shutdown: Called at shut-down time to quiesce the device.
> - *
> + * @shutdown_wait: If this method exists, devices are stored on a separate
> + * list after shutdown() has been called and
> + * shutdown_wait() is called synchronously on each device
> + * in this list in turn.
> * @online: Called to put the device back online (after offlining it).
> * @offline: Called to put the device offline for hot-removal. May fail.
> *
> @@ -87,6 +90,7 @@ struct bus_type {
> void (*sync_state)(struct device *dev);
> void (*remove)(struct device *dev);
> void (*shutdown)(struct device *dev);
> + void (*shutdown_wait)(struct device *dev);
>
> int (*online)(struct device *dev);
> int (*offline)(struct device *dev);
> --
> 2.39.3
>
>
>
More information about the Linux-nvme
mailing list