304-mips_disable_fpu.patch 4.1 KB

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