[PATCH 0/2] qemu: Provide sane default for dump_guest_core

*** BLURB HERE *** Michal Prívozník (2): qemu.conf.in: Fix dumpCore capitalization qemu: Provide sane default for dump_guest_core meson.build | 1 + src/qemu/qemu.conf.in | 4 ++-- src/qemu/qemu_conf.c | 11 +++++++++++ tests/testutilsqemu.c | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) -- 2.44.2

In qemu.conf.in we give examples of enabling/disabling core dumps in domain XML. But the attribute is spelled wrong. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu.conf.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 6bc2140dcb..e1f3046177 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -692,7 +692,7 @@ # guest RAM, if the 'dump_guest_core' setting has been enabled, # or if the guest XML contains # -# <memory dumpcore="on">...guest ram...</memory> +# <memory dumpCore="on">...guest ram...</memory> # # If guest RAM is to be included, ensure the max_core limit # is set to at least the size of the largest expected guest @@ -714,7 +714,7 @@ # be included in QEMU core dumps. # # This setting will be ignored if the guest XML has set the -# dumpcore attribute on the <memory> element. +# dumpCore attribute on the <memory> element. # #dump_guest_core = 1 -- 2.44.2

QEMU uses Linux extensions to madvise() to include/exclue guest memory from core dump. These are obviously not available everywhere. Currently, users have two options: 1) configure <memory dumpCore=''/> in domain XML, or 2) configure dump_guest_core in qemu.conf While these work, they may harm user experience as "things just don't work" out of the box. Provide sane default in virQEMUDriverConfigNew() so neither of two options is required. To have predictable results in tests, explicitly set cfg->dumpGuestCore to false in qemuTestDriverInit() (which creates cfg object for tests). Resolves: https://gitlab.com/libvirt/libvirt/-/issues/679 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- meson.build | 1 + src/qemu/qemu_conf.c | 11 +++++++++++ tests/testutilsqemu.c | 2 ++ 3 files changed, 14 insertions(+) diff --git a/meson.build b/meson.build index 4c6e5a088e..aa6b8ce5aa 100644 --- a/meson.build +++ b/meson.build @@ -676,6 +676,7 @@ headers = [ 'sched.h', 'sys/auxv.h', 'sys/ioctl.h', + 'sys/mman.h', 'sys/mount.h', 'sys/syscall.h', 'sys/ucred.h', diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index b36bede6c3..2c4e6a74cb 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -26,6 +26,10 @@ #include <unistd.h> #include <fcntl.h> +#ifdef WITH_SYS_MMAN_H +# include <sys/mman.h> +#endif + #include "virerror.h" #include "qemu_conf.h" #include "qemu_capabilities.h" @@ -287,6 +291,13 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, cfg->deprecationBehavior = g_strdup("none"); cfg->storageUseNbdkit = USE_NBDKIT_DEFAULT; +#ifndef MADV_DONTDUMP + /* QEMU uses Linux extensions to madvise() (MADV_DODUMP/MADV_DONTDUMP) to + * include/exclude guest memory from core dump. These might be unavailable + * on some systems. Provide sane default. */ + cfg->dumpGuestCore = true; +#endif + return g_steal_pointer(&cfg); } diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index ee6cae218a..4daee432e5 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -407,6 +407,8 @@ int qemuTestDriverInit(virQEMUDriver *driver) cfg->hugetlbfs[0].deflt = true; cfg->hugetlbfs[1].size = 1048576; + cfg->dumpGuestCore = false; + driver->privileged = true; return 0; -- 2.44.2

On Thu, Sep 19, 2024 at 09:04:11AM +0200, Michal Privoznik wrote:
QEMU uses Linux extensions to madvise() to include/exclue guest
s/exclue/exclude/
memory from core dump. These are obviously not available everywhere. Currently, users have two options:
1) configure <memory dumpCore=''/> in domain XML, or 2) configure dump_guest_core in qemu.conf
While these work, they may harm user experience as "things just don't work" out of the box. Provide sane default in virQEMUDriverConfigNew() so neither of two options is required.
To have predictable results in tests, explicitly set cfg->dumpGuestCore to false in qemuTestDriverInit() (which creates cfg object for tests).
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/679
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- meson.build | 1 + src/qemu/qemu_conf.c | 11 +++++++++++ tests/testutilsqemu.c | 2 ++ 3 files changed, 14 insertions(+)
diff --git a/meson.build b/meson.build index 4c6e5a088e..aa6b8ce5aa 100644 --- a/meson.build +++ b/meson.build @@ -676,6 +676,7 @@ headers = [ 'sched.h', 'sys/auxv.h', 'sys/ioctl.h', + 'sys/mman.h', 'sys/mount.h', 'sys/syscall.h', 'sys/ucred.h', diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index b36bede6c3..2c4e6a74cb 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -26,6 +26,10 @@ #include <unistd.h> #include <fcntl.h>
+#ifdef WITH_SYS_MMAN_H +# include <sys/mman.h> +#endif + #include "virerror.h" #include "qemu_conf.h" #include "qemu_capabilities.h" @@ -287,6 +291,13 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, cfg->deprecationBehavior = g_strdup("none"); cfg->storageUseNbdkit = USE_NBDKIT_DEFAULT;
+#ifndef MADV_DONTDUMP + /* QEMU uses Linux extensions to madvise() (MADV_DODUMP/MADV_DONTDUMP) to + * include/exclude guest memory from core dump. These might be unavailable + * on some systems. Provide sane default. */ + cfg->dumpGuestCore = true; +#endif +
I'd like a VIR_INFO or something here to see that we're not able to exclude that from the dump, just in case someone is trying to figure that out from the logs. Also the qemu.conf file says it *will* be disabled by default, so maybe adjusting the wording with something like "if possible" added there might be worth it. Simply to avoid further issues being filed.
return g_steal_pointer(&cfg); }
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index ee6cae218a..4daee432e5 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -407,6 +407,8 @@ int qemuTestDriverInit(virQEMUDriver *driver) cfg->hugetlbfs[0].deflt = true; cfg->hugetlbfs[1].size = 1048576;
+ cfg->dumpGuestCore = false; + driver->privileged = true;
return 0; -- 2.44.2
participants (2)
-
Martin Kletzander
-
Michal Privoznik