From ab3e000fdefa15404bf0a25dee375e684b02eb00 Mon Sep 17 00:00:00 2001
From: Ian Moffett <ian@osmora.org>
Date: Sat, 25 May 2024 23:25:11 -0400
Subject: kernel: vm_map: Fix deadlock

Signed-off-by: Ian Moffett <ian@osmora.org>
---
 sys/vm/vm_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'sys/vm')

diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c
index 2501e08..11222e0 100644
--- a/sys/vm/vm_map.c
+++ b/sys/vm/vm_map.c
@@ -287,7 +287,6 @@ munmap(void *addr, size_t len)
     size_t map_len, granule;
     vaddr_t map_start, map_end;
 
-    spinlock_acquire(&td->mapspace_lock);
     ms = &td->mapspace;
 
     granule = vm_get_page_size();
@@ -296,6 +295,7 @@ munmap(void *addr, size_t len)
         return -1;
     }
 
+    spinlock_acquire(&td->mapspace_lock);
     map_start = mapping->range.start;
     map_end = mapping->range.end;
     map_len = map_end - map_start;
-- 
cgit v1.2.3