Message ID | 20240712094630.29757-2-vigbalas@amd.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Add XSAVE layout description to Core files for debuggers to support varying XSAVE layouts | expand |
On Fri, Jul 12 2024 at 15:16, Vignesh Balasubramanian wrote: > diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h > index 1fb83d477..cad37090b 100644 > --- a/arch/x86/include/asm/elf.h > +++ b/arch/x86/include/asm/elf.h > @@ -13,6 +13,15 @@ > #include <asm/auxvec.h> > #include <asm/fsgsbase.h> > > +struct xfeat_component { > + u32 type; > + u32 size; > + u32 offset; > + u32 flags; > +} __packed; > + > +_Static_assert(sizeof(struct xfeat_component)%4 == 0, "xfeat_component is not aligned"); This struct is only used in xstate.c and asm/elf.h is not a UAPI header. So what's the point of declaring it in the header instead of xtsate.c? If this needs to provided for user space consumption, then it want's to be in a UAPI header, no? Thanks, tglx
On 7/13/2024 4:12 PM, Thomas Gleixner wrote: > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > On Fri, Jul 12 2024 at 15:16, Vignesh Balasubramanian wrote: >> diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h >> index 1fb83d477..cad37090b 100644 >> --- a/arch/x86/include/asm/elf.h >> +++ b/arch/x86/include/asm/elf.h >> @@ -13,6 +13,15 @@ >> #include <asm/auxvec.h> >> #include <asm/fsgsbase.h> >> >> +struct xfeat_component { >> + u32 type; >> + u32 size; >> + u32 offset; >> + u32 flags; >> +} __packed; >> + >> +_Static_assert(sizeof(struct xfeat_component)%4 == 0, "xfeat_component is not aligned"); > This struct is only used in xstate.c and asm/elf.h is not a UAPI > header. So what's the point of declaring it in the header instead of > xtsate.c? > > If this needs to provided for user space consumption, then it want's to > be in a UAPI header, no? Our initial idea is to pass the "struct xfeat_component" through "glibc". is "include/uapi/linux/elf.h" proper header to add this ? I couldn't see any proper header inside "arch/x86/include/uapi/asm/". Please advise. thanks, vigneshbalu > Thanks, > > tglx
On Wed, Jul 17, 2024 at 03:02:23PM +0530, Balasubrmanian, Vignesh wrote: > > On 7/13/2024 4:12 PM, Thomas Gleixner wrote: > > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > > > > On Fri, Jul 12 2024 at 15:16, Vignesh Balasubramanian wrote: > > > diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h > > > index 1fb83d477..cad37090b 100644 > > > --- a/arch/x86/include/asm/elf.h > > > +++ b/arch/x86/include/asm/elf.h > > > @@ -13,6 +13,15 @@ > > > #include <asm/auxvec.h> > > > #include <asm/fsgsbase.h> > > > > > > +struct xfeat_component { > > > + u32 type; > > > + u32 size; > > > + u32 offset; > > > + u32 flags; > > > +} __packed; > > > + > > > +_Static_assert(sizeof(struct xfeat_component)%4 == 0, "xfeat_component is not aligned"); > > This struct is only used in xstate.c and asm/elf.h is not a UAPI > > header. So what's the point of declaring it in the header instead of > > xtsate.c? > > > > If this needs to provided for user space consumption, then it want's to > > be in a UAPI header, no? > Our initial idea is to pass the "struct xfeat_component" through "glibc". > is "include/uapi/linux/elf.h" proper header to add this ? I'd rather not put arch-specific things in the main UAPI elf.h file unless there is a good reason. > I couldn't see any proper header inside "arch/x86/include/uapi/asm/". Other architectures have arch/*/include/uapi/asm/elf.h, so it may be time to add one for x86 too. For this to be UAPI, I would want to see more explicit namespacing, e.g. struct x86_xfeat_component, etc. -Kees
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1d7122a18..0ea43da0b 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -107,6 +107,7 @@ config X86 select ARCH_HAS_DEBUG_WX select ARCH_HAS_ZONE_DMA_SET if EXPERT select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_EXTRA_ELF_NOTES select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI select ARCH_MIGHT_HAVE_PC_PARPORT diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index 1fb83d477..cad37090b 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -13,6 +13,15 @@ #include <asm/auxvec.h> #include <asm/fsgsbase.h> +struct xfeat_component { + u32 type; + u32 size; + u32 offset; + u32 flags; +} __packed; + +_Static_assert(sizeof(struct xfeat_component)%4 == 0, "xfeat_component is not aligned"); + typedef unsigned long elf_greg_t; #define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t)) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index c5a026fee..5d59f390c 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -13,6 +13,7 @@ #include <linux/seq_file.h> #include <linux/proc_fs.h> #include <linux/vmalloc.h> +#include <linux/coredump.h> #include <asm/fpu/api.h> #include <asm/fpu/regset.h> @@ -1838,3 +1839,89 @@ int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns, return 0; } #endif /* CONFIG_PROC_PID_ARCH_STATUS */ + +#ifdef CONFIG_COREDUMP +static const char owner_name[] = "LINUX"; + +/* + * Dump type, size, offset and flag values for every xfeature that is present. + */ +static int dump_xsave_layout_desc(struct coredump_params *cprm) +{ + int num_records = 0; + int i; + + for_each_extended_xfeature(i, fpu_user_cfg.max_features) { + struct xfeat_component xc = { + .type = i, + .size = xstate_sizes[i], + .offset = xstate_offsets[i], + /* reserved for future use */ + .flags = 0, + }; + + if (!dump_emit(cprm, &xc, sizeof(xc))) + return 0; + + num_records++; + } + return num_records; +} + +static u32 get_xsave_desc_size(void) +{ + u32 cnt = 0; + u32 i; + + for_each_extended_xfeature(i, fpu_user_cfg.max_features) + cnt++; + + return cnt * (sizeof(struct xfeat_component)); +} + +int elf_coredump_extra_notes_write(struct coredump_params *cprm) +{ + int num_records = 0; + struct elf_note en; + + if (!fpu_user_cfg.max_features) + return 0; + + en.n_namesz = sizeof(owner_name); + en.n_descsz = get_xsave_desc_size(); + en.n_type = NT_X86_XSAVE_LAYOUT; + + if (!dump_emit(cprm, &en, sizeof(en))) + return 1; + if (!dump_emit(cprm, owner_name, en.n_namesz)) + return 1; + if (!dump_align(cprm, 4)) + return 1; + + num_records = dump_xsave_layout_desc(cprm); + if (!num_records) + return 1; + + /* Total size should be equal to the number of records */ + if ((sizeof(struct xfeat_component) * num_records) != en.n_descsz) + return 1; + + return 0; +} + +int elf_coredump_extra_notes_size(void) +{ + int size; + + if (!fpu_user_cfg.max_features) + return 0; + + /* .note header */ + size = sizeof(struct elf_note); + /* Name plus alignment to 4 bytes */ + size += roundup(sizeof(owner_name), 4); + size += get_xsave_desc_size(); + + return size; +} +#endif /* CONFIG_COREDUMP */ diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index a43897b03..3d15c7369 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -2006,7 +2006,7 @@ static int elf_core_dump(struct coredump_params *cprm) { size_t sz = info.size; - /* For cell spufs */ + /* For cell spufs and x86 xstate */ sz += elf_coredump_extra_notes_size(); phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL); @@ -2070,7 +2070,7 @@ static int elf_core_dump(struct coredump_params *cprm) if (!write_note_info(&info, cprm)) goto end_coredump; - /* For cell spufs */ + /* For cell spufs and x86 xstate */ if (elf_coredump_extra_notes_write(cprm)) goto end_coredump; diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h index b54b313bc..e30a9b47d 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -411,6 +411,7 @@ typedef struct elf64_shdr { #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ /* Old binutils treats 0x203 as a CET state */ #define NT_X86_SHSTK 0x204 /* x86 SHSTK state */ +#define NT_X86_XSAVE_LAYOUT 0x205 /* XSAVE layout description */ #define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ #define NT_S390_TIMER 0x301 /* s390 timer register */ #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */