Subject: Re: UVM/PMAP_NEW on i386 panics ... not anymore
To: None <port-i386@NetBSD.ORG, chuck@NetBSD.ORG, thorpej@nas.nasa.gov>
From: Stefan Grefen <grefen@hprc.tandem.com>
List: port-i386
Date: 05/20/1998 22:43:27
I just found a little time (under the carpet :- )) and digged into 
the problem.
The problem is that if the pte page for an virtual address is not there, 
the I386 copyout code traps trying to testb the pte for this va. 
uvm can't page the pte page in and but because copyfault is set 
copyout just returns EFAULT via copyfault instead of panicing on the kernel
page-fault.

I fixed this by hacking code into trap.c to get this special case
and simulate (yuck) a testb setting PSL_Z. This results in a call
to trapwrite which gives uvm the correct page to fault-in.

The patch is below.

Now PC104 board boots again ...

Stefan
---
*** trap.c	Thu Mar  5 13:20:21 1998
--- /homes/grefen/trap.c	Wed May 20 22:07:28 1998
***************
*** 442,447 ****
--- 442,479 ----
  		/* Fault the original page in. */
  #if defined(UVM)
  		rv = uvm_fault(map, va, 0, ftype);
+ 
+ #if defined(I386_CPU)
+ 		/*
+ 		 * Now comes a realy ugly hack.
+ 		 * This can happen if copyout trys to 
+ 		 * check access for zfod and the 
+ 		 * pde entry is not yet there.
+ 		 * We do a very accurate check for this 
+ 		 * and than simultae a failure for the 
+ 		 * write test.
+ 		 * we could move that in front of the
+ 		 * uvm_fault above for performance reasons.
+ 		 * 
+ 		 * Stefan Grefen grefen@carpe.net
+ 		 */
+ 		if(rv 					/* mapping failed */
+ 		    && map!=kernel_map 			/* user process   */
+ 		    && va>=(vm_offset_t)PTE_BASE 	/* page table range*/
+ 		    && va<(vm_offset_t)PDP_BASE 	/*   ""		  */
+ 		    && pcb->pcb_onfault 		/* copyout and friends*/
+ #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
+ 		    && cpu_class==CPUCLASS_386          /* 386 CPU active */
+ #endif
+ 		) {
+ 		    int pde=*(int *)(vtopte(va));	/* get the pde */
+ 		    if(pde==0) {			/* pte page missing */
+ 			frame.tf_eflags|=PSL_Z;		/* testb return zero */
+ 		        frame.tf_eip += 8;		/* Yuck .... */
+ 			return;				/* done */
+ 		    }
+ 		}
+ #endif
  #else
  		rv = vm_fault(map, va, ftype, FALSE);
  #endif


--
Stefan Grefen                                Tandem Computers Europe Inc.
grefen@hprc.tandem.com                       High Performance Research Center
Committee, n.:
        A group of men who individually can do nothing but as a group
	decide that nothing can be done.
			-- Fred Allen