Hi Kazu
Thank you for your advice.
> Does this mean that the current "memset(buf, entry, len)" is a bug,
> because
entry is ulong, right? If so, I agree.
Yes.
Subject: [PATCH] Fix: "rd" command to read zram buf on Linux 5.17 and later
Kernel commit a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage"),
which is contained in Linux 5.17 and later kernels. Use zspage_5_17 to be compatible with later versions.
Kernel commit ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page"),
page->index and page->freelist are at the same offset in struct page.
Kernel commit f635725c3905e ("zram: do not waste zram_table_entry flags bits"),
which is contained in Linux 6.1 and later kernels. let ZRAM_FLAG_SHIFT follow ZRAM_LOCK.
Before:
crash> mod -s zram zram.ko
MODULE NAME BASE SIZE OBJECT FILE
ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
crash> mod -s zsmalloc zsmalloc.ko
MODULE NAME BASE SIZE OBJECT FILE
ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
crash> rd 0x13d89fb0
rd: zspage magic incorrect: b0
After:
crash> rd 0x13d89fb0
13d89fb0: c2b54f7170883b20 ;.pqO..
Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
Link: https://lkml.kernel.org/r/20220912152744.527438-1-senozhatsky@xxxxxxxxxxxx
Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
---
defs.h | 26 +++++++++++++++++++++
diskdump.c | 66 ++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 80 insertions(+), 12 deletions(-)
diff --git a/defs.h b/defs.h
index 96a7a2a..2038351 100644
--- a/defs.h
+++ b/defs.h
@@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
long module_memory_base;
long module_memory_size;
long irq_data_irq;
+ long zspage_huge;
};
struct size_table { /* stash of commonly-used sizes */
@@ -7210,6 +7211,19 @@ ulong try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulon
#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
#define ZRAM_FLAG_SHIFT (1<<24)
#define ZRAM_FLAG_SAME_BIT (1<<25)
+
+struct zram_pageflags {
+ long ZRAM_LOCK;
+ long ZRAM_SAME;
+};
+
+/*
+ * diskdump.c
+ */
+extern struct zram_pageflags zram_pageflags;
+#define ZRAM_PAGEFLAG_INIT(X, Y) (zram_pageflags.X = Y)
+#define ZRAM_PAGEFLAG_VALUE(X) (zram_pageflags.X)
+
struct zspage {
struct {
unsigned int fullness : 2;
@@ -7221,6 +7235,18 @@ struct zspage {
unsigned int freeobj;
};
+struct zspage_5_17 {
+ struct {
+ unsigned int huge : 1;
+ unsigned int fullness : 2;
+ unsigned int class : 9;
+ unsigned int isolated : 3;
+ unsigned int magic : 8;
+ };
+ unsigned int inuse;
+ unsigned int freeobj;
+};
+
/*
* makedumpfile.c
*/
diff --git a/diskdump.c b/diskdump.c
index 2c284ff..d6c114d 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -2745,6 +2745,8 @@ diskdump_device_dump_info(FILE *ofp)
}
}
+struct zram_pageflags zram_pageflags = { 0 };
+
static void
zram_init(void)
{
@@ -2754,6 +2756,17 @@ zram_init(void)
if (INVALID_MEMBER(zram_table_flag))
MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
+ MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
+
+ if (!ZRAM_PAGEFLAG_VALUE(ZRAM_LOCK)) {
+ ZRAM_PAGEFLAG_INIT(ZRAM_LOCK, 24);
+ if (!enumerator_value("ZRAM_LOCK", &zram_pageflags.ZRAM_LOCK)
+ && THIS_KERNEL_VERSION >= LINUX(6,1,0))
+ ZRAM_PAGEFLAG_INIT(ZRAM_LOCK, PAGESHIFT() + 1);
+ ZRAM_PAGEFLAG_INIT(ZRAM_SAME, ZRAM_PAGEFLAG_VALUE(ZRAM_LOCK) + 1);
+ }
}
static unsigned char *
@@ -2761,9 +2774,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
{
ulong obj, off, class, page, zspage;
struct zspage zspage_s;
+ struct zspage_5_17 zspage_5_17_s;
physaddr_t paddr;
unsigned int obj_idx, class_idx, size;
ulong pages[2], sizes[2];
+ ulong zs_magic;
readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
obj >>= OBJ_TAG_BITS;
@@ -2772,11 +2787,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
readmem(page + OFFSET(page_private), KVADDR, &zspage,
sizeof(void *), "page_private", FAULT_ON_ERROR);
- readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
- class_idx = zspage_s.class;
- if (zspage_s.magic != ZSPAGE_MAGIC)
- error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
+ if (VALID_MEMBER(zspage_huge)) {
+ readmem(zspage, KVADDR, &zspage_5_17_s, sizeof(struct zspage_5_17), "zspage_5_17", FAULT_ON_ERROR);
+ class_idx = zspage_5_17_s.class;
+ zs_magic = zspage_5_17_s.magic;
+ } else {
+ readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
+ class_idx = zspage_s.class;
+ zs_magic = zspage_s.magic;
+ }
+
+ if (zs_magic != ZSPAGE_MAGIC)
+ error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
class = pool + OFFSET(zspoll_size_class);
class += (class_idx * sizeof(void *));
@@ -2794,8 +2817,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
}
pages[0] = page;
- readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
- sizeof(void *), "page_freelist", FAULT_ON_ERROR);
+ if (VALID_MEMBER(page_freelist)) {
+ readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
+ sizeof(void *), "page_freelist", FAULT_ON_ERROR);
+ } else {
+ readmem(page + OFFSET(page_index), KVADDR, &pages[1],
+ sizeof(void *), "page_index", FAULT_ON_ERROR);
+ }
sizes[0] = PAGESIZE() - off;
sizes[1] = size - sizes[0];
if (!is_page_ptr(pages[0], &paddr)) {
@@ -2812,9 +2840,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
out:
- readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
- if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
- return (zram_buf + ZS_HANDLE_SIZE);
+ if (!VALID_MEMBER(zspage_huge)) {
+ readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
+ if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
+ return (zram_buf + ZS_HANDLE_SIZE);
+ }
+ } else {
+ if (!zspage_5_17_s.huge) {
+ return (zram_buf + ZS_HANDLE_SIZE);
+ }
}
return zram_buf;
@@ -2929,6 +2963,7 @@ 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;
+ unsigned long *same_buf = NULL;
if (INVALID_MEMBER(zram_compressor)) {
zram_init();
@@ -2992,11 +3027,18 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
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)) {
- memset(buf, entry, len);
+
+ if (!entry || flags & (1 << ZRAM_PAGEFLAG_VALUE(ZRAM_SAME))) {
+ same_buf = (unsigned long *)GETBUF(PAGESIZE());
+ for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
+ same_buf[count] = entry;
+ }
+ memcpy(buf, same_buf + off, len);
+ FREEBUF(same_buf);
goto out;
}
- size = flags & (ZRAM_FLAG_SHIFT -1);
+
+ size = flags & ((1 << ZRAM_PAGEFLAG_VALUE(ZRAM_LOCK)) - 1);
if (size == 0) {
len = 0;
goto out;
--
2.39.0
Thanks.
Guanyou.
--
Crash-utility mailing listCrash-utility@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/crash-utility
Contribution Guidelines: https://github.com/crash-utility/crash/wiki
发件人: HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
发送时间: 2023年10月13日 10:54:44
收件人: 陈冠有; crash-utility@xxxxxxxxxx
抄送: lijiang@xxxxxxxxxx
主题: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
发送时间: 2023年10月13日 10:54:44
收件人: 陈冠有; crash-utility@xxxxxxxxxx
抄送: lijiang@xxxxxxxxxx
主题: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈
On 2023/10/12 17:56, 陈冠有 wrote:
> Subject: [PATCH] Fix: "rd" command to read zram buf on Linux 5.17 and later
>
>
> Kernel commit a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage"),
> which is contained in Linux 5.17 and later kernels.
> Kernel commit ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
> Kernel commit f635725c3905e ("zram: do not waste zram_table_entry flags bits"),
> which is contained in Linux 6.1 and later kernels.
Thanks for sending the updated patch.
The commit log can be updated later... some comments below.
>
> Before:
> crash> mod -s zram zram.ko
> MODULE NAME BASE SIZE OBJECT FILE
> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
> crash> mod -s zsmalloc zsmalloc.ko
> MODULE NAME BASE SIZE OBJECT FILE
> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
> crash> rd 0x13d89fb0
> rd: zspage magic incorrect: b0
>
> After:
> crash> rd 0x13d89fb0
> 13d89fb0: c2b54f7170883b20 ;.pqO..
>
> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> Link: https://lkml.kernel.org/r/20220912152744.527438-1-senozhatsky@xxxxxxxxxxxx
>
> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
> ---
> defs.h | 13 +++++++++++
> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
> 2 files changed, 68 insertions(+), 12 deletions(-)
>
> diff --git a/defs.h b/defs.h
> index 96a7a2a..95ccbb4 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
> long module_memory_base;
> long module_memory_size;
> long irq_data_irq;
> + long zspage_huge;
> };
>
> struct size_table { /* stash of commonly-used sizes */
> @@ -7221,6 +7222,18 @@ struct zspage {
> unsigned int freeobj;
> };
>
> +struct zspage_5_17 {
> + struct {
> + unsigned int huge : 1;
> + unsigned int fullness : 2;
> + unsigned int class : 9;
> + unsigned int isolated : 3;
> + unsigned int magic : 8;
> + };
> + unsigned int inuse;
> + unsigned int freeobj;
> +};
> +
> /*
> * makedumpfile.c
> */
> diff --git a/diskdump.c b/diskdump.c
> index 2c284ff..625b3a0 100644
> --- a/diskdump.c
> +++ b/diskdump.c
> @@ -2754,6 +2754,9 @@ zram_init(void)
> if (INVALID_MEMBER(zram_table_flag))
> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
> }
>
> static unsigned char *
> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
> {
> ulong obj, off, class, page, zspage;
> struct zspage zspage_s;
> + struct zspage_5_17 zspage_5_17_s;
> physaddr_t paddr;
> unsigned int obj_idx, class_idx, size;
> ulong pages[2], sizes[2];
> + ulong zs_magic;
>
> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
> obj >>= OBJ_TAG_BITS;
> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>
> readmem(page + OFFSET(page_private), KVADDR, &zspage,
> sizeof(void *), "page_private", FAULT_ON_ERROR);
> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>
> - class_idx = zspage_s.class;
> - if (zspage_s.magic != ZSPAGE_MAGIC)
> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
> + if (VALID_MEMBER(zspage_huge)) {
> + readmem(zspage, KVADDR, &zspage_5_17_s, sizeof(struct zspage_5_17), "zspage_5_17", FAULT_ON_ERROR);
> + class_idx = zspage_5_17_s.class;
> + zs_magic = zspage_5_17_s.magic;
> + } else {
> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
> + class_idx = zspage_s.class;
> + zs_magic = zspage_s.magic;
> + }
> +
> + if (zs_magic != ZSPAGE_MAGIC)
> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>
> class = pool + OFFSET(zspoll_size_class);
> class += (class_idx * sizeof(void *));
> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
> }
>
> pages[0] = page;
> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + if (VALID_MEMBER(page_freelist)) {
> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + } else {
> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
> + sizeof(void *), "page_index", FAULT_ON_ERROR);
> + }
> sizes[0] = PAGESIZE() - off;
> sizes[1] = size - sizes[0];
> if (!is_page_ptr(pages[0], &paddr)) {
> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>
> out:
> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> - return (zram_buf + ZS_HANDLE_SIZE);
> + if (!VALID_MEMBER(zspage_huge)) {
> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> + } else {
> + if (!zspage_5_17_s.huge) {
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> }
>
> return zram_buf;
> @@ -2929,6 +2953,11 @@ 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;
> + unsigned long *same_buf = NULL;
> + bool is_same = false;
> + ulong ZRAM_SAME_PAGEFLAG;
> + ulong ZRAM_WB_PAGEFLAG;
> + long ZRAM_LOCK_VALUE = 24;
is_same and ZRAM_WB_PAGEFLAG are not used.
cc -c -g -DX86_64 -DLZO -DSNAPPY -DZSTD -DGDB_10_2 diskdump.c -Wall -O2
-Wstrict-prototypes -Wmissing-prototypes -fstack-protector
-Wformat-security
diskdump.c: In function 'try_zram_decompress':
diskdump.c:2959:8: warning: variable 'ZRAM_WB_PAGEFLAG' set but not used
[-Wunused-but-set-variable]
ulong ZRAM_WB_PAGEFLAG;
^~~~~~~~~~~~~~~~
diskdump.c:2957:7: warning: unused variable 'is_same' [-Wunused-variable]
bool is_same = false;
^~~~~~~
>
> if (INVALID_MEMBER(zram_compressor)) {
> zram_init();
> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
> 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)) {
> - memset(buf, entry, len);
> +
> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
This is one of slow functions, so this makes the rd command very slow,
e.g. "rd 7f88aa3ff000 32" takes more than 1 second on a machine:
crash> rd 7f88aa3ff000 32 | elaps.py
7f88aa3ff000: 0000000000000000 0101010101010101 ................
7f88aa3ff010: 0101010101010101 0101010101010101 ................
7f88aa3ff020: 0101010101010101 0101010101010101 ................
...
(elaps: 0:00:01.135)
crash>
The value does not change in a vmcore/kcore, how about having these
static long ZRAM_LOCK;
static long ZRAM_SAME;
in diskdump.c and get it in zram_init()?
> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
> +
> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
> +
> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
> + same_buf[count] = entry;
> + }
Does this mean that the current "memset(buf, entry, len)" is a bug,
because entry is ulong, right? If so, I agree.
> + memcpy(buf, same_buf + off, PAGESIZE());
This PAGESIZE() should be len?
Thanks,
Kazu
> + FREEBUF(same_buf);
> goto out;
> }
> - size = flags & (ZRAM_FLAG_SHIFT -1);
> +
> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
> if (size == 0) {
> len = 0;
> goto out;
> --
> 2.39.0
>
> Thanks.
> --
> Crash-utility mailing list
> Crash-utility@xxxxxxxxxx
> https://listman.redhat.com/mailman/listinfo/crash-utility
> Contribution Guidelines: https://github.com/crash-utility/crash/wiki
>
>
> ________________________________
> 发件人: HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
> 发送时间: 2023年10月12日 16:17:43
> 收件人: 陈冠有; crash-utility@xxxxxxxxxx
> 抄送: lijiang@xxxxxxxxxx
> 主题: Re: 答复: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
>
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈
>
> On 2023/10/09 15:09, 陈冠有 wrote:
>> Hi Kazu
>>
>
> Thank you for the information.
>
> I'm reviewing this, but could you please resend a patch as an attached
> plain text file? Your email cannot be applied with "git am" due to
> base64 encoding and broken indents.
>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the moment.
>
> ok, the commit a41ec880aa7b exists since Linux 5.17, so "zspage_5_17"
> would be better.
>
> Thanks,
> Kazu
>
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>>
>> ________________________________
>> 发件人: HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> 发送时间: 2023年10月4日 9:33:57
>> 收件人: 陈冠有; crash-utility@xxxxxxxxxx
>> 抄送: lijiang@xxxxxxxxxx
>> 主题: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
>>
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
>>
>>
>> Hi Kazu
>>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the
>> moment.
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at
>> the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>> ------------------------------------------------------------------------
>> *发件人:* HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> *发送时间:* 2023年10月4日 9:33:57
>> *收件人:* 陈冠有; crash-utility@xxxxxxxxxx
>> *抄送:* lijiang@xxxxxxxxxx
>> *主题:* [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from
>> page to zspage
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请
>> 将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
>> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
>> in any way (including, but not limited to, total or partial disclosure,
>> reproduction, or dissemination) by persons other than the intended
>> recipient(s) is prohibited. If you receive this e-mail in error, please
>> notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出
>> 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄
>> 露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件
>> 通知发件人并删除本邮件! This e-mail and its attachments contain
>> confidential information from XIAOMI, which is intended only for the
>> person or entity whose address is listed above. Any use of the
>> information contained herein in any way (including, but not limited to,
>> total or partial disclosure, reproduction, or dissemination) by persons
>> other than the intended recipient(s) is prohibited. If you receive this
>> e-mail in error, please notify the sender by phone or email immediately
>> and delete it!******/#
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
>
>
> Subject: [PATCH] Fix: "rd" command to read zram buf on Linux 5.17 and later
>
>
> Kernel commit a41ec880aa7b ("zsmalloc: move huge compressed obj from
> page to zspage"),
> which is contained in Linux 5.17 and later kernels.
> Kernel commit ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct
> page")
> Kernel commit f635725c3905e ("zram: do not waste zram_table_entry flags
> bits"),
> which is contained in Linux 6.1 and later kernels.
>
> Before:
> crash> mod -s zram zram.ko
> MODULE NAME BASE
> SIZE OBJECT FILE
> ffffffde224db800 zram
> ffffffde224d2000 57344 zram.ko
> crash> mod -s zsmalloc zsmalloc.ko
> MODULE NAME BASE
> SIZE OBJECT FILE
> ffffffde224c5180 zsmalloc
> ffffffde224bf000 40960 zsmalloc.ko
> crash> rd 0x13d89fb0
> rd: zspage magic incorrect: b0
>
> After:
> crash> rd 0x13d89fb0
> 13d89fb0: c2b54f7170883b20 ;.pqO..
>
> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> Link:
> https://lkml.kernel.org/r/20220912152744.527438-1-senozhatsky@xxxxxxxxxxxx
>
> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
> ---
> defs.h | 13 +++++++++++
> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
> 2 files changed, 68 insertions(+), 12 deletions(-)
>
> diff --git a/defs.h b/defs.h
> index 96a7a2a..95ccbb4 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash
> of commonly-used offsets */
> long module_memory_base;
> long module_memory_size;
> long irq_data_irq;
> + long zspage_huge;
> };
>
> struct size_table { /* stash of commonly-used sizes */
> @@ -7221,6 +7222,18 @@ struct zspage {
> unsigned int freeobj;
> };
>
> +struct zspage_5_17 {
> + struct {
> + unsigned int huge : 1;
> + unsigned int fullness : 2;
> + unsigned int class : 9;
> + unsigned int isolated : 3;
> + unsigned int magic : 8;
> + };
> + unsigned int inuse;
> + unsigned int freeobj;
> +};
> +
> /*
> * makedumpfile.c
> */
> diff --git a/diskdump.c b/diskdump.c
> index 2c284ff..625b3a0 100644
> --- a/diskdump.c
> +++ b/diskdump.c
> @@ -2754,6 +2754,9 @@ zram_init(void)
> if (INVALID_MEMBER(zram_table_flag))
> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
> }
>
> static unsigned char *
> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
> {
> ulong obj, off, class, page, zspage;
> struct zspage zspage_s;
> + struct zspage_5_17 zspage_5_17_s;
> physaddr_t paddr;
> unsigned int obj_idx, class_idx, size;
> ulong pages[2], sizes[2];
> + ulong zs_magic;
>
> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry",
> FAULT_ON_ERROR);
> obj >>= OBJ_TAG_BITS;
> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
>
> readmem(page + OFFSET(page_private), KVADDR, &zspage,
> sizeof(void *), "page_private", FAULT_ON_ERROR);
> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage",
> FAULT_ON_ERROR);
>
> - class_idx = zspage_s.class;
> - if (zspage_s.magic != ZSPAGE_MAGIC)
> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
> + if (VALID_MEMBER(zspage_huge)) {
> + readmem(zspage, KVADDR, &zspage_5_17_s, sizeof(struct
> zspage_5_17), "zspage_5_17", FAULT_ON_ERROR);
> + class_idx = zspage_5_17_s.class;
> + zs_magic = zspage_5_17_s.magic;
> + } else {
> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage),
> "zspage", FAULT_ON_ERROR);
> + class_idx = zspage_s.class;
> + zs_magic = zspage_s.magic;
> + }
> +
> + if (zs_magic != ZSPAGE_MAGIC)
> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>
> class = pool + OFFSET(zspoll_size_class);
> class += (class_idx * sizeof(void *));
> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
> }
>
> pages[0] = page;
> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + if (VALID_MEMBER(page_freelist)) {
> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + } else {
> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
> + sizeof(void *), "page_index", FAULT_ON_ERROR);
> + }
> sizes[0] = PAGESIZE() - off;
> sizes[1] = size - sizes[0];
> if (!is_page_ptr(pages[0], &paddr)) {
> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram
> buffer[1]", FAULT_ON_ERROR);
>
> out:
> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags",
> FAULT_ON_ERROR);
> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> - return (zram_buf + ZS_HANDLE_SIZE);
> + if (!VALID_MEMBER(zspage_huge)) {
> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags",
> FAULT_ON_ERROR);
> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> + } else {
> + if (!zspage_5_17_s.huge) {
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> }
>
> return zram_buf;
> @@ -2929,6 +2953,11 @@ 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;
> + unsigned long *same_buf = NULL;
> + bool is_same = false;
> + ulong ZRAM_SAME_PAGEFLAG;
> + ulong ZRAM_WB_PAGEFLAG;
> + long ZRAM_LOCK_VALUE = 24;
>
> if (INVALID_MEMBER(zram_compressor)) {
> zram_init();
> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned
> char *buf, ulong len, ulonglong
> 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)) {
> - memset(buf, entry, len);
> +
> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
> +
> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
> +
> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long);
> count++) {
> + same_buf[count] = entry;
> + }
> + memcpy(buf, same_buf + off, PAGESIZE());
> + FREEBUF(same_buf);
> goto out;
> }
> - size = flags & (ZRAM_FLAG_SHIFT -1);
> +
> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
> if (size == 0) {
> len = 0;
> goto out;
> --
> 2.39.0
>
> Thanks.
> --
> Crash-utility mailing list
> Crash-utility@xxxxxxxxxx
> https://listman.redhat.com/mailman/listinfo/crash-utility
> <https://listman.redhat.com/mailman/listinfo/crash-utility>
> Contribution Guidelines: https://github.com/crash-utility/crash/wiki
> <https://github.com/crash-utility/crash/wiki>
>
> ------------------------------------------------------------------------
> *发件人:* HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
> *发送时间:* 2023年10月12日 16:17:43
> *收件人:* 陈冠有; crash-utility@xxxxxxxxxx
> *抄送:* lijiang@xxxxxxxxxx
> *主题:* Re: 答复: [External Mail]Re: [PATCH v4] Fix: move huge
> compressed obj from page to zspage
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请
> 将邮件转发给misec@xxxxxxxxxx进行反馈
>
> On 2023/10/09 15:09, 陈冠有 wrote:
>> Hi Kazu
>>
>
> Thank you for the information.
>
> I'm reviewing this, but could you please resend a patch as an attached
> plain text file? Your email cannot be applied with "git am" due to
> base64 encoding and broken indents.
>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the moment.
>
> ok, the commit a41ec880aa7b exists since Linux 5.17, so "zspage_5_17"
> would be better.
>
> Thanks,
> Kazu
>
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>>
>> ________________________________
>> 发件人: HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> 发送时间: 2023年10月4日 9:33:57
>> 收件人: 陈冠有; crash-utility@xxxxxxxxxx
>> 抄送: lijiang@xxxxxxxxxx
>> 主题: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
>>
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
> in any way (including, but not limited to, total or partial disclosure,
> reproduction, or dissemination) by persons other than the intended
> recipient(s) is prohibited. If you receive this e-mail in error, please
> notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
> in any way (including, but not limited to, total or partial disclosure,
> reproduction, or dissemination) by persons other than the intended
> recipient(s) is prohibited. If you receive this e-mail in error, please
> notify the sender by phone or email immediately and delete it!******/#
>>
>>
>> Hi Kazu
>>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the
>> moment.
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at
>> the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>> ------------------------------------------------------------------------
>> *发件人:* HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> *发送时间:* 2023年10月4日 9:33:57
>> *收件人:* 陈冠有; crash-utility@xxxxxxxxxx
>> *抄送:* lijiang@xxxxxxxxxx
>> *主题:* [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from
>> page to zspage
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请
>> 将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>
>> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>>
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
>> in any way (including, but not limited to, total or partial disclosure,
>> reproduction, or dissemination) by persons other than the intended
>> recipient(s) is prohibited. If you receive this e-mail in error, please
>> notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出
>> 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄
>> 露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件
>> 通知发件人并删除本邮件! This e-mail and its attachments contain
>> confidential information from XIAOMI, which is intended only for the
>> person or entity whose address is listed above. Any use of the
>> information contained herein in any way (including, but not limited to,
>> total or partial disclosure, reproduction, or dissemination) by persons
>> other than the intended recipient(s) is prohibited. If you receive this
>> e-mail in error, please notify the sender by phone or email immediately
>> and delete it!******/#
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出
> 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄
> 露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件
> 通知发件人并删除本邮件! This e-mail and its attachments contain
> confidential information from XIAOMI, which is intended only for the
> person or entity whose address is listed above. Any use of the
> information contained herein in any way (including, but not limited to,
> total or partial disclosure, reproduction, or dissemination) by persons
> other than the intended recipient(s) is prohibited. If you receive this
> e-mail in error, please notify the sender by phone or email immediately
> and delete it!******/#
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or
entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you
receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
On 2023/10/12 17:56, 陈冠有 wrote:
> Subject: [PATCH] Fix: "rd" command to read zram buf on Linux 5.17 and later
>
>
> Kernel commit a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage"),
> which is contained in Linux 5.17 and later kernels.
> Kernel commit ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
> Kernel commit f635725c3905e ("zram: do not waste zram_table_entry flags bits"),
> which is contained in Linux 6.1 and later kernels.
Thanks for sending the updated patch.
The commit log can be updated later... some comments below.
>
> Before:
> crash> mod -s zram zram.ko
> MODULE NAME BASE SIZE OBJECT FILE
> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
> crash> mod -s zsmalloc zsmalloc.ko
> MODULE NAME BASE SIZE OBJECT FILE
> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
> crash> rd 0x13d89fb0
> rd: zspage magic incorrect: b0
>
> After:
> crash> rd 0x13d89fb0
> 13d89fb0: c2b54f7170883b20 ;.pqO..
>
> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> Link: https://lkml.kernel.org/r/20220912152744.527438-1-senozhatsky@xxxxxxxxxxxx
>
> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
> ---
> defs.h | 13 +++++++++++
> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
> 2 files changed, 68 insertions(+), 12 deletions(-)
>
> diff --git a/defs.h b/defs.h
> index 96a7a2a..95ccbb4 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
> long module_memory_base;
> long module_memory_size;
> long irq_data_irq;
> + long zspage_huge;
> };
>
> struct size_table { /* stash of commonly-used sizes */
> @@ -7221,6 +7222,18 @@ struct zspage {
> unsigned int freeobj;
> };
>
> +struct zspage_5_17 {
> + struct {
> + unsigned int huge : 1;
> + unsigned int fullness : 2;
> + unsigned int class : 9;
> + unsigned int isolated : 3;
> + unsigned int magic : 8;
> + };
> + unsigned int inuse;
> + unsigned int freeobj;
> +};
> +
> /*
> * makedumpfile.c
> */
> diff --git a/diskdump.c b/diskdump.c
> index 2c284ff..625b3a0 100644
> --- a/diskdump.c
> +++ b/diskdump.c
> @@ -2754,6 +2754,9 @@ zram_init(void)
> if (INVALID_MEMBER(zram_table_flag))
> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
> }
>
> static unsigned char *
> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
> {
> ulong obj, off, class, page, zspage;
> struct zspage zspage_s;
> + struct zspage_5_17 zspage_5_17_s;
> physaddr_t paddr;
> unsigned int obj_idx, class_idx, size;
> ulong pages[2], sizes[2];
> + ulong zs_magic;
>
> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
> obj >>= OBJ_TAG_BITS;
> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>
> readmem(page + OFFSET(page_private), KVADDR, &zspage,
> sizeof(void *), "page_private", FAULT_ON_ERROR);
> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>
> - class_idx = zspage_s.class;
> - if (zspage_s.magic != ZSPAGE_MAGIC)
> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
> + if (VALID_MEMBER(zspage_huge)) {
> + readmem(zspage, KVADDR, &zspage_5_17_s, sizeof(struct zspage_5_17), "zspage_5_17", FAULT_ON_ERROR);
> + class_idx = zspage_5_17_s.class;
> + zs_magic = zspage_5_17_s.magic;
> + } else {
> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
> + class_idx = zspage_s.class;
> + zs_magic = zspage_s.magic;
> + }
> +
> + if (zs_magic != ZSPAGE_MAGIC)
> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>
> class = pool + OFFSET(zspoll_size_class);
> class += (class_idx * sizeof(void *));
> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
> }
>
> pages[0] = page;
> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + if (VALID_MEMBER(page_freelist)) {
> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + } else {
> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
> + sizeof(void *), "page_index", FAULT_ON_ERROR);
> + }
> sizes[0] = PAGESIZE() - off;
> sizes[1] = size - sizes[0];
> if (!is_page_ptr(pages[0], &paddr)) {
> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>
> out:
> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> - return (zram_buf + ZS_HANDLE_SIZE);
> + if (!VALID_MEMBER(zspage_huge)) {
> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> + } else {
> + if (!zspage_5_17_s.huge) {
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> }
>
> return zram_buf;
> @@ -2929,6 +2953,11 @@ 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;
> + unsigned long *same_buf = NULL;
> + bool is_same = false;
> + ulong ZRAM_SAME_PAGEFLAG;
> + ulong ZRAM_WB_PAGEFLAG;
> + long ZRAM_LOCK_VALUE = 24;
is_same and ZRAM_WB_PAGEFLAG are not used.
cc -c -g -DX86_64 -DLZO -DSNAPPY -DZSTD -DGDB_10_2 diskdump.c -Wall -O2
-Wstrict-prototypes -Wmissing-prototypes -fstack-protector
-Wformat-security
diskdump.c: In function 'try_zram_decompress':
diskdump.c:2959:8: warning: variable 'ZRAM_WB_PAGEFLAG' set but not used
[-Wunused-but-set-variable]
ulong ZRAM_WB_PAGEFLAG;
^~~~~~~~~~~~~~~~
diskdump.c:2957:7: warning: unused variable 'is_same' [-Wunused-variable]
bool is_same = false;
^~~~~~~
>
> if (INVALID_MEMBER(zram_compressor)) {
> zram_init();
> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
> 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)) {
> - memset(buf, entry, len);
> +
> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
This is one of slow functions, so this makes the rd command very slow,
e.g. "rd 7f88aa3ff000 32" takes more than 1 second on a machine:
crash> rd 7f88aa3ff000 32 | elaps.py
7f88aa3ff000: 0000000000000000 0101010101010101 ................
7f88aa3ff010: 0101010101010101 0101010101010101 ................
7f88aa3ff020: 0101010101010101 0101010101010101 ................
...
(elaps: 0:00:01.135)
crash>
The value does not change in a vmcore/kcore, how about having these
static long ZRAM_LOCK;
static long ZRAM_SAME;
in diskdump.c and get it in zram_init()?
> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
> +
> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
> +
> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
> + same_buf[count] = entry;
> + }
Does this mean that the current "memset(buf, entry, len)" is a bug,
because entry is ulong, right? If so, I agree.
> + memcpy(buf, same_buf + off, PAGESIZE());
This PAGESIZE() should be len?
Thanks,
Kazu
> + FREEBUF(same_buf);
> goto out;
> }
> - size = flags & (ZRAM_FLAG_SHIFT -1);
> +
> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
> if (size == 0) {
> len = 0;
> goto out;
> --
> 2.39.0
>
> Thanks.
> --
> Crash-utility mailing list
> Crash-utility@xxxxxxxxxx
> https://listman.redhat.com/mailman/listinfo/crash-utility
> Contribution Guidelines: https://github.com/crash-utility/crash/wiki
>
>
> ________________________________
> 发件人: HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
> 发送时间: 2023年10月12日 16:17:43
> 收件人: 陈冠有; crash-utility@xxxxxxxxxx
> 抄送: lijiang@xxxxxxxxxx
> 主题: Re: 答复: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
>
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈
>
> On 2023/10/09 15:09, 陈冠有 wrote:
>> Hi Kazu
>>
>
> Thank you for the information.
>
> I'm reviewing this, but could you please resend a patch as an attached
> plain text file? Your email cannot be applied with "git am" due to
> base64 encoding and broken indents.
>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the moment.
>
> ok, the commit a41ec880aa7b exists since Linux 5.17, so "zspage_5_17"
> would be better.
>
> Thanks,
> Kazu
>
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>>
>> ________________________________
>> 发件人: HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> 发送时间: 2023年10月4日 9:33:57
>> 收件人: 陈冠有; crash-utility@xxxxxxxxxx
>> 抄送: lijiang@xxxxxxxxxx
>> 主题: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
>>
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
>>
>>
>> Hi Kazu
>>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the
>> moment.
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at
>> the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>> ------------------------------------------------------------------------
>> *发件人:* HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> *发送时间:* 2023年10月4日 9:33:57
>> *收件人:* 陈冠有; crash-utility@xxxxxxxxxx
>> *抄送:* lijiang@xxxxxxxxxx
>> *主题:* [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from
>> page to zspage
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请
>> 将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
>> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
>> in any way (including, but not limited to, total or partial disclosure,
>> reproduction, or dissemination) by persons other than the intended
>> recipient(s) is prohibited. If you receive this e-mail in error, please
>> notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出
>> 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄
>> 露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件
>> 通知发件人并删除本邮件! This e-mail and its attachments contain
>> confidential information from XIAOMI, which is intended only for the
>> person or entity whose address is listed above. Any use of the
>> information contained herein in any way (including, but not limited to,
>> total or partial disclosure, reproduction, or dissemination) by persons
>> other than the intended recipient(s) is prohibited. If you receive this
>> e-mail in error, please notify the sender by phone or email immediately
>> and delete it!******/#
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
>
>
> Subject: [PATCH] Fix: "rd" command to read zram buf on Linux 5.17 and later
>
>
> Kernel commit a41ec880aa7b ("zsmalloc: move huge compressed obj from
> page to zspage"),
> which is contained in Linux 5.17 and later kernels.
> Kernel commit ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct
> page")
> Kernel commit f635725c3905e ("zram: do not waste zram_table_entry flags
> bits"),
> which is contained in Linux 6.1 and later kernels.
>
> Before:
> crash> mod -s zram zram.ko
> MODULE NAME BASE
> SIZE OBJECT FILE
> ffffffde224db800 zram
> ffffffde224d2000 57344 zram.ko
> crash> mod -s zsmalloc zsmalloc.ko
> MODULE NAME BASE
> SIZE OBJECT FILE
> ffffffde224c5180 zsmalloc
> ffffffde224bf000 40960 zsmalloc.ko
> crash> rd 0x13d89fb0
> rd: zspage magic incorrect: b0
>
> After:
> crash> rd 0x13d89fb0
> 13d89fb0: c2b54f7170883b20 ;.pqO..
>
> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> Link:
> https://lkml.kernel.org/r/20220912152744.527438-1-senozhatsky@xxxxxxxxxxxx
>
> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
> ---
> defs.h | 13 +++++++++++
> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
> 2 files changed, 68 insertions(+), 12 deletions(-)
>
> diff --git a/defs.h b/defs.h
> index 96a7a2a..95ccbb4 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash
> of commonly-used offsets */
> long module_memory_base;
> long module_memory_size;
> long irq_data_irq;
> + long zspage_huge;
> };
>
> struct size_table { /* stash of commonly-used sizes */
> @@ -7221,6 +7222,18 @@ struct zspage {
> unsigned int freeobj;
> };
>
> +struct zspage_5_17 {
> + struct {
> + unsigned int huge : 1;
> + unsigned int fullness : 2;
> + unsigned int class : 9;
> + unsigned int isolated : 3;
> + unsigned int magic : 8;
> + };
> + unsigned int inuse;
> + unsigned int freeobj;
> +};
> +
> /*
> * makedumpfile.c
> */
> diff --git a/diskdump.c b/diskdump.c
> index 2c284ff..625b3a0 100644
> --- a/diskdump.c
> +++ b/diskdump.c
> @@ -2754,6 +2754,9 @@ zram_init(void)
> if (INVALID_MEMBER(zram_table_flag))
> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
> }
>
> static unsigned char *
> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
> {
> ulong obj, off, class, page, zspage;
> struct zspage zspage_s;
> + struct zspage_5_17 zspage_5_17_s;
> physaddr_t paddr;
> unsigned int obj_idx, class_idx, size;
> ulong pages[2], sizes[2];
> + ulong zs_magic;
>
> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry",
> FAULT_ON_ERROR);
> obj >>= OBJ_TAG_BITS;
> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
>
> readmem(page + OFFSET(page_private), KVADDR, &zspage,
> sizeof(void *), "page_private", FAULT_ON_ERROR);
> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage",
> FAULT_ON_ERROR);
>
> - class_idx = zspage_s.class;
> - if (zspage_s.magic != ZSPAGE_MAGIC)
> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
> + if (VALID_MEMBER(zspage_huge)) {
> + readmem(zspage, KVADDR, &zspage_5_17_s, sizeof(struct
> zspage_5_17), "zspage_5_17", FAULT_ON_ERROR);
> + class_idx = zspage_5_17_s.class;
> + zs_magic = zspage_5_17_s.magic;
> + } else {
> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage),
> "zspage", FAULT_ON_ERROR);
> + class_idx = zspage_s.class;
> + zs_magic = zspage_s.magic;
> + }
> +
> + if (zs_magic != ZSPAGE_MAGIC)
> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>
> class = pool + OFFSET(zspoll_size_class);
> class += (class_idx * sizeof(void *));
> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
> }
>
> pages[0] = page;
> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + if (VALID_MEMBER(page_freelist)) {
> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
> + } else {
> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
> + sizeof(void *), "page_index", FAULT_ON_ERROR);
> + }
> sizes[0] = PAGESIZE() - off;
> sizes[1] = size - sizes[0];
> if (!is_page_ptr(pages[0], &paddr)) {
> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle,
> unsigned char *zram_buf)
> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram
> buffer[1]", FAULT_ON_ERROR);
>
> out:
> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags",
> FAULT_ON_ERROR);
> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> - return (zram_buf + ZS_HANDLE_SIZE);
> + if (!VALID_MEMBER(zspage_huge)) {
> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags",
> FAULT_ON_ERROR);
> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> + } else {
> + if (!zspage_5_17_s.huge) {
> + return (zram_buf + ZS_HANDLE_SIZE);
> + }
> }
>
> return zram_buf;
> @@ -2929,6 +2953,11 @@ 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;
> + unsigned long *same_buf = NULL;
> + bool is_same = false;
> + ulong ZRAM_SAME_PAGEFLAG;
> + ulong ZRAM_WB_PAGEFLAG;
> + long ZRAM_LOCK_VALUE = 24;
>
> if (INVALID_MEMBER(zram_compressor)) {
> zram_init();
> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned
> char *buf, ulong len, ulonglong
> 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)) {
> - memset(buf, entry, len);
> +
> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
> +
> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
> +
> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long);
> count++) {
> + same_buf[count] = entry;
> + }
> + memcpy(buf, same_buf + off, PAGESIZE());
> + FREEBUF(same_buf);
> goto out;
> }
> - size = flags & (ZRAM_FLAG_SHIFT -1);
> +
> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
> if (size == 0) {
> len = 0;
> goto out;
> --
> 2.39.0
>
> Thanks.
> --
> Crash-utility mailing list
> Crash-utility@xxxxxxxxxx
> https://listman.redhat.com/mailman/listinfo/crash-utility
> <https://listman.redhat.com/mailman/listinfo/crash-utility>
> Contribution Guidelines: https://github.com/crash-utility/crash/wiki
> <https://github.com/crash-utility/crash/wiki>
>
> ------------------------------------------------------------------------
> *发件人:* HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
> *发送时间:* 2023年10月12日 16:17:43
> *收件人:* 陈冠有; crash-utility@xxxxxxxxxx
> *抄送:* lijiang@xxxxxxxxxx
> *主题:* Re: 答复: [External Mail]Re: [PATCH v4] Fix: move huge
> compressed obj from page to zspage
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请
> 将邮件转发给misec@xxxxxxxxxx进行反馈
>
> On 2023/10/09 15:09, 陈冠有 wrote:
>> Hi Kazu
>>
>
> Thank you for the information.
>
> I'm reviewing this, but could you please resend a patch as an attached
> plain text file? Your email cannot be applied with "git am" due to
> base64 encoding and broken indents.
>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the moment.
>
> ok, the commit a41ec880aa7b exists since Linux 5.17, so "zspage_5_17"
> would be better.
>
> Thanks,
> Kazu
>
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>>
>> ________________________________
>> 发件人: HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> 发送时间: 2023年10月4日 9:33:57
>> 收件人: 陈冠有; crash-utility@xxxxxxxxxx
>> 抄送: lijiang@xxxxxxxxxx
>> 主题: [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from page to zspage
>>
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
> in any way (including, but not limited to, total or partial disclosure,
> reproduction, or dissemination) by persons other than the intended
> recipient(s) is prohibited. If you receive this e-mail in error, please
> notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
> in any way (including, but not limited to, total or partial disclosure,
> reproduction, or dissemination) by persons other than the intended
> recipient(s) is prohibited. If you receive this e-mail in error, please
> notify the sender by phone or email immediately and delete it!******/#
>>
>>
>> Hi Kazu
>>
>>
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>> zspage6 meam linux 6 and later, because I don't have a better way at the
>> moment.
>>
>>
>> ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page")
>>
>> using page->index to store 'page' (page->index and page->freelist are at
>> the same offset in struct page).
>>
>>
>> f635725c3905e ("zram: do not waste zram_table_entry flags bits")
>>
>> -#define ZRAM_FLAG_SHIFT 24
>> +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
>>
>> enum zram_pageflags {
>> /* zram slot is locked */
>> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
>> ZRAM_SAME, /* Page consists the same element */
>> ZRAM_WB, /* page is stored on backing_device */
>> ZRAM_UNDER_WB, /* page is under writeback */
>> ZRAM_HUGE, /* Incompressible page */
>> ZRAM_IDLE, /* not accessed page since last idle marking */
>> ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */
>>
>> ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */
>> ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */
>>
>> __NR_ZRAM_PAGEFLAGS,
>> };
>>
>> Thanks
>>
>> ------------------------------------------------------------------------
>> *发件人:* HAGIO KAZUHITO(?尾 一仁) <k-hagio-ab@xxxxxxx>
>> *发送时间:* 2023年10月4日 9:33:57
>> *收件人:* 陈冠有; crash-utility@xxxxxxxxxx
>> *抄送:* lijiang@xxxxxxxxxx
>> *主题:* [External Mail]Re: [PATCH v4] Fix: move huge compressed obj from
>> page to zspage
>> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请
>> 将邮件转发给misec@xxxxxxxxxx进行反馈
>>
>> On 2023/09/20 12:28, 陈冠有 wrote:
>>> when zspage define 'huge', crash-utility zram decompress fail.
>>> we need to be compatible with the previous kernel,
>>> so we can't define 'huge' directly in zspage.
>>
>> Thank you for the patch, is this v4 patch the latest one?
>>
>>>
>>> Before:
>>> crash> mod -s zram zram.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224db800 zram ffffffde224d2000 57344 zram.ko
>>> crash> mod -s zsmalloc zsmalloc.ko
>>> MODULE NAME BASE SIZE OBJECT FILE
>>> ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko
>>> crash> rd 0x13d89fb0
>>> rd: zspage magic incorrect: b0
>>>
>>> After:
>>> crash> rd 0x13d89fb0
>>> 13d89fb0: c2b54f7170883b20 ;.pqO..
>>>
>>> Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>
>> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx
> <https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx>>
>>
>> Please use the commit information if it's already in the kernel.
>> a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage")
>>
>>>
>>> Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
>>> ---
>>> defs.h | 13 +++++++++++
>>> diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----------
>>> 2 files changed, 68 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/defs.h b/defs.h
>>> index 96a7a2a..0af69cc 100644
>>> --- a/defs.h
>>> +++ b/defs.h
>>> @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */
>>> long module_memory_base;
>>> long module_memory_size;
>>> long irq_data_irq;
>>> + long zspage_huge;
>>> };
>>>
>>> struct size_table { /* stash of commonly-used sizes */
>>> @@ -7221,6 +7222,18 @@ struct zspage {
>>> unsigned int freeobj;
>>> };
>>>
>>> +struct zspage6 {
>>
>> Why is this name "zspage6"?
>>
>>> + struct {
>>> + unsigned int huge : 1;
>>> + unsigned int fullness : 2;
>>> + unsigned int class : 9;
>>> + unsigned int isolated : 3;
>>> + unsigned int magic : 8;
>>> + };
>>> + unsigned int inuse;
>>> + unsigned int freeobj;
>>> +};
>>> +
>>> /*
>>> * makedumpfile.c
>>> */
>>> diff --git a/diskdump.c b/diskdump.c
>>> index 2c284ff..02aaf1b 100644
>>> --- a/diskdump.c
>>> +++ b/diskdump.c
>>> @@ -2754,6 +2754,9 @@ zram_init(void)
>>> if (INVALID_MEMBER(zram_table_flag))
>>> MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size");
>>> + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge");
>>> }
>>>
>>> static unsigned char *
>>> @@ -2761,9 +2764,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> {
>>> ulong obj, off, class, page, zspage;
>>> struct zspage zspage_s;
>>> + struct zspage6 zspage6_s;
>>> physaddr_t paddr;
>>> unsigned int obj_idx, class_idx, size;
>>> ulong pages[2], sizes[2];
>>> + ulong zs_magic;
>>>
>>> readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR);
>>> obj >>= OBJ_TAG_BITS;
>>> @@ -2772,11 +2777,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>>
>>> readmem(page + OFFSET(page_private), KVADDR, &zspage,
>>> sizeof(void *), "page_private", FAULT_ON_ERROR);
>>> - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>>
>>> - class_idx = zspage_s.class;
>>> - if (zspage_s.magic != ZSPAGE_MAGIC)
>>> - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic);
>>> + if (VALID_MEMBER(zspage_huge)) {
>>> + readmem(zspage, KVADDR, &zspage6_s, sizeof(struct zspage6), "zspage6", FAULT_ON_ERROR);
>>> + class_idx = zspage6_s.class;
>>> + zs_magic = zspage6_s.magic;
>>> + } else {
>>> + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
>>> + class_idx = zspage_s.class;
>>> + zs_magic = zspage_s.magic;
>>> + }
>>> +
>>> + if (zs_magic != ZSPAGE_MAGIC)
>>> + error(FATAL, "zspage magic incorrect: %x\n", zs_magic);
>>>
>>> class = pool + OFFSET(zspoll_size_class);
>>> class += (class_idx * sizeof(void *));
>>> @@ -2794,8 +2807,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> }
>>>
>>> pages[0] = page;
>>> - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> - sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + if (VALID_MEMBER(page_freelist)) {
>>> + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1],
>>> + sizeof(void *), "page_freelist", FAULT_ON_ERROR);
>>> + } else {
>>> + readmem(page + OFFSET(page_index), KVADDR, &pages[1],
>>> + sizeof(void *), "page_index", FAULT_ON_ERROR);
>>> + }
>>
>> What is the kernel commit related to this hunk?
>>
>>> sizes[0] = PAGESIZE() - off;
>>> sizes[1] = size - sizes[0];
>>> if (!is_page_ptr(pages[0], &paddr)) {
>>> @@ -2812,9 +2830,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
>>> readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR);
>>>
>>> out:
>>> - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> - return (zram_buf + ZS_HANDLE_SIZE);
>>> + if (!VALID_MEMBER(zspage_huge)) {
>>> + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
>>> + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> + } else {
>>> + if (!zspage6_s.huge) {
>>> + return (zram_buf + ZS_HANDLE_SIZE);
>>> + }
>>> }
>>>
>>> return zram_buf;
>>> @@ -2929,6 +2953,11 @@ 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;
>>> + unsigned long *same_buf = NULL;
>>> + bool is_same = false;
>>> + ulong ZRAM_SAME_PAGEFLAG;
>>> + ulong ZRAM_WB_PAGEFLAG;
>>> + long ZRAM_LOCK_VALUE = 24;
>>>
>>> if (INVALID_MEMBER(zram_compressor)) {
>>> zram_init();
>>> @@ -2992,11 +3021,25 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
>>> 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)) {
>>> - memset(buf, entry, len);
>>> +
>>> + if (!enumerator_value("ZRAM_LOCK", &ZRAM_LOCK_VALUE)
>>> + && THIS_KERNEL_VERSION >= LINUX(6,1,0))
>>> + ZRAM_LOCK_VALUE = PAGESHIFT() + 1;
>>> +
>>> + ZRAM_SAME_PAGEFLAG = ZRAM_LOCK_VALUE + 1;
>>> + ZRAM_WB_PAGEFLAG = ZRAM_LOCK_VALUE + 2;
>>> +
>>> + if (!entry || flags & (1 << ZRAM_SAME_PAGEFLAG)) {
>>> + same_buf = (unsigned long *)GETBUF(PAGESIZE());
>>> + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) {
>>> + same_buf[count] = entry;
>>> + }
>>> + memcpy(buf, same_buf + off, PAGESIZE());
>>> + FREEBUF(same_buf);
>>
>> What is the kernel commit related to this hunk?
>>
>> And I could not apply this, could you resend it as a plain text email or
>> an attached plain text file?
>>
>> Thanks,
>> Kazu
>>
>>> goto out;
>>> }
>>> - size = flags & (ZRAM_FLAG_SHIFT -1);
>>> +
>>> + size = flags & ((1 << ZRAM_LOCK_VALUE) - 1);
>>> if (size == 0) {
>>> len = 0;
>>> goto out;
>>> --
>>> 2.39.0
>>>
>>>
>>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein
>> in any way (including, but not limited to, total or partial disclosure,
>> reproduction, or dissemination) by persons other than the intended
>> recipient(s) is prohibited. If you receive this e-mail in error, please
>> notify the sender by phone or email immediately and delete it!******/#
>> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出
>> 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄
>> 露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件
>> 通知发件人并删除本邮件! This e-mail and its attachments contain
>> confidential information from XIAOMI, which is intended only for the
>> person or entity whose address is listed above. Any use of the
>> information contained herein in any way (including, but not limited to,
>> total or partial disclosure, reproduction, or dissemination) by persons
>> other than the intended recipient(s) is prohibited. If you receive this
>> e-mail in error, please notify the sender by phone or email immediately
>> and delete it!******/#
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出
> 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄
> 露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件
> 通知发件人并删除本邮件! This e-mail and its attachments contain
> confidential information from XIAOMI, which is intended only for the
> person or entity whose address is listed above. Any use of the
> information contained herein in any way (including, but not limited to,
> total or partial disclosure, reproduction, or dissemination) by persons
> other than the intended recipient(s) is prohibited. If you receive this
> e-mail in error, please notify the sender by phone or email immediately
> and delete it!******/#
From 47a1139126e7467044f95cc23ac463b1a6c1915c Mon Sep 17 00:00:00 2001 From: chenguanyou <chenguanyou@xxxxxxxxxx> Date: Mon, 11 Sep 2023 20:59:39 +0800 Subject: [PATCH] Fix: "rd" command to read zram buf on Linux 5.17 and later Kernel commit a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage"), which is contained in Linux 5.17 and later kernels. Use zspage_5_17 to be compatible with later versions. Kernel commit ffedd09fa9b06 ("zsmalloc: Stop using slab fields in struct page"), page->index and page->freelist are at the same offset in struct page. Kernel commit f635725c3905e ("zram: do not waste zram_table_entry flags bits"), which is contained in Linux 6.1 and later kernels. let ZRAM_FLAG_SHIFT follow ZRAM_LOCK. Before: crash> mod -s zram zram.ko MODULE NAME BASE SIZE OBJECT FILE ffffffde224db800 zram ffffffde224d2000 57344 zram.ko crash> mod -s zsmalloc zsmalloc.ko MODULE NAME BASE SIZE OBJECT FILE ffffffde224c5180 zsmalloc ffffffde224bf000 40960 zsmalloc.ko crash> rd 0x13d89fb0 rd: zspage magic incorrect: b0 After: crash> rd 0x13d89fb0 13d89fb0: c2b54f7170883b20 ;.pqO.. Link: https://lkml.kernel.org/r/20211115185909.3949505-6-minchan@xxxxxxxxxx Link: https://lkml.kernel.org/r/20220912152744.527438-1-senozhatsky@xxxxxxxxxxxx Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx> --- defs.h | 26 +++++++++++++++++++++ diskdump.c | 66 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/defs.h b/defs.h index 96a7a2a..2038351 100644 --- a/defs.h +++ b/defs.h @@ -2225,6 +2225,7 @@ struct offset_table { /* stash of commonly-used offsets */ long module_memory_base; long module_memory_size; long irq_data_irq; + long zspage_huge; }; struct size_table { /* stash of commonly-used sizes */ @@ -7210,6 +7211,19 @@ ulong try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulon #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT) #define ZRAM_FLAG_SHIFT (1<<24) #define ZRAM_FLAG_SAME_BIT (1<<25) + +struct zram_pageflags { + long ZRAM_LOCK; + long ZRAM_SAME; +}; + +/* + * diskdump.c + */ +extern struct zram_pageflags zram_pageflags; +#define ZRAM_PAGEFLAG_INIT(X, Y) (zram_pageflags.X = Y) +#define ZRAM_PAGEFLAG_VALUE(X) (zram_pageflags.X) + struct zspage { struct { unsigned int fullness : 2; @@ -7221,6 +7235,18 @@ struct zspage { unsigned int freeobj; }; +struct zspage_5_17 { + struct { + unsigned int huge : 1; + unsigned int fullness : 2; + unsigned int class : 9; + unsigned int isolated : 3; + unsigned int magic : 8; + }; + unsigned int inuse; + unsigned int freeobj; +}; + /* * makedumpfile.c */ diff --git a/diskdump.c b/diskdump.c index 2c284ff..d6c114d 100644 --- a/diskdump.c +++ b/diskdump.c @@ -2745,6 +2745,8 @@ diskdump_device_dump_info(FILE *ofp) } } +struct zram_pageflags zram_pageflags = { 0 }; + static void zram_init(void) { @@ -2754,6 +2756,17 @@ zram_init(void) if (INVALID_MEMBER(zram_table_flag)) MEMBER_OFFSET_INIT(zram_table_flag, "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(size_class_size, "size_class", "size"); + MEMBER_OFFSET_INIT(zspage_huge, "zspage", "huge"); + + if (!ZRAM_PAGEFLAG_VALUE(ZRAM_LOCK)) { + ZRAM_PAGEFLAG_INIT(ZRAM_LOCK, 24); + if (!enumerator_value("ZRAM_LOCK", &zram_pageflags.ZRAM_LOCK) + && THIS_KERNEL_VERSION >= LINUX(6,1,0)) + ZRAM_PAGEFLAG_INIT(ZRAM_LOCK, PAGESHIFT() + 1); + ZRAM_PAGEFLAG_INIT(ZRAM_SAME, ZRAM_PAGEFLAG_VALUE(ZRAM_LOCK) + 1); + } } static unsigned char * @@ -2761,9 +2774,11 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf) { ulong obj, off, class, page, zspage; struct zspage zspage_s; + struct zspage_5_17 zspage_5_17_s; physaddr_t paddr; unsigned int obj_idx, class_idx, size; ulong pages[2], sizes[2]; + ulong zs_magic; readmem(handle, KVADDR, &obj, sizeof(void *), "zram entry", FAULT_ON_ERROR); obj >>= OBJ_TAG_BITS; @@ -2772,11 +2787,19 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf) readmem(page + OFFSET(page_private), KVADDR, &zspage, sizeof(void *), "page_private", FAULT_ON_ERROR); - readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR); - class_idx = zspage_s.class; - if (zspage_s.magic != ZSPAGE_MAGIC) - error(FATAL, "zspage magic incorrect: %x\n", zspage_s.magic); + if (VALID_MEMBER(zspage_huge)) { + readmem(zspage, KVADDR, &zspage_5_17_s, sizeof(struct zspage_5_17), "zspage_5_17", FAULT_ON_ERROR); + class_idx = zspage_5_17_s.class; + zs_magic = zspage_5_17_s.magic; + } else { + readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR); + class_idx = zspage_s.class; + zs_magic = zspage_s.magic; + } + + if (zs_magic != ZSPAGE_MAGIC) + error(FATAL, "zspage magic incorrect: %x\n", zs_magic); class = pool + OFFSET(zspoll_size_class); class += (class_idx * sizeof(void *)); @@ -2794,8 +2817,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf) } pages[0] = page; - readmem(page + OFFSET(page_freelist), KVADDR, &pages[1], - sizeof(void *), "page_freelist", FAULT_ON_ERROR); + if (VALID_MEMBER(page_freelist)) { + readmem(page + OFFSET(page_freelist), KVADDR, &pages[1], + sizeof(void *), "page_freelist", FAULT_ON_ERROR); + } else { + readmem(page + OFFSET(page_index), KVADDR, &pages[1], + sizeof(void *), "page_index", FAULT_ON_ERROR); + } sizes[0] = PAGESIZE() - off; sizes[1] = size - sizes[0]; if (!is_page_ptr(pages[0], &paddr)) { @@ -2812,9 +2840,15 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf) readmem(paddr, PHYSADDR, zram_buf + sizes[0], sizes[1], "zram buffer[1]", FAULT_ON_ERROR); out: - readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR); - if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag - return (zram_buf + ZS_HANDLE_SIZE); + if (!VALID_MEMBER(zspage_huge)) { + readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR); + if (!(obj & (1<<10))) { //PG_OwnerPriv1 flag + return (zram_buf + ZS_HANDLE_SIZE); + } + } else { + if (!zspage_5_17_s.huge) { + return (zram_buf + ZS_HANDLE_SIZE); + } } return zram_buf; @@ -2929,6 +2963,7 @@ 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; + unsigned long *same_buf = NULL; if (INVALID_MEMBER(zram_compressor)) { zram_init(); @@ -2992,11 +3027,18 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong 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)) { - memset(buf, entry, len); + + if (!entry || flags & (1 << ZRAM_PAGEFLAG_VALUE(ZRAM_SAME))) { + same_buf = (unsigned long *)GETBUF(PAGESIZE()); + for (int count = 0; count < PAGESIZE() / sizeof(unsigned long); count++) { + same_buf[count] = entry; + } + memcpy(buf, same_buf + off, len); + FREEBUF(same_buf); goto out; } - size = flags & (ZRAM_FLAG_SHIFT -1); + + size = flags & ((1 << ZRAM_PAGEFLAG_VALUE(ZRAM_LOCK)) - 1); if (size == 0) { len = 0; goto out; -- 2.39.0
-- Crash-utility mailing list Crash-utility@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/crash-utility Contribution Guidelines: https://github.com/crash-utility/crash/wiki