Skip to contentSkip to conversation

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

PATCH Superseded WorksButNotTested 3 participants 4 messages May 1, 2025

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user

---
 include/exec/page-protection.h | 6 ++++++
 linux-user/elfload.c           | 4 ++++
 linux-user/mmap.c              | 5 +++++
 3 files changed, 15 insertions(+)
include/exec/page-protection.h +6 -0
index c43231af8b..f8826d917e 100644
@@ -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
linux-user/elfload.c +4 -0
index fbfdec2f17..41c46da055 100644
@@ -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
linux-user/mmap.c +5 -0
index f88a80c31e..62fc8ac921 100644
@@ -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;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · WorksButNotTested
---
  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~

Quoted 46 lines
include/exec/page-protection.h +6 -0
index c43231af8b..f8826d917e 100644
@@ -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
linux-user/elfload.c +4 -0
index fbfdec2f17..41c46da055 100644
@@ -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
linux-user/mmap.c +5 -0
index f88a80c31e..62fc8ac921 100644
@@ -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;
author
#2 lore raw

Awesome. Thanks. How do I do that? Sorry I'm new to this workflow. Can you point me at a reference?

Quoted 65 lines · On Thu, 1 May 2025, 22:27 Richard Henderson, <[email protected]>…
Quoted 6 lines · WorksButNotTested
---
  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~

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/exec/page-protection.h

include/exec/page-protection.h line 42

Quoted 9 lines

index c43231af8b..f8826d917e 100644

include/exec/page-protection.h +2 -0
@@ -38,4 +38,10 @@
   */
  #define PAGE_PASSTHROUGH 0x0800
 
+/*
+ * For linux-user, indicates that the page should not be included in a

core

linux-user/elfload.c static size_t vma_dump_size(target_ulong start,

Quoted 10 lines
include/exec/page-protection.h +4 -0
+ * dump.
+ */
+#define PAGE_DONTDUMP   0x1000
+
  #endif
linux-user/elfload.c +0 -0
index fbfdec2f17..41c46da055 100644
@@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start,

target_ulong end,

linux-user/mmap.c abi_long target_madvise(abi_ulong start,

Quoted 15 lines
linux-user/elfload.c +4 -0
          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
linux-user/mmap.c +0 -0
index f88a80c31e..62fc8ac921 100644
@@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start,

abi_ulong len_in, int advice)

Quoted 11 lines
linux-user/mmap.c +5 -0
       */
      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;