* [PATCH] sbitmap: Protect swap_lock from softirqs
@ 2019-01-14 17:25 Steven Rostedt
2019-01-14 19:32 ` Linus Torvalds
0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2019-01-14 17:25 UTC (permalink / raw)
To: Jens Axboe
Cc: LKML, Linus Torvalds, Andrew Morton, Peter Zijlstra,
Thomas Gleixner, Ingo Molnar, Clark Williams, Bart Van Assche,
Ming Lei
From: Steven Rostedt (VMware) <rostedt@goodmis.org>
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.
Cc: stable@vger.kernel.org
Reported-by: Clark Williams <williams@redhat.com>
Fixes: 58ab5e32e6fd ("sbitmap: silence bogus lockdep IRQ warning")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index 65c2d06250a6..864354000e04 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -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;
@@ -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;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] sbitmap: Protect swap_lock from softirqs
2019-01-14 17:25 [PATCH] sbitmap: Protect swap_lock from softirqs Steven Rostedt
@ 2019-01-14 19:32 ` Linus Torvalds
0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2019-01-14 19:32 UTC (permalink / raw)
To: Steven Rostedt
Cc: Jens Axboe, LKML, Andrew Morton, Peter Zijlstra, Thomas Gleixner,
Ingo Molnar, Clark Williams, Bart Van Assche, Ming Lei
On Tue, Jan 15, 2019 at 5:25 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> 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.
>
> Cc: stable@vger.kernel.org
Ack and applied, except for the "stable" tag.
Both the original buggy code, and the incorrect "shut up lockdep" were
only merged after 4.20.
Linus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-14 19:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14 17:25 [PATCH] sbitmap: Protect swap_lock from softirqs Steven Rostedt
2019-01-14 19:32 ` Linus Torvalds
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.