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