Skip to contentSkip to conversation

Support RISCV64 arch and common commands

PATCH Superseded Xianting Tian 4 participants 25 messages Jul 18, 2022 – Aug 1, 2022

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Support RISCV64 arch and common commands

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

      KERNEL: vmlinux
    DUMPFILE: vmcore
        CPUS: 1
        DATE: Fri Jul 15 10:24:25 CST 2022
      UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
       TASKS: 41
    NODENAME: buildroot
     RELEASE: 5.18.9
     VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
     MACHINE: riscv64  (unknown Mhz)
      MEMORY: 1 GB
       PANIC: "Kernel panic - not syncing: sysrq triggered crash"
         PID: 113
     COMMAND: "sh"
        TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
         CPU: 0
       STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00
$5 = {
flags = 0x1000,

  {
    {
      {
        lru = {
          next = 0xff6000003effbf08,
          prev = 0xff6000003effbf08
        },
        {
          __filler = 0xff6000003effbf08,
          mlock_count = 0x3effbf08
        }
      },
      mapping = 0x0,
      index = 0x0,
      private = 0x0
    },

... ...

crash> mod

     MODULE       NAME             BASE         SIZE  OBJECT FILE
ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

PGD: ffffffff810e9ff8 => 2ffff001
P4D: 0000000000000000 => 000000002fffec01
PUD: 00005605c2957470 => 0000000020949801
PMD: 00007fff7f1750c0 => 0000000020947401
PTE: 0 => 209534e7
PAGE: 000000008254d000

  PTE     PHYSICAL  FLAGS
209534e7  8254d000  (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

 Makefile            |    7 +-
 README              |    2 +-
 configure.c         |   39 +-
 defs.h              |  248 +++++++-
 diskdump.c          |   21 +-
 help.c              |    2 +-
 lkcd_vmdump_v2_v3.h |    2 +-
 netdump.c           |   22 +-
 ramdump.c           |    2 +
 riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
 symbols.c           |   10 +
 11 files changed, 1759 insertions(+), 10 deletions(-)
 create mode 100644 riscv64.c
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

PATCH 1/8 Add RISCV64 framework code support

This patch mainly added some environment configurations, macro definitions, specific architecture structures and some function declarations supported by the RISCV64 architecture.

We can use the build command to get the simplest version crash tool:
make target=RISCV64 -j2

---
 Makefile            |   7 +-
 README              |   2 +-
 configure.c         |  39 ++++++++++-
 defs.h              | 155 +++++++++++++++++++++++++++++++++++++++++++-
 diskdump.c          |  11 +++-
 help.c              |   2 +-
 lkcd_vmdump_v2_v3.h |   2 +-
 netdump.c           |   9 ++-
 ramdump.c           |   2 +
 riscv64.c           |  56 ++++++++++++++++
 symbols.c           |  10 +++
 11 files changed, 285 insertions(+), 10 deletions(-)
 create mode 100644 riscv64.c
Makefile +5 -2
index 162c2ba..54ebb43 100644
@@ -64,7 +64,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
 	kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
 	printk.c \
 	alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
-	arm.c arm64.c mips.c mips64.c sparc64.c \
+	arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
 	extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
 	lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
 	lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -84,7 +84,7 @@ OBJECT_FILES=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 \
 	printk.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 mips64.o sparc64.o \
+	arm.o arm64.o mips.o mips64.o riscv64.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 \
@@ -438,6 +438,9 @@ mips.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips.c
 mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c
 	${CC} -c ${CRASH_CFLAGS} mips64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
+riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
+	${CC} -c ${CRASH_CFLAGS} riscv64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+
 sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
 	${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
README +1 -1
index 5abbce1..5ac5b60 100644
@@ -37,7 +37,7 @@
   These are the current prerequisites: 
 
   o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,
-     mips64, s390 and s390x-based kernels are supported.  Other architectures
+     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures
      may be addressed in the future.
 
   o  One size fits all -- the utility can be run on any Linux kernel version
configure.c +38 -1
index 5188851..0d216d1 100644
@@ -107,6 +107,7 @@ void add_extra_lib(char *);
 #undef MIPS
 #undef SPARC64
 #undef MIPS64
+#undef RISCV64
 
 #define UNKNOWN 0
 #define X86     1
@@ -122,6 +123,7 @@ void add_extra_lib(char *);
 #define MIPS    11
 #define SPARC64 12
 #define MIPS64  13
+#define RISCV64 14
 
 #define TARGET_X86    "TARGET=X86"
 #define TARGET_ALPHA  "TARGET=ALPHA"
@@ -136,6 +138,7 @@ void add_extra_lib(char *);
 #define TARGET_MIPS   "TARGET=MIPS"
 #define TARGET_MIPS64 "TARGET=MIPS64"
 #define TARGET_SPARC64 "TARGET=SPARC64"
+#define TARGET_RISCV64 "TARGET=RISCV64"
 
 #define TARGET_CFLAGS_X86    "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
 #define TARGET_CFLAGS_ALPHA  "TARGET_CFLAGS="
@@ -158,6 +161,8 @@ void add_extra_lib(char *);
 #define TARGET_CFLAGS_MIPS_ON_X86_64  "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
 #define TARGET_CFLAGS_MIPS64          "TARGET_CFLAGS="
 #define TARGET_CFLAGS_SPARC64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64_ON_X86_64	"TARGET_CFLAGS="
 
 #define GDB_TARGET_DEFAULT        "GDB_CONF_FLAGS="
 #define GDB_TARGET_ARM_ON_X86     "GDB_CONF_FLAGS=--target=arm-elf-linux"
@@ -168,6 +173,7 @@ void add_extra_lib(char *);
 #define GDB_TARGET_PPC64_ON_X86_64  "GDB_CONF_FLAGS=--target=powerpc64le-unknown-linux-gnu"
 #define GDB_TARGET_MIPS_ON_X86     "GDB_CONF_FLAGS=--target=mipsel-elf-linux"
 #define GDB_TARGET_MIPS_ON_X86_64  "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
+#define GDB_TARGET_RISCV64_ON_X86_64  "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu"
      
 /*
  *  The original plan was to allow the use of a particular version
@@ -404,6 +410,9 @@ get_current_configuration(struct supported_gdb_version *sp)
 #ifdef __sparc_v9__
 	target_data.target = SPARC64;
 #endif
+#ifdef __riscv64__
+	target_data.target = RISCV64;
+#endif
 
 	set_initial_target(sp);
 
@@ -457,6 +466,12 @@ get_current_configuration(struct supported_gdb_version *sp)
 			if ((target_data.initial_gdb_target != UNKNOWN) &&
 			    (target_data.host != target_data.initial_gdb_target))
 				arch_mismatch(sp);
+		} else if ((target_data.target == X86_64) &&
+			(name_to_target((char *)target_data.target_as_param) == RISCV64)) {
+			/*
+			 *  Build an RISCV64 crash binary on an X86_64 host.
+			 */
+			target_data.target = RISCV64;
 		} else {
 			fprintf(stderr,
 			    "\ntarget=%s is not supported on the %s host architecture\n\n",
@@ -497,6 +512,10 @@ get_current_configuration(struct supported_gdb_version *sp)
 		    (target_data.target != MIPS64))
 			arch_mismatch(sp);
 
+		if ((target_data.initial_gdb_target == RISCV64) &&
+		    (target_data.target != RISCV64))
+			arch_mismatch(sp);
+
 		if ((target_data.initial_gdb_target == X86) &&
 		    (target_data.target != X86)) {
 			if (target_data.target == X86_64) 
@@ -660,6 +679,9 @@ show_configuration(void)
 	case SPARC64:
 		printf("TARGET: SPARC64\n");
 		break;
+	case RISCV64:
+		printf("TARGET: RISCV64\n");
+		break;
 	}
 
 	if (strlen(target_data.program)) {
@@ -777,6 +799,14 @@ build_configure(struct supported_gdb_version *sp)
 		target = TARGET_SPARC64;
 		target_CFLAGS = TARGET_CFLAGS_SPARC64;
 		break;
+	case RISCV64:
+		target = TARGET_RISCV64;
+		if (target_data.host == X86_64) {
+			target_CFLAGS = TARGET_CFLAGS_RISCV64_ON_X86_64;
+			gdb_conf_flags = GDB_TARGET_RISCV64_ON_X86_64;
+		} else
+			target_CFLAGS = TARGET_CFLAGS_RISCV64;
+		break;
 	}
 
 	ldflags = get_extra_flags("LDFLAGS.extra", NULL);
@@ -1374,7 +1404,7 @@ make_spec_file(struct supported_gdb_version *sp)
 	printf("Vendor: Red Hat, Inc.\n");
 	printf("Packager: Dave Anderson <[email protected]>\n");
 	printf("ExclusiveOS: Linux\n");
-	printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64\n");
+	printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64\n");
 	printf("Buildroot: %%{_tmppath}/%%{name}-root\n");
 	printf("BuildRequires: ncurses-devel zlib-devel bison\n");
 	printf("Requires: binutils\n");
@@ -1613,6 +1643,8 @@ set_initial_target(struct supported_gdb_version *sp)
 		target_data.initial_gdb_target = MIPS;
 	else if (strncmp(buf, "SPARC64", strlen("SPARC64")) == 0)
 		target_data.initial_gdb_target = SPARC64;
+	else if (strncmp(buf, "RISCV64", strlen("RISCV64")) == 0)
+		target_data.initial_gdb_target = RISCV64;
 }
 
 char *
@@ -1633,6 +1665,7 @@ target_to_name(int target)
 	case MIPS:   return("MIPS");
 	case MIPS64: return("MIPS64");
 	case SPARC64: return("SPARC64");
+	case RISCV64: return("RISCV64");
 	}
 
 	return "UNKNOWN";
@@ -1697,6 +1730,10 @@ name_to_target(char *name)
 		return MIPS64;
 	else if (strncmp(name, "sparc64", strlen("sparc64")) == 0)
 		return SPARC64;
+	else if (strncmp(name, "RISCV64", strlen("RISCV64")) == 0)
+		return RISCV64;
+	else if (strncmp(name, "riscv64", strlen("riscv64")) == 0)
+		return RISCV64;
 
 	return UNKNOWN;
 }
defs.h +154 -1

203 lines not on this page · raw message

diskdump.c +9 -2
index 2c1f9be..28503bc 100644
@@ -622,6 +622,9 @@ restart:
 	else if (STRNEQ(header->utsname.machine, "aarch64") &&
 	    machine_type_mismatch(file, "ARM64", NULL, 0))
 		goto err;
+	else if (STRNEQ(header->utsname.machine, "riscv64") &&
+	    machine_type_mismatch(file, "RISCV64", NULL, 0))
+		goto err;
 
 	if (header->block_size != block_size) {
 		block_size = header->block_size;
@@ -780,6 +783,8 @@ restart:
 		dd->machine_type = EM_AARCH64;
 	else if (machine_type("SPARC64"))
 		dd->machine_type = EM_SPARCV9;
+	else if (machine_type("RISCV64"))
+		dd->machine_type = EM_RISCV;
 	else {
 		error(INFO, "%s: unsupported machine type: %s\n", 
 			DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
@@ -1751,7 +1756,8 @@ dump_note_offsets(FILE *fp)
 			qemu = FALSE;
 			if (machine_type("X86_64") || machine_type("S390X") ||
 			    machine_type("ARM64") || machine_type("PPC64") ||
-			    machine_type("SPARC64") || machine_type("MIPS64")) {
+			    machine_type("SPARC64") || machine_type("MIPS64") ||
+			    machine_type("RISCV64")) {
 				note64 = (void *)dd->notes_buf + tot;
 				len = sizeof(Elf64_Nhdr);
 				if (STRNEQ((char *)note64 + len, "QEMU"))
@@ -2558,7 +2564,8 @@ dump_registers_for_compressed_kdump(void)
 	if (!KDUMP_CMPRS_VALID() || (dd->header->header_version < 4) ||
 	    !(machine_type("X86") || machine_type("X86_64") ||
 	      machine_type("ARM64") || machine_type("PPC64") ||
-	      machine_type("MIPS") || machine_type("MIPS64")))
+	      machine_type("MIPS") || machine_type("MIPS64") ||
+	      machine_type("RISCV64")))
 		error(FATAL, "-r option not supported for this dumpfile\n");
 
 	if (machine_type("ARM64") && (kt->cpus != dd->num_prstatus_notes))
help.c +1 -1
index 99214c1..253c71b 100644
@@ -9512,7 +9512,7 @@ char *README[] = {
 "  These are the current prerequisites: ",
 "",
 "  o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,",
-"     mips64, s390 and s390x-based kernels are supported.  Other architectures",
+"     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures",
 "     may be addressed in the future.",
 "",
 "  o  One size fits all -- the utility can be run on any Linux kernel version",
lkcd_vmdump_v2_v3.h +1 -1
index 984c2c2..7fa70b9 100644
@@ -37,7 +37,7 @@
 
 #if defined(ARM) || defined(X86) || defined(PPC) || defined(S390) || \
 	defined(S390X) || defined(ARM64) || defined(MIPS) || \
-	defined(MIPS64) || defined(SPARC64)
+	defined(MIPS64) || defined(SPARC64) || defined(RISCV64)
 
 /*
  * Kernel header file for Linux crash dumps.
netdump.c +8 -1
index ff273b4..4ec12a0 100644
@@ -300,6 +300,12 @@ is_netdump(char *file, ulong source_query)
 				goto bailout;
 			break;
 
+		case EM_RISCV:
+			if (machine_type_mismatch(file, "RISCV64", NULL,
+			    source_query))
+				goto bailout;
+			break;
+
 		default:
 			if (machine_type_mismatch(file, "(unknown)", NULL,
 			    source_query))
@@ -2935,7 +2941,8 @@ dump_registers_for_elf_dumpfiles(void)
 
         if (!(machine_type("X86") || machine_type("X86_64") || 
 	    machine_type("ARM64") || machine_type("PPC64") ||
-	    machine_type("MIPS") || machine_type("MIPS64")))
+	    machine_type("MIPS") || machine_type("MIPS64") ||
+	    machine_type("RISCV64")))
                 error(FATAL, "-r option not supported for this dumpfile\n");
 
 	if (NETDUMP_DUMPFILE()) {
ramdump.c +2 -0
index a206fcb..d2bd7ff 100644
@@ -188,6 +188,8 @@ char *ramdump_to_elf(void)
 		e_machine = EM_MIPS;
 	else if (machine_type("X86_64"))
 		e_machine = EM_X86_64;
+	else if (machine_type("RISCV64"))
+		e_machine = EM_RISCV;
 	else
 		error(FATAL, "ramdump: unsupported machine type: %s\n", 
 			MACHINE_TYPE);
riscv64.c new file +56 -0

56 lines not on this page · raw message

symbols.c +10 -0
index bee1faf..ea9e83e 100644
@@ -3743,6 +3743,11 @@ is_kernel(char *file)
 				goto bailout;
 			break;
 
+		case EM_RISCV:
+			if (machine_type_mismatch(file, "RISCV64", NULL, 0))
+				goto bailout;
+			break;
+
 		default:
 			if (machine_type_mismatch(file, "(unknown)", NULL, 0))
 				goto bailout;
@@ -4002,6 +4007,11 @@ is_shared_object(char *file)
 			if (machine_type("MIPS64"))
 				return TRUE;
 			break;
+
+		case EM_RISCV:
+			if (machine_type("RISCV64"))
+				return TRUE;
+			break;
 		}
 
 		if (CRASHDEBUG(1))
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw

Re: [Crash-utility][PATCH 1/8] Add RISCV64 framework code support

Quoted 60 lines · Xianting Tian

This patch mainly added some environment configurations, macro definitions, specific architecture structures and some function declarations supported by the RISCV64 architecture.

We can use the build command to get the simplest version crash tool:
make target=RISCV64 -j2

---
  Makefile            |   7 +-
  README              |   2 +-
  configure.c         |  39 ++++++++++-
  defs.h              | 155 +++++++++++++++++++++++++++++++++++++++++++-
  diskdump.c          |  11 +++-
  help.c              |   2 +-
  lkcd_vmdump_v2_v3.h |   2 +-
  netdump.c           |   9 ++-
  ramdump.c           |   2 +
  riscv64.c           |  56 ++++++++++++++++
  symbols.c           |  10 +++
  11 files changed, 285 insertions(+), 10 deletions(-)

create mode 100644 riscv64.c

Makefile +5 -2
index 162c2ba..54ebb43 100644
@@ -64,7 +64,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
  	kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
  	printk.c \
  	alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
-	arm.c arm64.c mips.c mips64.c sparc64.c \
+	arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
  	extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
  	lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
  	lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -84,7 +84,7 @@ OBJECT_FILES=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 \
  	printk.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 mips64.o sparc64.o \
+	arm.o arm64.o mips.o mips64.o riscv64.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 \
@@ -438,6 +438,9 @@ mips.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips.c
  mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c
  	${CC} -c ${CRASH_CFLAGS} mips64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
+riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
+	${CC} -c ${CRASH_CFLAGS} riscv64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+
  sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
  	${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
README +0 -0
index 5abbce1..5ac5b60 100644

README line 43

Quoted 8 lines
README +1 -1
@@ -37,7 +37,7 @@
    These are the current prerequisites:
 
    o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,
-     mips64, s390 and s390x-based kernels are supported.  Other architectures
+     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures
       may be addressed in the future.
 
    o  One size fits all -- the utility can be run on any Linux kernel version

For README, please append a description of x86_64 binary for riscv64 dumpfiles here:
---
o On an x86_64 host, an x86_64 binary that can be used to analyze ppc64le dumpfiles may be built by typing "make target=PPC64".

Traditionally when vmcores are compressed via the makedumpfile(8) facility
---

Quoted 69 lines
configure.c +15 -0
index 5188851..0d216d1 100644
@@ -107,6 +107,7 @@ void add_extra_lib(char *);
  #undef MIPS
  #undef SPARC64
  #undef MIPS64
+#undef RISCV64
 
  #define UNKNOWN 0
  #define X86     1
@@ -122,6 +123,7 @@ void add_extra_lib(char *);
  #define MIPS    11
  #define SPARC64 12
  #define MIPS64  13
+#define RISCV64 14
 
  #define TARGET_X86    "TARGET=X86"
  #define TARGET_ALPHA  "TARGET=ALPHA"
@@ -136,6 +138,7 @@ void add_extra_lib(char *);
  #define TARGET_MIPS   "TARGET=MIPS"
  #define TARGET_MIPS64 "TARGET=MIPS64"
  #define TARGET_SPARC64 "TARGET=SPARC64"
+#define TARGET_RISCV64 "TARGET=RISCV64"
 
  #define TARGET_CFLAGS_X86    "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
  #define TARGET_CFLAGS_ALPHA  "TARGET_CFLAGS="
@@ -158,6 +161,8 @@ void add_extra_lib(char *);
  #define TARGET_CFLAGS_MIPS_ON_X86_64  "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
  #define TARGET_CFLAGS_MIPS64          "TARGET_CFLAGS="
  #define TARGET_CFLAGS_SPARC64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64_ON_X86_64	"TARGET_CFLAGS="
 
  #define GDB_TARGET_DEFAULT        "GDB_CONF_FLAGS="
  #define GDB_TARGET_ARM_ON_X86     "GDB_CONF_FLAGS=--target=arm-elf-linux"
@@ -168,6 +173,7 @@ void add_extra_lib(char *);
  #define GDB_TARGET_PPC64_ON_X86_64  "GDB_CONF_FLAGS=--target=powerpc64le-unknown-linux-gnu"
  #define GDB_TARGET_MIPS_ON_X86     "GDB_CONF_FLAGS=--target=mipsel-elf-linux"
  #define GDB_TARGET_MIPS_ON_X86_64  "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
+#define GDB_TARGET_RISCV64_ON_X86_64  "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu"
 
  /*
   *  The original plan was to allow the use of a particular version
@@ -404,6 +410,9 @@ get_current_configuration(struct supported_gdb_version *sp)
  #ifdef __sparc_v9__
  	target_data.target = SPARC64;
  #endif
+#ifdef __riscv64__
+	target_data.target = RISCV64;
+#endif
 
  	set_initial_target(sp);
 
@@ -457,6 +466,12 @@ get_current_configuration(struct supported_gdb_version *sp)
  			if ((target_data.initial_gdb_target != UNKNOWN) &&
  			    (target_data.host != target_data.initial_gdb_target))
  				arch_mismatch(sp);
+		} else if ((target_data.target == X86_64) &&
+			(name_to_target((char *)target_data.target_as_param) == RISCV64)) {
+			/*
+			 *  Build an RISCV64 crash binary on an X86_64 host.
+			 */
+			target_data.target = RISCV64;
  		} else {
  			fprintf(stderr,
  			    "\ntarget=%s is not supported on the %s host architecture\n\n",

configure.c get_current_configuration(struct supported_gdb_version *sp) · line 518

Quoted 7 lines
configure.c +4 -0
@@ -497,6 +512,10 @@ get_current_configuration(struct supported_gdb_version *sp)
  		    (target_data.target != MIPS64))
  			arch_mismatch(sp);
 
+		if ((target_data.initial_gdb_target == RISCV64) &&
+		    (target_data.target != RISCV64))
+			arch_mismatch(sp);
+

Please add the case where target_data.target is X86_64. Otherwise, the "sticky" target for build on x86_64 will not work:

$ make

The initial build in this source tree was for the RISCV64 architecture.

In order to build a crash binary for the X86_64 architecture:
1. remove the gdb-10.2 subdirectory
2. perform a "make clean"
3. retry the build

make: *** [Makefile:252: all] Error 1

Quoted 104 lines
configure.c +19 -1
  		if ((target_data.initial_gdb_target == X86) &&
  		    (target_data.target != X86)) {
  			if (target_data.target == X86_64)
@@ -660,6 +679,9 @@ show_configuration(void)
  	case SPARC64:
  		printf("TARGET: SPARC64\n");
  		break;
+	case RISCV64:
+		printf("TARGET: RISCV64\n");
+		break;
  	}
 
  	if (strlen(target_data.program)) {
@@ -777,6 +799,14 @@ build_configure(struct supported_gdb_version *sp)
  		target = TARGET_SPARC64;
  		target_CFLAGS = TARGET_CFLAGS_SPARC64;
  		break;
+	case RISCV64:
+		target = TARGET_RISCV64;
+		if (target_data.host == X86_64) {
+			target_CFLAGS = TARGET_CFLAGS_RISCV64_ON_X86_64;
+			gdb_conf_flags = GDB_TARGET_RISCV64_ON_X86_64;
+		} else
+			target_CFLAGS = TARGET_CFLAGS_RISCV64;
+		break;
  	}
 
  	ldflags = get_extra_flags("LDFLAGS.extra", NULL);
@@ -1374,7 +1404,7 @@ make_spec_file(struct supported_gdb_version *sp)
  	printf("Vendor: Red Hat, Inc.\n");
  	printf("Packager: Dave Anderson <[email protected]>\n");
  	printf("ExclusiveOS: Linux\n");
-	printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64\n");
+	printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64\n");
  	printf("Buildroot: %%{_tmppath}/%%{name}-root\n");
  	printf("BuildRequires: ncurses-devel zlib-devel bison\n");
  	printf("Requires: binutils\n");
@@ -1613,6 +1643,8 @@ set_initial_target(struct supported_gdb_version *sp)
  		target_data.initial_gdb_target = MIPS;
  	else if (strncmp(buf, "SPARC64", strlen("SPARC64")) == 0)
  		target_data.initial_gdb_target = SPARC64;
+	else if (strncmp(buf, "RISCV64", strlen("RISCV64")) == 0)
+		target_data.initial_gdb_target = RISCV64;
  }
 
  char *
@@ -1633,6 +1665,7 @@ target_to_name(int target)
  	case MIPS:   return("MIPS");
  	case MIPS64: return("MIPS64");
  	case SPARC64: return("SPARC64");
+	case RISCV64: return("RISCV64");
  	}
 
  	return "UNKNOWN";
@@ -1697,6 +1730,10 @@ name_to_target(char *name)
  		return MIPS64;
  	else if (strncmp(name, "sparc64", strlen("sparc64")) == 0)
  		return SPARC64;
+	else if (strncmp(name, "RISCV64", strlen("RISCV64")) == 0)
+		return RISCV64;
+	else if (strncmp(name, "riscv64", strlen("riscv64")) == 0)
+		return RISCV64;
 
  	return UNKNOWN;
  }
defs.h +9 -1
index 9b1b69a..42ffba3 100644
@@ -76,7 +76,7 @@
  #if !defined(X86) && !defined(X86_64) && !defined(ALPHA) && !defined(PPC) && \
      !defined(IA64) && !defined(PPC64) && !defined(S390) && !defined(S390X) && \
      !defined(ARM) && !defined(ARM64) && !defined(MIPS) && !defined(MIPS64) && \
-    !defined(SPARC64)
+    !defined(RISCV64) && !defined(SPARC64)
  #ifdef __alpha__
  #define ALPHA
  #endif
@@ -118,6 +118,9 @@
  #ifdef __sparc_v9__
  #define SPARC64
  #endif
+#ifdef __riscv64__
+#define RISCV64
+#endif
  #endif
 
  #ifdef X86
@@ -159,6 +162,9 @@
  #ifdef SPARC64
  #define NR_CPUS  (4096)
  #endif
+#ifdef RISCV64
+#define NR_CPUS  (256)
+#endif
 
  #define NR_DEVICE_DUMPS (64)
 
@@ -3484,6 +3490,63 @@ struct arm64_stackframe {
  #define _MAX_PHYSMEM_BITS       48
  #endif  /* MIPS64 */
 
+#ifdef RISCV64
+#define _64BIT_

defs.h struct arm64_stackframe { · line 3504

Quoted 10 lines
defs.h +10 -0
+#define MACHINE_TYPE		"RISCV64"
+
+/*
+ * Direct memory mapping
+ */
+#define PTOV(X)										\
+	(((unsigned long)(X)+(machdep->kvbase)) - machdep->machspec->phys_base)
+#define VTOP(X)	({									\
+	ulong _X = X;									\
+	(THIS_KERNEL_VERSION >= 0x50D00 &&						\

Please use LINUX(x,y,z) macro.

Quoted 34 lines
defs.h +34 -0
+		(_X) >= machdep->machspec->kernel_link_addr) ?				\
+		(((unsigned long)(_X)-(machdep->machspec->kernel_link_addr)) +		\
+		 machdep->machspec->phys_base):						\
+		(((unsigned long)(_X)-(machdep->kvbase)) +				\
+		 machdep->machspec->phys_base);						\
+	})
+#define PAGEBASE(X)		(((ulong)(X)) & (ulong)machdep->pagemask)
+
+/*
+ * Stack size order
+ */
+#define THREAD_SIZE_ORDER       2
+
+#define PAGE_OFFSET		(machdep->machspec->page_offset)
+#define VMALLOC_START		(machdep->machspec->vmalloc_start_addr)
+#define VMALLOC_END		(machdep->machspec->vmalloc_end)
+#define VMEMMAP_VADDR		(machdep->machspec->vmemmap_vaddr)
+#define VMEMMAP_END		(machdep->machspec->vmemmap_end)
+#define MODULES_VADDR		(machdep->machspec->modules_vaddr)
+#define MODULES_END		(machdep->machspec->modules_end)
+#define IS_VMALLOC_ADDR(X)	riscv64_IS_VMALLOC_ADDR((ulong)(X))
+
+/* from arch/riscv/include/asm/pgtable.h */
+#define __SWP_TYPE_SHIFT        6
+#define __SWP_TYPE_BITS         5
+#define __SWP_TYPE_MASK         ((1UL << __SWP_TYPE_BITS) - 1)
+#define __SWP_OFFSET_SHIFT      (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
+
+#define MAX_SWAPFILES_CHECK()   BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)
+
+#define SWP_TYPE(entry)		(((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
+#define SWP_OFFSET(entry)	((entry) >> __SWP_OFFSET_SHIFT)
+#define __swp_type(entry)       SWP_TYPE(entry)
+#define __swp_offset(entry)     SWP_OFFSET(entry)

defs.h struct arm64_stackframe { · line 3548

Quoted 10 lines
defs.h +10 -0
+
+#define TIF_SIGPENDING          (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2)
+
+/* from arch/riscv/include/asm/sparsemem.h */
+#define _SECTION_SIZE_BITS      27
+#define _MAX_PHYSMEM_BITS       56 /* 56-bit physical address supported */
+#define PHYS_MASK_SHIFT		_MAX_PHYSMEM_BITS
+#define PHYS_MASK		(((1UL) << PHYS_MASK_SHIFT) - 1)
+
+#endif  /* RISCV64 */

Spaces and tabs for indent are mixed in this ifdef block, please use tabs usually if you have no intention.

Thanks,
Kazu

Quoted 311 lines
defs.h +91 -0
+
  #ifdef X86
  #define _32BIT_
  #define MACHINE_TYPE       "X86"
@@ -4532,6 +4595,10 @@ struct machine_specific {
  #define MAX_HEXADDR_STRLEN (16)
  #define UVADDR_PRLEN      (16)
  #endif
+#ifdef RISCV64
+#define MAX_HEXADDR_STRLEN (16)
+#define UVADDR_PRLEN       (16)
+#endif
 
  #define BADADDR  ((ulong)(-1))
  #define BADVAL   ((ulong)(-1))
@@ -5126,6 +5193,9 @@ void dump_build_data(void);
  #ifdef MIPS64
  #define machdep_init(X) mips64_init(X)
  #endif
+#ifdef RISCV64
+#define machdep_init(X) riscv64_init(X)
+#endif
  #ifdef SPARC64
  #define machdep_init(X) sparc64_init(X)
  #endif
@@ -5606,6 +5676,9 @@ void display_help_screen(char *);
  #ifdef SPARC64
  #define dump_machdep_table(X) sparc64_dump_machdep_table(X)
  #endif
+#ifdef RISCV64
+#define dump_machdep_table(X) riscv64_dump_machdep_table(X)
+#endif
  extern char *help_pointer[];
  extern char *help_alias[];
  extern char *help_ascii[];
@@ -6682,6 +6755,86 @@ struct machine_specific {
 
  #endif /* MIPS64 */
 
+/*
+ * riscv64.c
+ */
+void riscv64_display_regs_from_elf_notes(int, FILE *);
+
+#ifdef RISCV64
+void riscv64_init(int);
+void riscv64_dump_machdep_table(ulong);
+int riscv64_IS_VMALLOC_ADDR(ulong);
+
+#define display_idt_table() \
+	error(FATAL, "-d option is not applicable to RISCV64 architecture\n")
+
+/* from arch/riscv/include/asm/ptrace.h */
+struct riscv64_register {
+	ulong regs[36];
+};
+
+struct riscv64_pt_regs {
+	ulong badvaddr;
+	ulong cause;
+	ulong epc;
+};
+
+struct riscv64_unwind_frame {
+	ulong fp;
+	ulong sp;
+	ulong pc;
+};
+
+#define KSYMS_START	(0x1)
+
+struct machine_specific {
+	ulong phys_base;
+	ulong page_offset;
+	ulong vmalloc_start_addr;
+	ulong vmalloc_end;
+	ulong vmemmap_vaddr;
+	ulong vmemmap_end;
+	ulong modules_vaddr;
+	ulong modules_end;
+	ulong kernel_link_addr;
+	ulong address_space_end;
+
+	ulong _page_present;
+	ulong _page_read;
+	ulong _page_write;
+	ulong _page_exec;
+	ulong _page_user;
+	ulong _page_global;
+	ulong _page_accessed;
+	ulong _page_dirty;
+	ulong _page_soft;
+
+	ulong _pfn_shift;
+
+	struct riscv64_register *crash_task_regs;
+};
+/* from arch/riscv/include/asm/pgtable-bits.h */
+#define 	_PAGE_PRESENT	(machdep->machspec->_page_present)
+#define 	_PAGE_READ	(machdep->machspec->_page_read)
+#define 	_PAGE_WRITE	(machdep->machspec->_page_write)
+#define 	_PAGE_EXEC	(machdep->machspec->_page_exec)
+#define 	_PAGE_USER	(machdep->machspec->_page_user)
+#define 	_PAGE_GLOBAL	(machdep->machspec->_page_global)
+#define 	_PAGE_ACCESSED	(machdep->machspec->_page_accessed)
+#define 	_PAGE_DIRTY	(machdep->machspec->_page_dirty)
+#define 	_PAGE_SOFT	(machdep->machspec->_page_soft)
+#define 	_PAGE_SEC	(machdep->machspec->_page_sec)
+#define 	_PAGE_SHARE	(machdep->machspec->_page_share)
+#define 	_PAGE_BUF	(machdep->machspec->_page_buf)
+#define 	_PAGE_CACHE	(machdep->machspec->_page_cache)
+#define 	_PAGE_SO	(machdep->machspec->_page_so)
+#define 	_PAGE_SPECIAL	_PAGE_SOFT
+#define		_PAGE_TABLE	_PAGE_PRESENT
+#define 	_PAGE_PROT_NONE	_PAGE_READ
+#define 	_PAGE_PFN_SHIFT	10
+
+#endif /* RISCV64 */
+
  /*
   * sparc64.c
   */
diskdump.c +9 -2
index 2c1f9be..28503bc 100644
@@ -622,6 +622,9 @@ restart:
  	else if (STRNEQ(header->utsname.machine, "aarch64") &&
  	    machine_type_mismatch(file, "ARM64", NULL, 0))
  		goto err;
+	else if (STRNEQ(header->utsname.machine, "riscv64") &&
+	    machine_type_mismatch(file, "RISCV64", NULL, 0))
+		goto err;
 
  	if (header->block_size != block_size) {
  		block_size = header->block_size;
@@ -780,6 +783,8 @@ restart:
  		dd->machine_type = EM_AARCH64;
  	else if (machine_type("SPARC64"))
  		dd->machine_type = EM_SPARCV9;
+	else if (machine_type("RISCV64"))
+		dd->machine_type = EM_RISCV;
  	else {
  		error(INFO, "%s: unsupported machine type: %s\n",
  			DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
@@ -1751,7 +1756,8 @@ dump_note_offsets(FILE *fp)
  			qemu = FALSE;
  			if (machine_type("X86_64") || machine_type("S390X") ||
  			    machine_type("ARM64") || machine_type("PPC64") ||
-			    machine_type("SPARC64") || machine_type("MIPS64")) {
+			    machine_type("SPARC64") || machine_type("MIPS64") ||
+			    machine_type("RISCV64")) {
  				note64 = (void *)dd->notes_buf + tot;
  				len = sizeof(Elf64_Nhdr);
  				if (STRNEQ((char *)note64 + len, "QEMU"))
@@ -2558,7 +2564,8 @@ dump_registers_for_compressed_kdump(void)
  	if (!KDUMP_CMPRS_VALID() || (dd->header->header_version < 4) ||
  	    !(machine_type("X86") || machine_type("X86_64") ||
  	      machine_type("ARM64") || machine_type("PPC64") ||
-	      machine_type("MIPS") || machine_type("MIPS64")))
+	      machine_type("MIPS") || machine_type("MIPS64") ||
+	      machine_type("RISCV64")))
  		error(FATAL, "-r option not supported for this dumpfile\n");
 
  	if (machine_type("ARM64") && (kt->cpus != dd->num_prstatus_notes))
help.c +1 -1
index 99214c1..253c71b 100644
@@ -9512,7 +9512,7 @@ char *README[] = {
  "  These are the current prerequisites: ",
  "",
  "  o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,",
-"     mips64, s390 and s390x-based kernels are supported.  Other architectures",
+"     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures",
  "     may be addressed in the future.",
  "",
  "  o  One size fits all -- the utility can be run on any Linux kernel version",
lkcd_vmdump_v2_v3.h +1 -1
index 984c2c2..7fa70b9 100644
@@ -37,7 +37,7 @@
 
  #if defined(ARM) || defined(X86) || defined(PPC) || defined(S390) || \
  	defined(S390X) || defined(ARM64) || defined(MIPS) || \
-	defined(MIPS64) || defined(SPARC64)
+	defined(MIPS64) || defined(SPARC64) || defined(RISCV64)
 
  /*
   * Kernel header file for Linux crash dumps.
netdump.c +8 -1
index ff273b4..4ec12a0 100644
@@ -300,6 +300,12 @@ is_netdump(char *file, ulong source_query)
  				goto bailout;
  			break;
 
+		case EM_RISCV:
+			if (machine_type_mismatch(file, "RISCV64", NULL,
+			    source_query))
+				goto bailout;
+			break;
+
  		default:
  			if (machine_type_mismatch(file, "(unknown)", NULL,
  			    source_query))
@@ -2935,7 +2941,8 @@ dump_registers_for_elf_dumpfiles(void)
 
          if (!(machine_type("X86") || machine_type("X86_64") ||
  	    machine_type("ARM64") || machine_type("PPC64") ||
-	    machine_type("MIPS") || machine_type("MIPS64")))
+	    machine_type("MIPS") || machine_type("MIPS64") ||
+	    machine_type("RISCV64")))
                  error(FATAL, "-r option not supported for this dumpfile\n");
 
  	if (NETDUMP_DUMPFILE()) {
ramdump.c +2 -0
index a206fcb..d2bd7ff 100644
@@ -188,6 +188,8 @@ char *ramdump_to_elf(void)
  		e_machine = EM_MIPS;
  	else if (machine_type("X86_64"))
  		e_machine = EM_X86_64;
+	else if (machine_type("RISCV64"))
+		e_machine = EM_RISCV;
  	else
  		error(FATAL, "ramdump: unsupported machine type: %s\n",
  			MACHINE_TYPE);
riscv64.c new file +56 -0
new file mode 100644
index 0000000..c7df857
@@ -0,0 +1,56 @@
+/* riscv64.c - core analysis suite
+ *
+ * Copyright (C) 2022 Alibaba Group Holding Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#ifdef RISCV64
+
+#include <elf.h>
+#include "defs.h"
+
+void
+riscv64_dump_machdep_table(ulong arg)
+{
+}
+
+/*
+ *  Include both vmalloc'd and module address space as VMALLOC space.
+ */
+int
+riscv64_IS_VMALLOC_ADDR(ulong vaddr)
+{
+	return ((vaddr >= VMALLOC_START && vaddr <= VMALLOC_END) ||
+		(vaddr >= VMEMMAP_VADDR && vaddr <= VMEMMAP_END) ||
+		(vaddr >= MODULES_VADDR && vaddr <= MODULES_END));
+}
+
+void
+riscv64_init(int when)
+{
+}
+
+void
+riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
+{
+}
+
+#else /* !RISCV64 */
+
+#include "defs.h"
+
+void
+riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
+{
+	return;
+}
+
+#endif /* !RISCV64 */
symbols.c +5 -0
index bee1faf..ea9e83e 100644
@@ -3743,6 +3743,11 @@ is_kernel(char *file)
  				goto bailout;
  			break;
 
+		case EM_RISCV:
+			if (machine_type_mismatch(file, "RISCV64", NULL, 0))
+				goto bailout;
+			break;
+
  		default:
  			if (machine_type_mismatch(file, "(unknown)", NULL, 0))
  				goto bailout;
@@ -4002,6 +4007,11 @@ is_shared_object(char *file)
  			if (machine_type("MIPS64"))

symbols.c is_shared_object(char *file) · line 4017

Quoted 10 lines
symbols.c +5 -0
  				return TRUE;
  			break;
+
+		case EM_RISCV:
+			if (machine_type("RISCV64"))
+				return TRUE;
+			break;
  		}
 
  		if (CRASHDEBUG(1))

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw

Re: [Crash-utility][PATCH 1/8] Add RISCV64 framework code support

Quoted 68 lines · HAGIO KAZUHITO(萩尾 一仁)
Quoted 67 lines · Xianting Tian

This patch mainly added some environment configurations, macro definitions, specific architecture structures and some function declarations supported by the RISCV64 architecture.

We can use the build command to get the simplest version crash tool:
make target=RISCV64 -j2

---
   Makefile            |   7 +-
   README              |   2 +-
   configure.c         |  39 ++++++++++-
   defs.h              | 155 +++++++++++++++++++++++++++++++++++++++++++-
   diskdump.c          |  11 +++-
   help.c              |   2 +-
   lkcd_vmdump_v2_v3.h |   2 +-
   netdump.c           |   9 ++-
   ramdump.c           |   2 +
   riscv64.c           |  56 ++++++++++++++++
   symbols.c           |  10 +++
   11 files changed, 285 insertions(+), 10 deletions(-)

create mode 100644 riscv64.c

Makefile +5 -2
index 162c2ba..54ebb43 100644
@@ -64,7 +64,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
   	kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
   	printk.c \
   	alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
-	arm.c arm64.c mips.c mips64.c sparc64.c \
+	arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
   	extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
   	lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
   	lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -84,7 +84,7 @@ OBJECT_FILES=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 \
   	printk.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 mips64.o sparc64.o \
+	arm.o arm64.o mips.o mips64.o riscv64.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 \
@@ -438,6 +438,9 @@ mips.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips.c
   mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c
   	${CC} -c ${CRASH_CFLAGS} mips64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
+riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
+	${CC} -c ${CRASH_CFLAGS} riscv64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+
   sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
   	${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
README +1 -1
index 5abbce1..5ac5b60 100644
@@ -37,7 +37,7 @@
     These are the current prerequisites:
 
     o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,
-     mips64, s390 and s390x-based kernels are supported.  Other architectures
+     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures
        may be addressed in the future.
 
Quoted 7 lines

README line 43

Quoted 1 line
README +0 -0
     o  One size fits all -- the utility can be run on any Linux kernel version

For README, please append a description of x86_64 binary for riscv64 dumpfiles here:
---
o On an x86_64 host, an x86_64 binary that can be used to analyze ppc64le dumpfiles may be built by typing "make target=PPC64".

Shouldn't debugging of a riscv64 crash binary also be possible on riscv64?

Best regards

Heinrich

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw

Re: [Crash-utility][PATCH 1/8] Add RISCV64 framework code support

Quoted 73 lines · Heinrich Schuchardt
Quoted 63 lines · HAGIO KAZUHITO(萩尾 一仁)
Quoted 62 lines · Xianting Tian

This patch mainly added some environment configurations, macro definitions, specific architecture structures and some function declarations supported by the RISCV64 architecture.

We can use the build command to get the simplest version crash tool:
    make target=RISCV64 -j2

---
   Makefile            |   7 +-
   README              |   2 +-
   configure.c         |  39 ++++++++++-
   defs.h              | 155 +++++++++++++++++++++++++++++++++++++++++++- diskdump.c          |  11 +++-
   help.c              |   2 +-
   lkcd_vmdump_v2_v3.h |   2 +-

   netdump.c           |   9 ++-
   ramdump.c           |   2 +
   riscv64.c           |  56 ++++++++++++++++
   symbols.c           |  10 +++
   11 files changed, 285 insertions(+), 10 deletions(-)

   create mode 100644 riscv64.c

Makefile +2 -2
index 162c2ba..54ebb43 100644
@@ -64,7 +64,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
        kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
        printk.c \
        alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
-    arm.c arm64.c mips.c mips64.c sparc64.c \
+    arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
        extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
        lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
        lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -84,7 +84,7 @@ OBJECT_FILES=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 \
        printk.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 mips64.o sparc64.o \
+    arm.o arm64.o mips.o mips64.o riscv64.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 \
@@ -438,6 +438,9 @@ mips.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips.c

   mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c
       ${CC} -c ${CRASH_CFLAGS} mips64.c ${WARNING_OPTIONS} ${WARNING_ERROR}

Makefile +3 -0
+riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
+    ${CC} -c ${CRASH_CFLAGS} riscv64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+

   sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
       ${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}

README +0 -0
index 5abbce1..5ac5b60 100644
@@ -37,7 +37,7 @@

     These are the current prerequisites:
     o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips, -     mips64, s390 and s390x-based kernels are supported.  Other architectures +     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures

Quoted 8 lines
Quoted 2 lines

        may be addressed in the future.
     o  One size fits all -- the utility can be run on any Linux kernel version

For README, please append a description of x86_64 binary for riscv64 dumpfiles here:
---
    o  On an x86_64 host, an x86_64 binary that can be used to analyze ppc64le dumpfiles may be built by typing "make target=PPC64".

Quoted 1 line

Shouldn't debugging of a riscv64 crash binary also be possible on riscv64?

Yes, my comment is an additional request about the README file. Does this answer your question?

Thanks,
Kazu
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw

Re: [Crash-utility][PATCH 1/8] Add RISCV64 framework code support

In reply to Xianting Tian
Quoted 224 lines · Xianting Tian

This patch mainly added some environment configurations, macro definitions, specific architecture structures and some function declarations supported by the RISCV64 architecture.

We can use the build command to get the simplest version crash tool:
make target=RISCV64 -j2

---
 Makefile            |   7 +-
 README              |   2 +-
 configure.c         |  39 ++++++++++-
 defs.h              | 155 +++++++++++++++++++++++++++++++++++++++++++-
 diskdump.c          |  11 +++-
 help.c              |   2 +-
 lkcd_vmdump_v2_v3.h |   2 +-
 netdump.c           |   9 ++-
 ramdump.c           |   2 +
 riscv64.c           |  56 ++++++++++++++++
 symbols.c           |  10 +++
 11 files changed, 285 insertions(+), 10 deletions(-)
 create mode 100644 riscv64.c
Makefile +5 -2
index 162c2ba..54ebb43 100644
@@ -64,7 +64,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
        kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
        printk.c \
        alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
-       arm.c arm64.c mips.c mips64.c sparc64.c \
+       arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
        extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
        lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
        lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -84,7 +84,7 @@ OBJECT_FILES=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 \
        printk.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 mips64.o sparc64.o \
+       arm.o arm64.o mips.o mips64.o riscv64.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 \
@@ -438,6 +438,9 @@ mips.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips.c
 mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c
        ${CC} -c ${CRASH_CFLAGS} mips64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
+riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
+       ${CC} -c ${CRASH_CFLAGS} riscv64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+
 sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
        ${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
README +1 -1
index 5abbce1..5ac5b60 100644
@@ -37,7 +37,7 @@
   These are the current prerequisites:
 
   o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,
-     mips64, s390 and s390x-based kernels are supported.  Other architectures
+     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures
      may be addressed in the future.
 
   o  One size fits all -- the utility can be run on any Linux kernel version
configure.c +38 -1
index 5188851..0d216d1 100644
@@ -107,6 +107,7 @@ void add_extra_lib(char *);
 #undef MIPS
 #undef SPARC64
 #undef MIPS64
+#undef RISCV64
 
 #define UNKNOWN 0
 #define X86     1
@@ -122,6 +123,7 @@ void add_extra_lib(char *);
 #define MIPS    11
 #define SPARC64 12
 #define MIPS64  13
+#define RISCV64 14
 
 #define TARGET_X86    "TARGET=X86"
 #define TARGET_ALPHA  "TARGET=ALPHA"
@@ -136,6 +138,7 @@ void add_extra_lib(char *);
 #define TARGET_MIPS   "TARGET=MIPS"
 #define TARGET_MIPS64 "TARGET=MIPS64"
 #define TARGET_SPARC64 "TARGET=SPARC64"
+#define TARGET_RISCV64 "TARGET=RISCV64"
 
 #define TARGET_CFLAGS_X86    "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
 #define TARGET_CFLAGS_ALPHA  "TARGET_CFLAGS="
@@ -158,6 +161,8 @@ void add_extra_lib(char *);
 #define TARGET_CFLAGS_MIPS_ON_X86_64  "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
 #define TARGET_CFLAGS_MIPS64          "TARGET_CFLAGS="
 #define TARGET_CFLAGS_SPARC64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64_ON_X86_64        "TARGET_CFLAGS="
 
 #define GDB_TARGET_DEFAULT        "GDB_CONF_FLAGS="
 #define GDB_TARGET_ARM_ON_X86     "GDB_CONF_FLAGS=--target=arm-elf-linux"
@@ -168,6 +173,7 @@ void add_extra_lib(char *);
 #define GDB_TARGET_PPC64_ON_X86_64  "GDB_CONF_FLAGS=--target=powerpc64le-unknown-linux-gnu"
 #define GDB_TARGET_MIPS_ON_X86     "GDB_CONF_FLAGS=--target=mipsel-elf-linux"
 #define GDB_TARGET_MIPS_ON_X86_64  "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
+#define GDB_TARGET_RISCV64_ON_X86_64  "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu"
 
 /*
  *  The original plan was to allow the use of a particular version
@@ -404,6 +410,9 @@ get_current_configuration(struct supported_gdb_version *sp)
 #ifdef __sparc_v9__
        target_data.target = SPARC64;
 #endif
+#ifdef __riscv64__
+       target_data.target = RISCV64;
+#endif
 
        set_initial_target(sp);
 
@@ -457,6 +466,12 @@ get_current_configuration(struct supported_gdb_version *sp)
                        if ((target_data.initial_gdb_target != UNKNOWN) &&
                            (target_data.host != target_data.initial_gdb_target))
                                arch_mismatch(sp);
+               } else if ((target_data.target == X86_64) &&
+                       (name_to_target((char *)target_data.target_as_param) == RISCV64)) {
+                       /*
+                        *  Build an RISCV64 crash binary on an X86_64 host.
+                        */
+                       target_data.target = RISCV64;
                } else {
                        fprintf(stderr,
                            "\ntarget=%s is not supported on the %s host architecture\n\n",
@@ -497,6 +512,10 @@ get_current_configuration(struct supported_gdb_version *sp)
                    (target_data.target != MIPS64))
                        arch_mismatch(sp);
 
+               if ((target_data.initial_gdb_target == RISCV64) &&
+                   (target_data.target != RISCV64))
+                       arch_mismatch(sp);
+
                if ((target_data.initial_gdb_target == X86) &&
                    (target_data.target != X86)) {
                        if (target_data.target == X86_64)
@@ -660,6 +679,9 @@ show_configuration(void)
        case SPARC64:
                printf("TARGET: SPARC64\n");
                break;
+       case RISCV64:
+               printf("TARGET: RISCV64\n");
+               break;
        }
 
        if (strlen(target_data.program)) {
@@ -777,6 +799,14 @@ build_configure(struct supported_gdb_version *sp)
                target = TARGET_SPARC64;
                target_CFLAGS = TARGET_CFLAGS_SPARC64;
                break;
+       case RISCV64:
+               target = TARGET_RISCV64;
+               if (target_data.host == X86_64) {
+                       target_CFLAGS = TARGET_CFLAGS_RISCV64_ON_X86_64;
+                       gdb_conf_flags = GDB_TARGET_RISCV64_ON_X86_64;
+               } else
+                       target_CFLAGS = TARGET_CFLAGS_RISCV64;
+               break;
        }
 
        ldflags = get_extra_flags("LDFLAGS.extra", NULL);
@@ -1374,7 +1404,7 @@ make_spec_file(struct supported_gdb_version *sp)
        printf("Vendor: Red Hat, Inc.\n");
        printf("Packager: Dave Anderson <[email protected]>\n");
        printf("ExclusiveOS: Linux\n");
-       printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64\n");
+       printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64\n");
        printf("Buildroot: %%{_tmppath}/%%{name}-root\n");
        printf("BuildRequires: ncurses-devel zlib-devel bison\n");
        printf("Requires: binutils\n");
@@ -1613,6 +1643,8 @@ set_initial_target(struct supported_gdb_version *sp)
                target_data.initial_gdb_target = MIPS;
        else if (strncmp(buf, "SPARC64", strlen("SPARC64")) == 0)
                target_data.initial_gdb_target = SPARC64;
+       else if (strncmp(buf, "RISCV64", strlen("RISCV64")) == 0)
+               target_data.initial_gdb_target = RISCV64;
 }
 
 char *
@@ -1633,6 +1665,7 @@ target_to_name(int target)
        case MIPS:   return("MIPS");
        case MIPS64: return("MIPS64");
        case SPARC64: return("SPARC64");
+       case RISCV64: return("RISCV64");
        }
 
        return "UNKNOWN";
@@ -1697,6 +1730,10 @@ name_to_target(char *name)
                return MIPS64;
        else if (strncmp(name, "sparc64", strlen("sparc64")) == 0)
                return SPARC64;
+       else if (strncmp(name, "RISCV64", strlen("RISCV64")) == 0)
+               return RISCV64;
+       else if (strncmp(name, "riscv64", strlen("riscv64")) == 0)
+               return RISCV64;
 
        return UNKNOWN;
 }
defs.h +1 -1
index 9b1b69a..42ffba3 100644
@@ -76,7 +76,7 @@
 #if !defined(X86) && !defined(X86_64) && !defined(ALPHA) && !defined(PPC) && \
     !defined(IA64) && !defined(PPC64) && !defined(S390) && !defined(S390X) && \
     !defined(ARM) && !defined(ARM64) && !defined(MIPS) && !defined(MIPS64) && \
-    !defined(SPARC64)
+    !defined(RISCV64) && !defined(SPARC64)
 #ifdef __alpha__
 #define ALPHA
 #endif

defs.h line 121

Quoted 4 lines
defs.h +1 -0
@@ -118,6 +118,9 @@
 #ifdef __sparc_v9__
 #define SPARC64
 #endif
+#ifdef __riscv64__

this is wrong, should be
#if defined(__riscv) && (__riscv_xlen == 64)

Quoted 400 lines
defs.h +152 -0
+#define RISCV64
+#endif
 #endif
 
 #ifdef X86
@@ -159,6 +162,9 @@
 #ifdef SPARC64
 #define NR_CPUS  (4096)
 #endif
+#ifdef RISCV64
+#define NR_CPUS  (256)
+#endif
 
 #define NR_DEVICE_DUMPS (64)
 
@@ -3484,6 +3490,63 @@ struct arm64_stackframe {
 #define _MAX_PHYSMEM_BITS       48
 #endif  /* MIPS64 */
 
+#ifdef RISCV64
+#define _64BIT_
+#define MACHINE_TYPE           "RISCV64"
+
+/*
+ * Direct memory mapping
+ */
+#define PTOV(X)                                                                                \
+       (((unsigned long)(X)+(machdep->kvbase)) - machdep->machspec->phys_base)
+#define VTOP(X)        ({                                                                      \
+       ulong _X = X;                                                                   \
+       (THIS_KERNEL_VERSION >= 0x50D00 &&                                              \
+               (_X) >= machdep->machspec->kernel_link_addr) ?                          \
+               (((unsigned long)(_X)-(machdep->machspec->kernel_link_addr)) +          \
+                machdep->machspec->phys_base):                                         \
+               (((unsigned long)(_X)-(machdep->kvbase)) +                              \
+                machdep->machspec->phys_base);                                         \
+       })
+#define PAGEBASE(X)            (((ulong)(X)) & (ulong)machdep->pagemask)
+
+/*
+ * Stack size order
+ */
+#define THREAD_SIZE_ORDER       2
+
+#define PAGE_OFFSET            (machdep->machspec->page_offset)
+#define VMALLOC_START          (machdep->machspec->vmalloc_start_addr)
+#define VMALLOC_END            (machdep->machspec->vmalloc_end)
+#define VMEMMAP_VADDR          (machdep->machspec->vmemmap_vaddr)
+#define VMEMMAP_END            (machdep->machspec->vmemmap_end)
+#define MODULES_VADDR          (machdep->machspec->modules_vaddr)
+#define MODULES_END            (machdep->machspec->modules_end)
+#define IS_VMALLOC_ADDR(X)     riscv64_IS_VMALLOC_ADDR((ulong)(X))
+
+/* from arch/riscv/include/asm/pgtable.h */
+#define __SWP_TYPE_SHIFT        6
+#define __SWP_TYPE_BITS         5
+#define __SWP_TYPE_MASK         ((1UL << __SWP_TYPE_BITS) - 1)
+#define __SWP_OFFSET_SHIFT      (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
+
+#define MAX_SWAPFILES_CHECK()   BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)
+
+#define SWP_TYPE(entry)                (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
+#define SWP_OFFSET(entry)      ((entry) >> __SWP_OFFSET_SHIFT)
+#define __swp_type(entry)       SWP_TYPE(entry)
+#define __swp_offset(entry)     SWP_OFFSET(entry)
+
+#define TIF_SIGPENDING          (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2)
+
+/* from arch/riscv/include/asm/sparsemem.h */
+#define _SECTION_SIZE_BITS      27
+#define _MAX_PHYSMEM_BITS       56 /* 56-bit physical address supported */
+#define PHYS_MASK_SHIFT                _MAX_PHYSMEM_BITS
+#define PHYS_MASK              (((1UL) << PHYS_MASK_SHIFT) - 1)
+
+#endif  /* RISCV64 */
+
 #ifdef X86
 #define _32BIT_
 #define MACHINE_TYPE       "X86"
@@ -4532,6 +4595,10 @@ struct machine_specific {
 #define MAX_HEXADDR_STRLEN (16)
 #define UVADDR_PRLEN      (16)
 #endif
+#ifdef RISCV64
+#define MAX_HEXADDR_STRLEN (16)
+#define UVADDR_PRLEN       (16)
+#endif
 
 #define BADADDR  ((ulong)(-1))
 #define BADVAL   ((ulong)(-1))
@@ -5126,6 +5193,9 @@ void dump_build_data(void);
 #ifdef MIPS64
 #define machdep_init(X) mips64_init(X)
 #endif
+#ifdef RISCV64
+#define machdep_init(X) riscv64_init(X)
+#endif
 #ifdef SPARC64
 #define machdep_init(X) sparc64_init(X)
 #endif
@@ -5606,6 +5676,9 @@ void display_help_screen(char *);
 #ifdef SPARC64
 #define dump_machdep_table(X) sparc64_dump_machdep_table(X)
 #endif
+#ifdef RISCV64
+#define dump_machdep_table(X) riscv64_dump_machdep_table(X)
+#endif
 extern char *help_pointer[];
 extern char *help_alias[];
 extern char *help_ascii[];
@@ -6682,6 +6755,86 @@ struct machine_specific {
 
 #endif /* MIPS64 */
 
+/*
+ * riscv64.c
+ */
+void riscv64_display_regs_from_elf_notes(int, FILE *);
+
+#ifdef RISCV64
+void riscv64_init(int);
+void riscv64_dump_machdep_table(ulong);
+int riscv64_IS_VMALLOC_ADDR(ulong);
+
+#define display_idt_table() \
+       error(FATAL, "-d option is not applicable to RISCV64 architecture\n")
+
+/* from arch/riscv/include/asm/ptrace.h */
+struct riscv64_register {
+       ulong regs[36];
+};
+
+struct riscv64_pt_regs {
+       ulong badvaddr;
+       ulong cause;
+       ulong epc;
+};
+
+struct riscv64_unwind_frame {
+       ulong fp;
+       ulong sp;
+       ulong pc;
+};
+
+#define KSYMS_START    (0x1)
+
+struct machine_specific {
+       ulong phys_base;
+       ulong page_offset;
+       ulong vmalloc_start_addr;
+       ulong vmalloc_end;
+       ulong vmemmap_vaddr;
+       ulong vmemmap_end;
+       ulong modules_vaddr;
+       ulong modules_end;
+       ulong kernel_link_addr;
+       ulong address_space_end;
+
+       ulong _page_present;
+       ulong _page_read;
+       ulong _page_write;
+       ulong _page_exec;
+       ulong _page_user;
+       ulong _page_global;
+       ulong _page_accessed;
+       ulong _page_dirty;
+       ulong _page_soft;
+
+       ulong _pfn_shift;
+
+       struct riscv64_register *crash_task_regs;
+};
+/* from arch/riscv/include/asm/pgtable-bits.h */
+#define        _PAGE_PRESENT   (machdep->machspec->_page_present)
+#define        _PAGE_READ      (machdep->machspec->_page_read)
+#define        _PAGE_WRITE     (machdep->machspec->_page_write)
+#define        _PAGE_EXEC      (machdep->machspec->_page_exec)
+#define        _PAGE_USER      (machdep->machspec->_page_user)
+#define        _PAGE_GLOBAL    (machdep->machspec->_page_global)
+#define        _PAGE_ACCESSED  (machdep->machspec->_page_accessed)
+#define        _PAGE_DIRTY     (machdep->machspec->_page_dirty)
+#define        _PAGE_SOFT      (machdep->machspec->_page_soft)
+#define        _PAGE_SEC       (machdep->machspec->_page_sec)
+#define        _PAGE_SHARE     (machdep->machspec->_page_share)
+#define        _PAGE_BUF       (machdep->machspec->_page_buf)
+#define        _PAGE_CACHE     (machdep->machspec->_page_cache)
+#define        _PAGE_SO        (machdep->machspec->_page_so)
+#define        _PAGE_SPECIAL   _PAGE_SOFT
+#define                _PAGE_TABLE     _PAGE_PRESENT
+#define        _PAGE_PROT_NONE _PAGE_READ
+#define        _PAGE_PFN_SHIFT 10
+
+#endif /* RISCV64 */
+
 /*
  * sparc64.c
  */
diskdump.c +9 -2
index 2c1f9be..28503bc 100644
@@ -622,6 +622,9 @@ restart:
        else if (STRNEQ(header->utsname.machine, "aarch64") &&
            machine_type_mismatch(file, "ARM64", NULL, 0))
                goto err;
+       else if (STRNEQ(header->utsname.machine, "riscv64") &&
+           machine_type_mismatch(file, "RISCV64", NULL, 0))
+               goto err;
 
        if (header->block_size != block_size) {
                block_size = header->block_size;
@@ -780,6 +783,8 @@ restart:
                dd->machine_type = EM_AARCH64;
        else if (machine_type("SPARC64"))
                dd->machine_type = EM_SPARCV9;
+       else if (machine_type("RISCV64"))
+               dd->machine_type = EM_RISCV;
        else {
                error(INFO, "%s: unsupported machine type: %s\n",
                        DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
@@ -1751,7 +1756,8 @@ dump_note_offsets(FILE *fp)
                        qemu = FALSE;
                        if (machine_type("X86_64") || machine_type("S390X") ||
                            machine_type("ARM64") || machine_type("PPC64") ||
-                           machine_type("SPARC64") || machine_type("MIPS64")) {
+                           machine_type("SPARC64") || machine_type("MIPS64") ||
+                           machine_type("RISCV64")) {
                                note64 = (void *)dd->notes_buf + tot;
                                len = sizeof(Elf64_Nhdr);
                                if (STRNEQ((char *)note64 + len, "QEMU"))
@@ -2558,7 +2564,8 @@ dump_registers_for_compressed_kdump(void)
        if (!KDUMP_CMPRS_VALID() || (dd->header->header_version < 4) ||
            !(machine_type("X86") || machine_type("X86_64") ||
              machine_type("ARM64") || machine_type("PPC64") ||
-             machine_type("MIPS") || machine_type("MIPS64")))
+             machine_type("MIPS") || machine_type("MIPS64") ||
+             machine_type("RISCV64")))
                error(FATAL, "-r option not supported for this dumpfile\n");
 
        if (machine_type("ARM64") && (kt->cpus != dd->num_prstatus_notes))
help.c +1 -1
index 99214c1..253c71b 100644
@@ -9512,7 +9512,7 @@ char *README[] = {
 "  These are the current prerequisites: ",
 "",
 "  o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,",
-"     mips64, s390 and s390x-based kernels are supported.  Other architectures",
+"     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures",
 "     may be addressed in the future.",
 "",
 "  o  One size fits all -- the utility can be run on any Linux kernel version",
lkcd_vmdump_v2_v3.h +1 -1
index 984c2c2..7fa70b9 100644
@@ -37,7 +37,7 @@
 
 #if defined(ARM) || defined(X86) || defined(PPC) || defined(S390) || \
        defined(S390X) || defined(ARM64) || defined(MIPS) || \
-       defined(MIPS64) || defined(SPARC64)
+       defined(MIPS64) || defined(SPARC64) || defined(RISCV64)
 
 /*
  * Kernel header file for Linux crash dumps.
netdump.c +8 -1
index ff273b4..4ec12a0 100644
@@ -300,6 +300,12 @@ is_netdump(char *file, ulong source_query)
                                goto bailout;
                        break;
 
+               case EM_RISCV:
+                       if (machine_type_mismatch(file, "RISCV64", NULL,
+                           source_query))
+                               goto bailout;
+                       break;
+
                default:
                        if (machine_type_mismatch(file, "(unknown)", NULL,
                            source_query))
@@ -2935,7 +2941,8 @@ dump_registers_for_elf_dumpfiles(void)
 
         if (!(machine_type("X86") || machine_type("X86_64") ||
            machine_type("ARM64") || machine_type("PPC64") ||
-           machine_type("MIPS") || machine_type("MIPS64")))
+           machine_type("MIPS") || machine_type("MIPS64") ||
+           machine_type("RISCV64")))
                 error(FATAL, "-r option not supported for this dumpfile\n");
 
        if (NETDUMP_DUMPFILE()) {
ramdump.c +2 -0
index a206fcb..d2bd7ff 100644
@@ -188,6 +188,8 @@ char *ramdump_to_elf(void)
                e_machine = EM_MIPS;
        else if (machine_type("X86_64"))
                e_machine = EM_X86_64;
+       else if (machine_type("RISCV64"))
+               e_machine = EM_RISCV;
        else
                error(FATAL, "ramdump: unsupported machine type: %s\n",
                        MACHINE_TYPE);
riscv64.c new file +56 -0
new file mode 100644
index 0000000..c7df857
@@ -0,0 +1,56 @@
+/* riscv64.c - core analysis suite
+ *
+ * Copyright (C) 2022 Alibaba Group Holding Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#ifdef RISCV64
+
+#include <elf.h>
+#include "defs.h"
+
+void
+riscv64_dump_machdep_table(ulong arg)
+{
+}
+
+/*
+ *  Include both vmalloc'd and module address space as VMALLOC space.
+ */
+int
+riscv64_IS_VMALLOC_ADDR(ulong vaddr)
+{
+       return ((vaddr >= VMALLOC_START && vaddr <= VMALLOC_END) ||
+               (vaddr >= VMEMMAP_VADDR && vaddr <= VMEMMAP_END) ||
+               (vaddr >= MODULES_VADDR && vaddr <= MODULES_END));
+}
+
+void
+riscv64_init(int when)
+{
+}
+
+void
+riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
+{
+}
+
+#else /* !RISCV64 */
+
+#include "defs.h"
+
+void
+riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
+{
+       return;
+}
+
+#endif /* !RISCV64 */
symbols.c +10 -1
index bee1faf..ea9e83e 100644
@@ -3743,6 +3743,11 @@ is_kernel(char *file)
                                goto bailout;
                        break;
 
+               case EM_RISCV:
+                       if (machine_type_mismatch(file, "RISCV64", NULL, 0))
+                               goto bailout;
+                       break;
+
                default:
                        if (machine_type_mismatch(file, "(unknown)", NULL, 0))
                                goto bailout;
@@ -4002,6 +4007,11 @@ is_shared_object(char *file)
                        if (machine_type("MIPS64"))
                                return TRUE;
                        break;
+
+               case EM_RISCV:
+                       if (machine_type("RISCV64"))
+                               return TRUE;
+                       break;
                }
 
                if (CRASHDEBUG(1))
--

2.17.1

Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw

Re: [Crash-utility][PATCH 1/8] Add RISCV64 framework code support

Quoted 223 lines · Yixun Lan
Quoted 221 lines · Xianting Tian

This patch mainly added some environment configurations, macro definitions, specific architecture structures and some function declarations supported by the RISCV64 architecture.

We can use the build command to get the simplest version crash tool:
make target=RISCV64 -j2

---
  Makefile            |   7 +-
  README              |   2 +-
  configure.c         |  39 ++++++++++-
  defs.h              | 155 +++++++++++++++++++++++++++++++++++++++++++-
  diskdump.c          |  11 +++-
  help.c              |   2 +-
  lkcd_vmdump_v2_v3.h |   2 +-
  netdump.c           |   9 ++-
  ramdump.c           |   2 +
  riscv64.c           |  56 ++++++++++++++++
  symbols.c           |  10 +++
  11 files changed, 285 insertions(+), 10 deletions(-)

create mode 100644 riscv64.c

Makefile +5 -2
index 162c2ba..54ebb43 100644
@@ -64,7 +64,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
         kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
         printk.c \
         alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
-       arm.c arm64.c mips.c mips64.c sparc64.c \
+       arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
         extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
         lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
         lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -84,7 +84,7 @@ OBJECT_FILES=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 \
         printk.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 mips64.o sparc64.o \
+       arm.o arm64.o mips.o mips64.o riscv64.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 \
@@ -438,6 +438,9 @@ mips.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips.c
  mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c
         ${CC} -c ${CRASH_CFLAGS} mips64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
+riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
+       ${CC} -c ${CRASH_CFLAGS} riscv64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+
  sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
         ${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
 
README +1 -1
index 5abbce1..5ac5b60 100644
@@ -37,7 +37,7 @@
    These are the current prerequisites:
 
    o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,
-     mips64, s390 and s390x-based kernels are supported.  Other architectures
+     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures
       may be addressed in the future.
 
    o  One size fits all -- the utility can be run on any Linux kernel version
configure.c +38 -1
index 5188851..0d216d1 100644
@@ -107,6 +107,7 @@ void add_extra_lib(char *);
  #undef MIPS
  #undef SPARC64
  #undef MIPS64
+#undef RISCV64
 
  #define UNKNOWN 0
  #define X86     1
@@ -122,6 +123,7 @@ void add_extra_lib(char *);
  #define MIPS    11
  #define SPARC64 12
  #define MIPS64  13
+#define RISCV64 14
 
  #define TARGET_X86    "TARGET=X86"
  #define TARGET_ALPHA  "TARGET=ALPHA"
@@ -136,6 +138,7 @@ void add_extra_lib(char *);
  #define TARGET_MIPS   "TARGET=MIPS"
  #define TARGET_MIPS64 "TARGET=MIPS64"
  #define TARGET_SPARC64 "TARGET=SPARC64"
+#define TARGET_RISCV64 "TARGET=RISCV64"
 
  #define TARGET_CFLAGS_X86    "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
  #define TARGET_CFLAGS_ALPHA  "TARGET_CFLAGS="
@@ -158,6 +161,8 @@ void add_extra_lib(char *);
  #define TARGET_CFLAGS_MIPS_ON_X86_64  "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
  #define TARGET_CFLAGS_MIPS64          "TARGET_CFLAGS="
  #define TARGET_CFLAGS_SPARC64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64         "TARGET_CFLAGS="
+#define TARGET_CFLAGS_RISCV64_ON_X86_64        "TARGET_CFLAGS="
 
  #define GDB_TARGET_DEFAULT        "GDB_CONF_FLAGS="
  #define GDB_TARGET_ARM_ON_X86     "GDB_CONF_FLAGS=--target=arm-elf-linux"
@@ -168,6 +173,7 @@ void add_extra_lib(char *);
  #define GDB_TARGET_PPC64_ON_X86_64  "GDB_CONF_FLAGS=--target=powerpc64le-unknown-linux-gnu"
  #define GDB_TARGET_MIPS_ON_X86     "GDB_CONF_FLAGS=--target=mipsel-elf-linux"
  #define GDB_TARGET_MIPS_ON_X86_64  "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
+#define GDB_TARGET_RISCV64_ON_X86_64  "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu"
 
  /*
   *  The original plan was to allow the use of a particular version
@@ -404,6 +410,9 @@ get_current_configuration(struct supported_gdb_version *sp)
  #ifdef __sparc_v9__
         target_data.target = SPARC64;
  #endif
+#ifdef __riscv64__
+       target_data.target = RISCV64;
+#endif
 
         set_initial_target(sp);
 
@@ -457,6 +466,12 @@ get_current_configuration(struct supported_gdb_version *sp)
                         if ((target_data.initial_gdb_target != UNKNOWN) &&
                             (target_data.host != target_data.initial_gdb_target))
                                 arch_mismatch(sp);
+               } else if ((target_data.target == X86_64) &&
+                       (name_to_target((char *)target_data.target_as_param) == RISCV64)) {
+                       /*
+                        *  Build an RISCV64 crash binary on an X86_64 host.
+                        */
+                       target_data.target = RISCV64;
                 } else {
                         fprintf(stderr,
                             "\ntarget=%s is not supported on the %s host architecture\n\n",
@@ -497,6 +512,10 @@ get_current_configuration(struct supported_gdb_version *sp)
                     (target_data.target != MIPS64))
                         arch_mismatch(sp);
 
+               if ((target_data.initial_gdb_target == RISCV64) &&
+                   (target_data.target != RISCV64))
+                       arch_mismatch(sp);
+
                 if ((target_data.initial_gdb_target == X86) &&
                     (target_data.target != X86)) {
                         if (target_data.target == X86_64)
@@ -660,6 +679,9 @@ show_configuration(void)
         case SPARC64:
                 printf("TARGET: SPARC64\n");
                 break;
+       case RISCV64:
+               printf("TARGET: RISCV64\n");
+               break;
         }
 
         if (strlen(target_data.program)) {
@@ -777,6 +799,14 @@ build_configure(struct supported_gdb_version *sp)
                 target = TARGET_SPARC64;
                 target_CFLAGS = TARGET_CFLAGS_SPARC64;
                 break;
+       case RISCV64:
+               target = TARGET_RISCV64;
+               if (target_data.host == X86_64) {
+                       target_CFLAGS = TARGET_CFLAGS_RISCV64_ON_X86_64;
+                       gdb_conf_flags = GDB_TARGET_RISCV64_ON_X86_64;
+               } else
+                       target_CFLAGS = TARGET_CFLAGS_RISCV64;
+               break;
         }
 
         ldflags = get_extra_flags("LDFLAGS.extra", NULL);
@@ -1374,7 +1404,7 @@ make_spec_file(struct supported_gdb_version *sp)
         printf("Vendor: Red Hat, Inc.\n");
         printf("Packager: Dave Anderson <[email protected]>\n");
         printf("ExclusiveOS: Linux\n");
-       printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64\n");
+       printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64\n");
         printf("Buildroot: %%{_tmppath}/%%{name}-root\n");
         printf("BuildRequires: ncurses-devel zlib-devel bison\n");
         printf("Requires: binutils\n");
@@ -1613,6 +1643,8 @@ set_initial_target(struct supported_gdb_version *sp)
                 target_data.initial_gdb_target = MIPS;
         else if (strncmp(buf, "SPARC64", strlen("SPARC64")) == 0)
                 target_data.initial_gdb_target = SPARC64;
+       else if (strncmp(buf, "RISCV64", strlen("RISCV64")) == 0)
+               target_data.initial_gdb_target = RISCV64;
  }
 
  char *
@@ -1633,6 +1665,7 @@ target_to_name(int target)
         case MIPS:   return("MIPS");
         case MIPS64: return("MIPS64");
         case SPARC64: return("SPARC64");
+       case RISCV64: return("RISCV64");
         }
 
         return "UNKNOWN";
@@ -1697,6 +1730,10 @@ name_to_target(char *name)
                 return MIPS64;
         else if (strncmp(name, "sparc64", strlen("sparc64")) == 0)
                 return SPARC64;
+       else if (strncmp(name, "RISCV64", strlen("RISCV64")) == 0)
+               return RISCV64;
+       else if (strncmp(name, "riscv64", strlen("riscv64")) == 0)
+               return RISCV64;
 
         return UNKNOWN;
  }
defs.h +1 -1
index 9b1b69a..42ffba3 100644
@@ -76,7 +76,7 @@
  #if !defined(X86) && !defined(X86_64) && !defined(ALPHA) && !defined(PPC) && \
      !defined(IA64) && !defined(PPC64) && !defined(S390) && !defined(S390X) && \
      !defined(ARM) && !defined(ARM64) && !defined(MIPS) && !defined(MIPS64) && \
-    !defined(SPARC64)
+    !defined(RISCV64) && !defined(SPARC64)
  #ifdef __alpha__
  #define ALPHA
Quoted 8 lines

defs.h line 121

Quoted 6 lines
defs.h +1 -0
  #endif
@@ -118,6 +118,9 @@
  #ifdef __sparc_v9__
  #define SPARC64
  #endif
+#ifdef __riscv64__

this is wrong, should be
#if defined(__riscv) && (__riscv_xlen == 64)

thanks, will fix it in V2

Quoted 401 lines
Quoted 401 lines
defs.h +152 -0
+#define RISCV64
+#endif
  #endif
 
  #ifdef X86
@@ -159,6 +162,9 @@
  #ifdef SPARC64
  #define NR_CPUS  (4096)
  #endif
+#ifdef RISCV64
+#define NR_CPUS  (256)
+#endif
 
  #define NR_DEVICE_DUMPS (64)
 
@@ -3484,6 +3490,63 @@ struct arm64_stackframe {
  #define _MAX_PHYSMEM_BITS       48
  #endif  /* MIPS64 */
 
+#ifdef RISCV64
+#define _64BIT_
+#define MACHINE_TYPE           "RISCV64"
+
+/*
+ * Direct memory mapping
+ */
+#define PTOV(X)                                                                                \
+       (((unsigned long)(X)+(machdep->kvbase)) - machdep->machspec->phys_base)
+#define VTOP(X)        ({                                                                      \
+       ulong _X = X;                                                                   \
+       (THIS_KERNEL_VERSION >= 0x50D00 &&                                              \
+               (_X) >= machdep->machspec->kernel_link_addr) ?                          \
+               (((unsigned long)(_X)-(machdep->machspec->kernel_link_addr)) +          \
+                machdep->machspec->phys_base):                                         \
+               (((unsigned long)(_X)-(machdep->kvbase)) +                              \
+                machdep->machspec->phys_base);                                         \
+       })
+#define PAGEBASE(X)            (((ulong)(X)) & (ulong)machdep->pagemask)
+
+/*
+ * Stack size order
+ */
+#define THREAD_SIZE_ORDER       2
+
+#define PAGE_OFFSET            (machdep->machspec->page_offset)
+#define VMALLOC_START          (machdep->machspec->vmalloc_start_addr)
+#define VMALLOC_END            (machdep->machspec->vmalloc_end)
+#define VMEMMAP_VADDR          (machdep->machspec->vmemmap_vaddr)
+#define VMEMMAP_END            (machdep->machspec->vmemmap_end)
+#define MODULES_VADDR          (machdep->machspec->modules_vaddr)
+#define MODULES_END            (machdep->machspec->modules_end)
+#define IS_VMALLOC_ADDR(X)     riscv64_IS_VMALLOC_ADDR((ulong)(X))
+
+/* from arch/riscv/include/asm/pgtable.h */
+#define __SWP_TYPE_SHIFT        6
+#define __SWP_TYPE_BITS         5
+#define __SWP_TYPE_MASK         ((1UL << __SWP_TYPE_BITS) - 1)
+#define __SWP_OFFSET_SHIFT      (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
+
+#define MAX_SWAPFILES_CHECK()   BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)
+
+#define SWP_TYPE(entry)                (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
+#define SWP_OFFSET(entry)      ((entry) >> __SWP_OFFSET_SHIFT)
+#define __swp_type(entry)       SWP_TYPE(entry)
+#define __swp_offset(entry)     SWP_OFFSET(entry)
+
+#define TIF_SIGPENDING          (THIS_KERNEL_VERSION >= LINUX(2,6,23) ? 1 : 2)
+
+/* from arch/riscv/include/asm/sparsemem.h */
+#define _SECTION_SIZE_BITS      27
+#define _MAX_PHYSMEM_BITS       56 /* 56-bit physical address supported */
+#define PHYS_MASK_SHIFT                _MAX_PHYSMEM_BITS
+#define PHYS_MASK              (((1UL) << PHYS_MASK_SHIFT) - 1)
+
+#endif  /* RISCV64 */
+
  #ifdef X86
  #define _32BIT_
  #define MACHINE_TYPE       "X86"
@@ -4532,6 +4595,10 @@ struct machine_specific {
  #define MAX_HEXADDR_STRLEN (16)
  #define UVADDR_PRLEN      (16)
  #endif
+#ifdef RISCV64
+#define MAX_HEXADDR_STRLEN (16)
+#define UVADDR_PRLEN       (16)
+#endif
 
  #define BADADDR  ((ulong)(-1))
  #define BADVAL   ((ulong)(-1))
@@ -5126,6 +5193,9 @@ void dump_build_data(void);
  #ifdef MIPS64
  #define machdep_init(X) mips64_init(X)
  #endif
+#ifdef RISCV64
+#define machdep_init(X) riscv64_init(X)
+#endif
  #ifdef SPARC64
  #define machdep_init(X) sparc64_init(X)
  #endif
@@ -5606,6 +5676,9 @@ void display_help_screen(char *);
  #ifdef SPARC64
  #define dump_machdep_table(X) sparc64_dump_machdep_table(X)
  #endif
+#ifdef RISCV64
+#define dump_machdep_table(X) riscv64_dump_machdep_table(X)
+#endif
  extern char *help_pointer[];
  extern char *help_alias[];
  extern char *help_ascii[];
@@ -6682,6 +6755,86 @@ struct machine_specific {
 
  #endif /* MIPS64 */
 
+/*
+ * riscv64.c
+ */
+void riscv64_display_regs_from_elf_notes(int, FILE *);
+
+#ifdef RISCV64
+void riscv64_init(int);
+void riscv64_dump_machdep_table(ulong);
+int riscv64_IS_VMALLOC_ADDR(ulong);
+
+#define display_idt_table() \
+       error(FATAL, "-d option is not applicable to RISCV64 architecture\n")
+
+/* from arch/riscv/include/asm/ptrace.h */
+struct riscv64_register {
+       ulong regs[36];
+};
+
+struct riscv64_pt_regs {
+       ulong badvaddr;
+       ulong cause;
+       ulong epc;
+};
+
+struct riscv64_unwind_frame {
+       ulong fp;
+       ulong sp;
+       ulong pc;
+};
+
+#define KSYMS_START    (0x1)
+
+struct machine_specific {
+       ulong phys_base;
+       ulong page_offset;
+       ulong vmalloc_start_addr;
+       ulong vmalloc_end;
+       ulong vmemmap_vaddr;
+       ulong vmemmap_end;
+       ulong modules_vaddr;
+       ulong modules_end;
+       ulong kernel_link_addr;
+       ulong address_space_end;
+
+       ulong _page_present;
+       ulong _page_read;
+       ulong _page_write;
+       ulong _page_exec;
+       ulong _page_user;
+       ulong _page_global;
+       ulong _page_accessed;
+       ulong _page_dirty;
+       ulong _page_soft;
+
+       ulong _pfn_shift;
+
+       struct riscv64_register *crash_task_regs;
+};
+/* from arch/riscv/include/asm/pgtable-bits.h */
+#define        _PAGE_PRESENT   (machdep->machspec->_page_present)
+#define        _PAGE_READ      (machdep->machspec->_page_read)
+#define        _PAGE_WRITE     (machdep->machspec->_page_write)
+#define        _PAGE_EXEC      (machdep->machspec->_page_exec)
+#define        _PAGE_USER      (machdep->machspec->_page_user)
+#define        _PAGE_GLOBAL    (machdep->machspec->_page_global)
+#define        _PAGE_ACCESSED  (machdep->machspec->_page_accessed)
+#define        _PAGE_DIRTY     (machdep->machspec->_page_dirty)
+#define        _PAGE_SOFT      (machdep->machspec->_page_soft)
+#define        _PAGE_SEC       (machdep->machspec->_page_sec)
+#define        _PAGE_SHARE     (machdep->machspec->_page_share)
+#define        _PAGE_BUF       (machdep->machspec->_page_buf)
+#define        _PAGE_CACHE     (machdep->machspec->_page_cache)
+#define        _PAGE_SO        (machdep->machspec->_page_so)
+#define        _PAGE_SPECIAL   _PAGE_SOFT
+#define                _PAGE_TABLE     _PAGE_PRESENT
+#define        _PAGE_PROT_NONE _PAGE_READ
+#define        _PAGE_PFN_SHIFT 10
+
+#endif /* RISCV64 */
+
  /*
   * sparc64.c
   */
diskdump.c +9 -2
index 2c1f9be..28503bc 100644
@@ -622,6 +622,9 @@ restart:
         else if (STRNEQ(header->utsname.machine, "aarch64") &&
             machine_type_mismatch(file, "ARM64", NULL, 0))
                 goto err;
+       else if (STRNEQ(header->utsname.machine, "riscv64") &&
+           machine_type_mismatch(file, "RISCV64", NULL, 0))
+               goto err;
 
         if (header->block_size != block_size) {
                 block_size = header->block_size;
@@ -780,6 +783,8 @@ restart:
                 dd->machine_type = EM_AARCH64;
         else if (machine_type("SPARC64"))
                 dd->machine_type = EM_SPARCV9;
+       else if (machine_type("RISCV64"))
+               dd->machine_type = EM_RISCV;
         else {
                 error(INFO, "%s: unsupported machine type: %s\n",
                         DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
@@ -1751,7 +1756,8 @@ dump_note_offsets(FILE *fp)
                         qemu = FALSE;
                         if (machine_type("X86_64") || machine_type("S390X") ||
                             machine_type("ARM64") || machine_type("PPC64") ||
-                           machine_type("SPARC64") || machine_type("MIPS64")) {
+                           machine_type("SPARC64") || machine_type("MIPS64") ||
+                           machine_type("RISCV64")) {
                                 note64 = (void *)dd->notes_buf + tot;
                                 len = sizeof(Elf64_Nhdr);
                                 if (STRNEQ((char *)note64 + len, "QEMU"))
@@ -2558,7 +2564,8 @@ dump_registers_for_compressed_kdump(void)
         if (!KDUMP_CMPRS_VALID() || (dd->header->header_version < 4) ||
             !(machine_type("X86") || machine_type("X86_64") ||
               machine_type("ARM64") || machine_type("PPC64") ||
-             machine_type("MIPS") || machine_type("MIPS64")))
+             machine_type("MIPS") || machine_type("MIPS64") ||
+             machine_type("RISCV64")))
                 error(FATAL, "-r option not supported for this dumpfile\n");
 
         if (machine_type("ARM64") && (kt->cpus != dd->num_prstatus_notes))
help.c +1 -1
index 99214c1..253c71b 100644
@@ -9512,7 +9512,7 @@ char *README[] = {
  "  These are the current prerequisites: ",
  "",
  "  o  At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,",
-"     mips64, s390 and s390x-based kernels are supported.  Other architectures",
+"     mips64, riscv64, s390 and s390x-based kernels are supported.  Other architectures",
  "     may be addressed in the future.",
  "",
  "  o  One size fits all -- the utility can be run on any Linux kernel version",
lkcd_vmdump_v2_v3.h +1 -1
index 984c2c2..7fa70b9 100644
@@ -37,7 +37,7 @@
 
  #if defined(ARM) || defined(X86) || defined(PPC) || defined(S390) || \
         defined(S390X) || defined(ARM64) || defined(MIPS) || \
-       defined(MIPS64) || defined(SPARC64)
+       defined(MIPS64) || defined(SPARC64) || defined(RISCV64)
 
  /*
   * Kernel header file for Linux crash dumps.
netdump.c +8 -1
index ff273b4..4ec12a0 100644
@@ -300,6 +300,12 @@ is_netdump(char *file, ulong source_query)
                                 goto bailout;
                         break;
 
+               case EM_RISCV:
+                       if (machine_type_mismatch(file, "RISCV64", NULL,
+                           source_query))
+                               goto bailout;
+                       break;
+
                 default:
                         if (machine_type_mismatch(file, "(unknown)", NULL,
                             source_query))
@@ -2935,7 +2941,8 @@ dump_registers_for_elf_dumpfiles(void)
 
          if (!(machine_type("X86") || machine_type("X86_64") ||
             machine_type("ARM64") || machine_type("PPC64") ||
-           machine_type("MIPS") || machine_type("MIPS64")))
+           machine_type("MIPS") || machine_type("MIPS64") ||
+           machine_type("RISCV64")))
                  error(FATAL, "-r option not supported for this dumpfile\n");
 
         if (NETDUMP_DUMPFILE()) {
ramdump.c +2 -0
index a206fcb..d2bd7ff 100644
@@ -188,6 +188,8 @@ char *ramdump_to_elf(void)
                 e_machine = EM_MIPS;
         else if (machine_type("X86_64"))
                 e_machine = EM_X86_64;
+       else if (machine_type("RISCV64"))
+               e_machine = EM_RISCV;
         else
                 error(FATAL, "ramdump: unsupported machine type: %s\n",
                         MACHINE_TYPE);
riscv64.c new file +56 -0
new file mode 100644
index 0000000..c7df857
@@ -0,0 +1,56 @@
+/* riscv64.c - core analysis suite
+ *
+ * Copyright (C) 2022 Alibaba Group Holding Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#ifdef RISCV64
+
+#include <elf.h>
+#include "defs.h"
+
+void
+riscv64_dump_machdep_table(ulong arg)
+{
+}
+
+/*
+ *  Include both vmalloc'd and module address space as VMALLOC space.
+ */
+int
+riscv64_IS_VMALLOC_ADDR(ulong vaddr)
+{
+       return ((vaddr >= VMALLOC_START && vaddr <= VMALLOC_END) ||
+               (vaddr >= VMEMMAP_VADDR && vaddr <= VMEMMAP_END) ||
+               (vaddr >= MODULES_VADDR && vaddr <= MODULES_END));
+}
+
+void
+riscv64_init(int when)
+{
+}
+
+void
+riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
+{
+}
+
+#else /* !RISCV64 */
+
+#include "defs.h"
+
+void
+riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
+{
+       return;
+}
+
+#endif /* !RISCV64 */
symbols.c +10 -1
index bee1faf..ea9e83e 100644
@@ -3743,6 +3743,11 @@ is_kernel(char *file)
                                 goto bailout;
                         break;
 
+               case EM_RISCV:
+                       if (machine_type_mismatch(file, "RISCV64", NULL, 0))
+                               goto bailout;
+                       break;
+
                 default:
                         if (machine_type_mismatch(file, "(unknown)", NULL, 0))
                                 goto bailout;
@@ -4002,6 +4007,11 @@ is_shared_object(char *file)
                         if (machine_type("MIPS64"))
                                 return TRUE;
                         break;
+
+               case EM_RISCV:
+                       if (machine_type("RISCV64"))
+                               return TRUE;
+                       break;
                 }
 
                 if (CRASHDEBUG(1))
--

2.17.1

Quoted 4 lines
Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#7 lore raw

PATCH 2/8 RISCV64: Make crash tool enter command line and support some commands

In reply to Xianting Tian

1. Add riscv64_init() implementation, do all necessary machine-specific setup, which will be called multiple times during initialization.
2. Add riscv64 sv39/48/57 pagetable macro definitions, the function of converting virtual address to a physical address via 4k page table.
3. Add the implementation of the vtop command, which is used to convert a virtual address to a physical address(call the functions defined in 2).
4. Add the implementation to get virtual memory layout, va_bits, phys_ram_base from vmcoreinfo. As these configurations changes from time to time, we send a Linux kernel patch to export these configurations, which can simplify the development of crash tool.
The Linux patch(patch 3 of the series of patches):

	https://lore.kernel.org/linux-riscv/[email protected]/

5. Add riscv64_get_smp_cpus() implementation, get the number of online cpus.
6. Add riscv64_get_page_size() implementation, get page size. And so on.

With this patch, we can enter crash command line, and run "vtop", "mod", "rd", "*", "p", "kmem" ...

Tested on QEMU RISCV64 end and SoC platform of T-head Xuantie 910 CPU.

      KERNEL: vmlinux
    DUMPFILE: vmcore
        CPUS: 1
        DATE: Fri Jul 15 10:24:25 CST 2022
      UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
       TASKS: 41
    NODENAME: buildroot
     RELEASE: 5.18.9
     VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
     MACHINE: riscv64  (unknown Mhz)
      MEMORY: 1 GB
       PANIC: "Kernel panic - not syncing: sysrq triggered crash"
         PID: 113
     COMMAND: "sh"
        TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
         CPU: 0
       STATE: TASK_RUNNING (PANIC)

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00
$5 = {
flags = 0x1000,

  {
    {
      {
        lru = {
          next = 0xff6000003effbf08,
          prev = 0xff6000003effbf08
        },
        {
          __filler = 0xff6000003effbf08,
          mlock_count = 0x3effbf08
        }
      },
      mapping = 0x0,
      index = 0x0,
      private = 0x0
    },

crash> mod

     MODULE       NAME             BASE         SIZE  OBJECT FILE
ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

PGD: ffffffff810e9ff8 => 2ffff001
P4D: 0000000000000000 => 000000002fffec01
PUD: 00005605c2957470 => 0000000020949801
PMD: 00007fff7f1750c0 => 0000000020947401
PTE: 0 => 209534e7
PAGE: 000000008254d000

  PTE     PHYSICAL  FLAGS
209534e7  8254d000  (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

---
 defs.h     |  93 +++++
 diskdump.c |  10 +
 riscv64.c  | 983 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1086 insertions(+)
defs.h +93 -0
index 42ffba3..be4db94 100644
@@ -3494,6 +3494,81 @@ struct arm64_stackframe {
 #define _64BIT_
 #define MACHINE_TYPE		"RISCV64"
 
+typedef struct { ulong pgd; } pgd_t;
+typedef struct { ulong p4d; } p4d_t;
+typedef struct { ulong pud; } pud_t;
+typedef struct { ulong pmd; } pmd_t;
+typedef struct { ulong pte; } pte_t;
+typedef signed int s32;
+
+/* arch/riscv/include/asm/pgtable-64.h */
+#define PGD_SHIFT_L3		(30)
+#define PGD_SHIFT_L4		(39)
+#define PGD_SHIFT_L5		(48)
+
+#define P4D_SHIFT		(39)
+#define PUD_SHIFT		(30)
+#define PMD_SHIFT		(21)
+
+#define PTRS_PER_PGD		(512)
+#define PTRS_PER_P4D		(512)
+#define PTRS_PER_PUD		(512)
+#define PTRS_PER_PMD		(512)
+#define PTRS_PER_PTE		(512)
+
+/*
+ * Mask for PPN and PROT bit53~0 of PTE
+ * 63 6261  60    54  53 10  9 8 7 6 5 4 3 2 1 0
+ * N  PBMT  Reserved  P P N  RSW D A G U X W R V
+ */
+#define PTE_PFN_PROT_MASK	0x3FFFFFFFFFFFFF
+
+/*
+ * 3-levels / 4K pages
+ *
+ * sv39
+ * PGD  |  PMD  |  PTE  |  OFFSET  |
+ *  9   |   9   |   9   |    12    |
+ */
+#define pgd_index_l3_4k(addr) (((addr) >> PGD_SHIFT_L3) & (PTRS_PER_PGD - 1))
+#define pmd_index_l3_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pte_index_l3_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1))
+
+/*
+ * 4-levels / 4K pages
+ *
+ * sv48
+ * PGD  |  PUD  |  PMD  |   PTE   |  OFFSET  |
+ *  9   |   9   |   9   |    9    |    12    |
+ */
+#define pgd_index_l4_4k(addr) (((addr) >> PGD_SHIFT_L4) & (PTRS_PER_PGD - 1))
+#define pud_index_l4_4k(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
+#define pmd_index_l4_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pte_index_l4_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1))
+
+/*
+ * 5-levels / 4K pages
+ *
+ * sv48
+ * PGD  |  P4D  |  PUD  |  PMD  |   PTE   |  OFFSET  |
+ *  9   |   9   |   9   |   9   |    9    |    12    |
+ */
+#define pgd_index_l5_4k(addr) (((addr) >> PGD_SHIFT_L5) & (PTRS_PER_PGD - 1))
+#define p4d_index_l5_4k(addr) (((addr) >> P4D_SHIFT) & (PTRS_PER_P4D - 1))
+#define pud_index_l5_4k(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
+#define pmd_index_l5_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pte_index_l5_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1))
+
+#define VM_L3_4K	(0x2)
+#define VM_L3_2M	(0x4)
+#define VM_L3_1G	(0x8)
+#define VM_L4_4K	(0x10)
+#define VM_L4_2M	(0x20)
+#define VM_L4_1G	(0x40)
+#define VM_L5_4K	(0x80)
+#define VM_L5_2M	(0x100)
+#define VM_L5_1G	(0x200)
+
 /*
  * Direct memory mapping
  */
@@ -3545,6 +3620,14 @@ struct arm64_stackframe {
 #define PHYS_MASK_SHIFT		_MAX_PHYSMEM_BITS
 #define PHYS_MASK		(((1UL) << PHYS_MASK_SHIFT) - 1)
 
+#define IS_LAST_P4D_READ(p4d)	((ulong)(p4d) == machdep->machspec->last_p4d_read)
+#define FILL_P4D(P4D, TYPE, SIZE)                                             \
+    if (!IS_LAST_P4D_READ(P4D)) {                                             \
+	    readmem((ulonglong)((ulong)(P4D)), TYPE, machdep->machspec->p4d,  \
+		     SIZE, "p4d page", FAULT_ON_ERROR);                       \
+	    machdep->machspec->last_p4d_read = (ulong)(P4D);                  \
+    }
+
 #endif  /* RISCV64 */
 
 #ifdef X86
@@ -6810,6 +6893,10 @@ struct machine_specific {
 	ulong _page_soft;
 
 	ulong _pfn_shift;
+	ulong va_bits;
+	char *p4d;
+	ulong last_p4d_read;
+	ulong struct_page_size;
 
 	struct riscv64_register *crash_task_regs;
 };
@@ -6833,6 +6920,12 @@ struct machine_specific {
 #define 	_PAGE_PROT_NONE	_PAGE_READ
 #define 	_PAGE_PFN_SHIFT	10
 
+/* from 'struct pt_regs' definitions of RISC-V arch */
+#define RISCV64_REGS_EPC  0
+#define RISCV64_REGS_RA   1
+#define RISCV64_REGS_SP   2
+#define RISCV64_REGS_FP   8
+
 #endif /* RISCV64 */
 
 /*
diskdump.c +10 -0
index 28503bc..cf5f5d9 100644
@@ -1531,6 +1531,12 @@ get_diskdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp)
 	machdep->get_stack_frame(bt, eip, esp);
 }
 
+static void
+get_diskdump_regs_riscv64(struct bt_info *bt, ulong *eip, ulong *esp)
+{
+	machdep->get_stack_frame(bt, eip, esp);
+}
+
 static void
 get_diskdump_regs_sparc64(struct bt_info *bt, ulong *eip, ulong *esp)
 {
@@ -1610,6 +1616,10 @@ get_diskdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
 		get_diskdump_regs_sparc64(bt, eip, esp);
 		break;
 
+	case EM_RISCV:
+		get_diskdump_regs_riscv64(bt, eip, esp);
+		break;
+
 	default:
 		error(FATAL, "%s: unsupported machine type: %s\n",
 			DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
riscv64.c +983 -0

1,004 lines not on this page · raw message

Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#8 lore raw

Re: [Crash-utility][PATCH 2/8] RISCV64: Make crash tool enter command line and support some commands

Quoted 265 lines · Xianting Tian

1. Add riscv64_init() implementation, do all necessary machine-specific setup, which will be called multiple times during initialization.
2. Add riscv64 sv39/48/57 pagetable macro definitions, the function of converting virtual address to a physical address via 4k page table.
3. Add the implementation of the vtop command, which is used to convert a virtual address to a physical address(call the functions defined in 2).
4. Add the implementation to get virtual memory layout, va_bits, phys_ram_base from vmcoreinfo. As these configurations changes from time to time, we send a Linux kernel patch to export these configurations, which can simplify the development of crash tool.
The Linux patch(patch 3 of the series of patches):
https://lore.kernel.org/linux-riscv/[email protected]/
5. Add riscv64_get_smp_cpus() implementation, get the number of online cpus.
6. Add riscv64_get_page_size() implementation, get page size.
And so on.

With this patch, we can enter crash command line, and run "vtop", "mod", "rd", "*", "p", "kmem" ...

Tested on QEMU RISCV64 end and SoC platform of T-head Xuantie 910 CPU.

       KERNEL: vmlinux
     DUMPFILE: vmcore
         CPUS: 1
         DATE: Fri Jul 15 10:24:25 CST 2022
       UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
        TASKS: 41
     NODENAME: buildroot
      RELEASE: 5.18.9
      VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
      MACHINE: riscv64  (unknown Mhz)
       MEMORY: 1 GB
        PANIC: "Kernel panic - not syncing: sysrq triggered crash"
          PID: 113
      COMMAND: "sh"
         TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
          CPU: 0
        STATE: TASK_RUNNING (PANIC)

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
   flags = 0x1000,
   {
     {
       {
         lru = {
           next = 0xff6000003effbf08,
           prev = 0xff6000003effbf08
         },
         {
           __filler = 0xff6000003effbf08,
           mlock_count = 0x3effbf08
         }
       },
       mapping = 0x0,
       index = 0x0,
       private = 0x0
     },

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

    PGD: ffffffff810e9ff8 => 2ffff001
   P4D: 0000000000000000 => 000000002fffec01
   PUD: 00005605c2957470 => 0000000020949801
   PMD: 00007fff7f1750c0 => 0000000020947401
    PTE: 0 => 209534e7

PAGE: 000000008254d000

PTE PHYSICAL FLAGS
209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

---
  defs.h     |  93 +++++
  diskdump.c |  10 +
  riscv64.c  | 983 +++++++++++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 1086 insertions(+)
defs.h +93 -0
index 42ffba3..be4db94 100644
@@ -3494,6 +3494,81 @@ struct arm64_stackframe {
  #define _64BIT_
  #define MACHINE_TYPE		"RISCV64"
 
+typedef struct { ulong pgd; } pgd_t;
+typedef struct { ulong p4d; } p4d_t;
+typedef struct { ulong pud; } pud_t;
+typedef struct { ulong pmd; } pmd_t;
+typedef struct { ulong pte; } pte_t;
+typedef signed int s32;
+
+/* arch/riscv/include/asm/pgtable-64.h */
+#define PGD_SHIFT_L3		(30)
+#define PGD_SHIFT_L4		(39)
+#define PGD_SHIFT_L5		(48)
+
+#define P4D_SHIFT		(39)
+#define PUD_SHIFT		(30)
+#define PMD_SHIFT		(21)
+
+#define PTRS_PER_PGD		(512)
+#define PTRS_PER_P4D		(512)
+#define PTRS_PER_PUD		(512)
+#define PTRS_PER_PMD		(512)
+#define PTRS_PER_PTE		(512)
+
+/*
+ * Mask for PPN and PROT bit53~0 of PTE
+ * 63 6261  60    54  53 10  9 8 7 6 5 4 3 2 1 0
+ * N  PBMT  Reserved  P P N  RSW D A G U X W R V
+ */
+#define PTE_PFN_PROT_MASK	0x3FFFFFFFFFFFFF
+
+/*
+ * 3-levels / 4K pages
+ *
+ * sv39
+ * PGD  |  PMD  |  PTE  |  OFFSET  |
+ *  9   |   9   |   9   |    12    |
+ */
+#define pgd_index_l3_4k(addr) (((addr) >> PGD_SHIFT_L3) & (PTRS_PER_PGD - 1))
+#define pmd_index_l3_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pte_index_l3_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1))
+
+/*
+ * 4-levels / 4K pages
+ *
+ * sv48
+ * PGD  |  PUD  |  PMD  |   PTE   |  OFFSET  |
+ *  9   |   9   |   9   |    9    |    12    |
+ */
+#define pgd_index_l4_4k(addr) (((addr) >> PGD_SHIFT_L4) & (PTRS_PER_PGD - 1))
+#define pud_index_l4_4k(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
+#define pmd_index_l4_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pte_index_l4_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1))
+
+/*
+ * 5-levels / 4K pages
+ *
+ * sv48
+ * PGD  |  P4D  |  PUD  |  PMD  |   PTE   |  OFFSET  |
+ *  9   |   9   |   9   |   9   |    9    |    12    |
+ */
+#define pgd_index_l5_4k(addr) (((addr) >> PGD_SHIFT_L5) & (PTRS_PER_PGD - 1))
+#define p4d_index_l5_4k(addr) (((addr) >> P4D_SHIFT) & (PTRS_PER_P4D - 1))
+#define pud_index_l5_4k(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
+#define pmd_index_l5_4k(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pte_index_l5_4k(addr) (((addr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1))
+
+#define VM_L3_4K	(0x2)
+#define VM_L3_2M	(0x4)
+#define VM_L3_1G	(0x8)
+#define VM_L4_4K	(0x10)
+#define VM_L4_2M	(0x20)
+#define VM_L4_1G	(0x40)
+#define VM_L5_4K	(0x80)
+#define VM_L5_2M	(0x100)
+#define VM_L5_1G	(0x200)
+
  /*
   * Direct memory mapping
   */
@@ -3545,6 +3620,14 @@ struct arm64_stackframe {
  #define PHYS_MASK_SHIFT		_MAX_PHYSMEM_BITS
  #define PHYS_MASK		(((1UL) << PHYS_MASK_SHIFT) - 1)
 
+#define IS_LAST_P4D_READ(p4d)	((ulong)(p4d) == machdep->machspec->last_p4d_read)
+#define FILL_P4D(P4D, TYPE, SIZE)                                             \
+    if (!IS_LAST_P4D_READ(P4D)) {                                             \
+	    readmem((ulonglong)((ulong)(P4D)), TYPE, machdep->machspec->p4d,  \
+		     SIZE, "p4d page", FAULT_ON_ERROR);                       \
+	    machdep->machspec->last_p4d_read = (ulong)(P4D);                  \
+    }
+
  #endif  /* RISCV64 */
 
  #ifdef X86
@@ -6810,6 +6893,10 @@ struct machine_specific {
  	ulong _page_soft;
 
  	ulong _pfn_shift;
+	ulong va_bits;
+	char *p4d;
+	ulong last_p4d_read;
+	ulong struct_page_size;
 
  	struct riscv64_register *crash_task_regs;
  };
@@ -6833,6 +6920,12 @@ struct machine_specific {
  #define 	_PAGE_PROT_NONE	_PAGE_READ
  #define 	_PAGE_PFN_SHIFT	10
 
+/* from 'struct pt_regs' definitions of RISC-V arch */
+#define RISCV64_REGS_EPC  0
+#define RISCV64_REGS_RA   1
+#define RISCV64_REGS_SP   2
+#define RISCV64_REGS_FP   8
+
  #endif /* RISCV64 */
 
  /*
diskdump.c +10 -0
index 28503bc..cf5f5d9 100644
@@ -1531,6 +1531,12 @@ get_diskdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp)
  	machdep->get_stack_frame(bt, eip, esp);
  }
 
+static void
+get_diskdump_regs_riscv64(struct bt_info *bt, ulong *eip, ulong *esp)
+{
+	machdep->get_stack_frame(bt, eip, esp);
+}
+
  static void
  get_diskdump_regs_sparc64(struct bt_info *bt, ulong *eip, ulong *esp)
  {
@@ -1610,6 +1616,10 @@ get_diskdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
  		get_diskdump_regs_sparc64(bt, eip, esp);
  		break;
 
+	case EM_RISCV:
+		get_diskdump_regs_riscv64(bt, eip, esp);
+		break;
+
  	default:
  		error(FATAL, "%s: unsupported machine type: %s\n",
  			DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
riscv64.c +6 -0
index c7df857..9d40297 100644
@@ -16,10 +16,304 @@
 
  #include <elf.h>
  #include "defs.h"
+#include <math.h>
+
+static ulong riscv64_get_page_size(void);
+static int riscv64_vtop_3level_4k(ulong *pgd, ulong vaddr,
+			    physaddr_t *paddr, int verbose);
+static int riscv64_vtop_4level_4k(ulong *pgd, ulong vaddr,

riscv64.c line 34

Quoted 10 lines
riscv64.c +10 -0
+			    physaddr_t *paddr, int verbose);
+static int riscv64_vtop_5level_4k(ulong *pgd, ulong vaddr,
+			    physaddr_t *paddr, int verbose);
+static void riscv64_page_type_init(void);
+static int riscv64_is_kvaddr(ulong vaddr);
+static int riscv64_is_uvaddr(ulong vaddr, struct task_context *tc);
+static int riscv64_uvtop(struct task_context *tc, ulong vaddr,
+			 physaddr_t *paddr, int verbose);
+static int riscv64_kvtop(struct task_context *tc, ulong kvaddr,
+			 physaddr_t *paddr, int verbose);

(In whole, you can use about 100 chars in a line, if you like.)

Quoted 208 lines
riscv64.c +204 -0
+static void riscv64_cmd_mach(void);
+static int riscv64_translate_pte(ulong, void *, ulonglong);
+static int riscv64_init_active_task_regs(void);
+static int riscv64_get_crash_notes(void);
+static int riscv64_get_elf_notes(void);
+static void riscv64_get_va_range(struct machine_specific *ms);
+static void riscv64_get_struct_page_size(struct machine_specific *ms);
+
+#define REG_FMT	"%016lx"
+#define SZ_2G	0x80000000
+
+/*
+ * Holds registers during the crash.
+ */
+static struct riscv64_register *panic_task_regs;
+
+/* from arch/riscv/include/asm/stacktrace.h */
+struct stackframe {
+	ulong fp;
+	ulong ra;
+};
+
+static struct machine_specific riscv64_machine_specific = {
+	._page_present = (1 << 0),
+	._page_read = (1 << 1),
+	._page_write = (1 << 2),
+	._page_exec = (1 << 3),
+	._page_user = (1 << 4),
+	._page_global = (1 << 5),
+	._page_accessed = (1 << 6),
+	._page_dirty = (1 << 7),
+	._page_soft = (1 << 8),
+
+	.va_bits = 0,
+	.struct_page_size = 0,
+};
+
+static void
+pt_level_alloc(char **lvl, char *name)
+{
+	size_t sz = PAGESIZE();
+	void *pointer = malloc(sz);
+
+	if (!pointer)
+		error(FATAL, name);
+	*lvl = pointer;
+}
+
+static void
+riscv64_get_phys_ram_base(struct machine_specific *ms)
+{
+	char *string;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(phys_ram_base)"))) {
+		ms->phys_base = atol(string);
+		free(string);
+	} else
+		/*
+		 * It can't continue without phys_ram_base. As for qemu rv64
+		 * env and hardware platform, phys_ram_base may different.
+		 */
+		error(FATAL, "cannot read phys_ram_base\n");
+}
+
+static ulong
+riscv64_get_page_size(void)
+{
+	return memory_page_size();
+}
+
+static ulong
+riscv64_vmalloc_start(void)
+{
+	return ((ulong)VMALLOC_START);
+}
+
+/* Get the size of struct page {} */
+static void riscv64_get_struct_page_size(struct machine_specific *ms)
+{
+	char *string;
+
+	string = pc->read_vmcoreinfo("SIZE(page)");
+	if (string)
+		ms->struct_page_size = atol(string);
+	free(string);
+}
+
+/*
+ * Get the max shift of the size of struct page.
+ * Most of the time, it is 64 bytes, but not sure.
+*/
+static int riscv64_get_struct_page_max_shift(struct machine_specific *ms)
+{
+	return (int)ceil(log2(ms->struct_page_size));
+}
+
+static void
+riscv64_cmd_mach(void)
+{
+	/* TODO: */
+}
+
+static int
+riscv64_verify_symbol(const char *name, ulong value, char type)
+{
+	/* TODO: */
+	return TRUE;
+}
 
  void
  riscv64_dump_machdep_table(ulong arg)
  {
+	/* TODO: */
+}
+
+static ulong
+riscv64_processor_speed(void)
+{
+	/* TODO: */
+	return 0;
+}
+
+static unsigned long riscv64_get_kernel_version(void)
+{
+	char *string;
+	char buf[BUFSIZE];
+	char *p1, *p2;
+
+	if (THIS_KERNEL_VERSION)
+		return THIS_KERNEL_VERSION;
+
+	string = pc->read_vmcoreinfo("OSRELEASE");
+	if (string) {
+		strcpy(buf, string);
+
+		p1 = p2 = buf;
+		while (*p2 != '.')
+			p2++;
+		*p2 = NULLCHAR;
+		kt->kernel_version[0] = atoi(p1);
+
+		p1 = ++p2;
+		while (*p2 != '.')
+			p2++;
+		*p2 = NULLCHAR;
+		kt->kernel_version[1] = atoi(p1);
+
+		p1 = ++p2;
+		while ((*p2 >= '0') && (*p2 <= '9'))
+			p2++;
+		*p2 = NULLCHAR;
+		kt->kernel_version[2] = atoi(p1);
+	}
+	free(string);
+	return THIS_KERNEL_VERSION;
+}
+
+static void riscv64_get_va_range(struct machine_specific *ms)
+{
+	unsigned long kernel_version = riscv64_get_kernel_version();
+	char *string;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(VA_BITS)"))) {
+		ms->va_bits = atol(string);
+		free(string);
+	} else
+		goto error;
+	if ((string = pc->read_vmcoreinfo("NUMBER(PAGE_OFFSET)"))) {
+		ms->page_offset = htol(string, QUIET, NULL);
+		free(string);
+	} else
+		goto error;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(VMALLOC_START)"))) {
+		ms->vmalloc_start_addr = htol(string, QUIET, NULL);
+		free(string);
+	} else
+		goto error;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(VMALLOC_END)"))) {
+		ms->vmalloc_end = htol(string, QUIET, NULL);
+                free(string);
+	} else
+		goto error;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(VMEMMAP_START)"))) {
+		ms->vmemmap_vaddr = htol(string, QUIET, NULL);
+		free(string);
+	} else
+		goto error;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(VMEMMAP_END)"))) {
+		ms->vmemmap_end = htol(string, QUIET, NULL);
+		free(string);
+	} else
+		goto error;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(KERNEL_LINK_ADDR)"))) {
+		ms->kernel_link_addr = htol(string, QUIET, NULL);
+		free(string);
+	} else
+		goto error;
+
+	if ((string = pc->read_vmcoreinfo("NUMBER(ADDRESS_SPACE_END)"))) {
+		ms->address_space_end = htol(string, QUIET, NULL);
+		free(string);
+	} else
+		goto error;

riscv64.c line 252

Quoted 10 lines
riscv64.c +10 -0
+
+	/*
+	 * From Linux 5.13, the kernel mapping is moved to the last 2GB
+	 * of the address space, modules use the 2GB memory range right
+	 * before the kernel. Before Linux 5.13, modules area is embedded
+	 * in vmalloc area.
+	 *
+	 * 5.13 = 0x5 << 16 | 0xD << 8
+	 */
+	if (kernel_version >= 0x50D00) {

Please use LINUX() macro.

Quoted 17 lines
riscv64.c +17 -0
+		if ((string = pc->read_vmcoreinfo("NUMBER(MODULES_VADDR)"))) {
+			ms->modules_vaddr = htol(string, QUIET, NULL);
+			free(string);
+		} else
+			goto error;
+
+		if ((string = pc->read_vmcoreinfo("NUMBER(MODULES_END)"))) {
+			ms->modules_end = htol(string, QUIET, NULL);
+			free(string);
+		} else
+			goto error;
+	} else {
+		ms->modules_vaddr = ms->vmalloc_start_addr;
+		ms->modules_end = ms->vmalloc_end;
+	}
+
+	if (CRASHDEBUG(8)) {

riscv64.c line 279

Quoted 10 lines
riscv64.c +10 -0
+		fprintf(fp, "va_bits	: %ld\n", ms->va_bits);
+		fprintf(fp, "vmemmap	: 0x%lx - 0x%lx\n",
+			ms->vmemmap_vaddr, ms->vmemmap_end);
+		fprintf(fp, "vmalloc	: 0x%lx - 0x%lx\n",
+			ms->vmalloc_start_addr, ms->vmalloc_end);
+		fprintf(fp, "lowmem	: 0x%lx -\n", ms->page_offset);
+		fprintf(fp, "mudules	: 0x%lx - 0x%lx\n",
+			ms->modules_vaddr, ms->modules_end);
+		fprintf(fp, "kernel	: 0x%lx - 0x%lx\n",
+			ms->kernel_link_addr, ms->address_space_end);

These are essential information, I think CRASHDEBUG(1) would be better for checking them.

The other patches look good to me.

Thanks,
Kazu

Quoted 731 lines
riscv64.c +721 -0
+	}
+	return;
+error:
+	error(FATAL, "cannot get vm layout\n");
+}
+
+static int
+riscv64_is_kvaddr(ulong vaddr)
+{
+	if (IS_VMALLOC_ADDR(vaddr))
+		return TRUE;
+
+	return (vaddr >= machdep->kvbase);
+}
+
+static int
+riscv64_is_uvaddr(ulong vaddr, struct task_context *unused)
+{
+	if (IS_VMALLOC_ADDR(vaddr))
+		return FALSE;
+
+	return (vaddr < machdep->kvbase);
+}
+
+static int
+riscv64_is_task_addr(ulong task)
+{
+	if (tt->flags & THREAD_INFO)
+		return IS_KVADDR(task);
+
+	return (IS_KVADDR(task) && ALIGNED_STACK_OFFSET(task) == 0);
+}
+
+static int
+riscv64_get_smp_cpus(void)
+{
+	return (get_cpus_online() > 0) ? get_cpus_online() : kt->cpus;
  }
 
  /*
@@ -33,11 +327,700 @@ riscv64_IS_VMALLOC_ADDR(ulong vaddr)
  		(vaddr >= MODULES_VADDR && vaddr <= MODULES_END));
  }
 
+/*
+ * Translate a PTE, returning TRUE if the page is present.
+ * If a physaddr pointer is passed in, don't print anything.
+ */
+static int
+riscv64_translate_pte(ulong pte, void *physaddr, ulonglong unused)
+{
+	char ptebuf[BUFSIZE];
+	char physbuf[BUFSIZE];
+	char buf[BUFSIZE];
+	int page_present;
+	int len1, len2, others;
+	ulong paddr;
+
+	paddr = PTOB(pte >> _PAGE_PFN_SHIFT);
+	page_present = !!(pte & _PAGE_PRESENT);
+
+	if (physaddr) {
+		*(ulong *)physaddr = paddr;
+		return page_present;
+	}
+
+	sprintf(ptebuf, "%lx", pte);
+	len1 = MAX(strlen(ptebuf), strlen("PTE"));
+	fprintf(fp, "%s  ", mkstring(buf, len1, CENTER | LJUST, "PTE"));
+
+	if (!page_present)
+		return page_present;
+
+	sprintf(physbuf, "%lx", paddr);
+	len2 = MAX(strlen(physbuf), strlen("PHYSICAL"));
+	fprintf(fp, "%s  ", mkstring(buf, len2, CENTER | LJUST, "PHYSICAL"));
+
+	fprintf(fp, "FLAGS\n");
+	fprintf(fp, "%s  %s  ",
+		mkstring(ptebuf, len1, CENTER | RJUST, NULL),
+		mkstring(physbuf, len2, CENTER | RJUST, NULL));
+
+	fprintf(fp, "(");
+	others = 0;
+
+#define CHECK_PAGE_FLAG(flag)				\
+	if ((_PAGE_##flag) && (pte & _PAGE_##flag))	\
+		fprintf(fp, "%s" #flag, others++ ? "|" : "")
+	if (pte) {
+		CHECK_PAGE_FLAG(PRESENT);
+		CHECK_PAGE_FLAG(READ);
+		CHECK_PAGE_FLAG(WRITE);
+		CHECK_PAGE_FLAG(EXEC);
+		CHECK_PAGE_FLAG(USER);
+		CHECK_PAGE_FLAG(GLOBAL);
+		CHECK_PAGE_FLAG(ACCESSED);
+		CHECK_PAGE_FLAG(DIRTY);
+		CHECK_PAGE_FLAG(SOFT);
+	} else {
+		fprintf(fp, "no mapping");
+	}
+
+	fprintf(fp, ")\n");
+
+	return page_present;
+}
+
+static void
+riscv64_page_type_init(void)
+{
+	ulong va_bits = machdep->machspec->va_bits;
+
+	/*
+	 * For RISCV64 arch, any level of PTE may be a leaf PTE,
+	 * so in addition to 4KiB pages,
+	 * Sv39 supports 2 MiB megapages, 1 GiB gigapages;
+	 * Sv48 supports 2 MiB megapages, 1 GiB gigapages, 512 GiB terapages;
+	 * Sv57 supports 2 MiB megapages, 1 GiB gigapages, 512 GiB terapages, and 256 TiB petapages.
+	 *
+	 * refs to riscv-privileged spec.
+	 *
+	 * We just support 4KiB, 2MiB, 1GiB now.
+	 */
+	switch (machdep->pagesize)
+	{
+	case 0x1000:		// 4 KiB
+		machdep->flags |= (va_bits == 57 ? VM_L5_4K :
+				  (va_bits == 48 ? VM_L4_4K : VM_L3_4K));
+		break;
+	case 0x200000:		// 2 MiB
+		/* TODO: */
+	case 0x40000000: 	// 1 GiB
+		/* TODO: */
+	default:
+		if (machdep->pagesize)
+			error(FATAL, "invalid/unsupported page size: %d\n",
+			      machdep->pagesize);
+		else
+			error(FATAL, "cannot determine page size\n");
+	}
+}
+
+static int
+riscv64_vtop_3level_4k(ulong *pgd, ulong vaddr, physaddr_t *paddr, int verbose)
+{
+	ulong *pgd_ptr, pgd_val;
+	ulong *pmd_ptr, pmd_val;
+	ulong *pte_ptr, pte_val, pte_pfn;
+	ulong pt_phys;
+
+	/* PGD */
+	pgd_ptr = pgd + pgd_index_l3_4k(vaddr);
+	FILL_PGD(pgd, KVADDR, PAGESIZE());
+	pgd_val = ULONG(machdep->pgd + PAGEOFFSET(pgd_ptr));
+	if (verbose)
+		fprintf(fp, "   PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val);
+	if (!pgd_val)
+		goto no_page;
+	pgd_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pgd_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PMD */
+	FILL_PMD(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pmd_val = ULONG(machdep->pmd + PAGEOFFSET(sizeof(pmd_t) *
+			pmd_index_l3_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
+	if (!pmd_val)
+		goto no_page;
+	pmd_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pmd_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PTE */
+	FILL_PTBL(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pte_val = ULONG(machdep->ptbl + PAGEOFFSET(sizeof(pte_t) *
+			pte_index_l3_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
+	if (!pte_val)
+		goto no_page;
+	pte_val &= PTE_PFN_PROT_MASK;
+	pte_pfn = pte_val >> _PAGE_PFN_SHIFT;
+
+	if (!(pte_val & _PAGE_PRESENT)) {
+		if (verbose) {
+			fprintf(fp, "\n");
+			riscv64_translate_pte((ulong)pte_val, 0, 0);
+		}
+		fprintf(fp, " PAGE: %016lx not present\n\n", PAGEBASE(*paddr));
+		return FALSE;
+	}
+
+	*paddr = PTOB(pte_pfn) + PAGEOFFSET(vaddr);
+
+	if (verbose) {
+		fprintf(fp, " PAGE: %016lx\n\n", PAGEBASE(*paddr));
+		riscv64_translate_pte(pte_val, 0, 0);
+	}
+
+	return TRUE;
+no_page:
+	fprintf(fp, "invalid\n");
+	return FALSE;
+}
+
+static int
+riscv64_vtop_4level_4k(ulong *pgd, ulong vaddr, physaddr_t *paddr, int verbose)
+{
+	ulong *pgd_ptr, pgd_val;
+	ulong *pud_ptr, pud_val;
+	ulong *pmd_ptr, pmd_val;
+	ulong *pte_ptr, pte_val, pte_pfn;
+	ulong pt_phys;
+
+	/* PGD */
+	pgd_ptr = pgd + pgd_index_l4_4k(vaddr);
+	FILL_PGD(pgd, KVADDR, PAGESIZE());
+	pgd_val = ULONG(machdep->pgd + PAGEOFFSET(pgd_ptr));
+	if (verbose)
+		fprintf(fp, "   PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val);
+	if (!pgd_val)
+		goto no_page;
+	pgd_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pgd_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PUD */
+	FILL_PUD(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pud_val = ULONG(machdep->pud + PAGEOFFSET(sizeof(pud_t) *
+			pud_index_l4_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "  PUD: %016lx => %016lx\n", (ulong)pud_ptr, pud_val);
+	if (!pud_val)
+		goto no_page;
+	pud_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pud_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PMD */
+	FILL_PMD(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pmd_val = ULONG(machdep->pmd + PAGEOFFSET(sizeof(pmd_t) *
+			pmd_index_l4_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
+	if (!pmd_val)
+		goto no_page;
+	pmd_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pmd_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PTE */
+	FILL_PTBL(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pte_val = ULONG(machdep->ptbl + PAGEOFFSET(sizeof(pte_t) *
+			pte_index_l4_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
+	if (!pte_val)
+		goto no_page;
+	pte_val &= PTE_PFN_PROT_MASK;
+	pte_pfn = pte_val >> _PAGE_PFN_SHIFT;
+
+	if (!(pte_val & _PAGE_PRESENT)) {
+		if (verbose) {
+			fprintf(fp, "\n");
+			riscv64_translate_pte((ulong)pte_val, 0, 0);
+		}
+		fprintf(fp, " PAGE: %016lx not present\n\n", PAGEBASE(*paddr));
+		return FALSE;
+	}
+
+	*paddr = PTOB(pte_pfn) + PAGEOFFSET(vaddr);
+
+	if (verbose) {
+		fprintf(fp, " PAGE: %016lx\n\n", PAGEBASE(*paddr));
+		riscv64_translate_pte(pte_val, 0, 0);
+	}
+
+	return TRUE;
+no_page:
+	fprintf(fp, "invalid\n");
+	return FALSE;
+}
+
+static int
+riscv64_vtop_5level_4k(ulong *pgd, ulong vaddr, physaddr_t *paddr, int verbose)
+{
+	ulong *pgd_ptr, pgd_val;
+	ulong *p4d_ptr, p4d_val;
+	ulong *pud_ptr, pud_val;
+	ulong *pmd_ptr, pmd_val;
+	ulong *pte_ptr, pte_val, pte_pfn;
+	ulong pt_phys;
+
+	/* PGD */
+	pgd_ptr = pgd + pgd_index_l5_4k(vaddr);
+	FILL_PGD(pgd, KVADDR, PAGESIZE());
+	pgd_val = ULONG(machdep->pgd + PAGEOFFSET(pgd_ptr));
+	if (verbose)
+		fprintf(fp, "   PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val);
+	if (!pgd_val)
+		goto no_page;
+	pgd_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pgd_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* P4D */
+	FILL_P4D(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	p4d_val = ULONG(machdep->machspec->p4d + PAGEOFFSET(sizeof(p4d_t) *
+			p4d_index_l5_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "  P4D: %016lx => %016lx\n", (ulong)p4d_ptr, p4d_val);
+	if (!p4d_val)
+		goto no_page;
+	p4d_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (p4d_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PUD */
+	FILL_PUD(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pud_val = ULONG(machdep->pud + PAGEOFFSET(sizeof(pud_t) *
+			pud_index_l5_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "  PUD: %016lx => %016lx\n", (ulong)pud_ptr, pud_val);
+	if (!pud_val)
+		goto no_page;
+	pud_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pud_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PMD */
+	FILL_PMD(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pmd_val = ULONG(machdep->pmd + PAGEOFFSET(sizeof(pmd_t) *
+			pmd_index_l4_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
+	if (!pmd_val)
+		goto no_page;
+	pmd_val &= PTE_PFN_PROT_MASK;
+	pt_phys = (pmd_val >> _PAGE_PFN_SHIFT) << PAGESHIFT();
+
+	/* PTE */
+	FILL_PTBL(PAGEBASE(pt_phys), PHYSADDR, PAGESIZE());
+	pte_val = ULONG(machdep->ptbl + PAGEOFFSET(sizeof(pte_t) *
+			pte_index_l4_4k(vaddr)));
+	if (verbose)
+		fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
+	if (!pte_val)
+		goto no_page;
+	pte_val &= PTE_PFN_PROT_MASK;
+	pte_pfn = pte_val >> _PAGE_PFN_SHIFT;
+
+	if (!(pte_val & _PAGE_PRESENT)) {
+		if (verbose) {
+			fprintf(fp, "\n");
+			riscv64_translate_pte((ulong)pte_val, 0, 0);
+		}
+		printf("!_PAGE_PRESENT\n");
+		return FALSE;
+	}
+
+	*paddr = PTOB(pte_pfn) + PAGEOFFSET(vaddr);
+
+	if (verbose) {
+		fprintf(fp, " PAGE: %016lx\n\n", PAGEBASE(*paddr));
+		riscv64_translate_pte(pte_val, 0, 0);
+	}
+
+	return TRUE;
+no_page:
+	fprintf(fp, "invalid\n");
+	return FALSE;
+}
+
+static int
+riscv64_init_active_task_regs(void)
+{
+	int retval;
+
+	retval = riscv64_get_crash_notes();
+	if (retval == TRUE)
+		return retval;
+
+	return riscv64_get_elf_notes();
+}
+
+/*
+ * Retrieve task registers for the time of the crash.
+ */
+static int
+riscv64_get_crash_notes(void)
+{
+	struct machine_specific *ms = machdep->machspec;
+	ulong crash_notes;
+	Elf64_Nhdr *note;
+	ulong offset;
+	char *buf, *p;
+	ulong *notes_ptrs;
+	ulong i;
+
+	/*
+	 * crash_notes contains per cpu memory for storing cpu states
+	 * in case of system crash.
+	 */
+	if (!symbol_exists("crash_notes"))
+		return FALSE;
+
+	crash_notes = symbol_value("crash_notes");
+
+	notes_ptrs = (ulong *)GETBUF(kt->cpus*sizeof(notes_ptrs[0]));
+
+	/*
+	 * Read crash_notes for the first CPU. crash_notes are in standard ELF
+	 * note format.
+	 */
+	if (!readmem(crash_notes, KVADDR, &notes_ptrs[kt->cpus-1],
+	    sizeof(notes_ptrs[kt->cpus-1]), "crash_notes",
+		     RETURN_ON_ERROR)) {
+		error(WARNING, "cannot read crash_notes\n");
+		FREEBUF(notes_ptrs);
+		return FALSE;
+	}
+
+	if (symbol_exists("__per_cpu_offset")) {
+
+		/*
+		 * Add __per_cpu_offset for each cpu to form the pointer to the notes
+		 */
+		for (i = 0; i < kt->cpus; i++)
+			notes_ptrs[i] = notes_ptrs[kt->cpus-1] + kt->__per_cpu_offset[i];
+	}
+
+	buf = GETBUF(SIZE(note_buf));
+
+	if (!(panic_task_regs = calloc((size_t)kt->cpus, sizeof(*panic_task_regs))))
+		error(FATAL, "cannot calloc panic_task_regs space\n");
+
+	for (i = 0; i < kt->cpus; i++) {
+
+		if (!readmem(notes_ptrs[i], KVADDR, buf, SIZE(note_buf), "note_buf_t",
+			     RETURN_ON_ERROR)) {
+			error(WARNING,
+				"cannot find NT_PRSTATUS note for cpu: %d\n", i);
+			goto fail;
+		}
+
+		/*
+		 * Do some sanity checks for this note before reading registers from it.
+		 */
+		note = (Elf64_Nhdr *)buf;
+		p = buf + sizeof(Elf64_Nhdr);
+
+		/*
+		 * dumpfiles created with qemu won't have crash_notes, but there will
+		 * be elf notes; dumpfiles created by kdump do not create notes for
+		 * offline cpus.
+		 */
+		if (note->n_namesz == 0 && (DISKDUMP_DUMPFILE() || KDUMP_DUMPFILE())) {
+			if (DISKDUMP_DUMPFILE())
+				note = diskdump_get_prstatus_percpu(i);
+			else if (KDUMP_DUMPFILE())
+				note = netdump_get_prstatus_percpu(i);
+			if (note) {
+				/*
+				 * SIZE(note_buf) accounts for a "final note", which is a
+				 * trailing empty elf note header.
+				 */
+				long notesz = SIZE(note_buf) - sizeof(Elf64_Nhdr);
+
+				if (sizeof(Elf64_Nhdr) + roundup(note->n_namesz, 4) +
+				    note->n_descsz == notesz)
+					BCOPY((char *)note, buf, notesz);
+			} else {
+				error(WARNING,
+					"cannot find NT_PRSTATUS note for cpu: %d\n", i);
+				continue;
+			}
+		}
+
+		/*
+		 * Check the sanity of NT_PRSTATUS note only for each online cpu.
+		 */
+		if (note->n_type != NT_PRSTATUS) {
+			error(WARNING, "invalid NT_PRSTATUS note (n_type != NT_PRSTATUS)\n");
+			goto fail;
+		}
+		if (!STRNEQ(p, "CORE")) {
+			error(WARNING, "invalid NT_PRSTATUS note (name != \"CORE\"\n");
+			goto fail;
+		}
+
+		/*
+		 * Find correct location of note data. This contains elf_prstatus
+		 * structure which has registers etc. for the crashed task.
+		 */
+		offset = sizeof(Elf64_Nhdr);
+		offset = roundup(offset + note->n_namesz, 4);
+		p = buf + offset; /* start of elf_prstatus */
+
+		BCOPY(p + OFFSET(elf_prstatus_pr_reg), &panic_task_regs[i],
+		      sizeof(panic_task_regs[i]));
+	}
+
+	/*
+	 * And finally we have the registers for the crashed task. This is
+	 * used later on when dumping backtrace.
+	 */
+	ms->crash_task_regs = panic_task_regs;
+
+	FREEBUF(buf);
+	FREEBUF(notes_ptrs);
+	return TRUE;
+
+fail:
+	FREEBUF(buf);
+	FREEBUF(notes_ptrs);
+	free(panic_task_regs);
+	return FALSE;
+}
+
+static int
+riscv64_get_elf_notes(void)
+{
+	struct machine_specific *ms = machdep->machspec;
+	int i;
+
+	if (!DISKDUMP_DUMPFILE() && !KDUMP_DUMPFILE())
+		return false;
+
+	panic_task_regs = calloc(kt->cpus, sizeof(*panic_task_regs));
+	if (!panic_task_regs)
+		error(FATAL, "cannot calloc panic_task_regs space\n");
+
+	for (i = 0; i < kt->cpus; i++) {
+		Elf64_Nhdr *note = NULL;
+		size_t len;
+
+		if (DISKDUMP_DUMPFILE())
+			note = diskdump_get_prstatus_percpu(i);
+		else if (KDUMP_DUMPFILE())
+			note = netdump_get_prstatus_percpu(i);
+
+		if (!note) {
+			error(WARNING,
+				"cannot find NT_PRSTATUS note for cpu: %d\n", i);
+			continue;
+		}
+
+		len = sizeof(Elf64_Nhdr);
+		len = roundup(len + note->n_namesz, 4);
+
+		BCOPY((char *)note + len + OFFSET(elf_prstatus_pr_reg),
+		      &panic_task_regs[i], sizeof(panic_task_regs[i]));
+	}
+
+	ms->crash_task_regs = panic_task_regs;
+
+	return TRUE;
+}
+
+/*
+ * Translates a user virtual address to its physical address.
+ */
+static int
+riscv64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose)
+{
+	ulong mm, active_mm;
+	ulong *pgd;
+
+	if (!tc)
+		error(FATAL, "current context invalid\n");
+
+	*paddr = 0;
+
+	if (is_kernel_thread(tc->task) && IS_KVADDR(uvaddr)) {
+		readmem(tc->task + OFFSET(task_struct_active_mm),
+			KVADDR, &active_mm, sizeof(void *),
+			"task active_mm contents", FAULT_ON_ERROR);
+
+		if (!active_mm)
+			error(FATAL,
+			      "no active_mm for this kernel thread\n");
+
+		readmem(active_mm + OFFSET(mm_struct_pgd),
+			KVADDR, &pgd, sizeof(long),
+			"mm_struct pgd", FAULT_ON_ERROR);
+	} else {
+		if ((mm = task_mm(tc->task, TRUE)))
+			pgd = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd));
+		else
+			readmem(tc->mm_struct + OFFSET(mm_struct_pgd),
+				KVADDR, &pgd, sizeof(long), "mm_struct pgd",
+				FAULT_ON_ERROR);
+	}
+
+	switch (machdep->flags & (VM_L3_4K | VM_L4_4K | VM_L5_4K))
+	{
+	case VM_L3_4K:
+		return riscv64_vtop_3level_4k(pgd, uvaddr, paddr, verbose);
+	case VM_L4_4K:
+		return riscv64_vtop_4level_4k(pgd, uvaddr, paddr, verbose);
+	case VM_L5_4K:
+		return riscv64_vtop_5level_4k(pgd, uvaddr, paddr, verbose);
+	default:
+		return FALSE;
+	}
+}
+
+static int
+riscv64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose)
+{
+	ulong kernel_pgd;
+
+	if (!IS_KVADDR(kvaddr))
+		return FALSE;
+
+	if (!vt->vmalloc_start) {
+		*paddr = VTOP(kvaddr);
+		return TRUE;
+	}
+
+	if (!IS_VMALLOC_ADDR(kvaddr)) {
+		*paddr = VTOP(kvaddr);
+		if (!verbose)
+			return TRUE;
+	}
+
+	kernel_pgd = vt->kernel_pgd[0];
+	*paddr = 0;
+
+	switch (machdep->flags & (VM_L3_4K | VM_L4_4K | VM_L5_4K))
+	{
+	case VM_L3_4K:
+		return riscv64_vtop_3level_4k((ulong *)kernel_pgd, kvaddr, paddr, verbose);
+	case VM_L4_4K:
+		return riscv64_vtop_4level_4k((ulong *)kernel_pgd, kvaddr, paddr, verbose);
+	case VM_L5_4K:
+		return riscv64_vtop_5level_4k((ulong *)kernel_pgd, kvaddr, paddr, verbose);
+	default:
+		return FALSE;
+	}
+}
+
  void
  riscv64_init(int when)
  {
+	switch (when) {
+	case SETUP_ENV:
+		machdep->process_elf_notes = process_elf64_notes;
+		break;
+
+	case PRE_SYMTAB:
+		machdep->verify_symbol = riscv64_verify_symbol;
+		machdep->machspec = &riscv64_machine_specific;
+		if (pc->flags & KERNEL_DEBUG_QUERY)
+			return;
+
+		machdep->verify_paddr = generic_verify_paddr;
+		machdep->ptrs_per_pgd = PTRS_PER_PGD;
+		break;
+
+	case PRE_GDB:
+		machdep->pagesize = riscv64_get_page_size();
+		machdep->pageshift = ffs(machdep->pagesize) - 1;
+		machdep->pageoffset = machdep->pagesize - 1;
+		machdep->pagemask = ~((ulonglong)machdep->pageoffset);
+		machdep->stacksize = machdep->pagesize << THREAD_SIZE_ORDER;
+
+		riscv64_get_phys_ram_base(machdep->machspec);
+		riscv64_get_struct_page_size(machdep->machspec);
+		riscv64_get_va_range(machdep->machspec);
+
+		pt_level_alloc(&machdep->pgd, "cannot malloc pgd space.");
+		pt_level_alloc(&machdep->machspec->p4d, "cannot malloc p4d space.");
+		pt_level_alloc(&machdep->pud, "cannot malloc pud space.");
+		pt_level_alloc(&machdep->pmd, "cannot malloc pmd space.");
+		pt_level_alloc(&machdep->ptbl, "cannot malloc ptbl space.");
+
+		machdep->last_pgd_read = 0;
+		machdep->machspec->last_p4d_read = 0;
+		machdep->last_pud_read = 0;
+		machdep->last_pmd_read = 0;
+		machdep->last_ptbl_read = 0;
+
+		machdep->kvbase = machdep->machspec->page_offset;
+		machdep->identity_map_base = machdep->kvbase;
+		machdep->is_kvaddr = riscv64_is_kvaddr;
+		machdep->is_uvaddr = riscv64_is_uvaddr;
+		machdep->uvtop = riscv64_uvtop;
+		machdep->kvtop = riscv64_kvtop;
+		machdep->cmd_mach = riscv64_cmd_mach;
+
+		machdep->vmalloc_start = riscv64_vmalloc_start;
+		machdep->processor_speed = riscv64_processor_speed;
+		machdep->get_stackbase = generic_get_stackbase;
+		machdep->get_stacktop = generic_get_stacktop;
+		machdep->translate_pte = riscv64_translate_pte;
+		machdep->memory_size = generic_memory_size;
+		machdep->is_task_addr = riscv64_is_task_addr;
+		machdep->get_smp_cpus = riscv64_get_smp_cpus;
+		machdep->value_to_symbol = generic_machdep_value_to_symbol;
+		machdep->show_interrupts = generic_show_interrupts;
+		machdep->get_irq_affinity = generic_get_irq_affinity;
+		machdep->init_kernel_pgd = NULL; /* pgd set by symbol_value("swapper_pg_dir") */
+		break;
+
+	case POST_GDB:
+		machdep->section_size_bits = _SECTION_SIZE_BITS;
+		machdep->max_physmem_bits = _MAX_PHYSMEM_BITS;
+		riscv64_page_type_init();
+
+		if (!machdep->hz)
+			machdep->hz = 250;
+
+		if (symbol_exists("irq_desc"))
+			ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc,
+					  "irq_desc", NULL, 0);
+		else if (kernel_symbol_exists("nr_irqs"))
+			get_symbol_data("nr_irqs", sizeof(unsigned int),
+					&machdep->nr_irqs);
+
+		MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus",
+				   "pr_reg");
+
+		STRUCT_SIZE_INIT(note_buf, "note_buf_t");
+		break;
+
+	case POST_VM:
+		/*
+		 * crash_notes contains machine specific information about the
+		 * crash. In particular, it contains CPU registers at the time
+		 * of the crash. We need this information to extract correct
+		 * backtraces from the panic task.
+		 */
+		if (!ACTIVE() && !riscv64_init_active_task_regs())
+			error(WARNING,
+				"cannot retrieve registers for active task%s\n\n",
+				kt->cpus > 1 ? "s" : "");

riscv64.c riscv64_IS_VMALLOC_ADDR(ulong vaddr) · line 1026

Quoted 10 lines
riscv64.c +5 -0
+		break;
+	}
  }
 
+/*
+ * 'help -r' command output
+ */
  void
  riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
  {

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#9 lore raw

PATCH 3/8 RISCV64: Add 'dis' command support

In reply to Xianting Tian

Use generic_dis_filter() function to support dis command implementation.

With this patch, we can get the disassembled code, crash> dis __crash_kexec

0xffffffff80088580 <__crash_kexec>:     addi    sp,sp,-352
0xffffffff80088582 <__crash_kexec+2>:   sd      s0,336(sp)
0xffffffff80088584 <__crash_kexec+4>:   sd      s1,328(sp)
0xffffffff80088586 <__crash_kexec+6>:   sd      s2,320(sp)
0xffffffff80088588 <__crash_kexec+8>:   addi    s0,sp,352
0xffffffff8008858a <__crash_kexec+10>:  sd      ra,344(sp)
0xffffffff8008858c <__crash_kexec+12>:  sd      s3,312(sp)
0xffffffff8008858e <__crash_kexec+14>:  sd      s4,304(sp)
0xffffffff80088590 <__crash_kexec+16>:  auipc   s2,0x1057
0xffffffff80088594 <__crash_kexec+20>:  addi    s2,s2,-1256
0xffffffff80088598 <__crash_kexec+24>:  ld      a5,0(s2)
0xffffffff8008859c <__crash_kexec+28>:  mv      s1,a0
0xffffffff8008859e <__crash_kexec+30>:  auipc   a0,0xfff
---
 riscv64.c | 1 +
 1 file changed, 1 insertion(+)
riscv64.c +1 -0
index 9d40297..a812635 100644
@@ -977,6 +977,7 @@ riscv64_init(int when)
 		machdep->is_task_addr = riscv64_is_task_addr;
 		machdep->get_smp_cpus = riscv64_get_smp_cpus;
 		machdep->value_to_symbol = generic_machdep_value_to_symbol;
+		machdep->dis_filter = generic_dis_filter;
 		machdep->show_interrupts = generic_show_interrupts;
 		machdep->get_irq_affinity = generic_get_irq_affinity;
 		machdep->init_kernel_pgd = NULL; /* pgd set by symbol_value("swapper_pg_dir") */
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#10 lore raw

PATCH 4/8 RISCV64: Add 'irq' command support

In reply to Xianting Tian

With the patch, we can get the irq info,
crash> irq
IRQ IRQ_DESC/_DATA IRQACTION NAME
0 (unused) (unused)

  1   ff60000001329600  ff60000001d17180  "101000.rtc"
  2   ff60000001329800  ff60000001d17680  "ttyS0"
  3   ff60000001329a00  ff60000001c33c00  "virtio0"
  4   ff60000001329c00  ff60000001c33f80  "virtio1"
  5   ff6000000120f400  ff60000001216000  "riscv-timer"
---
 riscv64.c | 1 +
 1 file changed, 1 insertion(+)
riscv64.c +1 -0
index a812635..465834f 100644
@@ -978,6 +978,7 @@ riscv64_init(int when)
 		machdep->get_smp_cpus = riscv64_get_smp_cpus;
 		machdep->value_to_symbol = generic_machdep_value_to_symbol;
 		machdep->dis_filter = generic_dis_filter;
+		machdep->dump_irq = generic_dump_irq;
 		machdep->show_interrupts = generic_show_interrupts;
 		machdep->get_irq_affinity = generic_get_irq_affinity;
 		machdep->init_kernel_pgd = NULL; /* pgd set by symbol_value("swapper_pg_dir") */
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#11 lore raw

PATCH 5/8 RISCV64: Add 'bt' command support

In reply to Xianting Tian

1, Add the implementation to get stack frame from active & inactive
task's stack.
2, Add 'bt -l' command support get a line number associated with a
current pc address.
3, Add 'bt -f' command support to display all stack data contained
in a frame

With the patch, we can get the backtrace,
crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

crash> bt -l
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8
/buildroot/qemu_riscv64_virt_defconfig/build/linux-custom/arch/riscv/kernel/crash_save_regs.S: 47
#1 [ff20000010333cf0] panic at ffffffff806578c6
/buildroot/qemu_riscv64_virt_defconfig/build/linux-custom/kernel/panic.c: 276
... ...

crash> bt -f
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8

    [PC: ffffffff800078f8 RA: ffffffff806578c6 SP: ff20000010333b90 SIZE: 352]
    ff20000010333b90: ff20000010333bb0 ffffffff800078f8
    ff20000010333ba0: ffffffff8008862c ff20000010333b90
    ff20000010333bb0: ffffffff810dde38 ff6000000226c200
    ff20000010333bc0: ffffffff8032be68 0720072007200720

... ...

---
 netdump.c |  13 +++
 riscv64.c | 283 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 296 insertions(+)
netdump.c +13 -0
index 4ec12a0..1f418e6 100644
@@ -42,6 +42,7 @@ static void get_netdump_regs_ppc64(struct bt_info *, ulong *, ulong *);
 static void get_netdump_regs_arm(struct bt_info *, ulong *, ulong *);
 static void get_netdump_regs_arm64(struct bt_info *, ulong *, ulong *);
 static void get_netdump_regs_mips(struct bt_info *, ulong *, ulong *);
+static void get_netdump_regs_riscv(struct bt_info *, ulong *, ulong *);
 static void check_dumpfile_size(char *);
 static int proc_kcore_init_32(FILE *, int);
 static int proc_kcore_init_64(FILE *, int);
@@ -2675,6 +2676,10 @@ get_netdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
 		return get_netdump_regs_mips(bt, eip, esp);
 		break;
 
+	case EM_RISCV:
+		return get_netdump_regs_riscv(bt, eip, esp);
+		break;
+
 	default:
 		error(FATAL, 
 		   "support for ELF machine type %d not available\n",
@@ -2931,6 +2936,8 @@ display_regs_from_elf_notes(int cpu, FILE *ofp)
 		mips_display_regs_from_elf_notes(cpu, ofp);
 	} else if (machine_type("MIPS64")) {
 		mips64_display_regs_from_elf_notes(cpu, ofp);
+	} else if (machine_type("RISCV64")) {
+		riscv64_display_regs_from_elf_notes(cpu, ofp);
 	}
 }
 
@@ -3877,6 +3884,12 @@ get_netdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp)
 	machdep->get_stack_frame(bt, eip, esp);
 }
 
+static void
+get_netdump_regs_riscv(struct bt_info *bt, ulong *eip, ulong *esp)
+{
+	machdep->get_stack_frame(bt, eip, esp);
+}
+
 int 
 is_partial_netdump(void)
 {
riscv64.c +283 -0

307 lines not on this page · raw message

Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#12 lore raw

PATCH 6/8 RISCV64: Add 'help -r' command support

In reply to Xianting Tian

Add support form printing out the registers from the dump file.

With the patch, we can get the regs,
crash> help -r
CPU 0:
epc : ffffffff800078f8 ra : ffffffff8008862c sp : ff20000010333b90
gp : ffffffff810dde38 tp : ff6000000226c200 t0 : ffffffff8032be68 t1 : 0720072007200720 t2 : 666666666666663c s0 : ff20000010333cf0 s1 : 0000000000000000 a0 : ff20000010333b98 a1 : 0000000000000001 a2 : 0000000000000010 a3 : 0000000000000000 a4 : 0000000000000000 a5 : ff60000001c78000 a6 : 000000000000003c a7 : ffffffff8035c9a4 s2 : ffffffff810df0a8 s3 : ffffffff810df718 s4 : ff20000010333b98 s5 : 0000000000000000 s6 : 0000000000000007 s7 : ffffffff80c4a468 s8 : 00ffffffca281410 s9 : 0000000000000007 s10: 00aaaaaab5bb6700
s11: 0000000000000001 t3 : ff60000001218f00 t4 : ff60000001218f00 t5 : ff60000001218000 t6 : ff20000010333988

---
 riscv64.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
riscv64.c +38 -0
index c00ce90..475dc98 100644
@@ -1309,6 +1309,44 @@ riscv64_init(int when)
 void
 riscv64_display_regs_from_elf_notes(int cpu, FILE *ofp)
 {
+	const struct machine_specific *ms = machdep->machspec;
+	struct riscv64_register *regs;
+
+	if (!ms->crash_task_regs) {
+		error(INFO, "registers not collected for cpu %d\n", cpu);
+		return;
+	}
+
+	regs = &ms->crash_task_regs[cpu];
+	if (!regs->regs[RISCV64_REGS_SP] && !regs->regs[RISCV64_REGS_EPC]) {
+		error(INFO, "registers not collected for cpu %d\n", cpu);
+		return;
+	}
+
+	/* Print riscv64 32 regs */
+	fprintf(ofp,
+		"epc : " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n"
+		" gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n"
+		" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n"
+		" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n"
+		" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n"
+		" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n"
+		" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n"
+		" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n"
+		" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n"
+		" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n"
+		" t5 : " REG_FMT " t6 : " REG_FMT "\n",
+		regs->regs[0],  regs->regs[1],  regs->regs[2],
+		regs->regs[3],  regs->regs[4],  regs->regs[5],
+		regs->regs[6],  regs->regs[7],  regs->regs[8],
+		regs->regs[9],  regs->regs[10], regs->regs[11],
+		regs->regs[12], regs->regs[13], regs->regs[14],
+		regs->regs[15], regs->regs[16], regs->regs[17],
+		regs->regs[18], regs->regs[19], regs->regs[20],
+		regs->regs[21], regs->regs[22], regs->regs[23],
+		regs->regs[24], regs->regs[25], regs->regs[26],
+		regs->regs[27], regs->regs[28], regs->regs[29],
+		regs->regs[30], regs->regs[31]);
 }
 
 #else /* !RISCV64 */
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#13 lore raw

PATCH 7/8 RISCV64: Add 'mach' command support

In reply to Xianting Tian

With the patch we can get some basic machine state information, crash> mach
MACHINE TYPE: riscv64
MEMORY SIZE: 1 GB
CPUS: 1
PROCESSOR SPEED: (unknown)
HZ: 250
PAGE SIZE: 4096
KERNEL STACK SIZE: 16384

---
 riscv64.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
riscv64.c +44 -1
index 475dc98..cbf75cf 100644
@@ -139,10 +139,53 @@ static int riscv64_get_struct_page_max_shift(struct machine_specific *ms)
 	return (int)ceil(log2(ms->struct_page_size));
 }
 
+/*
+ * "mach" command output.
+ */
+static void
+riscv64_display_machine_stats(void)
+{
+	struct new_utsname *uts;
+	char buf[BUFSIZE];
+	ulong mhz;
+
+	uts = &kt->utsname;
+
+	fprintf(fp, "		MACHINE TYPE: %s\n", uts->machine);
+	fprintf(fp, "		 MEMORY SIZE: %s\n", get_memory_size(buf));
+	fprintf(fp, "			CPUS: %d\n", get_cpus_to_display());
+	fprintf(fp, "	     PROCESSOR SPEED: ");
+	if ((mhz = machdep->processor_speed()))
+		fprintf(fp, "%ld Mhz\n", mhz);
+	else
+		fprintf(fp, "(unknown)\n");
+	fprintf(fp, "			  HZ: %d\n", machdep->hz);
+	fprintf(fp, "		   PAGE SIZE: %d\n", PAGESIZE());
+	fprintf(fp, "	   KERNEL STACK SIZE: %ld\n", STACKSIZE());
+}
+
 static void
 riscv64_cmd_mach(void)
 {
-	/* TODO: */
+	int c;
+
+	while ((c = getopt(argcnt, args, "cmo")) != EOF) {
+		switch (c) {
+		case 'c':
+		case 'm':
+		case 'o':
+			option_not_supported(c);
+			break;
+		default:
+			argerrs++;
+			break;
+		}
+	}
+
+	if (argerrs)
+		cmd_usage(pc->curcmd, SYNOPSIS);
+
+	riscv64_display_machine_stats();
 }
 
 static int
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#14 lore raw

PATCH 8/8 RISCV64: Add the implementation of symbol verify

In reply to Xianting Tian

Verify the symbol to accept or reject a symbol from the kernel namelist.

---
 riscv64.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
riscv64.c +11 -2
index cbf75cf..04064df 100644
@@ -188,11 +188,20 @@ riscv64_cmd_mach(void)
 	riscv64_display_machine_stats();
 }
 
+/*
+ * Accept or reject a symbol from the kernel namelist.
+ */
 static int
 riscv64_verify_symbol(const char *name, ulong value, char type)
 {
-	/* TODO: */
-	return TRUE;
+	if (CRASHDEBUG(8) && name && strlen(name))
+		fprintf(fp, "%08lx %s\n", value, name);
+
+	if (STREQ(name, "_text") || STREQ(name, "_stext"))
+		machdep->flags |= KSYMS_START;
+
+	return (name && strlen(name) && (machdep->flags & KSYMS_START) &&
+		!STRNEQ(name, "__func__.") && !STRNEQ(name, "__crc_"));
 }
 
 void
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#15 lore raw
In reply to Xianting Tian
Quoted 3 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

With the patchset, the following warnings are emitted.

$ make clean target=RISCV64 ; make warn target=RISCV64
...
cc -c -g -DRISCV64  -DGDB_10_2  riscv64.c -Wall -O2 -Wstrict-prototypes -Wmissing-prototypes -fstack-protector -Wformat-security
riscv64.c: In function ‘riscv64_get_stack_frame’:
riscv64.c:904:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
   int ret = 0;
       ^~~
At top level:
riscv64.c:137:12: warning: ‘riscv64_get_struct_page_max_shift’ defined but not used [-Wunused-function]
  static int riscv64_get_struct_page_max_shift(struct machine_specific *ms)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c: In function ‘riscv64_vtop_3level_4k’:
riscv64.c:515:3: warning: ‘pmd_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:526:3: warning: ‘pte_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c: In function ‘riscv64_vtop_4level_4k’:
riscv64.c:579:3: warning: ‘pud_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "  PUD: %016lx => %016lx\n", (ulong)pud_ptr, pud_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:590:3: warning: ‘pmd_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:601:3: warning: ‘pte_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c: In function ‘riscv64_vtop_5level_4k’:
riscv64.c:655:3: warning: ‘p4d_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "  P4D: %016lx => %016lx\n", (ulong)p4d_ptr, p4d_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:666:3: warning: ‘pud_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "  PUD: %016lx => %016lx\n", (ulong)pud_ptr, pud_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:677:3: warning: ‘pmd_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:688:3: warning: ‘pte_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks,
Kazu

Quoted 122 lines

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

       KERNEL: vmlinux
     DUMPFILE: vmcore
         CPUS: 1
         DATE: Fri Jul 15 10:24:25 CST 2022
       UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
        TASKS: 41
     NODENAME: buildroot
      RELEASE: 5.18.9
      VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
      MACHINE: riscv64  (unknown Mhz)
       MEMORY: 1 GB
        PANIC: "Kernel panic - not syncing: sysrq triggered crash"
          PID: 113
      COMMAND: "sh"
         TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
          CPU: 0
        STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
   flags = 0x1000,
   {
     {
       {
         lru = {
           next = 0xff6000003effbf08,
           prev = 0xff6000003effbf08
         },
         {
           __filler = 0xff6000003effbf08,
           mlock_count = 0x3effbf08
         }
       },
       mapping = 0x0,
       index = 0x0,
       private = 0x0
     },
   ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

    PGD: ffffffff810e9ff8 => 2ffff001
   P4D: 0000000000000000 => 000000002fffec01
   PUD: 00005605c2957470 => 0000000020949801
   PMD: 00007fff7f1750c0 => 0000000020947401
    PTE: 0 => 209534e7

PAGE: 000000008254d000

PTE PHYSICAL FLAGS
209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

  Makefile            |    7 +-
  README              |    2 +-
  configure.c         |   39 +-
  defs.h              |  248 +++++++-
  diskdump.c          |   21 +-
  help.c              |    2 +-
  lkcd_vmdump_v2_v3.h |    2 +-
  netdump.c           |   22 +-
  ramdump.c           |    2 +
  riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
  symbols.c           |   10 +
  11 files changed, 1759 insertions(+), 10 deletions(-)
Quoted 2 lines

create mode 100644 riscv64.c

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#16 lore raw
Quoted 39 lines · HAGIO KAZUHITO(萩尾 一仁)
Quoted 3 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

With the patchset, the following warnings are emitted.

$ make clean target=RISCV64 ; make warn target=RISCV64
...
cc -c -g -DRISCV64  -DGDB_10_2  riscv64.c -Wall -O2 -Wstrict-prototypes -Wmissing-prototypes -fstack-protector -Wformat-security
riscv64.c: In function ‘riscv64_get_stack_frame’:
riscv64.c:904:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
    int ret = 0;
        ^~~
At top level:
riscv64.c:137:12: warning: ‘riscv64_get_struct_page_max_shift’ defined but not used [-Wunused-function]
   static int riscv64_get_struct_page_max_shift(struct machine_specific *ms)
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c: In function ‘riscv64_vtop_3level_4k’:
riscv64.c:515:3: warning: ‘pmd_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:526:3: warning: ‘pte_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c: In function ‘riscv64_vtop_4level_4k’:
riscv64.c:579:3: warning: ‘pud_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "  PUD: %016lx => %016lx\n", (ulong)pud_ptr, pud_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:590:3: warning: ‘pmd_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:601:3: warning: ‘pte_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c: In function ‘riscv64_vtop_5level_4k’:
riscv64.c:655:3: warning: ‘p4d_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "  P4D: %016lx => %016lx\n", (ulong)p4d_ptr, p4d_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:666:3: warning: ‘pud_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Quoted 8 lines
     fprintf(fp, "  PUD: %016lx => %016lx\n", (ulong)pud_ptr, pud_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:677:3: warning: ‘pmd_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "  PMD: %016lx => %016lx\n", (ulong)pmd_ptr, pmd_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riscv64.c:688:3: warning: ‘pte_ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     fprintf(fp, "   PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

thanks for the comments for the series of patches, I will fix it V2.

Quoted 126 lines

Thanks,
Kazu

Quoted 122 lines

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

        KERNEL: vmlinux
      DUMPFILE: vmcore
          CPUS: 1
          DATE: Fri Jul 15 10:24:25 CST 2022
        UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
         TASKS: 41
      NODENAME: buildroot
       RELEASE: 5.18.9
       VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
       MACHINE: riscv64  (unknown Mhz)
        MEMORY: 1 GB
         PANIC: "Kernel panic - not syncing: sysrq triggered crash"
           PID: 113
       COMMAND: "sh"
          TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
           CPU: 0
         STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
    flags = 0x1000,
    {
      {
        {
          lru = {
            next = 0xff6000003effbf08,
            prev = 0xff6000003effbf08
          },
          {
            __filler = 0xff6000003effbf08,
            mlock_count = 0x3effbf08
          }
        },
        mapping = 0x0,
        index = 0x0,
        private = 0x0
      },
    ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

     PGD: ffffffff810e9ff8 => 2ffff001
    P4D: 0000000000000000 => 000000002fffec01
    PUD: 00005605c2957470 => 0000000020949801
    PMD: 00007fff7f1750c0 => 0000000020947401
     PTE: 0 => 209534e7

PAGE: 000000008254d000

PTE PHYSICAL FLAGS
209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

   Makefile            |    7 +-
   README              |    2 +-
   configure.c         |   39 +-
   defs.h              |  248 +++++++-
   diskdump.c          |   21 +-
   help.c              |    2 +-
   lkcd_vmdump_v2_v3.h |    2 +-
   netdump.c           |   22 +-
   ramdump.c           |    2 +
   riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
   symbols.c           |   10 +
   11 files changed, 1759 insertions(+), 10 deletions(-)

create mode 100644 riscv64.c

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#17 lore raw
In reply to Xianting Tian

Hi Xianting

Quoted 128 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

      KERNEL: vmlinux
    DUMPFILE: vmcore
        CPUS: 1
        DATE: Fri Jul 15 10:24:25 CST 2022
      UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
       TASKS: 41
    NODENAME: buildroot
     RELEASE: 5.18.9
     VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
     MACHINE: riscv64  (unknown Mhz)
      MEMORY: 1 GB
       PANIC: "Kernel panic - not syncing: sysrq triggered crash"
         PID: 113
     COMMAND: "sh"
        TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
         CPU: 0
       STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00
$5 = {
flags = 0x1000,

  {
    {
      {
        lru = {
          next = 0xff6000003effbf08,
          prev = 0xff6000003effbf08
        },
        {
          __filler = 0xff6000003effbf08,
          mlock_count = 0x3effbf08
        }
      },
      mapping = 0x0,
      index = 0x0,
      private = 0x0
    },

... ...

crash> mod

     MODULE       NAME             BASE         SIZE  OBJECT FILE
ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

   PGD: ffffffff810e9ff8 => 2ffff001

P4D: 0000000000000000 => 000000002fffec01
PUD: 00005605c2957470 => 0000000020949801
PMD: 00007fff7f1750c0 => 0000000020947401
PTE: 0 => 209534e7
PAGE: 000000008254d000

  PTE     PHYSICAL  FLAGS
209534e7  8254d000  (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

 Makefile            |    7 +-
 README              |    2 +-
 configure.c         |   39 +-
 defs.h              |  248 +++++++-
 diskdump.c          |   21 +-
 help.c              |    2 +-
 lkcd_vmdump_v2_v3.h |    2 +-
 netdump.c           |   22 +-
 ramdump.c           |    2 +
 riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
 symbols.c           |   10 +
 11 files changed, 1759 insertions(+), 10 deletions(-)
 create mode 100644 riscv64.c
Quoted 3 lines

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

  121 |         struct pt_regs       dh_regs;
      |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

   90 |         struct pt_regs       dha_regs;
      |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1
make[4]: *** [Makefile:1871: gdb] Error 2
make[3]: *** [Makefile:10072: all-gdb] Error 2
make[2]: *** [Makefile:860: all] Error 2

crash build failed

=====
and this error can be fixed by applying the following patch, can you help to double check if it's a correct fix?

lkcd_vmdump_v1.h +2 -0
index 4933427..f6c4a26 100644
@@ -118,10 +118,12 @@ typedef struct _dump_header_s {
 #ifndef S390
 #ifndef S390X
 #ifndef ARM64
+#ifndef RISCV64
        struct pt_regs       dh_regs;
 #endif
 #endif
 #endif
+#endif
 #endif
 
        /* the address of the current task */
lkcd_vmdump_v2_v3.h +2 -0
index 7fa70b9..6d4fd27 100644
@@ -87,10 +87,12 @@ typedef struct _dump_header_asm_s {
 #ifndef S390
 #ifndef S390X
 #ifndef ARM64
+#ifndef RISCV64
        struct pt_regs       dha_regs;
 #endif
 #endif
 #endif
+#endif
 
 } dump_header_asm_t;
 

===

Yixun Lan

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#18 lore raw
Quoted 151 lines · Yixun Lan

Hi Xianting

Quoted 125 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

       KERNEL: vmlinux
     DUMPFILE: vmcore
         CPUS: 1
         DATE: Fri Jul 15 10:24:25 CST 2022
       UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
        TASKS: 41
     NODENAME: buildroot
      RELEASE: 5.18.9
      VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
      MACHINE: riscv64  (unknown Mhz)
       MEMORY: 1 GB
        PANIC: "Kernel panic - not syncing: sysrq triggered crash"
          PID: 113
      COMMAND: "sh"
         TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
          CPU: 0
        STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
   flags = 0x1000,
   {
     {
       {
         lru = {
           next = 0xff6000003effbf08,
           prev = 0xff6000003effbf08
         },
         {
           __filler = 0xff6000003effbf08,
           mlock_count = 0x3effbf08
         }
       },
       mapping = 0x0,
       index = 0x0,
       private = 0x0
     },
   ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

    PGD: ffffffff810e9ff8 => 2ffff001
   P4D: 0000000000000000 => 000000002fffec01
   PUD: 00005605c2957470 => 0000000020949801
   PMD: 00007fff7f1750c0 => 0000000020947401
    PTE: 0 => 209534e7

PAGE: 000000008254d000

PTE PHYSICAL FLAGS
209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

  Makefile            |    7 +-
  README              |    2 +-
  configure.c         |   39 +-
  defs.h              |  248 +++++++-
  diskdump.c          |   21 +-
  help.c              |    2 +-
  lkcd_vmdump_v2_v3.h |    2 +-
  netdump.c           |   22 +-
  ramdump.c           |    2 +
  riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
  symbols.c           |   10 +
  11 files changed, 1759 insertions(+), 10 deletions(-)
Quoted 5 lines

create mode 100644 riscv64.c

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

   121 |         struct pt_regs       dh_regs;
       |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

Quoted 8 lines
    90 |         struct pt_regs       dha_regs;
       |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1
make[4]: *** [Makefile:1871: gdb] Error 2
make[3]: *** [Makefile:10072: all-gdb] Error 2
make[2]: *** [Makefile:860: all] Error 2

crash build failed

It's strange, actually I didn't meet such compiling error by 'make target=RISCV64', the compiling is OK.

Do you have more details for the build?

Quoted 41 lines

=====
and this error can be fixed by applying the following patch, can you help to double check if it's a correct fix?

lkcd_vmdump_v1.h +2 -0
index 4933427..f6c4a26 100644
@@ -118,10 +118,12 @@ typedef struct _dump_header_s {
  #ifndef S390
  #ifndef S390X
  #ifndef ARM64
+#ifndef RISCV64
         struct pt_regs       dh_regs;
  #endif
  #endif
  #endif
+#endif
  #endif
 
         /* the address of the current task */
lkcd_vmdump_v2_v3.h +2 -0
index 7fa70b9..6d4fd27 100644
@@ -87,10 +87,12 @@ typedef struct _dump_header_asm_s {
  #ifndef S390
  #ifndef S390X
  #ifndef ARM64
+#ifndef RISCV64
         struct pt_regs       dha_regs;
  #endif
  #endif
  #endif
+#endif
 
  } dump_header_asm_t;
 

===

Quoted 1 line

Yixun Lan

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#19 lore raw

HI Xianting

Quoted 161 lines · Xianting Tian
Quoted 158 lines · Yixun Lan

Hi Xianting

Quoted 125 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

       KERNEL: vmlinux
     DUMPFILE: vmcore
         CPUS: 1
         DATE: Fri Jul 15 10:24:25 CST 2022
       UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
        TASKS: 41
     NODENAME: buildroot
      RELEASE: 5.18.9
      VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
      MACHINE: riscv64  (unknown Mhz)
       MEMORY: 1 GB
        PANIC: "Kernel panic - not syncing: sysrq triggered crash"
          PID: 113
      COMMAND: "sh"
         TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
          CPU: 0
        STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
   flags = 0x1000,
   {
     {
       {
         lru = {
           next = 0xff6000003effbf08,
           prev = 0xff6000003effbf08
         },
         {
           __filler = 0xff6000003effbf08,
           mlock_count = 0x3effbf08
         }
       },
       mapping = 0x0,
       index = 0x0,
       private = 0x0
     },
   ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

    PGD: ffffffff810e9ff8 => 2ffff001
   P4D: 0000000000000000 => 000000002fffec01
   PUD: 00005605c2957470 => 0000000020949801
   PMD: 00007fff7f1750c0 => 0000000020947401
    PTE: 0 => 209534e7

PAGE: 000000008254d000

PTE PHYSICAL FLAGS
209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

  Makefile            |    7 +-
  README              |    2 +-
  configure.c         |   39 +-
  defs.h              |  248 +++++++-
  diskdump.c          |   21 +-
  help.c              |    2 +-
  lkcd_vmdump_v2_v3.h |    2 +-
  netdump.c           |   22 +-
  ramdump.c           |    2 +
  riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
  symbols.c           |   10 +
  11 files changed, 1759 insertions(+), 10 deletions(-)
Quoted 5 lines

create mode 100644 riscv64.c

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

   121 |         struct pt_regs       dh_regs;
       |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

    90 |         struct pt_regs       dha_regs;
       |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1
make[4]: *** [Makefile:1871: gdb] Error 2
make[3]: *** [Makefile:10072: all-gdb] Error 2
make[2]: *** [Makefile:860: all] Error 2

Quoted 7 lines
Quoted 1 line

crash build failed

It's strange, actually I didn't meet such compiling error by 'make target=RISCV64', the compiling is OK.

Do you have more details for the build?

FYI, I'm using source code of crash, commit: f37df7df8a50
I don't think it's necessary to pass 'target' variable explicitly, see the comment of Makefile

==== snip of Makefile

# target could be set on command line when invoking make. Like: make target=ARM
# otherwise target will be the same as the host
ifneq ($(target),)
CONF_TARGET_FLAG="-t$(target)"
endif
====

besides, it actually recognized the correct target successfully

==== snip of build log
make -j8 CC=riscv64-unknown-linux-gnu-gcc AR=riscv64-unknown-linux-gnu-ar 'CFLAGS=-O2 -pipe' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed'
TARGET: RISCV64
CRASH: 8.0.1++
GDB: 10.2
====

please check [1] for full build log
[1] https://dev.gentoo.org/~dlan/logs/crash-build.log.xz

Quoted 37 lines
Quoted 37 lines

=====
and this error can be fixed by applying the following patch, can you help to double check if it's a correct fix?

lkcd_vmdump_v1.h +2 -0
index 4933427..f6c4a26 100644
@@ -118,10 +118,12 @@ typedef struct _dump_header_s {
  #ifndef S390
  #ifndef S390X
  #ifndef ARM64
+#ifndef RISCV64
         struct pt_regs       dh_regs;
  #endif
  #endif
  #endif
+#endif
  #endif
 
         /* the address of the current task */
lkcd_vmdump_v2_v3.h +2 -0
index 7fa70b9..6d4fd27 100644
@@ -87,10 +87,12 @@ typedef struct _dump_header_asm_s {
  #ifndef S390
  #ifndef S390X
  #ifndef ARM64
+#ifndef RISCV64
         struct pt_regs       dha_regs;
  #endif
  #endif
  #endif
+#endif
 
Quoted 5 lines
Quoted 5 lines
lkcd_vmdump_v2_v3.h +0 -0
  } dump_header_asm_t;
 

===

Yixun Lan

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#20 lore raw
Quoted 184 lines · Yixun Lan

HI Xianting

Quoted 160 lines · Xianting Tian
Quoted 158 lines · Yixun Lan

Hi Xianting

Quoted 125 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

        KERNEL: vmlinux
      DUMPFILE: vmcore
          CPUS: 1
          DATE: Fri Jul 15 10:24:25 CST 2022
        UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
         TASKS: 41
      NODENAME: buildroot
       RELEASE: 5.18.9
       VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
       MACHINE: riscv64  (unknown Mhz)
        MEMORY: 1 GB
         PANIC: "Kernel panic - not syncing: sysrq triggered crash"
           PID: 113
       COMMAND: "sh"
          TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
           CPU: 0
         STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
    flags = 0x1000,
    {
      {
        {
          lru = {
            next = 0xff6000003effbf08,
            prev = 0xff6000003effbf08
          },
          {
            __filler = 0xff6000003effbf08,
            mlock_count = 0x3effbf08
          }
        },
        mapping = 0x0,
        index = 0x0,
        private = 0x0
      },
    ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

     PGD: ffffffff810e9ff8 => 2ffff001
    P4D: 0000000000000000 => 000000002fffec01
    PUD: 00005605c2957470 => 0000000020949801
    PMD: 00007fff7f1750c0 => 0000000020947401
     PTE: 0 => 209534e7

PAGE: 000000008254d000

PTE PHYSICAL FLAGS
209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

   Makefile            |    7 +-
   README              |    2 +-
   configure.c         |   39 +-
   defs.h              |  248 +++++++-
   diskdump.c          |   21 +-
   help.c              |    2 +-
   lkcd_vmdump_v2_v3.h |    2 +-
   netdump.c           |   22 +-
   ramdump.c           |    2 +
   riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
   symbols.c           |   10 +
   11 files changed, 1759 insertions(+), 10 deletions(-)
Quoted 5 lines

create mode 100644 riscv64.c

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

    121 |         struct pt_regs       dh_regs;
        |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

     90 |         struct pt_regs       dha_regs;
        |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1
make[4]: *** [Makefile:1871: gdb] Error 2
make[3]: *** [Makefile:10072: all-gdb] Error 2
make[2]: *** [Makefile:860: all] Error 2

Quoted 6 lines
Quoted 1 line

crash build failed

It's strange, actually I didn't meet such compiling error by 'make target=RISCV64', the compiling is OK.

Do you have more details for the build?

FYI, I'm using source code of crash, commit: f37df7df8a50
I don't think it's necessary to pass 'target' variable explicitly, see the comment of Makefile

==== snip of Makefile

# target could be set on command line when invoking make. Like: make target=ARM
# otherwise target will be the same as the host
ifneq ($(target),)
CONF_TARGET_FLAG="-t$(target)"
endif
====

besides, it actually recognized the correct target successfully

Quoted 8 lines

==== snip of build log
make -j8 CC=riscv64-unknown-linux-gnu-gcc AR=riscv64-unknown-linux-gnu-ar 'CFLAGS=-O2 -pipe' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed'
TARGET: RISCV64
CRASH: 8.0.1++

    GDB: 10.2

====

Sorry, I don't quite understand, we usually build crash tool on x86_64 for analyzing other ARCH's vmcore.

As README shows, we need type target=XXX for analyzing XXX arch vmcore. If we only use 'make' to build on X86_64, it is used to analyze x86_64's vmcore.

I don't think "make -j8 CC=riscv64-unknown-linux-gnu-gcc" is ok for the build.  If I am wrong, please correct me. thanks

README:

  The crash binary can only be used on systems of the same architecture as the host build system.  There are a few optional manners of building the crash binary:

  o  On an x86_64 host, a 32-bit x86 binary that can be used to analyze 32-bit x86 dumpfiles may be built by typing "make target=X86". o  On an x86 or x86_64 host, a 32-bit x86 binary that can be used to analyze 32-bit arm dumpfiles may be built by typing "make target=ARM". o  On an x86 or x86_64 host, a 32-bit x86 binary that can be used to analyze 32-bit mips dumpfiles may be built by typing "make target=MIPS". o  On an ppc64 host, a 32-bit ppc binary that can be used to analyze 32-bit ppc dumpfiles may be built by typing "make target=PPC". o  On an x86_64 host, an x86_64 binary that can be used to analyze arm64 dumpfiles may be built by typing "make target=ARM64". o  On an x86_64 host, an x86_64 binary that can be used to analyze ppc64le dumpfiles may be built by typing "make target=PPC64". o  On an x86_64 host, an x86_64 binary that can be used to analyze riscv64 dumpfiles may be built by typing "make target=RISCV64".

Quoted 40 lines

please check [1] for full build log
[1] https://dev.gentoo.org/~dlan/logs/crash-build.log.xz

Quoted 36 lines
Quoted 36 lines

=====
and this error can be fixed by applying the following patch, can you help to double check if it's a correct fix?

lkcd_vmdump_v1.h +2 -0
index 4933427..f6c4a26 100644
@@ -118,10 +118,12 @@ typedef struct _dump_header_s {
   #ifndef S390
   #ifndef S390X
   #ifndef ARM64
+#ifndef RISCV64
          struct pt_regs       dh_regs;
   #endif
   #endif
   #endif
+#endif
   #endif
 
          /* the address of the current task */
lkcd_vmdump_v2_v3.h +2 -0
index 7fa70b9..6d4fd27 100644
@@ -87,10 +87,12 @@ typedef struct _dump_header_asm_s {
   #ifndef S390
   #ifndef S390X
   #ifndef ARM64
+#ifndef RISCV64
          struct pt_regs       dha_regs;
   #endif
   #endif
   #endif
+#endif
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lkcd_vmdump_v2_v3.h +0 -0
   } dump_header_asm_t;
 

===

Yixun Lan

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#21 lore raw

HI Xianting:

Quoted 199 lines · Xianting Tian
Quoted 184 lines · Yixun Lan

HI Xianting

Quoted 160 lines · Xianting Tian
Quoted 158 lines · Yixun Lan

Hi Xianting

Quoted 125 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

        KERNEL: vmlinux
      DUMPFILE: vmcore
          CPUS: 1
          DATE: Fri Jul 15 10:24:25 CST 2022
        UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
         TASKS: 41
      NODENAME: buildroot
       RELEASE: 5.18.9
       VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
       MACHINE: riscv64  (unknown Mhz)
        MEMORY: 1 GB
         PANIC: "Kernel panic - not syncing: sysrq triggered crash"
           PID: 113
       COMMAND: "sh"
          TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
           CPU: 0
         STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
    flags = 0x1000,
    {
      {
        {
          lru = {
            next = 0xff6000003effbf08,
            prev = 0xff6000003effbf08
          },
          {
            __filler = 0xff6000003effbf08,
            mlock_count = 0x3effbf08
          }
        },
        mapping = 0x0,
        index = 0x0,
        private = 0x0
      },
    ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

     PGD: ffffffff810e9ff8 => 2ffff001
    P4D: 0000000000000000 => 000000002fffec01
    PUD: 00005605c2957470 => 0000000020949801
    PMD: 00007fff7f1750c0 => 0000000020947401
     PTE: 0 => 209534e7

PAGE: 000000008254d000

PTE PHYSICAL FLAGS
209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604 #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8 #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

   Makefile            |    7 +-
   README              |    2 +-
   configure.c         |   39 +-
   defs.h              |  248 +++++++-
   diskdump.c          |   21 +-
   help.c              |    2 +-
   lkcd_vmdump_v2_v3.h |    2 +-
   netdump.c           |   22 +-
   ramdump.c           |    2 +
   riscv64.c           | 1414 +++++++++++++++++++++++++++++++++++++++++++
   symbols.c           |   10 +
   11 files changed, 1759 insertions(+), 10 deletions(-)
Quoted 5 lines

create mode 100644 riscv64.c

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

    121 |         struct pt_regs       dh_regs;
        |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

     90 |         struct pt_regs       dha_regs;
        |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1 make[4]: *** [Makefile:1871: gdb] Error 2 make[3]: *** [Makefile:10072: all-gdb] Error 2 make[2]: *** [Makefile:860: all] Error 2

Quoted 6 lines
Quoted 1 line

crash build failed

It's strange, actually I didn't meet such compiling error by 'make target=RISCV64', the compiling is OK.

Do you have more details for the build?

FYI, I'm using source code of crash, commit: f37df7df8a50
I don't think it's necessary to pass 'target' variable explicitly, see the comment of Makefile

==== snip of Makefile

# target could be set on command line when invoking make. Like: make target=ARM
# otherwise target will be the same as the host
ifneq ($(target),)
CONF_TARGET_FLAG="-t$(target)"
endif
====

besides, it actually recognized the correct target successfully

Quoted 8 lines

==== snip of build log
make -j8 CC=riscv64-unknown-linux-gnu-gcc AR=riscv64-unknown-linux-gnu-ar 'CFLAGS=-O2 -pipe' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed'
TARGET: RISCV64
CRASH: 8.0.1++

    GDB: 10.2

====

Sorry, I don't quite understand, we usually build crash tool on x86_64 for analyzing other ARCH's vmcore.

Quoted 7 lines

As README shows, we need type target=XXX for analyzing XXX arch vmcore. If we only use 'make' to build on X86_64, it is used to analyze x86_64's vmcore.

I don't think "make -j8 CC=riscv64-unknown-linux-gnu-gcc" is ok for the build. If I am wrong, please correct me. thanks

the difference is :
I'm here using native compiling approach for crash utility, which mean the host OS distro is also a riscv64 (lp64d) Linux.

# uname -a
Linux unmatch 5.18.15-gentoo-riscv64 #1 SMP Sat Jul 30 20:12:16 CST
2022 riscv64 GNU/Linux

this should also work as expected which already proved by arm64/ppc/etc..

Yixun

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#22 lore raw
Quoted 211 lines · Yixun Lan

HI Xianting:

Quoted 196 lines · Xianting Tian
Quoted 183 lines · Yixun Lan

HI Xianting

Quoted 159 lines · Xianting Tian
Quoted 158 lines · Yixun Lan

Hi Xianting

Quoted 127 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

         KERNEL: vmlinux
       DUMPFILE: vmcore
           CPUS: 1
           DATE: Fri Jul 15 10:24:25 CST 2022
         UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
          TASKS: 41
       NODENAME: buildroot
        RELEASE: 5.18.9
        VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
        MACHINE: riscv64  (unknown Mhz)
         MEMORY: 1 GB
          PANIC: "Kernel panic - not syncing: sysrq triggered crash"
            PID: 113
        COMMAND: "sh"
           TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
            CPU: 0
          STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
     flags = 0x1000,
     {
       {
         {
           lru = {
             next = 0xff6000003effbf08,
             prev = 0xff6000003effbf08
           },
           {
             __filler = 0xff6000003effbf08,
             mlock_count = 0x3effbf08
           }
         },
         mapping = 0x0,
         index = 0x0,
         private = 0x0
       },
     ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

      PGD: ffffffff810e9ff8 => 2ffff001
     P4D: 0000000000000000 => 000000002fffec01
     PUD: 00005605c2957470 => 0000000020949801
     PMD: 00007fff7f1750c0 => 0000000020947401
      PTE: 0 => 209534e7
    PAGE: 000000008254d000

     PTE     PHYSICAL  FLAGS

209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"

    #0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8
    #1 [ff20000010333cf0] panic at ffffffff806578c6
    #2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c
    #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604
    #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4
    #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8
    #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
    #7 [ff20000010333e80] ksys_write at ffffffff80152eda
    #8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

Makefile | 7 +-
README | 2 +-
configure.c | 39 +-
defs.h | 248 +++++++-
diskdump.c | 21 +-
help.c | 2 +-
lkcd_vmdump_v2_v3.h | 2 +-
netdump.c | 22 +-
ramdump.c | 2 +
riscv64.c | 1414 +++++++++++++++++++++++++++++++++++++++++++
symbols.c | 10 +
11 files changed, 1759 insertions(+), 10 deletions(-) create mode 100644 riscv64.c

Quoted 3 lines

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

     121 |         struct pt_regs       dh_regs;
         |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

      90 |         struct pt_regs       dha_regs;
         |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1 make[4]: *** [Makefile:1871: gdb] Error 2 make[3]: *** [Makefile:10072: all-gdb] Error 2 make[2]: *** [Makefile:860: all] Error 2

Quoted 6 lines
Quoted 1 line

crash build failed

It's strange, actually I didn't meet such compiling error by 'make target=RISCV64', the compiling is OK.

Do you have more details for the build?

FYI, I'm using source code of crash, commit: f37df7df8a50
I don't think it's necessary to pass 'target' variable explicitly, see the comment of Makefile

==== snip of Makefile

# target could be set on command line when invoking make. Like: make target=ARM
# otherwise target will be the same as the host
ifneq ($(target),)
CONF_TARGET_FLAG="-t$(target)"
endif
====

besides, it actually recognized the correct target successfully

Quoted 8 lines

==== snip of build log
make -j8 CC=riscv64-unknown-linux-gnu-gcc AR=riscv64-unknown-linux-gnu-ar 'CFLAGS=-O2 -pipe' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed'
TARGET: RISCV64
CRASH: 8.0.1++

     GDB: 10.2

====

Sorry, I don't quite understand, we usually build crash tool on x86_64 for analyzing other ARCH's vmcore.

Quoted 7 lines

As README shows, we need type target=XXX for analyzing XXX arch vmcore. If we only use 'make' to build on X86_64, it is used to analyze x86_64's vmcore.

I don't think "make -j8 CC=riscv64-unknown-linux-gnu-gcc" is ok for the build. If I am wrong, please correct me. thanks

the difference is :
I'm here using native compiling approach for crash utility, which mean the host OS distro is also a riscv64 (lp64d) Linux.

Quoted 5 lines
# uname -a
Linux unmatch 5.18.15-gentoo-riscv64 #1 SMP Sat Jul 30 20:12:16 CST
2022 riscv64 GNU/Linux

this should also work as expected which already proved by arm64/ppc/etc..

Thanks, seems not all ARCHs support such build.

Anyway, I will add your fix as a separate patch to be included by my patch set, and add "Co-developed-by: Yixun Lan <[email protected]>"

Quoted 3 lines

Yixun

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#23 lore raw

Hi Xianting

Quoted 218 lines · Xianting Tian
Quoted 215 lines · Yixun Lan

HI Xianting:

Quoted 196 lines · Xianting Tian
Quoted 183 lines · Yixun Lan

HI Xianting

Quoted 159 lines · Xianting Tian
Quoted 158 lines · Yixun Lan

Hi Xianting

Quoted 127 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

         KERNEL: vmlinux
       DUMPFILE: vmcore
           CPUS: 1
           DATE: Fri Jul 15 10:24:25 CST 2022
         UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
          TASKS: 41
       NODENAME: buildroot
        RELEASE: 5.18.9
        VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
        MACHINE: riscv64  (unknown Mhz)
         MEMORY: 1 GB
          PANIC: "Kernel panic - not syncing: sysrq triggered crash"
            PID: 113
        COMMAND: "sh"
           TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
            CPU: 0
          STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
     flags = 0x1000,
     {
       {
         {
           lru = {
             next = 0xff6000003effbf08,
             prev = 0xff6000003effbf08
           },
           {
             __filler = 0xff6000003effbf08,
             mlock_count = 0x3effbf08
           }
         },
         mapping = 0x0,
         index = 0x0,
         private = 0x0
       },
     ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

      PGD: ffffffff810e9ff8 => 2ffff001
     P4D: 0000000000000000 => 000000002fffec01
     PUD: 00005605c2957470 => 0000000020949801
     PMD: 00007fff7f1750c0 => 0000000020947401
      PTE: 0 => 209534e7
    PAGE: 000000008254d000

     PTE     PHYSICAL  FLAGS

209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"

    #0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8
    #1 [ff20000010333cf0] panic at ffffffff806578c6
    #2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c
    #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604
    #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4
    #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8
    #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
    #7 [ff20000010333e80] ksys_write at ffffffff80152eda
    #8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

Makefile | 7 +-
README | 2 +-
configure.c | 39 +-
defs.h | 248 +++++++-
diskdump.c | 21 +-
help.c | 2 +-
lkcd_vmdump_v2_v3.h | 2 +-
netdump.c | 22 +-
ramdump.c | 2 +
riscv64.c | 1414 +++++++++++++++++++++++++++++++++++++++++++
symbols.c | 10 +
11 files changed, 1759 insertions(+), 10 deletions(-) create mode 100644 riscv64.c

Quoted 3 lines

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

     121 |         struct pt_regs       dh_regs;
         |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

      90 |         struct pt_regs       dha_regs;
         |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1 make[4]: *** [Makefile:1871: gdb] Error 2 make[3]: *** [Makefile:10072: all-gdb] Error 2 make[2]: *** [Makefile:860: all] Error 2

Quoted 6 lines
Quoted 1 line

crash build failed

It's strange, actually I didn't meet such compiling error by 'make target=RISCV64', the compiling is OK.

Do you have more details for the build?

FYI, I'm using source code of crash, commit: f37df7df8a50
I don't think it's necessary to pass 'target' variable explicitly, see the comment of Makefile

==== snip of Makefile

# target could be set on command line when invoking make. Like: make target=ARM
# otherwise target will be the same as the host
ifneq ($(target),)
CONF_TARGET_FLAG="-t$(target)"
endif
====

besides, it actually recognized the correct target successfully

Quoted 8 lines

==== snip of build log
make -j8 CC=riscv64-unknown-linux-gnu-gcc AR=riscv64-unknown-linux-gnu-ar 'CFLAGS=-O2 -pipe' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed'
TARGET: RISCV64
CRASH: 8.0.1++

     GDB: 10.2

====

Sorry, I don't quite understand, we usually build crash tool on x86_64 for analyzing other ARCH's vmcore.

Quoted 7 lines

As README shows, we need type target=XXX for analyzing XXX arch vmcore. If we only use 'make' to build on X86_64, it is used to analyze x86_64's vmcore.

I don't think "make -j8 CC=riscv64-unknown-linux-gnu-gcc" is ok for the build. If I am wrong, please correct me. thanks

the difference is :
I'm here using native compiling approach for crash utility, which mean the host OS distro is also a riscv64 (lp64d) Linux.

# uname -a
Linux unmatch 5.18.15-gentoo-riscv64 #1 SMP Sat Jul 30 20:12:16 CST
2022 riscv64 GNU/Linux
Quoted 7 lines
Quoted 1 line

this should also work as expected which already proved by arm64/ppc/etc..

Thanks, seems not all ARCHs support such build.

Anyway, I will add your fix as a separate patch to be included by my patch set, and add "Co-developed-by: Yixun Lan <[email protected]>"

hey, I think it's not quite an independent patch, so I'm totally fine with it folding into other patches,
and since it's trivial, I don't mind dropping the "Co-developed-by" tag, instead if you like, you can add my "Tested-by" tag

thanks

Yixun

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#24 lore raw
Quoted 223 lines · Yixun Lan

Hi Xianting

Quoted 219 lines · Xianting Tian
Quoted 210 lines · Yixun Lan

HI Xianting:

Quoted 195 lines · Xianting Tian
Quoted 183 lines · Yixun Lan

HI Xianting

Quoted 159 lines · Xianting Tian
Quoted 158 lines · Yixun Lan

Hi Xianting

Quoted 127 lines · Xianting Tian

This series of patches are for Crash-utility tool, it make crash tool support RISCV64 arch and the common commands(*, bt, p, rd, mod, log, set, struct, task, dis and so on).

To make the crash tool work normally for RISCV64 arch, we need a Linux kernel patch(under reviewing), which exports the kernel virtual memory layout, va_bits, phys_ram_base to vmcoreinfo, it can simplify the development of crash tool.

The Linux kernel patches:
https://lore.kernel.org/linux-riscv/[email protected]/

This series of patches are tested on QEMU RISCV64 env and SoC platform of T-head Xuantie 910 CPU.

====================================
Some test examples list as below
====================================
... ...

          KERNEL: vmlinux
        DUMPFILE: vmcore
            CPUS: 1
            DATE: Fri Jul 15 10:24:25 CST 2022
          UPTIME: 00:00:33
LOAD AVERAGE: 0.05, 0.01, 0.00
           TASKS: 41
        NODENAME: buildroot
         RELEASE: 5.18.9
         VERSION: #30 SMP Fri Jul 15 09:47:03 CST 2022
         MACHINE: riscv64  (unknown Mhz)
          MEMORY: 1 GB
           PANIC: "Kernel panic - not syncing: sysrq triggered crash"
             PID: 113
         COMMAND: "sh"
            TASK: ff60000002269600  [THREAD_INFO: ff60000002269600]
             CPU: 0
           STATE: TASK_RUNNING (PANIC)

carsh>

crash> p mem_map
mem_map = $1 = (struct page *) 0xff6000003effbf00

crash> p /x *(struct page *) 0xff6000003effbf00

$5 = {
      flags = 0x1000,
      {
        {
          {
            lru = {
              next = 0xff6000003effbf08,
              prev = 0xff6000003effbf08
            },
            {
              __filler = 0xff6000003effbf08,
              mlock_count = 0x3effbf08
            }
          },
          mapping = 0x0,
          index = 0x0,
          private = 0x0
        },
      ... ...

crash> mod
MODULE NAME BASE SIZE OBJECT FILE

ffffffff0113e740  nvme_core  ffffffff01133000  98304  (not loaded)  [CONFIG_KALLSYMS]
ffffffff011542c0  nvme       ffffffff0114c000  61440  (not loaded)  [CONFIG_KALLSYMS]

crash> rd ffffffff0113e740 8

ffffffff0113e740:  0000000000000000 ffffffff810874f8   .........t......
ffffffff0113e750:  ffffffff011542c8 726f635f656d766e   .B......nvme_cor
ffffffff0113e760:  0000000000000065 0000000000000000   e...............
ffffffff0113e770:  0000000000000000 0000000000000000   ................

crash> vtop ffffffff0113e740
VIRTUAL PHYSICAL
ffffffff0113e740 8254d740

       PGD: ffffffff810e9ff8 => 2ffff001
      P4D: 0000000000000000 => 000000002fffec01
      PUD: 00005605c2957470 => 0000000020949801
      PMD: 00007fff7f1750c0 => 0000000020947401
       PTE: 0 => 209534e7
     PAGE: 000000008254d000

      PTE     PHYSICAL  FLAGS

209534e7 8254d000 (PRESENT|READ|WRITE|GLOBAL|ACCESSED|DIRTY)

PAGE PHYSICAL MAPPING INDEX CNT FLAGS
ff6000003f0777d8 8254d000 0 0 1 0

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"

     #0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8
     #1 [ff20000010333cf0] panic at ffffffff806578c6
     #2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c
     #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604
     #4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4
     #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8
     #6 [ff20000010333e40] vfs_write at ffffffff80152bb2
     #7 [ff20000010333e80] ksys_write at ffffffff80152eda
     #8 [ff20000010333ed0] sys_write at ffffffff80152f52

Xianting Tian (8):
Add RISCV64 framework code support
RISCV64: Make crash tool enter command line and support some commands
RISCV64: Add 'dis' command support
RISCV64: Add 'irq' command support
RISCV64: Add 'bt' command support
RISCV64: Add 'help -r' command support
RISCV64: Add 'mach' command support
RISCV64: Add the implementation of symbol verify

Makefile | 7 +-
README | 2 +-
configure.c | 39 +-
defs.h | 248 +++++++-
diskdump.c | 21 +-
help.c | 2 +-
lkcd_vmdump_v2_v3.h | 2 +-
netdump.c | 22 +-
ramdump.c | 2 +
riscv64.c | 1414 +++++++++++++++++++++++++++++++++++++++++++
symbols.c | 10 +
11 files changed, 1759 insertions(+), 10 deletions(-) create mode 100644 riscv64.c

Quoted 3 lines

--
2.17.1

I'm actually having problem with these patch set, got a compiling error:

=== error log ===
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_common.c
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v1.c -DMCLX
riscv64-unknown-linux-gnu-gcc -c -g -DRISCV64 -DGDB_10_2 -O2 -pipe lkcd_v2_v3.c -DMCLX
In file included from lkcd_v1.c:21:
lkcd_vmdump_v1.h:121:30: error: field ‘dh_regs’ has incomplete type

      121 |         struct pt_regs       dh_regs;
          |                              ^~~~~~~

make[5]: *** [Makefile:385: lkcd_v1.o] Error 1
make[5]: *** Waiting for unfinished jobs....
In file included from lkcd_v2_v3.c:21:
lkcd_vmdump_v2_v3.h:90:30: error: field ‘dha_regs’ has incomplete type

       90 |         struct pt_regs       dha_regs;
          |                              ^~~~~~~~

make[5]: *** [Makefile:388: lkcd_v2_v3.o] Error 1 make[4]: *** [Makefile:1871: gdb] Error 2 make[3]: *** [Makefile:10072: all-gdb] Error 2 make[2]: *** [Makefile:860: all] Error 2

Quoted 6 lines
Quoted 1 line

crash build failed

It's strange, actually I didn't meet such compiling error by 'make target=RISCV64', the compiling is OK.

Do you have more details for the build?

FYI, I'm using source code of crash, commit: f37df7df8a50
I don't think it's necessary to pass 'target' variable explicitly, see the comment of Makefile

==== snip of Makefile

# target could be set on command line when invoking make. Like: make target=ARM
# otherwise target will be the same as the host
ifneq ($(target),)
CONF_TARGET_FLAG="-t$(target)"
endif
====

besides, it actually recognized the correct target successfully

Quoted 8 lines

==== snip of build log
make -j8 CC=riscv64-unknown-linux-gnu-gcc AR=riscv64-unknown-linux-gnu-ar 'CFLAGS=-O2 -pipe' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed'
TARGET: RISCV64

    CRASH: 8.0.1++
      GDB: 10.2

====

Sorry, I don't quite understand, we usually build crash tool on x86_64 for analyzing other ARCH's vmcore.

Quoted 7 lines

As README shows, we need type target=XXX for analyzing XXX arch vmcore. If we only use 'make' to build on X86_64, it is used to analyze x86_64's vmcore.

I don't think "make -j8 CC=riscv64-unknown-linux-gnu-gcc" is ok for the build. If I am wrong, please correct me. thanks

the difference is :
I'm here using native compiling approach for crash utility, which mean the host OS distro is also a riscv64 (lp64d) Linux.

Quoted 5 lines
# uname -a
Linux unmatch 5.18.15-gentoo-riscv64 #1 SMP Sat Jul 30 20:12:16 CST
2022 riscv64 GNU/Linux

this should also work as expected which already proved by arm64/ppc/etc..

Thanks, seems not all ARCHs support such build.

Quoted 7 lines
Quoted 3 lines

Anyway, I will add your fix as a separate patch to be included by my patch set, and add "Co-developed-by: Yixun Lan <[email protected]>"

hey, I think it's not quite an independent patch, so I'm totally fine with it folding into other patches,
and since it's trivial, I don't mind dropping the "Co-developed-by" tag, instead if you like, you can add my "Tested-by" tag

It is OK, V2 patch set has sent, you can check it.

Quoted 4 lines

thanks

Yixun

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv