From bd285887999ec723585ddde369a3f3351463ccac Mon Sep 17 00:00:00 2001 From: John Dyson Date: Mon, 15 Dec 1997 05:16:09 +0000 Subject: [PATCH] Fix a recursive kernel_map lock problem in vm_zone allocator. PR: 5298 --- sys/vm/vm_zone.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/sys/vm/vm_zone.c b/sys/vm/vm_zone.c index 5dfbf503ec8..fc1e5ba9cc2 100644 --- a/sys/vm/vm_zone.c +++ b/sys/vm/vm_zone.c @@ -18,7 +18,7 @@ * 5. Modifications may be freely made to this file if the above conditions * are met. * - * $Id: vm_zone.c,v 1.11 1997/12/05 19:55:52 bde Exp $ + * $Id: vm_zone.c,v 1.12 1997/12/14 05:17:41 dyson Exp $ */ #include @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -304,26 +305,29 @@ _zget(vm_zone_t z) nitems = (i * PAGE_SIZE) / z->zsize; } else { nbytes = z->zalloc * PAGE_SIZE; + /* - * We can wait, so just do normal kernel map allocation + * Check to see if the kernel map is already locked. We could allow + * for recursive locks, but that eliminates a valuable debugging + * mechanism, and opens up the kernel map for potential corruption + * by inconsistent data structure manipulation. We could also use + * the interrupt allocation mechanism, but that has size limitations. + * Luckily, we have kmem_map that is a submap of kernel map available + * for memory allocation, and manipulation of that map doesn't affect + * the kernel map structures themselves. + * + * We can wait, so just do normal map allocation in the appropriate + * map. */ - item = (void *) kmem_alloc(kernel_map, nbytes); - -#if 0 - if (z->zname) - printf("zalloc: %s, %d (0x%x --> 0x%x)\n", - z->zname, z->zalloc, item, - (char *)item + nbytes); - else - printf("zalloc: XXX(%d), %d (0x%x --> 0x%x)\n", - z->zsize, z->zalloc, item, - (char *)item + nbytes); - - for (i = 0; i < nbytes; i += PAGE_SIZE) - printf("(%x, %x)", (char *) item + i, - pmap_kextract((char *) item + i)); - printf("\n"); -#endif + if (lockstatus(&kernel_map->lock)) { + int s; + s = splhigh(); + item = (void *) kmem_malloc(kmem_map, nbytes, M_WAITOK); + splx(s); + } else { + item = (void *) kmem_alloc(kernel_map, nbytes); + } + nitems = nbytes / z->zsize; } z->ztotal += nitems; -- 2.45.2