Skip to content

Commit 23722fb

Browse files
sudeep-hollaSuzuki K Poulose
authored andcommitted
coresight: Fix possible deadlock with lock dependency
With lockdeps enabled, we get the following warning: ====================================================== WARNING: possible circular locking dependency detected ------------------------------------------------------ kworker/u12:1/53 is trying to acquire lock: ffff80000adce220 (coresight_mutex){+.+.}-{4:4}, at: coresight_set_assoc_ectdev_mutex+0x3c/0x5c but task is already holding lock: ffff80000add1f60 (ect_mutex){+.+.}-{4:4}, at: cti_probe+0x318/0x394 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (ect_mutex){+.+.}-{4:4}: __mutex_lock_common+0xd8/0xe60 mutex_lock_nested+0x44/0x50 cti_add_assoc_to_csdev+0x4c/0x184 coresight_register+0x2f0/0x314 tmc_probe+0x33c/0x414 -> #0 (coresight_mutex){+.+.}-{4:4}: __lock_acquire+0x1a20/0x32d0 lock_acquire+0x160/0x308 __mutex_lock_common+0xd8/0xe60 mutex_lock_nested+0x44/0x50 coresight_set_assoc_ectdev_mutex+0x3c/0x5c cti_update_conn_xrefs+0x6c/0xf8 cti_probe+0x33c/0x394 other info that might help us debug this: Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(ect_mutex); lock(coresight_mutex); lock(ect_mutex); lock(coresight_mutex); *** DEADLOCK *** 4 locks held by kworker/u12:1/53: #0: ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_one_work+0x1fc/0x63c #1: (deferred_probe_work){+.+.}-{0:0}, at: process_one_work+0x228/0x63c #2: (&dev->mutex){....}-{4:4}, at: __device_attach+0x48/0x1a8 #3: (ect_mutex){+.+.}-{4:4}, at: cti_probe+0x318/0x394 To fix the same, call cti_add_assoc_to_csdev without the holding coresight_mutex and confine the locking while setting the associated ect / cti device using coresight_set_assoc_ectdev_mutex(). Fixes: 177af82 ("coresight: cti: Enable CTI associated with devices") Cc: Mathieu Poirier <[email protected]> Cc: Suzuki K Poulose <[email protected]> Cc: Mike Leach <[email protected]> Cc: Leo Yan <[email protected]> Signed-off-by: Sudeep Holla <[email protected]> Reviewed-by: Mike Leach <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9abf231 commit 23722fb

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,14 +1687,15 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
16871687
ret = coresight_fixup_device_conns(csdev);
16881688
if (!ret)
16891689
ret = coresight_fixup_orphan_conns(csdev);
1690-
if (!ret && cti_assoc_ops && cti_assoc_ops->add)
1691-
cti_assoc_ops->add(csdev);
16921690

16931691
out_unlock:
16941692
mutex_unlock(&coresight_mutex);
16951693
/* Success */
1696-
if (!ret)
1694+
if (!ret) {
1695+
if (cti_assoc_ops && cti_assoc_ops->add)
1696+
cti_assoc_ops->add(csdev);
16971697
return csdev;
1698+
}
16981699

16991700
/* Unregister the device if needed */
17001701
if (registered) {

drivers/hwtracing/coresight/coresight-cti-core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ cti_match_fixup_csdev(struct cti_device *ctidev, const char *node_name,
541541
/*
542542
* Search the cti list to add an associated CTI into the supplied CS device
543543
* This will set the association if CTI declared before the CS device.
544-
* (called from coresight_register() with coresight_mutex locked).
544+
* (called from coresight_register() without coresight_mutex locked).
545545
*/
546546
static void cti_add_assoc_to_csdev(struct coresight_device *csdev)
547547
{
@@ -569,7 +569,8 @@ static void cti_add_assoc_to_csdev(struct coresight_device *csdev)
569569
* if we found a matching csdev then update the ECT
570570
* association pointer for the device with this CTI.
571571
*/
572-
csdev->ect_dev = ect_item->csdev;
572+
coresight_set_assoc_ectdev_mutex(csdev->ect_dev,
573+
ect_item->csdev);
573574
break;
574575
}
575576
}

0 commit comments

Comments
 (0)