dump: report win-dmp via vmcoreinfo, guard guest-RAM reads during migration
v5 cover dump: report win-dmp via vmcoreinfo, guard guest-RAM reads during migration
This series fixes Windows-dump (win-dmp) availability reporting and closes a related hole found while doing so: several commands read guest RAM and must not run while a migration destination is still receiving it.
dump-guest-memory, memsave and pmemsave all read guest RAM on the main thread with the BQL held. On a migration destination that RAM is either still being loaded (precopy) or pulled from the source on demand (postcopy, where the guest already runs). During precopy the read returns incomplete data; during postcopy it deadlocks, as the read faults on a not-yet-received page while the postcopy incoming path needs the BQL the reader holds to install it. dump-guest-memory only guarded the precopy phase and memsave/pmemsave had no guard at all, so a new migration_guest_ram_loading() predicate captures both phases and all three commands now use it.
query-dump-guest-memory-capability also advertised win-dmp for every x86 VM, and dump-guest-memory accepted it unconditionally; win-dmp only works when the guest has published a Windows dump header through vmcoreinfo. win_dump_available() now reads that note back from the vmcoreinfo device and validates it, keeping its original signature, so the dump.c call sites are unchanged.
The series also adds the first qtest coverage for dump-guest-memory:
capability list, ELF and kdump output, protocol errors, and win-dmp reporting in both directions (the positive case forges a vmcoreinfo note, so no Windows guest is needed).
Tested:
- Linux guest: win-dmp not advertised; an explicit win-dmp request is rejected without stopping the guest; elf/kdump dumps work.
- Windows Server 2022 guest: win-dmp advertised once vmcoreinfo is populated; dump-guest-memory format=win-dmp produces a valid (PAGEDU64) crashdump.
- Live postcopy migration: on the destination, dump-guest-memory, memsave and pmemsave are all refused immediately, without faulting a page.
This supersedes the earlier "dump: enhance win_dump_available to report properly" series, which obtained the note by reusing the dump setup path (splitting dump_init() and stopping the vCPUs). Reading vmcoreinfo directly is much smaller.
Changes since v4:
- Refuse guest-RAM reads (dump-guest-memory, memsave, pmemsave) while a migration destination is still receiving RAM, via a shared migration_guest_ram_loading() helper.
- Decide win-dmp availability by reading vmcoreinfo directly instead of splitting dump_init()/dump_preinit() and stopping the vCPUs.
- Add dump-guest-memory qtests.
Denis V. Lunev (7):
migration: add migration_guest_ram_loading() helper
dump: refuse dump-guest-memory while guest RAM is being migrated system/cpus: refuse memsave/pmemsave while guest RAM is being migrated
dump: make win_dump_available() check vmcoreinfo for a Windows dump
header
tests/qtest: add dump-guest-memory test
tests/qtest/dump: reject win-dmp without vmcoreinfo tests/qtest/dump: cover win-dmp availability via vmcoreinfo
MAINTAINERS | 1 + dump/dump.c | 5 +- dump/win_dump-x86.c | 42 +++++ include/migration/misc.h | 3 + migration/migration.c | 6 + system/cpus.c | 11 ++ tests/qtest/dump-test.c | 331 +++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 8 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/dump-test.c
base-commit: c7cf7c810153d6f5f31aa2d5c0dee9087f6b4dff
Signature · 1 line
2.53.0
PATCH v5 1/7 migration: add migration_guest_ram_loading() helper
Operations that read guest RAM (dump-guest-memory, memsave, pmemsave) must refuse to run while the destination of a migration is still receiving that RAM: during precopy it is incomplete, and during postcopy a read faults the page in from the source. Provide a single predicate they can share instead of open-coding the runstate and postcopy checks.
--- include/migration/misc.h | 3 +++ migration/migration.c | 6 ++++++ 2 files changed, 9 insertions(+)
include/migration/misc.h +3 -0
@@ -117,6 +117,9 @@ void migration_file_set_error(int ret, Error *err);/* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ bool migration_in_incoming_postcopy (void ); +/* True while the destination still receives guest RAM (precopy or postcopy) */ +bool migration_guest_ram_loading (void ); +/* True if incoming migration entered POSTCOPY_INCOMING_ADVISE */ bool migration_incoming_postcopy_advised (void );
migration/migration.c +6 -0
@@ -1643,6 +1643,12 @@ bool migration_in_incoming_postcopy(void)return ps >=POSTCOPY_INCOMING_DISCARD && ps <POSTCOPY_INCOMING_END ; } +bool migration_guest_ram_loading (void ) +{ +return runstate_check (RUN_STATE_INMIGRATE ) || +migration_in_incoming_postcopy (); +} +bool migration_incoming_postcopy_advised (void ) {PostcopyState ps =postcopy_state_get ();
Signature · 1 line
2.53.0
PATCH v5 2/7 dump: refuse dump-guest-memory while guest RAM is being migrated
In reply to Denis V. Lunev via qemu developmentdump-guest-memory reads all of guest RAM. The existing guard only rejects the dump in RUN_STATE_INMIGRATE, i.e. the precopy load phase. On a postcopy destination the guest already runs (RUN_STATE_RUNNING) while its pages are pulled from the source on demand.
A non-detached dump reads that RAM on the main thread with the BQL held. Touching a not-yet-received page blocks on the userfault, and because the postcopy incoming path itself takes the BQL to install pages, the transfer that would satisfy the fault cannot progress: the VM deadlocks.
Use migration_guest_ram_loading(), which also covers postcopy, so the dump is refused for the whole time the destination is still receiving guest RAM.
--- dump/dump.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
dump/dump.c +3 -2
@@ -29,6 +29,7 @@#include "qemu/main-loop.h" #include "hw/misc/vmcoreinfo.h" #include "migration/blocker.h" +#include "migration/misc.h" #include "hw/core/cpu.h" #include "win_dump.h" #include "qemu/range.h"
@@ -2079,8 +2080,8 @@ void qmp_dump_guest_memory(bool paging, const char *protocol,bool detach_p = false;bool kdump_raw = false; -if (runstate_check (RUN_STATE_INMIGRATE )) { -error_setg (errp,"Dump not allowed during incoming migration." ); +if (migration_guest_ram_loading ()) { +error_setg (errp,"Dump not allowed during migration." );return ; }
Signature · 1 line
2.53.0
PATCH v5 3/7 system/cpus: refuse memsave/pmemsave while guest RAM is being migrated
In reply to Denis V. Lunev via qemu developmentmemsave and pmemsave read guest memory and write it to a file, with no guard at all. They run on the main thread with the BQL held, so on a postcopy destination touching a not-yet-received page deadlocks: the thread blocks on the userfault while the postcopy incoming path waits for the BQL to install that page. During precopy the read returns incomplete state instead.
Refuse both while guest RAM is still being received, using the same migration_guest_ram_loading() check as dump-guest-memory.
--- system/cpus.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
system/cpus.c +11 -0
@@ -42,6 +42,7 @@#include "hw/core/nmi.h" #include "system/replay.h" #include "system/runstate.h" +#include "migration/misc.h" #include "system/cpu-timers.h" #include "system/whpx.h" #include "hw/core/boards.h"
@@ -841,6 +842,11 @@ void qmp_memsave(uint64_t addr, uint64_t size, const char *filename,uint8_t buf[1024 ];uint64_t orig_addr = addr, orig_size = size; +if (migration_guest_ram_loading ()) { +error_setg (errp,"Guest memory access not allowed during migration" ); +return ; + } +if (!has_cpu) { cpu_index =0 ; }
@@ -887,6 +893,11 @@ void qmp_pmemsave(uint64_t addr, uint64_t size, const char *filename,uint64_t l;uint8_t buf[1024 ]; +if (migration_guest_ram_loading ()) { +error_setg (errp,"Guest memory access not allowed during migration" ); +return ; + } + f =fopen (filename,"wb" );if (!f) {error_setg_file_open (errp, errno, filename);
Signature · 1 line
2.53.0
PATCH v5 4/7 dump: make win_dump_available() check vmcoreinfo for a Windows dump header
In reply to Denis V. Lunev via qemu developmentQMP query-dump-guest-memory-capability reports win-dmp as available for any x86 VM, and dump-guest-memory accepts the win-dmp format unconditionally. Both are wrong: win-dmp only works when the guest has published a Windows dump header through vmcoreinfo.
The guest registers that note with the vmcoreinfo device (its physical address and size), so win_dump_available() can read it back directly and validate the note size and the Windows dump header signature. This needs no other guest state, so it does not stop the vCPUs.
The capability query reads the note on the main thread with the BQL held and has no migration guard of its own, so it is skipped while a migration destination is still receiving guest RAM: there the read would deadlock against the postcopy load (which needs the BQL) or, in precopy, see incomplete pages.
Based on the original work of Nikolai Barybin.
--- dump/win_dump-x86.c | 49 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-)
dump/win_dump-x86.c +44 -5
@@ -17,11 +17,10 @@#include "qemu/win_dump_defs.h" #include "win_dump.h" #include "cpu.h" - -bool win_dump_available (Error **errp) -{ -return true; -} +#include "qemu/bswap.h" +#include "hw/misc/vmcoreinfo.h" +#include "migration/misc.h" +#include "standard-headers/linux/qemu_fw_cfg.h" static size_t win_dump_ptr_size (bool x64) {
@@ -403,6 +402,46 @@ static void restore_context(WinDumpHeader *h, bool x64, } } +bool win_dump_available (Error **errp) +{ +VMCoreInfoState *vmci =vmcoreinfo_find (); + g_autofree uint8_t *note = NULL; +Error *local_err =NULL ; +WinDumpHeader *h; +uint32_t size; +bool x64 = true; + +if (migration_guest_ram_loading ()) { +error_setg (errp,"win-dump: not available during migration" ); +return false; + } + +if (!vmci || !vmci->has_vmcoreinfo || +le16_to_cpu (vmci->vmcoreinfo.guest_format) != +FW_CFG_VMCOREINFO_FORMAT_ELF ) { +error_setg (errp,"win-dump: no vmcoreinfo note from the guest" ); +return false; + } + + size =le32_to_cpu (vmci->vmcoreinfo.size); +if (size !=VMCOREINFO_WIN_DUMP_NOTE_SIZE32 && + size !=VMCOREINFO_WIN_DUMP_NOTE_SIZE64 ) { +error_setg (errp,"win-dump: invalid vmcoreinfo note size" ); +return false; + } + + note =g_malloc (size); +cpu_physical_memory_read (le64_to_cpu (vmci->vmcoreinfo.paddr), note, size); + + h = (void *)(note +VMCOREINFO_ELF_NOTE_HDR_SIZE ); +if (!check_header (h, &x64, &local_err)) { +error_propagate (errp, local_err); +return false; + } + +return true; +} +void create_win_dump (DumpState *s,Error **errp) {WinDumpHeader *h = (void *)(s->guest_note +VMCOREINFO_ELF_NOTE_HDR_SIZE );
Signature · 1 line
2.53.0
PATCH v5 5/7 tests/qtest: add dump-guest-memory test
In reply to Denis V. Lunev via qemu developmentThere is currently almost no coverage for the dump-guest-memory QMP command beyond the test-hmp smoke test. Add a qtest that runs on a bare machine (no guest OS) and checks:
- query-dump-guest-memory-capability always advertises 'elf';
- an ELF dump is produced and starts with the ELF magic;
- a non-raw kdump dump is emitted in makedumpfile flattened format;
- a raw kdump dump starts with the on-disk KDUMP header;
- an unknown protocol is rejected without killing the VM, and dumping still works afterwards.
--- MAINTAINERS | 1 + tests/qtest/dump-test.c | 188 ++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 3 files changed, 190 insertions(+) create mode 100644 tests/qtest/dump-test.c
MAINTAINERS +1 -0
@@ -3291,6 +3291,7 @@ F: scripts/dump-guest-memory.py F: stubs/dump.c F: docs/specs/vmcoreinfo.rst F: tests/qtest/vmcoreinfo-test.c +F: tests/qtest/dump-test.c Error reporting M: Markus Armbruster <[email protected]>
tests/qtest/dump-test.c new file +188 -0
188 lines not on this page · raw message
tests/qtest/meson.build +1 -0
@@ -59,6 +59,7 @@ qtests_i386 = \ (config_all_devices.has_key('CONFIG_FDC_ISA') ? ['fdc-test'] : []) + \ (config_all_devices.has_key('CONFIG_I440FX') ? ['fw_cfg-test'] : []) + \ (config_all_devices.has_key('CONFIG_FW_CFG_DMA') ? ['vmcoreinfo-test'] : []) + \ + ['dump-test'] + \ (config_all_devices.has_key('CONFIG_I440FX') ? ['i440fx-test'] : []) + \ (config_all_devices.has_key('CONFIG_I440FX') ? ['ide-test'] : []) + \ (config_all_devices.has_key('CONFIG_I440FX') ? ['numa-test'] : []) + \
Signature · 1 line
2.53.0
PATCH v5 6/7 tests/qtest/dump: reject win-dmp without vmcoreinfo
In reply to Denis V. Lunev via qemu developmentRequesting the Windows crashdump format (win-dmp) on a guest that does not expose a Windows dump header through vmcoreinfo must be rejected, not silently turned into a bogus dump. Add a test that asks for win-dmp on a plain VM and checks the request fails with "invalid vmcoreinfo note size" and that the VM stays usable afterwards (a subsequent ELF dump succeeds).
The test is x86_64 only, where win_dump_available() performs this check.
--- tests/qtest/dump-test.c | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
tests/qtest/dump-test.c +49 -0
@@ -174,8 +174,51 @@ static void test_dump_invalid_protocol(void)qtest_quit (qts); } +/* +* Requesting win-dmp without a Windows dump header in vmcoreinfo must be +* rejected with a clear error -- and must leave the VM usable, rather than +* produce a bogus dump. +*/ +static void test_dump_win_dmp_unavailable (void ) +{ +QTestState *qts =dump_test_start (); + g_autofree char *tmp = NULL; + g_autofree char *proto = NULL; + g_autofree char *path = NULL; +GError *err =NULL ; +QDict *resp, *error; +const char *desc; +int fd; + + fd =g_file_open_tmp ("dump-test-XXXXXX" , &tmp, &err); +g_assert_no_error (err); +close (fd); + proto =g_strdup_printf ("file:%s" , tmp); + + resp =qtest_qmp (qts, +"{ 'execute': 'dump-guest-memory'," +" 'arguments': { 'paging': false, 'protocol': %s," +" 'format': 'win-dmp' } }" , proto); + error =qdict_get_qdict (resp,"error" ); +g_assert_nonnull (error); + desc =qdict_get_try_str (error,"desc" ); +g_assert_nonnull (desc); +g_assert_nonnull (strstr (desc,"vmcoreinfo" )); +qobject_unref (resp); +unlink (tmp); + +/* the failed request must not wedge the VM: a plain dump still works */ + path =do_dump (qts,NULL ); +assert_valid_elf_core (path); +unlink (path); + +qtest_quit (qts); +} +int main (int argc,char **argv) { +const char *arch =qtest_get_arch (); +g_test_init (&argc, &argv,NULL );qtest_add_func ("/dump/query-capability" , test_query_capability);
@@ -184,5 +227,11 @@ int main(int argc, char **argv)qtest_add_func ("/dump/kdump-raw-zlib" , test_dump_kdump_raw_zlib);qtest_add_func ("/dump/invalid-protocol" , test_dump_invalid_protocol); +/* win-dmp is an x86_64-only format */ +if (g_str_equal (arch,"x86_64" )) { +qtest_add_func ("/dump/win-dmp-unavailable" , + test_dump_win_dmp_unavailable); + } +return g_test_run (); }
Signature · 1 line
2.53.0
PATCH v5 7/7 tests/qtest/dump: cover win-dmp availability via vmcoreinfo
In reply to Denis V. Lunev via qemu developmentwin-dmp becomes available only once the guest exposes a Windows dump header through vmcoreinfo. Forge exactly such a note (an ELF note header followed by a WinDumpHeader64 carrying the PAGE/DU64 signatures, the layout a Windows guest with the QEMU vmcoreinfo writer produces), place it in guest RAM, point the vmcoreinfo device at it via fw_cfg, and check that win-dmp flips from unavailable to available.
This exercises win_dump_available()'s positive path without a real Windows guest. It only covers availability reporting; the actual win-dmp generation (create_win_dump()) needs real Windows kernel structures and is not exercised here.
The test is registered only on x86_64 with a vmcoreinfo device present.
--- tests/qtest/dump-test.c | 94 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)
tests/qtest/dump-test.c +94 -0
@@ -12,10 +12,15 @@#include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/libqos-pc.h" +#include "libqos/fw_cfg.h" #include "qobject/qdict.h" #include "qobject/qlist.h" #include "qobject/qstring.h" #include "qemu/bswap.h" +#include "qemu/win_dump_defs.h" +#include "standard-headers/linux/qemu_fw_cfg.h" +#include "hw/misc/vmcoreinfo.h" #include "elf.h" #define KDUMP_RAW_MAGIC "KDUMP "
@@ -215,6 +220,90 @@ static void test_dump_win_dmp_unavailable(void)qtest_quit (qts); } +static bool capability_has_format (QTestState *qts,const char *want) +{ +QDict *resp, *ret; +QList *formats; +QListEntry *e; +bool found = false; + + resp =qtest_qmp (qts, +"{ 'execute': 'query-dump-guest-memory-capability' }" ); +g_assert (qdict_haskey (resp,"return" )); + ret =qdict_get_qdict (resp,"return" ); + formats =qdict_get_qlist (ret,"formats" ); +g_assert_nonnull (formats); + + QLIST_FOREACH_ENTRY(formats, e) { +QString *qs =qobject_to (QString,qlist_entry_obj (e)); + +if (g_str_equal (qstring_get_str (qs), want)) { + found = true; + } + } +qobject_unref (resp); +return found; +} + +/* +* win-dmp becomes available only once the guest exposes a Windows dump +* header through vmcoreinfo. Forge exactly such a note -- the layout a +* Windows guest with the QEMU vmcoreinfo writer produces: a fixed-size ELF +* note header followed by a WinDumpHeader64 carrying the PAGE/DU64 +* signatures -- place it in guest RAM, point the vmcoreinfo device at it +* via fw_cfg, and check that win-dmp flips from unavailable to available. +* +* This only covers availability *reporting*; the actual win-dmp generation +* (create_win_dump()) needs real Windows kernel structures and is not +* exercised here. +*/ +static void test_dump_win_dmp_available (void ) +{ +const uint64_t paddr =0x800000 ;/* 8 MiB, inside guest RAM */ +size_t notesz =VMCOREINFO_WIN_DUMP_NOTE_SIZE64 ; + g_autofree uint8_t *note = g_malloc0(notesz); +Elf64_Nhdr *nhdr = (Elf64_Nhdr *)note; +WinDumpHeader64 *hdr; +FWCfgVMCoreInfo info; +QFWCFG *fw_cfg; +QOSState *qs; + +/* the WinDumpHeader64 must sit right after the fixed ELF note header */ + g_assert_cmpint(sizeof(WinDumpHeader64) % 4, ==, 0); + + nhdr->n_namesz =cpu_to_le32 (sizeof ("VMCOREINFO" ));/* 11 -> padded 12 */ + nhdr->n_descsz =cpu_to_le32 (sizeof (WinDumpHeader64)); + nhdr->n_type =0 ; +memcpy (note +sizeof (Elf64_Nhdr),"VMCOREINFO" ,sizeof ("VMCOREINFO" ) -1 ); + + hdr = (WinDumpHeader64 *)(note +VMCOREINFO_ELF_NOTE_HDR_SIZE ); +memcpy (hdr->Signature,"PAGE" ,sizeof (hdr->Signature)); +memcpy (hdr->ValidDump,"DU64" ,sizeof (hdr->ValidDump)); + + qs =qtest_pc_boot ("-device vmcoreinfo -m 16" ); + fw_cfg =pc_fw_cfg_init (qs->qts); + +/* with no guest note yet, win-dmp must not be advertised */ +g_assert_false (capability_has_format (qs->qts,"win-dmp" )); + +/* place the forged note in guest RAM and point vmcoreinfo at it */ +qtest_memwrite (qs->qts, paddr, note, notesz); + +memset (&info,0 ,sizeof (info)); + info.host_format =cpu_to_le16 (FW_CFG_VMCOREINFO_FORMAT_ELF ); + info.guest_format =cpu_to_le16 (FW_CFG_VMCOREINFO_FORMAT_ELF ); + info.size =cpu_to_le32 (notesz); + info.paddr =cpu_to_le64 (paddr); +qfw_cfg_write_file (fw_cfg, qs,FW_CFG_VMCOREINFO_FILENAME , + &info,sizeof (info)); + +/* now win-dmp must be reported as available */ +g_assert_true (capability_has_format (qs->qts,"win-dmp" )); + +pc_fw_cfg_uninit (fw_cfg); +qtest_shutdown (qs); +} +int main (int argc,char **argv) {const char *arch =qtest_get_arch ();
@@ -231,6 +320,11 @@ int main(int argc, char **argv)if (g_str_equal (arch,"x86_64" )) {qtest_add_func ("/dump/win-dmp-unavailable" , test_dump_win_dmp_unavailable); + +if (qtest_has_device ("vmcoreinfo" )) { +qtest_add_func ("/dump/win-dmp-available" , + test_dump_win_dmp_available); + } }return g_test_run ();
Signature · 1 line
2.53.0
Hi
Quoted 50 lines · Denis V. Lunev via qemu development
This series fixes Windows-dump (win-dmp) availability reporting and closes a related hole found while doing so: several commands read guest RAM and must not run while a migration destination is still receiving it.
dump-guest-memory, memsave and pmemsave all read guest RAM on the main thread with the BQL held. On a migration destination that RAM is either still being loaded (precopy) or pulled from the source on demand (postcopy, where the guest already runs). During precopy the read returns incomplete data; during postcopy it deadlocks, as the read faults on a not-yet-received page while the postcopy incoming path needs the BQL the reader holds to install it. dump-guest-memory only guarded the precopy phase and memsave/pmemsave had no guard at all, so a new
migration_guest_ram_loading()predicate captures both phases and all three commands now use it.query-dump-guest-memory-capability also advertised win-dmp for every x86 VM, and dump-guest-memory accepted it unconditionally; win-dmp only works when the guest has published a Windows dump header through vmcoreinfo.
win_dump_available()now reads that note back from the vmcoreinfo device and validates it, keeping its original signature, so thedump.ccall sites are unchanged.The series also adds the first qtest coverage for dump-guest-memory:
capability list, ELF and kdump output, protocol errors, and win-dmp reporting in both directions (the positive case forges a vmcoreinfo note, so no Windows guest is needed).Tested:
- Linux guest: win-dmp not advertised; an explicit win-dmp request is rejected without stopping the guest; elf/kdump dumps work.
- Windows Server 2022 guest: win-dmp advertised once vmcoreinfo is populated; dump-guest-memory format=win-dmp produces a valid (PAGEDU64) crashdump.
- Live postcopy migration: on the destination, dump-guest-memory, memsave and pmemsave are all refused immediately, without faulting a page.This supersedes the earlier "dump: enhance
win_dump_availableto report properly" series, which obtained the note by reusing the dump setup path (splittingdump_init()and stopping the vCPUs). Reading vmcoreinfo directly is much smaller.Changes since v4:
- Refuse guest-RAM reads (dump-guest-memory, memsave, pmemsave) while a migration destination is still receiving RAM, via a sharedmigration_guest_ram_loading()helper.
- Decide win-dmp availability by reading vmcoreinfo directly instead of splitting dump_init()/dump_preinit() and stopping the vCPUs.
- Add dump-guest-memory qtests.
Quoted 6 lines
Denis V. Lunev (7):
migration: addmigration_guest_ram_loading()helper
dump: refuse dump-guest-memory while guest RAM is being migrated system/cpus: refuse memsave/pmemsave while guest RAM is being migrated
dump: makewin_dump_available()check vmcoreinfo for a Windows dump
header
Looks all good to me, except it needs s/cpu_physical_memory_read/physical_memory_read now. I can do that on MR
Philippe, do you know why physical_memory_read/write() do not return MemTxResult?
Quoted 21 lines
tests/qtest: add dump-guest-memory test tests/qtest/dump: reject win-dmp without vmcoreinfo tests/qtest/dump: cover win-dmp availability via vmcoreinfo
MAINTAINERS | 1 + dump/dump.c | 5 +- dump/win_dump-x86.c | 42 +++++ include/migration/misc.h | 3 + migration/migration.c | 6 + system/cpus.c | 11 ++ tests/qtest/dump-test.c | 331 +++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 8 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/dump-test.cbase-commit:
c7cf7c810153d6f5f31aa2d5c0dee9087f6b4dff--
2.53.0
Quoted 61 lines · Marc-André Lureau
Hi
Quoted 50 lines · Denis V. Lunev via qemu development
This series fixes Windows-dump (win-dmp) availability reporting and closes a related hole found while doing so: several commands read guest RAM and must not run while a migration destination is still receiving it.
dump-guest-memory, memsave and pmemsave all read guest RAM on the main thread with the BQL held. On a migration destination that RAM is either still being loaded (precopy) or pulled from the source on demand (postcopy, where the guest already runs). During precopy the read returns incomplete data; during postcopy it deadlocks, as the read faults on a not-yet-received page while the postcopy incoming path needs the BQL the reader holds to install it. dump-guest-memory only guarded the precopy phase and memsave/pmemsave had no guard at all, so a new
migration_guest_ram_loading()predicate captures both phases and all three commands now use it.query-dump-guest-memory-capability also advertised win-dmp for every x86 VM, and dump-guest-memory accepted it unconditionally; win-dmp only works when the guest has published a Windows dump header through vmcoreinfo.
win_dump_available()now reads that note back from the vmcoreinfo device and validates it, keeping its original signature, so thedump.ccall sites are unchanged.The series also adds the first qtest coverage for dump-guest-memory:
capability list, ELF and kdump output, protocol errors, and win-dmp reporting in both directions (the positive case forges a vmcoreinfo note, so no Windows guest is needed).Tested:
- Linux guest: win-dmp not advertised; an explicit win-dmp request is rejected without stopping the guest; elf/kdump dumps work.
- Windows Server 2022 guest: win-dmp advertised once vmcoreinfo is populated; dump-guest-memory format=win-dmp produces a valid (PAGEDU64) crashdump.
- Live postcopy migration: on the destination, dump-guest-memory, memsave and pmemsave are all refused immediately, without faulting a page.This supersedes the earlier "dump: enhance
win_dump_availableto report properly" series, which obtained the note by reusing the dump setup path (splittingdump_init()and stopping the vCPUs). Reading vmcoreinfo directly is much smaller.Changes since v4:
- Refuse guest-RAM reads (dump-guest-memory, memsave, pmemsave) while a migration destination is still receiving RAM, via a sharedmigration_guest_ram_loading()helper.
- Decide win-dmp availability by reading vmcoreinfo directly instead of splitting dump_init()/dump_preinit() and stopping the vCPUs.
- Add dump-guest-memory qtests.Quoted 6 lines
Denis V. Lunev (7):
migration: addmigration_guest_ram_loading()helper
dump: refuse dump-guest-memory while guest RAM is being migrated system/cpus: refuse memsave/pmemsave while guest RAM is being migrated
dump: makewin_dump_available()check vmcoreinfo for a Windows dump
header
Quoted 6 lines
Looks all good to me, except it needs s/cpu_physical_memory_read/physical_memory_read now. I can do that on MR
Philippe, do you know why physical_memory_read/write() do not return MemTxResult?
Because these is the legacy API we want to remove; commit b7ecba0f6f6 recommends to use address_space_*() instead:
``address_space_*``
~~~~~~~~~~~~~~~~~~~
These functions are the primary ones to use when emulating CPU or device memory accesses.
[...]
``physical_memory_*``
~~~~~~~~~~~~~~~~~~~~~~~~~
These are convenience functions which are identical to ``address_space_*`` but operate specifically on the legacy global ``&address_space_memory`` address space (which might not be used by all machines), always pass a ``MEMTXATTRS_UNSPECIFIED`` set of memory attributes and ignore whether the memory transaction succeeded or failed. Expected users are hardware device models. For new code they are better avoided
[...]
Quoted 22 lines
Quoted 22 lines
tests/qtest: add dump-guest-memory test tests/qtest/dump: reject win-dmp without vmcoreinfo tests/qtest/dump: cover win-dmp availability via vmcoreinfo
MAINTAINERS | 1 + dump/dump.c | 5 +- dump/win_dump-x86.c | 42 +++++ include/migration/misc.h | 3 + migration/migration.c | 6 + system/cpus.c | 11 ++ tests/qtest/dump-test.c | 331 +++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 8 files changed, 398 insertions(+), 2 deletions(-)create mode 100644
tests/qtest/dump-test.cbase-commit:
c7cf7c810153d6f5f31aa2d5c0dee9087f6b4dff--
2.53.0
Quoted 71 lines · Denis V. Lunev
This series fixes Windows-dump (win-dmp) availability reporting and closes a related hole found while doing so: several commands read guest RAM and must not run while a migration destination is still receiving it.
dump-guest-memory, memsave and pmemsave all read guest RAM on the main thread with the BQL held. On a migration destination that RAM is either still being loaded (precopy) or pulled from the source on demand (postcopy, where the guest already runs). During precopy the read returns incomplete data; during postcopy it deadlocks, as the read faults on a not-yet-received page while the postcopy incoming path needs the BQL the reader holds to install it. dump-guest-memory only guarded the precopy phase and memsave/pmemsave had no guard at all, so a new
migration_guest_ram_loading()predicate captures both phases and all three commands now use it.query-dump-guest-memory-capability also advertised win-dmp for every x86 VM, and dump-guest-memory accepted it unconditionally; win-dmp only works when the guest has published a Windows dump header through vmcoreinfo.
win_dump_available()now reads that note back from the vmcoreinfo device and validates it, keeping its original signature, so thedump.ccall sites are unchanged.The series also adds the first qtest coverage for dump-guest-memory:
capability list, ELF and kdump output, protocol errors, and win-dmp reporting in both directions (the positive case forges a vmcoreinfo note, so no Windows guest is needed).Tested:
- Linux guest: win-dmp not advertised; an explicit win-dmp request is rejected without stopping the guest; elf/kdump dumps work.
- Windows Server 2022 guest: win-dmp advertised once vmcoreinfo is populated; dump-guest-memory format=win-dmp produces a valid (PAGEDU64) crashdump.
- Live postcopy migration: on the destination, dump-guest-memory, memsave and pmemsave are all refused immediately, without faulting a page.This supersedes the earlier "dump: enhance
win_dump_availableto report properly" series, which obtained the note by reusing the dump setup path (splittingdump_init()and stopping the vCPUs). Reading vmcoreinfo directly is much smaller.Changes since v4:
- Refuse guest-RAM reads (dump-guest-memory, memsave, pmemsave) while a migration destination is still receiving RAM, via a sharedmigration_guest_ram_loading()helper.
- Decide win-dmp availability by reading vmcoreinfo directly instead of splitting dump_init()/dump_preinit() and stopping the vCPUs.
- Add dump-guest-memory qtests.Denis V. Lunev (7):
migration: addmigration_guest_ram_loading()helper
dump: refuse dump-guest-memory while guest RAM is being migrated system/cpus: refuse memsave/pmemsave while guest RAM is being migrated
dump: makewin_dump_available()check vmcoreinfo for a Windows dump
header
tests/qtest: add dump-guest-memory test
tests/qtest/dump: reject win-dmp without vmcoreinfo tests/qtest/dump: cover win-dmp availability via vmcoreinfoMAINTAINERS | 1 + dump/dump.c | 5 +- dump/win_dump-x86.c | 42 +++++ include/migration/misc.h | 3 + migration/migration.c | 6 + system/cpus.c | 11 ++ tests/qtest/dump-test.c | 331 +++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 8 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/dump-test.c
Quoted 1 line
base-commit:
c7cf7c810153d6f5f31aa2d5c0dee9087f6b4dff
Hello, Marc-Andre!
Should I do something with this series or it is good to go in. Its final destiny is unclear for me at the moment.
Can you shed some light with it?
Thank you in advance,
Den
Hi
Quoted 73 lines · Denis V. Lunev
Quoted 71 lines · Denis V. Lunev
This series fixes Windows-dump (win-dmp) availability reporting and closes a related hole found while doing so: several commands read guest RAM and must not run while a migration destination is still receiving it.
dump-guest-memory, memsave and pmemsave all read guest RAM on the main thread with the BQL held. On a migration destination that RAM is either still being loaded (precopy) or pulled from the source on demand (postcopy, where the guest already runs). During precopy the read returns incomplete data; during postcopy it deadlocks, as the read faults on a not-yet-received page while the postcopy incoming path needs the BQL the reader holds to install it. dump-guest-memory only guarded the precopy phase and memsave/pmemsave had no guard at all, so a new
migration_guest_ram_loading()predicate captures both phases and all three commands now use it.query-dump-guest-memory-capability also advertised win-dmp for every x86 VM, and dump-guest-memory accepted it unconditionally; win-dmp only works when the guest has published a Windows dump header through vmcoreinfo.
win_dump_available()now reads that note back from the vmcoreinfo device and validates it, keeping its original signature, so thedump.ccall sites are unchanged.The series also adds the first qtest coverage for dump-guest-memory:
capability list, ELF and kdump output, protocol errors, and win-dmp reporting in both directions (the positive case forges a vmcoreinfo note, so no Windows guest is needed).Tested:
- Linux guest: win-dmp not advertised; an explicit win-dmp request is rejected without stopping the guest; elf/kdump dumps work.
- Windows Server 2022 guest: win-dmp advertised once vmcoreinfo is populated; dump-guest-memory format=win-dmp produces a valid (PAGEDU64) crashdump.
- Live postcopy migration: on the destination, dump-guest-memory, memsave and pmemsave are all refused immediately, without faulting a page.This supersedes the earlier "dump: enhance
win_dump_availableto report properly" series, which obtained the note by reusing the dump setup path (splittingdump_init()and stopping the vCPUs). Reading vmcoreinfo directly is much smaller.Changes since v4:
- Refuse guest-RAM reads (dump-guest-memory, memsave, pmemsave) while a migration destination is still receiving RAM, via a sharedmigration_guest_ram_loading()helper.
- Decide win-dmp availability by reading vmcoreinfo directly instead of splitting dump_init()/dump_preinit() and stopping the vCPUs.
- Add dump-guest-memory qtests.Denis V. Lunev (7):
migration: addmigration_guest_ram_loading()helper
dump: refuse dump-guest-memory while guest RAM is being migrated system/cpus: refuse memsave/pmemsave while guest RAM is being migrated
dump: makewin_dump_available()check vmcoreinfo for a Windows dump
header
tests/qtest: add dump-guest-memory test
tests/qtest/dump: reject win-dmp without vmcoreinfo tests/qtest/dump: cover win-dmp availability via vmcoreinfoMAINTAINERS | 1 + dump/dump.c | 5 +- dump/win_dump-x86.c | 42 +++++ include/migration/misc.h | 3 + migration/migration.c | 6 + system/cpus.c | 11 ++ tests/qtest/dump-test.c | 331 +++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 8 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/dump-test.c
Quoted 8 lines
Quoted 1 line
base-commit:
c7cf7c810153d6f5f31aa2d5c0dee9087f6b4dffHello, Marc-Andre!
Should I do something with this series or it is good to go in. Its final destiny is unclear for me at the moment.
Can you shed some light with it?
I'll prepare a PR. thanks