Skip to contentSkip to conversation

userfaultfd: replace ENOSPC with ESRCH in case mm has gone during copy/zeropage

PATCH In review Mike Rapoport 2 participants 3 messages Aug 7, 2017 – Aug 10, 2017

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

PATCH 1/1 userfaultfd: replace ENOSPC with ESRCH in case mm has gone during copy/zeropage

When the process exit races with outstanding mcopy_atomic, it would be better to return ESRCH error. When such race occurs the process and it's mm are going away and returning "no such process" to the uffd monitor seems better fit than ENOSPC.

Cc Andrea Arcangeli <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Cc Mike Kravetz <[email protected]>

---
The man-pages update is ready and I'll send it out once the patch is merged.

 fs/userfaultfd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/userfaultfd.c +2 -2
index 06ea26b8c996..b0d5897bc4e6 100644
@@ -1600,7 +1600,7 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx,
 				   uffdio_copy.len);
 		mmput(ctx->mm);
 	} else {
-		return -ENOSPC;
+		return -ESRCH;
 	}
 	if (unlikely(put_user(ret, &user_uffdio_copy->copy)))
 		return -EFAULT;
@@ -1647,7 +1647,7 @@ static int userfaultfd_zeropage(struct userfaultfd_ctx *ctx,
 				     uffdio_zeropage.range.len);
 		mmput(ctx->mm);
 	} else {
-		return -ENOSPC;
+		return -ESRCH;
 	}
 	if (unlikely(put_user(ret, &user_uffdio_zeropage->zeropage)))
 		return -EFAULT;
Signature · 1 line
2.7.4
#1 lore raw

(adding Michal)

Quoted 43 lines · Mike Rapoport

When the process exit races with outstanding mcopy_atomic, it would be better to return ESRCH error. When such race occurs the process and it's mm are going away and returning "no such process" to the uffd monitor seems better fit than ENOSPC.

Cc Andrea Arcangeli <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Cc Mike Kravetz <[email protected]>

---
The man-pages update is ready and I'll send it out once the patch is merged.

 fs/userfaultfd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/userfaultfd.c +2 -2
index 06ea26b8c996..b0d5897bc4e6 100644
@@ -1600,7 +1600,7 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx,
 				   uffdio_copy.len);
 		mmput(ctx->mm);
 	} else {
-		return -ENOSPC;
+		return -ESRCH;
 	}
 	if (unlikely(put_user(ret, &user_uffdio_copy->copy)))
 		return -EFAULT;
@@ -1647,7 +1647,7 @@ static int userfaultfd_zeropage(struct userfaultfd_ctx *ctx,
 				     uffdio_zeropage.range.len);
 		mmput(ctx->mm);
 	} else {
-		return -ENOSPC;
+		return -ESRCH;
 	}
 	if (unlikely(put_user(ret, &user_uffdio_zeropage->zeropage)))
 		return -EFAULT;
Signature · 1 line
2.7.4
Signature · 8 lines
Sincerely yours,
Mike.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by
#2 lore raw
Quoted 1 line · Mike Rapoport

(adding Michal)

Thanks

Quoted 5 lines · Mike Rapoport
Quoted 4 lines

When the process exit races with outstanding mcopy_atomic, it would be better to return ESRCH error. When such race occurs the process and it's mm are going away and returning "no such process" to the uffd monitor seems better fit than ENOSPC.

Not only the error message would be less confusing I also think that error handling should be more straightforward. Although I cannot find any guidelines for ENOSPC handling I've considered this errno as potentially temporary and retry might be feasible while ESRCH is a terminal error. I do not expect any userfaultfd users would retry on error but who knows how the interface will be used in future so better be prepared.

Quoted 6 lines
Quoted 6 lines
Cc Andrea Arcangeli <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Cc Mike Kravetz <[email protected]>
Quoted 37 lines
Quoted 32 lines

---
The man-pages update is ready and I'll send it out once the patch is merged.

 fs/userfaultfd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/userfaultfd.c +2 -2
index 06ea26b8c996..b0d5897bc4e6 100644
@@ -1600,7 +1600,7 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx,
 				   uffdio_copy.len);
 		mmput(ctx->mm);
 	} else {
-		return -ENOSPC;
+		return -ESRCH;
 	}
 	if (unlikely(put_user(ret, &user_uffdio_copy->copy)))
 		return -EFAULT;
@@ -1647,7 +1647,7 @@ static int userfaultfd_zeropage(struct userfaultfd_ctx *ctx,
 				     uffdio_zeropage.range.len);
 		mmput(ctx->mm);
 	} else {
-		return -ENOSPC;
+		return -ESRCH;
 	}
 	if (unlikely(put_user(ret, &user_uffdio_zeropage->zeropage)))
 		return -EFAULT;
Signature · 1 line
2.7.4
Signature · 2 lines
Sincerely yours,
Mike.
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>