Skip to contentSkip to conversation

Switch to page_mkwrite_check_truncate

PATCH Superseded Andreas Gruenbacher 3 participants 12 messages Feb 13, 2020 – Feb 17, 2020

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover Switch to page_mkwrite_check_truncate

Hi,

Darrick ended up not merge these changes through the xfs tree, so could you please pick them up and put them in your trees for the next merge window? Luckily the changes are all independend of each other.

Thanks,
Andreas

Andreas Gruenbacher (7):
fs: Un-inline page_mkwrite_check_truncate
fs: Switch to page_mkwrite_check_truncate in block_page_mkwrite
ubifs: Switch to page_mkwrite_check_truncate in ubifs_vm_page_mkwrite
ext4: Switch to page_mkwrite_check_truncate in ext4_page_mkwrite
f2fs: Switch to page_mkwrite_check_truncate in f2fs_vm_page_mkwrite
ceph: Switch to page_mkwrite_check_truncate in ceph_page_mkwrite
btrfs: Switch to page_mkwrite_check_truncate in btrfs_page_mkwrite

 fs/btrfs/inode.c        | 16 +++++-----------
 fs/buffer.c             | 16 +++-------------
 fs/ceph/addr.c          |  2 +-
 fs/ext4/inode.c         | 15 ++++-----------
 fs/f2fs/file.c          | 19 +++++++------------
 fs/ubifs/file.c         |  3 +--
 include/linux/pagemap.h | 28 +---------------------------
 mm/filemap.c            | 28 ++++++++++++++++++++++++++++
 8 files changed, 50 insertions(+), 77 deletions(-)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/7 fs: Un-inline page_mkwrite_check_truncate

Per review comments from Jan and Ted, un-inline page_mkwrite_check_truncate and move it to mm/filemap.c. This function doesn't seem worth inlining.

---
 include/linux/pagemap.h | 28 +---------------------------
 mm/filemap.c            | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 27 deletions(-)
include/linux/pagemap.h +1 -27
index ccb14b6a16b5..6c9c5b88924d 100644
@@ -636,32 +636,6 @@ static inline unsigned long dir_pages(struct inode *inode)
 			       PAGE_SHIFT;
 }
 
-/**
- * page_mkwrite_check_truncate - check if page was truncated
- * @page: the page to check
- * @inode: the inode to check the page against
- *
- * Returns the number of bytes in the page up to EOF,
- * or -EFAULT if the page was truncated.
- */
-static inline int page_mkwrite_check_truncate(struct page *page,
-					      struct inode *inode)
-{
-	loff_t size = i_size_read(inode);
-	pgoff_t index = size >> PAGE_SHIFT;
-	int offset = offset_in_page(size);
-
-	if (page->mapping != inode->i_mapping)
-		return -EFAULT;
-
-	/* page is wholly inside EOF */
-	if (page->index < index)
-		return PAGE_SIZE;
-	/* page is wholly past EOF */
-	if (page->index > index || !offset)
-		return -EFAULT;
-	/* page is partially inside EOF */
-	return offset;
-}
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode);
 
 #endif /* _LINUX_PAGEMAP_H */
mm/filemap.c +28 -0
index 1784478270e1..edcb4a8a6121 100644
@@ -2678,6 +2678,34 @@ const struct vm_operations_struct generic_file_vm_ops = {
 	.page_mkwrite	= filemap_page_mkwrite,
 };
 
+/**
+ * page_mkwrite_check_truncate - check if page was truncated
+ * @page: the page to check
+ * @inode: the inode to check the page against
+ *
+ * Returns the number of bytes in the page up to EOF,
+ * or -EFAULT if the page was truncated.
+ */
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode)
+{
+	loff_t size = i_size_read(inode);
+	pgoff_t index = size >> PAGE_SHIFT;
+	int offset = offset_in_page(size);
+
+	if (page->mapping != inode->i_mapping)
+		return -EFAULT;
+
+	/* page is wholly inside EOF */
+	if (page->index < index)
+		return PAGE_SIZE;
+	/* page is wholly past EOF */
+	if (page->index > index || !offset)
+		return -EFAULT;
+	/* page is partially inside EOF */
+	return offset;
+}
+EXPORT_SYMBOL(page_mkwrite_check_truncate);
+
 /* This is used for a general mmap of a disk file */
 
 int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
Signature · 1 line
2.24.1
maintainer Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] fs: Un-inline page_mkwrite_check_truncate

Quoted 6 lines · Andreas Gruenbacher

Per review comments from Jan and Ted, un-inline page_mkwrite_check_truncate and move it to mm/filemap.c. This function doesn't seem worth inlining.

Looks good to me. You can add:

Honza

Quoted 81 lines
include/linux/pagemap.h +1 -27
index ccb14b6a16b5..6c9c5b88924d 100644
@@ -636,32 +636,6 @@ static inline unsigned long dir_pages(struct inode *inode)
 			       PAGE_SHIFT;
 }
 
-/**
- * page_mkwrite_check_truncate - check if page was truncated
- * @page: the page to check
- * @inode: the inode to check the page against
- *
- * Returns the number of bytes in the page up to EOF,
- * or -EFAULT if the page was truncated.
- */
-static inline int page_mkwrite_check_truncate(struct page *page,
-					      struct inode *inode)
-{
-	loff_t size = i_size_read(inode);
-	pgoff_t index = size >> PAGE_SHIFT;
-	int offset = offset_in_page(size);
-
-	if (page->mapping != inode->i_mapping)
-		return -EFAULT;
-
-	/* page is wholly inside EOF */
-	if (page->index < index)
-		return PAGE_SIZE;
-	/* page is wholly past EOF */
-	if (page->index > index || !offset)
-		return -EFAULT;
-	/* page is partially inside EOF */
-	return offset;
-}
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode);
 
 #endif /* _LINUX_PAGEMAP_H */
mm/filemap.c +28 -0
index 1784478270e1..edcb4a8a6121 100644
@@ -2678,6 +2678,34 @@ const struct vm_operations_struct generic_file_vm_ops = {
 	.page_mkwrite	= filemap_page_mkwrite,
 };
 
+/**
+ * page_mkwrite_check_truncate - check if page was truncated
+ * @page: the page to check
+ * @inode: the inode to check the page against
+ *
+ * Returns the number of bytes in the page up to EOF,
+ * or -EFAULT if the page was truncated.
+ */
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode)
+{
+	loff_t size = i_size_read(inode);
+	pgoff_t index = size >> PAGE_SHIFT;
+	int offset = offset_in_page(size);
+
+	if (page->mapping != inode->i_mapping)
+		return -EFAULT;
+
+	/* page is wholly inside EOF */
+	if (page->index < index)
+		return PAGE_SIZE;
+	/* page is wholly past EOF */
+	if (page->index > index || !offset)
+		return -EFAULT;
+	/* page is partially inside EOF */
+	return offset;
+}
+EXPORT_SYMBOL(page_mkwrite_check_truncate);
+
 /* This is used for a general mmap of a disk file */
 
 int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
Signature · 1 line
2.24.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw

PATCH v2 1/1 fs: Un-inline page_mkwrite_check_truncate

In reply to Andreas Gruenbacher

Per review comments from Jan and Ted, un-inline page_mkwrite_check_truncate and move it to mm/filemap.c. This function doesn't seem worth inlining.

v2: Define page_mkwrite_check_truncate outside the CONFIG_MMU guard in mm/filemap.c to allow block_page_mkwrite to use this helper on ARCH=m68k.

---
 include/linux/pagemap.h | 28 +---------------------------
 mm/filemap.c            | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 27 deletions(-)
include/linux/pagemap.h +1 -27
index ccb14b6a16b5..6c9c5b88924d 100644
@@ -636,32 +636,6 @@ static inline unsigned long dir_pages(struct inode *inode)
 			       PAGE_SHIFT;
 }
 
-/**
- * page_mkwrite_check_truncate - check if page was truncated
- * @page: the page to check
- * @inode: the inode to check the page against
- *
- * Returns the number of bytes in the page up to EOF,
- * or -EFAULT if the page was truncated.
- */
-static inline int page_mkwrite_check_truncate(struct page *page,
-					      struct inode *inode)
-{
-	loff_t size = i_size_read(inode);
-	pgoff_t index = size >> PAGE_SHIFT;
-	int offset = offset_in_page(size);
-
-	if (page->mapping != inode->i_mapping)
-		return -EFAULT;
-
-	/* page is wholly inside EOF */
-	if (page->index < index)
-		return PAGE_SIZE;
-	/* page is wholly past EOF */
-	if (page->index > index || !offset)
-		return -EFAULT;
-	/* page is partially inside EOF */
-	return offset;
-}
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode);
 
 #endif /* _LINUX_PAGEMAP_H */
mm/filemap.c +28 -0
index 1784478270e1..eac4f7e84823 100644
@@ -2305,6 +2305,34 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 }
 EXPORT_SYMBOL(generic_file_read_iter);
 
+/**
+ * page_mkwrite_check_truncate - check if page was truncated
+ * @page: the page to check
+ * @inode: the inode to check the page against
+ *
+ * Returns the number of bytes in the page up to EOF,
+ * or -EFAULT if the page was truncated.
+ */
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode)
+{
+	loff_t size = i_size_read(inode);
+	pgoff_t index = size >> PAGE_SHIFT;
+	int offset = offset_in_page(size);
+
+	if (page->mapping != inode->i_mapping)
+		return -EFAULT;
+
+	/* page is wholly inside EOF */
+	if (page->index < index)
+		return PAGE_SIZE;
+	/* page is wholly past EOF */
+	if (page->index > index || !offset)
+		return -EFAULT;
+	/* page is partially inside EOF */
+	return offset;
+}
+EXPORT_SYMBOL(page_mkwrite_check_truncate);
+
 #ifdef CONFIG_MMU
 #define MMAP_LOTSAMISS  (100)
 /*
Signature · 1 line
2.24.1
maintainer Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH v2] fs: Un-inline page_mkwrite_check_truncate

Quoted 11 lines · Andreas Gruenbacher

Per review comments from Jan and Ted, un-inline page_mkwrite_check_truncate and move it to mm/filemap.c. This function doesn't seem worth inlining.

v2: Define page_mkwrite_check_truncate outside the CONFIG_MMU guard in mm/filemap.c to allow block_page_mkwrite to use this helper on ARCH=m68k.

Still looks good to me :). You can add:

Honza

Quoted 85 lines
---
 include/linux/pagemap.h | 28 +---------------------------
 mm/filemap.c            | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 27 deletions(-)
include/linux/pagemap.h +1 -27
index ccb14b6a16b5..6c9c5b88924d 100644
@@ -636,32 +636,6 @@ static inline unsigned long dir_pages(struct inode *inode)
 			       PAGE_SHIFT;
 }
 
-/**
- * page_mkwrite_check_truncate - check if page was truncated
- * @page: the page to check
- * @inode: the inode to check the page against
- *
- * Returns the number of bytes in the page up to EOF,
- * or -EFAULT if the page was truncated.
- */
-static inline int page_mkwrite_check_truncate(struct page *page,
-					      struct inode *inode)
-{
-	loff_t size = i_size_read(inode);
-	pgoff_t index = size >> PAGE_SHIFT;
-	int offset = offset_in_page(size);
-
-	if (page->mapping != inode->i_mapping)
-		return -EFAULT;
-
-	/* page is wholly inside EOF */
-	if (page->index < index)
-		return PAGE_SIZE;
-	/* page is wholly past EOF */
-	if (page->index > index || !offset)
-		return -EFAULT;
-	/* page is partially inside EOF */
-	return offset;
-}
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode);
 
 #endif /* _LINUX_PAGEMAP_H */
mm/filemap.c +28 -0
index 1784478270e1..eac4f7e84823 100644
@@ -2305,6 +2305,34 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 }
 EXPORT_SYMBOL(generic_file_read_iter);
 
+/**
+ * page_mkwrite_check_truncate - check if page was truncated
+ * @page: the page to check
+ * @inode: the inode to check the page against
+ *
+ * Returns the number of bytes in the page up to EOF,
+ * or -EFAULT if the page was truncated.
+ */
+int page_mkwrite_check_truncate(struct page *page, struct inode *inode)
+{
+	loff_t size = i_size_read(inode);
+	pgoff_t index = size >> PAGE_SHIFT;
+	int offset = offset_in_page(size);
+
+	if (page->mapping != inode->i_mapping)
+		return -EFAULT;
+
+	/* page is wholly inside EOF */
+	if (page->index < index)
+		return PAGE_SIZE;
+	/* page is wholly past EOF */
+	if (page->index > index || !offset)
+		return -EFAULT;
+	/* page is partially inside EOF */
+	return offset;
+}
+EXPORT_SYMBOL(page_mkwrite_check_truncate);
+
 #ifdef CONFIG_MMU
 #define MMAP_LOTSAMISS  (100)
 /*
Signature · 1 line
2.24.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw

PATCH 2/7 fs: Switch to page_mkwrite_check_truncate in block_page_mkwrite

In reply to Andreas Gruenbacher

Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected.

---
 fs/buffer.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
fs/buffer.c +3 -13
index b8d28370cfd7..31a9a02878a2 100644
@@ -2499,23 +2499,13 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
 	struct page *page = vmf->page;
 	struct inode *inode = file_inode(vma->vm_file);
 	unsigned long end;
-	loff_t size;
 	int ret;
 
 	lock_page(page);
-	size = i_size_read(inode);
-	if ((page->mapping != inode->i_mapping) ||
-	    (page_offset(page) > size)) {
-		/* We overload EFAULT to mean page got truncated */
-		ret = -EFAULT;
+	ret = page_mkwrite_check_truncate(page, inode);
+	if (ret < 0)
 		goto out_unlock;
-	}
-
-	/* page is wholly or partially inside EOF */
-	if (((page->index + 1) << PAGE_SHIFT) > size)
-		end = size & ~PAGE_MASK;
-	else
-		end = PAGE_SIZE;
+	end = ret;
 
 	ret = __block_write_begin(page, 0, end, get_block);
 	if (!ret)
Signature · 1 line
2.24.1
#6 lore raw

PATCH 3/7 ubifs: Switch to page_mkwrite_check_truncate in ubifs_vm_page_mkwrite

In reply to Andreas Gruenbacher

Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected.

---
 fs/ubifs/file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ubifs/file.c +1 -2
index 743928efffc1..395ff2081ecb 100644
@@ -1559,8 +1559,7 @@ static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf)
 	}
 
 	lock_page(page);
-	if (unlikely(page->mapping != inode->i_mapping ||
-		     page_offset(page) > i_size_read(inode))) {
+	if (unlikely(page_mkwrite_check_truncate(page, inode) < 0)) {
 		/* Page got truncated out from underneath us */
 		goto sigbus;
 	}
Signature · 1 line
2.24.1
#7 lore raw

PATCH 4/7 ext4: Switch to page_mkwrite_check_truncate in ext4_page_mkwrite

In reply to Andreas Gruenbacher

Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected.

---
 fs/ext4/inode.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
fs/ext4/inode.c +4 -11
index 1305b810c44a..4e00a6014fb3 100644
@@ -5902,13 +5902,11 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct page *page = vmf->page;
-	loff_t size;
 	unsigned long len;
 	int err;
 	vm_fault_t ret;
 	struct file *file = vma->vm_file;
 	struct inode *inode = file_inode(file);
-	struct address_space *mapping = inode->i_mapping;
 	handle_t *handle;
 	get_block_t *get_block;
 	int retries = 0;
@@ -5938,18 +5936,13 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
 	}
 
 	lock_page(page);
-	size = i_size_read(inode);
-	/* Page got truncated from under us? */
-	if (page->mapping != mapping || page_offset(page) > size) {
+	err = page_mkwrite_check_truncate(page, inode);
+	if (err < 0) {
 		unlock_page(page);
-		ret = VM_FAULT_NOPAGE;
-		goto out;
+		goto out_ret;
 	}
+	len = err;
 
-	if (page->index == size >> PAGE_SHIFT)
-		len = size & ~PAGE_MASK;
-	else
-		len = PAGE_SIZE;
 	/*
 	 * Return if we have all the buffers mapped. This avoids the need to do
 	 * journal_start/journal_stop which can block and take a long time
Signature · 1 line
2.24.1
#8 lore raw

PATCH 5/7 f2fs: Switch to page_mkwrite_check_truncate in f2fs_vm_page_mkwrite

In reply to Andreas Gruenbacher

Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected.

---
 fs/f2fs/file.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
fs/f2fs/file.c +7 -12
index 0d4da644df3b..0d5ac7a92230 100644
@@ -52,7 +52,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct dnode_of_data dn;
 	bool need_alloc = true;
-	int err = 0;
+	int offset, err = 0;
 
 	if (unlikely(f2fs_cp_error(sbi))) {
 		err = -EIO;
@@ -91,11 +91,12 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 	file_update_time(vmf->vma->vm_file);
 	down_read(&F2FS_I(inode)->i_mmap_sem);
 	lock_page(page);
-	if (unlikely(page->mapping != inode->i_mapping ||
-			page_offset(page) > i_size_read(inode) ||
-			!PageUptodate(page))) {
+	offset = -EFAULT;
+	if (likely(PageUptodate(page)))
+		offset = page_mkwrite_check_truncate(page, inode);
+	if (unlikely(offset < 0)) {
 		unlock_page(page);
-		err = -EFAULT;
+		err = offset;
 		goto out_sem;
 	}
 
@@ -124,14 +125,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 	if (PageMappedToDisk(page))
 		goto out_sem;
 
-	/* page is wholly or partially inside EOF */
-	if (((loff_t)(page->index + 1) << PAGE_SHIFT) >
-						i_size_read(inode)) {
-		loff_t offset;
-
-		offset = i_size_read(inode) & ~PAGE_MASK;
+	if (offset != PAGE_SIZE)
 		zero_user_segment(page, offset, PAGE_SIZE);
-	}
 	set_page_dirty(page);
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
Signature · 1 line
2.24.1
#9 lore raw

PATCH 6/7 ceph: Switch to page_mkwrite_check_truncate in ceph_page_mkwrite

In reply to Andreas Gruenbacher

Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected.

---
 fs/ceph/addr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/addr.c +1 -1
index 7ab616601141..ef958aa4adb4 100644
@@ -1575,7 +1575,7 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)
 	do {
 		lock_page(page);
 
-		if ((off > size) || (page->mapping != inode->i_mapping)) {
+		if (page_mkwrite_check_truncate(page, inode) < 0) {
 			unlock_page(page);
 			ret = VM_FAULT_NOPAGE;
 			break;
Signature · 1 line
2.24.1
#10 lore raw

Re: [PATCH 6/7] ceph: Switch to page_mkwrite_check_truncate in ceph_page_mkwrite

Quoted 16 lines · Andreas Gruenbacher

Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected.

---
 fs/ceph/addr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/addr.c +0 -0
index 7ab616601141..ef958aa4adb4 100644

fs/ceph/addr.c static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf) · line 1581

Quoted 8 lines
fs/ceph/addr.c +1 -1
@@ -1575,7 +1575,7 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)
 	do {
 		lock_page(page);
 
-		if ((off > size) || (page->mapping != inode->i_mapping)) {
+		if (page_mkwrite_check_truncate(page, inode) < 0) {
 			unlock_page(page);
 			ret = VM_FAULT_NOPAGE;
 			break;

Thanks Andreas. Merged into the ceph-client/testing branch and should make v5.7.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#11 lore raw

PATCH 7/7 btrfs: Switch to page_mkwrite_check_truncate in btrfs_page_mkwrite

In reply to Andreas Gruenbacher

Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here.

---
 fs/btrfs/inode.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
fs/btrfs/inode.c +5 -11
index 5b3ec93ff911..532cc4aa9222 100644
@@ -8441,16 +8441,15 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
 		goto out_noreserve;
 	}
 
-	ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */
 again:
 	lock_page(page);
-	size = i_size_read(inode);
 
-	if ((page->mapping != inode->i_mapping) ||
-	    (page_start >= size)) {
-		/* page got truncated out from underneath us */
+	ret2 = page_mkwrite_check_truncate(page, inode);
+	if (ret2 < 0) {
+		ret = block_page_mkwrite_return(ret2);
 		goto out_unlock;
 	}
+	zero_start = ret2;
 	wait_on_page_writeback(page);
 
 	lock_extent_bits(io_tree, page_start, page_end, &cached_state);
@@ -8471,6 +8470,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
 		goto again;
 	}
 
+	size = i_size_read(inode);
 	if (page->index == ((size - 1) >> PAGE_SHIFT)) {
 		reserved_space = round_up(size - page_start,
 					  fs_info->sectorsize);
@@ -8502,12 +8502,6 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
 		goto out_unlock;
 	}
 
-	/* page is wholly or partially inside EOF */
-	if (page_start + PAGE_SIZE > size)
-		zero_start = offset_in_page(size);
-	else
-		zero_start = PAGE_SIZE;
-
 	if (zero_start != PAGE_SIZE) {
 		kaddr = kmap(page);
 		memset(kaddr + zero_start, 0, PAGE_SIZE - zero_start);
Signature · 1 line
2.24.1