hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/kernel/locking/rwsem-rt.c
....@@ -1,10 +1,9 @@
1
-/*
2
- */
3
-#include <linux/blkdev.h>
1
+// SPDX-License-Identifier: GPL-2.0-only
42 #include <linux/rwsem.h>
53 #include <linux/sched/debug.h>
64 #include <linux/sched/signal.h>
75 #include <linux/export.h>
6
+#include <linux/blkdev.h>
87
98 #include "rtmutex_common.h"
109
....@@ -88,13 +87,12 @@
8887
8988 if (__down_read_trylock(sem))
9089 return 0;
90
+
9191 /*
92
- * If rt_mutex blocks, the function sched_submit_work will not call
93
- * blk_schedule_flush_plug (because tsk_is_pi_blocked would be true).
94
- * We must call blk_schedule_flush_plug here, if we don't call it,
95
- * a deadlock in I/O may happen.
92
+ * Flush blk before ->pi_blocked_on is set. At schedule() time it is too
93
+ * late if one of the callbacks needs to acquire a sleeping lock.
9694 */
97
- if (unlikely(blk_needs_flush_plug(current)))
95
+ if (blk_needs_flush_plug(current))
9896 blk_schedule_flush_plug(current);
9997
10098 might_sleep();
....@@ -229,6 +227,13 @@
229227 struct rt_mutex *m = &sem->rtmutex;
230228 unsigned long flags;
231229
230
+ /*
231
+ * Flush blk before ->pi_blocked_on is set. At schedule() time it is too
232
+ * late if one of the callbacks needs to acquire a sleeping lock.
233
+ */
234
+ if (blk_needs_flush_plug(current))
235
+ blk_schedule_flush_plug(current);
236
+
232237 /* Take the rtmutex as a first step */
233238 if (__rt_mutex_lock_state(m, state))
234239 return -EINTR;