Skip to contentSkip to conversation

mm: Create the new vm_fault_t type

PATCH Superseded Souptick Joarder 3 participants 5 messages Nov 6, 2018

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
v2: Updated the change log and corrected the document part.
name added to the enum that kernel-doc able to parse it.

 include/linux/mm.h       | 46 ------------------------------
 include/linux/mm_types.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 47 deletions(-)
include/linux/mm.h +0 -46
index fcf9cc9..511a3ce 100644
@@ -1267,52 +1267,6 @@ static inline void clear_page_pfmemalloc(struct page *page)
 }
 
 /*
- * Different kinds of faults, as returned by handle_mm_fault().
- * Used to decide whether a process gets delivered SIGBUS or
- * just gets major/minor fault counters bumped up.
- */
-
-#define VM_FAULT_OOM	0x0001
-#define VM_FAULT_SIGBUS	0x0002
-#define VM_FAULT_MAJOR	0x0004
-#define VM_FAULT_WRITE	0x0008	/* Special case for get_user_pages */
-#define VM_FAULT_HWPOISON 0x0010	/* Hit poisoned small page */
-#define VM_FAULT_HWPOISON_LARGE 0x0020  /* Hit poisoned large page. Index encoded in upper bits */
-#define VM_FAULT_SIGSEGV 0x0040
-
-#define VM_FAULT_NOPAGE	0x0100	/* ->fault installed the pte, not return page */
-#define VM_FAULT_LOCKED	0x0200	/* ->fault locked the returned page */
-#define VM_FAULT_RETRY	0x0400	/* ->fault blocked, must retry */
-#define VM_FAULT_FALLBACK 0x0800	/* huge page fault failed, fall back to small */
-#define VM_FAULT_DONE_COW   0x1000	/* ->fault has fully handled COW */
-#define VM_FAULT_NEEDDSYNC  0x2000	/* ->fault did not modify page tables
-					 * and needs fsync() to complete (for
-					 * synchronous page faults in DAX) */
-
-#define VM_FAULT_ERROR	(VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
-			 VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
-			 VM_FAULT_FALLBACK)
-
-#define VM_FAULT_RESULT_TRACE \
-	{ VM_FAULT_OOM,			"OOM" }, \
-	{ VM_FAULT_SIGBUS,		"SIGBUS" }, \
-	{ VM_FAULT_MAJOR,		"MAJOR" }, \
-	{ VM_FAULT_WRITE,		"WRITE" }, \
-	{ VM_FAULT_HWPOISON,		"HWPOISON" }, \
-	{ VM_FAULT_HWPOISON_LARGE,	"HWPOISON_LARGE" }, \
-	{ VM_FAULT_SIGSEGV,		"SIGSEGV" }, \
-	{ VM_FAULT_NOPAGE,		"NOPAGE" }, \
-	{ VM_FAULT_LOCKED,		"LOCKED" }, \
-	{ VM_FAULT_RETRY,		"RETRY" }, \
-	{ VM_FAULT_FALLBACK,		"FALLBACK" }, \
-	{ VM_FAULT_DONE_COW,		"DONE_COW" }, \
-	{ VM_FAULT_NEEDDSYNC,		"NEEDDSYNC" }
-
-/* Encode hstate index for a hwpoisoned large page */
-#define VM_FAULT_SET_HINDEX(x) ((x) << 12)
-#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
-
-/*
  * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
  */
 extern void pagefault_out_of_memory(void);
include/linux/mm_types.h +72 -1

85 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw
Quoted 93 lines · Souptick Joarder

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.

---
v2: Updated the change log and corrected the document part.
name added to the enum that kernel-doc able to parse it.

 include/linux/mm.h       | 46 ------------------------------
 include/linux/mm_types.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 47 deletions(-)
include/linux/mm.h +0 -46
index fcf9cc9..511a3ce 100644
@@ -1267,52 +1267,6 @@ static inline void clear_page_pfmemalloc(struct page *page)
 }
 
 /*
- * Different kinds of faults, as returned by handle_mm_fault().
- * Used to decide whether a process gets delivered SIGBUS or
- * just gets major/minor fault counters bumped up.
- */
-
-#define VM_FAULT_OOM	0x0001
-#define VM_FAULT_SIGBUS	0x0002
-#define VM_FAULT_MAJOR	0x0004
-#define VM_FAULT_WRITE	0x0008	/* Special case for get_user_pages */
-#define VM_FAULT_HWPOISON 0x0010	/* Hit poisoned small page */
-#define VM_FAULT_HWPOISON_LARGE 0x0020  /* Hit poisoned large page. Index encoded in upper bits */
-#define VM_FAULT_SIGSEGV 0x0040
-
-#define VM_FAULT_NOPAGE	0x0100	/* ->fault installed the pte, not return page */
-#define VM_FAULT_LOCKED	0x0200	/* ->fault locked the returned page */
-#define VM_FAULT_RETRY	0x0400	/* ->fault blocked, must retry */
-#define VM_FAULT_FALLBACK 0x0800	/* huge page fault failed, fall back to small */
-#define VM_FAULT_DONE_COW   0x1000	/* ->fault has fully handled COW */
-#define VM_FAULT_NEEDDSYNC  0x2000	/* ->fault did not modify page tables
-					 * and needs fsync() to complete (for
-					 * synchronous page faults in DAX) */
-
-#define VM_FAULT_ERROR	(VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
-			 VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
-			 VM_FAULT_FALLBACK)
-
-#define VM_FAULT_RESULT_TRACE \
-	{ VM_FAULT_OOM,			"OOM" }, \
-	{ VM_FAULT_SIGBUS,		"SIGBUS" }, \
-	{ VM_FAULT_MAJOR,		"MAJOR" }, \
-	{ VM_FAULT_WRITE,		"WRITE" }, \
-	{ VM_FAULT_HWPOISON,		"HWPOISON" }, \
-	{ VM_FAULT_HWPOISON_LARGE,	"HWPOISON_LARGE" }, \
-	{ VM_FAULT_SIGSEGV,		"SIGSEGV" }, \
-	{ VM_FAULT_NOPAGE,		"NOPAGE" }, \
-	{ VM_FAULT_LOCKED,		"LOCKED" }, \
-	{ VM_FAULT_RETRY,		"RETRY" }, \
-	{ VM_FAULT_FALLBACK,		"FALLBACK" }, \
-	{ VM_FAULT_DONE_COW,		"DONE_COW" }, \
-	{ VM_FAULT_NEEDDSYNC,		"NEEDDSYNC" }
-
-/* Encode hstate index for a hwpoisoned large page */
-#define VM_FAULT_SET_HINDEX(x) ((x) << 12)
-#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
-
-/*
  * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
  */
 extern void pagefault_out_of_memory(void);
include/linux/mm_types.h +0 -1
index 5ed8f62..beee607 100644
@@ -22,7 +22,6 @@
 #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;
@@ -609,6 +608,78 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
 
 struct vm_fault;

include/linux/mm_types.h static inline bool mm_tlb_flush_nested(struct mm_struct *mm) · line 619

Quoted 10 lines
include/linux/mm_types.h +9 -0
 
+/**
+ * typedef vm_fault_t - Return type for page fault handlers.
+ *
+ * Page fault handlers return a bitmask of %VM_FAULT values.
+ */
+typedef __bitwise unsigned int vm_fault_t;
+
+/**
+ * enum - VM_FAULT code

It should be 'enum vm_fault_reason' here.
A more elaborate brief description would also be nice.

Quoted 69 lines
include/linux/mm_types.h +63 -0
+ *
+ * Page fault handlers return a bitmask of these values to tell
+ * the core VM what happened when handling the fault. Used to decide
+ * whether a process gets delivered SIGBUS or just gets major/minor
+ * fault counters bumped up.
+ *
+ * @VM_FAULT_OOM:		Out Of Memory
+ * @VM_FAULT_SIGBUS:		Bad access
+ * @VM_FAULT_MAJOR:		Page read from storage
+ * @VM_FAULT_WRITE:		Special case for get_user_pages
+ * @VM_FAULT_HWPOISON:		Hit poisoned small page
+ * @VM_FAULT_HWPOISON_LARGE:	Hit poisoned large page. Index encoded
+ *				in upper bits
+ * @VM_FAULT_SIGSEGV:		segmentation fault
+ * @VM_FAULT_NOPAGE:		->fault installed the pte, not return page
+ * @VM_FAULT_LOCKED:		->fault locked the returned page
+ * @VM_FAULT_RETRY:		->fault blocked, must retry
+ * @VM_FAULT_FALLBACK:		huge page fault failed, fall back to small
+ * @VM_FAULT_DONE_COW:		->fault has fully handled COW
+ * @VM_FAULT_NEEDDSYNC:		->fault did not modify page tables and needs
+ *				fsync() to complete (for synchronous page faults
+ *				in DAX)
+ */
+enum vm_fault_reason {
+	VM_FAULT_OOM            = (__force vm_fault_t)0x000001,
+	VM_FAULT_SIGBUS         = (__force vm_fault_t)0x000002,
+	VM_FAULT_MAJOR          = (__force vm_fault_t)0x000004,
+	VM_FAULT_WRITE          = (__force vm_fault_t)0x000008,
+	VM_FAULT_HWPOISON       = (__force vm_fault_t)0x000010,
+	VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
+	VM_FAULT_SIGSEGV        = (__force vm_fault_t)0x000040,
+	VM_FAULT_NOPAGE         = (__force vm_fault_t)0x000100,
+	VM_FAULT_LOCKED         = (__force vm_fault_t)0x000200,
+	VM_FAULT_RETRY          = (__force vm_fault_t)0x000400,
+	VM_FAULT_FALLBACK       = (__force vm_fault_t)0x000800,
+	VM_FAULT_DONE_COW       = (__force vm_fault_t)0x001000,
+	VM_FAULT_NEEDDSYNC      = (__force vm_fault_t)0x002000,
+	VM_FAULT_HINDEX_MASK    = (__force vm_fault_t)0x0f0000,
+};
+
+/* Encode hstate index for a hwpoisoned large page */
+#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
+#define VM_FAULT_GET_HINDEX(x) (((x) >> 16) & 0xf)
+
+#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS |	\
+			VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON |	\
+			VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
+
+#define VM_FAULT_RESULT_TRACE \
+	{ VM_FAULT_OOM,                 "OOM" },	\
+	{ VM_FAULT_SIGBUS,              "SIGBUS" },	\
+	{ VM_FAULT_MAJOR,               "MAJOR" },	\
+	{ VM_FAULT_WRITE,               "WRITE" },	\
+	{ VM_FAULT_HWPOISON,            "HWPOISON" },	\
+	{ VM_FAULT_HWPOISON_LARGE,      "HWPOISON_LARGE" },	\
+	{ VM_FAULT_SIGSEGV,             "SIGSEGV" },	\
+	{ VM_FAULT_NOPAGE,              "NOPAGE" },	\
+	{ VM_FAULT_LOCKED,              "LOCKED" },	\
+	{ VM_FAULT_RETRY,               "RETRY" },	\
+	{ VM_FAULT_FALLBACK,            "FALLBACK" },	\
+	{ VM_FAULT_DONE_COW,            "DONE_COW" },	\
+	{ VM_FAULT_NEEDDSYNC,           "NEEDDSYNC" }
+
 struct vm_special_mapping {
 	const char *name;	/* The name, e.g. "[vdso]". */
 
Signature · 1 line
1.9.1
Signature · 2 lines
Sincerely yours,
Mike.
#2 lore raw
Quoted 96 lines · Mike Rapoport
Quoted 94 lines · Souptick Joarder

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.

---
v2: Updated the change log and corrected the document part.
name added to the enum that kernel-doc able to parse it.

 include/linux/mm.h       | 46 ------------------------------
 include/linux/mm_types.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 47 deletions(-)
include/linux/mm.h +0 -46
index fcf9cc9..511a3ce 100644
@@ -1267,52 +1267,6 @@ static inline void clear_page_pfmemalloc(struct page *page)
 }
 
 /*
- * Different kinds of faults, as returned by handle_mm_fault().
- * Used to decide whether a process gets delivered SIGBUS or
- * just gets major/minor fault counters bumped up.
- */
-
-#define VM_FAULT_OOM 0x0001
-#define VM_FAULT_SIGBUS      0x0002
-#define VM_FAULT_MAJOR       0x0004
-#define VM_FAULT_WRITE       0x0008  /* Special case for get_user_pages */
-#define VM_FAULT_HWPOISON 0x0010     /* Hit poisoned small page */
-#define VM_FAULT_HWPOISON_LARGE 0x0020  /* Hit poisoned large page. Index encoded in upper bits */
-#define VM_FAULT_SIGSEGV 0x0040
-
-#define VM_FAULT_NOPAGE      0x0100  /* ->fault installed the pte, not return page */
-#define VM_FAULT_LOCKED      0x0200  /* ->fault locked the returned page */
-#define VM_FAULT_RETRY       0x0400  /* ->fault blocked, must retry */
-#define VM_FAULT_FALLBACK 0x0800     /* huge page fault failed, fall back to small */
-#define VM_FAULT_DONE_COW   0x1000   /* ->fault has fully handled COW */
-#define VM_FAULT_NEEDDSYNC  0x2000   /* ->fault did not modify page tables
-                                      * and needs fsync() to complete (for
-                                      * synchronous page faults in DAX) */
-
-#define VM_FAULT_ERROR       (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
-                      VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
-                      VM_FAULT_FALLBACK)
-
-#define VM_FAULT_RESULT_TRACE \
-     { VM_FAULT_OOM,                 "OOM" }, \
-     { VM_FAULT_SIGBUS,              "SIGBUS" }, \
-     { VM_FAULT_MAJOR,               "MAJOR" }, \
-     { VM_FAULT_WRITE,               "WRITE" }, \
-     { VM_FAULT_HWPOISON,            "HWPOISON" }, \
-     { VM_FAULT_HWPOISON_LARGE,      "HWPOISON_LARGE" }, \
-     { VM_FAULT_SIGSEGV,             "SIGSEGV" }, \
-     { VM_FAULT_NOPAGE,              "NOPAGE" }, \
-     { VM_FAULT_LOCKED,              "LOCKED" }, \
-     { VM_FAULT_RETRY,               "RETRY" }, \
-     { VM_FAULT_FALLBACK,            "FALLBACK" }, \
-     { VM_FAULT_DONE_COW,            "DONE_COW" }, \
-     { VM_FAULT_NEEDDSYNC,           "NEEDDSYNC" }
-
-/* Encode hstate index for a hwpoisoned large page */
-#define VM_FAULT_SET_HINDEX(x) ((x) << 12)
-#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
-
-/*
  * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
  */
 extern void pagefault_out_of_memory(void);
include/linux/mm_types.h +0 -1
index 5ed8f62..beee607 100644
@@ -22,7 +22,6 @@
 #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;
@@ -609,6 +608,78 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
 
 struct vm_fault;
 
Quoted 11 lines

include/linux/mm_types.h static inline bool mm_tlb_flush_nested(struct mm_struct *mm) · line 619

Quoted 9 lines
include/linux/mm_types.h +9 -0
+/**
+ * typedef vm_fault_t - Return type for page fault handlers.
+ *
+ * Page fault handlers return a bitmask of %VM_FAULT values.
+ */
+typedef __bitwise unsigned int vm_fault_t;
+
+/**
+ * enum - VM_FAULT code

It should be 'enum vm_fault_reason' here.

Sorry, missed it.

Quoted 1 line

A more elaborate brief description would also be nice.

This much description is not sufficient to explain the enum ?

Quoted 75 lines
Quoted 68 lines
include/linux/mm_types.h +63 -1
+ *
+ * Page fault handlers return a bitmask of these values to tell
+ * the core VM what happened when handling the fault. Used to decide
+ * whether a process gets delivered SIGBUS or just gets major/minor
+ * fault counters bumped up.
+ *
+ * @VM_FAULT_OOM:            Out Of Memory
+ * @VM_FAULT_SIGBUS:         Bad access
+ * @VM_FAULT_MAJOR:          Page read from storage
+ * @VM_FAULT_WRITE:          Special case for get_user_pages
+ * @VM_FAULT_HWPOISON:               Hit poisoned small page
+ * @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded
+ *                           in upper bits
+ * @VM_FAULT_SIGSEGV:                segmentation fault
+ * @VM_FAULT_NOPAGE:         ->fault installed the pte, not return page
+ * @VM_FAULT_LOCKED:         ->fault locked the returned page
+ * @VM_FAULT_RETRY:          ->fault blocked, must retry
+ * @VM_FAULT_FALLBACK:               huge page fault failed, fall back to small
+ * @VM_FAULT_DONE_COW:               ->fault has fully handled COW
+ * @VM_FAULT_NEEDDSYNC:              ->fault did not modify page tables and needs
+ *                           fsync() to complete (for synchronous page faults
+ *                           in DAX)
+ */
+enum vm_fault_reason {
+     VM_FAULT_OOM            = (__force vm_fault_t)0x000001,
+     VM_FAULT_SIGBUS         = (__force vm_fault_t)0x000002,
+     VM_FAULT_MAJOR          = (__force vm_fault_t)0x000004,
+     VM_FAULT_WRITE          = (__force vm_fault_t)0x000008,
+     VM_FAULT_HWPOISON       = (__force vm_fault_t)0x000010,
+     VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
+     VM_FAULT_SIGSEGV        = (__force vm_fault_t)0x000040,
+     VM_FAULT_NOPAGE         = (__force vm_fault_t)0x000100,
+     VM_FAULT_LOCKED         = (__force vm_fault_t)0x000200,
+     VM_FAULT_RETRY          = (__force vm_fault_t)0x000400,
+     VM_FAULT_FALLBACK       = (__force vm_fault_t)0x000800,
+     VM_FAULT_DONE_COW       = (__force vm_fault_t)0x001000,
+     VM_FAULT_NEEDDSYNC      = (__force vm_fault_t)0x002000,
+     VM_FAULT_HINDEX_MASK    = (__force vm_fault_t)0x0f0000,
+};
+
+/* Encode hstate index for a hwpoisoned large page */
+#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
+#define VM_FAULT_GET_HINDEX(x) (((x) >> 16) & 0xf)
+
+#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS |     \
+                     VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON |  \
+                     VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
+
+#define VM_FAULT_RESULT_TRACE \
+     { VM_FAULT_OOM,                 "OOM" },        \
+     { VM_FAULT_SIGBUS,              "SIGBUS" },     \
+     { VM_FAULT_MAJOR,               "MAJOR" },      \
+     { VM_FAULT_WRITE,               "WRITE" },      \
+     { VM_FAULT_HWPOISON,            "HWPOISON" },   \
+     { VM_FAULT_HWPOISON_LARGE,      "HWPOISON_LARGE" },     \
+     { VM_FAULT_SIGSEGV,             "SIGSEGV" },    \
+     { VM_FAULT_NOPAGE,              "NOPAGE" },     \
+     { VM_FAULT_LOCKED,              "LOCKED" },     \
+     { VM_FAULT_RETRY,               "RETRY" },      \
+     { VM_FAULT_FALLBACK,            "FALLBACK" },   \
+     { VM_FAULT_DONE_COW,            "DONE_COW" },   \
+     { VM_FAULT_NEEDDSYNC,           "NEEDDSYNC" }
+
 struct vm_special_mapping {
      const char *name;       /* The name, e.g. "[vdso]". */
 
--
Quoted 2 lines

1.9.1

--
Sincerely yours,
Mike.

#3 lore raw
Quoted 109 lines · Souptick Joarder
Quoted 96 lines · Mike Rapoport
Quoted 94 lines · Souptick Joarder

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.

---
v2: Updated the change log and corrected the document part.
name added to the enum that kernel-doc able to parse it.

 include/linux/mm.h       | 46 ------------------------------
 include/linux/mm_types.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 47 deletions(-)
include/linux/mm.h +0 -46
index fcf9cc9..511a3ce 100644
@@ -1267,52 +1267,6 @@ static inline void clear_page_pfmemalloc(struct page *page)
 }
 
 /*
- * Different kinds of faults, as returned by handle_mm_fault().
- * Used to decide whether a process gets delivered SIGBUS or
- * just gets major/minor fault counters bumped up.
- */
-
-#define VM_FAULT_OOM 0x0001
-#define VM_FAULT_SIGBUS      0x0002
-#define VM_FAULT_MAJOR       0x0004
-#define VM_FAULT_WRITE       0x0008  /* Special case for get_user_pages */
-#define VM_FAULT_HWPOISON 0x0010     /* Hit poisoned small page */
-#define VM_FAULT_HWPOISON_LARGE 0x0020  /* Hit poisoned large page. Index encoded in upper bits */
-#define VM_FAULT_SIGSEGV 0x0040
-
-#define VM_FAULT_NOPAGE      0x0100  /* ->fault installed the pte, not return page */
-#define VM_FAULT_LOCKED      0x0200  /* ->fault locked the returned page */
-#define VM_FAULT_RETRY       0x0400  /* ->fault blocked, must retry */
-#define VM_FAULT_FALLBACK 0x0800     /* huge page fault failed, fall back to small */
-#define VM_FAULT_DONE_COW   0x1000   /* ->fault has fully handled COW */
-#define VM_FAULT_NEEDDSYNC  0x2000   /* ->fault did not modify page tables
-                                      * and needs fsync() to complete (for
-                                      * synchronous page faults in DAX) */
-
-#define VM_FAULT_ERROR       (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
-                      VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
-                      VM_FAULT_FALLBACK)
-
-#define VM_FAULT_RESULT_TRACE \
-     { VM_FAULT_OOM,                 "OOM" }, \
-     { VM_FAULT_SIGBUS,              "SIGBUS" }, \
-     { VM_FAULT_MAJOR,               "MAJOR" }, \
-     { VM_FAULT_WRITE,               "WRITE" }, \
-     { VM_FAULT_HWPOISON,            "HWPOISON" }, \
-     { VM_FAULT_HWPOISON_LARGE,      "HWPOISON_LARGE" }, \
-     { VM_FAULT_SIGSEGV,             "SIGSEGV" }, \
-     { VM_FAULT_NOPAGE,              "NOPAGE" }, \
-     { VM_FAULT_LOCKED,              "LOCKED" }, \
-     { VM_FAULT_RETRY,               "RETRY" }, \
-     { VM_FAULT_FALLBACK,            "FALLBACK" }, \
-     { VM_FAULT_DONE_COW,            "DONE_COW" }, \
-     { VM_FAULT_NEEDDSYNC,           "NEEDDSYNC" }
-
-/* Encode hstate index for a hwpoisoned large page */
-#define VM_FAULT_SET_HINDEX(x) ((x) << 12)
-#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
-
-/*
  * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
  */
 extern void pagefault_out_of_memory(void);
include/linux/mm_types.h +0 -1
index 5ed8f62..beee607 100644
@@ -22,7 +22,6 @@
 #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;
@@ -609,6 +608,78 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
 
 struct vm_fault;
 
Quoted 11 lines

include/linux/mm_types.h static inline bool mm_tlb_flush_nested(struct mm_struct *mm) · line 619

Quoted 9 lines
include/linux/mm_types.h +9 -0
+/**
+ * typedef vm_fault_t - Return type for page fault handlers.
+ *
+ * Page fault handlers return a bitmask of %VM_FAULT values.
+ */
+typedef __bitwise unsigned int vm_fault_t;
+
+/**
+ * enum - VM_FAULT code

It should be 'enum vm_fault_reason' here.

Quoted 6 lines

Sorry, missed it.

Quoted 1 line

A more elaborate brief description would also be nice.

This much description is not sufficient to explain the enum ?

Quoted 1 line

The description below is fine, but kernel-doc will use "VM_FAULT code" as the "short description" and the explanation will be used as "long description".

So either replace "VM_FAULT code" with something like "page fault handler return codes" or put the long explanation next to 'enum vm_fault_reason':

/**
* enum vm_fault_reason - page fault handlers return a bitmask of these
* values ...
* ...
*/

Please take a look at "Structure, union, and enumeration documentation" in Documentation/doc-guide/kernel-doc.rst [1].

[1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#structure-union-and-enumeration-documentation

Quoted 75 lines
Quoted 74 lines
Quoted 67 lines
include/linux/mm_types.h +63 -1
+ *
+ * Page fault handlers return a bitmask of these values to tell
+ * the core VM what happened when handling the fault. Used to decide
+ * whether a process gets delivered SIGBUS or just gets major/minor
+ * fault counters bumped up.
+ *
+ * @VM_FAULT_OOM:            Out Of Memory
+ * @VM_FAULT_SIGBUS:         Bad access
+ * @VM_FAULT_MAJOR:          Page read from storage
+ * @VM_FAULT_WRITE:          Special case for get_user_pages
+ * @VM_FAULT_HWPOISON:               Hit poisoned small page
+ * @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded
+ *                           in upper bits
+ * @VM_FAULT_SIGSEGV:                segmentation fault
+ * @VM_FAULT_NOPAGE:         ->fault installed the pte, not return page
+ * @VM_FAULT_LOCKED:         ->fault locked the returned page
+ * @VM_FAULT_RETRY:          ->fault blocked, must retry
+ * @VM_FAULT_FALLBACK:               huge page fault failed, fall back to small
+ * @VM_FAULT_DONE_COW:               ->fault has fully handled COW
+ * @VM_FAULT_NEEDDSYNC:              ->fault did not modify page tables and needs
+ *                           fsync() to complete (for synchronous page faults
+ *                           in DAX)
+ */
+enum vm_fault_reason {
+     VM_FAULT_OOM            = (__force vm_fault_t)0x000001,
+     VM_FAULT_SIGBUS         = (__force vm_fault_t)0x000002,
+     VM_FAULT_MAJOR          = (__force vm_fault_t)0x000004,
+     VM_FAULT_WRITE          = (__force vm_fault_t)0x000008,
+     VM_FAULT_HWPOISON       = (__force vm_fault_t)0x000010,
+     VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020,
+     VM_FAULT_SIGSEGV        = (__force vm_fault_t)0x000040,
+     VM_FAULT_NOPAGE         = (__force vm_fault_t)0x000100,
+     VM_FAULT_LOCKED         = (__force vm_fault_t)0x000200,
+     VM_FAULT_RETRY          = (__force vm_fault_t)0x000400,
+     VM_FAULT_FALLBACK       = (__force vm_fault_t)0x000800,
+     VM_FAULT_DONE_COW       = (__force vm_fault_t)0x001000,
+     VM_FAULT_NEEDDSYNC      = (__force vm_fault_t)0x002000,
+     VM_FAULT_HINDEX_MASK    = (__force vm_fault_t)0x0f0000,
+};
+
+/* Encode hstate index for a hwpoisoned large page */
+#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16))
+#define VM_FAULT_GET_HINDEX(x) (((x) >> 16) & 0xf)
+
+#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS |     \
+                     VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON |  \
+                     VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
+
+#define VM_FAULT_RESULT_TRACE \
+     { VM_FAULT_OOM,                 "OOM" },        \
+     { VM_FAULT_SIGBUS,              "SIGBUS" },     \
+     { VM_FAULT_MAJOR,               "MAJOR" },      \
+     { VM_FAULT_WRITE,               "WRITE" },      \
+     { VM_FAULT_HWPOISON,            "HWPOISON" },   \
+     { VM_FAULT_HWPOISON_LARGE,      "HWPOISON_LARGE" },     \
+     { VM_FAULT_SIGSEGV,             "SIGSEGV" },    \
+     { VM_FAULT_NOPAGE,              "NOPAGE" },     \
+     { VM_FAULT_LOCKED,              "LOCKED" },     \
+     { VM_FAULT_RETRY,               "RETRY" },      \
+     { VM_FAULT_FALLBACK,            "FALLBACK" },   \
+     { VM_FAULT_DONE_COW,            "DONE_COW" },   \
+     { VM_FAULT_NEEDDSYNC,           "NEEDDSYNC" }
+
 struct vm_special_mapping {
      const char *name;       /* The name, e.g. "[vdso]". */
 
--
Quoted 2 lines

1.9.1

--
Sincerely yours,
Mike.

Signature · 2 lines
Sincerely yours,
Mike.
#4 lore raw
In reply to Souptick Joarder
Thank you for the patch! Perhaps something to improve:

Hi Souptick,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.20-rc1 next-20181106]
[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/mm-Create-the-new-vm_fault_t-type/20181106-171908
config: i386-randconfig-h1-11061829 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

>> drivers//dma-buf/udmabuf.c:34:2: warning: initialization from incompatible pointer type

.fault = udmabuf_vm_fault,
^
drivers//dma-buf/udmabuf.c:34:2: warning: (near initialization for 'udmabuf_vm_ops.fault')

vim +34 drivers//dma-buf/udmabuf.c

fbb0de79 Gerd Hoffmann 2018-08-27 32

fbb0de79 Gerd Hoffmann 2018-08-27  33  static const struct vm_operations_struct udmabuf_vm_ops = {
fbb0de79 Gerd Hoffmann 2018-08-27 @34  	.fault = udmabuf_vm_fault,
fbb0de79 Gerd Hoffmann 2018-08-27  35  };

fbb0de79 Gerd Hoffmann 2018-08-27 36

:::::: The code at line 34 was first introduced by commit :::::: fbb0de795078190a9834b3409e4b009cfb18a6d4 Add udmabuf misc device

:::::: TO: Gerd Hoffmann <[email protected]>
:::::: CC: Gerd Hoffmann <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation