Skip to contentSkip to conversation

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

PATCH Superseded Manuel Lauss 2 participants 4 messages Apr 8, 2014 MIPS

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 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: 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 v6 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).

---
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          | 25 +++++++++++++++++--------
 arch/mips/include/asm/fpu_emulator.h | 15 +++++++++++++++
 4 files changed, 44 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 +17 -8
index 4d86b72..c3d418d 100644
@@ -154,17 +154,26 @@ static inline void lose_fpu(int save)
 static inline int init_fpu(void)
 {
 	int ret = 0;
+	static int first = 1;
 
-	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();
+		if (likely(first)) {
+			first = 0;
+			pr_err("FPU support disabled, but FPU use "
+			       "detected! Make sure you have a "
+			       "softfloat userspace!\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 v6 2/2] MIPS: optional floating point support

Quoted 10 lines · Manuel Lauss

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).

---

(snip)

arch/mips/include/asm/fpu.h static inline void lose_fpu(int save) · line 157

Quoted 9 lines
arch/mips/include/asm/fpu.h +1 -0
index 4d86b72..c3d418d 100644
@@ -154,17 +154,26 @@ static inline void lose_fpu(int save)
 static inline int init_fpu(void)
 {
        int ret = 0;
+       static int first = 1;

This one could go into the else branch of (IS_ENABLED(CONFIG_MIPS_FPU_SUPPORT)).

Quoted 4 lines
arch/mips/include/asm/fpu.h +0 -3
-       preempt_disable();
-       if (cpu_has_fpu) {
-               ret = __own_fpu();

arch/mips/include/asm/fpu.h static inline void lose_fpu(int save) · line 166

Quoted 10 lines
arch/mips/include/asm/fpu.h +8 -2
-               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();

Braces belong on all branches of a conditional, see Chapter 3 of CodingStyle.

arch/mips/include/asm/fpu.h static inline void lose_fpu(int save) · line 173

Quoted 8 lines
arch/mips/include/asm/fpu.h +6 -1
+               preempt_enable();
        } else {
-               fpu_emulator_init_fpu();
+               if (likely(first)) {
+                       first = 0;
+                       pr_err("FPU support disabled, but FPU use "
+                              "detected! Make sure you have a "
+                              "softfloat userspace!\n");

Don't split strings, it makes it hard to grep for and they have a special exception to exceed the normal 80 characters per line limit (Checkpatch does not complain about it). See also Chapter 2 of CodingStyle.

Apart from that it looks okay to me.

Regards

Jonas

#3 lore raw

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

Quoted 14 lines · Jonas Gorski
Quoted 10 lines · Manuel Lauss

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).

---

(snip)

Quoted 13 lines

arch/mips/include/asm/fpu.h static inline void lose_fpu(int save) · line 157

Quoted 9 lines
arch/mips/include/asm/fpu.h +1 -0
index 4d86b72..c3d418d 100644
@@ -154,17 +154,26 @@ static inline void lose_fpu(int save)
 static inline int init_fpu(void)
 {
        int ret = 0;
+       static int first = 1;

This one could go into the else branch of (IS_ENABLED(CONFIG_MIPS_FPU_SUPPORT)). [...]
Braces belong on all branches of a conditional, see Chapter 3 of CodingStyle.

Done x2

Quoted 9 lines

arch/mips/include/asm/fpu.h static inline void lose_fpu(int save) · line 173

Quoted 8 lines
arch/mips/include/asm/fpu.h +6 -1
+               preempt_enable();
        } else {
-               fpu_emulator_init_fpu();
+               if (likely(first)) {
+                       first = 0;
+                       pr_err("FPU support disabled, but FPU use "
+                              "detected! Make sure you have a "
+                              "softfloat userspace!\n");
Quoted 4 lines

Don't split strings, it makes it hard to grep for and they have a special exception to exceed the normal 80 characters per line limit (Checkpatch does not complain about it). See also Chapter 2 of CodingStyle.

I'll trim the text a bit as well.

Thanks!
Manuel