Skip to contentSkip to conversation

dump/win_dump: Build almost once

PATCH Superseded Philippe Mathieu-Daudé 2 participants 9 messages Jan 8 – Jan 21 Arm/Amlogic Meson SoC support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover dump/win_dump: Build almost once

v2:
- Rebase on Nikolai patches (included) to avoid rebase
- Add Kconfig symbol to only build for x86 targets

Nikolai Barybin (2):
dump: enhance dump_state_prepare fd initialization
dump: enhance win_dump_available to report properly

Philippe Mathieu-Daudé (2):
dump: Abort in create_win_dump() on non-x86 guests
dump: Build stubs once for non-x86 targets

 dump/win_dump.h                     |   2 +-
 dump/dump.c                         | 138 ++++++++++++++++------------
 dump/win_dump-stubs.c               |  21 +++++
 dump/{win_dump.c => win_dump-x86.c} |  37 ++++----
 Kconfig                             |   1 +
 dump/Kconfig                        |   4 +
 dump/meson.build                    |   3 +-
 7 files changed, 127 insertions(+), 79 deletions(-)
 create mode 100644 dump/win_dump-stubs.c
 rename dump/{win_dump.c => win_dump-x86.c} (95%)
 create mode 100644 dump/Kconfig
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 1/4 dump: enhance dump_state_prepare fd initialization

From: Nikolai Barybin <[email protected]>

Initializing descriptor with zero is unsafe: during cleanup we risk to unconditional close of fd == 0 in case dump state wasn't fully initialized. Thus, let's init fd with -1 value and check its value before closing it.

Message-ID: <[email protected]>

---
 dump/dump.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
dump/dump.c +6 -3
index f7a99a7af2e..016a7d7b970 100644
@@ -104,7 +104,10 @@ static int dump_cleanup(DumpState *s)
 
     guest_phys_blocks_free(&s->guest_phys_blocks);
     memory_mapping_list_free(&s->list);
-    close(s->fd);
+    if (s->fd != -1) {
+        close(s->fd);
+    }
+    s->fd = -1;
     g_free(s->guest_note);
     g_clear_pointer(&s->string_table_buf, g_array_unref);
     s->guest_note = NULL;
@@ -1709,8 +1712,8 @@ static DumpState dump_state_global = { .status = DUMP_STATUS_NONE };
 
 static void dump_state_prepare(DumpState *s)
 {
-    /* zero the struct, setting status to active */
-    *s = (DumpState) { .status = DUMP_STATUS_ACTIVE };
+    /* zero the struct, setting status to active and fd to -1 */
+    *s = (DumpState) { .fd = -1, .status = DUMP_STATUS_ACTIVE };
 }
 
 bool qemu_system_dump_in_progress(void)
Signature · 1 line
2.52.0
#2 lore raw

PATCH v2 2/4 dump: enhance win_dump_available to report properly

In reply to Philippe Mathieu-Daudé

From: Nikolai Barybin <[email protected]>

QMP query-dump-guest-memory-capability reports win dump as available for any x86 VM, which is false.

This patch implements proper query of vmcoreinfo and calculation of guest note size. Based on that we can surely report whether win dump available or not.

To perform this I suggest to split dump_init() into dump_preinit() and dump_init_complete() to avoid exausting copypaste in win_dump_available().

For further reference one may review this libvirt discussion:
https://lists.libvirt.org/archives/list/[email protected]/thread/HJ3JRLWLGN3IKIC22OQ3PMZ4J3EFG5XB/#HJ3JRLWLGN3IKIC22OQ3PMZ4J3EFG5XB
[PATCH 0/4] Allow xml-configured coredump format on VM crash

Message-ID: <[email protected]>

---
 dump/win_dump.h |   2 +-
 dump/dump.c     | 129 +++++++++++++++++++++++++++---------------------
 dump/win_dump.c |  23 +++++++--
 3 files changed, 95 insertions(+), 59 deletions(-)
dump/win_dump.h +1 -1
index 9d6cfa47c56..62e19c25273 100644
@@ -14,7 +14,7 @@
 #include "system/dump.h"
 
 /* Check Windows dump availability for the current target */
-bool win_dump_available(Error **errp);
+bool win_dump_available(DumpState *s, Error **errp);
 
 void create_win_dump(DumpState *s, Error **errp);
 
dump/dump.c +74 -55

190 lines not on this page · raw message

dump/win_dump.c +20 -3
index 3162e8bd487..d42427feb22 100644
@@ -20,8 +20,25 @@
 
 #if defined(TARGET_X86_64)
 
-bool win_dump_available(Error **errp)
+static bool check_header(WinDumpHeader *h, bool *x64, Error **errp);
+
+bool win_dump_available(DumpState *s, Error **errp)
 {
+    WinDumpHeader *h = (void *)(s->guest_note + VMCOREINFO_ELF_NOTE_HDR_SIZE);
+    Error *local_err = NULL;
+    bool x64 = true;
+
+    if (s->guest_note_size != VMCOREINFO_WIN_DUMP_NOTE_SIZE32 &&
+            s->guest_note_size != VMCOREINFO_WIN_DUMP_NOTE_SIZE64) {
+        error_setg(errp, "win-dump: invalid vmcoreinfo note size");
+        return false;
+    }
+
+    if (!check_header(h, &x64, &local_err)) {
+        error_propagate(errp, local_err);
+        return false;
+    }
+
     return true;
 }
 
@@ -480,7 +497,7 @@ out_cr3:
 
 #else /* !TARGET_X86_64 */
 
-bool win_dump_available(Error **errp)
+bool win_dump_available(DumpState *s, Error **errp)
 {
     error_setg(errp, "Windows dump is only available for x86-64");
 
@@ -489,7 +506,7 @@ bool win_dump_available(Error **errp)
 
 void create_win_dump(DumpState *s, Error **errp)
 {
-    win_dump_available(errp);
+    win_dump_available(s, errp);
 }
 
 #endif
Signature · 1 line
2.52.0
#3 lore raw

Re: [PATCH v2 2/4] dump: enhance win_dump_available to report properly

Hi Nikolai,

Quoted 5 lines · Philippe Mathieu-Daudé

From: Nikolai Barybin <[email protected]>

QMP query-dump-guest-memory-capability reports win dump as available for any x86 VM, which is false.

Quoted 7 lines

This patch implements proper query of vmcoreinfo and calculation of guest note size. Based on that we can surely report whether win dump available or not.

To perform this I suggest to split dump_init() into dump_preinit() and dump_init_complete() to avoid exausting copypaste in win_dump_available().

This patch breaks CI (failure running tests/qtest/qmp-cmd-test.c).

Before:

{ "execute": "query-dump-guest-memory-capability" } {"return": {"formats": ["elf", "kdump-zlib", "kdump-raw-zlib"]}}

After:

{ "execute": "query-dump-guest-memory-capability" }
{"error": {"class": "GenericError", "desc": "dumping guest memory is not supported on this target"}}

CI output:

ERROR:../../tests/qtest/qmp-cmd-test.c:85:test_query: assertion failed: (qdict_haskey(resp, "return")) Bail out! ERROR:../../tests/qtest/qmp-cmd-test.c:85:test_query: assertion failed: (qdict_haskey(resp, "return")) Aborted (core dumped)

I'm dropping the entire series.

Quoted 280 lines

For further reference one may review this libvirt discussion:
https://lists.libvirt.org/archives/list/[email protected]/thread/HJ3JRLWLGN3IKIC22OQ3PMZ4J3EFG5XB/#HJ3JRLWLGN3IKIC22OQ3PMZ4J3EFG5XB
[PATCH 0/4] Allow xml-configured coredump format on VM crash

Message-ID: <[email protected]>

---
  dump/win_dump.h |   2 +-
  dump/dump.c     | 129 +++++++++++++++++++++++++++---------------------
  dump/win_dump.c |  23 +++++++--
  3 files changed, 95 insertions(+), 59 deletions(-)
dump/win_dump.h +1 -1
index 9d6cfa47c56..62e19c25273 100644
@@ -14,7 +14,7 @@
  #include "system/dump.h"
 
  /* Check Windows dump availability for the current target */
-bool win_dump_available(Error **errp);
+bool win_dump_available(DumpState *s, Error **errp);
 
  void create_win_dump(DumpState *s, Error **errp);
 
dump/dump.c +74 -55
index 016a7d7b970..89ce9bcd77e 100644
@@ -1781,10 +1781,7 @@ static void vmcoreinfo_update_phys_base(DumpState *s)
      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, bool kdump_raw,
-                      Error **errp)
+static void dump_preinit(DumpState *s, Error **errp)
  {
      ERRP_GUARD();
      VMCoreInfoState *vmci = vmcoreinfo_find();
@@ -1792,16 +1789,6 @@ static void dump_init(DumpState *s, int fd, bool has_format,
      int nr_cpus;
      int ret;
 
-    s->has_format = has_format;
-    s->format = format;
-    s->written_size = 0;
-    s->kdump_raw = kdump_raw;
-
-    /* kdump-compressed is conflict with paging and filter */
-    if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
-        assert(!paging && !has_filter);
-    }
-
      if (runstate_is_running()) {
          vm_stop(RUN_STATE_SAVE_VM);
          s->resume = true;
@@ -1818,41 +1805,10 @@ static void dump_init(DumpState *s, int fd, bool has_format,
          nr_cpus++;
      }
 
-    s->fd = fd;
-    if (has_filter && !length) {
-        error_setg(errp, "parameter 'length' expects a non-zero size");
-        goto cleanup;
-    }
-    s->filter_area_begin = begin;
-    s->filter_area_length = length;
-
-    /* First index is 0, it's the special null name */
-    s->string_table_buf = g_array_new(FALSE, TRUE, 1);
-    /*
-     * Allocate the null name, due to the clearing option set to true
-     * it will be 0.
-     */
-    g_array_set_size(s->string_table_buf, 1);
-
      memory_mapping_list_init(&s->list);
-
      guest_phys_blocks_init(&s->guest_phys_blocks);
      guest_phys_blocks_append(&s->guest_phys_blocks);
-    s->total_size = dump_calculate_size(s);
-#ifdef DEBUG_DUMP_GUEST_MEMORY
-    fprintf(stderr, "DUMP: total memory to dump: %lu\n", s->total_size);
-#endif
 
-    /* it does not make sense to dump non-existent memory */
-    if (!s->total_size) {
-        error_setg(errp, "dump: no guest memory to dump");
-        goto cleanup;
-    }
-
-    /* get dump info: endian, class and architecture.
-     * If the target architecture is not supported, cpu_get_dump_info() will
-     * return -1.
-     */
      ret = cpu_get_dump_info(&s->dump_info, &s->guest_phys_blocks);
      if (ret < 0) {
          error_setg(errp,
@@ -1910,6 +1866,56 @@ static void dump_init(DumpState *s, int fd, bool has_format,
          }
      }
 
+    s->nr_cpus = nr_cpus;
+    return;
+cleanup:
+    dump_cleanup(s);
+}
+
+static void dump_init_complete(DumpState *s, int fd, bool has_format,
+                               DumpGuestMemoryFormat format, bool paging,
+                               bool has_filter, int64_t begin, int64_t length,
+                               bool kdump_raw, Error **errp)
+{
+    ERRP_GUARD();
+
+    s->has_format = has_format;
+    s->format = format;
+    s->written_size = 0;
+    s->kdump_raw = kdump_raw;
+
+    /* kdump-compressed is conflict with paging and filter */
+    if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
+        assert(!paging && !has_filter);
+    }
+
+    s->fd = fd;
+    if (has_filter && !length) {
+        error_setg(errp, "parameter 'length' expects a non-zero size");
+        goto cleanup;
+    }
+    s->filter_area_begin = begin;
+    s->filter_area_length = length;
+
+    /* First index is 0, it's the special null name */
+    s->string_table_buf = g_array_new(FALSE, TRUE, 1);
+    /*
+     * Allocate the null name, due to the clearing option set to true
+     * it will be 0.
+     */
+    g_array_set_size(s->string_table_buf, 1);
+
+    s->total_size = dump_calculate_size(s);
+#ifdef DEBUG_DUMP_GUEST_MEMORY
+    fprintf(stderr, "DUMP: total memory to dump: %lu\n", s->total_size);
+#endif
+
+    /* it does not make sense to dump non-existent memory */
+    if (!s->total_size) {
+        error_setg(errp, "dump: no guest memory to dump");
+        goto cleanup;
+    }
+
      /* get memory mapping */
      if (paging) {
          qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, errp);
@@ -1920,8 +1926,6 @@ static void dump_init(DumpState *s, int fd, bool has_format,
          qemu_get_guest_simple_memory_mapping(&s->list, &s->guest_phys_blocks);
      }
 
-    s->nr_cpus = nr_cpus;
-
      get_max_mapnr(s);
 
      uint64_t tmp;
@@ -2151,11 +2155,6 @@ void qmp_dump_guest_memory(bool paging, const char *protocol,
      }
  #endif
 
-    if (has_format && format == DUMP_GUEST_MEMORY_FORMAT_WIN_DMP
-        && !win_dump_available(errp)) {
-        return;
-    }
-
      if (strstart(protocol, "fd:", &p)) {
          fd = monitor_get_fd(monitor_cur(), p, errp);
          if (fd == -1) {
@@ -2194,9 +2193,19 @@ void qmp_dump_guest_memory(bool paging, const char *protocol,
 
      s = &dump_state_global;
      dump_state_prepare(s);
+    dump_preinit(s, errp);
+    if (*errp) {
+        qatomic_set(&s->status, DUMP_STATUS_FAILED);
+        return;
+    }
 
-    dump_init(s, fd, has_format, format, paging, has_begin,
-              begin, length, kdump_raw, errp);
+    if (has_format && format == DUMP_GUEST_MEMORY_FORMAT_WIN_DMP
+        && !win_dump_available(s, errp)) {
+        return;
+    }
+
+    dump_init_complete(s, fd, has_format, format, paging, has_begin,
+                       begin, length, kdump_raw, errp);
      if (*errp) {
          qatomic_set(&s->status, DUMP_STATUS_FAILED);
          return;
@@ -2219,6 +2228,13 @@ DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
                                    g_new0(DumpGuestMemoryCapability, 1);
      DumpGuestMemoryFormatList **tail = &cap->formats;
 
+    DumpState *s = g_new0(DumpState, 1);
+    dump_state_prepare(s);
+    dump_preinit(s, errp);
+    if (*errp) {
+        goto cleanup;
+    }
+
      /* elf is always available */
      QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_ELF);
 
@@ -2238,9 +2254,12 @@ DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
      QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_KDUMP_RAW_SNAPPY);
  #endif
 
-    if (win_dump_available(NULL)) {
+    if (win_dump_available(s, NULL)) {
          QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_WIN_DMP);
      }
 
+ cleanup:
+    dump_cleanup(s);
+    g_free(s);
      return cap;
  }
dump/win_dump.c +20 -3
index 3162e8bd487..d42427feb22 100644
@@ -20,8 +20,25 @@
 
  #if defined(TARGET_X86_64)
 
-bool win_dump_available(Error **errp)
+static bool check_header(WinDumpHeader *h, bool *x64, Error **errp);
+
+bool win_dump_available(DumpState *s, Error **errp)
  {
+    WinDumpHeader *h = (void *)(s->guest_note + VMCOREINFO_ELF_NOTE_HDR_SIZE);
+    Error *local_err = NULL;
+    bool x64 = true;
+
+    if (s->guest_note_size != VMCOREINFO_WIN_DUMP_NOTE_SIZE32 &&
+            s->guest_note_size != VMCOREINFO_WIN_DUMP_NOTE_SIZE64) {
+        error_setg(errp, "win-dump: invalid vmcoreinfo note size");
+        return false;
+    }
+
+    if (!check_header(h, &x64, &local_err)) {
+        error_propagate(errp, local_err);
+        return false;
+    }
+
      return true;
  }
 
@@ -480,7 +497,7 @@ out_cr3:
 
  #else /* !TARGET_X86_64 */
 
-bool win_dump_available(Error **errp)
+bool win_dump_available(DumpState *s, Error **errp)
  {
      error_setg(errp, "Windows dump is only available for x86-64");
 
@@ -489,7 +506,7 @@ bool win_dump_available(Error **errp)
 
  void create_win_dump(DumpState *s, Error **errp)
  {
-    win_dump_available(errp);
+    win_dump_available(s, errp);
  }
 
  #endif
#4 lore raw

PATCH v2 3/4 dump: Abort in create_win_dump() on non-x86 guests

In reply to Philippe Mathieu-Daudé

qmp_dump_guest_memory() checks win_dump_available() before calling create_win_dump(). On non-x86 targets calling it would be a programming error, so abort.

---
 dump/win_dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
dump/win_dump.c +1 -1
index d42427feb22..e5fdc12ad34 100644
@@ -506,7 +506,7 @@ bool win_dump_available(DumpState *s, Error **errp)
 
 void create_win_dump(DumpState *s, Error **errp)
 {
-    win_dump_available(s, errp);
+    g_assert_not_reached();
 }
 
 #endif
Signature · 1 line
2.52.0
#5 lore raw

PATCH v2 4/4 dump: Build stubs once for non-x86 targets

In reply to Philippe Mathieu-Daudé

Rather than compiling the same content for all targets (unused most of the time, i.e. qemu-system-avr ...), extract the non x86 specific parts to a stub file and build it once for all non-x86 targets.
Add a Kconfig symbol to only select the target-specific file with the x86 target (rename this file with '-x86' suffix).

---
 dump/win_dump-stubs.c               | 21 +++++++++++++++++++++
 dump/{win_dump.c => win_dump-x86.c} | 20 +-------------------
 Kconfig                             |  1 +
 dump/Kconfig                        |  4 ++++
 dump/meson.build                    |  3 ++-
 5 files changed, 29 insertions(+), 20 deletions(-)
 create mode 100644 dump/win_dump-stubs.c
 rename dump/{win_dump.c => win_dump-x86.c} (97%)
 create mode 100644 dump/Kconfig
dump/win_dump-stubs.c new file +21 -0
new file mode 100644
index 00000000000..07d1a0c5ea9
@@ -0,0 +1,21 @@
+/*
+ * Windows crashdump stubs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "win_dump.h"
+
+bool win_dump_available(DumpState *s, Error **errp)
+{
+    error_setg(errp, "x86-64 Windows guest dump not built-in");
+
+    return false;
+}
+
+void create_win_dump(DumpState *s, Error **errp)
+{
+    g_assert_not_reached();
+}
dump/win_dump-x86.c renamed from dump/win_dump.c +1 -19
similarity index 97%
rename from dump/win_dump.c
rename to dump/win_dump-x86.c
index e5fdc12ad34..4f8bcc356fc 100644
@@ -1,5 +1,5 @@
 /*
- * Windows crashdump (target specific implementations)
+ * Windows crashdump (x86 specific implementations)
  *
  * Copyright (c) 2018 Virtuozzo International GmbH
  *
@@ -18,8 +18,6 @@
 #include "win_dump.h"
 #include "cpu.h"
 
-#if defined(TARGET_X86_64)
-
 static bool check_header(WinDumpHeader *h, bool *x64, Error **errp);
 
 bool win_dump_available(DumpState *s, Error **errp)
@@ -494,19 +492,3 @@ out_free:
 out_cr3:
     first_x86_cpu->env.cr[3] = saved_cr3;
 }
-
-#else /* !TARGET_X86_64 */
-
-bool win_dump_available(DumpState *s, Error **errp)
-{
-    error_setg(errp, "Windows dump is only available for x86-64");
-
-    return false;
-}
-
-void create_win_dump(DumpState *s, Error **errp)
-{
-    g_assert_not_reached();
-}
-
-#endif
Kconfig +1 -0
index 63ca7f46df7..26388c12838 100644
@@ -1,6 +1,7 @@
 source Kconfig.host
 source backends/Kconfig
 source accel/Kconfig
+source dump/Kconfig
 source target/Kconfig
 source hw/Kconfig
 source semihosting/Kconfig
dump/Kconfig new file +4 -0
new file mode 100644
index 00000000000..99f99ff4a4f
@@ -0,0 +1,4 @@
+config WINDUMP
+    bool
+    default y if I386
+    depends on I386
dump/meson.build +2 -1
index 4277ce9328a..26e1561ed48 100644
@@ -1,2 +1,3 @@
 system_ss.add([files('dump.c', 'dump-hmp-cmds.c'), snappy, lzo])
-specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: files('win_dump.c'))
+specific_ss.add(when: 'CONFIG_WINDUMP', if_true: files('win_dump-x86.c'))
+system_ss.add(when: 'CONFIG_WINDUMP', if_false: files('win_dump-stubs.c'))
Signature · 1 line
2.52.0
Reviewed-by on v2 4/4
#6 lore raw

Re: [PATCH v2 4/4] dump: Build stubs once for non-x86 targets

Hi

Quoted 117 lines · Philippe Mathieu-Daudé

Rather than compiling the same content for all targets (unused most of the time, i.e. qemu-system-avr ...), extract the non x86 specific parts to a stub file and build it once for all non-x86 targets.
Add a Kconfig symbol to only select the target-specific file with the x86 target (rename this file with '-x86' suffix).

---
 dump/win_dump-stubs.c               | 21 +++++++++++++++++++++
 dump/{win_dump.c => win_dump-x86.c} | 20 +-------------------
 Kconfig                             |  1 +
 dump/Kconfig                        |  4 ++++
 dump/meson.build                    |  3 ++-
 5 files changed, 29 insertions(+), 20 deletions(-)
 create mode 100644 dump/win_dump-stubs.c
 rename dump/{win_dump.c => win_dump-x86.c} (97%)
 create mode 100644 dump/Kconfig
dump/win_dump-stubs.c new file +21 -0
new file mode 100644
index 00000000000..07d1a0c5ea9
@@ -0,0 +1,21 @@
+/*
+ * Windows crashdump stubs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "win_dump.h"
+
+bool win_dump_available(DumpState *s, Error **errp)
+{
+    error_setg(errp, "x86-64 Windows guest dump not built-in");
+
+    return false;
+}
+
+void create_win_dump(DumpState *s, Error **errp)
+{
+    g_assert_not_reached();
+}
dump/win_dump-x86.c renamed from dump/win_dump.c +1 -19
similarity index 97%
rename from dump/win_dump.c
rename to dump/win_dump-x86.c
index e5fdc12ad34..4f8bcc356fc 100644
@@ -1,5 +1,5 @@
 /*
- * Windows crashdump (target specific implementations)
+ * Windows crashdump (x86 specific implementations)
  *
  * Copyright (c) 2018 Virtuozzo International GmbH
  *
@@ -18,8 +18,6 @@
 #include "win_dump.h"
 #include "cpu.h"
 
-#if defined(TARGET_X86_64)
-
 static bool check_header(WinDumpHeader *h, bool *x64, Error **errp);
 
 bool win_dump_available(DumpState *s, Error **errp)
@@ -494,19 +492,3 @@ out_free:
 out_cr3:
     first_x86_cpu->env.cr[3] = saved_cr3;
 }
-
-#else /* !TARGET_X86_64 */
-
-bool win_dump_available(DumpState *s, Error **errp)
-{
-    error_setg(errp, "Windows dump is only available for x86-64");
-
-    return false;
-}
-
-void create_win_dump(DumpState *s, Error **errp)
-{
-    g_assert_not_reached();
-}
-
-#endif
Kconfig +1 -0
index 63ca7f46df7..26388c12838 100644
@@ -1,6 +1,7 @@
 source Kconfig.host
 source backends/Kconfig
 source accel/Kconfig
+source dump/Kconfig
 source target/Kconfig
 source hw/Kconfig
 source semihosting/Kconfig
dump/Kconfig new file +4 -0
new file mode 100644
index 00000000000..99f99ff4a4f
@@ -0,0 +1,4 @@
+config WINDUMP
+    bool
+    default y if I386
+    depends on I386
dump/meson.build +0 -0
index 4277ce9328a..26e1561ed48 100644

dump/meson.build line 2

Quoted 3 lines
dump/meson.build +1 -1
@@ -1,2 +1,3 @@
 system_ss.add([files('dump.c', 'dump-hmp-cmds.c'), snappy, lzo])
-specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: files('win_dump.c'))
+specific_ss.add(when: 'CONFIG_WINDUMP', if_true: files('win_dump-x86.c'))

I thought this could end up in qemu-user, but apparently I was wrong..

Quoted 5 lines
dump/meson.build +1 -1
+system_ss.add(when: 'CONFIG_WINDUMP', if_false: files('win_dump-stubs.c'))
--

2.52.0

#7 lore raw

Re: [PATCH v2 4/4] dump: Build stubs once for non-x86 targets

Quoted 128 lines · Marc-André Lureau

Hi

On Thu, Jan 8, 2026 at 8:12 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

    Rather than compiling the same content for all targets (unused
    most of the time, i.e. qemu-system-avr ...), extract the non
    x86 specific parts to a stub file and build it once for all
    non-x86 targets.
    Add a Kconfig symbol to only select the target-specific file
    with the x86 target (rename this file with '-x86' suffix).

    Signed-off-by: Philippe Mathieu-Daudé <[email protected]
    <mailto:[email protected]>>
    ---
      dump/win_dump-stubs.c               | 21 +++++++++++++++++++++
      dump/{win_dump.c => win_dump-x86.c} | 20 +-------------------
      Kconfig                             |  1 +
      dump/Kconfig                        |  4 ++++
      dump/meson.build                    |  3 ++-
      5 files changed, 29 insertions(+), 20 deletions(-)
      create mode 100644 dump/win_dump-stubs.c
      rename dump/{win_dump.c => win_dump-x86.c} (97%)
      create mode 100644 dump/Kconfig

    diff --git a/dump/win_dump-stubs.c b/dump/win_dump-stubs.c
    new file mode 100644
    index 00000000000..07d1a0c5ea9
    --- /dev/null
    +++ b/dump/win_dump-stubs.c
    @@ -0,0 +1,21 @@
    +/*
    + * Windows crashdump stubs
    + *
    + * SPDX-License-Identifier: GPL-2.0-or-later
    + */
    +
    +#include "qemu/osdep.h"
    +#include "qapi/error.h"
    +#include "win_dump.h"
    +
    +bool win_dump_available(DumpState *s, Error **errp)
    +{
    +    error_setg(errp, "x86-64 Windows guest dump not built-in");
    +
    +    return false;
    +}
    +
    +void create_win_dump(DumpState *s, Error **errp)
    +{
    +    g_assert_not_reached();
    +}
    diff --git a/dump/win_dump.c b/dump/win_dump-x86.c
    similarity index 97%
    rename from dump/win_dump.c
    rename to dump/win_dump-x86.c
    index e5fdc12ad34..4f8bcc356fc 100644
    --- a/dump/win_dump.c
    +++ b/dump/win_dump-x86.c
    @@ -1,5 +1,5 @@
      /*
    - * Windows crashdump (target specific implementations)
    + * Windows crashdump (x86 specific implementations)
       *
       * Copyright (c) 2018 Virtuozzo International GmbH
       *
    @@ -18,8 +18,6 @@
      #include "win_dump.h"
      #include "cpu.h"

    -#if defined(TARGET_X86_64)
    -
      static bool check_header(WinDumpHeader *h, bool *x64, Error **errp);

      bool win_dump_available(DumpState *s, Error **errp)
    @@ -494,19 +492,3 @@ out_free:
      out_cr3:
          first_x86_cpu->env.cr <http://env.cr>[3] = saved_cr3;
      }
    -
    -#else /* !TARGET_X86_64 */
    -
    -bool win_dump_available(DumpState *s, Error **errp)
    -{
    -    error_setg(errp, "Windows dump is only available for x86-64");
    -
    -    return false;
    -}
    -
    -void create_win_dump(DumpState *s, Error **errp)
    -{
    -    g_assert_not_reached();
    -}
    -
    -#endif
    diff --git a/Kconfig b/Kconfig
    index 63ca7f46df7..26388c12838 100644
    --- a/Kconfig
    +++ b/Kconfig
    @@ -1,6 +1,7 @@
      source Kconfig.host
      source backends/Kconfig
      source accel/Kconfig
    +source dump/Kconfig
      source target/Kconfig
      source hw/Kconfig
      source semihosting/Kconfig
    diff --git a/dump/Kconfig b/dump/Kconfig
    new file mode 100644
    index 00000000000..99f99ff4a4f
    --- /dev/null
    +++ b/dump/Kconfig
    @@ -0,0 +1,4 @@
    +config WINDUMP
    +    bool
    +    default y if I386
    +    depends on I386
    diff --git a/dump/meson.build b/dump/meson.build
    index 4277ce9328a..26e1561ed48 100644
    --- a/dump/meson.build
    +++ b/dump/meson.build
    @@ -1,2 +1,3 @@
      system_ss.add([files('dump.c', 'dump-hmp-cmds.c'), snappy, lzo])
    -specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true:
    files('win_dump.c'))
    +specific_ss.add(when: 'CONFIG_WINDUMP', if_true: files('win_dump-
    x86.c'))
Quoted 1 line

I thought this could end up in qemu-user, but apparently I was wrong..

I was myself surprised too. I think this is somehow by luck, because IIUC Kconfig symbols aren't evaluated for user emulation (IOW the file isn't added because CONFIG_WINDUMP is unset on USER).

Quoted 2 lines
Reviewed-by Marc-André Lureau <[email protected] <mailto:[email protected]>>

Thanks!

Quoted 6 lines
    +system_ss.add(when: 'CONFIG_WINDUMP', if_false: files('win_dump-
    stubs.c'))
    -- 
    2.52.0
#8 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Nikolai Barybin (2):
dump: enhance dump_state_prepare fd initialization
dump: enhance win_dump_available to report properly

Philippe Mathieu-Daudé (2):
dump: Abort in create_win_dump() on non-x86 guests
dump: Build stubs once for non-x86 targets

Series queued, thanks.