Skip to content

Commit 90cb574

Browse files
Souptick Joardersfrothwell
authored andcommitted
mm: create the new vm_fault_t type
Page fault handlers are supposed to return VM_FAULT codes, but some drivers/file systems mistakenly return error numbers. Now that all drivers/file systems have been converted to use the vm_fault_t return type, change the type definition to no longer be compatible with 'int'. By making it an unsigned int, the function prototype becomes incompatible with a function which returns int. Sparse will detect any attempts to return a value which is not a VM_FAULT code. VM_FAULT_SET_HINDEX and VM_FAULT_GET_HINDEX values are changed to avoid conflict with other VM_FAULT codes. Link: http://lkml.kernel.org/r/20190108183041.GA12137@jordon-HP-15-Notebook-PC Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com> Reviewed-by: William Kucharski <william.kucharski@oracle.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> Reviewed-by: Matthew Wilcox <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
1 parent 6b95e7a commit 90cb574

File tree

2 files changed

+72
-47
lines changed

2 files changed

+72
-47
lines changed

include/linux/mm.h

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,52 +1323,6 @@ static inline void clear_page_pfmemalloc(struct page *page)
13231323
page->index = 0;
13241324
}
13251325

1326-
/*
1327-
* Different kinds of faults, as returned by handle_mm_fault().
1328-
* Used to decide whether a process gets delivered SIGBUS or
1329-
* just gets major/minor fault counters bumped up.
1330-
*/
1331-
1332-
#define VM_FAULT_OOM 0x0001
1333-
#define VM_FAULT_SIGBUS 0x0002
1334-
#define VM_FAULT_MAJOR 0x0004
1335-
#define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */
1336-
#define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned small page */
1337-
#define VM_FAULT_HWPOISON_LARGE 0x0020 /* Hit poisoned large page. Index encoded in upper bits */
1338-
#define VM_FAULT_SIGSEGV 0x0040
1339-
1340-
#define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */
1341-
#define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */
1342-
#define VM_FAULT_RETRY 0x0400 /* ->fault blocked, must retry */
1343-
#define VM_FAULT_FALLBACK 0x0800 /* huge page fault failed, fall back to small */
1344-
#define VM_FAULT_DONE_COW 0x1000 /* ->fault has fully handled COW */
1345-
#define VM_FAULT_NEEDDSYNC 0x2000 /* ->fault did not modify page tables
1346-
* and needs fsync() to complete (for
1347-
* synchronous page faults in DAX) */
1348-
1349-
#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
1350-
VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
1351-
VM_FAULT_FALLBACK)
1352-
1353-
#define VM_FAULT_RESULT_TRACE \
1354-
{ VM_FAULT_OOM, "OOM" }, \
1355-
{ VM_FAULT_SIGBUS, "SIGBUS" }, \
1356-
{ VM_FAULT_MAJOR, "MAJOR" }, \
1357-
{ VM_FAULT_WRITE, "WRITE" }, \
1358-
{ VM_FAULT_HWPOISON, "HWPOISON" }, \
1359-
{ VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \
1360-
{ VM_FAULT_SIGSEGV, "SIGSEGV" }, \
1361-
{ VM_FAULT_NOPAGE, "NOPAGE" }, \
1362-
{ VM_FAULT_LOCKED, "LOCKED" }, \
1363-
{ VM_FAULT_RETRY, "RETRY" }, \
1364-
{ VM_FAULT_FALLBACK, "FALLBACK" }, \
1365-
{ VM_FAULT_DONE_COW, "DONE_COW" }, \
1366-
{ VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }
1367-
1368-
/* Encode hstate index for a hwpoisoned large page */
1369-
#define VM_FAULT_SET_HINDEX(x) ((x) << 12)
1370-
#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
1371-
13721326
/*
13731327
* Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
13741328
*/

include/linux/mm_types.h

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

25-
typedef int vm_fault_t;
2625

2726
struct address_space;
2827
struct mem_cgroup;
@@ -614,6 +613,78 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
614613

615614
struct vm_fault;
616615

616+
/**
617+
* typedef vm_fault_t - Return type for page fault handlers.
618+
*
619+
* Page fault handlers return a bitmask of %VM_FAULT values.
620+
*/
621+
typedef __bitwise unsigned int vm_fault_t;
622+
623+
/**
624+
* enum vm_fault_reason - Page fault handlers return a bitmask of
625+
* these values to tell the core VM what happened when handling the
626+
* fault. Used to decide whether a process gets delivered SIGBUS or
627+
* just gets major/minor fault counters bumped up.
628+
*
629+
* @VM_FAULT_OOM: Out Of Memory
630+
* @VM_FAULT_SIGBUS: Bad access
631+
* @VM_FAULT_MAJOR: Page read from storage
632+
* @VM_FAULT_WRITE: Special case for get_user_pages
633+
* @VM_FAULT_HWPOISON: Hit poisoned small page
634+
* @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded
635+
* in upper bits
636+
* @VM_FAULT_SIGSEGV: segmentation fault
637+
* @VM_FAULT_NOPAGE: ->fault installed the pte, not return page
638+
* @VM_FAULT_LOCKED: ->fault locked the returned page
639+
* @VM_FAULT_RETRY: ->fault blocked, must retry
640+
* @VM_FAULT_FALLBACK: huge page fault failed, fall back to small
641+
* @VM_FAULT_DONE_COW: ->fault has fully handled COW
642+
* @VM_FAULT_NEEDDSYNC: ->fault did not modify page tables and needs
643+
* fsync() to complete (for synchronous page faults
644+
* in DAX)
645+
* @VM_FAULT_HINDEX_MASK: mask HINDEX value
646+
*
647+
*/
648+
enum vm_fault_reason {
649+
VM_FAULT_OOM = (__force vm_fault_t)0x000001,
650+
VM_FAULT_SIGBUS = (__force vm_fault_t)0x000002,
651+
VM_FAULT_MAJOR = (__force vm_fault_t)0x000004,
652+
VM_FAULT_WRITE = (__force vm_fault_t)0x000008,
653+
VM_FAULT_HWPOISON = (__force vm_fault_t)0x000010,
654+
VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
655+
VM_FAULT_SIGSEGV = (__force vm_fault_t)0x000040,
656+
VM_FAULT_NOPAGE = (__force vm_fault_t)0x000100,
657+
VM_FAULT_LOCKED = (__force vm_fault_t)0x000200,
658+
VM_FAULT_RETRY = (__force vm_fault_t)0x000400,
659+
VM_FAULT_FALLBACK = (__force vm_fault_t)0x000800,
660+
VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000,
661+
VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000,
662+
VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000,
663+
};
664+
665+
/* Encode hstate index for a hwpoisoned large page */
666+
#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
667+
#define VM_FAULT_GET_HINDEX(x) (((x) >> 16) & 0xf)
668+
669+
#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | \
670+
VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \
671+
VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
672+
673+
#define VM_FAULT_RESULT_TRACE \
674+
{ VM_FAULT_OOM, "OOM" }, \
675+
{ VM_FAULT_SIGBUS, "SIGBUS" }, \
676+
{ VM_FAULT_MAJOR, "MAJOR" }, \
677+
{ VM_FAULT_WRITE, "WRITE" }, \
678+
{ VM_FAULT_HWPOISON, "HWPOISON" }, \
679+
{ VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \
680+
{ VM_FAULT_SIGSEGV, "SIGSEGV" }, \
681+
{ VM_FAULT_NOPAGE, "NOPAGE" }, \
682+
{ VM_FAULT_LOCKED, "LOCKED" }, \
683+
{ VM_FAULT_RETRY, "RETRY" }, \
684+
{ VM_FAULT_FALLBACK, "FALLBACK" }, \
685+
{ VM_FAULT_DONE_COW, "DONE_COW" }, \
686+
{ VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }
687+
617688
struct vm_special_mapping {
618689
const char *name; /* The name, e.g. "[vdso]". */
619690

0 commit comments

Comments
 (0)