Skip to content

Commit

Permalink
block: fix queue locking verification
Browse files Browse the repository at this point in the history
The new queue_flag_set/clear() functions verify that the queue is
locked, but in doing so they will actually instead oops if the queue
lock hasn't been initialized at all.

So fix the lock debug test to consider the "no lock" case to be
unlocked.  This way you get a nice WARN_ON_ONCE() instead of a fatal
oops.

Bug introduced by commit 75ad23b
("block: make queue flags non-atomic").

Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Nick Piggin <npiggin@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Apr 29, 2008
1 parent 25a0258 commit 8f45c1a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ struct request_queue
#define QUEUE_FLAG_BIDI 9 /* queue supports bidi requests */
#define QUEUE_FLAG_NOMERGES 10 /* disable merge attempts */

static inline int queue_is_locked(struct request_queue *q)
{
spinlock_t *lock = q->queue_lock;
return lock && spin_is_locked(lock);
}

static inline void queue_flag_set_unlocked(unsigned int flag,
struct request_queue *q)
{
Expand All @@ -418,7 +424,7 @@ static inline void queue_flag_set_unlocked(unsigned int flag,

static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
{
WARN_ON_ONCE(!spin_is_locked(q->queue_lock));
WARN_ON_ONCE(!queue_is_locked(q));
__set_bit(flag, &q->queue_flags);
}

Expand All @@ -430,7 +436,7 @@ static inline void queue_flag_clear_unlocked(unsigned int flag,

static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
{
WARN_ON_ONCE(!spin_is_locked(q->queue_lock));
WARN_ON_ONCE(!queue_is_locked(q));
__clear_bit(flag, &q->queue_flags);
}

Expand Down

0 comments on commit 8f45c1a

Please sign in to comment.