Blame SOURCES/kvm-hw-misc-add-vmcoreinfo-device.patch

9bac43
From a230ce8214e3d23ddb3aae86c9afa9bfb0242e83 Mon Sep 17 00:00:00 2001
9bac43
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
9bac43
Date: Mon, 27 Nov 2017 22:51:05 +0100
9bac43
Subject: [PATCH 07/21] hw/misc: add vmcoreinfo device
9bac43
MIME-Version: 1.0
9bac43
Content-Type: text/plain; charset=UTF-8
9bac43
Content-Transfer-Encoding: 8bit
9bac43
9bac43
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
Message-id: <20171127225111.24518-4-marcandre.lureau@redhat.com>
9bac43
Patchwork-id: 77924
9bac43
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 3/9] hw/misc: add vmcoreinfo device
9bac43
Bugzilla: 1398633
9bac43
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9bac43
RH-Acked-by: Andrew Jones <drjones@redhat.com>
9bac43
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
See docs/specs/vmcoreinfo.txt for details.
9bac43
9bac43
"etc/vmcoreinfo" fw_cfg entry is added when using "-device vmcoreinfo".
9bac43
9bac43
Minor conflict in hw/misc/Makefile.objs due to commented device
9bac43
introduced in commit 0e72e616b2d80e47c0eb6c5976276e9f8d920e92
9bac43
9bac43
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
9bac43
(cherry picked from commit 6e43353f10c6688060af0bc26bdfdd4cf9c96ea2)
9bac43
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 docs/specs/vmcoreinfo.txt    | 41 +++++++++++++++++++
9bac43
 hw/misc/Makefile.objs        |  1 +
9bac43
 hw/misc/vmcoreinfo.c         | 96 ++++++++++++++++++++++++++++++++++++++++++++
9bac43
 include/hw/misc/vmcoreinfo.h | 46 +++++++++++++++++++++
9bac43
 4 files changed, 184 insertions(+)
9bac43
 create mode 100644 docs/specs/vmcoreinfo.txt
9bac43
 create mode 100644 hw/misc/vmcoreinfo.c
9bac43
 create mode 100644 include/hw/misc/vmcoreinfo.h
9bac43
9bac43
diff --git a/docs/specs/vmcoreinfo.txt b/docs/specs/vmcoreinfo.txt
9bac43
new file mode 100644
9bac43
index 0000000..2868a77
9bac43
--- /dev/null
9bac43
+++ b/docs/specs/vmcoreinfo.txt
9bac43
@@ -0,0 +1,41 @@
9bac43
+=================
9bac43
+VMCoreInfo device
9bac43
+=================
9bac43
+
9bac43
+The `-device vmcoreinfo` will create a fw_cfg entry for a guest to
9bac43
+store dump details.
9bac43
+
9bac43
+etc/vmcoreinfo
9bac43
+**************
9bac43
+
9bac43
+A guest may use this fw_cfg entry to add information details to qemu
9bac43
+dumps.
9bac43
+
9bac43
+The entry of 16 bytes has the following layout, in little-endian::
9bac43
+
9bac43
+#define VMCOREINFO_FORMAT_NONE 0x0
9bac43
+#define VMCOREINFO_FORMAT_ELF 0x1
9bac43
+
9bac43
+    struct FWCfgVMCoreInfo {
9bac43
+        uint16_t host_format;  /* formats host supports */
9bac43
+        uint16_t guest_format; /* format guest supplies */
9bac43
+        uint32_t size;         /* size of vmcoreinfo region */
9bac43
+        uint64_t paddr;        /* physical address of vmcoreinfo region */
9bac43
+    };
9bac43
+
9bac43
+Only full write (of 16 bytes) are considered valid for further
9bac43
+processing of entry values.
9bac43
+
9bac43
+A write of 0 in guest_format will disable further processing of
9bac43
+vmcoreinfo entry values & content.
9bac43
+
9bac43
+Format & content
9bac43
+****************
9bac43
+
9bac43
+As of qemu 2.11, only VMCOREINFO_FORMAT_ELF is supported.
9bac43
+
9bac43
+The entry gives location and size of an ELF note that is appended in
9bac43
+qemu dumps.
9bac43
+
9bac43
+The note format/class must be of the target bitness and the size must
9bac43
+be less than 1Mb.
9bac43
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
9bac43
index a1007ae..b4cbebf 100644
9bac43
--- a/hw/misc/Makefile.objs
9bac43
+++ b/hw/misc/Makefile.objs
9bac43
@@ -9,6 +9,7 @@ common-obj-$(CONFIG_PCI_TESTDEV) += pci-testdev.o
9bac43
 common-obj-$(CONFIG_EDU) += edu.o
9bac43
 
9bac43
 #common-obj-y += unimp.o
9bac43
+common-obj-y += vmcoreinfo.o
9bac43
 
9bac43
 obj-$(CONFIG_VMPORT) += vmport.o
9bac43
 
9bac43
diff --git a/hw/misc/vmcoreinfo.c b/hw/misc/vmcoreinfo.c
9bac43
new file mode 100644
9bac43
index 0000000..a618e12
9bac43
--- /dev/null
9bac43
+++ b/hw/misc/vmcoreinfo.c
9bac43
@@ -0,0 +1,96 @@
9bac43
+/*
9bac43
+ * Virtual Machine coreinfo device
9bac43
+ *
9bac43
+ * Copyright (C) 2017 Red Hat, Inc.
9bac43
+ *
9bac43
+ * Authors: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
+ *
9bac43
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
9bac43
+ * See the COPYING file in the top-level directory.
9bac43
+ *
9bac43
+ */
9bac43
+#include "qemu/osdep.h"
9bac43
+#include "qapi/error.h"
9bac43
+#include "hw/nvram/fw_cfg.h"
9bac43
+#include "hw/misc/vmcoreinfo.h"
9bac43
+
9bac43
+static void fw_cfg_vmci_write(void *dev, off_t offset, size_t len)
9bac43
+{
9bac43
+    VMCoreInfoState *s = VMCOREINFO(dev);
9bac43
+
9bac43
+    s->has_vmcoreinfo = offset == 0 && len == sizeof(s->vmcoreinfo)
9bac43
+        && s->vmcoreinfo.guest_format != VMCOREINFO_FORMAT_NONE;
9bac43
+}
9bac43
+
9bac43
+static void vmcoreinfo_reset(void *dev)
9bac43
+{
9bac43
+    VMCoreInfoState *s = VMCOREINFO(dev);
9bac43
+
9bac43
+    s->has_vmcoreinfo = false;
9bac43
+    memset(&s->vmcoreinfo, 0, sizeof(s->vmcoreinfo));
9bac43
+    s->vmcoreinfo.host_format = cpu_to_le16(VMCOREINFO_FORMAT_ELF);
9bac43
+}
9bac43
+
9bac43
+static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
9bac43
+{
9bac43
+    VMCoreInfoState *s = VMCOREINFO(dev);
9bac43
+    FWCfgState *fw_cfg = fw_cfg_find();
9bac43
+
9bac43
+    /* Given that this function is executing, there is at least one VMCOREINFO
9bac43
+     * device. Check if there are several.
9bac43
+     */
9bac43
+    if (!vmcoreinfo_find()) {
9bac43
+        error_setg(errp, "at most one %s device is permitted",
9bac43
+                   VMCOREINFO_DEVICE);
9bac43
+        return;
9bac43
+    }
9bac43
+
9bac43
+    if (!fw_cfg || !fw_cfg->dma_enabled) {
9bac43
+        error_setg(errp, "%s device requires fw_cfg with DMA",
9bac43
+                   VMCOREINFO_DEVICE);
9bac43
+        return;
9bac43
+    }
9bac43
+
9bac43
+    fw_cfg_add_file_callback(fw_cfg, "etc/vmcoreinfo",
9bac43
+                             NULL, fw_cfg_vmci_write, s,
9bac43
+                             &s->vmcoreinfo, sizeof(s->vmcoreinfo), false);
9bac43
+
9bac43
+    qemu_register_reset(vmcoreinfo_reset, dev);
9bac43
+}
9bac43
+
9bac43
+static const VMStateDescription vmstate_vmcoreinfo = {
9bac43
+    .name = "vmcoreinfo",
9bac43
+    .version_id = 1,
9bac43
+    .minimum_version_id = 1,
9bac43
+    .fields = (VMStateField[]) {
9bac43
+        VMSTATE_BOOL(has_vmcoreinfo, VMCoreInfoState),
9bac43
+        VMSTATE_UINT16(vmcoreinfo.host_format, VMCoreInfoState),
9bac43
+        VMSTATE_UINT16(vmcoreinfo.guest_format, VMCoreInfoState),
9bac43
+        VMSTATE_UINT32(vmcoreinfo.size, VMCoreInfoState),
9bac43
+        VMSTATE_UINT64(vmcoreinfo.paddr, VMCoreInfoState),
9bac43
+        VMSTATE_END_OF_LIST()
9bac43
+    },
9bac43
+};
9bac43
+
9bac43
+static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
9bac43
+{
9bac43
+    DeviceClass *dc = DEVICE_CLASS(klass);
9bac43
+
9bac43
+    dc->vmsd = &vmstate_vmcoreinfo;
9bac43
+    dc->realize = vmcoreinfo_realize;
9bac43
+    dc->hotpluggable = false;
9bac43
+}
9bac43
+
9bac43
+static const TypeInfo vmcoreinfo_device_info = {
9bac43
+    .name          = VMCOREINFO_DEVICE,
9bac43
+    .parent        = TYPE_DEVICE,
9bac43
+    .instance_size = sizeof(VMCoreInfoState),
9bac43
+    .class_init    = vmcoreinfo_device_class_init,
9bac43
+};
9bac43
+
9bac43
+static void vmcoreinfo_register_types(void)
9bac43
+{
9bac43
+    type_register_static(&vmcoreinfo_device_info);
9bac43
+}
9bac43
+
9bac43
+type_init(vmcoreinfo_register_types)
9bac43
diff --git a/include/hw/misc/vmcoreinfo.h b/include/hw/misc/vmcoreinfo.h
9bac43
new file mode 100644
9bac43
index 0000000..c3aa856
9bac43
--- /dev/null
9bac43
+++ b/include/hw/misc/vmcoreinfo.h
9bac43
@@ -0,0 +1,46 @@
9bac43
+/*
9bac43
+ * Virtual Machine coreinfo device
9bac43
+ *
9bac43
+ * Copyright (C) 2017 Red Hat, Inc.
9bac43
+ *
9bac43
+ * Authors: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
+ *
9bac43
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
9bac43
+ * See the COPYING file in the top-level directory.
9bac43
+ *
9bac43
+ */
9bac43
+#ifndef VMCOREINFO_H
9bac43
+#define VMCOREINFO_H
9bac43
+
9bac43
+#include "hw/qdev.h"
9bac43
+
9bac43
+#define VMCOREINFO_DEVICE "vmcoreinfo"
9bac43
+#define VMCOREINFO(obj) OBJECT_CHECK(VMCoreInfoState, (obj), VMCOREINFO_DEVICE)
9bac43
+
9bac43
+#define VMCOREINFO_FORMAT_NONE 0x0
9bac43
+#define VMCOREINFO_FORMAT_ELF 0x1
9bac43
+
9bac43
+/* all fields are little-endian */
9bac43
+typedef struct FWCfgVMCoreInfo {
9bac43
+    uint16_t host_format; /* set on reset */
9bac43
+    uint16_t guest_format;
9bac43
+    uint32_t size;
9bac43
+    uint64_t paddr;
9bac43
+} QEMU_PACKED FWCfgVMCoreInfo;
9bac43
+
9bac43
+typedef struct VMCoreInfoState {
9bac43
+    DeviceClass parent_obj;
9bac43
+
9bac43
+    bool has_vmcoreinfo;
9bac43
+    FWCfgVMCoreInfo vmcoreinfo;
9bac43
+} VMCoreInfoState;
9bac43
+
9bac43
+/* returns NULL unless there is exactly one device */
9bac43
+static inline VMCoreInfoState *vmcoreinfo_find(void)
9bac43
+{
9bac43
+    Object *o = object_resolve_path_type("", VMCOREINFO_DEVICE, NULL);
9bac43
+
9bac43
+    return o ? VMCOREINFO(o) : NULL;
9bac43
+}
9bac43
+
9bac43
+#endif
9bac43
-- 
9bac43
1.8.3.1
9bac43