archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mm/madvise: report SIGBUS as -EFAULT for MADV_POPULATE_(READ|WRITE)
@ 2021-07-26 15:49 David Hildenbrand
  2021-07-30 12:23 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: David Hildenbrand @ 2021-07-26 15:49 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, Linux API, David Hildenbrand, Arnd Bergmann,
	Michal Hocko, Oscar Salvador, Matthew Wilcox, Andrea Arcangeli,
	Minchan Kim, Jann Horn, Jason Gunthorpe, Dave Hansen,
	Hugh Dickins, Rik van Riel, Michael S . Tsirkin,
	Kirill A . Shutemov, Vlastimil Babka, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, Thomas Bogendoerfer,
	James E.J. Bottomley, Helge Deller, Chris Zankel, Max Filippov,
	Mike Kravetz, Peter Xu, Rolf Eike Beer, Ram Pai, Shuah Khan

Doing some extended tests and polishing the man page update for
MADV_POPULATE_(READ|WRITE), I realized that we end up converting also
SIGBUS (via -EFAULT) to -EINVAL, making it look like yet another
madvise() user error.

We want to report only problematic mappings and permission problems that
the user could have know as -EINVAL.

Let's not convert -EFAULT arising due to SIGBUS (or SIGSEGV) to
-EINVAL, but instead indicate -EFAULT to user space. While we could also
convert it to -ENOMEM, using -EFAULT looks more helpful when user space
might want to troubleshoot what's going wrong: MADV_POPULATE_(READ|WRITE)
is not part of an final Linux release and we can still adjust the behavior.

Fixes: 4ca9b3859dac ("mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables")
Cc: Arnd Bergmann <>
Cc: Michal Hocko <>
Cc: Oscar Salvador <>
Cc: Matthew Wilcox (Oracle) <>
Cc: Andrea Arcangeli <>
Cc: Minchan Kim <>
Cc: Jann Horn <>
Cc: Jason Gunthorpe <>
Cc: Dave Hansen <>
Cc: Hugh Dickins <>
Cc: Rik van Riel <>
Cc: Michael S. Tsirkin <>
Cc: Kirill A. Shutemov <>
Cc: Vlastimil Babka <>
Cc: Richard Henderson <>
Cc: Ivan Kokshaysky <>
Cc: Matt Turner <>
Cc: Thomas Bogendoerfer <>
Cc: "James E.J. Bottomley" <>
Cc: Helge Deller <>
Cc: Chris Zankel <>
Cc: Max Filippov <>
Cc: Mike Kravetz <>
Cc: Peter Xu <>
Cc: Rolf Eike Beer <>
Cc: Ram Pai <>
Cc: Shuah Khan <>
Signed-off-by: David Hildenbrand <>
 mm/gup.c     | 7 +++++--
 mm/madvise.c | 4 +++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 42b8b1fa6521..b94717977d17 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1558,9 +1558,12 @@ long faultin_vma_page_range(struct vm_area_struct *vma, unsigned long start,
 		gup_flags |= FOLL_WRITE;
-	 * See check_vma_flags(): Will return -EFAULT on incompatible mappings
-	 * or with insufficient permissions.
+	 * We want to report -EINVAL instead of -EFAULT for any permission
+	 * problems or incompatible mappings.
+	if (check_vma_flags(vma, gup_flags))
+		return -EINVAL;
 	return __get_user_pages(mm, start, nr_pages, gup_flags,
 				NULL, NULL, locked);
diff --git a/mm/madvise.c b/mm/madvise.c
index 6d3d348b17f4..5c065bc8b5f6 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -862,10 +862,12 @@ static long madvise_populate(struct vm_area_struct *vma,
 			switch (pages) {
 			case -EINTR:
 				return -EINTR;
-			case -EFAULT: /* Incompatible mappings / permissions. */
+			case -EINVAL: /* Incompatible mappings / permissions. */
 				return -EINVAL;
 			case -EHWPOISON:
 				return -EHWPOISON;
+				return -EFAULT;
 				pr_warn_once("%s: unhandled return value: %ld\n",
 					     __func__, pages);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-30 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26 15:49 [PATCH v1] mm/madvise: report SIGBUS as -EFAULT for MADV_POPULATE_(READ|WRITE) David Hildenbrand
2021-07-30 12:23 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).