Bug 60633 - X86 kernel fails to restore the DAZ bit in MXSCR
Summary: X86 kernel fails to restore the DAZ bit in MXSCR
Status: RESOLVED CODE_FIX
Alias: None
Product: Platform Specific/Hardware
Classification: Unclassified
Component: i386 (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: platform_i386
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-26 15:58 UTC by H.J. Lu
Modified: 2013-07-26 16:20 UTC (History)
1 user (show)

See Also:
Kernel Version: 3.11.0
Subsystem:
Regression: No
Bisected commit-id:


Attachments
A testcase (2.74 KB, text/plain)
2013-07-26 16:01 UTC, H.J. Lu
Details

Description H.J. Lu 2013-07-26 15:58:26 UTC
GCC will optimize mxcsr_feature_mask_init in arch/x86/kernel/i387.c:

                memset(&fx_scratch, 0, sizeof(struct i387_fxsave_struct));
                asm volatile("fxsave %0" : : "m" (fx_scratch));
                mask = fx_scratch.mxcsr_mask;
                if (mask == 0)
                        mask = 0x0000ffbf;

to

                memset(&fx_scratch, 0, sizeof(struct i387_fxsave_struct));
                asm volatile("fxsave %0" : : "m" (fx_scratch));
                mask = 0x0000ffbf;

since asm statement doesn’t say it will update fx_scratch.  As the result,
the DAZ bit will be cleared.  This patch

diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 202d24f..5d576ab 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -116,7 +116,7 @@ static void mxcsr_feature_mask_init(void)
 
   if (cpu_has_fxsr) {
      memset(&fx_scratch, 0, sizeof(struct i387_fxsave_struct));
-     asm volatile("fxsave %0" : : "m" (fx_scratch));
+     asm volatile("fxsave %0" : "+m" (fx_scratch));
      mask = fx_scratch.mxcsr_mask;
      if (mask == 0)
         mask = 0x0000ffbf;

fixes it. This bug dates back to at least kernel 2.6.12.
Comment 1 H.J. Lu 2013-07-26 16:01:51 UTC
Created attachment 107021 [details]
A testcase
Comment 2 H. Peter Anvin 2013-07-26 16:05:54 UTC
Hi H.J.,

I will apply this patch, but in the future, if you could please send patches (including the description) as a mail to the address listed in the MAINTAINERS file, in this case:

hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org

... and include the line:

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

... or any other email address you may prefer to use.
Comment 3 H. Peter Anvin 2013-07-26 16:20:26 UTC
Patch committed to -tip:

http://git.kernel.org/tip/eaa5a990191d204ba0f9d35dbe5505ec2cdd1460

Note You need to log in before you can comment on or make changes to this bug.