From b823bbd6beb99e28a67cc810c6dd7c1ac6ac8bab Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 14 Mar 2001 06:48:53 +0000 Subject: [PATCH] Fix a lock reversal problem in the VM subsystem related to threaded programs. There is a case during a fork() which can cause a deadlock. From Tor - The workaround that consists of setting a flag in the vm map that indicates that a fork is in progress and using that mark in the page fault handling to force a revalidation failure. That change will only affect (pessimize) page fault handling during fork for threaded (linuxthreads style) applications and applications using aio_*(). Submited by: tegge --- sys/vm/vm_fault.c | 6 ++++++ sys/vm/vm_map.c | 3 +++ sys/vm/vm_map.h | 1 + 3 files changed, 10 insertions(+) diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 2b200042c99..48120ee6239 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -725,6 +725,12 @@ readrest: vput(fs.vp); fs.vp = NULL; } + + if (fs.map->infork) { + release_page(&fs); + unlock_and_deallocate(&fs); + goto RetryFault; + } /* * To avoid trying to write_lock the map while another process diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 2b57b9da404..6ff0ab9fa74 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -254,6 +254,7 @@ vm_map_init(map, min, max) map->nentries = 0; map->size = 0; map->system_map = 0; + map->infork = 0; map->min_offset = min; map->max_offset = max; map->first_free = &map->header; @@ -2123,6 +2124,7 @@ vmspace_fork(vm1) vm_object_t object; vm_map_lock(old_map); + old_map->infork = 1; vm2 = vmspace_alloc(old_map->min_offset, old_map->max_offset); bcopy(&vm1->vm_startcopy, &vm2->vm_startcopy, @@ -2215,6 +2217,7 @@ vmspace_fork(vm1) } new_map->size = old_map->size; + old_map->infork = 0; vm_map_unlock(old_map); return (vm2); diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 291826b5064..d52d2d89bc6 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -162,6 +162,7 @@ struct vm_map { int nentries; /* Number of entries */ vm_size_t size; /* virtual size */ u_char system_map; /* Am I a system map? */ + u_char infork; /* Am I in fork processing? */ vm_map_entry_t hint; /* hint for quick lookups */ unsigned int timestamp; /* Version number */ vm_map_entry_t first_free; /* First free space hint */