[PATCH] libcfs: Fix a sleep-in-atomic bug in cfs_percpt_lock and cfs_percpt_unlock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The driver may sleep under a spin lock, and the function call path is:
cfs_percpt_lock/cfs_percpt_unlock (acquire the lock by spin_lock)
  LASSERT
    lbug_with_loc
      libcfs_debug_dumplog
        schedule and kthread_run --> may sleep

To fix it, all "LASSERT" is placed out of the spin_lock and spin_unlock.

Signed-off-by: Jia-Ju Bai <baijiaju1990@xxxxxxx>
---
 drivers/staging/lustre/lnet/libcfs/libcfs_lock.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c b/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c
index 1967b97c..a2ce092f 100644
--- a/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c
+++ b/drivers/staging/lustre/lnet/libcfs/libcfs_lock.c
@@ -113,9 +113,10 @@ struct cfs_percpt_lock *
 
 	/* exclusive lock request */
 	for (i = 0; i < ncpt; i++) {
+		if (!i)
+			LASSERT(!pcl->pcl_locked);
 		spin_lock(pcl->pcl_locks[i]);
 		if (!i) {
-			LASSERT(!pcl->pcl_locked);
 			/* nobody should take private lock after this
 			 * so I wouldn't starve for too long time
 			 */
@@ -141,11 +142,11 @@ struct cfs_percpt_lock *
 	}
 
 	for (i = ncpt - 1; i >= 0; i--) {
-		if (!i) {
-			LASSERT(pcl->pcl_locked);
+		if (!i)
 			pcl->pcl_locked = 0;
-		}
 		spin_unlock(pcl->pcl_locks[i]);
+		if (!i)
+			LASSERT(pcl->pcl_locked);
 	}
 }
 EXPORT_SYMBOL(cfs_percpt_unlock);
-- 
1.7.9.5


_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux