Whamcloud - gitweb
LU-6432 libcfs: lock-class for cfs_percpt_lock 68/14368/8
authorLiang Zhen <liang.zhen@intel.com>
Tue, 15 Sep 2015 13:44:54 +0000 (09:44 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 24 Sep 2015 02:34:05 +0000 (02:34 +0000)
initialise lock-class for each sublock of cfs_percpt_lock
to eliminate false alarm ""possible recursive locking detected"

Signed-off-by: Liang Zhen <liang.zhen@intel.com>
Change-Id: I29467e3a21560ff4bb5127ea686dea4f6acfd9a2
Reviewed-on: http://review.whamcloud.com/14368
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/include/libcfs/libcfs_cpu.h
libcfs/libcfs/libcfs_lock.c

index 98832fd..57a4425 100644 (file)
@@ -261,7 +261,8 @@ struct cfs_percpt_lock {
  * create a cpu-partition lock based on CPU partition table \a cptab,
  * each private lock has extra \a psize bytes padding data
  */
-struct cfs_percpt_lock *cfs_percpt_lock_alloc(struct cfs_cpt_table *cptab);
+struct cfs_percpt_lock *cfs_percpt_lock_create(struct cfs_cpt_table *cptab,
+                                              struct lock_class_key *keys);
 /* destroy a cpu-partition lock */
 void cfs_percpt_lock_free(struct cfs_percpt_lock *pcl);
 
@@ -270,6 +271,21 @@ void cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index);
 /* unlock private lock \a index of \a pcl */
 void cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index);
 
+#define CFS_PERCPT_LOCK_KEYS   256
+
+/* NB: don't allocate keys dynamically, lockdep needs them to be in ".data" */
+#define cfs_percpt_lock_alloc(cptab)                                   \
+({                                                                     \
+       static struct lock_class_key  ___keys[CFS_PERCPT_LOCK_KEYS];    \
+       struct cfs_percpt_lock       *___lk;                            \
+                                                                       \
+       if (cfs_cpt_number(cptab) > CFS_PERCPT_LOCK_KEYS)               \
+               ___lk = cfs_percpt_lock_create(cptab, NULL);            \
+       else                                                            \
+               ___lk = cfs_percpt_lock_create(cptab, ___keys);         \
+       ___lk;                                                          \
+})
+
 /**
  * allocate \a nr_bytes of physical memory from a contiguous region with the
  * properties of \a flags which are bound to the partition id \a cpt. This
index dae4287..9087bd4 100644 (file)
@@ -54,7 +54,8 @@ EXPORT_SYMBOL(cfs_percpt_lock_free);
  * reason we always allocate cacheline-aligned memory block.
  */
 struct cfs_percpt_lock *
-cfs_percpt_lock_alloc(struct cfs_cpt_table *cptab)
+cfs_percpt_lock_create(struct cfs_cpt_table *cptab,
+                      struct lock_class_key *keys)
 {
        struct cfs_percpt_lock  *pcl;
        spinlock_t              *lock;
@@ -72,12 +73,20 @@ cfs_percpt_lock_alloc(struct cfs_cpt_table *cptab)
                return NULL;
        }
 
-       cfs_percpt_for_each(lock, i, pcl->pcl_locks)
+       if (keys == NULL) {
+               CWARN("Cannot setup class key for percpt lock, you may see "
+                     "recursive locking warnings which are actually fake.\n");
+       }
+
+       cfs_percpt_for_each(lock, i, pcl->pcl_locks) {
                spin_lock_init(lock);
+               if (keys != NULL)
+                       lockdep_set_class(lock, &keys[i]);
+       }
 
        return pcl;
 }
-EXPORT_SYMBOL(cfs_percpt_lock_alloc);
+EXPORT_SYMBOL(cfs_percpt_lock_create);
 
 /**
  * lock a CPU partition