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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'x86-fpu-2024-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fpu updates from Thomas Gleixner:
"Provide FPU buffer layout in core dumps:

Debuggers have guess the FPU buffer layout in core dumps, which is
error prone. This is because AMD and Intel layouts differ.

To avoid buggy heuristics add a ELF section which describes the buffer
layout which can be retrieved by tools"

* tag 'x86-fpu-2024-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/elf: Add a new FPU buffer layout info to x86 core files

+109 -2
+1
arch/x86/Kconfig
··· 107 107 select ARCH_HAS_DEBUG_WX 108 108 select ARCH_HAS_ZONE_DMA_SET if EXPERT 109 109 select ARCH_HAVE_NMI_SAFE_CMPXCHG 110 + select ARCH_HAVE_EXTRA_ELF_NOTES 110 111 select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE 111 112 select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI 112 113 select ARCH_MIGHT_HAVE_PC_PARPORT
+16
arch/x86/include/uapi/asm/elf.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 + #ifndef _UAPI_ASM_X86_ELF_H 3 + #define _UAPI_ASM_X86_ELF_H 4 + 5 + #include <linux/types.h> 6 + 7 + struct x86_xfeat_component { 8 + __u32 type; 9 + __u32 size; 10 + __u32 offset; 11 + __u32 flags; 12 + } __packed; 13 + 14 + _Static_assert(sizeof(struct x86_xfeat_component) % 4 == 0, "x86_xfeat_component is not aligned"); 15 + 16 + #endif /* _UAPI_ASM_X86_ELF_H */
+89
arch/x86/kernel/fpu/xstate.c
··· 13 13 #include <linux/seq_file.h> 14 14 #include <linux/proc_fs.h> 15 15 #include <linux/vmalloc.h> 16 + #include <linux/coredump.h> 16 17 17 18 #include <asm/fpu/api.h> 18 19 #include <asm/fpu/regset.h> ··· 23 22 #include <asm/tlbflush.h> 24 23 #include <asm/prctl.h> 25 24 #include <asm/elf.h> 25 + 26 + #include <uapi/asm/elf.h> 26 27 27 28 #include "context.h" 28 29 #include "internal.h" ··· 1844 1841 return 0; 1845 1842 } 1846 1843 #endif /* CONFIG_PROC_PID_ARCH_STATUS */ 1844 + 1845 + #ifdef CONFIG_COREDUMP 1846 + static const char owner_name[] = "LINUX"; 1847 + 1848 + /* 1849 + * Dump type, size, offset and flag values for every xfeature that is present. 1850 + */ 1851 + static int dump_xsave_layout_desc(struct coredump_params *cprm) 1852 + { 1853 + int num_records = 0; 1854 + int i; 1855 + 1856 + for_each_extended_xfeature(i, fpu_user_cfg.max_features) { 1857 + struct x86_xfeat_component xc = { 1858 + .type = i, 1859 + .size = xstate_sizes[i], 1860 + .offset = xstate_offsets[i], 1861 + /* reserved for future use */ 1862 + .flags = 0, 1863 + }; 1864 + 1865 + if (!dump_emit(cprm, &xc, sizeof(xc))) 1866 + return 0; 1867 + 1868 + num_records++; 1869 + } 1870 + return num_records; 1871 + } 1872 + 1873 + static u32 get_xsave_desc_size(void) 1874 + { 1875 + u32 cnt = 0; 1876 + u32 i; 1877 + 1878 + for_each_extended_xfeature(i, fpu_user_cfg.max_features) 1879 + cnt++; 1880 + 1881 + return cnt * (sizeof(struct x86_xfeat_component)); 1882 + } 1883 + 1884 + int elf_coredump_extra_notes_write(struct coredump_params *cprm) 1885 + { 1886 + int num_records = 0; 1887 + struct elf_note en; 1888 + 1889 + if (!fpu_user_cfg.max_features) 1890 + return 0; 1891 + 1892 + en.n_namesz = sizeof(owner_name); 1893 + en.n_descsz = get_xsave_desc_size(); 1894 + en.n_type = NT_X86_XSAVE_LAYOUT; 1895 + 1896 + if (!dump_emit(cprm, &en, sizeof(en))) 1897 + return 1; 1898 + if (!dump_emit(cprm, owner_name, en.n_namesz)) 1899 + return 1; 1900 + if (!dump_align(cprm, 4)) 1901 + return 1; 1902 + 1903 + num_records = dump_xsave_layout_desc(cprm); 1904 + if (!num_records) 1905 + return 1; 1906 + 1907 + /* Total size should be equal to the number of records */ 1908 + if ((sizeof(struct x86_xfeat_component) * num_records) != en.n_descsz) 1909 + return 1; 1910 + 1911 + return 0; 1912 + } 1913 + 1914 + int elf_coredump_extra_notes_size(void) 1915 + { 1916 + int size; 1917 + 1918 + if (!fpu_user_cfg.max_features) 1919 + return 0; 1920 + 1921 + /* .note header */ 1922 + size = sizeof(struct elf_note); 1923 + /* Name plus alignment to 4 bytes */ 1924 + size += roundup(sizeof(owner_name), 4); 1925 + size += get_xsave_desc_size(); 1926 + 1927 + return size; 1928 + } 1929 + #endif /* CONFIG_COREDUMP */
+2 -2
fs/binfmt_elf.c
··· 2039 2039 { 2040 2040 size_t sz = info.size; 2041 2041 2042 - /* For cell spufs */ 2042 + /* For cell spufs and x86 xstate */ 2043 2043 sz += elf_coredump_extra_notes_size(); 2044 2044 2045 2045 phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL); ··· 2103 2103 if (!write_note_info(&info, cprm)) 2104 2104 goto end_coredump; 2105 2105 2106 - /* For cell spufs */ 2106 + /* For cell spufs and x86 xstate */ 2107 2107 if (elf_coredump_extra_notes_write(cprm)) 2108 2108 goto end_coredump; 2109 2109
+1
include/uapi/linux/elf.h
··· 411 411 #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ 412 412 /* Old binutils treats 0x203 as a CET state */ 413 413 #define NT_X86_SHSTK 0x204 /* x86 SHSTK state */ 414 + #define NT_X86_XSAVE_LAYOUT 0x205 /* XSAVE layout description */ 414 415 #define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ 415 416 #define NT_S390_TIMER 0x301 /* s390 timer register */ 416 417 #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */