[RFC PATCH 08/10] x86/fpu: Don't keep state_size in perm struct

From: Jiaxun Yang
Date: Thu Dec 02 2021 - 19:37:06 EST


As we are now calculating kernel fpstate size accroading
to features actually in use, there is no need to keep the
size of states permitted.

Signed-off-by: Jiaxun Yang <j.yang-87@xxxxxxxxxxxx>
---
arch/x86/include/asm/fpu/types.h | 8 --------
arch/x86/kernel/fpu/core.c | 1 -
arch/x86/kernel/fpu/xstate.c | 8 ++------
3 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h
index 3c06c82ab355..a2cadaa9c305 100644
--- a/arch/x86/include/asm/fpu/types.h
+++ b/arch/x86/include/asm/fpu/types.h
@@ -409,14 +409,6 @@ struct fpu_state_perm {
*/
u64 __state_perm;

- /*
- * @__state_size:
- *
- * The size required for @__state_perm. Only valid to access
- * with sighand locked.
- */
- unsigned int __state_size;
-
/*
* @__user_state_size:
*
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 861cbfc51c17..b257e2dac39a 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -473,7 +473,6 @@ void fpstate_reset(struct fpu *fpu)

/* Initialize the permission related info in fpu */
fpu->perm.__state_perm = fpu_kernel_cfg.default_features;
- fpu->perm.__state_size = fpu_kernel_cfg.default_size;
fpu->perm.__user_state_size = fpu_user_cfg.default_size;
}

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 8519a6286d0d..4621b51d1b20 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1590,9 +1590,8 @@ static int __xstate_request_perm(u64 permitted, u64 requested)
* vendors into extending XFD for the pre AMX states, especially
* AVX512.
*/
- bool compacted = cpu_feature_enabled(X86_FEATURE_XSAVES);
struct fpu *fpu = &current->group_leader->thread.fpu;
- unsigned int ksize, usize;
+ unsigned int usize;
u64 mask;
int ret;

@@ -1602,7 +1601,6 @@ static int __xstate_request_perm(u64 permitted, u64 requested)

/* Calculate the resulting kernel state size */
mask = permitted | requested;
- ksize = xstate_calculate_size(mask, compacted);

/* Calculate the resulting user state size */
mask &= XFEATURE_MASK_USER_SUPPORTED;
@@ -1615,7 +1613,6 @@ static int __xstate_request_perm(u64 permitted, u64 requested)
/* Pairs with the READ_ONCE() in xstate_get_group_perm() */
WRITE_ONCE(fpu->perm.__state_perm, requested);
/* Protected by sighand lock */
- fpu->perm.__state_size = ksize;
fpu->perm.__user_state_size = usize;
return ret;
}
@@ -1663,7 +1660,7 @@ static int xstate_request_perm(unsigned long idx)
int xfd_enable_feature(u64 xfd_err)
{
u64 xfd_event = xfd_err & XFEATURE_MASK_USER_DYNAMIC;
- unsigned int ksize, usize;
+ unsigned int usize;
struct fpu *fpu;

if (!xfd_event) {
@@ -1681,7 +1678,6 @@ int xfd_enable_feature(u64 xfd_err)
}

fpu = &current->group_leader->thread.fpu;
- ksize = fpu->perm.__state_size;
usize = fpu->perm.__user_state_size;
/*
* The feature is permitted. State size is sufficient. Dropping
--
2.30.2