From patchwork Tue Mar 22 21:39:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12789072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DB8AC433EF for ; Tue, 22 Mar 2022 21:40:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 084DA6B0082; Tue, 22 Mar 2022 17:40:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F001E6B0087; Tue, 22 Mar 2022 17:40:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7A696B0099; Tue, 22 Mar 2022 17:40:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id BE0346B0082 for ; Tue, 22 Mar 2022 17:40:06 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 963E723882 for ; Tue, 22 Mar 2022 21:40:06 +0000 (UTC) X-FDA: 79273340412.15.94CF50B Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf01.hostedemail.com (Postfix) with ESMTP id 1A1A640037 for ; Tue, 22 Mar 2022 21:39:43 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DE5E3B81DB0; Tue, 22 Mar 2022 21:39:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E9BDC340EE; Tue, 22 Mar 2022 21:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647985181; bh=3i4QFs9B/uJnET8QE64iVchO6AOcfb7NZ+OdPYD0EhQ=; h=Date:To:From:In-Reply-To:Subject:From; b=e4Ji6y9xnPSjqjiv/7IHeYY2dhl1ypWy/fV9Wy03JRcX3zT35M9DaLn5J3LEprq6b cj1/9iK70GKHLSbaknOaJTQdhU/3fFdEP68GAhufOzDTXza6vYu5NZotBzuU6r44eG iPAofHTR6eIPTCsyee8Bp/WwU4rxr56E4QuMsvP4= Date: Tue, 22 Mar 2022 14:39:40 -0700 To: willy@infradead.org,peterx@redhat.com,lukas.bulwahn@gmail.com,kirill.shutemov@linux.intel.com,jgg@ziepe.ca,jgg@nvidia.com,jack@suse.cz,imbrenda@linux.ibm.com,hch@lst.de,david@redhat.com,alex.williamson@redhat.com,aarcange@redhat.com,jhubbard@nvidia.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220322143803.04a5e59a07e48284f196a2f9@linux-foundation.org> Subject: [patch 023/227] mm/gup: follow_pfn_pte(): -EEXIST cleanup Message-Id: <20220322213941.7E9BDC340EE@smtp.kernel.org> Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=e4Ji6y9x; spf=pass (imf01.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Stat-Signature: jpjpnea4di9yt778y4q4oeibi9zdwn4q X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1A1A640037 X-HE-Tag: 1647985183-676647 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: John Hubbard Subject: mm/gup: follow_pfn_pte(): -EEXIST cleanup Remove a quirky special case from follow_pfn_pte(), and adjust its callers to match. Caller changes include: __get_user_pages(): Regardless of any FOLL_* flags, get_user_pages() and its variants should handle PFN-only entries by stopping early, if the caller expected **pages to be filled in. This makes for a more reliable API, as compared to the previous approach of skipping over such entries (and thus leaving them silently unwritten). move_pages(): squash the -EEXIST error return from follow_page() into -EFAULT, because -EFAULT is listed in the man page, whereas -EEXIST is not. Link: https://lkml.kernel.org/r/20220204020010.68930-3-jhubbard@nvidia.com Signed-off-by: John Hubbard Suggested-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara Cc: Peter Xu Cc: Lukas Bulwahn Cc: Matthew Wilcox Cc: Claudio Imbrenda Cc: Alex Williamson Cc: Andrea Arcangeli Cc: David Hildenbrand Cc: Jason Gunthorpe Cc: Kirill A. Shutemov Signed-off-by: Andrew Morton --- mm/gup.c | 13 ++++++++----- mm/migrate.c | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) --- a/mm/gup.c~mm-gup-follow_pfn_pte-eexist-cleanup +++ a/mm/gup.c @@ -464,10 +464,6 @@ static struct page *no_page_table(struct static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, unsigned int flags) { - /* No page to get reference */ - if (flags & (FOLL_GET | FOLL_PIN)) - return -EFAULT; - if (flags & FOLL_TOUCH) { pte_t entry = *pte; @@ -1205,8 +1201,15 @@ retry: } else if (PTR_ERR(page) == -EEXIST) { /* * Proper page table entry exists, but no corresponding - * struct page. + * struct page. If the caller expects **pages to be + * filled in, bail out now, because that can't be done + * for this page. */ + if (pages) { + ret = PTR_ERR(page); + goto out; + } + goto next_page; } else if (IS_ERR(page)) { ret = PTR_ERR(page); --- a/mm/migrate.c~mm-gup-follow_pfn_pte-eexist-cleanup +++ a/mm/migrate.c @@ -1762,6 +1762,13 @@ static int do_pages_move(struct mm_struc } /* + * The move_pages() man page does not have an -EEXIST choice, so + * use -EFAULT instead. + */ + if (err == -EEXIST) + err = -EFAULT; + + /* * If the page is already on the target node (!err), store the * node, otherwise, store the err. */