]> www.infradead.org Git - users/willy/xarray.git/commit
btrfs: fix race with memory mapped writes when activating swap file
authorFilipe Manana <fdmanana@suse.com>
Fri, 29 Nov 2024 12:25:30 +0000 (12:25 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Dec 2024 21:03:43 +0000 (22:03 +0100)
commit0525064bb82e50d59543b62b9d41a606198a4a44
tree17b2b05af48701d5d432ed0405e158c7dce2e0d5
parent0fba7be1ca6df2881e68386e5575fe096f33c4ca
btrfs: fix race with memory mapped writes when activating swap file

When activating the swap file we flush all delalloc and wait for ordered
extent completion, so that we don't miss any delalloc and extents before
we check that the file's extent layout is usable for a swap file and
activate the swap file. We are called with the inode's VFS lock acquired,
so we won't race with buffered and direct IO writes, however we can still
race with memory mapped writes since they don't acquire the inode's VFS
lock. The race window is between flushing all delalloc and locking the
whole file's extent range, since memory mapped writes lock an extent range
with the length of a page.

Fix this by acquiring the inode's mmap lock before we flush delalloc.

CC: stable@vger.kernel.org # 5.4+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c