Index: sys/vm/vm_map.c =================================================================== --- sys/vm/vm_map.c +++ sys/vm/vm_map.c @@ -389,6 +389,9 @@ if (vm->vm_refcnt == 0) panic("vmspace_free: attempt to free already freed vmspace"); + /* Ensure that pmap updates are visible to vmspace_exit(). */ + atomic_thread_fence_rel(); + if (atomic_fetchadd_int(&vm->vm_refcnt, -1) == 1) vmspace_dofree(vm); } @@ -425,10 +428,11 @@ * reference to the vmspace. */ + atomic_thread_fence_rel(); p = td->td_proc; vm = p->p_vmspace; atomic_add_int(&vmspace0.vm_refcnt, 1); - refcnt = vm->vm_refcnt; + refcnt = atomic_load_int(&vm->vm_refcnt); do { if (refcnt > 1 && p->p_vmspace != &vmspace0) { /* Switch now since other proc might free vmspace */ @@ -439,6 +443,7 @@ } } while (!atomic_fcmpset_int(&vm->vm_refcnt, &refcnt, refcnt - 1)); if (refcnt == 1) { + atomic_thread_fence_acq(); if (p->p_vmspace != vm) { /* vmspace not yet freed, switch back */ PROC_VMSPACE_LOCK(p);