From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3gKq-0000FK-9M for qemu-devel@nongnu.org; Thu, 16 Jan 2014 01:21:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3gKg-0004oh-5A for qemu-devel@nongnu.org; Thu, 16 Jan 2014 01:21:48 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:53651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3gKf-0004oH-Dh for qemu-devel@nongnu.org; Thu, 16 Jan 2014 01:21:38 -0500 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Jan 2014 16:21:34 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 7DAD92BB0053 for ; Thu, 16 Jan 2014 17:21:32 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s0G62ZSx4850010 for ; Thu, 16 Jan 2014 17:02:37 +1100 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s0G6LUef014384 for ; Thu, 16 Jan 2014 17:21:30 +1100 From: Alexey Kardashevskiy Date: Thu, 16 Jan 2014 17:21:27 +1100 Message-Id: <1389853287-25458-3-git-send-email-aik@ozlabs.ru> In-Reply-To: <1389853287-25458-1-git-send-email-aik@ozlabs.ru> References: <1389853287-25458-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH 2/2] vfio: fix mapping of MSIX bar List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Paolo Bonzini , Alex Williamson VFIO virtualizes MSIX table for the guest but not mapping the part of a BAR which contains an MSIX table. Since vfio_mmap_bar() mmaps chunks before and after the MSIX table, they have to be aligned to the host page size which may be TARGET_PAGE_MASK (4K) or 64K in case of PPC64. This fixes boundaries calculations to use the real host page size. Without the patch, the chunk before MSIX table may overlap with the MSIX table and mmap will fail in the host kernel. The result will be serious slowdown as the whole BAR will be emulated by QEMU. Signed-off-by: Alexey Kardashevskiy --- hw/misc/vfio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index 9aecaa8..9989bea 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -2501,7 +2501,7 @@ static void vfio_map_bar(VFIODevice *vdev, int nr) * potentially insert a direct-mapped subregion before and after it. */ if (vdev->msix && vdev->msix->table_bar == nr) { - size = vdev->msix->table_offset & TARGET_PAGE_MASK; + size = vdev->msix->table_offset & qemu_host_page_mask; } strncat(name, " mmap", sizeof(name) - strlen(name) - 1); @@ -2513,8 +2513,8 @@ static void vfio_map_bar(VFIODevice *vdev, int nr) if (vdev->msix && vdev->msix->table_bar == nr) { unsigned start; - start = TARGET_PAGE_ALIGN(vdev->msix->table_offset + - (vdev->msix->entries * PCI_MSIX_ENTRY_SIZE)); + start = HOST_PAGE_ALIGN(vdev->msix->table_offset + + (vdev->msix->entries * PCI_MSIX_ENTRY_SIZE)); size = start < bar->size ? bar->size - start : 0; strncat(name, " msix-hi", sizeof(name) - strlen(name) - 1); -- 1.8.4.rc4