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

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