kernel: update 3.18 to 3.18.14
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.18 / 304-mips_disable_fpu.patch
1 From: Manuel Lauss <manuel.lauss@gmail.com>
2 Subject: [RFC PATCH v4 2/2] MIPS: make FPU emulator optional
3 Date: Mon, 7 Apr 2014 12:57:04 +0200
4 Message-Id: <1396868224-252888-2-git-send-email-manuel.lauss@gmail.com>
5
6 This small patch makes the MIPS FPU emulator optional. The kernel
7 kills float-users on systems without a hardware FPU by sending a SIGILL.
8
9 Disabling the emulator shrinks vmlinux by about 54kBytes (32bit,
10 optimizing for size).
11
12 Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
13 ---
14 v4: rediffed because of patch 1/2, should now work with micromips as well
15 v3: updated patch description with size savings.
16 v2: incorporated changes suggested by Jonas Gorski
17 force the fpu emulator on for micromips: relocating the parts
18 of the mmips code in the emulator to other areas would be a
19 much larger change; I went the cheap route instead with this.
20
21 arch/mips/Kbuild | 2 +-
22 arch/mips/Kconfig | 14 ++++++++++++++
23 arch/mips/include/asm/fpu.h | 5 +++--
24 arch/mips/include/asm/fpu_emulator.h | 15 +++++++++++++++
25 4 files changed, 33 insertions(+), 3 deletions(-)
26
27 --- a/arch/mips/Kconfig
28 +++ b/arch/mips/Kconfig
29 @@ -2495,6 +2495,20 @@ config MIPS_O32_FP64_SUPPORT
30
31 If unsure, say N.
32
33 +config MIPS_FPU_EMULATOR
34 + bool "MIPS FPU Emulator"
35 + default y
36 + help
37 + This option lets you disable the built-in MIPS FPU (Coprocessor 1)
38 + emulator, which handles floating-point instructions on processors
39 + without a hardware FPU. It is generally a good idea to keep the
40 + emulator built-in, unless you are perfectly sure you have a
41 + complete soft-float environment. With the emulator disabled, all
42 + users of float operations will be killed with an illegal instr-
43 + uction exception.
44 +
45 + Say Y, please.
46 +
47 config USE_OF
48 bool
49 select OF
50 --- a/arch/mips/Makefile
51 +++ b/arch/mips/Makefile
52 @@ -275,7 +275,7 @@ OBJCOPYFLAGS += --remove-section=.regin
53 head-y := arch/mips/kernel/head.o
54
55 libs-y += arch/mips/lib/
56 -libs-y += arch/mips/math-emu/
57 +libs-$(CONFIG_MIPS_FPU_EMULATOR) += arch/mips/math-emu/
58
59 # See arch/mips/Kbuild for content of core part of the kernel
60 core-y += arch/mips/
61 --- a/arch/mips/include/asm/fpu.h
62 +++ b/arch/mips/include/asm/fpu.h
63 @@ -169,8 +169,10 @@ static inline int init_fpu(void)
64 ret = __own_fpu();
65 if (!ret)
66 _init_fpu();
67 - } else
68 + } else if (IS_ENABLED(CONFIG_MIPS_FPU_EMULATOR))
69 fpu_emulator_init_fpu();
70 + else
71 + ret = SIGILL;
72
73 return ret;
74 }
75 --- a/arch/mips/include/asm/fpu_emulator.h
76 +++ b/arch/mips/include/asm/fpu_emulator.h
77 @@ -30,6 +30,7 @@
78 #include <asm/local.h>
79 #include <asm/processor.h>
80
81 +#ifdef CONFIG_MIPS_FPU_EMULATOR
82 #ifdef CONFIG_DEBUG_FS
83
84 struct mips_fpu_emulator_stats {
85 @@ -65,6 +66,20 @@ extern int do_dsemulret(struct pt_regs *
86 extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
87 struct mips_fpu_struct *ctx, int has_fpu,
88 void *__user *fault_addr);
89 +#else /* no CONFIG_MIPS_FPU_EMULATOR */
90 +static inline int do_dsemulret(struct pt_regs *xcp)
91 +{
92 + return 0; /* 0 means error, should never get here anyway */
93 +}
94 +
95 +static inline int fpu_emulator_cop1Handler(struct pt_regs *xcp,
96 + struct mips_fpu_struct *ctx, int has_fpu,
97 + void *__user *fault_addr)
98 +{
99 + return SIGILL; /* we don't speak MIPS FPU */
100 +}
101 +#endif /* CONFIG_MIPS_FPU_EMULATOR */
102 +
103 int process_fpemu_return(int sig, void __user *fault_addr);
104 int mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
105 unsigned long *contpc);