diff mbox series

[v2,1/3] target-i386: seperate MCIP & MCE_MASK error reason

Message ID 20200922095630.394893-2-pizhenwei@bytedance.com (mailing list archive)
State New, archived
Headers show
Series add MEMORY_FAILURE event | expand

Commit Message

zhenwei pi Sept. 22, 2020, 9:56 a.m. UTC
Previously we can only get a simple string "Triple fault" in qemu
log. Add detailed message for the two reasons to describe why qemu
has to reset the guest.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 target/i386/helper.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

Comments

Philippe Mathieu-Daudé Sept. 22, 2020, 10:23 a.m. UTC | #1
On 9/22/20 11:56 AM, zhenwei pi wrote:
> Previously we can only get a simple string "Triple fault" in qemu
> log. Add detailed message for the two reasons to describe why qemu
> has to reset the guest.
> 
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> ---
>  target/i386/helper.c | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/target/i386/helper.c b/target/i386/helper.c
> index 70be53e2c3..0c7fd32491 100644
> --- a/target/i386/helper.c
> +++ b/target/i386/helper.c
> @@ -857,6 +857,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>      X86CPU *cpu = X86_CPU(cs);
>      CPUX86State *cenv = &cpu->env;
>      uint64_t *banks = cenv->mce_banks + 4 * params->bank;
> +    char msg[64];

The preferred for is now to use 'g_autofree char *msg = NULL'
here and g_strdup_printf() instead of snprintf().

> +    bool need_reset = false;
>  
>      cpu_synchronize_state(cs);
>  
> @@ -894,16 +896,25 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>              return;
>          }
>  
> -        if ((cenv->mcg_status & MCG_STATUS_MCIP) ||
> -            !(cenv->cr[4] & CR4_MCE_MASK)) {
> -            monitor_printf(params->mon,
> -                           "CPU %d: Previous MCE still in progress, raising"
> -                           " triple fault\n",
> -                           cs->cpu_index);
> -            qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
> +        if (cenv->mcg_status & MCG_STATUS_MCIP) {
> +            need_reset = true;
> +            snprintf(msg, sizeof(msg), "CPU %d: Previous MCE still in progress,"
> +                     " raising triple fault", cs->cpu_index);
> +        }
> +
> +        if (!(cenv->cr[4] & CR4_MCE_MASK)) {
> +            need_reset = true;
> +            snprintf(msg, sizeof(msg), "CPU %d: MCE capability is not enabled,"
> +                     " raising triple fault", cs->cpu_index);
> +        }
> +
> +        if (need_reset) {
> +            monitor_printf(params->mon, "%s", msg);
> +            qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
>              qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
>              return;
>          }
> +
>          if (banks[1] & MCI_STATUS_VAL) {
>              params->status |= MCI_STATUS_OVER;
>          }
>
diff mbox series

Patch

diff --git a/target/i386/helper.c b/target/i386/helper.c
index 70be53e2c3..0c7fd32491 100644
--- a/target/i386/helper.c
+++ b/target/i386/helper.c
@@ -857,6 +857,8 @@  static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
     X86CPU *cpu = X86_CPU(cs);
     CPUX86State *cenv = &cpu->env;
     uint64_t *banks = cenv->mce_banks + 4 * params->bank;
+    char msg[64];
+    bool need_reset = false;
 
     cpu_synchronize_state(cs);
 
@@ -894,16 +896,25 @@  static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
             return;
         }
 
-        if ((cenv->mcg_status & MCG_STATUS_MCIP) ||
-            !(cenv->cr[4] & CR4_MCE_MASK)) {
-            monitor_printf(params->mon,
-                           "CPU %d: Previous MCE still in progress, raising"
-                           " triple fault\n",
-                           cs->cpu_index);
-            qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
+        if (cenv->mcg_status & MCG_STATUS_MCIP) {
+            need_reset = true;
+            snprintf(msg, sizeof(msg), "CPU %d: Previous MCE still in progress,"
+                     " raising triple fault", cs->cpu_index);
+        }
+
+        if (!(cenv->cr[4] & CR4_MCE_MASK)) {
+            need_reset = true;
+            snprintf(msg, sizeof(msg), "CPU %d: MCE capability is not enabled,"
+                     " raising triple fault", cs->cpu_index);
+        }
+
+        if (need_reset) {
+            monitor_printf(params->mon, "%s", msg);
+            qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
             qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
             return;
         }
+
         if (banks[1] & MCI_STATUS_VAL) {
             params->status |= MCI_STATUS_OVER;
         }