mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [GIT PULL 08/19 for v7.4] vfs coredump
Date: Fri, 16 Oct 2026 12:18:00 +0200	[thread overview]
Message-ID: <20261016-vfs-7.4-rc1.coredump-5fe9155f7d73@brauner> (raw)
In-Reply-To: <20261016-vfs-v74-41eaf6c4712c@brauner>

Hey Linus,

/* Summary */

This adds sparse coredumps and per-request memory type selection to the
coredump socket protocol.

A coredump sent over the socket transfers every zero of every hole in
every mapping. For a process with 128 threads that's 1 GB of mostly
thread stacks, 8 MB reservations with a few pages touched, and the
holes sit in the middle of the dump rather than at the end. The
coredump_filter bit that was proposed for this stops each PT_LOAD at
the last populated page. But that mask says which kinds of memory to
include and propagates across fork and exec, whereas what is selected
here is an encoding. The usermodehelper isn't salvagable for this
either. The coredump socket already has a handshake for exactly this.

A server that raises COREDUMP_RECORDS in coredump_ack->mask gets the
coredump as a sequence of records, each a struct coredump_record_header
followed by what it describes. The stream ends explicitly with an end
record that reports the size, so a missing one means truncation. With
COREDUMP_SPARSE holes cross the socket as a bare header that says how
many zero bytes were skipped. Reassembling the records gives back the
same coredump, so a debugger and everything else still see an ordinary
core file. Numbers from the selftests: the 128 thread process sends
1424153 bytes for a coredump of 1075150848 bytes, a 256 MB mapping with
the first and the last page touched sends 188793 bytes for 268890112
bytes, and with COREDUMP_RECORDS alone the record overhead is under one
percent. The selftests also simulate a server uploading to a blob store
that can't seek and rewrites the program headers so the object is an
ordinary ELF core file without the holes.

COREDUMP_MEMORY_TYPES lets the server choose what memory to dump per
request instead of relying on the static /proc/<pid>/coredump_filter
of the crashing task. The request carries the default types and a mask
of every type the kernel knows about, the ack carries the selection.
Zero is valid and dumps the program headers and notes and nothing but
the mappings that are always dumped.

Preparatory cleanups refuse negative skips in dump_skip_to(), chunk
every write at a page so a pipe or a socket never takes a short write
in the middle of a record, make the dump helpers return bool and
replace the core_dumped integer with COREDUMP_STATE_STARTED and
COREDUMP_STATE_TRUNCATED flags.

Also included is a fix for coredump_parse() reading core_pattern while
it is being modified. The sysctl handler now validates a copy and
publishes it under a spinlock and the parser works on a snapshot, so a
rejected pattern is never visible and the rollback logic goes away.
And to_kthread()'s lockless flags read is annotated with READ_ONCE().

/* Testing */

No build failures or warnings were observed.

/* Conflicts */

Merge conflicts with mainline
=============================

This conflicts with the kernel-7.4-rc1.signal tag in
tools/testing/selftests/coredump/coredump_test.h and
tools/testing/selftests/coredump/coredump_test_helpers.c between commit
7ac8d57a436c8 ("selftests/coredump: test that TIF_NOTIFY_SIGNAL doesn't
truncate a coredump") from that tag and commit eec8727ba2730
("selftests/coredump: add a separate helper header") from this tag. The
signal tag is merged before this one. The signal tag adds the
coredump_notify_signal.h and sys/syscall.h includes and this tag moves
everything else the two files shared into coredump_test_helpers.h:

diff --cc tools/testing/selftests/coredump/coredump_test.h
index 06f997ba47fd,8d99b5cb2f12..000000000000
--- a/tools/testing/selftests/coredump/coredump_test.h
+++ b/tools/testing/selftests/coredump/coredump_test.h
@@@ -3,19 -3,9 +3,10 @@@
  #ifndef __COREDUMP_TEST_H
  #define __COREDUMP_TEST_H
  
- #include <stdbool.h>
- #include <sys/types.h>
- #include <linux/coredump.h>
- 
  #include "../kselftest_harness.h"
- #include "../pidfd/pidfd.h"
 +#include "coredump_notify_signal.h"
  
- #ifndef PAGE_SIZE
- #define PAGE_SIZE 4096
- #endif
- 
- #define NUM_THREAD_SPAWN 128
+ #include "coredump_test_helpers.h"
  
  /* Coredump fixture */
  FIXTURE(coredump)
diff --cc tools/testing/selftests/coredump/coredump_test_helpers.c
index f8d416180d5b,4e36e3e4fb78..000000000000
--- a/tools/testing/selftests/coredump/coredump_test_helpers.c
+++ b/tools/testing/selftests/coredump/coredump_test_helpers.c
@@@ -22,32 -17,22 +22,24 @@@
  #include <sys/ioctl.h>
  #include <sys/mman.h>
  #include <sys/socket.h>
+ #include <sys/stat.h>
 +#include <sys/syscall.h>
  #include <sys/types.h>
  #include <sys/un.h>
  #include <sys/wait.h>
  #include <unistd.h>
  
  #include "../filesystems/wrappers.h"
- #include "../pidfd/pidfd.h"
 +#include "coredump_notify_signal.h"
  
- /* Forward declarations to avoid including harness header */
- struct __test_metadata;
+ #include "coredump_test_helpers.h"
  
- /* Match the fixture definition from coredump_test.h */
- struct _fixture_coredump_data {
- 	char original_core_pattern[256];
- 	pid_t pid_coredump_server;
- 	int fd_tmpfs_detached;
- };
- 
- #ifndef PAGE_SIZE
- #define PAGE_SIZE 4096
+ #if __ELF_NATIVE_CLASS == 64
+ #define COREDUMP_ELFCLASS ELFCLASS64
+ #else
+ #define COREDUMP_ELFCLASS ELFCLASS32
  #endif
  
- #define NUM_THREAD_SPAWN 128
- 
  void *do_nothing(void *arg)
  {
  	(void)arg;

Merge conflicts with other trees
================================

This conflicts with the mm tree in fs/coredump.c between commit
e2f895dd2f8cb ("mm: rename is_vm_hugetlb_page() to vma_is_hugetlb()")
from the mm tree and commit 757ebc30a3725 ("coredump: select memory
types to include") from this tree:

diff --cc fs/coredump.c
index 5820cb8ec88e,357f0774d5a1..5b657770f154
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@@ -1608,10 -1850,12 +1850,12 @@@ static unsigned long vma_dump_size(stru
  	}
  
  	/* Hugetlb memory check */
 -	if (is_vm_hugetlb_page(vma)) {
 +	if (vma_is_hugetlb(vma)) {
- 		if ((vma->vm_flags & VM_SHARED) && FILTER(HUGETLB_SHARED))
+ 		if ((vma->vm_flags & VM_SHARED) &&
+ 		    COREDUMP_MEMORY_TYPE_INCLUDE(memory_types, HUGETLB_SHARED))
  			goto whole;
- 		if (!(vma->vm_flags & VM_SHARED) && FILTER(HUGETLB_PRIVATE))
+ 		if (!(vma->vm_flags & VM_SHARED) &&
+ 		    COREDUMP_MEMORY_TYPE_INCLUDE(memory_types, HUGETLB_PRIVATE))
  			goto whole;
  		return 0;
  	}

The following changes since commit cee9395acd8043be0644b25c34bfa86623f2b935:

  Linux 7.3-rc1 (2026-08-30 13:34:40 -0700)

are available in the Git repository at:

  git@gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs tags/vfs-7.4-rc1.coredump

for you to fetch changes up to fd00a46e36a12c5279d3d163f0d0c8f83d12dc09:

  kthread: Annotate lockless to_kthread() flags access (2026-09-25 11:33:50 +0200)

----------------------------------------------------------------
vfs-7.4-rc1.coredump

Please consider pulling these changes from the signed vfs-7.4-rc1.coredump tag.

Thanks!
Christian

----------------------------------------------------------------
Christian Brauner (30):
      coredump: refuse negative skips
      coredump: set the minimum send buffer size
      selftests/coredump: discard the right amount after the coredump request
      selftests/coredump: collapse the expected request check into the helper
      selftests/coredump: add a separate helper header
      coredump: pin the protocol struct sizes
      coredump: move the negotiated mask into struct coredump_params
      coredump: deduplicate the to_skip flush
      coredump: make the dump helper return bool
      coredump: always chunk writes
      coredump: clean up coredump state handling
      coredump: add COREDUMP_RECORDS to the coredump socket protocol
      coredump: add COREDUMP_SPARSE to the coredump socket protocol
      tools: sync coredump.h header
      coredump: send the coredump in records if requested
      coredump: describe the holes when COREDUMP_SPARSE is negotiated
      selftests/coredump: test COREDUMP_RECORDS and COREDUMP_SPARSE
      selftests/coredump: hand the record stream to a sink
      selftests/coredump: put a hole in the middle of a sparse mapping
      selftests/coredump: simulate a blob store
      selftests/coredump: show how to inspect the task to decide how the coredump should be sent
      Merge patch series "coredump: allow to create sparse coredumps on the coredump socket"
      coredump: select memory types to include
      tools: sync coredump.h header
      selftests/coredump: simplify the refusal tests
      selftests/coredump: test COREDUMP_MEMORY_TYPES
      selftests/coredump: improve coredump size negotiation tests
      selftests/coredump: test failed handshakes
      Merge patch series "coredump: select memory types per request"
      coredump: parse a snapshot of core_pattern

Kunwu Chan (1):
      kthread: Annotate lockless to_kthread() flags access

 Documentation/filesystems/proc.rst                 |    4 +
 fs/binfmt_elf.c                                    |   12 +-
 fs/binfmt_elf_fdpic.c                              |   12 +-
 fs/coredump.c                                      |  490 ++++--
 include/linux/binfmts.h                            |    3 +-
 include/linux/coredump.h                           |   37 +-
 include/uapi/linux/coredump.h                      |  149 +-
 kernel/kthread.c                                   |    2 +-
 tools/include/uapi/linux/coredump.h                |  149 +-
 .../coredump/coredump_socket_protocol_test.c       | 1829 +++++++++++++++-----
 tools/testing/selftests/coredump/coredump_test.h   |   31 +-
 .../selftests/coredump/coredump_test_helpers.c     | 1432 ++++++++++++++-
 .../selftests/coredump/coredump_test_helpers.h     |   79 +
 13 files changed, 3597 insertions(+), 632 deletions(-)
 create mode 100644 tools/testing/selftests/coredump/coredump_test_helpers.h

  parent reply	other threads:[~2026-10-16 10:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 10:13 [GIT PULL 00/19 for v7.4] v7.4 Christian Brauner
2026-10-16 10:14 ` [GIT PULL 01/19 for v7.4] ipc misc Christian Brauner
2026-10-16 10:15 ` [GIT PULL 02/19 for v7.4] kernel signal Christian Brauner
2026-10-16 10:15 ` [GIT PULL 03/19 for v7.4] namespace misc Christian Brauner
2026-10-16 10:16 ` [GIT PULL 04/19 for v7.4] vfs bfs Christian Brauner
2026-10-16 10:16 ` [GIT PULL 05/19 for v7.4] vfs bh Christian Brauner
2026-10-16 10:16 ` [GIT PULL 06/19 for v7.4] vfs binfmt Christian Brauner
2026-10-16 10:17 ` [GIT PULL 07/19 for v7.4] vfs close_range Christian Brauner
2026-10-16 10:18 ` Christian Brauner [this message]
2026-10-16 10:18 ` [GIT PULL 09/19 for v7.4] vfs file Christian Brauner
2026-10-16 10:19 ` [GIT PULL 10/19 for v7.4] vfs idmap Christian Brauner
2026-10-16 10:21 ` [GIT PULL 11/19 for v7.4] vfs iomap Christian Brauner
2026-10-16 10:21 ` [GIT PULL 12/19 for v7.4] vfs kernfs Christian Brauner
2026-10-16 10:22 ` [GIT PULL 13/19 for v7.4] vfs lookup Christian Brauner
2026-10-16 10:23 ` [GIT PULL 14/19 for v7.4] vfs misc Christian Brauner
2026-10-16 10:24 ` [GIT PULL 15/19 for v7.4] vfs mount Christian Brauner
2026-10-16 10:25 ` [GIT PULL 16/19 for v7.4] vfs netfs Christian Brauner
2026-10-16 10:26 ` [GIT PULL 17/19 for v7.4] vfs shared net-next pidfd Christian Brauner
2026-10-16 10:26 ` [GIT PULL 18/19 for v7.4] vfs shared super Christian Brauner
2026-10-16 10:27 ` [GIT PULL 19/19 for v7.4] vfs sync_close Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261016-vfs-7.4-rc1.coredump-5fe9155f7d73@brauner \
    --to=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®