edecca
From efc0312e1edb3d8196806606fbb639bbbd0bd6d4 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <efc0312e1edb3d8196806606fbb639bbbd0bd6d4@dist-git>
edecca
From: Vitaly Kuznetsov <vkuznets@redhat.com>
edecca
Date: Thu, 9 Aug 2018 15:14:21 +0200
edecca
Subject: [PATCH] conf: qemu: add support for Hyper-V PV TLB flush
edecca
MIME-Version: 1.0
edecca
Content-Type: text/plain; charset=UTF-8
edecca
Content-Transfer-Encoding: 8bit
edecca
edecca
Qemu-3.0 supports Hyper-V-style PV TLB flush, Windows guests can benefit
edecca
from this feature as KVM knows which vCPUs are not currently scheduled (and
edecca
thus don't require any immediate action).
edecca
edecca
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
edecca
Reviewed-by: John Ferlan <jferlan@redhat.com>
edecca
(cherry picked from commit f4c39db7366376bd95e1751b0e3ced9c73c14f5b)
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1589702
edecca
edecca
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
---
edecca
 docs/formatdomain.html.in               | 7 +++++++
edecca
 docs/schemas/domaincommon.rng           | 5 +++++
edecca
 src/conf/domain_conf.c                  | 6 +++++-
edecca
 src/conf/domain_conf.h                  | 1 +
edecca
 src/cpu/cpu_x86.c                       | 3 +++
edecca
 src/cpu/cpu_x86_data.h                  | 1 +
edecca
 src/qemu/qemu_command.c                 | 1 +
edecca
 src/qemu/qemu_parse_command.c           | 1 +
edecca
 src/qemu/qemu_process.c                 | 1 +
edecca
 tests/qemuxml2argvdata/hyperv-off.xml   | 1 +
edecca
 tests/qemuxml2argvdata/hyperv.args      | 2 +-
edecca
 tests/qemuxml2argvdata/hyperv.xml       | 1 +
edecca
 tests/qemuxml2xmloutdata/hyperv-off.xml | 1 +
edecca
 tests/qemuxml2xmloutdata/hyperv.xml     | 1 +
edecca
 14 files changed, 30 insertions(+), 2 deletions(-)
edecca
edecca
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
edecca
index 43a1067501..c019b26644 100644
edecca
--- a/docs/formatdomain.html.in
edecca
+++ b/docs/formatdomain.html.in
edecca
@@ -1917,6 +1917,7 @@
edecca
     <vendor_id state='on' value='KVM Hv'/>
edecca
     <frequencies state='on'/>
edecca
     <reenlightenment state='on'/>
edecca
+    <tlbflush state='on'/>
edecca
   </hyperv>
edecca
   <kvm>
edecca
     <hidden state='on'/>
edecca
@@ -2051,6 +2052,12 @@
edecca
            on, off
edecca
           4.7.0 (QEMU 3.0)
edecca
         
edecca
+        
edecca
+          tlbflush
edecca
+          Enable PV TLB flush support
edecca
+           on, off
edecca
+          4.7.0 (QEMU 3.0)
edecca
+        
edecca
       
edecca
       
edecca
       
pvspinlock
edecca
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
edecca
index ceee7a8efe..1c6f2a295d 100644
edecca
--- a/docs/schemas/domaincommon.rng
edecca
+++ b/docs/schemas/domaincommon.rng
edecca
@@ -5723,6 +5723,11 @@
edecca
             <ref name="featurestate"/>
edecca
           </element>
edecca
         </optional>
edecca
+        <optional>
edecca
+          <element name="tlbflush">
edecca
+            <ref name="featurestate"/>
edecca
+          </element>
edecca
+        </optional>
edecca
       </interleave>
edecca
     </element>
edecca
   </define>
edecca
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
edecca
index 18b4d03a61..e013e9f0c5 100644
edecca
--- a/src/conf/domain_conf.c
edecca
+++ b/src/conf/domain_conf.c
edecca
@@ -171,7 +171,8 @@ VIR_ENUM_IMPL(virDomainHyperv, VIR_DOMAIN_HYPERV_LAST,
edecca
               "reset",
edecca
               "vendor_id",
edecca
               "frequencies",
edecca
-              "reenlightenment")
edecca
+              "reenlightenment",
edecca
+              "tlbflush")
edecca
 
edecca
 VIR_ENUM_IMPL(virDomainKVM, VIR_DOMAIN_KVM_LAST,
edecca
               "hidden")
edecca
@@ -20055,6 +20056,7 @@ virDomainDefParseXML(xmlDocPtr xml,
edecca
             case VIR_DOMAIN_HYPERV_RESET:
edecca
             case VIR_DOMAIN_HYPERV_FREQUENCIES:
edecca
             case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
edecca
+            case VIR_DOMAIN_HYPERV_TLBFLUSH:
edecca
                 break;
edecca
 
edecca
             case VIR_DOMAIN_HYPERV_SPINLOCKS:
edecca
@@ -22248,6 +22250,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDefPtr src,
edecca
             case VIR_DOMAIN_HYPERV_RESET:
edecca
             case VIR_DOMAIN_HYPERV_FREQUENCIES:
edecca
             case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
edecca
+            case VIR_DOMAIN_HYPERV_TLBFLUSH:
edecca
                 if (src->hyperv_features[i] != dst->hyperv_features[i]) {
edecca
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
edecca
                                    _("State of HyperV enlightenment "
edecca
@@ -27898,6 +27901,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
edecca
                     case VIR_DOMAIN_HYPERV_RESET:
edecca
                     case VIR_DOMAIN_HYPERV_FREQUENCIES:
edecca
                     case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
edecca
+                    case VIR_DOMAIN_HYPERV_TLBFLUSH:
edecca
                         break;
edecca
 
edecca
                     case VIR_DOMAIN_HYPERV_SPINLOCKS:
edecca
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
edecca
index e450923019..d32514e7e6 100644
edecca
--- a/src/conf/domain_conf.h
edecca
+++ b/src/conf/domain_conf.h
edecca
@@ -1793,6 +1793,7 @@ typedef enum {
edecca
     VIR_DOMAIN_HYPERV_VENDOR_ID,
edecca
     VIR_DOMAIN_HYPERV_FREQUENCIES,
edecca
     VIR_DOMAIN_HYPERV_REENLIGHTENMENT,
edecca
+    VIR_DOMAIN_HYPERV_TLBFLUSH,
edecca
 
edecca
     VIR_DOMAIN_HYPERV_LAST
edecca
 } virDomainHyperv;
edecca
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
edecca
index 7a48b78eb9..7fa84f6014 100644
edecca
--- a/src/cpu/cpu_x86.c
edecca
+++ b/src/cpu/cpu_x86.c
edecca
@@ -113,6 +113,8 @@ KVM_FEATURE_DEF(VIR_CPU_x86_KVM_HV_FREQUENCIES,
edecca
                 0x40000003, 0x00000800);
edecca
 KVM_FEATURE_DEF(VIR_CPU_x86_KVM_HV_REENLIGHTENMENT,
edecca
                 0x40000003, 0x00002000);
edecca
+KVM_FEATURE_DEF(VIR_CPU_x86_KVM_HV_TLBFLUSH,
edecca
+                0x40000004, 0x00000004);
edecca
 
edecca
 static virCPUx86Feature x86_kvm_features[] =
edecca
 {
edecca
@@ -135,6 +137,7 @@ static virCPUx86Feature x86_kvm_features[] =
edecca
     KVM_FEATURE(VIR_CPU_x86_KVM_HV_RESET),
edecca
     KVM_FEATURE(VIR_CPU_x86_KVM_HV_FREQUENCIES),
edecca
     KVM_FEATURE(VIR_CPU_x86_KVM_HV_REENLIGHTENMENT),
edecca
+    KVM_FEATURE(VIR_CPU_x86_KVM_HV_TLBFLUSH),
edecca
 };
edecca
 
edecca
 typedef struct _virCPUx86Model virCPUx86Model;
edecca
diff --git a/src/cpu/cpu_x86_data.h b/src/cpu/cpu_x86_data.h
edecca
index a810c64fc9..090a21156f 100644
edecca
--- a/src/cpu/cpu_x86_data.h
edecca
+++ b/src/cpu/cpu_x86_data.h
edecca
@@ -65,6 +65,7 @@ struct _virCPUx86CPUID {
edecca
 # define VIR_CPU_x86_KVM_HV_RESET     "__kvm_hv_reset"
edecca
 # define VIR_CPU_x86_KVM_HV_FREQUENCIES "__kvm_hv_frequencies"
edecca
 # define VIR_CPU_x86_KVM_HV_REENLIGHTENMENT "__kvm_hv_reenlightenment"
edecca
+# define VIR_CPU_x86_KVM_HV_TLBFLUSH  "__kvm_hv_tlbflush"
edecca
 
edecca
 
edecca
 # define VIR_CPU_X86_DATA_INIT { 0 }
edecca
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
edecca
index 48f3b09ec9..a3d605c00f 100644
edecca
--- a/src/qemu/qemu_command.c
edecca
+++ b/src/qemu/qemu_command.c
edecca
@@ -6921,6 +6921,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
edecca
             case VIR_DOMAIN_HYPERV_RESET:
edecca
             case VIR_DOMAIN_HYPERV_FREQUENCIES:
edecca
             case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
edecca
+            case VIR_DOMAIN_HYPERV_TLBFLUSH:
edecca
                 if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON)
edecca
                     virBufferAsprintf(&buf, ",hv_%s",
edecca
                                       virDomainHypervTypeToString(i));
edecca
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
edecca
index 1e67a5a8c8..fdc1d34068 100644
edecca
--- a/src/qemu/qemu_parse_command.c
edecca
+++ b/src/qemu/qemu_parse_command.c
edecca
@@ -1538,6 +1538,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
edecca
             case VIR_DOMAIN_HYPERV_RESET:
edecca
             case VIR_DOMAIN_HYPERV_FREQUENCIES:
edecca
             case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
edecca
+            case VIR_DOMAIN_HYPERV_TLBFLUSH:
edecca
                 if (value) {
edecca
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
edecca
                                    _("HyperV feature '%s' should not "
edecca
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
edecca
index 990d4d3046..23958bcbce 100644
edecca
--- a/src/qemu/qemu_process.c
edecca
+++ b/src/qemu/qemu_process.c
edecca
@@ -3925,6 +3925,7 @@ qemuProcessVerifyHypervFeatures(virDomainDefPtr def,
edecca
         case VIR_DOMAIN_HYPERV_RESET:
edecca
         case VIR_DOMAIN_HYPERV_FREQUENCIES:
edecca
         case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
edecca
+        case VIR_DOMAIN_HYPERV_TLBFLUSH:
edecca
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
edecca
                            _("host doesn't support hyperv '%s' feature"),
edecca
                            virDomainHypervTypeToString(i));
edecca
diff --git a/tests/qemuxml2argvdata/hyperv-off.xml b/tests/qemuxml2argvdata/hyperv-off.xml
edecca
index b2e3612df9..dc5777355f 100644
edecca
--- a/tests/qemuxml2argvdata/hyperv-off.xml
edecca
+++ b/tests/qemuxml2argvdata/hyperv-off.xml
edecca
@@ -22,6 +22,7 @@
edecca
       <vendor_id state='off'/>
edecca
       <frequencies state='off'/>
edecca
       <reenlightenment state='off'/>
edecca
+      <tlbflush state='off'/>
edecca
     </hyperv>
edecca
   </features>
edecca
   <clock offset='utc'/>
edecca
diff --git a/tests/qemuxml2argvdata/hyperv.args b/tests/qemuxml2argvdata/hyperv.args
edecca
index 4feafad8e2..6ee6198fb0 100644
edecca
--- a/tests/qemuxml2argvdata/hyperv.args
edecca
+++ b/tests/qemuxml2argvdata/hyperv.args
edecca
@@ -10,7 +10,7 @@ QEMU_AUDIO_DRV=none \
edecca
 -machine pc,accel=tcg,usb=off,dump-guest-core=off \
edecca
 -cpu 'qemu32,hv_relaxed,hv_vapic,hv_spinlocks=0x2fff,hv_vpindex,hv_runtime,\
edecca
 hv_synic,hv_stimer,hv_reset,hv_vendor_id=KVM Hv,hv_frequencies,\
edecca
-hv_reenlightenment' \
edecca
+hv_reenlightenment,hv_tlbflush' \
edecca
 -m 214 \
edecca
 -smp 6,sockets=6,cores=1,threads=1 \
edecca
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
edecca
diff --git a/tests/qemuxml2argvdata/hyperv.xml b/tests/qemuxml2argvdata/hyperv.xml
edecca
index 20fcdba59e..816adf6907 100644
edecca
--- a/tests/qemuxml2argvdata/hyperv.xml
edecca
+++ b/tests/qemuxml2argvdata/hyperv.xml
edecca
@@ -22,6 +22,7 @@
edecca
       <vendor_id state='on' value='KVM Hv'/>
edecca
       <frequencies state='on'/>
edecca
       <reenlightenment state='on'/>
edecca
+      <tlbflush state='on'/>
edecca
     </hyperv>
edecca
   </features>
edecca
   <clock offset='utc'/>
edecca
diff --git a/tests/qemuxml2xmloutdata/hyperv-off.xml b/tests/qemuxml2xmloutdata/hyperv-off.xml
edecca
index 4a41e0c37e..77a8dac810 100644
edecca
--- a/tests/qemuxml2xmloutdata/hyperv-off.xml
edecca
+++ b/tests/qemuxml2xmloutdata/hyperv-off.xml
edecca
@@ -22,6 +22,7 @@
edecca
       <vendor_id state='off'/>
edecca
       <frequencies state='off'/>
edecca
       <reenlightenment state='off'/>
edecca
+      <tlbflush state='off'/>
edecca
     </hyperv>
edecca
   </features>
edecca
   <clock offset='utc'/>
edecca
diff --git a/tests/qemuxml2xmloutdata/hyperv.xml b/tests/qemuxml2xmloutdata/hyperv.xml
edecca
index 183b45980b..fc8c59a557 100644
edecca
--- a/tests/qemuxml2xmloutdata/hyperv.xml
edecca
+++ b/tests/qemuxml2xmloutdata/hyperv.xml
edecca
@@ -22,6 +22,7 @@
edecca
       <vendor_id state='on' value='KVM Hv'/>
edecca
       <frequencies state='on'/>
edecca
       <reenlightenment state='on'/>
edecca
+      <tlbflush state='on'/>
edecca
     </hyperv>
edecca
   </features>
edecca
   <clock offset='utc'/>
edecca
-- 
edecca
2.19.1
edecca