From mboxrd@z Thu Jan 1 00:00:00 1970 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 AE53E4AA59D for ; Wed, 2 Sep 2026 17:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368951; cv=none; b=msKDHaUqII+LL3GJVB3GN/pswW1wke+li823KSTt5lXVk5iUvpNsOF3Sje/T712T0X8iW1Gw68i07wviVedM2Bszd+cSV5JGFI5/KUKBWRvOJoKJt3qFDLwVwSNcn6PoGg1dTCvctiLon9VEydOp/T8Wc/bEWshKxXdTMNXMXuA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368951; c=relaxed/simple; bh=JNrK/0ub6m0FDk0x2dT/rnm7U5smWJV1A0KGzkCWXGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V1GoZc1pTrjsm5gzSWmhUF5/caHVnZTk0hu62/KirLiMHQ593Q2BVwM+3DPjRiqiyLl/xh7rI3fxZvZQE8ayABuw3FaETCmA7fCKvX7xIW2uBi+xVDRmwHoKR9lwZS0aYLGXNl8wtZRoxe/2gaXzDWsUK9VdIuxwimJxXcfUGGY= 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=Zueahx/V; 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="Zueahx/V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368948; 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=Zueahx/Vd6tcT4h8YQlLZji03NrQY3BfIcLFjlRavsNnYvmq8EXTJ/kFYMTrl655FVTRNE DD+uaR+LvEMicbzOajIJWAe1TzdPjDQ3lNu1N1+45RnDVBL+Gc9qd8dWewMIz/YMD2ReJ/ VxcAgocEE86ID9+gjCidMFgzBFaV7Vc= 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-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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 *new_parent, if (!dev) return -EINVAL; + /* + * 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 = get_device(new_parent); new_parent_kobj = get_device_parent(dev, new_parent); -- 2.55.0