Switch to page_mkwrite_check_truncate
Subsystems (8)
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
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
@@ -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
@@ -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
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_truncateand move it tomm/filemap.c. This function doesn't seem worth inlining.Signed-off-by Andreas Gruenbacher <[email protected]>Cc Jan Kara <[email protected]>Cc Theodore Y. Ts'o <[email protected]>
Looks good to me. You can add:
Honza
Quoted 81 lines
include/linux/pagemap.h +1
-27@@ -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@@ -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
PATCH v2 1/1 fs: Un-inline page_mkwrite_check_truncate
In reply to Andreas GruenbacherPer 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
@@ -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
@@ -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
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_truncateand move it tomm/filemap.c. This function doesn't seem worth inlining.v2: Define
page_mkwrite_check_truncateoutside theCONFIG_MMUguard inmm/filemap.cto allowblock_page_mkwriteto use this helper on ARCH=m68k.Reported-by kbuild test robot <[email protected]>Signed-off-by Andreas Gruenbacher <[email protected]>Cc Jan Kara <[email protected]>Cc Theodore Y. Ts'o <[email protected]>
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@@ -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@@ -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
PATCH 2/7 fs: Switch to page_mkwrite_check_truncate in block_page_mkwrite
In reply to Andreas GruenbacherUse 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
@@ -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
PATCH 3/7 ubifs: Switch to page_mkwrite_check_truncate in ubifs_vm_page_mkwrite
In reply to Andreas GruenbacherUse 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
@@ -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
PATCH 4/7 ext4: Switch to page_mkwrite_check_truncate in ext4_page_mkwrite
In reply to Andreas GruenbacherUse 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
@@ -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
PATCH 5/7 f2fs: Switch to page_mkwrite_check_truncate in f2fs_vm_page_mkwrite
In reply to Andreas GruenbacherUse 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
@@ -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
PATCH 6/7 ceph: Switch to page_mkwrite_check_truncate in ceph_page_mkwrite
In reply to Andreas GruenbacherUse 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
@@ -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
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_truncateinstead of reimplementing it here. Other than with the existing code, fail with-EFAULT/VM_FAULT_NOPAGEwhenpage_offset(page)== size here as well, as should be expected.Signed-off-by Andreas Gruenbacher <[email protected]>Acked-by Jeff Layton <[email protected]>--- fs/ceph/addr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ceph/addr.c +0
-0
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]>
PATCH 7/7 btrfs: Switch to page_mkwrite_check_truncate in btrfs_page_mkwrite
In reply to Andreas GruenbacherUse 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
@@ -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