* [PATCH v1 1/4] x86/fpu/xstate: Convert get_xsave_addr() to a static function
2023-06-21 12:09 [PATCH v1 0/4] x86/fpu: a few code cleanup Chang S. Bae
@ 2023-06-21 12:09 ` Chang S. Bae
2023-06-21 12:09 ` [PATCH v1 2/4] x86/fpu/xstate: Simplify xstate_calculate_size() Chang S. Bae
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Chang S. Bae @ 2023-06-21 12:09 UTC (permalink / raw)
To: linux-kernel, x86
Cc: tglx, mingo, bp, dave.hansen, hpa, andrew.cooper3, chang.seok.bae
The function is defined as global but is not invoked anywhere else.
Switch it a local (static) function.
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
---
arch/x86/kernel/fpu/xstate.c | 2 +-
arch/x86/kernel/fpu/xstate.h | 2 --
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 0bab497c9436..2f03acc47f62 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -956,7 +956,7 @@ static void *__raw_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
* address of the state in the xsave area, or NULL if the
* field is not present in the xsave buffer.
*/
-void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
+static void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
{
/*
* Do we even *have* xsave state?
diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h
index a4ecb04d8d64..82f2d3c41298 100644
--- a/arch/x86/kernel/fpu/xstate.h
+++ b/arch/x86/kernel/fpu/xstate.h
@@ -53,8 +53,6 @@ extern int copy_sigframe_from_user_to_xstate(struct task_struct *tsk, const void
extern void fpu__init_cpu_xstate(void);
extern void fpu__init_system_xstate(unsigned int legacy_size);
-extern void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
-
static inline u64 xfeatures_mask_supervisor(void)
{
return fpu_kernel_cfg.max_features & XFEATURE_MASK_SUPERVISOR_SUPPORTED;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 2/4] x86/fpu/xstate: Simplify xstate_calculate_size()
2023-06-21 12:09 [PATCH v1 0/4] x86/fpu: a few code cleanup Chang S. Bae
2023-06-21 12:09 ` [PATCH v1 1/4] x86/fpu/xstate: Convert get_xsave_addr() to a static function Chang S. Bae
@ 2023-06-21 12:09 ` Chang S. Bae
2023-06-21 12:09 ` [PATCH v1 3/4] x86/fpu/xstate: Simplify print_xstate_features() Chang S. Bae
2023-06-21 12:09 ` [PATCH v1 4/4] x86/fpu: Remove the unnecessary fpstate_reset() invocation Chang S. Bae
3 siblings, 0 replies; 5+ messages in thread
From: Chang S. Bae @ 2023-06-21 12:09 UTC (permalink / raw)
To: linux-kernel, x86
Cc: tglx, mingo, bp, dave.hansen, hpa, andrew.cooper3, chang.seok.bae
This size calculation code uses xfeatures_get_offset() only for the
compacted format. But, it is capable of handling both formats. Use it
for simpler and more concise code.
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
---
arch/x86/kernel/fpu/xstate.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 2f03acc47f62..d488621b280e 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -563,14 +563,11 @@ static bool __init check_xstate_against_struct(int nr)
static unsigned int xstate_calculate_size(u64 xfeatures, bool compacted)
{
unsigned int topmost = fls64(xfeatures) - 1;
- unsigned int offset = xstate_offsets[topmost];
if (topmost <= XFEATURE_SSE)
return sizeof(struct xregs_state);
- if (compacted)
- offset = xfeature_get_offset(xfeatures, topmost);
- return offset + xstate_sizes[topmost];
+ return xfeature_get_offset(xfeatures, topmost) + xstate_sizes[topmost];
}
/*
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 3/4] x86/fpu/xstate: Simplify print_xstate_features()
2023-06-21 12:09 [PATCH v1 0/4] x86/fpu: a few code cleanup Chang S. Bae
2023-06-21 12:09 ` [PATCH v1 1/4] x86/fpu/xstate: Convert get_xsave_addr() to a static function Chang S. Bae
2023-06-21 12:09 ` [PATCH v1 2/4] x86/fpu/xstate: Simplify xstate_calculate_size() Chang S. Bae
@ 2023-06-21 12:09 ` Chang S. Bae
2023-06-21 12:09 ` [PATCH v1 4/4] x86/fpu: Remove the unnecessary fpstate_reset() invocation Chang S. Bae
3 siblings, 0 replies; 5+ messages in thread
From: Chang S. Bae @ 2023-06-21 12:09 UTC (permalink / raw)
To: linux-kernel, x86
Cc: tglx, mingo, bp, dave.hansen, hpa, andrew.cooper3, chang.seok.bae
The print_xstate_features() invokes print_xstate_feature() multiple
times in separate lines which can be replaced with a loop.
The print_xstate_feature() function already checks the feature
enabling status, and it is only called from within
print_xstate_features(). So the code can be relocated.
Move the code exactly to print_xstate_features() and wrap it with a
loop there.
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
---
arch/x86/kernel/fpu/xstate.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index d488621b280e..6d72498ea0bc 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -253,31 +253,20 @@ static void __init setup_xstate_cache(void)
}
}
-static void __init print_xstate_feature(u64 xstate_mask)
-{
- const char *feature_name;
-
- if (cpu_has_xfeatures(xstate_mask, &feature_name))
- pr_info("x86/fpu: Supporting XSAVE feature 0x%03Lx: '%s'\n", xstate_mask, feature_name);
-}
-
/*
* Print out all the supported xstate features:
*/
static void __init print_xstate_features(void)
{
- print_xstate_feature(XFEATURE_MASK_FP);
- print_xstate_feature(XFEATURE_MASK_SSE);
- print_xstate_feature(XFEATURE_MASK_YMM);
- print_xstate_feature(XFEATURE_MASK_BNDREGS);
- print_xstate_feature(XFEATURE_MASK_BNDCSR);
- print_xstate_feature(XFEATURE_MASK_OPMASK);
- print_xstate_feature(XFEATURE_MASK_ZMM_Hi256);
- print_xstate_feature(XFEATURE_MASK_Hi16_ZMM);
- print_xstate_feature(XFEATURE_MASK_PKRU);
- print_xstate_feature(XFEATURE_MASK_PASID);
- print_xstate_feature(XFEATURE_MASK_XTILE_CFG);
- print_xstate_feature(XFEATURE_MASK_XTILE_DATA);
+ int i;
+
+ for (i = 0; i < XFEATURE_MAX; i++) {
+ u64 mask = BIT_ULL(i);
+ const char *name;
+
+ if (cpu_has_xfeatures(mask, &name))
+ pr_info("x86/fpu: Supporting XSAVE feature 0x%03Lx: '%s'\n", mask, name);
+ }
}
/*
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 4/4] x86/fpu: Remove the unnecessary fpstate_reset() invocation
2023-06-21 12:09 [PATCH v1 0/4] x86/fpu: a few code cleanup Chang S. Bae
` (2 preceding siblings ...)
2023-06-21 12:09 ` [PATCH v1 3/4] x86/fpu/xstate: Simplify print_xstate_features() Chang S. Bae
@ 2023-06-21 12:09 ` Chang S. Bae
3 siblings, 0 replies; 5+ messages in thread
From: Chang S. Bae @ 2023-06-21 12:09 UTC (permalink / raw)
To: linux-kernel, x86
Cc: tglx, mingo, bp, dave.hansen, hpa, andrew.cooper3, chang.seok.bae
fpstate_reset() initializes the fpstate container. But, when no state
has been established yet, calling this is not meaningful. In the
fpu__init_system() function, it is called immediately after the legacy
FPU size is determined. So, remove it as not causing any issues.
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
---
The change made by fpstate_reset() can be measured with this:
static struct fpstate fps;
void __init fpu__init_system(struct cpuinfo_x86 *c)
{
memcpy(&fps, ¤t->thread.fpu.__fpstate, sizeof(struct fpstate));
fpstate_reset(¤t->thread.fpu);
if (memcmp(&fps, ¤t->thread.fpu.__fpstate, sizeof(struct fpstate)))
pr_info("fpstate has reason to be inited at %s\n", __func__);
else
pr_info("fpstate has no reason to be inited at %s\n", __func__);
...
}
Although it looks to be a no-op, there might be some unknown
intention behind it. If there is a specific reason for invoking
fpstate_reset() at that point, this should be documented properly
instead of removing it.
---
arch/x86/kernel/fpu/init.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index 998a08f17e33..95af3084c4cf 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -213,7 +213,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)
*/
void __init fpu__init_system(void)
{
- fpstate_reset(¤t->thread.fpu);
fpu__init_system_early_generic();
/*
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread