Skip to content

Commit 65f666c

Browse files
Ming Leiaxboe
authored andcommitted
lib/sbitmap: define swap_lock as raw_spinlock_t
When called from sbitmap_queue_get(), sbitmap_deferred_clear() may be run with preempt disabled. In RT kernel, spin_lock() can sleep, then warning of "BUG: sleeping function called from invalid context" can be triggered. Fix it by replacing it with raw_spin_lock. Cc: Yang Yang <yang.yang@vivo.com> Fixes: 72d04bd ("sbitmap: fix io hung due to race on sbitmap_word::cleared") Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Yang Yang <yang.yang@vivo.com> Link: https://lore.kernel.org/r/20240919021709.511329-1-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 9ba5dcc commit 65f666c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/linux/sbitmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct sbitmap_word {
4040
/**
4141
* @swap_lock: serializes simultaneous updates of ->word and ->cleared
4242
*/
43-
spinlock_t swap_lock;
43+
raw_spinlock_t swap_lock;
4444
} ____cacheline_aligned_in_smp;
4545

4646
/**

lib/sbitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static inline bool sbitmap_deferred_clear(struct sbitmap_word *map,
6565
{
6666
unsigned long mask, word_mask;
6767

68-
guard(spinlock_irqsave)(&map->swap_lock);
68+
guard(raw_spinlock_irqsave)(&map->swap_lock);
6969

7070
if (!map->cleared) {
7171
if (depth == 0)
@@ -136,7 +136,7 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
136136
}
137137

138138
for (i = 0; i < sb->map_nr; i++)
139-
spin_lock_init(&sb->map[i].swap_lock);
139+
raw_spin_lock_init(&sb->map[i].swap_lock);
140140

141141
return 0;
142142
}

0 commit comments

Comments
 (0)