2019-11-01 12:45:54

by Cyrill Gorcunov

[permalink] [raw]
Subject: [PATCH -tip] x86/fpu: Shrink space allocated for xstate_comp_offsets

In the commit 8ff925e10f2c72680918b95173ef4f8bb982d59e up to 64 entries
are allocated for xstate_comp_offsets while we only handle XFEATURE_MAX
entries. For this reason xstate_offsets and xstate_sizes already defined
with the explicit limit. Lets do the same for compressed format for
consistency sake.

Actually I guess the main idea was to cover all possible bits in
xfeatures_mask but this doesn't explain why other members such as
standart offsets and sizes were not using the same. So I think better
to use known XFEATURE_MAX limit everywhere and extend it on demand
when new features get implemented on hardware level.

Signed-off-by: Cyrill Gorcunov <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Thomas Gleixner <[email protected]>
CC: H. Peter Anvin <[email protected]>
---
arch/x86/kernel/fpu/xstate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-tip.git/arch/x86/kernel/fpu/xstate.c
===================================================================
--- linux-tip.git.orig/arch/x86/kernel/fpu/xstate.c
+++ linux-tip.git/arch/x86/kernel/fpu/xstate.c
@@ -60,7 +60,7 @@ u64 xfeatures_mask __read_mostly;

static unsigned int xstate_offsets[XFEATURE_MAX] = { [ 0 ... XFEATURE_MAX - 1] = -1};
static unsigned int xstate_sizes[XFEATURE_MAX] = { [ 0 ... XFEATURE_MAX - 1] = -1};
-static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8];
+static unsigned int xstate_comp_offsets[XFEATURE_MAX] = { [ 0 ... XFEATURE_MAX - 1] = -1};

/*
* The XSAVE area of kernel can be in standard or compacted format;
@@ -342,7 +342,7 @@ static int xfeature_is_aligned(int xfeat
*/
static void __init setup_xstate_comp(void)
{
- unsigned int xstate_comp_sizes[sizeof(xfeatures_mask)*8];
+ unsigned int xstate_comp_sizes[XFEATURE_MAX];
int i;

/*


2019-11-04 21:16:06

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [tip: x86/fpu] x86/fpu: Shrink space allocated for xstate_comp_offsets

The following commit has been merged into the x86/fpu branch of tip:

Commit-ID: c08550510ca26bd57eabfe912281635e382193e5
Gitweb: https://git.kernel.org/tip/c08550510ca26bd57eabfe912281635e382193e5
Author: Cyrill Gorcunov <[email protected]>
AuthorDate: Fri, 01 Nov 2019 15:42:28 +03:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Mon, 04 Nov 2019 22:04:19 +01:00

x86/fpu: Shrink space allocated for xstate_comp_offsets

commit 8ff925e10f2c ("x86/xsaves: Clean up code in xstate offsets
computation in xsave area") introduced an allocation of 64 entries for
xstate_comp_offsets while the code only handles up to XFEATURE_MAX entries.

For this reason xstate_offsets and xstate_sizes are already defined with
the explicit XFEATURE_MAX limit.

Do the same for compressed format for consistency sake.

As the changelog of that commit is not giving any information it's assumed
that the main idea was to cover all possible bits in xfeatures_mask, but
this doesn't explain why other variables such as the non-compacted offsets
and sizes are explicitely limited to XFEATURE_MAX.

For consistency it's better to use the XFEATURE_MAX limit everywhere and
extend it on demand when new features get implemented at the hardware
level and subsequently supported by the kernel.

Signed-off-by: Cyrill Gorcunov <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]

---
arch/x86/kernel/fpu/xstate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 18ffc6f..a8bd5c0 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -60,7 +60,7 @@ u64 xfeatures_mask __read_mostly;

static unsigned int xstate_offsets[XFEATURE_MAX] = { [ 0 ... XFEATURE_MAX - 1] = -1};
static unsigned int xstate_sizes[XFEATURE_MAX] = { [ 0 ... XFEATURE_MAX - 1] = -1};
-static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8];
+static unsigned int xstate_comp_offsets[XFEATURE_MAX] = { [ 0 ... XFEATURE_MAX - 1] = -1};

/*
* The XSAVE area of kernel can be in standard or compacted format;
@@ -342,7 +342,7 @@ static int xfeature_is_aligned(int xfeature_nr)
*/
static void __init setup_xstate_comp(void)
{
- unsigned int xstate_comp_sizes[sizeof(xfeatures_mask)*8];
+ unsigned int xstate_comp_sizes[XFEATURE_MAX];
int i;

/*