From nobody Tue Apr 7 21:49:30 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EA8A371069 for ; Tue, 7 Apr 2026 15:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775576172; cv=none; b=NaBrYBQ4tTx3+vOpDWy7QIt9e3vI8qPvdU4Vd+0i4Q6qa38o4qThnN5u2ZMPnb8P0p2w9lCd5Hzg4g9/P1cpxBPk4PpRkOFJiTXdQJ3dd9VE1oax8WhN4UuxPA4yxLpHUHxbBRQZzCVA7DwdyXW98GKK09RvuGC2vzAMSacZ3WA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775576172; c=relaxed/simple; bh=LwF4g3GgiBopq5VLyCEXnqlJVDeMdGzjLGWlnJ5pbBY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fACxzFV8wCt6l5uTuDwH6Fotad7nhMd/14ekFTfF06nEbjCCvFRBb2qQWQ3dgp7riEkYtOZ7RoaRaQ50/Hdfe52Ksgra5gFNSZu5+Lr01d2QP+77CxSsr3FJSg5XZtyEzf6lNceSzb6A6+0sMu1O7dpovvQ1GFhTmTQrHHgEJA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IZAfxBYg; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IZAfxBYg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775576162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xf8VBa3s5TDbzdGc7YU+V5MBvNbOIU1Be5qZpIougPY=; b=IZAfxBYgMuWZWvRB0atHAwjpvBrF0FB5PeFbKPzEEDMB5JmBbPyA5w3Vn4etUj6p9BEl3t MtO4QKe2soS1GxuUnyj09YydRtQfiGVP0n/kcDp9K2n+RNlgEuILSGOnz3LzZ71eRMqJCN lXS4Hf08aHP7OJZQ9lpGwfjQZ3xpJ00= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-EltgH6WzOTqdn50Q92ivvQ-1; Tue, 07 Apr 2026 11:36:00 -0400 X-MC-Unique: EltgH6WzOTqdn50Q92ivvQ-1 X-Mimecast-MFC-AGG-ID: EltgH6WzOTqdn50Q92ivvQ_1775576158 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1275418005BA; Tue, 7 Apr 2026 15:35:57 +0000 (UTC) Received: from fedora-work.redhat.com (unknown [10.22.80.127]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DCD97180035F; Tue, 7 Apr 2026 15:35:51 +0000 (UTC) From: David Jeffery To: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Tarun Sahu , Pasha Tatashin , =?UTF-8?q?Micha=C5=82=20C=C5=82api=C5=84ski?= , Jordan Richards , Ewan Milne , John Meneghini , "Lombardi, Maurizio" , Stuart Hayes , Laurence Oberman , Bart Van Assche , Bjorn Helgaas , "Martin K . Petersen" , David Jeffery Subject: [PATCH 2/5] driver core: do not always lock parent in shutdown Date: Tue, 7 Apr 2026 11:35:29 -0400 Message-ID: <20260407153532.6395-3-djeffery@redhat.com> In-Reply-To: <20260407153532.6395-1-djeffery@redhat.com> References: <20260407153532.6395-1-djeffery@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" Don't lock a parent device unless it is needed in device_shutdown. This is in preparation for making device shutdown asynchronous, when it will be needed to allow children of a common parent to shut down simultaneously. And only acquire a reference to the parent device if the parent is to be locked. Signed-off-by: Stuart Hayes Signed-off-by: David Jeffery Tested-by: Laurence Oberman --- drivers/base/core.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index fabd17be1175..0fb2f3ccc3bd 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4784,13 +4784,8 @@ int device_change_owner(struct device *dev, kuid_t k= uid, kgid_t kgid) return error; } =20 -static void shutdown_one_device(struct device *dev) +static void __shutdown_one_device(struct device *dev) { - struct device *parent =3D dev->parent; - - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); device_lock(dev); =20 /* Don't allow any more runtime suspends */ @@ -4813,10 +4808,23 @@ static void shutdown_one_device(struct device *dev) } =20 device_unlock(dev); - if (parent) +} + +static void shutdown_one_device(struct device *dev) +{ + struct device *parent; + + /* hold lock if needed to avoid race with probe/release */ + if (dev->bus && dev->bus->need_parent_lock && + (parent =3D get_device(dev->parent))) { + device_lock(parent); + __shutdown_one_device(dev); device_unlock(parent); + put_device(parent); + } else { + __shutdown_one_device(dev); + } =20 - put_device(parent); put_device(dev); } =20 @@ -4842,12 +4850,6 @@ void device_shutdown(void) dev =3D list_entry(devices_kset->list.prev, struct device, kobj.entry); =20 - /* - * hold reference count of device's parent to - * prevent it from being freed because parent's - * lock is to be held - */ - get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the --=20 2.53.0