Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1653935 > unrolled thread

[PATCH] libcfs: Fix a sleep-in-atomic bug in cfs_wi_deschedule

Started byJia-Ju Bai <baijiaju1990@163.com>
First post2017-05-31 09:50 +0200
Last post2017-05-31 09:50 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] libcfs: Fix a sleep-in-atomic bug in cfs_wi_deschedule Jia-Ju Bai <baijiaju1990@163.com> - 2017-05-31 09:50 +0200

#1653935 — [PATCH] libcfs: Fix a sleep-in-atomic bug in cfs_wi_deschedule

FromJia-Ju Bai <baijiaju1990@163.com>
Date2017-05-31 09:50 +0200
Subject[PATCH] libcfs: Fix a sleep-in-atomic bug in cfs_wi_deschedule
Message-ID<tN6yd-1Qs-5@gated-at.bofh.it>
The driver may sleep under a spin lock, and the function call path is:
cfs_wi_deschedule (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@163.com>
---
 drivers/staging/lustre/lnet/libcfs/workitem.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c
index dbc2a9b..7e25eb9 100644
--- a/drivers/staging/lustre/lnet/libcfs/workitem.c
+++ b/drivers/staging/lustre/lnet/libcfs/workitem.c
@@ -140,6 +140,11 @@ struct cfs_wi_sched {
 
 	LASSERT(!in_interrupt()); /* because we use plain spinlock */
 	LASSERT(!sched->ws_stopping);
+	if (wi->wi_scheduled) {
+		LASSERT(!list_empty(&wi->wi_list));
+		LASSERT(sched->ws_nscheduled > 0);
+	}
+	LASSERT(list_empty(&wi->wi_list));
 
 	/*
 	 * return 0 if it's running already, otherwise return 1, which
@@ -151,17 +156,11 @@ struct cfs_wi_sched {
 	rc = !(wi->wi_running);
 
 	if (wi->wi_scheduled) { /* cancel pending schedules */
-		LASSERT(!list_empty(&wi->wi_list));
 		list_del_init(&wi->wi_list);
-
-		LASSERT(sched->ws_nscheduled > 0);
 		sched->ws_nscheduled--;
-
 		wi->wi_scheduled = 0;
 	}
 
-	LASSERT(list_empty(&wi->wi_list));
-
 	spin_unlock(&sched->ws_lock);
 	return rc;
 }
-- 
1.7.9.5

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web