Subject: mb_map->lock.can_sleep
To: None <tech-kern@sun-lamp.cs.berkeley.edu>
From: Gordon W. Ross <gwr@jericho.mc.com>
List: tech-kern
Date: 05/03/1994 01:25:26
I have discovered that the lock.can_sleep flags DO indeed need to be
TRUE for b_map and kmem_map or user-level access will break.

Here is a better piece of DIAGNOSTIC code with some helpful
comments for the next poor unsuspecting sucker...
The addition below would have helped me find an spl problem.

Gordon

*** sys/vm/vm_kern.c.orig	Sat Jan  8 05:50:08 1994
--- sys/vm/vm_kern.c	Mon May  2 22:50:48 1994
***************
*** 396,401 ****
--- 396,426 ----
  	size = round_page(size);
  	addr = vm_map_min(map);
  
+ #ifdef	DIAGNOSTIC
+ 	if (canwait==0) {
+ 		/*
+ 		 * This has been called from an interrupt context.  Make
+ 		 * sure we can get the lock without sleeping. This is a
+ 		 * concern because the maps mb_map and kmem_map have the
+ 		 * lock.can_sleep member set to TRUE.  The following call
+ 		 * to vm_map_find only avoids calling sleep only by virtue
+ 		 * of the fact that the user-level code uses splvm() to
+ 		 * keep out interrupts while the map is locked.
+ 		 */
+ 		simple_lock(&map->lock.interlock);
+ 		if (map->lock.want_write ||
+ 			map->lock.want_upgrade ||
+ 			map->lock.read_count )
+ 		{
+ 			panic("kmem_malloc: map busy (%d,%d,%d)",
+ 				  map->lock.want_write,
+ 				  map->lock.want_upgrade,
+ 				  map->lock.read_count);
+ 		}
+ 		simple_lock(&map->lock.interlock);
+ 	}
+ #endif
+ 
  	if (vm_map_find(map, NULL, (vm_offset_t)0,
  			&addr, size, TRUE) != KERN_SUCCESS) {
  		if (canwait) { /* XXX -- then we should wait */

------------------------------------------------------------------------------