[PATCH] qemu: enable QEMU core dump by default on Linux

Daniel P. Berrangé posted 1 patch 3 weeks, 1 day ago
src/qemu/qemu.conf.in |  8 +++++---
src/qemu/qemu_conf.c  | 10 +++++++---
2 files changed, 12 insertions(+), 6 deletions(-)
[PATCH] qemu: enable QEMU core dump by default on Linux
Posted by Daniel P. Berrangé 3 weeks, 1 day ago
The Linux MADV_DONTDUMP flag was added to Linux kernels > 3.3,
back in 2012, and the dump-guest-core flag was added to QEMU
> 1.0 at the same time.

IOW, on Linux we have long been able to assume that QEMU core
dumps will exclude guest memory, unless the user has overridden
the host level defaults in the domain XML.

It is desirable to permit QEMU core dumps out of the box to make
it easier for users to report crashes to their OS vendor without
having to reconfigure and restart libvirt daemons and their
running guests.

While there is a risk that an admin may have set 'dump_guest_core'
to true, while leaving 'max_core' to 0, on balance the benefits
of easier troubleshooting outweigh the risk of changing the
defaults to permit core dumps.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/qemu/qemu.conf.in |  8 +++++---
 src/qemu/qemu_conf.c  | 10 +++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in
index 89c9b6b913..d853136f10 100644
--- a/src/qemu/qemu.conf.in
+++ b/src/qemu/qemu.conf.in
@@ -709,7 +709,9 @@
 # As a special case it can be set to the string "unlimited" to
 # to allow arbitrarily sized core dumps.
 #
-# By default the core dump size is set to 0 disabling all dumps
+# By default the core dump size is set to unlimited on
+# Linux where 'dump_guest_core' defaults to false, and
+# is set to 0 on other platforms, disabling all dumps
 #
 # Size is a positive integer specifying bytes or the
 # string "unlimited"
@@ -717,8 +719,8 @@
 #max_core = "unlimited"
 
 # Determine if guest RAM is included in QEMU core dumps. By
-# default guest RAM will be excluded if a new enough QEMU is
-# present and host kernel supports it. Setting this to '1' will
+# default guest RAM will be excluded on Linux platforms,
+# and included on all other patforms. Setting this to '1' will
 # force guest RAM to always be included in QEMU core dumps.
 #
 # This setting will be ignored if the guest XML has set the
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 7c15c521c7..8b9fe4e381 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -291,10 +291,14 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged,
     cfg->deprecationBehavior = g_strdup("none");
     cfg->storageUseNbdkit = USE_NBDKIT_DEFAULT;
 
-#ifndef MADV_DONTDUMP
+#ifdef MADV_DONTDUMP
+    cfg->maxCore = ULLONG_MAX;
+#else
     /* 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. */
+     * include/exclude guest memory from core dump. On non-Linux systems
+     * core dumps will unavoidably include all guest RAM, so toggle the
+     * default to reflect this and warn the admin.
+     */
     VIR_INFO("Host kernel doesn't support MADV_DONTDUMP. Enabling dump_guest_core");
     cfg->dumpGuestCore = true;
 #endif
-- 
2.46.0
Re: [PATCH] qemu: enable QEMU core dump by default on Linux
Posted by Richard W.M. Jones 3 weeks, 1 day ago
On Fri, Nov 29, 2024 at 12:00:51PM +0000, Daniel P. Berrangé wrote:
> The Linux MADV_DONTDUMP flag was added to Linux kernels > 3.3,
> back in 2012, and the dump-guest-core flag was added to QEMU
> > 1.0 at the same time.
> 
> IOW, on Linux we have long been able to assume that QEMU core
> dumps will exclude guest memory, unless the user has overridden
> the host level defaults in the domain XML.
> 
> It is desirable to permit QEMU core dumps out of the box to make
> it easier for users to report crashes to their OS vendor without
> having to reconfigure and restart libvirt daemons and their
> running guests.
> 
> While there is a risk that an admin may have set 'dump_guest_core'
> to true, while leaving 'max_core' to 0, on balance the benefits
> of easier troubleshooting outweigh the risk of changing the
> defaults to permit core dumps.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Yes yes yes!

Reviewed-by: Richard W.M. Jones <rjones@redhat.com>

> ---
>  src/qemu/qemu.conf.in |  8 +++++---
>  src/qemu/qemu_conf.c  | 10 +++++++---
>  2 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in
> index 89c9b6b913..d853136f10 100644
> --- a/src/qemu/qemu.conf.in
> +++ b/src/qemu/qemu.conf.in
> @@ -709,7 +709,9 @@
>  # As a special case it can be set to the string "unlimited" to
>  # to allow arbitrarily sized core dumps.
>  #
> -# By default the core dump size is set to 0 disabling all dumps
> +# By default the core dump size is set to unlimited on
> +# Linux where 'dump_guest_core' defaults to false, and
> +# is set to 0 on other platforms, disabling all dumps
>  #
>  # Size is a positive integer specifying bytes or the
>  # string "unlimited"
> @@ -717,8 +719,8 @@
>  #max_core = "unlimited"
>  
>  # Determine if guest RAM is included in QEMU core dumps. By
> -# default guest RAM will be excluded if a new enough QEMU is
> -# present and host kernel supports it. Setting this to '1' will
> +# default guest RAM will be excluded on Linux platforms,
> +# and included on all other patforms. Setting this to '1' will
>  # force guest RAM to always be included in QEMU core dumps.
>  #
>  # This setting will be ignored if the guest XML has set the
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 7c15c521c7..8b9fe4e381 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -291,10 +291,14 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged,
>      cfg->deprecationBehavior = g_strdup("none");
>      cfg->storageUseNbdkit = USE_NBDKIT_DEFAULT;
>  
> -#ifndef MADV_DONTDUMP
> +#ifdef MADV_DONTDUMP
> +    cfg->maxCore = ULLONG_MAX;
> +#else
>      /* 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. */
> +     * include/exclude guest memory from core dump. On non-Linux systems
> +     * core dumps will unavoidably include all guest RAM, so toggle the
> +     * default to reflect this and warn the admin.
> +     */
>      VIR_INFO("Host kernel doesn't support MADV_DONTDUMP. Enabling dump_guest_core");
>      cfg->dumpGuestCore = true;
>  #endif
> -- 
> 2.46.0

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
nbdkit - Flexible, fast NBD server with plugins
https://gitlab.com/nbdkit/nbdkit