All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	qemu-s390x@nongnu.org, qemu-ppc@nongnu.org,
	qemu-block@nongnu.org,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Helge Deller" <deller@gmx.de>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Greg Kurz" <groug@kaod.org>, "Thomas Huth" <thuth@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Eric Farman" <farman@linux.ibm.com>
Subject: Re: [PATCH 1/5] hw/nmi: Have nmi_monitor_handler() return a boolean indicating error
Date: Thu, 23 Feb 2023 16:26:14 +0100	[thread overview]
Message-ID: <87a614s8rt.fsf@pond.sub.org> (raw)
In-Reply-To: <20230216122524.67212-2-philmd@linaro.org> ("Philippe Mathieu-Daudé"'s message of "Thu, 16 Feb 2023 13:25:20 +0100")

Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Following the example documented since commit e3fe3988d7 ("error:
> Document Error API usage rules"), have the nmi_monitor_handler
> return a boolean indicating whether an error is set or not and
> convert its implementations.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/core/nmi.c              | 3 +--
>  hw/hppa/machine.c          | 3 ++-
>  hw/i386/x86.c              | 3 ++-
>  hw/intc/m68k_irqc.c        | 4 +++-
>  hw/m68k/q800.c             | 4 +++-
>  hw/misc/macio/gpio.c       | 4 +++-
>  hw/ppc/pnv.c               | 3 ++-
>  hw/ppc/spapr.c             | 3 ++-
>  hw/s390x/s390-virtio-ccw.c | 4 +++-
>  include/hw/nmi.h           | 3 ++-
>  10 files changed, 23 insertions(+), 11 deletions(-)
>
> diff --git a/hw/core/nmi.c b/hw/core/nmi.c
> index 481c4b3c7e..76cb3ba3b0 100644
> --- a/hw/core/nmi.c
> +++ b/hw/core/nmi.c
> @@ -43,8 +43,7 @@ static int do_nmi(Object *o, void *opaque)
>          NMIClass *nc = NMI_GET_CLASS(n);
>  
>          ns->handled = true;
> -        nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
> -        if (ns->err) {
> +        if (!nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err)) {
>              return -1;
>          }
>      }
> diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
> index 7ac68c943f..da7c36c554 100644
> --- a/hw/hppa/machine.c
> +++ b/hw/hppa/machine.c
> @@ -437,13 +437,14 @@ static void hppa_machine_reset(MachineState *ms, ShutdownCause reason)
>      cpu[0]->env.gr[19] = FW_CFG_IO_BASE;
>  }
>  
> -static void hppa_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool hppa_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs;
>  
>      CPU_FOREACH(cs) {
>          cpu_interrupt(cs, CPU_INTERRUPT_NMI);
>      }
> +    return true;
>  }
>  
>  static void hppa_machine_init_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> index eaff4227bd..8bd0691705 100644
> --- a/hw/i386/x86.c
> +++ b/hw/i386/x86.c
> @@ -501,7 +501,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
>      return ms->possible_cpus;
>  }
>  
> -static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool x86_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      /* cpu index isn't used */
>      CPUState *cs;
> @@ -515,6 +515,7 @@ static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
>              apic_deliver_nmi(cpu->apic_state);
>          }
>      }
> +    return true;
>  }
>  
>  static long get_file_size(FILE *f)
> diff --git a/hw/intc/m68k_irqc.c b/hw/intc/m68k_irqc.c
> index 0c515e4ecb..e05083e756 100644
> --- a/hw/intc/m68k_irqc.c
> +++ b/hw/intc/m68k_irqc.c
> @@ -70,9 +70,11 @@ static void m68k_irqc_instance_init(Object *obj)
>      qdev_init_gpio_in(DEVICE(obj), m68k_set_irq, M68K_IRQC_LEVEL_NUM);
>  }
>  
> -static void m68k_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool m68k_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      m68k_set_irq(n, M68K_IRQC_LEVEL_7, 1);
> +
> +    return true;
>  }
>  
>  static const VMStateDescription vmstate_m68k_irqc = {
> diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
> index 9d52ca6613..8631a226cd 100644
> --- a/hw/m68k/q800.c
> +++ b/hw/m68k/q800.c
> @@ -227,13 +227,15 @@ static void glue_auxmode_set_irq(void *opaque, int irq, int level)
>      s->auxmode = level;
>  }
>  
> -static void glue_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool glue_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      GLUEState *s = GLUE(n);
>  
>      /* Hold NMI active for 100ms */
>      GLUE_set_irq(s, GLUE_IRQ_IN_NMI, 1);
>      timer_mod(s->nmi_release, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 100);
> +
> +    return true;
>  }
>  
>  static void glue_nmi_release(void *opaque)
> diff --git a/hw/misc/macio/gpio.c b/hw/misc/macio/gpio.c
> index c8ac5633b2..0a7214421c 100644
> --- a/hw/misc/macio/gpio.c
> +++ b/hw/misc/macio/gpio.c
> @@ -182,10 +182,12 @@ static void macio_gpio_reset(DeviceState *dev)
>      macio_set_gpio(s, 1, true);
>  }
>  
> -static void macio_gpio_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool macio_gpio_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      macio_set_gpio(MACIO_GPIO(n), 9, true);
>      macio_set_gpio(MACIO_GPIO(n), 9, false);
> +
> +    return true;
>  }
>  
>  static void macio_gpio_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> index 44b1fbbc93..38e69f3b39 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -2309,13 +2309,14 @@ static void pnv_cpu_do_nmi_on_cpu(CPUState *cs, run_on_cpu_data arg)
>      }
>  }
>  
> -static void pnv_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool pnv_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs;
>  
>      CPU_FOREACH(cs) {
>          async_run_on_cpu(cs, pnv_cpu_do_nmi_on_cpu, RUN_ON_CPU_NULL);
>      }
> +    return true;
>  }
>  
>  static void pnv_machine_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 4921198b9d..d298068169 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -3464,13 +3464,14 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg)
>      }
>  }
>  
> -static void spapr_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool spapr_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs;
>  
>      CPU_FOREACH(cs) {
>          async_run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL);
>      }
> +    return true;
>  }
>  
>  int spapr_lmb_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index f22f61b8b6..af7e6c632a 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -570,11 +570,13 @@ static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
>      return NULL;
>  }
>  
> -static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool s390_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs = qemu_get_cpu(cpu_index);
>  
>      s390_cpu_restart(S390_CPU(cs));
> +
> +    return true;
>  }
>  
>  static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
> diff --git a/include/hw/nmi.h b/include/hw/nmi.h
> index fff41bebc6..3e827a254a 100644
> --- a/include/hw/nmi.h
> +++ b/include/hw/nmi.h
> @@ -37,7 +37,8 @@ typedef struct NMIState NMIState;
>  struct NMIClass {
>      InterfaceClass parent_class;
>  
> -    void (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
> +    /** Returns: %true on success, %false on error. */
> +    bool (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
>  };
>  
>  void nmi_monitor_handle(int cpu_index, Error **errp);

None of the handlers can actually fail.  Evidence: you add only return
true, never return false.  Correct (I checked).

I think I'd make it official and drop the handler's Error ** parameter
instead of changing its return type.

You decide.

Reviewed-by: Markus Armbruster <armbru@redhat.com>


  reply	other threads:[~2023-02-23 15:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 12:25 [PATCH 0/5] bulk: Have object_child_foreach() take Error* and return boolean Philippe Mathieu-Daudé
2023-02-16 12:25 ` [PATCH 1/5] hw/nmi: Have nmi_monitor_handler() return a boolean indicating error Philippe Mathieu-Daudé
2023-02-23 15:26   ` Markus Armbruster [this message]
2023-02-16 12:25 ` [PATCH 2/5] spapr/ddw: Remove confuse return value in spapr_phb_get_free_liobn() Philippe Mathieu-Daudé
2023-02-17 10:31   ` Daniel Henrique Barboza
2023-02-16 12:25 ` [PATCH 3/5] bulk: Have object_child_foreach() take Error* and return boolean Philippe Mathieu-Daudé
2023-02-16 12:30   ` Michael S. Tsirkin
2023-02-23 15:40   ` Markus Armbruster
2023-02-16 12:25 ` [RFC PATCH 4/5] hw/nmi: Simplify nmi_monitor_handle() and do_nmi() Philippe Mathieu-Daudé
2023-02-16 12:25 ` [RFC PATCH 5/5] hw/ppc/pnv_bmc: Simplify pnv_bmc_find() Philippe Mathieu-Daudé
2023-02-16 18:12   ` Cédric Le Goater
2023-02-16 19:16     ` Philippe Mathieu-Daudé
2023-02-17  8:04       ` Cédric Le Goater
2023-02-23 15:42   ` Markus Armbruster

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=87a614s8rt.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=deller@gmx.de \
    --cc=eduardo@habkost.net \
    --cc=farman@linux.ibm.com \
    --cc=groug@kaod.org \
    --cc=iii@linux.ibm.com \
    --cc=laurent@vivier.eu \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    /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.