From nobody Mon May 25 04:34:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 319A9390986 for ; Mon, 18 May 2026 19:32:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132761; cv=none; b=UdM0qNajXoyyR5/CLlAn1ljSifI3RqY2EoELu6J/ZOVd88aHgvGeL4lg55EOPMLyM/lDINYcLujsJWzJgeLKrYiSgfr7MUKbbsB9JeRlJNDkkdBvVKT/D1uyWcLLpTnG3dSiwNKf+96H2VLLcUFHC0ntoSauMLZwJ35EIhbU+Bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132761; c=relaxed/simple; bh=IIRHCnVj1kX8zn6wuGPePV3IttKqKOMHUG8l3MzGKqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XIyiSO01aBBXzr81nKQm1hXqZn88e0A9J/NZ/2FJOelqfUHj+ZPQ5BrN5rx1vkL+608s5WhY3uzxTHXel5uL2VeoZtUYL/vmt35E8zd83vvbg3gLq1HHqrfHSkBJwGwSkO27wRy2xtl4mK2jr/texTP8M40kIcIgiTqONDtwH9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JHVKx/vi; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JHVKx/vi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779132759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hmj7+uAJKKkRlThg41ZSGB94iiYxo+Hfgee3MngZrIo=; b=JHVKx/vijX3z6DzAvUoOmvcGtuTNmKjn5etgiVfWzsCq5+Ovkgf9RXH0AAiGIsN5oIdkrI G9sdfIT3bSUUrmHBz6h6aTcQoHkZL9WnF9tZfjDGMAWFhG5vY+nvTCj8tQxaKPg5jeRkOf aCCdEcFk9AYaFvccqXd1qhW2drca15c= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-Q2uPVdsvMNmdyw3tWJXI-A-1; Mon, 18 May 2026 15:32:35 -0400 X-MC-Unique: Q2uPVdsvMNmdyw3tWJXI-A-1 X-Mimecast-MFC-AGG-ID: Q2uPVdsvMNmdyw3tWJXI-A_1779132753 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D4AFA1956050; Mon, 18 May 2026 19:32:32 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.152]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D22611800370; Mon, 18 May 2026 19:32:27 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , kexec@lists.infradead.org, David Jeffery , Pasha Tatashin Subject: [PATCH 1/5] driver core: separate function to shutdown one device Date: Mon, 18 May 2026 15:32:00 -0400 Message-ID: <20260518193204.14273-2-djeffery@redhat.com> In-Reply-To: <20260518193204.14273-1-djeffery@redhat.com> References: <20260518193204.14273-1-djeffery@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Make a separate function for the part of device_shutdown() that does the shutown for a single device. This is in preparation for making device shutdown asynchronous. Signed-off-by: Stuart Hayes Signed-off-by: David Jeffery Tested-by: Laurence Oberman Tested-by: Tarun Sahu Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin --- drivers/base/core.c | 71 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index d49420e066de..127432248165 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4795,12 +4795,48 @@ int device_change_owner(struct device *dev, kuid_t = kuid, kgid_t kgid) return error; } =20 +static void shutdown_one_device(struct device *dev) +{ + struct device *parent =3D dev->parent; + + /* hold lock to avoid race with probe/release */ + if (parent) + device_lock(parent); + device_lock(dev); + + /* Don't allow any more runtime suspends */ + pm_runtime_get_noresume(dev); + pm_runtime_barrier(dev); + + if (dev->class && dev->class->shutdown_pre) { + if (initcall_debug) + 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); + } else if (dev->driver && dev->driver->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->driver->shutdown(dev); + } + + device_unlock(dev); + if (parent) + device_unlock(parent); + + put_device(parent); + put_device(dev); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ void device_shutdown(void) { - struct device *dev, *parent; + struct device *dev; =20 wait_for_device_probe(); device_block_probing(); @@ -4822,7 +4858,7 @@ void device_shutdown(void) * prevent it from being freed because parent's * lock is to be held */ - parent =3D get_device(dev->parent); + get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the @@ -4831,36 +4867,7 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); =20 - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); - - /* Don't allow any more runtime suspends */ - pm_runtime_get_noresume(dev); - pm_runtime_barrier(dev); - - if (dev->class && dev->class->shutdown_pre) { - if (initcall_debug) - 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); - } else if (dev->driver && dev->driver->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->driver->shutdown(dev); - } - - device_unlock(dev); - if (parent) - device_unlock(parent); - - put_device(dev); - put_device(parent); + shutdown_one_device(dev); =20 spin_lock(&devices_kset->list_lock); } --=20 2.53.0 From nobody Mon May 25 04:34:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A98AD220698 for ; Mon, 18 May 2026 19:32:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132767; cv=none; b=WrgiUhb3mZsK9F1wJdAMd79G2wO5HUlZ0+Kt0I61b0C6GZl81neoiZZpUgnG1Ct7axoQi11xk7t5KFOCJMiitLwqMWPeSfZxpy0svCRCp3f16YLsvOpX1oom9T6na1gctGHdEPZ38DvxE4lNWGHSv1lKFCMlLgJHL6aEhEdrL9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132767; c=relaxed/simple; bh=Hw2l+SM+6/7rTA3960MSyjQ7M8RDG1rDl0U21kueAxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Aa/XosJffu3p5Wln81Uol/Gy0hJugc+FNi0UqkLYxZPW/XYh3ctCkHbTJI1PdwHxxhsjEA0MMyE9idcxbQvbNDKGvYGAM5UOwl6sHp1j07dhNOyf+t5pChVD/UnGmSkk5k2DIfsinYC/BrcaIwUQ5ylewL7jQQ+w/DR8qR5YXBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LW/flowE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LW/flowE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779132764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nqk72bG//fPU4sQo4pIFsdxIJ3sb1ha1IaNOs+/lbsM=; b=LW/flowE1UdnKbOVejgyyoyTMKkxiuMiOPZEQAgi3lL7d0NDz7ZWOrnQeOCGVDohJ7Q2GX Wb4bfFYHR0dZbCM17YFViRc2NYvTnKbZf441WASynI1NZxzS2c8PSqBoghOgbjnT83jIXq SeVJGm3Cg5R58jZYbFYgYuaG5zqpRqM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-SDOxfBqpMNCBceTnGg7BLA-1; Mon, 18 May 2026 15:32:40 -0400 X-MC-Unique: SDOxfBqpMNCBceTnGg7BLA-1 X-Mimecast-MFC-AGG-ID: SDOxfBqpMNCBceTnGg7BLA_1779132758 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F27C01956089; Mon, 18 May 2026 19:32:37 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.152]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D4E51800357; Mon, 18 May 2026 19:32:32 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , kexec@lists.infradead.org, David Jeffery , Pasha Tatashin Subject: [PATCH 2/5] driver core: do not always lock parent in shutdown Date: Mon, 18 May 2026 15:32:01 -0400 Message-ID: <20260518193204.14273-3-djeffery@redhat.com> In-Reply-To: <20260518193204.14273-1-djeffery@redhat.com> References: <20260518193204.14273-1-djeffery@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Don't lock a parent device unless it is needed in device_shutdown. This is in preparation for making device shutdown asynchronous, when it will be needed to allow children of a common parent to shut down simultaneously. And only acquire a reference to the parent device if the parent is to be locked. Signed-off-by: Stuart Hayes Signed-off-by: David Jeffery Tested-by: Laurence Oberman Tested-by: Tarun Sahu Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin --- drivers/base/core.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 127432248165..6e2c37115bc1 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4795,13 +4795,8 @@ int device_change_owner(struct device *dev, kuid_t k= uid, kgid_t kgid) return error; } =20 -static void shutdown_one_device(struct device *dev) +static void __shutdown_one_device(struct device *dev) { - struct device *parent =3D dev->parent; - - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); device_lock(dev); =20 /* Don't allow any more runtime suspends */ @@ -4824,10 +4819,23 @@ static void shutdown_one_device(struct device *dev) } =20 device_unlock(dev); - if (parent) +} + +static void shutdown_one_device(struct device *dev) +{ + struct device *parent; + + /* hold lock if needed to avoid race with probe/release */ + if (dev->bus && dev->bus->need_parent_lock && + (parent =3D get_device(dev->parent))) { + device_lock(parent); + __shutdown_one_device(dev); device_unlock(parent); + put_device(parent); + } else { + __shutdown_one_device(dev); + } =20 - put_device(parent); put_device(dev); } =20 @@ -4853,12 +4861,6 @@ void device_shutdown(void) dev =3D list_entry(devices_kset->list.prev, struct device, kobj.entry); =20 - /* - * hold reference count of device's parent to - * prevent it from being freed because parent's - * lock is to be held - */ - get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the --=20 2.53.0 From nobody Mon May 25 04:34:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B80E38AC7C for ; Mon, 18 May 2026 19:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132772; cv=none; b=TPQl6Kitt/TjLPQSHKHbngxU0unPgMJokLkaJenaWsUu1u6OkzyfaQrFjBSHNVbh/2gzCA9PinjrVI+DAouqU2O0IlKCVC+ZhgZ3sFH8/XD/qUKl5YyE14xGHk9g35FdlBceJZQ9Pj1tgS0NZvY6HjD+7uWcASEvN00EafcAfkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132772; c=relaxed/simple; bh=CQgn1ObnguriMrz2zvjUOxWWQVTtI7Yz6suMD6xl3O4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N+vXxdEtc9U/nFpNDXmYBZ9RzU8eCsrK5RzsHnspq4fhyiZb+s+Zv2fGm7tzWVlXAbfFA3DuSJgTDr05y6F399vNjxLCHgVxSYjLYzyd4uoiV1CfbGic/f3o5H1+eqldkqxykCFoW3ub4F6sgAJel/7lwcO2ZrHksYYAIP2yt1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cTu3BpW9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cTu3BpW9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779132769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ccOxduzI5ZCdWn1j1nlz1GbnV3NgyuIW6LgV0qj+TfQ=; b=cTu3BpW9FiU+Btu52yFYOdntxGD1GWbvSuabAzzThomkkEyJIubsGipCAAw0i4OX312Ngi UzI8TIBjWQhwcl6DsYqEnLfaBHycv/noUehfN58LFbDZCcZOpMMLL8zYpqlasmGKao/qMr gWLJb2doX8hu2wXgLIuFj8e/862qhcE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-6lbJNzIWO_yVilLh3p8pAA-1; Mon, 18 May 2026 15:32:46 -0400 X-MC-Unique: 6lbJNzIWO_yVilLh3p8pAA-1 X-Mimecast-MFC-AGG-ID: 6lbJNzIWO_yVilLh3p8pAA_1779132763 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30A0819560BB; Mon, 18 May 2026 19:32:43 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.152]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2F17E18004A3; Mon, 18 May 2026 19:32:38 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , kexec@lists.infradead.org, David Jeffery , Pasha Tatashin Subject: [PATCH 3/5] driver core: async device shutdown infrastructure Date: Mon, 18 May 2026 15:32:02 -0400 Message-ID: <20260518193204.14273-4-djeffery@redhat.com> In-Reply-To: <20260518193204.14273-1-djeffery@redhat.com> References: <20260518193204.14273-1-djeffery@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Patterned after async suspend, allow devices to mark themselves as wanting to perform async shutdown. Devices using async shutdown wait only for their dependencies to shutdown before executing their shutdown routine. Sync shutdown devices are shut down one at a time and will only wait for an async shutdown device if the async device is a dependency. Enabled by default, async shutdown can be explicitly enabled or disabled by using the kernel parameter "core.async_shutdown=3D" Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Tested-by: Laurence Oberman Tested-by: Tarun Sahu Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin --- .../admin-guide/kernel-parameters.txt | 10 ++ drivers/base/base.h | 2 + drivers/base/core.c | 101 +++++++++++++++++- include/linux/device.h | 2 + 4 files changed, 114 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index b5a51a36a048..dd912f47ace4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1019,6 +1019,16 @@ Kernel parameters seconds. A value of 0 disables the blank timer. Defaults to 0. =20 + core.async_shutdown=3D + [KNL] + Format: + Enable or disable asynchronous shutdown support. When + enabled, on system shutdown unrelated devices flagged + as async shutdown compatible may be shut down in + parallel and asynchronously. When disabled, device + shutdown is performed in a serially and synchronously. + Enabled by default. + coredump_filter=3D [KNL] Change the default value for /proc//coredump_filter. diff --git a/drivers/base/base.h b/drivers/base/base.h index 483b99b4fa3d..aefa4f256d59 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -103,6 +103,7 @@ struct driver_private { * dev_err_probe() for later retrieval via debugfs * @device: pointer back to the struct device that this structure is * associated with. + * @complete: completion for device shutdown ordering * @dead: This device is currently either in the process of or has been * removed from the system. Any asynchronous events scheduled for this * device should exit without taking any action. @@ -119,6 +120,7 @@ struct device_private { const struct device_driver *async_driver; char *deferred_probe_reason; struct device *device; + struct completion complete; u8 dead:1; }; #define to_device_private_parent(obj) \ diff --git a/drivers/base/core.c b/drivers/base/core.c index 6e2c37115bc1..cab10b0e70db 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include #include @@ -37,6 +38,10 @@ #include "physical_location.h" #include "power/power.h" =20 +static bool async_shutdown =3D true; +module_param(async_shutdown, bool, 0644); +MODULE_PARM_DESC(async_shutdown, "Enable asynchronous device shutdown supp= ort"); + /* Device links support. */ static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count =3D 1; @@ -3536,6 +3541,7 @@ static int device_private_init(struct device *dev) klist_init(&dev->p->klist_children, klist_children_get, klist_children_put); INIT_LIST_HEAD(&dev->p->deferred_probe); + init_completion(&dev->p->complete); return 0; } =20 @@ -4795,6 +4801,37 @@ int device_change_owner(struct device *dev, kuid_t k= uid, kgid_t kgid) return error; } =20 +static bool wants_async_shutdown(struct device *dev) +{ + return async_shutdown && dev_async_shutdown(dev); +} + +static int wait_for_device_shutdown(struct device *dev, void *data) +{ + bool async =3D *(bool *)data; + + if (async || wants_async_shutdown(dev)) + wait_for_completion(&dev->p->complete); + + return 0; +} + +static void wait_for_shutdown_dependencies(struct device *dev, bool async) +{ + struct device_link *link; + int idx; + + device_for_each_child(dev, &async, wait_for_device_shutdown); + + idx =3D device_links_read_lock(); + + dev_for_each_link_to_consumer(link, dev) + if (!device_link_flag_is_sync_state_only(link->flags)) + wait_for_device_shutdown(link->consumer, &async); + + device_links_read_unlock(idx); +} + static void __shutdown_one_device(struct device *dev) { device_lock(dev); @@ -4818,6 +4855,8 @@ static void __shutdown_one_device(struct device *dev) dev->driver->shutdown(dev); } =20 + complete_all(&dev->p->complete); + device_unlock(dev); } =20 @@ -4839,6 +4878,55 @@ static void shutdown_one_device(struct device *dev) put_device(dev); } =20 +static void async_shutdown_handler(void *data, async_cookie_t cookie) +{ + struct device *dev =3D data; + + wait_for_shutdown_dependencies(dev, true); + shutdown_one_device(dev); +} + +static bool shutdown_device_async(struct device *dev) +{ + if (async_schedule_dev_nocall(async_shutdown_handler, dev)) + return true; + return false; +} + + +static void early_async_shutdown_devices(void) +{ + struct device *dev, *next, *needs_put =3D NULL; + + if (!async_shutdown) + return; + + spin_lock(&devices_kset->list_lock); + + list_for_each_entry_safe_reverse(dev, next, &devices_kset->list, + kobj.entry) { + if (wants_async_shutdown(dev)) { + get_device(dev); + + if (shutdown_device_async(dev)) { + list_del_init(&dev->kobj.entry); + } else { + /* + * async failed, clean up extra references + * and run from the standard shutdown loop + */ + needs_put =3D dev; + break; + } + } + } + + spin_unlock(&devices_kset->list_lock); + + if (needs_put) + put_device(needs_put); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ @@ -4851,6 +4939,12 @@ void device_shutdown(void) =20 cpufreq_suspend(); =20 + /* + * Start async device threads where possible to maximize potential + * parallelism and minimize false dependency on unrelated sync devices + */ + early_async_shutdown_devices(); + spin_lock(&devices_kset->list_lock); /* * Walk the devices list backward, shutting down each in turn. @@ -4869,11 +4963,16 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); =20 - shutdown_one_device(dev); + if (!wants_async_shutdown(dev) || !shutdown_device_async(dev)) { + wait_for_shutdown_dependencies(dev, false); + shutdown_one_device(dev); + } =20 spin_lock(&devices_kset->list_lock); } spin_unlock(&devices_kset->list_lock); + + async_synchronize_full(); } =20 /* diff --git a/include/linux/device.h b/include/linux/device.h index d54c86d77764..0f2aeba34483 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -546,6 +546,7 @@ enum struct_device_flags { DEV_FLAG_OF_NODE_REUSED =3D 7, DEV_FLAG_OFFLINE_DISABLED =3D 8, DEV_FLAG_OFFLINE =3D 9, + DEV_FLAG_ASYNC_SHUTDOWN =3D 10, =20 DEV_FLAG_COUNT }; @@ -763,6 +764,7 @@ __create_dev_flag_accessors(dma_coherent, DEV_FLAG_DMA_= COHERENT); __create_dev_flag_accessors(of_node_reused, DEV_FLAG_OF_NODE_REUSED); __create_dev_flag_accessors(offline_disabled, DEV_FLAG_OFFLINE_DISABLED); __create_dev_flag_accessors(offline, DEV_FLAG_OFFLINE); +__create_dev_flag_accessors(async_shutdown, DEV_FLAG_ASYNC_SHUTDOWN); =20 #undef __create_dev_flag_accessors =20 --=20 2.53.0 From nobody Mon May 25 04:34:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DC7139023B for ; Mon, 18 May 2026 19:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132778; cv=none; b=su2v+fhn9fBInesIYjF5URbewQoGiJtLv303khbBlcgQXuPI/4nJXCudYBtsNUxtXrFVrFb40gKjbb58nUOpV8rOIHRWJrL3CgcnJghYV36/1695yAyS3RakC/LaZGGg2t9Lm2AbN0P2wkACjPeTzzCiNzdkLI3J3jula2G6+W8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132778; c=relaxed/simple; bh=lHO62KHj5xtAVk+yQYPSq9oz83FZ6sHlXYLK9x5ljV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=neFuTfUJQNsVN9GkxXg6adkgvP+dfNJnYDkSBESb2OHeiA39tth1sJ6lA4PnPfgXUFgr518Rvhf90EVaT6i/hY8jDzlUwl/ip6h06XeSms8OOIz0MPrlCNA7ps9olh+FavmJLtNAL9GwCNyB0G7IaJuGhMvZd0ArEBPldluuxPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XgS+9xJ3; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XgS+9xJ3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779132775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qPWATKDr1MIUpUAApy0bSzHq965blpXvCBAbAZAmjDk=; b=XgS+9xJ3SxjZ18l3wKUJK/Ia6NMSyzdagWBpl6aNsJS7Rc7kgfym3M+FeBL7Bdc8BgQNNt q5RF40G0OUt5MfXOjwbz8ujXnYNMJKBjmr9bwWZbp6L2yLKgv1Tc9I4AqaxzRYu2pXaWyx Ykx/wmWxaNT1hS+aVNxtnXJGpTPmGlA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-ZxUhGcyYP6Gk1CcBFOQdug-1; Mon, 18 May 2026 15:32:51 -0400 X-MC-Unique: ZxUhGcyYP6Gk1CcBFOQdug-1 X-Mimecast-MFC-AGG-ID: ZxUhGcyYP6Gk1CcBFOQdug_1779132769 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A1E7C195609D; Mon, 18 May 2026 19:32:48 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.152]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7F9D9180075B; Mon, 18 May 2026 19:32:43 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , kexec@lists.infradead.org, David Jeffery , Pasha Tatashin , Bjorn Helgaas Subject: [PATCH 4/5] PCI: Enable async shutdown support Date: Mon, 18 May 2026 15:32:03 -0400 Message-ID: <20260518193204.14273-5-djeffery@redhat.com> In-Reply-To: <20260518193204.14273-1-djeffery@redhat.com> References: <20260518193204.14273-1-djeffery@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Like its async suspend support, allow PCI device shutdown to be performed asynchronously to reduce shutdown time. Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Tested-by: Laurence Oberman Tested-by: Tarun Sahu Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Reviewed-by: Bjorn Helgaas --- drivers/pci/probe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b63cd0c310bc..7cf3dabc885e 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1045,6 +1045,7 @@ static int pci_register_host_bridge(struct pci_host_b= ridge *bridge) =20 bus->bridge =3D get_device(&bridge->dev); device_enable_async_suspend(bus->bridge); + dev_set_async_shutdown(bus->bridge); pci_set_bus_of_node(bus); pci_set_bus_msi_domain(bus); if (bridge->msi_domain && !dev_get_msi_domain(&bus->dev) && @@ -2753,6 +2754,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_b= us *bus) pci_reassigndev_resource_alignment(dev); =20 pci_init_capabilities(dev); + dev_set_async_shutdown(&dev->dev); =20 /* * Add the device to our list of discovered devices --=20 2.53.0 From nobody Mon May 25 04:34:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F2AA3909BC for ; Mon, 18 May 2026 19:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132784; cv=none; b=MtPf9gvcJcMp+T6p//R1eZI2U2fQpS+EmDQPDarxl1LvYgXAGQpknYxh2YKSxcoVJXvVP9/Yr0huQhL67jIdIYcyboVIvrt90SxTMg7kGqJCRY9whGOBBPPfVv392kLbf8oUA9yrcZNcg8w9HaAFK5zDg2TQaWB/gNiif380pRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779132784; c=relaxed/simple; bh=MIwWzoNcld1di3sRY67JHF3L4tOIb9uRI+f7jDr1q6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CoF3EesbpDddR2o6VYcjBhBPe2zslJoDamxJFJoW2hkf0Qv7zOVFOvs0F6iPcoKqe1ufvr1C3UdQhX0+H8QZxCVENtO5RhKRKcVzl//F5tPd7IfkW4G/jlXxtetY69K5W6PkIO4ydIheUKGAi20HFjP5yHOAibs6B39iVLBLzMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=g+UJobrY; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g+UJobrY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779132782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6NRtUq4tdDKEDZRdGQPjS5xvGqYmmi7/Q1au3JiknCE=; b=g+UJobrY+YhRuZak/BnV7bhzekuDeGW2HBv37uhWggwqgn2Cc6Ld2rSWxJbonOw9H5JpnP QWQcKdy3atAzcawOXfDwTb8bVNfnIfv630LZYQQ2D03j12jlK4kSELTsk03SqkDxCR3raM eqH1ANc3/U+Av+fcj7iuCG1rAp0TOB8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-PTUTGaNwPNeIevaoNKwCVQ-1; Mon, 18 May 2026 15:32:56 -0400 X-MC-Unique: PTUTGaNwPNeIevaoNKwCVQ-1 X-Mimecast-MFC-AGG-ID: PTUTGaNwPNeIevaoNKwCVQ_1779132774 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7B13A1956089; Mon, 18 May 2026 19:32:54 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.152]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0E4BD18004A3; Mon, 18 May 2026 19:32:48 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , kexec@lists.infradead.org, David Jeffery , Pasha Tatashin Subject: [PATCH 5/5] scsi: Enable async shutdown support Date: Mon, 18 May 2026 15:32:04 -0400 Message-ID: <20260518193204.14273-6-djeffery@redhat.com> In-Reply-To: <20260518193204.14273-1-djeffery@redhat.com> References: <20260518193204.14273-1-djeffery@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Like scsi's async suspend support, allow scsi devices to be shut down asynchronously to reduce system shutdown time. Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Tested-by: Laurence Oberman Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Reviewed-by: John Garry --- drivers/scsi/hosts.c | 2 ++ drivers/scsi/scsi_sysfs.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index e047747d4ecf..bf691acc7a67 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -273,6 +273,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, pm_runtime_set_active(&shost->shost_gendev); pm_runtime_enable(&shost->shost_gendev); device_enable_async_suspend(&shost->shost_gendev); + dev_set_async_shutdown(&shost->shost_gendev); =20 error =3D device_add(&shost->shost_gendev); if (error) @@ -282,6 +283,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, get_device(shost->shost_gendev.parent); =20 device_enable_async_suspend(&shost->shost_dev); + dev_set_async_shutdown(&shost->shost_dev); =20 get_device(&shost->shost_gendev); error =3D device_add(&shost->shost_dev); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index dfc3559e7e04..8fd317aef37b 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1386,6 +1386,7 @@ static int scsi_target_add(struct scsi_target *starge= t) pm_runtime_set_active(&starget->dev); pm_runtime_enable(&starget->dev); device_enable_async_suspend(&starget->dev); + dev_set_async_shutdown(&starget->dev); =20 return 0; } @@ -1412,6 +1413,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) transport_configure_device(&starget->dev); =20 device_enable_async_suspend(&sdev->sdev_gendev); + dev_set_async_shutdown(&sdev->sdev_gendev); scsi_autopm_get_target(starget); pm_runtime_set_active(&sdev->sdev_gendev); if (!sdev->rpm_autosuspend) @@ -1431,6 +1433,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) } =20 device_enable_async_suspend(&sdev->sdev_dev); + dev_set_async_shutdown(&sdev->sdev_dev); error =3D device_add(&sdev->sdev_dev); if (error) { sdev_printk(KERN_INFO, sdev, --=20 2.53.0