Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp392449iob; Wed, 18 May 2022 04:40:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+uKmvH3+PpXfc6Q7I85/pFI+OUfKog1BVtc00oN0H/iWx7VSpcUOXq3xStiW2/Gj2GsFT X-Received: by 2002:a05:6a00:b8b:b0:50d:6080:6be7 with SMTP id g11-20020a056a000b8b00b0050d60806be7mr27379927pfj.56.1652874001098; Wed, 18 May 2022 04:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652874001; cv=none; d=google.com; s=arc-20160816; b=A+6rbV8Lf5G7QzAHbPMyECIzGbwQ2LFcRbRKi8um3W4KRsW8Ok4LnMpGgBZDdHl6Wy Rcf9Scf4YMFsDuL+bawEJtVA1SPEN51bmEuwtwe0WWGMYXgL1AhzPyXjQf8/DRGhkCgg QgwE0h5qe0Fg5PjrHWXMSh1KnmjCLdGHSlmjkGjoZJjhzz+OMddinGH8VGDtKYKXAixG WXUTDV6LxgXY+6QTyS/3LFMVcSHY6yWmXS7igZLX7vWIQLtQqTgu7hDFqPnDUVzmDaXB qtKUTz8nR4SJf1fGAusBpoCI+CEeYvrqJ0s1BvfWpyDC+/K1hXbduNxZdj2BZKyKV5vr xgFA== 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; bh=Zrwlit81NOfQDl1MFOpzqvUONSVA1zEjJ5vK5GKa7Pw=; b=tL8g13U5Nk0IVxs21ankSa1rG0FOB8/WcIhAkzrJsP61EaejcAA0Skg20TAdT92+cZ 3b+WJl0e37MKizxh4VnkZLk1TtMbHOVtJrVSMcue/gmjPkDti/3ea6Sc/KCFph6VvC/B 3xzwx98ot1tjWIfwSnFcc16jXsOs0gZbp1ZrxJVeZe2k0CZnac4JcTyvKZPO0xZ7KmnN g8miQdSOrnjUk6mevScmPON2hIn/AdglNDNmhjdzUTmPlPuj8zg7D9VR+HiUVXpl80eU ao5Ad+a8Cfx1z1W227CH+aL37J6+/EamWz9MyBIay+7KUKliwycTA7EImOnOWNfRlTVM OZCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e9-20020a17090ac20900b001df4c6c0525si6432942pjt.19.2022.05.18.04.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 04:40:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 974E0179084; Wed, 18 May 2022 04:39:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235823AbiERLjE (ORCPT + 99 others); Wed, 18 May 2022 07:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235714AbiERLjD (ORCPT ); Wed, 18 May 2022 07:39:03 -0400 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 626791737FD; Wed, 18 May 2022 04:39:02 -0700 (PDT) Received: by mail-yb1-f181.google.com with SMTP id i11so3136958ybq.9; Wed, 18 May 2022 04:39:02 -0700 (PDT) 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=Zrwlit81NOfQDl1MFOpzqvUONSVA1zEjJ5vK5GKa7Pw=; b=5LAwZ/0aXU/TFm/3rmx7Bf7k7eNA7YPfYllc6rr80HyF64df52Kt6fmFBY4mcu9wF5 L1Dbtq/nAi+r6KYY59ToEvz2ebQ1CFeS0mZikArLI1Sw+rwBBWC6dbxGjnn7EqvFt3vD 7E+z9pe0yboQpZmJhvKjYLFvDBtLJl3e7Ewf0VaG4g4mfocw1iy+ZVYx9pmWGR/iZGMV a74TqR+aj5XoeQppTEWgpIipxY+Orh2nU3AV+nT8DQivRqIk+PdlYL6FxhzxTgMkLe4Z YDc7CXzbzhmNwiwBRhQWf3dI1PNwjtEGTr53gLMnoTyO0yjFA+AUGJodeEqF/q2/Qcwo y8TQ== X-Gm-Message-State: AOAM533QJ2hMTDMbEa7mL8cRCMfCm1BzR+ObtE6JPyFhHhMlfaw7tIrK Qviwv3zPBhYU/XNquwlGc5ZX9XFbzEFlBGAzU3g= X-Received: by 2002:a25:7717:0:b0:64d:854f:2da4 with SMTP id s23-20020a257717000000b0064d854f2da4mr15356551ybc.633.1652873941589; Wed, 18 May 2022 04:39:01 -0700 (PDT) MIME-Version: 1.0 References: <20220517220816.1635044-1-tansuresh@google.com> <20220517220816.1635044-2-tansuresh@google.com> In-Reply-To: <20220517220816.1635044-2-tansuresh@google.com> From: "Rafael J. Wysocki" Date: Wed, 18 May 2022 13:38:49 +0200 Message-ID: Subject: Re: [PATCH v3 1/3] driver core: Support asynchronous driver shutdown To: Tanjore Suresh Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , 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=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 On Wed, May 18, 2022 at 12:08 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 > --- > 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. I'm going to repeat my point here, but only once. I see no reason to do async shutdown this way, instead of adding a flag for drivers to opt in for calling their existing shutdown callbacks asynchronously, in analogy with the async suspend and resume implementation. Is there any reason why this is not viable? > * > * @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.550.gb090851708-goog >