All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Subject: [GIT PULL 7/8] tests/qtest/dump: cover win-dmp availability via vmcoreinfo
Date: Tue, 30 Jun 2026 19:13:22 +0400	[thread overview]
Message-ID: <20260630-dump-v1-7-7df3087dffc9@redhat.com> (raw)
In-Reply-To: <20260630-dump-v1-0-7df3087dffc9@redhat.com>

From: "Denis V. Lunev" <den@openvz.org>

win-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.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20260619101834.228432-8-den@openvz.org>
---
 tests/qtest/dump-test.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/tests/qtest/dump-test.c b/tests/qtest/dump-test.c
index 6afaa2c2ea4..30c95a35285 100644
--- a/tests/qtest/dump-test.c
+++ b/tests/qtest/dump-test.c
@@ -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();

-- 
2.54.0



  parent reply	other threads:[~2026-06-30 15:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 15:13 [GIT PULL 0/8] Dump patches for 2026-06-30 Marc-André Lureau
2026-06-30 15:13 ` [GIT PULL 1/8] migration: add migration_guest_ram_loading() helper Marc-André Lureau
2026-06-30 15:13 ` [GIT PULL 2/8] dump: refuse dump-guest-memory while guest RAM is being migrated Marc-André Lureau
2026-06-30 15:13 ` [GIT PULL 3/8] system/cpus: refuse memsave/pmemsave " Marc-André Lureau
2026-06-30 15:13 ` [GIT PULL 4/8] dump: make win_dump_available() check vmcoreinfo for a Windows dump header Marc-André Lureau
2026-06-30 15:13 ` [GIT PULL 5/8] tests/qtest: add dump-guest-memory test Marc-André Lureau
2026-06-30 15:13 ` [GIT PULL 6/8] tests/qtest/dump: reject win-dmp without vmcoreinfo Marc-André Lureau
2026-06-30 15:13 ` Marc-André Lureau [this message]
2026-06-30 15:13 ` [GIT PULL 8/8] dump: fix misleading VMCOREINFO phys_base parse error Marc-André Lureau
2026-07-02 18:49 ` [GIT PULL 0/8] Dump patches for 2026-06-30 Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260630-dump-v1-7-7df3087dffc9@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.