Blame SOURCES/kvm-x86-host-phys-bits-limit-option.patch

7711c0
From 714c0396845fe74f8ccb9a72a7f0ab6753248e6e Mon Sep 17 00:00:00 2001
7711c0
From: Eduardo Habkost <ehabkost@redhat.com>
7711c0
Date: Thu, 11 Apr 2019 21:48:45 +0200
7711c0
Subject: [PATCH 159/163] x86: host-phys-bits-limit option
7711c0
7711c0
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
7711c0
Message-id: <20190411214846.8816-2-ehabkost@redhat.com>
7711c0
Patchwork-id: 85608
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 1/2] x86: host-phys-bits-limit option
7711c0
Bugzilla: 1691519
7711c0
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
7711c0
RH-Acked-by: Pankaj Gupta <pagupta@redhat.com>
7711c0
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
7711c0
7711c0
Some downstream distributions of QEMU set host-phys-bits=on by
7711c0
default.  This worked very well for most use cases, because
7711c0
phys-bits really didn't have huge consequences. The only
7711c0
difference was on the CPUID data seen by guests, and on the
7711c0
handling of reserved bits.
7711c0
7711c0
This changed in KVM commit 855feb673640 ("KVM: MMU: Add 5 level
7711c0
EPT & Shadow page table support").  Now choosing a large
7711c0
phys-bits value for a VM has bigger impact: it will make KVM use
7711c0
5-level EPT even when it's not really necessary.  This means
7711c0
using the host phys-bits value may not be the best choice.
7711c0
7711c0
Management software could address this problem by manually
7711c0
configuring phys-bits depending on the size of the VM and the
7711c0
amount of MMIO address space required for hotplug.  But this is
7711c0
not trivial to implement.
7711c0
7711c0
However, there's another workaround that would work for most
7711c0
cases: keep using the host phys-bits value, but only if it's
7711c0
smaller than 48.  This patch makes this possible by introducing a
7711c0
new "-cpu" option: "host-phys-bits-limit".  Management software
7711c0
or users can make sure they will always use 4-level EPT using:
7711c0
"host-phys-bits=on,host-phys-bits-limit=48".
7711c0
7711c0
This behavior is still not enabled by default because QEMU
7711c0
doesn't enable host-phys-bits=on by default.  But users,
7711c0
management software, or downstream distributions may choose to
7711c0
change their defaults using the new option.
7711c0
7711c0
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
7711c0
Message-Id: <20181211192527.13254-1-ehabkost@redhat.com>
7711c0
[ehabkost: removed test code while some issues are addressed]
7711c0
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
7711c0
(cherry picked from commit 258fe08bd341d2e230676228307294e41f33002c)
7711c0
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
7711c0
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 target/i386/cpu.c | 5 +++++
7711c0
 target/i386/cpu.h | 3 +++
7711c0
 2 files changed, 8 insertions(+)
7711c0
7711c0
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
7711c0
index 2f6d5f4..c5156c8 100644
7711c0
--- a/target/i386/cpu.c
7711c0
+++ b/target/i386/cpu.c
7711c0
@@ -4826,6 +4826,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
7711c0
             if (cpu->host_phys_bits) {
7711c0
                 /* The user asked for us to use the host physical bits */
7711c0
                 cpu->phys_bits = host_phys_bits;
7711c0
+                if (cpu->host_phys_bits_limit &&
7711c0
+                    cpu->phys_bits > cpu->host_phys_bits_limit) {
7711c0
+                    cpu->phys_bits = cpu->host_phys_bits_limit;
7711c0
+                }
7711c0
             }
7711c0
 
7711c0
             /* Print a warning if the user set it to a value that's not the
7711c0
@@ -5377,6 +5381,7 @@ static Property x86_cpu_properties[] = {
7711c0
     DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
7711c0
     DEFINE_PROP_UINT32("phys-bits", X86CPU, phys_bits, 0),
7711c0
     DEFINE_PROP_BOOL("host-phys-bits", X86CPU, host_phys_bits, false),
7711c0
+    DEFINE_PROP_UINT8("host-phys-bits-limit", X86CPU, host_phys_bits_limit, 0),
7711c0
     DEFINE_PROP_BOOL("fill-mtrr-mask", X86CPU, fill_mtrr_mask, true),
7711c0
     DEFINE_PROP_UINT32("level", X86CPU, env.cpuid_level, UINT32_MAX),
7711c0
     DEFINE_PROP_UINT32("xlevel", X86CPU, env.cpuid_xlevel, UINT32_MAX),
7711c0
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
7711c0
index 75cf5ed..392065d 100644
7711c0
--- a/target/i386/cpu.h
7711c0
+++ b/target/i386/cpu.h
7711c0
@@ -1419,6 +1419,9 @@ struct X86CPU {
7711c0
     /* if true override the phys_bits value with a value read from the host */
7711c0
     bool host_phys_bits;
7711c0
 
7711c0
+    /* if set, limit maximum value for phys_bits when host_phys_bits is true */
7711c0
+    uint8_t host_phys_bits_limit;
7711c0
+
7711c0
     /* Stop SMI delivery for migration compatibility with old machines */
7711c0
     bool kvm_no_smi_migration;
7711c0
 
7711c0
-- 
7711c0
1.8.3.1
7711c0