linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] x86/fpu: don't abuse x86_task_fpu(PF_USER_WORKER) in .regset_get() paths
@ 2025-08-22 15:36 Oleg Nesterov
  2025-08-22 15:36 ` [PATCH v2 1/5] x86/fpu: don't use x86_task_fpu() in copy_xstate_to_uabi_buf() Oleg Nesterov
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Oleg Nesterov @ 2025-08-22 15:36 UTC (permalink / raw)
  To: Borislav Petkov, Dave Hansen, Deepak Gupta, H. Peter Anvin,
	Ingo Molnar, Mark Brown, Peter Zijlstra, Rick Edgecombe,
	Sohil Mehta, Thomas Gleixner
  Cc: linux-kernel, x86

PF_USER_WORKER threads don't really differ from PF_KTHREAD threads
at least in that they never return to usermode and never use their
FPU state.

However, ptrace or coredump paths can access their FPU state and this
is the only reason why x86_task_fpu(PF_USER_WORKER) needs to work and
and discriminate PF_USER_WORKER from PF_KTHREAD. Unlike all other x86
FPU code paths which do not distinguish them.

OTOH, arch/x86/kernel/fpu/regset.c doesn't really need "struct fpu *",
the .regset_get() functions actually need a "struct fpstate *". If the
target task is PF_USER_WORKER, they can safely use &init_fpstate. So
this series adds the new simple helper

	static struct fpstate *get_fpstate(struct task_struct *task)
	{
		struct fpu *fpu;

		if (unlikely(task->flags & PF_USER_WORKER))
			return &init_fpstate;

		fpu = x86_task_fpu(task);
		if (task == current)
			fpu_sync_fpstate(fpu);
		return fpu->fpstate;
	}

which can be used instead of x86_task_fpu(task)->fpstate pattern in
arch/x86/kernel/fpu/regset.c.

However, there is an annoying complication: shstk_alloc_thread_stack()
can alloc the pointless shadow stack for PF_USER_WORKER thread and set
the ARCH_SHSTK_SHSTK flag. This means that ssp_get()->ssp_active() can
return true, and in this case it wouldn't be right to use the "unrelated"
init_fpstate.

That is why this series includes 4/5, and to me it looks like a cleanup
which makes sense regardless.

Link to V1: https://lore.kernel.org/all/20250814101340.GA17288@redhat.com/

Changes:

	- improve the subject/changelog in 1/5

	- drop "x86/shstk: add "task_struct *tsk" argument to reset_thread_features()"

	- rework 4/5 to not use reset_thread_features()

TODO:
	update the fpregs_soft_get() and user_regset.set() paths as well

Oleg.
---

 arch/x86/include/asm/shstk.h |  4 ++--
 arch/x86/kernel/fpu/regset.c | 46 ++++++++++++++++++++++++++------------------
 arch/x86/kernel/fpu/xstate.c | 12 ++++++------
 arch/x86/kernel/fpu/xstate.h |  4 ++--
 arch/x86/kernel/process.c    |  2 +-
 arch/x86/kernel/shstk.c      |  9 +++++++--
 6 files changed, 45 insertions(+), 32 deletions(-)


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2025-09-04 13:46 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 15:36 [PATCH v2 0/5] x86/fpu: don't abuse x86_task_fpu(PF_USER_WORKER) in .regset_get() paths Oleg Nesterov
2025-08-22 15:36 ` [PATCH v2 1/5] x86/fpu: don't use x86_task_fpu() in copy_xstate_to_uabi_buf() Oleg Nesterov
2025-08-22 15:36 ` [PATCH v2 2/5] x86/fpu: regset: introduce get_fpstate() helper Oleg Nesterov
2025-08-22 15:36 ` [PATCH v2 3/5] x86/fpu: fold sync_fpstate() into get_fpstate() Oleg Nesterov
2025-08-22 15:37 ` [PATCH v2 4/5] x86/shstk: don't create the shadow stack for PF_USER_WORKERs Oleg Nesterov
2025-08-22 15:37 ` [PATCH v2 5/5] x86/fpu: change get_fpstate() to return &init_fpstate if PF_USER_WORKER Oleg Nesterov
2025-08-22 16:32 ` [PATCH v2 0/5] x86/fpu: don't abuse x86_task_fpu(PF_USER_WORKER) in .regset_get() paths Edgecombe, Rick P
2025-08-22 19:21   ` Oleg Nesterov
2025-08-22 20:01     ` Edgecombe, Rick P
2025-08-25 13:47       ` Oleg Nesterov
2025-08-27 14:12         ` Edgecombe, Rick P
2025-08-27 14:51           ` Oleg Nesterov
2025-08-28 21:48             ` Edgecombe, Rick P
2025-08-29 15:06               ` Oleg Nesterov
2025-09-02 20:37                 ` Edgecombe, Rick P
2025-09-03  9:54                   ` Oleg Nesterov
2025-09-03 15:46                     ` Edgecombe, Rick P
2025-09-04 13:44                       ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).