diff mbox series

[1/3] Btrfs: fix wrong file range cleanup after an error filling dealloc range

Message ID 20200527101553.25396-1-fdmanana@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/3] Btrfs: fix wrong file range cleanup after an error filling dealloc range | expand

Commit Message

Filipe Manana May 27, 2020, 10:15 a.m. UTC
From: Filipe Manana <fdmanana@suse.com>

If an error happens while running dellaloc in COW mode for a range, we can
end up calling extent_clear_unlock_delalloc() for a range that goes beyond
our range's end offset by 1 byte, which affects 1 extra page. This results
in clearing bits and doing page operations (such as a page unlock) outside
our target range.

Fix that by calling extent_clear_unlock_delalloc() with an inclusive end
offset, instead of an exclusive end offset, at cow_file_range().

Fixes: a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba May 27, 2020, 3:01 p.m. UTC | #1
On Wed, May 27, 2020 at 11:15:53AM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> If an error happens while running dellaloc in COW mode for a range, we can
> end up calling extent_clear_unlock_delalloc() for a range that goes beyond
> our range's end offset by 1 byte, which affects 1 extra page. This results
> in clearing bits and doing page operations (such as a page unlock) outside
> our target range.
> 
> Fix that by calling extent_clear_unlock_delalloc() with an inclusive end
> offset, instead of an exclusive end offset, at cow_file_range().
> 
> Fixes: a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

1-3 added to misc-next, thanks.
Filipe Manana May 27, 2020, 4:31 p.m. UTC | #2
On Wed, May 27, 2020 at 4:02 PM David Sterba <dsterba@suse.cz> wrote:
>
> On Wed, May 27, 2020 at 11:15:53AM +0100, fdmanana@kernel.org wrote:
> > From: Filipe Manana <fdmanana@suse.com>
> >
> > If an error happens while running dellaloc in COW mode for a range, we can
> > end up calling extent_clear_unlock_delalloc() for a range that goes beyond
> > our range's end offset by 1 byte, which affects 1 extra page. This results
> > in clearing bits and doing page operations (such as a page unlock) outside
> > our target range.
> >
> > Fix that by calling extent_clear_unlock_delalloc() with an inclusive end
> > offset, instead of an exclusive end offset, at cow_file_range().
> >
> > Fixes: a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")
> > Signed-off-by: Filipe Manana <fdmanana@suse.com>
>
> 1-3 added to misc-next, thanks.

So I noticed earlier that in patch 3/3, I mention "generic/061"
instead of "btrfs/061". Would you mind amending the changelog with
just that?

Thanks.
David Sterba May 27, 2020, 6:40 p.m. UTC | #3
On Wed, May 27, 2020 at 05:31:48PM +0100, Filipe Manana wrote:
> On Wed, May 27, 2020 at 4:02 PM David Sterba <dsterba@suse.cz> wrote:
> >
> > On Wed, May 27, 2020 at 11:15:53AM +0100, fdmanana@kernel.org wrote:
> > > From: Filipe Manana <fdmanana@suse.com>
> > >
> > > If an error happens while running dellaloc in COW mode for a range, we can
> > > end up calling extent_clear_unlock_delalloc() for a range that goes beyond
> > > our range's end offset by 1 byte, which affects 1 extra page. This results
> > > in clearing bits and doing page operations (such as a page unlock) outside
> > > our target range.
> > >
> > > Fix that by calling extent_clear_unlock_delalloc() with an inclusive end
> > > offset, instead of an exclusive end offset, at cow_file_range().
> > >
> > > Fixes: a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")
> > > Signed-off-by: Filipe Manana <fdmanana@suse.com>
> >
> > 1-3 added to misc-next, thanks.
> 
> So I noticed earlier that in patch 3/3, I mention "generic/061"
> instead of "btrfs/061". Would you mind amending the changelog with
> just that?

Changelog updated, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 320d1062068d..79f833f920d3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1142,7 +1142,7 @@  static noinline int cow_file_range(struct inode *inode,
 	 */
 	if (extent_reserved) {
 		extent_clear_unlock_delalloc(inode, start,
-					     start + cur_alloc_size,
+					     start + cur_alloc_size - 1,
 					     locked_page,
 					     clear_bits,
 					     page_ops);