5c27b6
From b638d9571e6497978c350e86671d9161c0b4c314 Mon Sep 17 00:00:00 2001
5c27b6
Message-Id: <b638d9571e6497978c350e86671d9161c0b4c314@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
5c27b6
https://bugzilla.redhat.com/show_bug.cgi?id=1447612
5c27b6
5c27b6
Conflicts:
5c27b6
    - mostly context onflicts
5c27b6
    - qemuDomainDefCPUPostParse did not exist in 7.3
5c27b6
    - QEMU_CAPS_CPU_CACHE capability was not backported because it
5c27b6
      depends on non-existent QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION and
5c27b6
      thus it would never be set anyway; in other words, l3-cache=off
5c27b6
      and host-cache-info=off will never be used
5c27b6
5c27b6
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
5c27b6
---
5c27b6
 src/qemu/qemu_command.c                            | 23 ++++++++
5c27b6
 src/qemu/qemu_domain.c                             | 67 ++++++++++++++++++++++
5c27b6
 .../qemuxml2argv-cpu-cache-disable.args            | 21 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-disable.xml             | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-disable2.args           | 21 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-disable2.xml            | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-disable3.args           | 22 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-disable3.xml            | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-emulate-l2.xml          | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-emulate-l3.args         | 21 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-emulate-l3.xml          | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-passthrough-l3.xml      | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-passthrough.args        | 21 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-passthrough.xml         | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-passthrough2.args       | 21 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-passthrough2.xml        | 20 +++++++
5c27b6
 .../qemuxml2argv-cpu-cache-passthrough3.xml        | 20 +++++++
5c27b6
 tests/qemuxml2argvtest.c                           |  9 +++
5c27b6
 18 files changed, 406 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
5c27b6
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
5c27b6
index bd01a0f76..f5b41257c 100644
5c27b6
--- a/src/qemu/qemu_command.c
5c27b6
+++ b/src/qemu/qemu_command.c
5c27b6
@@ -6854,6 +6854,29 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
5c27b6
         have_cpu = true;
5c27b6
     }
5c27b6
 
5c27b6
+    if (def->cpu && def->cpu->cache) {
5c27b6
+        virCPUCacheDefPtr cache = def->cpu->cache;
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");
5c27b6
+            break;
5c27b6
+
5c27b6
+        case VIR_CPU_CACHE_MODE_PASSTHROUGH:
5c27b6
+            virBufferAddLit(&buf, ",host-cache-info=on");
5c27b6
+            break;
5c27b6
+
5c27b6
+        case VIR_CPU_CACHE_MODE_DISABLE:
5c27b6
+        case VIR_CPU_CACHE_MODE_LAST:
5c27b6
+            break;
5c27b6
+        }
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
5c27b6
index b91db229f..7aa6de742 100644
5c27b6
--- a/src/qemu/qemu_domain.c
5c27b6
+++ b/src/qemu/qemu_domain.c
5c27b6
@@ -2328,6 +2328,70 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def)
5c27b6
 
5c27b6
 
5c27b6
 static int
5c27b6
+qemuDomainDefCPUPostParse(virDomainDefPtr def)
5c27b6
+{
5c27b6
+    if (!def->cpu)
5c27b6
+        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
+
5c27b6
+    return 0;
5c27b6
+}
5c27b6
+
5c27b6
+
5c27b6
+static int
5c27b6
 qemuDomainDefPostParse(virDomainDefPtr def,
5c27b6
                        virCapsPtr caps,
5c27b6
                        unsigned int parseFlags,
5c27b6
@@ -2385,6 +2449,9 @@ qemuDomainDefPostParse(virDomainDefPtr def,
5c27b6
     if (qemuDomainDefVcpusPostParse(def) < 0)
5c27b6
         goto cleanup;
5c27b6
 
5c27b6
+    if (qemuDomainDefCPUPostParse(def) < 0)
5c27b6
+        goto cleanup;
5c27b6
+
5c27b6
     ret = 0;
5c27b6
  cleanup:
5c27b6
     virObjectUnref(qemuCaps);
5c27b6
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-cache-disable.args
5c27b6
new file mode 100644
5c27b6
index 000000000..9348e01f8
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 \
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-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
5c27b6
index 000000000..bbfd5ba2c
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,\
5c27b6
++lahf_lm \
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
5c27b6
index 000000000..0d1652e5c
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>
5c27b6
+  <cpu mode='host-model'>
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
5c27b6
index 000000000..0b9fb18e9
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 \
5c27b6
+-cpu host,l3-cache=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-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
5c27b6
index 000000000..d7863ba2e
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 \
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-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
5c27b6
index cbf785e1b..3cc798782 100644
5c27b6
--- a/tests/qemuxml2argvtest.c
5c27b6
+++ b/tests/qemuxml2argvtest.c
5c27b6
@@ -2117,6 +2117,15 @@ mymain(void)
5c27b6
 
5c27b6
     DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
5c27b6
 
5c27b6
+    DO_TEST("cpu-cache-disable", QEMU_CAPS_KVM);
5c27b6
+    DO_TEST("cpu-cache-disable2", QEMU_CAPS_KVM);
5c27b6
+    DO_TEST("cpu-cache-disable3", QEMU_CAPS_KVM);
5c27b6
+    DO_TEST("cpu-cache-passthrough", QEMU_CAPS_KVM);
5c27b6
+    DO_TEST("cpu-cache-passthrough2", QEMU_CAPS_KVM);
5c27b6
+    DO_TEST("cpu-cache-emulate-l3", QEMU_CAPS_KVM);
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);
5c27b6
     qemuTestDriverFree(&driver);
5c27b6
 
5c27b6
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
5c27b6
-- 
5c27b6
2.12.2
5c27b6