From nobody Fri Mar 29 00:14:31 2024 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; dkim=fail; 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 1507680588096138.0298699087092; Tue, 10 Oct 2017 17:09:48 -0700 (PDT) Received: from localhost ([::1]:37900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e24an-0005AV-DR for importer@patchew.org; Tue, 10 Oct 2017 20:09:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e24Y8-0003gs-5j for qemu-devel@nongnu.org; Tue, 10 Oct 2017 20:07:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e24Y3-0004kt-VA for qemu-devel@nongnu.org; Tue, 10 Oct 2017 20:07:00 -0400 Received: from ozlabs.org ([103.22.144.67]:52231) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e24Y3-0004kS-K7; Tue, 10 Oct 2017 20:06:55 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3yBZ645245z9t5C; Wed, 11 Oct 2017 11:06:52 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1507680412; bh=CGHNYksoViY9KWzlu43sRc0uO2mwbFMjelyMD7dwLpY=; h=From:To:Cc:Subject:Date:From; b=B8LQUEHNqf6MWIDoYt/jX3zShGQJk7P+VfkP73yAyEGLGKcyRzOQQY+EzwTCFVSOo Lby/Kyr/IJNjN3/fYcg69njSZEKbi9J6/00dK6ZKHET3jO2QUcVDWfvmalC/IP0qmw yCOtsVPO2TY8wAf2jjMm9oHC6pfvKRc74RA5UpJA= From: David Gibson To: lvivier@redhat.com, groug@kaod.org, clg@kaod.org Date: Wed, 11 Oct 2017 11:06:49 +1100 Message-Id: <20171011000649.22012-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.13.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCHv2] spapr: Correct RAM size calculation for HPT resizing 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: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In order to prevent the guest from forcing the allocation of large amounts of qemu memory (or host kernel memory, in the case of KVM HV), we limit the size of Hashed Page Table (HPT) it is allowed to allocated, based on its RAM size. However, the current calculation is not correct: it only adds up the size of plugged memory, ignoring the base memory size. This patch corrects it. While we're there, use get_plugged_memory_size() instead of directly calling pc_existing_dimms_capacity(). The only difference is that it will abort on failure, which is right: a failure here indicates something wrong within qemu. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Laurent Vivier --- hw/ppc/spapr_hcall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Changes in v2: * Also remove redundant initializer of current_ram_size diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 8d72bb7c1c..0d59d1534d 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -472,7 +472,7 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *cp= u, target_ulong flags =3D args[0]; int shift =3D args[1]; sPAPRPendingHPT *pending =3D spapr->pending_hpt; - uint64_t current_ram_size =3D MACHINE(spapr)->ram_size; + uint64_t current_ram_size; int rc; =20 if (spapr->resize_hpt =3D=3D SPAPR_RESIZE_HPT_DISABLED) { @@ -494,7 +494,7 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *cp= u, return H_PARAMETER; } =20 - current_ram_size =3D pc_existing_dimms_capacity(&error_fatal); + current_ram_size =3D MACHINE(spapr)->ram_size + get_plugged_memory_siz= e(); =20 /* We only allow the guest to allocate an HPT one order above what * we'd normally give them (to stop a small guest claiming a huge --=20 2.13.6