Blob Blame History Raw
From b4335c3290082dd8aa0915e340b625197d80fdc3 Mon Sep 17 00:00:00 2001
Message-Id: <b4335c3290082dd8aa0915e340b625197d80fdc3@dist-git>
From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: Thu, 9 Aug 2018 15:14:19 +0200
Subject: [PATCH] conf: qemu: add support for Hyper-V frequency MSRs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Qemu-2.12 gained 'hv-frequencies' cpu flag to enable Hyper-V frequency
MSRs. These MSRs are required (but not sufficient) to make Hyper-V on
KVM pass stable TSC page clocksource to L2 guests.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit 8253bca9615233f670c7dad659c120e4556a748a)

https://bugzilla.redhat.com/show_bug.cgi?id=1589702

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 docs/formatdomain.html.in               | 7 +++++++
 docs/schemas/domaincommon.rng           | 5 +++++
 src/conf/domain_conf.c                  | 6 +++++-
 src/conf/domain_conf.h                  | 1 +
 src/cpu/cpu_x86.c                       | 3 +++
 src/cpu/cpu_x86_data.h                  | 1 +
 src/qemu/qemu_command.c                 | 1 +
 src/qemu/qemu_parse_command.c           | 1 +
 src/qemu/qemu_process.c                 | 1 +
 tests/qemuxml2argvdata/hyperv-off.xml   | 1 +
 tests/qemuxml2argvdata/hyperv.args      | 2 +-
 tests/qemuxml2argvdata/hyperv.xml       | 1 +
 tests/qemuxml2xmloutdata/hyperv-off.xml | 1 +
 tests/qemuxml2xmloutdata/hyperv.xml     | 1 +
 14 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 42acf7a828..3b493a98ac 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1915,6 +1915,7 @@
     &lt;synic state='on'/&gt;
     &lt;reset state='on'/&gt;
     &lt;vendor_id state='on' value='KVM Hv'/&gt;
+    &lt;frequencies state='on'/&gt;
   &lt;/hyperv&gt;
   &lt;kvm&gt;
     &lt;hidden state='on'/&gt;
@@ -2037,6 +2038,12 @@
           <td>on, off; value - string, up to 12 characters</td>
           <td><span class="since">1.3.3 (QEMU 2.5)</span></td>
         </tr>
+        <tr>
+          <td>frequencies</td>
+          <td>Expose frequency MSRs</td>
+          <td> on, off</td>
+          <td><span class="since">4.7.0 (QEMU 2.12)</span></td>
+        </tr>
       </table>
       </dd>
       <dt><code>pvspinlock</code></dt>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index ac04af51a1..f156a6b7c4 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -5713,6 +5713,11 @@
             </optional>
           </element>
         </optional>
+        <optional>
+          <element name="frequencies">
+            <ref name="featurestate"/>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 240b33f28c..150dd8acc8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -169,7 +169,8 @@ VIR_ENUM_IMPL(virDomainHyperv, VIR_DOMAIN_HYPERV_LAST,
               "synic",
               "stimer",
               "reset",
-              "vendor_id")
+              "vendor_id",
+              "frequencies")
 
 VIR_ENUM_IMPL(virDomainKVM, VIR_DOMAIN_KVM_LAST,
               "hidden")
@@ -20051,6 +20052,7 @@ virDomainDefParseXML(xmlDocPtr xml,
             case VIR_DOMAIN_HYPERV_SYNIC:
             case VIR_DOMAIN_HYPERV_STIMER:
             case VIR_DOMAIN_HYPERV_RESET:
+            case VIR_DOMAIN_HYPERV_FREQUENCIES:
                 break;
 
             case VIR_DOMAIN_HYPERV_SPINLOCKS:
@@ -22242,6 +22244,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDefPtr src,
             case VIR_DOMAIN_HYPERV_SYNIC:
             case VIR_DOMAIN_HYPERV_STIMER:
             case VIR_DOMAIN_HYPERV_RESET:
+            case VIR_DOMAIN_HYPERV_FREQUENCIES:
                 if (src->hyperv_features[i] != dst->hyperv_features[i]) {
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                    _("State of HyperV enlightenment "
@@ -27890,6 +27893,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                     case VIR_DOMAIN_HYPERV_SYNIC:
                     case VIR_DOMAIN_HYPERV_STIMER:
                     case VIR_DOMAIN_HYPERV_RESET:
+                    case VIR_DOMAIN_HYPERV_FREQUENCIES:
                         break;
 
                     case VIR_DOMAIN_HYPERV_SPINLOCKS:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5e2f21dea3..97d38ff7b9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1791,6 +1791,7 @@ typedef enum {
     VIR_DOMAIN_HYPERV_STIMER,
     VIR_DOMAIN_HYPERV_RESET,
     VIR_DOMAIN_HYPERV_VENDOR_ID,
+    VIR_DOMAIN_HYPERV_FREQUENCIES,
 
     VIR_DOMAIN_HYPERV_LAST
 } virDomainHyperv;
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 809da94117..a2fbfb577d 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -109,6 +109,8 @@ KVM_FEATURE_DEF(VIR_CPU_x86_KVM_HV_VPINDEX,
                 0x40000003, 0x00000040);
 KVM_FEATURE_DEF(VIR_CPU_x86_KVM_HV_RESET,
                 0x40000003, 0x00000080);
+KVM_FEATURE_DEF(VIR_CPU_x86_KVM_HV_FREQUENCIES,
+                0x40000003, 0x00000800);
 
 static virCPUx86Feature x86_kvm_features[] =
 {
@@ -129,6 +131,7 @@ static virCPUx86Feature x86_kvm_features[] =
     KVM_FEATURE(VIR_CPU_x86_KVM_HV_VAPIC),
     KVM_FEATURE(VIR_CPU_x86_KVM_HV_VPINDEX),
     KVM_FEATURE(VIR_CPU_x86_KVM_HV_RESET),
+    KVM_FEATURE(VIR_CPU_x86_KVM_HV_FREQUENCIES),
 };
 
 typedef struct _virCPUx86Model virCPUx86Model;
diff --git a/src/cpu/cpu_x86_data.h b/src/cpu/cpu_x86_data.h
index b89110f16c..c01eb41be5 100644
--- a/src/cpu/cpu_x86_data.h
+++ b/src/cpu/cpu_x86_data.h
@@ -63,6 +63,7 @@ struct _virCPUx86CPUID {
 # define VIR_CPU_x86_KVM_HV_VAPIC     "__kvm_hv_vapic"
 # define VIR_CPU_x86_KVM_HV_VPINDEX   "__kvm_hv_vpindex"
 # define VIR_CPU_x86_KVM_HV_RESET     "__kvm_hv_reset"
+# define VIR_CPU_x86_KVM_HV_FREQUENCIES "__kvm_hv_frequencies"
 
 
 # define VIR_CPU_X86_DATA_INIT { 0 }
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 028f48310b..82c349819e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6919,6 +6919,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
             case VIR_DOMAIN_HYPERV_SYNIC:
             case VIR_DOMAIN_HYPERV_STIMER:
             case VIR_DOMAIN_HYPERV_RESET:
+            case VIR_DOMAIN_HYPERV_FREQUENCIES:
                 if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON)
                     virBufferAsprintf(&buf, ",hv_%s",
                                       virDomainHypervTypeToString(i));
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
index 351425fedd..ffea9a26bd 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -1536,6 +1536,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             case VIR_DOMAIN_HYPERV_SYNIC:
             case VIR_DOMAIN_HYPERV_STIMER:
             case VIR_DOMAIN_HYPERV_RESET:
+            case VIR_DOMAIN_HYPERV_FREQUENCIES:
                 if (value) {
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                    _("HyperV feature '%s' should not "
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2d51c0fa25..dd92a6c179 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3923,6 +3923,7 @@ qemuProcessVerifyHypervFeatures(virDomainDefPtr def,
         case VIR_DOMAIN_HYPERV_SYNIC:
         case VIR_DOMAIN_HYPERV_STIMER:
         case VIR_DOMAIN_HYPERV_RESET:
+        case VIR_DOMAIN_HYPERV_FREQUENCIES:
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("host doesn't support hyperv '%s' feature"),
                            virDomainHypervTypeToString(i));
diff --git a/tests/qemuxml2argvdata/hyperv-off.xml b/tests/qemuxml2argvdata/hyperv-off.xml
index ba9c978848..d3a8455ac3 100644
--- a/tests/qemuxml2argvdata/hyperv-off.xml
+++ b/tests/qemuxml2argvdata/hyperv-off.xml
@@ -20,6 +20,7 @@
       <stimer state='off'/>
       <reset state='off'/>
       <vendor_id state='off'/>
+      <frequencies state='off'/>
     </hyperv>
   </features>
   <clock offset='utc'/>
diff --git a/tests/qemuxml2argvdata/hyperv.args b/tests/qemuxml2argvdata/hyperv.args
index a1acbb63de..53026bb2d5 100644
--- a/tests/qemuxml2argvdata/hyperv.args
+++ b/tests/qemuxml2argvdata/hyperv.args
@@ -9,7 +9,7 @@ QEMU_AUDIO_DRV=none \
 -S \
 -machine pc,accel=tcg,usb=off,dump-guest-core=off \
 -cpu 'qemu32,hv_relaxed,hv_vapic,hv_spinlocks=0x2fff,hv_vpindex,hv_runtime,\
-hv_synic,hv_stimer,hv_reset,hv_vendor_id=KVM Hv' \
+hv_synic,hv_stimer,hv_reset,hv_vendor_id=KVM Hv,hv_frequencies' \
 -m 214 \
 -smp 6,sockets=6,cores=1,threads=1 \
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
diff --git a/tests/qemuxml2argvdata/hyperv.xml b/tests/qemuxml2argvdata/hyperv.xml
index 09f6d21024..27372d1636 100644
--- a/tests/qemuxml2argvdata/hyperv.xml
+++ b/tests/qemuxml2argvdata/hyperv.xml
@@ -20,6 +20,7 @@
       <stimer state='on'/>
       <reset state='on'/>
       <vendor_id state='on' value='KVM Hv'/>
+      <frequencies state='on'/>
     </hyperv>
   </features>
   <clock offset='utc'/>
diff --git a/tests/qemuxml2xmloutdata/hyperv-off.xml b/tests/qemuxml2xmloutdata/hyperv-off.xml
index 07eaf7219d..3ba0b827c3 100644
--- a/tests/qemuxml2xmloutdata/hyperv-off.xml
+++ b/tests/qemuxml2xmloutdata/hyperv-off.xml
@@ -20,6 +20,7 @@
       <stimer state='off'/>
       <reset state='off'/>
       <vendor_id state='off'/>
+      <frequencies state='off'/>
     </hyperv>
   </features>
   <clock offset='utc'/>
diff --git a/tests/qemuxml2xmloutdata/hyperv.xml b/tests/qemuxml2xmloutdata/hyperv.xml
index f9ae9504de..1e47a946d6 100644
--- a/tests/qemuxml2xmloutdata/hyperv.xml
+++ b/tests/qemuxml2xmloutdata/hyperv.xml
@@ -20,6 +20,7 @@
       <stimer state='on'/>
       <reset state='on'/>
       <vendor_id state='on' value='KVM Hv'/>
+      <frequencies state='on'/>
     </hyperv>
   </features>
   <clock offset='utc'/>
-- 
2.19.1