From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9qde-0000NG-PR for qemu-devel@nongnu.org; Thu, 15 Aug 2013 02:02:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V9qdW-0006T6-8G for qemu-devel@nongnu.org; Thu, 15 Aug 2013 02:02:26 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:59408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9qdW-0006St-2B for qemu-devel@nongnu.org; Thu, 15 Aug 2013 02:02:18 -0400 Received: by mail-pd0-f174.google.com with SMTP id y13so426241pdi.19 for ; Wed, 14 Aug 2013 23:02:17 -0700 (PDT) Message-ID: <520C6EE1.8020503@ozlabs.ru> Date: Thu, 15 Aug 2013 16:02:09 +1000 From: Alexey Kardashevskiy MIME-Version: 1.0 References: <1375863692-12207-1-git-send-email-aik@ozlabs.ru> <1375863692-12207-6-git-send-email-aik@ozlabs.ru> <1376345237.22121.15.camel@ul30vt.home> In-Reply-To: <1376345237.22121.15.camel@ul30vt.home> Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 5/8] vfio: Add guest side IOMMU support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: Anthony Liguori , "Michael S . Tsirkin" , Alexander Graf , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Paul Mackerras , David Gibson On 08/13/2013 08:07 AM, Alex Williamson wrote: >> +static void vfio_listener_region_add(MemoryListener *listener, >> + MemoryRegionSection *section) >> +{ >> + VFIOContainer *container = container_of(listener, VFIOContainer, >> + iommu_data.listener); >> + hwaddr iova, end; >> + int ret; >> >> if (vfio_listener_skipped_section(section)) { >> DPRINTF("SKIPPING region_add %"HWADDR_PRIx" - %"PRIx64"\n", >> @@ -1952,19 +2011,51 @@ static void vfio_listener_region_add(MemoryListener *listener, >> return; >> } >> >> - vaddr = memory_region_get_ram_ptr(section->mr) + >> - section->offset_within_region + >> - (iova - section->offset_within_address_space); >> - >> - DPRINTF("region_add %"HWADDR_PRIx" - %"HWADDR_PRIx" [%p]\n", >> - iova, end - 1, vaddr); >> - >> - memory_region_ref(section->mr); >> - 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); >> + if (memory_region_is_iommu(section->mr)) { >> + VFIOGuestIOMMU *giommu; >> + >> + DPRINTF("region_add [iommu] %"HWADDR_PRIx" - %"HWADDR_PRIx"\n", >> + iova, end - 1); >> + >> + memory_region_ref(section->mr); >> + /* >> + * FIXME: We should do some checking to see if the >> + * capabilities of the host VFIO IOMMU are adequate to model >> + * the guest IOMMU >> + * >> + * FIXME: This assumes that the guest IOMMU is empty of >> + * mappings at this point - we should either enforce this, or >> + * loop through existing mappings to map them into VFIO. >> + * >> + * FIXME: For VFIO iommu types which have KVM acceleration to >> + * avoid bouncing all map/unmaps through qemu this way, this >> + * would be the right place to wire that up (tell the KVM >> + * device emulation the VFIO iommu handles to use). >> + */ >> + giommu = g_malloc0(sizeof(*giommu)); >> + giommu->iommu = section->mr; >> + giommu->container = container; >> + giommu->n.notify = vfio_iommu_map_notify; >> + QLIST_INSERT_HEAD(&container->guest_iommus, giommu, list); >> + memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); >> + >> + } else if (memory_region_is_ram(section->mr)) { >> + void *vaddr; >> + >> + vaddr = memory_region_get_ram_ptr(section->mr) + >> + section->offset_within_region + >> + (iova - section->offset_within_address_space); >> + >> + DPRINTF("region_add [ram] %"HWADDR_PRIx" - %"HWADDR_PRIx" [%p]\n", >> + iova, end - 1, vaddr); >> + >> + memory_region_ref(section->mr); > > > Where are these unref'd? It is already vfio_listener_region_del(), as the original ref() which this patch just moves around. -- Alexey