[PATCH] Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user

WorksButNotTested posted 1 patch 6 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250501181758.1057834-1-62701594+WorksButNotTested@users.noreply.github.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Laurent Vivier <laurent@vivier.eu>
There is a newer version of this series
include/exec/page-protection.h | 6 ++++++
linux-user/elfload.c           | 4 ++++
linux-user/mmap.c              | 5 +++++
3 files changed, 15 insertions(+)
[PATCH] Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
Posted by WorksButNotTested 6 months, 2 weeks ago
---
 include/exec/page-protection.h | 6 ++++++
 linux-user/elfload.c           | 4 ++++
 linux-user/mmap.c              | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/include/exec/page-protection.h b/include/exec/page-protection.h
index c43231af8b..f8826d917e 100644
--- a/include/exec/page-protection.h
+++ b/include/exec/page-protection.h
@@ -38,4 +38,10 @@
  */
 #define PAGE_PASSTHROUGH 0x0800
 
+/*
+ * For linux-user, indicates that the page should not be included in a core 
+ * dump.
+ */
+#define PAGE_DONTDUMP   0x1000
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index fbfdec2f17..41c46da055 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start, target_ulong end,
         return 0;
     }
 
+    if (flags & PAGE_DONTDUMP) {
+        return 0;
+    }
+
     /*
      * Usually we don't dump executable pages as they contain
      * non-writable code that debugger can read directly from
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index f88a80c31e..62fc8ac921 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
      */
     mmap_lock();
     switch (advice) {
+    case MADV_DONTDUMP:
+        if (len > 0) {
+            page_set_flags(start, start + len - 1, PAGE_DONTDUMP);
+        }
+        break;
     case MADV_WIPEONFORK:
     case MADV_KEEPONFORK:
         ret = -EINVAL;
-- 
2.43.0
Re: [PATCH] Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
Posted by Richard Henderson 6 months, 2 weeks ago
On 5/1/25 11:17, WorksButNotTested wrote:
> ---
>   include/exec/page-protection.h | 6 ++++++
>   linux-user/elfload.c           | 4 ++++
>   linux-user/mmap.c              | 5 +++++
>   3 files changed, 15 insertions(+)
> 

Seems reasonable.  Add a patch description and a Signed-off-by, please.


r~

> diff --git a/include/exec/page-protection.h b/include/exec/page-protection.h
> index c43231af8b..f8826d917e 100644
> --- a/include/exec/page-protection.h
> +++ b/include/exec/page-protection.h
> @@ -38,4 +38,10 @@
>    */
>   #define PAGE_PASSTHROUGH 0x0800
>   
> +/*
> + * For linux-user, indicates that the page should not be included in a core
> + * dump.
> + */
> +#define PAGE_DONTDUMP   0x1000
> +
>   #endif
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index fbfdec2f17..41c46da055 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start, target_ulong end,
>           return 0;
>       }
>   
> +    if (flags & PAGE_DONTDUMP) {
> +        return 0;
> +    }
> +
>       /*
>        * Usually we don't dump executable pages as they contain
>        * non-writable code that debugger can read directly from
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index f88a80c31e..62fc8ac921 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
>        */
>       mmap_lock();
>       switch (advice) {
> +    case MADV_DONTDUMP:
> +        if (len > 0) {
> +            page_set_flags(start, start + len - 1, PAGE_DONTDUMP);
> +        }
> +        break;
>       case MADV_WIPEONFORK:
>       case MADV_KEEPONFORK:
>           ret = -EINVAL;
Re: [PATCH] Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
Posted by Jon Wilson 6 months, 2 weeks ago
Awesome. Thanks. How do I do that? Sorry I'm new to this workflow. Can you
point me at a reference?

On Thu, 1 May 2025, 22:27 Richard Henderson, <richard.henderson@linaro.org>
wrote:

> On 5/1/25 11:17, WorksButNotTested wrote:
> > ---
> >   include/exec/page-protection.h | 6 ++++++
> >   linux-user/elfload.c           | 4 ++++
> >   linux-user/mmap.c              | 5 +++++
> >   3 files changed, 15 insertions(+)
> >
>
> Seems reasonable.  Add a patch description and a Signed-off-by, please.
>
>
> r~
>
> > diff --git a/include/exec/page-protection.h
> b/include/exec/page-protection.h
> > index c43231af8b..f8826d917e 100644
> > --- a/include/exec/page-protection.h
> > +++ b/include/exec/page-protection.h
> > @@ -38,4 +38,10 @@
> >    */
> >   #define PAGE_PASSTHROUGH 0x0800
> >
> > +/*
> > + * For linux-user, indicates that the page should not be included in a
> core
> > + * dump.
> > + */
> > +#define PAGE_DONTDUMP   0x1000
> > +
> >   #endif
> > diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> > index fbfdec2f17..41c46da055 100644
> > --- a/linux-user/elfload.c
> > +++ b/linux-user/elfload.c
> > @@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start,
> target_ulong end,
> >           return 0;
> >       }
> >
> > +    if (flags & PAGE_DONTDUMP) {
> > +        return 0;
> > +    }
> > +
> >       /*
> >        * Usually we don't dump executable pages as they contain
> >        * non-writable code that debugger can read directly from
> > diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> > index f88a80c31e..62fc8ac921 100644
> > --- a/linux-user/mmap.c
> > +++ b/linux-user/mmap.c
> > @@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start,
> abi_ulong len_in, int advice)
> >        */
> >       mmap_lock();
> >       switch (advice) {
> > +    case MADV_DONTDUMP:
> > +        if (len > 0) {
> > +            page_set_flags(start, start + len - 1, PAGE_DONTDUMP);
> > +        }
> > +        break;
> >       case MADV_WIPEONFORK:
> >       case MADV_KEEPONFORK:
> >           ret = -EINVAL;
>
>
Re: [PATCH] Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
Posted by BALATON Zoltan 6 months, 2 weeks ago
On Thu, 1 May 2025, Jon Wilson wrote:
> Awesome. Thanks. How do I do that? Sorry I'm new to this workflow. Can you
> point me at a reference?

qemu.org -> Contribute -> Patch submission guidelines:

https://www.qemu.org/docs/master/devel/submitting-a-patch.html

Regards,
BALATON Zoltan