From nobody Fri Sep 25 01:20:27 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 31A0B4F5DE1 for ; Thu, 17 Sep 2026 16:38:07 +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=1789663088; cv=none; b=Ju0jK03JLsZxWcI8b3k/7mQjhyCsYmhMLH4E8vSbLAbuRcxLgSueI5FCGAAQBfGfgnoLpsICgca8VO/+brhU1B4n+jFMUUBeMruyN5sCbrWt0GEvIWVT7cVq3gtpf2ezmCNTZs0rmgIB4Lwf77tw1A9PJnjWqgVWFsdcOqhhQFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663088; c=relaxed/simple; bh=CvVkhhBXZG0ZDrJsnmBXLSGYgGyIZi2GM0825+aHLdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qArVY5lM3XViTasoaNs1ZvhKwmGzvo1OPoxE5J4IZJMkzVaihpPtHFOXl2DNwvNzy+7F0Z0S5JrygkrC/iPjzNCPcMX389ouSUpUWxhlaFcqmmHRaJLvwNvIH5tM2F0d9MLPt7F6846UWitJmv5GbMTrlxUppyS49aon+GIKNF4= 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=Rmpjcppn; 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="Rmpjcppn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663086; 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=S4w5b49VFjE4E0AFoA0Qcj7jylDcxSilk3hvFC5nqKA=; b=RmpjcppnVLH3j9FcHtxu5IYYZh1zGH/YRjIlg3Ip1A736b+/yRbXHliJItTFvNZuBm2l9S Kq9hG+zvFn3x3Q1/264ydeFHZO6+fzBrP5WjV/7Y6jrCr2a6xTuIYTqX18LfQsZwei8sWT M6o1n422YPH6izmMSmBqGb+4k8ZMc9U= 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-561-bOGKzHNkPFmH3dTNlkqmpQ-1; Thu, 17 Sep 2026 12:38:00 -0400 X-MC-Unique: bOGKzHNkPFmH3dTNlkqmpQ-1 X-Mimecast-MFC-AGG-ID: bOGKzHNkPFmH3dTNlkqmpQ_1789663078 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 4C6221806D31; Thu, 17 Sep 2026 16:37:58 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1189A180035F; Thu, 17 Sep 2026 16:37:53 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery Subject: [PATCH 1/9] driver core: rely on put_device to free dev->p Date: Thu, 17 Sep 2026 12:37:36 -0400 Message-ID: <20260917163744.191748-2-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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" From: Tarun Sahu device_add allocate private_data for device and assigns to dev->p. If device_add fails in later steps of the function, it cleans up this dev->p which is not necessary because In the next call, put_device free it anyway (if reference to the device is 0 which will be unless someone concurrently get the reference to this device). This avoids unnecessary races introduced in system. After device is added in device_kset->list by device_add and later steps in the device_add function failures occur, it will free dev->p manually, while in between there might be a user of device_kset->list will take reference to the device just added by device_add. and might try to access dev->p. So relying on put_device to free dev->p prevents such problem. Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery Tested-by: Laurence Oberman --- drivers/base/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 4c0c373998a1..83263e3fa5d4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2618,6 +2618,7 @@ static void device_release(struct kobject *kobj) struct device *dev =3D kobj_to_dev(kobj); struct device_private *p =3D dev->p; =20 + dev->p =3D NULL; /* * Some platform devices are driven without driver attached * and managed resources may have been acquired. Make sure @@ -3828,8 +3829,6 @@ int device_add(struct device *dev) parent_error: put_device(parent); name_error: - kfree(dev->p); - dev->p =3D NULL; goto done; } EXPORT_SYMBOL_GPL(device_add); --=20 2.55.0 From nobody Fri Sep 25 01:20:27 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 055084E4338 for ; Thu, 17 Sep 2026 16:38:11 +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=1789663093; cv=none; b=lhv31Xbcm+vRwuOHIcBhI4F1kFX35jZ2Q/B9b8QHsDGnU7QTLjaEBHVndNdUODchJR5E9/kBFvamzV+u+8CYPivVC/dNOvT8RGUhz+VU6nKxsAxbVaGqwKkBr2bIxjVQt2j4030ew6nxm8QCJT6ZyKasggYGU8VIEvASoTmzfXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663093; c=relaxed/simple; bh=IWHexqUg6916nspV1VRDVgr5pFAZ+u0l6fG7BM3sYa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Me+pFUTBmwOQaD6Jy/gZqrX/NtIt5bx/G5kjEfICQwJkS8mEcQQbpBufnpVKPncC6b8la73/2DOXLjqedQaPybyBXxjTTJksvGt7LBcnjOPbb4dLz0x43D6W59cOefIe8vce/w2HKNuBuEQVAg4YBbE1+lni9fyMPtoct9l2BtI= 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=OVIb0DrD; 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="OVIb0DrD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663090; 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=FxOEy23CdjWO+tWUfg0nkvoqJt9R/kFtS/CvH38ECoU=; b=OVIb0DrDZGiwxWkougyhfz1P2srnOcFZsqz8qpQOh0OgO+Iens+T+i5qnkkNayxXdNr+Tj tBEONv0khAVSsVASf2zMfPg9FvjfBQ1wGdRRfS+4x5/KEsnccpq3lpY6pzc/JXHLScgE4l W/FNlocBCSQI9ZSZKoITivusVBth7os= 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-342--4PG5_tROealErGyQ7B0Pg-1; Thu, 17 Sep 2026 12:38:05 -0400 X-MC-Unique: -4PG5_tROealErGyQ7B0Pg-1 X-Mimecast-MFC-AGG-ID: -4PG5_tROealErGyQ7B0Pg_1789663083 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 6435618C1072; Thu, 17 Sep 2026 16:38:02 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A18211800361; Thu, 17 Sep 2026 16:37:58 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery Subject: [PATCH 2/9] driver core: prevent device_add() during system shutdown Date: Thu, 17 Sep 2026 12:37:37 -0400 Message-ID: <20260917163744.191748-3-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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" From: Tarun Sahu In Async device shutdown, device_kset->list lock is released to handle asynchronisation and hold again to get entry from device_kset->list. Which will leave window when device_add can try to add the device to device_kset list and temper with ongoing shutdown process. New added device can be async type or sync type and might also introduce new dependency which can cause device_shutdown path to deadlock. S is waiting C to finish but C is never scheduled as it was added recently from device_add path. And C can only be scheduled when main loops continue to reach to C which is waiting on S. So, When a system enters shutdown (SYSTEM_HALT, SYSTEM_POWER_OFF, or SYSTEM_RESTART), new devices should not be allowed to be added. Adding system_state check (system_is_shutting_down()) to avoid device_add incase of these states of the system. And use srcu so the device shutdown operation can synchronize device_add and ensure any device_add in progress is finished. Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery Tested-by: Laurence Oberman --- drivers/base/core.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 83263e3fa5d4..bce555dd74f6 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -47,6 +47,22 @@ static bool fw_devlink_drv_reg_done; static bool fw_devlink_best_effort; static struct workqueue_struct *device_link_wq; =20 +/** + * system_is_shutting_down - Check if system state is not active. + * + * When system state is not active and in shutdown state, new devices + * should not be allowed to be added. + * + * If system_state is SYSTEM_HALT || SYSTEM_POWER_OFF || SYSTEM_RESTART + * this function will return true. + */ +static inline bool system_is_shutting_down(void) +{ + return system_state =3D=3D SYSTEM_HALT || + system_state =3D=3D SYSTEM_POWER_OFF || + system_state =3D=3D SYSTEM_RESTART; +} + /** * __fwnode_link_add - Create a link between two fwnode_handles. * @con: Consumer end of the link. @@ -3614,6 +3630,9 @@ static int device_private_init(struct device *dev) return 0; } =20 + +DEFINE_STATIC_SRCU(device_add_srcu); + /** * device_add - add device to device hierarchy. * @dev: device. @@ -3647,13 +3666,20 @@ int device_add(struct device *dev) struct device *parent; struct kobject *kobj; struct class_interface *class_intf; - int error =3D -EINVAL; + int idx, error =3D -EINVAL; struct kobject *glue_dir =3D NULL; =20 + idx =3D srcu_read_lock(&device_add_srcu); + dev =3D get_device(dev); if (!dev) goto done; =20 + if (unlikely(system_is_shutting_down())) { + error =3D -ESHUTDOWN; + goto done; + } + if (!dev->p) { error =3D device_private_init(dev); if (error) @@ -3803,6 +3829,7 @@ int device_add(struct device *dev) } done: put_device(dev); + srcu_read_unlock(&device_add_srcu, idx); return error; SysEntryError: if (MAJOR(dev->devt)) @@ -4877,6 +4904,7 @@ void device_shutdown(void) =20 wait_for_device_probe(); device_block_probing(); + synchronize_srcu(&device_add_srcu); =20 cpufreq_suspend(); =20 --=20 2.55.0 From nobody Fri Sep 25 01:20:27 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 51D00515961 for ; Thu, 17 Sep 2026 16:38:13 +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=1789663095; cv=none; b=JNSpHSfZroZk2zXH8B9QWsMglXzRDZIzKQMKVP+zwKnCWhAtf6YNCiqBZ3Nmial/lTD2UGQ8LKWpk6dI+OWJhrcwFbBBLiHfl02kBjOljFzHbNMv2OPIDH2/03ybFRrLlZEr9ZWk2972snKa2HRidE8U2sFA4EC/8DC9FA1e+OM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663095; c=relaxed/simple; bh=JNrK/0ub6m0FDk0x2dT/rnm7U5smWJV1A0KGzkCWXGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CwA1fonbZThn/lN1lSLqAllGqnywHKuY9C+DMAUfOgfEYnulCFoKFpzA+JZaz+6Ki1w4XHuQp6hQYC3jfhho9Wkwwk/yUWVlPPYoXe806soYm//TuoYXRDB9/5Gfw6sV9kkwdY6SxETtQqZvkbpxxu+oAG3AAQwCzlMwaPa0Fms= 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=MvscYrmQ; 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="MvscYrmQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663092; 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=OLtaBWF2S8xYQupQu7qrCH159MdeXfdQdbvdeZt1vZM=; b=MvscYrmQcB/Z3hbZ41tOrodk/CCJdpTT6NPByJ94dGaqrHyKL8h2WLJqMVLFJwN61ZnZiX 3qMoVbKE4tV42x3bqOi3g+lOYqREp59PFRI59+6sVUn1tG1aLl9ryMocBxBUn/wRyOVdl5 Er8WFqE6Hbiv7Kjylbnn4TLByE0Dey4= 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-17-vRZGW6qeMHCQ833EE_bFRw-1; Thu, 17 Sep 2026 12:38:08 -0400 X-MC-Unique: vRZGW6qeMHCQ833EE_bFRw-1 X-Mimecast-MFC-AGG-ID: vRZGW6qeMHCQ833EE_bFRw_1789663086 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 53D55183019C; Thu, 17 Sep 2026 16:38:06 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A66F41800345; Thu, 17 Sep 2026 16:38:02 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery Subject: [PATCH 3/9] driver core: warn should device_move try to move a need_parent_lock device Date: Thu, 17 Sep 2026 12:37:38 -0400 Message-ID: <20260917163744.191748-4-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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" Currently, no device has need_parent_lock set and is moved by device_move. need_parent_lock is only set by the usb bus and very few device types ever use device_move. Add a warning to device_move to catch should it ever be used on a device with need_parent_lock set. The combination would break the immutable relationship needed between parent and child for need_parent_lock when locking and unlocking both. Suggested-by: Tarun Sahu Signed-off-by: David Jeffery Tested-by: Laurence Oberman --- drivers/base/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index bce555dd74f6..e8a62c8f0ad3 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4705,6 +4705,14 @@ int device_move(struct device *dev, struct device *n= ew_parent, if (!dev) return -EINVAL; =20 + /* + * device_move() should not be used on devices with need_parent_lock + * set. Concurrent reparenting will violate the immutable + * relationship needed while locking and unlocking both parent and + * child. + */ + WARN_ON(dev->bus && dev->bus->need_parent_lock); + device_pm_lock(); new_parent =3D get_device(new_parent); new_parent_kobj =3D get_device_parent(dev, new_parent); --=20 2.55.0 From nobody Fri Sep 25 01:20:27 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 5CD304EDCCA for ; Thu, 17 Sep 2026 16:38: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=1789663099; cv=none; b=BoALVogzj1iyhneEUS2UNRiw/PCZxFtnCVAKp4R2Ur9NaGm7KGM16hxzGM9p9nA5O4uVAsLRxqZYLzeRLyMouvqqgUY125Mgijuj5pfCggEWQC7c7FGpot+epElHNqU4oFbtvPWXQ1KA7SdB1IDHVwZ0oopPKFhgEqudwujHhSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663099; c=relaxed/simple; bh=EP0KuVg6dnAsKqEThnw3EV3YBp7Sy2fuZ57mmoXdlhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YocxNSh62CXN1joNrzfR6Pw6yNQyhX3nOoHY/as3vgXHaZEf85boMX6A7hIzXVgonAjHMrG8WqgynFYCQ2Ng83QaxuAKfuO72SrSFT+D73mQIEyULDL/hawNxiKffXgcaYzBO7WRACmYHgc4GGZX7vTYqf9e78qlMy0BbDXaau4= 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=aM6p91zW; 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="aM6p91zW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663095; 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=7SXPhK4KAKzT6yjy3hN3OczRFZykeYYqxRn6w8LmMcQ=; b=aM6p91zW3fmp0oo42bR4uxbucHwUNEb5RZKKdoAms5w5N6QfZctkGLv/eCeFvu5S8cqbk7 VUeINmcwpPnvRJ8U4a2nkLmpAaaxkqwckLVuc+LsDq4NctYyDB/9as44WFvIsIny+b+Enq +NHuuwi0BoyxfZbqUGR9QlfSiSicZvM= 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-617-fGJVoa_JOW66ztstGARIHA-1; Thu, 17 Sep 2026 12:38:12 -0400 X-MC-Unique: fGJVoa_JOW66ztstGARIHA-1 X-Mimecast-MFC-AGG-ID: fGJVoa_JOW66ztstGARIHA_1789663090 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 188DE1828B22; Thu, 17 Sep 2026 16:38:10 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A17DF1800345; Thu, 17 Sep 2026 16:38:06 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery , Pasha Tatashin Subject: [PATCH 4/9] driver core: separate function to shutdown one device Date: Thu, 17 Sep 2026 12:37:39 -0400 Message-ID: <20260917163744.191748-5-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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 Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin --- drivers/base/core.c | 65 ++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index e8a62c8f0ad3..7fe3fa6870a7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4903,6 +4903,40 @@ 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, struct device *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(dev); + put_device(parent); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ @@ -4940,36 +4974,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, parent); =20 spin_lock(&devices_kset->list_lock); } --=20 2.55.0 From nobody Fri Sep 25 01:20:27 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 3E8C25304DD for ; Thu, 17 Sep 2026 16:38: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=1789663102; cv=none; b=qvzMErbbuirvWlyxgRzqV93chs5HxZcwg8+uSuE/efIzqA7Dzu9AJmkl84w9KVv2oUJM+Rdwj/KD5MGwMKEbheDc8esF6NKnD37Xqy3jMcyUVOSB9AmBiCTsjEzBFzpe4GpZ4DKd2c5TA3Q3fxiTTgnpLtTziSh4aYAELL4P814= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663102; c=relaxed/simple; bh=Woa6N9v+SMe+iqq4nIasCho+fXRyxC/tVADO5/OfTKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hSAEChc6AwNEpSAZ5/wDmMgVdIHUP+RvnQHa1S/zUoVjMOIF8WYJltkmbUgeh0CPlFCND7z6yESZvg2aWSe/rccHGEmOqsZtAvNzUavQ0+eAZ6nQIiKd5/muNv29x3W+9iPaMFKCuwn6uRWtMS1QH054lLQCY9i4mneaoMIeyv8= 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=clmhPv/6; 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="clmhPv/6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663099; 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=bxjP7KUlohvZ2YPEyHIa7bKbPs42+xcSHkWZNTuvybw=; b=clmhPv/6l4tYFXmjjZoqfRSFlEVATGV33ejSi13Myr9S2fFLhXym/L0YoboWYEmTmHgIgW G501QCxfRJU7nNwFi+JqBDAs5s2bvcIkWOhXeJlqPP0pOCWxWGFYsY8FmEb5o/AWl7iP5V 0suZfADtI9544dpuAW9ENa9ScfMYaZs= 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-33-d1egqnKpMDii9sPsfNsXyQ-1; Thu, 17 Sep 2026 12:38:15 -0400 X-MC-Unique: d1egqnKpMDii9sPsfNsXyQ-1 X-Mimecast-MFC-AGG-ID: d1egqnKpMDii9sPsfNsXyQ_1789663093 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 746FB1955BE7; Thu, 17 Sep 2026 16:38:13 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5704C1800345; Thu, 17 Sep 2026 16:38:10 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery Subject: [PATCH 5/9] driver core: do not always lock parent in shutdown Date: Thu, 17 Sep 2026 12:37:40 -0400 Message-ID: <20260917163744.191748-6-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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 Signed-off-by: Tarun Sahu Tested-by: Laurence Oberman --- drivers/base/core.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 7fe3fa6870a7..93605698affc 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4903,12 +4903,10 @@ 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) +static void __shutdown_one_device(struct device *dev) { - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); + if (!dev->p || dev->p->dead) + return; =20 /* Don't allow any more runtime suspends */ pm_runtime_get_noresume(dev); @@ -4928,13 +4926,33 @@ static void shutdown_one_device(struct device *dev,= struct device *parent) dev_info(dev, "shutdown\n"); dev->driver->shutdown(dev); } +} =20 - device_unlock(dev); - if (parent) +static void shutdown_one_device(struct device *dev) +{ + struct device *parent; + + device_lock(dev); + + /* use parent lock if needed to avoid race with probe/release */ + if (dev->p && !dev->p->dead && dev->bus && dev->bus->need_parent_lock && + (parent =3D get_device(dev->parent))) { + /* the parent lock needs to be acquired first, so re-lock */ + device_unlock(dev); + + device_lock(parent); + device_lock(dev); + + __shutdown_one_device(dev); + device_unlock(dev); device_unlock(parent); + put_device(parent); + } else { + __shutdown_one_device(dev); + device_unlock(dev); + } =20 put_device(dev); - put_device(parent); } =20 /** @@ -4942,7 +4960,7 @@ static void shutdown_one_device(struct device *dev, s= truct device *parent) */ void device_shutdown(void) { - struct device *dev, *parent; + struct device *dev; =20 wait_for_device_probe(); device_block_probing(); @@ -4960,12 +4978,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 - */ - parent =3D get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the @@ -4974,7 +4986,7 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); =20 - shutdown_one_device(dev, parent); + shutdown_one_device(dev); =20 spin_lock(&devices_kset->list_lock); } --=20 2.55.0 From nobody Fri Sep 25 01:20:27 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 E610C4E77EC for ; Thu, 17 Sep 2026 16:38:24 +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=1789663106; cv=none; b=AwrXYKaZPli8Xx1S85BfNJsQkVZYql6469oq4iIsHnn+d0L9orhYR0bBWXZNV0AXK29rkPg5U7nAGZxGDsqeBwSd5mytjHqkIokcUxH7rmK/wJzju3tD17TEFmLO3in6ncyGOLsqRZZVFaOSg5p07M7peuGIxbPHEw53MEvzxuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663106; c=relaxed/simple; bh=kgZrPmx/NyFTZxQkq//uth9TK84g9fa8u7sjNfnFGag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GJpbin8wAovrH9qTrRwL+yeDw1uryldwWNGPoDXFym6y7y7+4YybYfjDkctsg2QjV6YnaJ0fTZxk/WqUFq41R2SKQJVyd6KMCYWxMoVvG8nmDYcxLCaTUdtiCj7tIszjKRzr1vnhDVmf/60WcEHGfLYFIB74GxJfpfUTVvmR10o= 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=KWj4EN1Q; 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="KWj4EN1Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663103; 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=65taMl2yTlmMjt0Af/cEbsAbd3mCjNHU7Qdvsgj6qag=; b=KWj4EN1Qt8qjU/rn8J8dJlYuplswP+fbhPYTdVs7tWT1CUyoS/qb2vzsEe8ECoYovi+RTx 9gOCrwokiwZtvgwIQlbw3c3a+D9UbEmsvXyAXA3Ln9StiokpNX+7PNrl2bSQkzJ3Pru36s aYs8gEv/T2DtbvsltrmhhsTR+AiyQpU= 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-170-fy8tx8a2PPu998dE2LH1tw-1; Thu, 17 Sep 2026 12:38:19 -0400 X-MC-Unique: fy8tx8a2PPu998dE2LH1tw-1 X-Mimecast-MFC-AGG-ID: fy8tx8a2PPu998dE2LH1tw_1789663097 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 4071A180B5F6; Thu, 17 Sep 2026 16:38:17 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B7C161800352; Thu, 17 Sep 2026 16:38:13 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery Subject: [PATCH 6/9] driver core: async device shutdown infrastructure Date: Thu, 17 Sep 2026 12:37:41 -0400 Message-ID: <20260917163744.191748-7-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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. 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 Signed-off-by: Tarun Sahu Tested-by: Laurence Oberman --- .../admin-guide/kernel-parameters.txt | 10 ++ drivers/base/base.h | 2 + drivers/base/core.c | 141 +++++++++++++++++- include/linux/device.h | 2 + 4 files changed, 154 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 68647ff4bdd2..6532bd0bbfdf 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -995,6 +995,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 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 a5b7abc10ff0..40dbf588a5d6 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 93605698affc..7fee6043dd37 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include #include @@ -37,6 +38,11 @@ #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"); +static bool async_shutdown_enabled; + /* Device links support. */ static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count =3D 1; @@ -3627,6 +3633,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 @@ -3925,6 +3932,7 @@ bool kill_device(struct device *dev) if (dev->p->dead) return false; dev->p->dead =3D true; + complete_all(&dev->p->complete); return true; } EXPORT_SYMBOL_GPL(kill_device); @@ -4903,6 +4911,40 @@ 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_enabled && dev_async_shutdown(dev); +} + +static int wait_for_device_shutdown(struct device *dev, void *data) +{ + bool async =3D *(bool *)data; + + if (!dev->p || !device_is_registered(dev)) + return 0; + + 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) { if (!dev->p || dev->p->dead) @@ -4926,6 +4968,8 @@ static void __shutdown_one_device(struct device *dev) dev_info(dev, "shutdown\n"); dev->driver->shutdown(dev); } + + complete_all(&dev->p->complete); } =20 static void shutdown_one_device(struct device *dev) @@ -4955,6 +4999,88 @@ 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; + + dev_clear_async_shutdown(dev); + return false; +} + + +static void start_async_shutdown_devices(void) +{ + struct device *dev, *next, *ndev, *needs_put =3D NULL; + bool clear_async =3D false; + + if (!async_shutdown_enabled) + return; + + spin_lock(&devices_kset->list_lock); +restart: + list_for_each_entry_safe_reverse(dev, next, &devices_kset->list, + kobj.entry) { + if (wants_async_shutdown(dev)) { + if (clear_async) { + dev_clear_async_shutdown(dev); + continue; + } + /* one device reference for this function */ + get_device(dev); + /* another to pass to the async task */ + get_device(dev); + + if (!list_entry_is_head(next, &devices_kset->list, + kobj.entry)) + ndev =3D get_device(next); + else + ndev =3D NULL; + spin_unlock(&devices_kset->list_lock); + + if (shutdown_device_async(dev)) { + spin_lock(&devices_kset->list_lock); + list_del_init(&dev->kobj.entry); + spin_unlock(&devices_kset->list_lock); + } else { + /* + * async failed, clean up extra reference + * and run shutdown from the sync shutdown loop + */ + clear_async =3D true; + put_device(dev); + } + put_device(dev); + + if (needs_put) + put_device(needs_put); + needs_put =3D ndev; + spin_lock(&devices_kset->list_lock); + /* + * If the next device has been marked dead while the + * spinlock was released, or if it has been unlinked + * from the list, it may no longer be on the + * devices_kset list. Restart the list walk to be safe. + */ + if (ndev && (ndev->p->dead || list_empty(&ndev->kobj.entry))) + goto restart; + } + } + + spin_unlock(&devices_kset->list_lock); + + if (needs_put) + put_device(needs_put); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ @@ -4968,6 +5094,14 @@ void device_shutdown(void) =20 cpufreq_suspend(); =20 + async_shutdown_enabled =3D async_shutdown; + + /* + * Start async device threads where possible to maximize potential + * parallelism and minimize false dependency on unrelated sync devices + */ + start_async_shutdown_devices(); + spin_lock(&devices_kset->list_lock); /* * Walk the devices list backward, shutting down each in turn. @@ -4986,11 +5120,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 aee79fd6b32b..1ebafa798462 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -612,6 +612,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 }; @@ -829,6 +830,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.55.0 From nobody Fri Sep 25 01:20:27 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 8904C5304BF for ; Thu, 17 Sep 2026 16:38:27 +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=1789663109; cv=none; b=aSLpNmTKWCbpSmN8iaeDwOYY4SnSeZBYLx+4+GwUtd/9eBHPriEwI5vE4q921WfYhhG7EK8sWJdGE/KG/WFInh1nB9/Fq5f5Mbbi/esFQMO7e8TlXOesDjJc6m3qcvLREQ4th5dr4Fesf70gtmaMW45jVSLNlXt5TDDmNOlJJcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663109; c=relaxed/simple; bh=eNLC4ZzypIvS3WzbYcz7lFQurlQk7Y3PYIywCoFC+MM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=th8BByWK9i+nXHcNJNpJgdO9zaatjWS8GGLBIlz+jCQvWv+qfbNUe3LJPe1c/QLY864moTTRxryxOEgYKau9vOZi/ZHo9i6c2JVu9xkwGZTP8aRtaG55I5ATi34GWmRDjhKpVBWEA5iIbKBsUUbdqlYCGD0CFwe/y6XHbNb2W4E= 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=AwNslG6k; 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="AwNslG6k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663106; 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=6CVM95O8nJA2j5PntuVbYrjGyYXMZc4AlBaFKMW1Qic=; b=AwNslG6klItLL6WqWd2n5wUpZl2jzPJx88sTbebKmsieKRW3k3oUIMfB0SGk/wVNGyL4q9 gpsulGgYoRSUi5gqc1tAgxk9J5bBva318AqyEtC8D5lgSqtcbl0nbIrxhOiI8iUJc0CAdM emq0Cz4bpuESUH2EA/29tok6XqgZ4KE= 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-489-IyQ06wh3MyeKK2BB8h10PA-1; Thu, 17 Sep 2026 12:38:23 -0400 X-MC-Unique: IyQ06wh3MyeKK2BB8h10PA-1 X-Mimecast-MFC-AGG-ID: IyQ06wh3MyeKK2BB8h10PA_1789663100 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C82E21955DB3; Thu, 17 Sep 2026 16:38:20 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8430C1800361; Thu, 17 Sep 2026 16:38:17 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery , Bjorn Helgaas Subject: [PATCH 7/9] PCI: Link a virtual function to its physical function Date: Thu, 17 Sep 2026 12:37:42 -0400 Message-ID: <20260917163744.191748-8-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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" With a PCI virtual function having the same bus for its parent as the physical function it is associated with, there is no explicit dependency between the two in the device tree. With async shutdown, this can result in the PF being shutdown before the VF has an opportunity to shutdown. Link the VF as a consumer of the PF to note its dependency and ensure clean shutdown ordering. Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery Tested-by: Laurence Oberman Reviewed-by: Bjorn Helgaas --- drivers/pci/iov.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 9d408fb8ac25..9b74211c6ab4 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -382,14 +382,20 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) } =20 pci_device_add(virtfn, virtfn->bus); + if (!device_link_add(&virtfn->dev, &dev->dev, DL_FLAG_STATELESS)) { + rc =3D -ENOMEM; + goto failed1; + } + rc =3D pci_iov_sysfs_link(dev, virtfn, id); if (rc) - goto failed1; + goto unlink; =20 pci_bus_add_device(virtfn); =20 return 0; - +unlink: + device_link_remove(&virtfn->dev, &dev->dev); failed1: pci_stop_and_remove_bus_device(virtfn); pci_dev_put(dev); @@ -421,6 +427,7 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id) if (virtfn->dev.kobj.sd) sysfs_remove_link(&virtfn->dev.kobj, "physfn"); =20 + device_link_remove(&virtfn->dev, &dev->dev); pci_stop_and_remove_bus_device(virtfn); virtfn_remove_bus(dev->bus, virtfn->bus); =20 --=20 2.55.0 From nobody Fri Sep 25 01:20:27 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 405D45326DD for ; Thu, 17 Sep 2026 16:38:33 +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=1789663115; cv=none; b=hpCrh8lRAN8cOHhfv4qTimsyElC2nqnYGbzx/sse4JrVBCNTLRIgcNv2WnXDXVdC3o0FIGcUM1y5W+WuD6vV6qKOyvA1bJOTjE1RBrhpDqEtLe4WwEdsS3VCG/gfsraaO6jdcwqpZvJVc0dDtvSNppjVsa4dZLsISKZeXHszdOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663115; c=relaxed/simple; bh=Tkmhq7ipcJ4eJBwsM1IcqrP9wqQcBe6egEgtbha4A80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ef90fn6vCayIq4fDpiGh7Mgu7sqtJVG8t1Cq6D/2nrgQZKLLOLXkeTXE1WovQM5csdxz4hD4yb1kFL1sxpT0/dIS/PH7x5DShfICkv1z0COB13+ddaoXdCTuYevMWH44+1oQq7OIrlXNb8Ckg7bYshVFtwVtf2ZZ+/xzSJVJES8= 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=RTJWZfe+; 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="RTJWZfe+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663113; 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=J5XvO9ED1PnQW6LvxI91yeoYZ/9/NbKN8AWis2OJ8FM=; b=RTJWZfe+vQ4uAvkEPxSX4BRUGFaFwWarF3KmcAO+Jl7ZELiAqandvhi0BXoCdkgHV4sdLz rxjpy0u+BoPDeJ0RBgnRtyn9YQocFGIEhPSJ5MAu8nPCqda2HhL6zciMCXKY+ye/wncuwA QdmfA26npnO79O3W6LC4PAMZRz60kkY= 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-88-CeX5IH-BPMSoXeUtkPmpQA-1; Thu, 17 Sep 2026 12:38:29 -0400 X-MC-Unique: CeX5IH-BPMSoXeUtkPmpQA-1 X-Mimecast-MFC-AGG-ID: CeX5IH-BPMSoXeUtkPmpQA_1789663104 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C3D801944E40; Thu, 17 Sep 2026 16:38:24 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 179061800345; Thu, 17 Sep 2026 16:38:20 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery , Pasha Tatashin , Bjorn Helgaas Subject: [PATCH 8/9] PCI: Enable async shutdown support Date: Thu, 17 Sep 2026 12:37:43 -0400 Message-ID: <20260917163744.191748-9-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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 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 27008e2ea5af..101a96718acd 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1038,6 +1038,7 @@ static int pci_register_host_bridge(struct pci_host_b= ridge *bridge) if (err) goto free; =20 + dev_set_async_shutdown(&bridge->dev); /* Temporarily move resources off the list */ list_splice_init(&bridge->windows, &resources); err =3D device_add(&bridge->dev); @@ -2748,6 +2749,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 platform_pci_configure_wake(dev); =20 --=20 2.55.0 From nobody Fri Sep 25 01:20:27 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 BCDE15172D6 for ; Thu, 17 Sep 2026 16:38:36 +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=1789663118; cv=none; b=TZvxLamzvx9DHFlq1+L3vZ+rJj6jy0Cge3YV9iFRmyPx1vSD9JnZ4cIpIjMNpyG7Rk9urqZXasfroubt5PCoyxF5BkWxVqo7HEqvkhEyKNZXPjsZYuE3EtK8fCq0umoFbDPV9RpNapxCwg5IhaDJpGw/1UrIOETs/aR7/BBLXz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789663118; c=relaxed/simple; bh=1XNAjcMfzxS737UbycscQLHar4hJeLnVfG7xL8UK+Sc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rywksQEsm9CU0tBsrb/YmwVt8z0e0v6ZY6Pl0DuAGQaN3xaF4q2aHn1jcqzTYbruWqlS0XrVMwstpdQ+fjVcoU1SHxj2QZoRr2RY2c4mmoEqJu77DZiHf7BbozAkN74vgH7ATjZIECH9DIQQv4QhBB7QzFwF17dnHOfB49zBlik= 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=KyNiU37/; 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="KyNiU37/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789663115; 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=exa5f/DcwNCR5E0w8unUqAO11f1n98HF5VNU5M/lSuA=; b=KyNiU37/xHS5BSbjpeJy3dilSi2DvnTSuCGuooOxC/CBAVgobCJohFXMuTU0QQiu6ozueC 6VUZMl3M4lZ0qcJ/1wB5cz7NL51r8HXzw3bM8lnQqtdL2JnspmFzRgtSm9PYPhyt655fgP IMuEczaBlkyAq8l5d/enNgOqpRS6clU= 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-627-kkknJbLZP_Gzu6UXMZrJpQ-1; Thu, 17 Sep 2026 12:38:30 -0400 X-MC-Unique: kkknJbLZP_Gzu6UXMZrJpQ-1 X-Mimecast-MFC-AGG-ID: kkknJbLZP_Gzu6UXMZrJpQ_1789663108 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 4414C18F0F01; Thu, 17 Sep 2026 16:38:28 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0123F1800352; Thu, 17 Sep 2026 16:38:24 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery , Pasha Tatashin Subject: [PATCH 9/9] scsi: Enable async shutdown support Date: Thu, 17 Sep 2026 12:37:44 -0400 Message-ID: <20260917163744.191748-10-djeffery@redhat.com> In-Reply-To: <20260917163744.191748-1-djeffery@redhat.com> References: <20260917163744.191748-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 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 e72055c1ebbb..75592f41ef39 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -272,6 +272,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 9480432f650b..52e1e38dc027 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1387,6 +1387,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; } @@ -1413,6 +1414,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) @@ -1432,6 +1434,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.55.0