diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c index 4d6ee72d6..b523260a8 100644 --- a/hypervisor/common/hv_main.c +++ b/hypervisor/common/hv_main.c @@ -123,33 +123,51 @@ void get_vmexit_profile(char *str_arg, size_t str_max) uint16_t cpu, i; size_t len, size = str_max; - len = snprintf(str, size, "\r\nNow(us) = %16lld\r\n", - ticks_to_us(rdtsc())); + len = snprintf(str, size, "\r\nNow(us) = %16lld\r\n", ticks_to_us(rdtsc())); + if (len >= size) { + goto overflow; + } size -= len; str += len; len = snprintf(str, size, "\r\nREASON"); + if (len >= size) { + goto overflow; + } size -= len; str += len; for (cpu = 0U; cpu < phys_cpu_num; cpu++) { len = snprintf(str, size, "\t CPU%hu\t US", cpu); + if (len >= size) { + goto overflow; + } size -= len; str += len; } for (i = 0U; i < 64U; i++) { len = snprintf(str, size, "\r\n0x%x", i); + if (len >= size) { + goto overflow; + } size -= len; str += len; for (cpu = 0U; cpu < phys_cpu_num; cpu++) { - len = snprintf(str, size, "\t%10lld\t%10lld", - per_cpu(vmexit_cnt, cpu)[i], + len = snprintf(str, size, "\t%10lld\t%10lld", per_cpu(vmexit_cnt, cpu)[i], ticks_to_us(per_cpu(vmexit_time, cpu)[i])); + if (len >= size) { + goto overflow; + } + size -= len; str += len; } } snprintf(str, size, "\r\n"); + return; + +overflow: + printf("buffer size could not be enough! please check!\n"); } #endif /* HV_DEBUG */ diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index 2606d2abf..df2a9250e 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -11,7 +11,8 @@ #define MAX_STR_SIZE 256U #define SHELL_PROMPT_STR "ACRN:\\>" -char shell_log_buf[CPU_PAGE_SIZE*2]; +#define SHELL_LOG_BUF_SIZE (CPU_PAGE_SIZE * CONFIG_MAX_PCPU_NUM / 2U) +static char shell_log_buf[SHELL_LOG_BUF_SIZE]; /* Input Line Other - Switch to the "other" input line (there are only two * input lines total). @@ -657,7 +658,7 @@ static int shell_vcpu_dumpreg(int argc, char **argv) vcpu = vcpu_from_vid(vm, vcpu_id); dump.vcpu = vcpu; dump.str = shell_log_buf; - dump.str_max = CPU_PAGE_SIZE; + dump.str_max = SHELL_LOG_BUF_SIZE; if (vcpu->pcpu_id == get_cpu_id()) { vcpu_dumpreg(&dump); } else { @@ -764,14 +765,14 @@ static int shell_to_sos_console(__unused int argc, __unused char **argv) static int shell_show_cpu_int(__unused int argc, __unused char **argv) { - get_cpu_interrupt_info(shell_log_buf, CPU_PAGE_SIZE); + get_cpu_interrupt_info(shell_log_buf, SHELL_LOG_BUF_SIZE); shell_puts(shell_log_buf); return 0; } static int shell_show_ptdev_info(__unused int argc, __unused char **argv) { - get_ptdev_info(shell_log_buf, CPU_PAGE_SIZE); + get_ptdev_info(shell_log_buf, SHELL_LOG_BUF_SIZE); shell_puts(shell_log_buf); return 0; @@ -789,7 +790,7 @@ static int shell_show_vioapic_info(int argc, char **argv) ret = atoi(argv[1]); if (ret >= 0) { vmid = (uint16_t) ret; - get_vioapic_info(shell_log_buf, CPU_PAGE_SIZE, vmid); + get_vioapic_info(shell_log_buf, SHELL_LOG_BUF_SIZE, vmid); shell_puts(shell_log_buf); return 0; } @@ -801,7 +802,7 @@ static int shell_show_ioapic_info(__unused int argc, __unused char **argv) { int err = 0; - err = get_ioapic_info(shell_log_buf, 2 * CPU_PAGE_SIZE); + err = get_ioapic_info(shell_log_buf, SHELL_LOG_BUF_SIZE); shell_puts(shell_log_buf); return err; @@ -809,7 +810,7 @@ static int shell_show_ioapic_info(__unused int argc, __unused char **argv) static int shell_show_vmexit_profile(__unused int argc, __unused char **argv) { - get_vmexit_profile(shell_log_buf, 2*CPU_PAGE_SIZE); + get_vmexit_profile(shell_log_buf, SHELL_LOG_BUF_SIZE); shell_puts(shell_log_buf); return 0; diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index a52df9ccf..868d884d5 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -245,7 +245,7 @@ struct vcpu { struct vcpu_dump { struct vcpu *vcpu; char *str; - int str_max; + uint32_t str_max; }; static inline bool is_vcpu_bsp(const struct vcpu *vcpu)