Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp180367iob; Mon, 2 May 2022 16:26:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt2f7fNdQLqkWm6Hzza/Yj/MY9z5JlDaHSvN46BjGW6AZubbgfVutkCW4MQtsehayalu60 X-Received: by 2002:a63:824a:0:b0:3ab:4599:4bff with SMTP id w71-20020a63824a000000b003ab45994bffmr11369035pgd.378.1651534008210; Mon, 02 May 2022 16:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651534008; cv=none; d=google.com; s=arc-20160816; b=Sy14wUEj7BZHI1VneKWe1DoJmMrUbvvzOS9sNDeJNUQqUmrJShyouiCQENlITMATWf jRNaxl6LOPPvLdT0GeA1ofcXKp32pUaEqnRYXAdchAKB/3HCsByWgmZ7An/y4E/qufGq 5HMPntO9kOMV+9EAQOt0iMA1/EafVFYvGFdxA6M5uZ6UokTNzS4OgUx70tJR1lY2xM6R i4VOR1nNvQ3N9kXX9lEWMS1YT/6+KFbZVWMdhjt/6HyhUDJZi7nLCXC2PhXPtLT9iZOk cToPKSTozdU6fvVFd3YsJz0U+5tSR1AUBJcBvsy9CbkUagCY3rhndVZG86ifPEeJk1OS i0MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+UEKgXrrD0bBkveYKV1BzyuG02j+m4QM4Vug4t1K1Lc=; b=i1+yFR9UK1yHNENkg+GMT6dTxONoCRRdfYrduPsObJsKmq948LJtrxdLVz7vV6zMtz WpuRHzxwKMtm50G7PF14o2lImAzUP5D1uPY8SgtKhneJywTOXxqWxEREfuK7cs9WUSRu 5Vw1V9Dv6pF8bmC54MLO+Tq46RK+WQmr6Awt9I2TfB49rI6seFxxLWkYz2daWYdxV0BX ScCtEYnw6EcpyRaNH2063rkIGX3QJoX/pSp3i0HzEeiW3ts8XUpALv1mwr4xuphE5c5p s81ERZN8ydIaytaNRhHFLdwljKRpVmKNhIWaztR6AkleI6CMG5Z1vrxJ2APXf3UJBAnh YBHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QTAhsROB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id pb6-20020a17090b3c0600b001dc439d1eefsi571569pjb.104.2022.05.02.16.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 16:26:48 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QTAhsROB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 18F73DF0; Mon, 2 May 2022 16:26:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379874AbiD2SGk (ORCPT + 99 others); Fri, 29 Apr 2022 14:06:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379866AbiD2SGj (ORCPT ); Fri, 29 Apr 2022 14:06:39 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F995D4C4D for ; Fri, 29 Apr 2022 11:03:19 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id h8so10520911iov.12 for ; Fri, 29 Apr 2022 11:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+UEKgXrrD0bBkveYKV1BzyuG02j+m4QM4Vug4t1K1Lc=; b=QTAhsROB7PeybDtVIea7NpCcw6Y2SGXrxVNMO7ueaeqMjkvhygrvrO0CB92dH9jYHv /1nCwI6Csg2CaPABJV27UPGb+RZGethrwyW6l9S/0RC4pDBGuwKfa+1q7I/+z5H21Z+w +7l5ZduiDLL6NLD8GFd41Tsa7yF5dg6x6s+q3kbxi4YNf3F7vWX1I2KU7vW2wJ2z/HrJ TdeOd6pFhgxZGYn+oda5ArqSaiiM9auNh6u6kBlG8er/5Dn7LqYesgqm6k8RG1rG2swV jLFb9vwGPv4PNejd+S6r4d5/N9/J7CVn5pzUglxFfDhAg7y/B0z64DikIAot0VeJMD+r oaRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+UEKgXrrD0bBkveYKV1BzyuG02j+m4QM4Vug4t1K1Lc=; b=088KfxnmexoKybaMgmNHz7A0C12vA8vFT8k1raEf0G5X4V1kQEwuJ5k6pweNEfuf1+ PWTcLKKBno9b6CskswJD+Bbv09U0o7juXiSmWWoQUOpP749BqEqzXjkNRxyKu+AzJsPN jE0BuNbo2yKFNoLHtiHV1eapC29dVysgQzZgOMjSAgGBUNSPI14eglSFwzX7nsWUmEP6 mVx0FPGJBsSH4PMMB5iJtqY9EeSTob0+peDxh2Y2JAUmkOaHpgfVhRsydE0jYROxxAQU ZJgiVKb1PqSD8poI0XFcjgswHYqUHWLE0JTM9DtbSK0Jix81U5WCNXBqvqe6PZhAWmG9 wR7Q== X-Gm-Message-State: AOAM530Dt9GLbgMk1fAaJg+LBLq7lb1GduuOE3z9quW9TE+A9dYQfKuJ Z4PiZwx9LpgKt/HMLg+WxOFBTjH9ed0qxxFl86fSmeFBsbE= X-Received: by 2002:a02:7a06:0:b0:32b:1b83:649a with SMTP id a6-20020a027a06000000b0032b1b83649amr229323jac.29.1651255398079; Fri, 29 Apr 2022 11:03:18 -0700 (PDT) MIME-Version: 1.0 References: <20220412224348.1038613-1-tansuresh@google.com> <20220412224348.1038613-2-tansuresh@google.com> In-Reply-To: From: Tanjore Suresh Date: Fri, 29 Apr 2022 11:03:07 -0700 Message-ID: Subject: Re: [PATCH v2 1/3] driver core: Support asynchronous driver shutdown To: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman , Christoph Hellwig , Sagi Grimberg , Bjorn Helgaas , Linux Kernel Mailing List , linux-nvme , Linux PCI Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rafael, That is a good observation, however, many of the use cases in data centers (deployment of devices in data centers) do not exploit device power management. Therefore, I'm not sure that is the right way to design this. Also if you look into device_shutdown (drivers/base/core.c) generic kernel routine does not exploit the shutdown method suggested by you instead use the generic shutdown methods defined in bus, class, drivers structures. Therefore, adopting to expand on those generic shutdown interfaces is the incremental choice to not confuse driver developers. Hope this clarifies why this extension is proposed when compared to overloading a generic shutdown entry point with device power management requirements. Thanks sureshtk On Fri, Apr 15, 2022 at 7:42 AM Rafael J. Wysocki wrote: > > On Wed, Apr 13, 2022 at 12:44 AM Tanjore Suresh wrote: > > > > This changes the bus driver interface with additional entry points > > to enable devices to implement asynchronous shutdown. The existing > > synchronous interface to shutdown is unmodified and retained for > > backward compatibility. > > > > This changes the common device shutdown code to enable devices to > > participate in asynchronous shutdown implementation. > > > > Signed-off-by: Tanjore Suresh > > Is there any specific reason why you didn't follow the design of, say, > dpm_suspend(), where the "async" devices only need to have a flag set > and the driver is not required to implement any new callbacks? > > IMO having different driver interfaces for asynchronous suspend and > shutdown would be quite confusing for driver developers, wouldn't it? > > > --- > > drivers/base/core.c | 38 +++++++++++++++++++++++++++++++++++++- > > include/linux/device/bus.h | 12 ++++++++++++ > > 2 files changed, 49 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/base/core.c b/drivers/base/core.c > > index 3d6430eb0c6a..ba267ae70a22 100644 > > --- a/drivers/base/core.c > > +++ b/drivers/base/core.c > > @@ -4479,6 +4479,7 @@ EXPORT_SYMBOL_GPL(device_change_owner); > > void device_shutdown(void) > > { > > struct device *dev, *parent; > > + LIST_HEAD(async_shutdown_list); > > > > wait_for_device_probe(); > > device_block_probing(); > > @@ -4523,7 +4524,13 @@ void device_shutdown(void) > > dev_info(dev, "shutdown_pre\n"); > > dev->class->shutdown_pre(dev); > > } > > - if (dev->bus && dev->bus->shutdown) { > > + if (dev->bus && dev->bus->async_shutdown_start) { > > + if (initcall_debug) > > + dev_info(dev, "async_shutdown_start\n"); > > + dev->bus->async_shutdown_start(dev); > > + list_add_tail(&dev->kobj.entry, > > + &async_shutdown_list); > > + } else if (dev->bus && dev->bus->shutdown) { > > if (initcall_debug) > > dev_info(dev, "shutdown\n"); > > dev->bus->shutdown(dev); > > @@ -4543,6 +4550,35 @@ void device_shutdown(void) > > spin_lock(&devices_kset->list_lock); > > } > > spin_unlock(&devices_kset->list_lock); > > + > > + /* > > + * Second pass spin for only devices, that have configured > > + * Asynchronous shutdown. > > + */ > > + while (!list_empty(&async_shutdown_list)) { > > + dev = list_entry(async_shutdown_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 (dev->bus && dev->bus->async_shutdown_end) { > > + if (initcall_debug) > > + dev_info(dev, > > + "async_shutdown_end called\n"); > > + dev->bus->async_shutdown_end(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 a039ab809753..f582c9d21515 100644 > > --- a/include/linux/device/bus.h > > +++ b/include/linux/device/bus.h > > @@ -49,6 +49,16 @@ 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. > > + * @async_shutdown_start: Called at the shutdown-time to start > > + * the shutdown process on the device. > > + * This entry point will be called only > > + * when the bus driver has indicated it would > > + * like to participate in asynchronous shutdown > > + * completion. > > + * @async_shutdown_end: Called at shutdown-time to complete the shutdown > > + * process of the device. This entry point will be called > > + * only when the bus drive has indicated it would like to > > + * participate in the asynchronous shutdown completion. > > * > > * @online: Called to put the device back online (after offlining it). > > * @offline: Called to put the device offline for hot-removal. May fail. > > @@ -93,6 +103,8 @@ struct bus_type { > > void (*sync_state)(struct device *dev); > > void (*remove)(struct device *dev); > > void (*shutdown)(struct device *dev); > > + void (*async_shutdown_start)(struct device *dev); > > + void (*async_shutdown_end)(struct device *dev); > > > > int (*online)(struct device *dev); > > int (*offline)(struct device *dev); > > -- > > 2.36.0.rc0.470.gd361397f0d-goog > >