* [PATCH v2 0/5] elf: Define note name macros
@ 2025-01-04 14:38 Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 1/5] " Akihiko Odaki
` (6 more replies)
0 siblings, 7 replies; 15+ messages in thread
From: Akihiko Odaki @ 2025-01-04 14:38 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Baoquan He, Vivek Goyal, Dave Young
Cc: linux-mm, linux-kernel, linuxppc-dev, linux-s390, kexec, devel,
Akihiko Odaki
elf.h had a comment saying:
> Notes used in ET_CORE. Architectures export some of the arch register
> sets using the corresponding note types via the PTRACE_GETREGSET and
> PTRACE_SETREGSET requests.
> The note name for these types is "LINUX", except NT_PRFPREG that is
> named "CORE".
However, NT_PRSTATUS is also named "CORE". It is also unclear what
"these types" refers to.
To fix these problems, define a name for each note type. The added
definitions are macros so the kernel and userspace can directly refer to
them.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
Changes in v2:
- Added a macro definition for each note type instead of trying to
describe in a comment.
- Link to v1: https://lore.kernel.org/r/20241225-elf-v1-1-79e940350d50@daynix.com
---
Akihiko Odaki (5):
elf: Define note name macros
binfmt_elf: Use note name macros
powwerpc: Use note name macros
crash: Use note name macros
crash: Remove KEXEC_CORE_NOTE_NAME
arch/powerpc/kernel/fadump.c | 2 +-
arch/powerpc/platforms/powernv/opal-core.c | 8 +--
arch/s390/kernel/crash_dump.c | 2 +-
fs/binfmt_elf.c | 21 ++++----
fs/binfmt_elf_fdpic.c | 8 +--
fs/proc/kcore.c | 12 ++---
include/linux/kexec.h | 2 -
include/linux/vmcore_info.h | 3 +-
include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++--
kernel/crash_core.c | 2 +-
10 files changed, 111 insertions(+), 35 deletions(-)
---
base-commit: a32e14f8aef69b42826cf0998b068a43d486a9e9
change-id: 20241210-elf-b80ea3949c39
Best regards,
--
Akihiko Odaki <akihiko.odaki@daynix.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 1/5] elf: Define note name macros
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
@ 2025-01-04 14:38 ` Akihiko Odaki
2025-01-06 2:21 ` Baoquan He
` (2 more replies)
2025-01-04 14:38 ` [PATCH v2 2/5] binfmt_elf: Use " Akihiko Odaki
` (5 subsequent siblings)
6 siblings, 3 replies; 15+ messages in thread
From: Akihiko Odaki @ 2025-01-04 14:38 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Baoquan He, Vivek Goyal, Dave Young
Cc: linux-mm, linux-kernel, linuxppc-dev, linux-s390, kexec, devel,
Akihiko Odaki
elf.h had a comment saying:
> Notes used in ET_CORE. Architectures export some of the arch register
> sets using the corresponding note types via the PTRACE_GETREGSET and
> PTRACE_SETREGSET requests.
> The note name for these types is "LINUX", except NT_PRFPREG that is
> named "CORE".
However, NT_PRSTATUS is also named "CORE". It is also unclear what
"these types" refers to.
To fix these problems, define a name for each note type. The added
definitions are macros so the kernel and userspace can directly refer to
them.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 83 insertions(+), 3 deletions(-)
diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
index b44069d29cec..014b705b97d7 100644
--- a/include/uapi/linux/elf.h
+++ b/include/uapi/linux/elf.h
@@ -372,8 +372,6 @@ typedef struct elf64_shdr {
* Notes used in ET_CORE. Architectures export some of the arch register sets
* using the corresponding note types via the PTRACE_GETREGSET and
* PTRACE_SETREGSET requests.
- * The note name for these types is "LINUX", except NT_PRFPREG that is named
- * "CORE".
*/
#define NT_PRSTATUS 1
#define NT_PRFPREG 2
@@ -460,9 +458,91 @@ typedef struct elf64_shdr {
#define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
#define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
-/* Note types with note name "GNU" */
+/* Note used in ET_EXEC and ET_DYN. */
#define NT_GNU_PROPERTY_TYPE_0 5
+/* Note names */
+#define NN_PRSTATUS "CORE"
+#define NN_PRFPREG "CORE"
+#define NN_PRPSINFO "CORE"
+#define NN_TASKSTRUCT "CORE"
+#define NN_AUXV "CORE"
+#define NN_SIGINFO "CORE"
+#define NN_FILE "CORE"
+#define NN_PRXFPREG "LINUX"
+#define NN_PPC_VMX "LINUX"
+#define NN_PPC_SPE "LINUX"
+#define NN_PPC_VSX "LINUX"
+#define NN_PPC_TAR "LINUX"
+#define NN_PPC_PPR "LINUX"
+#define NN_PPC_DSCR "LINUX"
+#define NN_PPC_EBB "LINUX"
+#define NN_PPC_PMU "LINUX"
+#define NN_PPC_TM_CGPR "LINUX"
+#define NN_PPC_TM_CFPR "LINUX"
+#define NN_PPC_TM_CVMX "LINUX"
+#define NN_PPC_TM_CVSX "LINUX"
+#define NN_PPC_TM_SPR "LINUX"
+#define NN_PPC_TM_CTAR "LINUX"
+#define NN_PPC_TM_CPPR "LINUX"
+#define NN_PPC_TM_CDSCR "LINUX"
+#define NN_PPC_PKEY "LINUX"
+#define NN_PPC_DEXCR "LINUX"
+#define NN_PPC_HASHKEYR "LINUX"
+#define NN_386_TLS "LINUX"
+#define NN_386_IOPERM "LINUX"
+#define NN_X86_XSTATE "LINUX"
+#define NN_X86_SHSTK "LINUX"
+#define NN_X86_XSAVE_LAYOUT "LINUX"
+#define NN_S390_HIGH_GPRS "LINUX"
+#define NN_S390_TIMER "LINUX"
+#define NN_S390_TODCMP "LINUX"
+#define NN_S390_TODPREG "LINUX"
+#define NN_S390_CTRS "LINUX"
+#define NN_S390_PREFIX "LINUX"
+#define NN_S390_LAST_BREAK "LINUX"
+#define NN_S390_SYSTEM_CALL "LINUX"
+#define NN_S390_TDB "LINUX"
+#define NN_S390_VXRS_LOW "LINUX"
+#define NN_S390_VXRS_HIGH "LINUX"
+#define NN_S390_GS_CB "LINUX"
+#define NN_S390_GS_BC "LINUX"
+#define NN_S390_RI_CB "LINUX"
+#define NN_S390_PV_CPU_DATA "LINUX"
+#define NN_ARM_VFP "LINUX"
+#define NN_ARM_TLS "LINUX"
+#define NN_ARM_HW_BREAK "LINUX"
+#define NN_ARM_HW_WATCH "LINUX"
+#define NN_ARM_SYSTEM_CALL "LINUX"
+#define NN_ARM_SVE "LINUX"
+#define NN_ARM_PAC_MASK "LINUX"
+#define NN_ARM_PACA_KEYS "LINUX"
+#define NN_ARM_PACG_KEYS "LINUX"
+#define NN_ARM_TAGGED_ADDR_CTRL "LINUX"
+#define NN_ARM_PAC_ENABLED_KEYS "LINUX"
+#define NN_ARM_SSVE "LINUX"
+#define NN_ARM_ZA "LINUX"
+#define NN_ARM_ZT "LINUX"
+#define NN_ARM_FPMR "LINUX"
+#define NN_ARM_POE "LINUX"
+#define NN_ARM_GCS "LINUX"
+#define NN_ARC_V2 "LINUX"
+#define NN_VMCOREDD "LINUX"
+#define NN_MIPS_DSP "LINUX"
+#define NN_MIPS_FP_MODE "LINUX"
+#define NN_MIPS_MSA "LINUX"
+#define NN_RISCV_CSR "LINUX"
+#define NN_RISCV_VECTOR "LINUX"
+#define NN_RISCV_TAGGED_ADDR_CTRL "LINUX"
+#define NN_LOONGARCH_CPUCFG "LINUX"
+#define NN_LOONGARCH_CSR "LINUX"
+#define NN_LOONGARCH_LSX "LINUX"
+#define NN_LOONGARCH_LASX "LINUX"
+#define NN_LOONGARCH_LBT "LINUX"
+#define NN_LOONGARCH_HW_BREAK "LINUX"
+#define NN_LOONGARCH_HW_WATCH "LINUX"
+#define NN_GNU_PROPERTY_TYPE_0 "GNU"
+
/* Note header in a PT_NOTE section */
typedef struct elf32_note {
Elf32_Word n_namesz; /* Name size */
--
2.47.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 2/5] binfmt_elf: Use note name macros
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 1/5] " Akihiko Odaki
@ 2025-01-04 14:38 ` Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 3/5] powwerpc: " Akihiko Odaki
` (4 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Akihiko Odaki @ 2025-01-04 14:38 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Baoquan He, Vivek Goyal, Dave Young
Cc: linux-mm, linux-kernel, linuxppc-dev, linux-s390, kexec, devel,
Akihiko Odaki
Use note name macros to match with the userspace's expectation.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
fs/binfmt_elf.c | 21 ++++++++++-----------
fs/binfmt_elf_fdpic.c | 8 ++++----
2 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 106f0e8af177..5b4a92e5e508 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -762,8 +762,7 @@ static int parse_elf_property(const char *data, size_t *off, size_t datasz,
}
#define NOTE_DATA_SZ SZ_1K
-#define GNU_PROPERTY_TYPE_0_NAME "GNU"
-#define NOTE_NAME_SZ (sizeof(GNU_PROPERTY_TYPE_0_NAME))
+#define NOTE_NAME_SZ (sizeof(NN_GNU_PROPERTY_TYPE_0))
static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr,
struct arch_elf_state *arch)
@@ -800,7 +799,7 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr,
if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 ||
note.nhdr.n_namesz != NOTE_NAME_SZ ||
strncmp(note.data + sizeof(note.nhdr),
- GNU_PROPERTY_TYPE_0_NAME, n - sizeof(note.nhdr)))
+ NN_GNU_PROPERTY_TYPE_0, n - sizeof(note.nhdr)))
return -ENOEXEC;
off = round_up(sizeof(note.nhdr) + NOTE_NAME_SZ,
@@ -1603,14 +1602,14 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
do
i += 2;
while (auxv[i - 2] != AT_NULL);
- fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
+ fill_note(note, NN_AUXV, NT_AUXV, i * sizeof(elf_addr_t), auxv);
}
static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
const kernel_siginfo_t *siginfo)
{
copy_siginfo_to_external(csigdata, siginfo);
- fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
+ fill_note(note, NN_SIGINFO, NT_SIGINFO, sizeof(*csigdata), csigdata);
}
/*
@@ -1706,7 +1705,7 @@ static int fill_files_note(struct memelfnote *note, struct coredump_params *cprm
}
size = name_curpos - (char *)data;
- fill_note(note, "CORE", NT_FILE, size, data);
+ fill_note(note, NN_FILE, NT_FILE, size, data);
return 0;
}
@@ -1767,7 +1766,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
regset_get(t->task, &view->regsets[0],
sizeof(t->prstatus.pr_reg), &t->prstatus.pr_reg);
- fill_note(&t->notes[0], "CORE", NT_PRSTATUS,
+ fill_note(&t->notes[0], NN_PRSTATUS, NT_PRSTATUS,
PRSTATUS_SIZE, &t->prstatus);
info->size += notesize(&t->notes[0]);
@@ -1801,7 +1800,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
if (is_fpreg)
SET_PR_FPVALID(&t->prstatus);
- fill_note(&t->notes[note_iter], is_fpreg ? "CORE" : "LINUX",
+ fill_note(&t->notes[note_iter], is_fpreg ? NN_PRFPREG : "LINUX",
note_type, ret, data);
info->size += notesize(&t->notes[note_iter]);
@@ -1821,7 +1820,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
fill_prstatus(&t->prstatus.common, p, signr);
elf_core_copy_task_regs(p, &t->prstatus.pr_reg);
- fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus),
+ fill_note(&t->notes[0], NN_PRSTATUS, NT_PRSTATUS, sizeof(t->prstatus),
&(t->prstatus));
info->size += notesize(&t->notes[0]);
@@ -1832,7 +1831,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
}
t->prstatus.pr_fpvalid = 1;
- fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(*fpu), fpu);
+ fill_note(&t->notes[1], NN_PRFPREG, NT_PRFPREG, sizeof(*fpu), fpu);
info->size += notesize(&t->notes[1]);
return 1;
@@ -1852,7 +1851,7 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
if (!psinfo)
return 0;
- fill_note(&info->psinfo, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
+ fill_note(&info->psinfo, NN_PRPSINFO, NT_PRPSINFO, sizeof(*psinfo), psinfo);
#ifdef CORE_DUMP_USE_REGSET
view = task_user_regset_view(dump_task);
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index f1a7c4875c4a..96bd9d2f23d7 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -1397,7 +1397,7 @@ static struct elf_thread_status *elf_dump_thread_status(long signr, struct task_
regset_get(p, &view->regsets[0],
sizeof(t->prstatus.pr_reg), &t->prstatus.pr_reg);
- fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus),
+ fill_note(&t->notes[0], NN_PRSTATUS, NT_PRSTATUS, sizeof(t->prstatus),
&t->prstatus);
t->num_notes++;
*sz += notesize(&t->notes[0]);
@@ -1415,7 +1415,7 @@ static struct elf_thread_status *elf_dump_thread_status(long signr, struct task_
}
if (t->prstatus.pr_fpvalid) {
- fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu),
+ fill_note(&t->notes[1], NN_PRFPREG, NT_PRFPREG, sizeof(t->fpu),
&t->fpu);
t->num_notes++;
*sz += notesize(&t->notes[1]);
@@ -1530,7 +1530,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
*/
fill_psinfo(psinfo, current->group_leader, current->mm);
- fill_note(&psinfo_note, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
+ fill_note(&psinfo_note, NN_PRPSINFO, NT_PRPSINFO, sizeof(*psinfo), psinfo);
thread_status_size += notesize(&psinfo_note);
auxv = (elf_addr_t *) current->mm->saved_auxv;
@@ -1538,7 +1538,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
do
i += 2;
while (auxv[i - 2] != AT_NULL);
- fill_note(&auxv_note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
+ fill_note(&auxv_note, NN_AUXV, NT_AUXV, i * sizeof(elf_addr_t), auxv);
thread_status_size += notesize(&auxv_note);
offset = sizeof(*elf); /* ELF header */
--
2.47.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 3/5] powwerpc: Use note name macros
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 1/5] " Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 2/5] binfmt_elf: Use " Akihiko Odaki
@ 2025-01-04 14:38 ` Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 4/5] crash: " Akihiko Odaki
` (3 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Akihiko Odaki @ 2025-01-04 14:38 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Baoquan He, Vivek Goyal, Dave Young
Cc: linux-mm, linux-kernel, linuxppc-dev, linux-s390, kexec, devel,
Akihiko Odaki
Use note name macros to match with the userspace's expectation.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
arch/powerpc/kernel/fadump.c | 2 +-
arch/powerpc/platforms/powernv/opal-core.c | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 4b371c738213..d44349fe8e2b 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -751,7 +751,7 @@ u32 *__init fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs)
* prstatus.pr_pid = ????
*/
elf_core_copy_regs(&prstatus.pr_reg, regs);
- buf = append_elf_note(buf, CRASH_CORE_NOTE_NAME, NT_PRSTATUS,
+ buf = append_elf_note(buf, NN_PRSTATUS, NT_PRSTATUS,
&prstatus, sizeof(prstatus));
return buf;
}
diff --git a/arch/powerpc/platforms/powernv/opal-core.c b/arch/powerpc/platforms/powernv/opal-core.c
index c9a9b759cc92..a379ff86c120 100644
--- a/arch/powerpc/platforms/powernv/opal-core.c
+++ b/arch/powerpc/platforms/powernv/opal-core.c
@@ -149,7 +149,7 @@ static Elf64_Word *__init auxv_to_elf64_notes(Elf64_Word *buf,
/* end of vector */
bufp[idx++] = cpu_to_be64(AT_NULL);
- buf = append_elf64_note(buf, CRASH_CORE_NOTE_NAME, NT_AUXV,
+ buf = append_elf64_note(buf, NN_AUXV, NT_AUXV,
oc_conf->auxv_buf, AUXV_DESC_SZ);
return buf;
}
@@ -252,7 +252,7 @@ static Elf64_Word * __init opalcore_append_cpu_notes(Elf64_Word *buf)
* crashing CPU's prstatus.
*/
first_cpu_note = buf;
- buf = append_elf64_note(buf, CRASH_CORE_NOTE_NAME, NT_PRSTATUS,
+ buf = append_elf64_note(buf, NN_PRSTATUS, NT_PRSTATUS,
&prstatus, sizeof(prstatus));
for (i = 0; i < oc_conf->num_cpus; i++, bufp += size_per_thread) {
@@ -279,7 +279,7 @@ static Elf64_Word * __init opalcore_append_cpu_notes(Elf64_Word *buf)
fill_prstatus(&prstatus, thread_pir, ®s);
if (thread_pir != oc_conf->crashing_cpu) {
- buf = append_elf64_note(buf, CRASH_CORE_NOTE_NAME,
+ buf = append_elf64_note(buf, NN_PRSTATUS,
NT_PRSTATUS, &prstatus,
sizeof(prstatus));
} else {
@@ -287,7 +287,7 @@ static Elf64_Word * __init opalcore_append_cpu_notes(Elf64_Word *buf)
* Add crashing CPU as the first NT_PRSTATUS note for
* GDB to process the core file appropriately.
*/
- append_elf64_note(first_cpu_note, CRASH_CORE_NOTE_NAME,
+ append_elf64_note(first_cpu_note, NN_PRSTATUS,
NT_PRSTATUS, &prstatus,
sizeof(prstatus));
}
--
2.47.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 4/5] crash: Use note name macros
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
` (2 preceding siblings ...)
2025-01-04 14:38 ` [PATCH v2 3/5] powwerpc: " Akihiko Odaki
@ 2025-01-04 14:38 ` Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 5/5] crash: Remove KEXEC_CORE_NOTE_NAME Akihiko Odaki
` (2 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Akihiko Odaki @ 2025-01-04 14:38 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Baoquan He, Vivek Goyal, Dave Young
Cc: linux-mm, linux-kernel, linuxppc-dev, linux-s390, kexec, devel,
Akihiko Odaki
Use note name macros to match with the userspace's expectation.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
fs/proc/kcore.c | 12 ++++++------
include/linux/vmcore_info.h | 2 +-
kernel/crash_core.c | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index e376f48c4b8b..e5612313b8b4 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -34,8 +34,6 @@
#include <asm/sections.h>
#include "internal.h"
-#define CORE_STR "CORE"
-
#ifndef ELF_CORE_EFLAGS
#define ELF_CORE_EFLAGS 0
#endif
@@ -119,7 +117,9 @@ static size_t get_kcore_size(int *nphdr, size_t *phdrs_len, size_t *notes_len,
*phdrs_len = *nphdr * sizeof(struct elf_phdr);
*notes_len = (4 * sizeof(struct elf_note) +
- 3 * ALIGN(sizeof(CORE_STR), 4) +
+ ALIGN(sizeof(NN_PRSTATUS), 4) +
+ ALIGN(sizeof(NN_PRPSINFO), 4) +
+ ALIGN(sizeof(NN_TASKSTRUCT), 4) +
VMCOREINFO_NOTE_NAME_BYTES +
ALIGN(sizeof(struct elf_prstatus), 4) +
ALIGN(sizeof(struct elf_prpsinfo), 4) +
@@ -444,11 +444,11 @@ static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
goto out;
}
- append_kcore_note(notes, &i, CORE_STR, NT_PRSTATUS, &prstatus,
+ append_kcore_note(notes, &i, NN_PRSTATUS, NT_PRSTATUS, &prstatus,
sizeof(prstatus));
- append_kcore_note(notes, &i, CORE_STR, NT_PRPSINFO, &prpsinfo,
+ append_kcore_note(notes, &i, NN_PRPSINFO, NT_PRPSINFO, &prpsinfo,
sizeof(prpsinfo));
- append_kcore_note(notes, &i, CORE_STR, NT_TASKSTRUCT, current,
+ append_kcore_note(notes, &i, NN_TASKSTRUCT, NT_TASKSTRUCT, current,
arch_task_struct_size);
/*
* vmcoreinfo_size is mostly constant after init time, but it
diff --git a/include/linux/vmcore_info.h b/include/linux/vmcore_info.h
index e1dec1a6a749..1672801fd98c 100644
--- a/include/linux/vmcore_info.h
+++ b/include/linux/vmcore_info.h
@@ -8,7 +8,7 @@
#define CRASH_CORE_NOTE_NAME "CORE"
#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
-#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(CRASH_CORE_NOTE_NAME), 4)
+#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(NN_PRSTATUS), 4)
#define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
/*
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 078fe5bc5a74..335b8425dd4b 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -436,7 +436,7 @@ void crash_save_cpu(struct pt_regs *regs, int cpu)
memset(&prstatus, 0, sizeof(prstatus));
prstatus.common.pr_pid = current->pid;
elf_core_copy_regs(&prstatus.pr_reg, regs);
- buf = append_elf_note(buf, KEXEC_CORE_NOTE_NAME, NT_PRSTATUS,
+ buf = append_elf_note(buf, NN_PRSTATUS, NT_PRSTATUS,
&prstatus, sizeof(prstatus));
final_note(buf);
}
--
2.47.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 5/5] crash: Remove KEXEC_CORE_NOTE_NAME
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
` (3 preceding siblings ...)
2025-01-04 14:38 ` [PATCH v2 4/5] crash: " Akihiko Odaki
@ 2025-01-04 14:38 ` Akihiko Odaki
2025-01-06 14:51 ` Dave Martin
2025-01-06 6:07 ` [PATCH v2 0/5] elf: Define note name macros Baoquan He
2025-01-06 15:23 ` Dave Martin
6 siblings, 1 reply; 15+ messages in thread
From: Akihiko Odaki @ 2025-01-04 14:38 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Baoquan He, Vivek Goyal, Dave Young
Cc: linux-mm, linux-kernel, linuxppc-dev, linux-s390, kexec, devel,
Akihiko Odaki
Now KEXEC_CORE_NOTE_NAME is only used at one place and it does not seem
to provide any value anymore. Replace the remaining usage with the
literal and remove the macro.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
arch/s390/kernel/crash_dump.c | 2 +-
include/linux/kexec.h | 2 --
include/linux/vmcore_info.h | 1 -
3 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
index cd0c93a8fb8b..4a9817489e35 100644
--- a/arch/s390/kernel/crash_dump.c
+++ b/arch/s390/kernel/crash_dump.c
@@ -253,7 +253,7 @@ static const char *nt_name(Elf64_Word type)
const char *name = "LINUX";
if (type == NT_PRPSINFO || type == NT_PRSTATUS || type == NT_PRFPREG)
- name = KEXEC_CORE_NOTE_NAME;
+ name = "CORE";
return name;
}
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index f0e9f8eda7a3..c840431eadda 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -68,8 +68,6 @@ extern note_buf_t __percpu *crash_notes;
#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
#endif
-#define KEXEC_CORE_NOTE_NAME CRASH_CORE_NOTE_NAME
-
/*
* This structure is used to hold the arguments that are used when loading
* kernel binaries.
diff --git a/include/linux/vmcore_info.h b/include/linux/vmcore_info.h
index 1672801fd98c..37e003ae5262 100644
--- a/include/linux/vmcore_info.h
+++ b/include/linux/vmcore_info.h
@@ -6,7 +6,6 @@
#include <linux/elfcore.h>
#include <linux/elf.h>
-#define CRASH_CORE_NOTE_NAME "CORE"
#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(NN_PRSTATUS), 4)
#define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
--
2.47.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] elf: Define note name macros
2025-01-04 14:38 ` [PATCH v2 1/5] " Akihiko Odaki
@ 2025-01-06 2:21 ` Baoquan He
2025-01-06 5:07 ` Akihiko Odaki
2025-01-06 14:39 ` Dave Martin
2025-01-06 16:48 ` Kees Cook
2 siblings, 1 reply; 15+ messages in thread
From: Baoquan He @ 2025-01-06 2:21 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
On 01/04/25 at 11:38pm, Akihiko Odaki wrote:
> elf.h had a comment saying:
> > Notes used in ET_CORE. Architectures export some of the arch register
> > sets using the corresponding note types via the PTRACE_GETREGSET and
> > PTRACE_SETREGSET requests.
> > The note name for these types is "LINUX", except NT_PRFPREG that is
> > named "CORE".
>
> However, NT_PRSTATUS is also named "CORE". It is also unclear what
> "these types" refers to.
>
> To fix these problems, define a name for each note type. The added
> definitions are macros so the kernel and userspace can directly refer to
> them.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 83 insertions(+), 3 deletions(-)
>
> diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
> index b44069d29cec..014b705b97d7 100644
> --- a/include/uapi/linux/elf.h
> +++ b/include/uapi/linux/elf.h
> @@ -372,8 +372,6 @@ typedef struct elf64_shdr {
> * Notes used in ET_CORE. Architectures export some of the arch register sets
> * using the corresponding note types via the PTRACE_GETREGSET and
> * PTRACE_SETREGSET requests.
> - * The note name for these types is "LINUX", except NT_PRFPREG that is named
> - * "CORE".
> */
> #define NT_PRSTATUS 1
> #define NT_PRFPREG 2
> @@ -460,9 +458,91 @@ typedef struct elf64_shdr {
> #define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
> #define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
>
> -/* Note types with note name "GNU" */
> +/* Note used in ET_EXEC and ET_DYN. */
> #define NT_GNU_PROPERTY_TYPE_0 5
>
> +/* Note names */
> +#define NN_PRSTATUS "CORE"
> +#define NN_PRFPREG "CORE"
> +#define NN_PRPSINFO "CORE"
> +#define NN_TASKSTRUCT "CORE"
> +#define NN_AUXV "CORE"
> +#define NN_SIGINFO "CORE"
> +#define NN_FILE "CORE"
> +#define NN_PRXFPREG "LINUX"
No objection to make them clearer. Thanks for the effort.
Wondering where below arch specific macros are used. So you just
added all NN_xxx for the corresponding NT_xxx? Not sure if this is
needed if we don't use them at all in the current kernel.
> +#define NN_PPC_VMX "LINUX"
> +#define NN_PPC_SPE "LINUX"
> +#define NN_PPC_VSX "LINUX"
> +#define NN_PPC_TAR "LINUX"
> +#define NN_PPC_PPR "LINUX"
> +#define NN_PPC_DSCR "LINUX"
> +#define NN_PPC_EBB "LINUX"
> +#define NN_PPC_PMU "LINUX"
> +#define NN_PPC_TM_CGPR "LINUX"
> +#define NN_PPC_TM_CFPR "LINUX"
> +#define NN_PPC_TM_CVMX "LINUX"
> +#define NN_PPC_TM_CVSX "LINUX"
> +#define NN_PPC_TM_SPR "LINUX"
> +#define NN_PPC_TM_CTAR "LINUX"
> +#define NN_PPC_TM_CPPR "LINUX"
> +#define NN_PPC_TM_CDSCR "LINUX"
> +#define NN_PPC_PKEY "LINUX"
> +#define NN_PPC_DEXCR "LINUX"
> +#define NN_PPC_HASHKEYR "LINUX"
> +#define NN_386_TLS "LINUX"
> +#define NN_386_IOPERM "LINUX"
> +#define NN_X86_XSTATE "LINUX"
> +#define NN_X86_SHSTK "LINUX"
> +#define NN_X86_XSAVE_LAYOUT "LINUX"
> +#define NN_S390_HIGH_GPRS "LINUX"
> +#define NN_S390_TIMER "LINUX"
> +#define NN_S390_TODCMP "LINUX"
> +#define NN_S390_TODPREG "LINUX"
> +#define NN_S390_CTRS "LINUX"
> +#define NN_S390_PREFIX "LINUX"
> +#define NN_S390_LAST_BREAK "LINUX"
> +#define NN_S390_SYSTEM_CALL "LINUX"
> +#define NN_S390_TDB "LINUX"
> +#define NN_S390_VXRS_LOW "LINUX"
> +#define NN_S390_VXRS_HIGH "LINUX"
> +#define NN_S390_GS_CB "LINUX"
> +#define NN_S390_GS_BC "LINUX"
> +#define NN_S390_RI_CB "LINUX"
> +#define NN_S390_PV_CPU_DATA "LINUX"
> +#define NN_ARM_VFP "LINUX"
> +#define NN_ARM_TLS "LINUX"
> +#define NN_ARM_HW_BREAK "LINUX"
> +#define NN_ARM_HW_WATCH "LINUX"
> +#define NN_ARM_SYSTEM_CALL "LINUX"
> +#define NN_ARM_SVE "LINUX"
> +#define NN_ARM_PAC_MASK "LINUX"
> +#define NN_ARM_PACA_KEYS "LINUX"
> +#define NN_ARM_PACG_KEYS "LINUX"
> +#define NN_ARM_TAGGED_ADDR_CTRL "LINUX"
> +#define NN_ARM_PAC_ENABLED_KEYS "LINUX"
> +#define NN_ARM_SSVE "LINUX"
> +#define NN_ARM_ZA "LINUX"
> +#define NN_ARM_ZT "LINUX"
> +#define NN_ARM_FPMR "LINUX"
> +#define NN_ARM_POE "LINUX"
> +#define NN_ARM_GCS "LINUX"
> +#define NN_ARC_V2 "LINUX"
> +#define NN_VMCOREDD "LINUX"
> +#define NN_MIPS_DSP "LINUX"
> +#define NN_MIPS_FP_MODE "LINUX"
> +#define NN_MIPS_MSA "LINUX"
> +#define NN_RISCV_CSR "LINUX"
> +#define NN_RISCV_VECTOR "LINUX"
> +#define NN_RISCV_TAGGED_ADDR_CTRL "LINUX"
> +#define NN_LOONGARCH_CPUCFG "LINUX"
> +#define NN_LOONGARCH_CSR "LINUX"
> +#define NN_LOONGARCH_LSX "LINUX"
> +#define NN_LOONGARCH_LASX "LINUX"
> +#define NN_LOONGARCH_LBT "LINUX"
> +#define NN_LOONGARCH_HW_BREAK "LINUX"
> +#define NN_LOONGARCH_HW_WATCH "LINUX"
> +#define NN_GNU_PROPERTY_TYPE_0 "GNU"
> +
> /* Note header in a PT_NOTE section */
> typedef struct elf32_note {
> Elf32_Word n_namesz; /* Name size */
>
> --
> 2.47.1
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] elf: Define note name macros
2025-01-06 2:21 ` Baoquan He
@ 2025-01-06 5:07 ` Akihiko Odaki
2025-01-06 6:06 ` Baoquan He
0 siblings, 1 reply; 15+ messages in thread
From: Akihiko Odaki @ 2025-01-06 5:07 UTC (permalink / raw)
To: Baoquan He
Cc: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
On 2025/01/06 11:21, Baoquan He wrote:
> On 01/04/25 at 11:38pm, Akihiko Odaki wrote:
>> elf.h had a comment saying:
>>> Notes used in ET_CORE. Architectures export some of the arch register
>>> sets using the corresponding note types via the PTRACE_GETREGSET and
>>> PTRACE_SETREGSET requests.
>>> The note name for these types is "LINUX", except NT_PRFPREG that is
>>> named "CORE".
>>
>> However, NT_PRSTATUS is also named "CORE". It is also unclear what
>> "these types" refers to.
>>
>> To fix these problems, define a name for each note type. The added
>> definitions are macros so the kernel and userspace can directly refer to
>> them.
>>
>> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>> ---
>> include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 83 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
>> index b44069d29cec..014b705b97d7 100644
>> --- a/include/uapi/linux/elf.h
>> +++ b/include/uapi/linux/elf.h
>> @@ -372,8 +372,6 @@ typedef struct elf64_shdr {
>> * Notes used in ET_CORE. Architectures export some of the arch register sets
>> * using the corresponding note types via the PTRACE_GETREGSET and
>> * PTRACE_SETREGSET requests.
>> - * The note name for these types is "LINUX", except NT_PRFPREG that is named
>> - * "CORE".
>> */
>> #define NT_PRSTATUS 1
>> #define NT_PRFPREG 2
>> @@ -460,9 +458,91 @@ typedef struct elf64_shdr {
>> #define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
>> #define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
>>
>> -/* Note types with note name "GNU" */
>> +/* Note used in ET_EXEC and ET_DYN. */
>> #define NT_GNU_PROPERTY_TYPE_0 5
>>
>> +/* Note names */
>> +#define NN_PRSTATUS "CORE"
>> +#define NN_PRFPREG "CORE"
>> +#define NN_PRPSINFO "CORE"
>> +#define NN_TASKSTRUCT "CORE"
>> +#define NN_AUXV "CORE"
>> +#define NN_SIGINFO "CORE"
>> +#define NN_FILE "CORE"
>> +#define NN_PRXFPREG "LINUX"
>
> No objection to make them clearer. Thanks for the effort.
>
> Wondering where below arch specific macros are used. So you just
> added all NN_xxx for the corresponding NT_xxx? Not sure if this is
> needed if we don't use them at all in the current kernel.
Indeed I just added all NN_xxx. The kernel won't use the macros that are
defined as "LINUX"; fs/binfmt_elf.c uses "LINUX" by default as the notes
named "CORE" or "GNU" are exceptional.
Userspace applications may still be interested in these macros as
demonstrated in:
https://lore.kernel.org/r/Z3f7zJwu8bu8HYln@e133380.arm.com
These macros also serve as documentation; correcting and clarifying the
documentation is the main purpose of this series.
>
>> +#define NN_PPC_VMX "LINUX"
>> +#define NN_PPC_SPE "LINUX"
>> +#define NN_PPC_VSX "LINUX"
>> +#define NN_PPC_TAR "LINUX"
>> +#define NN_PPC_PPR "LINUX"
>> +#define NN_PPC_DSCR "LINUX"
>> +#define NN_PPC_EBB "LINUX"
>> +#define NN_PPC_PMU "LINUX"
>> +#define NN_PPC_TM_CGPR "LINUX"
>> +#define NN_PPC_TM_CFPR "LINUX"
>> +#define NN_PPC_TM_CVMX "LINUX"
>> +#define NN_PPC_TM_CVSX "LINUX"
>> +#define NN_PPC_TM_SPR "LINUX"
>> +#define NN_PPC_TM_CTAR "LINUX"
>> +#define NN_PPC_TM_CPPR "LINUX"
>> +#define NN_PPC_TM_CDSCR "LINUX"
>> +#define NN_PPC_PKEY "LINUX"
>> +#define NN_PPC_DEXCR "LINUX"
>> +#define NN_PPC_HASHKEYR "LINUX"
>> +#define NN_386_TLS "LINUX"
>> +#define NN_386_IOPERM "LINUX"
>> +#define NN_X86_XSTATE "LINUX"
>> +#define NN_X86_SHSTK "LINUX"
>> +#define NN_X86_XSAVE_LAYOUT "LINUX"
>> +#define NN_S390_HIGH_GPRS "LINUX"
>> +#define NN_S390_TIMER "LINUX"
>> +#define NN_S390_TODCMP "LINUX"
>> +#define NN_S390_TODPREG "LINUX"
>> +#define NN_S390_CTRS "LINUX"
>> +#define NN_S390_PREFIX "LINUX"
>> +#define NN_S390_LAST_BREAK "LINUX"
>> +#define NN_S390_SYSTEM_CALL "LINUX"
>> +#define NN_S390_TDB "LINUX"
>> +#define NN_S390_VXRS_LOW "LINUX"
>> +#define NN_S390_VXRS_HIGH "LINUX"
>> +#define NN_S390_GS_CB "LINUX"
>> +#define NN_S390_GS_BC "LINUX"
>> +#define NN_S390_RI_CB "LINUX"
>> +#define NN_S390_PV_CPU_DATA "LINUX"
>> +#define NN_ARM_VFP "LINUX"
>> +#define NN_ARM_TLS "LINUX"
>> +#define NN_ARM_HW_BREAK "LINUX"
>> +#define NN_ARM_HW_WATCH "LINUX"
>> +#define NN_ARM_SYSTEM_CALL "LINUX"
>> +#define NN_ARM_SVE "LINUX"
>> +#define NN_ARM_PAC_MASK "LINUX"
>> +#define NN_ARM_PACA_KEYS "LINUX"
>> +#define NN_ARM_PACG_KEYS "LINUX"
>> +#define NN_ARM_TAGGED_ADDR_CTRL "LINUX"
>> +#define NN_ARM_PAC_ENABLED_KEYS "LINUX"
>> +#define NN_ARM_SSVE "LINUX"
>> +#define NN_ARM_ZA "LINUX"
>> +#define NN_ARM_ZT "LINUX"
>> +#define NN_ARM_FPMR "LINUX"
>> +#define NN_ARM_POE "LINUX"
>> +#define NN_ARM_GCS "LINUX"
>> +#define NN_ARC_V2 "LINUX"
>> +#define NN_VMCOREDD "LINUX"
>> +#define NN_MIPS_DSP "LINUX"
>> +#define NN_MIPS_FP_MODE "LINUX"
>> +#define NN_MIPS_MSA "LINUX"
>> +#define NN_RISCV_CSR "LINUX"
>> +#define NN_RISCV_VECTOR "LINUX"
>> +#define NN_RISCV_TAGGED_ADDR_CTRL "LINUX"
>> +#define NN_LOONGARCH_CPUCFG "LINUX"
>> +#define NN_LOONGARCH_CSR "LINUX"
>> +#define NN_LOONGARCH_LSX "LINUX"
>> +#define NN_LOONGARCH_LASX "LINUX"
>> +#define NN_LOONGARCH_LBT "LINUX"
>> +#define NN_LOONGARCH_HW_BREAK "LINUX"
>> +#define NN_LOONGARCH_HW_WATCH "LINUX"
>> +#define NN_GNU_PROPERTY_TYPE_0 "GNU"
>> +
>> /* Note header in a PT_NOTE section */
>> typedef struct elf32_note {
>> Elf32_Word n_namesz; /* Name size */
>>
>> --
>> 2.47.1
>>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] elf: Define note name macros
2025-01-06 5:07 ` Akihiko Odaki
@ 2025-01-06 6:06 ` Baoquan He
0 siblings, 0 replies; 15+ messages in thread
From: Baoquan He @ 2025-01-06 6:06 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
On 01/06/25 at 02:07pm, Akihiko Odaki wrote:
> On 2025/01/06 11:21, Baoquan He wrote:
> > On 01/04/25 at 11:38pm, Akihiko Odaki wrote:
> > > elf.h had a comment saying:
> > > > Notes used in ET_CORE. Architectures export some of the arch register
> > > > sets using the corresponding note types via the PTRACE_GETREGSET and
> > > > PTRACE_SETREGSET requests.
> > > > The note name for these types is "LINUX", except NT_PRFPREG that is
> > > > named "CORE".
> > >
> > > However, NT_PRSTATUS is also named "CORE". It is also unclear what
> > > "these types" refers to.
> > >
> > > To fix these problems, define a name for each note type. The added
> > > definitions are macros so the kernel and userspace can directly refer to
> > > them.
> > >
> > > Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> > > ---
> > > include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
> > > 1 file changed, 83 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
> > > index b44069d29cec..014b705b97d7 100644
> > > --- a/include/uapi/linux/elf.h
> > > +++ b/include/uapi/linux/elf.h
> > > @@ -372,8 +372,6 @@ typedef struct elf64_shdr {
> > > * Notes used in ET_CORE. Architectures export some of the arch register sets
> > > * using the corresponding note types via the PTRACE_GETREGSET and
> > > * PTRACE_SETREGSET requests.
> > > - * The note name for these types is "LINUX", except NT_PRFPREG that is named
> > > - * "CORE".
> > > */
> > > #define NT_PRSTATUS 1
> > > #define NT_PRFPREG 2
> > > @@ -460,9 +458,91 @@ typedef struct elf64_shdr {
> > > #define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
> > > #define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
> > > -/* Note types with note name "GNU" */
> > > +/* Note used in ET_EXEC and ET_DYN. */
> > > #define NT_GNU_PROPERTY_TYPE_0 5
> > > +/* Note names */
> > > +#define NN_PRSTATUS "CORE"
> > > +#define NN_PRFPREG "CORE"
> > > +#define NN_PRPSINFO "CORE"
> > > +#define NN_TASKSTRUCT "CORE"
> > > +#define NN_AUXV "CORE"
> > > +#define NN_SIGINFO "CORE"
> > > +#define NN_FILE "CORE"
> > > +#define NN_PRXFPREG "LINUX"
> >
> > No objection to make them clearer. Thanks for the effort.
> >
> > Wondering where below arch specific macros are used. So you just
> > added all NN_xxx for the corresponding NT_xxx? Not sure if this is
> > needed if we don't use them at all in the current kernel.
>
> Indeed I just added all NN_xxx. The kernel won't use the macros that are
> defined as "LINUX"; fs/binfmt_elf.c uses "LINUX" by default as the notes
> named "CORE" or "GNU" are exceptional.
>
> Userspace applications may still be interested in these macros as
> demonstrated in:
> https://lore.kernel.org/r/Z3f7zJwu8bu8HYln@e133380.arm.com
>
> These macros also serve as documentation; correcting and clarifying the
> documentation is the main purpose of this series.
I see, thanks. Then the overall series looks good to me.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 0/5] elf: Define note name macros
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
` (4 preceding siblings ...)
2025-01-04 14:38 ` [PATCH v2 5/5] crash: Remove KEXEC_CORE_NOTE_NAME Akihiko Odaki
@ 2025-01-06 6:07 ` Baoquan He
2025-01-06 15:23 ` Dave Martin
6 siblings, 0 replies; 15+ messages in thread
From: Baoquan He @ 2025-01-06 6:07 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Dave Martin, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
On 01/04/25 at 11:38pm, Akihiko Odaki wrote:
> elf.h had a comment saying:
> > Notes used in ET_CORE. Architectures export some of the arch register
> > sets using the corresponding note types via the PTRACE_GETREGSET and
> > PTRACE_SETREGSET requests.
> > The note name for these types is "LINUX", except NT_PRFPREG that is
> > named "CORE".
>
> However, NT_PRSTATUS is also named "CORE". It is also unclear what
> "these types" refers to.
>
> To fix these problems, define a name for each note type. The added
> definitions are macros so the kernel and userspace can directly refer to
> them.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> Changes in v2:
> - Added a macro definition for each note type instead of trying to
> describe in a comment.
> - Link to v1: https://lore.kernel.org/r/20241225-elf-v1-1-79e940350d50@daynix.com
The entire patchset looks good to me, thx.
Acked-by: Baoquan He <bhe@redhat.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] elf: Define note name macros
2025-01-04 14:38 ` [PATCH v2 1/5] " Akihiko Odaki
2025-01-06 2:21 ` Baoquan He
@ 2025-01-06 14:39 ` Dave Martin
2025-01-06 16:48 ` Kees Cook
2 siblings, 0 replies; 15+ messages in thread
From: Dave Martin @ 2025-01-06 14:39 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Baoquan He, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
On Sat, Jan 04, 2025 at 11:38:34PM +0900, Akihiko Odaki wrote:
> elf.h had a comment saying:
> > Notes used in ET_CORE. Architectures export some of the arch register
> > sets using the corresponding note types via the PTRACE_GETREGSET and
> > PTRACE_SETREGSET requests.
> > The note name for these types is "LINUX", except NT_PRFPREG that is
> > named "CORE".
>
> However, NT_PRSTATUS is also named "CORE". It is also unclear what
> "these types" refers to.
>
> To fix these problems, define a name for each note type. The added
> definitions are macros so the kernel and userspace can directly refer to
> them.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 83 insertions(+), 3 deletions(-)
>
> diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
> index b44069d29cec..014b705b97d7 100644
> --- a/include/uapi/linux/elf.h
> +++ b/include/uapi/linux/elf.h
> @@ -372,8 +372,6 @@ typedef struct elf64_shdr {
> * Notes used in ET_CORE. Architectures export some of the arch register sets
> * using the corresponding note types via the PTRACE_GETREGSET and
> * PTRACE_SETREGSET requests.
> - * The note name for these types is "LINUX", except NT_PRFPREG that is named
> - * "CORE".
Maybe most people would find it obvious, but is it worth saying what
the NT_ and NN_ macros are for? They can easily be explained in terms
of the elfXX_note struct fields.
> */
> #define NT_PRSTATUS 1
> #define NT_PRFPREG 2
> @@ -460,9 +458,91 @@ typedef struct elf64_shdr {
> #define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
> #define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
>
> -/* Note types with note name "GNU" */
> +/* Note used in ET_EXEC and ET_DYN. */
May just "other notes"? I think that the comment might bitrot
over time.
> #define NT_GNU_PROPERTY_TYPE_0 5
>
> +/* Note names */
> +#define NN_PRSTATUS "CORE"
Can these be interleaved with the NT_ definitions? I think this would
make the resulting header (and the diff) easier to read.
> +#define NN_PRFPREG "CORE"
[...]
> +#define NN_GNU_PROPERTY_TYPE_0 "GNU"
[...]
Cheers
---Dave
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 5/5] crash: Remove KEXEC_CORE_NOTE_NAME
2025-01-04 14:38 ` [PATCH v2 5/5] crash: Remove KEXEC_CORE_NOTE_NAME Akihiko Odaki
@ 2025-01-06 14:51 ` Dave Martin
0 siblings, 0 replies; 15+ messages in thread
From: Dave Martin @ 2025-01-06 14:51 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Baoquan He, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
Hi,
On Sat, Jan 04, 2025 at 11:38:38PM +0900, Akihiko Odaki wrote:
> Now KEXEC_CORE_NOTE_NAME is only used at one place and it does not seem
> to provide any value anymore. Replace the remaining usage with the
> literal and remove the macro.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> arch/s390/kernel/crash_dump.c | 2 +-
> include/linux/kexec.h | 2 --
> include/linux/vmcore_info.h | 1 -
> 3 files changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
> index cd0c93a8fb8b..4a9817489e35 100644
> --- a/arch/s390/kernel/crash_dump.c
> +++ b/arch/s390/kernel/crash_dump.c
> @@ -253,7 +253,7 @@ static const char *nt_name(Elf64_Word type)
> const char *name = "LINUX";
>
> if (type == NT_PRPSINFO || type == NT_PRSTATUS || type == NT_PRFPREG)
> - name = KEXEC_CORE_NOTE_NAME;
> + name = "CORE";
If I've understood the code here correctly, the note type is supplied
at all the nt_init() and nt_size() call sites, so instead of this hack
can we wrap those in macros that get the formal name from elf.h rather
than guessing it here? e.g.:
#define nt_size(..., note, ...) \
__nt_size(..., NT ## _ ## note, NN ## _ ## note, ...)
etc.
The compiler is quite likely to fold away most of the implied
duplication of code (it would be interesting to look at the compiler
output) -- but anyway, this is super-slow-path: nobody expects realtime
response when the kernel has crashed.
[...]
Cheers
---Dave
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 0/5] elf: Define note name macros
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
` (5 preceding siblings ...)
2025-01-06 6:07 ` [PATCH v2 0/5] elf: Define note name macros Baoquan He
@ 2025-01-06 15:23 ` Dave Martin
6 siblings, 0 replies; 15+ messages in thread
From: Dave Martin @ 2025-01-06 15:23 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Eric Biederman, Kees Cook, Catalin Marinas, Mark Brown,
Baoquan He, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
Hi,
On Sat, Jan 04, 2025 at 11:38:33PM +0900, Akihiko Odaki wrote:
> elf.h had a comment saying:
> > Notes used in ET_CORE. Architectures export some of the arch register
> > sets using the corresponding note types via the PTRACE_GETREGSET and
> > PTRACE_SETREGSET requests.
> > The note name for these types is "LINUX", except NT_PRFPREG that is
> > named "CORE".
>
> However, NT_PRSTATUS is also named "CORE". It is also unclear what
> "these types" refers to.
>
> To fix these problems, define a name for each note type. The added
> definitions are macros so the kernel and userspace can directly refer to
> them.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Should this be Cc'd at least to the GNU binutils or gdb folks?
Also the glibc and elfutils projects, both of which maintain a version
of elf.h. They may have their own view on the best way to approach
this issue.
If cross-posting to other project mailing lists, it might make sense to
add a bit more background explaining the motivation for the change.
[...]
Cheers
---Dave
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] elf: Define note name macros
2025-01-04 14:38 ` [PATCH v2 1/5] " Akihiko Odaki
2025-01-06 2:21 ` Baoquan He
2025-01-06 14:39 ` Dave Martin
@ 2025-01-06 16:48 ` Kees Cook
2025-01-06 17:23 ` Dave Martin
2 siblings, 1 reply; 15+ messages in thread
From: Kees Cook @ 2025-01-06 16:48 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Eric Biederman, Catalin Marinas, Mark Brown, Dave Martin,
Baoquan He, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
On Sat, Jan 04, 2025 at 11:38:34PM +0900, Akihiko Odaki wrote:
> elf.h had a comment saying:
> > Notes used in ET_CORE. Architectures export some of the arch register
> > sets using the corresponding note types via the PTRACE_GETREGSET and
> > PTRACE_SETREGSET requests.
> > The note name for these types is "LINUX", except NT_PRFPREG that is
> > named "CORE".
>
> However, NT_PRSTATUS is also named "CORE". It is also unclear what
> "these types" refers to.
>
> To fix these problems, define a name for each note type. The added
> definitions are macros so the kernel and userspace can directly refer to
> them.
While ELF is specified in the Tool Interface Standard[1], the core dump
format doesn't have an official specification. It does follow a lot of
agreed rules, though, and the "note name" is intended to help coredump
consumers distinguish between "common" things ("CORE") and Linux-specific
things ("LINUX").
I think this should be explicitly spelled out in the UAPI header,
even if we have "mistakes" for this mapping.
I'm not convinced we need these macros, though: everything is "LINUX"
expect the common types. And the GNU types are "GNU". There are only 7
types under the "CORE" name. :)
For the macros, I'd much prefer NN_CORE, NN_LINUX, and NN_GNU.
If you really want to be able to examine the name from the type, then
yeah, I guess we need something like the macros you have, but I'd much
prefer also adding a macro like Dave suggested[2], and then replace the
fill_note() with a macro that can unwrap it:
fill_note(note, NT_SIGINFO, size..., data...);
The repetition of NN_type, NT_type doesn't feel robust if we have a
programmatic mapping: only the "type" is needed to determine both, so
why supply both?
-Kees
[1] https://refspecs.linuxfoundation.org/elf/elf.pdf
[2] https://lore.kernel.org/lkml/Z3vuBTiQvnRvv9DQ@e133380.arm.com/
--
Kees Cook
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/5] elf: Define note name macros
2025-01-06 16:48 ` Kees Cook
@ 2025-01-06 17:23 ` Dave Martin
0 siblings, 0 replies; 15+ messages in thread
From: Dave Martin @ 2025-01-06 17:23 UTC (permalink / raw)
To: Kees Cook
Cc: Akihiko Odaki, Eric Biederman, Catalin Marinas, Mark Brown,
Baoquan He, Vivek Goyal, Dave Young, linux-mm, linux-kernel,
linuxppc-dev, linux-s390, kexec, devel
Hi all,
On Mon, Jan 06, 2025 at 08:48:05AM -0800, Kees Cook wrote:
> On Sat, Jan 04, 2025 at 11:38:34PM +0900, Akihiko Odaki wrote:
> > elf.h had a comment saying:
> > > Notes used in ET_CORE. Architectures export some of the arch register
> > > sets using the corresponding note types via the PTRACE_GETREGSET and
> > > PTRACE_SETREGSET requests.
> > > The note name for these types is "LINUX", except NT_PRFPREG that is
> > > named "CORE".
> >
> > However, NT_PRSTATUS is also named "CORE". It is also unclear what
> > "these types" refers to.
> >
> > To fix these problems, define a name for each note type. The added
> > definitions are macros so the kernel and userspace can directly refer to
> > them.
>
> While ELF is specified in the Tool Interface Standard[1], the core dump
> format doesn't have an official specification. It does follow a lot of
> agreed rules, though, and the "note name" is intended to help coredump
> consumers distinguish between "common" things ("CORE") and Linux-specific
> things ("LINUX").
>
> I think this should be explicitly spelled out in the UAPI header,
> even if we have "mistakes" for this mapping.
This seems reasonable.
> I'm not convinced we need these macros, though: everything is "LINUX"
> expect the common types. And the GNU types are "GNU". There are only 7
> types under the "CORE" name. :)
My starting point for suggesting the new macros was that the current
usage seems to be a historical accident; there doesn't seem to be an
underlying logic to it, except that arch-independent core note types
defined by Linux are named "CORE" ... except when they aren't.
Although the number of exceptional cases is small today, this doesn't
make for a robust rule -- nothing really prevents more unintentional
anomalies being added in future, so it seems prone to bitrot.
If the names are arbitrary, having a table rather than trying to
describe a rule seems the best way to avoid confusion.
Documenting these in a regular way may also encourage people to treat
the name as a formal part of the identifier, rather than a sort of
"comment" that nobody is quite sure what to do with (even if [1] makes
it clear).
That said, software does cope with the situation today; it's just a bit
gross.
>
> For the macros, I'd much prefer NN_CORE, NN_LINUX, and NN_GNU.
What would be the point of these?
#define NN_CORE "CORE" doesn't convey any information at all, though I
suppose it does provide a layer of typo-resistance.
> If you really want to be able to examine the name from the type, then
> yeah, I guess we need something like the macros you have, but I'd much
> prefer also adding a macro like Dave suggested[2], and then replace the
> fill_note() with a macro that can unwrap it:
>
> fill_note(note, NT_SIGINFO, size..., data...);
>
> The repetition of NN_type, NT_type doesn't feel robust if we have a
> programmatic mapping: only the "type" is needed to determine both, so
> why supply both?
>
> -Kees
>
> [1] https://refspecs.linuxfoundation.org/elf/elf.pdf
> [2] https://lore.kernel.org/lkml/Z3vuBTiQvnRvv9DQ@e133380.arm.com/
Although not "robust", it should at least be obvious to the eye of
anyone pasting and repurposing an existing snippet of code that the
"type" is probably supposed to match in a single call.
I suppose we could have a kernel helper function containing a big
switch that gives you the name for each recognised note type though.
At the source code level, that would avoid specifying the "NN_"
arguments explicitly. But if we still want a canonical way to describe
this mapping in elf.h, the "NN_" macros still serve a purpose.
With a literal string instead, I would expect then when adapting
fill_note(note, NT_SIGINFO, "CORE", ...)
to
fill_note(note, NT_WIZZFOO, ???, ...)
it's not clear what ??? should be. I think people have tended to shrug
and just leave it unchanged -- so, it depends on which bit of code was
randomly chosen to serve as a template. I could be guessing wrongly
about that, but if that's how the name gets chosen for new notes then
it doesn't feel ideal.
Cheers
---Dave
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-01-06 17:24 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-04 14:38 [PATCH v2 0/5] elf: Define note name macros Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 1/5] " Akihiko Odaki
2025-01-06 2:21 ` Baoquan He
2025-01-06 5:07 ` Akihiko Odaki
2025-01-06 6:06 ` Baoquan He
2025-01-06 14:39 ` Dave Martin
2025-01-06 16:48 ` Kees Cook
2025-01-06 17:23 ` Dave Martin
2025-01-04 14:38 ` [PATCH v2 2/5] binfmt_elf: Use " Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 3/5] powwerpc: " Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 4/5] crash: " Akihiko Odaki
2025-01-04 14:38 ` [PATCH v2 5/5] crash: Remove KEXEC_CORE_NOTE_NAME Akihiko Odaki
2025-01-06 14:51 ` Dave Martin
2025-01-06 6:07 ` [PATCH v2 0/5] elf: Define note name macros Baoquan He
2025-01-06 15:23 ` Dave Martin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox