cloudius-systems / osv

OSv, a new operating system for the cloud.
osv.io
Other
4.12k stars 605 forks source link

rofs: use contiguous buffer when reading i-node table #1328

Closed wkozaczuk closed 3 months ago

wkozaczuk commented 3 months ago

The filesystem read and write operations call block device drivers strategy() function. The buffer argument of these functions needs to point to a contiguous area of physical memory because eventually the virtual address pointer will be converted to a physical one before being passed to the host layer.

Unfortunately, the logic in the ROFS mount that reads the master block and the i-node table uses regular malloc() to allocate buffers to read to. Everything works fine if the i-node table occupies less than 1 page (4K) on disk. But if it occupies more than 1 page of memory and underlying physical memory is fragmented one can experience errors like the one in the description of issue #1033.

This patch fixes this issue, by changing two malloc() calls with alloc_phys_contiguous_aligned(). In addition, we improve the code by using std::unique_ptr() to let the compiler emit code to automatically call free_phys_contiguous_aligned() in all cases when the rofs_mount() returns.

Fixes #1033