From nobody Fri Dec 19 12:50:32 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BA192580EE; Mon, 14 Apr 2025 07:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744616090; cv=none; b=pUa7/bfZ5maR9HiYOxZ25yLnHEBHcxzV5DIrrXGNAy5gLUZeYSJE5RSCTEZXrd7kCyPEHPagHmz/SDhL/5wMtdusi57mw4GFboyF55Ps65EQgu5EsBunzLMR6ZinIj7WK4EPcOXFIEtwvaWW69YRAeG9KJafsuZjMRmiwglBVv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744616090; c=relaxed/simple; bh=2AqFaaVVlBvEZiwu6OujEy+cmoPolG+hfLrABeNwABw=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=Xp+ot7HFNbDboW4zn3jyukehiEsh2nc54UAufJLG4UX70DueNNTcBmPDR9B0jsm0yeFXT/KLaBPBCusAMLmSPR6OEbbcfvzDoyUt2auA+TOVf7379Tr9wc++ugjwe981xKwQUix9oHq4xbljnp34CmONj7TkFKdg7mKkQqVtqkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=n/NL8SpA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7gUO4Nft; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="n/NL8SpA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7gUO4Nft" Date: Mon, 14 Apr 2025 07:34:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744616086; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ZqD7RUr1PuLIwugMQKUQuYjk3Dp0V/kEJsTkWo1oZo=; b=n/NL8SpA8HUnH8EA7cAEAvOOKuSChREyb+flC5kMMwLKXELo5h1kZXoW91d0Qz1ekqti8J AaUx7QLOUnGsrq2TacYZgmCmqmGjDgAF2S8yIub3o92x+F+LMsI44ozzTfpwX1IC1hIPm3 6bxznaadbYcXx4GDUu1tveCrnnFpdCIxhVqshjaCzHSvuoLbICIECQEgrPCeWYtCu7yvKR QJlvfvhU99zUKlVzvSSdIDB5XrWOnvDiNRXchEDn0GUfOQTd7QOGHnwZwnCJShEachASbu ygYnRCoeXoxmYbyXdhjs0zvhjHCw+x0qA11Cgzs16rfvDCFi2Sbv3nMz4/XGZg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744616086; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ZqD7RUr1PuLIwugMQKUQuYjk3Dp0V/kEJsTkWo1oZo=; b=7gUO4Nftp/YVN08xxuo/aJkMDk1G/YA7OaSqpUESokSzZMxBZEkBTxaP4fcXxmgwnHvia+ 56AkFkl07Lf6+XBg== From: "tip-bot2 for Ingo Molnar" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/merge] x86/fpu: Remove init_task FPU state dependencies, add debugging warning for PF_KTHREAD tasks Cc: Ingo Molnar , Andy Lutomirski , Brian Gerst , "Chang S. Bae" , Fenghua Yu , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Peter Zijlstra , Uros Bizjak , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250409211127.3544993-8-mingo@kernel.org> References: <20250409211127.3544993-8-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174461608607.31282.3975145232708711882.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/merge branch of tip: Commit-ID: 22aafe3bcb67472effdea1ccf0df20280192bbaf Gitweb: https://git.kernel.org/tip/22aafe3bcb67472effdea1ccf0df20280= 192bbaf Author: Ingo Molnar AuthorDate: Wed, 09 Apr 2025 23:11:26 +02:00 Committer: Ingo Molnar CommitterDate: Mon, 14 Apr 2025 08:18:29 +02:00 x86/fpu: Remove init_task FPU state dependencies, add debugging warning for= PF_KTHREAD tasks init_task's FPU state initialization was a bit of a hack: __x86_init_fpu_begin =3D .; . =3D __x86_init_fpu_begin + 128*PAGE_SIZE; __x86_init_fpu_end =3D .; But the init task isn't supposed to be using the FPU context in any case, so remove the hack and add in some debug warnings. As Linus noted in the discussion, the init task (and other PF_KTHREAD tasks) *can* use the FPU via kernel_fpu_begin()/_end(), but they don't need the context area because their FPU use is not preemptible or reentrant, and they don't return to user-space. Signed-off-by: Ingo Molnar Cc: Andy Lutomirski Cc: Brian Gerst Cc: Chang S. Bae Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Uros Bizjak Link: https://lore.kernel.org/r/20250409211127.3544993-8-mingo@kernel.org --- arch/x86/include/asm/processor.h | 6 +++++- arch/x86/kernel/fpu/core.c | 15 +++++++++++---- arch/x86/kernel/fpu/init.c | 3 +-- arch/x86/kernel/fpu/xstate.c | 3 --- arch/x86/kernel/vmlinux.lds.S | 4 ---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index b7f7c9c..eaa7214 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -516,7 +516,11 @@ struct thread_struct { #endif }; =20 -#define x86_task_fpu(task) ((struct fpu *)((void *)(task) + sizeof(*(task)= ))) +#ifdef CONFIG_X86_DEBUG_FPU +extern struct fpu *x86_task_fpu(struct task_struct *task); +#else +# define x86_task_fpu(task) ((struct fpu *)((void *)(task) + sizeof(*(task= )))) +#endif =20 /* * X86 doesn't need any embedded-FPU-struct quirks: diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 4a21938..4d1a205 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -51,6 +51,16 @@ static DEFINE_PER_CPU(bool, in_kernel_fpu); */ DEFINE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx); =20 +#ifdef CONFIG_X86_DEBUG_FPU +struct fpu *x86_task_fpu(struct task_struct *task) +{ + if (WARN_ON_ONCE(task->flags & PF_KTHREAD)) + return NULL; + + return (void *)task + sizeof(*task); +} +#endif + /* * Can we use the FPU in kernel mode with the * whole "kernel_fpu_begin/end()" sequence? @@ -599,11 +609,9 @@ int fpu_clone(struct task_struct *dst, unsigned long c= lone_flags, bool minimal, * * This is safe because task_struct size is a multiple of cacheline size. */ - struct fpu *src_fpu =3D x86_task_fpu(current); - struct fpu *dst_fpu =3D x86_task_fpu(dst); + struct fpu *dst_fpu =3D (void *)dst + sizeof(*dst); =20 BUILD_BUG_ON(sizeof(*dst) % SMP_CACHE_BYTES !=3D 0); - BUG_ON(!src_fpu); =20 /* The new task's FPU state cannot be valid in the hardware. */ dst_fpu->last_cpu =3D -1; @@ -666,7 +674,6 @@ int fpu_clone(struct task_struct *dst, unsigned long cl= one_flags, bool minimal, if (update_fpu_shstk(dst, ssp)) return 1; =20 - trace_x86_fpu_copy_src(src_fpu); trace_x86_fpu_copy_dst(dst_fpu); =20 return 0; diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index da41a1d..16b6611 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -38,7 +38,7 @@ static void fpu__init_cpu_generic(void) /* Flush out any pending x87 state: */ #ifdef CONFIG_MATH_EMULATION if (!boot_cpu_has(X86_FEATURE_FPU)) - fpstate_init_soft(&x86_task_fpu(current)->fpstate->regs.soft); + ; else #endif asm volatile ("fninit"); @@ -207,7 +207,6 @@ static void __init fpu__init_system_xstate_size_legacy(= void) fpu_kernel_cfg.default_size =3D size; fpu_user_cfg.max_size =3D size; fpu_user_cfg.default_size =3D size; - fpstate_reset(x86_task_fpu(current)); } =20 /* diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 253da5a..4c771b9 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -870,9 +870,6 @@ void __init fpu__init_system_xstate(unsigned int legacy= _size) if (err) goto out_disable; =20 - /* Reset the state for the current task */ - fpstate_reset(x86_task_fpu(current)); - /* * Update info used for ptrace frames; use standard-format size and no * supervisor xstates: diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index d9ca2d1..ccdc45e 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -181,10 +181,6 @@ SECTIONS /* equivalent to task_pt_regs(&init_task) */ __top_init_kernel_stack =3D __end_init_stack - TOP_OF_KERNEL_STACK_PADDI= NG - PTREGS_SIZE; =20 - __x86_init_fpu_begin =3D .; - . =3D __x86_init_fpu_begin + 128*PAGE_SIZE; - __x86_init_fpu_end =3D .; - #ifdef CONFIG_X86_32 /* 32 bit has nosave before _edata */ NOSAVE_DATA