[Crash-utility] Re: [PATCH v2] Fix 'rd' command for zram data display in Linux 6.2+

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Chengen,

thank you for the update.

On 2023/11/17 12:45, Chengen Du wrote:
> A kernel commit 7ac07a26dea7 (zram: preparation for multi-zcomp support)
> in Linux replaces "compressor" with "comp_algs" in the zram struct.
> If not fixed, the issue triggers the following error:
>    rd: WARNING: Some pages are swapped out to zram. Please run mod -s zram.
>    rd: invalid user virtual address: ffff7d23f010  type: "64-bit UVADDR"
> 
> Signed-off-by: Chengen Du <chengen.du@xxxxxxxxxxxxx>
> ---
>   defs.h     |  1 +
>   diskdump.c | 56 +++++++++++++++++++++++++++++++++++-------------------
>   2 files changed, 37 insertions(+), 20 deletions(-)
> 
> diff --git a/defs.h b/defs.h
> index 788f63a..2cae5b6 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -2227,6 +2227,7 @@ struct offset_table {                    /* stash of commonly-used offsets */
>   	long module_memory_size;
>   	long irq_data_irq;
>   	long zspage_huge;
> +	long zram_comp_algs;
>   };
>   
>   struct size_table {         /* stash of commonly-used sizes */
> diff --git a/diskdump.c b/diskdump.c
> index 0fe46f4..d7e4380 100644
> --- a/diskdump.c
> +++ b/diskdump.c
> @@ -2757,6 +2757,8 @@ diskdump_device_dump_info(FILE *ofp)
>   
>   static ulong ZRAM_FLAG_SHIFT;
>   static ulong ZRAM_FLAG_SAME_BIT;
> +static ulong ZRAM_COMP_PRIORITY_BIT1;
> +static ulong ZRAM_COMP_PRIORITY_MASK;
>   
>   static void
>   zram_init(void)
> @@ -2765,6 +2767,8 @@ zram_init(void)
>   
>   	MEMBER_OFFSET_INIT(zram_mempoll, "zram", "mem_pool");
>   	MEMBER_OFFSET_INIT(zram_compressor, "zram", "compressor");
> +	if (INVALID_MEMBER(zram_compressor))
> +		MEMBER_OFFSET_INIT(zram_comp_algs, "zram", "comp_algs");
>   	MEMBER_OFFSET_INIT(zram_table_flag, "zram_table_entry", "flags");
>   	if (INVALID_MEMBER(zram_table_flag))
>   		MEMBER_OFFSET_INIT(zram_table_flag, "zram_table_entry", "value");
> @@ -2782,6 +2786,8 @@ zram_init(void)
>   
>   	ZRAM_FLAG_SHIFT = 1 << zram_flag_shift;
>   	ZRAM_FLAG_SAME_BIT = 1 << (zram_flag_shift+1);
> +	ZRAM_COMP_PRIORITY_BIT1 = ZRAM_FLAG_SHIFT + 7;
> +	ZRAM_COMP_PRIORITY_MASK = 0x3;
>   
>   	if (CRASHDEBUG(1))
>   		fprintf(fp, "zram_flag_shift: %ld\n", zram_flag_shift);
> @@ -2980,13 +2986,15 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>   	unsigned char *outbuf = NULL;
>   	ulong zram, zram_table_entry, sector, index, entry, flags, size,
>   		outsize, off;
> +	int comp_alg_unavail;
>   
> -	if (INVALID_MEMBER(zram_compressor)) {
> +	comp_alg_unavail = INVALID_MEMBER(zram_compressor) && INVALID_MEMBER(zram_comp_algs);
> +	if (comp_alg_unavail) {

This variable saves nothing, and looking around, I found that we don't 
need to use the zram.comp* members.  The offset of zram.mem_pool has 
been used since the first implementation [1], so I would like to change 
this to INVALID_MEMBER(zram_mem_pool) and attached it.

So the patch is ok.

Acked-by: Kazuhito Hagio <k-hagio-ab@xxxxxxx>

[1] https://github.com/crash-utility/crash/commit/b12bdd36cf7c


Lianbo, zram related offsets have some typos, irregular names and lack 
of "help -o" output.  I made the patch 2/2 in this opportunity, could 
you review this too?

Thanks,
Kazu
From 896c27e06102e9f6c8f7dc0263b9a3cbb2603c83 Mon Sep 17 00:00:00 2001
From: Chengen Du <chengen.du@xxxxxxxxxxxxx>
Date: Fri, 17 Nov 2023 11:45:33 +0800
Subject: [PATCH 1/2] Fix "rd" command for zram data display in Linux 6.2 and
 later

A kernel commit 7ac07a26dea7 (zram: preparation for multi-zcomp support)
in Linux replaces "compressor" with "comp_algs" in the zram struct.
If not fixed, the issue triggers the following error:

  rd: WARNING: Some pages are swapped out to zram. Please run mod -s zram.
  rd: invalid user virtual address: ffff7d23f010  type: "64-bit UVADDR"

Signed-off-by: Chengen Du <chengen.du@xxxxxxxxxxxxx>
---
 defs.h     |  1 +
 diskdump.c | 47 ++++++++++++++++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/defs.h b/defs.h
index 788f63ada739..2cae5b61e589 100644
--- a/defs.h
+++ b/defs.h
@@ -2227,6 +2227,7 @@ struct offset_table {                    /* stash of commonly-used offsets */
 	long module_memory_size;
 	long irq_data_irq;
 	long zspage_huge;
+	long zram_comp_algs;
 };
 
 struct size_table {         /* stash of commonly-used sizes */
diff --git a/diskdump.c b/diskdump.c
index 0fe46f4644d0..25054d96313e 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -2757,6 +2757,8 @@ diskdump_device_dump_info(FILE *ofp)
 
 static ulong ZRAM_FLAG_SHIFT;
 static ulong ZRAM_FLAG_SAME_BIT;
+static ulong ZRAM_COMP_PRIORITY_BIT1;
+static ulong ZRAM_COMP_PRIORITY_MASK;
 
 static void
 zram_init(void)
@@ -2765,6 +2767,8 @@ zram_init(void)
 
 	MEMBER_OFFSET_INIT(zram_mempoll, "zram", "mem_pool");
 	MEMBER_OFFSET_INIT(zram_compressor, "zram", "compressor");
+	if (INVALID_MEMBER(zram_compressor))
+		MEMBER_OFFSET_INIT(zram_comp_algs, "zram", "comp_algs");
 	MEMBER_OFFSET_INIT(zram_table_flag, "zram_table_entry", "flags");
 	if (INVALID_MEMBER(zram_table_flag))
 		MEMBER_OFFSET_INIT(zram_table_flag, "zram_table_entry", "value");
@@ -2782,6 +2786,8 @@ zram_init(void)
 
 	ZRAM_FLAG_SHIFT = 1 << zram_flag_shift;
 	ZRAM_FLAG_SAME_BIT = 1 << (zram_flag_shift+1);
+	ZRAM_COMP_PRIORITY_BIT1 = ZRAM_FLAG_SHIFT + 7;
+	ZRAM_COMP_PRIORITY_MASK = 0x3;
 
 	if (CRASHDEBUG(1))
 		fprintf(fp, "zram_flag_shift: %ld\n", zram_flag_shift);
@@ -2981,9 +2987,9 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
 	ulong zram, zram_table_entry, sector, index, entry, flags, size,
 		outsize, off;
 
-	if (INVALID_MEMBER(zram_compressor)) {
+	if (INVALID_MEMBER(zram_mempoll)) {
 		zram_init();
-		if (INVALID_MEMBER(zram_compressor)) {
+		if (INVALID_MEMBER(zram_mempoll)) {
 			error(WARNING,
 			      "Some pages are swapped out to zram. "
 			      "Please run mod -s zram.\n");
@@ -2997,8 +3003,28 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
 	if (!get_disk_name_private_data(pte_val, vaddr, NULL, &zram))
 		return 0;
 
-	readmem(zram + OFFSET(zram_compressor), KVADDR, name,
-		sizeof(name), "zram compressor", FAULT_ON_ERROR);
+	if (THIS_KERNEL_VERSION >= LINUX(2, 6, 0))
+		swp_offset = (ulonglong)__swp_offset(pte_val);
+	else
+		swp_offset = (ulonglong)SWP_OFFSET(pte_val);
+
+	sector = swp_offset << (PAGESHIFT() - 9);
+	index = sector >> SECTORS_PER_PAGE_SHIFT;
+	readmem(zram, KVADDR, &zram_table_entry,
+		sizeof(void *), "zram_table_entry", FAULT_ON_ERROR);
+	zram_table_entry += (index * SIZE(zram_table_entry));
+	readmem(zram_table_entry + OFFSET(zram_table_flag), KVADDR, &flags,
+		sizeof(void *), "zram_table_flag", FAULT_ON_ERROR);
+	if (VALID_MEMBER(zram_compressor))
+		readmem(zram + OFFSET(zram_compressor), KVADDR, name, sizeof(name),
+			"zram compressor", FAULT_ON_ERROR);
+	else {
+		ulong comp_alg_addr;
+		uint32_t prio = (flags >> ZRAM_COMP_PRIORITY_BIT1) & ZRAM_COMP_PRIORITY_MASK;
+		readmem(zram + OFFSET(zram_comp_algs) + sizeof(const char *) * prio, KVADDR,
+			&comp_alg_addr, sizeof(comp_alg_addr), "zram comp_algs", FAULT_ON_ERROR);
+		read_string(comp_alg_addr, name, sizeof(name));
+	}
 	if (STREQ(name, "lzo")) {
 #ifdef LZO
 		if (!(dd->flags & LZO_SUPPORTED)) {
@@ -3019,12 +3045,6 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
 		return 0;
 	}
 
-	if (THIS_KERNEL_VERSION >= LINUX(2, 6, 0)) {
-		swp_offset = (ulonglong)__swp_offset(pte_val);
-	} else {
-		swp_offset = (ulonglong)SWP_OFFSET(pte_val);
-	}
-
 	zram_buf = (unsigned char *)GETBUF(PAGESIZE());
 	/* lookup page from swap cache */
 	off = PAGEOFFSET(vaddr);
@@ -3034,15 +3054,8 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
 		goto out;
 	}
 
-	sector = swp_offset << (PAGESHIFT() - 9);
-	index = sector >> SECTORS_PER_PAGE_SHIFT;
-	readmem(zram, KVADDR, &zram_table_entry,
-		sizeof(void *), "zram_table_entry", FAULT_ON_ERROR);
-	zram_table_entry += (index * SIZE(zram_table_entry));
 	readmem(zram_table_entry, KVADDR, &entry,
 		sizeof(void *), "entry of table", FAULT_ON_ERROR);
-	readmem(zram_table_entry + OFFSET(zram_table_flag), KVADDR, &flags,
-		sizeof(void *), "zram_table_flag", FAULT_ON_ERROR);
 	if (!entry || (flags & ZRAM_FLAG_SAME_BIT)) {
 		int count;
 		ulong *same_buf = (ulong *)GETBUF(PAGESIZE());
-- 
2.31.1

From 25bbeafae75a5111267c1f590ed57a713ddb273a Mon Sep 17 00:00:00 2001
From: Kazuhito Hagio <k-hagio-ab@xxxxxxx>
Date: Mon, 20 Nov 2023 13:22:56 +0900
Subject: [PATCH 2/2] Fix typos in offset_table and missing "help -o" items

Several zram related members in the offset_table have typos and
irregular naming rule, also they are not in the "help -o" output.
Let's fix these to avoid confusion.

Signed-off-by: Kazuhito Hagio <k-hagio-ab@xxxxxxx>
---
 defs.h     |  8 ++++----
 diskdump.c | 24 ++++++++++++------------
 memory.c   |  2 +-
 symbols.c  | 12 ++++++++++++
 4 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/defs.h b/defs.h
index 2cae5b61e589..5218a94fe4a4 100644
--- a/defs.h
+++ b/defs.h
@@ -2112,13 +2112,13 @@ struct offset_table {                    /* stash of commonly-used offsets */
 	long bpf_prog_aux_name;
 	long page_private;
 	long swap_info_struct_bdev;
-	long zram_mempoll;
+	long zram_mem_pool;
 	long zram_compressor;
-	long zram_table_flag;
-	long zspoll_size_class;
+	long zram_table_entry_flags;
+	long zs_pool_size_class;
 	long size_class_size;
 	long gendisk_private_data;
-	long zram_table_entry;
+	long zram_table_entry;	/* unused; but cannot remove */
 	long module_core_size_rw;
 	long module_core_size_rx;
 	long module_init_size_rw;
diff --git a/diskdump.c b/diskdump.c
index 25054d96313e..f20f3ac519a1 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -2765,15 +2765,15 @@ zram_init(void)
 {
 	long zram_flag_shift;
 
-	MEMBER_OFFSET_INIT(zram_mempoll, "zram", "mem_pool");
+	MEMBER_OFFSET_INIT(zram_mem_pool, "zram", "mem_pool");
 	MEMBER_OFFSET_INIT(zram_compressor, "zram", "compressor");
 	if (INVALID_MEMBER(zram_compressor))
 		MEMBER_OFFSET_INIT(zram_comp_algs, "zram", "comp_algs");
-	MEMBER_OFFSET_INIT(zram_table_flag, "zram_table_entry", "flags");
-	if (INVALID_MEMBER(zram_table_flag))
-		MEMBER_OFFSET_INIT(zram_table_flag, "zram_table_entry", "value");
+	MEMBER_OFFSET_INIT(zram_table_entry_flags, "zram_table_entry", "flags");
+	if (INVALID_MEMBER(zram_table_entry_flags))
+		MEMBER_OFFSET_INIT(zram_table_entry_flags, "zram_table_entry", "value");
 	STRUCT_SIZE_INIT(zram_table_entry, "zram_table_entry");
-	MEMBER_OFFSET_INIT(zspoll_size_class, "zs_pool", "size_class");
+	MEMBER_OFFSET_INIT(zs_pool_size_class, "zs_pool", "size_class");
 	MEMBER_OFFSET_INIT(size_class_size, "size_class", "size");
 	MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
 
@@ -2826,7 +2826,7 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
 	if (zs_magic != ZSPAGE_MAGIC)
 		error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
 
-	class = pool + OFFSET(zspoll_size_class);
+	class = pool + OFFSET(zs_pool_size_class);
 	class += (class_idx * sizeof(void *));
 	readmem(class, KVADDR, &class, sizeof(void *), "size_class", FAULT_ON_ERROR);
 	readmem(class + OFFSET(size_class_size), KVADDR,
@@ -2987,9 +2987,9 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
 	ulong zram, zram_table_entry, sector, index, entry, flags, size,
 		outsize, off;
 
-	if (INVALID_MEMBER(zram_mempoll)) {
+	if (INVALID_MEMBER(zram_mem_pool)) {
 		zram_init();
-		if (INVALID_MEMBER(zram_mempoll)) {
+		if (INVALID_MEMBER(zram_mem_pool)) {
 			error(WARNING,
 			      "Some pages are swapped out to zram. "
 			      "Please run mod -s zram.\n");
@@ -3013,8 +3013,8 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
 	readmem(zram, KVADDR, &zram_table_entry,
 		sizeof(void *), "zram_table_entry", FAULT_ON_ERROR);
 	zram_table_entry += (index * SIZE(zram_table_entry));
-	readmem(zram_table_entry + OFFSET(zram_table_flag), KVADDR, &flags,
-		sizeof(void *), "zram_table_flag", FAULT_ON_ERROR);
+	readmem(zram_table_entry + OFFSET(zram_table_entry_flags), KVADDR, &flags,
+		sizeof(void *), "zram_table_entry.flags", FAULT_ON_ERROR);
 	if (VALID_MEMBER(zram_compressor))
 		readmem(zram + OFFSET(zram_compressor), KVADDR, name, sizeof(name),
 			"zram compressor", FAULT_ON_ERROR);
@@ -3072,8 +3072,8 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
 		goto out;
 	}
 
-	readmem(zram + OFFSET(zram_mempoll), KVADDR, &zram,
-		sizeof(void *), "zram_mempoll", FAULT_ON_ERROR);
+	readmem(zram + OFFSET(zram_mem_pool), KVADDR, &zram,
+		sizeof(void *), "zram.mem_pool", FAULT_ON_ERROR);
 
 	obj_addr = zram_object_addr(zram, entry, zram_buf);
 	if (obj_addr == NULL) {
diff --git a/memory.c b/memory.c
index 86ccec5e2bac..791194a405d4 100644
--- a/memory.c
+++ b/memory.c
@@ -519,7 +519,7 @@ vm_init(void)
         	"swap_info_struct", "old_block_size");
 	MEMBER_OFFSET_INIT(swap_info_struct_bdev, "swap_info_struct", "bdev");
 
-	MEMBER_OFFSET_INIT(zspoll_size_class, "zs_pool", "size_class");
+	MEMBER_OFFSET_INIT(zs_pool_size_class, "zs_pool", "size_class");
 	MEMBER_OFFSET_INIT(size_class_size, "size_class", "size");
 
 	MEMBER_OFFSET_INIT(block_device_bd_inode, "block_device", "bd_inode");
diff --git a/symbols.c b/symbols.c
index 8e8b4c31d915..176c95026f03 100644
--- a/symbols.c
+++ b/symbols.c
@@ -10304,6 +10304,7 @@ dump_offset_table(char *spec, ulong makestruct)
                 OFFSET(page_active));
         fprintf(fp, "            page_compound_head: %ld\n",
                 OFFSET(page_compound_head));
+        fprintf(fp, "                  page_private: %ld\n", OFFSET(page_private));
 
 	fprintf(fp, "        trace_print_flags_mask: %ld\n",
 		OFFSET(trace_print_flags_mask));
@@ -10330,6 +10331,7 @@ dump_offset_table(char *spec, ulong makestruct)
 		OFFSET(swap_info_struct_inuse_pages));
         fprintf(fp, "swap_info_struct_old_block_size: %ld\n",
 		OFFSET(swap_info_struct_old_block_size));
+        fprintf(fp, "         swap_info_struct_bdev: %ld\n", OFFSET(swap_info_struct_bdev));
 	fprintf(fp, "         block_device_bd_inode: %ld\n",
 		OFFSET(block_device_bd_inode));
 	fprintf(fp, "          block_device_bd_list: %ld\n",
@@ -11359,6 +11361,8 @@ dump_offset_table(char *spec, ulong makestruct)
 		OFFSET(gendisk_part0));
 	fprintf(fp, "                 gendisk_queue: %ld\n",
 		OFFSET(gendisk_queue));
+	fprintf(fp, "          gendisk_private_data: %ld\n", OFFSET(gendisk_private_data));
+
 	fprintf(fp, "                 hd_struct_dev: %ld\n",
 		OFFSET(hd_struct_dev));
 	fprintf(fp, "             hd_struct_dkstats: %ld\n",
@@ -11765,6 +11769,14 @@ dump_offset_table(char *spec, ulong makestruct)
 	fprintf(fp, "            maple_metadata_end: %ld\n", OFFSET(maple_metadata_end));
 	fprintf(fp, "            maple_metadata_gap: %ld\n", OFFSET(maple_metadata_gap));
 
+	fprintf(fp, "                 zram_mem_pool: %ld\n", OFFSET(zram_mem_pool));
+	fprintf(fp, "               zram_compressor: %ld\n", OFFSET(zram_compressor));
+	fprintf(fp, "                zram_comp_algs: %ld\n", OFFSET(zram_comp_algs));
+	fprintf(fp, "        zram_table_entry_flags: %ld\n", OFFSET(zram_table_entry_flags));
+	fprintf(fp, "            zs_pool_size_class: %ld\n", OFFSET(zs_pool_size_class));
+	fprintf(fp, "               size_class_size: %ld\n", OFFSET(size_class_size));
+	fprintf(fp, "                   zspage_huge: %ld\n", OFFSET(zspage_huge));
+
 	fprintf(fp, "\n                    size_table:\n");
 	fprintf(fp, "                          page: %ld\n", SIZE(page));
 	fprintf(fp, "                    page_flags: %ld\n", SIZE(page_flags));
-- 
2.31.1

--
Crash-utility mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxxxxxx
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux