mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:22:46 +00:00 
			
		
		
		
	Kernel: Protect Inode list with SpinLock (#2748)
Fixes crashes when a context switch happens in the middle of modifying it, or when another thread on another processor modifies it at the same time.
This commit is contained in:
		
							parent
							
								
									d4b87fb18e
								
							
						
					
					
						commit
						6df87b51f7
					
				
					 1 changed files with 7 additions and 1 deletions
				
			
		|  | @ -36,8 +36,12 @@ | ||||||
| 
 | 
 | ||||||
| namespace Kernel { | namespace Kernel { | ||||||
| 
 | 
 | ||||||
|  | static SpinLock s_all_inodes_lock; | ||||||
|  | 
 | ||||||
| InlineLinkedList<Inode>& all_inodes() | InlineLinkedList<Inode>& all_inodes() | ||||||
| { | { | ||||||
|  |     ASSERT(s_all_inodes_lock.is_locked()); | ||||||
|  | 
 | ||||||
|     static InlineLinkedList<Inode>* list; |     static InlineLinkedList<Inode>* list; | ||||||
|     if (!list) |     if (!list) | ||||||
|         list = new InlineLinkedList<Inode>; |         list = new InlineLinkedList<Inode>; | ||||||
|  | @ -48,7 +52,7 @@ void Inode::sync() | ||||||
| { | { | ||||||
|     NonnullRefPtrVector<Inode, 32> inodes; |     NonnullRefPtrVector<Inode, 32> inodes; | ||||||
|     { |     { | ||||||
|         InterruptDisabler disabler; |         ScopedSpinLock all_inodes_lock(s_all_inodes_lock); | ||||||
|         for (auto& inode : all_inodes()) { |         for (auto& inode : all_inodes()) { | ||||||
|             if (inode.is_metadata_dirty()) |             if (inode.is_metadata_dirty()) | ||||||
|                 inodes.append(inode); |                 inodes.append(inode); | ||||||
|  | @ -111,11 +115,13 @@ Inode::Inode(FS& fs, unsigned index) | ||||||
|     : m_fs(fs) |     : m_fs(fs) | ||||||
|     , m_index(index) |     , m_index(index) | ||||||
| { | { | ||||||
|  |     ScopedSpinLock all_inodes_lock(s_all_inodes_lock); | ||||||
|     all_inodes().append(this); |     all_inodes().append(this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Inode::~Inode() | Inode::~Inode() | ||||||
| { | { | ||||||
|  |     ScopedSpinLock all_inodes_lock(s_all_inodes_lock); | ||||||
|     all_inodes().remove(this); |     all_inodes().remove(this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tom
						Tom