@samitouri / QOSamiQemu / commits / 1c0e259c5a

dump: make win_dump_available() check vmcoreinfo for a Windows dump header

QMP 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. Signed-off-by: Denis V. Lunev <den@openvz.org> [ MA - changed physical_memory_read() call ] Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20260619101834.228432-5-den@openvz.org>

Denis V. Lunev committed Jun 19, 2026 at 12:18 UTC 1c0e259c5a356ce28fc014c7897df643c1ec91e0
1 file changed +44 -5
dump/win_dump-x86.c
+44 -5
@@ -18,11 +18,10 @@
18 #include "qemu/win_dump_defs.h"
19 #include "win_dump.h"
20 #include "cpu.h"
21 -
22 -bool win_dump_available(Error **errp)
23 -{
24 - return true;
25 -}
21 +#include "qemu/bswap.h"
22 +#include "hw/misc/vmcoreinfo.h"
23 +#include "migration/misc.h"
24 +#include "standard-headers/linux/qemu_fw_cfg.h"
25
26 static size_t win_dump_ptr_size(bool x64)
27 {
@@ -404,6 +403,46 @@ static void restore_context(WinDumpHeader *h, bool x64,
403 }
404 }
405
406 +bool win_dump_available(Error **errp)
407 +{
408 + VMCoreInfoState *vmci = vmcoreinfo_find();
409 + g_autofree uint8_t *note = NULL;
410 + Error *local_err = NULL;
411 + WinDumpHeader *h;
412 + uint32_t size;
413 + bool x64 = true;
414 +
415 + if (migration_guest_ram_loading()) {
416 + error_setg(errp, "win-dump: not available during migration");
417 + return false;
418 + }
419 +
420 + if (!vmci || !vmci->has_vmcoreinfo ||
421 + le16_to_cpu(vmci->vmcoreinfo.guest_format) !=
422 + FW_CFG_VMCOREINFO_FORMAT_ELF) {
423 + error_setg(errp, "win-dump: no vmcoreinfo note from the guest");
424 + return false;
425 + }
426 +
427 + size = le32_to_cpu(vmci->vmcoreinfo.size);
428 + if (size != VMCOREINFO_WIN_DUMP_NOTE_SIZE32 &&
429 + size != VMCOREINFO_WIN_DUMP_NOTE_SIZE64) {
430 + error_setg(errp, "win-dump: invalid vmcoreinfo note size");
431 + return false;
432 + }
433 +
434 + note = g_malloc(size);
435 + physical_memory_read(le64_to_cpu(vmci->vmcoreinfo.paddr), note, size);
436 +
437 + h = (void *)(note + VMCOREINFO_ELF_NOTE_HDR_SIZE);
438 + if (!check_header(h, &x64, &local_err)) {
439 + error_propagate(errp, local_err);
440 + return false;
441 + }
442 +
443 + return true;
444 +}
445 +
446 void create_win_dump(DumpState *s, Error **errp)
447 {
448 WinDumpHeader *h = (void *)(s->guest_note + VMCOREINFO_ELF_NOTE_HDR_SIZE);