From nobody Sat Sep 26 09:16:54 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 EEE314AD4A0 for ; Wed, 2 Sep 2026 17:09: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=1788368943; cv=none; b=Bym8n1hwuGYDXfdK4ie29J/2gbEhb/rHWRkw8PaR73dIz0kYdNmF0fL2Dsp2p/H3YdMBqgFYX6somuyjXLG+Jpb+dXTIjBWbZs4kUp8QrwWbGPzxb1UsSruV2a/ZuJIFgno1bhC5R85OKOcNYLmn5fcFd0uRlHtr7bTyGCU9I3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368943; c=relaxed/simple; bh=CvVkhhBXZG0ZDrJsnmBXLSGYgGyIZi2GM0825+aHLdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LJqNKB8d9LsQl88gb6q6SRVjcuvPqUnCf/87SKRWe7flJPVNE9BIpwqfuL98dxCV5OqoVdGz69NZT29igGq96pE9YI42R+0itAWXPKyQQwpvH7lLuKxkDlNsPQ46If9b2Vg+b2GghmUpBVOLFoLxEAzmRgI0fQboAEx8TY6ElD4= 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=R5A09UO7; 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="R5A09UO7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368940; 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=R5A09UO7LuPGZnNjuwP02oasEIEAa0A6q9NMJUPJxp50KPVA/K275sVaPjY7A8POeGDuZh fV633ipMw/hkLWFt1kf2v+ZYWY655CEoGd7s37Omzx2K72GqrlQyo0qhG3nQ3N75XEyR5m D8ebHKCa4ov4iwtijYG1A0opGhvh2/U= 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-37--k90ol-JP_ebVAxtldOu9g-1; Wed, 02 Sep 2026 13:08:55 -0400 X-MC-Unique: -k90ol-JP_ebVAxtldOu9g-1 X-Mimecast-MFC-AGG-ID: -k90ol-JP_ebVAxtldOu9g_1788368933 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 4B1821944D43; Wed, 2 Sep 2026 17:08:52 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1A2201955D69; Wed, 2 Sep 2026 17:08: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, "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: Wed, 2 Sep 2026 13:07:26 -0400 Message-ID: <20260902170734.95504-2-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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 Sat Sep 26 09:16:54 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 3030837883C for ; Wed, 2 Sep 2026 17:09:03 +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=1788368945; cv=none; b=p+FlmteF/+PEy4+16hMmd5NC+0QexN2PpmZoj0SZmvW1hQlgXQHOXGHRmEu5K2XrOgcP/WzcU+bT3Dq5jU9i+vNCb5P7DZnXCtNAhV1bpEzEy5v0md5t+LKunxCRBAiEcWwp+/JEY7kxMSBgVdf5Yv6S1JhCu+Hurisvfb3Oz2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368945; c=relaxed/simple; bh=IWHexqUg6916nspV1VRDVgr5pFAZ+u0l6fG7BM3sYa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r2Hj25/ELcsE/SuLKP7nPUHv3FTdf0F8P3N96MU/eOvAs3vwYjM5fjDDbvlfgUM0OBVyrxtF3xsk085Hjo+B9KQMvl2LCVhu6IDDOhZ1Unpyd2+z4kyrAprcIenFip6RxfL9hNFt3L20eQMENrJIOPR+DyEY6Ka5UWAaM5JVMDc= 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=XBacqY77; 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="XBacqY77" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368942; 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=XBacqY77se7lcLapxnvPc6BnJn3r66s9qPqv3gyUsfMxMWK+Akr09GQmy6VhRIJnxA3gd/ JRNluBOKts7urWBd4l49CIc2fBRAk9KQlnmVDcHzYOJ8qeQfYXdeDghSWeTPJHu4qEhb1m TOXdSKTAGH7y5fCZo5WROY1gYldszZY= 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-278-BT5SXAruNeqn80UTKMXMYQ-1; Wed, 02 Sep 2026 13:08:58 -0400 X-MC-Unique: BT5SXAruNeqn80UTKMXMYQ-1 X-Mimecast-MFC-AGG-ID: BT5SXAruNeqn80UTKMXMYQ_1788368936 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 05CC31954223; Wed, 2 Sep 2026 17:08:56 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B49031955D8D; Wed, 2 Sep 2026 17:08:52 +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: Wed, 2 Sep 2026 13:07:27 -0400 Message-ID: <20260902170734.95504-3-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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 Sat Sep 26 09:16:54 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 98B044AD7C5 for ; Wed, 2 Sep 2026 17:09: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=1788368949; cv=none; b=eGrwkvnj4CcXj+VgbN3IhJPhS/tR+bt9C1BULJB7sHeBpg7AYcVTl+i7e/89MiMO6Jg4hPH+6vGIyzTztBr/sudSC1cx4H6oPvIWWOoeb8NID20bxfOWDwYQaMibODwrrDMDsJTf7weCGZ3ana8NVogf52lwKTWUkZc/5k7bbgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368949; c=relaxed/simple; bh=JNrK/0ub6m0FDk0x2dT/rnm7U5smWJV1A0KGzkCWXGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uyyJm5ggchN39vSRzjmOCF5jeU8T6LGLrFX6MX/gOg6h7S5Ua8LKbuIKYwbEYKPzxoWuqsvF//shlnuJpTCSQwDk11sn2iGZJXnDOYvM1cGwdJofMt13RYFBPEZU5i2chMPdpvPwmm/3DjHjpvUG1FR6JbUCSomPgcDJZ8sTvSA= 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=I4dJTas9; 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="I4dJTas9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368946; 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=I4dJTas9LBJwaCjjy4L9cGlCeACIzSgmQ+zm5sKOdjb24UI72rhe/RBiaesXWFuUu+QSe6 Xj9RhGj02UDeOJEEg5KQ3DSLoCqW2bTc8qBybm3fzV1KA1i2PYbPyggZv83kh0gi19OQCh +yfpC2K2wiz/2DrHYekQHYNWCP+/5qQ= 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-659-3OijcrHXP6-6pAt_90kFWA-1; Wed, 02 Sep 2026 13:09:02 -0400 X-MC-Unique: 3OijcrHXP6-6pAt_90kFWA-1 X-Mimecast-MFC-AGG-ID: 3OijcrHXP6-6pAt_90kFWA_1788368939 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 AB3701834507; Wed, 2 Sep 2026 17:08:59 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 65E4A1955D8D; Wed, 2 Sep 2026 17:08: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, "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: Wed, 2 Sep 2026 13:07:28 -0400 Message-ID: <20260902170734.95504-4-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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 Sat Sep 26 09:16:54 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 611DD4AD7C5 for ; Wed, 2 Sep 2026 17:09:12 +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=1788368954; cv=none; b=KGjFH1hrcAjriTlqrG0Z08JNm274o4UpmgPJkays9eMt3z3NIfDDAJYsi3RK9k159VZE5lD5GHNrqwFSAORj7qL8MMjjz1HS36XC7UDo/4QVLxEuCUYU1yAnk8KWZMjKsBWprurK2P7A3Wl/XfoZXgTiCVdeVS/Xv18Yt58EaBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368954; c=relaxed/simple; bh=EP0KuVg6dnAsKqEThnw3EV3YBp7Sy2fuZ57mmoXdlhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RMOhCHo2xQUkYtYJjFEl7x5UNd04czJsGoC9MCQS8qlQ4jNY/KkRAQxRwMpc0VOZ1kSs5xBQqxMjfG8NkLTNQG3amVPqolgb7dUebqEMU8azXYu+ISsTt0Ypckz+GB/XH04lH+adE1FfsgDF+pqx2WWoLUWAactpdoaz6cyxi2c= 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=jTCYG3Qr; 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="jTCYG3Qr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368951; 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=jTCYG3Qrlhok/GfSqO5RAbqRYHbNC1+rGMMEvwtuvQAreR02B2mt1FQo9YFexKFF4UJ824 pMa9YJ5ZfOH/01d73PSYGb+G4LBXARvYnpRnxCgNyl8ZWSLsCK3cX7fjMRdTTJZOkVQba9 jv8JcQpCDUmVRD1OwyHYJJRn4qkGas8= 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-584-mp7Qq3AwPPavquaSLoN8EA-1; Wed, 02 Sep 2026 13:09:06 -0400 X-MC-Unique: mp7Qq3AwPPavquaSLoN8EA-1 X-Mimecast-MFC-AGG-ID: mp7Qq3AwPPavquaSLoN8EA_1788368944 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 1B484183F9F0; Wed, 2 Sep 2026 17:09:04 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC5551955D8D; Wed, 2 Sep 2026 17:08: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, "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: Wed, 2 Sep 2026 13:07:29 -0400 Message-ID: <20260902170734.95504-5-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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 Sat Sep 26 09:16:54 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 BD42C34D382 for ; Wed, 2 Sep 2026 17:09:15 +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=1788368957; cv=none; b=rixVNqncq+qQtkhgj6U8Q5fcFpowyAyWgIaRi2SQDwVPgNfODKhRHBhmt7oSDQp9uiw19WbYVU+T0VDaqVbIAAA1DqiaClOVAiI2vjUCpic6SKF3rPbAfkJ+7yxOX+TjDmDgr/Fd9y1BSuYt8Q++ek5ohE+xj8mXVeBqwJjLTQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368957; c=relaxed/simple; bh=cC2isaE+1W+YicVT8Qyd5eWBKkTFJ4yHKIV3K9h3ZPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m1QtYFicAWW5OYaR3Eb11HYyo11qgBXxo6+aTpefoNcahXqz6x/B6bg5wiJrrmtCHJl33k190ih9srm6HmdKVUixig4LITazYytujqouOKPBzNvogyMl8JxC6oDLN/ougQnJD9R2LkI02spWIijw1nJQyMbsUFBOa92aeRV2b5I= 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=CGfGvD/Q; 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="CGfGvD/Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368954; 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=xFedaJf96u/IFmXVEGhrII3ALQIExPZnlCwobbHj5Ck=; b=CGfGvD/Q9jL9wOJs+9Gibvii+16xkTDyDC6M49ZYvMLx476FIlDO91Yzj1Q9p+m/2vjSIW ePGdcgqKjK8UyPXhnGFM2ssjyxC93yPx2CXh0vMr2uWuhYSOwngjmLwhCIaqo24L6AdJZO bQAqq1skdmmKJ51BDKpKFdjU88ZRQ+A= 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-382-2b6pOkKVPKqro4x_LFnWaA-1; Wed, 02 Sep 2026 13:09:11 -0400 X-MC-Unique: 2b6pOkKVPKqro4x_LFnWaA-1 X-Mimecast-MFC-AGG-ID: 2b6pOkKVPKqro4x_LFnWaA_1788368947 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 C3FCC1834577; Wed, 2 Sep 2026 17:09:07 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 613211955D8D; Wed, 2 Sep 2026 17:09: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, "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: Wed, 2 Sep 2026 13:07:30 -0400 Message-ID: <20260902170734.95504-6-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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..05285fae143d 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->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 /** @@ -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 Sat Sep 26 09:16:54 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 3F25F34D382 for ; Wed, 2 Sep 2026 17:09:21 +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=1788368963; cv=none; b=dGTdOvcuy+iCt7oiTrlX8dNmr3kuGMhM5NoVK6GmUM/Rd7yAm37rXgj4mMGT0gXaWlhLrxbYYFqhieqQ028fYCkStFrZHMtiUAXeBjTkngf/M4B44usXq6L+6j3hKgWzhzq8CfJLnUMo+oFpXhcsoDZiTA70N2arLesOoB/AjDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368963; c=relaxed/simple; bh=/mJ/VFztWHR48z3DYcQ4dvuWBy6nrpgsJHggqxQGjcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pPIi1m5EG5m8rKAXwbbAPVWBMrHbVaULOnxhldxAdJ8Txi8+nxpSxx4VwSg66LOL/qlvGRjgbG5WRBCvs9TJSSaX4kDm3qXCrDga9fA4Zu3xVg5NUEbWIqLkQTRqUcEPWPxDQzFUePf5LEvMaHepPMU7CROLqc+Sm6uUi8G0HW4= 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=dIYTIkx9; 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="dIYTIkx9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368960; 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=XkfLLacNfXVi4QGy6SE6uvIGL/VffexPOhZENCjoBGY=; b=dIYTIkx93pwn6PRWH746Ag0WrGh+YmLu+/n7nNoLSrBLsASxGd9HOeI/iUznRQrD8JHOQu ts7FVwWFF7AvAGV6cFi3lnVMp+2tyLIVp9cWGaGtYaI6fAKrr3ZOY/lXozF3ZXWWCB14vF 4IQjwMEEY2hNZnqNkqlK1rBXJlgy41U= 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-636-hveSJt00OyKKU9wPa90llw-1; Wed, 02 Sep 2026 13:09:14 -0400 X-MC-Unique: hveSJt00OyKKU9wPa90llw-1 X-Mimecast-MFC-AGG-ID: hveSJt00OyKKU9wPa90llw_1788368951 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 7313819300FC; Wed, 2 Sep 2026 17:09:11 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 10AA01955D8D; Wed, 2 Sep 2026 17:09: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, "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: Wed, 2 Sep 2026 13:07:31 -0400 Message-ID: <20260902170734.95504-7-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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 05285fae143d..30caa7151750 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 Sat Sep 26 09:16:54 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 904204AE119 for ; Wed, 2 Sep 2026 17:09:22 +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=1788368964; cv=none; b=EVrivl+/lO017G27exHk/DBOjEzz6ktz5UL7ETuHkjs0VrPIHcsuu6rCxCa23g+Yana9rOXJ9hvwpAh+r3iBTc76WiHDVBthi/CufXdJHdAHgUVELAjVTW/QbqVEllKIMlPrvfob0sLlF6XdGBM8MdEUpdNtRTVP6ZLFIfARnGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368964; c=relaxed/simple; bh=+TFumKg4vUw97Pul2ExjPcC44bsRVHJ+Tf9Dy7/Z9m8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xrkelhfk6cJyl5gcqCypAsvvXMzF9gr4hbqzC7nWx7eRRBhpB1GtxG5HGY8dN/NbZjs2B3ar97/3qxZ7GrFfWPY0WpR1ITGMJMT8j+uroG8MaHrWpXFavttmcOGlBBRwaSidYW4Av/WuJRiRsqQeJUyth0OSEvZ+ZXGdMtFPT6s= 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=B4VcIbDq; 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="B4VcIbDq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368961; 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=6VcPgyv1gE40oA19P7nVU/CSABYm1sXHl0KxbrSx48A=; b=B4VcIbDqkfTMbUE14t7RMrKVk3DWQMI7/6x4rdUDTNyZMp+JYZutNwcTCh75v9fnBD+qwL BGXa6vM7J4HmTyUJ02Tvn5MoC8rXkpehwGaRNfFfQcabZr6p2iPCGBL+0wVBZqTmFRh3gw lPTNXR4O8LAJIfyv+88d+8HBaKZKWIA= 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-357-9ohpF6yuO9K3q3jbMtnuDg-1; Wed, 02 Sep 2026 13:09:17 -0400 X-MC-Unique: 9ohpF6yuO9K3q3jbMtnuDg-1 X-Mimecast-MFC-AGG-ID: 9ohpF6yuO9K3q3jbMtnuDg_1788368955 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 09AB8180267F; Wed, 2 Sep 2026 17:09:15 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AF3D11955D8D; Wed, 2 Sep 2026 17:09:11 +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 7/9] PCI: Link a virtual function to its physical function Date: Wed, 2 Sep 2026 13:07:32 -0400 Message-ID: <20260902170734.95504-8-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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 --- 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 Sat Sep 26 09:16:54 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 AF3644AC17C for ; Wed, 2 Sep 2026 17:09:26 +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=1788368968; cv=none; b=LgWZDPhaR2s44+8h0diS3sgKIm+wiuINWQ8KVvj6Sy00QRDUNpo2J2plBw6QGjCY5ffavjnpFCLy963ozAZ9xwZkwki0zhjkdPyLRXv/X2/S2Ctydws7EfrA2NrO10a/+gBsIOP2KnQt/wZWipFH5UzA81VnBHquKAFg643KpPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368968; c=relaxed/simple; bh=Tkmhq7ipcJ4eJBwsM1IcqrP9wqQcBe6egEgtbha4A80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EWk52r4NJzzg1JgPAkFTo4iKIO4JVJG/URM2ey9ayeyomuqF3GkvX559+adjB78wvdKGso9LwNHK3in7GxKYzz4D3iePqmOhZd/KtQDJiMoq5g1wm8z6Il6PVwHPx8WG6JsEbaCVg1jjvNL9HceN/U345PJ9Ypb7eXsmwziWTGI= 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=OSPgVEOX; 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="OSPgVEOX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368965; 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=OSPgVEOX7exVfnqBLyTq8cc8423LCRujipn1TXXIUznQcVo8h8gZuyJf7d3Y0jAeFk6RBO g+JFhOcSYB9SskyYHdXIMOlHfwu48Nz4o2hF0r7BAN9TmjjcnS/sM/hcGexQPN/2Rxetoo p1nkkJx+wKB88KYO6ej3E/x3h/+vLew= 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-9-RlASwZBONFq4QpmPmgESSw-1; Wed, 02 Sep 2026 13:09:22 -0400 X-MC-Unique: RlASwZBONFq4QpmPmgESSw-1 X-Mimecast-MFC-AGG-ID: RlASwZBONFq4QpmPmgESSw_1788368960 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 AF38C1828B88; Wed, 2 Sep 2026 17:09:19 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D9151955D8D; Wed, 2 Sep 2026 17:09:15 +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: Wed, 2 Sep 2026 13:07:33 -0400 Message-ID: <20260902170734.95504-9-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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 Sat Sep 26 09:16:54 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 783BD4AE8C5 for ; Wed, 2 Sep 2026 17:09:31 +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=1788368972; cv=none; b=EULRWx35Oc+kRiws3a+OTdOHFJrS3R2kpYUn94+zmWwBP+Axx9zuG3LoFS7FfChCXXBjifDUYKyVNf2QvdKuJGjM7rE2zLjO0XGQhXO2Mg+jHmHExGt0w3B3U7JVchaykJk7leapRopfNvnjrkS0EzHr4zRg+2qnqBc7CJTQcuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368972; c=relaxed/simple; bh=1XNAjcMfzxS737UbycscQLHar4hJeLnVfG7xL8UK+Sc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kvMMgbufc5fiPtv9ZSuei04Y/Bc2hq80aUpfBy8a07GYNu7DZ8SGDSsi/BUPs4ptUbYCgIVFLFGehjjJncqQP84aooZP9zp3af954McgWlt9hmEgX4euJV58jIJ/OJNGoydhnn7LHiqkQGKbL0RyJo75P5NxZ0OfdxFUP7aI0A0= 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=GPSZOWUO; 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="GPSZOWUO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368970; 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=GPSZOWUOoeKZiEr4i6EH9qHK5GOkdITE6zpjFsZrany7RBChLtP6yRrfWy6hLPIrJsAuIn 4vuX+jsO8HO4YAXSXAum+P2bl/qO1SmzONEziBoVhcoVAPU5assROiNvwoVTzTTkFHGmET CLpj6hSRWXoqTDGukWIqCJZoTE4TJus= 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-550-bn1786veOnyAjry3NGuzPg-1; Wed, 02 Sep 2026 13:09:26 -0400 X-MC-Unique: bn1786veOnyAjry3NGuzPg-1 X-Mimecast-MFC-AGG-ID: bn1786veOnyAjry3NGuzPg_1788368963 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 969BE1953994; Wed, 2 Sep 2026 17:09:23 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DEC121955D8D; Wed, 2 Sep 2026 17:09:19 +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: Wed, 2 Sep 2026 13:07:34 -0400 Message-ID: <20260902170734.95504-10-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-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.0 on 10.30.177.12 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