Skip to contentSkip to conversation

btrfs: remove the dead copied check in btrfs_copy_from_user()

PATCH In review Qu Wenruo 2 participants 3 messages Aug 13, 2020 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: remove the dead copied check in btrfs_copy_from_user()

There is btrfs specific check in btrfs_copy_from_user(), after iov_iter_copy_from_user_atomic() call, we check if the page is uptodate and if the copied bytes is smaller than what we expect.

However that check will never be triggered due to the following reasons:
- PageUptodate() check conflicts with current behavior Currently we ensure all pages that will go through a partial write (some bytes are not covered by the write range) will be forced uptodate.

This is the common behavior to ensure we get the correct content. This behavior is always true, no matter if my previous patch "btrfs:
refactor how we prepare pages for btrfs_buffered_write()" is applied.

- iov_iter_copy_from_user_atomic() only returns 0 or @bytes It won't return a short write.

So we're completely fine to remove the (PageUptodate() && copied < count) check, as we either get copied == 0, and break the loop anyway, or do a proper copy.

This will revert commit 31339acd07b4 ("Btrfs: deal with short returns from copy_from_user").

---
 fs/btrfs/file.c | 12 ------------
 1 file changed, 12 deletions(-)
fs/btrfs/file.c +0 -12
index 705ebe709e8d..2f96f083eb8c 100644
@@ -403,18 +403,6 @@ static noinline int btrfs_copy_from_user(loff_t pos, size_t write_bytes,
 		/* Flush processor's dcache for this page */
 		flush_dcache_page(page);
 
-		/*
-		 * if we get a partial write, we can end up with
-		 * partially up to date pages.  These add
-		 * a lot of complexity, so make sure they don't
-		 * happen by forcing this copy to be retried.
-		 *
-		 * The rest of the btrfs_file_write code will fall
-		 * back to page at a time copies after we return 0.
-		 */
-		if (!PageUptodate(page) && copied < count)
-			copied = 0;
-
 		iov_iter_advance(i, copied);
 		write_bytes -= copied;
 		total_copied += copied;
Signature · 1 line
2.28.0
#1 lore raw
Quoted 10 lines · Qu Wenruo

There is btrfs specific check in btrfs_copy_from_user(), after iov_iter_copy_from_user_atomic() call, we check if the page is uptodate and if the copied bytes is smaller than what we expect.

However that check will never be triggered due to the following reasons:
- PageUptodate() check conflicts with current behavior Currently we ensure all pages that will go through a partial write (some bytes are not covered by the write range) will be forced uptodate.

Quoted 3 lines

This is the common behavior to ensure we get the correct content. This behavior is always true, no matter if my previous patch "btrfs:
refactor how we prepare pages for btrfs_buffered_write()" is applied.

Would it make sense to add an assert here? Checking for the page up-to-date status.

Quoted 2 lines

- iov_iter_copy_from_user_atomic() only returns 0 or @bytes It won't return a short write.

And maybe for that one too, I'm not able to navigate through the maze of the iov_iter_* macros.

Quoted 6 lines

So we're completely fine to remove the (PageUptodate() && copied < count) check, as we either get copied == 0, and break the loop anyway, or do a proper copy.

This will revert commit 31339acd07b4 ("Btrfs: deal with short returns from copy_from_user").

As this is a very old patch, the changes outside of btrfs are likely to make the piece of code redundant.

author
#2 lore raw
Quoted 11 lines · David Sterba
Quoted 10 lines · Qu Wenruo

There is btrfs specific check in btrfs_copy_from_user(), after iov_iter_copy_from_user_atomic() call, we check if the page is uptodate and if the copied bytes is smaller than what we expect.

However that check will never be triggered due to the following reasons:
- PageUptodate() check conflicts with current behavior Currently we ensure all pages that will go through a partial write (some bytes are not covered by the write range) will be forced uptodate.

Quoted 6 lines
Quoted 3 lines

This is the common behavior to ensure we get the correct content. This behavior is always true, no matter if my previous patch "btrfs:
refactor how we prepare pages for btrfs_buffered_write()" is applied.

Would it make sense to add an assert here? Checking for the page up-to-date status.

We can have page without uptodate bit.

Uptodate is only forced for partial written pages.
For pages that would be completely covered by write range, it doesn't need to be uptodate.

Thus the ASSERT() may be more complex than what we initially thought, but may still be feasible.

Quoted 6 lines
Quoted 3 lines

- iov_iter_copy_from_user_atomic() only returns 0 or @bytes It won't return a short write.

And maybe for that one too, I'm not able to navigate through the maze of the iov_iter_* macros.

Well, after more digging, we have similar check hidden in other location. In fact fs/buffer.c has its block_write_end() which do the same check there.

So I'm afraid unless we go through the whole maze, it may still be a problem.

The current theory would be a write in a page, but split into several different iov, thus we can still write some iov, but fails the remaining, thus lead the problem.

Please discard this patch.

Thanks,
Qu

Quoted 11 lines
Quoted 7 lines

So we're completely fine to remove the (PageUptodate() && copied < count) check, as we either get copied == 0, and break the loop anyway, or do a proper copy.

This will revert commit 31339acd07b4 ("Btrfs: deal with short returns from copy_from_user").

As this is a very old patch, the changes outside of btrfs are likely to make the piece of code redundant.