Skip to content

Commit 7e7ce87

Browse files
Fenghua YuH. Peter Anvin
authored andcommitted
x86/xsaves: Enable xsaves/xrstors
If xsaves/xrstors is enabled, compacted format of xsave area will be used and less memory may be used for context per process. And modified optimization implemented in xsaves/xrstors improves performance of saving xstate. Signed-off-by: Fenghua Yu <fenghua.yu@intel.com> Link: http://lkml.kernel.org/r/1401387164-43416-16-git-send-email-fenghua.yu@intel.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent 47c2f29 commit 7e7ce87

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

arch/x86/kernel/xsave.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/bootmem.h>
1010
#include <linux/compat.h>
11+
#include <linux/cpu.h>
1112
#include <asm/i387.h>
1213
#include <asm/fpu-internal.h>
1314
#include <asm/sigframe.h>
@@ -24,7 +25,9 @@ u64 pcntxt_mask;
2425
struct xsave_struct *init_xstate_buf;
2526

2627
static struct _fpx_sw_bytes fx_sw_reserved, fx_sw_reserved_ia32;
27-
static unsigned int *xstate_offsets, *xstate_sizes, xstate_features;
28+
static unsigned int *xstate_offsets, *xstate_sizes;
29+
static unsigned int *xstate_comp_offsets, *xstate_comp_sizes;
30+
static unsigned int xstate_features;
2831

2932
/*
3033
* If a processor implementation discern that a processor state component is
@@ -283,7 +286,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
283286

284287
if (use_xsave()) {
285288
/* These bits must be zero. */
286-
xsave_hdr->reserved1[0] = xsave_hdr->reserved1[1] = 0;
289+
memset(xsave_hdr->reserved, 0, 48);
287290

288291
/*
289292
* Init the state that is not present in the memory
@@ -526,6 +529,30 @@ static int __init eager_fpu_setup(char *s)
526529
}
527530
__setup("eagerfpu=", eager_fpu_setup);
528531

532+
533+
/*
534+
* Calculate total size of enabled xstates in XCR0/pcntxt_mask.
535+
*/
536+
static void __init init_xstate_size(void)
537+
{
538+
unsigned int eax, ebx, ecx, edx;
539+
int i;
540+
541+
if (!cpu_has_xsaves) {
542+
cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
543+
xstate_size = ebx;
544+
return;
545+
}
546+
547+
xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE;
548+
for (i = 2; i < 64; i++) {
549+
if (test_bit(i, (unsigned long *)&pcntxt_mask)) {
550+
cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
551+
xstate_size += eax;
552+
}
553+
}
554+
}
555+
529556
/*
530557
* Enable and initialize the xsave feature.
531558
*/
@@ -557,8 +584,7 @@ static void __init xstate_enable_boot_cpu(void)
557584
/*
558585
* Recompute the context size for enabled features
559586
*/
560-
cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
561-
xstate_size = ebx;
587+
init_xstate_size();
562588

563589
update_regset_xstate_info(xstate_size, pcntxt_mask);
564590
prepare_fx_sw_frame();
@@ -578,8 +604,9 @@ static void __init xstate_enable_boot_cpu(void)
578604
}
579605
}
580606

581-
pr_info("enabled xstate_bv 0x%llx, cntxt size 0x%x\n",
582-
pcntxt_mask, xstate_size);
607+
pr_info("enabled xstate_bv 0x%llx, cntxt size 0x%x using %s\n",
608+
pcntxt_mask, xstate_size,
609+
cpu_has_xsaves ? "compacted form" : "standard form");
583610
}
584611

585612
/*

0 commit comments

Comments
 (0)