Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

core_pattern: add CPU specifier

Statistically, in a large deployment regular segfaults may indicate a CPU
issue.

Currently, it is not possible to find out what CPU the segfault happened
on. There are at least two attempts to improve segfault logging with this
regard, but they do not help in case the logs rotate.

Hence, lets make sure it is possible to permanently record a CPU the task
ran on using a new core_pattern specifier.

Link: https://lkml.kernel.org/r/20220903064330.20772-1-oleksandr@redhat.com
Signed-off-by: Oleksandr Natalenko <oleksandr@redhat.com>
Suggested-by: Renaud Métrich <rmetrich@redhat.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "Eric W . Biederman" <ebiederm@xmission.com>
Cc: Grzegorz Halat <ghalat@redhat.com>
Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Joel Savitz <jsavitz@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kees Cook <keescook@chromium.org>
Cc: Laurent Dufour <ldufour@linux.ibm.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Rob Herring <robh@kernel.org>
Cc: Stephen Kitt <steve@sk2.org>
Cc: Will Deacon <will@kernel.org>
Cc: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Oleksandr Natalenko and committed by
Andrew Morton
8603b6f5 597d77d2

+7
+1
Documentation/admin-guide/sysctl/kernel.rst
··· 174 174 %f executable filename 175 175 %E executable path 176 176 %c maximum size of core file by resource limit RLIMIT_CORE 177 + %C CPU the task ran on 177 178 %<OTHER> both are dropped 178 179 ======== ========================================== 179 180
+5
fs/coredump.c
··· 325 325 err = cn_printf(cn, "%lu", 326 326 rlimit(RLIMIT_CORE)); 327 327 break; 328 + /* CPU the task ran on */ 329 + case 'C': 330 + err = cn_printf(cn, "%d", cprm->cpu); 331 + break; 328 332 default: 329 333 break; 330 334 } ··· 538 534 */ 539 535 .mm_flags = mm->flags, 540 536 .vma_meta = NULL, 537 + .cpu = raw_smp_processor_id(), 541 538 }; 542 539 543 540 audit_core_dumps(siginfo->si_signo);
+1
include/linux/coredump.h
··· 22 22 struct file *file; 23 23 unsigned long limit; 24 24 unsigned long mm_flags; 25 + int cpu; 25 26 loff_t written; 26 27 loff_t pos; 27 28 loff_t to_skip;