Blame SOURCES/kvm-spapr-Correct-RAM-size-calculation-for-HPT-resizing.patch

4a2fec
From 61cace627e7140a63e27c7b1f949fc3b44ec120c Mon Sep 17 00:00:00 2001
4a2fec
From: Serhii Popovych <spopovyc@redhat.com>
4a2fec
Date: Wed, 22 Nov 2017 13:35:31 +0100
4a2fec
Subject: [PATCH 1/7] spapr: Correct RAM size calculation for HPT resizing
4a2fec
4a2fec
RH-Author: Serhii Popovych <spopovyc@redhat.com>
4a2fec
Message-id: <1511357731-4779-1-git-send-email-spopovyc@redhat.com>
4a2fec
Patchwork-id: 77778
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH v2] spapr: Correct RAM size calculation for HPT resizing
4a2fec
Bugzilla: 1499647
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
RH-Acked-by: David Gibson <dgibson@redhat.com>
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
4a2fec
From: David Gibson <david@gibson.dropbear.id.au>
4a2fec
4a2fec
The only thing making this change distinct from one in
4a2fec
upstream is get_plugged_memory_size() function which
4a2fec
isn't present in 2.10.x branch and it is a part of new
4a2fec
QMP interface command which we do not want to introduce
4a2fec
in downstream.
4a2fec
4a2fec
So assuming that we replace get_plugged_memory_size()
4a2fec
with direct call to pc_existing_dimms_capacity().
4a2fec
4a2fec
    commit db50f280cf5f714e64ff2b134aae138908f07502
4a2fec
    Author: David Gibson <david@gibson.dropbear.id.au>
4a2fec
    Date:   Wed Oct 11 00:16:57 2017 +1100
4a2fec
4a2fec
    spapr: Correct RAM size calculation for HPT resizing
4a2fec
4a2fec
    In order to prevent the guest from forcing the allocation of large amounts
4a2fec
    of qemu memory (or host kernel memory, in the case of KVM HV), we limit
4a2fec
    the size of Hashed Page Table (HPT) it is allowed to allocated, based on
4a2fec
    its RAM size.
4a2fec
4a2fec
    However, the current calculation is not correct: it only adds up the size
4a2fec
    of plugged memory, ignoring the base memory size.  This patch corrects it.
4a2fec
4a2fec
    While we're there, use get_plugged_memory_size() instead of directly
4a2fec
    calling pc_existing_dimms_capacity().  The only difference is that it
4a2fec
    will abort on failure, which is right: a failure here indicates something
4a2fec
    wrong within qemu.
4a2fec
4a2fec
    Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4a2fec
    Reviewed-by: Greg Kurz <groug@kaod.org>
4a2fec
    Reviewed-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
4a2fec
Signed-off-by: Serhii Popovych <spopovyc@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/ppc/spapr_hcall.c | 5 +++--
4a2fec
 1 file changed, 3 insertions(+), 2 deletions(-)
4a2fec
4a2fec
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
4a2fec
index b503299..217358d 100644
4a2fec
--- a/hw/ppc/spapr_hcall.c
4a2fec
+++ b/hw/ppc/spapr_hcall.c
4a2fec
@@ -472,7 +472,7 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *cpu,
4a2fec
     target_ulong flags = args[0];
4a2fec
     int shift = args[1];
4a2fec
     sPAPRPendingHPT *pending = spapr->pending_hpt;
4a2fec
-    uint64_t current_ram_size = MACHINE(spapr)->ram_size;
4a2fec
+    uint64_t current_ram_size;
4a2fec
     int rc;
4a2fec
 
4a2fec
     if (spapr->resize_hpt == SPAPR_RESIZE_HPT_DISABLED) {
4a2fec
@@ -494,7 +494,8 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *cpu,
4a2fec
         return H_PARAMETER;
4a2fec
     }
4a2fec
 
4a2fec
-    current_ram_size = pc_existing_dimms_capacity(&error_fatal);
4a2fec
+    current_ram_size = MACHINE(spapr)->ram_size +
4a2fec
+                       pc_existing_dimms_capacity(&error_fatal);
4a2fec
 
4a2fec
     /* We only allow the guest to allocate an HPT one order above what
4a2fec
      * we'd normally give them (to stop a small guest claiming a huge
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec