diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-03 15:33:29 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-03 16:11:26 +0100 |
commit | ca42621be17a85f0ec3513404a6fbce063be370d (patch) | |
tree | b47ba53fb0fbc1695695f9ac53e7c7150f744305 | |
parent | ddde9e7ee52b6d5c955ce3bbd4bc46eff5e0ed94 (diff) | |
download | serenity-ca42621be17a85f0ec3513404a6fbce063be370d.zip |
Kernel: Protect FramebufferDevice with spinlock instead of mutex
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.cpp | 18 | ||||
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.h | 2 | ||||
-rw-r--r-- | Kernel/Graphics/GenericFramebufferDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Graphics/GenericFramebufferDevice.h | 7 | ||||
-rw-r--r-- | Kernel/Graphics/VirtIOGPU/FramebufferDevice.cpp | 8 |
5 files changed, 18 insertions, 19 deletions
diff --git a/Kernel/Graphics/FramebufferDevice.cpp b/Kernel/Graphics/FramebufferDevice.cpp index ab3dbca7c4..f8f77780b9 100644 --- a/Kernel/Graphics/FramebufferDevice.cpp +++ b/Kernel/Graphics/FramebufferDevice.cpp @@ -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); diff --git a/Kernel/Graphics/FramebufferDevice.h b/Kernel/Graphics/FramebufferDevice.h index 8846112434..7b1573c5b5 100644 --- a/Kernel/Graphics/FramebufferDevice.h +++ b/Kernel/Graphics/FramebufferDevice.h @@ -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; diff --git a/Kernel/Graphics/GenericFramebufferDevice.cpp b/Kernel/Graphics/GenericFramebufferDevice.cpp index d2b37f1e8e..6d622542ef 100644 --- a/Kernel/Graphics/GenericFramebufferDevice.cpp +++ b/Kernel/Graphics/GenericFramebufferDevice.cpp @@ -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; diff --git a/Kernel/Graphics/GenericFramebufferDevice.h b/Kernel/Graphics/GenericFramebufferDevice.h index 6c21041c9f..0c26985b75 100644 --- a/Kernel/Graphics/GenericFramebufferDevice.h +++ b/Kernel/Graphics/GenericFramebufferDevice.h @@ -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; }; } diff --git a/Kernel/Graphics/VirtIOGPU/FramebufferDevice.cpp b/Kernel/Graphics/VirtIOGPU/FramebufferDevice.cpp index 58728ec86d..e70733e7d5 100644 --- a/Kernel/Graphics/VirtIOGPU/FramebufferDevice.cpp +++ b/Kernel/Graphics/VirtIOGPU/FramebufferDevice.cpp @@ -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 |