From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V90Gj-0000vw-Eb for qemu-devel@nongnu.org; Mon, 12 Aug 2013 18:07:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V90Ge-0003Eu-EV for qemu-devel@nongnu.org; Mon, 12 Aug 2013 18:07:17 -0400 Message-ID: <1376345223.22121.14.camel@ul30vt.home> From: Alex Williamson Date: Mon, 12 Aug 2013 16:07:03 -0600 In-Reply-To: <1375863692-12207-7-git-send-email-aik@ozlabs.ru> References: <1375863692-12207-1-git-send-email-aik@ozlabs.ru> <1375863692-12207-7-git-send-email-aik@ozlabs.ru> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 6/8] spapr vfio: add vfio_container_spapr_get_info() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: Anthony Liguori , "Michael S . Tsirkin" , Alexander Graf , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Paul Mackerras , David Gibson On Wed, 2013-08-07 at 18:21 +1000, Alexey Kardashevskiy wrote: > As sPAPR platform supports DMA windows on a PCI bus, the information > about their location and size should be passed into the guest via > the device tree. > > The patch adds a helper to read this info from the container fd. > > Signed-off-by: Alexey Kardashevskiy > --- > hw/misc/vfio.c | 37 +++++++++++++++++++++++++++++++++++++ > include/hw/misc/vfio.h | 11 +++++++++++ > 2 files changed, 48 insertions(+) > create mode 100644 include/hw/misc/vfio.h > > diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c > index 3855efe..4571f64 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 > @@ -3488,3 +3489,39 @@ static void register_vfio_pci_dev_type(void) > } > > type_init(register_vfio_pci_dev_type) > + > +int vfio_container_spapr_get_info(AddressSpace *as, int32_t groupid, > + struct vfio_iommu_spapr_tce_info *info, > + int *group_fd) > +{ > + VFIOAddressSpace *space; > + VFIOGroup *group; > + VFIOContainer *container; > + int ret, fd; > + > + space = vfio_get_address_space(as); > + if (!space) { > + return -1; > + } > + group = vfio_get_group(groupid, space); > + if (!group) { > + return -1; > + } > + container = group->container; > + if (!group->container) { > + return -1; > + } > + fd = container->fd; > + if (!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IOMMU)) { > + return -1; > + } > + ret = ioctl(fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, info); > + if (ret) { > + error_report("vfio: failed to get iommu info for container: %s", > + strerror(errno)); > + return -1; > + } Doesn't this leak on all the exit paths if the address space and group don't exist yet? > + *group_fd = group->fd; > + > + return 0; > +} > diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h > new file mode 100644 > index 0000000..ac9a971 > --- /dev/null > +++ b/include/hw/misc/vfio.h > @@ -0,0 +1,11 @@ > +#ifndef VFIO_API_H > +#define VFIO_API_H > + > +#include "qemu/typedefs.h" > +#include > + > +extern int vfio_container_spapr_get_info(AddressSpace *as, int32_t groupid, > + struct vfio_iommu_spapr_tce_info *info, > + int *group_fd); > + > +#endif