Skip to content

Commit 1c8f422

Browse files
Souptick Joardertorvalds
authored andcommitted
mm: change return type to vm_fault_t
The plan for these patches is to introduce the typedef, initially just as documentation ("These functions should return a VM_FAULT_ status"). We'll trickle the patches to individual drivers/filesystems in through the maintainers, as far as possible. Then we'll change the typedef to an unsigned int and break the compilation of any unconverted drivers/filesystems. vmf_insert_page(), vmf_insert_mixed() and vmf_insert_pfn() are three newly added functions. The various drivers/filesystems where return value of fault(), huge_fault(), page_mkwrite() and pfn_mkwrite() get converted, will need them. These functions will return correct VM_FAULT_ code based on err value. We've had bugs before where drivers returned -EFOO. And we have this silly inefficiency where vm_insert_xxx() return an errno which (afaict) every driver then converts into a VM_FAULT code. In many cases drivers failed to return correct VM_FAULT code value despite of vm_insert_xxx() fails. We have indentified and clean up all those existing bugs and silly inefficiencies in driver/filesystems by adding these three new inline wrappers. As mentioned above, we will trickle those patches to individual drivers/filesystems in through maintainers after these three wrapper functions are merged. Eventually we can convert vm_insert_xxx() into vmf_insert_xxx() and remove these inline wrappers, but these are a good intermediate step. Link: http://lkml.kernel.org/r/20180310162351.GA7422@jordon-HP-15-Notebook-PC Signed-off-by: Souptick Joarder <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Matthew Wilcox <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d46078b commit 1c8f422

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

include/linux/mm.h

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,19 @@ struct vm_operations_struct {
386386
void (*close)(struct vm_area_struct * area);
387387
int (*split)(struct vm_area_struct * area, unsigned long addr);
388388
int (*mremap)(struct vm_area_struct * area);
389-
int (*fault)(struct vm_fault *vmf);
390-
int (*huge_fault)(struct vm_fault *vmf, enum page_entry_size pe_size);
389+
vm_fault_t (*fault)(struct vm_fault *vmf);
390+
vm_fault_t (*huge_fault)(struct vm_fault *vmf,
391+
enum page_entry_size pe_size);
391392
void (*map_pages)(struct vm_fault *vmf,
392393
pgoff_t start_pgoff, pgoff_t end_pgoff);
393394
unsigned long (*pagesize)(struct vm_area_struct * area);
394395

395396
/* notification that a previously read-only page is about to become
396397
* writable, if an error is returned it will cause a SIGBUS */
397-
int (*page_mkwrite)(struct vm_fault *vmf);
398+
vm_fault_t (*page_mkwrite)(struct vm_fault *vmf);
398399

399400
/* same as page_mkwrite when using VM_PFNMAP|VM_MIXEDMAP */
400-
int (*pfn_mkwrite)(struct vm_fault *vmf);
401+
vm_fault_t (*pfn_mkwrite)(struct vm_fault *vmf);
401402

402403
/* called by access_process_vm when get_user_pages() fails, typically
403404
* for use by special VMAs that can switch between memory and hardware
@@ -2424,6 +2425,44 @@ int vm_insert_mixed_mkwrite(struct vm_area_struct *vma, unsigned long addr,
24242425
pfn_t pfn);
24252426
int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len);
24262427

2428+
static inline vm_fault_t vmf_insert_page(struct vm_area_struct *vma,
2429+
unsigned long addr, struct page *page)
2430+
{
2431+
int err = vm_insert_page(vma, addr, page);
2432+
2433+
if (err == -ENOMEM)
2434+
return VM_FAULT_OOM;
2435+
if (err < 0 && err != -EBUSY)
2436+
return VM_FAULT_SIGBUS;
2437+
2438+
return VM_FAULT_NOPAGE;
2439+
}
2440+
2441+
static inline vm_fault_t vmf_insert_mixed(struct vm_area_struct *vma,
2442+
unsigned long addr, pfn_t pfn)
2443+
{
2444+
int err = vm_insert_mixed(vma, addr, pfn);
2445+
2446+
if (err == -ENOMEM)
2447+
return VM_FAULT_OOM;
2448+
if (err < 0 && err != -EBUSY)
2449+
return VM_FAULT_SIGBUS;
2450+
2451+
return VM_FAULT_NOPAGE;
2452+
}
2453+
2454+
static inline vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma,
2455+
unsigned long addr, unsigned long pfn)
2456+
{
2457+
int err = vm_insert_pfn(vma, addr, pfn);
2458+
2459+
if (err == -ENOMEM)
2460+
return VM_FAULT_OOM;
2461+
if (err < 0 && err != -EBUSY)
2462+
return VM_FAULT_SIGBUS;
2463+
2464+
return VM_FAULT_NOPAGE;
2465+
}
24272466

24282467
struct page *follow_page_mask(struct vm_area_struct *vma,
24292468
unsigned long address, unsigned int foll_flags,

include/linux/mm_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#endif
2323
#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
2424

25+
typedef int vm_fault_t;
26+
2527
struct address_space;
2628
struct mem_cgroup;
2729
struct hmm;

0 commit comments

Comments
 (0)