From patchwork Tue Mar 1 09:10:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 8463301 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1D0029F38C for ; Tue, 1 Mar 2016 09:16:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E5B0202C8 for ; Tue, 1 Mar 2016 09:16:32 +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 52759200CF for ; Tue, 1 Mar 2016 09:16:31 +0000 (UTC) Received: from localhost ([::1]:41874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagPu-000871-Kf for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 04:16:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagLt-0001Ij-H0 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aagLn-0007Vb-W5 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:21 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:42552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagLn-0007U6-Eg for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:15 -0500 Received: from localhost by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Mar 2016 19:12:11 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 1 Mar 2016 19:12:09 +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 d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id A5C1A357805C; Tue, 1 Mar 2016 20:12:09 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u219C1ij7471590; Tue, 1 Mar 2016 20:12:09 +1100 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 u219Bb2A021683; Tue, 1 Mar 2016 20:11:37 +1100 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 u219BaxI021234; Tue, 1 Mar 2016 20:11:36 +1100 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 9687EA03B1; 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 8EBD6E39DE; Tue, 1 Mar 2016 20:10:46 +1100 (AEDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Tue, 1 Mar 2016 20:10:34 +1100 Message-Id: <1456823441-46757-10-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-0033-0000-0000-000003076EFA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.142 Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org Subject: [Qemu-devel] [PATCH qemu v13 09/16] vfio: Generalize IOMMU memory listener 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 At the moment VFIOContainer uses one memory listener which listens on PCI address space for both Type1 and sPAPR IOMMUs. Soon we will need another listener to listen on RAM; this will do DMA memory pre-registration for sPAPR guests which basically pins all guest pages in the host physical RAM. This introduces VFIOMemoryListener which is wrapper for MemoryListener and stores a pointer to the container. This allows having multiple memory listeners for the same container. This replaces the existing @listener with @iommu_listener. This should cause no change in behavior. Signed-off-by: Alexey Kardashevskiy --- hw/vfio/common.c | 41 +++++++++++++++++++++++++++++++---------- include/hw/vfio/vfio-common.h | 9 ++++++++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ca3fd47..0e67a5a 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -318,10 +318,10 @@ static hwaddr vfio_container_granularity(VFIOContainer *container) return (hwaddr)1 << ctz64(container->iova_pgsizes); } -static void vfio_listener_region_add(MemoryListener *listener, +static void vfio_listener_region_add(VFIOMemoryListener *vlistener, MemoryRegionSection *section) { - VFIOContainer *container = container_of(listener, VFIOContainer, listener); + VFIOContainer *container = vlistener->container; hwaddr iova, end; Int128 llend; void *vaddr; @@ -425,10 +425,10 @@ fail: } } -static void vfio_listener_region_del(MemoryListener *listener, +static void vfio_listener_region_del(VFIOMemoryListener *vlistener, MemoryRegionSection *section) { - VFIOContainer *container = container_of(listener, VFIOContainer, listener); + VFIOContainer *container = vlistener->container; hwaddr iova, end; int ret; MemoryRegion *iommu = NULL; @@ -492,14 +492,33 @@ static void vfio_listener_region_del(MemoryListener *listener, } } -static const MemoryListener vfio_memory_listener = { - .region_add = vfio_listener_region_add, - .region_del = vfio_listener_region_del, +static void vfio_iommu_listener_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOMemoryListener *vlistener = container_of(listener, VFIOMemoryListener, + listener); + + vfio_listener_region_add(vlistener, section); +} + + +static void vfio_iommu_listener_region_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOMemoryListener *vlistener = container_of(listener, VFIOMemoryListener, + listener); + + vfio_listener_region_del(vlistener, section); +} + +static const MemoryListener vfio_iommu_listener = { + .region_add = vfio_iommu_listener_region_add, + .region_del = vfio_iommu_listener_region_del, }; static void vfio_listener_release(VFIOContainer *container) { - memory_listener_unregister(&container->listener); + memory_listener_unregister(&container->iommu_listener.listener); } int vfio_mmap_region(Object *obj, VFIORegion *region, @@ -768,9 +787,11 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as) goto free_container_exit; } - container->listener = vfio_memory_listener; + container->iommu_listener.container = container; + container->iommu_listener.listener = vfio_iommu_listener; - memory_listener_register(&container->listener, container->space->as); + memory_listener_register(&container->iommu_listener.listener, + container->space->as); if (container->error) { ret = container->error; diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 9ffa681..b6b736c 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -57,12 +57,19 @@ typedef struct VFIOAddressSpace { QLIST_ENTRY(VFIOAddressSpace) list; } VFIOAddressSpace; +typedef struct VFIOContainer VFIOContainer; + +typedef struct VFIOMemoryListener { + struct MemoryListener listener; + VFIOContainer *container; +} VFIOMemoryListener; + struct VFIOGroup; typedef struct VFIOContainer { VFIOAddressSpace *space; int fd; /* /dev/vfio/vfio, empowered by the attached groups */ - MemoryListener listener; + VFIOMemoryListener iommu_listener; int error; bool initialized; /*