From mboxrd@z Thu Jan 1 00:00:00 1970 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 8110BC433F5 for ; Thu, 3 Feb 2022 15:19:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C19C98D0153; Thu, 3 Feb 2022 10:19:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC9998D0124; Thu, 3 Feb 2022 10:19:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A91828D0153; Thu, 3 Feb 2022 10:19:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id 9B8098D0124 for ; Thu, 3 Feb 2022 10:19:18 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 60B6C18288A49 for ; Thu, 3 Feb 2022 15:19:18 +0000 (UTC) X-FDA: 79101827196.15.BEB9EA8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 8FFE414000F for ; Thu, 3 Feb 2022 15:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=JubVW6L5I/oihcd7EvRehLP90WpN/OdP8an7CGcf4Fg=; b=bhxVJaUVl9+20YoeMhbPx/Ti1Z tco5qjym0K5TEZxv0+zYQVOkXL6etkFMiS4CNqYzIFVCxB57iunTOFwiZklveFN/VH72wcRgjRMbm 0S/ZT7oRcua/0tPaFvyN33V1PE+v4Il/rT76ARoGi74foqRik63V8G8uRs7ioWWHCmGdwM6kD0WKD hqrUyp0e2iqBGvOZfIZ9d6fzZZGaTgmNTKAn/sjq93rO86RsXSSIEDwqEbExnYJgfBELURKum0tWf cnItgvVkK7h/pvAC9he1tPDGzEbEPZzY3TM4hvnp6CyU37QwJH8/9hXUnRRqJUgU+wSuOczVvlwvi ztpVpezw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFdsv-00295Z-1R; Thu, 03 Feb 2022 15:18:57 +0000 Date: Thu, 3 Feb 2022 15:18:57 +0000 From: Matthew Wilcox To: Jason Gunthorpe Cc: Jan Kara , John Hubbard , Andrew Morton , Peter Xu , David Hildenbrand , Lukas Bulwahn , Claudio Imbrenda , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , LKML , linux-mm@kvack.org Subject: Re: [PATCH v3 2/4] mm/gup: clean up follow_pfn_pte() slightly Message-ID: References: <20220203093232.572380-1-jhubbard@nvidia.com> <20220203093232.572380-3-jhubbard@nvidia.com> <20220203135352.55f35pztwmdx2rhk@quack3.lan> <20220203150123.GB8034@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220203150123.GB8034@ziepe.ca> X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 8FFE414000F X-Stat-Signature: owyrxpkp6b4zg34fjort76jc1gsd3i3c Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=bhxVJaUV; dmarc=none; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: nil X-HE-Tag: 1643901557-620690 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: On Thu, Feb 03, 2022 at 11:01:23AM -0400, Jason Gunthorpe wrote: > On Thu, Feb 03, 2022 at 02:53:52PM +0100, Jan Kara wrote: > > On Thu 03-02-22 01:32:30, John Hubbard wrote: > > > 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). > > > > > > Cc: Peter Xu > > > Cc: Lukas Bulwahn > > > Suggested-by: Jason Gunthorpe > > > Reviewed-by: Jason Gunthorpe > > > Signed-off-by: John Hubbard > > > mm/gup.c | 11 ++++++----- > > > 1 file changed, 6 insertions(+), 5 deletions(-) > > > > > > diff --git a/mm/gup.c b/mm/gup.c > > > index 65575ae3602f..cad3f28492e3 100644 > > > +++ b/mm/gup.c > > > @@ -439,10 +439,6 @@ static struct page *no_page_table(struct vm_area_struct *vma, > > > 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; > > > > > > > This will also modify the error code returned from follow_page(). > > Er, but isn't that the whole point of this entire design? It is what > the commit that added it says: > > commit 1027e4436b6a5c413c95d95e50d0f26348a602ac > Author: Kirill A. Shutemov > Date: Fri Sep 4 15:47:55 2015 -0700 > > mm: make GUP handle pfn mapping unless FOLL_GET is requested > > With DAX, pfn mapping becoming more common. The patch adjusts GUP code to > cover pfn mapping for cases when we don't need struct page to proceed. > > To make it possible, let's change follow_page() code to return -EEXIST > error code if proper page table entry exists, but no corresponding struct > page. __get_user_page() would ignore the error code and move to the next > page frame. > > The immediate effect of the change is working MAP_POPULATE and mlock() on > DAX mappings. > > > A quick audit shows that at least the user in mm/migrate.c will > > propagate this error code to userspace and I'm not sure the change > > in error code will not break something... EEXIST is a bit strange > > error code to get from move_pages(2). > > That makes sense, maybe move_pages should squash the return codes to > EEXIST? I think EFAULT is the closest: This is a zero page or the memory area is not mapped by the process. EBUSY implies it can be tried again later.