[RFC PATCH v2 21/22] coredump: Use PAGE_SIZE_MIN for the zero-fill buffer

From: Eric Curtin

Date: Tue Dec 01 2026 - 22:17:01 EST


From: Ryan Roberts <ryan.roberts@xxxxxxx>

With boot-time page size selection PAGE_SIZE is not a compile-time
constant, so it cannot size the static zeroes[] buffer in
__dump_skip(), and some fs code must be reworked as well.

In __dump_skip(), size zeroes[] and the chunk length with
PAGE_SIZE_MIN. This is the old PAGE_SIZE when the page size is fixed;
PAGE_SIZE_MIN is preferred over PAGE_SIZE_MAX to save memory.

In binfmt_elf, turn the #if choosing ELF_MIN_ALIGN into a ternary
expression that evaluates at run time, and define elf_format with
DEFINE_GLOBAL_PAGE_SIZE_VAR() so that its ELF_EXEC_PAGESIZE based
initialiser can be deferred to boot.

No functional change for compile-time page sizes.

Signed-off-by: Ryan Roberts <ryan.roberts@xxxxxxx>
Signed-off-by: Eric Curtin <eric.curtin@xxxxxxxxxx>
---
fs/binfmt_elf.c | 11 ++++-------
fs/coredump.c | 4 ++--
2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index bf7f8f47548d..9adec104a211 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -79,11 +79,8 @@ static bool elf_core_dump(struct coredump_params *cprm);
#define elf_core_dump NULL
#endif

-#if ELF_EXEC_PAGESIZE > PAGE_SIZE
-#define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
-#else
-#define ELF_MIN_ALIGN PAGE_SIZE
-#endif
+#define ELF_MIN_ALIGN \
+ (ELF_EXEC_PAGESIZE > PAGE_SIZE ? ELF_EXEC_PAGESIZE : PAGE_SIZE)

#ifndef ELF_CORE_EFLAGS
#define ELF_CORE_EFLAGS 0
@@ -93,14 +90,14 @@ static bool elf_core_dump(struct coredump_params *cprm);
#define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1))
#define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))

-static struct linux_binfmt elf_format = {
+static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct linux_binfmt, elf_format, {
.module = THIS_MODULE,
.load_binary = load_elf_binary,
#ifdef CONFIG_COREDUMP
.core_dump = elf_core_dump,
.min_coredump = ELF_EXEC_PAGESIZE,
#endif
-};
+});

#define BAD_ADDR(x) (unlikely((unsigned long)(x) >= TASK_SIZE))

diff --git a/fs/coredump.c b/fs/coredump.c
index 82ef9d115999..e9658771c217 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1442,7 +1442,7 @@ static void dump_end_record(struct coredump_params *cprm)

static bool __dump_skip(struct coredump_params *cprm, size_t nr)
{
- static char zeroes[PAGE_SIZE];
+ static char zeroes[PAGE_SIZE_MIN];
struct file *file = cprm->file;

if (dump_sparse(cprm)) {
@@ -1460,7 +1460,7 @@ static bool __dump_skip(struct coredump_params *cprm, size_t nr)
}

while (nr) {
- size_t chunk = min_t(size_t, nr, PAGE_SIZE);
+ size_t chunk = min_t(size_t, nr, PAGE_SIZE_MIN);

if (!__dump_emit(cprm, zeroes, chunk))
return false;