[PATCH Bugfix 3/4] x86/xsaves: Rename xstate_size to kernel_xstate_size to explicitely distinguish xstate size in kernel from user space

From: Fenghua Yu
Date: Sat Apr 18 2015 - 16:15:49 EST


From: Fenghua Yu <fenghua.yu@xxxxxxxxx>

User space uses standard format xsave area. fpstate in signal frame should
have standard format size.

To explicitly distinguish between xstate size in kernel space and the one
in user space, we rename xstate_size to kernel_xstate_size. This patch is
not fixing a bug. It just makes kernel code more clear.

So we define the xsave area sizes in two global variables:

kernel_xstate_size (previous xstate_size): the xsave area size used in
xsave area allocated in kernel
user_xstate_size: the xsave area size used in xsave area used by user.

In no "xsaves" case, xsave area in both user space and kernel space are in
standard format. Therefore, kernel_xstate_size and user_xstate_size are
equal.

In "xsaves" case, xsave area in user space is in standard format while
xsave area in kernel space is in compact format. Therefore, kernel's
xstate size is less than user's xstate size.

Signed-off-by: Fenghua Yu <fenghua.yu@xxxxxxxxx>
Reviewed-by: Dave Hansen <dave.hansen@xxxxxxxxx>
---
arch/x86/include/asm/fpu-internal.h | 4 ++--
arch/x86/include/asm/processor.h | 2 +-
arch/x86/kernel/i387.c | 18 +++++++++---------
arch/x86/kernel/process.c | 2 +-
arch/x86/kernel/xsave.c | 14 +++++++-------
5 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
index c00c769..5d9ba0c 100644
--- a/arch/x86/include/asm/fpu-internal.h
+++ b/arch/x86/include/asm/fpu-internal.h
@@ -597,14 +597,14 @@ static inline void fpu_free(struct fpu *fpu)
static inline void fpu_copy(struct task_struct *dst, struct task_struct *src)
{
if (use_eager_fpu()) {
- memset(&dst->thread.fpu.state->xsave, 0, xstate_size);
+ memset(&dst->thread.fpu.state->xsave, 0, kernel_xstate_size);
__save_fpu(dst);
} else {
struct fpu *dfpu = &dst->thread.fpu;
struct fpu *sfpu = &src->thread.fpu;

unlazy_fpu(src);
- memcpy(dfpu->state, sfpu->state, xstate_size);
+ memcpy(dfpu->state, sfpu->state, kernel_xstate_size);
}
}

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 576ff8c..f26051b 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -482,7 +482,7 @@ DECLARE_PER_CPU(struct irq_stack *, hardirq_stack);
DECLARE_PER_CPU(struct irq_stack *, softirq_stack);
#endif /* X86_64 */

-extern unsigned int xstate_size;
+extern unsigned int kernel_xstate_size;
extern unsigned int user_xstate_size;
extern void free_thread_xstate(struct task_struct *);
extern struct kmem_cache *task_xstate_cachep;
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 00918327..47759a5 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -133,8 +133,8 @@ void unlazy_fpu(struct task_struct *tsk)
EXPORT_SYMBOL(unlazy_fpu);

unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu;
-unsigned int xstate_size;
-EXPORT_SYMBOL_GPL(xstate_size);
+unsigned int kernel_xstate_size;
+EXPORT_SYMBOL_GPL(kernel_xstate_size);
static struct i387_fxsave_struct fx_scratch;

static void mxcsr_feature_mask_init(void)
@@ -154,7 +154,7 @@ static void mxcsr_feature_mask_init(void)
static void init_thread_xstate(void)
{
/*
- * Note that xstate_size might be overwriten later during
+ * Note that kernel_xstate_size might be overwriten later during
* xsave_init().
*/

@@ -165,14 +165,14 @@ static void init_thread_xstate(void)
*/
setup_clear_cpu_cap(X86_FEATURE_XSAVE);
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
- xstate_size = sizeof(struct i387_soft_struct);
+ kernel_xstate_size = sizeof(struct i387_soft_struct);
return;
}

if (cpu_has_fxsr)
- xstate_size = sizeof(struct i387_fxsave_struct);
+ kernel_xstate_size = sizeof(struct i387_fxsave_struct);
else
- xstate_size = sizeof(struct i387_fsave_struct);
+ kernel_xstate_size = sizeof(struct i387_fsave_struct);
}

/*
@@ -208,9 +208,9 @@ void fpu_init(void)

/*
* init_thread_xstate is only called once to avoid overriding
- * xstate_size during boot time or during CPU hotplug.
+ * kernel_xstate_size during boot time or during CPU hotplug.
*/
- if (xstate_size == 0)
+ if (kernel_xstate_size == 0)
init_thread_xstate();

mxcsr_feature_mask_init();
@@ -225,7 +225,7 @@ void fpu_finit(struct fpu *fpu)
return;
}

- memset(fpu->state, 0, xstate_size);
+ memset(fpu->state, 0, kernel_xstate_size);

if (cpu_has_fxsr) {
fx_finit(&fpu->state->fxsave);
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 8213da6..ded2c82 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -113,7 +113,7 @@ void arch_release_task_struct(struct task_struct *tsk)
void arch_task_cache_init(void)
{
task_xstate_cachep =
- kmem_cache_create("task_xstate", xstate_size,
+ kmem_cache_create("task_xstate", kernel_xstate_size,
__alignof__(union thread_xstate),
SLAB_PANIC | SLAB_NOTRACK, NULL);
setup_xstate_comp();
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
index b8373a0..98c236f 100644
--- a/arch/x86/kernel/xsave.c
+++ b/arch/x86/kernel/xsave.c
@@ -409,7 +409,7 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
{
int ia32_fxstate = (buf != buf_fx);
struct task_struct *tsk = current;
- int state_size = xstate_size;
+ int state_size = kernel_xstate_size;
u64 xstate_bv = 0;
int fx_only = 0;

@@ -609,7 +609,7 @@ static void __init setup_init_fpu_buf(void)
* Setup init_xstate_buf to represent the init state of
* all the features managed by the xsave
*/
- init_xstate_buf = alloc_bootmem_align(xstate_size,
+ init_xstate_buf = alloc_bootmem_align(kernel_xstate_size,
__alignof__(struct xsave_struct));
fx_finit(&init_xstate_buf->i387);

@@ -663,15 +663,15 @@ static void __init init_xstate_size(void)
user_xstate_size = ebx;

if (!cpu_has_xsaves) {
- xstate_size = ebx;
+ kernel_xstate_size = ebx;
return;
}

- xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE;
+ kernel_xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE;
for (i = 2; i < 64; i++) {
if (test_bit(i, (unsigned long *)&pcntxt_mask)) {
cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
- xstate_size += eax;
+ kernel_xstate_size += eax;
}
}
}
@@ -709,7 +709,7 @@ static void __init xstate_enable_boot_cpu(void)
*/
init_xstate_size();

- update_regset_xstate_info(xstate_size, pcntxt_mask);
+ update_regset_xstate_info(kernel_xstate_size, pcntxt_mask);
prepare_fx_sw_frame();
setup_init_fpu_buf();

@@ -728,7 +728,7 @@ static void __init xstate_enable_boot_cpu(void)
}

pr_info("enabled xstate_bv 0x%llx, cntxt size 0x%x using %s\n",
- pcntxt_mask, xstate_size,
+ pcntxt_mask, kernel_xstate_size,
cpu_has_xsaves ? "compacted form" : "standard form");
}

--
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/