From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zyayb-0001Rr-Vk for qemu-devel@nongnu.org; Tue, 17 Nov 2015 02:46:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyayX-00075n-SC for qemu-devel@nongnu.org; Tue, 17 Nov 2015 02:46:53 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:56261) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyayX-00075g-MW for qemu-devel@nongnu.org; Tue, 17 Nov 2015 02:46:49 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NXY00H5S89Y3N70@mailout3.w1.samsung.com> for qemu-devel@nongnu.org; Tue, 17 Nov 2015 07:46:46 +0000 (GMT) From: Pavel Fedin Date: Tue, 17 Nov 2015 10:46:44 +0300 Message-id: <00fe01d1210c$1be12880$53a37980$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit Content-language: ru Subject: [Qemu-devel] [PATCH] vfio: Align iova also to IOMMU page size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: 'Alex Williamson' On some architectures TARGET_PAGE_ALIGN() is not enough to get the right alignment. For example on ARM TARGET_PAGE_BITS is 10 because some old CPUs support 1K page size, while minimum SMMU page size is 4K. This fixes problems like: 2015-11-17T07:37:42.892265Z qemu-system-aarch64: VFIO_MAP_DMA: -22 2015-11-17T07:37:42.892309Z qemu-system-aarch64: vfio_dma_map(0x223da230, 0x80002f0400, 0x10fc00, 0x7f89b40400) = -22 (Invalid argument) qemu: hardware error: vfio: DMA mapping failed, unable to continue Signed-off-by: Pavel Fedin --- hw/vfio/common.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ff5a89a..328140c 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -326,7 +326,7 @@ static void vfio_listener_region_add(MemoryListener *listener, MemoryRegionSection *section) { VFIOContainer *container = container_of(listener, VFIOContainer, listener); - hwaddr iova, end; + hwaddr iova, end, iommu_page_size; Int128 llend; void *vaddr; int ret; @@ -346,6 +346,8 @@ static void vfio_listener_region_add(MemoryListener *listener, } iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); + iommu_page_size = vfio_container_granularity(container); + iova = (iova + iommu_page_size - 1) & ~(iommu_page_size - 1); llend = int128_make64(section->offset_within_address_space); llend = int128_add(llend, section->size); llend = int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); @@ -390,8 +392,7 @@ static void vfio_listener_region_add(MemoryListener *listener, QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); - memory_region_iommu_replay(giommu->iommu, &giommu->n, - vfio_container_granularity(container), + memory_region_iommu_replay(giommu->iommu, &giommu->n, iommu_page_size, false); return; -- 1.9.5.msysgit.0