From nobody Tue Jun 16 19:33:07 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 7AF1338AC85 for ; Wed, 29 Apr 2026 17:51:01 +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=1777485062; cv=none; b=PErBV6YsI0YInCS0zV3/oK2/JHw0/9FyA3dPGEAV5T6+MLo2whfLE66FqugLemrWcqeRo81PS93VXqaFVnFWDl+Qh9TI9QFkdjmMOTUBCHsvOi1uGEJw5nUIHTvhflef9pyCpS0oz0QDate7Zzl/hZG0aGxMwQxbY4oDlDl1Tbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485062; c=relaxed/simple; bh=STIwt9gAk1FaUXXBbUvSbB4skwLNDKuHH/bTEx0BxrY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oc95jzUjdNDzCaz5w/tvv/csuLwgL/oQnyvdDuAUfen6rzQTrqVwuSgin0M+yl454vtpzc8cc8W0MQw0fVLraFFLhq3AVCdhVriQDZUmuLZqDbW4w0b9exb7jUsjxSC3YPxF4MkUzj1Z9BQNoMFsQvbMICVGNVNKg0vvRlwCKQc= 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=ekziuZmK; 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="ekziuZmK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777485060; 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=/C64blJM3Kjz6Rlhck7tMz+JFCKWeVjDfMx7FPCDn24=; b=ekziuZmKDb7Mbg22Je3cfeHbwnyOlEDtOI6Zl2Ta5C1fYeFvz5CriQZdPP9TwV1WS7jcdL /ym9DBaoj5agw1Cy2IrH3BOH89g/zhAIvMbai6zTLho7d1tHRw+K9IDP9MYzjrj4olMzPe jXA00hvRyBkGK42rAEO7X54vtlRDq6g= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-344-dKMwVYqFMc6TdsCEsQTSYg-1; Wed, 29 Apr 2026 13:50:56 -0400 X-MC-Unique: dKMwVYqFMc6TdsCEsQTSYg-1 X-Mimecast-MFC-AGG-ID: dKMwVYqFMc6TdsCEsQTSYg_1777485053 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3009518005AA; Wed, 29 Apr 2026 17:50:53 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 25DDE300019F; Wed, 29 Apr 2026 17:50:47 +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: Wed, 29 Apr 2026 13:50:12 -0400 Message-ID: <20260429175016.7915-2-djeffery@redhat.com> In-Reply-To: <20260429175016.7915-1-djeffery@redhat.com> References: <20260429175016.7915-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.4 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 Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Tested-by: Tarun Sahu --- 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 bd2ddf2aab50..90ef21c1e713 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4799,12 +4799,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(); @@ -4826,7 +4862,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 @@ -4835,36 +4871,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 Tue Jun 16 19:33:07 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 12B3238AC85 for ; Wed, 29 Apr 2026 17:51:06 +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=1777485067; cv=none; b=O5KSuLlOY7x/DwUp181lGXJHGaLmO3o91opMDUIG+KkQNMnLtsdvlp0r4ACd8eZexXUOtSdtqsy4nmH26wNieTUKqmC5AfA0mnXplSq3DOflAc1tHRIb83GPuhpJt5ntIXWKn74dnx1uUxnGAaj+antbfy8imH+ufAgMQwzJ74M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485067; c=relaxed/simple; bh=9/aCzZS9VmM/5YKrDbywSiRMILYOnTwHf+zOSZrkanY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U5l+Ky11lq1iiYEsaFkVAeO4yT/dcenyVQG3H0m2sD06vfPDAk4miuNhpY3VPROoEFsfoF67LHn+o9t3Ui3KOjI3N9+vDPBp6smbnFUfeaprXN9OXzpUZbWycFJ0/ULBPV66D9iJhMj3PFkutUryMQUXVqaUEvc9gtselTRp0xI= 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=UIQgTRD6; 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="UIQgTRD6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777485065; 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=fb0axA2F4uBUU3oNRkOoe05jXOarYOs75I9L8oq7gEE=; b=UIQgTRD6tglY1m5vzMaag8wkMg5JxYaz3Ant0PfcuNhyS3CjuS4Hg11aE15TuIvQP9dZ/W kvksjfTTYweevI523CN/9mmzDZReaxNjziL9ho6k34xNiVKurd0fk98L36FLwcyG+EJOmw 5+YXTUZTSg1Z3tCJeZparQDojYyW/Vo= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-12-NLJua771MEuaxlitmQs91Q-1; Wed, 29 Apr 2026 13:51:02 -0400 X-MC-Unique: NLJua771MEuaxlitmQs91Q-1 X-Mimecast-MFC-AGG-ID: NLJua771MEuaxlitmQs91Q_1777485060 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EF2D18004A9; Wed, 29 Apr 2026 17:50:59 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 998C030001A1; Wed, 29 Apr 2026 17:50:53 +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: Wed, 29 Apr 2026 13:50:13 -0400 Message-ID: <20260429175016.7915-3-djeffery@redhat.com> In-Reply-To: <20260429175016.7915-1-djeffery@redhat.com> References: <20260429175016.7915-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.4 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 Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Tested-by: Tarun Sahu --- 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 90ef21c1e713..00979555995f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4799,13 +4799,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 */ @@ -4828,10 +4823,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 @@ -4857,12 +4865,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 Tue Jun 16 19:33:07 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 DDAD738B7C1 for ; Wed, 29 Apr 2026 17:51:14 +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=1777485076; cv=none; b=gmkkjDLRNasi6+nixm+rtqiPlSWSWKQub/boSSnnqamt/0gZiRHE1xmwB+qMFIkhEdnfebjDiV0SoghFHbanloQKpxj/9zmGWYMV/hyc/9IICO9bViX+rkqkWK0pL49u8kM75JRWxeVSnlQFqz6GydW45N6pE5yE4BeT3G/hwIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485076; c=relaxed/simple; bh=3jFLYA1TT54QwrGuC3QtItyR47oUvW51Q1i8xF0GVmo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cEXl1wodDAg6HzYqAknfK3TPk8p1fn3FyaibFRuwue9nwgq7oVcWpQauHAmICETguIRKwZJhJ4trz9b1DErs/MyaRG3K2qLv1ct4QWg0IuCXMoK3uuOIGT4w6aI+njN8xBYdeOuhuydXsRlv9UJ57iRqjFPwvgBjZBDaMsQO7/w= 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=R6uP8UHA; 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="R6uP8UHA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777485074; 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=pciMxu+OtNDFx/HoCUy1oQD0OEIqbWw7T12d0qH6yoU=; b=R6uP8UHAiUhvlH5Rv3TepiHEzRfLHc3w400l0RiNZe4qlymj15TMIWEWBj0xSGT/yRl/GX nsLSuyQ/NJNer0dQ4E94qDX1AhAYIOAtvZn481ocwGwgH4TINFeilGC+B5pBQtklFflhB0 JT2KSfFDDerLV3n8JvRu+cKk+TAV048= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-z64996jGMneEwxo_Q5fYvw-1; Wed, 29 Apr 2026 13:51:08 -0400 X-MC-Unique: z64996jGMneEwxo_Q5fYvw-1 X-Mimecast-MFC-AGG-ID: z64996jGMneEwxo_Q5fYvw_1777485066 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EA0E31800345; Wed, 29 Apr 2026 17:51:05 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C8EC5300019F; Wed, 29 Apr 2026 17:50:59 +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: Wed, 29 Apr 2026 13:50:14 -0400 Message-ID: <20260429175016.7915-4-djeffery@redhat.com> In-Reply-To: <20260429175016.7915-1-djeffery@redhat.com> References: <20260429175016.7915-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.4 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. Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Tested-by: Laurence Oberman Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Tested-by: Tarun Sahu --- drivers/base/base.h | 2 + drivers/base/core.c | 101 ++++++++++++++++++++++++++++++++++++++++- include/linux/device.h | 14 +++++- 3 files changed, 115 insertions(+), 2 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 30b416588617..8b155a91ac3a 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -116,6 +116,7 @@ struct driver_type { * @device: pointer back to the struct device that this structure is * associated with. * @driver_type: The type of the bound Rust driver. + * @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. @@ -135,6 +136,7 @@ struct device_private { #ifdef CONFIG_RUST struct driver_type driver_type; #endif + 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 00979555995f..92f788fd813d 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; @@ -3540,6 +3545,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 @@ -4799,6 +4805,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; +} + +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); @@ -4822,6 +4859,8 @@ static void __shutdown_one_device(struct device *dev) dev->driver->shutdown(dev); } =20 + complete_all(&dev->p->complete); + device_unlock(dev); } =20 @@ -4843,6 +4882,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. */ @@ -4855,6 +4943,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. @@ -4873,11 +4967,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 9c8fde6a3d86..4b04cf62912b 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -615,6 +615,8 @@ enum struct_device_flags { * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. * @dma_iommu: Device is using default IOMMU implementation for DMA and * doesn't rely on dma_ops structure. + * @async_shutdown: Device shutdown may be run asynchronously and in paral= lel + * to the shutdown of unrelated devices * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an @@ -738,7 +740,7 @@ struct device { #ifdef CONFIG_IOMMU_DMA bool dma_iommu:1; #endif - + bool async_shutdown:1; DECLARE_BITMAP(flags, DEV_FLAG_COUNT); }; =20 @@ -969,6 +971,16 @@ static inline bool device_async_suspend_enabled(struct= device *dev) return !!dev->power.async_suspend; } =20 +static inline void device_enable_async_shutdown(struct device *dev) +{ + dev->async_shutdown =3D true; +} + +static inline bool device_async_shutdown_enabled(struct device *dev) +{ + return dev->async_shutdown; +} + static inline bool device_pm_not_required(struct device *dev) { return dev->power.no_pm; --=20 2.53.0 From nobody Tue Jun 16 19:33:07 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 73C4A38B133 for ; Wed, 29 Apr 2026 17:51:19 +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=1777485080; cv=none; b=XMrM942f4mIslOKa4p22ILAfMYpoz/rIBys7NbnvcoHV3QM8oS7BA/5dlkhTkgSrYqMFsyPFgiO4fbW/tqzHbpWAwxMd3X9iLLiaWcRNEFiztd9HHPBvBJ9VoM/YAwP3qQZCpr3QwPD5RtNhevh1TSgOW/oj+MPu83Hdc89W4RM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485080; c=relaxed/simple; bh=Z3ca1mwVV9tvMoPvpLPM4RlOmGhZUMxjiOj6IqI81pc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JjEWFrr/oQIwGpkp0LvrzyoZJuodA4E6RQrOTtF1dX9J2+fpoj6SEnVi1E7ZHVr29SdT13Jg6u2Oempnu0IziSHHKSQRoQOR/HXdLfAFPtUEp6/KEQPaMWwwF/8Av4HAtoFFkfFS18aY5uUPetj3Ddw7aYElSrXShlW51pR2xZM= 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=OaNIz5L5; 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="OaNIz5L5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777485078; 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=U54ViaHQ6SdACiN5txV3sQNUzriUf70Auy/2LcwcU0s=; b=OaNIz5L5TPTNPMwImfl4W9jEI4XQ0DmW+Pijj6CsUwUhIvOHEjH+wHjm3N3v5u9YRb1C++ Mvxa+f9yRaW/NT3OnZPND8kl/OckMLaffm1wEEMQGeWpccMje7hATrBjlHJA2LV+/aHq2P LbwrBtxIi55Hu4WJVCi7jK7KvClSKD4= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-685-VbipQuUTOhiPukFtFJk__Q-1; Wed, 29 Apr 2026 13:51:14 -0400 X-MC-Unique: VbipQuUTOhiPukFtFJk__Q-1 X-Mimecast-MFC-AGG-ID: VbipQuUTOhiPukFtFJk__Q_1777485071 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCF881800347; Wed, 29 Apr 2026 17:51:11 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 41FCC30001BB; Wed, 29 Apr 2026 17:51:06 +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 4/5] PCI: Enable async shutdown support Date: Wed, 29 Apr 2026 13:50:15 -0400 Message-ID: <20260429175016.7915-5-djeffery@redhat.com> In-Reply-To: <20260429175016.7915-1-djeffery@redhat.com> References: <20260429175016.7915-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.4 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 Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Reviewed-by: Bjorn Helgaas Tested-by: Tarun Sahu reviewed-by from the other subsystems it touches. --- drivers/pci/probe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b63cd0c310bc..86e855090553 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); + device_enable_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); + device_enable_async_shutdown(&dev->dev); =20 /* * Add the device to our list of discovered devices --=20 2.53.0 From nobody Tue Jun 16 19:33:07 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 293A73B19A6 for ; Wed, 29 Apr 2026 17:51:25 +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=1777485088; cv=none; b=Q/rOhwvrOuD0laN+SolAegI28hMtJ3CmxjER1c+1IwvMWQHNuJGvsqfUC+vu5ukyhK2u9B/81DZpwpTubZ9Wcmla31wsQjwGhBH+hqHtICh6pS9iIaNuHvGmgmRGv/Xb1s1P/dTWkX717wAuzF2VAFzIWvs5E/AOClO5FzfM4DY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777485088; c=relaxed/simple; bh=Nc5Cr28OkE2x5OT1A09Y8jID2eQr5wsfn890+tcJ1zE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LI4Q6AD/FTSh0pr1UKFfNrlHya1M/aK/XUJ3q1F78YAwIdwXAB1u6POGp6epGLnhGvKWGn+CpeBzihTo/7UxxOcU0Ep1y9ikAAHPk9+n3Lk/Bt6HvEBYmBVLdmRp8spUQd3ZtpANHlhLZsFyREoe300e9kHhsDD1B7bAxJ63jZc= 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=hYAIyRau; 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="hYAIyRau" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777485084; 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=EBdaR0NkwnB5xuO+5ZF2TJ2EyUG8XWEvOxuQoPiLdNw=; b=hYAIyRauMzVBOrkBU1MnKMpWgxplNlqlN4elGzLoj69OBVDEoqrAcr5cOgseV1NkIPUrkK 3aosDO6xAhN4QT/9ScMapqhq1hYau9xgWpR26vOt+JFv00Tu3CiQ+SmtBXmli/yyof8DcZ MBZaOBpNBp4Y0hiDdE1pzXvNcvQa0QA= 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-581-dm3F43fDMaia9pQhJ4kSRw-1; Wed, 29 Apr 2026 13:51:20 -0400 X-MC-Unique: dm3F43fDMaia9pQhJ4kSRw-1 X-Mimecast-MFC-AGG-ID: dm3F43fDMaia9pQhJ4kSRw_1777485077 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 8D33F19560BB; Wed, 29 Apr 2026 17:51:17 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1AB0D300019F; Wed, 29 Apr 2026 17:51:11 +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: Wed, 29 Apr 2026 13:50:16 -0400 Message-ID: <20260429175016.7915-6-djeffery@redhat.com> In-Reply-To: <20260429175016.7915-1-djeffery@redhat.com> References: <20260429175016.7915-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.4 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 Tested-by: Tarun Sahu --- 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..471b5ce878b0 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); + device_enable_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); + device_enable_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..5946ed77b3bd 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); + device_enable_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); + device_enable_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); + device_enable_async_shutdown(&sdev->sdev_dev); error =3D device_add(&sdev->sdev_dev); if (error) { sdev_printk(KERN_INFO, sdev, --=20 2.53.0