hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/arch/mips/kernel/process.c
....@@ -42,7 +42,6 @@
4242 #include <asm/irq.h>
4343 #include <asm/mips-cps.h>
4444 #include <asm/msa.h>
45
-#include <asm/pgtable.h>
4645 #include <asm/mipsregs.h>
4746 #include <asm/processor.h>
4847 #include <asm/reg.h>
....@@ -53,6 +52,7 @@
5352 #include <asm/inst.h>
5453 #include <asm/stacktrace.h>
5554 #include <asm/irq_regs.h>
55
+#include <asm/exec.h>
5656
5757 #ifdef CONFIG_HOTPLUG_CPU
5858 void arch_cpu_idle_dead(void)
....@@ -69,13 +69,15 @@
6969 unsigned long status;
7070
7171 /* New thread loses kernel privileges. */
72
- status = regs->cp0_status & ~(ST0_CU0|ST0_CU1|ST0_FR|KU_MASK);
72
+ status = regs->cp0_status & ~(ST0_CU0|ST0_CU1|ST0_CU2|ST0_FR|KU_MASK);
7373 status |= KU_USER;
7474 regs->cp0_status = status;
7575 lose_fpu(0);
7676 clear_thread_flag(TIF_MSA_CTX_LIVE);
7777 clear_used_math();
78
+#ifdef CONFIG_MIPS_FP_SUPPORT
7879 atomic_set(&current->thread.bd_emu_frame, BD_EMUFRAME_NONE);
80
+#endif
7981 init_dsp();
8082 regs->cp0_epc = pc;
8183 regs->regs[29] = sp;
....@@ -118,8 +120,9 @@
118120 /*
119121 * Copy architecture-specific thread state
120122 */
121
-int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
122
- unsigned long kthread_arg, struct task_struct *p, unsigned long tls)
123
+int copy_thread(unsigned long clone_flags, unsigned long usp,
124
+ unsigned long kthread_arg, struct task_struct *p,
125
+ unsigned long tls)
123126 {
124127 struct thread_info *ti = task_thread_info(p);
125128 struct pt_regs *childregs, *regs = current_pt_regs();
....@@ -131,8 +134,8 @@
131134 childregs = (struct pt_regs *) childksp - 1;
132135 /* Put the stack after the struct pt_regs. */
133136 childksp = (unsigned long) childregs;
134
- p->thread.cp0_status = read_c0_status() & ~(ST0_CU2|ST0_CU1);
135
- if (unlikely(p->flags & PF_KTHREAD)) {
137
+ p->thread.cp0_status = (read_c0_status() & ~(ST0_CU2|ST0_CU1)) | ST0_KERNEL_CUMASK;
138
+ if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
136139 /* kernel thread */
137140 unsigned long status = p->thread.cp0_status;
138141 memset(childregs, 0, sizeof(struct pt_regs));
....@@ -176,7 +179,9 @@
176179 clear_tsk_thread_flag(p, TIF_FPUBOUND);
177180 #endif /* CONFIG_MIPS_MT_FPAFF */
178181
182
+#ifdef CONFIG_MIPS_FP_SUPPORT
179183 atomic_set(&p->thread.bd_emu_frame, BD_EMUFRAME_NONE);
184
+#endif
180185
181186 if (clone_flags & CLONE_SETTLS)
182187 ti->tp_value = tls;
....@@ -275,7 +280,21 @@
275280 *poff = ip->i_format.simmediate / sizeof(ulong);
276281 return 1;
277282 }
278
-
283
+#ifdef CONFIG_CPU_LOONGSON64
284
+ if ((ip->loongson3_lswc2_format.opcode == swc2_op) &&
285
+ (ip->loongson3_lswc2_format.ls == 1) &&
286
+ (ip->loongson3_lswc2_format.fr == 0) &&
287
+ (ip->loongson3_lswc2_format.base == 29)) {
288
+ if (ip->loongson3_lswc2_format.rt == 31) {
289
+ *poff = ip->loongson3_lswc2_format.offset << 1;
290
+ return 1;
291
+ }
292
+ if (ip->loongson3_lswc2_format.rq == 31) {
293
+ *poff = (ip->loongson3_lswc2_format.offset << 1) + 1;
294
+ return 1;
295
+ }
296
+ }
297
+#endif
279298 return 0;
280299 #endif
281300 }
....@@ -650,8 +669,10 @@
650669 {
651670 unsigned long top = TASK_SIZE & PAGE_MASK;
652671
653
- /* One page for branch delay slot "emulation" */
654
- top -= PAGE_SIZE;
672
+ if (IS_ENABLED(CONFIG_MIPS_FP_SUPPORT)) {
673
+ /* One page for branch delay slot "emulation" */
674
+ top -= PAGE_SIZE;
675
+ }
655676
656677 /* Space for the VDSO, data page & GIC user page */
657678 top -= PAGE_ALIGN(current->thread.abi->vdso->size);
....@@ -736,10 +757,9 @@
736757 /*
737758 * This is icky, but we use this to simply ensure that all CPUs have
738759 * context switched, regardless of whether they were previously running
739
- * kernel or user code. This ensures that no CPU currently has its FPU
740
- * enabled, or is about to attempt to enable it through any path other
741
- * than enable_restore_fp_context() which will wait appropriately for
742
- * fp_mode_switching to be zero.
760
+ * kernel or user code. This ensures that no CPU that a mode-switching
761
+ * program may execute on keeps its FPU enabled (& in the old mode)
762
+ * throughout the mode switch.
743763 */
744764 return 0;
745765 }
....@@ -827,8 +847,6 @@
827847 for_each_cpu_and(cpu, &process_cpus, cpu_online_mask)
828848 work_on_cpu(cpu, prepare_for_fp_mode_switch, NULL);
829849 put_online_cpus();
830
-
831
- wake_up_var(&task->mm->context.fp_mode_switching);
832850
833851 return 0;
834852 }