d33f440f04
Release crash-7.2.9-6 Resolves: rhbz#1895255 Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
155 lines
5.5 KiB
Diff
155 lines
5.5 KiB
Diff
From 74474a366d1244d344ad9ff222e8e2351a96af8c Mon Sep 17 00:00:00 2001
|
|
From: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
|
|
Date: Fri, 25 Dec 2020 15:48:50 +0900
|
|
Subject: [PATCH 09/11] memory, zram: introduce and export readswap()
|
|
|
|
try_zram_decompress() is currently exported to extension modules, but
|
|
from a viewpoint of author of extension modules, it's better to export
|
|
an interface to read memory on swap; difference of decompressor are
|
|
then hidden within the interface and there is no need for extension
|
|
modules to update accordingly each time new decompressor are added in
|
|
the future.
|
|
|
|
So let's introduce function readswap() as an interface to read memory
|
|
on swap.
|
|
|
|
Signed-off-by: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
|
|
---
|
|
defs.h | 1 +
|
|
diskdump.c | 63 ++++++++++++++++++++++++++++++++++++++----------------
|
|
memory.c | 2 +-
|
|
3 files changed, 46 insertions(+), 20 deletions(-)
|
|
|
|
diff --git a/defs.h b/defs.h
|
|
index ebd7bb615b61..c29b3fa3dee9 100644
|
|
--- a/defs.h
|
|
+++ b/defs.h
|
|
@@ -6539,6 +6539,7 @@ int diskdump_get_nr_cpus(void);
|
|
QEMUCPUState *diskdump_get_qemucpustate(int);
|
|
void diskdump_device_dump_info(FILE *);
|
|
void diskdump_device_dump_extract(int, char *, FILE *);
|
|
+ulong readswap(ulonglong pte_val, char *buf, ulong len, ulonglong vaddr);
|
|
/*support for zram*/
|
|
ulong try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong vaddr);
|
|
#define OBJ_TAG_BITS 1
|
|
diff --git a/diskdump.c b/diskdump.c
|
|
index a4ca38f6c732..03a77a977646 100644
|
|
--- a/diskdump.c
|
|
+++ b/diskdump.c
|
|
@@ -2709,24 +2709,13 @@ lookup_swap_cache(ulonglong pte_val, unsigned char *zram_buf)
|
|
return NULL;
|
|
}
|
|
|
|
-ulong (*decompressor)(unsigned char *in_addr, ulong in_size, unsigned char *out_addr, ulong *out_size, void *other/* NOT USED */);
|
|
-/*
|
|
- * If userspace address was swapped out to zram, this function is called to decompress the object.
|
|
- * try_zram_decompress returns decompressed page data and data length
|
|
- */
|
|
-ulong
|
|
-try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong vaddr)
|
|
+static int get_disk_name_private_data(ulonglong pte_val, ulonglong vaddr,
|
|
+ char *name, ulong *private_data)
|
|
{
|
|
- char name[32] = {0};
|
|
- ulonglong swp_offset;
|
|
- ulong swap_info, bdev, bd_disk, zram, zram_table_entry, sector, index, entry, flags, size, outsize, off;
|
|
- unsigned char *obj_addr = NULL;
|
|
- unsigned char *zram_buf = NULL;
|
|
- unsigned char *outbuf = NULL;
|
|
+ ulong swap_info, bdev, bd_disk;
|
|
|
|
- off = PAGEOFFSET(vaddr);
|
|
if (!symbol_exists("swap_info"))
|
|
- return 0;
|
|
+ return FALSE;
|
|
|
|
swap_info = symbol_value("swap_info");
|
|
|
|
@@ -2743,14 +2732,49 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
|
|
sizeof(void *), "swap_info_struct_bdev", FAULT_ON_ERROR);
|
|
readmem(bdev + OFFSET(block_device_bd_disk), KVADDR, &bd_disk,
|
|
sizeof(void *), "block_device_bd_disk", FAULT_ON_ERROR);
|
|
- readmem(bd_disk + OFFSET(gendisk_disk_name), KVADDR, name,
|
|
+ if (name)
|
|
+ readmem(bd_disk + OFFSET(gendisk_disk_name), KVADDR, name,
|
|
strlen("zram"), "gendisk_disk_name", FAULT_ON_ERROR);
|
|
+ if (private_data)
|
|
+ readmem(bd_disk + OFFSET(gendisk_private_data), KVADDR,
|
|
+ private_data, sizeof(void *), "gendisk_private_data",
|
|
+ FAULT_ON_ERROR);
|
|
+
|
|
+ return TRUE;
|
|
+}
|
|
+
|
|
+ulong readswap(ulonglong pte_val, char *buf, ulong len, ulonglong vaddr)
|
|
+{
|
|
+ char name[32] = {0};
|
|
|
|
- if (strncmp(name, "zram", strlen("zram"))) {
|
|
+ if (!get_disk_name_private_data(pte_val, vaddr, name, NULL))
|
|
+ return 0;
|
|
+
|
|
+ if (!strncmp(name, "zram", 4)) {
|
|
+ return try_zram_decompress(pte_val, (unsigned char *)buf, len, vaddr);
|
|
+ } else {
|
|
if (CRASHDEBUG(2))
|
|
error(WARNING, "this page has been swapped to %s\n", name);
|
|
return 0;
|
|
}
|
|
+}
|
|
+
|
|
+ulong (*decompressor)(unsigned char *in_addr, ulong in_size, unsigned char *out_addr,
|
|
+ ulong *out_size, void *other/* NOT USED */);
|
|
+/*
|
|
+ * If userspace address was swapped out to zram, this function is called to decompress the object.
|
|
+ * try_zram_decompress returns decompressed page data and data length
|
|
+ */
|
|
+ulong
|
|
+try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong vaddr)
|
|
+{
|
|
+ char name[32] = {0};
|
|
+ ulonglong swp_offset;
|
|
+ unsigned char *obj_addr = NULL;
|
|
+ unsigned char *zram_buf = NULL;
|
|
+ unsigned char *outbuf = NULL;
|
|
+ ulong zram, zram_table_entry, sector, index, entry, flags, size,
|
|
+ outsize, off;
|
|
|
|
if (INVALID_MEMBER(zram_compressor)) {
|
|
zram_init();
|
|
@@ -2765,8 +2789,8 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
|
|
if (CRASHDEBUG(2))
|
|
error(WARNING, "this page has swapped to zram\n");
|
|
|
|
- readmem(bd_disk + OFFSET(gendisk_private_data), KVADDR, &zram,
|
|
- sizeof(void *), "gendisk_private_data", FAULT_ON_ERROR);
|
|
+ if (!get_disk_name_private_data(pte_val, vaddr, NULL, &zram))
|
|
+ return 0;
|
|
|
|
readmem(zram + OFFSET(zram_compressor), KVADDR, name,
|
|
sizeof(name), "zram compressor", FAULT_ON_ERROR);
|
|
@@ -2798,6 +2822,7 @@ try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulonglong
|
|
|
|
zram_buf = (unsigned char *)GETBUF(PAGESIZE());
|
|
/* lookup page from swap cache */
|
|
+ off = PAGEOFFSET(vaddr);
|
|
obj_addr = lookup_swap_cache(pte_val, zram_buf);
|
|
if (obj_addr != NULL) {
|
|
memcpy(buf, obj_addr + off, len);
|
|
diff --git a/memory.c b/memory.c
|
|
index 33b0ca7af977..17ac40b3e0f9 100644
|
|
--- a/memory.c
|
|
+++ b/memory.c
|
|
@@ -2294,7 +2294,7 @@ readmem(ulonglong addr, int memtype, void *buffer, long size,
|
|
if (cnt > size)
|
|
cnt = size;
|
|
|
|
- cnt = try_zram_decompress(paddr, (unsigned char *)bufptr, cnt, addr);
|
|
+ cnt = readswap(paddr, bufptr, cnt, addr);
|
|
if (cnt) {
|
|
bufptr += cnt;
|
|
addr += cnt;
|
|
--
|
|
2.29.2
|
|
|