]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/fpu: Remove the thread::fpu pointer
authorIngo Molnar <mingo@kernel.org>
Wed, 9 Apr 2025 21:11:23 +0000 (23:11 +0200)
committerIngo Molnar <mingo@kernel.org>
Mon, 14 Apr 2025 06:18:29 +0000 (08:18 +0200)
As suggested by Oleg, remove the thread::fpu pointer, as we can
calculate it via x86_task_fpu() at compile-time.

This improves code generation a bit:

   kepler:~/tip> size vmlinux.before vmlinux.after
   text        data        bss        dec         hex        filename
   26475405    10435342    1740804    38651551    24dc69f    vmlinux.before
   26475339    10959630    1216516    38651485    24dc65d    vmlinux.after

Suggested-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Chang S. Bae <chang.seok.bae@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Uros Bizjak <ubizjak@gmail.com>
Link: https://lore.kernel.org/r/20250409211127.3544993-5-mingo@kernel.org
arch/x86/include/asm/processor.h
arch/x86/kernel/fpu/core.c
arch/x86/kernel/fpu/init.c
arch/x86/kernel/process.c
arch/x86/kernel/vmlinux.lds.S

index 5ea7e5d2c4de07af6b602498c8c745b0398e2d76..b7f7c9c83409824a85208f7713fe3cd04307cdf7 100644 (file)
@@ -514,12 +514,9 @@ struct thread_struct {
 
        struct thread_shstk     shstk;
 #endif
-
-       /* Floating point and extended processor state */
-       struct fpu              *fpu;
 };
 
-#define x86_task_fpu(task) ((task)->thread.fpu)
+#define x86_task_fpu(task)     ((struct fpu *)((void *)(task) + sizeof(*(task))))
 
 /*
  * X86 doesn't need any embedded-FPU-struct quirks:
index 853a738fdf2d36e3a9532917f5a660ef0a902f5a..974b276ff0da230a22573b1674a969ef21006d70 100644 (file)
@@ -600,13 +600,11 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
         * This is safe because task_struct size is a multiple of cacheline size.
         */
        struct fpu *src_fpu = x86_task_fpu(current);
-       struct fpu *dst_fpu = (void *)dst + sizeof(*dst);
+       struct fpu *dst_fpu = x86_task_fpu(dst);
 
        BUILD_BUG_ON(sizeof(*dst) % SMP_CACHE_BYTES != 0);
        BUG_ON(!src_fpu);
 
-       dst->thread.fpu = dst_fpu;
-
        /* The new task's FPU state cannot be valid in the hardware. */
        dst_fpu->last_cpu = -1;
 
index 848ea79886bac44418cce476ea9809551e2f4a77..da41a1d2c40f40a0d17d4c8490a6eecc64d897fb 100644 (file)
@@ -76,7 +76,6 @@ static struct fpu x86_init_fpu __attribute__ ((aligned (64))) __read_mostly;
 static void __init fpu__init_system_early_generic(void)
 {
        fpstate_reset(&x86_init_fpu);
-       current->thread.fpu = &x86_init_fpu;
        set_thread_flag(TIF_NEED_FPU_LOAD);
        x86_init_fpu.last_cpu = -1;
 
index 3ce4cce46f3f51d055e7b8856bfee202cc7b8b1f..88868a90459e9b5c30eecd420ba69c5e79475f7d 100644 (file)
@@ -102,8 +102,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 #ifdef CONFIG_VM86
        dst->thread.vm86 = NULL;
 #endif
-       /* Drop the copied pointer to current's fpstate */
-       dst->thread.fpu = NULL;
 
        return 0;
 }
index ccdc45e5b75961711580f62cb2a73f48c1c433c5..d9ca2d1754dafc3d01f34b46af1eb8f183373b8b 100644 (file)
@@ -181,6 +181,10 @@ SECTIONS
                /* equivalent to task_pt_regs(&init_task) */
                __top_init_kernel_stack = __end_init_stack - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE;
 
+               __x86_init_fpu_begin = .;
+               . = __x86_init_fpu_begin + 128*PAGE_SIZE;
+               __x86_init_fpu_end = .;
+
 #ifdef CONFIG_X86_32
                /* 32 bit has nosave before _edata */
                NOSAVE_DATA