Skip to contentSkip to conversation

elf: Define note name macros

PATCH Superseded Akihiko Odaki 4 participants 15 messages Jan 4, 2025 – Jan 6, 2025

Subsystems (11)
Memory management VFS PowerPC s390 +7 more subsystems

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover elf: Define note name macros

elf.h had a comment saying:

Quoted 5 lines

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.

---
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/[email protected]

---
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,

Signature · 1 line
Akihiko Odaki <[email protected]>
#1 lore raw

PATCH v2 1/5 elf: Define note name macros

elf.h had a comment saying:

Quoted 5 lines

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.

---
 include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 83 insertions(+), 3 deletions(-)
include/uapi/linux/elf.h +83 -3
index b44069d29cec..014b705b97d7 100644
@@ -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 */
Signature · 1 line
2.47.1
#2 lore raw
Quoted 39 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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.

---
 include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 83 insertions(+), 3 deletions(-)
include/uapi/linux/elf.h +1 -3
index b44069d29cec..014b705b97d7 100644
@@ -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

include/uapi/linux/elf.h typedef struct elf64_shdr { · line 472

Quoted 10 lines
include/uapi/linux/elf.h +9 -0
 
+/* 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.

Quoted 80 lines
include/uapi/linux/elf.h +73 -0
+#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 */
Signature · 2 lines
-- 
2.47.1
#3 lore raw
Quoted 53 lines · Baoquan He
Quoted 39 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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.

---
  include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
  1 file changed, 83 insertions(+), 3 deletions(-)
include/uapi/linux/elf.h +1 -3
index b44069d29cec..014b705b97d7 100644
@@ -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

include/uapi/linux/elf.h typedef struct elf64_shdr { · line 472

Quoted 10 lines
include/uapi/linux/elf.h +9 -0
 
+/* 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.

Quoted 3 lines

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/[email protected]

These macros also serve as documentation; correcting and clarifying the documentation is the main purpose of this series.

Quoted 82 lines
Quoted 81 lines
include/uapi/linux/elf.h +73 -0
+#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 */
Signature · 2 lines
-- 
2.47.1
#4 lore raw
Quoted 60 lines · Akihiko Odaki
Quoted 51 lines · Baoquan He
Quoted 37 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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.

---
  include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
  1 file changed, 83 insertions(+), 3 deletions(-)
include/uapi/linux/elf.h +1 -3
index b44069d29cec..014b705b97d7 100644
@@ -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. */

include/uapi/linux/elf.h typedef struct elf64_shdr { · line 470

Quoted 10 lines
include/uapi/linux/elf.h +9 -0
  #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.

Quoted 3 lines

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.

Quoted 6 lines

Userspace applications may still be interested in these macros as demonstrated in:
https://lore.kernel.org/r/[email protected]

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.

#5 lore raw
In reply to Akihiko Odaki
Quoted 24 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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.

---
 include/uapi/linux/elf.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 83 insertions(+), 3 deletions(-)
include/uapi/linux/elf.h +0 -0
index b44069d29cec..014b705b97d7 100644

include/uapi/linux/elf.h typedef struct elf64_shdr { · line 376

Quoted 5 lines
include/uapi/linux/elf.h +0 -2
@@ -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.

include/uapi/linux/elf.h typedef struct elf64_shdr { · line 461

Quoted 9 lines
include/uapi/linux/elf.h +1 -1
  */
 #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.

include/uapi/linux/elf.h typedef struct elf64_shdr { · line 465

Quoted 4 lines
include/uapi/linux/elf.h +2 -0
 #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.

Quoted 1 line
include/uapi/linux/elf.h +1 -0
+#define NN_PRFPREG	"CORE"

[...]

Quoted 1 line

+#define NN_GNU_PROPERTY_TYPE_0 "GNU"

[...]

Cheers
---Dave

maintainer
#6 lore raw
In reply to Akihiko Odaki
Quoted 7 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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".

Quoted 6 lines

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/[email protected]/

Signature · 1 line
Kees Cook
#7 lore raw

Hi all,

Quoted 15 lines · Kees Cook
Quoted 7 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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".

Quoted 6 lines

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.

Quoted 8 lines

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.

Quoted 3 lines

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.

Quoted 2 lines

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.

Quoted 7 lines

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...);
Quoted 8 lines

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/[email protected]/

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

#8 lore raw

PATCH v2 2/5 binfmt_elf: Use note name macros

In reply to Akihiko Odaki

Use note name macros to match with the userspace's expectation.

---
 fs/binfmt_elf.c       | 21 ++++++++++-----------
 fs/binfmt_elf_fdpic.c |  8 ++++----
 2 files changed, 14 insertions(+), 15 deletions(-)
fs/binfmt_elf.c +10 -11
index 106f0e8af177..5b4a92e5e508 100644
@@ -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);
fs/binfmt_elf_fdpic.c +4 -4
index f1a7c4875c4a..96bd9d2f23d7 100644
@@ -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 */
Signature · 1 line
2.47.1
#9 lore raw

PATCH v2 3/5 powwerpc: Use note name macros

In reply to Akihiko Odaki

Use note name macros to match with the userspace's expectation.

---
 arch/powerpc/kernel/fadump.c               | 2 +-
 arch/powerpc/platforms/powernv/opal-core.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/kernel/fadump.c +1 -1
index 4b371c738213..d44349fe8e2b 100644
@@ -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;
 }
arch/powerpc/platforms/powernv/opal-core.c +4 -4
index c9a9b759cc92..a379ff86c120 100644
@@ -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, &regs);
 
 		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));
 		}
Signature · 1 line
2.47.1
#10 lore raw

PATCH v2 4/5 crash: Use note name macros

In reply to Akihiko Odaki

Use note name macros to match with the userspace's expectation.

---
 fs/proc/kcore.c             | 12 ++++++------
 include/linux/vmcore_info.h |  2 +-
 kernel/crash_core.c         |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)
fs/proc/kcore.c +6 -6
index e376f48c4b8b..e5612313b8b4 100644
@@ -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
include/linux/vmcore_info.h +1 -1
index e1dec1a6a749..1672801fd98c 100644
@@ -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)
 
 /*
kernel/crash_core.c +1 -1
index 078fe5bc5a74..335b8425dd4b 100644
@@ -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);
 }
Signature · 1 line
2.47.1
#11 lore raw

PATCH v2 5/5 crash: Remove KEXEC_CORE_NOTE_NAME

In reply to 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.

---
 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(-)
arch/s390/kernel/crash_dump.c +1 -1
index cd0c93a8fb8b..4a9817489e35 100644
@@ -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;
 }
 
include/linux/kexec.h +0 -2
index f0e9f8eda7a3..c840431eadda 100644
@@ -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.
include/linux/vmcore_info.h +0 -1
index 1672801fd98c..37e003ae5262 100644
@@ -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)
Signature · 1 line
2.47.1
#12 lore raw

Re: [PATCH v2 5/5] crash: Remove KEXEC_CORE_NOTE_NAME

Hi,

Quoted 16 lines · 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.

---
 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(-)
arch/s390/kernel/crash_dump.c +0 -0
index cd0c93a8fb8b..4a9817489e35 100644

arch/s390/kernel/crash_dump.c static const char *nt_name(Elf64_Word type) · line 256

Quoted 5 lines
arch/s390/kernel/crash_dump.c +1 -1
@@ -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

Acked-by on the v2 series
#13 lore raw
In reply to Akihiko Odaki
Quoted 14 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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.

Quoted 6 lines

---
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/[email protected]

The entire patchset looks good to me, thx.

#14 lore raw
In reply to Akihiko Odaki

Hi,

Quoted 7 lines · Akihiko Odaki

elf.h had a comment saying:

Quoted 5 lines

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".

Quoted 8 lines

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.

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