Hi,
I think I have found a hole in the logic used to protect buffers, the only
time it will really trip a system up is if it is using highmem, otherwise
it just adds more buffers into the buffer free list.
Consider the following scenario:
1. We write a large number of pages into a file, some of these are
created as highmem pages.
2. Before the data is flushed out to disk we start truncating the file,
in parallel with this a sync call is running.
The truncate path calls block_flushpage which does an unmap on the buffers,
and then calls try_to_free_buffers with wait set to zero. If one of the
page's buffers is currently being waited for by the sync call then it is
sleeping on the buffer with b_count elevated. b_count will remain elevated
until the sync thread is running on the cpu again, and until this time,
the buffer_busy test used by try_to_free_buffers() will return true.
If the I/O on the buffer has been completed and the buffer is already unlocked
when the unmap_buffer() call is made then the try_to_free_buffers thread will
complete without blocking, and will leave the buffer on the page. Note that
setting wait to 2 does not appear to prevent this from happening either - the
sync_page_buffers call just zips past the buffer since it is already clean
and unlocked.
We now return to truncate_complete_page() and remove the page from the inode,
the only reference to the page is now the buffer head.
If we unmount the filesystem at this point then the __invalidate_buffers()
call will return the buffer to the free list. So we now have a buffer with a
highmem page on the freelist, if a call to getblk pulls this buffer of the
list and does something like read ext2 metadata with it then the kernel will
oops when it attempts to look at the buffer contents.
While this scenario seems a little contrived, sync is not the only candidate
here, any thread which sleeps waiting for a buffer_head with b_count elevated
could cause the leak.
It seems that either the b_count reference on the buffer should be made into
something more like the inode reference count - when it goes to zero the buffer
is freed, or at least the put_last_free code should free this type of buffer via
__put_unused_buffer_head rather than putting it on the free list. Then we
need to deal with the reference count on the page which is still there
because we did not remove the buffer_heads.
Steve
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [EMAIL PROTECTED]