HV: fix bug "vmexit" cmd cause HV console hung

on KBL-NUC when input "vmexit" in hypervisor console,
the console or HV/SOS could be hung, the root cause is:
the log buffer is overflow for 8 CPU cores info.

to resolve the issue:
1. increase the shell log buffer size according to the
physical CPU max number
2. check the snprintf return value, if no buffer left,
just return.

Tracked-On: #1587
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Minggui Cao 2018-10-31 11:38:07 +08:00 committed by lijinxia
parent 0255e62798
commit b048835c45
3 changed files with 31 additions and 12 deletions

View File

@ -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 */

View File

@ -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;

View File

@ -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)