c1c534
From b66931b0282f0209a262854b54b590d008070f85 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <b66931b0282f0209a262854b54b590d008070f85@dist-git>
c1c534
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
c1c534
Date: Wed, 29 Nov 2017 17:00:04 +0100
c1c534
Subject: [PATCH] qemu: add vmcoreinfo support
c1c534
MIME-Version: 1.0
c1c534
Content-Type: text/plain; charset=UTF-8
c1c534
Content-Transfer-Encoding: 8bit
c1c534
c1c534
Starting from qemu 2.11, the `-device vmcoreinfo` will create a fw_cfg
c1c534
entry for a guest to store dump details, necessary to process kernel
c1c534
dump with KASLR enabled and providing additional kernel details.
c1c534
c1c534
In essence, it is similar to -fw_cfg name=etc/vmcoreinfo,file=X but in
c1c534
this case it is not backed by a file, but collected by QEMU itself.
c1c534
c1c534
Since the device is a singleton and shouldn't use additional hardware
c1c534
resources, it is presented as a <feature> element in the libvirt
c1c534
domain XML.
c1c534
c1c534
The device is arm/x86 only for now (targets that support fw_cfg+dma).
c1c534
c1c534
Related to:
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1395248
c1c534
c1c534
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
c1c534
(cherry picked from commit 7e4177a35bae49a53b04940be04418daaa988734)
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 docs/formatdomain.html.in                          |  4 +++
c1c534
 docs/schemas/domaincommon.rng                      |  9 +++++
c1c534
 src/conf/domain_conf.c                             |  3 ++
c1c534
 src/conf/domain_conf.h                             |  1 +
c1c534
 src/qemu/qemu_capabilities.c                       |  3 +-
c1c534
 src/qemu/qemu_capabilities.h                       |  2 +-
c1c534
 src/qemu/qemu_command.c                            | 25 ++++++++++++++
c1c534
 .../qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args  | 25 ++++++++++++++
c1c534
 tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml | 28 ++++++++++++++++
c1c534
 tests/qemuxml2argvtest.c                           |  1 +
c1c534
 .../qemuxml2xmlout-vmcoreinfo.xml                  | 38 ++++++++++++++++++++++
c1c534
 tests/qemuxml2xmltest.c                            |  1 +
c1c534
 12 files changed, 138 insertions(+), 2 deletions(-)
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml
c1c534
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml
c1c534
c1c534
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
c1c534
index cc1c5577cd..6807da5c6f 100644
c1c534
--- a/docs/formatdomain.html.in
c1c534
+++ b/docs/formatdomain.html.in
c1c534
@@ -1940,6 +1940,10 @@
c1c534
           which is also known as a split I/O APIC mode.
c1c534
           Since 3.4.0 (QEMU/KVM only)
c1c534
       
c1c534
+      
vmcoreinfo
c1c534
+      
Enable QEMU vmcoreinfo device to let the guest kernel save debug
c1c534
+          details. Since 3.10.0 (QEMU only)
c1c534
+      
c1c534
     
c1c534
 
c1c534
     

Time keeping

c1c534
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
c1c534
index 5576128db5..05709afc0c 100644
c1c534
--- a/docs/schemas/domaincommon.rng
c1c534
+++ b/docs/schemas/domaincommon.rng
c1c534
@@ -4747,6 +4747,9 @@
c1c534
           <optional>
c1c534
             <ref name="hpt"/>
c1c534
           </optional>
c1c534
+          <optional>
c1c534
+            <ref name="vmcoreinfo"/>
c1c534
+          </optional>
c1c534
         </interleave>
c1c534
       </element>
c1c534
     </optional>
c1c534
@@ -4947,6 +4950,12 @@
c1c534
     </element>
c1c534
   </define>
c1c534
 
c1c534
+  <define name="vmcoreinfo">
c1c534
+    <element name="vmcoreinfo">
c1c534
+      <empty/>
c1c534
+    </element>
c1c534
+  </define>
c1c534
+
c1c534
   <define name="address">
c1c534
     <element name="address">
c1c534
       <choice>
c1c534
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c1c534
index bd6d851f21..2d54037b71 100644
c1c534
--- a/src/conf/domain_conf.c
c1c534
+++ b/src/conf/domain_conf.c
c1c534
@@ -150,6 +150,7 @@ VIR_ENUM_IMPL(virDomainFeature, VIR_DOMAIN_FEATURE_LAST,
c1c534
               "smm",
c1c534
               "ioapic",
c1c534
               "hpt",
c1c534
+              "vmcoreinfo",
c1c534
 );
c1c534
 
c1c534
 VIR_ENUM_IMPL(virDomainCapabilitiesPolicy, VIR_DOMAIN_CAPABILITIES_POLICY_LAST,
c1c534
@@ -18824,6 +18825,7 @@ virDomainDefParseXML(xmlDocPtr xml,
c1c534
         case VIR_DOMAIN_FEATURE_VIRIDIAN:
c1c534
         case VIR_DOMAIN_FEATURE_PRIVNET:
c1c534
         case VIR_DOMAIN_FEATURE_HYPERV:
c1c534
+        case VIR_DOMAIN_FEATURE_VMCOREINFO:
c1c534
         case VIR_DOMAIN_FEATURE_KVM:
c1c534
             def->features[val] = VIR_TRISTATE_SWITCH_ON;
c1c534
             break;
c1c534
@@ -26265,6 +26267,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
c1c534
             case VIR_DOMAIN_FEATURE_ACPI:
c1c534
             case VIR_DOMAIN_FEATURE_PAE:
c1c534
             case VIR_DOMAIN_FEATURE_VIRIDIAN:
c1c534
+            case VIR_DOMAIN_FEATURE_VMCOREINFO:
c1c534
             case VIR_DOMAIN_FEATURE_PRIVNET:
c1c534
                 switch ((virTristateSwitch) def->features[i]) {
c1c534
                 case VIR_TRISTATE_SWITCH_ABSENT:
c1c534
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
c1c534
index 479a791f29..698d3280fe 100644
c1c534
--- a/src/conf/domain_conf.h
c1c534
+++ b/src/conf/domain_conf.h
c1c534
@@ -1735,6 +1735,7 @@ typedef enum {
c1c534
     VIR_DOMAIN_FEATURE_SMM,
c1c534
     VIR_DOMAIN_FEATURE_IOAPIC,
c1c534
     VIR_DOMAIN_FEATURE_HPT,
c1c534
+    VIR_DOMAIN_FEATURE_VMCOREINFO,
c1c534
 
c1c534
     VIR_DOMAIN_FEATURE_LAST
c1c534
 } virDomainFeature;
c1c534
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
c1c534
index 13ff1286c4..4301d2e799 100644
c1c534
--- a/src/qemu/qemu_capabilities.c
c1c534
+++ b/src/qemu/qemu_capabilities.c
c1c534
@@ -444,7 +444,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
c1c534
               "vxhs",
c1c534
               "virtio-blk.num-queues",
c1c534
               "machine.pseries.resize-hpt",
c1c534
-
c1c534
+              "vmcoreinfo",
c1c534
               "spapr-vty",
c1c534
 
c1c534
               /* 275 */
c1c534
@@ -1684,6 +1684,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
c1c534
     { "pcie-root-port", QEMU_CAPS_DEVICE_PCIE_ROOT_PORT },
c1c534
     { "qemu-xhci", QEMU_CAPS_DEVICE_QEMU_XHCI },
c1c534
     { "spapr-pci-host-bridge", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE },
c1c534
+    { "vmcoreinfo", QEMU_CAPS_DEVICE_VMCOREINFO },
c1c534
     { "spapr-vty", QEMU_CAPS_DEVICE_SPAPR_VTY },
c1c534
     { "sclplmconsole", QEMU_CAPS_DEVICE_SCLPLMCONSOLE },
c1c534
     { "isa-serial", QEMU_CAPS_DEVICE_ISA_SERIAL },
c1c534
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
c1c534
index 3e016b7c79..c6eb9df146 100644
c1c534
--- a/src/qemu/qemu_capabilities.h
c1c534
+++ b/src/qemu/qemu_capabilities.h
c1c534
@@ -430,7 +430,7 @@ typedef enum {
c1c534
     QEMU_CAPS_VXHS, /* -drive file.driver=vxhs via query-qmp-schema */
c1c534
     QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES, /* virtio-blk-*.num-queues */
c1c534
     QEMU_CAPS_MACHINE_PSERIES_RESIZE_HPT, /* -machine pseries,resize-hpt */
c1c534
-
c1c534
+    QEMU_CAPS_DEVICE_VMCOREINFO, /* -device vmcoreinfo */
c1c534
     QEMU_CAPS_DEVICE_SPAPR_VTY, /* -device spapr-vty */
c1c534
 
c1c534
     /* 275 */
c1c534
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c1c534
index b462c7cf09..a1bf230fad 100644
c1c534
--- a/src/qemu/qemu_command.c
c1c534
+++ b/src/qemu/qemu_command.c
c1c534
@@ -9922,6 +9922,28 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static int
c1c534
+qemuBuildVMCoreInfoCommandLine(virCommandPtr cmd,
c1c534
+                               const virDomainDef *def,
c1c534
+                               virQEMUCapsPtr qemuCaps)
c1c534
+{
c1c534
+    virTristateSwitch vmci = def->features[VIR_DOMAIN_FEATURE_VMCOREINFO];
c1c534
+
c1c534
+    if (vmci != VIR_TRISTATE_SWITCH_ON)
c1c534
+        return 0;
c1c534
+
c1c534
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMCOREINFO)) {
c1c534
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
c1c534
+                       _("vmcoreinfo is not available "
c1c534
+                         "with this QEMU binary"));
c1c534
+        return -1;
c1c534
+    }
c1c534
+
c1c534
+    virCommandAddArgList(cmd, "-device", "vmcoreinfo", NULL);
c1c534
+    return 0;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 qemuBuildPanicCommandLine(virCommandPtr cmd,
c1c534
                           const virDomainDef *def,
c1c534
@@ -10341,6 +10363,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
c1c534
     if (qemuBuildNVRAMCommandLine(cmd, def, qemuCaps) < 0)
c1c534
         goto error;
c1c534
 
c1c534
+    if (qemuBuildVMCoreInfoCommandLine(cmd, def, qemuCaps) < 0)
c1c534
+        goto error;
c1c534
+
c1c534
     if (snapshot)
c1c534
         virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL);
c1c534
 
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args
c1c534
new file mode 100644
c1c534
index 0000000000..772e5a071f
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args
c1c534
@@ -0,0 +1,25 @@
c1c534
+LC_ALL=C \
c1c534
+PATH=/bin \
c1c534
+HOME=/home/test \
c1c534
+USER=test \
c1c534
+LOGNAME=test \
c1c534
+QEMU_AUDIO_DRV=none \
c1c534
+/usr/bin/qemu-system-i686 \
c1c534
+-name QEMUGuest1 \
c1c534
+-S \
c1c534
+-M pc \
c1c534
+-m 214 \
c1c534
+-smp 1,sockets=1,cores=1,threads=1 \
c1c534
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
c1c534
+-nographic \
c1c534
+-nodefaults \
c1c534
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
c1c534
+server,nowait \
c1c534
+-mon chardev=charmonitor,id=monitor,mode=readline \
c1c534
+-no-acpi \
c1c534
+-boot c \
c1c534
+-usb \
c1c534
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
c1c534
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
c1c534
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
c1c534
+-device vmcoreinfo
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml
c1c534
new file mode 100644
c1c534
index 0000000000..f8e5865310
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml
c1c534
@@ -0,0 +1,28 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>QEMUGuest1</name>
c1c534
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c1c534
+  <memory unit='KiB'>219100</memory>
c1c534
+  <currentMemory unit='KiB'>219100</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='i686' machine='pc'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
c1c534
+  <features>
c1c534
+    <vmcoreinfo/>
c1c534
+  </features>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-i686</emulator>
c1c534
+    <disk type='block' device='disk'>
c1c534
+      <source dev='/dev/HostVG/QEMUGuest1'/>
c1c534
+      <target dev='hda' bus='ide'/>
c1c534
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c1c534
+    </disk>
c1c534
+    <controller type='ide' index='0'/>
c1c534
+    <memballoon model='virtio'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c1c534
index 686a63855c..686d289b89 100644
c1c534
--- a/tests/qemuxml2argvtest.c
c1c534
+++ b/tests/qemuxml2argvtest.c
c1c534
@@ -2933,6 +2933,7 @@ mymain(void)
c1c534
     DO_TEST_PARSE_ERROR("cpu-cache-emulate-l2", QEMU_CAPS_KVM);
c1c534
     DO_TEST_PARSE_ERROR("cpu-cache-passthrough3", QEMU_CAPS_KVM);
c1c534
     DO_TEST_PARSE_ERROR("cpu-cache-passthrough-l3", QEMU_CAPS_KVM);
c1c534
+    DO_TEST("vmcoreinfo", QEMU_CAPS_DEVICE_VMCOREINFO);
c1c534
 
c1c534
     DO_TEST("user-aliases", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_CIRRUS_VGA,
c1c534
             QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_PIIX_DISABLE_S3,
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml
c1c534
new file mode 100644
c1c534
index 0000000000..a3922d6304
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml
c1c534
@@ -0,0 +1,38 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>QEMUGuest1</name>
c1c534
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c1c534
+  <memory unit='KiB'>219100</memory>
c1c534
+  <currentMemory unit='KiB'>219100</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='i686' machine='pc'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
c1c534
+  <features>
c1c534
+    <vmcoreinfo/>
c1c534
+  </features>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-i686</emulator>
c1c534
+    <disk type='block' device='disk'>
c1c534
+      <source dev='/dev/HostVG/QEMUGuest1'/>
c1c534
+      <target dev='hda' bus='ide'/>
c1c534
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c1c534
+    </disk>
c1c534
+    <controller type='ide' index='0'>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
c1c534
+    </controller>
c1c534
+    <controller type='usb' index='0'>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
c1c534
+    </controller>
c1c534
+    <controller type='pci' index='0' model='pci-root'/>
c1c534
+    <input type='mouse' bus='ps2'/>
c1c534
+    <input type='keyboard' bus='ps2'/>
c1c534
+    <memballoon model='virtio'>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
c1c534
+    </memballoon>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
c1c534
index 8766646738..5ca0ea3a22 100644
c1c534
--- a/tests/qemuxml2xmltest.c
c1c534
+++ b/tests/qemuxml2xmltest.c
c1c534
@@ -1319,6 +1319,7 @@ mymain(void)
c1c534
     DO_TEST("cpu-check-default-none2", NONE);
c1c534
     DO_TEST("cpu-check-default-partial", NONE);
c1c534
     DO_TEST("cpu-check-default-partial2", NONE);
c1c534
+    DO_TEST("vmcoreinfo", NONE);
c1c534
 
c1c534
     DO_TEST("smartcard-host", NONE);
c1c534
     DO_TEST("smartcard-host-certificates", NONE);
c1c534
-- 
c1c534
2.15.1
c1c534