mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:02:45 +00:00 
			
		
		
		
	Kernel: Fix deadlock in ~Memory::Region()
First off: unregister the region from MemoryManager before unmapping it. The order of operations here was a bit strange, presumably to avoid a situation where a fault would happen while unmapping, and the fault handler would find the MemoryManager region list in an invalid state. Unregistering it before unmapping sidesteps the whole problem, and allows us to easily fix another problem: a deadlock could occur due to inconsistent acquisition order (PageDirectory must come before MM.)
This commit is contained in:
		
							parent
							
								
									95c8e421ae
								
							
						
					
					
						commit
						08b4d8f0de
					
				
					 1 changed files with 4 additions and 6 deletions
				
			
		|  | @ -40,16 +40,14 @@ Region::~Region() | |||
| { | ||||
|     m_vmobject->remove_region(*this); | ||||
| 
 | ||||
|     // Make sure we disable interrupts so we don't get interrupted between unmapping and unregistering.
 | ||||
|     // Unmapping the region will give the VM back to the VirtualRangeAllocator, so an interrupt handler would
 | ||||
|     // find the address<->region mappings in an invalid state there.
 | ||||
|     ScopedSpinLock lock(s_mm_lock); | ||||
|     MM.unregister_region(*this); | ||||
| 
 | ||||
|     if (m_page_directory) { | ||||
|         ScopedSpinLock page_lock(m_page_directory->get_lock()); | ||||
|         ScopedSpinLock lock(s_mm_lock); | ||||
|         unmap(ShouldDeallocateVirtualRange::Yes); | ||||
|         VERIFY(!m_page_directory); | ||||
|     } | ||||
| 
 | ||||
|     MM.unregister_region(*this); | ||||
| } | ||||
| 
 | ||||
| OwnPtr<Region> Region::clone() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling