Blame SOURCES/0003-sbitmapq-fix-invalid-offset-for-sbitmap_queue_alloc_.patch

1a20ba
From a295cb40cd5d24fb5995cc78d29c5def3843d285 Mon Sep 17 00:00:00 2001
1a20ba
From: Lianbo Jiang <lijiang@redhat.com>
1a20ba
Date: Mon, 23 May 2022 18:04:14 +0800
1a20ba
Subject: [PATCH 03/18] sbitmapq: fix invalid offset for
1a20ba
 "sbitmap_queue_alloc_hint" on Linux v5.13-rc1
1a20ba
1a20ba
Kernel commit c548e62bcf6a ("scsi: sbitmap: Move allocation hint
1a20ba
into sbitmap") moved the alloc_hint member from struct sbitmap_queue
1a20ba
to struct sbitmap.  Without the patch, the sbitmapq will fail:
1a20ba
1a20ba
  crash> sbitmapq 0xffff8e99d0dc8010
1a20ba
1a20ba
  sbitmapq: invalid structure member offset: sbitmap_queue_alloc_hint
1a20ba
          FILE: sbitmap.c  LINE: 365  FUNCTION: sbitmap_queue_context_load()
1a20ba
1a20ba
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
1a20ba
---
1a20ba
 defs.h    |  2 ++
1a20ba
 sbitmap.c | 14 ++++++++++++--
1a20ba
 symbols.c |  2 ++
1a20ba
 3 files changed, 16 insertions(+), 2 deletions(-)
1a20ba
1a20ba
diff --git a/defs.h b/defs.h
1a20ba
index a6735d07b32f..0aeb98c4f654 100644
1a20ba
--- a/defs.h
1a20ba
+++ b/defs.h
1a20ba
@@ -2168,6 +2168,7 @@ struct offset_table {                    /* stash of commonly-used offsets */
1a20ba
 	long sbitmap_queue_min_shallow_depth;
1a20ba
 	long sbq_wait_state_wait_cnt;
1a20ba
 	long sbq_wait_state_wait;
1a20ba
+	long sbitmap_alloc_hint;
1a20ba
 };
1a20ba
 
1a20ba
 struct size_table {         /* stash of commonly-used sizes */
1a20ba
@@ -5907,6 +5908,7 @@ struct sbitmap_context {
1a20ba
 	unsigned shift;
1a20ba
 	unsigned map_nr;
1a20ba
 	ulong map_addr;
1a20ba
+	ulong alloc_hint;
1a20ba
 };
1a20ba
 
1a20ba
 typedef bool (*sbitmap_for_each_fn)(unsigned int idx, void *p);
1a20ba
diff --git a/sbitmap.c b/sbitmap.c
1a20ba
index 7693eef6cebd..2921d5447c65 100644
1a20ba
--- a/sbitmap.c
1a20ba
+++ b/sbitmap.c
1a20ba
@@ -285,6 +285,7 @@ void sbitmap_for_each_set(const struct sbitmap_context *sc,
1a20ba
 static void sbitmap_queue_show(const struct sbitmap_queue_context *sqc,
1a20ba
 		const struct sbitmap_context *sc)
1a20ba
 {
1a20ba
+	ulong alloc_hint_addr = 0;
1a20ba
 	int cpus = get_cpus_possible();
1a20ba
 	int sbq_wait_state_size, wait_cnt_off, wait_off, list_head_off;
1a20ba
 	char *sbq_wait_state_buf;
1a20ba
@@ -297,6 +298,11 @@ static void sbitmap_queue_show(const struct sbitmap_queue_context *sqc,
1a20ba
 	fprintf(fp, "bits_per_word = %u\n", 1U << sc->shift);
1a20ba
 	fprintf(fp, "map_nr = %u\n", sc->map_nr);
1a20ba
 
1a20ba
+	if (VALID_MEMBER(sbitmap_queue_alloc_hint))
1a20ba
+		alloc_hint_addr = sqc->alloc_hint;
1a20ba
+	else if (VALID_MEMBER(sbitmap_alloc_hint)) /* 5.13 and later */
1a20ba
+		alloc_hint_addr = sc->alloc_hint;
1a20ba
+
1a20ba
 	fputs("alloc_hint = {", fp);
1a20ba
 	first = true;
1a20ba
 	for (i = 0; i < cpus; i++) {
1a20ba
@@ -307,7 +313,7 @@ static void sbitmap_queue_show(const struct sbitmap_queue_context *sqc,
1a20ba
 			fprintf(fp, ", ");
1a20ba
 		first = false;
1a20ba
 
1a20ba
-		ptr = kt->__per_cpu_offset[i] + sqc->alloc_hint;
1a20ba
+		ptr = kt->__per_cpu_offset[i] + alloc_hint_addr;
1a20ba
 		readmem(ptr, KVADDR, &val, sizeof(val), "alloc_hint", FAULT_ON_ERROR);
1a20ba
 
1a20ba
 		fprintf(fp, "%u", val);
1a20ba
@@ -362,7 +368,8 @@ static void sbitmap_queue_context_load(ulong addr, struct sbitmap_queue_context
1a20ba
 		error(FATAL, "cannot read sbitmap_queue\n");
1a20ba
 	}
1a20ba
 
1a20ba
-	sqc->alloc_hint = ULONG(sbitmap_queue_buf + OFFSET(sbitmap_queue_alloc_hint));
1a20ba
+	if (VALID_MEMBER(sbitmap_queue_alloc_hint))
1a20ba
+		sqc->alloc_hint = ULONG(sbitmap_queue_buf + OFFSET(sbitmap_queue_alloc_hint));
1a20ba
 	sqc->wake_batch = UINT(sbitmap_queue_buf + OFFSET(sbitmap_queue_wake_batch));
1a20ba
 	sqc->wake_index = INT(sbitmap_queue_buf + OFFSET(sbitmap_queue_wake_index));
1a20ba
 	sqc->ws_addr = ULONG(sbitmap_queue_buf + OFFSET(sbitmap_queue_ws));
1a20ba
@@ -387,6 +394,8 @@ void sbitmap_context_load(ulong addr, struct sbitmap_context *sc)
1a20ba
 	sc->shift = UINT(sbitmap_buf + OFFSET(sbitmap_shift));
1a20ba
 	sc->map_nr = UINT(sbitmap_buf + OFFSET(sbitmap_map_nr));
1a20ba
 	sc->map_addr = ULONG(sbitmap_buf + OFFSET(sbitmap_map));
1a20ba
+	if (VALID_MEMBER(sbitmap_alloc_hint))
1a20ba
+		sc->alloc_hint = ULONG(sbitmap_buf + OFFSET(sbitmap_alloc_hint));
1a20ba
 
1a20ba
 	FREEBUF(sbitmap_buf);
1a20ba
 }
1a20ba
@@ -512,6 +521,7 @@ void sbitmapq_init(void)
1a20ba
 	MEMBER_OFFSET_INIT(sbitmap_shift, "sbitmap", "shift");
1a20ba
 	MEMBER_OFFSET_INIT(sbitmap_map_nr, "sbitmap", "map_nr");
1a20ba
 	MEMBER_OFFSET_INIT(sbitmap_map, "sbitmap", "map");
1a20ba
+	MEMBER_OFFSET_INIT(sbitmap_alloc_hint, "sbitmap", "alloc_hint");
1a20ba
 
1a20ba
 	MEMBER_OFFSET_INIT(sbitmap_queue_sb, "sbitmap_queue", "sb");
1a20ba
 	MEMBER_OFFSET_INIT(sbitmap_queue_alloc_hint, "sbitmap_queue", "alloc_hint");
1a20ba
diff --git a/symbols.c b/symbols.c
1a20ba
index ba5e2741347d..fd0eb06899f0 100644
1a20ba
--- a/symbols.c
1a20ba
+++ b/symbols.c
1a20ba
@@ -10708,6 +10708,8 @@ dump_offset_table(char *spec, ulong makestruct)
1a20ba
 		OFFSET(sbitmap_map_nr));
1a20ba
 	fprintf(fp, "                   sbitmap_map: %ld\n",
1a20ba
 		OFFSET(sbitmap_map));
1a20ba
+	fprintf(fp, "            sbitmap_alloc_hint: %ld\n",
1a20ba
+		OFFSET(sbitmap_alloc_hint));
1a20ba
 	fprintf(fp, "              sbitmap_queue_sb: %ld\n",
1a20ba
 		OFFSET(sbitmap_queue_sb));
1a20ba
 	fprintf(fp, "      sbitmap_queue_alloc_hint: %ld\n",
1a20ba
-- 
1a20ba
2.30.2
1a20ba