All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
To: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Cc: Artyom Tarasenko <atar4qemu@gmail.com>
Subject: Re: [Qemu-devel] [PATCH] hw/sparc/sun4m: Fix problems with device introspection
Date: Fri, 15 Jun 2018 09:33:23 +0100	[thread overview]
Message-ID: <8de353d3-c4bc-f10e-1eaf-8ea7b989b97d@ilande.co.uk> (raw)
In-Reply-To: <16444602-26f5-46ba-2d39-92e68c5bf904@redhat.com>

On 15/06/18 06:15, Thomas Huth wrote:

> On 05.04.2018 12:43, Thomas Huth wrote:
>> Several devices of the sun4m machines are using &error_fatal in
>> their instance_init function and thus can cause QEMU to abort
>> unexpectedly:
>>
>> $ echo "{'execute':'qmp_capabilities'}"\
>>         "{'execute':'device-list-properties',"\
>>         " 'arguments':{'typename':'openprom'}}" \
>>         | sparc-softmmu/qemu-system-sparc -M SS-10 -S -qmp stdio
>> {"QMP": {"version": {"qemu": {"micro": 91, "minor": 11, "major": 2},
>>   "package": "build-all"}, "capabilities": []}}
>> {"return": {}}
>> RAMBlock "sun4m.prom" already registered, abort!
>> Aborted (core dumped)
>>
>> $ echo "{'execute':'qmp_capabilities'}"\
>>         "{'execute':'device-list-properties',"\
>>         " 'arguments':{'typename':'macio_idreg'}}" \
>>         | sparc-softmmu/qemu-system-sparc -M SS-10 -S -qmp stdio
>> {"QMP": {"version": {"qemu": {"micro": 91, "minor": 11, "major": 2},
>>   "package": "build-all"}, "capabilities": []}}
>> {"return": {}}
>> RAMBlock "sun4m.idreg" already registered, abort!
>> Aborted (core dumped)
>>
>> $ echo "{'execute':'qmp_capabilities'}"\
>>         "{'execute':'device-list-properties',"\
>>         " 'arguments':{'typename':'tcx_afx'}}" \
>>         | sparc-softmmu/qemu-system-sparc -M SS-5 -S -qmp stdio
>> {"QMP": {"version": {"qemu": {"micro": 91, "minor": 11, "major": 2},
>>   "package": "build-all"}, "capabilities": []}}
>> {"return": {}}
>> RAMBlock "sun4m.afx" already registered, abort!
>> Aborted (core dumped)
>>
>> Fix the issues by converting the instance_init functions into realize()
>> functions instead, which are allowed to fail (and not called during
>> device introspection).
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   hw/sparc/sun4m.c | 67 ++++++++++++++++++++++++++++++++++++++++++--------------
>>   1 file changed, 50 insertions(+), 17 deletions(-)
>>
>> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
>> index 6471aca..8254ec3 100644
>> --- a/hw/sparc/sun4m.c
>> +++ b/hw/sparc/sun4m.c
>> @@ -572,23 +572,36 @@ typedef struct IDRegState {
>>       MemoryRegion mem;
>>   } IDRegState;
>>   
>> -static void idreg_init1(Object *obj)
>> +static void idreg_realize(DeviceState *ds, Error **errp)
>>   {
>> -    IDRegState *s = MACIO_ID_REGISTER(obj);
>> -    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>> +    IDRegState *s = MACIO_ID_REGISTER(ds);
>> +    SysBusDevice *dev = SYS_BUS_DEVICE(ds);
>> +    Error *local_err = NULL;
>> +
>> +    memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.idreg",
>> +                                     sizeof(idreg_data), &local_err);
>> +    if (local_err) {
>> +        error_propagate(errp, local_err);
>> +        return;
>> +    }
>>   
>> -    memory_region_init_ram_nomigrate(&s->mem, obj,
>> -                           "sun4m.idreg", sizeof(idreg_data), &error_fatal);
>>       vmstate_register_ram_global(&s->mem);
>>       memory_region_set_readonly(&s->mem, true);
>>       sysbus_init_mmio(dev, &s->mem);
>>   }
>>   
>> +static void idreg_class_init(ObjectClass *oc, void *data)
>> +{
>> +    DeviceClass *dc = DEVICE_CLASS(oc);
>> +
>> +    dc->realize = idreg_realize;
>> +}
>> +
>>   static const TypeInfo idreg_info = {
>>       .name          = TYPE_MACIO_ID_REGISTER,
>>       .parent        = TYPE_SYS_BUS_DEVICE,
>>       .instance_size = sizeof(IDRegState),
>> -    .instance_init = idreg_init1,
>> +    .class_init    = idreg_class_init,
>>   };
>>   
>>   #define TYPE_TCX_AFX "tcx_afx"
>> @@ -613,21 +626,35 @@ static void afx_init(hwaddr addr)
>>       sysbus_mmio_map(s, 0, addr);
>>   }
>>   
>> -static void afx_init1(Object *obj)
>> +static void afx_realize(DeviceState *ds, Error **errp)
>>   {
>> -    AFXState *s = TCX_AFX(obj);
>> -    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>> +    AFXState *s = TCX_AFX(ds);
>> +    SysBusDevice *dev = SYS_BUS_DEVICE(ds);
>> +    Error *local_err = NULL;
>> +
>> +    memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.afx", 4,
>> +                                     &local_err);
>> +    if (local_err) {
>> +        error_propagate(errp, local_err);
>> +        return;
>> +    }
>>   
>> -    memory_region_init_ram_nomigrate(&s->mem, obj, "sun4m.afx", 4, &error_fatal);
>>       vmstate_register_ram_global(&s->mem);
>>       sysbus_init_mmio(dev, &s->mem);
>>   }
>>   
>> +static void afx_class_init(ObjectClass *oc, void *data)
>> +{
>> +    DeviceClass *dc = DEVICE_CLASS(oc);
>> +
>> +    dc->realize = afx_realize;
>> +}
>> +
>>   static const TypeInfo afx_info = {
>>       .name          = TYPE_TCX_AFX,
>>       .parent        = TYPE_SYS_BUS_DEVICE,
>>       .instance_size = sizeof(AFXState),
>> -    .instance_init = afx_init1,
>> +    .class_init    = afx_class_init,
>>   };
>>   
>>   #define TYPE_OPENPROM "openprom"
>> @@ -680,13 +707,19 @@ static void prom_init(hwaddr addr, const char *bios_name)
>>       }
>>   }
>>   
>> -static void prom_init1(Object *obj)
>> +static void prom_realize(DeviceState *ds, Error **errp)
>>   {
>> -    PROMState *s = OPENPROM(obj);
>> -    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>> +    PROMState *s = OPENPROM(ds);
>> +    SysBusDevice *dev = SYS_BUS_DEVICE(ds);
>> +    Error *local_err = NULL;
>> +
>> +    memory_region_init_ram_nomigrate(&s->prom, OBJECT(ds), "sun4m.prom",
>> +                                     PROM_SIZE_MAX, &local_err);
>> +    if (local_err) {
>> +        error_propagate(errp, local_err);
>> +        return;
>> +    }
>>   
>> -    memory_region_init_ram_nomigrate(&s->prom, obj, "sun4m.prom", PROM_SIZE_MAX,
>> -                           &error_fatal);
>>       vmstate_register_ram_global(&s->prom);
>>       memory_region_set_readonly(&s->prom, true);
>>       sysbus_init_mmio(dev, &s->prom);
>> @@ -701,6 +734,7 @@ static void prom_class_init(ObjectClass *klass, void *data)
>>       DeviceClass *dc = DEVICE_CLASS(klass);
>>   
>>       dc->props = prom_properties;
>> +    dc->realize = prom_realize;
>>   }
>>   
>>   static const TypeInfo prom_info = {
>> @@ -708,7 +742,6 @@ static const TypeInfo prom_info = {
>>       .parent        = TYPE_SYS_BUS_DEVICE,
>>       .instance_size = sizeof(PROMState),
>>       .class_init    = prom_class_init,
>> -    .instance_init = prom_init1,
>>   };
>>   
>>   #define TYPE_SUN4M_MEMORY "memory"
>>
> 
> Ping!

Ooops sorry - I vaguely remember seeing this before but must have 
forgotten about them. Both patches look good to me, so I'll add my R-B 
and add them to my qemu-sparc queue.


ATB,

Mark.

      parent reply	other threads:[~2018-06-15  8:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-05 10:43 [Qemu-devel] [PATCH] hw/sparc/sun4m: Fix problems with device introspection Thomas Huth
2018-04-06 14:42 ` Mark Cave-Ayland
2018-06-15  5:15 ` Thomas Huth
2018-06-15  7:43   ` Artyom Tarasenko
2018-06-15  8:33   ` Mark Cave-Ayland [this message]

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=8de353d3-c4bc-f10e-1eaf-8ea7b989b97d@ilande.co.uk \
    --to=mark.cave-ayland@ilande.co.uk \
    --cc=atar4qemu@gmail.com \
    --cc=qemu-devel@nongnu.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.