forked from mirrors/linux
		
	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>
This commit is contained in:
		
							parent
							
								
									61ada528de
								
							
						
					
					
						commit
						e22b886a8a
					
				
					 1 changed files with 16 additions and 0 deletions
				
			
		| 
						 | 
					@ -261,6 +261,7 @@ __out:	__ret;								\
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define wait_event(wq, condition)					\
 | 
					#define wait_event(wq, condition)					\
 | 
				
			||||||
do {									\
 | 
					do {									\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (condition)							\
 | 
						if (condition)							\
 | 
				
			||||||
		break;							\
 | 
							break;							\
 | 
				
			||||||
	__wait_event(wq, condition);					\
 | 
						__wait_event(wq, condition);					\
 | 
				
			||||||
| 
						 | 
					@ -293,6 +294,7 @@ do {									\
 | 
				
			||||||
#define wait_event_timeout(wq, condition, timeout)			\
 | 
					#define wait_event_timeout(wq, condition, timeout)			\
 | 
				
			||||||
({									\
 | 
					({									\
 | 
				
			||||||
	long __ret = timeout;						\
 | 
						long __ret = timeout;						\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (!___wait_cond_timeout(condition))				\
 | 
						if (!___wait_cond_timeout(condition))				\
 | 
				
			||||||
		__ret = __wait_event_timeout(wq, condition, timeout);	\
 | 
							__ret = __wait_event_timeout(wq, condition, timeout);	\
 | 
				
			||||||
	__ret;								\
 | 
						__ret;								\
 | 
				
			||||||
| 
						 | 
					@ -318,6 +320,7 @@ do {									\
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define wait_event_cmd(wq, condition, cmd1, cmd2)			\
 | 
					#define wait_event_cmd(wq, condition, cmd1, cmd2)			\
 | 
				
			||||||
do {									\
 | 
					do {									\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (condition)							\
 | 
						if (condition)							\
 | 
				
			||||||
		break;							\
 | 
							break;							\
 | 
				
			||||||
	__wait_event_cmd(wq, condition, cmd1, cmd2);			\
 | 
						__wait_event_cmd(wq, condition, cmd1, cmd2);			\
 | 
				
			||||||
| 
						 | 
					@ -345,6 +348,7 @@ do {									\
 | 
				
			||||||
#define wait_event_interruptible(wq, condition)				\
 | 
					#define wait_event_interruptible(wq, condition)				\
 | 
				
			||||||
({									\
 | 
					({									\
 | 
				
			||||||
	int __ret = 0;							\
 | 
						int __ret = 0;							\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (!(condition))						\
 | 
						if (!(condition))						\
 | 
				
			||||||
		__ret = __wait_event_interruptible(wq, condition);	\
 | 
							__ret = __wait_event_interruptible(wq, condition);	\
 | 
				
			||||||
	__ret;								\
 | 
						__ret;								\
 | 
				
			||||||
| 
						 | 
					@ -378,6 +382,7 @@ do {									\
 | 
				
			||||||
#define wait_event_interruptible_timeout(wq, condition, timeout)	\
 | 
					#define wait_event_interruptible_timeout(wq, condition, timeout)	\
 | 
				
			||||||
({									\
 | 
					({									\
 | 
				
			||||||
	long __ret = timeout;						\
 | 
						long __ret = timeout;						\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (!___wait_cond_timeout(condition))				\
 | 
						if (!___wait_cond_timeout(condition))				\
 | 
				
			||||||
		__ret = __wait_event_interruptible_timeout(wq,		\
 | 
							__ret = __wait_event_interruptible_timeout(wq,		\
 | 
				
			||||||
						condition, timeout);	\
 | 
											condition, timeout);	\
 | 
				
			||||||
| 
						 | 
					@ -428,6 +433,7 @@ do {									\
 | 
				
			||||||
#define wait_event_hrtimeout(wq, condition, timeout)			\
 | 
					#define wait_event_hrtimeout(wq, condition, timeout)			\
 | 
				
			||||||
({									\
 | 
					({									\
 | 
				
			||||||
	int __ret = 0;							\
 | 
						int __ret = 0;							\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (!(condition))						\
 | 
						if (!(condition))						\
 | 
				
			||||||
		__ret = __wait_event_hrtimeout(wq, condition, timeout,	\
 | 
							__ret = __wait_event_hrtimeout(wq, condition, timeout,	\
 | 
				
			||||||
					       TASK_UNINTERRUPTIBLE);	\
 | 
										       TASK_UNINTERRUPTIBLE);	\
 | 
				
			||||||
| 
						 | 
					@ -453,6 +459,7 @@ do {									\
 | 
				
			||||||
#define wait_event_interruptible_hrtimeout(wq, condition, timeout)	\
 | 
					#define wait_event_interruptible_hrtimeout(wq, condition, timeout)	\
 | 
				
			||||||
({									\
 | 
					({									\
 | 
				
			||||||
	long __ret = 0;							\
 | 
						long __ret = 0;							\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (!(condition))						\
 | 
						if (!(condition))						\
 | 
				
			||||||
		__ret = __wait_event_hrtimeout(wq, condition, timeout,	\
 | 
							__ret = __wait_event_hrtimeout(wq, condition, timeout,	\
 | 
				
			||||||
					       TASK_INTERRUPTIBLE);	\
 | 
										       TASK_INTERRUPTIBLE);	\
 | 
				
			||||||
| 
						 | 
					@ -466,6 +473,7 @@ do {									\
 | 
				
			||||||
#define wait_event_interruptible_exclusive(wq, condition)		\
 | 
					#define wait_event_interruptible_exclusive(wq, condition)		\
 | 
				
			||||||
({									\
 | 
					({									\
 | 
				
			||||||
	int __ret = 0;							\
 | 
						int __ret = 0;							\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (!(condition))						\
 | 
						if (!(condition))						\
 | 
				
			||||||
		__ret = __wait_event_interruptible_exclusive(wq, condition);\
 | 
							__ret = __wait_event_interruptible_exclusive(wq, condition);\
 | 
				
			||||||
	__ret;								\
 | 
						__ret;								\
 | 
				
			||||||
| 
						 | 
					@ -640,6 +648,7 @@ do {									\
 | 
				
			||||||
#define wait_event_killable(wq, condition)				\
 | 
					#define wait_event_killable(wq, condition)				\
 | 
				
			||||||
({									\
 | 
					({									\
 | 
				
			||||||
	int __ret = 0;							\
 | 
						int __ret = 0;							\
 | 
				
			||||||
 | 
						might_sleep();							\
 | 
				
			||||||
	if (!(condition))						\
 | 
						if (!(condition))						\
 | 
				
			||||||
		__ret = __wait_event_killable(wq, condition);		\
 | 
							__ret = __wait_event_killable(wq, condition);		\
 | 
				
			||||||
	__ret;								\
 | 
						__ret;								\
 | 
				
			||||||
| 
						 | 
					@ -891,6 +900,7 @@ extern int bit_wait_io_timeout(struct wait_bit_key *);
 | 
				
			||||||
static inline int
 | 
					static inline int
 | 
				
			||||||
wait_on_bit(void *word, int bit, unsigned mode)
 | 
					wait_on_bit(void *word, int bit, unsigned mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						might_sleep();
 | 
				
			||||||
	if (!test_bit(bit, word))
 | 
						if (!test_bit(bit, word))
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	return out_of_line_wait_on_bit(word, bit,
 | 
						return out_of_line_wait_on_bit(word, bit,
 | 
				
			||||||
| 
						 | 
					@ -915,6 +925,7 @@ wait_on_bit(void *word, int bit, unsigned mode)
 | 
				
			||||||
static inline int
 | 
					static inline int
 | 
				
			||||||
wait_on_bit_io(void *word, int bit, unsigned mode)
 | 
					wait_on_bit_io(void *word, int bit, unsigned mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						might_sleep();
 | 
				
			||||||
	if (!test_bit(bit, word))
 | 
						if (!test_bit(bit, word))
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	return out_of_line_wait_on_bit(word, bit,
 | 
						return out_of_line_wait_on_bit(word, bit,
 | 
				
			||||||
| 
						 | 
					@ -941,6 +952,7 @@ wait_on_bit_io(void *word, int bit, unsigned mode)
 | 
				
			||||||
static inline int
 | 
					static inline int
 | 
				
			||||||
wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
 | 
					wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						might_sleep();
 | 
				
			||||||
	if (!test_bit(bit, word))
 | 
						if (!test_bit(bit, word))
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	return out_of_line_wait_on_bit(word, bit, action, mode);
 | 
						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
 | 
				
			||||||
static inline int
 | 
					static inline int
 | 
				
			||||||
wait_on_bit_lock(void *word, int bit, unsigned mode)
 | 
					wait_on_bit_lock(void *word, int bit, unsigned mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						might_sleep();
 | 
				
			||||||
	if (!test_and_set_bit(bit, word))
 | 
						if (!test_and_set_bit(bit, word))
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode);
 | 
						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)
 | 
				
			||||||
static inline int
 | 
					static inline int
 | 
				
			||||||
wait_on_bit_lock_io(void *word, int bit, unsigned mode)
 | 
					wait_on_bit_lock_io(void *word, int bit, unsigned mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						might_sleep();
 | 
				
			||||||
	if (!test_and_set_bit(bit, word))
 | 
						if (!test_and_set_bit(bit, word))
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode);
 | 
						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)
 | 
				
			||||||
static inline int
 | 
					static inline int
 | 
				
			||||||
wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
 | 
					wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						might_sleep();
 | 
				
			||||||
	if (!test_and_set_bit(bit, word))
 | 
						if (!test_and_set_bit(bit, word))
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	return out_of_line_wait_on_bit_lock(word, bit, action, mode);
 | 
						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
 | 
				
			||||||
static inline
 | 
					static inline
 | 
				
			||||||
int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode)
 | 
					int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						might_sleep();
 | 
				
			||||||
	if (atomic_read(val) == 0)
 | 
						if (atomic_read(val) == 0)
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	return out_of_line_wait_on_atomic_t(val, action, mode);
 | 
						return out_of_line_wait_on_atomic_t(val, action, mode);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue