From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C40CD3D2FFE for ; Tue, 20 Jan 2026 21:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768943920; cv=none; b=V1nad7hHO+Ldxj+d5nJLOZB+0zvE4FY68RKWCNu490jgYmKNsaA6/bvGDMIMfPpeFYgFmSvTAQmhEc9Rk6dV28FyC5bIa8lTHgrCgbrJ5jWAGLSgMbFPtGRh6G37sM0WY2mea4iDeRVQmNqQVCngRd2HrG4XCnPpAKp37vYGBvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768943920; c=relaxed/simple; bh=MpuVn4+smeVhQJG6XLCjTMMp4ldgAexrPvLkXRYPeQU=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:To:From:Subject: References:In-Reply-To; b=nilkXJ2dWiqD1F2aFuQ1A45qZMaNdF01Uvtypp7ycDMKB55yHe+t7yNLbkWKUvqEvQsIPnj2QFxGMU8IyUd91YH+e+knQMeZPmFpU38hvxHZJqmO9dN4SaqmYMDffY2KN47gw3NfI3Fc8eF7yjaA+ZM0olT9s4W62DcO5aw9neE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iPafgtzA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iPafgtzA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E54CC16AAE; Tue, 20 Jan 2026 21:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768943920; bh=MpuVn4+smeVhQJG6XLCjTMMp4ldgAexrPvLkXRYPeQU=; h=Date:Cc:To:From:Subject:References:In-Reply-To:From; b=iPafgtzAX+/kGYL5NhROgoiU5BqRmt9GsP4Xf2Pa7997yuH5KGQcqtuu/yPsCKTqT nnMr78YKbiG1Vv/CN5JVBVGBcBqimJu55CrC5MNCrfJIVK5+1k3gv2qK6mUbvmKbRz I9pQFdZlX2w0Cx7unjsv4HFFfSzaOJcvGXtvccJ3zSb3Hc7afVpBZz/4RHZOoU/3ny Zl0DH1oS09TfHC4bYn3mock2wl3/mbeCILcZTy89l4dq4EDkDggYToeANSIN4BH5MT ro5LteJqhMYtgHnpaFrEQemAHwNRz4g2ZdNe9T0k+6scr02tiGVTAbT3/G1KMvrsXM 6iV5kUz6Sx0UA== 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 Content-Type: text/plain; charset=UTF-8 Date: Tue, 20 Jan 2026 22:18:36 +0100 Message-Id: Cc: "Gui-Dong Han" , , , , , "Qiu-ji Chen" , , "Marek Szyprowski" To: "Mark Brown" From: "Danilo Krummrich" Subject: Re: [PATCH v5] driver core: enforce device_lock for driver_match_device() References: <20260113162843.12712-1-hanguidong02@gmail.com> <7ae38e31-ef31-43ad-9106-7c76ea0e8596@sirena.org.uk> <4ec6cf46-990e-489c-836e-49124034b67f@sirena.org.uk> <47a4290a-6e5b-4648-b798-e9d967b570b4@sirena.org.uk> In-Reply-To: <47a4290a-6e5b-4648-b798-e9d967b570b4@sirena.org.uk> On Tue Jan 20, 2026 at 9:05 PM CET, Mark Brown wrote: > On Tue, Jan 20, 2026 at 07:36:05PM +0100, Danilo Krummrich wrote: >> On Tue Jan 20, 2026 at 6:38 PM CET, Mark Brown wrote: > >> > I tried lockdep but didn't see anything different. Instrumenting with >> > printk() tells me it's deadlocking trying to attach arm-smmu on Juno >> > (that's a v1 SMMU on this platform), I'll try to poke further but it'l= l >> > likely be tomorrow at the earliest. > >> Maybe the following diff faking the lock for lockdep helps, as it should= keep >> things running, i.e. with this we have the exact same semantics as if we= 'd >> revert the patch (except for the lockdep check of course). > > That does allow us to continue to make progress, the SMMU never manages > to probe AFAICT but we do boot normally. I really would expect a lockdep splat in this case, so I was even about to = ask whether CONFIG_PROVE_LOCKING etc. is enabled. But it's me who messed it up.= I missed that we have lockdep_set_novalidate_class(&dev->mutex). (The fact that the SMMU never manages to probe must be unrelated, i.e. a different issue. Since my diff should be equivalent to a revert of the patc= h, except that it fakes that the mutex has been taken for lockdep.) Anyways, this should work: diff --git a/drivers/base/base.h b/drivers/base/base.h index 677320881af1..4741412d7e46 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -190,8 +190,13 @@ static inline int driver_match_device(const struct dev= ice_driver *drv, static inline int driver_match_device_locked(const struct device_driver *d= rv, struct device *dev) { - guard(device)(dev); - return driver_match_device(drv, dev); + int ret; + + mutex_acquire(&dev->mutex.dep_map, 0, 0, _THIS_IP_); + ret =3D driver_match_device(drv, dev); + mutex_release(&dev->mutex.dep_map, _THIS_IP_); + + return ret; } static inline void dev_sync_state(struct device *dev) diff --git a/drivers/base/core.c b/drivers/base/core.c index 40de2f51a1b1..af270362aeb7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3159,7 +3159,7 @@ void device_initialize(struct device *dev) kobject_init(&dev->kobj, &device_ktype); INIT_LIST_HEAD(&dev->dma_pools); mutex_init(&dev->mutex); - lockdep_set_novalidate_class(&dev->mutex); + //lockdep_set_novalidate_class(&dev->mutex); spin_lock_init(&dev->devres_lock); INIT_LIST_HEAD(&dev->devres_head); device_pm_init(dev);