From patchwork Fri Jul 10 10:43:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 493730 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 5E0ED1401AF for ; Fri, 10 Jul 2015 20:47:16 +1000 (AEST) Received: from localhost ([::1]:44027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDVpq-0003it-Hq for incoming@patchwork.ozlabs.org; Fri, 10 Jul 2015 06:47:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDVnm-0000zz-Bu for qemu-devel@nongnu.org; Fri, 10 Jul 2015 06:45:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZDVni-00069Z-6Y for qemu-devel@nongnu.org; Fri, 10 Jul 2015 06:45:06 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:47857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDVnh-00067z-Km for qemu-devel@nongnu.org; Fri, 10 Jul 2015 06:45:02 -0400 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Jul 2015 20:44:55 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Jul 2015 20:44:53 +1000 X-Helo: d23dlp03.au.ibm.com X-MailFrom: aik@ozlabs.ru X-RcptTo: qemu-ppc@nongnu.org Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 8447A3578052; Fri, 10 Jul 2015 20:44:52 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t6AAifNe36438040; Fri, 10 Jul 2015 20:44:52 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t6AAiG0B003569; Fri, 10 Jul 2015 20:44:17 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t6AAiGlL003207; Fri, 10 Jul 2015 20:44:16 +1000 Received: from bran.ozlabs.ibm.com (unknown [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id A2A8FA03B2; Fri, 10 Jul 2015 20:43:52 +1000 (AEST) Received: from ka1.ozlabs.ibm.com (ka1.ozlabs.ibm.com [10.61.145.11]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 9C18FE38E2; Fri, 10 Jul 2015 20:43:52 +1000 (AEST) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Fri, 10 Jul 2015 20:43:47 +1000 Message-Id: <1436525028-23963-5-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.4.0.rc3.8.gfb3e7d5 In-Reply-To: <1436525028-23963-1-git-send-email-aik@ozlabs.ru> References: <1436525028-23963-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15071010-0009-0000-0000-000001AAB3BB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.145 Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH qemu 4/5] vfio: Refactor memory listener to accommodate more IOMMU types 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 The vfio_memory_listener is registered for PCI address space. On Type1 IOMMU that falls back to @address_space_memory and the listener is called on RAM blocks. On sPAPR IOMMU is guest visible and the listener is called on DMA windows. Therefore Type1 IOMMU only handled RAM regions and sPAPR IOMMU only handled IOMMU regions. With the memory preregistration, there is need to handle RAM regions in the listener for sPAPR IOMMU too. To make next patches simpler/nicer, this moves DMA mapping/unmapping code to a case in a switch. This should cause no change in behavior. Signed-off-by: Alexey Kardashevskiy --- hw/vfio/common.c | 63 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 788c87a..77b5ab0 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -397,26 +397,36 @@ static void vfio_listener_region_add(MemoryListener *listener, section->offset_within_region + (iova - section->offset_within_address_space); - trace_vfio_listener_region_add_ram(iova, end - 1, vaddr); + switch (container->iommu_data.type) { + case VFIO_TYPE1_IOMMU: + case VFIO_TYPE1v2_IOMMU: + trace_vfio_listener_region_add_ram(iova, end - 1, vaddr); - ret = vfio_dma_map(container, iova, end - iova, vaddr, section->readonly); - if (ret) { - error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx", %p) = %d (%m)", - container, iova, end - iova, vaddr, ret); + ret = vfio_dma_map(container, iova, end - iova, vaddr, section->readonly); + if (ret) { + error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx", %p) = %d (%m)", + container, iova, end - iova, vaddr, ret); + goto error_exit; + } + break; + } + + return; + +error_exit: - /* - * On the initfn path, store the first error in the container so we - * can gracefully fail. Runtime, there's not much we can do other - * than throw a hardware error. - */ - if (!container->iommu_data.type1.initialized) { - if (!container->iommu_data.type1.error) { - container->iommu_data.type1.error = ret; - } - } else { - hw_error("vfio: DMA mapping failed, unable to continue"); + /* + * On the initfn path, store the first error in the container so we + * can gracefully fail. Runtime, there's not much we can do other + * than throw a hardware error. + */ + if (!container->iommu_data.type1.initialized) { + if (!container->iommu_data.type1.error) { + container->iommu_data.type1.error = ret; } + } else { + hw_error("vfio: DMA mapping failed, unable to continue"); } } @@ -474,14 +484,19 @@ static void vfio_listener_region_del(MemoryListener *listener, return; } - trace_vfio_listener_region_del(iova, end - 1); + switch (container->iommu_data.type) { + case VFIO_TYPE1_IOMMU: + case VFIO_TYPE1v2_IOMMU: + trace_vfio_listener_region_del(iova, end - 1); - ret = vfio_dma_unmap(container, iova, end - iova); - memory_region_unref(section->mr); - if (ret) { - error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx") = %d (%m)", - container, iova, end - iova, ret); + ret = vfio_dma_unmap(container, iova, end - iova); + memory_region_unref(section->mr); + if (ret) { + error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") = %d (%m)", + container, iova, end - iova, ret); + } + break; } }