Blame SOURCES/0016-Make-dev-d-D-options-parse-sbitmap-on-Linux-4.18-and.patch

d67611
From c07068266b41450ca6821ee0a1a3adf34206015f Mon Sep 17 00:00:00 2001
d67611
From: Kazuhito Hagio <k-hagio-ab@nec.com>
d67611
Date: Fri, 10 Jun 2022 15:21:53 +0900
d67611
Subject: [PATCH 16/18] Make "dev -d|-D" options parse sbitmap on Linux 4.18
d67611
 and later
d67611
d67611
There have been a few reports that the "dev -d|-D" options displayed
d67611
incorrect I/O stats due to racy blk_mq_ctx.rq_* counters.  To fix it,
d67611
make the options parse sbitmap to count I/O stats on Linux 4.18 and
d67611
later kernels, which include RHEL8 ones.
d67611
d67611
To do this, adjust to the blk_mq_tags structure of Linux 5.10 through
d67611
5.15 kernels, which contain kernel commit 222a5ae03cdd ("blk-mq: Use
d67611
pointers for blk_mq_tags bitmap tags") and do not contain ae0f1a732f4a
d67611
("blk-mq: Stop using pointers for blk_mq_tags bitmap tags").
d67611
d67611
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
d67611
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
d67611
---
d67611
 dev.c | 25 +++++++++++++++++++++++--
d67611
 1 file changed, 23 insertions(+), 2 deletions(-)
d67611
d67611
diff --git a/dev.c b/dev.c
d67611
index 0172c83ffaea..db97f8aebdc2 100644
d67611
--- a/dev.c
d67611
+++ b/dev.c
d67611
@@ -4339,6 +4339,10 @@ static void bt_for_each(ulong q, ulong tags, ulong sbq, uint reserved, uint nr_r
d67611
 static void queue_for_each_hw_ctx(ulong q, ulong *hctx, uint cnt, struct diskio *dio)
d67611
 {
d67611
 	uint i;
d67611
+	int bitmap_tags_is_ptr = 0;
d67611
+
d67611
+	if (MEMBER_TYPE("blk_mq_tags", "bitmap_tags") == TYPE_CODE_PTR)
d67611
+		bitmap_tags_is_ptr = 1;
d67611
 
d67611
 	for (i = 0; i < cnt; i++) {
d67611
 		ulong addr = 0, tags = 0;
d67611
@@ -4357,9 +4361,17 @@ static void queue_for_each_hw_ctx(ulong q, ulong *hctx, uint cnt, struct diskio
d67611
 
d67611
 		if (nr_reserved_tags) {
d67611
 			addr = tags + OFFSET(blk_mq_tags_breserved_tags);
d67611
+			if (bitmap_tags_is_ptr &&
d67611
+			    !readmem(addr, KVADDR, &addr, sizeof(ulong),
d67611
+					"blk_mq_tags.bitmap_tags", RETURN_ON_ERROR))
d67611
+				break;
d67611
 			bt_for_each(q, tags, addr, 1, nr_reserved_tags, dio);
d67611
 		}
d67611
 		addr = tags + OFFSET(blk_mq_tags_bitmap_tags);
d67611
+		if (bitmap_tags_is_ptr &&
d67611
+		    !readmem(addr, KVADDR, &addr, sizeof(ulong),
d67611
+				"blk_mq_tags.bitmap_tags", RETURN_ON_ERROR))
d67611
+			break;
d67611
 		bt_for_each(q, tags, addr, 0, nr_reserved_tags, dio);
d67611
 	}
d67611
 }
d67611
@@ -4423,14 +4435,23 @@ get_mq_diskio(unsigned long q, unsigned long *mq_count)
d67611
 	unsigned long mctx_addr;
d67611
 	struct diskio tmp = {0};
d67611
 
d67611
-	if (INVALID_MEMBER(blk_mq_ctx_rq_dispatched) ||
d67611
-	    INVALID_MEMBER(blk_mq_ctx_rq_completed)) {
d67611
+	/*
d67611
+	 * Currently this function does not support old blk-mq implementation
d67611
+	 * before 12f5b9314545 ("blk-mq: Remove generation seqeunce"), so
d67611
+	 * filter them out.
d67611
+	 */
d67611
+	if (VALID_MEMBER(request_state)) {
d67611
+		if (CRASHDEBUG(1))
d67611
+			fprintf(fp, "mq: using sbitmap\n");
d67611
 		get_mq_diskio_from_hw_queues(q, &tmp);
d67611
 		mq_count[0] = tmp.read;
d67611
 		mq_count[1] = tmp.write;
d67611
 		return;
d67611
 	}
d67611
 
d67611
+	if (CRASHDEBUG(1))
d67611
+		fprintf(fp, "mq: using blk_mq_ctx.rq_{completed,dispatched} counters\n");
d67611
+
d67611
 	readmem(q + OFFSET(request_queue_queue_ctx), KVADDR, &queue_ctx,
d67611
 		sizeof(ulong), "request_queue.queue_ctx",
d67611
 		FAULT_ON_ERROR);
d67611
-- 
d67611
2.30.2
d67611