From nobody Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 801F14BC02C for ; Fri, 21 Aug 2026 14:24:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322300; cv=none; b=jvjk6rh0mXqvaqc599LIzEZ0VmS5HwU7cIcQnRlzyczQXfCF+alOZvWwEC4fWSBFLHM+IaXz7W6wb+zIJp14om+H6iFq6Lz7O7Dy+yCW1LnfxCbECEmg97QpbuMGpQs3AhpZWvCd63YWR7WjBNn3MYIIav28Djukoi1YqomuYb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322300; c=relaxed/simple; bh=CvVkhhBXZG0ZDrJsnmBXLSGYgGyIZi2GM0825+aHLdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ulGzODQXGtZF8oWMsqb/32cEPCS4MA2c6xRFzK1ydZOskTIwtZ7doTaMHiTZNuKBSlnnRlM+X1ZrPsP22qFzZ3hAI6vLr+ddpYb8iyLl8pZxxOBwyG27o2LG7aSslW3OPm+kO8MmEsLX9qaKDzzzkR+SRHRaXI/T6HuFRQT/8r0= 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=Uu6uKCGg; 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="Uu6uKCGg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322292; 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=Uu6uKCGg3AV+mdpgzBizeIeQkRlbDMmGsYKZDzFB+XVZzYvIuqa1t6KvH/zp+CV7P2Xj/h j9ZSysvWUgS+/oAg98ZnJzF33nOa6aN9/llR8n0sBeImcX70jGhusrwI0tzSfYM2H2D0Bb zKJCeBoBspvwYBD2YzEIpj+UA7SHXAY= 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-235-0DWkU8VlPs6IoD1cwnQOkQ-1; Fri, 21 Aug 2026 10:24:49 -0400 X-MC-Unique: 0DWkU8VlPs6IoD1cwnQOkQ-1 X-Mimecast-MFC-AGG-ID: 0DWkU8VlPs6IoD1cwnQOkQ_1787322288 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 4B37F1801BEC; Fri, 21 Aug 2026 14:24:47 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A50C11800346; Fri, 21 Aug 2026 14:24:44 +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, David Jeffery Subject: [PATCH 1/9] driver core: rely on put_device to free dev->p Date: Fri, 21 Aug 2026 10:24:06 -0400 Message-ID: <20260821142414.150892-2-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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 Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C2C54C041B for ; Fri, 21 Aug 2026 14:25:01 +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=1787322307; cv=none; b=QSb9drnqTkNUrf6QY+RC0WbF0q3NcNRajbN3ZjruITLmG1qq6GBZghCcaBlOm/kNqoPE5cPq9439+XHkLuDNqIEZavyz0T3WK7C7fF4tYCa1uV+XWaTVsYEy9ntlZFCMIP8rgn4vToKrzKH0W8ecR6RZEaVYSiCpVeZKhXYgsbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322307; c=relaxed/simple; bh=W6FS670jxUF+AdAIfuFCT+t+f8ySA3Fg6X9MUK/oz/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pzdGPYazryHW3yt9bZLm/azT/U5d4qzbqnuM0teBBTPI6uywPcGKeeTBycs6yXP8pygH5z6rzRbve/tvQcO5jtwM1HGIbCY75TSbNBPhlePYIZNKSiQ7bTG+oz7J21YNMxbsm1MbF0o0Rx7T2id+MnpiQMuTioiaJudSKh+0NxY= 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=VfR1CSAQ; 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="VfR1CSAQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322297; 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=BvLQwuQsxkf9F2xZNCYKTp5KyAP5LYYETgZttqdI30g=; b=VfR1CSAQgXBTh452g/0nKmWqDtvBCeREfI7+PUM9a5rfnSflQKgv6FraBdQwjU8Pnlu+Jy HKaTpwh9mPgeFbJxBONM8/VDq2CaP0xKmZsPgyG9rsy0vpc26TpDb0rE+HmqRBcL1YW8lo 5ENURzLZFNSbRAWz7uNIVcWbSSCqgsU= 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-377-RH6zw2N2ODGYKZGfVV-FQg-1; Fri, 21 Aug 2026 10:24:52 -0400 X-MC-Unique: RH6zw2N2ODGYKZGfVV-FQg-1 X-Mimecast-MFC-AGG-ID: RH6zw2N2ODGYKZGfVV-FQg_1787322290 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 3688C1955BFE; Fri, 21 Aug 2026 14:24:50 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CAF8718005BB; Fri, 21 Aug 2026 14:24:47 +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, David Jeffery Subject: [PATCH 2/9] driver core: prevent device_add() during system shutdown Date: Fri, 21 Aug 2026 10:24:07 -0400 Message-ID: <20260821142414.150892-3-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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. While device_add() performs an initial check of system_is_shutting_down(), a race window exists between this initial check and kobject_add(), during which device_shutdown() may already be scanning devices_kset->list. If device_shutdown() passes the device after kobject_add() registers it onto devices_kset->list, device_add() would otherwise complete device initialization and driver matching, leaving an active device running after system shutdown finishes. Fix this TOCTOU race by re-checking system_is_shutting_down() under devices_kset->list_lock right after kobject_add(). Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery Tested-by: Laurence Oberman --- drivers/base/core.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 83263e3fa5d4..bd9c2921e326 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. @@ -3654,6 +3670,11 @@ int device_add(struct 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) @@ -3703,6 +3724,18 @@ int device_add(struct device *dev) goto Error; } =20 + /* + * Check system_state again under list_lock to prevent a TOCTOU race + * where device_shutdown() runs concurrently and misses this device. + */ + spin_lock(&devices_kset->list_lock); + if (unlikely(system_is_shutting_down())) { + spin_unlock(&devices_kset->list_lock); + error =3D -ESHUTDOWN; + goto ShutdownError; + } + spin_unlock(&devices_kset->list_lock); + /* notify platform of device entry */ device_platform_notify(dev); =20 @@ -3822,6 +3855,7 @@ int device_add(struct device *dev) attrError: device_platform_notify_remove(dev); kobject_uevent(&dev->kobj, KOBJ_REMOVE); + ShutdownError: glue_dir =3D get_glue_dir(dev); kobject_del(&dev->kobj); Error: --=20 2.55.0 From nobody Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C60394C77A9 for ; Fri, 21 Aug 2026 14:25:01 +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=1787322304; cv=none; b=VVkCHa5J7OS4/Vpf1mEFbbqsMzxaxFTgFPJZ8ZQTO0GhSAeEaAz8XtPeHAi3b7owZIPlIRIywFV9d1nC6IW2x2yRiIPCTtN+gLX4wnpr2o9q3CrdH/h6lLHIRkj4gB8eqpfRVBQwxk6CimoK08b7nTGdgmXJV30pjCmFczpqpvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322304; c=relaxed/simple; bh=3lQMPdYbR1RntwK+bxjJtg5kiwvAYZO4Z6X9Nwg+SoI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bp756r5cJO6xCCQc2/gzDd7/EH4nIi+0x7/Ks0Yc9sHvwI8UUQ5mrEvXiVNBleRU+AHAVLmRQxGGfqdkax/BOGypLqquyiDSlT8m/YevbIwRdvnYPehinLtumrkrtQBbq5JqKs1JUOWsKL3mXWsPpyrqY+OR+pDFzvJ7WxfQx+I= 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=FbEI0Z/f; 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="FbEI0Z/f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322299; 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=IU0vv4gN2o5y5prXUpJQRh2FejWBebUitlBF1Qr8ENg=; b=FbEI0Z/fwJeAkfo8wFinbf56id4Qs11t9jXaqn/8EZMQuJkHB+mBzhX9t53i3070oMcW29 xdU/rLD4DdmocUrm94ikhBd1WhRK4Iujd6uoNQc7L1TBOm1rfU3mm0GYBtY0hdJX8Rdll5 3jpHDv2Kqsxxmxns12EdOCK4qZpwmL0= 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-255-E0vuZrlmMeSZFl2-63xpJw-1; Fri, 21 Aug 2026 10:24:55 -0400 X-MC-Unique: E0vuZrlmMeSZFl2-63xpJw-1 X-Mimecast-MFC-AGG-ID: E0vuZrlmMeSZFl2-63xpJw_1787322293 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 22CFF1954208; Fri, 21 Aug 2026 14:24:53 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C2E6180034F; Fri, 21 Aug 2026 14:24:50 +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, David Jeffery Subject: [PATCH 3/9] driver core: warn should device_move try to move a need_parent_lock device Date: Fri, 21 Aug 2026 10:24:08 -0400 Message-ID: <20260821142414.150892-4-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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. Signed-off-by: David Jeffery Tested-by: Laurence Oberman Suggested-by: Tarun Sahu --- drivers/base/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index bd9c2921e326..75f5931165a8 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4712,6 +4712,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 Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 407CF4C9550 for ; Fri, 21 Aug 2026 14:25:07 +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=1787322309; cv=none; b=uJ5Dstj6ryBRyu6Ai/9DMuqe1dqF+FM0b2KaVwxANWgD9ttfBZhj88FLJcDzzyO+67vmHhbubZ+zSaugpLP3OjsNUUprF7jlXbfU9fWwdYHpm1yq0faJ9mrAdBxcywrpmbJbOC8cXktpCd1EovWC30xn53h9JoWxjBchb6ntX1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322309; c=relaxed/simple; bh=TUNZAGJ8NS4yQJHqG+jndRCTH9fz2EzUUgct2wCRBWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G9ywsMXJl2Rhjeb32caMPoSmju/6DMxMefR2GsC5U2LzUZV2P1smo9DiUeiLwKZG/DKPzbhFJmH1M2eFeQBKWsFTftHm/39k6eRKWYrRyxGu0al5nVdMM2puBc+QFrzgAclbo/QYxpO7EIzPk/tfKSqcKZt1qyOqFu5VlmWjXgk= 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=Xy/RSgfJ; 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="Xy/RSgfJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322306; 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=uQriG7YcJmiiNOWQvqK/7JJ3Dxkgd3HtvvGvRtKCsy4=; b=Xy/RSgfJJGAYNZPul9bkN/N7SznrluCA9wSgnHvvOauX1fOAkGiPCH8M+b+v4wY1WXvygE v6pzghn2jK9Spv3Qd5C5cXAuBWq9+HELBDcDDQpjIfhgbDxbGt4P37Xb6AcKwv/a2chBAs GTR+JmfY7fsOGwO0LYghAJ2NDGr3X9k= 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-248-jp2jjpJgM8eimwEFXLiTpg-1; Fri, 21 Aug 2026 10:24:59 -0400 X-MC-Unique: jp2jjpJgM8eimwEFXLiTpg-1 X-Mimecast-MFC-AGG-ID: jp2jjpJgM8eimwEFXLiTpg_1787322296 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 1BA1519540DF; Fri, 21 Aug 2026 14:24:56 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 74B671800346; Fri, 21 Aug 2026 14:24: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, David Jeffery , "Martin K. Petersen" , Pasha Tatashin Subject: [PATCH 4/9] driver core: separate function to shutdown one device Date: Fri, 21 Aug 2026 10:24:09 -0400 Message-ID: <20260821142414.150892-5-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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 75f5931165a8..a94d24b30c30 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4910,6 +4910,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. */ @@ -4946,36 +4980,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 Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 936224D2EEC for ; Fri, 21 Aug 2026 14:25: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=1787322314; cv=none; b=FfJPuW+/SFUOwNkHwtIr62SPRln6kbCtj2xF7rgG7ETiva/0KECAKDAJO54j0tpDyafjMcBQX0znZbIS/MRcnHU+iqrHiteXWPRN6njkDCA//GTlxuHAtOYXQpLBpWam1vZK2P8254jY7vfI4u4r2WBK/ngXtt7TO9010QCqz4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322314; c=relaxed/simple; bh=PpCFqoRTZpuvsvOZ0n6sLpsfDEkS0I7BJkxeNNLASWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FV3yGD2z1Hi6cisTmYa2m6xe5N8n4A1gvC+kbFpOS+m5X4/7Pe3Nlas36XNjflLbcMp08vLEEDGHheVpEkq6/epDXzHXwbSURhjME4aIYS3MefTdSXb3ZUHMFuoiOfT4+HhImVirutKyb9nFdhcRVnuNhVZWiiBVV50Ljv43hPU= 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=T4QGn2wp; 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="T4QGn2wp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322311; 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=DMrZ3k+8w7iHo+aJLNVhsbxB4A7X4+dEmXKkGn+Muu4=; b=T4QGn2wp1NOLh2jV+mK6XdiWNWA1D0Mm7Tihnp/x79tNh9fE0EjeiEhcXS4d+Skasmv262 MlYK0y2T8zFBaKdejdT0L7TEADjPpChUBGnOmTRcO8RgbfhDvDsqjoHmDTuNjZW+EvTvwP n3SLlgDfVZfJa5y74MDdvarIb2niubA= 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-505-Ui0UpXs6OW60e-6v_nFLxg-1; Fri, 21 Aug 2026 10:25:02 -0400 X-MC-Unique: Ui0UpXs6OW60e-6v_nFLxg-1 X-Mimecast-MFC-AGG-ID: Ui0UpXs6OW60e-6v_nFLxg_1787322299 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 0B5321955DE3; Fri, 21 Aug 2026 14:24:59 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 478731800346; Fri, 21 Aug 2026 14:24:56 +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, David Jeffery Subject: [PATCH 5/9] driver core: do not always lock parent in shutdown Date: Fri, 21 Aug 2026 10:24:10 -0400 Message-ID: <20260821142414.150892-6-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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 --- The sashiko patch analysis may complain about the parent locking and possible use of device_move. This issue cannot currently happen as devices with need_parent_lock do not use device_move. An earlier patch also adds a warning for this condition should some future code change violate the incompatibility between need_parent_lock and device_move. 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 a94d24b30c30..cd725466c32d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4910,12 +4910,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); @@ -4935,13 +4933,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->bus && dev->bus->need_parent_lock && dev->p && !dev->p->dead && + (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 /** @@ -4949,7 +4967,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(); @@ -4966,12 +4984,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 @@ -4980,7 +4992,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 Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 522174BCAA9 for ; Fri, 21 Aug 2026 14:25:09 +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=1787322311; cv=none; b=SzCrkNtDjnUHmRoLbVGGU/e9/VwDKVcIMkhSAkvqYp8nmgutS66UF7PrC16ej8vgQEBK7Hj9kENViZ6gxjlZOADEpQHAm25ZK6AF6EWM90OTyePrwVSnuIr3Fe7GRuL7U67zAXp0ZJnw/qbDi6r3jmB1apLrQkQmVysZUGGHIgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322311; c=relaxed/simple; bh=vCqJoa7y6H7gvwP6YHrfRy6NervclZ/8iIAEMaffwKE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u9M99GLFOOL51fOG66/T6Xkl0QF/uEkzT1eCw/KDqUEAv5m0/BhcSKc14/BV79hnO0Tce60mRFvWwwsbBplxYyeZr4tEoLGJ9x+nleAleuI7hMQmQjUUysj42LxR34+GOTkBAAzd61pUH7gAOdpF2I7gc/i+WBecXzU9dSoDzkY= 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=Sc5tFQYp; 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="Sc5tFQYp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322308; 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=Jr+Ir/Uj5p87dzJoYXiMsCrjOYIUZwTUAT4lIZUqasw=; b=Sc5tFQYpp7581vO8Df75KuLPmONCpxpbuvkRSRESJdn4XDL6KH+l61syAVh0+jgf3YRPzK 42+9Um0D2P2OaU9MEF6ppc/FCU6ElPBajpPthTf2+SEkx5qbIta+E5tUNknbqCXpA6/P4l 1YvYalaXv1OOGK7hA6e9l/lVhi+UG8I= 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-131-8ijUOe0-MlG3XBzXr8Ko8w-1; Fri, 21 Aug 2026 10:25:03 -0400 X-MC-Unique: 8ijUOe0-MlG3XBzXr8Ko8w-1 X-Mimecast-MFC-AGG-ID: 8ijUOe0-MlG3XBzXr8Ko8w_1787322302 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 BF9561801BF4; Fri, 21 Aug 2026 14:25:01 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 689D8180034F; Fri, 21 Aug 2026 14:24:59 +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, David Jeffery Subject: [PATCH 6/9] driver core: async device shutdown infrastructure Date: Fri, 21 Aug 2026 10:24:11 -0400 Message-ID: <20260821142414.150892-7-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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 b5493a7f8f22..f0de215963c6 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -989,6 +989,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 cd725466c32d..42cd77486e00 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 @@ -3932,6 +3939,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); @@ -4910,6 +4918,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) @@ -4933,6 +4975,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) @@ -4962,6 +5006,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. */ @@ -4974,6 +5100,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. @@ -4992,11 +5126,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 7b2baffdd2f5..f913d72218f8 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -610,6 +610,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 }; @@ -827,6 +828,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 Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3B7D4D8D89 for ; Fri, 21 Aug 2026 14:25:16 +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=1787322318; cv=none; b=T4A2OvLWwJ8nyePnDQlyFlHncLviphJVIfpX8ECRG7lEjDBKexyFlYLJboWQgkCDA5JDzlPbdth7ZgE9KXtPPZLhEEz6gqLJ4y7e2WZWeOYGJWm1QfbJc6W3f0sw8ELiTdnrHFPsuc645e7u42JJ8QaLgCZX6oQT8+5+GdclHZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322318; c=relaxed/simple; bh=NMGsdHfv3kJB9yX9focVMEcZIChlcDtecusG5LE85CM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mU2gthUUjrtBGfJ7MfpvPfj5Vn1jfibRvMy2yuVLvd4oV1fQgKvbM9kWmU6v3vHGOUlK1SerMnBoe6E+bYjtw/sYVW3fIExwc7kVjKq0a1C2WqSHqg65jlQRzugiZoA2gEOj4l0zkWDkDr/Y2uEDLPj93DmjneJQ60k2K9PQHhw= 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=jGTLNgrr; 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="jGTLNgrr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322315; 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=qUje89Fd4abdoDeewa2Je7uJEn5QSHfX2TySvfVb0Hk=; b=jGTLNgrrwUyv81PdDL70XRqSUWCP9fgd1gciidq/YMbxuNRklvl8jAk/xhXJCKnsP2MBGa PUsRroU6vtHPK1NpH9nPybgBwcxilnGup1O8jGzmqxuuPjZ06+7OcO7x6J62Tozs1kw/Y3 p9ZfR1/wgBfovk2p9bVhdrUwcx9Xbv0= 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-356-W2RI67c_PTGqth6y7MB6JA-1; Fri, 21 Aug 2026 10:25:06 -0400 X-MC-Unique: W2RI67c_PTGqth6y7MB6JA-1 X-Mimecast-MFC-AGG-ID: W2RI67c_PTGqth6y7MB6JA_1787322304 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 4F9661801209; Fri, 21 Aug 2026 14:25:04 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0E3681800346; Fri, 21 Aug 2026 14:25:01 +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, David Jeffery Subject: [PATCH 7/9] PCI: Link a virtual function to its physical function Date: Fri, 21 Aug 2026 10:24:12 -0400 Message-ID: <20260821142414.150892-8-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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 --- 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 b0d24839c084..c75da093d60c 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 Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56E504C77CB for ; Fri, 21 Aug 2026 14:25:17 +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=1787322318; cv=none; b=dq60I68Ocq4f1m0wzLixXPXWhWEq8AY9X8OX41giKei7r8C4j2uQincldwuh2UEnfOFnaHUD5Tgw7HIacL2PBL4log+74DK4180q9oqwHmJjmqVnp85bPZgAn54OutHvihyy54JakAIxP60tsO7oi6cUmrSwchYioAvRBiW9eH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322318; c=relaxed/simple; bh=QDnzyAXfkVtXx6dafjBq5IPhp7lT//fl6PxTNeIYJZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qr6ZF4NdCMP9d2NjXSh0E/VECOExSNVGj4iGPrfsgRVtG/Ea0qRzhd+KgHxCcY/RDhcY4ZjzCzRUjDl7fQyNtdyfgNMmKFHGXsuhqDy9GhvD7axw5I3t1rGvMFXT++y52oITl3ojUVbEqE14EntGNXgm34gNfQOvv2UWZhA667k= 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=EZNunhb3; 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="EZNunhb3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322316; 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=2wH5PJaoSf+WZ0HADj6Qf/btDMSF680EsLu/bDLMdGU=; b=EZNunhb3lU0tDAVruN7wfqHwqcCriNbzKtAYZAzN66jlc8ysY2Pepc474Gs6Mz7IlaUVr0 oAWCei36jGwGHRAgcsrDlDnPPeUSRYfQJuqs0PjKWVisRBRvTbviykxFWrzeYJNXjPOTbV 2zLat8aGqd+gQ7wPuOrgjuvDV9xhm5o= 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-148-wb891n9mO46S-xNiZu2-Pw-1; Fri, 21 Aug 2026 10:25:10 -0400 X-MC-Unique: wb891n9mO46S-xNiZu2-Pw-1 X-Mimecast-MFC-AGG-ID: wb891n9mO46S-xNiZu2-Pw_1787322307 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 6E43718011EC; Fri, 21 Aug 2026 14:25:07 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 93532180034F; Fri, 21 Aug 2026 14:25:04 +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, David Jeffery , "Martin K. Petersen" , Pasha Tatashin , Bjorn Helgaas Subject: [PATCH 8/9] PCI: Enable async shutdown support Date: Fri, 21 Aug 2026 10:24:13 -0400 Message-ID: <20260821142414.150892-9-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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 dd0abbc63e18..af2381446406 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1046,6 +1046,7 @@ static int pci_register_host_bridge(struct pci_host_b= ridge *bridge) =20 bus->bridge =3D get_device(&bridge->dev); device_enable_async_suspend(bus->bridge); + dev_set_async_shutdown(bus->bridge); pci_set_bus_of_node(bus); pci_set_bus_msi_domain(bus); if (bridge->msi_domain && !dev_get_msi_domain(&bus->dev) && @@ -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 /* * Add the device to our list of discovered devices --=20 2.55.0 From nobody Mon Sep 28 12:33:32 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F048B4D90C3 for ; Fri, 21 Aug 2026 14:25:18 +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=1787322320; cv=none; b=OprbQIVzGZvAxIDoUA7z2R1LSaLX5QwlGqpBtraglIYHpEAfP4M1FT7Zd7wx6lWUOzvQnNMdynL+VvYQtIJk13zzc1ynSgDg3jKcQNGKD+WwKwQT++C+B1QhKyFZBP0KFYB3WE9m/d2rf5U0atsxSuFVMoy4JsRIH7/FGsmOV0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787322320; c=relaxed/simple; bh=6qSHeZjvuVz7SpbdcsJj4YY+CVwV7Le/BHQ1rg7aQGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1XfVIwPIwL3zKc6czCajtq4MjRV4sxDEUb25L98KZJQ/cMFXlX0Q2j4/+eJApewDeEbyJ+cHVvNhT7YtE7czmYIxt+PhKy5kC+BNXBFTri3H/29roY9dgH84XplmrAL73wMLN9HJ8d/QQqqwiCO/LxCknc0Dq2yn197+NFF1fI= 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=HFlIPCc+; 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="HFlIPCc+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787322318; 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=3QMD3k9RzE+xvFDxxs5UwrRSerQjrcJtmAMSaBUs0Kg=; b=HFlIPCc+5rK7nqYOcP8HIPJhWNYhN+l5GosyNsGnVNwB5v3O8DpKm3x+69++kLWS6A4PbL 1FDEAggvpcOfjz/LegJWM2OimgPDxvv7m5pA9Nc6fzx89wGkKE/bFz4VxrvknG+t1o2zJ+ XHOqkzcjGWHH4PoGDe8+yPuHHrCmdK4= 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-136-BZNRm3BfODCEh5x4I07Yqg-1; Fri, 21 Aug 2026 10:25:13 -0400 X-MC-Unique: BZNRm3BfODCEh5x4I07Yqg-1 X-Mimecast-MFC-AGG-ID: BZNRm3BfODCEh5x4I07Yqg_1787322310 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 59FBC1955BC7; Fri, 21 Aug 2026 14:25:10 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BA565180034F; Fri, 21 Aug 2026 14:25:07 +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, David Jeffery , "Martin K. Petersen" , Pasha Tatashin , John Garry Subject: [PATCH 9/9] scsi: Enable async shutdown support Date: Fri, 21 Aug 2026 10:24:14 -0400 Message-ID: <20260821142414.150892-10-djeffery@redhat.com> In-Reply-To: <20260821142414.150892-1-djeffery@redhat.com> References: <20260821142414.150892-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 e047747d4ecf..bf691acc7a67 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -273,6 +273,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, pm_runtime_set_active(&shost->shost_gendev); pm_runtime_enable(&shost->shost_gendev); device_enable_async_suspend(&shost->shost_gendev); + dev_set_async_shutdown(&shost->shost_gendev); =20 error =3D device_add(&shost->shost_gendev); if (error) @@ -282,6 +283,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, get_device(shost->shost_gendev.parent); =20 device_enable_async_suspend(&shost->shost_dev); + dev_set_async_shutdown(&shost->shost_dev); =20 get_device(&shost->shost_gendev); error =3D device_add(&shost->shost_dev); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index dfc3559e7e04..8fd317aef37b 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1386,6 +1386,7 @@ static int scsi_target_add(struct scsi_target *starge= t) pm_runtime_set_active(&starget->dev); pm_runtime_enable(&starget->dev); device_enable_async_suspend(&starget->dev); + dev_set_async_shutdown(&starget->dev); =20 return 0; } @@ -1412,6 +1413,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) transport_configure_device(&starget->dev); =20 device_enable_async_suspend(&sdev->sdev_gendev); + dev_set_async_shutdown(&sdev->sdev_gendev); scsi_autopm_get_target(starget); pm_runtime_set_active(&sdev->sdev_gendev); if (!sdev->rpm_autosuspend) @@ -1431,6 +1433,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) } =20 device_enable_async_suspend(&sdev->sdev_dev); + dev_set_async_shutdown(&sdev->sdev_dev); error =3D device_add(&sdev->sdev_dev); if (error) { sdev_printk(KERN_INFO, sdev, --=20 2.55.0