Skip to content

Commit 5a7fde5

Browse files
committed
sbitmap: use READ_ONCE to access map->word
jira LE-4066 Rebuild_History Non-Buildable kernel-4.18.0-553.72.1.el8_10 commit-author linke li <lilinke99@qq.com> commit 6ad0d7e In __sbitmap_queue_get_batch(), map->word is read several times, and update atomically using atomic_long_try_cmpxchg(). But the first two read of map->word is not protected. This patch moves the statement val = READ_ONCE(map->word) forward, eliminating unprotected accesses to map->word within the function. It is aimed at reducing the number of benign races reported by KCSAN in order to focus future debugging effort on harmful races. Signed-off-by: linke li <lilinke99@qq.com> Link: https://lore.kernel.org/r/tencent_0B517C25E519D3D002194E8445E86C04AD0A@qq.com Signed-off-by: Jens Axboe <axboe@kernel.dk> (cherry picked from commit 6ad0d7e) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 816620b commit 5a7fde5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/sbitmap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,18 +517,18 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
517517
struct sbitmap_word *map = &sb->map[index];
518518
unsigned long get_mask;
519519
unsigned int map_depth = __map_depth(sb, index);
520+
unsigned long val;
520521

521522
sbitmap_deferred_clear(map);
522-
if (map->word == (1UL << (map_depth - 1)) - 1)
523+
val = READ_ONCE(map->word);
524+
if (val == (1UL << (map_depth - 1)) - 1)
523525
goto next;
524526

525-
nr = find_first_zero_bit(&map->word, map_depth);
527+
nr = find_first_zero_bit(&val, map_depth);
526528
if (nr + nr_tags <= map_depth) {
527529
atomic_long_t *ptr = (atomic_long_t *) &map->word;
528-
unsigned long val;
529530

530531
get_mask = ((1UL << nr_tags) - 1) << nr;
531-
val = READ_ONCE(map->word);
532532
while (!atomic_long_try_cmpxchg(ptr, &val,
533533
get_mask | val))
534534
;

0 commit comments

Comments
 (0)