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

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