qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Thomas Huth <huth@tuxfamily.org>
Cc: qemu-devel@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
	"Anthony Green" <green@moxielogic.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Guan Xuetao" <gxt@mprc.pku.edu.cn>, "Jia Liu" <proljc@gmail.com>,
	"Magnus Damm" <magnus.damm@gmail.com>,
	"Alexander Graf" <agraf@suse.de>,
	"Hervé Poussineau" <hpoussin@reactos.org>,
	"Richard Henderson" <rth@twiddle.net>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Andrew Jones" <drjones@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Riku Voipio" <riku.voipio@iki.fi>,
	"Fabien Chouteau" <chouteau@adacore.com>,
	"Jan Kiszka" <jan.kiszka@web.de>,
	"Yongbok Kim" <yongbok.kim@imgtec.com>,
	"Stafford Horne" <shorne@gmail.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Michael Walle" <michael@walle.cc>,
	"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [Qemu-devel] [PATCH 2/6] cpu: make cpu_generic_init() abort QEMU on error
Date: Mon, 11 Sep 2017 16:51:54 +0200	[thread overview]
Message-ID: <20170911165154.41c5aa48@nial.brq.redhat.com> (raw)
In-Reply-To: <d021bc33-5b0c-f5d2-e619-e06705a32043@tuxfamily.org>

On Tue, 5 Sep 2017 07:41:51 +0200
Thomas Huth <huth@tuxfamily.org> wrote:

> On 04.09.2017 16:00, Igor Mammedov wrote:
> > Almost every user of cpu_generic_init() checks for
> > returned NULL and then reports failure in a custom way
> > and aborts process.
> > Some users assume that call can't fail and don't check
> > for failure, though they should have checked for it.
> > 
> > In either cases cpu_generic_init() failure is fatal,
> > so instead of checking for failure and reporting
> > it various ways, make cpu_generic_init() report
> > errors in consistent way and terminate QEMU on failure.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > Even though it's tree wide change, it's trivial so all
> > affected call sites are included within one patch.  
> [...]
> > diff --git a/qom/cpu.c b/qom/cpu.c
> > index d715890..307d638 100644
> > --- a/qom/cpu.c
> > +++ b/qom/cpu.c
> > @@ -61,7 +61,7 @@ CPUState *cpu_create(const char *typename)
> >      if (err != NULL) {
> >          error_report_err(err);
> >          object_unref(OBJECT(cpu));
> > -        return NULL;
> > +        exit(EXIT_FAILURE);
> >      }
> >      return cpu;
> >  }
> > @@ -78,8 +78,9 @@ const char *cpu_parse_features(const char *typename, const char *cpu_model)
> >  
> >      oc = cpu_class_by_name(typename, model_pieces[0]);
> >      if (oc == NULL) {
> > +        error_report("unable to find CPU model '%s'", model_pieces[0]);
> >          g_strfreev(model_pieces);
> > -        return NULL;
> > +        exit(EXIT_FAILURE);
> >      }
> >  
> >      cpu_type = object_class_get_name(oc);
> > @@ -88,7 +89,7 @@ const char *cpu_parse_features(const char *typename, const char *cpu_model)
> >      g_strfreev(model_pieces);
> >      if (err != NULL) {
> >          error_report_err(err);
> > -        return NULL;
> > +        exit(EXIT_FAILURE);
> >      }
> >      return cpu_type;
> >  }
> > @@ -100,10 +101,8 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
> >       */
> >      const char *cpu_type = cpu_parse_features(typename, cpu_model);
> >  
> > -    if (cpu_type) {
> > -        return cpu_create(cpu_type);
> > -    }
> > -    return NULL;
> > +    assert(cpu_type);
> > +    return cpu_create(cpu_type);
> >  }  
> 
> Not sure, but wouldn't it be better to do the error reporting and exit
> in cpu_generic_init() instead? In case we ever might want to re-use the
> create and parse_feature functions for device_add later (?), and then
> the functions must not exit directly anymore...
1st:
cpu_generic_init() should be removed once I convert all users to use
MachineState::cpu_type + cpu_create() instead of cpu_generic_init(cpu_model).
So no board would have to deal with cpu_model directly.

2nd:
device_add already does
  obj = object_new() + ... + obj.realize = true
hence cpu_create() is of no use there.
However cpu_create() is still useful as all users that
just need to create and realize cpu without extra configuration,
could benefit from unified error checking/message and 'small' code
deduplication as diffstat for this patch shows.

   38 files changed, 8 insertions(+), 169 deletions(-)

3rd:
parse_feature callbacks are meant to be called only once
and do nothing if called multiple times. They convert
'-cpu foo,features' option into a set of global properties which
are applied every created cpu instance of given type.
So when 'device_add cpu_foo' is called, there is no need to call
parse_features(). 


> 
>  Thomas
> 

  parent reply	other threads:[~2017-09-11 14:52 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 14:00 [Qemu-devel] [PATCH 0/6] generalize parsing of cpu_model (x86/arm) Igor Mammedov
2017-09-04 14:00 ` [Qemu-devel] [PATCH 1/6] qom: cpus: split cpu_generic_init() on feature parsing and cpu creation parts Igor Mammedov
2017-09-04 15:30   ` Philippe Mathieu-Daudé
2017-09-04 14:00 ` [Qemu-devel] [PATCH 2/6] cpu: make cpu_generic_init() abort QEMU on error Igor Mammedov
2017-09-04 15:15   ` Philippe Mathieu-Daudé
2017-09-11 14:30     ` Igor Mammedov
2017-09-05  5:41   ` Thomas Huth
2017-09-05 11:22     ` Eduardo Habkost
2017-09-11 14:51     ` Igor Mammedov [this message]
2017-09-05 20:19   ` Eduardo Habkost
2017-09-11 14:23     ` Igor Mammedov
2017-09-04 14:00 ` [Qemu-devel] [PATCH 3/6] cpu: rename cpu_parse_features() to cpu_parse_cpu_model() Igor Mammedov
2017-09-04 15:03   ` Philippe Mathieu-Daudé
2017-09-04 19:06     ` Igor Mammedov
2017-09-05  5:38       ` Thomas Huth
2017-09-11 15:07         ` Igor Mammedov
2017-09-04 14:01 ` [Qemu-devel] [PATCH 4/6] vl.c: convert cpu_model to cpu type and set of global properties before machine_init() Igor Mammedov
2017-09-04 14:01 ` [Qemu-devel] [PATCH 5/6] pc: use generic cpu_model parsing Igor Mammedov
2017-09-04 15:33   ` Philippe Mathieu-Daudé
2017-09-04 14:01 ` [Qemu-devel] [PATCH 6/6] arm: drop intermadiate cpu_model -> cpu type parsing and use cpu type directly Igor Mammedov
2017-09-05 21:31   ` Eduardo Habkost
2017-09-05 21:47     ` Alistair Francis
2017-09-05 22:12       ` Eduardo Habkost
2017-09-05 22:46         ` Alistair Francis
2017-09-06  0:16           ` Alistair Francis
2017-09-09 20:30           ` Eduardo Habkost
2017-09-09 22:41             ` Peter Maydell
2017-09-09 23:22               ` Eduardo Habkost
2017-09-12 10:22             ` Igor Mammedov
2017-09-12 12:01               ` Eduardo Habkost
2017-09-12 10:53         ` Igor Mammedov
2017-09-12 16:29           ` Alistair Francis
2017-09-12 11:02       ` Igor Mammedov
2017-09-12 12:04         ` Eduardo Habkost
2017-09-12 12:11     ` Igor Mammedov
2017-09-12 12:53       ` Eduardo Habkost
2017-09-12 14:06         ` Igor Mammedov

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=20170911165154.41c5aa48@nial.brq.redhat.com \
    --to=imammedo@redhat.com \
    --cc=agraf@suse.de \
    --cc=atar4qemu@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=chouteau@adacore.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=drjones@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=green@moxielogic.com \
    --cc=gxt@mprc.pku.edu.cn \
    --cc=hpoussin@reactos.org \
    --cc=huth@tuxfamily.org \
    --cc=jan.kiszka@web.de \
    --cc=jcmvbkbc@gmail.com \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=laurent@vivier.eu \
    --cc=magnus.damm@gmail.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=michael@walle.cc \
    --cc=peter.maydell@linaro.org \
    --cc=proljc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    --cc=rth@twiddle.net \
    --cc=shorne@gmail.com \
    --cc=yongbok.kim@imgtec.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).