From 8615271e4578ec32cd688dbedc3f81d9f08f1475 Mon Sep 17 00:00:00 2001 From: hangliu1 Date: Wed, 15 Oct 2025 16:52:45 +0800 Subject: [PATCH] hv: multiarch: move shell_dump_host_mem to common move shell_dump_host_mem in x86 to common shell.c for riscv, hypervisor only maps mmio and hv memory, beyond the above range memroy dump wil cause exception. Tracked-On: #8831 Signed-off-by: hangliu1 Reviewed-by: Fei Li Acked-by: Wang, Yu1 --- hypervisor/debug/shell.c | 38 +++++++++++++++++++++++++++++ hypervisor/debug/shell_priv.h | 4 ++++ hypervisor/debug/x86/x86_shell.c | 41 -------------------------------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index 64fd347f0..86f0c14f1 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -29,6 +29,7 @@ extern uint32_t arch_shell_cmds_sz; static int32_t shell_cmd_help(__unused int32_t argc, __unused char **argv); static int32_t shell_version(__unused int32_t argc, __unused char **argv); static int32_t shell_loglevel(int32_t argc, char **argv); +static int32_t shell_dump_host_mem(int32_t argc, char **argv); static struct shell_cmd shell_cmds[] = { { @@ -49,6 +50,13 @@ static struct shell_cmd shell_cmds[] = { .help_str = SHELL_CMD_LOG_LVL_HELP, .fcn = shell_loglevel, }, + { + .str = SHELL_CMD_DUMP_HOST_MEM, + .cmd_param = SHELL_CMD_DUMP_HOST_MEM_PARAM, + .help_str = SHELL_CMD_DUMP_HOST_MEM_HELP, + .fcn = shell_dump_host_mem, + }, + }; /* for function key: up/down/right/left/home/end and delete key */ @@ -665,3 +673,33 @@ static int32_t shell_loglevel(int32_t argc, char **argv) return 0; } + +static int32_t shell_dump_host_mem(int32_t argc, char **argv) +{ + uint64_t *hva; + int32_t ret; + uint32_t i, length, loop_cnt; + char temp_str[MAX_STR_SIZE]; + + /* User input invalidation */ + if (argc != 3) { + ret = -EINVAL; + } else { + hva = (uint64_t *)strtoul_hex(argv[1]); + length = (uint32_t)strtol_deci(argv[2]); + + snprintf(temp_str, MAX_STR_SIZE, "Dump physical memory addr: 0x%016lx, length %d:\r\n", hva, length); + shell_puts(temp_str); + /* Change the length to a multiple of 32 if the length is not */ + loop_cnt = ((length & 0x1fU) == 0U) ? ((length >> 5U)) : ((length >> 5U) + 1U); + for (i = 0U; i < loop_cnt; i++) { + snprintf(temp_str, MAX_STR_SIZE, "HVA(0x%llx): 0x%016lx 0x%016lx 0x%016lx 0x%016lx\r\n", + hva, *hva, *(hva + 1UL), *(hva + 2UL), *(hva + 3UL)); + hva += 4UL; + shell_puts(temp_str); + } + ret = 0; + } + + return ret; +} diff --git a/hypervisor/debug/shell_priv.h b/hypervisor/debug/shell_priv.h index 2efc360b1..5dfcd29a0 100644 --- a/hypervisor/debug/shell_priv.h +++ b/hypervisor/debug/shell_priv.h @@ -66,6 +66,10 @@ struct shell { #define SHELL_CMD_LOG_LVL_HELP "No argument: get the level of logging for the console, memory and npk. Set "\ "the level by giving (up to) 3 parameters between 0 and 6 (verbose)" +#define SHELL_CMD_DUMP_HOST_MEM "dump_host_mem" +#define SHELL_CMD_DUMP_HOST_MEM_PARAM "" +#define SHELL_CMD_DUMP_HOST_MEM_HELP "Dump host memory, starting at a given address(Hex), and for a given length (Dec in bytes)" + void shell_puts(const char *string_ptr); #endif /* SHELL_PRIV_H */ diff --git a/hypervisor/debug/x86/x86_shell.c b/hypervisor/debug/x86/x86_shell.c index 6db297f11..f06bbb9e1 100644 --- a/hypervisor/debug/x86/x86_shell.c +++ b/hypervisor/debug/x86/x86_shell.c @@ -36,10 +36,6 @@ #define SHELL_CMD_VCPU_DUMPREG_PARAM "" #define SHELL_CMD_VCPU_DUMPREG_HELP "Dump registers for a specific vCPU" -#define SHELL_CMD_DUMP_HOST_MEM "dump_host_mem" -#define SHELL_CMD_DUMP_HOST_MEM_PARAM "" -#define SHELL_CMD_DUMP_HOST_MEM_HELP "Dump host memory, starting at a given address(Hex), and for a given length (Dec in bytes)" - #define SHELL_CMD_DUMP_GUEST_MEM "dump_guest_mem" #define SHELL_CMD_DUMP_GUEST_MEM_PARAM "" #define SHELL_CMD_DUMP_GUEST_MEM_HELP "Dump guest memory, vm id(Dec), starting at a given address(Hex), and for a given length (Dec in bytes)" @@ -88,7 +84,6 @@ static int32_t shell_list_vm(__unused int32_t argc, __unused char **argv); static int32_t shell_list_vcpu(__unused int32_t argc, __unused char **argv); static int32_t shell_vcpu_dumpreg(int32_t argc, char **argv); -static int32_t shell_dump_host_mem(int32_t argc, char **argv); static int32_t shell_dump_guest_mem(int32_t argc, char **argv); static int32_t shell_to_vm_console(int32_t argc, char **argv); static int32_t shell_show_cpu_int(__unused int32_t argc, __unused char **argv); @@ -119,12 +114,6 @@ struct shell_cmd arch_shell_cmds[] = { .help_str = SHELL_CMD_VCPU_DUMPREG_HELP, .fcn = shell_vcpu_dumpreg, }, - { - .str = SHELL_CMD_DUMP_HOST_MEM, - .cmd_param = SHELL_CMD_DUMP_HOST_MEM_PARAM, - .help_str = SHELL_CMD_DUMP_HOST_MEM_HELP, - .fcn = shell_dump_host_mem, - }, { .str = SHELL_CMD_DUMP_GUEST_MEM, .cmd_param = SHELL_CMD_DUMP_GUEST_MEM_PARAM, @@ -465,36 +454,6 @@ out: return status; } -static int32_t shell_dump_host_mem(int32_t argc, char **argv) -{ - uint64_t *hva; - int32_t ret; - uint32_t i, length, loop_cnt; - char temp_str[MAX_STR_SIZE]; - - /* User input invalidation */ - if (argc != 3) { - ret = -EINVAL; - } else { - hva = (uint64_t *)strtoul_hex(argv[1]); - length = (uint32_t)strtol_deci(argv[2]); - - snprintf(temp_str, MAX_STR_SIZE, "Dump physical memory addr: 0x%016lx, length %d:\r\n", hva, length); - shell_puts(temp_str); - /* Change the length to a multiple of 32 if the length is not */ - loop_cnt = ((length & 0x1fU) == 0U) ? ((length >> 5U)) : ((length >> 5U) + 1U); - for (i = 0U; i < loop_cnt; i++) { - snprintf(temp_str, MAX_STR_SIZE, "HVA(0x%llx): 0x%016lx 0x%016lx 0x%016lx 0x%016lx\r\n", - hva, *hva, *(hva + 1UL), *(hva + 2UL), *(hva + 3UL)); - hva += 4UL; - shell_puts(temp_str); - } - ret = 0; - } - - return ret; -} - static void dump_guest_mem(void *data) { uint64_t i, fault_addr;