KASLR kernel dump support
v2 cover KASLR kernel dump support
Recent linux kernels enable KASLR to randomize phys/virt memory addresses. This series aims to provide enough information in qemu dumps so that crash utility can work with randomized kernel too (it hasn't been tested on other archs than x86 though, help welcome).
The vmcoreinfo device is an emulated ACPI device that 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). The version field with value 0 is meant to give paddr/size of the VMCOREINFO ELF PT_NOTE, other values can be used for different purposes or OSes. (note: some wanted to see pvpanic somehow merged with this device, I have no clear idea how to do that, nor do I think this is a good idea since the devices are quite different, used at different time for different purposes. And it can be done as a future iteration if it is appropriate, feel free to send patches)
Crash 7.1.9 will parse the "phys_base" value from the VMCOREINFO note, and thus will work with KASLR-dump produced by this series.
By priority, VMCOREINFO "phys_base" value is the most accurate. If not available, qemu will keep the current guessed value.
The series implements the VMCOREINFO note addition in qemu ELF/kdump, as well as the python scripts/dump-guest-memory.py.
To test:
Compile and run a guest kernel with CONFIG_RANDOMIZE_BASE=y.
Run qemu with -device vmcoreinfo.
Load the experimental vmcoreinfo module in guest
https://github.com/elmarco/vmgenid-test/blob/master/qemuvmci-test.c.
Produce an ELF dump:
{ "execute": "dump-guest-memory", "arguments": { "protocol": "file:dump", "paging": false } }
Produce a kdump:
{ "execute": "dump-guest-memory", "arguments": { "protocol": "file:dump", "paging": false, "format": "kdump-zlib" } }
Or with (gdb) dump-guest-memory, with scripts/dump-guest-memory.py script.
Analyze with crash >= 7.1.9
$ crash vmlinux dump
v2: from Laszlo review
- vmci: fix guest endianess handling
- vmci: fix wrong sizeof()
- vmci: add back reset logic from vmgenid
- dump: have 1MB size limit for vmcoreinfo
- dump: fix potential off-by-1 buffer manipulation
- dump: use temporary variable for qemu_strtou64
- dump: fixed VMCOREINFO duplication in kdump
- update gdb script to not call into qemu process
- update MAINTAINERS with some new files
Marc-André Lureau (7):
vmgenid: replace x-write-pointer-available hack
acpi: add vmcoreinfo device
tests: add simple vmcoreinfo test
dump: add vmcoreinfo ELF note
kdump: add vmcoreinfo ELF note
scripts/dump-guest-memory.py: add vmcoreinfo
MAINTAINERS: add Dump maintainers
scripts/dump-guest-memory.py | 40 +++++++ include/hw/acpi/aml-build.h | 1 + include/hw/acpi/bios-linker-loader.h | 2 + include/hw/acpi/vmcoreinfo.h | 36 ++++++ include/hw/compat.h | 4 - include/sysemu/dump.h | 2 + dump.c | 145 ++++++++++++++++++++++++ hw/acpi/aml-build.c | 2 + hw/acpi/bios-linker-loader.c | 10 ++ hw/acpi/vmcoreinfo.c | 211 +++++++++++++++++++++++++++++++++++ hw/acpi/vmgenid.c | 9 +- hw/i386/acpi-build.c | 14 +++ tests/vmcoreinfo-test.c | 130 +++++++++++++++++++++ MAINTAINERS | 9 ++ 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 + tests/Makefile.include | 2 + 20 files changed, 747 insertions(+), 12 deletions(-) create mode 100644 include/hw/acpi/vmcoreinfo.h create mode 100644 hw/acpi/vmcoreinfo.c create mode 100644 tests/vmcoreinfo-test.c create mode 100644 docs/specs/vmcoreinfo.txt
Signature · 1 line
2.13.1.395.gf7b71de06
PATCH v2 1/7 vmgenid: replace x-write-pointer-available hack
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 in fw_cfg, which this machine type does not provide $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.9 -global fw_cfg.dma_enabled=off qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support in fw_cfg, which this machine type does not provide $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.6 -global fw_cfg.dma_enabled=on [boots normally]
--- 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(-)
include/hw/acpi/bios-linker-loader.h +2 -0
@@ -7,6 +7,8 @@ typedef struct BIOSLinker {GArray *file_list; } BIOSLinker; +bool bios_linker_loader_can_write_pointer (void ); +BIOSLinker *bios_linker_loader_init (void ); void bios_linker_loader_alloc(BIOSLinker *linker,
include/hw/compat.h +0 -4
@@ -150,10 +150,6 @@ .driver = "fw_cfg_io",\ .property = "dma_enabled",\ .value = "off",\ - },{\ - .driver = "vmgenid",\ - .property = "x-write-pointer-available",\ - .value = "off",\ },#define HW_COMPAT_2_3 \
hw/acpi/bios-linker-loader.c +10 -0
@@ -168,6 +168,16 @@ bios_linker_find_file(const BIOSLinker *linker, const char *name)return NULL ; } +/* +* board code must realize fw_cfg first, as a fixed device, before +* another device realize function call bios_linker_loader_can_write_pointer() +*/ +bool bios_linker_loader_can_write_pointer (void ) +{ +FWCfgState *fw_cfg =fw_cfg_find (); +return fw_cfg &&fw_cfg_dma_enabled (fw_cfg); +} +/* * bios_linker_loader_alloc: ask guest to load file into guest memory. *
hw/acpi/vmgenid.c +1 -8
@@ -205,17 +205,11 @@ static void vmgenid_handle_reset(void *opaque)memset (vms->vmgenid_addr_le,0 ,ARRAY_SIZE (vms->vmgenid_addr_le)); } -static Property vmgenid_properties[] = { -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 =VMGENID (dev); -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_DEVICE );return ;
@@ -239,7 +233,6 @@ static void vmgenid_device_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_vmgenid; dc->realize = vmgenid_realize; dc->hotpluggable = false; - dc->props = vmgenid_properties;object_class_property_add_str (klass,VMGENID_GUID ,NULL , vmgenid_set_guid,NULL );
Signature · 1 line
2.13.1.395.gf7b71de06
Re: [Qemu-devel] [PATCH v2 1/7] vmgenid: replace x-write-pointer-available hack
Quoted 62 lines · Marc-André Lureau
This compat property sole function is to prevent the device from being instantiated. Instead of requiring an extra compat property, check if
fw_cfghas DMA enabled.
fw_cfgis a built-in device that is initialized very early by the machine init code. We have at least one other device that also assumesfw_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 in fw_cfg, which this machine type does not provide $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.9 -global fw_cfg.dma_enabled=off qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support in fw_cfg, which this machine type does not provide $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.6 -global fw_cfg.dma_enabled=on [boots normally]Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>Reviewed-by Ben Warren <[email protected]>--- 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(-)include/hw/acpi/bios-linker-loader.h +2
-0@@ -7,6 +7,8 @@ typedef struct BIOSLinker {GArray *file_list; } BIOSLinker; +bool bios_linker_loader_can_write_pointer (void ); +BIOSLinker *bios_linker_loader_init (void ); void bios_linker_loader_alloc(BIOSLinker *linker,include/hw/compat.h +0
-4@@ -150,10 +150,6 @@ .driver = "fw_cfg_io",\ .property = "dma_enabled",\ .value = "off",\ - },{\ - .driver = "vmgenid",\ - .property = "x-write-pointer-available",\ - .value = "off",\ },#define HW_COMPAT_2_3 \hw/acpi/bios-linker-loader.c +0
-0
hw/acpi/bios-linker-loader.c bios_linker_find_file(const BIOSLinker *linker, const char *name) · line 174
Quoted 7 lines
hw/acpi/bios-linker-loader.c +4
-0@@ -168,6 +168,16 @@ bios_linker_find_file(const BIOSLinker *linker, const char *name)return NULL ; } +/* +* board code must realize fw_cfg first, as a fixed device, before +* another device realize function call bios_linker_loader_can_write_pointer() +*/
The closing "*/" is not correctly indented.
With that fixed,
Thanks
Laszlo
Quoted 41 lines
hw/acpi/bios-linker-loader.c +6
-0+bool bios_linker_loader_can_write_pointer (void ) +{ +FWCfgState *fw_cfg =fw_cfg_find (); +return fw_cfg &&fw_cfg_dma_enabled (fw_cfg); +} +/* * bios_linker_loader_alloc: ask guest to load file into guest memory. * hw/acpi/vmgenid.c +1
-8@@ -205,17 +205,11 @@ static void vmgenid_handle_reset(void *opaque)memset (vms->vmgenid_addr_le,0 ,ARRAY_SIZE (vms->vmgenid_addr_le)); } -static Property vmgenid_properties[] = { -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 =VMGENID (dev); -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_DEVICE );return ;@@ -239,7 +233,6 @@ static void vmgenid_device_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_vmgenid; dc->realize = vmgenid_realize; dc->hotpluggable = false; - dc->props = vmgenid_properties;object_class_property_add_str (klass,VMGENID_GUID ,NULL , vmgenid_set_guid,NULL );
PATCH v2 2/7 acpi: add vmcoreinfo device
In reply to Marc-André LureauThe 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
--- include/hw/acpi/aml-build.h | 1 + include/hw/acpi/vmcoreinfo.h | 36 +++++++ 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, 403 insertions(+) create mode 100644 include/hw/acpi/vmcoreinfo.h create mode 100644 hw/acpi/vmcoreinfo.c create mode 100644 docs/specs/vmcoreinfo.txt
include/hw/acpi/aml-build.h +1 -0
@@ -211,6 +211,7 @@ struct AcpiBuildTables {GArray *rsdp;GArray *tcpalog;GArray *vmgenid; +GArray *vmcoreinfo;BIOSLinker *linker; } AcpiBuildTables;
include/hw/acpi/vmcoreinfo.h new file +36 -0
@@ -0,0 +1,36 @@ +#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" + +#define VMCOREINFO_FW_CFG_SIZE 4096/* Occupy a page of memory */ +#define VMCOREINFO_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ + +#define VMCOREINFO (obj) OBJECT_CHECK(VMCoreInfoState, (obj), VMCOREINFO_DEVICE) + +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 *vmci); +bool vmcoreinfo_get (VMCoreInfoState *vis,uint64_t *paddr,uint32_t *size, +Error **errp); + +#endif
hw/acpi/aml-build.c +2 -0
@@ -1561,6 +1561,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) tables->table_data =g_array_new (false, true/* clear */ ,1 ); tables->tcpalog =g_array_new (false, true/* clear */ ,1 ); tables->vmgenid =g_array_new (false, true/* clear */ ,1 ); + tables->vmcoreinfo =g_array_new (false, true/* clear */ ,1 ); tables->linker =bios_linker_loader_init (); }
@@ -1571,6 +1572,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, 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); }/* Build rsdt table */
hw/acpi/vmcoreinfo.c new file +208 -0
208 lines not on this page · raw message
hw/i386/acpi-build.c +14 -0
@@ -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 = tables->table_data;AcpiSlicOem slic_oem = { .id =NULL , .table_id =NULL };Object *vmgenid_dev; +Object *vmcoreinfo_dev;acpi_get_pm_info (&pm);acpi_get_misc_info (&misc);
@@ -2680,6 +2682,12 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)vmgenid_build_acpi (VMGENID (vmgenid_dev), tables_blob, tables->vmgenid, tables->linker); } + vmcoreinfo_dev =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); + }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;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 =find_vmcoreinfo_dev (); +if (vmcoreinfo_dev) { +vmcoreinfo_add_fw_cfg (VMCOREINFO (vmcoreinfo_dev), pcms->fw_cfg, + tables.vmcoreinfo); + }if (!pcmc->rsdp_in_ram) {/*
default-configs/arm-softmmu.mak +1 -0
@@ -120,6 +120,7 @@ CONFIG_XIO3130=y CONFIG_IOH3420=y CONFIG_I82801B11=y CONFIG_ACPI=y +CONFIG_ACPI_VMCOREINFO=y CONFIG_SMBIOS=y CONFIG_ASPEED_SOC=y CONFIG_GPIO_KEY=y
default-configs/i386-softmmu.mak +1 -0
@@ -59,3 +59,4 @@ CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) CONFIG_PXB=y CONFIG_ACPI_VMGENID=y +CONFIG_ACPI_VMCOREINFO=y
default-configs/x86_64-softmmu.mak +1 -0
@@ -59,3 +59,4 @@ CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) CONFIG_PXB=y CONFIG_ACPI_VMGENID=y +CONFIG_ACPI_VMCOREINFO=y
docs/specs/vmcoreinfo.txt new file +138 -0
138 lines not on this page · raw message
hw/acpi/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o +common-obj-$(CONFIG_ACPI_VMCOREINFO) += vmcoreinfo.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o common-obj-y += acpi_interface.o
Signature · 1 line
2.13.1.395.gf7b71de06
Re: [Qemu-devel] [PATCH v2 2/7] acpi: add vmcoreinfo device
Quoted 12 lines · Marc-André Lureau
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_INFOevent 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.cSigned-off-by Marc-André Lureau <[email protected]>
Quoted 15 lines
--- include/hw/acpi/aml-build.h | 1 + include/hw/acpi/vmcoreinfo.h | 36 +++++++ 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, 403 insertions(+) create mode 100644 include/hw/acpi/vmcoreinfo.h create mode 100644 hw/acpi/vmcoreinfo.c create mode 100644 docs/specs/vmcoreinfo.txt
Re: [Qemu-devel] [PATCH v2 2/7] acpi: add vmcoreinfo device
In reply to Marc-André LureauMarc-André,
sorry about this, but I have another late comment (I shoudl have pointed this out in v1). Regarding:
include/hw/acpi/vmcoreinfo.h line 14
Quoted 3 lines · Marc-André Lureau
include/hw/acpi/vmcoreinfo.h new file +3
-0+#define VMCOREINFO_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/
and
docs/specs/vmcoreinfo.txt line 69
Quoted 7 lines
docs/specs/vmcoreinfo.txt new file +7
-0+ Method (ADDR, 0, NotSerialized) + { + Local0 = Package (0x02) {} + Local0 [Zero] = (VCIA + 0x28) + Local0 [One] = Zero + Return (Local0) + }
and
Quoted 8 lines
docs/specs/vmcoreinfo.txt new file +8
-0+In order to implement an OVMF "SDT Header Probe Suppressor", the contents of +the vmcoreinfo blob has 40 bytes of padding: + ++-----------------------------------+ +| SSDT with OEM Table ID = VMCOREIN | ++-----------------------------------+ +| ... | TOP OF PAGE +| VCIA dword object ----------------|-----> +---------------------------+
docs/specs/vmcoreinfo.txt line 131
Quoted 10 lines
docs/specs/vmcoreinfo.txt new file +10
-0+| ... | | fw-allocated array for | +| _STA method referring to VCIA | | "etc/vmcoreinfo" | +| ... | +---------------------------+ +| ADDR method referring to VCIA | | 0: OVMF SDT Header probe | +| ... | | suppressor | ++-----------------------------------+ | 40: uint32 version field | + | 44: info contents | + | .... | + +---------------------------+ + END OF PAGE
Please define the VMCOREINFO_OFFSET macro like this:
#define VMCOREINFO_OFFSET sizeof(AcpiTableHeader)
and then please refresh the documentation as well:
- replace decimal "40" with "36",
- replace 0x28 in the dumped SSDT with 0x24.
Namely, in order to suppress the OVMF ACP Table Header Probe -- "SDT" simply means "System Description Table" --, it's enough to add zero-padding that *precisely* covers such a header.
Given that we have a typedef for this header in QEMU, we should use it in the definition of VMCOREINFO_OFFSET.
Now, the reason why VMGENID uses 40 instead comes from another
requirement: the VMGENID GUID has to be aligned at 8 bytes. (See requirement "R1a" in "docs/specs/vmgenid.txt".) Therefore the directly necessary 36 bytes of padding are rounded up to 40. See again "docs/specs/vmgenid.txt":
----------------------------------+
| SSDT with OEM Table ID = VMGENID |
+----------------------------------+
| ... | TOP OF PAGE
| VGIA dword object ---------------|-----> +---------------------------+
| ... | | fw-allocated array for |
| _STA method referring to VGIA | | "etc/vmgenid_guid" |
| ... | +---------------------------+
| ADDR method referring to VGIA | | 0: OVMF SDT Header probe |
| ... | | suppressor |
+----------------------------------+ | 36: padding for 8-byte |
| alignment |
| 40: GUID |
| 56: padding to page size |
+---------------------------+END OF PAGE
At offset 36 of "etc/vmgenid_guid", it says "padding for 8-byte alignment".
For VMCOREINFO, you don't need this extra alignment to 8 bytes, before the "version" field is listed. So please make the VMCOREINFO_OFFSET reflect what's actually necessary.
The rest of the code doesn't have to be modified (including your experimental guest kernel driver); changing VMCOREINFO_OFFSET will update all necessary locations automatically, including the generated AML. Only the docs have to be synced manually.
... In fact, there *is* yet another location to update: the test case. I suggest to include "hw/acpi/vmcoreinfo.h" in "tests/vmcoreinfo-test.c", rather than open-code VMCOREINFO_OFFSET there. ... Oh wait: in the test case you don't even use VMCOREINFO_OFFSET for anything. So just delete the macro definition from that patch.
Thank you (and sorry about the churn),
Laszlo
Re: [Qemu-devel] [PATCH v2 2/7] acpi: add vmcoreinfo device
Quoted 44 lines · Laszlo Ersek
Marc-André,
sorry about this, but I have another late comment (I shoudl have pointed this out in v1). Regarding:
include/hw/acpi/vmcoreinfo.h line 14
Quoted 3 lines · Marc-André Lureau
include/hw/acpi/vmcoreinfo.h new file +3
-0+#define VMCOREINFO_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ and
docs/specs/vmcoreinfo.txt line 69
Quoted 7 lines
docs/specs/vmcoreinfo.txt new file +7
-0+ Method (ADDR, 0, NotSerialized) + { + Local0 = Package (0x02) {} + Local0 [Zero] = (VCIA + 0x28) + Local0 [One] = Zero + Return (Local0) + }and
Quoted 8 lines
docs/specs/vmcoreinfo.txt new file +8
-0+In order to implement an OVMF "SDT Header Probe Suppressor", the contents of +the vmcoreinfo blob has 40 bytes of padding: + ++-----------------------------------+ +| SSDT with OEM Table ID = VMCOREIN | ++-----------------------------------+ +| ... | TOP OF PAGE +| VCIA dword object ----------------|-----> +---------------------------+docs/specs/vmcoreinfo.txt line 131
Quoted 10 lines
docs/specs/vmcoreinfo.txt new file +10
-0+| ... | | fw-allocated array for | +| _STA method referring to VCIA | | "etc/vmcoreinfo" | +| ... | +---------------------------+ +| ADDR method referring to VCIA | | 0: OVMF SDT Header probe | +| ... | | suppressor | ++-----------------------------------+ | 40: uint32 version field | + | 44: info contents | + | .... | + +---------------------------+ + END OF PAGEPlease define the
VMCOREINFO_OFFSETmacro like this:
Quoted 4 lines
#define VMCOREINFO_OFFSET sizeof(AcpiTableHeader)and then please refresh the documentation as well:
- replace decimal "40" with "36",
also replace decimal "44", the offset of "info contents", with "40"... you get the idea.
Thanks
Laszlo
Quoted 52 lines
- replace
0x28in the dumped SSDT with0x24.Namely, in order to suppress the OVMF ACP Table Header Probe -- "SDT" simply means "System Description Table" --, it's enough to add zero-padding that *precisely* covers such a header.
Given that we have a typedef for this header in QEMU, we should use it in the definition of
VMCOREINFO_OFFSET.Now, the reason why VMGENID uses 40 instead comes from another
requirement: the VMGENID GUID has to be aligned at 8 bytes. (See requirement "R1a" in "docs/specs/vmgenid.txt".) Therefore the directly necessary 36 bytes of padding are rounded up to 40. See again "docs/specs/vmgenid.txt":----------------------------------+
| SSDT with OEM Table ID = VMGENID | +----------------------------------+ | ... | TOP OF PAGE | VGIA dword object ---------------|-----> +---------------------------+ | ... | | fw-allocated array for | | _STA method referring to VGIA | | "etc/vmgenid_guid" | | ... | +---------------------------+ | ADDR method referring to VGIA | | 0: OVMF SDT Header probe | | ... | | suppressor | +----------------------------------+ | 36: padding for 8-byte | | alignment | | 40: GUID | | 56: padding to page size | +---------------------------+END OF PAGE
At offset 36 of "etc/vmgenid_guid", it says "padding for 8-byte alignment".
For VMCOREINFO, you don't need this extra alignment to 8 bytes, before the "version" field is listed. So please make the
VMCOREINFO_OFFSETreflect what's actually necessary.The rest of the code doesn't have to be modified (including your experimental guest kernel driver); changing
VMCOREINFO_OFFSETwill update all necessary locations automatically, including the generated AML. Only the docs have to be synced manually.... In fact, there *is* yet another location to update: the test case. I suggest to include "
hw/acpi/vmcoreinfo.h" in "tests/vmcoreinfo-test.c", rather than open-codeVMCOREINFO_OFFSETthere. ... Oh wait: in the test case you don't even useVMCOREINFO_OFFSETfor anything. So just delete the macro definition from that patch.Thank you (and sorry about the churn),
Laszlo
PATCH v2 3/7 tests: add simple vmcoreinfo test
In reply to Marc-André LureauThis test is based off vmgenid test from Ben Warren <[email protected]>. It simply checks the vmcoreinfo ACPI device is present and that the memory region associated can be read.
--- tests/vmcoreinfo-test.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.include | 2 + 2 files changed, 132 insertions(+) create mode 100644 tests/vmcoreinfo-test.c
tests/vmcoreinfo-test.c new file +130 -0
@@ -0,0 +1,130 @@ +/* +* 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 later. +* See the COPYING file in the top-level directory. +*/ + +#include <glib.h> +#include <string.h> +#include <unistd.h> +#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 VMCOREINFO_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ +#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 VgidTable; + +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; +VgidTable vgid_table; +int i; + +/* Tables may take a short time to be set up by the guest */ +for (i =0 ; i <RSDP_TRIES_MAX ; i++) { + off =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 = 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 = (rsdt_table.length -sizeof (AcpiRsdtDescriptorRev1)) / +sizeof (uint32_t ); + g_assert_cmpint(tables_nr, >, 0); + +/* get the addresses of the tables pointed by rsdt */ + tables =g_new0 (uint32_t, tables_nr); +ACPI_READ_ARRAY_PTR (tables, tables_nr, rsdt); + +for (i =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 (vgid_table.name_op, tables[i]); +g_assert (vgid_table.name_op ==0x08 );/* name */ +ACPI_READ_ARRAY (vgid_table.vcia, tables[i]); +g_assert (memcmp (vgid_table.vcia,"VCIA" ,4 ) ==0 ); +ACPI_READ_FIELD (vgid_table.val_op, tables[i]); +g_assert (vgid_table.val_op ==0x0C );/* dword */ +ACPI_READ_FIELD (vgid_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 vgid_table.vcia_val; + } + } +g_free (tables); +return 0 ; +} + +static void vmcoreinfo_test (void ) +{ +gchar *cmd; +uint32_t vmci_addr; +int i; + + cmd =g_strdup_printf ("-machine accel=tcg -device vmcoreinfo,id=vmci" ); +qtest_start (cmd); + + vmci_addr =acpi_find_vcia (); +g_assert (vmci_addr); + +for (i =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 =g_test_run (); + +return ret; +}
tests/Makefile.include +2 -0
@@ -251,6 +251,7 @@ gcov-files-i386-y += hw/usb/hcd-xhci.c check-qtest-i386-y += tests/pc-cpu-test$(EXESUF) check-qtest-i386-y += tests/q35-test$(EXESUF) check-qtest-i386-y += tests/vmgenid-test$(EXESUF) +check-qtest-i386-y += tests/vmcoreinfo-test$(EXESUF) gcov-files-i386-y += hw/pci-host/q35.c check-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) += 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 tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")
Signature · 1 line
2.13.1.395.gf7b71de06
Re: [Qemu-devel] [PATCH v2 3/7] tests: add simple vmcoreinfo test
I didn't look at this patch in the previous version, hoping that someone else would. Apparently that hasn't happened, so I'll comment, purely based on a comparison with the vmgenid test:
Quoted 41 lines · Marc-André Lureau
This test is based off vmgenid test from Ben Warren <[email protected]>. It simply checks the vmcoreinfo ACPI device is present and that the memory region associated can be read.
Signed-off-by Marc-André Lureau <[email protected]>--- tests/vmcoreinfo-test.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.include | 2 + 2 files changed, 132 insertions(+) create mode 100644 tests/vmcoreinfo-test.ctests/vmcoreinfo-test.c new file +24
-0@@ -0,0 +1,130 @@ +/* +* 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 later. +* See the COPYING file in the top-level directory. +*/ + +#include <glib.h> +#include <string.h> +#include <unistd.h> +#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 VMCOREINFO_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ +#define RSDP_ADDR_INVALID 0x100000/* RSDP must be below this address */
tests/vmcoreinfo-test.c line 34
Quoted 10 lines
tests/vmcoreinfo-test.c new file +10
-0+#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 VgidTable;
This should be called something resembling "vmcoreinfo table".
tests/vmcoreinfo-test.c line 45
Quoted 11 lines
tests/vmcoreinfo-test.c new file +11
-0+ +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; +VgidTable vgid_table;
ditto.
With these fixed:
Thanks
Laszlo
Quoted 106 lines
tests/vmcoreinfo-test.c new file +85
-0+int i; + +/* Tables may take a short time to be set up by the guest */ +for (i =0 ; i <RSDP_TRIES_MAX ; i++) { + off =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 = 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 = (rsdt_table.length -sizeof (AcpiRsdtDescriptorRev1)) / +sizeof (uint32_t ); + g_assert_cmpint(tables_nr, >, 0); + +/* get the addresses of the tables pointed by rsdt */ + tables =g_new0 (uint32_t, tables_nr); +ACPI_READ_ARRAY_PTR (tables, tables_nr, rsdt); + +for (i =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 (vgid_table.name_op, tables[i]); +g_assert (vgid_table.name_op ==0x08 );/* name */ +ACPI_READ_ARRAY (vgid_table.vcia, tables[i]); +g_assert (memcmp (vgid_table.vcia,"VCIA" ,4 ) ==0 ); +ACPI_READ_FIELD (vgid_table.val_op, tables[i]); +g_assert (vgid_table.val_op ==0x0C );/* dword */ +ACPI_READ_FIELD (vgid_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 vgid_table.vcia_val; + } + } +g_free (tables); +return 0 ; +} + +static void vmcoreinfo_test (void ) +{ +gchar *cmd; +uint32_t vmci_addr; +int i; + + cmd =g_strdup_printf ("-machine accel=tcg -device vmcoreinfo,id=vmci" ); +qtest_start (cmd); + + vmci_addr =acpi_find_vcia (); +g_assert (vmci_addr); + +for (i =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 =g_test_run (); + +return ret; +}tests/Makefile.include +2
-0@@ -251,6 +251,7 @@ gcov-files-i386-y += hw/usb/hcd-xhci.c check-qtest-i386-y += tests/pc-cpu-test$(EXESUF) check-qtest-i386-y += tests/q35-test$(EXESUF) check-qtest-i386-y += tests/vmgenid-test$(EXESUF) +check-qtest-i386-y += tests/vmcoreinfo-test$(EXESUF) gcov-files-i386-y += hw/pci-host/q35.c check-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) += 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 tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")
PATCH v2 4/7 dump: add vmcoreinfo ELF note
In reply to Marc-André LureauRead 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_dump_info_get()
(2) vmcoreinfo ELF note NUMBER(phys_base)= 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.
--- include/sysemu/dump.h | 2 + dump.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)
include/sysemu/dump.h +2 -0
@@ -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;uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);
dump.c +125 -0
183 lines not on this page · raw message
Signature · 1 line
2.13.1.395.gf7b71de06
Re: [Qemu-devel] [PATCH v2 4/7] dump: add vmcoreinfo ELF note
Quoted 6 lines · Marc-André Lureau
Read the vmcoreinfo ELF
PT_NOTEfrom 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_baseinformation.(1) arch guessed value from
cpu_dump_info_get()
I recommend using the clipboard; the function is still called cpu_get_dump_info() :)
Quoted 191 lines
(2) vmcoreinfo ELF note NUMBER(phys_base)= field
NUMBER(phys_base)in vmcoreinfo has only been recently introduced in Linux 4.10 (401721ecd1dc"kexec: export the value ofphys_baseinstead 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_basevalue is stored in the same dump field locations as before, and may duplicate the information available in the vmcoreinfo ELFPT_NOTE. Crash tools should be prepared to handle this case.Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/dump.h | 2 + dump.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)include/sysemu/dump.h +2
-0@@ -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;uint16_t cpu_to_dump16 (DumpState *s,uint16_t val);dump.c +94
-0@@ -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" #include <zlib.h> #ifdef CONFIG_LZO @@ -38,6 +40,11 @@#define ELF_MACHINE_UNAME "Unknown"#endif +#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 ==ELFDATA2LSB ) {@@ -76,6 +83,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 =NULL ;if (s->resume) {if (s->detached) {qemu_mutex_lock_iothread ();@@ -235,6 +244,19 @@ static inline int cpu_index(CPUState *cpu)return cpu->cpu_index +1 ; } +static void write_vmcoreinfo_note (WriteCoreDumpFunction f,DumpState *s, +Error **errp) +{ +int ret; + +if (s->vmcoreinfo) { + ret =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 +280,8 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,return ; } } + +write_vmcoreinfo_note (f, s, errp); }static void write_elf32_note (DumpState *s,Error **errp)@@ -303,6 +327,8 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,return ; } } + +write_vmcoreinfo_note (f, s, errp); }static void write_elf_section (DumpState *s,int type,Error **errp)@@ -714,6 +740,44 @@ static int buf_write_note(const void *buf, size_t size, void *opaque)return 0 ; } +/* +* 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 ==ELFCLASS64 ) { +const Elf64_Nhdr *hdr = note; + note_head_sz =sizeof (Elf64_Nhdr); + name_sz =tswap64 (hdr->n_namesz); + desc_sz =tswap64 (hdr->n_descsz); + }else { +const Elf32_Nhdr *hdr = note; + note_head_sz =sizeof (Elf32_Nhdr); + name_sz =tswap32 (hdr->n_namesz); + desc_sz =tswap32 (hdr->n_descsz); + } + +if (note_head_size) { + *note_head_size = note_head_sz; + } +if (name_size) { + *name_size = name_sz; + } +if (desc_size) { + *desc_size = desc_sz; + } +} +/* write common header, sub header and elf note to vmcore */ static void create_header32 (DumpState *s,Error **errp) {@@ -1488,10 +1552,40 @@ static int64_t dump_calculate_size(DumpState *s)return total; } +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 =ROUND_UP (note_head_size,4 ); + name_size =ROUND_UP (name_size,4 ); + vmci = s->vmcoreinfo + note_head_size + name_size; + *(vmci + size) ='\0' ; + + lines =g_strsplit ((char *)vmci,"\n" ,-1 ); +for (i =0 ; lines[i]; i++) { +if (g_str_has_prefix (lines[i],"NUMBER(phys_base)=" )) { +if (qemu_strtou64 (lines[i] +18 ,NULL ,16 , + &phys_base) <0 ) { +error_report ("Failed to read NUMBER(phys_base)=" ); + }else { + s->dump_info.phys_base = 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 =find_vmcoreinfo_dev ();CPUState *cpu;int nr_cpus;Error *err =NULL ;
dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1660
Quoted 4 lines
dump.c +1
-0@@ -1563,6 +1657,37 @@ static void dump_init(DumpState *s, int fd, bool has_format, goto cleanup; } +#define MAX_VMCOREINFO_SIZE (1 << 20)/* 1MB should be enough */
I think we generally place macros like this near the top of the file. You already #define ELF_NOTE_SIZE up there.
dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1661
Quoted 1 line
dump.c +1
-0+if (vmcoreinfo_dev) {
I'm sorry, I should have asked for this in the previous version -- can you place a comment here, above the "if", saying that 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.
dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1670
Quoted 9 lines
dump.c +9
-0+uint64_t addr, note_head_size, name_size, desc_size; +uint32_t size; + + note_head_size = s->dump_info.d_class ==ELFCLASS32 ? +sizeof (Elf32_Nhdr) :sizeof (Elf64_Nhdr); + +if (!vmcoreinfo_get (VMCOREINFO (vmcoreinfo_dev), + &addr, &size, &err)) { +error_report_err (err);
Apologies, I should have noticed this too in the previous version. After you print and free the error with error_report_err(), you should also null the "err" variable. The dump_init() function goes on to receive further errors into "err", and if "err" is not NULL at that point, two things can happen:
- if a function uses error_propagate() into "err", then "err" will appear to have been set earlier, and error_propagate() will drop the new error.
- if error_setg() or similar is used instead, then that will trip an assert.
dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1672
Quoted 2 lines
dump.c +2
-0+ }else if (size < note_head_size || size >MAX_VMCOREINFO_SIZE ) { +error_report ("vmcoreinfo size is invalid: %u" , size);
Consider using "%"PRIu32 for stylistic reasons, although in practice %u is perfectly fine for uint32_t (since uint32_t *is* "unsigned int").
dump.c static void dump_init(DumpState *s, int fd, bool has_format, · line 1677
Quoted 5 lines
dump.c +5
-0+ }else { + s->vmcoreinfo =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);
So, to answer your earlier question, please check both "name_size" and "desc_size" individually against MAX_VMCOREINFO_SIZE. (While preserving the cumulative size check below, of course.) This is simple enough and ensures neither the roundings nor the additions can overflow later.
If any of these checks fails, you'll have to free and null s->vmcoreinfo here too.
The rest looks good!
Thanks!
Laszlo
Quoted 17 lines
dump.c +13
-0+ s->vmcoreinfo_size =ELF_NOTE_SIZE (note_head_size, name_size, + desc_size); +if (s->vmcoreinfo_size > size) { +error_report ("Invalid vmcoreinfo header, size mismatch" ); +g_free (s->vmcoreinfo); + s->vmcoreinfo =NULL ; + }else { +vmcoreinfo_update_phys_base (s); + s->note_size += s->vmcoreinfo_size; + } + } + } +/* get memory mapping */ if (paging) {qemu_get_guest_memory_mapping (&s->list, &s->guest_phys_blocks, &err);
PATCH v2 5/7 kdump: add vmcoreinfo ELF note
In reply to Marc-André Lureaukdump header provides offset and size of the vmcoreinfo ELF note, append it if available.
--- dump.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
dump.c +20 -0
@@ -839,6 +839,16 @@ static void create_header32(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size - s->vmcoreinfo_size + + (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump32 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump32 (s, s->note_size);
@@ -939,6 +949,16 @@ static void create_header64(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size - s->vmcoreinfo_size + + (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump64 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump64 (s, s->note_size);
Signature · 1 line
2.13.1.395.gf7b71de06
Re: [Qemu-devel] [PATCH v2 5/7] kdump: add vmcoreinfo ELF note
Quoted 37 lines · Marc-André Lureau
kdump header provides offset and size of the vmcoreinfo ELF note, append it if available.
Signed-off-by Marc-André Lureau <[email protected]>--- dump.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)dump.c +13
-0@@ -839,6 +839,16 @@ static void create_header32(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size - s->vmcoreinfo_size + + (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump32 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump32 (s, s->note_size);@@ -939,6 +949,16 @@ static void create_header64(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =DISKDUMP_HEADER_BLOCKS * block_size + size; +if (s->vmcoreinfo) { +uint64_t hsize, name_size, size_vmcoreinfo_desc, offset_vmcoreinfo; +
dump.c static void create_header64(DumpState *s, Error **errp) · line 964
Quoted 10 lines
dump.c +7
-0+get_note_sizes (s, s->vmcoreinfo, &hsize, &name_size, &size_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size - s->vmcoreinfo_size + + (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump64 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump64 (s, s->note_size);
I continue to think that this patch is unnecessary, but if you insist, it does look OK to me.
Re: [Qemu-devel] [PATCH v2 5/7] kdump: add vmcoreinfo ELF note
Hi
Quoted 52 lines · Laszlo Ersek
Quoted 37 lines · Marc-André Lureau
kdump header provides offset and size of the vmcoreinfo ELF note, append it if available.
Signed-off-by Marc-André Lureau <[email protected]>--- dump.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)dump.c +13
-0@@ -839,6 +839,16 @@ static void create_header32(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size - s->vmcoreinfo_size + + (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump32 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump32 (s, s->note_size);@@ -939,6 +949,16 @@ static void create_header64(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =DISKDUMP_HEADER_BLOCKS * block_size + size; +if (s->vmcoreinfo) { +uint64_t hsize, name_size, size_vmcoreinfo_desc, offset_vmcoreinfo; +dump.c static void create_header64(DumpState *s, Error **errp) · line 964
Quoted 10 lines
dump.c +7
-0+get_note_sizes (s, s->vmcoreinfo, &hsize, &name_size, &size_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size - s->vmcoreinfo_size + + (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump64 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump64 (s, s->note_size);I continue to think that this patch is unnecessary, but if you insist, it does look OK to me.
Quoted 1 line
Reviewed-by Laszlo Ersek <[email protected]>
Without it, crash doesn't read the vmcoreinfo PT_NOTE. And for some reason, the phys_base in the header wasn't enough (to be doubled checked).
Any comment Dave about crash handling of vmcoreinfo in kdump files?
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH v2 5/7] kdump: add vmcoreinfo ELF note
----- Original Message -----
Quoted 64 lines
Hi
Quoted 61 lines · Laszlo Ersek
Quoted 48 lines · Marc-André Lureau
kdump header provides offset and size of the vmcoreinfo ELF note, append it if available.
Signed-off-by Marc-André Lureau <[email protected]>--- dump.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)dump.c +5
-0@@ -839,6 +839,16 @@ static void create_header32(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size -
s->vmcoreinfo_size+dump.c +10
-0+ (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump32 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump32 (s, s->note_size);@@ -939,6 +949,16 @@ static void create_header64(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size -
s->vmcoreinfo_size+dump.c static void create_header64(DumpState *s, Error **errp) · line 963
Quoted 7 lines
dump.c +5
-0+ (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump64 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump64 (s, s->note_size);I continue to think that this patch is unnecessary, but if you insist,
it does look OK to me.
Quoted 7 lines
Quoted 1 line
Reviewed-by Laszlo Ersek <[email protected]>Without it, crash doesn't read the vmcoreinfo
PT_NOTE. And for some reason, thephys_basein the header wasn't enough (to be doubled checked).Any comment Dave about crash handling of vmcoreinfo in kdump files?
It just reads the kdump_sub_header's offset_vmcoreinfo and size_vmcoreinfo fields to gather the vmcoreinfo data into a local buffer of memory, and scans the strings for whatever it's looking for.
With respect to phys_base, the only thing that might be of consequence is this fairly recent change that's currently only in the github repo, queued for crash-7.2.0:
commit a4a538caca140a8e948bbdae2be311168db7a1eb
Author: Dave Anderson <[email protected]>
Date: Tue May 2 16:51:53 2017 -0400
Fix for Linux 4.10 and later kdump dumpfiles, or kernels that have backported commit 401721ecd1dcb0a428aa5d6832ee05ffbdbffbbe, titled "kexec: export the value of phys_base instead of symbol address". Without the patch, if the x86_64 "phys_base" value in the VMCOREINFO note is a negative decimal number, the crash session fails during session intialization with a "page excluded" or "seek error" when reading "page_offset_base".
([email protected])
Also, 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.
Dave
Quoted 6 lines
--
Marc-André Lureau
Re: [Qemu-devel] [PATCH v2 5/7] kdump: add vmcoreinfo ELF note
Quoted 96 lines · Dave Anderson
----- Original Message -----
Quoted 64 lines
Hi
Quoted 61 lines · Laszlo Ersek
Quoted 48 lines · Marc-André Lureau
kdump header provides offset and size of the vmcoreinfo ELF note, append it if available.
Signed-off-by Marc-André Lureau <[email protected]>--- dump.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)dump.c +5
-0@@ -839,6 +839,16 @@ static void create_header32(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size -
s->vmcoreinfo_size+dump.c +10
-0+ (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump32 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump32 (s, s->note_size);@@ -939,6 +949,16 @@ static void create_header64(DumpState *s, Error **errp) kh->dump_level =cpu_to_dump32 (s,DUMP_LEVEL ); offset_note =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_vmcoreinfo_desc); + offset_vmcoreinfo = offset_note + s->note_size -
s->vmcoreinfo_size+dump.c static void create_header64(DumpState *s, Error **errp) · line 963
Quoted 7 lines
dump.c +5
-0+ (DIV_ROUND_UP (hsize,4 ) +DIV_ROUND_UP (name_size,4 )) *4 ; + kh->offset_vmcoreinfo =cpu_to_dump64 (s, offset_vmcoreinfo); + kh->size_vmcoreinfo =cpu_to_dump64 (s, size_vmcoreinfo_desc); + } + kh->offset_note =cpu_to_dump64 (s, offset_note); kh->note_size =cpu_to_dump64 (s, s->note_size);I continue to think that this patch is unnecessary, but if you insist,
it does look OK to me.
Quoted 7 lines
Quoted 1 line
Reviewed-by Laszlo Ersek <[email protected]>Without it, crash doesn't read the vmcoreinfo
PT_NOTE. And for some reason, thephys_basein the header wasn't enough (to be doubled checked).Any comment Dave about crash handling of vmcoreinfo in kdump files?
It just reads the kdump_sub_header's
offset_vmcoreinfoandsize_vmcoreinfofields to gather the vmcoreinfo data into a local buffer of memory, and scans the strings for whatever it's looking for.With respect to
phys_base, the only thing that might be of consequence is this fairly recent change that's currently only in the github repo, queued for crash-7.2.0:commit
a4a538caca140a8e948bbdae2be311168db7a1eb
Author: Dave Anderson <[email protected]>
Date: Tue May 2 16:51:53 2017 -0400Fix for Linux 4.10 and later kdump dumpfiles, or kernels that have backported commit
401721ecd1dcb0a428aa5d6832ee05ffbdbffbbe, titled "kexec: export the value ofphys_baseinstead of symbol address". Without the patch, if thex86_64"phys_base" value in the VMCOREINFO note is a negative decimal number, the crash session fails during session intialization with a "page excluded" or "seek error" when reading "page_offset_base".
([email protected])
Quoted 2 lines
Also, crash-7.1.9 was the first version that started looking in the vmcoreinfo data for
phys_baseinstead of in thekdump_sub_header.
OK, if crash (or earlier versions of crash) need this QEMU patch, then I'm fine with it -- my R-b stands.
Thanks
Laszlo
PATCH v2 6/7 scripts/dump-guest-memory.py: add vmcoreinfo
In reply to Marc-André LureauAdd 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().
--- scripts/dump-guest-memory.py | 40 ++++++++++++++++++++++++++++++++++++++++ hw/acpi/vmcoreinfo.c | 3 +++ 2 files changed, 43 insertions(+)
scripts/dump-guest-memory.py +40 -0
@@ -14,6 +14,7 @@ the COPYING file in the top-level directory. """ import ctypes +import struct UINTPTR_T = gdb.lookup_type("uintptr_t")
@@ -120,6 +121,20 @@ class ELF(object): self.segments[0].p_filesz += ctypes.sizeof(note) self.segments[0].p_memsz += ctypes.sizeof(note) + + def add_vmcoreinfo_note(self, vmcoreinfo): + """Adds a vmcoreinfo note to the ELF dump.""" + chead = type(get_arch_note(self.endianness, 0, 0)) + header = chead.from_buffer_copy(vmcoreinfo[0:ctypes.sizeof(chead)]) + note = get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(note)) + header_size = ctypes.sizeof(note) - header.n_descsz + + self.notes.append(note) + self.segments[0].p_filesz += ctypes.sizeof(note) + self.segments[0].p_memsz += ctypes.sizeof(note) + def add_segment(self, p_type, p_paddr, p_size): """Adds a segment to the elf."""
@@ -505,6 +520,30 @@ shape and this command should mostly work.""" cur += chunk_size left -= chunk_size + def phys_memory_read(self, addr, size): + qemu_core = gdb.inferiors()[0] + for block in self.guest_phys_blocks: + if block["target_start"] <= addr < block["target_end"]: + haddr = block["host_addr"] + (addr - block["target_start"]) + return qemu_core.read_memory(haddr, size) + + def add_vmcoreinfo(self): + if not gdb.parse_and_eval("vmcoreinfo_gdb_helper"): + return + + addr = gdb.parse_and_eval("vmcoreinfo_gdb_helper.vmcoreinfo_addr_le") + addr = bytes([addr[i] for i in range(4)]) + addr = struct.unpack("<I", addr)[0] + + mem = self.phys_memory_read(addr, 16) + (version, addr, size) = struct.unpack("<IQI", mem) + if version != 0: + return + + vmcoreinfo = self.phys_memory_read(addr, size) + if vmcoreinfo: + self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes()) + def invoke(self, args, from_tty): """Handles command invocation from gdb."""
@@ -518,6 +557,7 @@ shape and this command should mostly work.""" self.elf = ELF(argv[1]) self.guest_phys_blocks = get_guest_phys_blocks() + self.add_vmcoreinfo() with open(argv[0], "wb") as vmcore: self.dump_init(vmcore)
hw/acpi/vmcoreinfo.c +3 -0
@@ -163,6 +163,8 @@ static void vmcoreinfo_handle_reset(void *opaque)memset (vis->vmcoreinfo_addr_le,0 ,ARRAY_SIZE (vis->vmcoreinfo_addr_le)); } +static VMCoreInfoState *vmcoreinfo_gdb_helper; +static void vmcoreinfo_realize (DeviceState *dev,Error **errp) {if (!bios_linker_loader_can_write_pointer ()) {
@@ -181,6 +183,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)return ; } + vmcoreinfo_gdb_helper =VMCOREINFO (dev);qemu_register_reset (vmcoreinfo_handle_reset, dev); }
Signature · 1 line
2.13.1.395.gf7b71de06
Re: [Qemu-devel] [PATCH v2 6/7] scripts/dump-guest-memory.py: add vmcoreinfo
Quoted 24 lines · Marc-André Lureau
Add vmcoreinfo ELF note if vmcoreinfo device is ready.
To help the python script, add a little global
vmcoreinfo_gdbstructure, that is populated withvmcoreinfo_gdb_update().Signed-off-by Marc-André Lureau <[email protected]>--- scripts/dump-guest-memory.py | 40 ++++++++++++++++++++++++++++++++++++++++ hw/acpi/vmcoreinfo.c | 3 +++ 2 files changed, 43 insertions(+)scripts/dump-guest-memory.py +1
-0@@ -14,6 +14,7 @@ the COPYING file in the top-level directory. """ import ctypes +import struct UINTPTR_T = gdb.lookup_type("uintptr_t")
scripts/dump-guest-memory.py class ELF(object): · line 128
Quoted 8 lines
scripts/dump-guest-memory.py +5
-0@@ -120,6 +121,20 @@ class ELF(object): self.segments[0].p_filesz += ctypes.sizeof(note) self.segments[0].p_memsz += ctypes.sizeof(note) + + def add_vmcoreinfo_note(self, vmcoreinfo): + """Adds a vmcoreinfo note to the ELF dump.""" + chead = type(get_arch_note(self.endianness, 0, 0)) + header = chead.from_buffer_copy(vmcoreinfo[0:ctypes.sizeof(chead)])
Maybe it's obvious to others, but I would have been helped a lot if a comment had explained that you are creating a fake note (with 0 desc size and 0 name size) to figure out the size of the note header. And then you copy that many bytes out of the vmcoreinfo ELF note.
scripts/dump-guest-memory.py class ELF(object): · line 130
Quoted 2 lines
scripts/dump-guest-memory.py +2
-0+ note = get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz)
Why the -1?
... I think I'm giving up here for this method. My python is weak and I can't follow this too well. Please add some comments.
More comments below:
Quoted 11 lines
scripts/dump-guest-memory.py +7
-0+ ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(note)) + header_size = ctypes.sizeof(note) - header.n_descsz + + self.notes.append(note) + self.segments[0].p_filesz += ctypes.sizeof(note) + self.segments[0].p_memsz += ctypes.sizeof(note) + def add_segment(self, p_type, p_paddr, p_size): """Adds a segment to the elf."""
scripts/dump-guest-memory.py shape and this command should mostly work.""" · line 526
Quoted 7 lines
scripts/dump-guest-memory.py +4
-0@@ -505,6 +520,30 @@ shape and this command should mostly work.""" cur += chunk_size left -= chunk_size + def phys_memory_read(self, addr, size): + qemu_core = gdb.inferiors()[0] + for block in self.guest_phys_blocks: + if block["target_start"] <= addr < block["target_end"]:
Although I don't expect a single read to straddle phys-blocks, I would prefer if you checked (addr + size) -- and not just addr -- against block["target_end"].
Quoted 46 lines
scripts/dump-guest-memory.py +21
-0+ haddr = block["host_addr"] + (addr - block["target_start"]) + return qemu_core.read_memory(haddr, size) + + def add_vmcoreinfo(self): + if not gdb.parse_and_eval("vmcoreinfo_gdb_helper"): + return + + addr = gdb.parse_and_eval("vmcoreinfo_gdb_helper.vmcoreinfo_addr_le") + addr = bytes([addr[i] for i in range(4)]) + addr = struct.unpack("<I", addr)[0] + + mem = self.phys_memory_read(addr, 16) + (version, addr, size) = struct.unpack("<IQI", mem) + if version != 0: + return + + vmcoreinfo = self.phys_memory_read(addr, size) + if vmcoreinfo: + self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes()) + def invoke(self, args, from_tty): """Handles command invocation from gdb."""@@ -518,6 +557,7 @@ shape and this command should mostly work.""" self.elf = ELF(argv[1]) self.guest_phys_blocks = get_guest_phys_blocks() + self.add_vmcoreinfo() with open(argv[0], "wb") as vmcore: self.dump_init(vmcore)hw/acpi/vmcoreinfo.c +2
-0@@ -163,6 +163,8 @@ static void vmcoreinfo_handle_reset(void *opaque)memset (vis->vmcoreinfo_addr_le,0 ,ARRAY_SIZE (vis->vmcoreinfo_addr_le)); } +static VMCoreInfoState *vmcoreinfo_gdb_helper; +static void vmcoreinfo_realize (DeviceState *dev,Error **errp) {if (!bios_linker_loader_can_write_pointer ()) {
hw/acpi/vmcoreinfo.c static void vmcoreinfo_realize(DeviceState *dev, Error **errp) · line 189
Quoted 7 lines
hw/acpi/vmcoreinfo.c +1
-0@@ -181,6 +183,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)return ; } + vmcoreinfo_gdb_helper =VMCOREINFO (dev);qemu_register_reset (vmcoreinfo_handle_reset, dev); }
I guess we don't build QEMU with link-time optimization at the moment.
With link-time optimization, I think gcc might reasonably optimize away the assignment to "vmcoreinfo_gdb_helper", and "vmcoreinfo_gdb_helper" itself. This is why I suggested "volatile":
static VMCoreInfoState * volatile vmcoreinfo_gdb_helper;
Do you think volatile is only superfluous, or do you actively dislike it for some reason?
Thanks,
Laszlo
Re: [Qemu-devel] [PATCH v2 6/7] scripts/dump-guest-memory.py: add vmcoreinfo
Hi
----- Original Message -----
Quoted 28 lines · Marc-André Lureau
Quoted 27 lines
Add vmcoreinfo ELF note if vmcoreinfo device is ready.
To help the python script, add a little global
vmcoreinfo_gdbstructure, that is populated withvmcoreinfo_gdb_update().Signed-off-by Marc-André Lureau <[email protected]>--- scripts/dump-guest-memory.py | 40 ++++++++++++++++++++++++++++++++++++++++ hw/acpi/vmcoreinfo.c | 3 +++ 2 files changed, 43 insertions(+)scripts/dump-guest-memory.py +1
-0@@ -14,6 +14,7 @@ the COPYING file in the top-level directory. """ import ctypes +import struct UINTPTR_T = gdb.lookup_type("uintptr_t")@@ -120,6 +121,20 @@ class ELF(object): self.segments[0].p_filesz += ctypes.sizeof(note) self.segments[0].p_memsz += ctypes.sizeof(note)
Quoted 12 lines
scripts/dump-guest-memory.py class ELF(object):
Quoted 6 lines
scripts/dump-guest-memory.py +5
-0+ + def add_vmcoreinfo_note(self, vmcoreinfo): + """Adds a vmcoreinfo note to the ELF dump.""" + chead = type(get_arch_note(self.endianness, 0, 0)) + header = chead.from_buffer_copy(vmcoreinfo[0:ctypes.sizeof(chead)])Maybe it's obvious to others, but I would have been helped a lot if a comment had explained that you are creating a fake note (with 0 desc size and 0 name size) to figure out the size of the note header. And then you copy that many bytes out of the vmcoreinfo ELF note.
ok
Quoted 4 lines
scripts/dump-guest-memory.py class ELF(object): · line 130
Quoted 2 lines
scripts/dump-guest-memory.py +2
-0+ note = get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz)Why the -1?
because get_arch_note() adds + 1 (supposedly for the ending \0, see also add_note())
Quoted 3 lines
... I think I'm giving up here for this method. My python is weak and I can't follow this too well. Please add some comments.
I simplified a bit the code now, I was also discovering some ctype usage.
Quoted 17 lines
More comments below:
Quoted 15 lines
scripts/dump-guest-memory.py +7
-0+ ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(note)) + header_size = ctypes.sizeof(note) - header.n_descsz + + self.notes.append(note) + self.segments[0].p_filesz += ctypes.sizeof(note) + self.segments[0].p_memsz += ctypes.sizeof(note) + def add_segment(self, p_type, p_paddr, p_size):"""Adds a segment to the elf."""
scripts/dump-guest-memory.py +0
-0@@ -505,6 +520,30 @@ shape and this command should mostly work.""" cur += chunk_size left -= chunk_size
Quoted 8 lines
scripts/dump-guest-memory.py shape and this command should mostly work.""" · line 526
Quoted 4 lines
scripts/dump-guest-memory.py +4
-0+ def phys_memory_read(self, addr, size): + qemu_core = gdb.inferiors()[0] + for block in self.guest_phys_blocks: + if block["target_start"] <= addr < block["target_end"]:Although I don't expect a single read to straddle phys-blocks, I would prefer if you checked (addr + size) -- and not just addr -- against block["target_end"].
done
Quoted 61 lines
Quoted 51 lines
scripts/dump-guest-memory.py +20
-0+ haddr = block["host_addr"] + (addr - block["target_start"]) + return qemu_core.read_memory(haddr, size) + + def add_vmcoreinfo(self): + if not gdb.parse_and_eval("vmcoreinfo_gdb_helper"): + return + + addr = gdb.parse_and_eval("vmcoreinfo_gdb_helper.vmcoreinfo_addr_le") + addr = bytes([addr[i] for i in range(4)]) + addr = struct.unpack("<I", addr)[0] + + mem = self.phys_memory_read(addr, 16) + (version, addr, size) = struct.unpack("<IQI", mem) + if version != 0: + return + + vmcoreinfo = self.phys_memory_read(addr, size) + if vmcoreinfo: + self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes()) + def invoke(self, args, from_tty):"""Handles command invocation from gdb."""
scripts/dump-guest-memory.py +1
-0@@ -518,6 +557,7 @@ shape and this command should mostly work.""" self.elf = ELF(argv[1]) self.guest_phys_blocks = get_guest_phys_blocks() + self.add_vmcoreinfo() with open(argv[0], "wb") as vmcore: self.dump_init(vmcore)hw/acpi/vmcoreinfo.c +2
-0@@ -163,6 +163,8 @@ static void vmcoreinfo_handle_reset(void *opaque)memset (vis->vmcoreinfo_addr_le,0 ,ARRAY_SIZE (vis->vmcoreinfo_addr_le)); } +static VMCoreInfoState *vmcoreinfo_gdb_helper; +static void vmcoreinfo_realize (DeviceState *dev,Error **errp) {if (!bios_linker_loader_can_write_pointer()) {hw/acpi/vmcoreinfo.c static void vmcoreinfo_realize(DeviceState *dev, Error · line 189
Quoted 7 lines
hw/acpi/vmcoreinfo.c +1
-0@@ -181,6 +183,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)return ; } + vmcoreinfo_gdb_helper =VMCOREINFO (dev);qemu_register_reset (vmcoreinfo_handle_reset, dev); }I guess we don't build QEMU with link-time optimization at the moment.
Quoted 8 lines
With link-time optimization, I think gcc might reasonably optimize away the assignment to "
vmcoreinfo_gdb_helper", and "vmcoreinfo_gdb_helper" itself. This is why I suggested "volatile":static VMCoreInfoState * volatile
vmcoreinfo_gdb_helper;Do you think volatile is only superfluous, or do you actively dislike it for some reason?
Yeah, I am not convinced volatile is the best way, but nor is static.
Let's export it?
Re: [Qemu-devel] [PATCH v2 6/7] scripts/dump-guest-memory.py: add vmcoreinfo
Quoted 29 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 26 lines · Marc-André Lureau
Quoted 10 lines
Add vmcoreinfo ELF note if vmcoreinfo device is ready.
To help the python script, add a little global
vmcoreinfo_gdbstructure, that is populated withvmcoreinfo_gdb_update().Signed-off-by Marc-André Lureau <[email protected]>hw/acpi/vmcoreinfo.c static void vmcoreinfo_realize(DeviceState *dev, Error · line 189
Quoted 7 lines
hw/acpi/vmcoreinfo.c +1
-0@@ -181,6 +183,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)return ; } + vmcoreinfo_gdb_helper =VMCOREINFO (dev);qemu_register_reset (vmcoreinfo_handle_reset, dev); }I guess we don't build QEMU with link-time optimization at the moment.
With link-time optimization, I think gcc might reasonably optimize away the assignment to "
vmcoreinfo_gdb_helper", and "vmcoreinfo_gdb_helper" itself. This is why I suggested "volatile":
Quoted 8 lines
Quoted 4 lines
static VMCoreInfoState * volatile
vmcoreinfo_gdb_helper;Do you think volatile is only superfluous, or do you actively dislike it for some reason?
Yeah, I am not convinced volatile is the best way, but nor is static.
Let's export it?
Volatile guarantees that the assignment will take place according to the behavior of the "abstract C machine" described by ISO C. From ISO C99,
6.7.3 Type qualifiers
6 An object that has volatile-qualified type may be modified in ways
unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously. [116] What constitutes an access to an object that has volatile-qualified type is implementation-defined.
Footnote 116: A volatile declaration may be used to describe an object
corresponding to a memory-mapped input/output port or an object accessed by an asynchronously interrupting function. Actions on objects so declared shall not be "optimized out" by an implementation or reordered except as permitted by the rules for evaluating expressions.
So basically if you can find the symbol somehow, it will always have the right value, due to the volatile qualifier, regardless of the optimizations the compiler did.
Internal vs. external linkage ("static" vs. "extern") is a different question; it might affect whether you find the symbol at all. IME, symbols for objects with internal linkage are preserved, if: (a) you don't strip the final binary, and (b) gcc doesn't optimize the variable away.
With link-time / full program optimization, gcc is entitled to optimize away variables with external linkage too, so "extern" in itself is not bulletproof. Volatile is more important.
Given volatile, I'm sort of neutral on extern vs. static. However, if you make the variable extern, that makes abuse from other source files easier. (The variable should only be looked at with gdb.) This is also why I originally suggested to limit the scope of even the static variable to function scope -- this way abuse would completely be prevented (nothing else could access the variable even from the same translation unit), and gdb would still find the variable (IME).
Thanks
Laszlo
Re: [Qemu-devel] [PATCH v2 6/7] scripts/dump-guest-memory.py: add vmcoreinfo
Hi
----- Original Message -----
Quoted 72 lines · Marc-André Lureau
Quoted 30 lines
Hi
----- Original Message -----
Quoted 27 lines · Marc-André Lureau
Quoted 10 lines
Add vmcoreinfo ELF note if vmcoreinfo device is ready.
To help the python script, add a little global
vmcoreinfo_gdbstructure, that is populated withvmcoreinfo_gdb_update().Signed-off-by Marc-André Lureau <[email protected]>(quoted diff) +0
-0@@ -181,6 +183,7 @@ static void vmcoreinfo_realize(DeviceState *dev,Error
**errp)Quoted 8 lines
return; }+ vmcoreinfo_gdb_helper = VMCOREINFO(dev); qemu_register_reset(vmcoreinfo_handle_reset, dev);}
I guess we don't build QEMU with link-time optimization at the moment.
With link-time optimization, I think gcc might reasonably optimize away the assignment to "
vmcoreinfo_gdb_helper", and "vmcoreinfo_gdb_helper" itself. This is why I suggested "volatile":Quoted 8 lines
Quoted 4 lines
static VMCoreInfoState * volatile
vmcoreinfo_gdb_helper;Do you think volatile is only superfluous, or do you actively dislike it for some reason?
Yeah, I am not convinced volatile is the best way, but nor is static.
Let's export it?
Volatile guarantees that the assignment will take place according to the behavior of the "abstract C machine" described by ISO C. From ISO C99,
6.7.3 Type qualifiers
6 An object that has volatile-qualified type may be modified in ways
unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously. [116] What constitutes an access to an object that has volatile-qualified type is implementation-defined.Footnote 116: A volatile declaration may be used to describe an object
corresponding to a memory-mapped input/output port or an object accessed by an asynchronously interrupting function. Actions on objects so declared shall not be "optimized out" by an implementation or reordered except as permitted by the rules for evaluating expressions.So basically if you can find the symbol somehow, it will always have the right value, due to the volatile qualifier, regardless of the optimizations the compiler did.
Internal vs. external linkage ("static" vs. "extern") is a different question; it might affect whether you find the symbol at all. IME, symbols for objects with internal linkage are preserved, if: (a) you don't strip the final binary, and (b) gcc doesn't optimize the variable away.
Quoted 3 lines
With link-time / full program optimization, gcc is entitled to optimize away variables with external linkage too, so "extern" in itself is not bulletproof. Volatile is more important.
Ok, you seem confident about this sort of things, I am not, I'll follow you :)
Quoted 9 lines
Given volatile, I'm sort of neutral on extern vs. static. However, if you make the variable extern, that makes abuse from other source files easier. (The variable should only be looked at with gdb.) This is also why I originally suggested to limit the scope of even the static variable to function scope -- this way abuse would completely be prevented (nothing else could access the variable even from the same translation unit), and gdb would still find the variable (IME).
How do you access a static inside a function? Gdb can look it up but complains that it's not in current context.
Re: [Qemu-devel] [PATCH v2 6/7] scripts/dump-guest-memory.py: add vmcoreinfo
Quoted 90 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 72 lines · Marc-André Lureau
Quoted 30 lines
Hi
----- Original Message -----
Quoted 27 lines · Marc-André Lureau
Quoted 10 lines
Add vmcoreinfo ELF note if vmcoreinfo device is ready.
To help the python script, add a little global
vmcoreinfo_gdbstructure, that is populated withvmcoreinfo_gdb_update().Signed-off-by Marc-André Lureau <[email protected]>(quoted diff) +0
-0@@ -181,6 +183,7 @@ static void vmcoreinfo_realize(DeviceState *dev,Error
**errp)Quoted 8 lines
return; }+ vmcoreinfo_gdb_helper = VMCOREINFO(dev); qemu_register_reset(vmcoreinfo_handle_reset, dev);}
I guess we don't build QEMU with link-time optimization at the moment.
With link-time optimization, I think gcc might reasonably optimize away the assignment to "
vmcoreinfo_gdb_helper", and "vmcoreinfo_gdb_helper" itself. This is why I suggested "volatile":Quoted 8 lines
Quoted 4 lines
static VMCoreInfoState * volatile
vmcoreinfo_gdb_helper;Do you think volatile is only superfluous, or do you actively dislike it for some reason?
Yeah, I am not convinced volatile is the best way, but nor is static.
Let's export it?
Volatile guarantees that the assignment will take place according to the behavior of the "abstract C machine" described by ISO C. From ISO C99,
6.7.3 Type qualifiers
6 An object that has volatile-qualified type may be modified in ways
unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously. [116] What constitutes an access to an object that has volatile-qualified type is implementation-defined.Footnote 116: A volatile declaration may be used to describe an object
corresponding to a memory-mapped input/output port or an object accessed by an asynchronously interrupting function. Actions on objects so declared shall not be "optimized out" by an implementation or reordered except as permitted by the rules for evaluating expressions.So basically if you can find the symbol somehow, it will always have the right value, due to the volatile qualifier, regardless of the optimizations the compiler did.
Internal vs. external linkage ("static" vs. "extern") is a different question; it might affect whether you find the symbol at all. IME, symbols for objects with internal linkage are preserved, if: (a) you don't strip the final binary, and (b) gcc doesn't optimize the variable away.
Quoted 3 lines
With link-time / full program optimization, gcc is entitled to optimize away variables with external linkage too, so "extern" in itself is not bulletproof. Volatile is more important.
Ok, you seem confident about this sort of things, I am not, I'll follow you :)
Quoted 9 lines
Given volatile, I'm sort of neutral on extern vs. static. However, if you make the variable extern, that makes abuse from other source files easier. (The variable should only be looked at with gdb.) This is also why I originally suggested to limit the scope of even the static variable to function scope -- this way abuse would completely be prevented (nothing else could access the variable even from the same translation unit), and gdb would still find the variable (IME).
Quoted 2 lines
How do you access a static inside a function? Gdb can look it up but complains that it's not in current context.
According to <https://sourceware.org/gdb/onlinedocs/gdb/Variables.html>,
the magic incantation is
function::variable
If this doesn't work (in case the realize function isn't on the stack at all), then I agree the variable should be made file scope.
Thanks
Laszlo
Re: [Qemu-devel] [PATCH v2 6/7] scripts/dump-guest-memory.py: add vmcoreinfo
Hi
----- Original Message -----
Quoted 92 lines · Marc-André Lureau
Quoted 91 lines
Hi
----- Original Message -----
Quoted 72 lines · Marc-André Lureau
Quoted 30 lines
Hi
----- Original Message -----
Quoted 27 lines · Marc-André Lureau
Quoted 10 lines
Add vmcoreinfo ELF note if vmcoreinfo device is ready.
To help the python script, add a little global
vmcoreinfo_gdbstructure, that is populated withvmcoreinfo_gdb_update().Signed-off-by Marc-André Lureau <[email protected]>(quoted diff) +0
-0@@ -181,6 +183,7 @@ static void vmcoreinfo_realize(DeviceState *dev,Error
**errp)Quoted 8 lines
return; }+ vmcoreinfo_gdb_helper = VMCOREINFO(dev); qemu_register_reset(vmcoreinfo_handle_reset, dev);}
I guess we don't build QEMU with link-time optimization at the moment.
With link-time optimization, I think gcc might reasonably optimize away the assignment to "
vmcoreinfo_gdb_helper", and "vmcoreinfo_gdb_helper" itself. This is why I suggested "volatile":Quoted 8 lines
Quoted 4 lines
static VMCoreInfoState * volatile
vmcoreinfo_gdb_helper;Do you think volatile is only superfluous, or do you actively dislike it for some reason?
Yeah, I am not convinced volatile is the best way, but nor is static.
Let's export it?
Volatile guarantees that the assignment will take place according to the behavior of the "abstract C machine" described by ISO C. From ISO C99,
6.7.3 Type qualifiers
6 An object that has volatile-qualified type may be modified in ways
unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously. [116] What constitutes an access to an object that has volatile-qualified type is implementation-defined.Footnote 116: A volatile declaration may be used to describe an object
corresponding to a memory-mapped input/output port or an object accessed by an asynchronously interrupting function. Actions on objects so declared shall not be "optimized out" by an implementation or reordered except as permitted by the rules for evaluating expressions.So basically if you can find the symbol somehow, it will always have the right value, due to the volatile qualifier, regardless of the optimizations the compiler did.
Internal vs. external linkage ("static" vs. "extern") is a different question; it might affect whether you find the symbol at all. IME, symbols for objects with internal linkage are preserved, if: (a) you don't strip the final binary, and (b) gcc doesn't optimize the variable away.
Quoted 3 lines
With link-time / full program optimization, gcc is entitled to optimize away variables with external linkage too, so "extern" in itself is not bulletproof. Volatile is more important.
Ok, you seem confident about this sort of things, I am not, I'll follow you :)
Quoted 9 lines
Given volatile, I'm sort of neutral on extern vs. static. However, if you make the variable extern, that makes abuse from other source files easier. (The variable should only be looked at with gdb.) This is also why I originally suggested to limit the scope of even the static variable to function scope -- this way abuse would completely be prevented (nothing else could access the variable even from the same translation unit), and gdb would still find the variable (IME).
Quoted 9 lines
Quoted 3 lines
How do you access a static inside a function? Gdb can look it up but complains that it's not in current context.
According to <https://sourceware.org/gdb/onlinedocs/gdb/Variables.html>,
the magic incantation is
function::variable
Thanks that works! I'll update the patch
Quoted 3 lines
If this doesn't work (in case the realize function isn't on the stack at all), then I agree the variable should be made file scope.
Why would it matter if realize is on the stack? It's likely not :)
Re: [Qemu-devel] [PATCH v2 6/7] scripts/dump-guest-memory.py: add vmcoreinfo
Quoted 11 lines · Marc-André Lureau
Quoted 9 lines
Quoted 3 lines
How do you access a static inside a function? Gdb can look it up but complains that it's not in current context.
According to <https://sourceware.org/gdb/onlinedocs/gdb/Variables.html>,
the magic incantation is
function::variableThanks that works! I'll update the patch
Great!
Quoted 6 lines
Quoted 4 lines
If this doesn't work (in case the realize function isn't on the stack at all), then I agree the variable should be made file scope.
Why would it matter if realize is on the stack? It's likely not :)
I agree the realize function will likely not be on the stack, and I also agree that it should not matter. However, the gdb docs seemed a bit unclear to me regarding this, so I wasn't 100% sure without trying.
Thanks
Laszlo
PATCH v2 7/7 MAINTAINERS: add Dump maintainers
In reply to Marc-André LureauProposing myself, since I have some familiarity with the code now.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -1272,6 +1272,15 @@ S: Maintained F: device_tree.c F: include/sysemu/device_tree.h +Dump +S: Supported +M: Marc-André Lureau <[email protected]> +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 <[email protected]> S: Supported
Signature · 1 line
2.13.1.395.gf7b71de06
Re: [Qemu-devel] [PATCH v2 7/7] MAINTAINERS: add Dump maintainers
Quoted 18 lines · Marc-André Lureau
Proposing myself, since I have some familiarity with the code now.
Signed-off-by Marc-André Lureau <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +2
-0@@ -1272,6 +1272,15 @@ S: Maintained F: device_tree.c F: include/sysemu/device_tree.h +Dump +S: Supported
MAINTAINERS S: Maintained · line 1286
Quoted 10 lines
MAINTAINERS +7
-0+M: Marc-André Lureau <[email protected]> +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 <[email protected]> S: Supported