All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: zhenwei pi <pizhenwei@bytedance.com>,
	pbonzini@redhat.com, peter.maydell@linaro.org
Cc: mtosatti@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 3/3] target-i386: post memory failure event to uplayer
Date: Tue, 22 Sep 2020 12:30:49 +0200	[thread overview]
Message-ID: <776b6afe-022e-f304-4bc9-f1f486d75af2@redhat.com> (raw)
In-Reply-To: <20200922095630.394893-4-pizhenwei@bytedance.com>

On 9/22/20 11:56 AM, zhenwei pi wrote:
> Post memory failure event to uplayer to handle hardware memory
> corrupted event. Rather than simple QEMU log, QEMU could report more
> effective message to uplayer. For example, guest crashes by MCE,
> selecting another host server is a better choice.
> 
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> ---
>  target/i386/helper.c | 15 +++++++++++++++
>  target/i386/kvm.c    |  7 ++++++-
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/target/i386/helper.c b/target/i386/helper.c
> index 0c7fd32491..47823c29e4 100644
> --- a/target/i386/helper.c
> +++ b/target/i386/helper.c
> @@ -18,6 +18,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qapi/qapi-events-run-state.h"
>  #include "cpu.h"
>  #include "exec/exec-all.h"
>  #include "qemu/qemu-print.h"
> @@ -858,6 +859,7 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>      CPUX86State *cenv = &cpu->env;
>      uint64_t *banks = cenv->mce_banks + 4 * params->bank;
>      char msg[64];
> +    MemoryFailureFlags mf_flags = {0};
>      bool need_reset = false;
>  
>      cpu_synchronize_state(cs);
> @@ -869,6 +871,12 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>      if (!(params->flags & MCE_INJECT_UNCOND_AO)
>          && !(params->status & MCI_STATUS_AR)
>          && (cenv->mcg_status & MCG_STATUS_MCIP)) {
> +        mf_flags.has_action_required = true;
> +        mf_flags.action_required = false;
> +        mf_flags.has_recursive = true;
> +        mf_flags.recursive = true;
> +        qapi_event_send_memory_failure(MEMORY_FAILURE_ACTION_GUEST_MCE_INJECT,
> +                                       true, &mf_flags);

Can you extract a function such:

static void emit_guest_mce_failure(bool action_required, bool recursive)
{
  ...
}

To use as:

           emit_guest_mce_failure(true, true);

>          return;
>      }
>  
> @@ -909,6 +917,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>          }
>  
>          if (need_reset) {
> +            qapi_event_send_memory_failure(
> +                 MEMORY_FAILURE_ACTION_GUEST_MCE_FATAL, false, NULL);
>              monitor_printf(params->mon, "%s", msg);
>              qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
>              qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
> @@ -934,6 +944,11 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>      } else {
>          banks[1] |= MCI_STATUS_OVER;
>      }
> +
> +    mf_flags.has_action_required = true;
> +    mf_flags.action_required = !!(params->status & MCI_STATUS_AR);
> +    qapi_event_send_memory_failure(MEMORY_FAILURE_ACTION_GUEST_MCE_INJECT,
> +                                   true, &mf_flags);

And here:

       emit_guest_mce_failure(params->status & MCI_STATUS_AR, false);

>  }
>  
>  void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 9efb07e7c8..989889c291 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -14,6 +14,7 @@
>  
>  #include "qemu/osdep.h"
>  #include "qapi/error.h"
> +#include "qapi/qapi-events-run-state.h"
>  #include <sys/ioctl.h>
>  #include <sys/utsname.h>
>  
> @@ -577,6 +578,8 @@ static void kvm_mce_inject(X86CPU *cpu, hwaddr paddr, int code)
>  
>  static void hardware_memory_error(void *host_addr)
>  {
> +    qapi_event_send_memory_failure(MEMORY_FAILURE_ACTION_HYPERVISOR_FATAL,
> +                                   false, NULL);
>      error_report("QEMU got Hardware memory error at addr %p", host_addr);
>      exit(1);
>  }
> @@ -631,7 +634,9 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)
>          hardware_memory_error(addr);
>      }
>  
> -    /* Hope we are lucky for AO MCE */
> +    /* Hope we are lucky for AO MCE, just notify a event */
> +    qapi_event_send_memory_failure(MEMORY_FAILURE_ACTION_HYPERVISOR_IGNORE,
> +                                   false, NULL);
>  }
>  
>  static void kvm_reset_exception(CPUX86State *env)
> 



  reply	other threads:[~2020-09-22 10:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  9:56 [PATCH v2 0/3] add MEMORY_FAILURE event zhenwei pi
2020-09-22  9:56 ` [PATCH v2 1/3] target-i386: seperate MCIP & MCE_MASK error reason zhenwei pi
2020-09-22 10:23   ` Philippe Mathieu-Daudé
2020-09-22  9:56 ` [PATCH v2 2/3] qapi/run-state.json: introduce memory failure event zhenwei pi
2020-09-22  9:56 ` [PATCH v2 3/3] target-i386: post memory failure event to uplayer zhenwei pi
2020-09-22 10:30   ` Philippe Mathieu-Daudé [this message]
2020-09-23  3:12     ` [External] " zhenwei pi
2020-09-22 15:40 ` [PATCH v2 0/3] add MEMORY_FAILURE event no-reply
2020-09-28 12:01 ` PING: " zhenwei pi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=776b6afe-022e-f304-4bc9-f1f486d75af2@redhat.com \
    --to=philmd@redhat.com \
    --cc=armbru@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=pizhenwei@bytedance.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.