Skip to content

Commit fbb564a

Browse files
ChiWu-Zeroaxboe
authored andcommitted
lib/sbitmap: Fix invalid loop in __sbitmap_queue_get_batch()
1. Getting next index before continue branch. 2. Checking free bits when setting the target bits. Otherwise, it may reuse the busying bits. Signed-off-by: wuchi <wuchi.zero@gmail.com> Reviewed-by: Martin Wilck <mwilck@suse.com> Link: https://lore.kernel.org/r/20220605145835.26916-1-wuchi.zero@gmail.com Fixes: 9672b0d ("sbitmap: add __sbitmap_queue_get_batch()") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e531485 commit fbb564a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/sbitmap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
528528

529529
sbitmap_deferred_clear(map);
530530
if (map->word == (1UL << (map_depth - 1)) - 1)
531-
continue;
531+
goto next;
532532

533533
nr = find_first_zero_bit(&map->word, map_depth);
534534
if (nr + nr_tags <= map_depth) {
@@ -539,6 +539,8 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
539539
get_mask = ((1UL << map_tags) - 1) << nr;
540540
do {
541541
val = READ_ONCE(map->word);
542+
if ((val & ~get_mask) != val)
543+
goto next;
542544
ret = atomic_long_cmpxchg(ptr, val, get_mask | val);
543545
} while (ret != val);
544546
get_mask = (get_mask & ~ret) >> nr;
@@ -549,6 +551,7 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
549551
return get_mask;
550552
}
551553
}
554+
next:
552555
/* Jump to next index. */
553556
if (++index >= sb->map_nr)
554557
index = 0;

0 commit comments

Comments
 (0)