qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] What's IOMMUMemoryRegion's super?
@ 2019-07-03  5:05 Markus Armbruster
  2019-07-03  5:37 ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2019-07-03  5:05 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexey Kardashevskiy, David Gibson, Daniel P. Berrangé,
	qemu-devel, Eduardo Habkost

The usual QOM boilerplate for defining a sub-{type,class} looks like
this:

    static const TypeInfo sysbus_device_type_info = {
        .name = TYPE_SYS_BUS_DEVICE,
        .parent = TYPE_DEVICE,
        .instance_size = sizeof(SysBusDevice),
        .abstract = true,
        .class_size = sizeof(SysBusDeviceClass),
        .class_init = sysbus_device_class_init,
    };

    typedef struct SysBusDeviceClass {
        /*< private >*/
        DeviceClass parent_class;
        [...]
    } SysBusDeviceClass;

    struct SysBusDevice {
        /*< private >*/
        DeviceState parent_obj;
        [...]
    };

Note the TypeInfo states the parent type (member @parent), and
associated class and instance structs (used members @instance_size and
@class_size) have the parent type's class and member struct as first
member.

This makes type casts to parent types work.  The checked QOM casts add
safety by checking it's actually a parent type.

Now consider TYPE_IOMMU_MEMORY_REGION:

    static const TypeInfo iommu_memory_region_info = {
        .parent             = TYPE_MEMORY_REGION,
        .name               = TYPE_IOMMU_MEMORY_REGION,
        .class_size         = sizeof(IOMMUMemoryRegionClass),
        .instance_size      = sizeof(IOMMUMemoryRegion),
        .instance_init      = iommu_memory_region_initfn,
        .abstract           = true,
    };

    typedef struct IOMMUMemoryRegionClass {
        /* private */
--->    struct DeviceClass parent_class;
        [...]
    };

    struct IOMMUMemoryRegion {
        MemoryRegion parent_obj;
        [...]
    };

The parent is TYPE_MEMORY_REGION, and the instance struct's first member is
TYPE_MEMORY_REGION's instance struct as I expect, but the class struct's
first member is something else entirely.

What's going on here?  Am I confused?

The commit message is of no help whatsoever:

    commit 1221a4746769f70231beab4db8da1c937e60340c
    Author: Alexey Kardashevskiy <aik@ozlabs.ru>
    Date:   Tue Jul 11 13:56:20 2017 +1000

        memory/iommu: introduce IOMMUMemoryRegionClass

        This finishes QOM'fication of IOMMUMemoryRegion by introducing
        a IOMMUMemoryRegionClass. This also provides a fastpath analog for
        IOMMU_MEMORY_REGION_GET_CLASS().

        This makes IOMMUMemoryRegion an abstract class.

        Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
        Message-Id: <20170711035620.4232-3-aik@ozlabs.ru>
        Acked-by: Cornelia Huck <cohuck@redhat.com>
        Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] What's IOMMUMemoryRegion's super?
  2019-07-03  5:05 [Qemu-devel] What's IOMMUMemoryRegion's super? Markus Armbruster
@ 2019-07-03  5:37 ` Paolo Bonzini
  2019-07-03  6:15   ` David Gibson
  2019-07-03 10:37   ` Markus Armbruster
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-07-03  5:37 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Alexey Kardashevskiy, David Gibson, Daniel P. Berrangé,
	qemu-devel, Eduardo Habkost

On 03/07/19 07:05, Markus Armbruster wrote:
>     static const TypeInfo iommu_memory_region_info = {
>         .parent             = TYPE_MEMORY_REGION,
>         .name               = TYPE_IOMMU_MEMORY_REGION,
>         .class_size         = sizeof(IOMMUMemoryRegionClass),
>         .instance_size      = sizeof(IOMMUMemoryRegion),
>         .instance_init      = iommu_memory_region_initfn,
>         .abstract           = true,
>     };
> 
>     typedef struct IOMMUMemoryRegionClass {
>         /* private */
> --->    struct DeviceClass parent_class;
>         [...]
>     };
> 
>     struct IOMMUMemoryRegion {
>         MemoryRegion parent_obj;
>         [...]
>     };
> 
> The parent is TYPE_MEMORY_REGION, and the instance struct's first member is
> TYPE_MEMORY_REGION's instance struct as I expect, but the class struct's
> first member is something else entirely.

Cut-and-paste error.  MemoryRegion adds no methods so that could be
either ObjectClass or better

    typedef struct MemoryRegionClass {
        /* private */
        ObjectClass parent_class;
    } ObjectClass;

Paolo


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] What's IOMMUMemoryRegion's super?
  2019-07-03  5:37 ` Paolo Bonzini
@ 2019-07-03  6:15   ` David Gibson
  2019-07-03 10:37   ` Markus Armbruster
  1 sibling, 0 replies; 4+ messages in thread
From: David Gibson @ 2019-07-03  6:15 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexey Kardashevskiy, Daniel P. Berrangé, Markus Armbruster,
	Eduardo Habkost, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1459 bytes --]

On Wed, Jul 03, 2019 at 07:37:46AM +0200, Paolo Bonzini wrote:
> On 03/07/19 07:05, Markus Armbruster wrote:
> >     static const TypeInfo iommu_memory_region_info = {
> >         .parent             = TYPE_MEMORY_REGION,
> >         .name               = TYPE_IOMMU_MEMORY_REGION,
> >         .class_size         = sizeof(IOMMUMemoryRegionClass),
> >         .instance_size      = sizeof(IOMMUMemoryRegion),
> >         .instance_init      = iommu_memory_region_initfn,
> >         .abstract           = true,
> >     };
> > 
> >     typedef struct IOMMUMemoryRegionClass {
> >         /* private */
> > --->    struct DeviceClass parent_class;
> >         [...]
> >     };
> > 
> >     struct IOMMUMemoryRegion {
> >         MemoryRegion parent_obj;
> >         [...]
> >     };
> > 
> > The parent is TYPE_MEMORY_REGION, and the instance struct's first member is
> > TYPE_MEMORY_REGION's instance struct as I expect, but the class struct's
> > first member is something else entirely.
> 
> Cut-and-paste error.  MemoryRegion adds no methods so that could be
> either ObjectClass or better
> 
>     typedef struct MemoryRegionClass {
>         /* private */
>         ObjectClass parent_class;
>     } ObjectClass;

I concur.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] What's IOMMUMemoryRegion's super?
  2019-07-03  5:37 ` Paolo Bonzini
  2019-07-03  6:15   ` David Gibson
@ 2019-07-03 10:37   ` Markus Armbruster
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2019-07-03 10:37 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexey Kardashevskiy, Daniel P. Berrangé, qemu-devel,
	Eduardo Habkost, David Gibson

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 03/07/19 07:05, Markus Armbruster wrote:
>>     static const TypeInfo iommu_memory_region_info = {
>>         .parent             = TYPE_MEMORY_REGION,
>>         .name               = TYPE_IOMMU_MEMORY_REGION,
>>         .class_size         = sizeof(IOMMUMemoryRegionClass),
>>         .instance_size      = sizeof(IOMMUMemoryRegion),
>>         .instance_init      = iommu_memory_region_initfn,
>>         .abstract           = true,
>>     };
>> 
>>     typedef struct IOMMUMemoryRegionClass {
>>         /* private */
>> --->    struct DeviceClass parent_class;
>>         [...]
>>     };
>> 
>>     struct IOMMUMemoryRegion {
>>         MemoryRegion parent_obj;
>>         [...]
>>     };
>> 
>> The parent is TYPE_MEMORY_REGION, and the instance struct's first member is
>> TYPE_MEMORY_REGION's instance struct as I expect, but the class struct's
>> first member is something else entirely.
>
> Cut-and-paste error.  MemoryRegion adds no methods so that could be

I wonder whether there's anything we could do to catch such errors
automatically.

> either ObjectClass or better
>
>     typedef struct MemoryRegionClass {
>         /* private */
>         ObjectClass parent_class;
>     } ObjectClass;

I'll prepare the patch.  Thanks!


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-03 13:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-03  5:05 [Qemu-devel] What's IOMMUMemoryRegion's super? Markus Armbruster
2019-07-03  5:37 ` Paolo Bonzini
2019-07-03  6:15   ` David Gibson
2019-07-03 10:37   ` Markus Armbruster

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).