From nobody Wed Nov 5 05:21:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505184861599786.8078410066622; Mon, 11 Sep 2017 19:54:21 -0700 (PDT) Received: from localhost ([::1]:33295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drbL8-0005LM-Vu for importer@patchew.org; Mon, 11 Sep 2017 22:54:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drbK8-0004yJ-II for qemu-devel@nongnu.org; Mon, 11 Sep 2017 22:53:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drbK4-00056a-Bk for qemu-devel@nongnu.org; Mon, 11 Sep 2017 22:53:16 -0400 Received: from ozlabs.ru ([107.173.13.209]:34924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drbK4-00056N-58; Mon, 11 Sep 2017 22:53:12 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id F108F3A6000B; Mon, 11 Sep 2017 22:54:22 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Tue, 12 Sep 2017 12:53:07 +1000 Message-Id: <20170912025307.45376-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 107.173.13.209 Subject: [Qemu-devel] [PATCH qemu] vfio, spapr: Fix levels calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The existing tries to round up the number of pages but @pages is always calculated as the rounded up value minus one which makes ctz64() always return 0 and have create.levels always set 1. This removes wrong "-1" and allows having more than 1 levels. This becomes handy for >128GB guests with standard 64K pages as this requires blocks with zone order 9 and the popular limit of CONFIG_FORCE_MAX_ZONEORDER=3D9 means that only blocks up to order 8 are allowed. Signed-off-by: Alexey Kardashevskiy --- hw/vfio/spapr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 32fd6a9b54..259397c002 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -163,7 +163,7 @@ int vfio_spapr_create_window(VFIOContainer *container, */ entries =3D create.window_size >> create.page_shift; pages =3D MAX((entries * sizeof(uint64_t)) / getpagesize(), 1); - pages =3D MAX(pow2ceil(pages) - 1, 1); /* Round up */ + pages =3D MAX(pow2ceil(pages), 1); /* Round up */ create.levels =3D ctz64(pages) / 6 + 1; =20 ret =3D ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create); --=20 2.11.0