Blame SOURCES/0005-sbitmapq-fix-invalid-offset-for-sbitmap_word_depth-o.patch

d67611
From 3750803f6ae5f5ad071f86ca916dbbb17b7a83a5 Mon Sep 17 00:00:00 2001
d67611
From: Lianbo Jiang <lijiang@redhat.com>
d67611
Date: Mon, 23 May 2022 18:04:16 +0800
d67611
Subject: [PATCH 05/18] sbitmapq: fix invalid offset for "sbitmap_word_depth"
d67611
 on Linux v5.18-rc1
d67611
d67611
Kernel commit 3301bc53358a ("lib/sbitmap: kill 'depth' from sbitmap_word")
d67611
removed the depth member from struct sbitmap_word.  Without the patch, the
d67611
sbitmapq will fail:
d67611
d67611
  crash> sbitmapq 0xffff8e99d0dc8010
d67611
d67611
  sbitmapq: invalid structure member offset: sbitmap_word_depth
d67611
          FILE: sbitmap.c  LINE: 84  FUNCTION: __sbitmap_weight()
d67611
d67611
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
d67611
---
d67611
 sbitmap.c | 19 +++++++++++--------
d67611
 1 file changed, 11 insertions(+), 8 deletions(-)
d67611
d67611
diff --git a/sbitmap.c b/sbitmap.c
d67611
index 7b318b533702..e8ebd62fe01c 100644
d67611
--- a/sbitmap.c
d67611
+++ b/sbitmap.c
d67611
@@ -78,10 +78,16 @@ static unsigned long bitmap_weight(unsigned long bitmap, unsigned int bits)
d67611
 	return w;
d67611
 }
d67611
 
d67611
+static inline unsigned int __map_depth(const struct sbitmap_context *sc, int index)
d67611
+{
d67611
+       if (index == sc->map_nr - 1)
d67611
+               return sc->depth - (index << sc->shift);
d67611
+       return 1U << sc->shift;
d67611
+}
d67611
+
d67611
 static unsigned int __sbitmap_weight(const struct sbitmap_context *sc, bool set)
d67611
 {
d67611
 	const ulong sbitmap_word_size = SIZE(sbitmap_word);
d67611
-	const ulong w_depth_off = OFFSET(sbitmap_word_depth);
d67611
 	const ulong w_word_off = OFFSET(sbitmap_word_word);
d67611
 	const ulong w_cleared_off = OFFSET(sbitmap_word_cleared);
d67611
 
d67611
@@ -99,7 +105,7 @@ static unsigned int __sbitmap_weight(const struct sbitmap_context *sc, bool set)
d67611
 			error(FATAL, "cannot read sbitmap_word\n");
d67611
 		}
d67611
 
d67611
-		depth = ULONG(sbitmap_word_buf + w_depth_off);
d67611
+		depth = __map_depth(sc, i);
d67611
 
d67611
 		if (set) {
d67611
 			word = ULONG(sbitmap_word_buf + w_word_off);
d67611
@@ -142,7 +148,6 @@ static void sbitmap_emit_byte(unsigned int offset, uint8_t byte)
d67611
 static void sbitmap_bitmap_show(const struct sbitmap_context *sc)
d67611
 {
d67611
 	const ulong sbitmap_word_size = SIZE(sbitmap_word);
d67611
-	const ulong w_depth_off = OFFSET(sbitmap_word_depth);
d67611
 	const ulong w_word_off = OFFSET(sbitmap_word_word);
d67611
 	const ulong w_cleared_off = OFFSET(sbitmap_word_cleared);
d67611
 
d67611
@@ -165,7 +170,7 @@ static void sbitmap_bitmap_show(const struct sbitmap_context *sc)
d67611
 
d67611
 		word = ULONG(sbitmap_word_buf + w_word_off);
d67611
 		cleared = ULONG(sbitmap_word_buf + w_cleared_off);
d67611
-		word_bits = ULONG(sbitmap_word_buf + w_depth_off);
d67611
+		word_bits = __map_depth(sc, i);
d67611
 
d67611
 		word &= ~cleared;
d67611
 
d67611
@@ -213,7 +218,6 @@ static void __sbitmap_for_each_set(const struct sbitmap_context *sc,
d67611
 		unsigned int start, sbitmap_for_each_fn fn, void *data)
d67611
 {
d67611
 	const ulong sbitmap_word_size = SIZE(sbitmap_word);
d67611
-	const ulong w_depth_off = OFFSET(sbitmap_word_depth);
d67611
 	const ulong w_word_off = OFFSET(sbitmap_word_word);
d67611
 	const ulong w_cleared_off = OFFSET(sbitmap_word_cleared);
d67611
 
d67611
@@ -232,7 +236,7 @@ static void __sbitmap_for_each_set(const struct sbitmap_context *sc,
d67611
 
d67611
 	while (scanned < sc->depth) {
d67611
 		unsigned long w_addr = sc->map_addr + (sbitmap_word_size * index);
d67611
-		unsigned long w_depth, w_word, w_cleared;
d67611
+		unsigned long w_word, w_cleared;
d67611
 		unsigned long word, depth;
d67611
 
d67611
 		if (!readmem(w_addr, KVADDR, sbitmap_word_buf, sbitmap_word_size, "sbitmap_word", RETURN_ON_ERROR)) {
d67611
@@ -240,11 +244,10 @@ static void __sbitmap_for_each_set(const struct sbitmap_context *sc,
d67611
 			error(FATAL, "cannot read sbitmap_word\n");
d67611
 		}
d67611
 
d67611
-		w_depth = ULONG(sbitmap_word_buf + w_depth_off);
d67611
 		w_word = ULONG(sbitmap_word_buf + w_word_off);
d67611
 		w_cleared = ULONG(sbitmap_word_buf + w_cleared_off);
d67611
 
d67611
-		depth = min(w_depth - nr, sc->depth - scanned);
d67611
+		depth = min(__map_depth(sc, index) - nr, sc->depth - scanned);
d67611
 
d67611
 		scanned += depth;
d67611
 		word = w_word & ~w_cleared;
d67611
-- 
d67611
2.30.2
d67611