lkml.org 
[lkml]   [2021]   [Jun]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] x86/fpu: Improve FPU APIs for independent features
Date
Having the functions that save and restore independent features accept,
but ignore, non-independent features is confusing, so instead require
that only independent features be independently saved and restored.

Remove a bunch of nonsense comments from the save and restore functions:
saving and restoring the XSAVE header makes no sense.

Document that fpu__clear_all() does not clear independent features.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
arch/x86/include/asm/fpu/xstate.h | 5 ++++-
arch/x86/kernel/fpu/core.c | 3 +++
arch/x86/kernel/fpu/xstate.c | 33 +++++++++++--------------------
3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h
index 5802b1715c7f..3bc5e6c9e47a 100644
--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -34,7 +34,10 @@
XFEATURE_MASK_BNDREGS | \
XFEATURE_MASK_BNDCSR)

-/* All currently supported supervisor features */
+/*
+ * All currently supported supervisor features that are saved and
+ * restored as part of the main task XSAVE buffers.
+ */
#define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID)

/*
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 571220ac8bea..9af361464c66 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -390,6 +390,9 @@ void fpu__clear_user_states(struct fpu *fpu)
fpu__clear(fpu, true);
}

+/*
+ * This does not affect independent features -- see XFEATURE_MASK_INDEPENDENT.
+ */
void fpu__clear_all(struct fpu *fpu)
{
fpu__clear(fpu, false);
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index d582275164ad..15bb87f4f510 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1292,29 +1292,26 @@ void copy_supervisor_to_kernel(struct xregs_state *xstate)
* @xstate: A pointer to an xsave area
* @mask: Represent the independent supervisor features saved into the xsave area
*
- * Only the independent supervisor states sets in the mask are saved into the xsave
- * area (See the comment in XFEATURE_MASK_INDEPENDENT for the details of independent
- * supervisor feature). Besides the independent supervisor states, the legacy
- * region and XSAVE header are also saved into the xsave area. The supervisor
- * features in the XFEATURE_MASK_SUPERVISOR_SUPPORTED and
- * XFEATURE_MASK_SUPERVISOR_UNSUPPORTED are not saved.
+ * The XSAVE header in the target buffer must already be initialized, as the
+ * XSAVES instruction may not fully initialize the XSAVE header.
*
* The xsave area must be 64-bytes aligned.
*/
void copy_independent_supervisor_to_kernel(struct xregs_state *xstate, u64 mask)
{
- u64 independent_mask = xfeatures_mask_independent() & mask;
u32 lmask, hmask;
int err;

+ WARN_ON_FPU(mask & ~xfeatures_mask_independent());
+
if (WARN_ON_FPU(!boot_cpu_has(X86_FEATURE_XSAVES)))
return;

- if (WARN_ON_FPU(!independent_mask))
+ if (WARN_ON_FPU(!mask))
return;

- lmask = independent_mask;
- hmask = independent_mask >> 32;
+ lmask = mask;
+ hmask = mask >> 32;

XSTATE_OP(XSAVES, xstate, lmask, hmask, err);

@@ -1328,29 +1325,23 @@ void copy_independent_supervisor_to_kernel(struct xregs_state *xstate, u64 mask)
* @xstate: A pointer to an xsave area
* @mask: Represent the independent supervisor features restored from the xsave area
*
- * Only the independent supervisor states sets in the mask are restored from the
- * xsave area (See the comment in XFEATURE_MASK_INDEPENDENT for the details of
- * independent supervisor feature). Besides the independent supervisor states, the
- * legacy region and XSAVE header are also restored from the xsave area. The
- * supervisor features in the XFEATURE_MASK_SUPERVISOR_SUPPORTED and
- * XFEATURE_MASK_SUPERVISOR_UNSUPPORTED are not restored.
- *
* The xsave area must be 64-bytes aligned.
*/
void copy_kernel_to_independent_supervisor(struct xregs_state *xstate, u64 mask)
{
- u64 independent_mask = xfeatures_mask_independent() & mask;
u32 lmask, hmask;
int err;

+ WARN_ON_FPU(mask & ~xfeatures_mask_independent());
+
if (WARN_ON_FPU(!boot_cpu_has(X86_FEATURE_XSAVES)))
return;

- if (WARN_ON_FPU(!independent_mask))
+ if (WARN_ON_FPU(!mask))
return;

- lmask = independent_mask;
- hmask = independent_mask >> 32;
+ lmask = mask;
+ hmask = mask >> 32;

XSTATE_OP(XRSTORS, xstate, lmask, hmask, err);

--
2.31.1
\
 
 \ /
  Last update: 2021-06-11 07:14    [W:0.051 / U:1.784 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site