Skip to contentSkip to conversation

x86: Disable generation of traditional x87 instructions

PATCH New Borislav Petkov 2 participants 2 messages Feb 5, 2014 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86: Disable generation of traditional x87 instructions

From: Borislav Petkov <[email protected]>

We recently had the case where wrongly used floating-constant 'E' caused the generation of traditional x87 instructions in kernel code and wreaking all kinds of havoc.

Disable the generation of those too. This will save people a lot of time when trying to debug such issues by erroring out of the build instead of let them manifest themselves in very spectacular and happy-crappy ways at runtime.

We're using -mno-fp-ret-in-387 in addition to -mno-80387 (which is == -msoft-float) because, as the gcc manpage says:

On machines where a function returns floating-point results in the 80387 register stack, some floating-point opcodes may be emitted even if -msoft-float is used.

so we want to turn off *all* non-integer instructions involving any architectural FPU state, unless it is absolutely necessary (and those cases need special handling anyway).

Cc Jiri Kosina <[email protected]>
Cc Michael Matz <[email protected]>
Cc Michal Hocko <[email protected]>
---
 arch/x86/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/Makefile +2 -2
index eeda43abed6e..a414b1471ffc 100644
@@ -82,8 +82,8 @@ else
         KBUILD_AFLAGS += -m64
         KBUILD_CFLAGS += -m64
 
-        # Don't autogenerate MMX or SSE instructions
-        KBUILD_CFLAGS += -mno-mmx -mno-sse
+        # Don't autogenerate traditional x87, MMX or SSE instructions
+        KBUILD_CFLAGS += -mno-mmx -mno-sse -mno-80387 -mno-fp-ret-in-387
 
 	# Use -mpreferred-stack-boundary=3 if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
Signature · 1 line
1.8.5.2.192.g7794a68
#1 lore raw
x86: Disable generation of traditional x87 instructions
Commit-ID:  b399fe355b30d0102e7690c99e6f764ddfd32ec3
Gitweb:     http://git.kernel.org/tip/b399fe355b30d0102e7690c99e6f764ddfd32ec3
Author:     Borislav Petkov <[email protected]>
AuthorDate: Wed, 5 Feb 2014 01:55:11 +0100
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Tue, 4 Feb 2014 20:00:35 -0800

x86: Disable generation of traditional x87 instructions

We recently had the case where wrongly used floating-constant 'E' caused the generation of traditional x87 instructions in kernel code and wreaking all kinds of havoc.

Disable the generation of those too. This will save people a lot of time when trying to debug such issues by erroring out of the build instead of let them manifest themselves in very spectacular and happy-crappy ways at runtime.

We're using -mno-fp-ret-in-387 in addition to -mno-80387 (which is == -msoft-float) because, as the gcc manpage says:

On machines where a function returns floating-point results in the 80387 register stack, some floating-point opcodes may be emitted even if -msoft-float is used.

so we want to turn off *all* non-integer instructions involving any architectural FPU state, unless it is absolutely necessary (and those cases need special handling anyway).

---
 arch/x86/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/Makefile +2 -2
index eeda43a..a414b14 100644
@@ -82,8 +82,8 @@ else
         KBUILD_AFLAGS += -m64
         KBUILD_CFLAGS += -m64
 
-        # Don't autogenerate MMX or SSE instructions
-        KBUILD_CFLAGS += -mno-mmx -mno-sse
+        # Don't autogenerate traditional x87, MMX or SSE instructions
+        KBUILD_CFLAGS += -mno-mmx -mno-sse -mno-80387 -mno-fp-ret-in-387
 
 	# Use -mpreferred-stack-boundary=3 if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)