hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/arch/mips/kernel/branch.c
....@@ -20,6 +20,8 @@
2020 #include <asm/ptrace.h>
2121 #include <linux/uaccess.h>
2222
23
+#include "probes-common.h"
24
+
2325 /*
2426 * Calculate and return exception PC in case of branch delay slot
2527 * for microMIPS and MIPS16e. It does not clear the ISA mode bit.
....@@ -32,7 +34,7 @@
3234 /* Calculate exception PC in branch delay slot. */
3335 if (__get_user(inst, (u16 __user *) msk_isa16_mode(epc))) {
3436 /* This should never happen because delay slot was checked. */
35
- force_sig(SIGSEGV, current);
37
+ force_sig(SIGSEGV);
3638 return epc;
3739 }
3840 if (cpu_has_mips16) {
....@@ -58,9 +60,7 @@
5860 unsigned long *contpc)
5961 {
6062 union mips_instruction insn = (union mips_instruction)dec_insn.insn;
61
- int bc_false = 0;
62
- unsigned int fcr31;
63
- unsigned int bit;
63
+ int __maybe_unused bc_false = 0;
6464
6565 if (!cpu_has_mmips)
6666 return 0;
....@@ -92,7 +92,7 @@
9292 regs->regs[31] = regs->cp0_epc +
9393 dec_insn.pc_inc +
9494 dec_insn.next_pc_inc;
95
- /* Fall through */
95
+ fallthrough;
9696 case mm_bltz_op:
9797 if ((long)regs->regs[insn.mm_i_format.rs] < 0)
9898 *contpc = regs->cp0_epc +
....@@ -108,7 +108,7 @@
108108 regs->regs[31] = regs->cp0_epc +
109109 dec_insn.pc_inc +
110110 dec_insn.next_pc_inc;
111
- /* Fall through */
111
+ fallthrough;
112112 case mm_bgez_op:
113113 if ((long)regs->regs[insn.mm_i_format.rs] >= 0)
114114 *contpc = regs->cp0_epc +
....@@ -139,10 +139,14 @@
139139 dec_insn.pc_inc +
140140 dec_insn.next_pc_inc;
141141 return 1;
142
+#ifdef CONFIG_MIPS_FP_SUPPORT
142143 case mm_bc2f_op:
143
- case mm_bc1f_op:
144
+ case mm_bc1f_op: {
145
+ unsigned int fcr31;
146
+ unsigned int bit;
147
+
144148 bc_false = 1;
145
- /* Fall through */
149
+ fallthrough;
146150 case mm_bc2t_op:
147151 case mm_bc1t_op:
148152 preempt_disable();
....@@ -167,6 +171,8 @@
167171 dec_insn.pc_inc + dec_insn.next_pc_inc;
168172 return 1;
169173 }
174
+#endif /* CONFIG_MIPS_FP_SUPPORT */
175
+ }
170176 break;
171177 case mm_pool16c_op:
172178 switch (insn.mm_i_format.rt) {
....@@ -174,7 +180,7 @@
174180 case mm_jalrs16_op:
175181 regs->regs[31] = regs->cp0_epc +
176182 dec_insn.pc_inc + dec_insn.next_pc_inc;
177
- /* Fall through */
183
+ fallthrough;
178184 case mm_jr16_op:
179185 *contpc = regs->regs[insn.mm_i_format.rs];
180186 return 1;
....@@ -235,7 +241,7 @@
235241 case mm_jal32_op:
236242 regs->regs[31] = regs->cp0_epc +
237243 dec_insn.pc_inc + dec_insn.next_pc_inc;
238
- /* Fall through */
244
+ fallthrough;
239245 case mm_j32_op:
240246 *contpc = regs->cp0_epc + dec_insn.pc_inc;
241247 *contpc >>= 27;
....@@ -301,7 +307,7 @@
301307 return 0;
302308
303309 sigsegv:
304
- force_sig(SIGSEGV, current);
310
+ force_sig(SIGSEGV);
305311 return -EFAULT;
306312 }
307313
....@@ -324,7 +330,7 @@
324330 /* Read the instruction. */
325331 addr = (u16 __user *)msk_isa16_mode(epc);
326332 if (__get_user(inst.full, addr)) {
327
- force_sig(SIGSEGV, current);
333
+ force_sig(SIGSEGV);
328334 return -EFAULT;
329335 }
330336
....@@ -339,7 +345,7 @@
339345 case MIPS16e_jal_op:
340346 addr += 1;
341347 if (__get_user(inst2, addr)) {
342
- force_sig(SIGSEGV, current);
348
+ force_sig(SIGSEGV);
343349 return -EFAULT;
344350 }
345351 fullinst = ((unsigned)inst.full << 16) | inst2;
....@@ -416,8 +422,8 @@
416422 int __compute_return_epc_for_insn(struct pt_regs *regs,
417423 union mips_instruction insn)
418424 {
419
- unsigned int bit, fcr31, dspcontrol, reg;
420425 long epc = regs->cp0_epc;
426
+ unsigned int dspcontrol;
421427 int ret = 0;
422428
423429 switch (insn.i_format.opcode) {
....@@ -428,7 +434,7 @@
428434 switch (insn.r_format.func) {
429435 case jalr_op:
430436 regs->regs[insn.r_format.rd] = epc + 8;
431
- /* Fall through */
437
+ fallthrough;
432438 case jr_op:
433439 if (NO_R6EMU && insn.r_format.func == jr_op)
434440 goto sigill_r2r6;
....@@ -447,6 +453,7 @@
447453 case bltzl_op:
448454 if (NO_R6EMU)
449455 goto sigill_r2r6;
456
+ fallthrough;
450457 case bltz_op:
451458 if ((long)regs->regs[insn.i_format.rs] < 0) {
452459 epc = epc + 4 + (insn.i_format.simmediate << 2);
....@@ -460,6 +467,7 @@
460467 case bgezl_op:
461468 if (NO_R6EMU)
462469 goto sigill_r2r6;
470
+ fallthrough;
463471 case bgez_op:
464472 if ((long)regs->regs[insn.i_format.rs] >= 0) {
465473 epc = epc + 4 + (insn.i_format.simmediate << 2);
....@@ -555,6 +563,7 @@
555563 case jalx_op:
556564 case jal_op:
557565 regs->regs[31] = regs->cp0_epc + 8;
566
+ fallthrough;
558567 case j_op:
559568 epc += 4;
560569 epc >>= 28;
....@@ -571,6 +580,7 @@
571580 case beql_op:
572581 if (NO_R6EMU)
573582 goto sigill_r2r6;
583
+ fallthrough;
574584 case beq_op:
575585 if (regs->regs[insn.i_format.rs] ==
576586 regs->regs[insn.i_format.rt]) {
....@@ -585,6 +595,7 @@
585595 case bnel_op:
586596 if (NO_R6EMU)
587597 goto sigill_r2r6;
598
+ fallthrough;
588599 case bne_op:
589600 if (regs->regs[insn.i_format.rs] !=
590601 regs->regs[insn.i_format.rt]) {
....@@ -599,6 +610,7 @@
599610 case blezl_op: /* not really i_format */
600611 if (!insn.i_format.rt && NO_R6EMU)
601612 goto sigill_r2r6;
613
+ fallthrough;
602614 case blez_op:
603615 /*
604616 * Compact branches for R6 for the
....@@ -634,6 +646,7 @@
634646 case bgtzl_op:
635647 if (!insn.i_format.rt && NO_R6EMU)
636648 goto sigill_r2r6;
649
+ fallthrough;
637650 case bgtz_op:
638651 /*
639652 * Compact branches for R6 for the
....@@ -667,23 +680,18 @@
667680 regs->cp0_epc = epc;
668681 break;
669682
683
+#ifdef CONFIG_MIPS_FP_SUPPORT
670684 /*
671685 * And now the FPA/cp1 branch instructions.
672686 */
673
- case cop1_op:
687
+ case cop1_op: {
688
+ unsigned int bit, fcr31, reg;
689
+
674690 if (cpu_has_mips_r6 &&
675691 ((insn.i_format.rs == bc1eqz_op) ||
676692 (insn.i_format.rs == bc1nez_op))) {
677
- if (!used_math()) { /* First time FPU user */
678
- ret = init_fpu();
679
- if (ret && NO_R6EMU) {
680
- ret = -ret;
681
- break;
682
- }
683
- ret = 0;
684
- set_used_math();
685
- }
686
- lose_fpu(1); /* Save FPU state for the emulator. */
693
+ if (!init_fp_ctx(current))
694
+ lose_fpu(1);
687695 reg = insn.i_format.rt;
688696 bit = get_fpr32(&current->thread.fpu.fpr[reg], 0) & 0x1;
689697 if (insn.i_format.rs == bc1eqz_op)
....@@ -736,6 +744,9 @@
736744 }
737745 break;
738746 }
747
+ }
748
+#endif /* CONFIG_MIPS_FP_SUPPORT */
749
+
739750 #ifdef CONFIG_CPU_CAVIUM_OCTEON
740751 case lwc2_op: /* This is bbit0 on Octeon */
741752 if ((regs->regs[insn.i_format.rs] & (1ull<<insn.i_format.rt))
....@@ -820,17 +831,17 @@
820831 sigill_dsp:
821832 pr_debug("%s: DSP branch but not DSP ASE - sending SIGILL.\n",
822833 current->comm);
823
- force_sig(SIGILL, current);
834
+ force_sig(SIGILL);
824835 return -EFAULT;
825836 sigill_r2r6:
826837 pr_debug("%s: R2 branch but r2-to-r6 emulator is not present - sending SIGILL.\n",
827838 current->comm);
828
- force_sig(SIGILL, current);
839
+ force_sig(SIGILL);
829840 return -EFAULT;
830841 sigill_r6:
831842 pr_debug("%s: R6 branch but no MIPSr6 ISA support - sending SIGILL.\n",
832843 current->comm);
833
- force_sig(SIGILL, current);
844
+ force_sig(SIGILL);
834845 return -EFAULT;
835846 }
836847 EXPORT_SYMBOL_GPL(__compute_return_epc_for_insn);
....@@ -850,7 +861,7 @@
850861 */
851862 addr = (unsigned int __user *) epc;
852863 if (__get_user(insn.word, addr)) {
853
- force_sig(SIGSEGV, current);
864
+ force_sig(SIGSEGV);
854865 return -EFAULT;
855866 }
856867
....@@ -858,7 +869,7 @@
858869
859870 unaligned:
860871 printk("%s: unaligned epc - sending SIGBUS.\n", current->comm);
861
- force_sig(SIGBUS, current);
872
+ force_sig(SIGBUS);
862873 return -EFAULT;
863874 }
864875