Patch "sbitmap: use READ_ONCE to access map->word" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    sbitmap: use READ_ONCE to access map->word

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     sbitmap-use-read_once-to-access-map-word.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit d9467d923cb0bd7b6e1e9ff47ddcb2b9947355c8
Author: linke li <lilinke99@xxxxxx>
Date:   Fri Apr 26 18:34:44 2024 +0800

    sbitmap: use READ_ONCE to access map->word
    
    [ Upstream commit 6ad0d7e0f4b68f87a98ea2b239123b7d865df86b ]
    
    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@xxxxxx>
    Link: https://lore.kernel.org/r/tencent_0B517C25E519D3D002194E8445E86C04AD0A@xxxxxx
    Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
    Stable-dep-of: 72d04bdcf3f7 ("sbitmap: fix io hung due to race on sbitmap_word::cleared")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index b942f2ba9a415..a727d0b12763a 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -503,18 +503,18 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
 		struct sbitmap_word *map = &sb->map[index];
 		unsigned long get_mask;
 		unsigned int map_depth = __map_depth(sb, index);
+		unsigned long val;
 
 		sbitmap_deferred_clear(map);
-		if (map->word == (1UL << (map_depth - 1)) - 1)
+		val = READ_ONCE(map->word);
+		if (val == (1UL << (map_depth - 1)) - 1)
 			goto next;
 
-		nr = find_first_zero_bit(&map->word, map_depth);
+		nr = find_first_zero_bit(&val, map_depth);
 		if (nr + nr_tags <= map_depth) {
 			atomic_long_t *ptr = (atomic_long_t *) &map->word;
-			unsigned long val;
 
 			get_mask = ((1UL << nr_tags) - 1) << nr;
-			val = READ_ONCE(map->word);
 			while (!atomic_long_try_cmpxchg(ptr, &val,
 							  get_mask | val))
 				;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux