From patchwork Thu Jan 29 09:27:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 434457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 50B451401F0 for ; Thu, 29 Jan 2015 20:38:08 +1100 (AEDT) Received: from localhost ([::1]:58496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGlY6-0004gF-I9 for incoming@patchwork.ozlabs.org; Thu, 29 Jan 2015 04:38:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGlOD-0005YZ-U2 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 04:28:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGlO5-0004HH-PM for qemu-devel@nongnu.org; Thu, 29 Jan 2015 04:27:53 -0500 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:58353) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGlO5-0004Es-21 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 04:27:45 -0500 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 29 Jan 2015 19:27:43 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 29 Jan 2015 19:27:41 +1000 Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 145762BB0047; Thu, 29 Jan 2015 20:27:41 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t0T9RYki43909216; Thu, 29 Jan 2015 20:27:34 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t0T9RdG4001386; Thu, 29 Jan 2015 20:27:39 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t0T9RWjZ000944; Thu, 29 Jan 2015 20:27:39 +1100 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.253.15]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 8165FA03B0; Thu, 29 Jan 2015 20:27:40 +1100 (AEDT) Received: from ka1.ozlabs.ibm.com (ka1.ozlabs.ibm.com [10.61.145.11]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id C359B16A9D1; Thu, 29 Jan 2015 20:27:39 +1100 (AEDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Thu, 29 Jan 2015 20:27:27 +1100 Message-Id: <1422523650-2888-16-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1422523650-2888-1-git-send-email-aik@ozlabs.ru> References: <1422523650-2888-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15012909-1618-0000-0000-0000018732FF X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.143 Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, Alexander Graf , David Gibson Subject: [Qemu-devel] [PATCH v4 15/18] spapr_pci_vfio: Enable multiple groups per container X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This enables multiple IOMMU groups in one VFIO container which means that multiple devices from different groups can share the same IOMMU table and locked pages counting can be done once as there is no need to have several containers for two or more groups. This removes a group id from vfio_container_ioctl(). The kernel support is required for this. This adds a check that there is just one VFIO container per PHB address space. Signed-off-by: Alexey Kardashevskiy --- hw/ppc/spapr_pci_vfio.c | 9 +++------ hw/vfio/common.c | 33 +++++++++++++++------------------ include/hw/vfio/vfio.h | 2 +- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c index b20ac90..257181d 100644 --- a/hw/ppc/spapr_pci_vfio.c +++ b/hw/ppc/spapr_pci_vfio.c @@ -33,11 +33,10 @@ static int spapr_pci_vfio_ddw_query(sPAPRPHBState *sphb, uint32_t *dma32_window_size, uint64_t *dma64_window_size) { - sPAPRPHBVFIOState *svphb = SPAPR_PCI_VFIO_HOST_BRIDGE(sphb); struct vfio_iommu_spapr_tce_info info = { .argsz = sizeof(info) }; int ret; - ret = vfio_container_ioctl(&sphb->iommu_as, svphb->iommugroupid, + ret = vfio_container_ioctl(&sphb->iommu_as, VFIO_IOMMU_SPAPR_TCE_GET_INFO, &info); if (ret) { return ret; @@ -55,7 +54,6 @@ static int spapr_pci_vfio_ddw_create(sPAPRPHBState *sphb, uint32_t liobn, uint32_t page_shift, uint32_t window_shift, sPAPRTCETable **ptcet) { - sPAPRPHBVFIOState *svphb = SPAPR_PCI_VFIO_HOST_BRIDGE(sphb); struct vfio_iommu_spapr_tce_create create = { .argsz = sizeof(create), .page_shift = page_shift, @@ -65,7 +63,7 @@ static int spapr_pci_vfio_ddw_create(sPAPRPHBState *sphb, uint32_t liobn, }; int ret; - ret = vfio_container_ioctl(&sphb->iommu_as, svphb->iommugroupid, + ret = vfio_container_ioctl(&sphb->iommu_as, VFIO_IOMMU_SPAPR_TCE_CREATE, &create); if (ret) { return ret; @@ -87,7 +85,6 @@ static int spapr_pci_vfio_ddw_create(sPAPRPHBState *sphb, uint32_t liobn, static int spapr_pci_vfio_ddw_remove(sPAPRPHBState *sphb, sPAPRTCETable *tcet) { - sPAPRPHBVFIOState *svphb = SPAPR_PCI_VFIO_HOST_BRIDGE(sphb); struct vfio_iommu_spapr_tce_remove remove = { .argsz = sizeof(remove), .start_addr = tcet->bus_offset @@ -95,7 +92,7 @@ static int spapr_pci_vfio_ddw_remove(sPAPRPHBState *sphb, sPAPRTCETable *tcet) int ret; spapr_pci_ddw_remove(sphb, tcet); - ret = vfio_container_ioctl(&sphb->iommu_as, svphb->iommugroupid, + ret = vfio_container_ioctl(&sphb->iommu_as, VFIO_IOMMU_SPAPR_TCE_REMOVE, &remove); return ret; diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 1cafcf8..a26cbae 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1011,34 +1011,31 @@ void vfio_put_base_device(VFIODevice *vbasedev) close(vbasedev->fd); } -static int vfio_container_do_ioctl(AddressSpace *as, int32_t groupid, +static int vfio_container_do_ioctl(AddressSpace *as, int req, void *param) { - VFIOGroup *group; VFIOContainer *container; - int ret = -1; + int ret; + VFIOAddressSpace *space; - group = vfio_get_group(groupid, as); - if (!group) { - error_report("vfio: group %d not registered", groupid); - return ret; - } + space = vfio_get_address_space(as); + container = QLIST_FIRST(&space->containers); - container = group->container; - if (group->container) { - ret = ioctl(container->fd, req, param); - if (ret < 0) { - error_report("vfio: failed to ioctl container: ret=%d, %s", - ret, strerror(errno)); - } + if (!container || QLIST_NEXT(container, next)) { + error_report("vfio: multiple containers per PHB are not supported"); + return -1; } - vfio_put_group(group); + ret = ioctl(container->fd, req, param); + if (ret < 0) { + error_report("vfio: failed to ioctl container: ret=%d, %s", + ret, strerror(errno)); + } return ret; } -int vfio_container_ioctl(AddressSpace *as, int32_t groupid, +int vfio_container_ioctl(AddressSpace *as, int req, void *param) { /* We allow only certain ioctls to the container */ @@ -1054,5 +1051,5 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, return -1; } - return vfio_container_do_ioctl(as, groupid, req, param); + return vfio_container_do_ioctl(as, req, param); } diff --git a/include/hw/vfio/vfio.h b/include/hw/vfio/vfio.h index 0b26cd8..76b5744 100644 --- a/include/hw/vfio/vfio.h +++ b/include/hw/vfio/vfio.h @@ -3,7 +3,7 @@ #include "qemu/typedefs.h" -extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid, +extern int vfio_container_ioctl(AddressSpace *as, int req, void *param); #endif