{"id":2225235,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2225235/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260420152608.6244-3-djeffery@redhat.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/1.1/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260420152608.6244-3-djeffery@redhat.com>","date":"2026-04-20T15:26:05","name":"[2/5] driver core: do not always lock parent in shutdown","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f762748dc815dc4117298e7510d7ba530221e588","submitter":{"id":24471,"url":"http://patchwork.ozlabs.org/api/1.1/people/24471/?format=json","name":"David Jeffery","email":"djeffery@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260420152608.6244-3-djeffery@redhat.com/mbox/","series":[{"id":500621,"url":"http://patchwork.ozlabs.org/api/1.1/series/500621/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=500621","date":"2026-04-20T15:26:04","name":"shut down devices asynchronously","version":1,"mbox":"http://patchwork.ozlabs.org/series/500621/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225235/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225235/checks/","tags":{},"headers":{"Return-Path":"\n <linux-pci+bounces-52786-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=ScuDWb8h;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-pci+bounces-52786-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com\n header.b=\"ScuDWb8h\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=170.10.129.124","smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=redhat.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=redhat.com"],"Received":["from sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzsG51LJdz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 03:01:33 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id 4716930EE242\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 15:27:11 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 9BB7C2ED870;\n\tMon, 20 Apr 2026 15:26:50 +0000 (UTC)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 142EC2F3C3E\n\tfor <linux-pci@vger.kernel.org>; Mon, 20 Apr 2026 15:26:47 +0000 (UTC)","from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-ohZyS1s6OyOy4C4sgKJYyw-1; Mon,\n 20 Apr 2026 11:26:43 -0400","from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id AD9A8195605E;\n\tMon, 20 Apr 2026 15:26:32 +0000 (UTC)","from fedora-work.redhat.com (unknown [10.22.65.236])\n\tby mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 5C7D819560B1;\n\tMon, 20 Apr 2026 15:26:28 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776698810; cv=none;\n b=WpcwK6AY2rYnpLylaecfwAFIqT/ZkK5nK8CIlhYe9FSi5enAFVh6Q8jnAwiTs0WTB/xWDuubHeArL/MzwxpGNYkxR4krEKMtuwIJbdAQiRrPsfWB/ENZylpFzJiPgp9GLWt8djJDc3zrAXY2VUemRxw6By7JSoB3nTMChgarhgs=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776698810; c=relaxed/simple;\n\tbh=dATQRFKcNLJjjRyV6a0dyqXpJdGDzEDhkgxOQ+dCuZg=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=LEkoTNvnbwq7gUN5UrjhgauittGeR2D6JILtuRRZ4FZ9S/mXVbPqoiQ5xkHuKTcXBNMGrC5CoGIPmeFAZLNYxz4IBICO0DazeyBC2kH/dvAGENUoK3fw5lKDerDSpkNIRqnhVBCwtpcumhKps2CCCUSLWhmznSxJA6ARwxnUUjY=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=quarantine dis=none) header.from=redhat.com;\n spf=pass smtp.mailfrom=redhat.com;\n dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com\n header.b=ScuDWb8h; arc=none smtp.client-ip=170.10.129.124","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1776698806;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=hcVVsfBQNN9rrh6Uf5d8BNbIQC5J9iqF/mHK2jES+/k=;\n\tb=ScuDWb8hgaPVkwQnDo9Qqqlvf/cosNMic/IbZQjmnQyAjuwIBxLikAJY9zd2lTQB2YIN86\n\tuJIY8qXa7nbzuySDxxVG4Ycqg2uCAO316r5VyoPzZ+nguR39qy7FHalPzZgZId7v6YnjUQ\n\tPqGBGyff1QEGY9ymrTo82fSR6vQqHjo=","X-MC-Unique":"ohZyS1s6OyOy4C4sgKJYyw-1","X-Mimecast-MFC-AGG-ID":"ohZyS1s6OyOy4C4sgKJYyw_1776698792","From":"David Jeffery <djeffery@redhat.com>","To":"linux-kernel@vger.kernel.org,\n\tdriver-core@lists.linux.dev,\n\tlinux-pci@vger.kernel.org,\n\tlinux-scsi@vger.kernel.org,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\t\"Rafael J. Wysocki\" <rafael@kernel.org>,\n\tDanilo Krummrich <dakr@kernel.org>","Cc":"Tarun Sahu <tarunsahu@google.com>, Pasha Tatashin <tatashin@google.com>,\n\t=?utf-8?b?TWljaGHFgiBDxYJhcGnFhHNraQ==?= <mclapinski@google.com>,\n Jordan Richards <jordanrichards@google.com>, Ewan Milne <emilne@redhat.com>,\n John Meneghini <jmeneghi@redhat.com>, \"Lombardi,\n Maurizio\" <mlombard@redhat.com>, Stuart Hayes <stuart.w.hayes@gmail.com>,\n Laurence Oberman <loberman@redhat.com>, Bart Van Assche <bvanassche@acm.org>,\n Bjorn Helgaas <helgaas@kernel.org>,\n \"Martin K . Petersen\" <martin.petersen@oracle.com>,\n John Garry <john.g.garry@oracle.com>, David Jeffery <djeffery@redhat.com>","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-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.12"},"content":"Don't lock a parent device unless it is needed in device_shutdown. This\nis in preparation for making device shutdown asynchronous, when it will\nbe needed to allow children of a common parent to shut down\nsimultaneously.\n\nAnd only acquire a reference to the parent device if the parent is to be\nlocked.\n\nSigned-off-by: Stuart Hayes <stuart.w.hayes@gmail.com>\nSigned-off-by: David Jeffery <djeffery@redhat.com>\nTested-by: Laurence Oberman <loberman@redhat.com>\n---\n drivers/base/core.c | 30 ++++++++++++++++--------------\n 1 file changed, 16 insertions(+), 14 deletions(-)","diff":"diff --git a/drivers/base/core.c b/drivers/base/core.c\nindex 5353c6c22d49..a32fc7141957 100644\n--- a/drivers/base/core.c\n+++ b/drivers/base/core.c\n@@ -4783,13 +4783,8 @@ int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)\n \treturn error;\n }\n \n-static void shutdown_one_device(struct device *dev)\n+static void __shutdown_one_device(struct device *dev)\n {\n-\tstruct device *parent = dev->parent;\n-\n-\t/* hold lock to avoid race with probe/release */\n-\tif (parent)\n-\t\tdevice_lock(parent);\n \tdevice_lock(dev);\n \n \t/* Don't allow any more runtime suspends */\n@@ -4812,10 +4807,23 @@ static void shutdown_one_device(struct device *dev)\n \t}\n \n \tdevice_unlock(dev);\n-\tif (parent)\n+}\n+\n+static void shutdown_one_device(struct device *dev)\n+{\n+\tstruct device *parent;\n+\n+\t/* hold lock if needed to avoid race with probe/release */\n+\tif (dev->bus && dev->bus->need_parent_lock &&\n+\t    (parent = get_device(dev->parent))) {\n+\t\tdevice_lock(parent);\n+\t\t__shutdown_one_device(dev);\n \t\tdevice_unlock(parent);\n+\t\tput_device(parent);\n+\t} else {\n+\t\t__shutdown_one_device(dev);\n+\t}\n \n-\tput_device(parent);\n \tput_device(dev);\n }\n \n@@ -4841,12 +4849,6 @@ void device_shutdown(void)\n \t\tdev = list_entry(devices_kset->list.prev, struct device,\n \t\t\t\tkobj.entry);\n \n-\t\t/*\n-\t\t * hold reference count of device's parent to\n-\t\t * prevent it from being freed because parent's\n-\t\t * lock is to be held\n-\t\t */\n-\t\tget_device(dev->parent);\n \t\tget_device(dev);\n \t\t/*\n \t\t * Make sure the device is off the kset list, in the\n","prefixes":["2/5"]}