From nobody Wed Feb 11 02:53:59 2026 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508215549923227.4600419981441; Mon, 16 Oct 2017 21:45:49 -0700 (PDT) Received: from localhost ([::1]:36457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4Jl0-0003Md-9P for importer@patchew.org; Tue, 17 Oct 2017 00:45:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4JOe-0008U2-5Z for qemu-devel@nongnu.org; Tue, 17 Oct 2017 00:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4JOa-0007BN-Oz for qemu-devel@nongnu.org; Tue, 17 Oct 2017 00:22:28 -0400 Received: from ozlabs.org ([103.22.144.67]:60637) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e4JOZ-00075c-Qg; Tue, 17 Oct 2017 00:22:24 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3yGMTx4Nmrz9t6N; Tue, 17 Oct 2017 15:22:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1508214133; bh=HKMTd9XzhzKLrkasEGX7eT2eJ0xRrRPMPyi2Y38BC7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jDO1QHxFgugIoYhwlmHKA+xenWS/Xt0Wa3Asdw/oc+eEdxIVKMsfG4lM1ufkSLBQ2 wHE05h+U5lGQ2Jngoev/pB57zqLfguutCfxtYucuS1V97wVeBaospfYXOmWtGAErgK qQNOxnWr0Pv5SJgynY9+h/m+W1ywZ0MVtLoNOsLo= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 17 Oct 2017 15:21:50 +1100 Message-Id: <20171017042152.29443-33-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171017042152.29443-1-david@gibson.dropbear.id.au> References: <20171017042152.29443-1-david@gibson.dropbear.id.au> 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] [PULL 32/34] 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: agraf@suse.de, ehabkost@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, imammedo@redhat.com, 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(-) 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