mm: Change return type to vm_fault_t
Subsystems (2)
PATCH 1/1 mm: Change return type to vm_fault_t
Use new return type vm_fault_t for fault handler
in struct vm_operations_struct.
vmf_insert_mixed(), vmf_insert_pfn() and vmf_insert_page() are newly added inline wrapper functions.
--- include/linux/mm.h | 47 +++++++++++++++++++++++++++++++++++++++++++---- include/linux/mm_types.h | 2 ++ 2 files changed, 45 insertions(+), 4 deletions(-)
include/linux/mm.h +43 -4
@@ -379,17 +379,18 @@ struct vm_operations_struct {void (*close)(struct vm_area_struct * area);int (*split)(struct vm_area_struct * area,unsigned long addr);int (*mremap)(struct vm_area_struct * area); -int (*fault)(struct vm_fault *vmf); -int (*huge_fault)(struct vm_fault *vmf,enum page_entry_size pe_size); +vm_fault_t (*fault)(struct vm_fault *vmf); +vm_fault_t (*huge_fault)(struct vm_fault *vmf, +enum page_entry_size pe_size);void (*map_pages)(struct vm_fault *vmf,pgoff_t start_pgoff,pgoff_t end_pgoff);/* notification that a previously read-only page is about to become * writable, if an error is returned it will cause a SIGBUS */ -int (*page_mkwrite)(struct vm_fault *vmf); +vm_fault_t (*page_mkwrite)(struct vm_fault *vmf);/* same as page_mkwrite when using VM_PFNMAP|VM_MIXEDMAP */ -int (*pfn_mkwrite)(struct vm_fault *vmf); +vm_fault_t (*pfn_mkwrite)(struct vm_fault *vmf);/* called by access_process_vm when get_user_pages() fails, typically * for use by special VMAs that can switch between memory and hardware
@@ -2413,6 +2414,44 @@ int vm_insert_mixed_mkwrite(struct vm_area_struct *vma, unsigned long addr, pfn_t pfn);int vm_iomap_memory (struct vm_area_struct *vma,phys_addr_t start,unsigned long len); +static inline vm_fault_t vmf_insert_page (struct vm_area_struct *vma, +unsigned long addr,struct page *page) +{ +int err =vm_insert_page (vma, addr, page); + +if (err == -ENOMEM ) +return VM_FAULT_OOM ; +if (err <0 && err != -EBUSY ) +return VM_FAULT_SIGBUS ; + +return VM_FAULT_NOPAGE ; +} + +static inline vm_fault_t vmf_insert_mixed (struct vm_area_struct *vma, +unsigned long addr,pfn_t pfn) +{ +int err =vm_insert_mixed (vma, addr, pfn); + +if (err == -ENOMEM ) +return VM_FAULT_OOM ; +if (err <0 && err != -EBUSY ) +return VM_FAULT_SIGBUS ; + +return VM_FAULT_NOPAGE ; +} + +static inline vm_fault_t vmf_insert_pfn (struct vm_area_struct *vma, +unsigned long addr,unsigned long pfn) +{ +int err =vm_insert_pfn (vma, addr, pfn); + +if (err == -ENOMEM ) +return VM_FAULT_OOM ; +if (err <0 && err != -EBUSY ) +return VM_FAULT_SIGBUS ; + +return VM_FAULT_NOPAGE ; +} struct page *follow_page_mask(struct vm_area_struct *vma, unsigned long address, unsigned int foll_flags,
include/linux/mm_types.h +2 -0
@@ -22,6 +22,8 @@#endif #define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1)) +typedef int vm_fault_t ; +struct address_space ;struct mem_cgroup ;struct hmm ;
--
1.9.1
Quoted 7 lines · Souptick Joarder
Use new return type
vm_fault_tfor fault handler
in structvm_operations_struct.
vmf_insert_mixed(),vmf_insert_pfn()andvmf_insert_page()are newly added inline wrapper functions.Signed-off-by Souptick Joarder <[email protected]>
Andrew, the plan for these patches is to introduce the typedef, initially just as documentation ("This function should return a VM_FAULT_ status"). We'll trickle the patches to individual drivers/filesystems in through the maintainers, as far as possible. In a few months, we'll probably dump a pile of patches to unloved drivers on you for merging. Then we'll change the typedef to an unsigned int and break the compilation of any unconverted driver.
Souptick has done a few dozen drivers already, and I've been doing my best to keep up with reviewing the patches submitted. There's some interesting patterns and commonalities between drivers (not to mention a few outright bugs) that we've noticed, and this'll be a good time to clean them up.
It'd be great to get this into Linus' tree sooner so we can start submitting the patches to the driver maintainers.
Andrew Morton
maintainerQuoted 2 lines · On Thu, 8 Mar 2018 18:35:23 +0530 Souptick Joarder <[email protected]> wrote:
Use new return type
vm_fault_tfor fault handler
in structvm_operations_struct.
I can't find vm_fault_t?
Quoted 2 lines
vmf_insert_mixed(),vmf_insert_pfn()andvmf_insert_page()are newly added inline wrapper functions.
Why?
include/linux/mm.h struct vm_operations_struct { · line 384
Quoted 12 lines
index ad06d42..a4d8853 100644
include/linux/mm.h +3
-2@@ -379,17 +379,18 @@ struct vm_operations_struct {void (*close)(struct vm_area_struct * area);int (*split)(struct vm_area_struct * area,unsigned long addr);int (*mremap)(struct vm_area_struct * area); -int (*fault)(struct vm_fault *vmf); -int (*huge_fault)(struct vm_fault *vmf,enum page_entry_size pe_size); +vm_fault_t (*fault)(struct vm_fault *vmf); +vm_fault_t (*huge_fault)(struct vm_fault *vmf, +enum page_entry_size pe_size);
Well if we're going to do this then we should convert all the .page_mkwrite() instances and a bunch of other stuff to use vm_fault_t. It's a lot of work. Perhaps we should just keep using "int".
Quoted 6 lines · Andrew Morton
Quoted 2 lines · On Thu, 8 Mar 2018 18:35:23 +0530 Souptick Joarder <[email protected]> wrote:
Use new return type
vm_fault_tfor fault handler
in structvm_operations_struct.I can't find
vm_fault_t?
Way down at the bottom, in mm_types.h. mm.h is a bit heavyweight, and we need vm_fault_t in vm_special_mapping->fault.
Quoted 4 lines
Quoted 2 lines
vmf_insert_mixed(),vmf_insert_pfn()andvmf_insert_page()are newly added inline wrapper functions.Why?
The various drivers that get converted will need them (or something similar to them). I think eventually we can convert vm_insert_foo() into vmf_insert_foo() and remove these inline wrappers, but these are a good intermediate step.
Quoted 3 lines
Well if we're going to do this then we should convert all the .page_mkwrite() instances and a bunch of other stuff to use
vm_fault_t. It's a lot of work. Perhaps we should just keep using "int".
We've had bugs before where drivers returned -EFOO. And we have this silly inefficiency where vm_insert_foo() return an errno which (afaict) every driver then converts into a VM_FAULT code. Souptick's willing to do the work; Michal Hocko agrees it's worth doing; I'm willing to supervise. It seems worth faciitating.
Andrew Morton
maintainerQuoted 19 lines · On Thu, 8 Mar 2018 14:22:01 -0800 Matthew Wilcox <[email protected]> wrote:
Quoted 7 lines · Souptick Joarder
Use new return type
vm_fault_tfor fault handler
in structvm_operations_struct.
vmf_insert_mixed(),vmf_insert_pfn()andvmf_insert_page()are newly added inline wrapper functions.Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Andrew, the plan for these patches is to introduce the typedef, initially just as documentation ("This function should return a
VM_FAULT_status"). We'll trickle the patches to individualdrivers/filesystemsin through the maintainers, as far as possible. In a few months, we'll probably dump a pile of patches to unloved drivers on you for merging. Then we'll change the typedef to an unsigned int and break the compilation of any unconverted driver.
Quoted 4 lines
Souptick has done a few dozen drivers already, and I've been doing my best to keep up with reviewing the patches submitted. There's some interesting patterns and commonalities between drivers (not to mention a few outright bugs) that we've noticed, and this'll be a good time to clean them up.
OK. All of this should be in the changelog, please. Along with a full explanation of the reasons for adding the new functions.
Quoted 2 lines
It'd be great to get this into Linus' tree sooner so we can start submitting the patches to the driver maintainers.
Sure. I assume that vm_fault_t is `int', so this bare patch won't cause a ton of type mismatch warnings?
Quoted 20 lines · Andrew Morton
Quoted 19 lines · On Thu, 8 Mar 2018 14:22:01 -0800 Matthew Wilcox <[email protected]> wrote:
Quoted 7 lines · Souptick Joarder
Use new return type
vm_fault_tfor fault handler
in structvm_operations_struct.
vmf_insert_mixed(),vmf_insert_pfn()andvmf_insert_page()are newly added inline wrapper functions.Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Andrew, the plan for these patches is to introduce the typedef, initially just as documentation ("This function should return a
VM_FAULT_status"). We'll trickle the patches to individualdrivers/filesystemsin through the maintainers, as far as possible. In a few months, we'll probably dump a pile of patches to unloved drivers on you for merging. Then we'll change the typedef to an unsigned int and break the compilation of any unconverted driver.
Quoted 7 lines
Quoted 4 lines
Souptick has done a few dozen drivers already, and I've been doing my best to keep up with reviewing the patches submitted. There's some interesting patterns and commonalities between drivers (not to mention a few outright bugs) that we've noticed, and this'll be a good time to clean them up.
OK. All of this should be in the changelog, please. Along with a full explanation of the reasons for adding the new functions.
Agreed. Souptick, can you take care of doing that and resubmitting the patch?
Quoted 5 lines
Quoted 2 lines
It'd be great to get this into Linus' tree sooner so we can start submitting the patches to the driver maintainers.
Sure. I assume that
vm_fault_tis `int', so this bare patch won't cause a ton of type mismatch warnings?
Exactly so.
Quoted 26 lines · Matthew Wilcox
Quoted 25 lines · Andrew Morton
Quoted 23 lines · On Thu, 8 Mar 2018 14:22:01 -0800 Matthew Wilcox <[email protected]> wrote:
Quoted 7 lines · Souptick Joarder
Use new return type
vm_fault_tfor fault handler
in structvm_operations_struct.
vmf_insert_mixed(),vmf_insert_pfn()andvmf_insert_page()are newly added inline wrapper functions.Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Andrew, the plan for these patches is to introduce the typedef, initially just as documentation ("This function should return a
VM_FAULT_status"). We'll trickle the patches to individualdrivers/filesystemsin through the maintainers, as far as possible. In a few months, we'll probably dump a pile of patches to unloved drivers on you for merging. Then we'll change the typedef to an unsigned int and break the compilation of any unconverted driver.Souptick has done a few dozen drivers already, and I've been doing my best to keep up with reviewing the patches submitted. There's some interesting patterns and commonalities between drivers (not to mention a few outright bugs) that we've noticed, and this'll be a good time to clean them up.
Quoted 5 lines
Quoted 2 lines
OK. All of this should be in the changelog, please. Along with a full explanation of the reasons for adding the new functions.
Agreed. Souptick, can you take care of doing that and resubmitting the patch?
Sure , I will add this into change log and resubmit the patch.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
It'd be great to get this into Linus' tree sooner so we can start submitting the patches to the driver maintainers.
Sure. I assume that
vm_fault_tis `int', so this bare patch won't cause a ton of type mismatch warnings?Exactly so.