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
Notes: sideshowbarker 2024-07-19 05:00:30 +09:00

View file

@ -36,8 +36,12 @@
namespace Kernel {
static SpinLock s_all_inodes_lock;
InlineLinkedList<Inode>& all_inodes()
{
ASSERT(s_all_inodes_lock.is_locked());
static InlineLinkedList<Inode>* list;
if (!list)
list = new InlineLinkedList<Inode>;
@ -48,7 +52,7 @@ void Inode::sync()
{
NonnullRefPtrVector<Inode, 32> inodes;
{
InterruptDisabler disabler;
ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
for (auto& inode : all_inodes()) {
if (inode.is_metadata_dirty())
inodes.append(inode);
@ -111,11 +115,13 @@ Inode::Inode(FS& fs, unsigned index)
: m_fs(fs)
, m_index(index)
{
ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
all_inodes().append(this);
}
Inode::~Inode()
{
ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
all_inodes().remove(this);
}