Open BurtonQin opened 4 years ago
There are two kinds of possible deadlock bugs in rcore-fs/rcore-fs-sfs/src/lib.rs:
Double-Lock: https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L394-L397 The first lock self.disk_inode.write() is on L394. fn _resize is called on L396. The read and write locks of self.disk_inode are heavily used in fn _resize and its callees. fn _write_at is called L397, which calls fn _io_at on L352. The second lock is on L324 in fn _io_at. https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L351-L352 https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L324 A simple drop(disk_inode) before L396 may fix the bugs. But we need to be careful about possible atomicity violations.
self.disk_inode.write()
fn _resize
self.disk_inode
fn _write_at
fn _io_at
drop(disk_inode)
Locks in conflicting orders: self.super_block.write() is called before self.free_map.write() in fn sync. https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L944-L951 self.super_block.write() is called after self.free_map.write() in fn alloc_block and fn free_block. https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L841-L845 https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L859-L863 A possible fix is to move self.free_map.write() before self.super_block.write() in fn sync.
self.super_block.write()
self.free_map.write()
fn sync
fn alloc_block
fn free_block
Yes, we didn't carefully handle locks.
There are two kinds of possible deadlock bugs in rcore-fs/rcore-fs-sfs/src/lib.rs:
Double-Lock: https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L394-L397 The first lock
self.disk_inode.write()
is on L394.fn _resize
is called on L396. The read and write locks ofself.disk_inode
are heavily used infn _resize
and its callees.fn _write_at
is called L397, which callsfn _io_at
on L352. The second lock is on L324 infn _io_at
. https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L351-L352 https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L324 A simpledrop(disk_inode)
before L396 may fix the bugs. But we need to be careful about possible atomicity violations.Locks in conflicting orders:
self.super_block.write()
is called beforeself.free_map.write()
infn sync
. https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L944-L951self.super_block.write()
is called afterself.free_map.write()
infn alloc_block
andfn free_block
. https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L841-L845 https://github.com/rcore-os/rcore-fs/blob/1fb7c0ee2eedb37516344e93c271c3e6795f9a89/rcore-fs-sfs/src/lib.rs#L859-L863 A possible fix is to moveself.free_map.write()
beforeself.super_block.write()
infn sync
.