Re: [PATCH 5/5] memory, zram: introduce and export readswap()

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

 



Hi, HATAYAMA

Thanks for the patch series.

在 2020年10月11日 09:34, crash-utility-request@xxxxxxxxxx 写道:
> Date: Sun, 11 Oct 2020 10:34:38 +0900
> From: HATAYAMA Daisuke <d.hatayama@xxxxxxxxxxx>
> To: crash-utility@xxxxxxxxxx
> Cc: HATAYAMA Daisuke <d.hatayama@xxxxxxxxxxx>
> Subject:  [PATCH 5/5] memory,	zram: introduce and
> 	export readswap()
> Message-ID: <1602380078-27010-6-git-send-email-d.hatayama@xxxxxxxxxxx>
> Content-Type: text/plain; charset="US-ASCII"
> 
> 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@xxxxxxxxxxx>
> ---
After applied this patch, I got the following compiling error. But when I
used the 'make lzo' command to compile, it doen't have any problems, which
automatically added the option '-DLZO' to compiling command.

Did you run into this compiling issue? Or is that the expected result?

BTW: Crash can be compiled successfully without this patch [PATCH 5/5].

[root@dell-pec5125-03 crash]# make
TARGET: X86_64
 CRASH: 7.2.8++
   GDB: 7.6

gcc -g -O2   -I. -I. -I./common -I./config -DLOCALEDIR="\"/usr/local/share/locale\"" -DCRASH_MERGE -DHAVE_CONFIG_H -I./../include/opcode -I./../opcodes/.. -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber  -I./gnulib/import -Ibuild-gnulib/import   -DTUI=1  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body  -c -o symtab.o -MT symtab.o -MMD -MP -MF .deps/symtab.Tpo symtab.c
Making init.c
gcc -g -O2   -I. -I. -I./common -I./config -DLOCALEDIR="\"/usr/local/share/locale\"" -DCRASH_MERGE -DHAVE_CONFIG_H -I./../include/opcode -I./../opcodes/.. -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber  -I./gnulib/import -Ibuild-gnulib/import   -DTUI=1  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body  -c -o init.o -MT init.o -MMD -MP -MF .deps/init.Tpo init.c
cc -c -g -DX86_64  -DGDB_7_6  build_data.c  
cc -c -g -DX86_64  -DGDB_7_6  main.c   
cc -c -g -DX86_64  -DGDB_7_6  tools.c  
cc -c -g -DX86_64  -DGDB_7_6  global_data.c  
cc -c -g -DX86_64  -DGDB_7_6  memory.c  
cc -c -g -DX86_64  -DGDB_7_6  filesys.c  
cc -c -g -DX86_64  -DGDB_7_6  help.c  
cc -c -g -DX86_64  -DGDB_7_6  task.c  
cc -c -g -DX86_64  -DGDB_7_6  kernel.c  
cc -c -g -DX86_64  -DGDB_7_6  test.c  
cc -c -g -DX86_64  -DGDB_7_6  gdb_interface.c  
cc -c -g -DX86_64  -DGDB_7_6  net.c  
cc -c -g -DX86_64  -DGDB_7_6  dev.c  
cc -c -g -DX86_64  -DGDB_7_6  bpf.c  
cc -c -g -DX86_64  -DGDB_7_6  alpha.c  
cc -c -g -DX86_64  -DGDB_7_6  x86.c -DMCLX  
cc -c -g -DX86_64  -DGDB_7_6  ppc.c  
cc -c -g -DX86_64  -DGDB_7_6  ia64.c  
cc -c -g -DX86_64  -DGDB_7_6  s390.c  
cc -c -g -DX86_64  -DGDB_7_6  s390x.c  
cc -c -g -DX86_64  -DGDB_7_6  s390dbf.c  
cc -c -g -DX86_64  -DGDB_7_6  ppc64.c  
cc -c -g -DX86_64  -DGDB_7_6  x86_64.c  
cc -c -g -DX86_64  -DGDB_7_6  arm.c  
cc -c -g -DX86_64  -DGDB_7_6  arm64.c  
cc -c -g -DX86_64  -DGDB_7_6  mips.c  
cc -c -g -DX86_64  -DGDB_7_6  sparc64.c  
cc -c -g -DX86_64  -DGDB_7_6  extensions.c  
cc -c -g -DX86_64  -DGDB_7_6  va_server.c  
cc -c -g -DX86_64  -DGDB_7_6  va_server_v1.c  
cc -c -g -DX86_64  -DGDB_7_6  symbols.c -I./gdb-7.6/bfd -I./gdb-7.6/include  
cc -c -g -DX86_64  -DGDB_7_6  cmdline.c -I./gdb-7.6/readline  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_common.c  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_v1.c -DMCLX  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_v2_v3.c -DMCLX  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_v5.c -DMCLX  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_v7.c -DMCLX  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_v8.c -DMCLX  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_fix_mem.c -DMCLX  
cc -c -g -DX86_64  -DGDB_7_6  s390_dump.c  
cc -c -g -DX86_64  -DGDB_7_6  netdump.c  
cc -c -g -DX86_64  -DGDB_7_6  diskdump.c  
cc -c -g -DX86_64  -DGDB_7_6  makedumpfile.c  
cc -c -g -DX86_64  -DGDB_7_6  xendump.c  
cc -c -g -DX86_64  -DGDB_7_6  lkcd_x86_trace.c -DREDHAT  
cc -c -g -DX86_64  -DGDB_7_6  unwind.c -DREDHAT -DUNWIND_V1 -o unwind_v1.o  
cc -c -g -DX86_64  -DGDB_7_6  unwind.c -DREDHAT -DUNWIND_V2 -o unwind_v2.o  
cc -c -g -DX86_64  -DGDB_7_6  unwind.c -DREDHAT -DUNWIND_V3 -o unwind_v3.o  
cc -c -g -DX86_64  -DGDB_7_6  unwind_x86_32_64.c -o unwind_x86_32_64.o  
cc -c -g -DX86_64  -DGDB_7_6  unwind_arm.c -o unwind_arm.o  
cc -c -g -DX86_64  -DGDB_7_6  xen_hyper.c  
cc -c -g -DX86_64  -DGDB_7_6  xen_hyper_command.c  
cc -c -g -DX86_64  -DGDB_7_6  xen_hyper_global_data.c  
cc -c -g -DX86_64  -DGDB_7_6  xen_hyper_dump_tables.c  
cc -c -g -DX86_64  -DGDB_7_6  kvmdump.c  
cc -c -g -DX86_64  -DGDB_7_6  qemu.c  
cc -c -g -DX86_64  -DGDB_7_6  qemu-load.c  
cc -c -g -DX86_64  -DGDB_7_6  sadump.c  
cc -c -g -DX86_64  -DGDB_7_6  ipcs.c  
cc -c -g -DX86_64  -DGDB_7_6  ramdump.c  
cc -c -g -DX86_64  -DGDB_7_6  vmware_vmss.c  
cc -c -g -DX86_64  -DGDB_7_6  vmware_guestdump.c  
cc -c -g -DX86_64  -DGDB_7_6  xen_dom0.c  
cc -c -g -DX86_64  -DGDB_7_6  kaslr_helper.c  
ar -rs crashlib.a main.o tools.o global_data.o memory.o filesys.o help.o task.o build_data.o kernel.o test.o gdb_interface.o net.o dev.o bpf.o alpha.o x86.o ppc.o ia64.o s390.o s390x.o s390dbf.o ppc64.o x86_64.o arm.o arm64.o mips.o sparc64.o extensions.o remote.o va_server.o va_server_v1.o symbols.o cmdline.o lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o lkcd_fix_mem.o s390_dump.o netdump.o diskdump.o makedumpfile.o xendump.o lkcd_x86_trace.o unwind_v1.o unwind_v2.o unwind_v3.o unwind_x86_32_64.o unwind_arm.o xen_hyper.o xen_hyper_command.o xen_hyper_global_data.o xen_hyper_dump_tables.o kvmdump.o qemu.o qemu-load.o sadump.o ipcs.o ramdump.o vmware_vmss.o vmware_guestdump.o xen_dom0.o kaslr_helper.o
ar: creating crashlib.a
gcc -g -O2      \
	-o ../../crash ../../crashlib.a amd64-tdep.o amd64-linux-tdep.o i386-tdep.o i387-tdep.o i386-linux-tdep.o glibc-tdep.o solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o ser-base.o ser-unix.o ser-pipe.o ser-tcp.o inf-ptrace.o fork-child.o i386-nat.o amd64-nat.o amd64-linux-nat.o linux-nat.o linux-osdata.o proc-service.o linux-thread-db.o linux-fork.o linux-procfs.o linux-ptrace.o linux-btrace.o remote.o dcache.o tracepoint.o ax-general.o ax-gdb.o remote-fileio.o remote-notif.o  cli-dump.o cli-decode.o cli-script.o cli-cmds.o cli-setshow.o cli-logging.o cli-interp.o cli-utils.o mi-out.o mi-console.o mi-cmds.o mi-cmd-catch.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o mi-cmd-file.o mi-cmd-disas.o mi-symbol-cmds.o mi-cmd-target.o mi-cmd-info.o mi-interp.o mi-main.o mi-parse.o mi-getopt.o tui-command.o tui-data.o tui-disasm.o tui-file.o tui-hooks.o tui-interp.o tui-io.o tui-layout.o tui-out.o tui-regs.o tui-source.o tui-stack.o tui-win.o tui-windata.o tui-wingeneral.o tui-winsource.o tui.o python.o py-value.o py-prettyprint.o py-auto-load.o elfread.o stap-probe.o posix-hdep.o c-exp.o cp-name-parser.o ada-exp.o jv-exp.o f-exp.o go-exp.o m2-exp.o p-exp.o version.o annotate.o addrmap.o auto-load.o auxv.o agent.o bfd-target.o blockframe.o breakpoint.o break-catch-sig.o findvar.o regcache.o cleanups.o charset.o continuations.o corelow.o disasm.o dummy-frame.o dfp.o source.o value.o eval.o valops.o valarith.o valprint.o printcmd.o block.o symtab.o psymtab.o symfile.o symmisc.o linespec.o dictionary.o infcall.o infcmd.o infrun.o expprint.o environ.o stack.o thread.o exceptions.o filesystem.o inf-child.o interps.o minidebug.o main.o macrotab.o macrocmd.o macroexp.o macroscope.o mi-common.o event-loop.o event-top.o inf-loop.o completer.o gdbarch.o arch-utils.o gdbtypes.o gdb_bfd.o gdb_obstack.o osabi.o copying.o memattr.o mem-break.o target.o parse.o language.o buildsym.o findcmd.o std-regs.o signals.o exec.o reverse.o bcache.o objfiles.o observer.o minsyms.o maint.o demangle.o dbxread.o coffread.o coff-pe-re

ad.o dwarf2read.o mipsread.o stabsread.o corefile.o dwarf2expr.o dwarf2loc.o dwarf2-frame.o dwarf2-frame-tailcall.o ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o ada-tasks.o ada-varobj.o ui-out.o cli-out.o varobj.o vec.o go-lang.o go-valprint.o go-typeprint.o jv-lang.o jv-valprint.o jv-typeprint.o m2-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o sentinel-frame.o complaints.o typeprint.o ada-typeprint.o c-typeprint.o f-typeprint.o m2-typeprint.o ada-valprint.o c-valprint.o cp-valprint.o d-valprint.o f-valprint.o m2-valprint.o serial.o mdebugread.o top.o utils.o ui-file.o user-regs.o frame.o frame-unwind.o doublest.o frame-base.o inline-frame.o gnu-v2-abi.o gnu-v3-abi.o cp-abi.o cp-support.o cp-namespace.o reggroups.o regset.o trad-frame.o tramp-frame.o solib.o solib-target.o prologue-value.o memory-map.o memrange.o xml-support.o xml-syscall.o xml-utils.o target-descriptions.o target-memory.o xml-tdesc.o xml-builtin.o inferior.o osdata.o gdb_usleep.o record.o record-full.o gcore.o gdb_vecs.o jit.o progspace.o skip.o probe.o common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o format.o registry.o btrace.o record-btrace.o inflow.o    init.o \
	   ../readline/libreadline.a ../opcodes/libopcodes.a ../bfd/libbfd.a  ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a    -ldl -lncurses -lz -lm  -llzma ../libiberty/libiberty.a  build-gnulib/import/libgnu.a -ldl -Wl,--dynamic-list=./proc-service.list  -lz -ldl -rdynamic
/usr/bin/ld: ../../crashlib.a(memory.o): in function `readmem':
/home/crash/memory.c:2299: undefined reference to `readswap'
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:1188: gdb] Error 1
make[2]: *** [Makefile:245: rebuild] Error 2
make[1]: *** [Makefile:233: gdb_merge] Error 2
make: *** [Makefile:225: all] Error 2
[root@dell-pec5125-03 crash]# 

Thanks.
Lianbo

>  defs.h     |  1 +
>  diskdump.c | 67 ++++++++++++++++++++++++++++++++++++++++++++------------------
>  memory.c   |  5 ++++-
>  3 files changed, 53 insertions(+), 20 deletions(-)
> 
> diff --git a/defs.h b/defs.h
> index c899fe2..8bb5618 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -6506,6 +6506,7 @@ int diskdump_kaslr_check(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);
>  #ifdef LZO
> diff --git a/diskdump.c b/diskdump.c
> index cdbc2d5..3762314 100644
> --- a/diskdump.c
> +++ b/diskdump.c
> @@ -2704,24 +2704,15 @@ 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");
>  
> @@ -2738,16 +2729,53 @@ 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();
> @@ -2763,8 +2791,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);
> @@ -2789,6 +2817,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 c951827..44213bb 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2296,7 +2296,10 @@ 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(addr,
> +						       bufptr,
> +						       cnt,
> +						       addr);
>  					if (cnt) {
>  						bufptr += cnt;
>  						addr += cnt;
> -- 1.8.3.1

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility




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

 

Powered by Linux