kernel: backport upstream usbnet fix (fixes #19455)
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.18 / 304-mips_disable_fpu.patch
index 4536ce6dae80710e530dd7c67c8c8728f95ee3e6..ae742dc325647e49b891b889c1a753f77d512edb 100644 (file)
-MIPS: allow disabling the kernel FPU emulator
-
-This patch allows turning off the in-kernel Algorithmics
-FPU emulator support, which allows one to save a couple of
-precious blocks on an embedded system.
-
-Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
+From:   Manuel Lauss <manuel.lauss@gmail.com>\r
+Subject: [RFC PATCH v4 2/2] MIPS: make FPU emulator optional\r
+Date:   Mon,  7 Apr 2014 12:57:04 +0200\r
+Message-Id: <1396868224-252888-2-git-send-email-manuel.lauss@gmail.com>\r
+\r
+This small patch makes the MIPS FPU emulator optional. The kernel\r
+kills float-users on systems without a hardware FPU by sending a SIGILL.\r
+\r
+Disabling the emulator shrinks vmlinux by about 54kBytes (32bit,\r
+optimizing for size).\r
+\r
+Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>\r
+---\r
+v4: rediffed because of patch 1/2, should now work with micromips as well\r
+v3: updated patch description with size savings.\r
+v2: incorporated changes suggested by Jonas Gorski\r
+    force the fpu emulator on for micromips: relocating the parts\r
+    of the mmips code in the emulator to other areas would be a\r
+    much larger change; I went the cheap route instead with this.\r
+\r
+ arch/mips/Kbuild                     |  2 +-\r
+ arch/mips/Kconfig                    | 14 ++++++++++++++\r
+ arch/mips/include/asm/fpu.h          |  5 +++--\r
+ arch/mips/include/asm/fpu_emulator.h | 15 +++++++++++++++\r
+ 4 files changed, 33 insertions(+), 3 deletions(-)\r
+\r
 --- a/arch/mips/Kconfig
 +++ b/arch/mips/Kconfig
-@@ -934,6 +934,17 @@ config I8259
- config MIPS_BONITO64
-       bool
+@@ -2495,6 +2495,20 @@ config MIPS_O32_FP64_SUPPORT
+         If unsure, say N.
  
-+config MIPS_FPU_EMU
-+      bool "Enable FPU emulation"
++config MIPS_FPU_EMULATOR
++      bool "MIPS FPU Emulator"
 +      default y
 +      help
-+         This option allows building a kernel with or without the Algorithmics
-+         FPU emulator enabled. Turning off this option results in a kernel which
-+         does not catch floating operations exceptions. Make sure that your toolchain
-+         is configured to enable software floating point emulation in that case.
++        This option lets you disable the built-in MIPS FPU (Coprocessor 1)
++        emulator, which handles floating-point instructions on processors
++        without a hardware FPU.  It is generally a good idea to keep the
++        emulator built-in, unless you are perfectly sure you have a
++        complete soft-float environment.  With the emulator disabled, all
++        users of float operations will be killed with an illegal instr-
++        uction exception.
 +
-+         If unsure say Y here.
++        Say Y, please.
 +
- config MIPS_MSC
+ config USE_OF
        bool
+       select OF
+--- a/arch/mips/Makefile
++++ b/arch/mips/Makefile
+@@ -275,7 +275,7 @@ OBJCOPYFLAGS               += --remove-section=.regin
+ head-y := arch/mips/kernel/head.o
  
---- a/arch/mips/math-emu/Makefile
-+++ b/arch/mips/math-emu/Makefile
-@@ -2,10 +2,12 @@
- # Makefile for the Linux/MIPS kernel FPU emulation.
- #
--obj-y := cp1emu.o ieee754m.o ieee754d.o ieee754dp.o ieee754sp.o ieee754.o \
-+obj-y := kernel_linkage.o
-+
-+obj-$(CONFIG_MIPS_FPU_EMU)    += ieee754m.o ieee754d.o ieee754dp.o ieee754sp.o ieee754.o \
-          ieee754xcpt.o dp_frexp.o dp_modf.o dp_div.o dp_mul.o dp_sub.o \
-          dp_add.o dp_fsp.o dp_cmp.o dp_logb.o dp_scalb.o dp_simple.o \
-          dp_tint.o dp_fint.o dp_tlong.o dp_flong.o sp_frexp.o sp_modf.o \
-          sp_div.o sp_mul.o sp_sub.o sp_add.o sp_fdp.o sp_cmp.o sp_logb.o \
-          sp_scalb.o sp_simple.o sp_tint.o sp_fint.o sp_tlong.o sp_flong.o \
--         dp_sqrt.o sp_sqrt.o kernel_linkage.o dsemul.o
-+         dp_sqrt.o sp_sqrt.o dsemul.o cp1emu.o
---- a/arch/mips/math-emu/kernel_linkage.c
-+++ b/arch/mips/math-emu/kernel_linkage.c
-@@ -29,6 +29,7 @@
+ libs-y                        += arch/mips/lib/
+-libs-y                        += arch/mips/math-emu/
++libs-$(CONFIG_MIPS_FPU_EMULATOR)      += arch/mips/math-emu/
  
- #define SIGNALLING_NAN 0x7ff800007ff80000LL
+ # See arch/mips/Kbuild for content of core part of the kernel
+ core-y += arch/mips/
+--- a/arch/mips/include/asm/fpu.h
++++ b/arch/mips/include/asm/fpu.h
+@@ -168,8 +168,10 @@ static inline int init_fpu(void)
+               ret = __own_fpu();
+               if (!ret)
+                       _init_fpu();
+-      } else
++      } else if (IS_ENABLED(CONFIG_MIPS_FPU_EMULATOR))
+               fpu_emulator_init_fpu();
++      else
++              ret = SIGILL;
  
-+#ifdef CONFIG_MIPS_FPU_EMU
- void fpu_emulator_init_fpu(void)
- {
-       static int first = 1;
-@@ -115,3 +116,36 @@ int fpu_emulator_restore_context32(struc
-       return err;
+       return ret;
  }
- #endif
-+
-+#else
-+
-+void fpu_emulator_init_fpu(void)
-+{
-+      printk(KERN_INFO "FPU emulator disabled, make sure your toolchain"
-+              "was compiled with software floating point support (soft-float)\n");
-+      return;
-+}
-+
-+int fpu_emulator_save_context(struct sigcontext __user *sc)
-+{
-+      return 0;
-+}
-+
-+int fpu_emulator_restore_context(struct sigcontext __user *sc)
-+{
-+      return 0;
-+}
-+
-+#ifdef CONFIG_64BIT
-+int fpu_emulator_save_context32(struct sigcontext32 __user *sc)
-+{
-+      return 0;
-+}
-+
-+int fpu_emulator_restore_context32(struct sigcontext32 __user *sc)
-+{
-+      return 0;
-+}
-+#endif /* CONFIG_64BIT */
-+
-+#endif /* CONFIG_MIPS_FPU_EMU */
 --- a/arch/mips/include/asm/fpu_emulator.h
 +++ b/arch/mips/include/asm/fpu_emulator.h
-@@ -27,6 +27,8 @@
- #include <asm/inst.h>
+@@ -30,6 +30,7 @@
  #include <asm/local.h>
+ #include <asm/processor.h>
  
-+#ifdef CONFIG_MIPS_FPU_EMU
-+
++#ifdef CONFIG_MIPS_FPU_EMULATOR
  #ifdef CONFIG_DEBUG_FS
  
  struct mips_fpu_emulator_stats {
-@@ -60,6 +62,38 @@ extern int fpu_emulator_cop1Handler(stru
- int process_fpemu_return(int sig, void __user *fault_addr);
- int mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
-                    unsigned long *contpc);
-+#else
-+static inline int mips_dsemul(struct pt_regs *regs, mips_instruction ir,
-+                            unsigned long cpc)
-+{
-+      return 0;
-+}
-+
+@@ -65,6 +66,20 @@ extern int do_dsemulret(struct pt_regs *
+ extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
+                                   struct mips_fpu_struct *ctx, int has_fpu,
+                                   void *__user *fault_addr);
++#else /* no CONFIG_MIPS_FPU_EMULATOR */
 +static inline int do_dsemulret(struct pt_regs *xcp)
 +{
-+      return 0;
++      return 0;       /* 0 means error, should never get here anyway */
 +}
 +
 +static inline int fpu_emulator_cop1Handler(struct pt_regs *xcp,
-+                                         struct mips_fpu_struct *ctx,
-+                                         int has_fpu,
-+                                         void *__user *fault_addr)
-+{
-+      return 0;
-+}
-+
-+static inline int process_fpemu_return(int sig, void __user *fault_addr)
++                              struct mips_fpu_struct *ctx, int has_fpu,
++                              void *__user *fault_addr)
 +{
-+      return -EINVAL;
++      return SIGILL;  /* we don't speak MIPS FPU */
 +}
++#endif        /* CONFIG_MIPS_FPU_EMULATOR */
 +
-+static inline int mm_isBranchInstr(struct pt_regs *regs,
-+                                 struct mm_decoded_insn dec_insn,
-+                                 unsigned long *contpc)
-+{
-+      return 0;
-+}
-+#endif /* CONFIG_MIPS_FPU_EMU */
- /*
-  * Instruction inserted following the badinst to further tag the sequence
---- a/arch/mips/kernel/traps.c
-+++ b/arch/mips/kernel/traps.c
-@@ -701,6 +701,7 @@ asmlinkage void do_ov(struct pt_regs *re
-       exception_exit(prev_state);
- }
-+#ifdef CONFIG_MIPS_FPU_EMU
- int process_fpemu_return(int sig, void __user *fault_addr)
- {
-       if (sig == SIGSEGV || sig == SIGBUS) {
-@@ -724,6 +725,7 @@ int process_fpemu_return(int sig, void _
-               return 0;
-       }
- }
-+#endif /* CONFIG_MIPS_FPU_EMU */
- /*
-  * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
+ int process_fpemu_return(int sig, void __user *fault_addr);
+ int mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
+                    unsigned long *contpc);