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

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