From patchwork Tue Mar 1 09:10:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 8463271 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 27DA3C0553 for ; Tue, 1 Mar 2016 09:15:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 764A5202B8 for ; Tue, 1 Mar 2016 09:15:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A4BEF202C8 for ; Tue, 1 Mar 2016 09:15:04 +0000 (UTC) Received: from localhost ([::1]:41854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagOV-0005aU-VL for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 04:15:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagLt-0001Ik-Hj for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aagLo-0007Vp-1E for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:21 -0500 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:53367) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagLn-0007UM-F3 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:15 -0500 Received: from localhost by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Mar 2016 19:12:13 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp08.au.ibm.com (202.81.31.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 1 Mar 2016 19:12:10 +1000 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: aik@ozlabs.ru X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id A91973578052; Tue, 1 Mar 2016 20:12:10 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u219C2aE44236886; Tue, 1 Mar 2016 20:12:10 +1100 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u219Bcm2018736; Tue, 1 Mar 2016 20:11:38 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u219BapY018161; Tue, 1 Mar 2016 20:11:37 +1100 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id C1053A03BC; Tue, 1 Mar 2016 20:10:46 +1100 (AEDT) Received: from vpl2.ozlabs.ibm.com (vpl2.ozlabs.ibm.com [10.61.141.27]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id BEE1DE39DB; Tue, 1 Mar 2016 20:10:46 +1100 (AEDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Tue, 1 Mar 2016 20:10:40 +1100 Message-Id: <1456823441-46757-16-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.5.0.rc3 In-Reply-To: <1456823441-46757-1-git-send-email-aik@ozlabs.ru> References: <1456823441-46757-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16030109-0029-0000-0000-000044243478 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.141 Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org Subject: [Qemu-devel] [PATCH qemu v13 15/16] vfio: Move iova_pgsizes from container to guest IOMMU 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The page size is an attribute of an IOMMU, not a container as a container may contain more just one IOMMU. This moves iova_pgsizes from VFIOContainer to VFIOGuestIOMMU. The following patch will use this. This removes iova_pgsizes from Type1 IOMMU as it is not used there anyway and when it will get guest visible IOMMU, it will use VFIOGuestIOMMU's iova_pgsizes. Signed-off-by: Alexey Kardashevskiy --- hw/vfio/common.c | 16 ++++------------ include/hw/vfio/vfio-common.h | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index f2a03e0..42ef1eb 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -313,9 +313,9 @@ out: rcu_read_unlock(); } -static hwaddr vfio_container_granularity(VFIOContainer *container) +static hwaddr vfio_container_granularity(VFIOGuestIOMMU *giommu) { - return (hwaddr)1 << ctz64(container->iova_pgsizes); + return (hwaddr)1 << ctz64(giommu->iova_pgsizes); } static hwaddr vfio_iommu_page_mask(MemoryRegion *mr) @@ -392,12 +392,13 @@ static void vfio_listener_region_add(VFIOMemoryListener *vlistener, section->offset_within_address_space; giommu->container = container; giommu->n.notify = vfio_iommu_map_notify; + giommu->iova_pgsizes = section->mr->iommu_ops->get_page_sizes(section->mr); QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); giommu->iommu->iommu_ops->vfio_notify(section->mr, true); memory_region_iommu_replay(giommu->iommu, &giommu->n, - vfio_container_granularity(container), + vfio_container_granularity(giommu), false); return; @@ -743,14 +744,8 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as) container->min_iova = 0; container->max_iova = (hwaddr)-1; - /* Assume just 4K IOVA page size */ - container->iova_pgsizes = 0x1000; info.argsz = sizeof(info); ret = ioctl(fd, VFIO_IOMMU_GET_INFO, &info); - /* Ignore errors */ - if ((ret == 0) && (info.flags & VFIO_IOMMU_INFO_PGSIZES)) { - container->iova_pgsizes = info.iova_pgsizes; - } } else if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IOMMU) || ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_v2_IOMMU)) { struct vfio_iommu_spapr_tce_info info; @@ -811,9 +806,6 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as) } container->min_iova = info.dma32_window_start; container->max_iova = container->min_iova + info.dma32_window_size - 1; - - /* Assume just 4K IOVA pages for now */ - container->iova_pgsizes = 0x1000; } else { error_report("vfio: No available IOMMU models"); ret = -EINVAL; diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index bcbc5cb..48a1d7f 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -80,7 +80,6 @@ typedef struct VFIOContainer { * future */ hwaddr min_iova, max_iova; - uint64_t iova_pgsizes; QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; QLIST_HEAD(, VFIOGroup) group_list; QLIST_ENTRY(VFIOContainer) next; @@ -90,6 +89,7 @@ typedef struct VFIOGuestIOMMU { VFIOContainer *container; MemoryRegion *iommu; hwaddr offset_within_address_space; + uint64_t iova_pgsizes; Notifier n; QLIST_ENTRY(VFIOGuestIOMMU) giommu_next; } VFIOGuestIOMMU;