Whamcloud - gitweb
LU-16807 libcfs: give the tcd_lock types different classes. 92/50992/3
authorMr NeilBrown <neilb@suse.de>
Fri, 20 Nov 2020 02:19:49 +0000 (13:19 +1100)
committerOleg Drokin <green@whamcloud.com>
Wed, 31 May 2023 19:15:01 +0000 (19:15 +0000)
There are three different trace contexts:
   process, softirq, irq.
Each has its own lock (tcd_lock) which is locked as appropriate for
that context.

lockdep currently doesn't see that they are different and so deduces
that the different uses might lead to deadlocks.

So use separate calls to spin_lock_init() so that they each get a
separate lock class, and lockdep sees no problem.

Test-Parameters: trivial testlist=sanity-lnet
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Icca7706d8e0d8ae8add4c540d2da090b53d7e65c
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50992
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/tracefile.c

index d79ec06..e45cf82 100644 (file)
@@ -1140,7 +1140,23 @@ int cfs_tracefile_init(int max_pages)
        cfs_tcd_for_each(tcd, i, j) {
                int factor = pages_factor[i];
 
-               spin_lock_init(&tcd->tcd_lock);
+               /* Note that we have three separate spin_lock_init()
+                * calls so that the locks get three separate classes
+                * and lockdep never thinks they are related.  As they
+                * are used in different interrupt contexts, lockdep
+                * would otherwise think that the usage would conflict.
+                */
+               switch(i) {
+               case CFS_TCD_TYPE_PROC:
+                       spin_lock_init(&tcd->tcd_lock);
+                       break;
+               case CFS_TCD_TYPE_SOFTIRQ:
+                       spin_lock_init(&tcd->tcd_lock);
+                       break;
+               case CFS_TCD_TYPE_IRQ:
+                       spin_lock_init(&tcd->tcd_lock);
+                       break;
+               }
                tcd->tcd_pages_factor = factor;
                tcd->tcd_type = i;
                tcd->tcd_cpu = j;