diff mbox

[4/5] vfio: Move container list to DMAContext

Message ID 1366804881-553-5-git-send-email-david@gibson.dropbear.id.au
State New
Headers show

Commit Message

David Gibson April 24, 2013, 12:01 p.m. UTC
At the moment, vfio maintains a global list of containers that are assumed
to be more or less interchangeable, since they are all set up with a
MemoryListener to have all of system memory mapped.  However, that only
makes sense if all the containers are used on devices which really do
expect a dma address space identical to system memory.

This patch moves towards that by making the list of containers per
DMAContext (which corresponds to a dma address space) instead of global.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 dma-helpers.c          |    2 ++
 hw/misc/vfio.c         |   13 ++++++++-----
 include/hw/misc/vfio.h |   28 ++++++++++++++++++++++++++++
 include/sysemu/dma.h   |    2 ++
 stubs/Makefile.objs    |    1 +
 stubs/vfio.c           |    6 ++++++
 6 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 include/hw/misc/vfio.h
 create mode 100644 stubs/vfio.c

Comments

Alex Williamson April 24, 2013, 3:12 p.m. UTC | #1
On Wed, 2013-04-24 at 22:01 +1000, David Gibson wrote:
> At the moment, vfio maintains a global list of containers that are assumed
> to be more or less interchangeable, since they are all set up with a
> MemoryListener to have all of system memory mapped.  However, that only
> makes sense if all the containers are used on devices which really do
> expect a dma address space identical to system memory.
> 
> This patch moves towards that by making the list of containers per
> DMAContext (which corresponds to a dma address space) instead of global.

This seems like an unnecessary intrusion into common code.  Why not
create a vfio specific list of dma objects, each with a list of
containers?  Thanks,

Alex

> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  dma-helpers.c          |    2 ++
>  hw/misc/vfio.c         |   13 ++++++++-----
>  include/hw/misc/vfio.h |   28 ++++++++++++++++++++++++++++
>  include/sysemu/dma.h   |    2 ++
>  stubs/Makefile.objs    |    1 +
>  stubs/vfio.c           |    6 ++++++
>  6 files changed, 47 insertions(+), 5 deletions(-)
>  create mode 100644 include/hw/misc/vfio.h
>  create mode 100644 stubs/vfio.c
> 
> diff --git a/dma-helpers.c b/dma-helpers.c
> index 272632f..f0c7866 100644
> --- a/dma-helpers.c
> +++ b/dma-helpers.c
> @@ -11,6 +11,7 @@
>  #include "trace.h"
>  #include "qemu/range.h"
>  #include "qemu/thread.h"
> +#include "hw/misc/vfio.h"
>  
>  /* #define DEBUG_IOMMU */
>  
> @@ -386,6 +387,7 @@ void dma_context_init(DMAContext *dma, AddressSpace *as, DMATranslateFunc transl
>      dma->translate = translate;
>      dma->map = map;
>      dma->unmap = unmap;
> +    dma_context_init_vfio(dma);
>  }
>  
>  void *iommu_dma_memory_map(DMAContext *dma, dma_addr_t addr, dma_addr_t *len,
> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
> index f77a599..ab870a8 100644
> --- a/hw/misc/vfio.c
> +++ b/hw/misc/vfio.c
> @@ -39,6 +39,7 @@
>  #include "qemu/range.h"
>  #include "sysemu/kvm.h"
>  #include "sysemu/sysemu.h"
> +#include "hw/misc/vfio.h"
>  
>  /* #define DEBUG_VFIO */
>  #ifdef DEBUG_VFIO
> @@ -179,9 +180,6 @@ typedef struct VFIOGroup {
>  
>  #define MSIX_CAP_LENGTH 12
>  
> -static QLIST_HEAD(, VFIOContainer)
> -    container_list = QLIST_HEAD_INITIALIZER(container_list);
> -
>  static QLIST_HEAD(, VFIOGroup)
>      group_list = QLIST_HEAD_INITIALIZER(group_list);
>  
> @@ -2613,6 +2611,11 @@ static int vfio_load_rom(VFIODevice *vdev)
>      return 0;
>  }
>  
> +void dma_context_init_vfio(DMAContext *dma)
> +{
> +    QLIST_INIT(&dma->vfio.containers);
> +}
> +
>  static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
>  {
>      VFIOContainer *container;
> @@ -2628,7 +2631,7 @@ static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
>          }
>      }
>  
> -    QLIST_FOREACH(container, &container_list, next) {
> +    QLIST_FOREACH(container, &dma->vfio.containers, next) {
>          if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {
>              group->container = container;
>              QLIST_INSERT_HEAD(&container->group_list, group, container_next);
> @@ -2683,7 +2686,7 @@ static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
>      }
>  
>      QLIST_INIT(&container->group_list);
> -    QLIST_INSERT_HEAD(&container_list, container, next);
> +    QLIST_INSERT_HEAD(&dma->vfio.containers, container, next);
>  
>      group->container = container;
>      QLIST_INSERT_HEAD(&container->group_list, group, container_next);
> diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h
> new file mode 100644
> index 0000000..18fe144
> --- /dev/null
> +++ b/include/hw/misc/vfio.h
> @@ -0,0 +1,28 @@
> +/*
> + * vfio based device assignment
> + *
> + * Copyright 2013 David Gibson, IBM Corporation.
> + * Copyright Red Hat, Inc. 2012
> + *
> + * This work is licensed under the terms of the GNU GPL, version
> + * 2. See the COPYING file in the top-level directory.
> + */
> +#ifndef QEMU_VFIO_H
> +#define QEMU_VFIO_H
> +
> +#include "qemu/queue.h"
> +
> +typedef struct DMAContext DMAContext;
> +struct DMAContext;
> +
> +typedef struct VFIOContainer VFIOContainer;
> +struct VFIOContainer;
> +
> +typedef struct DMAContextVFIO DMAContextVFIO;
> +struct DMAContextVFIO {
> +    QLIST_HEAD(, VFIOContainer) containers;
> +};
> +
> +void dma_context_init_vfio(DMAContext *dma);
> +
> +#endif /* QEMU_VFIO_H */
> diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
> index a52c93a..8692d0a 100644
> --- a/include/sysemu/dma.h
> +++ b/include/sysemu/dma.h
> @@ -15,6 +15,7 @@
>  #include "hw/hw.h"
>  #include "block/block.h"
>  #include "sysemu/kvm.h"
> +#include "hw/misc/vfio.h"
>  
>  typedef struct DMAContext DMAContext;
>  typedef struct ScatterGatherEntry ScatterGatherEntry;
> @@ -66,6 +67,7 @@ struct DMAContext {
>      DMATranslateFunc *translate;
>      DMAMapFunc *map;
>      DMAUnmapFunc *unmap;
> +    DMAContextVFIO vfio;
>  };
>  
>  /* A global DMA context corresponding to the address_space_memory
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 9c55b34..858ca6b 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -20,6 +20,7 @@ stub-obj-y += reset.o
>  stub-obj-y += set-fd-handler.o
>  stub-obj-y += slirp.o
>  stub-obj-y += sysbus.o
> +stub-obj-y += vfio.o
>  stub-obj-y += vm-stop.o
>  stub-obj-y += vmstate.o
>  stub-obj-$(CONFIG_WIN32) += fd-register.o
> diff --git a/stubs/vfio.c b/stubs/vfio.c
> new file mode 100644
> index 0000000..6fe4a84
> --- /dev/null
> +++ b/stubs/vfio.c
> @@ -0,0 +1,6 @@
> +#include "hw/misc/vfio.h"
> +#include "sysemu/dma.h"
> +
> +void dma_context_init_vfio(DMAContext *dma)
> +{
> +}
Paolo Bonzini April 24, 2013, 4:33 p.m. UTC | #2
Il 24/04/2013 17:12, Alex Williamson ha scritto:
>> > At the moment, vfio maintains a global list of containers that are assumed
>> > to be more or less interchangeable, since they are all set up with a
>> > MemoryListener to have all of system memory mapped.  However, that only
>> > makes sense if all the containers are used on devices which really do
>> > expect a dma address space identical to system memory.
>> > 
>> > This patch moves towards that by making the list of containers per
>> > DMAContext (which corresponds to a dma address space) instead of global.
> This seems like an unnecessary intrusion into common code.  Why not
> create a vfio specific list of dma objects, each with a list of
> containers?  Thanks,

Yeah, I suggest that this is re-evaluated on top of the iommu patches.

You can find them at git://github.com/bonzini/qemu.git, branch iommu.
It seems to work with pseries, at least my guest crashes at the same
place with and without.  USB works, and so do VGA and spapr-vscsi.

Paolo
David Gibson April 25, 2013, 6:35 a.m. UTC | #3
On Wed, Apr 24, 2013 at 09:12:39AM -0600, Alex Williamson wrote:
> On Wed, 2013-04-24 at 22:01 +1000, David Gibson wrote:
> > At the moment, vfio maintains a global list of containers that are assumed
> > to be more or less interchangeable, since they are all set up with a
> > MemoryListener to have all of system memory mapped.  However, that only
> > makes sense if all the containers are used on devices which really do
> > expect a dma address space identical to system memory.
> > 
> > This patch moves towards that by making the list of containers per
> > DMAContext (which corresponds to a dma address space) instead of global.
> 
> This seems like an unnecessary intrusion into common code.  Why not
> create a vfio specific list of dma objects, each with a list of
> containers?  Thanks,

Possible, but ugly.  DMAContext *is* the handle for a DMA address
space.  Having a parallel array of VFIO contextns would be converting
from the generic handle to the VFIO one would be a search, rather than
just a dereference, and making sure the lifetime of the VFIO one
matches the lifetime of the generic object would be unnecessarily
awkward.

Which reminds me, I forgot to implement a VFIO hook for DMAContext
destruction in this patch.  That does need to be fixed.
David Gibson April 25, 2013, 6:36 a.m. UTC | #4
On Wed, Apr 24, 2013 at 06:33:33PM +0200, Paolo Bonzini wrote:
> Il 24/04/2013 17:12, Alex Williamson ha scritto:
> >> > At the moment, vfio maintains a global list of containers that are assumed
> >> > to be more or less interchangeable, since they are all set up with a
> >> > MemoryListener to have all of system memory mapped.  However, that only
> >> > makes sense if all the containers are used on devices which really do
> >> > expect a dma address space identical to system memory.
> >> > 
> >> > This patch moves towards that by making the list of containers per
> >> > DMAContext (which corresponds to a dma address space) instead of global.
> > This seems like an unnecessary intrusion into common code.  Why not
> > create a vfio specific list of dma objects, each with a list of
> > containers?  Thanks,
> 
> Yeah, I suggest that this is re-evaluated on top of the iommu patches.

> You can find them at git://github.com/bonzini/qemu.git, branch iommu.
> It seems to work with pseries, at least my guest crashes at the same
> place with and without.  USB works, and so do VGA and spapr-vscsi.

Ok, I'll have a look when I get a chance.  Any guesses as to when they
might reach mainline?
Paolo Bonzini April 26, 2013, 8:44 a.m. UTC | #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 25/04/2013 08:36, David Gibson ha scritto:
> On Wed, Apr 24, 2013 at 06:33:33PM +0200, Paolo Bonzini wrote:
>> Il 24/04/2013 17:12, Alex Williamson ha scritto:
>>>>> At the moment, vfio maintains a global list of containers
>>>>> that are assumed to be more or less interchangeable, since
>>>>> they are all set up with a MemoryListener to have all of
>>>>> system memory mapped.  However, that only makes sense if
>>>>> all the containers are used on devices which really do 
>>>>> expect a dma address space identical to system memory.
>>>>> 
>>>>> This patch moves towards that by making the list of
>>>>> containers per DMAContext (which corresponds to a dma
>>>>> address space) instead of global.
>>> This seems like an unnecessary intrusion into common code.  Why
>>> not create a vfio specific list of dma objects, each with a
>>> list of containers?  Thanks,
>> 
>> Yeah, I suggest that this is re-evaluated on top of the iommu
>> patches.
> 
>> You can find them at git://github.com/bonzini/qemu.git, branch
>> iommu. It seems to work with pseries, at least my guest crashes
>> at the same place with and without.  USB works, and so do VGA and
>> spapr-vscsi.
> 
> Ok, I'll have a look when I get a chance.  Any guesses as to when
> they might reach mainline?

If I get your Tested-by, early in 1.6.

Paolo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRej5jAAoJEBvWZb6bTYby6I0P/1lUAJhlrZ3mJ7h3HOK/Hee4
3U+csDnpp9kBkkoueWcfg/u5FCEIQ5MDII4/qvcJ6onLB6kp6cTyU5KRUQEFw+SF
er/CfC3bIIo1wz3Ze6l9shOLa4bqiCawBGA5+dRKzh9KWuNwFmmkWjbUNBEgNcnb
0Iz2/jdL6KWEE8a7brCchJZpv6Ib0AhDMEp1wf6OwdJOWQx6BbLSr/SzFTb3/Wgs
JOawqd6Dd/O45E+b0rDkXoF2Fit/XvrBSm0Hju8zvT3XnWeJxIMEiFroJIN053F2
/QHPWoF/xLRnP1JPhxiudSHZCKOMxQn/XBYa+olxt4MhRzEU+0F3bgUY19+sjfbh
OAgtB5icjTP+gFPC2mw3wZZnHJ6Q0bWkLOSmQ4UXpcv88ZagJUDUTCiAWp2dPYnE
czKLUC5IB1KAp8AWb3dqiym/BpDPuO0s/15t19e2/qJOZKU4PDQJD9hSnnbcYwRN
dVMQWVpxKro2cZUXV6NbAhNXIdfM4WCdRDUDtRssAeaVOG5iiwdr481PC90+o7O1
gLLfKfsMytHflKwCre9ew6o+obwHXvSLbliou0kJAY0iuYyoAogu6zq4Eu+i+ia7
28JX5qpI/hRebacIKDryc0xGHGah06JHMLdITF7rLqH9fVg2X1Mz+4FAGwjUmO+m
+23q7kaLcfBMjmKKfS3O
=FkrW
-----END PGP SIGNATURE-----
Alexey Kardashevskiy April 26, 2013, 8:46 a.m. UTC | #6
On 04/26/2013 06:44 PM, Paolo Bonzini wrote:

> Il 25/04/2013 08:36, David Gibson ha scritto:
>> On Wed, Apr 24, 2013 at 06:33:33PM +0200, Paolo Bonzini wrote:
>>> Il 24/04/2013 17:12, Alex Williamson ha scritto:
>>>>>> At the moment, vfio maintains a global list of containers
>>>>>> that are assumed to be more or less interchangeable, since
>>>>>> they are all set up with a MemoryListener to have all of
>>>>>> system memory mapped.  However, that only makes sense if
>>>>>> all the containers are used on devices which really do
>>>>>> expect a dma address space identical to system memory.
>>>>>>
>>>>>> This patch moves towards that by making the list of
>>>>>> containers per DMAContext (which corresponds to a dma
>>>>>> address space) instead of global.
>>>> This seems like an unnecessary intrusion into common code.  Why
>>>> not create a vfio specific list of dma objects, each with a
>>>> list of containers?  Thanks,
>>>
>>> Yeah, I suggest that this is re-evaluated on top of the iommu
>>> patches.
>>
>>> You can find them at git://github.com/bonzini/qemu.git, branch
>>> iommu. It seems to work with pseries, at least my guest crashes
>>> at the same place with and without.  USB works, and so do VGA and
>>> spapr-vscsi.
>>
>> Ok, I'll have a look when I get a chance.  Any guesses as to when
>> they might reach mainline?
>
> If I get your Tested-by, early in 1.6.


Emulated PCI works on ppc64/spapr so far.
Paolo Bonzini April 26, 2013, 8:52 a.m. UTC | #7
Il 26/04/2013 10:46, Alexey Kardashevskiy ha scritto:
> On 04/26/2013 06:44 PM, Paolo Bonzini wrote:
>> Il 25/04/2013 08:36, David Gibson ha scritto:
>>> On Wed, Apr 24, 2013 at 06:33:33PM +0200, Paolo Bonzini wrote:
>>>> Il 24/04/2013 17:12, Alex Williamson ha scritto:
>>>>>>> At the moment, vfio maintains a global list of containers
>>>>>>> that are assumed to be more or less interchangeable, since
>>>>>>> they are all set up with a MemoryListener to have all of
>>>>>>> system memory mapped.  However, that only makes sense if
>>>>>>> all the containers are used on devices which really do
>>>>>>> expect a dma address space identical to system memory.
>>>>>>>
>>>>>>> This patch moves towards that by making the list of
>>>>>>> containers per DMAContext (which corresponds to a dma
>>>>>>> address space) instead of global.
>>>>> This seems like an unnecessary intrusion into common code.  Why
>>>>> not create a vfio specific list of dma objects, each with a
>>>>> list of containers?  Thanks,
>>>>
>>>> Yeah, I suggest that this is re-evaluated on top of the iommu
>>>> patches.
>>>
>>>> You can find them at git://github.com/bonzini/qemu.git, branch
>>>> iommu. It seems to work with pseries, at least my guest crashes
>>>> at the same place with and without.  USB works, and so do VGA and
>>>> spapr-vscsi.
>>>
>>> Ok, I'll have a look when I get a chance.  Any guesses as to when
>>> they might reach mainline?
>>
>> If I get your Tested-by, early in 1.6.
> 
> Emulated PCI works on ppc64/spapr so far.

What about VIO?  Doesn't it go through the IOMMU as well?  I'm sure you
can test it more than I did (it did break in Avi's original patches, so
it must not be that bad...).

Paolo
Alexey Kardashevskiy April 26, 2013, 8:56 a.m. UTC | #8
On 04/26/2013 06:52 PM, Paolo Bonzini wrote:
> Il 26/04/2013 10:46, Alexey Kardashevskiy ha scritto:
>> On 04/26/2013 06:44 PM, Paolo Bonzini wrote:
>>> Il 25/04/2013 08:36, David Gibson ha scritto:
>>>> On Wed, Apr 24, 2013 at 06:33:33PM +0200, Paolo Bonzini wrote:
>>>>> Il 24/04/2013 17:12, Alex Williamson ha scritto:
>>>>>>>> At the moment, vfio maintains a global list of containers
>>>>>>>> that are assumed to be more or less interchangeable, since
>>>>>>>> they are all set up with a MemoryListener to have all of
>>>>>>>> system memory mapped.  However, that only makes sense if
>>>>>>>> all the containers are used on devices which really do
>>>>>>>> expect a dma address space identical to system memory.
>>>>>>>>
>>>>>>>> This patch moves towards that by making the list of
>>>>>>>> containers per DMAContext (which corresponds to a dma
>>>>>>>> address space) instead of global.
>>>>>> This seems like an unnecessary intrusion into common code.  Why
>>>>>> not create a vfio specific list of dma objects, each with a
>>>>>> list of containers?  Thanks,
>>>>>
>>>>> Yeah, I suggest that this is re-evaluated on top of the iommu
>>>>> patches.
>>>>
>>>>> You can find them at git://github.com/bonzini/qemu.git, branch
>>>>> iommu. It seems to work with pseries, at least my guest crashes
>>>>> at the same place with and without.  USB works, and so do VGA and
>>>>> spapr-vscsi.
>>>>
>>>> Ok, I'll have a look when I get a chance.  Any guesses as to when
>>>> they might reach mainline?
>>>
>>> If I get your Tested-by, early in 1.6.
>>
>> Emulated PCI works on ppc64/spapr so far.
>
> What about VIO?  Doesn't it go through the IOMMU as well?  I'm sure you
> can test it more than I did (it did break in Avi's original patches, so
> it must not be that bad...).


I run QEMU with
-net nic,model=ibmveth -net user,hostfwd=tcp::5000-:22
and run in the guest: "dhclient ; wget google.com" which worked fine. When 
it damaged, it does not go further than dhclient :)
Paolo Bonzini April 26, 2013, 9:08 a.m. UTC | #9
Il 26/04/2013 10:56, Alexey Kardashevskiy ha scritto:
> On 04/26/2013 06:52 PM, Paolo Bonzini wrote:
>> Il 26/04/2013 10:46, Alexey Kardashevskiy ha scritto:
>>> On 04/26/2013 06:44 PM, Paolo Bonzini wrote:
>>>> Il 25/04/2013 08:36, David Gibson ha scritto:
>>>>> On Wed, Apr 24, 2013 at 06:33:33PM +0200, Paolo Bonzini wrote:
>>>>>> Il 24/04/2013 17:12, Alex Williamson ha scritto:
>>>>>>>>> At the moment, vfio maintains a global list of containers
>>>>>>>>> that are assumed to be more or less interchangeable, since
>>>>>>>>> they are all set up with a MemoryListener to have all of
>>>>>>>>> system memory mapped.  However, that only makes sense if
>>>>>>>>> all the containers are used on devices which really do
>>>>>>>>> expect a dma address space identical to system memory.
>>>>>>>>>
>>>>>>>>> This patch moves towards that by making the list of
>>>>>>>>> containers per DMAContext (which corresponds to a dma
>>>>>>>>> address space) instead of global.
>>>>>>> This seems like an unnecessary intrusion into common code.  Why
>>>>>>> not create a vfio specific list of dma objects, each with a
>>>>>>> list of containers?  Thanks,
>>>>>>
>>>>>> Yeah, I suggest that this is re-evaluated on top of the iommu
>>>>>> patches.
>>>>>
>>>>>> You can find them at git://github.com/bonzini/qemu.git, branch
>>>>>> iommu. It seems to work with pseries, at least my guest crashes
>>>>>> at the same place with and without.  USB works, and so do VGA and
>>>>>> spapr-vscsi.
>>>>>
>>>>> Ok, I'll have a look when I get a chance.  Any guesses as to when
>>>>> they might reach mainline?
>>>>
>>>> If I get your Tested-by, early in 1.6.
>>>
>>> Emulated PCI works on ppc64/spapr so far.
>>
>> What about VIO?  Doesn't it go through the IOMMU as well?  I'm sure you
>> can test it more than I did (it did break in Avi's original patches, so
>> it must not be that bad...).
> 
> I run QEMU with
> -net nic,model=ibmveth -net user,hostfwd=tcp::5000-:22
> and run in the guest: "dhclient ; wget google.com" which worked fine.
> When it damaged, it does not go further than dhclient :)

Ok, that counts as a Tested-by from you, I guess.

Paolo
diff mbox

Patch

diff --git a/dma-helpers.c b/dma-helpers.c
index 272632f..f0c7866 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -11,6 +11,7 @@ 
 #include "trace.h"
 #include "qemu/range.h"
 #include "qemu/thread.h"
+#include "hw/misc/vfio.h"
 
 /* #define DEBUG_IOMMU */
 
@@ -386,6 +387,7 @@  void dma_context_init(DMAContext *dma, AddressSpace *as, DMATranslateFunc transl
     dma->translate = translate;
     dma->map = map;
     dma->unmap = unmap;
+    dma_context_init_vfio(dma);
 }
 
 void *iommu_dma_memory_map(DMAContext *dma, dma_addr_t addr, dma_addr_t *len,
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index f77a599..ab870a8 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -39,6 +39,7 @@ 
 #include "qemu/range.h"
 #include "sysemu/kvm.h"
 #include "sysemu/sysemu.h"
+#include "hw/misc/vfio.h"
 
 /* #define DEBUG_VFIO */
 #ifdef DEBUG_VFIO
@@ -179,9 +180,6 @@  typedef struct VFIOGroup {
 
 #define MSIX_CAP_LENGTH 12
 
-static QLIST_HEAD(, VFIOContainer)
-    container_list = QLIST_HEAD_INITIALIZER(container_list);
-
 static QLIST_HEAD(, VFIOGroup)
     group_list = QLIST_HEAD_INITIALIZER(group_list);
 
@@ -2613,6 +2611,11 @@  static int vfio_load_rom(VFIODevice *vdev)
     return 0;
 }
 
+void dma_context_init_vfio(DMAContext *dma)
+{
+    QLIST_INIT(&dma->vfio.containers);
+}
+
 static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
 {
     VFIOContainer *container;
@@ -2628,7 +2631,7 @@  static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
         }
     }
 
-    QLIST_FOREACH(container, &container_list, next) {
+    QLIST_FOREACH(container, &dma->vfio.containers, next) {
         if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {
             group->container = container;
             QLIST_INSERT_HEAD(&container->group_list, group, container_next);
@@ -2683,7 +2686,7 @@  static int vfio_connect_context(VFIOGroup *group, DMAContext *dma)
     }
 
     QLIST_INIT(&container->group_list);
-    QLIST_INSERT_HEAD(&container_list, container, next);
+    QLIST_INSERT_HEAD(&dma->vfio.containers, container, next);
 
     group->container = container;
     QLIST_INSERT_HEAD(&container->group_list, group, container_next);
diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h
new file mode 100644
index 0000000..18fe144
--- /dev/null
+++ b/include/hw/misc/vfio.h
@@ -0,0 +1,28 @@ 
+/*
+ * vfio based device assignment
+ *
+ * Copyright 2013 David Gibson, IBM Corporation.
+ * Copyright Red Hat, Inc. 2012
+ *
+ * This work is licensed under the terms of the GNU GPL, version
+ * 2. See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_VFIO_H
+#define QEMU_VFIO_H
+
+#include "qemu/queue.h"
+
+typedef struct DMAContext DMAContext;
+struct DMAContext;
+
+typedef struct VFIOContainer VFIOContainer;
+struct VFIOContainer;
+
+typedef struct DMAContextVFIO DMAContextVFIO;
+struct DMAContextVFIO {
+    QLIST_HEAD(, VFIOContainer) containers;
+};
+
+void dma_context_init_vfio(DMAContext *dma);
+
+#endif /* QEMU_VFIO_H */
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index a52c93a..8692d0a 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -15,6 +15,7 @@ 
 #include "hw/hw.h"
 #include "block/block.h"
 #include "sysemu/kvm.h"
+#include "hw/misc/vfio.h"
 
 typedef struct DMAContext DMAContext;
 typedef struct ScatterGatherEntry ScatterGatherEntry;
@@ -66,6 +67,7 @@  struct DMAContext {
     DMATranslateFunc *translate;
     DMAMapFunc *map;
     DMAUnmapFunc *unmap;
+    DMAContextVFIO vfio;
 };
 
 /* A global DMA context corresponding to the address_space_memory
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 9c55b34..858ca6b 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -20,6 +20,7 @@  stub-obj-y += reset.o
 stub-obj-y += set-fd-handler.o
 stub-obj-y += slirp.o
 stub-obj-y += sysbus.o
+stub-obj-y += vfio.o
 stub-obj-y += vm-stop.o
 stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
diff --git a/stubs/vfio.c b/stubs/vfio.c
new file mode 100644
index 0000000..6fe4a84
--- /dev/null
+++ b/stubs/vfio.c
@@ -0,0 +1,6 @@ 
+#include "hw/misc/vfio.h"
+#include "sysemu/dma.h"
+
+void dma_context_init_vfio(DMAContext *dma)
+{
+}