aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/wait.h
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2014-09-24 04:18:48 -0400
committerIngo Molnar <mingo@kernel.org>2014-10-28 05:55:23 -0400
commite22b886a8a43b147e1994a9f970f678fc0df2033 (patch)
tree72ec37c3bc73f1e2e50bd52d153a7a364d09c3b6 /include/linux/wait.h
parent61ada528dea028331e99e8ceaed87c683ad25de2 (diff)
sched/wait: Add might_sleep() checks
Add more might_sleep() checks, suppose someone put a wait_event() like thing in a wait loop.. Can't put might_sleep() in ___wait_event() because there's the locked primitives which call ___wait_event() with locks held. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: tglx@linutronix.de Cc: ilya.dryomov@inktank.com Cc: umgwanakikbuti@gmail.com Cc: Oleg Nesterov <oleg@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20140924082242.119255706@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux/wait.h')
-rw-r--r--include/linux/wait.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h
index fc0e99395fbb..0421775e0b9f 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -261,6 +261,7 @@ __out: __ret; \
261 */ 261 */
262#define wait_event(wq, condition) \ 262#define wait_event(wq, condition) \
263do { \ 263do { \
264 might_sleep(); \
264 if (condition) \ 265 if (condition) \
265 break; \ 266 break; \
266 __wait_event(wq, condition); \ 267 __wait_event(wq, condition); \
@@ -293,6 +294,7 @@ do { \
293#define wait_event_timeout(wq, condition, timeout) \ 294#define wait_event_timeout(wq, condition, timeout) \
294({ \ 295({ \
295 long __ret = timeout; \ 296 long __ret = timeout; \
297 might_sleep(); \
296 if (!___wait_cond_timeout(condition)) \ 298 if (!___wait_cond_timeout(condition)) \
297 __ret = __wait_event_timeout(wq, condition, timeout); \ 299 __ret = __wait_event_timeout(wq, condition, timeout); \
298 __ret; \ 300 __ret; \
@@ -318,6 +320,7 @@ do { \
318 */ 320 */
319#define wait_event_cmd(wq, condition, cmd1, cmd2) \ 321#define wait_event_cmd(wq, condition, cmd1, cmd2) \
320do { \ 322do { \
323 might_sleep(); \
321 if (condition) \ 324 if (condition) \
322 break; \ 325 break; \
323 __wait_event_cmd(wq, condition, cmd1, cmd2); \ 326 __wait_event_cmd(wq, condition, cmd1, cmd2); \
@@ -345,6 +348,7 @@ do { \
345#define wait_event_interruptible(wq, condition) \ 348#define wait_event_interruptible(wq, condition) \
346({ \ 349({ \
347 int __ret = 0; \ 350 int __ret = 0; \
351 might_sleep(); \
348 if (!(condition)) \ 352 if (!(condition)) \
349 __ret = __wait_event_interruptible(wq, condition); \ 353 __ret = __wait_event_interruptible(wq, condition); \
350 __ret; \ 354 __ret; \
@@ -378,6 +382,7 @@ do { \
378#define wait_event_interruptible_timeout(wq, condition, timeout) \ 382#define wait_event_interruptible_timeout(wq, condition, timeout) \
379({ \ 383({ \
380 long __ret = timeout; \ 384 long __ret = timeout; \
385 might_sleep(); \
381 if (!___wait_cond_timeout(condition)) \ 386 if (!___wait_cond_timeout(condition)) \
382 __ret = __wait_event_interruptible_timeout(wq, \ 387 __ret = __wait_event_interruptible_timeout(wq, \
383 condition, timeout); \ 388 condition, timeout); \
@@ -428,6 +433,7 @@ do { \
428#define wait_event_hrtimeout(wq, condition, timeout) \ 433#define wait_event_hrtimeout(wq, condition, timeout) \
429({ \ 434({ \
430 int __ret = 0; \ 435 int __ret = 0; \
436 might_sleep(); \
431 if (!(condition)) \ 437 if (!(condition)) \
432 __ret = __wait_event_hrtimeout(wq, condition, timeout, \ 438 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
433 TASK_UNINTERRUPTIBLE); \ 439 TASK_UNINTERRUPTIBLE); \
@@ -453,6 +459,7 @@ do { \
453#define wait_event_interruptible_hrtimeout(wq, condition, timeout) \ 459#define wait_event_interruptible_hrtimeout(wq, condition, timeout) \
454({ \ 460({ \
455 long __ret = 0; \ 461 long __ret = 0; \
462 might_sleep(); \
456 if (!(condition)) \ 463 if (!(condition)) \
457 __ret = __wait_event_hrtimeout(wq, condition, timeout, \ 464 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
458 TASK_INTERRUPTIBLE); \ 465 TASK_INTERRUPTIBLE); \
@@ -466,6 +473,7 @@ do { \
466#define wait_event_interruptible_exclusive(wq, condition) \ 473#define wait_event_interruptible_exclusive(wq, condition) \
467({ \ 474({ \
468 int __ret = 0; \ 475 int __ret = 0; \
476 might_sleep(); \
469 if (!(condition)) \ 477 if (!(condition)) \
470 __ret = __wait_event_interruptible_exclusive(wq, condition);\ 478 __ret = __wait_event_interruptible_exclusive(wq, condition);\
471 __ret; \ 479 __ret; \
@@ -640,6 +648,7 @@ do { \
640#define wait_event_killable(wq, condition) \ 648#define wait_event_killable(wq, condition) \
641({ \ 649({ \
642 int __ret = 0; \ 650 int __ret = 0; \
651 might_sleep(); \
643 if (!(condition)) \ 652 if (!(condition)) \
644 __ret = __wait_event_killable(wq, condition); \ 653 __ret = __wait_event_killable(wq, condition); \
645 __ret; \ 654 __ret; \
@@ -891,6 +900,7 @@ extern int bit_wait_io_timeout(struct wait_bit_key *);
891static inline int 900static inline int
892wait_on_bit(void *word, int bit, unsigned mode) 901wait_on_bit(void *word, int bit, unsigned mode)
893{ 902{
903 might_sleep();
894 if (!test_bit(bit, word)) 904 if (!test_bit(bit, word))
895 return 0; 905 return 0;
896 return out_of_line_wait_on_bit(word, bit, 906 return out_of_line_wait_on_bit(word, bit,
@@ -915,6 +925,7 @@ wait_on_bit(void *word, int bit, unsigned mode)
915static inline int 925static inline int
916wait_on_bit_io(void *word, int bit, unsigned mode) 926wait_on_bit_io(void *word, int bit, unsigned mode)
917{ 927{
928 might_sleep();
918 if (!test_bit(bit, word)) 929 if (!test_bit(bit, word))
919 return 0; 930 return 0;
920 return out_of_line_wait_on_bit(word, bit, 931 return out_of_line_wait_on_bit(word, bit,
@@ -941,6 +952,7 @@ wait_on_bit_io(void *word, int bit, unsigned mode)
941static inline int 952static inline int
942wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) 953wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
943{ 954{
955 might_sleep();
944 if (!test_bit(bit, word)) 956 if (!test_bit(bit, word))
945 return 0; 957 return 0;
946 return out_of_line_wait_on_bit(word, bit, action, mode); 958 return out_of_line_wait_on_bit(word, bit, action, mode);
@@ -968,6 +980,7 @@ wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode
968static inline int 980static inline int
969wait_on_bit_lock(void *word, int bit, unsigned mode) 981wait_on_bit_lock(void *word, int bit, unsigned mode)
970{ 982{
983 might_sleep();
971 if (!test_and_set_bit(bit, word)) 984 if (!test_and_set_bit(bit, word))
972 return 0; 985 return 0;
973 return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode); 986 return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode);
@@ -991,6 +1004,7 @@ wait_on_bit_lock(void *word, int bit, unsigned mode)
991static inline int 1004static inline int
992wait_on_bit_lock_io(void *word, int bit, unsigned mode) 1005wait_on_bit_lock_io(void *word, int bit, unsigned mode)
993{ 1006{
1007 might_sleep();
994 if (!test_and_set_bit(bit, word)) 1008 if (!test_and_set_bit(bit, word))
995 return 0; 1009 return 0;
996 return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode); 1010 return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode);
@@ -1016,6 +1030,7 @@ wait_on_bit_lock_io(void *word, int bit, unsigned mode)
1016static inline int 1030static inline int
1017wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) 1031wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
1018{ 1032{
1033 might_sleep();
1019 if (!test_and_set_bit(bit, word)) 1034 if (!test_and_set_bit(bit, word))
1020 return 0; 1035 return 0;
1021 return out_of_line_wait_on_bit_lock(word, bit, action, mode); 1036 return out_of_line_wait_on_bit_lock(word, bit, action, mode);
@@ -1034,6 +1049,7 @@ wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned
1034static inline 1049static inline
1035int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode) 1050int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode)
1036{ 1051{
1052 might_sleep();
1037 if (atomic_read(val) == 0) 1053 if (atomic_read(val) == 0)
1038 return 0; 1054 return 0;
1039 return out_of_line_wait_on_atomic_t(val, action, mode); 1055 return out_of_line_wait_on_atomic_t(val, action, mode);