From patchwork Fri Aug 13 23:54:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12436399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 617A1C432BE for ; Fri, 13 Aug 2021 23:54:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1592D610FA for ; Fri, 13 Aug 2021 23:54:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1592D610FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id AC6F78D0007; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A77CF8D0003; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98DBE8D0007; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 7FF798D0003 for ; Fri, 13 Aug 2021 19:54:40 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 33EAD8249980 for ; Fri, 13 Aug 2021 23:54:40 +0000 (UTC) X-FDA: 78471714720.32.F83B33C Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf13.hostedemail.com (Postfix) with ESMTP id D19141013C73 for ; Fri, 13 Aug 2021 23:54:39 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 2659F610F7; Fri, 13 Aug 2021 23:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628898879; bh=NjQZrs+ymn1N+nS8UGQy8zm+/Gtdn8lVDmyEIRG5YNs=; h=Date:From:To:Subject:In-Reply-To:From; b=lUZv7W92e8FVCNZwU5YOyBZGutPKNEn5EwA1HP2L9VhFSn8JMx9+XU6SQ0I/mq+u2 /bsSZ+Tny8jULBQwpiQTblcMwQS6F0VT8jQZh550BUwjbL+kHRDQgdAdYEb0Yk6duc kwDdp+bh/BtUGj44JKyVn4RqitSkvc/T5bQ75f9Q= Date: Fri, 13 Aug 2021 16:54:37 -0700 From: Andrew Morton To: aarcange@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, chris@zankel.net, dave.hansen@intel.com, david@redhat.com, deller@gmx.de, eike-kernel@sf-tec.de, hughd@google.com, ink@jurassic.park.msu.ru, James.Bottomley@HansenPartnership.com, jannh@google.com, jcmvbkbc@gmail.com, jgg@ziepe.ca, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, linuxram@us.ibm.com, mattst88@gmail.com, mhocko@suse.com, mike.kravetz@oracle.com, minchan@kernel.org, mm-commits@vger.kernel.org, mst@redhat.com, osalvador@suse.de, peterx@redhat.com, riel@surriel.com, rth@twiddle.net, shuah@kernel.org, torvalds@linux-foundation.org, tsbogend@alpha.franken.de, vbabka@suse.cz, willy@infradead.org Subject: [patch 5/7] mm/madvise: report SIGBUS as -EFAULT for MADV_POPULATE_(READ|WRITE) Message-ID: <20210813235437.jpdoEJdjF%akpm@linux-foundation.org> In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: D19141013C73 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=lUZv7W92; dmarc=none; spf=pass (imf13.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam04 X-Stat-Signature: 6wucuagine59zyj91185fihg19y6ijaq X-HE-Tag: 1628898879-861414 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: David Hildenbrand Subject: 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 behavio= r. Link: https://lkml.kernel.org/r/20210726154932.102880-1-david@redhat.com Fixes: 4ca9b3859dac ("mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables") Signed-off-by: David Hildenbrand 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: Andrew Morton --- mm/gup.c | 7 +++++-- mm/madvise.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) --- a/mm/gup.c~mm-madvise-report-sigbus-as-efault-for-madv_populate_readwrite +++ a/mm/gup.c @@ -1558,9 +1558,12 @@ long faultin_vma_page_range(struct vm_ar 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); } --- a/mm/madvise.c~mm-madvise-report-sigbus-as-efault-for-madv_populate_readwrite +++ a/mm/madvise.c @@ -862,10 +862,12 @@ static long madvise_populate(struct vm_a switch (pages) { case -EINTR: return -EINTR; - case -EFAULT: /* Incompatible mappings / permissions. */ + case -EINVAL: /* Incompatible mappings / permissions. */ return -EINVAL; case -EHWPOISON: return -EHWPOISON; + case -EFAULT: /* VM_FAULT_SIGBUS or VM_FAULT_SIGSEGV */ + return -EFAULT; default: pr_warn_once("%s: unhandled return value: %ld\n", __func__, pages);