Skip to content

Commit

Permalink
sbitmap: Protect swap_lock from softirqs
Browse files Browse the repository at this point in the history
The swap_lock used by sbitmap has a chain with locks taken from softirq,
but the swap_lock is not protected from being preempted by softirqs.

A chain exists of:

 sbq->ws[i].wait -> dispatch_wait_lock -> swap_lock

Where the sbq->ws[i].wait lock can be taken from softirq context, which
means all locks below it in the chain must also be protected from
softirqs.

Reported-by: Clark Williams <williams@redhat.com>
Fixes: 58ab5e3 ("sbitmap: silence bogus lockdep IRQ warning")
Fixes: ea86ea2 ("sbitmap: amortize cost of clearing bits")
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Steven Rostedt (VMware) authored and Linus Torvalds committed Jan 14, 2019
1 parent c962cb3 commit 3719876
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/sbitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@
static inline bool sbitmap_deferred_clear(struct sbitmap *sb, int index)
{
unsigned long mask, val;
unsigned long __maybe_unused flags;
bool ret = false;

/* Silence bogus lockdep warning */
#if defined(CONFIG_LOCKDEP)
local_irq_save(flags);
#endif
spin_lock(&sb->map[index].swap_lock);
spin_lock_bh(&sb->map[index].swap_lock);

if (!sb->map[index].cleared)
goto out_unlock;
Expand All @@ -54,10 +49,7 @@ static inline bool sbitmap_deferred_clear(struct sbitmap *sb, int index)

ret = true;
out_unlock:
spin_unlock(&sb->map[index].swap_lock);
#if defined(CONFIG_LOCKDEP)
local_irq_restore(flags);
#endif
spin_unlock_bh(&sb->map[index].swap_lock);
return ret;
}

Expand Down

0 comments on commit 3719876

Please sign in to comment.