mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-10 13:19:31 +00:00
shell: refine shell function with copy_from_gva
using copy_from_gva for shell function shell_vcpu_dumpreg & shell_vcpu_dumpmem Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
@@ -637,6 +637,7 @@ int shell_resume_vcpu(struct shell *p_shell,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DUMPREG_SP_SIZE 32
|
||||||
int shell_vcpu_dumpreg(struct shell *p_shell,
|
int shell_vcpu_dumpreg(struct shell *p_shell,
|
||||||
int argc, char **argv)
|
int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -645,10 +646,10 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
|
|||||||
char temp_str[MAX_STR_SIZE];
|
char temp_str[MAX_STR_SIZE];
|
||||||
struct vm *vm;
|
struct vm *vm;
|
||||||
struct vcpu *vcpu;
|
struct vcpu *vcpu;
|
||||||
uint64_t gpa, hpa, i;
|
uint64_t i;
|
||||||
uint64_t *tmp;
|
uint64_t tmp[DUMPREG_SP_SIZE];
|
||||||
struct run_context *cur_context;
|
struct run_context *cur_context;
|
||||||
uint32_t err_code;
|
uint32_t err_code = 0;
|
||||||
|
|
||||||
/* User input invalidation */
|
/* User input invalidation */
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
@@ -725,19 +726,18 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
|
|||||||
shell_puts(p_shell, temp_str);
|
shell_puts(p_shell, temp_str);
|
||||||
|
|
||||||
/* dump sp */
|
/* dump sp */
|
||||||
status = gva2gpa(vcpu, cur_context->rsp, &gpa, &err_code);
|
status = copy_from_gva(vcpu, tmp, cur_context->rsp,
|
||||||
if (status) {
|
DUMPREG_SP_SIZE*sizeof(uint64_t), &err_code);
|
||||||
|
if (status < 0) {
|
||||||
|
/* copy_from_gva fail */
|
||||||
shell_puts(p_shell, "Cannot handle user gva yet!\r\n");
|
shell_puts(p_shell, "Cannot handle user gva yet!\r\n");
|
||||||
} else {
|
} else {
|
||||||
hpa = gpa2hpa(vm, gpa);
|
|
||||||
snprintf(temp_str, MAX_STR_SIZE,
|
snprintf(temp_str, MAX_STR_SIZE,
|
||||||
"\r\nDump RSP for vm %d, from "
|
"\r\nDump RSP for vm %d, from "
|
||||||
"gva 0x%016llx -> gpa 0x%016llx"
|
"gva 0x%016llx\r\n",
|
||||||
" -> hpa 0x%016llx:\r\n",
|
vm_id, cur_context->rsp);
|
||||||
vm_id, cur_context->rsp,gpa, hpa);
|
|
||||||
shell_puts(p_shell, temp_str);
|
shell_puts(p_shell, temp_str);
|
||||||
|
|
||||||
tmp = HPA2HVA(hpa);
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
snprintf(temp_str, MAX_STR_SIZE,
|
snprintf(temp_str, MAX_STR_SIZE,
|
||||||
"= 0x%016llx 0x%016llx "
|
"= 0x%016llx 0x%016llx "
|
||||||
@@ -751,18 +751,19 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_MEMDUMP_LEN (32*8)
|
||||||
int shell_vcpu_dumpmem(struct shell *p_shell,
|
int shell_vcpu_dumpmem(struct shell *p_shell,
|
||||||
int argc, char **argv)
|
int argc, char **argv)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
uint32_t vm_id, vcpu_id;
|
uint32_t vm_id, vcpu_id;
|
||||||
uint64_t gva, gpa, hpa;
|
uint64_t gva;
|
||||||
uint64_t *tmp;
|
uint64_t tmp[MAX_MEMDUMP_LEN/8];
|
||||||
uint32_t i, length = 32;
|
uint32_t i, length = 32;
|
||||||
char temp_str[MAX_STR_SIZE];
|
char temp_str[MAX_STR_SIZE];
|
||||||
struct vm *vm;
|
struct vm *vm;
|
||||||
struct vcpu *vcpu;
|
struct vcpu *vcpu;
|
||||||
uint32_t err_code;
|
uint32_t err_code = 0;
|
||||||
|
|
||||||
/* User input invalidation */
|
/* User input invalidation */
|
||||||
if (argc != 4 && argc != 5) {
|
if (argc != 4 && argc != 5) {
|
||||||
@@ -789,21 +790,23 @@ int shell_vcpu_dumpmem(struct shell *p_shell,
|
|||||||
if (argc == 5)
|
if (argc == 5)
|
||||||
length = atoi(argv[4]);
|
length = atoi(argv[4]);
|
||||||
|
|
||||||
|
if (length > MAX_MEMDUMP_LEN) {
|
||||||
|
shell_puts(p_shell, "over max length, round back\r\n");
|
||||||
|
length = MAX_MEMDUMP_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
vcpu = vcpu_from_vid(vm, (long)vcpu_id);
|
vcpu = vcpu_from_vid(vm, (long)vcpu_id);
|
||||||
if (vcpu) {
|
if (vcpu) {
|
||||||
status = gva2gpa(vcpu, gva, &gpa, &err_code);
|
status = copy_from_gva(vcpu, tmp, gva, length, &err_code);
|
||||||
if (status) {
|
if (status < 0) {
|
||||||
shell_puts(p_shell,
|
shell_puts(p_shell,
|
||||||
"Cannot handle user gva yet!\r\n");
|
"Cannot handle user gva yet!\r\n");
|
||||||
} else {
|
} else {
|
||||||
hpa = gpa2hpa(vcpu->vm, gpa);
|
|
||||||
snprintf(temp_str, MAX_STR_SIZE,
|
snprintf(temp_str, MAX_STR_SIZE,
|
||||||
"Dump memory for vcpu %d, from gva 0x%016llx ->"
|
"Dump memory for vcpu %d, from gva 0x%016llx, "
|
||||||
"gpa 0x%016llx -> hpa 0x%016llx, length "
|
"length %d:\r\n", vcpu_id, gva, length);
|
||||||
"%d:\r\n", vcpu_id, gva, gpa, hpa, length);
|
|
||||||
shell_puts(p_shell, temp_str);
|
shell_puts(p_shell, temp_str);
|
||||||
|
|
||||||
tmp = HPA2HVA(hpa);
|
|
||||||
for (i = 0; i < length/32; i++) {
|
for (i = 0; i < length/32; i++) {
|
||||||
snprintf(temp_str, MAX_STR_SIZE,
|
snprintf(temp_str, MAX_STR_SIZE,
|
||||||
"= 0x%016llx 0x%016llx 0x%016llx "
|
"= 0x%016llx 0x%016llx 0x%016llx "
|
||||||
|
@@ -78,7 +78,7 @@ struct shell_cmd {
|
|||||||
#define SHELL_CMD_VCPU_DUMPREG_HELP "Dump registers for a specific vcpu"
|
#define SHELL_CMD_VCPU_DUMPREG_HELP "Dump registers for a specific vcpu"
|
||||||
|
|
||||||
#define SHELL_CMD_VCPU_DUMPMEM "vcpu_dumpmem"
|
#define SHELL_CMD_VCPU_DUMPMEM "vcpu_dumpmem"
|
||||||
#define SHELL_CMD_VCPU_DUMPMEM_PARAM "<vcpu id, gva, length>"
|
#define SHELL_CMD_VCPU_DUMPMEM_PARAM "<vm_id, vcpu id, gva, length>"
|
||||||
#define SHELL_CMD_VCPU_DUMPMEM_HELP "Dump memory for a specific vcpu"
|
#define SHELL_CMD_VCPU_DUMPMEM_HELP "Dump memory for a specific vcpu"
|
||||||
|
|
||||||
#define SHELL_CMD_VM_CONSOLE "vm_console"
|
#define SHELL_CMD_VM_CONSOLE "vm_console"
|
||||||
|
Reference in New Issue
Block a user