Skip to content

Commit a42ee5e

Browse files
committed
lib/sbitmap: Fix invalid loop in __sbitmap_queue_get_batch()
jira LE-4066 Rebuild_History Non-Buildable kernel-4.18.0-553.72.1.el8_10 commit-author wuchi <wuchi.zero@gmail.com> commit fbb564a 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> (cherry picked from commit fbb564a) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 279a256 commit a42ee5e

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
@@ -527,7 +527,7 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
527527

528528
sbitmap_deferred_clear(map);
529529
if (map->word == (1UL << (map_depth - 1)) - 1)
530-
continue;
530+
goto next;
531531

532532
nr = find_first_zero_bit(&map->word, map_depth);
533533
if (nr + nr_tags <= map_depth) {
@@ -538,6 +538,8 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
538538
get_mask = ((1UL << map_tags) - 1) << nr;
539539
do {
540540
val = READ_ONCE(map->word);
541+
if ((val & ~get_mask) != val)
542+
goto next;
541543
ret = atomic_long_cmpxchg(ptr, val, get_mask | val);
542544
} while (ret != val);
543545
get_mask = (get_mask & ~ret) >> nr;
@@ -548,6 +550,7 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
548550
return get_mask;
549551
}
550552
}
553+
next:
551554
/* Jump to next index. */
552555
if (++index >= sb->map_nr)
553556
index = 0;

0 commit comments

Comments
 (0)