Skip to content

Commit

Permalink
x86/xsaves: Clean up code in xstate offsets computation in xsave area
Browse files Browse the repository at this point in the history
This patch cleans up some code in xstate offsets computation in xsave
area:

1. It changes xstate_comp_offsets as an array. This avoids possible NULL pointer
   caused by possible kmalloc() failure during boot time.
2. It changes the global variable xstate_comp_sizes to a local variable because
   it is used only in setup_xstate_comp().
3. It adds missing offsets for FP and SSE in xsave area.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Link: http://lkml.kernel.org/r/1401387164-43416-17-git-send-email-fenghua.yu@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
  • Loading branch information
Fenghua Yu authored and H. Peter Anvin committed May 31, 2014
1 parent c9e5a5a commit 8ff925e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions arch/x86/kernel/xsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct xsave_struct *init_xstate_buf;

static struct _fpx_sw_bytes fx_sw_reserved, fx_sw_reserved_ia32;
static unsigned int *xstate_offsets, *xstate_sizes;
static unsigned int *xstate_comp_offsets, *xstate_comp_sizes;
static unsigned int xstate_comp_offsets[sizeof(pcntxt_mask)*8];
static unsigned int xstate_features;

/*
Expand Down Expand Up @@ -491,11 +491,16 @@ static void __init setup_xstate_features(void)
*/
void setup_xstate_comp(void)
{
unsigned int xstate_comp_sizes[sizeof(pcntxt_mask)*8];
int i;

xstate_comp_offsets = kmalloc(xstate_features * sizeof(int),
GFP_KERNEL);
xstate_comp_sizes = kmalloc(xstate_features * sizeof(int), GFP_KERNEL);
/*
* The FP xstates and SSE xstates are legacy states. They are always
* in the fixed offsets in the xsave area in either compacted form
* or standard form.
*/
xstate_comp_offsets[0] = 0;
xstate_comp_offsets[1] = offsetof(struct i387_fxsave_struct, xmm_space);

if (!cpu_has_xsaves) {
for (i = 2; i < xstate_features; i++) {
Expand Down

0 comments on commit 8ff925e

Please sign in to comment.