Add a VMA flag saying that the folios mapped into a VMA should be
described to the kdump kernel through crash_memaction. The flag
indicates "marked" pages. The specific meaning of what pages are marked
is set through the crash_memaction= cmdline param, which currently
supports marking "secret" or "cache" pages.

The flag is an ordinary VMA flag, so splitting, merging, mremap() and
inheritance across fork() all behave the way they do for MADV_DONTFORK
and friends.

To allocate the flag, CONFIG_CRASH_MEMACTION gains a dependency on
64BIT. Both architectures that support the config are 64-bit already.

Signed-off-by: Jan Sebastian Götte <[email protected]>
Assisted-by: Claude Opus 5 <[email protected]>
---
 fs/proc/task_mmu.c   | 3 +++
 include/linux/mm.h   | 9 +++++++++
 kernel/Kconfig.kexec | 2 ++
 3 files changed, 14 insertions(+)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index c0d228036b8a..880946edf4df 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1161,6 +1161,9 @@ static void show_smap_vma_flags(struct seq_file *m, 
struct vm_area_struct *vma)
 #endif
 #ifdef CONFIG_64BIT
                [ilog2(VM_SEALED)] = "sl",
+#endif
+#ifdef CONFIG_CRASH_MEMACTION
+               [ilog2(VM_CRASH_MARK)] = "cm",
 #endif
        };
        size_t i;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index b9ed4f569b75..4ffe6350f865 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -345,6 +345,10 @@ enum {
        DECLARE_VMA_BIT(UFFD_MINOR, 41),
        DECLARE_VMA_BIT(SEALED, 42),
        DECLARE_VMA_BIT(UFFD_RWP, 43),
+#if defined(CONFIG_CRASH_MEMACTION)
+       /* Describe this VMA's folios to the kdump kernel; carries no type. */
+       DECLARE_VMA_BIT(CRASH_MARK, 44),
+#endif
        /* Flags that reuse flags above. */
        DECLARE_VMA_BIT_ALIAS(PKEY_BIT0, HIGH_ARCH_0),
        DECLARE_VMA_BIT_ALIAS(PKEY_BIT1, HIGH_ARCH_1),
@@ -526,6 +530,11 @@ enum {
 #define VM_ALLOW_ANY_UNCACHED  VM_NONE
 #define VM_SEALED              VM_NONE
 #endif
+#ifdef CONFIG_CRASH_MEMACTION
+#define VM_CRASH_MARK          INIT_VM_FLAG(CRASH_MARK)
+#else
+#define VM_CRASH_MARK          VM_NONE
+#endif
 #if defined(CONFIG_64BIT) || defined(CONFIG_PPC32)
 #define VM_DROPPABLE           INIT_VM_FLAG(DROPPABLE)
 #define VMA_DROPPABLE          mk_vma_flags(VMA_DROPPABLE_BIT)
diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
index 890c35199bea..3cdc8d459ac0 100644
--- a/kernel/Kconfig.kexec
+++ b/kernel/Kconfig.kexec
@@ -189,6 +189,8 @@ config CRASH_MEMACTION
        depends on !SLUB_TINY
        select SLAB_BUCKETS
        depends on ARCH_SUPPORTS_CRASH_MEMACTION
+       # VM_CRASH_MARK needs a bit from the 64-bit-only half of vm_flags.
+       depends on 64BIT
        help
          Track pages that may require special handling by the kdump kernel:
          pages holding secrets such as crypto keys, which it can wipe before

-- 
2.55.0


Reply via email to