From: Yu-cheng Yu <yu-cheng.yu@intel.com> To: linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Dave Hansen <dave.hansen@linux.intel.com>, Tony Luck <tony.luck@intel.com>, Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>, Rik van Riel <riel@surriel.com>, "Ravi V. Shankar" <ravi.v.shankar@intel.com>, Sebastian Andrzej Siewior <bigeasy@linutronix.de>, Fenghua Yu <fenghua.yu@intel.com>, Peter Zijlstra <peterz@infradead.org> Cc: Yu-cheng Yu <yu-cheng.yu@intel.com> Subject: [PATCH 2/3] x86/fpu/xstate: Fix XSAVES offsets in setup_xstate_comp() Date: Thu, 9 Jan 2020 13:14:51 -0800 [thread overview] Message-ID: <20200109211452.27369-3-yu-cheng.yu@intel.com> (raw) In-Reply-To: <20200109211452.27369-1-yu-cheng.yu@intel.com> In setup_xstate_comp(), each XSAVES component offset starts from the end of its preceding component plus alignment. A disabled feature does not take space and its offset should be set to the end of its preceding one with no alignment. However, in this case, alignment is incorrectly added to the offset, which can cause the next component to have a wrong offset. This problem has not been visible because currently there is no xfeature requiring alignment. Fix it by tracking the next starting offset only from enabled xfeatures. To make it clear, also change the function name to setup_xstate_comp_ offsets(). Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com> Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com> --- arch/x86/kernel/fpu/xstate.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 3ef3603bcfc5..73314e8fce02 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -344,9 +344,9 @@ static int xfeature_is_aligned(int xfeature_nr) * xsave area. This supports both standard format and compacted format * of the xsave aread. */ -static void __init setup_xstate_comp(void) +static void __init setup_xstate_comp_offsets(void) { - unsigned int xstate_comp_sizes[XFEATURE_MAX]; + unsigned int next_offset; int i; /* @@ -360,31 +360,23 @@ static void __init setup_xstate_comp(void) if (!boot_cpu_has(X86_FEATURE_XSAVES)) { for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { - if (xfeature_enabled(i)) { + if (xfeature_enabled(i)) xstate_comp_offsets[i] = xstate_offsets[i]; - xstate_comp_sizes[i] = xstate_sizes[i]; - } } return; } - xstate_comp_offsets[FIRST_EXTENDED_XFEATURE] = - FXSAVE_SIZE + XSAVE_HDR_SIZE; + next_offset = FXSAVE_SIZE + XSAVE_HDR_SIZE; for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { - if (xfeature_enabled(i)) - xstate_comp_sizes[i] = xstate_sizes[i]; - else - xstate_comp_sizes[i] = 0; + if (!xfeature_enabled(i)) + continue; - if (i > FIRST_EXTENDED_XFEATURE) { - xstate_comp_offsets[i] = xstate_comp_offsets[i-1] - + xstate_comp_sizes[i-1]; + if (xfeature_is_aligned(i)) + next_offset = ALIGN(next_offset, 64); - if (xfeature_is_aligned(i)) - xstate_comp_offsets[i] = - ALIGN(xstate_comp_offsets[i], 64); - } + xstate_comp_offsets[i] = next_offset; + next_offset += xstate_sizes[i]; } } @@ -778,7 +770,7 @@ void __init fpu__init_system_xstate(void) fpu__init_prepare_fx_sw_frame(); setup_init_fpu_buf(); - setup_xstate_comp(); + setup_xstate_comp_offsets(); print_xstate_offset_size(); pr_info("x86/fpu: Enabled xstate features 0x%llx, context size is %d bytes, using '%s' format.\n", -- 2.21.0
next prev parent reply other threads:[~2020-01-09 21:17 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-09 21:14 [PATCH 0/3] Fix two issues in XSAVES offset calculation Yu-cheng Yu 2020-01-09 21:14 ` [PATCH 1/3] x86/fpu/xstate: Fix last_good_offset in setup_xstate_features() Yu-cheng Yu 2020-02-11 18:56 ` Borislav Petkov 2020-02-12 14:50 ` [tip: x86/fpu] " tip-bot2 for Yu-cheng Yu 2020-01-09 21:14 ` Yu-cheng Yu [this message] 2020-02-12 14:50 ` [tip: x86/fpu] x86/fpu/xstate: Fix XSAVES offsets in setup_xstate_comp() tip-bot2 for Yu-cheng Yu 2020-01-09 21:14 ` [PATCH 3/3] x86/fpu/xstate: WARN_ONCE on checking alignment of disabled xfeatures Yu-cheng Yu 2020-02-12 14:50 ` [tip: x86/fpu] x86/fpu/xstate: Warn when " tip-bot2 for Yu-cheng Yu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200109211452.27369-3-yu-cheng.yu@intel.com \ --to=yu-cheng.yu@intel.com \ --cc=bigeasy@linutronix.de \ --cc=bp@alien8.de \ --cc=dave.hansen@linux.intel.com \ --cc=fenghua.yu@intel.com \ --cc=hpa@zytor.com \ --cc=linux-kernel@vger.kernel.org \ --cc=luto@kernel.org \ --cc=mingo@redhat.com \ --cc=peterz@infradead.org \ --cc=ravi.v.shankar@intel.com \ --cc=riel@surriel.com \ --cc=tglx@linutronix.de \ --cc=tony.luck@intel.com \ --cc=x86@kernel.org \ --subject='Re: [PATCH 2/3] x86/fpu/xstate: Fix XSAVES offsets in setup_xstate_comp()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).