Blame SOURCES/0011-Fix-for-dev-d-D-options-to-support-blk-mq-change-on-.patch

d67611
From 68ce0b9a35d77d767872dd1a729c50e4695a30a8 Mon Sep 17 00:00:00 2001
d67611
From: Lianbo Jiang <lijiang@redhat.com>
d67611
Date: Thu, 2 Jun 2022 20:12:56 +0800
d67611
Subject: [PATCH 11/18] Fix for "dev -d|-D" options to support blk-mq change on
d67611
 Linux v5.18-rc1
d67611
d67611
Kernel commit 4e5cc99e1e48 ("blk-mq: manage hctx map via xarray") removed
d67611
the "queue_hw_ctx" member from struct request_queue at Linux v5.18-rc1,
d67611
and replaced it with a struct xarray "hctx_table". Without the patch, the
d67611
"dev -d|-D" options will print an error:
d67611
d67611
  crash> dev -d
d67611
  MAJOR GENDISK            NAME       REQUEST_QUEUE      TOTAL  READ WRITE
d67611
d67611
  dev: invalid structure member offset: request_queue_queue_hw_ctx
d67611
d67611
With the patch:
d67611
  crash> dev -d
d67611
  MAJOR GENDISK            NAME       REQUEST_QUEUE      TOTAL  READ WRITE
d67611
      8 ffff8e99d0a1ae00   sda        ffff8e9c14c59980      10     6     4
d67611
d67611
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
d67611
---
d67611
 defs.h    |  1 +
d67611
 dev.c     | 42 +++++++++++++++++++++++++++++++++---------
d67611
 symbols.c |  2 ++
d67611
 3 files changed, 36 insertions(+), 9 deletions(-)
d67611
d67611
diff --git a/defs.h b/defs.h
d67611
index 2681586a33dc..7d3b73422f48 100644
d67611
--- a/defs.h
d67611
+++ b/defs.h
d67611
@@ -2180,6 +2180,7 @@ struct offset_table {                    /* stash of commonly-used offsets */
d67611
 	long blk_mq_tags_breserved_tags;
d67611
 	long blk_mq_tags_nr_reserved_tags;
d67611
 	long blk_mq_tags_rqs;
d67611
+	long request_queue_hctx_table;
d67611
 };
d67611
 
d67611
 struct size_table {         /* stash of commonly-used sizes */
d67611
diff --git a/dev.c b/dev.c
d67611
index 4be4c96df8b0..0172c83ffaea 100644
d67611
--- a/dev.c
d67611
+++ b/dev.c
d67611
@@ -4369,20 +4369,42 @@ static void get_mq_diskio_from_hw_queues(ulong q, struct diskio *dio)
d67611
 	uint cnt = 0;
d67611
 	ulong addr = 0, hctx_addr = 0;
d67611
 	ulong *hctx_array = NULL;
d67611
+	struct list_pair *lp = NULL;
d67611
+
d67611
+	if (VALID_MEMBER(request_queue_hctx_table)) {
d67611
+		addr = q + OFFSET(request_queue_hctx_table);
d67611
+		cnt = do_xarray(addr, XARRAY_COUNT, NULL);
d67611
+		lp = (struct list_pair *)GETBUF(sizeof(struct list_pair) * (cnt + 1));
d67611
+		if (!lp)
d67611
+			error(FATAL, "fail to get memory for list_pair.\n");
d67611
+		lp[0].index = cnt;
d67611
+		cnt = do_xarray(addr, XARRAY_GATHER, lp);
d67611
+	} else {
d67611
+		addr = q + OFFSET(request_queue_nr_hw_queues);
d67611
+		readmem(addr, KVADDR, &cnt, sizeof(uint),
d67611
+			"request_queue.nr_hw_queues", FAULT_ON_ERROR);
d67611
 
d67611
-	addr = q + OFFSET(request_queue_nr_hw_queues);
d67611
-	readmem(addr, KVADDR, &cnt, sizeof(uint),
d67611
-		"request_queue.nr_hw_queues", FAULT_ON_ERROR);
d67611
-
d67611
-	addr = q + OFFSET(request_queue_queue_hw_ctx);
d67611
-	readmem(addr, KVADDR, &hctx_addr, sizeof(void *),
d67611
-		"request_queue.queue_hw_ctx", FAULT_ON_ERROR);
d67611
+		addr = q + OFFSET(request_queue_queue_hw_ctx);
d67611
+		readmem(addr, KVADDR, &hctx_addr, sizeof(void *),
d67611
+			"request_queue.queue_hw_ctx", FAULT_ON_ERROR);
d67611
+	}
d67611
 
d67611
 	hctx_array = (ulong *)GETBUF(sizeof(void *) * cnt);
d67611
-	if (!hctx_array)
d67611
+	if (!hctx_array) {
d67611
+		if (lp)
d67611
+			FREEBUF(lp);
d67611
 		error(FATAL, "fail to get memory for the hctx_array\n");
d67611
+	}
d67611
+
d67611
+	if (lp && hctx_array) {
d67611
+		uint i;
d67611
+
d67611
+		/* copy it from list_pair to hctx_array */
d67611
+		for (i = 0; i < cnt; i++)
d67611
+			hctx_array[i] = (ulong)lp[i].value;
d67611
 
d67611
-	if (!readmem(hctx_addr, KVADDR, hctx_array, sizeof(void *) * cnt,
d67611
+		FREEBUF(lp);
d67611
+	} else if (!readmem(hctx_addr, KVADDR, hctx_array, sizeof(void *) * cnt,
d67611
 			"request_queue.queue_hw_ctx[]", RETURN_ON_ERROR)) {
d67611
 		FREEBUF(hctx_array);
d67611
 		return;
d67611
@@ -4755,6 +4777,8 @@ void diskio_init(void)
d67611
 			"request_queue", "queue_hw_ctx");
d67611
 		MEMBER_OFFSET_INIT(request_queue_nr_hw_queues,
d67611
 			"request_queue", "nr_hw_queues");
d67611
+		MEMBER_OFFSET_INIT(request_queue_hctx_table,
d67611
+			"request_queue", "hctx_table");
d67611
 		MEMBER_OFFSET_INIT(blk_mq_ctx_rq_dispatched, "blk_mq_ctx",
d67611
 			"rq_dispatched");
d67611
 		MEMBER_OFFSET_INIT(blk_mq_ctx_rq_completed, "blk_mq_ctx",
d67611
diff --git a/symbols.c b/symbols.c
d67611
index c1f09556d710..bee1faf92c83 100644
d67611
--- a/symbols.c
d67611
+++ b/symbols.c
d67611
@@ -10403,6 +10403,8 @@ dump_offset_table(char *spec, ulong makestruct)
d67611
 		OFFSET(request_queue_queue_hw_ctx));
d67611
 	fprintf(fp, "    request_queue_nr_hw_queues: %ld\n",
d67611
 		OFFSET(request_queue_nr_hw_queues));
d67611
+	fprintf(fp, "      request_queue_hctx_table: %ld\n",
d67611
+		OFFSET(request_queue_hctx_table));
d67611
 	fprintf(fp, "      blk_mq_ctx_rq_dispatched: %ld\n",
d67611
 		OFFSET(blk_mq_ctx_rq_dispatched));
d67611
 	fprintf(fp, "       blk_mq_ctx_rq_completed: %ld\n",
d67611
-- 
d67611
2.30.2
d67611