All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [PATCH v2 04/39] target/i386: decouple cpu_x86_inject_mce() from Monitor
Date: Mon, 10 Aug 2026 18:40:08 +0100	[thread overview]
Message-ID: <anoM-GDPeNTNfFR_@redhat.com> (raw)
In-Reply-To: <20260626-qemu-no-hmp-v2-4-8af31bc54c61@redhat.com>

On Fri, Jun 26, 2026 at 01:19:05AM +0400, Marc-André Lureau wrote:
> Replace monitor_printf() error reporting with the standard **errp
> pattern. Drop the Monitor *mon parameter and return bool to indicate
> success, improving the function usage from non-HMP contexts. Update the
> KVM MCE injection path and hmp_mce() accordingly.
> 
> Notes:
>  - we may want to print the error in KVM path too
>  - multiple error prints are now accumulated with error hints
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  target/i386/cpu.h     |  4 ++--
>  target/i386/helper.c  | 49 ++++++++++++++++++++++++++++---------------------
>  target/i386/kvm/kvm.c |  4 ++--
>  target/i386/monitor.c |  6 ++++--
>  4 files changed, 36 insertions(+), 27 deletions(-)


>  typedef struct MCEInjectionParams {
> -    Monitor *mon;
> +    GString *err;

Why not have "Error **errp"

>      int bank;
>      uint64_t status;
>      uint64_t mcg_status;
> @@ -428,9 +428,9 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>           * reporting is disabled
>           */
>          if ((cenv->mcg_cap & MCG_CTL_P) && cenv->mcg_ctl != ~(uint64_t)0) {
> -            monitor_printf(params->mon,
> -                           "CPU %d: Uncorrected error reporting disabled\n",
> -                           cs->cpu_index);
> +            g_string_append_printf(params->err,
> +                "CPU %d: Uncorrected error reporting disabled\n",
> +                cs->cpu_index);

and use  error_setg here and the other two places below.

>              return;
>          }
>  
> @@ -439,10 +439,9 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>           * reporting is disabled for the bank
>           */
>          if (banks[0] != ~(uint64_t)0) {
> -            monitor_printf(params->mon,
> -                           "CPU %d: Uncorrected error reporting disabled for"
> -                           " bank %d\n",
> -                           cs->cpu_index, params->bank);
> +            g_string_append_printf(params->err,
> +                "CPU %d: Uncorrected error reporting disabled for bank %d\n",
> +                cs->cpu_index, params->bank);
>              return;
>          }
>  
> @@ -459,7 +458,7 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>          if (need_reset) {
>              emit_guest_memory_failure(MEMORY_FAILURE_ACTION_RESET, ar,
>                                        recursive);
> -            monitor_printf(params->mon, "%s", msg);
> +            g_string_append_printf(params->err, "%s\n", msg);
>              qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
>              qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
>              return;
> @@ -488,14 +487,16 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
>      emit_guest_memory_failure(MEMORY_FAILURE_ACTION_INJECT, ar, recursive);
>  }
>  
> -void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
> +bool cpu_x86_inject_mce(X86CPU *cpu, int bank,
>                          uint64_t status, uint64_t mcg_status, uint64_t addr,
> -                        uint64_t misc, int flags)
> +                        uint64_t misc, int flags, Error **errp)
>  {
> +    ERRP_GUARD();
>      CPUState *cs = CPU(cpu);
>      CPUX86State *cenv = &cpu->env;
> +    g_autoptr(GString) err = g_string_new(NULL);
>      MCEInjectionParams params = {
> -        .mon = mon,
> +        .err = err,

This indirection via GString feels overkill when we could
use directly pass 'errp', given the ERRP_GUARD we have

>          .bank = bank,
>          .status = status,
>          .mcg_status = mcg_status,
> @@ -506,21 +507,21 @@ void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
>      unsigned bank_num = cenv->mcg_cap & 0xff;
>  
>      if (!cenv->mcg_cap) {
> -        monitor_printf(mon, "MCE injection not supported\n");
> -        return;
> +        error_setg(errp, "MCE injection not supported");
> +        return false;
>      }
>      if (bank >= bank_num) {
> -        monitor_printf(mon, "Invalid MCE bank number\n");
> -        return;
> +        error_setg(errp, "Invalid MCE bank number");
> +        return false;
>      }
>      if (!(status & MCI_STATUS_VAL)) {
> -        monitor_printf(mon, "Invalid MCE status code\n");
> -        return;
> +        error_setg(errp, "Invalid MCE status code");
> +        return false;
>      }
>      if ((flags & MCE_INJECT_BROADCAST)
>          && !cpu_x86_support_mca_broadcast(cenv)) {
> -        monitor_printf(mon, "Guest CPU does not support MCA broadcast\n");
> -        return;
> +        error_setg(errp, "Guest CPU does not support MCA broadcast");
> +        return false;
>      }
>  
>      run_on_cpu(cs, do_inject_x86_mce, RUN_ON_CPU_HOST_PTR(&params));
> @@ -539,6 +540,12 @@ void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
>              run_on_cpu(other_cs, do_inject_x86_mce, RUN_ON_CPU_HOST_PTR(&params));
>          }
>      }
> +    if (params.err->len) {
> +        error_setg(errp, "Failed to inject MCE");
> +        error_append_hint(errp, "%s", params.err->str);
> +        return false;
> +    }

This could be just

  if (*params.errp) {
     return false;
  }

> +    return true;
>  }
>  
>  static inline target_ulong get_memio_eip(CPUX86State *env)

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  reply	other threads:[~2026-08-10 17:41 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 21:19 [PATCH v2 00/39] Make HMP optional (and later standalone) Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 01/39] vl: fix -monitor none prefix matching Marc-André Lureau
2026-08-10 17:30   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 02/39] hmp: remove 'vcpu' argument from trace-event help Marc-André Lureau
2026-08-10 17:31   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 03/39] hmp: fix snapshot_blkdev argument type Marc-André Lureau
2026-08-10 17:35   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 04/39] target/i386: decouple cpu_x86_inject_mce() from Monitor Marc-André Lureau
2026-08-10 17:40   ` Daniel P. Berrangé [this message]
2026-06-25 21:19 ` [PATCH v2 05/39] target/i386: return an error for invalid CPU in hmp_mce() Marc-André Lureau
2026-08-10 17:42   ` Daniel P. Berrangé
2026-08-10 20:16   ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 06/39] system: move gpa2hva() to system memory unit Marc-André Lureau
2026-08-10 17:44   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 07/39] s390x: prevent crash if given invalid CPU# Marc-André Lureau
2026-08-10 17:44   ` Daniel P. Berrangé
2026-08-10 21:01   ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 08/39] system: decouple qmp_inject_nmi() from Monitor Marc-André Lureau
2026-08-10 17:48   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 09/39] hmp: correct the nmi documentation Marc-André Lureau
2026-08-10 17:51   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 10/39] monitor: move HMP-only fields from Monitor to MonitorHMP Marc-André Lureau
2026-08-10 17:54   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 11/39] tests/functional: use query-version QMP command instead of HMP Marc-André Lureau
2026-08-10 17:54   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 12/39] net/qapi: add x-query-usernet command Marc-André Lureau
2026-08-10 17:56   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 13/39] python, tests: switch usernet queries from HMP to QMP Marc-André Lureau
2026-08-10 18:00   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 14/39] tests/qtest/pnv: drop unnecessary -serial mon:stdio Marc-André Lureau
2026-08-10 18:01   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 15/39] tests/qtest/qmp-test: don't depend on human-monitor-command Marc-André Lureau
2026-08-10 18:03   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 16/39] tests/qtest/numa-test: replace HMP "info numa" with QMP query-cpus-fast Marc-André Lureau
2026-08-10 18:04   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 17/39] tests/qtest/cdrom-test: replace HMP "info block" with QMP query-block Marc-André Lureau
2026-08-10 18:05   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 18/39] tests/qtest/device-introspect-test: fix test without HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 19/39] tests/qemu-iotests/205: fix race in assertExportNotFound Marc-André Lureau
2026-08-10 18:15   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 20/39] net: add x-query-network QMP command Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 21/39] tests/qtest/netdev-socket: replace HMP with x-query-network QMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 22/39] qemu-io: propagate errors through Error API instead of printf Marc-André Lureau
2026-08-10 18:19   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 23/39] RFC: qtest: add qemu-io command to the qtest protocol Marc-André Lureau
2026-08-10 18:22   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 24/39] RFC: qtest/ide-test: convert to use qtest qemu-io command Marc-André Lureau
2026-08-10 18:22   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 25/39] block: add x-qemu-io QMP command Marc-André Lureau
2026-08-10 18:26   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 26/39] tests/qemu-iotests: add qmp_qemu_io() Marc-André Lureau
2026-08-10 18:24   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 27/39] tests/qemu-iotests: convert pause/resume_drive() to QMP Marc-André Lureau
2026-08-10 18:26   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 28/39] build-sys: add 'hmp' option Marc-André Lureau
2026-08-10 18:27   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 29/39] monitor: reject readline monitor when HMP is disabled Marc-André Lureau
2026-08-10 18:28   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 30/39] tests: skip HMP-dependent tests " Marc-André Lureau
2026-08-10 18:29   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 31/39] util: guard monitor_vprintf callers with CONFIG_HMP Marc-André Lureau
2026-08-10 18:34   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 32/39] qapi: make HMP-specific schema entries conditional on CONFIG_HMP Marc-André Lureau
2026-08-10 18:35   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 33/39] system: guard HMP initialization paths with CONFIG_HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 34/39] Guard HMP command implementations " Marc-André Lureau
2026-08-10 18:36   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 35/39] target: guard MonitorDef tables " Marc-André Lureau
2026-08-10 21:44   ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 36/39] hw: guard BusClass::print_dev " Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 37/39] build-sys: make HMP source files conditional on have_hmp Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 38/39] monitor: guard HMP internal helpers with CONFIG_HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 39/39] monitor: guard HMP monitor API " Marc-André Lureau
2026-08-10 21:49 ` [PATCH v2 00/39] Make HMP optional (and later standalone) Philippe Mathieu-Daudé

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=anoM-GDPeNTNfFR_@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=philmd@mailo.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.