fs: dax: Adding new return type vm_fault_t
Subsystems (2)
PATCH 1/1 fs: dax: Adding new return type vm_fault_t
Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.
Reference id -> 1c8f422059ae ("mm: change return type to vm_fault_t")
There was an existing bug inside dax_load_hole() if vm_insert_mixed had failed to allocate a page table, we'd return VM_FAULT_NOPAGE instead of VM_FAULT_OOM. With vmf_insert_mixed this issue is addressed.
vmf_insert_mixed_mkwrite() is the new wrapper function which will convert err returned from vm_insert_mixed_ mkwrite() to vm_fault_t type.
--- fs/dax.c | 56 +++++++++++++++++++++++++++++++---------------------- include/linux/dax.h | 4 ++-- 2 files changed, 35 insertions(+), 25 deletions(-)
fs/dax.c +33 -23
@@ -869,12 +869,12 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,* If this page is ever written to we will re-fault and change the mapping to * point to real DAX storage instead. */ -static int dax_load_hole (struct address_space *mapping,void *entry, +static vm_fault_t dax_load_hole (struct address_space *mapping,void *entry,struct vm_fault *vmf) {struct inode *inode = mapping->host;unsigned long vaddr = vmf->address; -int ret =VM_FAULT_NOPAGE ; +vm_fault_t ret =VM_FAULT_NOPAGE ;struct page *zero_page;void *entry2;
@@ -891,7 +891,7 @@ static int dax_load_hole(struct address_space *mapping, void *entry, goto out; } -vm_insert_mixed (vmf->vma, vaddr,page_to_pfn_t (zero_page)); + ret =vmf_insert_mixed (vmf->vma, vaddr,page_to_pfn_t (zero_page)); out:trace_dax_load_hole (inode, vmf, ret);return ret;
@@ -1074,7 +1074,7 @@ int __dax_zero_page_range(struct block_device *bdev, }EXPORT_SYMBOL_GPL (dax_iomap_rw); -static int dax_fault_return (int error) +static vm_fault_t dax_fault_return (int error) {if (error ==0 )return VM_FAULT_NOPAGE ;
@@ -1094,6 +1094,18 @@ static bool dax_fault_is_synchronous(unsigned long flags, && (iomap->flags &IOMAP_F_DIRTY ); } +static vm_fault_t vmf_insert_mixed_mkwrite (struct vm_area_struct *vma, +unsigned long addr,pfn_t pfn) +{ +int error; +vm_fault_t vmf_ret; + + error =vm_insert_mixed_mkwrite (vma, addr, pfn); + vmf_ret =dax_fault_return (error); + +return vmf_ret; +} +static int dax_iomap_pte_fault (struct vm_fault *vmf,pfn_t *pfnp,int *iomap_errp,const struct iomap_ops *ops) {
@@ -1107,7 +1119,7 @@ static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,int error, major =0 ;bool write = vmf->flags &FAULT_FLAG_WRITE ;bool sync; -int vmf_ret =0 ; +vm_fault_t vmf_ret =0 ;void *entry;pfn_t pfn;
@@ -1225,14 +1237,12 @@ static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, }trace_dax_insert_mapping (inode, vmf, entry);if (write) - error =vm_insert_mixed_mkwrite (vma, vaddr, pfn); + vmf_ret =vmf_insert_mixed_mkwrite (vma, vaddr, pfn);else - error =vm_insert_mixed (vma, vaddr, pfn); + vmf_ret =vmf_insert_mixed (vma, vaddr, pfn); + + goto finish_iomap; -/* -EBUSY is fine, somebody else faulted on the same PTE */ -if (error == -EBUSY ) - error =0 ; -break ;case IOMAP_UNWRITTEN :case IOMAP_HOLE :if (!write) {
@@ -1270,7 +1280,7 @@ static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, }#ifdef CONFIG_FS_DAX_PMD -static int dax_pmd_load_hole (struct vm_fault *vmf,struct iomap *iomap, +static vm_fault_t dax_pmd_load_hole (struct vm_fault *vmf,struct iomap *iomap,void *entry) {struct address_space *mapping = vmf->vma->vm_file->f_mapping;
@@ -1309,7 +1319,7 @@ static int dax_pmd_load_hole(struct vm_fault *vmf, struct iomap *iomap,return VM_FAULT_FALLBACK ; } -static int dax_iomap_pmd_fault (struct vm_fault *vmf,pfn_t *pfnp, +static vm_fault_t dax_iomap_pmd_fault (struct vm_fault *vmf,pfn_t *pfnp,const struct iomap_ops *ops) {struct vm_area_struct *vma = vmf->vma;
@@ -1319,7 +1329,7 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,bool sync;unsigned int iomap_flags = (write ?IOMAP_WRITE :0 ) |IOMAP_FAULT ;struct inode *inode = mapping->host; -int result =VM_FAULT_FALLBACK ; +vm_fault_t result =VM_FAULT_FALLBACK ;struct iomap iomap = {0 };pgoff_t max_pgoff, pgoff;void *entry;
@@ -1471,7 +1481,7 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, return result; }#else -static int dax_iomap_pmd_fault (struct vm_fault *vmf,pfn_t *pfnp, +static vm_fault_t dax_iomap_pmd_fault (struct vm_fault *vmf,pfn_t *pfnp,const struct iomap_ops *ops) {return VM_FAULT_FALLBACK ;
@@ -1491,7 +1501,7 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,* has done all the necessary locking for page fault to proceed * successfully. */ -int dax_iomap_fault (struct vm_fault *vmf,enum page_entry_size pe_size, +vm_fault_t dax_iomap_fault (struct vm_fault *vmf,enum page_entry_size pe_size,pfn_t *pfnp,int *iomap_errp,const struct iomap_ops *ops) {switch (pe_size) {
@@ -1515,14 +1525,14 @@ int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,* DAX file. It takes care of marking corresponding radix tree entry as dirty * as well. */ -static int dax_insert_pfn_mkwrite (struct vm_fault *vmf, +static vm_fault_t dax_insert_pfn_mkwrite (struct vm_fault *vmf,enum page_entry_size pe_size,pfn_t pfn) {struct address_space *mapping = vmf->vma->vm_file->f_mapping;void *entry, **slot;pgoff_t index = vmf->pgoff; -int vmf_ret, error; +vm_fault_t vmf_ret;spin_lock_irq (&mapping->tree_lock); entry =get_unlocked_mapping_entry (mapping, index, &slot);
@@ -1541,8 +1551,7 @@ static int dax_insert_pfn_mkwrite(struct vm_fault *vmf,spin_unlock_irq (&mapping->tree_lock);switch (pe_size) {case PE_SIZE_PTE : - error =vm_insert_mixed_mkwrite (vmf->vma, vmf->address, pfn); - vmf_ret =dax_fault_return (error); + vmf_ret =vmf_insert_mixed_mkwrite (vmf->vma, vmf->address, pfn);break ;#ifdef CONFIG_FS_DAX_PMD case PE_SIZE_PMD :
@@ -1568,8 +1577,8 @@ static int dax_insert_pfn_mkwrite(struct vm_fault *vmf,* stored persistently on the media and handles inserting of appropriate page * table entry. */ -int dax_finish_sync_fault (struct vm_fault *vmf,enum page_entry_size pe_size, -pfn_t pfn) +vm_fault_t dax_finish_sync_fault (struct vm_fault *vmf, +enum page_entry_size pe_size,pfn_t pfn) {int err;loff_t start = ((loff_t )vmf->pgoff) <<PAGE_SHIFT ;
@@ -1581,7 +1590,8 @@ int dax_finish_sync_fault(struct vm_fault *vmf, enum page_entry_size pe_size, len =PMD_SIZE ; else WARN_ON_ONCE(1); - err =vfs_fsync_range (vmf->vma->vm_file, start, start + len -1 ,1 ); + err =vfs_fsync_range (vmf->vma->vm_file, + start, start + len -1 ,1 );if (err)return VM_FAULT_SIGBUS ;return dax_insert_pfn_mkwrite (vmf, pe_size, pfn);
include/linux/dax.h +2 -2
@@ -97,8 +97,8 @@ ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops);int dax_iomap_fault (struct vm_fault *vmf,enum page_entry_size pe_size,pfn_t *pfnp,int *errp,const struct iomap_ops *ops); -int dax_finish_sync_fault (struct vm_fault *vmf,enum page_entry_size pe_size, -pfn_t pfn); +vm_fault_t dax_finish_sync_fault (struct vm_fault *vmf, +enum page_entry_size pe_size,pfn_t pfn);int dax_delete_mapping_entry (struct address_space *mapping,pgoff_t index);int dax_invalidate_mapping_entry_sync (struct address_space *mapping,pgoff_t index);
Signature · 1 line
1.9.1
Quoted 8 lines · Souptick Joarder
Use new return type
vm_fault_tfor fault handler. For now, this is just documenting that the function returns aVM_FAULTvalue rather than an errno. Once all instances are converted,vm_fault_twill become a distinct type.Reference id ->
1c8f422059ae("mm: change return type tovm_fault_t")
Quoted 8 lines
There was an existing bug inside
dax_load_hole()ifvm_insert_mixedhad failed to allocate a page table, we'd returnVM_FAULT_NOPAGEinstead ofVM_FAULT_OOM. Withvmf_insert_mixedthis issue is addressed.
vmf_insert_mixed_mkwrite()is the new wrapper function which will convert err returned fromvm_insert_mixed_mkwrite()tovm_fault_ttype.
This doesn't apply cleanly to v4.17-rc1, as it collides with patches from Dan, and it doesn't work when applied to v4.16 because we're missing the vmf_insert_mixed() wrapper. Generally when I have an odd baseline I provide a link to a publicly accessible tree so people can grab a working version of my patches, but in this case you probably just need to merge forward to the latest linux/master.
fs/dax.c static bool dax_fault_is_synchronous(unsigned long flags, · line 1104
Quoted 12 lines
fs/dax.c +8
-0@@ -1094,6 +1094,18 @@ static bool dax_fault_is_synchronous(unsigned long flags, && (iomap->flags &IOMAP_F_DIRTY ); } +static vm_fault_t vmf_insert_mixed_mkwrite (struct vm_area_struct *vma, +unsigned long addr,pfn_t pfn) +{ +int error; +vm_fault_t vmf_ret; + + error =vm_insert_mixed_mkwrite (vma, addr, pfn); + vmf_ret =dax_fault_return (error);
No need for all the temp variables and extra lines. This is simpler as:
error = vm_insert_mixed_mkwrite(vma, addr, pfn); return dax_fault_return(error);
Obviating the need for vmf_ret, or just:
return dax_fault_return(vm_insert_mixed_mkwrite(vma, addr, pfn));
Though this may change once you address the -EBUSY handling mentioned below.
Quoted 5 lines
fs/dax.c +0
-1@@ -1225,14 +1237,12 @@ static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, }trace_dax_insert_mapping (inode, vmf, entry);if (write) - error =vm_insert_mixed_mkwrite (vma, vaddr, pfn);
fs/dax.c static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, · line 1234
Quoted 10 lines
fs/dax.c +4
-4+ vmf_ret =vmf_insert_mixed_mkwrite (vma, vaddr, pfn); else - error =vm_insert_mixed (vma, vaddr, pfn); + vmf_ret =vmf_insert_mixed (vma, vaddr, pfn); + + goto finish_iomap; -/* -EBUSY is fine, somebody else faulted on the same PTE */ -if (error == -EBUSY ) - error =0 ;
In this rework you've lost this special case handling for -EBUSY, which means that with your code users hitting -EBUSY (which is a non-error) will get a VM_FAULT_SIGBUS.
Quoted 12 lines
fs/dax.c +2
-2@@ -1568,8 +1577,8 @@ static int dax_insert_pfn_mkwrite(struct vm_fault *vmf,* stored persistently on the media and handles inserting of appropriate page * table entry. */ -int dax_finish_sync_fault (struct vm_fault *vmf,enum page_entry_size pe_size, -pfn_t pfn) +vm_fault_t dax_finish_sync_fault (struct vm_fault *vmf, +enum page_entry_size pe_size,pfn_t pfn) {int err;loff_t start = ((loff_t )vmf->pgoff) <<PAGE_SHIFT ;
fs/dax.c int dax_finish_sync_fault(struct vm_fault *vmf, enum page_entry_size pe_size, · line 1594
Quoted 6 lines
fs/dax.c +2
-1@@ -1581,7 +1590,8 @@ int dax_finish_sync_fault(struct vm_fault *vmf, enum page_entry_size pe_size, len =PMD_SIZE ; else WARN_ON_ONCE(1); - err =vfs_fsync_range (vmf->vma->vm_file, start, start + len -1 ,1 ); + err =vfs_fsync_range (vmf->vma->vm_file, + start, start + len -1 ,1 );
Unrelated and unneeded whitespace change.
Matthew Wilcox
reviewerQuoted 8 lines · Souptick Joarder
There was an existing bug inside
dax_load_hole()ifvm_insert_mixedhad failed to allocate a page table, we'd returnVM_FAULT_NOPAGEinstead ofVM_FAULT_OOM. Withvmf_insert_mixedthis issue is addressed.
vmf_insert_mixed_mkwrite()is the new wrapper function which will convert err returned fromvm_insert_mixed_mkwrite()tovm_fault_ttype.
Since dax is the only caller of vm_insert_mixed_mkwrite(), rather than introducing a wrapper function, you should just convert vm_insert_mixed_mkwrite() to vmf_insert_mixed_mkwrite().
fs/dax.c static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, · line 1122
Quoted 5 lines
fs/dax.c +1
-1int error, major =0 ;bool write = vmf->flags &FAULT_FLAG_WRITE ;bool sync; -int vmf_ret =0 ; +vm_fault_t vmf_ret =0 ;
I'd rename this to just 'ret' like everywhere else.
Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Souptick Joarder
There was an existing bug inside
dax_load_hole()ifvm_insert_mixedhad failed to allocate a page table, we'd returnVM_FAULT_NOPAGEinstead ofVM_FAULT_OOM. Withvmf_insert_mixedthis issue is addressed.
Quoted 8 lines
Quoted 3 lines
vmf_insert_mixed_mkwrite()is the new wrapper function which will convert err returned fromvm_insert_mixed_mkwrite()tovm_fault_ttype.Since dax is the only caller of
vm_insert_mixed_mkwrite(), rather than introducing a wrapper function, you should just convertvm_insert_mixed_mkwrite()tovmf_insert_mixed_mkwrite().
Although vm_insert_mixed_mkwrite () is getting called only from dax, but if we directly change it to vmf_insert_mixed_mkwrite() with return type vm_fault_t, we end with changing multiple functions recursively. In my opinion, it will complicate things.
It's better to go with current inline vmf_insert_mixed_mkwrite() approach.
Matthew Wilcox
reviewerQuoted 16 lines · Souptick Joarder
Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Souptick Joarder
There was an existing bug inside
dax_load_hole()ifvm_insert_mixedhad failed to allocate a page table, we'd returnVM_FAULT_NOPAGEinstead ofVM_FAULT_OOM. Withvmf_insert_mixedthis issue is addressed.Quoted 8 lines
Quoted 3 lines
vmf_insert_mixed_mkwrite()is the new wrapper function which will convert err returned fromvm_insert_mixed_mkwrite()tovm_fault_ttype.Since dax is the only caller of
vm_insert_mixed_mkwrite(), rather than introducing a wrapper function, you should just convertvm_insert_mixed_mkwrite()tovmf_insert_mixed_mkwrite().
Quoted 6 lines
Although
vm_insert_mixed_mkwrite() is getting called only from dax, but if we directly change it tovmf_insert_mixed_mkwrite()with return typevm_fault_t, we end with changing multiple functions recursively. In my opinion, it will complicate things.It's better to go with current inline
vmf_insert_mixed_mkwrite()approach.
No, it's not. The point is to create patches which are self-contained and don't break anything. So we can't change vm_insert_mixed because it has so many users, and we need to transition to it gradually. But vm_insert_mixed_mkwrite only has one user, and we can just change both at the same time.
Quoted 5 lines
Quoted 5 lines
Although
vm_insert_mixed_mkwrite() is getting called only from dax, but if we directly change it tovmf_insert_mixed_mkwrite()with return typevm_fault_t, we end with changing multiple functions recursively. In my opinion, it will complicate things.
Quoted 7 lines
Quoted 1 line
It's better to go with current inline
vmf_insert_mixed_mkwrite()approach.No, it's not. The point is to create patches which are self-contained and don't break anything. So we can't change
vm_insert_mixedbecause it has so many users, and we need to transition to it gradually. Butvm_insert_mixed_mkwriteonly has one user, and we can just change both at the same time.
Agree with you. I have send both the patches cc'ing mm and fsdevel list. vmf_insert_mixed_mkwrite patch has to go first in linus tree.
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Souptick,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v4.16]
[cannot apply to linus/master v4.17-rc1 next-20180418]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Souptick-Joarder/fs-dax-Adding-new-return-type-vm_fault_t/20180418-152151
config: i386-randconfig-s1-201815 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
In file included from fs//ext2/file.c:24:0:
>> include/linux/dax.h:100:1: error: unknown type name 'vm_fault_t'
vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, ^~~~~~~~~~
vim +/vm_fault_t +100 include/linux/dax.h
95
96 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
97 const struct iomap_ops *ops);
98 int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
99 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
> 100 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, 101 enum page_entry_size pe_size, pfn_t pfn);
102 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
103 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
104 pgoff_t index);
105
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Souptick,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v4.16]
[cannot apply to linus/master v4.17-rc1 next-20180418]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Souptick-Joarder/fs-dax-Adding-new-return-type-vm_fault_t/20180418-152151
config: i386-randconfig-x014-201815 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
In file included from include/linux/mempolicy.h:11:0,
from include/linux/migrate.h:6,
from fs//btrfs/disk-io.c:29:
>> include/linux/dax.h:100:1: error: unknown type name 'vm_fault_t'; did you mean 'vm_flags_t'? vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, ^~~~~~~~~~
vm_flags_t
vim +100 include/linux/dax.h
95
96 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
97 const struct iomap_ops *ops);
98 int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
99 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
> 100 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, 101 enum page_entry_size pe_size, pfn_t pfn);
102 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
103 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
104 pgoff_t index);
105
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Hi Ross,
Quoted 6 lines · kbuild test robot
Hi Souptick,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v4.16]
[cannot apply to linus/master v4.17-rc1 next-20180418]
Does it mean patch was initially applied in v4.16 ?
As v4.16 build breaks it fails to apply in v4.17-rc1 and next-20180418 ?
Even for another patch in gma500 I receive similar error "vm_fault_t not defined".
These patches should work from 4.17-rc1 onward.
Whom to reach out for kbuild test failures ?
Quoted 11 lines · Souptick Joarder
Hi Ross,
Quoted 6 lines · kbuild test robot
Hi Souptick,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v4.16]
[cannot apply to linus/master v4.17-rc1 next-20180418]Does it mean patch was initially applied in v4.16 ?
Yes.
Quoted 1 line
As v4.16 build breaks it fails to apply in v4.17-rc1 and next-20180418 ?
When there is a build fail the robot will apply-and-test the patch on more base trees. Here the patch cannot apply to linus/master, v4.17-rc1 and next-20180418, so cannot be further tested there.
Thanks,
Fengguang
Quoted 13 lines · Fengguang Wu
Quoted 11 lines · Souptick Joarder
Hi Ross,
Quoted 6 lines · kbuild test robot
Hi Souptick,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v4.16]
[cannot apply to linus/master v4.17-rc1 next-20180418]Does it mean patch was initially applied in v4.16 ?
Quoted 7 lines
Yes.
Quoted 1 line
As v4.16 build breaks it fails to apply in v4.17-rc1 and next-20180418 ?
When there is a build fail the robot will apply-and-test the patch on more base trees. Here the patch cannot apply to linus/master, v4.17-rc1 and next-20180418, so cannot be further tested there.
Right - this needs to be rebased onto the current linux/master, as it currently collides with a patch from Dan which went into v4.17-rc1.