From e3e84f62054c6072a9c7438fb2880a2db88159d4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 12 Sep 2024 06:34:05 +0000 Subject: [PATCH] Revert "sbitmap: fix io hung due to race on sbitmap_word::cleared" This reverts commit 681583ad673186b5dec793f4b8c4f1dd242b89a5 which is commit 72d04bdcf3f7d7e07d82f9757946f68802a7270a upstream. It breaks the Android kernel abi and can be brought back in the future in an abi-safe way if it is really needed. Bug: 161946584 Change-Id: I6c645c8b4a157820561507a1cf3c1180b94aebff Signed-off-by: Greg Kroah-Hartman --- include/linux/sbitmap.h | 5 ----- lib/sbitmap.c | 36 +++++++----------------------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h index c09cdcc99471..d662cf136021 100644 --- a/include/linux/sbitmap.h +++ b/include/linux/sbitmap.h @@ -36,11 +36,6 @@ struct sbitmap_word { * @cleared: word holding cleared bits */ unsigned long cleared ____cacheline_aligned_in_smp; - - /** - * @swap_lock: serializes simultaneous updates of ->word and ->cleared - */ - spinlock_t swap_lock; } ____cacheline_aligned_in_smp; /** diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 61075535a807..a727d0b12763 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -60,30 +60,12 @@ static inline void update_alloc_hint_after_get(struct sbitmap *sb, /* * See if we have deferred clears that we can batch move */ -static inline bool sbitmap_deferred_clear(struct sbitmap_word *map, - unsigned int depth, unsigned int alloc_hint, bool wrap) +static inline bool sbitmap_deferred_clear(struct sbitmap_word *map) { - unsigned long mask, word_mask; + unsigned long mask; - guard(spinlock_irqsave)(&map->swap_lock); - - if (!map->cleared) { - if (depth == 0) - return false; - - word_mask = (~0UL) >> (BITS_PER_LONG - depth); - /* - * The current behavior is to always retry after moving - * ->cleared to word, and we change it to retry in case - * of any free bits. To avoid an infinite loop, we need - * to take wrap & alloc_hint into account, otherwise a - * soft lockup may occur. - */ - if (!wrap && alloc_hint) - word_mask &= ~((1UL << alloc_hint) - 1); - - return (READ_ONCE(map->word) & word_mask) != word_mask; - } + if (!READ_ONCE(map->cleared)) + return false; /* * First get a stable cleared mask, setting the old mask to 0. @@ -103,7 +85,6 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift, bool alloc_hint) { unsigned int bits_per_word; - int i; if (shift < 0) shift = sbitmap_calculate_shift(depth); @@ -135,9 +116,6 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift, return -ENOMEM; } - for (i = 0; i < sb->map_nr; i++) - spin_lock_init(&sb->map[i].swap_lock); - return 0; } EXPORT_SYMBOL_GPL(sbitmap_init_node); @@ -148,7 +126,7 @@ void sbitmap_resize(struct sbitmap *sb, unsigned int depth) unsigned int i; for (i = 0; i < sb->map_nr; i++) - sbitmap_deferred_clear(&sb->map[i], 0, 0, 0); + sbitmap_deferred_clear(&sb->map[i]); sb->depth = depth; sb->map_nr = DIV_ROUND_UP(sb->depth, bits_per_word); @@ -201,7 +179,7 @@ static int sbitmap_find_bit_in_word(struct sbitmap_word *map, alloc_hint, wrap); if (nr != -1) break; - if (!sbitmap_deferred_clear(map, depth, alloc_hint, wrap)) + if (!sbitmap_deferred_clear(map)) break; } while (1); @@ -527,7 +505,7 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags, unsigned int map_depth = __map_depth(sb, index); unsigned long val; - sbitmap_deferred_clear(map, 0, 0, 0); + sbitmap_deferred_clear(map); val = READ_ONCE(map->word); if (val == (1UL << (map_depth - 1)) - 1) goto next;