Skip to contentSkip to conversation

MIPS: move mmips branch support code out of the fpu emu code

PATCH In review Manuel Lauss 2 participants 3 messages Apr 8, 2014 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/2 MIPS: move mmips branch support code out of the fpu emu code

moves mm_isBranchInstr() from math-emu code to branch code. Required for a follow-on patch to disable the math-emu code completely.

---
v4/5/6/7: initial release, no changes

 arch/mips/include/asm/branch.h       |   2 +
 arch/mips/include/asm/fpu_emulator.h |   2 -
 arch/mips/kernel/branch.c            | 200 +++++++++++++++++++++++++++++++++++
 arch/mips/math-emu/cp1emu.c          | 198 ----------------------------------
 4 files changed, 202 insertions(+), 200 deletions(-)
arch/mips/include/asm/branch.h +2 -0
index e28a3e0..1c6b5c2 100644
@@ -17,6 +17,8 @@ extern int __compute_return_epc_for_insn(struct pt_regs *regs,
 					 union mips_instruction insn);
 extern int __microMIPS_compute_return_epc(struct pt_regs *regs);
 extern int __MIPS16e_compute_return_epc(struct pt_regs *regs);
+int mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
+		     unsigned long *contpc);
 
 
 static inline int delay_slot(struct pt_regs *regs)
arch/mips/include/asm/fpu_emulator.h +0 -2
index 2abb587..283e6f3 100644
@@ -58,8 +58,6 @@ extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
 				    struct mips_fpu_struct *ctx, int has_fpu,
 				    void *__user *fault_addr);
 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);
 
 /*
  * Instruction inserted following the badinst to further tag the sequence
arch/mips/kernel/branch.c +200 -0

212 lines not on this page · raw message

arch/mips/math-emu/cp1emu.c +0 -198

216 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

PATCH v7 2/2 MIPS: optional floating point support

This small patch makes the floating point support and the FPU-emulator optional. A Warning will be printed once when first use of floating point is detected.

Disabling fpu support shrinks vmlinux by about 54kBytes (32bit, optimizing for size), and it is mainly useful for embedded devices which have no need for float math (e.g. routers).

---
v7: codingstyle, checkpatch (Jonas Gorski)
v6: complain in kernel log about first attempted use of float ops.
v5: now disable float support completely to avoid sudden program crashes
on buggy fpus when the fpu emulator cannot take over (suggested by Paul Burton).
v4: rediffed because of patch 1/2, should now work with micromips as well
v3: updated patch description with size savings.
v2: incorporated changes suggested by Jonas Gorski
force the fpu emulator on for micromips: relocating the parts of the mmips code in the emulator to other areas would be a much larger change; I went the cheap route instead with this.

 arch/mips/Kbuild                     |  2 +-
 arch/mips/Kconfig                    | 11 +++++++++++
 arch/mips/include/asm/fpu.h          | 24 ++++++++++++++++--------
 arch/mips/include/asm/fpu_emulator.h | 15 +++++++++++++++
 4 files changed, 43 insertions(+), 9 deletions(-)
arch/mips/Kbuild +1 -1
index d2cfe45..730e0a7 100644
@@ -16,7 +16,7 @@ obj- := $(platform-)
 
 obj-y += kernel/
 obj-y += mm/
-obj-y += math-emu/
+obj-$(CONFIG_MIPS_FPU_SUPPORT) += math-emu/
 
 ifdef CONFIG_KVM
 obj-y += kvm/
arch/mips/Kconfig +11 -0
index 9b53358..c8040db 100644
@@ -2482,6 +2482,17 @@ config MIPS_O32_FP64_SUPPORT
 
 	  If unsure, say N.
 
+config MIPS_FPU_SUPPORT
+	bool "MIPS FPU Support"
+	default y
+	help
+	  Support for floating point registers and FP-hardware, and also
+	  the in-kernel FPU emulator.  Disabling this option will result
+	  in all uses of floating point hardware to be killed with an
+	  illegal instruction exception, and about a 50kB smaller kernel.
+
+	  Say Y.
+
 config USE_OF
 	bool
 	select OF
arch/mips/include/asm/fpu.h +16 -8
index 4d86b72..954f52d 100644
@@ -155,16 +155,24 @@ static inline int init_fpu(void)
 {
 	int ret = 0;
 
-	preempt_disable();
-	if (cpu_has_fpu) {
-		ret = __own_fpu();
-		if (!ret)
-			_init_fpu();
+	if (IS_ENABLED(CONFIG_MIPS_FPU_SUPPORT)) {
+		preempt_disable();
+		if (cpu_has_fpu) {
+			ret = __own_fpu();
+			if (!ret)
+				_init_fpu();
+		} else {
+			fpu_emulator_init_fpu();
+		}
+		preempt_enable();
 	} else {
-		fpu_emulator_init_fpu();
+		static int first = 1;
+		if (likely(first)) {
+			first = 0;
+			pr_err("FPU support disabled, but FPU use detected!\n");
+		}
+		ret = SIGILL;
 	}
-
-	preempt_enable();
 	return ret;
 }
 
arch/mips/include/asm/fpu_emulator.h +15 -0
index 283e6f3..552a054 100644
@@ -27,6 +27,7 @@
 #include <asm/inst.h>
 #include <asm/local.h>
 
+#ifdef CONFIG_MIPS_FPU_SUPPORT
 #ifdef CONFIG_DEBUG_FS
 
 struct mips_fpu_emulator_stats {
@@ -57,6 +58,20 @@ extern int do_dsemulret(struct pt_regs *xcp);
 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_SUPPORT */
+static inline int do_dsemulret(struct pt_regs *xcp)
+{
+	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 SIGILL;	/* we don't speak MIPS FPU */
+}
+#endif	/* CONFIG_MIPS_FPU_SUPPORT */
+
 int process_fpemu_return(int sig, void __user *fault_addr);
 
 /*
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v7 2/2] MIPS: optional floating point support

Quoted 17 lines · Manuel Lauss

(snip)

arch/mips/include/asm/fpu.h +3 -5
index 4d86b72..954f52d 100644
@@ -155,16 +155,24 @@ static inline int init_fpu(void)
 {
        int ret = 0;
 
-       preempt_disable();
-       if (cpu_has_fpu) {
-               ret = __own_fpu();
-               if (!ret)
-                       _init_fpu();
+       if (IS_ENABLED(CONFIG_MIPS_FPU_SUPPORT)) {
+               preempt_disable();
+               if (cpu_has_fpu) {

arch/mips/include/asm/fpu.h static inline int init_fpu(void) · line 169

Quoted 10 lines
arch/mips/include/asm/fpu.h +8 -1
+                       ret = __own_fpu();
+                       if (!ret)
+                               _init_fpu();
+               } else {
+                       fpu_emulator_init_fpu();
+               }
+               preempt_enable();
        } else {
-               fpu_emulator_init_fpu();
+               static int first = 1;

I really hate to nitpick again but ... empty line after variable definition, please?

arch/mips/include/asm/fpu.h static inline int init_fpu(void) · line 177

Quoted 10 lines
arch/mips/include/asm/fpu.h +5 -2
+               if (likely(first)) {
+                       first = 0;
+                       pr_err("FPU support disabled, but FPU use detected!\n");
+               }
+               ret = SIGILL;
        }
-
-       preempt_enable();
        return ret;
 }

Regards
Jonas