Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3096745pxb; Fri, 4 Feb 2022 00:53:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyj9KcM6mn/mYzqsCYZj3qC6jmpD+6BEfG3QQ73vaboy6r3TOtXfP5qgrJ7ZQkN/cqQAOcn X-Received: by 2002:a17:907:e91:: with SMTP id ho17mr1634766ejc.662.1643964834997; Fri, 04 Feb 2022 00:53:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643964834; cv=none; d=google.com; s=arc-20160816; b=M4h8//Wn/0xsTffk3r4Xu7wDH/dDW1a/GGhPsiXGNqpvurcEWoF45AcdsXM5EJYrbP 3MTGbbQMFiQ5FGDdfGVyI6QWs+6ttXXwrgO0CIjv0i2zz3hIvOTUkKO/H42217Hi/zNm VMOQDVNGi3TnhyQ+eVzIe9N0utiSX+f3HKLSiaenh2p1aO37HqxQbHdNEr1Ozg+S2LOj YLmujje5AZ0zwf2MunY+mZ5cKUPbrhr83Qt6UZbQEh+yc1pw5WqeVm/I0EEJNoPPDiNf PGoGIEQMH0uSkLE5bC5dxOECq6SgDNHvHCISUhgNWTxOFr99j2R+Wo1S7WuHEBwStL3T vYLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JubVW6L5I/oihcd7EvRehLP90WpN/OdP8an7CGcf4Fg=; b=CWIKyumtcEDp9siTDNlW/dupW1Tpa2rfI7QrXSoYIJpyiAGXl7VM18pDqUFI6C5aIn BE4bJRFnKUBdRAMWTC7b+rEuFxUJ43G4XIz/ygkYoOQl9N+F2vbVf1kJaAHGfdu9JaWx ySoxCiVIV2Fy4xcOlN6a/7o8Ivgrb8VQao1OnCXKXxGD7ZLXY1A1ruYauHfKmoRURHCW wy1Val4qnSc6vrTqZKigM8tlDAU4WOJ0t80U2vi6ZosowpzGxiqOkdwu7hX4S0qbJdfZ ogQfWs+SOEXRhVIr0gupM1ZxA+4FyXCtTs+n+ywAeOgQaYPriFSMU4CBNu2Rksup73CS YiwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=bhxVJaUV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn2si968622ejc.927.2022.02.04.00.53.29; Fri, 04 Feb 2022 00:53:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=bhxVJaUV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351786AbiBCPTQ (ORCPT + 99 others); Thu, 3 Feb 2022 10:19:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351806AbiBCPTO (ORCPT ); Thu, 3 Feb 2022 10:19:14 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DC83C061749 for ; Thu, 3 Feb 2022 07:19:14 -0800 (PST) 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.