1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 16:55:08 +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:
Tom 2020-07-09 13:51:58 -06:00 committed by GitHub
parent d4b87fb18e
commit 6df87b51f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
} }