76daa3
From b83a6ae1492fa004c6e0e34cfb3ac8efe21e7bd2 Mon Sep 17 00:00:00 2001
76daa3
From: David Gibson <dgibson@redhat.com>
76daa3
Date: Mon, 18 Sep 2017 00:20:08 +0100
76daa3
Subject: [PATCH] vfio, spapr: Fix levels calculation
76daa3
76daa3
RH-Author: David Gibson <dgibson@redhat.com>
76daa3
Message-id: <20170918002008.24430-1-dgibson@redhat.com>
76daa3
Patchwork-id: 76404
76daa3
O-Subject: [Pegas-1.0 qemu-kvm PATCH] vfio, spapr: Fix levels calculation
76daa3
Bugzilla: 1491749
76daa3
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
76daa3
RH-Acked-by: Suraj Jitindar Singh <sursingh@redhat.com>
76daa3
RH-Acked-by: Sam Bobroff <sbobroff@redhat.com>
76daa3
76daa3
From: Alexey Kardashevskiy <aik@ozlabs.ru>
76daa3
76daa3
The existing tries to round up the number of pages but @pages is always
76daa3
calculated as the rounded up value minus one  which makes ctz64() always
76daa3
return 0 and have create.levels always set 1.
76daa3
76daa3
This removes wrong "-1" and allows having more than 1 levels. This becomes
76daa3
handy for >128GB guests with standard 64K pages as this requires blocks
76daa3
with zone order 9 and the popular limit of CONFIG_FORCE_MAX_ZONEORDER=9
76daa3
means that only blocks up to order 8 are allowed.
76daa3
76daa3
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
76daa3
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
76daa3
(cherry picked from commit e100161b69f8cf56dae866912dfffe7dcd7140af)
76daa3
Signed-off-by: David Gibson <dgibson@redhat.com>
76daa3
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
76daa3
---
76daa3
 hw/vfio/spapr.c | 2 +-
76daa3
 1 file changed, 1 insertion(+), 1 deletion(-)
76daa3
76daa3
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
76daa3
index 4409bcc..4b85ba3 100644
76daa3
--- a/hw/vfio/spapr.c
76daa3
+++ b/hw/vfio/spapr.c
76daa3
@@ -162,7 +162,7 @@ int vfio_spapr_create_window(VFIOContainer *container,
76daa3
      */
76daa3
     entries = create.window_size >> create.page_shift;
76daa3
     pages = MAX((entries * sizeof(uint64_t)) / getpagesize(), 1);
76daa3
-    pages = MAX(pow2ceil(pages) - 1, 1); /* Round up */
76daa3
+    pages = MAX(pow2ceil(pages), 1); /* Round up */
76daa3
     create.levels = ctz64(pages) / 6 + 1;
76daa3
 
76daa3
     ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
76daa3
-- 
76daa3
1.8.3.1
76daa3