From nobody Tue Jun 16 19:32:35 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 CCB3F2D3A7C for ; Mon, 20 Apr 2026 15:26:39 +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=1776698801; cv=none; b=eOvo5eVn2VqCS+S11+Usfxz93mDylLIV/twVar66938wVRYChXq7r2iolTQ71bQ92t7G2gcbCPWx0cdY+Bm0LLKfGjgwu1E3tBT987TNpaHEo6j705RSYtxTfGZwxQtchMWJA2xLk31DT+s9WOAa1W5VVj7MLnwIL8NfvXQ/YYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776698801; c=relaxed/simple; bh=q+nfGdplbvQfboPdGnfM+qYt03BBKoSZgEfNKxAkmds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aPCS5eZXHHnSXB164qpzZatAIqCqFPVGtcRTP4cCCS47V5YQFn5p3KaH+TgNn1taI6+rnSrr8vVGJNGvLc06tyS54+GIAdlHAMGjyGJK8G6Y8NWHqMjnwpjqmWE/Zy/eBXg1HDMUSDS0naQKBmi8y2eP3pM2NOsp6b6+uVjDekU= 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=cDS2VcEZ; 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="cDS2VcEZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776698799; 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=lcIN1MIk0jsEfgbrlTzOCbftwfcBA0O12oRAeg/mS04=; b=cDS2VcEZIKax3kcKilpjbd33+rREybKtb8obwfnWPsLX7+DdfwW2kJ4UTbPm/+0lm2sbvA e9aq6cXrJyMjh2atedmCPA1SSczuRqAbUJ+fGzBQwTk1EiiooBJZcpllLF+QhiE17OX75r 0RjeJ18b3DtDms90ICSDhZ0Av3bLvcU= 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-20-8RAE0JxiPTCvPmKMtmBm-Q-1; Mon, 20 Apr 2026 11:26:35 -0400 X-MC-Unique: 8RAE0JxiPTCvPmKMtmBm-Q-1 X-Mimecast-MFC-AGG-ID: 8RAE0JxiPTCvPmKMtmBm-Q_1776698788 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 0C1C819560AE; Mon, 20 Apr 2026 15:26:28 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EAB4F19560B1; Mon, 20 Apr 2026 15:26:23 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , David Jeffery Subject: [PATCH 1/5] driver core: separate function to shutdown one device Date: Mon, 20 Apr 2026 11:26:04 -0400 Message-ID: <20260420152608.6244-2-djeffery@redhat.com> In-Reply-To: <20260420152608.6244-1-djeffery@redhat.com> References: <20260420152608.6244-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 =20 --- drivers/base/core.c | 71 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 0613de0fbe44..5353c6c22d49 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4783,12 +4783,48 @@ int device_change_owner(struct device *dev, kuid_t = kuid, kgid_t kgid) return error; } =20 +static void shutdown_one_device(struct device *dev) +{ + struct device *parent =3D dev->parent; + + /* hold lock to avoid race with probe/release */ + if (parent) + device_lock(parent); + device_lock(dev); + + /* Don't allow any more runtime suspends */ + pm_runtime_get_noresume(dev); + pm_runtime_barrier(dev); + + if (dev->class && dev->class->shutdown_pre) { + if (initcall_debug) + dev_info(dev, "shutdown_pre\n"); + dev->class->shutdown_pre(dev); + } + if (dev->bus && dev->bus->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->bus->shutdown(dev); + } else if (dev->driver && dev->driver->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->driver->shutdown(dev); + } + + device_unlock(dev); + if (parent) + device_unlock(parent); + + put_device(parent); + put_device(dev); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ void device_shutdown(void) { - struct device *dev, *parent; + struct device *dev; =20 wait_for_device_probe(); device_block_probing(); @@ -4810,7 +4846,7 @@ void device_shutdown(void) * prevent it from being freed because parent's * lock is to be held */ - parent =3D get_device(dev->parent); + get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the @@ -4819,36 +4855,7 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); =20 - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); - - /* Don't allow any more runtime suspends */ - pm_runtime_get_noresume(dev); - pm_runtime_barrier(dev); - - if (dev->class && dev->class->shutdown_pre) { - if (initcall_debug) - dev_info(dev, "shutdown_pre\n"); - dev->class->shutdown_pre(dev); - } - if (dev->bus && dev->bus->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->bus->shutdown(dev); - } else if (dev->driver && dev->driver->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->driver->shutdown(dev); - } - - device_unlock(dev); - if (parent) - device_unlock(parent); - - put_device(dev); - put_device(parent); + shutdown_one_device(dev); =20 spin_lock(&devices_kset->list_lock); } --=20 2.53.0 From nobody Tue Jun 16 19:32:35 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 5109E2F7AD2 for ; Mon, 20 Apr 2026 15:26:51 +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=1776698814; cv=none; b=Iwgf4eT2xgQ27o2O+MS7UI8y+zo9aNPNvw+kRcKqaPG5ttKJPvgz68qR/zF5CO24GqSXcqKy5xV7j3KvCy6aDnmq5HVUI45DvIwFYIPjkRWS65EUW6Xlv1b+lGmRfkhREFdBOpqPGzdB+MVMTB2vi7rPoitF2a9S3NwLMI0wAQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776698814; c=relaxed/simple; bh=dATQRFKcNLJjjRyV6a0dyqXpJdGDzEDhkgxOQ+dCuZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LyhlVlD5YGA2a7P7GqNxpTReZ60HuJqhBZRLYrdsPSA4iyKy/tnkkphfgS0FvmIN9A6IsLp7heRW7gl9yiw+xSFjquNDfJwCZ1jCyxhoLUPozTV0ZaGbm8T+AdShxON+6drgOSMjZEO96Q6acMAhwW4rExqZQti3jsX9WyYW2Cg= 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=AJfGaumX; 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="AJfGaumX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776698808; 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=hcVVsfBQNN9rrh6Uf5d8BNbIQC5J9iqF/mHK2jES+/k=; b=AJfGaumXCrqqAncqHgt3IpLpwSHDmkkv0GdtQ9muYBjd00eeum1IqvdGB0pARgW7XUArDS cssX4Zdcq68UmQjvMBxu/2CFUY7f3zf7nR5Ewls3KZxj3Hcg6egUWRg/gR5wsYf+ORwHMA cdFIXAHr66yi8GgVSgsMGD+4LlnYUz4= 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-661-ohZyS1s6OyOy4C4sgKJYyw-1; Mon, 20 Apr 2026 11:26:43 -0400 X-MC-Unique: ohZyS1s6OyOy4C4sgKJYyw-1 X-Mimecast-MFC-AGG-ID: ohZyS1s6OyOy4C4sgKJYyw_1776698792 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 AD9A8195605E; Mon, 20 Apr 2026 15:26:32 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5C7D819560B1; Mon, 20 Apr 2026 15:26:28 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , David Jeffery Subject: [PATCH 2/5] driver core: do not always lock parent in shutdown Date: Mon, 20 Apr 2026 11:26:05 -0400 Message-ID: <20260420152608.6244-3-djeffery@redhat.com> In-Reply-To: <20260420152608.6244-1-djeffery@redhat.com> References: <20260420152608.6244-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 Tested-by: Laurence Oberman Reviewed-by: Martin K. Petersen --- drivers/base/core.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 5353c6c22d49..a32fc7141957 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4783,13 +4783,8 @@ int device_change_owner(struct device *dev, kuid_t k= uid, kgid_t kgid) return error; } =20 -static void shutdown_one_device(struct device *dev) +static void __shutdown_one_device(struct device *dev) { - struct device *parent =3D dev->parent; - - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); device_lock(dev); =20 /* Don't allow any more runtime suspends */ @@ -4812,10 +4807,23 @@ static void shutdown_one_device(struct device *dev) } =20 device_unlock(dev); - if (parent) +} + +static void shutdown_one_device(struct device *dev) +{ + struct device *parent; + + /* hold lock if needed to avoid race with probe/release */ + if (dev->bus && dev->bus->need_parent_lock && + (parent =3D get_device(dev->parent))) { + device_lock(parent); + __shutdown_one_device(dev); device_unlock(parent); + put_device(parent); + } else { + __shutdown_one_device(dev); + } =20 - put_device(parent); put_device(dev); } =20 @@ -4841,12 +4849,6 @@ void device_shutdown(void) dev =3D list_entry(devices_kset->list.prev, struct device, kobj.entry); =20 - /* - * hold reference count of device's parent to - * prevent it from being freed because parent's - * lock is to be held - */ - get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the --=20 2.53.0 From nobody Tue Jun 16 19:32:35 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 4B8822D47FF for ; Mon, 20 Apr 2026 15:26:50 +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=1776698815; cv=none; b=EWDRAJ208JABVaKSdQXBIkjTPoVy/cvhl/rs9yAGJeuZt31wo2ZxL7KDd9DOjxuYbB4JqHA//+4XLFROH5HZC2+sk9qkNKceEIowaIHv5YqHW2Xl5u5VNJAe67MLqJs67kEkfXscYDh8y4i/vpt1LwBtmg8BnXypsqgPvY4IgUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776698815; c=relaxed/simple; bh=O30oSc4d6sJlnbWft49fam2+wUGO4ozeEfpz38lhXhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dBuaZepAF7XLttZZHeYJLTSVBTP41ytgdLe9XWqGdh7meXPkFItHMh5iZbRFJcopi23jMBJ4XZj+T1ABAZJktAu4g00MAFAODr3WvT5YC0fNU8cF7OKu097rEDEj35U7pSHwcBSVF3JYvDHG7MrKNcgskjWxDVmwZTXyfw+HPak= 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=iUCuABMw; 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="iUCuABMw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776698809; 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=cQ5AT1tbzICKr3jOKLeamrF5qJVCjqopcrnJXPTkUYk=; b=iUCuABMwor7YoOcO+kb95jUaEKyma6gcJfnLCO6shnrFDANJei6dPQLpFuhf+MbDw3PvjE KMcZ5E09u3Nke2rAiRR86IG3WEIkMrYDUh6hr24diuNZjW9ptB2dAYpj1lvCYEXsHgEM7R 6h45JKUQZa7OZWuICEoEGrtGlML16Ww= 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-626-PBUATNn4NMiljq0Z2UR1Qw-1; Mon, 20 Apr 2026 11:26:44 -0400 X-MC-Unique: PBUATNn4NMiljq0Z2UR1Qw-1 X-Mimecast-MFC-AGG-ID: PBUATNn4NMiljq0Z2UR1Qw_1776698796 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 BDCFA1800473; Mon, 20 Apr 2026 15:26:36 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1494519560AB; Mon, 20 Apr 2026 15:26:32 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , David Jeffery Subject: [PATCH 3/5] driver core: async device shutdown infrastructure Date: Mon, 20 Apr 2026 11:26:06 -0400 Message-ID: <20260420152608.6244-4-djeffery@redhat.com> In-Reply-To: <20260420152608.6244-1-djeffery@redhat.com> References: <20260420152608.6244-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. Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Tested-by: Laurence Oberman Reviewed-by: Martin K. Petersen --- drivers/base/base.h | 2 + drivers/base/core.c | 101 ++++++++++++++++++++++++++++++++++++++++- include/linux/device.h | 13 ++++++ 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 1af95ac68b77..cd435adeeac5 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -113,6 +113,7 @@ struct driver_type { * @device - pointer back to the struct device that this structure is * associated with. * @driver_type - The type of the bound Rust driver. + * @complete - completion for device shutdown ordering * @dead - This device is currently either in the process of or has been * removed from the system. Any asynchronous events scheduled for this * device should exit without taking any action. @@ -132,6 +133,7 @@ struct device_private { #ifdef CONFIG_RUST struct driver_type driver_type; #endif + struct completion complete; u8 dead:1; }; #define to_device_private_parent(obj) \ diff --git a/drivers/base/core.c b/drivers/base/core.c index a32fc7141957..2319c643b11f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include #include @@ -37,6 +38,10 @@ #include "physical_location.h" #include "power/power.h" =20 +static bool async_shutdown =3D true; +module_param(async_shutdown, bool, 0644); +MODULE_PARM_DESC(async_shutdown, "Enable asynchronous device shutdown supp= ort"); + /* Device links support. */ static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count =3D 1; @@ -3539,6 +3544,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 @@ -4783,6 +4789,37 @@ int device_change_owner(struct device *dev, kuid_t k= uid, kgid_t kgid) return error; } =20 +static bool wants_async_shutdown(struct device *dev) +{ + return async_shutdown && dev->async_shutdown; +} + +static int wait_for_device_shutdown(struct device *dev, void *data) +{ + bool async =3D *(bool *)data; + + if (async || wants_async_shutdown(dev)) + wait_for_completion(&dev->p->complete); + + return 0; +} + +static void wait_for_shutdown_dependencies(struct device *dev, bool async) +{ + struct device_link *link; + int idx; + + device_for_each_child(dev, &async, wait_for_device_shutdown); + + idx =3D device_links_read_lock(); + + dev_for_each_link_to_consumer(link, dev) + if (!device_link_flag_is_sync_state_only(link->flags)) + wait_for_device_shutdown(link->consumer, &async); + + device_links_read_unlock(idx); +} + static void __shutdown_one_device(struct device *dev) { device_lock(dev); @@ -4806,6 +4843,8 @@ static void __shutdown_one_device(struct device *dev) dev->driver->shutdown(dev); } =20 + complete_all(&dev->p->complete); + device_unlock(dev); } =20 @@ -4827,6 +4866,55 @@ static void shutdown_one_device(struct device *dev) put_device(dev); } =20 +static void async_shutdown_handler(void *data, async_cookie_t cookie) +{ + struct device *dev =3D data; + + wait_for_shutdown_dependencies(dev, true); + shutdown_one_device(dev); +} + +static bool shutdown_device_async(struct device *dev) +{ + if (async_schedule_dev_nocall(async_shutdown_handler, dev)) + return true; + return false; +} + + +static void early_async_shutdown_devices(void) +{ + struct device *dev, *next, *needs_put =3D NULL; + + if (!async_shutdown) + return; + + spin_lock(&devices_kset->list_lock); + + list_for_each_entry_safe_reverse(dev, next, &devices_kset->list, + kobj.entry) { + if (wants_async_shutdown(dev)) { + get_device(dev); + + if (shutdown_device_async(dev)) { + list_del_init(&dev->kobj.entry); + } else { + /* + * async failed, clean up extra references + * and run from the standard shutdown loop + */ + needs_put =3D dev; + break; + } + } + } + + spin_unlock(&devices_kset->list_lock); + + if (needs_put) + put_device(needs_put); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ @@ -4839,6 +4927,12 @@ void device_shutdown(void) =20 cpufreq_suspend(); =20 + /* + * Start async device threads where possible to maximize potential + * parallelism and minimize false dependency on unrelated sync devices + */ + early_async_shutdown_devices(); + spin_lock(&devices_kset->list_lock); /* * Walk the devices list backward, shutting down each in turn. @@ -4857,11 +4951,16 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); =20 - shutdown_one_device(dev); + if (!wants_async_shutdown(dev) || !shutdown_device_async(dev)) { + wait_for_shutdown_dependencies(dev, false); + shutdown_one_device(dev); + } =20 spin_lock(&devices_kset->list_lock); } spin_unlock(&devices_kset->list_lock); + + async_synchronize_full(); } =20 /* diff --git a/include/linux/device.h b/include/linux/device.h index e65d564f01cd..cdc890e5d6ae 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -553,6 +553,8 @@ struct device_physical_location { * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. * @dma_iommu: Device is using default IOMMU implementation for DMA and * doesn't rely on dma_ops structure. + * @async_shutdown: Device shutdown may be run asynchronously and in paral= lel + * to the shutdown of unrelated devices * * At the lowest level, every device in a Linux system is represented by an * instance of struct device. The device structure contains the information @@ -675,6 +677,7 @@ struct device { #ifdef CONFIG_IOMMU_DMA bool dma_iommu:1; #endif + bool async_shutdown:1; }; =20 /** @@ -878,6 +881,16 @@ static inline bool device_async_suspend_enabled(struct= device *dev) return !!dev->power.async_suspend; } =20 +static inline void device_enable_async_shutdown(struct device *dev) +{ + dev->async_shutdown =3D true; +} + +static inline bool device_async_shutdown_enabled(struct device *dev) +{ + return !!dev->async_shutdown; +} + static inline bool device_pm_not_required(struct device *dev) { return dev->power.no_pm; --=20 2.53.0 From nobody Tue Jun 16 19:32:35 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 356D83009C7 for ; Mon, 20 Apr 2026 15:26:53 +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=1776698817; cv=none; b=WS4gy2unBx6ccW6WI3o1vB21hhzkA6fr21WKQ6mNS2i25XSU+hVvSi4+sRYcoXYv/Bzdxr6cMMZGh9KVycav328vdv7o7eHWTOjELBeTquVb+EE4vySPTFSHJbfAj4+B3wNEKCGhKXGgG/6ItpNV0A7cn/Vo/5rhD1Ts+HCJrjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776698817; c=relaxed/simple; bh=4vvr+xDrAWxMxjnNh4nkvtXpBMA19u1S8MdxP1fEm4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P43R+U8zio6wtj2+CMW6lIM7rjXtPJHG0wApORiI/BpKZavqOwah5ZrvoRCQ/LGrdDgPbFZv5tSRRIEUA056frBtXja+Bc4SpGqYo7XkONca7k/HmG7L3UH12/cxdh9BB03hCf1aKt/Fu+l1n5NZjcQx/v0BvOT9NgS2bq3CJBE= 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=S42aLlRO; 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="S42aLlRO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776698812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jQvaSb3MuBGeMbb7vK8Mg571zM++WUT9vxPRh2XvaDA=; b=S42aLlRO5icvq1GT38VEUyT5td+13VdnYwBSx9IFmHLx4gSoRKff9V7Nu3xZVTw993/Mom 0gHVtWkjGBQvfeIa+3Y37+NmNmCeB1TC2lzFhKZtNPIAQguQh51Rg2Ucz1CIK7ZFNWduFw W9y7Needy2zeWTosC/4RqD9oZiXTvA8= 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-694-L-DnokiiM0SANo03j7vmxQ-1; Mon, 20 Apr 2026 11:26:48 -0400 X-MC-Unique: L-DnokiiM0SANo03j7vmxQ-1 X-Mimecast-MFC-AGG-ID: L-DnokiiM0SANo03j7vmxQ_1776698803 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 AF88218005A8; Mon, 20 Apr 2026 15:26:41 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 162C719560AB; Mon, 20 Apr 2026 15:26:36 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , David Jeffery Subject: [PATCH 4/5] PCI: Enable async shutdown support Date: Mon, 20 Apr 2026 11:26:07 -0400 Message-ID: <20260420152608.6244-5-djeffery@redhat.com> In-Reply-To: <20260420152608.6244-1-djeffery@redhat.com> References: <20260420152608.6244-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 --- drivers/pci/probe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index bccc7a4bdd79..4d98bab2163d 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1040,6 +1040,7 @@ static int pci_register_host_bridge(struct pci_host_b= ridge *bridge) =20 bus->bridge =3D get_device(&bridge->dev); device_enable_async_suspend(bus->bridge); + device_enable_async_shutdown(bus->bridge); pci_set_bus_of_node(bus); pci_set_bus_msi_domain(bus); if (bridge->msi_domain && !dev_get_msi_domain(&bus->dev) && @@ -2749,6 +2750,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_b= us *bus) pci_reassigndev_resource_alignment(dev); =20 pci_init_capabilities(dev); + device_enable_async_shutdown(&dev->dev); =20 /* * Add the device to our list of discovered devices --=20 2.53.0 From nobody Tue Jun 16 19:32:35 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 29F052FF66B for ; Mon, 20 Apr 2026 15:26:53 +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=1776698817; cv=none; b=jK5Tw9lhxWZ4J1CoWZPcet7nyVTGUGJsE6FTpK7iMxxIAYN3QDq2fLIl4y0yWbORjFsPvr2+aE1+a4X9ma56FF/9gtMYdZ6wOdD+9J0DApq3QBxIny1lZW8ooFYLWCX0Tq+morgkB/ZHYJHxo02kBFAfqRlEeTAepudrJevE/fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776698817; c=relaxed/simple; bh=DzGol+6Akg4BS/3rp1hfdfeLhb/Fbpu33lbWAn59wTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XeOuZs3sZwvr6SmSIN7NSXysSJ6jFvU9jSTpCcFEPHB6Mifu/la0G8+YnBq3u5YmZvxfE+V2cju1rmXDd3qj3Yi+XsSIBMUeMV0vBFxp3AzzCJK790lBZ7Y7H5a8EiWbCVtNz2cmIoC2rcmfwe34Vk1xoTCzNHq4k+woSUMaLWA= 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=Bzkbh3C/; 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="Bzkbh3C/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776698812; 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=OgXV8AVk24uZfipI0TCJZI2aNjRQXAU7ezMkj9ylv7U=; b=Bzkbh3C/fBWAZefDHR+TAAS6HRc6egR+VQl1zNqRO744xWie9SGVLW0oF4/WWNsFUC48xG tJ4A/J/sUQ+j09zMtQ+Ndzihk17YBtJ4Py7uvyJQ28lUXcsGmDHFiuFQ93kDDaPpZaKtOo 9Dhxctl6xjNLfxVB6Y/HblbIJuccIL4= 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-347-Y3tIG8GJMZqpjQl-iCmzxg-1; Mon, 20 Apr 2026 11:26:49 -0400 X-MC-Unique: Y3tIG8GJMZqpjQl-iCmzxg-1 X-Mimecast-MFC-AGG-ID: Y3tIG8GJMZqpjQl-iCmzxg_1776698806 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 DEA1419560B9; Mon, 20 Apr 2026 15:26:45 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.65.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0128B19560AB; Mon, 20 Apr 2026 15:26:41 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , John Garry , David Jeffery Subject: [PATCH 5/5] scsi: Enable async shutdown support Date: Mon, 20 Apr 2026 11:26:08 -0400 Message-ID: <20260420152608.6244-6-djeffery@redhat.com> In-Reply-To: <20260420152608.6244-1-djeffery@redhat.com> References: <20260420152608.6244-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: John Garry Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin --- drivers/scsi/hosts.c | 2 ++ drivers/scsi/scsi_sysfs.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index e047747d4ecf..471b5ce878b0 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -273,6 +273,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, pm_runtime_set_active(&shost->shost_gendev); pm_runtime_enable(&shost->shost_gendev); device_enable_async_suspend(&shost->shost_gendev); + device_enable_async_shutdown(&shost->shost_gendev); =20 error =3D device_add(&shost->shost_gendev); if (error) @@ -282,6 +283,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, get_device(shost->shost_gendev.parent); =20 device_enable_async_suspend(&shost->shost_dev); + device_enable_async_shutdown(&shost->shost_dev); =20 get_device(&shost->shost_gendev); error =3D device_add(&shost->shost_dev); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 6b8c5c05f294..0d450036236e 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1370,6 +1370,7 @@ static int scsi_target_add(struct scsi_target *starge= t) pm_runtime_set_active(&starget->dev); pm_runtime_enable(&starget->dev); device_enable_async_suspend(&starget->dev); + device_enable_async_shutdown(&starget->dev); =20 return 0; } @@ -1396,6 +1397,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) transport_configure_device(&starget->dev); =20 device_enable_async_suspend(&sdev->sdev_gendev); + device_enable_async_shutdown(&sdev->sdev_gendev); scsi_autopm_get_target(starget); pm_runtime_set_active(&sdev->sdev_gendev); if (!sdev->rpm_autosuspend) @@ -1415,6 +1417,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) } =20 device_enable_async_suspend(&sdev->sdev_dev); + device_enable_async_shutdown(&sdev->sdev_dev); error =3D device_add(&sdev->sdev_dev); if (error) { sdev_printk(KERN_INFO, sdev, --=20 2.53.0