Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2018-03-26 Thread Philippe Mathieu-Daudé
Hi Eduardo,

On 03/26/2018 08:18 AM, Eduardo Otubo wrote:
> QEMU fails when used with the following command line:
> 
> ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
> qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
> `!bus->dma[0] && !bus->dma[1]' failed.
> Aborted (core dumped)
> 
> The 40p machine type already creates the device i82374. If specified in the
> command line, it will try to create it again, hence generating the error. The
> function isa_bus_dma() isn't supposed to be called twice for the same bus. 
> This
> patch fixes this issue by calling involved functions with Error **error_fatal
> and propagating back the error so QEMU can fail nicely without Abort and core
> dump.

I came with a simpler patch (imho), keeping your comment.

> 
> Signed-off-by: Eduardo Otubo 
> ---
> v4:
>  * Change return value from int8_t to int
>  * Changed function calling for other architectures.
> 
> v3:
>  * Removed all unecessary local_err   
>   
>  
>  * Change return of isa_bus_dma() and DMA_init() from void to int8_t, 
>   
>  
>returning -EBUSY on error and 0 on success 
>   
>  
>  * Added qdev_cleanup_nofail() in case isa_bus_dma() returns error. The   
>   
>  
>cleanup looks safe, but please review if I didn't miss any detail  
>   
>  
>   
>   
>  
> v2:   
>   
>  
>  * Removed user_creatable=false and replaced by error handling using  
>   
>  
>Error **errp and error_propagate();  
> 
>  hw/core/qdev.c  | 16 
>  hw/dma/i82374.c |  3 ++-
>  hw/dma/i8257.c  | 35 +++
>  hw/i386/pc.c|  2 +-
>  hw/isa/isa-bus.c|  8 ++--
>  hw/mips/mips_fulong2e.c |  2 +-
>  hw/mips/mips_jazz.c |  2 +-
>  hw/mips/mips_malta.c|  2 +-
>  include/hw/dma/i8257.h  |  2 +-
>  include/hw/isa/isa.h|  2 +-
>  include/hw/qdev-core.h  |  1 +
>  11 files changed, 50 insertions(+), 25 deletions(-)
> 
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index f6f92473b8..e14164526f 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -345,6 +345,22 @@ void qdev_init_nofail(DeviceState *dev)
>  object_unref(OBJECT(dev));
>  }
>  
> +void qdev_cleanup_nofail(DeviceState *dev)
> +{
> +Error *err = NULL;
> +
> +assert(dev->realized);
> +
> +object_ref(OBJECT(dev));
> +object_property_set_bool(OBJECT(dev), false, "realized", );
> +if (err) {
> +error_reportf_err(err, "Clean up of device %s failed: ",
> +  object_get_typename(OBJECT(dev)));
> +exit(1);
> +}
> +object_unref(OBJECT(dev));
> +}
> +
>  void qdev_machine_creation_done(void)
>  {
>  /*
> diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> index 83c87d92e0..718cd632fd 100644
> --- a/hw/dma/i82374.c
> +++ b/hw/dma/i82374.c
> @@ -25,6 +25,7 @@
>  #include "qemu/osdep.h"
>  #include "hw/isa/isa.h"
>  #include "hw/dma/i8257.h"
> +#include "qapi/error.h"
>  
>  #define TYPE_I82374 "i82374"
>  #define I82374(obj) OBJECT_CHECK(I82374State, (obj), TYPE_I82374)
> @@ -124,7 +125,7 @@ static void i82374_realize(DeviceState *dev, Error **errp)
>  portio_list_add(>port_list, isa_address_space_io(>parent_obj),
>  s->iobase);
>  
> -i8257_dma_init(isa_bus_from_device(ISA_DEVICE(dev)), true);
> +i8257_dma_init(isa_bus_from_device(ISA_DEVICE(dev)), true, errp);
>  memset(s->commands, 0, sizeof(s->commands));
>  }
>  
> diff --git a/hw/dma/i8257.c b/hw/dma/i8257.c
> index 52675e97c9..84978f9459 100644
> --- a/hw/dma/i8257.c
> +++ b/hw/dma/i8257.c
> @@ -622,26 +622,29 @@ static void i8257_register_types(void)
>  

Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2018-03-26 Thread Paolo Bonzini
On 26/03/2018 14:14, Thomas Huth wrote:
>> +object_ref(OBJECT(dev));
>> +object_property_set_bool(OBJECT(dev), false, "realized", );
>> +if (err) {
>> +error_reportf_err(err, "Clean up of device %s failed: ",
>> +  object_get_typename(OBJECT(dev)));
>> +exit(1);
>> +}
>> +object_unref(OBJECT(dev));
>> +}
> 
> I'm not a qdev expert, but I wonder whether we need the full object_ref
> + unref dance here? If not, you could get rid of this function and
> simply do the object_property_set_bool(OBJECT(dev), false, "realized",
> _fatal) twice in i8257_dma_init() instead.

No, however we do need an object_unparent call.

Paolo



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2018-03-26 Thread Thomas Huth
On 26.03.2018 13:18, Eduardo Otubo wrote:
> QEMU fails when used with the following command line:
> 
> ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
> qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
> `!bus->dma[0] && !bus->dma[1]' failed.
> Aborted (core dumped)
> 
> The 40p machine type already creates the device i82374. If specified in the
> command line, it will try to create it again, hence generating the error. The
> function isa_bus_dma() isn't supposed to be called twice for the same bus. 
> This
> patch fixes this issue by calling involved functions with Error **error_fatal
> and propagating back the error so QEMU can fail nicely without Abort and core
> dump.
> 
> Signed-off-by: Eduardo Otubo 
> ---
> v4:
>  * Change return value from int8_t to int
>  * Changed function calling for other architectures.
> 
> v3:
>  * Removed all unecessary local_err   
>   
>  
>  * Change return of isa_bus_dma() and DMA_init() from void to int8_t, 
>   
>  
>returning -EBUSY on error and 0 on success 
>   
>  
>  * Added qdev_cleanup_nofail() in case isa_bus_dma() returns error. The   
>   
>  
>cleanup looks safe, but please review if I didn't miss any detail  
>   
>  
>   
>   
>  
> v2:   
>   
>  
>  * Removed user_creatable=false and replaced by error handling using  
>   
>  
>Error **errp and error_propagate();  
> 
>  hw/core/qdev.c  | 16 
>  hw/dma/i82374.c |  3 ++-
>  hw/dma/i8257.c  | 35 +++
>  hw/i386/pc.c|  2 +-
>  hw/isa/isa-bus.c|  8 ++--
>  hw/mips/mips_fulong2e.c |  2 +-
>  hw/mips/mips_jazz.c |  2 +-
>  hw/mips/mips_malta.c|  2 +-
>  include/hw/dma/i8257.h  |  2 +-
>  include/hw/isa/isa.h|  2 +-
>  include/hw/qdev-core.h  |  1 +
>  11 files changed, 50 insertions(+), 25 deletions(-)
> 
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index f6f92473b8..e14164526f 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -345,6 +345,22 @@ void qdev_init_nofail(DeviceState *dev)
>  object_unref(OBJECT(dev));
>  }
>  
> +void qdev_cleanup_nofail(DeviceState *dev)
> +{
> +Error *err = NULL;
> +
> +assert(dev->realized);
> +
> +object_ref(OBJECT(dev));
> +object_property_set_bool(OBJECT(dev), false, "realized", );
> +if (err) {
> +error_reportf_err(err, "Clean up of device %s failed: ",
> +  object_get_typename(OBJECT(dev)));
> +exit(1);
> +}
> +object_unref(OBJECT(dev));
> +}

I'm not a qdev expert, but I wonder whether we need the full object_ref
+ unref dance here? If not, you could get rid of this function and
simply do the object_property_set_bool(OBJECT(dev), false, "realized",
_fatal) twice in i8257_dma_init() instead.

>  void qdev_machine_creation_done(void)
>  {
>  /*
> diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> index 83c87d92e0..718cd632fd 100644
> --- a/hw/dma/i82374.c
> +++ b/hw/dma/i82374.c
> @@ -25,6 +25,7 @@
>  #include "qemu/osdep.h"
>  #include "hw/isa/isa.h"
>  #include "hw/dma/i8257.h"
> +#include "qapi/error.h"
>  
>  #define TYPE_I82374 "i82374"
>  #define I82374(obj) OBJECT_CHECK(I82374State, (obj), TYPE_I82374)
> @@ -124,7 +125,7 @@ static void i82374_realize(DeviceState *dev, Error **errp)
>  portio_list_add(>port_list, isa_address_space_io(>parent_obj),
>  s->iobase);
>  
> -i8257_dma_init(isa_bus_from_device(ISA_DEVICE(dev)), true);
> +i8257_dma_init(isa_bus_from_device(ISA_DEVICE(dev)), true, errp);

I think it would be better to move this at the beginning of the
i82374_realize 

[Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2018-03-26 Thread Eduardo Otubo
QEMU fails when used with the following command line:

./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
`!bus->dma[0] && !bus->dma[1]' failed.
Aborted (core dumped)

The 40p machine type already creates the device i82374. If specified in the
command line, it will try to create it again, hence generating the error. The
function isa_bus_dma() isn't supposed to be called twice for the same bus. This
patch fixes this issue by calling involved functions with Error **error_fatal
and propagating back the error so QEMU can fail nicely without Abort and core
dump.

Signed-off-by: Eduardo Otubo 
---
v4:
 * Change return value from int8_t to int
 * Changed function calling for other architectures.

v3:
 * Removed all unecessary local_err 

 
 * Change return of isa_bus_dma() and DMA_init() from void to int8_t,   

 
   returning -EBUSY on error and 0 on success   

 
 * Added qdev_cleanup_nofail() in case isa_bus_dma() returns error. The 

 
   cleanup looks safe, but please review if I didn't miss any detail

 


 
v2: 

 
 * Removed user_creatable=false and replaced by error handling using

 
   Error **errp and error_propagate();  

 hw/core/qdev.c  | 16 
 hw/dma/i82374.c |  3 ++-
 hw/dma/i8257.c  | 35 +++
 hw/i386/pc.c|  2 +-
 hw/isa/isa-bus.c|  8 ++--
 hw/mips/mips_fulong2e.c |  2 +-
 hw/mips/mips_jazz.c |  2 +-
 hw/mips/mips_malta.c|  2 +-
 include/hw/dma/i8257.h  |  2 +-
 include/hw/isa/isa.h|  2 +-
 include/hw/qdev-core.h  |  1 +
 11 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index f6f92473b8..e14164526f 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -345,6 +345,22 @@ void qdev_init_nofail(DeviceState *dev)
 object_unref(OBJECT(dev));
 }
 
+void qdev_cleanup_nofail(DeviceState *dev)
+{
+Error *err = NULL;
+
+assert(dev->realized);
+
+object_ref(OBJECT(dev));
+object_property_set_bool(OBJECT(dev), false, "realized", );
+if (err) {
+error_reportf_err(err, "Clean up of device %s failed: ",
+  object_get_typename(OBJECT(dev)));
+exit(1);
+}
+object_unref(OBJECT(dev));
+}
+
 void qdev_machine_creation_done(void)
 {
 /*
diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
index 83c87d92e0..718cd632fd 100644
--- a/hw/dma/i82374.c
+++ b/hw/dma/i82374.c
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/isa/isa.h"
 #include "hw/dma/i8257.h"
+#include "qapi/error.h"
 
 #define TYPE_I82374 "i82374"
 #define I82374(obj) OBJECT_CHECK(I82374State, (obj), TYPE_I82374)
@@ -124,7 +125,7 @@ static void i82374_realize(DeviceState *dev, Error **errp)
 portio_list_add(>port_list, isa_address_space_io(>parent_obj),
 s->iobase);
 
-i8257_dma_init(isa_bus_from_device(ISA_DEVICE(dev)), true);
+i8257_dma_init(isa_bus_from_device(ISA_DEVICE(dev)), true, errp);
 memset(s->commands, 0, sizeof(s->commands));
 }
 
diff --git a/hw/dma/i8257.c b/hw/dma/i8257.c
index 52675e97c9..84978f9459 100644
--- a/hw/dma/i8257.c
+++ b/hw/dma/i8257.c
@@ -622,26 +622,29 @@ static void i8257_register_types(void)
 
 type_init(i8257_register_types)
 
-void i8257_dma_init(ISABus *bus, bool high_page_enable)
+void i8257_dma_init(ISABus *bus, bool high_page_enable, Error **error_fatal)
 {
 ISADevice *isa1, *isa2;
-DeviceState *d;
+DeviceState *d1, *d2;
 
 isa1 = isa_create(bus, TYPE_I8257);
-d = DEVICE(isa1);
-qdev_prop_set_int32(d, 

Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-25 Thread Paolo Bonzini
On 25/09/2017 12:54, Michael Tokarev wrote:
>> Yes, that's correct. I can revert this patch with the error
>> propagation patch as well, if you guys don't mind.
> Hmm. After reading the original discussion I concluded this patch
> is okay.  I can remove it right now before the series has been
> applied, together with another tiny change.

No problem, it's okay for now as a trivial change.

Paolo



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-25 Thread Michael Tokarev
25.09.2017 12:26, Eduardo Otubo wrote:
> On Mon, Sep 25, 2017 at 11:11:37AM +0200, Paolo Bonzini wrote:
>> On 24/09/2017 23:02, Michael Tokarev wrote:
>>> 15.09.2017 12:06, Eduardo Otubo wrote:
 QEMU fails when used with the following command line:

   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device 
 i82374
   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
 `!bus->dma[0] && !bus->dma[1]' failed.
   Aborted (core dumped)

 The 40p machine type already creates the device i82374. If specified in the
 command line, it will try to create it again, hence generating the error. 
 The
 function isa_bus_dma() isn't supposed to be called twice for the same bus. 
 One
 way to avoid this problem is to set user_creatable=false.
>>>
>>> Applied to -trivial, thanks!
>>
>> Eduardo, weren't you going to send a version that propagates Error*
>> correctly instead?
> 
> Yes, that's correct. I can revert this patch with the error
> propagation patch as well, if you guys don't mind.

Hmm. After reading the original discussion I concluded this patch
is okay.  I can remove it right now before the series has been
applied, together with another tiny change.

Thanks,

/mjt



Re: [Qemu-devel] [[PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-25 Thread Paolo Bonzini
On 25/09/2017 11:26, Eduardo Otubo wrote:
> On Mon, Sep 25, 2017 at 11:11:37AM +0200, Paolo Bonzini wrote:
>> On 24/09/2017 23:02, Michael Tokarev wrote:
>>> 15.09.2017 12:06, Eduardo Otubo wrote:
 QEMU fails when used with the following command line:

   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device 
 i82374
   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
 `!bus->dma[0] && !bus->dma[1]' failed.
   Aborted (core dumped)

 The 40p machine type already creates the device i82374. If specified in the
 command line, it will try to create it again, hence generating the error. 
 The
 function isa_bus_dma() isn't supposed to be called twice for the same bus. 
 One
 way to avoid this problem is to set user_creatable=false.
>>>
>>> Applied to -trivial, thanks!
>>
>> Eduardo, weren't you going to send a version that propagates Error*
>> correctly instead?
> 
> Yes, that's correct. I can revert this patch with the error
> propagation patch as well, if you guys don't mind.

Sure, that's fine too.

Paolo



Re: [Qemu-devel] [[PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-25 Thread Eduardo Otubo
On Mon, Sep 25, 2017 at 11:11:37AM +0200, Paolo Bonzini wrote:
> On 24/09/2017 23:02, Michael Tokarev wrote:
> > 15.09.2017 12:06, Eduardo Otubo wrote:
> >> QEMU fails when used with the following command line:
> >>
> >>   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device 
> >> i82374
> >>   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
> >> `!bus->dma[0] && !bus->dma[1]' failed.
> >>   Aborted (core dumped)
> >>
> >> The 40p machine type already creates the device i82374. If specified in the
> >> command line, it will try to create it again, hence generating the error. 
> >> The
> >> function isa_bus_dma() isn't supposed to be called twice for the same bus. 
> >> One
> >> way to avoid this problem is to set user_creatable=false.
> > 
> > Applied to -trivial, thanks!
> 
> Eduardo, weren't you going to send a version that propagates Error*
> correctly instead?

Yes, that's correct. I can revert this patch with the error
propagation patch as well, if you guys don't mind.



Re: [Qemu-devel] [[PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-25 Thread Paolo Bonzini
On 24/09/2017 23:02, Michael Tokarev wrote:
> 15.09.2017 12:06, Eduardo Otubo wrote:
>> QEMU fails when used with the following command line:
>>
>>   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
>>   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
>> `!bus->dma[0] && !bus->dma[1]' failed.
>>   Aborted (core dumped)
>>
>> The 40p machine type already creates the device i82374. If specified in the
>> command line, it will try to create it again, hence generating the error. The
>> function isa_bus_dma() isn't supposed to be called twice for the same bus. 
>> One
>> way to avoid this problem is to set user_creatable=false.
> 
> Applied to -trivial, thanks!

Eduardo, weren't you going to send a version that propagates Error*
correctly instead?

Paolo




Re: [Qemu-devel] [[PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-24 Thread Michael Tokarev
15.09.2017 12:06, Eduardo Otubo wrote:
> QEMU fails when used with the following command line:
> 
>   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
>   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
> `!bus->dma[0] && !bus->dma[1]' failed.
>   Aborted (core dumped)
> 
> The 40p machine type already creates the device i82374. If specified in the
> command line, it will try to create it again, hence generating the error. The
> function isa_bus_dma() isn't supposed to be called twice for the same bus. One
> way to avoid this problem is to set user_creatable=false.

Applied to -trivial, thanks!

/mjt



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-16 Thread Paolo Bonzini


- Original Message -
> From: "Eduardo Habkost" 
> To: "Paolo Bonzini" 
> Cc: "Eduardo Otubo" , qemu-devel@nongnu.org, 
> qemu-triv...@nongnu.org, "Michael Tokarev"
> , "Markus Armbruster" , "Alexander Graf" 
> 
> Sent: Saturday, September 16, 2017 12:21:13 AM
> Subject: Re: [PATCH] dma/i82374: avoid double creation of i82374 device
> 
> On Fri, Sep 15, 2017 at 12:18:11PM +0200, Paolo Bonzini wrote:
> > On 15/09/2017 11:06, Eduardo Otubo wrote:
> > > QEMU fails when used with the following command line:
> > > 
> > >   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device
> > >   i82374
> > >   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion
> > >   `!bus->dma[0] && !bus->dma[1]' failed.
> > >   Aborted (core dumped)
> > > 
> > > The 40p machine type already creates the device i82374. If specified in
> > > the
> > > command line, it will try to create it again, hence generating the error.
> > > The
> > > function isa_bus_dma() isn't supposed to be called twice for the same
> > > bus. One
> > > way to avoid this problem is to set user_creatable=false.
> > > 
> > > A possible fix in a near future would be making
> > > isa_bus_dma()/DMA_init()/i82374_realize() return an error instead of
> > > asserting
> > > as well.
> > > 
> > > Signed-off-by: Eduardo Otubo 
> > > ---
> > >  hw/dma/i82374.c | 5 +
> > >  1 file changed, 5 insertions(+)
> > > 
> > > diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> > > index 6c0f975df0..e76dea8dc7 100644
> > > --- a/hw/dma/i82374.c
> > > +++ b/hw/dma/i82374.c
> > > @@ -139,6 +139,11 @@ static void i82374_class_init(ObjectClass *klass,
> > > void *data)
> > >  dc->realize = i82374_realize;
> > >  dc->vmsd = _i82374;
> > >  dc->props = i82374_properties;
> > > +dc->user_creatable = false;
> > > +/*
> > > + * Reason: i82374_realize() crashes (assertion failure inside
> > > isa_bus_dma()
> > > + * if the device is instantiated twice.
> > > + */
> > >  }
> > >  
> > >  static const TypeInfo i82374_info = {
> > > 
> > 
> > This breaks "make check", doesn't it?
> 
> Why would it?  I don't see any test code using -device i82374.
> (endianness-test uses -device i82378).

You're right, both Aurelien and I were confused.  If you want to
accept this patch it would be fine then, even if giving an error may
be preferrable.

Paolo



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-15 Thread Eduardo Habkost
On Fri, Sep 15, 2017 at 12:18:11PM +0200, Paolo Bonzini wrote:
> On 15/09/2017 11:06, Eduardo Otubo wrote:
> > QEMU fails when used with the following command line:
> > 
> >   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
> >   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
> > `!bus->dma[0] && !bus->dma[1]' failed.
> >   Aborted (core dumped)
> > 
> > The 40p machine type already creates the device i82374. If specified in the
> > command line, it will try to create it again, hence generating the error. 
> > The
> > function isa_bus_dma() isn't supposed to be called twice for the same bus. 
> > One
> > way to avoid this problem is to set user_creatable=false.
> > 
> > A possible fix in a near future would be making
> > isa_bus_dma()/DMA_init()/i82374_realize() return an error instead of 
> > asserting
> > as well.
> > 
> > Signed-off-by: Eduardo Otubo 
> > ---
> >  hw/dma/i82374.c | 5 +
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> > index 6c0f975df0..e76dea8dc7 100644
> > --- a/hw/dma/i82374.c
> > +++ b/hw/dma/i82374.c
> > @@ -139,6 +139,11 @@ static void i82374_class_init(ObjectClass *klass, void 
> > *data)
> >  dc->realize = i82374_realize;
> >  dc->vmsd = _i82374;
> >  dc->props = i82374_properties;
> > +dc->user_creatable = false;
> > +/*
> > + * Reason: i82374_realize() crashes (assertion failure inside 
> > isa_bus_dma()
> > + * if the device is instantiated twice.
> > + */
> >  }
> >  
> >  static const TypeInfo i82374_info = {
> > 
> 
> This breaks "make check", doesn't it?

Why would it?  I don't see any test code using -device i82374.
(endianness-test uses -device i82378).

> 
> v2 should be the one that returns an error instead of asserting.

I agree that returning an error is better.

-- 
Eduardo



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-15 Thread Eduardo Otubo
On Fri, Sep 15, 2017 at 12:18:11PM +0200, Paolo Bonzini wrote:
> On 15/09/2017 11:06, Eduardo Otubo wrote:
> > QEMU fails when used with the following command line:
> > 
> >   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
> >   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
> > `!bus->dma[0] && !bus->dma[1]' failed.
> >   Aborted (core dumped)
> > 
> > The 40p machine type already creates the device i82374. If specified in the
> > command line, it will try to create it again, hence generating the error. 
> > The
> > function isa_bus_dma() isn't supposed to be called twice for the same bus. 
> > One
> > way to avoid this problem is to set user_creatable=false.
> > 
> > A possible fix in a near future would be making
> > isa_bus_dma()/DMA_init()/i82374_realize() return an error instead of 
> > asserting
> > as well.
> > 
> > Signed-off-by: Eduardo Otubo 
> > ---
> >  hw/dma/i82374.c | 5 +
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> > index 6c0f975df0..e76dea8dc7 100644
> > --- a/hw/dma/i82374.c
> > +++ b/hw/dma/i82374.c
> > @@ -139,6 +139,11 @@ static void i82374_class_init(ObjectClass *klass, void 
> > *data)
> >  dc->realize = i82374_realize;
> >  dc->vmsd = _i82374;
> >  dc->props = i82374_properties;
> > +dc->user_creatable = false;
> > +/*
> > + * Reason: i82374_realize() crashes (assertion failure inside 
> > isa_bus_dma()
> > + * if the device is instantiated twice.
> > + */
> >  }
> >  
> >  static const TypeInfo i82374_info = {
> > 
> 
> This breaks "make check", doesn't it?
> 
> v2 should be the one that returns an error instead of asserting.

I guess I have misunderstood, then. I'll work on a patch to propagate
the error then.

Thanks,

-- 
Eduardo Otubo
Senior Software Engineer @ RedHat



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-15 Thread Paolo Bonzini
On 15/09/2017 11:06, Eduardo Otubo wrote:
> QEMU fails when used with the following command line:
> 
>   ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
>   qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion 
> `!bus->dma[0] && !bus->dma[1]' failed.
>   Aborted (core dumped)
> 
> The 40p machine type already creates the device i82374. If specified in the
> command line, it will try to create it again, hence generating the error. The
> function isa_bus_dma() isn't supposed to be called twice for the same bus. One
> way to avoid this problem is to set user_creatable=false.
> 
> A possible fix in a near future would be making
> isa_bus_dma()/DMA_init()/i82374_realize() return an error instead of asserting
> as well.
> 
> Signed-off-by: Eduardo Otubo 
> ---
>  hw/dma/i82374.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> index 6c0f975df0..e76dea8dc7 100644
> --- a/hw/dma/i82374.c
> +++ b/hw/dma/i82374.c
> @@ -139,6 +139,11 @@ static void i82374_class_init(ObjectClass *klass, void 
> *data)
>  dc->realize = i82374_realize;
>  dc->vmsd = _i82374;
>  dc->props = i82374_properties;
> +dc->user_creatable = false;
> +/*
> + * Reason: i82374_realize() crashes (assertion failure inside 
> isa_bus_dma()
> + * if the device is instantiated twice.
> + */
>  }
>  
>  static const TypeInfo i82374_info = {
> 

This breaks "make check", doesn't it?

v2 should be the one that returns an error instead of asserting.

Paolo



[Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-15 Thread Eduardo Otubo
QEMU fails when used with the following command line:

  ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
  qemu-system-ppc64: hw/isa/isa-bus.c:110: isa_bus_dma: Assertion `!bus->dma[0] 
&& !bus->dma[1]' failed.
  Aborted (core dumped)

The 40p machine type already creates the device i82374. If specified in the
command line, it will try to create it again, hence generating the error. The
function isa_bus_dma() isn't supposed to be called twice for the same bus. One
way to avoid this problem is to set user_creatable=false.

A possible fix in a near future would be making
isa_bus_dma()/DMA_init()/i82374_realize() return an error instead of asserting
as well.

Signed-off-by: Eduardo Otubo 
---
 hw/dma/i82374.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
index 6c0f975df0..e76dea8dc7 100644
--- a/hw/dma/i82374.c
+++ b/hw/dma/i82374.c
@@ -139,6 +139,11 @@ static void i82374_class_init(ObjectClass *klass, void 
*data)
 dc->realize = i82374_realize;
 dc->vmsd = _i82374;
 dc->props = i82374_properties;
+dc->user_creatable = false;
+/*
+ * Reason: i82374_realize() crashes (assertion failure inside isa_bus_dma()
+ * if the device is instantiated twice.
+ */
 }
 
 static const TypeInfo i82374_info = {
-- 
2.13.5




Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-07 Thread Paolo Bonzini
Il 02 set 2017 11:17 AM, "Aurelien Jarno"  ha scritto:

On 2017-09-01 11:30, Eduardo Habkost wrote:
> i82374 is compiled in only on ppc and sh4, so I'm CCing the
> maintainers for those architectures.

The i82374 device is not useful nor usable on SH4. It has just been
added in commit 85d3846a39 to be able to run the tests.


But that means that the patch is wrong and probably was not tested with
"make check".

Eduardo's proposal is the right one.

Paolo


Aurelien

--
Aurelien Jarno  GPG: 4096R/1DDD8C9B
aurel...@aurel32.net http://www.aurel32.net


Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-02 Thread Aurelien Jarno
On 2017-09-01 11:30, Eduardo Habkost wrote:
> i82374 is compiled in only on ppc and sh4, so I'm CCing the
> maintainers for those architectures.

The i82374 device is not useful nor usable on SH4. It has just been
added in commit 85d3846a39 to be able to run the tests.

Aurelien

-- 
Aurelien Jarno  GPG: 4096R/1DDD8C9B
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-01 Thread Eduardo Habkost
On Fri, Sep 01, 2017 at 05:34:34PM +0200, Markus Armbruster wrote:
> Eduardo Habkost  writes:
> 
> > i82374 is compiled in only on ppc and sh4, so I'm CCing the
> > maintainers for those architectures.
> >
> > On Fri, Sep 01, 2017 at 01:03:32PM +0200, Eduardo Otubo wrote:
> >> When used with the following command line:
> >> 
> >>  ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
> >> 
> >> QEMU with machine type 40p already creates the device i82374. If
> >> specified in the command line, it will try to create it again, hence
> >> generating the error.
> >
> > Which error?
> >
> >
> >>   One way to avoid this problem is to set
> >> user_creatable=false.
> >> 
> >> Signed-off-by: Eduardo Otubo 
> >
> > The patch does more than just avoiding double creation: it
> > prevents usage of "-device i82374" completely.
> >
> > Maybe nobody needs it to work with -device today (would the
> > device even work?) and it is OK to set user_creatable=false until
> > we fix the crash.  But we need to be sure of that.
> >
> >> ---
> >>  hw/dma/i82374.c | 1 +
> >>  1 file changed, 1 insertion(+)
> >> 
> >> diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> >> index 6c0f975df0..5275d822e0 100644
> >> --- a/hw/dma/i82374.c
> >> +++ b/hw/dma/i82374.c
> >> @@ -139,6 +139,7 @@ static void i82374_class_init(ObjectClass *klass, void 
> >> *data)
> >>  dc->realize = i82374_realize;
> >>  dc->vmsd = _i82374;
> >>  dc->props = i82374_properties;
> >> +dc->user_creatable = false;
> >
> > A "Reason:" comment explaining why user_creatable=false is
> > mandatory.  See the comment above user_creatable declaration in
> > qdev-core.h for reference.
> >
> > I suggest the following:
> >
> > /*
> >  * Reason: i82374_realize() crashes (assertion failure inside 
> > isa_bus_dma()
> >  * if the device is instantiated twice.
> >  */
> 
> We need to find out *why* it crashes.  Once we know, we can likely write
> a better comment.

It crashes because isa_bus_dma() isn't supposed to be called
twice for the same bus.

Making isa_bus_dma()/DMA_init()/i82374_realize() return an error
instead of asserting would be even better than setting
user_creatable=false.

-- 
Eduardo



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-01 Thread Markus Armbruster
Eduardo Habkost  writes:

> i82374 is compiled in only on ppc and sh4, so I'm CCing the
> maintainers for those architectures.
>
> On Fri, Sep 01, 2017 at 01:03:32PM +0200, Eduardo Otubo wrote:
>> When used with the following command line:
>> 
>>  ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
>> 
>> QEMU with machine type 40p already creates the device i82374. If
>> specified in the command line, it will try to create it again, hence
>> generating the error.
>
> Which error?
>
>
>>   One way to avoid this problem is to set
>> user_creatable=false.
>> 
>> Signed-off-by: Eduardo Otubo 
>
> The patch does more than just avoiding double creation: it
> prevents usage of "-device i82374" completely.
>
> Maybe nobody needs it to work with -device today (would the
> device even work?) and it is OK to set user_creatable=false until
> we fix the crash.  But we need to be sure of that.
>
>> ---
>>  hw/dma/i82374.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
>> index 6c0f975df0..5275d822e0 100644
>> --- a/hw/dma/i82374.c
>> +++ b/hw/dma/i82374.c
>> @@ -139,6 +139,7 @@ static void i82374_class_init(ObjectClass *klass, void 
>> *data)
>>  dc->realize = i82374_realize;
>>  dc->vmsd = _i82374;
>>  dc->props = i82374_properties;
>> +dc->user_creatable = false;
>
> A "Reason:" comment explaining why user_creatable=false is
> mandatory.  See the comment above user_creatable declaration in
> qdev-core.h for reference.
>
> I suggest the following:
>
> /*
>  * Reason: i82374_realize() crashes (assertion failure inside 
> isa_bus_dma()
>  * if the device is instantiated twice.
>  */

We need to find out *why* it crashes.  Once we know, we can likely write
a better comment.



Re: [Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-01 Thread Eduardo Habkost
i82374 is compiled in only on ppc and sh4, so I'm CCing the
maintainers for those architectures.

On Fri, Sep 01, 2017 at 01:03:32PM +0200, Eduardo Otubo wrote:
> When used with the following command line:
> 
>  ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374
> 
> QEMU with machine type 40p already creates the device i82374. If
> specified in the command line, it will try to create it again, hence
> generating the error.

Which error?


>   One way to avoid this problem is to set
> user_creatable=false.
> 
> Signed-off-by: Eduardo Otubo 

The patch does more than just avoiding double creation: it
prevents usage of "-device i82374" completely.

Maybe nobody needs it to work with -device today (would the
device even work?) and it is OK to set user_creatable=false until
we fix the crash.  But we need to be sure of that.

> ---
>  hw/dma/i82374.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
> index 6c0f975df0..5275d822e0 100644
> --- a/hw/dma/i82374.c
> +++ b/hw/dma/i82374.c
> @@ -139,6 +139,7 @@ static void i82374_class_init(ObjectClass *klass, void 
> *data)
>  dc->realize = i82374_realize;
>  dc->vmsd = _i82374;
>  dc->props = i82374_properties;
> +dc->user_creatable = false;

A "Reason:" comment explaining why user_creatable=false is
mandatory.  See the comment above user_creatable declaration in
qdev-core.h for reference.

I suggest the following:

/*
 * Reason: i82374_realize() crashes (assertion failure inside isa_bus_dma()
 * if the device is instantiated twice.
 */

-- 
Eduardo



[Qemu-devel] [PATCH] dma/i82374: avoid double creation of i82374 device

2017-09-01 Thread Eduardo Otubo
When used with the following command line:

 ./ppc64-softmmu/qemu-system-ppc64 -S -machine 40p,accel=tcg -device i82374

QEMU with machine type 40p already creates the device i82374. If
specified in the command line, it will try to create it again, hence
generating the error. One way to avoid this problem is to set
user_creatable=false.

Signed-off-by: Eduardo Otubo 
---
 hw/dma/i82374.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
index 6c0f975df0..5275d822e0 100644
--- a/hw/dma/i82374.c
+++ b/hw/dma/i82374.c
@@ -139,6 +139,7 @@ static void i82374_class_init(ObjectClass *klass, void 
*data)
 dc->realize = i82374_realize;
 dc->vmsd = _i82374;
 dc->props = i82374_properties;
+dc->user_creatable = false;
 }
 
 static const TypeInfo i82374_info = {
-- 
2.13.5