提交 73a3aeb3 编写于 作者: I Ingo Molnar

x86/fpu: Improve the __sanitize_i387_state() documentation

Improve the comments and add new ones, as this code isn't very obvious.
Reviewed-by: NBorislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: NIngo Molnar <mingo@kernel.org>
上级 e783e816
...@@ -30,19 +30,23 @@ static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8]; ...@@ -30,19 +30,23 @@ static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8];
static unsigned int xfeatures_nr; static unsigned int xfeatures_nr;
/* /*
* If a processor implementation discern that a processor state component is * When executing XSAVEOPT (optimized XSAVE), if a processor implementation
* in its initialized state it may modify the corresponding bit in the * detects that an FPU state component is still (or is again) in its
* header.xfeatures as '0', with out modifying the corresponding memory * initialized state, it may clear the corresponding bit in the header.xfeatures
* layout in the case of xsaveopt. While presenting the xstate information to * field, and can skip the writeout of registers to the corresponding memory layout.
* the user, we always ensure that the memory layout of a feature will be in *
* the init state if the corresponding header bit is zero. This is to ensure * This means that when the bit is zero, the state component might still contain
* that the user doesn't see some stale state in the memory layout during * some previous - non-initialized register state.
* signal handling, debugging etc. *
* Before writing xstate information to user-space we sanitize those components,
* to always ensure that the memory layout of a feature will be in the init state
* if the corresponding header bit is zero. This is to ensure that user-space doesn't
* see some stale state in the memory layout during signal handling, debugging etc.
*/ */
void __sanitize_i387_state(struct task_struct *tsk) void __sanitize_i387_state(struct task_struct *tsk)
{ {
struct i387_fxsave_struct *fx = &tsk->thread.fpu.state->fxsave; struct i387_fxsave_struct *fx = &tsk->thread.fpu.state->fxsave;
int feature_bit = 0x2; int feature_bit;
u64 xfeatures; u64 xfeatures;
if (!fx) if (!fx)
...@@ -76,19 +80,25 @@ void __sanitize_i387_state(struct task_struct *tsk) ...@@ -76,19 +80,25 @@ void __sanitize_i387_state(struct task_struct *tsk)
if (!(xfeatures & XSTATE_SSE)) if (!(xfeatures & XSTATE_SSE))
memset(&fx->xmm_space[0], 0, 256); memset(&fx->xmm_space[0], 0, 256);
/*
* First two features are FPU and SSE, which above we handled
* in a special way already:
*/
feature_bit = 0x2;
xfeatures = (xfeatures_mask & ~xfeatures) >> 2; xfeatures = (xfeatures_mask & ~xfeatures) >> 2;
/* /*
* Update all the other memory layouts for which the corresponding * Update all the remaining memory layouts according to their
* header bit is in the init state. * standard xstate layout, if their header bit is in the init
* state:
*/ */
while (xfeatures) { while (xfeatures) {
if (xfeatures & 0x1) { if (xfeatures & 0x1) {
int offset = xstate_offsets[feature_bit]; int offset = xstate_offsets[feature_bit];
int size = xstate_sizes[feature_bit]; int size = xstate_sizes[feature_bit];
memcpy(((void *) fx) + offset, memcpy((void *)fx + offset,
((void *) init_xstate_buf) + offset, (void *)init_xstate_buf + offset,
size); size);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册