All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Juan Quintela <quintela@redhat.com>
Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups
Date: Sun, 21 Mar 2010 21:51:43 -0500	[thread overview]
Message-ID: <4BA6DB3F.7010702@codemonkey.ws> (raw)
In-Reply-To: <m339ztp3kr.fsf@trasno.mitica>

On 03/21/2010 08:06 PM, Juan Quintela wrote:
> "Michael S. Tsirkin"<mst@redhat.com>  wrote:
>    
>> On Sun, Mar 21, 2010 at 06:11:43PM +0000, Jamie Lokier wrote:
>>      
>>> Michael S. Tsirkin wrote:
>>>        
>>>> That's version 1 of my patch. Version 2 removed even need for macro
>>>> completely by moving allocations to the caller.
>>>>          
>>> The downside of moving allocations are: (1) it's one more call in the
>>> caller, to allocate the type, (2) it needs a virtual destructor for
>>> each type to free the object, which can clutter the code if there is
>>> no other reason for virtual destructors.
>>>
>>> I don't think those are necessarily bad, but they can remove from the
>>> neatness of existing code.  Personally I favour an occasional macro
>>> using sizeof/offsetof/container_of if the result is a natural and
>>> sensible API to all of its callers.
>>>
>>> -- Jamie
>>>        
>> We need to free in caller anyway because structure is used
>> after cleanup. This can be changed by restructuring code ...
>> I don't have a strong preference, anything is better
>> than the hack relying on field being at offset 0 in structure.
>>      
> It is not a hack.
>
> Is the only sane way of sharing virtio common field without having to
> export all virtio particular structs :(
>
> I really hate how this is going :(
>
> a- we have code that assumes that virtio is the 1st element of all
>     virtio structs.
>
> b- we have a patch that codifies that virtio is used in that way (using
>     DO_UPCAST()) (me)
>
> c- we arrived to the point where being it at the beggining of the struct
>     is the bigger cast in the universe (I present everybody thinking that
>     to look at rest of qemu).  Patch is done that makes it possible to
>     alloc memory outside of virtio_common_init().  No code on virtio.c or
>     virtio-pci.c is changed to use this new offset.  (michael).
>
> d- Anthony arrives to the discussion stating that it should exist a
>     VirtIOPCIBus, that way virtio devices should be hanging of that bus
>     (that requires lots of changes).
>
> e- kraxel arrives to the discussion stating that initializing in the
>     middle of one struct is the right thing to do, except if you are
>     qdev, that then it is not.  I point to his suggestion that it makes
>     things still uglier (no answer yet, but it was weekend for him).
>
> f- I show using kraxel example how ugly things go (sizeof (struct A) +
>     sizeof (struct B) - sizeof (struct C)).  And here is when things fall
>     apart IMHO.  Michael states that it is ok to have to had:
>      - an offset field
>      - a pointer in one struct to inside the same struct (vdev)
>     but assuming and stating and using an offset 0 is ugly.
>
> Have I lost anything?  Is there a realistic way of getting struct
> VirtIODevice (and VirtIOBlock, ...) inside VirtIOPCIProxy that don't
> imply using an offset + a pointer + exporting the struct definitions
> only to calculate its size?
>    

The object model is wrong.

A VirtIOBlock device cannot be a VirtIODevice while being a 
VirtIOPCIProxy (proxy is a poor name, btw).

It really ought to be:

DeviceState -> VirtIODevice -> VirtIOBlock

and:

PCIDevice -> VirtIOPCI : implements VirtIOBus

The interface between the VirtIODevice and VirtIOBus is the virtio 
transport.

The main reason a separate bus is needed is the same reason it's needed 
in Linux.  VirtIOBlock has to be tied to some bus.  It cannot be tied to 
the PCI bus without having it be part of the implementation detail.  
Introducing another bus type fixes this (and it's what we do in the kernel).

With respect to save and restore, there really ought to be two separate 
sections.  One section containing just virtio information and another 
section that stores the PCI state.  Admittedly, that's going to be a 
tough change to make but it's the proper approach.

Regards,

Anthony Liguori

  reply	other threads:[~2010-03-22  2:51 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-16 18:51 [Qemu-devel] [PATCH 0/9] Virtio cleanups Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 1/9] qemu/pci: document msix_entries_nr field Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 2/9] virtio: Teach virtio-balloon about DO_UPCAST Juan Quintela
2010-03-18  7:29   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 3/9] virtio: Teach virtio-blk " Juan Quintela
2010-03-18  7:29   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 4/9] virtio: Teach virtio-net " Juan Quintela
2010-03-18  7:29   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 5/9] virtio: Use DO_UPCAST instead of a cast Juan Quintela
2010-03-18  7:30   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 6/9] virtio-pci: Remove duplicate test Juan Quintela
2010-03-18  7:25   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-18  8:26     ` Juan Quintela
2010-03-18  8:47       ` Michael S. Tsirkin
2010-03-18  8:59         ` Juan Quintela
2010-03-18  9:11           ` Michael S. Tsirkin
2010-03-18 11:40             ` Juan Quintela
2010-03-18 13:24               ` Michael S. Tsirkin
2010-03-18 13:47                 ` Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 7/9] QLIST: Introduce QLIST_COPY_HEAD Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 8/9] virtio-blk: change rq type to VirtIOBlockReq Juan Quintela
2010-03-18  7:27   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 9/9] virtio-blk: use QLIST for the list of requests Juan Quintela
2010-03-18  6:40 ` [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups Michael S. Tsirkin
2010-03-18  7:36   ` Juan Quintela
2010-03-18  7:42     ` Michael S. Tsirkin
2010-03-18  8:36       ` Juan Quintela
2010-03-18  9:07         ` Michael S. Tsirkin
2010-03-18 11:53           ` Juan Quintela
2010-03-18 12:33             ` Michael S. Tsirkin
2010-03-18 13:43               ` Juan Quintela
2010-03-18 13:47                 ` Michael S. Tsirkin
2010-03-18 14:21                   ` Juan Quintela
2010-03-18 17:13                     ` Michael S. Tsirkin
2010-03-19  1:41             ` Jamie Lokier
2010-03-21 14:31               ` Michael S. Tsirkin
2010-03-21 18:11                 ` Jamie Lokier
2010-03-21 19:16                   ` Michael S. Tsirkin
2010-03-22  1:06                     ` Juan Quintela
2010-03-22  2:51                       ` Anthony Liguori [this message]
2010-03-22 13:30                         ` Paul Brook
2010-03-22 14:49                           ` Anthony Liguori
2010-03-22 14:50                             ` Michael S. Tsirkin
2010-03-22 15:03                               ` Anthony Liguori
2010-03-22 15:17                                 ` Michael S. Tsirkin
2010-03-22 15:50                                   ` Anthony Liguori
2010-03-22 16:16                                     ` Paul Brook
2010-03-22 18:48                                       ` Anthony Liguori
2010-03-22 21:00                                         ` Paul Brook
2010-03-23  1:13                                           ` Anthony Liguori
2010-03-22 15:51                                   ` Paul Brook
2010-03-22 17:19                                     ` Michael S. Tsirkin
2010-03-22 22:16                                       ` Juan Quintela
2010-03-23  0:49                                         ` Paul Brook
2010-03-23  1:16                                           ` Anthony Liguori
2010-03-23 10:47                                             ` Michael S. Tsirkin
2010-03-23 11:11                                               ` Gerd Hoffmann
2010-03-23 11:40                                               ` Paul Brook
2010-03-23 11:58                                                 ` Michael S. Tsirkin
2010-03-23 12:32                                                   ` Juan Quintela
2010-03-21 19:57                   ` Michael S. Tsirkin
2010-03-22  1:13                     ` Juan Quintela
2010-03-22  8:37                       ` Michael S. Tsirkin
2010-03-18 10:05         ` Michael S. Tsirkin
2010-03-18 15:43     ` Gerd Hoffmann
2010-03-18 16:20       ` Juan Quintela
2010-03-18 16:36         ` Gerd Hoffmann
2010-03-18 17:08           ` Juan Quintela
2010-03-18 17:21             ` Michael S. Tsirkin
2010-03-18 19:37               ` Juan Quintela
2010-03-18 20:07           ` Anthony Liguori

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=4BA6DB3F.7010702@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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.