From: Oleg Nesterov <oleg@redhat.com>
To: Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Deepak Gupta <debug@rivosinc.com>,
"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@kernel.org>,
Mark Brown <broonie@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Sohil Mehta <sohil.mehta@intel.com>,
Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org
Subject: [PATCH v2 2/5] x86/fpu: regset: introduce get_fpstate() helper
Date: Fri, 22 Aug 2025 17:36:46 +0200 [thread overview]
Message-ID: <20250822153646.GA27144@redhat.com> (raw)
In-Reply-To: <20250822153603.GA27103@redhat.com>
After the previous change the regset get() functions do not really need
"struct fpu *", they can use "struct fpstate *" returned by the new helper
which also does sync_fpstate().
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
arch/x86/kernel/fpu/regset.c | 42 ++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c
index d280d415b171..f5a803774e1c 100644
--- a/arch/x86/kernel/fpu/regset.c
+++ b/arch/x86/kernel/fpu/regset.c
@@ -49,6 +49,13 @@ static void sync_fpstate(struct fpu *fpu)
fpu_sync_fpstate(fpu);
}
+static struct fpstate *get_fpstate(struct task_struct *task)
+{
+ struct fpu *fpu = x86_task_fpu(task);
+ sync_fpstate(fpu);
+ return fpu->fpstate;
+}
+
/*
* Invalidate cached FPU registers before modifying the stopped target
* task's fpstate.
@@ -71,19 +78,19 @@ static void fpu_force_restore(struct fpu *fpu)
int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
struct membuf to)
{
- struct fpu *fpu = x86_task_fpu(target);
+ struct fpstate *fpstate;
if (!cpu_feature_enabled(X86_FEATURE_FXSR))
return -ENODEV;
- sync_fpstate(fpu);
+ fpstate = get_fpstate(target);
if (!use_xsave()) {
- return membuf_write(&to, &fpu->fpstate->regs.fxsave,
- sizeof(fpu->fpstate->regs.fxsave));
+ return membuf_write(&to, &fpstate->regs.fxsave,
+ sizeof(fpstate->regs.fxsave));
}
- copy_xstate_to_uabi_buf(to, fpu->fpstate, target->thread.pkru, XSTATE_COPY_FX);
+ copy_xstate_to_uabi_buf(to, fpstate, target->thread.pkru, XSTATE_COPY_FX);
return 0;
}
@@ -130,14 +137,13 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
struct membuf to)
{
- struct fpu *fpu = x86_task_fpu(target);
+ struct fpstate *fpstate;
if (!cpu_feature_enabled(X86_FEATURE_XSAVE))
return -ENODEV;
- sync_fpstate(fpu);
-
- copy_xstate_to_uabi_buf(to, fpu->fpstate, target->thread.pkru, XSTATE_COPY_XSAVE);
+ fpstate = get_fpstate(target);
+ copy_xstate_to_uabi_buf(to, fpstate, target->thread.pkru, XSTATE_COPY_XSAVE);
return 0;
}
@@ -189,15 +195,15 @@ int ssp_active(struct task_struct *target, const struct user_regset *regset)
int ssp_get(struct task_struct *target, const struct user_regset *regset,
struct membuf to)
{
- struct fpu *fpu = x86_task_fpu(target);
+ struct fpstate *fpstate;
struct cet_user_state *cetregs;
if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK) ||
!ssp_active(target, regset))
return -ENODEV;
- sync_fpstate(fpu);
- cetregs = get_xsave_addr(&fpu->fpstate->regs.xsave, XFEATURE_CET_USER);
+ fpstate = get_fpstate(target);
+ cetregs = get_xsave_addr(&fpstate->regs.xsave, XFEATURE_CET_USER);
if (WARN_ON(!cetregs)) {
/*
* This shouldn't ever be NULL because shadow stack was
@@ -403,17 +409,17 @@ void convert_to_fxsr(struct fxregs_state *fxsave,
int fpregs_get(struct task_struct *target, const struct user_regset *regset,
struct membuf to)
{
- struct fpu *fpu = x86_task_fpu(target);
+ struct fpstate *fpstate;
struct user_i387_ia32_struct env;
struct fxregs_state fxsave, *fx;
- sync_fpstate(fpu);
-
if (!cpu_feature_enabled(X86_FEATURE_FPU))
return fpregs_soft_get(target, regset, to);
+ fpstate = get_fpstate(target);
+
if (!cpu_feature_enabled(X86_FEATURE_FXSR)) {
- return membuf_write(&to, &fpu->fpstate->regs.fsave,
+ return membuf_write(&to, &fpstate->regs.fsave,
sizeof(struct fregs_state));
}
@@ -421,10 +427,10 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
struct membuf mb = { .p = &fxsave, .left = sizeof(fxsave) };
/* Handle init state optimized xstate correctly */
- copy_xstate_to_uabi_buf(mb, fpu->fpstate, target->thread.pkru, XSTATE_COPY_FP);
+ copy_xstate_to_uabi_buf(mb, fpstate, target->thread.pkru, XSTATE_COPY_FP);
fx = &fxsave;
} else {
- fx = &fpu->fpstate->regs.fxsave;
+ fx = &fpstate->regs.fxsave;
}
__convert_from_fxsr(&env, target, fx);
--
2.25.1.362.g51ebf55
next prev parent reply other threads:[~2025-08-22 15:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Oleg Nesterov [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250822153646.GA27144@redhat.com \
--to=oleg@redhat.com \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=debug@rivosinc.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=sohil.mehta@intel.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®