mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2] libcfs: Fix a sleep-in-atomic bug in cfs_wi_exit
@ 2017-05-31  8:00 Jia-Ju Bai
  2017-05-31 13:39 ` Oleg Drokin
  2017-06-03  8:50 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2017-05-31  8:00 UTC (permalink / raw)
  To: oleg.drokin, andreas.dilger, jsimmons, gregkh, bobijam.xu, dmitry.eremin
  Cc: lustre-devel, devel, linux-kernel, Jia-Ju Bai

The driver may sleep under a spin lock, and the function call path is:
cfs_wi_exit (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 |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c
index dbc2a9b..928d06d 100644
--- a/drivers/staging/lustre/lnet/libcfs/workitem.c
+++ b/drivers/staging/lustre/lnet/libcfs/workitem.c
@@ -111,22 +111,23 @@ struct cfs_wi_sched {
 {
 	LASSERT(!in_interrupt()); /* because we use plain spinlock */
 	LASSERT(!sched->ws_stopping);
+	LASSERT(wi->wi_running);
+	if (wi->wi_scheduled) {
+		LASSERT(!list_empty(&wi->wi_list));
+		LASSERT(sched->ws_nscheduled > 0);
+	}
 
 	spin_lock(&sched->ws_lock);
 
-	LASSERT(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--;
 	}
 
-	LASSERT(list_empty(&wi->wi_list));
-
 	wi->wi_scheduled = 1; /* LBUG future schedule attempts */
 	spin_unlock(&sched->ws_lock);
+
+	LASSERT(list_empty(&wi->wi_list));
 }
 EXPORT_SYMBOL(cfs_wi_exit);
 
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-03 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-31  8:00 [PATCH V2] libcfs: Fix a sleep-in-atomic bug in cfs_wi_exit Jia-Ju Bai
2017-05-31 13:39 ` Oleg Drokin
2017-06-03  8:50 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®