304-mips_disable_fpu.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. From: Manuel Lauss <[email protected]>
  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: <[email protected]>
  5. This small patch makes the MIPS FPU emulator optional. The kernel
  6. kills float-users on systems without a hardware FPU by sending a SIGILL.
  7. Disabling the emulator shrinks vmlinux by about 54kBytes (32bit,
  8. optimizing for size).
  9. Signed-off-by: Manuel Lauss <[email protected]>
  10. ---
  11. v4: rediffed because of patch 1/2, should now work with micromips as well
  12. v3: updated patch description with size savings.
  13. v2: incorporated changes suggested by Jonas Gorski
  14. force the fpu emulator on for micromips: relocating the parts
  15. of the mmips code in the emulator to other areas would be a
  16. much larger change; I went the cheap route instead with this.
  17. arch/mips/Kbuild | 2 +-
  18. arch/mips/Kconfig | 14 ++++++++++++++
  19. arch/mips/include/asm/fpu.h | 5 +++--
  20. arch/mips/include/asm/fpu_emulator.h | 15 +++++++++++++++
  21. 4 files changed, 33 insertions(+), 3 deletions(-)
  22. --- a/arch/mips/Kconfig
  23. +++ b/arch/mips/Kconfig
  24. @@ -2891,6 +2891,20 @@ config MIPS_O32_FP64_SUPPORT
  25. If unsure, say N.
  26. +config MIPS_FPU_EMULATOR
  27. + bool "MIPS FPU Emulator"
  28. + default y
  29. + help
  30. + This option lets you disable the built-in MIPS FPU (Coprocessor 1)
  31. + emulator, which handles floating-point instructions on processors
  32. + without a hardware FPU. It is generally a good idea to keep the
  33. + emulator built-in, unless you are perfectly sure you have a
  34. + complete soft-float environment. With the emulator disabled, all
  35. + users of float operations will be killed with an illegal instr-
  36. + uction exception.
  37. +
  38. + Say Y, please.
  39. +
  40. config USE_OF
  41. bool
  42. select OF
  43. --- a/arch/mips/Makefile
  44. +++ b/arch/mips/Makefile
  45. @@ -287,7 +287,7 @@ OBJCOPYFLAGS += --remove-section=.regin
  46. head-y := arch/mips/kernel/head.o
  47. libs-y += arch/mips/lib/
  48. -libs-y += arch/mips/math-emu/
  49. +libs-$(CONFIG_MIPS_FPU_EMULATOR) += arch/mips/math-emu/
  50. # See arch/mips/Kbuild for content of core part of the kernel
  51. core-y += arch/mips/
  52. --- a/arch/mips/include/asm/fpu.h
  53. +++ b/arch/mips/include/asm/fpu.h
  54. @@ -227,8 +227,10 @@ static inline int init_fpu(void)
  55. /* Restore FRE */
  56. write_c0_config5(config5);
  57. enable_fpu_hazard();
  58. - } else
  59. + } else if (IS_ENABLED(CONFIG_MIPS_FPU_EMULATOR))
  60. fpu_emulator_init_fpu();
  61. + else
  62. + ret = SIGILL;
  63. return ret;
  64. }
  65. --- a/arch/mips/include/asm/fpu_emulator.h
  66. +++ b/arch/mips/include/asm/fpu_emulator.h
  67. @@ -30,6 +30,7 @@
  68. #include <asm/local.h>
  69. #include <asm/processor.h>
  70. +#ifdef CONFIG_MIPS_FPU_EMULATOR
  71. #ifdef CONFIG_DEBUG_FS
  72. struct mips_fpu_emulator_stats {
  73. @@ -63,6 +64,16 @@ do { \
  74. extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
  75. struct mips_fpu_struct *ctx, int has_fpu,
  76. void *__user *fault_addr);
  77. +#else /* no CONFIG_MIPS_FPU_EMULATOR */
  78. +static inline int fpu_emulator_cop1Handler(struct pt_regs *xcp,
  79. + struct mips_fpu_struct *ctx, int has_fpu,
  80. + void *__user *fault_addr)
  81. +{
  82. + *fault_addr = NULL;
  83. + return SIGILL; /* we don't speak MIPS FPU */
  84. +}
  85. +#endif /* CONFIG_MIPS_FPU_EMULATOR */
  86. +
  87. void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
  88. struct task_struct *tsk);
  89. int process_fpemu_return(int sig, void __user *fault_addr,
  90. --- a/arch/mips/include/asm/dsemul.h
  91. +++ b/arch/mips/include/asm/dsemul.h
  92. @@ -41,6 +41,7 @@ struct task_struct;
  93. extern int mips_dsemul(struct pt_regs *regs, mips_instruction ir,
  94. unsigned long branch_pc, unsigned long cont_pc);
  95. +#ifdef CONFIG_MIPS_FPU_EMULATOR
  96. /**
  97. * do_dsemulret() - Return from a delay slot 'emulation' frame
  98. * @xcp: User thread register context.
  99. @@ -88,5 +89,27 @@ extern bool dsemul_thread_rollback(struc
  100. * before @mm is freed in order to avoid memory leaks.
  101. */
  102. extern void dsemul_mm_cleanup(struct mm_struct *mm);
  103. +#else
  104. +static inline bool do_dsemulret(struct pt_regs *xcp)
  105. +{
  106. + return false;
  107. +}
  108. +
  109. +static inline bool dsemul_thread_cleanup(struct task_struct *tsk)
  110. +{
  111. + return false;
  112. +}
  113. +
  114. +static inline bool dsemul_thread_rollback(struct pt_regs *regs)
  115. +{
  116. + return false;
  117. +}
  118. +
  119. +static inline void dsemul_mm_cleanup(struct mm_struct *mm)
  120. +{
  121. +
  122. +}
  123. +
  124. +#endif
  125. #endif /* __MIPS_ASM_DSEMUL_H__ */