From nobody Tue Apr 7 20:07:30 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 52E6C3C198E for ; Tue, 7 Apr 2026 15:35:58 +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=1775576166; cv=none; b=nA55SF7+BVCMM8ECmudPV9+whorYDNfqO/m5GdRgkUZpSKgB3KjriMT1yF+Ce4sBzyXlnWwoUufF4SST3/umHOU0ex/DJS5FEJ4MBnLlmtmyDCVa8ILrSttzuB4LrTTPMHyvGQw93OfZ714BVWUaLLjhX66kVpg1MQjju31Pk1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775576166; c=relaxed/simple; bh=kRoqidn76LBXY2IXlFmqDdg3U/w/Upj+ZPVt/XMwYUg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q+M/Oua0CW2ekIGMQo859H6yx0I8SyRi8t+0Y/u4VSfEYV0WnTwwjf0CHG+ugSzpZZkieD06qCSQFkNcCLnHjLaSRabWLMxpF72RlSk9mxXqEtJqRgk2BMC6t4dwGglB4Uo4XPUgG+dg2sQU+41aV88ohE5xlvKL6gNCMVVsClc= 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=SHbjIXYS; 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="SHbjIXYS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775576156; 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=aXZu/sWmQ1CtFuGs5ckBkayr+c3ycVzXDHhFa+FzP/o=; b=SHbjIXYSN1kFZcNhFiUBnSfnUCoFP7R6/A0B9I51XxwqjqhfZWqbdyrepkcAJYzOoxbybx mJ8W6ma7YEoCajhNi+fKxR504eKqcoNYM+OayI8smr/vCMNNBUBEE963930n34WgTLHF0S yK+0X4QGPwqxy7c7OVSCbrERdDHlG1w= 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-288-gUGnNqi7Pbqoayj7nTeu-w-1; Tue, 07 Apr 2026 11:35:53 -0400 X-MC-Unique: gUGnNqi7Pbqoayj7nTeu-w-1 X-Mimecast-MFC-AGG-ID: gUGnNqi7Pbqoayj7nTeu-w_1775576151 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 81D6919560AE; Tue, 7 Apr 2026 15:35:51 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.127]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 64117180035F; Tue, 7 Apr 2026 15:35: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" , David Jeffery Subject: [PATCH 1/5] driver core: separate function to shutdown one device Date: Tue, 7 Apr 2026 11:35:28 -0400 Message-ID: <20260407153532.6395-2-djeffery@redhat.com> In-Reply-To: <20260407153532.6395-1-djeffery@redhat.com> References: <20260407153532.6395-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.111 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 --- 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 09b98f02f559..fabd17be1175 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4784,12 +4784,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(); @@ -4811,7 +4847,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 @@ -4820,36 +4856,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 Apr 7 20:07:30 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 6EA8A371069 for ; Tue, 7 Apr 2026 15:36:05 +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=1775576172; cv=none; b=NaBrYBQ4tTx3+vOpDWy7QIt9e3vI8qPvdU4Vd+0i4Q6qa38o4qThnN5u2ZMPnb8P0p2w9lCd5Hzg4g9/P1cpxBPk4PpRkOFJiTXdQJ3dd9VE1oax8WhN4UuxPA4yxLpHUHxbBRQZzCVA7DwdyXW98GKK09RvuGC2vzAMSacZ3WA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775576172; c=relaxed/simple; bh=LwF4g3GgiBopq5VLyCEXnqlJVDeMdGzjLGWlnJ5pbBY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fACxzFV8wCt6l5uTuDwH6Fotad7nhMd/14ekFTfF06nEbjCCvFRBb2qQWQ3dgp7riEkYtOZ7RoaRaQ50/Hdfe52Ksgra5gFNSZu5+Lr01d2QP+77CxSsr3FJSg5XZtyEzf6lNceSzb6A6+0sMu1O7dpovvQ1GFhTmTQrHHgEJA4= 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=IZAfxBYg; 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="IZAfxBYg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775576162; 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=Xf8VBa3s5TDbzdGc7YU+V5MBvNbOIU1Be5qZpIougPY=; b=IZAfxBYgMuWZWvRB0atHAwjpvBrF0FB5PeFbKPzEEDMB5JmBbPyA5w3Vn4etUj6p9BEl3t MtO4QKe2soS1GxuUnyj09YydRtQfiGVP0n/kcDp9K2n+RNlgEuILSGOnz3LzZ71eRMqJCN lXS4Hf08aHP7OJZQ9lpGwfjQZ3xpJ00= 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-516-EltgH6WzOTqdn50Q92ivvQ-1; Tue, 07 Apr 2026 11:36:00 -0400 X-MC-Unique: EltgH6WzOTqdn50Q92ivvQ-1 X-Mimecast-MFC-AGG-ID: EltgH6WzOTqdn50Q92ivvQ_1775576158 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 1275418005BA; Tue, 7 Apr 2026 15:35:57 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.127]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DCD97180035F; Tue, 7 Apr 2026 15:35:51 +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" , David Jeffery Subject: [PATCH 2/5] driver core: do not always lock parent in shutdown Date: Tue, 7 Apr 2026 11:35:29 -0400 Message-ID: <20260407153532.6395-3-djeffery@redhat.com> In-Reply-To: <20260407153532.6395-1-djeffery@redhat.com> References: <20260407153532.6395-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.111 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 --- 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 fabd17be1175..0fb2f3ccc3bd 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4784,13 +4784,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 */ @@ -4813,10 +4808,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 @@ -4842,12 +4850,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 Apr 7 20:07:30 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 0F9CD3C4567 for ; Tue, 7 Apr 2026 15:36:12 +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=1775576179; cv=none; b=L/SXvZ9D0MgKWavDhLWi32d0ChNPCAM5PgDXwwVwh+CWBYX3Ce62i/GsafkTZox5LFjnwEy4V4U7raGansCOQCm0O9Ehlbju0Na+sIdgsF3uV79nQ2YvLbwtHfV+vYcT8GmScV+ZqxGIitQMj1IU2Ksqyxqsy0PJmwbVdoXm+O0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775576179; c=relaxed/simple; bh=mpd6Cy76MjC+38ye2jj7ei/MJhynExxQIydz6BHpHEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=acjjm5Yqq2laI08vmJ32bWZroWmxDQEajj9hrys2i7uDf/z7WAsvyLJ7R2TB1bTr2tgQTDYeVS4puDI3jcXSnbxT4sjuSyGmpFDkelhWNb9HzW6BwI27Gwk+e++JO73QJKgPaJqEUOOntjOCUkH1OmmVCbQoKeVrEdg7P6EPN48= 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=dDQUOx3d; 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="dDQUOx3d" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775576169; 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=lIi8MnLsK9rqgcVhPGK6L1pnrqyxpZ0hlITssQNvVPg=; b=dDQUOx3dUTnqhAHozyG9NzGtWGMd8TZoSU+Vxs/Raf/lzP1aDR5Olr+qsnJf6NU0F8UDpG +VWf+TMuhzpGLa255ufSIJaGbrmjCC4C1xEN4oHerUMqiLUYB3gQu66AFyOLBdHnwlnO9/ bJMcYPHrKspf/itHOepjnhzq/NEw9Bk= 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-495-QptULq8QP4OWFSmD-GZQIA-1; Tue, 07 Apr 2026 11:36:04 -0400 X-MC-Unique: QptULq8QP4OWFSmD-GZQIA-1 X-Mimecast-MFC-AGG-ID: QptULq8QP4OWFSmD-GZQIA_1775576162 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 D493A18002E3; Tue, 7 Apr 2026 15:36:01 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.127]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 69DD61800576; Tue, 7 Apr 2026 15:35:57 +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" , David Jeffery Subject: [PATCH 3/5] driver core: async device shutdown infrastructure Date: Tue, 7 Apr 2026 11:35:30 -0400 Message-ID: <20260407153532.6395-4-djeffery@redhat.com> In-Reply-To: <20260407153532.6395-1-djeffery@redhat.com> References: <20260407153532.6395-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.111 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 --- drivers/base/base.h | 2 + drivers/base/core.c | 101 ++++++++++++++++++++++++++++++++++++++++- include/linux/device.h | 13 ++++++ 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 1af95ac68b77..cd435adeeac5 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -113,6 +113,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. @@ -132,6 +133,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 0fb2f3ccc3bd..89b482435e85 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 @@ -4784,6 +4790,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); @@ -4807,6 +4844,8 @@ static void __shutdown_one_device(struct device *dev) dev->driver->shutdown(dev); } =20 + complete_all(&dev->p->complete); + device_unlock(dev); } =20 @@ -4828,6 +4867,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. */ @@ -4840,6 +4928,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. @@ -4858,11 +4952,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 e65d564f01cd..cdc890e5d6ae 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -553,6 +553,8 @@ struct device_physical_location { * @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 * * At the lowest level, every device in a Linux system is represented by an * instance of struct device. The device structure contains the information @@ -675,6 +677,7 @@ struct device { #ifdef CONFIG_IOMMU_DMA bool dma_iommu:1; #endif + bool async_shutdown:1; }; =20 /** @@ -878,6 +881,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 Apr 7 20:07:30 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 BD0F53C1979 for ; Tue, 7 Apr 2026 15:36:16 +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=1775576185; cv=none; b=N4VwFSuGZcSqd9bttUz+959CwiTRHO2Tp1meJ4pM3TkKK7O34F/XVTJISgQIgMqG9R7wZQcSuwTuADs6pge9oJgxRJ0W/TaeodVr+iC9oqqNv2hvqRH2zUIupfjW6t7h1up9pKsdyvK1+dpkYOMUKzNXEDpYhSojvsajoGNllSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775576185; c=relaxed/simple; bh=4vvr+xDrAWxMxjnNh4nkvtXpBMA19u1S8MdxP1fEm4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XMJVJDQj1jI/KCdiQ6/kzOrRaPYOzFA3aldmSO6P9wF909+1SH+Fei5T+9gRDq3R4xXB5vj4/qPYAqsOuyw7CkS+NlGJRP02slpzv4SNTtgB1iKG/+NW7iiUA4D5r6Q3399/pAVrE4wNSabhni2uvVo4MtHg47dd+/pK65J99nk= 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=GOtDmQPZ; 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="GOtDmQPZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775576171; 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=jQvaSb3MuBGeMbb7vK8Mg571zM++WUT9vxPRh2XvaDA=; b=GOtDmQPZMaCwTO4NF7kJikuPLBWq2P5pu/2gZhto+hmt3mqOErV22licFHYSP3Wn1aFCxn X1yV5IVuGeDPME4tL+kxErT7TWxsjQj7kMikfjzlQe16GdJARfdqDrUgT+YZqArOlEVIRE MbSvxV+HCbj7A6T69Ue06IcINZOOfIA= 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-399-6dRSMBbgMj25xFQfNtrPEA-1; Tue, 07 Apr 2026 11:36:08 -0400 X-MC-Unique: 6dRSMBbgMj25xFQfNtrPEA-1 X-Mimecast-MFC-AGG-ID: 6dRSMBbgMj25xFQfNtrPEA_1775576166 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 59E7818005B6; Tue, 7 Apr 2026 15:36:06 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.127]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2F51E180035F; Tue, 7 Apr 2026 15:36:02 +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" , David Jeffery Subject: [PATCH 4/5] PCI: Enable async shutdown support Date: Tue, 7 Apr 2026 11:35:31 -0400 Message-ID: <20260407153532.6395-5-djeffery@redhat.com> In-Reply-To: <20260407153532.6395-1-djeffery@redhat.com> References: <20260407153532.6395-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.111 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 --- drivers/pci/probe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index bccc7a4bdd79..4d98bab2163d 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1040,6 +1040,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) && @@ -2749,6 +2750,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 Apr 7 20:07:30 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 9E9003C3BF8 for ; Tue, 7 Apr 2026 15:36:20 +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=1775576189; cv=none; b=CEeLALs3EhfVPh4vO5WGhg9W0LdkQshZBJcAaFt3fVpq55hyNmCKKlcilEoQ0Ukwo+Gcs1DePHMhAvUn2f1hC/Cbm01mYNKx7bDIeqAp9GTUbOF2/4ZBZvAIIhtUUmlVnzCnPO5XB+tYseu5Rx/XUylQZPuxTJ4Ap4n7nSZRqyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775576189; c=relaxed/simple; bh=hX445ynibnXiIWMEjocw1AVTzkgY1FNORC7rREkeDJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dlGRW7cd5jRNpEwLLx2wqaonw65LbC34YYGkGG/4dgolNhch752dHvHEjnjrsdFnUaB+Ek8UOJJ4k3Xaj2oCBz+EtacGGSnjAJLjNIRoTyI4DdD/V1+AYAnvnI/usp6SAwmEeG+QFdPce1MWP3xqJDHGzCAPKjkPRuvI/GFg7pE= 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=L3p8hNcD; 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="L3p8hNcD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775576176; 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=BQUsDl+61brgBW+bmtwfnTQiS3JcRbzE4Uc2abCpuBs=; b=L3p8hNcDjunEEeyhkIHm8WyBL+mBHp2d2gOgdVC+gAJo+f2hVbwyL0dhaIsft315wxUpVG VLS7ieRqq5XPJ04zF/9CsUtzXv/MlLagVlV8MVPR/kK2tKNwgtwYoFLG+AQZB8eUg2LpSW S+Wjb81alMllKorWGww2aFXU27A169E= 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-542-i3a9Ot2dP1qh06s5bqKUUw-1; Tue, 07 Apr 2026 11:36:13 -0400 X-MC-Unique: i3a9Ot2dP1qh06s5bqKUUw-1 X-Mimecast-MFC-AGG-ID: i3a9Ot2dP1qh06s5bqKUUw_1775576171 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 EDCEE195608C; Tue, 7 Apr 2026 15:36:10 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.127]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D1C3D1800594; Tue, 7 Apr 2026 15:36: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" , David Jeffery Subject: [PATCH 5/5] scsi: enable async shutdown support Date: Tue, 7 Apr 2026 11:35:32 -0400 Message-ID: <20260407153532.6395-6-djeffery@redhat.com> In-Reply-To: <20260407153532.6395-1-djeffery@redhat.com> References: <20260407153532.6395-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.111 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 --- drivers/scsi/hosts.c | 3 +++ drivers/scsi/scsi_scan.c | 1 + drivers/scsi/scsi_sysfs.c | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index e047747d4ecf..dfb38a82c0bf 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); @@ -519,6 +521,7 @@ struct Scsi_Host *scsi_host_alloc(const struct scsi_hos= t_template *sht, int priv shost->shost_gendev.bus =3D &scsi_bus_type; shost->shost_gendev.type =3D &scsi_host_type; scsi_enable_async_suspend(&shost->shost_gendev); + device_enable_async_shutdown(&shost->shost_gendev); =20 device_initialize(&shost->shost_dev); shost->shost_dev.parent =3D &shost->shost_gendev; diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 7b11bc7de0e3..72f30db8609a 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -515,6 +515,7 @@ static struct scsi_target *scsi_alloc_target(struct dev= ice *parent, dev->bus =3D &scsi_bus_type; dev->type =3D &scsi_target_type; scsi_enable_async_suspend(dev); + device_enable_async_shutdown(dev); starget->id =3D id; starget->channel =3D channel; starget->can_queue =3D 0; diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 6b8c5c05f294..c76ba17b206f 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1370,6 +1370,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; } @@ -1396,6 +1397,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) @@ -1415,6 +1417,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, @@ -1670,6 +1673,7 @@ void scsi_sysfs_device_initialize(struct scsi_device = *sdev) sdev->sdev_gendev.bus =3D &scsi_bus_type; sdev->sdev_gendev.type =3D &scsi_dev_type; scsi_enable_async_suspend(&sdev->sdev_gendev); + device_enable_async_shutdown(&sdev->sdev_gendev); dev_set_name(&sdev->sdev_gendev, "%d:%d:%d:%llu", sdev->host->host_no, sdev->channel, sdev->id, sdev->lun); sdev->sdev_gendev.groups =3D hostt->sdev_groups; --=20 2.53.0