Skip to content

Commit eb2faa5

Browse files
davidhildenbrandtorvalds
authored andcommitted
mm/madvise: report SIGBUS as -EFAULT for MADV_POPULATE_(READ|WRITE)
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. Link: https://lkml.kernel.org/r/20210726154932.102880-1-david@redhat.com Fixes: 4ca9b38 ("mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables") Signed-off-by: David Hildenbrand <david@redhat.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Michal Hocko <mhocko@suse.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Jann Horn <jannh@google.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Hugh Dickins <hughd@google.com> Cc: Rik van Riel <riel@surriel.com> Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Matt Turner <mattst88@gmail.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: Helge Deller <deller@gmx.de> Cc: Chris Zankel <chris@zankel.net> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Peter Xu <peterx@redhat.com> Cc: Rolf Eike Beer <eike-kernel@sf-tec.de> Cc: Ram Pai <linuxram@us.ibm.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a7f1d48 commit eb2faa5

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

mm/gup.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,9 +1558,12 @@ long faultin_vma_page_range(struct vm_area_struct *vma, unsigned long start,
15581558
gup_flags |= FOLL_WRITE;
15591559

15601560
/*
1561-
* See check_vma_flags(): Will return -EFAULT on incompatible mappings
1562-
* or with insufficient permissions.
1561+
* We want to report -EINVAL instead of -EFAULT for any permission
1562+
* problems or incompatible mappings.
15631563
*/
1564+
if (check_vma_flags(vma, gup_flags))
1565+
return -EINVAL;
1566+
15641567
return __get_user_pages(mm, start, nr_pages, gup_flags,
15651568
NULL, NULL, locked);
15661569
}

mm/madvise.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,12 @@ static long madvise_populate(struct vm_area_struct *vma,
862862
switch (pages) {
863863
case -EINTR:
864864
return -EINTR;
865-
case -EFAULT: /* Incompatible mappings / permissions. */
865+
case -EINVAL: /* Incompatible mappings / permissions. */
866866
return -EINVAL;
867867
case -EHWPOISON:
868868
return -EHWPOISON;
869+
case -EFAULT: /* VM_FAULT_SIGBUS or VM_FAULT_SIGSEGV */
870+
return -EFAULT;
869871
default:
870872
pr_warn_once("%s: unhandled return value: %ld\n",
871873
__func__, pages);

0 commit comments

Comments
 (0)