Skip to contentSkip to conversation

staging: lustre: Change return type to vm_fault_t

PATCH New Souptick Joarder 2 participants 6 messages Apr 21, 2018 – Apr 23, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lustre: Change return type to 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.

Commit 1c8f422059ae ("mm: change return type to vm_fault_t")

---
 drivers/staging/lustre/lustre/llite/llite_mmap.c | 29 ++++++++++++------------
 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/staging/lustre/lustre/llite/llite_mmap.c +15 -14
index c0533bd..6aafe7c 100644
@@ -231,7 +231,7 @@ static int ll_page_mkwrite0(struct vm_area_struct *vma, struct page *vmpage,
 	return result;
 }
 
-static inline int to_fault_error(int result)
+static inline vm_fault_t to_fault_error(int result)
 {
 	switch (result) {
 	case 0:
@@ -261,7 +261,7 @@ static inline int to_fault_error(int result)
  * \retval VM_FAULT_ERROR on general error
  * \retval NOPAGE_OOM not have memory for allocate new page
  */
-static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
+static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct lu_env	   *env;
 	struct cl_io	    *io;
@@ -269,7 +269,7 @@ static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 	struct page	     *vmpage;
 	unsigned long	    ra_flags;
 	int		      result = 0;
-	int		      fault_ret = 0;
+	vm_fault_t		fault_ret = 0;
 	u16 refcheck;
 
 	env = cl_env_get(&refcheck);
@@ -278,7 +278,7 @@ static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 
 	io = ll_fault_io_init(env, vma, vmf->pgoff, &ra_flags);
 	if (IS_ERR(io)) {
-		result = to_fault_error(PTR_ERR(io));
+		fault_ret = to_fault_error(PTR_ERR(io));
 		goto out;
 	}
 
@@ -319,7 +319,7 @@ static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 	if (result != 0 && !(fault_ret & VM_FAULT_RETRY))
 		fault_ret |= to_fault_error(result);
 
-	CDEBUG(D_MMAP, "%s fault %d/%d\n", current->comm, fault_ret, result);
+	CDEBUG(D_MMAP, "%s fault %x/%d\n", current->comm, fault_ret, result);
 	return fault_ret;
 }
 
@@ -327,7 +327,7 @@ static int ll_fault(struct vm_fault *vmf)
 {
 	int count = 0;
 	bool printed = false;
-	int result;
+	vm_fault_t result;
 	sigset_t set;
 
 	/* Only SIGKILL and SIGTERM are allowed for fault/nopage/mkwrite
@@ -370,12 +370,13 @@ static int ll_page_mkwrite(struct vm_fault *vmf)
 	int count = 0;
 	bool printed = false;
 	bool retry;
-	int result;
+	int err;
+	vm_fault_t ret;
 
 	file_update_time(vma->vm_file);
 	do {
 		retry = false;
-		result = ll_page_mkwrite0(vma, vmf->page, &retry);
+		err = ll_page_mkwrite0(vma, vmf->page, &retry);
 
 		if (!printed && ++count > 16) {
 			const struct dentry *de = vma->vm_file->f_path.dentry;
@@ -387,25 +388,25 @@ static int ll_page_mkwrite(struct vm_fault *vmf)
 		}
 	} while (retry);
 
-	switch (result) {
+	switch (err) {
 	case 0:
 		LASSERT(PageLocked(vmf->page));
-		result = VM_FAULT_LOCKED;
+		ret = VM_FAULT_LOCKED;
 		break;
 	case -ENODATA:
 	case -EAGAIN:
 	case -EFAULT:
-		result = VM_FAULT_NOPAGE;
+		ret = VM_FAULT_NOPAGE;
 		break;
 	case -ENOMEM:
-		result = VM_FAULT_OOM;
+		ret = VM_FAULT_OOM;
 		break;
 	default:
-		result = VM_FAULT_SIGBUS;
+		ret = VM_FAULT_SIGBUS;
 		break;
 	}
 
-	return result;
+	return ret;
 }
 
 /**
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 staging: lustre: Change return type to vm_fault_t

drivers/staging/lustre/lustre/llite/llite_mmap.c static inline int to_fault_error(int result) · line 267

Quoted 9 lines · Souptick Joarder
drivers/staging/lustre/lustre/llite/llite_mmap.c +1 -1
@@ -261,7 +261,7 @@ static inline int to_fault_error(int result)
  * \retval VM_FAULT_ERROR on general error
  * \retval NOPAGE_OOM not have memory for allocate new page
  */
-static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
+static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct lu_env	   *env;
 	struct cl_io	    *io;

Did you compile-test this with the sparse changes? Because I can see a problem here:

        env = cl_env_get(&refcheck);
        if (IS_ERR(env))
                return PTR_ERR(env);

drivers/staging/lustre/lustre/llite/llite_mmap.c static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf) · line 272

Quoted 6 lines
drivers/staging/lustre/lustre/llite/llite_mmap.c +1 -1
@@ -269,7 +269,7 @@ static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 	struct page	     *vmpage;
 	unsigned long	    ra_flags;
 	int		      result = 0;
-	int		      fault_ret = 0;
+	vm_fault_t		fault_ret = 0;

What odd indentation ...

#2 lore raw

PATCH 1/1 staging: lustre: Change return type to vm_fault_t

Quoted 13 lines · Matthew Wilcox

drivers/staging/lustre/lustre/llite/llite_mmap.c static inline int to_fault_error(int result) · line 267

Quoted 9 lines · Souptick Joarder
drivers/staging/lustre/lustre/llite/llite_mmap.c +1 -1
@@ -261,7 +261,7 @@ static inline int to_fault_error(int result)
  * \retval VM_FAULT_ERROR on general error
  * \retval NOPAGE_OOM not have memory for allocate new page
  */
-static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
+static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
      struct lu_env      *env;
      struct cl_io        *io;

Did you compile-test this with the sparse changes? Because I can see a problem here:

Yes, compile-tested. Sparse didn't throw any warning/error.

Quoted 5 lines
        env = cl_env_get(&refcheck);
        if (IS_ERR(env))
                return PTR_ERR(env);
Quoted 8 lines

drivers/staging/lustre/lustre/llite/llite_mmap.c static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf) · line 272

Quoted 6 lines
drivers/staging/lustre/lustre/llite/llite_mmap.c +1 -1
@@ -269,7 +269,7 @@ static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
      struct page          *vmpage;
      unsigned long       ra_flags;
      int                   result = 0;
-     int                   fault_ret = 0;
+     vm_fault_t              fault_ret = 0;

What odd indentation ...

Sorry, will correct it.

Quoted 1 line
#3 lore raw

PATCH 1/1 staging: lustre: Change return type to vm_fault_t

Quoted 15 lines · Souptick Joarder
Quoted 13 lines · Matthew Wilcox

drivers/staging/lustre/lustre/llite/llite_mmap.c static inline int to_fault_error(int result) · line 267

Quoted 9 lines · Souptick Joarder
drivers/staging/lustre/lustre/llite/llite_mmap.c +1 -1
@@ -261,7 +261,7 @@ static inline int to_fault_error(int result)
  * \retval VM_FAULT_ERROR on general error
  * \retval NOPAGE_OOM not have memory for allocate new page
  */
-static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
+static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
      struct lu_env      *env;
      struct cl_io        *io;

Did you compile-test this with the sparse changes? Because I can see a problem here:

Quoted 1 line

Yes, compile-tested. Sparse didn't throw any warning/error.

I think you need to check your setup ... I get this:

drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: warning: incorrect type in return expression (different base types)
drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: expected restricted vm_fault_t
drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: got long

#4 lore raw

PATCH 1/1 staging: lustre: Change return type to vm_fault_t

Quoted 16 lines · Matthew Wilcox
Quoted 15 lines · Souptick Joarder
Quoted 13 lines · Matthew Wilcox

drivers/staging/lustre/lustre/llite/llite_mmap.c static inline int to_fault_error(int result) · line 267

Quoted 9 lines · Souptick Joarder
drivers/staging/lustre/lustre/llite/llite_mmap.c +1 -1
@@ -261,7 +261,7 @@ static inline int to_fault_error(int result)
  * \retval VM_FAULT_ERROR on general error
  * \retval NOPAGE_OOM not have memory for allocate new page
  */
-static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
+static vm_fault_t ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
      struct lu_env      *env;
      struct cl_io        *io;

Did you compile-test this with the sparse changes? Because I can see a problem here:

Quoted 7 lines
Quoted 1 line

Yes, compile-tested. Sparse didn't throw any warning/error.

I think you need to check your setup ... I get this:

drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: warning: incorrect type in return expression (different base types)
drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: expected restricted vm_fault_t
drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: got long

What I am trying is -
after applying the patch in 4.17-rc1, enable the configuration for this driver and do "make c=1/2 -j8"

Let me verify again.

#5 lore raw

PATCH 1/1 staging: lustre: Change return type to vm_fault_t

Quoted 7 lines · Souptick Joarder
Quoted 5 lines · Matthew Wilcox

I think you need to check your setup ... I get this:

drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: warning: incorrect type in return expression (different base types)
drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: expected restricted vm_fault_t
drivers/staging/lustre/lustre/llite/llite_mmap.c:277:31: got long

Quoted 5 lines

What I am trying is -
after applying the patch in 4.17-rc1, enable the configuration for this driver and do "make c=1/2 -j8"

Let me verify again.

Yep, but you need to add the sparse annotations to make vm_fault_t a separate type. In case you've lost that patch ...

include/linux/mm.h +0 -46
index ad06d42adb1a..9ac6d2eb633f 100644
@@ -1174,52 +1175,6 @@ static inline void clear_page_pfmemalloc(struct page *page)
 	page->index = 0;
 }
 
-/*
- * 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.
  */
include/linux/mm_types.h +48 -0

54 lines not on this page · raw message