From nobody Wed May 1 03:21:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499769145023370.8524695111797; Tue, 11 Jul 2017 03:32:25 -0700 (PDT) Received: from localhost ([::1]:45386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsSs-0007vS-Gj for importer@patchew.org; Tue, 11 Jul 2017 06:32:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsR1-0006lE-62 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUsQz-0005e2-UU for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUsQz-0005dc-L9 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AD877D0E8; Tue, 11 Jul 2017 10:30:24 +0000 (UTC) Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A2F060467; Tue, 11 Jul 2017 10:30:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9AD877D0E8 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9AD877D0E8 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 12:30:05 +0200 Message-Id: <20170711103011.32631-2-marcandre.lureau@redhat.com> In-Reply-To: <20170711103011.32631-1-marcandre.lureau@redhat.com> References: <20170711103011.32631-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 11 Jul 2017 10:30:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/7] vmgenid: replace x-write-pointer-available hack X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, Ben Warren , "Michael S. Tsirkin" , anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This compat property sole function is to prevent the device from being instantiated. Instead of requiring an extra compat property, check if fw_cfg has DMA enabled. fw_cfg is a built-in device that is initialized very early by the machine init code. We have at least one other device that also assumes fw_cfg_find() can be safely used on realize: pvpanic. This has the additional benefit of handling other cases properly, like: $ qemu-system-x86_64 -device vmgenid -machine none qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support i= n fw_cfg, which this machine type does not provide $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.9 -global fw_cf= g.dma_enabled=3Doff qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support i= n fw_cfg, which this machine type does not provide $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.6 -global fw_cf= g.dma_enabled=3Don [boots normally] Suggested-by: Eduardo Habkost Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Michael S. Tsirkin Reviewed-by: Eduardo Habkost Reviewed-by: Ben Warren Reviewed-by: Laszlo Ersek --- include/hw/acpi/bios-linker-loader.h | 2 ++ include/hw/compat.h | 4 ---- hw/acpi/bios-linker-loader.c | 10 ++++++++++ hw/acpi/vmgenid.c | 9 +-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-li= nker-loader.h index efe17b0b9c..a711dbced8 100644 --- a/include/hw/acpi/bios-linker-loader.h +++ b/include/hw/acpi/bios-linker-loader.h @@ -7,6 +7,8 @@ typedef struct BIOSLinker { GArray *file_list; } BIOSLinker; =20 +bool bios_linker_loader_can_write_pointer(void); + BIOSLinker *bios_linker_loader_init(void); =20 void bios_linker_loader_alloc(BIOSLinker *linker, diff --git a/include/hw/compat.h b/include/hw/compat.h index 08f36004da..f414786604 100644 --- a/include/hw/compat.h +++ b/include/hw/compat.h @@ -150,10 +150,6 @@ .driver =3D "fw_cfg_io",\ .property =3D "dma_enabled",\ .value =3D "off",\ - },{\ - .driver =3D "vmgenid",\ - .property =3D "x-write-pointer-available",\ - .value =3D "off",\ }, =20 #define HW_COMPAT_2_3 \ diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c index 046183a0f1..d16b8bbcb1 100644 --- a/hw/acpi/bios-linker-loader.c +++ b/hw/acpi/bios-linker-loader.c @@ -168,6 +168,16 @@ bios_linker_find_file(const BIOSLinker *linker, const = char *name) return NULL; } =20 +/* + * board code must realize fw_cfg first, as a fixed device, before + * another device realize function call bios_linker_loader_can_write_point= er() + */ +bool bios_linker_loader_can_write_pointer(void) +{ + FWCfgState *fw_cfg =3D fw_cfg_find(); + return fw_cfg && fw_cfg_dma_enabled(fw_cfg); +} + /* * bios_linker_loader_alloc: ask guest to load file into guest memory. * diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c index a32b847fe0..ab5da293fd 100644 --- a/hw/acpi/vmgenid.c +++ b/hw/acpi/vmgenid.c @@ -205,17 +205,11 @@ static void vmgenid_handle_reset(void *opaque) memset(vms->vmgenid_addr_le, 0, ARRAY_SIZE(vms->vmgenid_addr_le)); } =20 -static Property vmgenid_properties[] =3D { - DEFINE_PROP_BOOL("x-write-pointer-available", VmGenIdState, - write_pointer_available, true), - DEFINE_PROP_END_OF_LIST(), -}; - static void vmgenid_realize(DeviceState *dev, Error **errp) { VmGenIdState *vms =3D VMGENID(dev); =20 - if (!vms->write_pointer_available) { + if (!bios_linker_loader_can_write_pointer()) { error_setg(errp, "%s requires DMA write support in fw_cfg, " "which this machine type does not provide", VMGENID_DEV= ICE); return; @@ -239,7 +233,6 @@ static void vmgenid_device_class_init(ObjectClass *klas= s, void *data) dc->vmsd =3D &vmstate_vmgenid; dc->realize =3D vmgenid_realize; dc->hotpluggable =3D false; - dc->props =3D vmgenid_properties; =20 object_class_property_add_str(klass, VMGENID_GUID, NULL, vmgenid_set_guid, NULL); --=20 2.13.1.395.gf7b71de06 From nobody Wed May 1 03:21:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149976915342628.381060785225714; Tue, 11 Jul 2017 03:32:33 -0700 (PDT) Received: from localhost ([::1]:45387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsT0-000834-T6 for importer@patchew.org; Tue, 11 Jul 2017 06:32:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsR5-0006o6-0D for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUsR2-0005f2-LN for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53562) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUsR2-0005eh-Bo for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 538255D699; Tue, 11 Jul 2017 10:30:27 +0000 (UTC) Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE5265C6D9; Tue, 11 Jul 2017 10:30:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 538255D699 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 538255D699 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 12:30:06 +0200 Message-Id: <20170711103011.32631-3-marcandre.lureau@redhat.com> In-Reply-To: <20170711103011.32631-1-marcandre.lureau@redhat.com> References: <20170711103011.32631-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 11 Jul 2017 10:30:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/7] acpi: add vmcoreinfo device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, "Michael S. Tsirkin" , Paolo Bonzini , anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The VM coreinfo (vmcoreinfo) device is an emulated device which exposes a 4k memory range to the guest to store various informations useful to debug the guest OS. (it is greatly inspired by the VMGENID device implementation) This is an early-boot alternative to the qemu-ga VMDUMP_INFO event proposed in "[PATCH 00/21] WIP: dump: add kaslr support". A proof-of-concept kernel module: https://github.com/elmarco/vmgenid-test/blob/master/qemuvmci-test.c Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Laszlo Ersek --- include/hw/acpi/aml-build.h | 1 + include/hw/acpi/vmcoreinfo.h | 37 +++++++ hw/acpi/aml-build.c | 2 + hw/acpi/vmcoreinfo.c | 208 +++++++++++++++++++++++++++++++++= ++++ hw/i386/acpi-build.c | 14 +++ default-configs/arm-softmmu.mak | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + docs/specs/vmcoreinfo.txt | 138 ++++++++++++++++++++++++ hw/acpi/Makefile.objs | 1 + 10 files changed, 404 insertions(+) create mode 100644 include/hw/acpi/vmcoreinfo.h create mode 100644 hw/acpi/vmcoreinfo.c create mode 100644 docs/specs/vmcoreinfo.txt diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 88d0738d76..cf781bcd34 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -211,6 +211,7 @@ struct AcpiBuildTables { GArray *rsdp; GArray *tcpalog; GArray *vmgenid; + GArray *vmcoreinfo; BIOSLinker *linker; } AcpiBuildTables; =20 diff --git a/include/hw/acpi/vmcoreinfo.h b/include/hw/acpi/vmcoreinfo.h new file mode 100644 index 0000000000..6a73bcd1b2 --- /dev/null +++ b/include/hw/acpi/vmcoreinfo.h @@ -0,0 +1,37 @@ +#ifndef ACPI_VMCOREINFO_H +#define ACPI_VMCOREINFO_H + +#include "hw/acpi/bios-linker-loader.h" +#include "hw/qdev.h" + +#define VMCOREINFO_DEVICE "vmcoreinfo" +#define VMCOREINFO_FW_CFG_FILE "etc/vmcoreinfo" +#define VMCOREINFO_ADDR_FW_CFG_FILE "etc/vmcoreinfo-addr" + +/* Occupy a page of memory */ +#define VMCOREINFO_FW_CFG_SIZE 4096 + +/* allow space for OVMF SDT Header Probe Supressor */ +#define VMCOREINFO_OFFSET sizeof(AcpiTableHeader) + +#define VMCOREINFO(obj) OBJECT_CHECK(VMCoreInfoState, (obj), VMCOREINFO_DE= VICE) + +typedef struct VMCoreInfoState { + DeviceClass parent_obj; + uint8_t vmcoreinfo_addr_le[8]; /* Address of memory region */ + bool write_pointer_available; +} VMCoreInfoState; + +/* returns NULL unless there is exactly one device */ +static inline Object *find_vmcoreinfo_dev(void) +{ + return object_resolve_path_type("", VMCOREINFO_DEVICE, NULL); +} + +void vmcoreinfo_build_acpi(VMCoreInfoState *vis, GArray *table_data, + GArray *vmci, BIOSLinker *linker); +void vmcoreinfo_add_fw_cfg(VMCoreInfoState *vis, FWCfgState *s, GArray *vm= ci); +bool vmcoreinfo_get(VMCoreInfoState *vis, uint64_t *paddr, uint32_t *size, + Error **errp); + +#endif diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 36a6cc450e..47043ade4a 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1561,6 +1561,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) tables->table_data =3D g_array_new(false, true /* clear */, 1); tables->tcpalog =3D g_array_new(false, true /* clear */, 1); tables->vmgenid =3D g_array_new(false, true /* clear */, 1); + tables->vmcoreinfo =3D g_array_new(false, true /* clear */, 1); tables->linker =3D bios_linker_loader_init(); } =20 @@ -1571,6 +1572,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *table= s, bool mfre) g_array_free(tables->table_data, true); g_array_free(tables->tcpalog, mfre); g_array_free(tables->vmgenid, mfre); + g_array_free(tables->vmcoreinfo, mfre); } =20 /* Build rsdt table */ diff --git a/hw/acpi/vmcoreinfo.c b/hw/acpi/vmcoreinfo.c new file mode 100644 index 0000000000..0ea41de8d9 --- /dev/null +++ b/hw/acpi/vmcoreinfo.c @@ -0,0 +1,208 @@ +/* + * Virtual Machine coreinfo device + * (based on Virtual Machine Generation ID Device) + * + * Copyright (C) 2017 Red Hat, Inc. + * Copyright (C) 2017 Skyport Systems. + * + * Authors: Marc-Andr=C3=A9 Lureau + * Ben Warren + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ +#include "qemu/osdep.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/vmcoreinfo.h" +#include "hw/nvram/fw_cfg.h" +#include "sysemu/sysemu.h" +#include "qapi/error.h" + +void vmcoreinfo_build_acpi(VMCoreInfoState *vis, GArray *table_data, + GArray *vmci, BIOSLinker *linker) +{ + Aml *ssdt, *dev, *scope, *method, *addr, *if_ctx; + uint32_t vcia_offset; + + g_array_set_size(vmci, VMCOREINFO_FW_CFG_SIZE); + + /* Put this in a separate SSDT table */ + ssdt =3D init_aml_allocator(); + + /* Reserve space for header */ + acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader)); + + /* Storage address */ + vcia_offset =3D table_data->len + + build_append_named_dword(ssdt->buf, "VCIA"); + scope =3D aml_scope("\\_SB"); + dev =3D aml_device("VMCI"); + aml_append(dev, aml_name_decl("_HID", aml_string("QEMUVMCI"))); + + /* Simple status method to check that address is linked and non-zero */ + method =3D aml_method("_STA", 0, AML_NOTSERIALIZED); + addr =3D aml_local(0); + aml_append(method, aml_store(aml_int(0xf), addr)); + if_ctx =3D aml_if(aml_equal(aml_name("VCIA"), aml_int(0))); + aml_append(if_ctx, aml_store(aml_int(0), addr)); + aml_append(method, if_ctx); + aml_append(method, aml_return(addr)); + aml_append(dev, method); + + /* the ADDR method returns two 32-bit words representing the lower and + * upper halves of the physical address of the vmcoreinfo area + */ + method =3D aml_method("ADDR", 0, AML_NOTSERIALIZED); + + addr =3D aml_local(0); + aml_append(method, aml_store(aml_package(2), addr)); + + aml_append(method, aml_store(aml_add(aml_name("VCIA"), + aml_int(VMCOREINFO_OFFSET), NULL), + aml_index(addr, aml_int(0)))); + aml_append(method, aml_store(aml_int(0), aml_index(addr, aml_int(1)))); + aml_append(method, aml_return(addr)); + + aml_append(dev, method); + aml_append(scope, dev); + aml_append(ssdt, scope); + + g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len); + + /* Allocate guest memory */ + bios_linker_loader_alloc(linker, VMCOREINFO_FW_CFG_FILE, vmci, 4096, + false /* page boundary, high memory */); + + /* Patch address of vmcoreinfo fw_cfg blob into the ADDR fw_cfg + * blob so QEMU can read the info from there. The address is + * expected to be < 4GB, but write 64 bits anyway. + * The address that is patched in is offset in order to implement + * the "OVMF SDT Header probe suppressor" + * see docs/specs/vmcoreinfo.txt for more details. + */ + bios_linker_loader_write_pointer(linker, + VMCOREINFO_ADDR_FW_CFG_FILE, 0, sizeof(uint64_t), + VMCOREINFO_FW_CFG_FILE, VMCOREINFO_OFFSET); + + /* Patch address of vmcoreinfo into the AML so OSPM can retrieve + * and read it. Note that while we provide storage for 64 bits, only + * the least-signficant 32 get patched into AML. + */ + bios_linker_loader_add_pointer(linker, + ACPI_BUILD_TABLE_FILE, vcia_offset, sizeof(uint32_t), + VMCOREINFO_FW_CFG_FILE, 0); + + build_header(linker, table_data, + (void *)(table_data->data + table_data->len - ssdt->buf->len), + "SSDT", ssdt->buf->len, 1, NULL, "VMCOREIN"); + free_aml_allocator(); +} + +void vmcoreinfo_add_fw_cfg(VMCoreInfoState *vis, FWCfgState *s, GArray *vm= ci) +{ + /* Create a read-only fw_cfg file for vmcoreinfo allocation */ + /* XXX: linker could learn to allocate without backing fw_cfg? */ + fw_cfg_add_file(s, VMCOREINFO_FW_CFG_FILE, vmci->data, + VMCOREINFO_FW_CFG_SIZE); + /* Create a read-write fw_cfg file for Address */ + fw_cfg_add_file_callback(s, VMCOREINFO_ADDR_FW_CFG_FILE, NULL, NULL, + vis->vmcoreinfo_addr_le, + ARRAY_SIZE(vis->vmcoreinfo_addr_le), false); +} + +bool vmcoreinfo_get(VMCoreInfoState *vis, + uint64_t *paddr, uint32_t *size, + Error **errp) +{ + uint32_t vmcoreinfo_addr; + uint32_t version; + + assert(vis); + assert(paddr); + assert(size); + + memcpy(&vmcoreinfo_addr, vis->vmcoreinfo_addr_le, sizeof(vmcoreinfo_ad= dr)); + vmcoreinfo_addr =3D le32_to_cpu(vmcoreinfo_addr); + if (!vmcoreinfo_addr) { + error_setg(errp, "BIOS has not yet written the address of %s", + VMCOREINFO_DEVICE); + return false; + } + + cpu_physical_memory_read(vmcoreinfo_addr, &version, sizeof(version)); + if (version !=3D 0) { + error_setg(errp, "Unknown %s memory version", VMCOREINFO_DEVICE); + return false; + } + + cpu_physical_memory_read(vmcoreinfo_addr + 4, paddr, sizeof(*paddr)); + *paddr =3D le64_to_cpu(*paddr); + cpu_physical_memory_read(vmcoreinfo_addr + 12, size, sizeof(*size)); + *size =3D le32_to_cpu(*size); + + return true; +} + +static const VMStateDescription vmstate_vmcoreinfo =3D { + .name =3D "vmcoreinfo", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8_ARRAY(vmcoreinfo_addr_le, VMCoreInfoState, sizeof(ui= nt64_t)), + VMSTATE_END_OF_LIST() + }, +}; + +static void vmcoreinfo_handle_reset(void *opaque) +{ + VMCoreInfoState *vis =3D VMCOREINFO(opaque); + + /* Clear the guest-allocated address when the VM resets */ + memset(vis->vmcoreinfo_addr_le, 0, ARRAY_SIZE(vis->vmcoreinfo_addr_le)= ); +} + +static void vmcoreinfo_realize(DeviceState *dev, Error **errp) +{ + if (!bios_linker_loader_can_write_pointer()) { + error_setg(errp, "%s requires DMA write support in fw_cfg, " + "which this machine type does not provide", + VMCOREINFO_DEVICE); + return; + } + + /* Given that this function is executing, there is at least one VMCORE= INFO + * device. Check if there are several. + */ + if (!find_vmcoreinfo_dev()) { + error_setg(errp, "at most one %s device is permitted", + VMCOREINFO_DEVICE); + return; + } + + qemu_register_reset(vmcoreinfo_handle_reset, dev); +} + +static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->vmsd =3D &vmstate_vmcoreinfo; + dc->realize =3D vmcoreinfo_realize; + dc->hotpluggable =3D false; +} + +static const TypeInfo vmcoreinfo_device_info =3D { + .name =3D VMCOREINFO_DEVICE, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(VMCoreInfoState), + .class_init =3D vmcoreinfo_device_class_init, +}; + +static void vmcoreinfo_register_types(void) +{ + type_register_static(&vmcoreinfo_device_info); +} + +type_init(vmcoreinfo_register_types) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 5464977424..6266b9d1bf 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -43,6 +43,7 @@ #include "sysemu/tpm.h" #include "hw/acpi/tpm.h" #include "hw/acpi/vmgenid.h" +#include "hw/acpi/vmcoreinfo.h" #include "sysemu/tpm_backend.h" #include "hw/timer/mc146818rtc_regs.h" #include "sysemu/numa.h" @@ -2631,6 +2632,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState= *machine) GArray *tables_blob =3D tables->table_data; AcpiSlicOem slic_oem =3D { .id =3D NULL, .table_id =3D NULL }; Object *vmgenid_dev; + Object *vmcoreinfo_dev; =20 acpi_get_pm_info(&pm); acpi_get_misc_info(&misc); @@ -2680,6 +2682,12 @@ void acpi_build(AcpiBuildTables *tables, MachineStat= e *machine) vmgenid_build_acpi(VMGENID(vmgenid_dev), tables_blob, tables->vmgenid, tables->linker); } + vmcoreinfo_dev =3D find_vmcoreinfo_dev(); + if (vmcoreinfo_dev) { + acpi_add_table(table_offsets, tables_blob); + vmcoreinfo_build_acpi(VMCOREINFO(vmcoreinfo_dev), tables_blob, + tables->vmcoreinfo, tables->linker); + } =20 if (misc.has_hpet) { acpi_add_table(table_offsets, tables_blob); @@ -2856,6 +2864,7 @@ void acpi_setup(void) AcpiBuildTables tables; AcpiBuildState *build_state; Object *vmgenid_dev; + Object *vmcoreinfo_dev; =20 if (!pcms->fw_cfg) { ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n"); @@ -2897,6 +2906,11 @@ void acpi_setup(void) vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg, tables.vmgenid); } + vmcoreinfo_dev =3D find_vmcoreinfo_dev(); + if (vmcoreinfo_dev) { + vmcoreinfo_add_fw_cfg(VMCOREINFO(vmcoreinfo_dev), pcms->fw_cfg, + tables.vmcoreinfo); + } =20 if (!pcmc->rsdp_in_ram) { /* diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 93e995d318..320dd3680d 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -120,6 +120,7 @@ CONFIG_XIO3130=3Dy CONFIG_IOH3420=3Dy CONFIG_I82801B11=3Dy CONFIG_ACPI=3Dy +CONFIG_ACPI_VMCOREINFO=3Dy CONFIG_SMBIOS=3Dy CONFIG_ASPEED_SOC=3Dy CONFIG_GPIO_KEY=3Dy diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmm= u.mak index d2ab2f6655..df68628895 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -59,3 +59,4 @@ CONFIG_SMBIOS=3Dy CONFIG_HYPERV_TESTDEV=3D$(CONFIG_KVM) CONFIG_PXB=3Dy CONFIG_ACPI_VMGENID=3Dy +CONFIG_ACPI_VMCOREINFO=3Dy diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-so= ftmmu.mak index 9bde2f1c4b..e39ad5a680 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -59,3 +59,4 @@ CONFIG_SMBIOS=3Dy CONFIG_HYPERV_TESTDEV=3D$(CONFIG_KVM) CONFIG_PXB=3Dy CONFIG_ACPI_VMGENID=3Dy +CONFIG_ACPI_VMCOREINFO=3Dy diff --git a/docs/specs/vmcoreinfo.txt b/docs/specs/vmcoreinfo.txt new file mode 100644 index 0000000000..36d5a39ab1 --- /dev/null +++ b/docs/specs/vmcoreinfo.txt @@ -0,0 +1,138 @@ +VIRTUAL MACHINE COREINFO DEVICE +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + +Copyright (C) 2017 Red Hat, Inc. + +This work is licensed under the terms of the GNU GPL, version 2 or later. +See the COPYING file in the top-level directory. + +=3D=3D=3D + +The VM coreinfo (vmcoreinfo) device is an emulated device which +exposes a 4k memory range to the guest to store various informations +useful to debug the guest OS. + +QEMU Implementation +------------------- + +The vmcoreinfo device is put in its own ACPI descriptor table, in a +Secondary System Description Table, or SSDT. + +The following is a dump of the contents from a running system: + +# iasl -p ./SSDT -d /sys/firmware/acpi/tables/SSDT +/* + * Intel ACPI Component Architecture + * AML/ASL+ Disassembler version 20160831-64 + * Copyright (c) 2000 - 2016 Intel Corporation + * + * Disassembling to symbolic ASL+ operators + * + * Disassembly of /sys/firmware/acpi/tables/SSDT, Mon Apr 24 15:59:53 2017 + * + * Original Table Header: + * Signature "SSDT" + * Length 0x00000086 (134) + * Revision 0x01 + * Checksum 0x5C + * OEM ID "BOCHS " + * OEM Table ID "VMCOREIN" + * OEM Revision 0x00000001 (1) + * Compiler ID "BXPC" + * Compiler Version 0x00000001 (1) + */ +DefinitionBlock ("", "SSDT", 1, "BOCHS ", "VMCOREIN", 0x00000001) +{ + Name (VCIA, 0x3FFFF000) + Scope (\_SB) + { + Device (VMCI) + { + Name (_HID, "QEMUVMCI") // _HID: Hardware ID + Method (_STA, 0, NotSerialized) // _STA: Status + { + Local0 =3D 0x0F + If (VCIA =3D=3D Zero) + { + Local0 =3D Zero + } + + Return (Local0) + } + + Method (ADDR, 0, NotSerialized) + { + Local0 =3D Package (0x02) {} + Local0 [Zero] =3D (VCIA + 0x24) + Local0 [One] =3D Zero + Return (Local0) + } + } + } +} + + +Design Details: +--------------- + +QEMU must be able to read the contents of the device memory, +specifically when starting a memory dump. In order to do this, QEMU +must know the address that has been allocated. + +The mechanism chosen for this memory sharing is writeable fw_cfg blobs. +These are data object that are visible to both QEMU and guests, and are +addressable as sequential files. + +More information about fw_cfg can be found in "docs/specs/fw_cfg.txt" + +Two fw_cfg blobs are used in this case: + +/etc/vmcoreinfo - used to allocate memory range, read-only to the gue= st +/etc/vmcoreinfo-addr - contains the address of the allocated range + - writeable by the guest + + +QEMU sends the following commands to the guest at startup: + +1. Allocate memory for vmcoreinfo fw_cfg blob. +2. Write the address of vmcoreinfo into the SSDT (VCIA ACPI variable as + shown above in the iasl dump). Note that this change is not propagated + back to QEMU. +3. Write the address of vmcoreinfo back to QEMU's copy of vmcoreinfo-addr + via the fw_cfg DMA interface. + +After step 3, QEMU is able to read the contents of vmcoreinfo. + +The value of VCIA is persisted via the VMState mechanism. + + +Storage Format: +--------------- + +The content is expected to use little-endian format. + +In order to implement an OVMF "SDT Header Probe Suppressor", the contents = of +the vmcoreinfo blob has 36 bytes of padding: + ++-----------------------------------+ +| SSDT with OEM Table ID =3D VMCOREIN | ++-----------------------------------+ +| ... | TOP OF PAGE +| VCIA dword object ----------------|-----> +---------------------------+ +| ... | | fw-allocated array for | +| _STA method referring to VCIA | | "etc/vmcoreinfo" | +| ... | +---------------------------+ +| ADDR method referring to VCIA | | 0: OVMF SDT Header probe | +| ... | | suppressor | ++-----------------------------------+ | 36: uint32 version field | + | 40: info contents | + | .... | + +---------------------------+ + END OF PAGE + +Version 0 content: + + uint64 paddr: + Physical address of the Linux vmcoreinfo ELF note. + uint32 size: + Size of the vmcoreinfo ELF note. diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 11c35bcb44..9623078f95 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) +=3D memory_hotplu= g.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) +=3D cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) +=3D nvdimm.o common-obj-$(CONFIG_ACPI_VMGENID) +=3D vmgenid.o +common-obj-$(CONFIG_ACPI_VMCOREINFO) +=3D vmcoreinfo.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) +=3D acpi-stub.o =20 common-obj-y +=3D acpi_interface.o --=20 2.13.1.395.gf7b71de06 From nobody Wed May 1 03:21:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149976920929863.00049971935857; Tue, 11 Jul 2017 03:33:29 -0700 (PDT) Received: from localhost ([::1]:45388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsTt-0000JU-Pc for importer@patchew.org; Tue, 11 Jul 2017 06:33:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsR8-0006qp-BL for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUsR6-0005gS-2s for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36206) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUsR5-0005gC-Ph for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF5E580476 for ; Tue, 11 Jul 2017 10:30:30 +0000 (UTC) Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BF805C8BB; Tue, 11 Jul 2017 10:30:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BF5E580476 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BF5E580476 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 12:30:07 +0200 Message-Id: <20170711103011.32631-4-marcandre.lureau@redhat.com> In-Reply-To: <20170711103011.32631-1-marcandre.lureau@redhat.com> References: <20170711103011.32631-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 11 Jul 2017 10:30:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 3/7] tests: add simple vmcoreinfo test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This test is based off vmgenid test from Ben Warren . It simply checks the vmcoreinfo ACPI device is present and that the memory region associated can be read. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Laszlo Ersek --- tests/vmcoreinfo-test.c | 127 ++++++++++++++++++++++++++++++++++++++++++++= ++++ tests/Makefile.include | 2 + 2 files changed, 129 insertions(+) create mode 100644 tests/vmcoreinfo-test.c diff --git a/tests/vmcoreinfo-test.c b/tests/vmcoreinfo-test.c new file mode 100644 index 0000000000..1378b4c1fc --- /dev/null +++ b/tests/vmcoreinfo-test.c @@ -0,0 +1,127 @@ +/* + * QTest testcase for VM coreinfo device + * + * Copyright (c) 2017 Red Hat, Inc. + * Copyright (c) 2017 Skyport Systems + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include +#include "qemu/osdep.h" +#include "qemu/bitmap.h" +#include "qemu/uuid.h" +#include "hw/acpi/acpi-defs.h" +#include "acpi-utils.h" +#include "libqtest.h" + +#define RSDP_ADDR_INVALID 0x100000 /* RSDP must be below this address */ +#define RSDP_SLEEP_US 100000 /* Sleep for 100ms between tries */ +#define RSDP_TRIES_MAX 100 /* Max total time is 10 seconds */ + +typedef struct { + AcpiTableHeader header; + gchar name_op; + gchar vcia[4]; + gchar val_op; + uint32_t vcia_val; +} QEMU_PACKED VmciTable; + +static uint32_t acpi_find_vcia(void) +{ + uint32_t off; + AcpiRsdpDescriptor rsdp_table; + uint32_t rsdt; + AcpiRsdtDescriptorRev1 rsdt_table; + int tables_nr; + uint32_t *tables; + AcpiTableHeader ssdt_table; + VmciTable vmci_table; + int i; + + /* Tables may take a short time to be set up by the guest */ + for (i =3D 0; i < RSDP_TRIES_MAX; i++) { + off =3D acpi_find_rsdp_address(); + if (off < RSDP_ADDR_INVALID) { + break; + } + g_usleep(RSDP_SLEEP_US); + } + g_assert_cmphex(off, <, RSDP_ADDR_INVALID); + + acpi_parse_rsdp_table(off, &rsdp_table); + + rsdt =3D rsdp_table.rsdt_physical_address; + /* read the header */ + ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt); + ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT"); + + /* compute the table entries in rsdt */ + tables_nr =3D (rsdt_table.length - sizeof(AcpiRsdtDescriptorRev1)) / + sizeof(uint32_t); + g_assert_cmpint(tables_nr, >, 0); + + /* get the addresses of the tables pointed by rsdt */ + tables =3D g_new0(uint32_t, tables_nr); + ACPI_READ_ARRAY_PTR(tables, tables_nr, rsdt); + + for (i =3D 0; i < tables_nr; i++) { + ACPI_READ_TABLE_HEADER(&ssdt_table, tables[i]); + if (!strncmp((char *)ssdt_table.oem_table_id, "VMCOREIN", 8)) { + /* the first entry in the table should be VCIA + * That's all we need + */ + ACPI_READ_FIELD(vmci_table.name_op, tables[i]); + g_assert(vmci_table.name_op =3D=3D 0x08); /* name */ + ACPI_READ_ARRAY(vmci_table.vcia, tables[i]); + g_assert(memcmp(vmci_table.vcia, "VCIA", 4) =3D=3D 0); + ACPI_READ_FIELD(vmci_table.val_op, tables[i]); + g_assert(vmci_table.val_op =3D=3D 0x0C); /* dword */ + ACPI_READ_FIELD(vmci_table.vcia_val, tables[i]); + /* The GUID is written at a fixed offset into the fw_cfg file + * in order to implement the "OVMF SDT Header probe suppressor" + * see docs/specs/vmgenid.txt for more details + */ + g_free(tables); + return vmci_table.vcia_val; + } + } + g_free(tables); + return 0; +} + +static void vmcoreinfo_test(void) +{ + gchar *cmd; + uint32_t vmci_addr; + int i; + + cmd =3D g_strdup_printf("-machine accel=3Dtcg -device vmcoreinfo,id=3D= vmci"); + qtest_start(cmd); + + vmci_addr =3D acpi_find_vcia(); + g_assert(vmci_addr); + + for (i =3D 0; i < 4096; i++) { + /* check the memory region can be read */ + readb(vmci_addr + i); + } + + qtest_quit(global_qtest); + g_free(cmd); +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/vmcoreinfo/test", vmcoreinfo_test); + ret =3D g_test_run(); + + return ret; +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 18cd06a6b3..f573c1d3c8 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -251,6 +251,7 @@ gcov-files-i386-y +=3D hw/usb/hcd-xhci.c check-qtest-i386-y +=3D tests/pc-cpu-test$(EXESUF) check-qtest-i386-y +=3D tests/q35-test$(EXESUF) check-qtest-i386-y +=3D tests/vmgenid-test$(EXESUF) +check-qtest-i386-y +=3D tests/vmcoreinfo-test$(EXESUF) gcov-files-i386-y +=3D hw/pci-host/q35.c check-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) +=3D tests/vhost-user-test$= (EXESUF) ifeq ($(CONFIG_VHOST_NET_TEST_i386),) @@ -762,6 +763,7 @@ tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer= .o tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) tests/numa-test$(EXESUF): tests/numa-test.o tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/acpi-utils.o +tests/vmcoreinfo-test$(EXESUF): tests/vmcoreinfo-test.o tests/acpi-utils.o =20 tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"L= INK","$(TARGET_DIR)$@") --=20 2.13.1.395.gf7b71de06 From nobody Wed May 1 03:21:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499769317779180.60887511937062; Tue, 11 Jul 2017 03:35:17 -0700 (PDT) Received: from localhost ([::1]:45396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsVg-00028i-7T for importer@patchew.org; Tue, 11 Jul 2017 06:35:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsRB-0006tM-5I for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUsR9-0005kt-Ob for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUsR9-0005jW-Eq for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67487285B5 for ; Tue, 11 Jul 2017 10:30:34 +0000 (UTC) Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10BD67D478; Tue, 11 Jul 2017 10:30:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 67487285B5 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 67487285B5 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 12:30:08 +0200 Message-Id: <20170711103011.32631-5-marcandre.lureau@redhat.com> In-Reply-To: <20170711103011.32631-1-marcandre.lureau@redhat.com> References: <20170711103011.32631-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 11 Jul 2017 10:30:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 4/7] dump: add vmcoreinfo ELF note X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Read the vmcoreinfo ELF PT_NOTE from guest memory when vmcoreinfo device provides the location, and write it as an ELF note in the dump. There are now 2 possible sources of phys_base information. (1) arch guessed value from cpu_get_dump_info() (2) vmcoreinfo ELF note NUMBER(phys_base)=3D field NUMBER(phys_base) in vmcoreinfo has only been recently introduced in Linux 4.10 (401721ecd1dc "kexec: export the value of phys_base instead of symbol address"). Since (2) has better chances to be accurate, the guessed value is replaced by the value from the vmcoreinfo ELF note. The phys_base value is stored in the same dump field locations as before, and may duplicate the information available in the vmcoreinfo ELF PT_NOTE. Crash tools should be prepared to handle this case. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Laszlo Ersek --- include/sysemu/dump.h | 2 + dump.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 136 insertions(+) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 2672a15f8b..111a7dcaa4 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -192,6 +192,8 @@ typedef struct DumpState { * this could be used to calculate * how much work we have * finished. */ + uint8_t *vmcoreinfo; /* ELF note content */ + size_t vmcoreinfo_size; } DumpState; =20 uint16_t cpu_to_dump16(DumpState *s, uint16_t val); diff --git a/dump.c b/dump.c index d9090a24cc..2928757584 100644 --- a/dump.c +++ b/dump.c @@ -26,6 +26,8 @@ #include "qapi/qmp/qerror.h" #include "qmp-commands.h" #include "qapi-event.h" +#include "qemu/error-report.h" +#include "hw/acpi/vmcoreinfo.h" =20 #include #ifdef CONFIG_LZO @@ -38,6 +40,13 @@ #define ELF_MACHINE_UNAME "Unknown" #endif =20 +#define MAX_VMCOREINFO_SIZE (1 << 20) /* 1MB should be enough */ + +#define ELF_NOTE_SIZE(hdr_size, name_size, desc_size) \ + ((DIV_ROUND_UP((hdr_size), 4) + \ + DIV_ROUND_UP((name_size), 4) + \ + DIV_ROUND_UP((desc_size), 4)) * 4) + uint16_t cpu_to_dump16(DumpState *s, uint16_t val) { if (s->dump_info.d_endian =3D=3D ELFDATA2LSB) { @@ -76,6 +85,8 @@ static int dump_cleanup(DumpState *s) guest_phys_blocks_free(&s->guest_phys_blocks); memory_mapping_list_free(&s->list); close(s->fd); + g_free(s->vmcoreinfo); + s->vmcoreinfo =3D NULL; if (s->resume) { if (s->detached) { qemu_mutex_lock_iothread(); @@ -235,6 +246,19 @@ static inline int cpu_index(CPUState *cpu) return cpu->cpu_index + 1; } =20 +static void write_vmcoreinfo_note(WriteCoreDumpFunction f, DumpState *s, + Error **errp) +{ + int ret; + + if (s->vmcoreinfo) { + ret =3D f(s->vmcoreinfo, s->vmcoreinfo_size, s); + if (ret < 0) { + error_setg(errp, "dump: failed to write vmcoreinfo"); + } + } +} + static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s, Error **errp) { @@ -258,6 +282,8 @@ static void write_elf64_notes(WriteCoreDumpFunction f, = DumpState *s, return; } } + + write_vmcoreinfo_note(f, s, errp); } =20 static void write_elf32_note(DumpState *s, Error **errp) @@ -303,6 +329,8 @@ static void write_elf32_notes(WriteCoreDumpFunction f, = DumpState *s, return; } } + + write_vmcoreinfo_note(f, s, errp); } =20 static void write_elf_section(DumpState *s, int type, Error **errp) @@ -714,6 +742,44 @@ static int buf_write_note(const void *buf, size_t size= , void *opaque) return 0; } =20 +/* + * This function retrieves various sizes from an elf header. + * + * @note has to be a valid ELF note. The return sizes are unmodified + * (not padded or rounded up to be multiple of 4). + */ +static void get_note_sizes(DumpState *s, const void *note, + uint64_t *note_head_size, + uint64_t *name_size, + uint64_t *desc_size) +{ + uint64_t note_head_sz; + uint64_t name_sz; + uint64_t desc_sz; + + if (s->dump_info.d_class =3D=3D ELFCLASS64) { + const Elf64_Nhdr *hdr =3D note; + note_head_sz =3D sizeof(Elf64_Nhdr); + name_sz =3D tswap64(hdr->n_namesz); + desc_sz =3D tswap64(hdr->n_descsz); + } else { + const Elf32_Nhdr *hdr =3D note; + note_head_sz =3D sizeof(Elf32_Nhdr); + name_sz =3D tswap32(hdr->n_namesz); + desc_sz =3D tswap32(hdr->n_descsz); + } + + if (note_head_size) { + *note_head_size =3D note_head_sz; + } + if (name_size) { + *name_size =3D name_sz; + } + if (desc_size) { + *desc_size =3D desc_sz; + } +} + /* write common header, sub header and elf note to vmcore */ static void create_header32(DumpState *s, Error **errp) { @@ -1488,10 +1554,40 @@ static int64_t dump_calculate_size(DumpState *s) return total; } =20 +static void vmcoreinfo_update_phys_base(DumpState *s) +{ + uint64_t size, note_head_size, name_size, phys_base; + char **lines; + uint8_t *vmci; + size_t i; + + get_note_sizes(s, s->vmcoreinfo, ¬e_head_size, &name_size, &size); + note_head_size =3D ROUND_UP(note_head_size, 4); + name_size =3D ROUND_UP(name_size, 4); + vmci =3D s->vmcoreinfo + note_head_size + name_size; + *(vmci + size) =3D '\0'; + + lines =3D g_strsplit((char *)vmci, "\n", -1); + for (i =3D 0; lines[i]; i++) { + if (g_str_has_prefix(lines[i], "NUMBER(phys_base)=3D")) { + if (qemu_strtou64(lines[i] + 18, NULL, 16, + &phys_base) < 0) { + error_report("warning: Failed to read NUMBER(phys_base)=3D= "); + } else { + s->dump_info.phys_base =3D phys_base; + } + break; + } + } + + g_strfreev(lines); +} + static void dump_init(DumpState *s, int fd, bool has_format, DumpGuestMemoryFormat format, bool paging, bool has_= filter, int64_t begin, int64_t length, Error **errp) { + Object *vmcoreinfo_dev =3D find_vmcoreinfo_dev(); CPUState *cpu; int nr_cpus; Error *err =3D NULL; @@ -1563,6 +1659,44 @@ static void dump_init(DumpState *s, int fd, bool has= _format, goto cleanup; } =20 + /* + * the goal of this block is to (a) update the previously guessed + * phys_base, (b) copy the vmcoreinfo note out of the guest. And + * that failure to do so is not fatal for dumping. + */ + if (vmcoreinfo_dev) { + uint64_t addr, note_head_size, name_size, desc_size; + uint32_t size; + + note_head_size =3D s->dump_info.d_class =3D=3D ELFCLASS32 ? + sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr); + + if (!vmcoreinfo_get(VMCOREINFO(vmcoreinfo_dev), + &addr, &size, &err)) { + error_report_err(err); + err =3D NULL; + } else if (size < note_head_size || size > MAX_VMCOREINFO_SIZE) { + error_report("warning: vmcoreinfo size is invalid: %" PRIu32, = size); + } else { + s->vmcoreinfo =3D g_malloc(size + 1); /* +1 for adding \0 */ + cpu_physical_memory_read(addr, s->vmcoreinfo, size); + + get_note_sizes(s, s->vmcoreinfo, NULL, &name_size, &desc_size); + s->vmcoreinfo_size =3D ELF_NOTE_SIZE(note_head_size, name_size, + desc_size); + if (name_size > MAX_VMCOREINFO_SIZE || + desc_size > MAX_VMCOREINFO_SIZE || + s->vmcoreinfo_size > size) { + error_report("warning: Invalid vmcoreinfo header"); + g_free(s->vmcoreinfo); + s->vmcoreinfo =3D NULL; + } else { + vmcoreinfo_update_phys_base(s); + s->note_size +=3D s->vmcoreinfo_size; + } + } + } + /* get memory mapping */ if (paging) { qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &er= r); --=20 2.13.1.395.gf7b71de06 From nobody Wed May 1 03:21:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499769308754440.7370474511208; Tue, 11 Jul 2017 03:35:08 -0700 (PDT) Received: from localhost ([::1]:45395 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsVV-000214-9u for importer@patchew.org; Tue, 11 Jul 2017 06:35:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsRC-0006uE-6I for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUsRB-0005lZ-6e for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUsRA-0005lC-W3 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 035E73B70F for ; Tue, 11 Jul 2017 10:30:36 +0000 (UTC) Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D4995C549; Tue, 11 Jul 2017 10:30:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 035E73B70F Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 035E73B70F From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 12:30:09 +0200 Message-Id: <20170711103011.32631-6-marcandre.lureau@redhat.com> In-Reply-To: <20170711103011.32631-1-marcandre.lureau@redhat.com> References: <20170711103011.32631-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 11 Jul 2017 10:30:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 5/7] kdump: add vmcoreinfo ELF note X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" kdump header provides offset and size of the vmcoreinfo ELF note, append it if available. crash-7.1.9 was the first version that started looking in the vmcoreinfo data for phys_base instead of in the kdump_sub_header. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Laszlo Ersek --- dump.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/dump.c b/dump.c index 2928757584..7c2b7dd0d3 100644 --- a/dump.c +++ b/dump.c @@ -841,6 +841,16 @@ static void create_header32(DumpState *s, Error **errp) kh->dump_level =3D cpu_to_dump32(s, DUMP_LEVEL); =20 offset_note =3D DISKDUMP_HEADER_BLOCKS * block_size + size; + if (s->vmcoreinfo) { + uint64_t hsize, name_size, size_vmcoreinfo_desc, offset_vmcoreinfo; + + get_note_sizes(s, s->vmcoreinfo, &hsize, &name_size, &size_vmcorei= nfo_desc); + offset_vmcoreinfo =3D offset_note + s->note_size - s->vmcoreinfo_s= ize + + (DIV_ROUND_UP(hsize, 4) + DIV_ROUND_UP(name_size, 4)) * 4; + kh->offset_vmcoreinfo =3D cpu_to_dump64(s, offset_vmcoreinfo); + kh->size_vmcoreinfo =3D cpu_to_dump32(s, size_vmcoreinfo_desc); + } + kh->offset_note =3D cpu_to_dump64(s, offset_note); kh->note_size =3D cpu_to_dump32(s, s->note_size); =20 @@ -941,6 +951,16 @@ static void create_header64(DumpState *s, Error **errp) kh->dump_level =3D cpu_to_dump32(s, DUMP_LEVEL); =20 offset_note =3D DISKDUMP_HEADER_BLOCKS * block_size + size; + if (s->vmcoreinfo) { + uint64_t hsize, name_size, size_vmcoreinfo_desc, offset_vmcoreinfo; + + get_note_sizes(s, s->vmcoreinfo, &hsize, &name_size, &size_vmcorei= nfo_desc); + offset_vmcoreinfo =3D offset_note + s->note_size - s->vmcoreinfo_s= ize + + (DIV_ROUND_UP(hsize, 4) + DIV_ROUND_UP(name_size, 4)) * 4; + kh->offset_vmcoreinfo =3D cpu_to_dump64(s, offset_vmcoreinfo); + kh->size_vmcoreinfo =3D cpu_to_dump64(s, size_vmcoreinfo_desc); + } + kh->offset_note =3D cpu_to_dump64(s, offset_note); kh->note_size =3D cpu_to_dump64(s, s->note_size); =20 --=20 2.13.1.395.gf7b71de06 From nobody Wed May 1 03:21:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499769442049319.2785246770188; Tue, 11 Jul 2017 03:37:22 -0700 (PDT) Received: from localhost ([::1]:45408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsXe-0003yT-MX for importer@patchew.org; Tue, 11 Jul 2017 06:37:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsRE-0006wj-MA for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUsRD-0005ml-DM for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48048) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUsRC-0005m1-Qd for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C599080F6D for ; Tue, 11 Jul 2017 10:30:37 +0000 (UTC) Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C55160467; Tue, 11 Jul 2017 10:30:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C599080F6D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C599080F6D From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 12:30:10 +0200 Message-Id: <20170711103011.32631-7-marcandre.lureau@redhat.com> In-Reply-To: <20170711103011.32631-1-marcandre.lureau@redhat.com> References: <20170711103011.32631-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 11 Jul 2017 10:30:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 6/7] scripts/dump-guest-memory.py: add vmcoreinfo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, "Michael S. Tsirkin" , anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add vmcoreinfo ELF note if vmcoreinfo device is ready. To help the python script, add a little global vmcoreinfo_gdb structure, that is populated with vmcoreinfo_gdb_update(). Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Laszlo Ersek --- scripts/dump-guest-memory.py | 46 ++++++++++++++++++++++++++++++++++++++++= ++++ hw/acpi/vmcoreinfo.c | 3 +++ 2 files changed, 49 insertions(+) diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index f7c6635f15..80730658ae 100644 --- a/scripts/dump-guest-memory.py +++ b/scripts/dump-guest-memory.py @@ -14,6 +14,7 @@ the COPYING file in the top-level directory. """ =20 import ctypes +import struct =20 UINTPTR_T =3D gdb.lookup_type("uintptr_t") =20 @@ -120,6 +121,22 @@ class ELF(object): self.segments[0].p_filesz +=3D ctypes.sizeof(note) self.segments[0].p_memsz +=3D ctypes.sizeof(note) =20 + + def add_vmcoreinfo_note(self, vmcoreinfo): + """Adds a vmcoreinfo note to the ELF dump.""" + # compute the header size, and copy that many bytes from the note + header =3D get_arch_note(self.endianness, 0, 0) + ctypes.memmove(ctypes.pointer(header), + vmcoreinfo, ctypes.sizeof(header)) + # now get the full note + note =3D get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(not= e)) + + self.notes.append(note) + self.segments[0].p_filesz +=3D ctypes.sizeof(note) + self.segments[0].p_memsz +=3D ctypes.sizeof(note) + def add_segment(self, p_type, p_paddr, p_size): """Adds a segment to the elf.""" =20 @@ -505,6 +522,34 @@ shape and this command should mostly work.""" cur +=3D chunk_size left -=3D chunk_size =20 + def phys_memory_read(self, addr, size): + qemu_core =3D gdb.inferiors()[0] + for block in self.guest_phys_blocks: + if block["target_start"] <=3D addr < block["target_end"] \ + and addr + size < block["target_end"]: + haddr =3D block["host_addr"] + (addr - block["target_start= "]) + return qemu_core.read_memory(haddr, size) + return None + + def add_vmcoreinfo(self): + if not gdb.parse_and_eval("vmcoreinfo_gdb_helper"): + return + + addr =3D gdb.parse_and_eval("vmcoreinfo_gdb_helper.vmcoreinfo_addr= _le") + addr =3D bytes([addr[i] for i in range(4)]) + addr =3D struct.unpack(" Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499769536164577.674314655053; Tue, 11 Jul 2017 03:38:56 -0700 (PDT) Received: from localhost ([::1]:45412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsZC-0005AD-SC for importer@patchew.org; Tue, 11 Jul 2017 06:38:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUsRI-0006zT-0N for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUsRG-0005oT-Nr for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55994) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUsRG-0005o3-HG for qemu-devel@nongnu.org; Tue, 11 Jul 2017 06:30:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72D8180C1D for ; Tue, 11 Jul 2017 10:30:41 +0000 (UTC) Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id E56065D6A6; Tue, 11 Jul 2017 10:30:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 72D8180C1D Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 72D8180C1D From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 12:30:11 +0200 Message-Id: <20170711103011.32631-8-marcandre.lureau@redhat.com> In-Reply-To: <20170711103011.32631-1-marcandre.lureau@redhat.com> References: <20170711103011.32631-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 11 Jul 2017 10:30:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 7/7] MAINTAINERS: add Dump maintainers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Proposing myself, since I have some familiarity with the code now. Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Laszlo Ersek --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9529c9484c..9cff1bee46 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1272,6 +1272,15 @@ S: Maintained F: device_tree.c F: include/sysemu/device_tree.h =20 +Dump +S: Supported +M: Marc-Andr=C3=A9 Lureau +F: dump.c +F: stubs/dump.c +F: include/sysemu/dump.h +F: include/sysemu/dump-arch.h +F: scripts/dump-guest-memory.py + Error reporting M: Markus Armbruster S: Supported --=20 2.13.1.395.gf7b71de06