Subject: other fix for the "unwiring unmanaged page" problem
To: None <tech-kern@NetBSD.ORG>
From: Matthias Drochner <drochner@zelux6.zel.kfa-juelich.de>
List: tech-kern
Date: 02/16/1998 17:56:00
Here is a different fix for the mentioned problem. It disallows procfs access
to regions mmap()ed from a device completely and thus avoids the situation
which led to the panic (or to data corruption without
MACHINE_NEW_NONCONTIG).
Would this be too restrictive?

best regards
Matthias

Index: miscfs/procfs/procfs_mem.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_mem.c,v
retrieving revision 1.18
diff -c -2 -r1.18 procfs_mem.c
*** procfs_mem.c	1998/02/10 14:10:35	1.18
--- procfs_mem.c	1998/02/16 16:36:02
***************
*** 158,162 ****
  		if (!error)
  			vm_map_lookup_done(tmap, out_entry);
!   
  		/*
  		 * Fault the page in...
--- 158,171 ----
  		if (!error)
  			vm_map_lookup_done(tmap, out_entry);
! 
! 		/*
! 		 * Don't allow to access memory mapped from a device
! 		 * because naive reads/writes could cause unwanted
! 		 * side effects.
! 		 */
! 		if (!error && object->pager &&
! 		    object->pager->pg_type == PG_DEVICE)
! 			error = EACCES;
! 
  		/*
  		 * Fault the page in...
Index: vm/vm_fault.c
===================================================================
RCS file: /cvsroot/src/sys/vm/vm_fault.c,v
retrieving revision 1.21
diff -c -2 -r1.21 vm_fault.c
*** vm_fault.c	1998/01/31 04:02:39	1.21
--- vm_fault.c	1998/02/16 16:36:03
***************
*** 921,924 ****
--- 921,928 ----
  			panic("unwire: page not in pmap");
  		}
+ #ifdef DIAGNOSTIC
+ 		if (!IS_VM_PHYSADDR(pa))
+ 			panic("vm_fault_unwire: unmanaged page");
+ #endif
  		pmap_change_wiring(pmap, va, FALSE);
  		vm_page_unwire(PHYS_TO_VM_PAGE(pa));