Skip to content

Commit

Permalink
lib/sbitmap: define swap_lock as raw_spinlock_t
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: 72d04bd ("sbitmap: fix io hung due to race on sbitmap_word::cleared")
Signed-off-by: Ming Lei <[email protected]>
Reviewed-by: Yang Yang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Ming Lei authored and axboe committed Sep 20, 2024
1 parent 9ba5dcc commit 65f666c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/linux/sbitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct sbitmap_word {
/**
* @swap_lock: serializes simultaneous updates of ->word and ->cleared
*/
spinlock_t swap_lock;
raw_spinlock_t swap_lock;
} ____cacheline_aligned_in_smp;

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/sbitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static inline bool sbitmap_deferred_clear(struct sbitmap_word *map,
{
unsigned long mask, word_mask;

guard(spinlock_irqsave)(&map->swap_lock);
guard(raw_spinlock_irqsave)(&map->swap_lock);

if (!map->cleared) {
if (depth == 0)
Expand Down Expand Up @@ -136,7 +136,7 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
}

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

return 0;
}
Expand Down

0 comments on commit 65f666c

Please sign in to comment.