From nobody Fri May 3 22:20:30 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 1500056684510954.9344108469314; Fri, 14 Jul 2017 11:24:44 -0700 (PDT) Received: from localhost ([::1]:39372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Gd-0007SX-7Y for importer@patchew.org; Fri, 14 Jul 2017 14:24:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5CT-0003xr-5z for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5CS-0005wf-24 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5CR-0005wA-PK for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C75313E70BA; Fri, 14 Jul 2017 18:20:22 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CB085D966; Fri, 14 Jul 2017 18:20:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C75313E70BA Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C75313E70BA From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:04 +0200 Message-Id: <20170714182012.4595-2-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 14 Jul 2017 18:20:22 +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 v4 1/8] 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 Fri May 3 22:20:30 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 1500056940742719.8425252036579; Fri, 14 Jul 2017 11:29:00 -0700 (PDT) Received: from localhost ([::1]:39395 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Kk-0003Ag-B4 for importer@patchew.org; Fri, 14 Jul 2017 14:28:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Cc-000442-Ju for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5CY-0005zr-88 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5CX-0005zD-Tx for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E754919D605; Fri, 14 Jul 2017 18:20:28 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3BE060604; Fri, 14 Jul 2017 18:20:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E754919D605 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E754919D605 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:05 +0200 Message-Id: <20170714182012.4595-3-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Jul 2017 18:20:29 +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 v4 2/8] 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 6b7bade183..7ac529680e 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 Fri May 3 22:20:30 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 1500056812870187.50227126800985; Fri, 14 Jul 2017 11:26:52 -0700 (PDT) Received: from localhost ([::1]:39384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5If-0001BA-MQ for importer@patchew.org; Fri, 14 Jul 2017 14:26:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Cd-00044Z-BP for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5Ca-00060p-6F for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5Ca-00060U-0P for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 085DBC0C4282 for ; Fri, 14 Jul 2017 18:20:31 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19BE560A9F; Fri, 14 Jul 2017 18:20:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 085DBC0C4282 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 085DBC0C4282 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:06 +0200 Message-Id: <20170714182012.4595-4-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 14 Jul 2017 18:20:31 +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 v4 3/8] stubs: add vmcoreinfo_get() stub 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, Paolo Bonzini , 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" Common dump code may call vmcoreinfo_get() which is not available on all targets. Signed-off-by: Marc-Andr=C3=A9 Lureau --- stubs/vmcoreinfo.c | 9 +++++++++ stubs/Makefile.objs | 1 + 2 files changed, 10 insertions(+) create mode 100644 stubs/vmcoreinfo.c diff --git a/stubs/vmcoreinfo.c b/stubs/vmcoreinfo.c new file mode 100644 index 0000000000..a994153832 --- /dev/null +++ b/stubs/vmcoreinfo.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" + +#include "hw/acpi/vmcoreinfo.h" + +bool vmcoreinfo_get(VMCoreInfoState *vis, uint64_t *paddr, uint32_t *size, + Error **errp) +{ + return false; +} diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index f5b47bfd74..3bedc73252 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -36,6 +36,7 @@ stub-obj-y +=3D qmp_pc_dimm_device_list.o stub-obj-y +=3D target-monitor-defs.o stub-obj-y +=3D target-get-monitor-def.o stub-obj-y +=3D pc_madt_cpu_entry.o +stub-obj-y +=3D vmcoreinfo.o stub-obj-y +=3D vmgenid.o stub-obj-y +=3D xen-common.o stub-obj-y +=3D xen-hvm.o --=20 2.13.1.395.gf7b71de06 From nobody Fri May 3 22:20:30 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 1500056525475841.3694003767578; Fri, 14 Jul 2017 11:22:05 -0700 (PDT) Received: from localhost ([::1]:39360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5E4-0004zV-5A for importer@patchew.org; Fri, 14 Jul 2017 14:22:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Cd-00044n-Jb for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5Cc-000623-FB for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52839) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5Cc-00061N-6a for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B20D344DF2 for ; Fri, 14 Jul 2017 18:20:33 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91BF05D965; Fri, 14 Jul 2017 18:20:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3B20D344DF2 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 3B20D344DF2 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:07 +0200 Message-Id: <20170714182012.4595-5-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 14 Jul 2017 18:20:33 +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 v4 4/8] 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 --- tests/vmcoreinfo-test.c | 141 ++++++++++++++++++++++++++++++++++++++++++++= ++++ tests/Makefile.include | 2 + 2 files changed, 143 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..a54f3b5c6a --- /dev/null +++ b/tests/vmcoreinfo-test.c @@ -0,0 +1,141 @@ +/* + * 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 "boot-sector.h" +#include "acpi-utils.h" +#include "libqtest.h" + +#define RSDP_ADDR_INVALID 0x100000 /* RSDP must be below this address */ + +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 rsdp_offset; + AcpiRsdpDescriptor rsdp_table; + uint32_t rsdt; + AcpiRsdtDescriptorRev1 rsdt_table; + int tables_nr; + uint32_t *tables; + AcpiTableHeader ssdt_table; + VmciTable vmci_table; + int i; + + /* Wait for guest firmware to finish and start the payload. */ + boot_sector_test(); + + /* Tables should be initialized now. */ + rsdp_offset =3D acpi_find_rsdp_address(); + + g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID); + + acpi_parse_rsdp_table(rsdp_offset, &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 char disk[] =3D "tests/vmci-test-disk-XXXXXX"; + +static char *cmd_strdup(void) +{ + return g_strdup_printf("-machine accel=3Dtcg " + "-device vmcoreinfo,id=3Dtestvmvci " + "-drive id=3Dhd0,if=3Dnone,file=3D%s,format=3Dr= aw " + "-device ide-hd,drive=3Dhd0 ", + disk); +} + +static void vmcoreinfo_test(void) +{ + gchar *cmd; + uint32_t vmci_addr; + int i; + + cmd =3D cmd_strdup(); + 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; + + ret =3D boot_sector_init(disk); + if (ret) { + return ret; + } + + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/vmcoreinfo/test", vmcoreinfo_test); + ret =3D g_test_run(); + boot_sector_cleanup(disk); + + return ret; +} diff --git a/tests/Makefile.include b/tests/Makefile.include index cfbb689e0e..dd515f2159 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/boot-sector.o test= s/acpi-utils.o +tests/vmcoreinfo-test$(EXESUF): tests/vmcoreinfo-test.o tests/boot-sector.= 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 Fri May 3 22:20:30 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 1500056659923700.586942367024; Fri, 14 Jul 2017 11:24:19 -0700 (PDT) Received: from localhost ([::1]:39371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5GE-00073p-7r for importer@patchew.org; Fri, 14 Jul 2017 14:24:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Ci-00049r-4W for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5Cg-00066g-M6 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57350) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5Cg-00065P-6R for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:38 -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 3B95D3AD570 for ; Fri, 14 Jul 2017 18:20:37 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92F966031D; Fri, 14 Jul 2017 18:20:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3B95D3AD570 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 3B95D3AD570 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:08 +0200 Message-Id: <20170714182012.4595-6-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-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]); Fri, 14 Jul 2017 18:20: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 v4 5/8] 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..d86b601248 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) { + warn_report("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. + * 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)) { + warn_report_err(err); + err =3D NULL; + } else if (size < note_head_size || size > MAX_VMCOREINFO_SIZE) { + warn_report("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) { + warn_report("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 Fri May 3 22:20:30 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 1500056782850696.6627323833366; Fri, 14 Jul 2017 11:26:22 -0700 (PDT) Received: from localhost ([::1]:39383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5ID-0000dB-IX for importer@patchew.org; Fri, 14 Jul 2017 14:26:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Cq-0004HI-KN for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5Cl-0006HB-7W for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5Ck-0006FN-Na for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20: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 BE1F4104D40 for ; Fri, 14 Jul 2017 18:20:41 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1574B52FC3; Fri, 14 Jul 2017 18:20:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BE1F4104D40 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BE1F4104D40 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:09 +0200 Message-Id: <20170714182012.4595-7-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-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.38]); Fri, 14 Jul 2017 18:20: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 v4 6/8] 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 d86b601248..b78d58ab0a 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 Fri May 3 22:20:30 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 1500056647167387.4298186617875; Fri, 14 Jul 2017 11:24:07 -0700 (PDT) Received: from localhost ([::1]:39370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Fz-0006jd-S3 for importer@patchew.org; Fri, 14 Jul 2017 14:24:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Ct-0004JO-DF for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5Cs-0006OU-9P for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5Cs-0006N7-0H for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1974A10AEEB for ; Fri, 14 Jul 2017 18:20:48 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34C246060A; Fri, 14 Jul 2017 18:20:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1974A10AEEB 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 1974A10AEEB From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:10 +0200 Message-Id: <20170714182012.4595-8-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 14 Jul 2017 18:20:48 +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 v4 7/8] 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 static vmcoreinfo_gdb_helper value to be looked up to get vmcoreinfo device singleton. Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Laszlo Ersek --- scripts/dump-guest-memory.py | 47 ++++++++++++++++++++++++++++++++++++++++= ++++ hw/acpi/vmcoreinfo.c | 3 +++ 2 files changed, 50 insertions(+) diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index f7c6635f15..e0589e5b7c 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,35 @@ 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 \ + and addr + size <=3D 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_realize::vmcoreinfo_gdb_help= er"): + return + + addr =3D gdb.parse_and_eval("vmcoreinfo_realize::vmcoreinfo_gdb_he= lper->" + "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 1500056770232699.3763853496084; Fri, 14 Jul 2017 11:26:10 -0700 (PDT) Received: from localhost ([::1]:39382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5I0-0000RW-U7 for importer@patchew.org; Fri, 14 Jul 2017 14:26:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5Cu-0004Kj-NS for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5Ct-0006PW-TQ for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12559) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5Ct-0006P1-NG for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:20:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AAC0F141C5 for ; Fri, 14 Jul 2017 18:20:50 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6B6A60A9F; Fri, 14 Jul 2017 18:20:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AAC0F141C5 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=marcandre.lureau@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AAC0F141C5 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 20:20:11 +0200 Message-Id: <20170714182012.4595-9-marcandre.lureau@redhat.com> In-Reply-To: <20170714182012.4595-1-marcandre.lureau@redhat.com> References: <20170714182012.4595-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Jul 2017 18:20:50 +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 v4 8/8] 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 b9aa878b84..391a28315c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1274,6 +1274,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