3e5111
From b34dc87751a8667f22ea78730a5b678f5bd469a4 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <b34dc87751a8667f22ea78730a5b678f5bd469a4@dist-git>
5c27b6
From: Jiri Denemark <jdenemar@redhat.com>
5c27b6
Date: Tue, 25 Apr 2017 19:07:19 +0200
5c27b6
Subject: [PATCH] qemu: Add support for guest CPU cache
5c27b6
5c27b6
This patch maps /domain/cpu/cache element into -cpu parameters:
5c27b6
5c27b6
- <cache mode='passthrough'/> is translated to host-cache-info=on
5c27b6
- <cache level='3' mode='emulate'/> is transformed into l3-cache=on
5c27b6
- <cache mode='disable'/> is turned in host-cache-info=off,l3-cache=off
5c27b6
5c27b6
Any other <cache> element is forbidden.
5c27b6
5c27b6
The tricky part is detecting whether QEMU supports the CPU properties.
5c27b6
5c27b6
The 'host-cache-info' property is introduced in v2.4.0-1389-ge265e3e480,
5c27b6
earlier QEMU releases enabled host-cache-info by default and had no way
5c27b6
to disable it. If the property is present, it defaults to 'off' for any
5c27b6
QEMU until at least 2.9.0.
5c27b6
5c27b6
The 'l3-cache' property was introduced later by v2.7.0-200-g14c985cffa.
5c27b6
Earlier versions worked as if l3-cache=off was passed. For any QEMU
5c27b6
until at least 2.9.0 l3-cache is 'off' by default.
5c27b6
5c27b6
QEMU 2.9.0 was the first release which supports probing both properties
5c27b6
by running device-list-properties with typename=host-x86_64-cpu. Older
5c27b6
QEMU releases did not support device-list-properties command for CPU
5c27b6
devices. Thus we can't really rely on probing them and we can just use
5c27b6
query-cpu-model-expansion QMP command as a witness.
5c27b6
5c27b6
Because the cache property probing is only reliable for QEMU >= 2.9.0
5c27b6
when both are already supported for quite a few releases, we let QEMU
5c27b6
report an error if a specific cache mode is explicitly requested. The
5c27b6
other mode (or both if a user requested CPU cache to be disabled) is
5c27b6
explicitly turned off for QEMU >= 2.9.0 to avoid any surprises in case
5c27b6
the QEMU defaults change. Any older QEMU already turns them off so not
5c27b6
doing so explicitly does not make any harm.
5c27b6
5c27b6
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
5c27b6
(cherry picked from commit df13c0b477ffda460eed259c3b8aab7255f11199)
5c27b6
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1428952
5c27b6
5c27b6
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
5c27b6
---
3e5111
 src/qemu/qemu_capabilities.c                       |  5 ++
3e5111
 src/qemu/qemu_capabilities.h                       |  1 +
3e5111
 src/qemu/qemu_command.c                            | 39 ++++++++++++++++
3e5111
 src/qemu/qemu_domain.c                             | 54 ++++++++++++++++++++++
3e5111
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  1 +
3e5111
 .../qemuxml2argv-cpu-cache-disable.args            | 21 +++++++++
3e5111
 .../qemuxml2argv-cpu-cache-disable.xml             | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-disable2.args           | 21 +++++++++
3e5111
 .../qemuxml2argv-cpu-cache-disable2.xml            | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-disable3.args           | 22 +++++++++
3e5111
 .../qemuxml2argv-cpu-cache-disable3.xml            | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-emulate-l2.xml          | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-emulate-l3.args         | 21 +++++++++
3e5111
 .../qemuxml2argv-cpu-cache-emulate-l3.xml          | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-passthrough-l3.xml      | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-passthrough.args        | 21 +++++++++
3e5111
 .../qemuxml2argv-cpu-cache-passthrough.xml         | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-passthrough2.args       | 21 +++++++++
3e5111
 .../qemuxml2argv-cpu-cache-passthrough2.xml        | 20 ++++++++
3e5111
 .../qemuxml2argv-cpu-cache-passthrough3.xml        | 20 ++++++++
3e5111
 tests/qemuxml2argvtest.c                           | 10 ++++
3e5111
 21 files changed, 417 insertions(+)
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.args
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.args
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.args
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l2.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.args
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough-l3.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.args
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.args
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.xml
5c27b6
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough3.xml
5c27b6
3e5111
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
3e5111
index 950a42bae..2c845853a 100644
3e5111
--- a/src/qemu/qemu_capabilities.c
3e5111
+++ b/src/qemu/qemu_capabilities.c
3e5111
@@ -364,6 +364,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
3e5111
               "query-cpu-definitions", /* 250 */
3e5111
               "block-write-threshold",
3e5111
               "query-named-block-nodes",
3e5111
+              "cpu-cache",
3e5111
     );
3e5111
 
3e5111
 
3e5111
@@ -4648,6 +4649,10 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
3e5111
         virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVDIMM))
3e5111
         virQEMUCapsClear(qemuCaps, QEMU_CAPS_DEVICE_NVDIMM);
3e5111
 
3e5111
+    if (ARCH_IS_X86(qemuCaps->arch) &&
3e5111
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
3e5111
+        virQEMUCapsSet(qemuCaps, QEMU_CAPS_CPU_CACHE);
3e5111
+
3e5111
     ret = 0;
3e5111
  cleanup:
3e5111
     return ret;
3e5111
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
3e5111
index 24e2f38ee..c466a63e7 100644
3e5111
--- a/src/qemu/qemu_capabilities.h
3e5111
+++ b/src/qemu/qemu_capabilities.h
3e5111
@@ -401,6 +401,7 @@ typedef enum {
3e5111
     QEMU_CAPS_QUERY_CPU_DEFINITIONS, /* qmp query-cpu-definitions */
3e5111
     QEMU_CAPS_BLOCK_WRITE_THRESHOLD, /* BLOCK_WRITE_THRESHOLD event */
3e5111
     QEMU_CAPS_QUERY_NAMED_BLOCK_NODES, /* qmp query-named-block-nodes */
3e5111
+    QEMU_CAPS_CPU_CACHE, /* -cpu supports host-cache-info and l3-cache properties */
3e5111
 
3e5111
     QEMU_CAPS_LAST /* this must always be the last item */
3e5111
 } virQEMUCapsFlags;
5c27b6
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
3e5111
index ff7f47e06..2105cde58 100644
5c27b6
--- a/src/qemu/qemu_command.c
5c27b6
+++ b/src/qemu/qemu_command.c
3e5111
@@ -7071,6 +7071,45 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
5c27b6
         have_cpu = true;
5c27b6
     }
5c27b6
 
5c27b6
+    if (def->cpu && def->cpu->cache) {
5c27b6
+        virCPUCacheDefPtr cache = def->cpu->cache;
3e5111
+        bool hostOff = false;
3e5111
+        bool l3Off = false;
5c27b6
+
5c27b6
+        if (!have_cpu) {
5c27b6
+            virBufferAdd(&buf, default_model, -1);
5c27b6
+            have_cpu = true;
5c27b6
+        }
5c27b6
+
5c27b6
+        switch (cache->mode) {
5c27b6
+        case VIR_CPU_CACHE_MODE_EMULATE:
5c27b6
+            virBufferAddLit(&buf, ",l3-cache=on");
3e5111
+            hostOff = true;
5c27b6
+            break;
5c27b6
+
5c27b6
+        case VIR_CPU_CACHE_MODE_PASSTHROUGH:
5c27b6
+            virBufferAddLit(&buf, ",host-cache-info=on");
3e5111
+            l3Off = true;
5c27b6
+            break;
5c27b6
+
5c27b6
+        case VIR_CPU_CACHE_MODE_DISABLE:
3e5111
+            hostOff = l3Off = true;
3e5111
+            break;
3e5111
+
5c27b6
+        case VIR_CPU_CACHE_MODE_LAST:
5c27b6
+            break;
5c27b6
+        }
3e5111
+
3e5111
+        if (hostOff &&
3e5111
+            def->cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH &&
3e5111
+            virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_CACHE))
3e5111
+            virBufferAddLit(&buf, ",host-cache-info=off");
3e5111
+
3e5111
+        if (l3Off &&
3e5111
+            virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_CACHE))
3e5111
+            virBufferAddLit(&buf, ",l3-cache=off");
5c27b6
+    }
5c27b6
+
5c27b6
     if (virBufferCheckError(&buf) < 0)
5c27b6
         goto cleanup;
5c27b6
 
5c27b6
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
3e5111
index 9c09ced0c..d31645fd1 100644
5c27b6
--- a/src/qemu/qemu_domain.c
5c27b6
+++ b/src/qemu/qemu_domain.c
3e5111
@@ -2688,6 +2688,60 @@ qemuDomainDefCPUPostParse(virDomainDefPtr def)
3e5111
     if (!def->cpu)
3e5111
         return 0;
5c27b6
 
5c27b6
+    if (def->cpu->cache) {
5c27b6
+        virCPUCacheDefPtr cache = def->cpu->cache;
5c27b6
+
5c27b6
+        if (!ARCH_IS_X86(def->os.arch)) {
5c27b6
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
5c27b6
+                           _("CPU cache specification is not supported "
5c27b6
+                             "for '%s' architecture"),
5c27b6
+                           virArchToString(def->os.arch));
5c27b6
+            return -1;
5c27b6
+        }
5c27b6
+
5c27b6
+        switch (cache->mode) {
5c27b6
+        case VIR_CPU_CACHE_MODE_EMULATE:
5c27b6
+            if (cache->level != 3) {
5c27b6
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
5c27b6
+                               _("CPU cache mode '%s' can only be used with "
5c27b6
+                                 "level='3'"),
5c27b6
+                               virCPUCacheModeTypeToString(cache->mode));
5c27b6
+                return -1;
5c27b6
+            }
5c27b6
+            break;
5c27b6
+
5c27b6
+        case VIR_CPU_CACHE_MODE_PASSTHROUGH:
5c27b6
+            if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
5c27b6
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
5c27b6
+                               _("CPU cache mode '%s' can only be used with "
5c27b6
+                                 "'%s' CPUs"),
5c27b6
+                               virCPUCacheModeTypeToString(cache->mode),
5c27b6
+                               virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH));
5c27b6
+                return -1;
5c27b6
+            }
5c27b6
+
5c27b6
+            if (cache->level != -1) {
5c27b6
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
5c27b6
+                               _("unsupported CPU cache level for mode '%s'"),
5c27b6
+                               virCPUCacheModeTypeToString(cache->mode));
5c27b6
+                return -1;
5c27b6
+            }
5c27b6
+            break;
5c27b6
+
5c27b6
+        case VIR_CPU_CACHE_MODE_DISABLE:
5c27b6
+            if (cache->level != -1) {
5c27b6
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
5c27b6
+                               _("unsupported CPU cache level for mode '%s'"),
5c27b6
+                               virCPUCacheModeTypeToString(cache->mode));
5c27b6
+                return -1;
5c27b6
+            }
5c27b6
+            break;
5c27b6
+
5c27b6
+        case VIR_CPU_CACHE_MODE_LAST:
5c27b6
+            break;
5c27b6
+        }
5c27b6
+    }
5c27b6
+
3e5111
     /* Nothing to be done if only CPU topology is specified. */
3e5111
     if (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
3e5111
         !def->cpu->model)
3e5111
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
3e5111
index 6386c4ed0..496c9ceb8 100644
3e5111
--- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
3e5111
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
3e5111
@@ -207,6 +207,7 @@
3e5111
   <flag name='query-cpu-definitions'/>
3e5111
   <flag name='block-write-threshold'/>
3e5111
   <flag name='query-named-block-nodes'/>
3e5111
+  <flag name='cpu-cache'/>
3e5111
   <version>2008090</version>
3e5111
   <kvmVersion>0</kvmVersion>
3e5111
   <package> (v2.9.0-rc0-142-g940a8ce)</package>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.args
5c27b6
new file mode 100644
3e5111
index 000000000..386e38d37
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.args
5c27b6
@@ -0,0 +1,21 @@
5c27b6
+LC_ALL=C \
5c27b6
+PATH=/bin \
5c27b6
+HOME=/home/test \
5c27b6
+USER=test \
5c27b6
+LOGNAME=test \
5c27b6
+QEMU_AUDIO_DRV=none \
5c27b6
+/usr/bin/kvm \
5c27b6
+-name foo \
5c27b6
+-S \
5c27b6
+-M pc \
3e5111
+-cpu host,host-cache-info=off,l3-cache=off \
5c27b6
+-m 214 \
5c27b6
+-smp 1,sockets=1,cores=1,threads=1 \
5c27b6
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
5c27b6
+-nographic \
5c27b6
+-nodefaults \
5c27b6
+-monitor unix:/tmp/lib/domain--1-foo/monitor.sock,server,nowait \
5c27b6
+-no-acpi \
5c27b6
+-boot c \
5c27b6
+-usb \
5c27b6
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..e6f39951c
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-passthrough'>
5c27b6
+    <cache mode='disable'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.args
5c27b6
new file mode 100644
5c27b6
index 000000000..9348e01f8
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.args
5c27b6
@@ -0,0 +1,21 @@
5c27b6
+LC_ALL=C \
5c27b6
+PATH=/bin \
5c27b6
+HOME=/home/test \
5c27b6
+USER=test \
5c27b6
+LOGNAME=test \
5c27b6
+QEMU_AUDIO_DRV=none \
5c27b6
+/usr/bin/kvm \
5c27b6
+-name foo \
5c27b6
+-S \
5c27b6
+-M pc \
5c27b6
+-cpu host \
5c27b6
+-m 214 \
5c27b6
+-smp 1,sockets=1,cores=1,threads=1 \
5c27b6
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
5c27b6
+-nographic \
5c27b6
+-nodefaults \
5c27b6
+-monitor unix:/tmp/lib/domain--1-foo/monitor.sock,server,nowait \
5c27b6
+-no-acpi \
5c27b6
+-boot c \
5c27b6
+-usb \
5c27b6
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..e6f39951c
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable2.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-passthrough'>
5c27b6
+    <cache mode='disable'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.args
5c27b6
new file mode 100644
3e5111
index 000000000..b882710c1
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.args
5c27b6
@@ -0,0 +1,22 @@
5c27b6
+LC_ALL=C \
5c27b6
+PATH=/bin \
5c27b6
+HOME=/home/test \
5c27b6
+USER=test \
5c27b6
+LOGNAME=test \
5c27b6
+QEMU_AUDIO_DRV=none \
5c27b6
+/usr/bin/kvm \
5c27b6
+-name foo \
5c27b6
+-S \
5c27b6
+-M pc \
5c27b6
+-cpu core2duo,+ds,+acpi,+ss,+ht,+tm,+pbe,+ds_cpl,+vmx,+est,+tm2,+cx16,+xtpr,\
3e5111
++lahf_lm,l3-cache=off \
5c27b6
+-m 214 \
5c27b6
+-smp 1,sockets=1,cores=1,threads=1 \
5c27b6
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
5c27b6
+-nographic \
5c27b6
+-nodefaults \
5c27b6
+-monitor unix:/tmp/lib/domain--1-foo/monitor.sock,server,nowait \
5c27b6
+-no-acpi \
5c27b6
+-boot c \
5c27b6
+-usb \
5c27b6
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..17078a1e8
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable3.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-model'>
5c27b6
+    <cache mode='disable'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l2.xml
5c27b6
new file mode 100644
3e5111
index 000000000..4757e85ea
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l2.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
3e5111
+  <cpu mode='host-model' check='full'>
5c27b6
+    <cache level='2' mode='emulate'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.args
5c27b6
new file mode 100644
3e5111
index 000000000..c2f5d19e1
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.args
5c27b6
@@ -0,0 +1,21 @@
5c27b6
+LC_ALL=C \
5c27b6
+PATH=/bin \
5c27b6
+HOME=/home/test \
5c27b6
+USER=test \
5c27b6
+LOGNAME=test \
5c27b6
+QEMU_AUDIO_DRV=none \
5c27b6
+/usr/bin/kvm \
5c27b6
+-name foo \
5c27b6
+-S \
5c27b6
+-M pc \
3e5111
+-cpu host,l3-cache=on,host-cache-info=off \
5c27b6
+-m 214 \
5c27b6
+-smp 1,sockets=1,cores=1,threads=1 \
5c27b6
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
5c27b6
+-nographic \
5c27b6
+-nodefaults \
5c27b6
+-monitor unix:/tmp/lib/domain--1-foo/monitor.sock,server,nowait \
5c27b6
+-no-acpi \
5c27b6
+-boot c \
5c27b6
+-usb \
5c27b6
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..17019c673
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-emulate-l3.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-passthrough'>
5c27b6
+    <cache level='3' mode='emulate'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough-l3.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough-l3.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..3471115ea
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough-l3.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-passthrough'>
5c27b6
+    <cache level='3' mode='passthrough'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.args
5c27b6
new file mode 100644
3e5111
index 000000000..1d824f6dd
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.args
5c27b6
@@ -0,0 +1,21 @@
5c27b6
+LC_ALL=C \
5c27b6
+PATH=/bin \
5c27b6
+HOME=/home/test \
5c27b6
+USER=test \
5c27b6
+LOGNAME=test \
5c27b6
+QEMU_AUDIO_DRV=none \
5c27b6
+/usr/bin/kvm \
5c27b6
+-name foo \
5c27b6
+-S \
5c27b6
+-M pc \
3e5111
+-cpu host,host-cache-info=on,l3-cache=off \
5c27b6
+-m 214 \
5c27b6
+-smp 1,sockets=1,cores=1,threads=1 \
5c27b6
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
5c27b6
+-nographic \
5c27b6
+-nodefaults \
5c27b6
+-monitor unix:/tmp/lib/domain--1-foo/monitor.sock,server,nowait \
5c27b6
+-no-acpi \
5c27b6
+-boot c \
5c27b6
+-usb \
5c27b6
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..74846fdd3
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-passthrough'>
5c27b6
+    <cache mode='passthrough'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.args
5c27b6
new file mode 100644
5c27b6
index 000000000..d7863ba2e
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.args
5c27b6
@@ -0,0 +1,21 @@
5c27b6
+LC_ALL=C \
5c27b6
+PATH=/bin \
5c27b6
+HOME=/home/test \
5c27b6
+USER=test \
5c27b6
+LOGNAME=test \
5c27b6
+QEMU_AUDIO_DRV=none \
5c27b6
+/usr/bin/kvm \
5c27b6
+-name foo \
5c27b6
+-S \
5c27b6
+-M pc \
5c27b6
+-cpu host,host-cache-info=on \
5c27b6
+-m 214 \
5c27b6
+-smp 1,sockets=1,cores=1,threads=1 \
5c27b6
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
5c27b6
+-nographic \
5c27b6
+-nodefaults \
5c27b6
+-monitor unix:/tmp/lib/domain--1-foo/monitor.sock,server,nowait \
5c27b6
+-no-acpi \
5c27b6
+-boot c \
5c27b6
+-usb \
5c27b6
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..74846fdd3
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough2.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-passthrough'>
5c27b6
+    <cache mode='passthrough'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough3.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough3.xml
5c27b6
new file mode 100644
5c27b6
index 000000000..6ad65700b
5c27b6
--- /dev/null
5c27b6
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-passthrough3.xml
5c27b6
@@ -0,0 +1,20 @@
5c27b6
+<domain type='kvm'>
5c27b6
+  <name>foo</name>
5c27b6
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
5c27b6
+  <memory unit='KiB'>219136</memory>
5c27b6
+  <currentMemory unit='KiB'>219136</currentMemory>
5c27b6
+  <vcpu placement='static'>1</vcpu>
5c27b6
+  <os>
5c27b6
+    <type arch='x86_64' machine='pc'>hvm</type>
5c27b6
+    <boot dev='hd'/>
5c27b6
+  </os>
5c27b6
+  <cpu mode='host-model'>
5c27b6
+    <cache mode='passthrough'/>
5c27b6
+  </cpu>
5c27b6
+  <clock offset='utc'/>
5c27b6
+  <on_poweroff>destroy</on_poweroff>
5c27b6
+  <on_reboot>restart</on_reboot>
5c27b6
+  <on_crash>destroy</on_crash>
5c27b6
+  <devices>
5c27b6
+  </devices>
5c27b6
+</domain>
5c27b6
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
3e5111
index 94be771d3..81cd2a6ec 100644
5c27b6
--- a/tests/qemuxml2argvtest.c
5c27b6
+++ b/tests/qemuxml2argvtest.c
3e5111
@@ -2521,6 +2521,16 @@ mymain(void)
3e5111
     DO_TEST("cpu-check-default-partial", QEMU_CAPS_KVM);
3e5111
     DO_TEST("cpu-check-default-partial2", QEMU_CAPS_KVM);
5c27b6
 
3e5111
+    DO_TEST("cpu-cache-disable", QEMU_CAPS_KVM, QEMU_CAPS_CPU_CACHE);
5c27b6
+    DO_TEST("cpu-cache-disable2", QEMU_CAPS_KVM);
3e5111
+    DO_TEST("cpu-cache-disable3", QEMU_CAPS_KVM, QEMU_CAPS_CPU_CACHE);
3e5111
+    DO_TEST("cpu-cache-passthrough", QEMU_CAPS_KVM, QEMU_CAPS_CPU_CACHE);
5c27b6
+    DO_TEST("cpu-cache-passthrough2", QEMU_CAPS_KVM);
3e5111
+    DO_TEST("cpu-cache-emulate-l3", QEMU_CAPS_KVM, QEMU_CAPS_CPU_CACHE);
5c27b6
+    DO_TEST_PARSE_ERROR("cpu-cache-emulate-l2", QEMU_CAPS_KVM);
5c27b6
+    DO_TEST_PARSE_ERROR("cpu-cache-passthrough3", QEMU_CAPS_KVM);
5c27b6
+    DO_TEST_PARSE_ERROR("cpu-cache-passthrough-l3", QEMU_CAPS_KVM);
3e5111
+
5c27b6
     qemuTestDriverFree(&driver);
5c27b6
 
5c27b6
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
5c27b6
-- 
5c27b6
2.12.2
5c27b6