mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:22:43 +00:00 
			
		
		
		
	Kernel: Protect FramebufferDevice with spinlock instead of mutex
This commit is contained in:
		
							parent
							
								
									ddde9e7ee5
								
							
						
					
					
						commit
						ca42621be1
					
				
					 5 changed files with 18 additions and 19 deletions
				
			
		|  | @ -130,7 +130,7 @@ ErrorOr<size_t> FramebufferDevice::buffer_length(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     auto adapter = m_graphics_adapter.strong_ref(); | ||||
|     if (!adapter) | ||||
|         return Error::from_errno(EIO); | ||||
|  | @ -145,7 +145,7 @@ ErrorOr<size_t> FramebufferDevice::pitch(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     return m_framebuffer_pitch; | ||||
| } | ||||
| ErrorOr<size_t> FramebufferDevice::height(size_t head) const | ||||
|  | @ -154,7 +154,7 @@ ErrorOr<size_t> FramebufferDevice::height(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     return m_framebuffer_height; | ||||
| } | ||||
| ErrorOr<size_t> FramebufferDevice::width(size_t head) const | ||||
|  | @ -163,7 +163,7 @@ ErrorOr<size_t> FramebufferDevice::width(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     return m_framebuffer_width; | ||||
| } | ||||
| ErrorOr<size_t> FramebufferDevice::vertical_offset(size_t head) const | ||||
|  | @ -172,7 +172,7 @@ ErrorOr<size_t> FramebufferDevice::vertical_offset(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_buffer_offset_lock); | ||||
|     SpinlockLocker locker(m_buffer_offset_lock); | ||||
|     return m_y_offset; | ||||
| } | ||||
| ErrorOr<bool> FramebufferDevice::vertical_offsetted(size_t head) const | ||||
|  | @ -181,7 +181,7 @@ ErrorOr<bool> FramebufferDevice::vertical_offsetted(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_buffer_offset_lock); | ||||
|     SpinlockLocker locker(m_buffer_offset_lock); | ||||
|     return m_y_offset == 0 ? 0 : 1; | ||||
| } | ||||
| 
 | ||||
|  | @ -191,8 +191,8 @@ ErrorOr<void> FramebufferDevice::set_head_resolution(size_t head, size_t width, | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker buffer_offset_locker(m_buffer_offset_lock); | ||||
|     MutexLocker resolution_locker(m_resolution_lock); | ||||
|     SpinlockLocker buffer_offset_locker(m_buffer_offset_lock); | ||||
|     SpinlockLocker resolution_locker(m_resolution_lock); | ||||
|     auto adapter = m_graphics_adapter.strong_ref(); | ||||
|     if (!adapter) | ||||
|         return Error::from_errno(EIO); | ||||
|  | @ -211,7 +211,7 @@ ErrorOr<void> FramebufferDevice::set_head_buffer(size_t head, bool second_buffer | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_buffer_offset_lock); | ||||
|     SpinlockLocker locker(m_buffer_offset_lock); | ||||
|     auto adapter = m_graphics_adapter.strong_ref(); | ||||
|     if (!adapter) | ||||
|         return Error::from_errno(EIO); | ||||
|  |  | |||
|  | @ -56,7 +56,7 @@ private: | |||
|     size_t m_framebuffer_height { 0 }; | ||||
| 
 | ||||
|     Spinlock m_activation_lock; | ||||
|     mutable Mutex m_buffer_offset_lock; | ||||
|     mutable Spinlock m_buffer_offset_lock; | ||||
| 
 | ||||
|     RefPtr<Memory::AnonymousVMObject> m_real_framebuffer_vmobject; | ||||
|     RefPtr<Memory::AnonymousVMObject> m_swapped_framebuffer_vmobject; | ||||
|  |  | |||
|  | @ -124,7 +124,7 @@ ErrorOr<void> GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned req | |||
|         auto flush_rects = TRY(copy_typed_from_user(user_flush_rects)); | ||||
|         if (Checked<unsigned>::multiplication_would_overflow(flush_rects.count, sizeof(FBRect))) | ||||
|             return Error::from_errno(EFAULT); | ||||
|         MutexLocker locker(m_flushing_lock); | ||||
|         SpinlockLocker locker(m_flushing_lock); | ||||
|         if (flush_rects.count > 0) { | ||||
|             for (unsigned i = 0; i < flush_rects.count; i++) { | ||||
|                 FBRect user_dirty_rect; | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ | |||
| #include <AK/Types.h> | ||||
| #include <Kernel/Devices/BlockDevice.h> | ||||
| #include <Kernel/Graphics/GenericGraphicsAdapter.h> | ||||
| #include <Kernel/Locking/Mutex.h> | ||||
| #include <Kernel/Locking/Spinlock.h> | ||||
| #include <LibC/sys/ioctl_numbers.h> | ||||
| 
 | ||||
| namespace Kernel { | ||||
|  | @ -63,9 +63,8 @@ protected: | |||
| 
 | ||||
|     GenericFramebufferDevice(const GenericGraphicsAdapter&); | ||||
|     mutable WeakPtr<GenericGraphicsAdapter> m_graphics_adapter; | ||||
|     mutable Mutex m_heads_lock; | ||||
|     mutable Mutex m_flushing_lock; | ||||
|     mutable Mutex m_resolution_lock; | ||||
|     mutable Spinlock m_flushing_lock; | ||||
|     mutable Spinlock m_resolution_lock; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ ErrorOr<size_t> FramebufferDevice::buffer_length(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     return display_info().rect.width * display_info().rect.height * 4; | ||||
| } | ||||
| ErrorOr<size_t> FramebufferDevice::pitch(size_t head) const | ||||
|  | @ -34,7 +34,7 @@ ErrorOr<size_t> FramebufferDevice::pitch(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     return display_info().rect.width * 4; | ||||
| } | ||||
| ErrorOr<size_t> FramebufferDevice::height(size_t head) const | ||||
|  | @ -43,7 +43,7 @@ ErrorOr<size_t> FramebufferDevice::height(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     return display_info().rect.height; | ||||
| } | ||||
| ErrorOr<size_t> FramebufferDevice::width(size_t head) const | ||||
|  | @ -52,7 +52,7 @@ ErrorOr<size_t> FramebufferDevice::width(size_t head) const | |||
|     // We take care to verify this at the GenericFramebufferDevice::ioctl method
 | ||||
|     // so if we happen to accidentally have a value different than 0, assert.
 | ||||
|     VERIFY(head == 0); | ||||
|     MutexLocker locker(m_resolution_lock); | ||||
|     SpinlockLocker locker(m_resolution_lock); | ||||
|     return display_info().rect.width; | ||||
| } | ||||
| ErrorOr<size_t> FramebufferDevice::vertical_offset(size_t head) const | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling