Resent-Date: Sun, 14 Feb 1999 01:39:17 +0100 (MET)
To: linux-m68k@lists.linux-m68k.org
Subject: Fix for vfork problem (hopefully)
X-Yow: Yow!  I'm imagining a surfer van filled with soy sauce!
From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
Date: 14 Feb 1999 01:39:11 +0100
Resent-From: linux-m68k@phil.uni-sb.de

I think i have found the problem that causes the vfork crashes on 040/060.
If i read the manuals correctly, movec to urp does not flush the ATC,
unlike pmove to crp on the 68851/030.  Thus SET_PAGE_DIR needs to do that
manually.  That should also fix the kmod crashes for real.

I have also optimized the 68030 case, to avoid flushing the ATC entries
for the kernel mapping.  On the 68851 pmove already does this by itself.

Andreas.


--- linux-2.2/arch/m68k/kernel/entry.S.~1~	Wed Jan 13 18:23:35 1999
+++ linux-2.2/arch/m68k/kernel/entry.S	Sat Feb 13 19:07:03 1999
@@ -320,7 +320,14 @@
 	movec	%d0,%cacr
 
 	/* switch the root pointer */
+#ifdef CPU_M68030_ONLY
+	.chip	68030
+	pmovefd	%a1@(TASK_TSS+TSS_CRP),%crp
+	.chip	68k
+	pflush	#0,#4
+#else
 	pmove	%a1@(TASK_TSS+TSS_CRP),%crp
+#endif
 #endif
 
 #if defined(CPU_M68020_OR_M68030) && defined(CPU_M68040_OR_M68060)
--- linux-2.2/include/asm-m68k/pgtable.h.~1~	Sun Jan 17 22:31:26 1999
+++ linux-2.2/include/asm-m68k/pgtable.h	Sat Feb 13 17:51:08 1999
@@ -507,6 +507,7 @@
 	if (tsk == current) {
 		if (CPU_IS_040_OR_060)
 			__asm__ __volatile__ (".chip 68040\n\t"
+					      "pflushan\n\t"
 					      "movec %0,%%urp\n\t"
 					      ".chip 68k"
 					      : : "r" (tsk->tss.crp[1]));
@@ -514,9 +515,21 @@
 			unsigned long tmp;
 			__asm__ __volatile__ ("movec  %%cacr,%0\n\t"
 					      "orw #0x0808,%0\n\t"
-					      "movec %0,%%cacr\n\t"
-					      "pmove %1,%%crp\n\t"
-					      : "=d" (tmp)
+					      "movec %0,%%cacr"
+					      : "=d" (tmp));
+			/* For a 030-only kernel, avoid flushing the whole
+			   ATC, we only need to flush the user entries.
+			   The 68851 does this by itself.  Avoid a runtime
+			   check here.  */
+			__asm__ __volatile__ (
+#ifdef CPU_M68030_ONLY
+					      ".chip 68030\n\t"
+					      "pmovefd %0,%%crp\n\t"
+					      ".chip 68k\n\t"
+					      "pflush #0,#4"
+#else
+					      "pmove %0,%%crp"
+#endif
 					      : "m" (tsk->tss.crp[0]));
 		}
 	}
--- linux-2.2/kernel/kmod.c.~1~	Fri Nov 13 19:55:13 1998
+++ linux-2.2/kernel/kmod.c	Sat Feb 13 17:24:31 1999
@@ -7,21 +7,15 @@
 
 	Modified to avoid chroot and file sharing problems.
 	Mikael Pettersson
-
-	Flush the MMU ATC entries in exec_modprobe - this clears up random
-	kmod crashes, especially on m68k.  Richard Hirst
-
 */
 
 #define __KERNEL_SYSCALLS__
 
 #include <linux/sched.h>
 #include <linux/unistd.h>
-#include <linux/mm.h>
 #include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
-#include <asm/pgtable.h>
 
 /*
 	modprobe_path is set via /proc/sys.
@@ -54,16 +48,6 @@
 	static char * envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
 	char *argv[] = { modprobe_path, "-s", "-k", (char*)module_name, NULL };
 	int i;
-
-	/*
-	 * The MMU ATC entries need flushing somewhere round here.  This
-	 * thread was created with CLONE_VM, so there was no cause to
-	 * flush it there.  exec_mmap() called as a result of the
-	 * following execve() finds current->mm->count=2, so that doesn't
-	 * flush the MMU either.
-	 */
-
-	flush_tlb_mm(current->mm);
 
 	use_init_file_context();
 

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org

