Message ID | 54607cf4-ddb6-7ef3-043-1d2de1a9a71@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp649012vqr; Thu, 8 Jun 2023 18:30:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/bP7EE5to5WCkI1BtvgIDDRWL2dFrrRgKKfq2uwAkYq8U7KJUWpry7bR88uws+3YsrxoD X-Received: by 2002:a05:6830:104c:b0:6af:8348:6a5f with SMTP id b12-20020a056830104c00b006af83486a5fmr78254otp.22.1686274231063; Thu, 08 Jun 2023 18:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686274231; cv=none; d=google.com; s=arc-20160816; b=E64tbKyu/tUW+CXWw4wrSqen+FwC7zWR/pDdv4mXI6VetAnpF/X3BwvKKgyWjEJdl0 KmAPu+iv5c7YgpQnmeC197RgXHM+4BH+MdAl/xfzlyZphZmxuku6qYcnEh8NEo3PDy+N mrr3nI4Y4bpV2lDv5eqfZpO3w3DKDoys+sPuDuicmF1MIlvbrUeX3pnjv+MC1ZiC+hLN OmozmJMUsRgpAjg9KtARnbp48gAgGrCuy3OOGmxCqW0Kp4okOpWoPgrQqD0hzehceMQp 1ihAmV9uuf6VBZ8UgaEXc5SwNb52I/3C15Wd+IBnP2PiEOzT2eMDuWMSKuRtzGMj/wcm HA7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=DKO2MGlysYL+7+oQy8UdaapVjC7HViDdumwjMefUUFk=; b=dh4kMKbpYU3yZEmkNhXwYNNT/HXg2cnMbHGCzKKYFM+ajSvYjf0QCcNWr04BblhzRI m4iA0igYh78xmNIQmZW2Goe2qgZKO/RJ3P/g/i5YyuE5rp+nG2NE1LqrE/Gj0cdV8WMT nTEbgK1aE4xz5Q7IEhCXsMaMbdH09QYLginZg/ORGT8zPteE5wIQf0EC6vwC7fCokQtD ENHRlKmlgunEkHKHHu3toUShwoe2fU8JL4WtccrE1KtOiyaWVzrmRxgUI4vjK3eq5yXN PqxMphHjfJDyCLgXM7sVzNcwnUozNgi5QzwKmbX5EHffQZr+0yqsNDV6HLKtZ78BMPYj GJZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=sgrtTue3; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a137-20020a621a8f000000b0063c56e46f9esi1645419pfa.294.2023.06.08.18.30.17; Thu, 08 Jun 2023 18:30:31 -0700 (PDT) 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=@google.com header.s=20221208 header.b=sgrtTue3; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236602AbjFIBLk (ORCPT <rfc822;literming00@gmail.com> + 99 others); Thu, 8 Jun 2023 21:11:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbjFIBLj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 8 Jun 2023 21:11:39 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E4330F2 for <linux-kernel@vger.kernel.org>; Thu, 8 Jun 2023 18:11:35 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-75d4b85b3ccso117688185a.2 for <linux-kernel@vger.kernel.org>; Thu, 08 Jun 2023 18:11:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686273094; x=1688865094; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=DKO2MGlysYL+7+oQy8UdaapVjC7HViDdumwjMefUUFk=; b=sgrtTue3rv24LYzFS1k289BQNEsOuAchrD6cHOusSyoPb1K73NZICBU4ccdS+MDThN zBEewtmtI4CNAWNB55+HxFZZrtyp16opIUtn0ashIh7fwhjdgk+9O/mwLbz9OSd84hi/ pBLFfsBUzEB4I2fW6b9r72oAK2m+QnFCxV5NwJBtw2NTKg7epNTeTUcPNH+shND90LBV x2i2pLMwvamhFrNXJIWV1Y51CIqpk9A6NTBVqHI51CoxyJBUf9QXsv4+sDVgvqVWsQDD RoswrTGcvQxNRpRSEw4ateSoH47vdZ8PWjBeC9XQHtwBxYtSov2fw90M/6dX+45eNcbK 0hmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686273094; x=1688865094; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DKO2MGlysYL+7+oQy8UdaapVjC7HViDdumwjMefUUFk=; b=Lws1I3lclU1q+6zInSyGiwQzMf+Gs3PMYWrRrKQPhNDBQnhkie/51y9NANO6Kpt5Nu QxY5/FnkMV27SVDEkCAD0LnaPQakAnFNjLJQTKR+SjdxB5Cc5o6e/fAy7MOyq8vl0MXL /GuiDxek7krBnQ4qg5NfLS4X27REZr3AXxOfBd5ToXbsoJ5UieXkuWO0jrH4De0Unyfc s6pNQxXlZZBgWMkBVpCUdSxL9aL5AE86x47d0A9/N4KMo8XghZ1W784GIVa5ztQ9QlQT KnRPW2BorJV8HHBM3db/+J6yDDAKvYOLErN1DQfpX0UNNEzJtT5+zxUpkFvgHJ+pNxAH PS0A== X-Gm-Message-State: AC+VfDx9AJoFaVwFy1ASMgzqQETBCROO5Wg6hBG+uGjFRvgxRqsG/lI3 HC4rSRfTn+7KZMmtEj5NPlq47g== X-Received: by 2002:a05:620a:a02:b0:75e:ba6e:be65 with SMTP id i2-20020a05620a0a0200b0075eba6ebe65mr6769325qka.55.1686273094097; Thu, 08 Jun 2023 18:11:34 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id y63-20020a817d42000000b0056507de3d82sm273863ywc.104.2023.06.08.18.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:11:33 -0700 (PDT) Date: Thu, 8 Jun 2023 18:11:29 -0700 (PDT) From: Hugh Dickins <hughd@google.com> X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton <akpm@linux-foundation.org> cc: Mike Kravetz <mike.kravetz@oracle.com>, Mike Rapoport <rppt@kernel.org>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Matthew Wilcox <willy@infradead.org>, David Hildenbrand <david@redhat.com>, Suren Baghdasaryan <surenb@google.com>, Qi Zheng <zhengqi.arch@bytedance.com>, Yang Shi <shy828301@gmail.com>, Mel Gorman <mgorman@techsingularity.net>, Peter Xu <peterx@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Will Deacon <will@kernel.org>, Yu Zhao <yuzhao@google.com>, Alistair Popple <apopple@nvidia.com>, Ralph Campbell <rcampbell@nvidia.com>, Ira Weiny <ira.weiny@intel.com>, Steven Price <steven.price@arm.com>, SeongJae Park <sj@kernel.org>, Lorenzo Stoakes <lstoakes@gmail.com>, Huang Ying <ying.huang@intel.com>, Naoya Horiguchi <naoya.horiguchi@nec.com>, Christophe Leroy <christophe.leroy@csgroup.eu>, Zack Rusin <zackr@vmware.com>, Jason Gunthorpe <jgg@ziepe.ca>, Axel Rasmussen <axelrasmussen@google.com>, Anshuman Khandual <anshuman.khandual@arm.com>, Pasha Tatashin <pasha.tatashin@soleen.com>, Miaohe Lin <linmiaohe@huawei.com>, Minchan Kim <minchan@kernel.org>, Christoph Hellwig <hch@infradead.org>, Song Liu <song@kernel.org>, Thomas Hellstrom <thomas.hellstrom@linux.intel.com>, Ryan Roberts <ryan.roberts@arm.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 05/32] mm/filemap: allow pte_offset_map_lock() to fail In-Reply-To: <c1c9a74a-bc5b-15ea-e5d2-8ec34bc921d@google.com> Message-ID: <54607cf4-ddb6-7ef3-043-1d2de1a9a71@google.com> References: <c1c9a74a-bc5b-15ea-e5d2-8ec34bc921d@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768186688324864484?= X-GMAIL-MSGID: =?utf-8?q?1768186688324864484?= |
Series |
mm: allow pte_offset_map[_lock]() to fail
|
|
Commit Message
Hugh Dickins
June 9, 2023, 1:11 a.m. UTC
filemap_map_pages() allow pte_offset_map_lock() to fail; and remove the
pmd_devmap_trans_unstable() check from filemap_map_pmd(), which can safely
return to filemap_map_pages() and let pte_offset_map_lock() discover that.
Signed-off-by: Hugh Dickins <hughd@google.com>
---
mm/filemap.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
Comments
On 8 Jun 2023, at 21:11, Hugh Dickins wrote: > filemap_map_pages() allow pte_offset_map_lock() to fail; and remove the > pmd_devmap_trans_unstable() check from filemap_map_pmd(), which can safely > return to filemap_map_pages() and let pte_offset_map_lock() discover that. > > Signed-off-by: Hugh Dickins <hughd@google.com> > --- > mm/filemap.c | 12 +++++------- > 1 file changed, 5 insertions(+), 7 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 28b42ee848a4..9e129ad43e0d 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3408,13 +3408,6 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio, > if (pmd_none(*vmf->pmd)) > pmd_install(mm, vmf->pmd, &vmf->prealloc_pte); > > - /* See comment in handle_pte_fault() */ > - if (pmd_devmap_trans_unstable(vmf->pmd)) { > - folio_unlock(folio); > - folio_put(folio); > - return true; > - } > - There is a pmd_trans_huge() check at the beginning, should it be removed as well? Since pte_offset_map_lock() is also able to detect it. > return false; > } > > @@ -3501,6 +3494,11 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, > > addr = vma->vm_start + ((start_pgoff - vma->vm_pgoff) << PAGE_SHIFT); > vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); > + if (!vmf->pte) { > + folio_unlock(folio); > + folio_put(folio); > + goto out; > + } > do { > again: > page = folio_file_page(folio, xas.xa_index); > -- > 2.35.3 These two changes affect the ret value. Before, pmd_devmap_trans_unstable() == true made ret = VM_FAULT_NPAGE, but now ret is the default 0 value. So ret should be set to VM_FAULT_NPAGE before goto out in the second hunk? -- Best Regards, Yan, Zi
On Mon, 10 Jul 2023, Zi Yan wrote: > On 8 Jun 2023, at 21:11, Hugh Dickins wrote: > > > filemap_map_pages() allow pte_offset_map_lock() to fail; and remove the > > pmd_devmap_trans_unstable() check from filemap_map_pmd(), which can safely > > return to filemap_map_pages() and let pte_offset_map_lock() discover that. > > > > Signed-off-by: Hugh Dickins <hughd@google.com> > > --- > > mm/filemap.c | 12 +++++------- > > 1 file changed, 5 insertions(+), 7 deletions(-) > > > > diff --git a/mm/filemap.c b/mm/filemap.c > > index 28b42ee848a4..9e129ad43e0d 100644 > > --- a/mm/filemap.c > > +++ b/mm/filemap.c > > @@ -3408,13 +3408,6 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio, > > if (pmd_none(*vmf->pmd)) > > pmd_install(mm, vmf->pmd, &vmf->prealloc_pte); > > > > - /* See comment in handle_pte_fault() */ > > - if (pmd_devmap_trans_unstable(vmf->pmd)) { > > - folio_unlock(folio); > > - folio_put(folio); > > - return true; > > - } > > - > > There is a pmd_trans_huge() check at the beginning, should it be removed > as well? Since pte_offset_map_lock() is also able to detect it. It probably could be removed: but mostly I avoided such cleanups, in the hope that the patches could be more easily reviewed as safe. But I was eager to delete that obscure pmd_devmap_trans_unstable(). The whole strategy of dealing with the pmd_trans_huge()-like cases first, and only finally arriving at the pte_offset_map_lock() when other cases have been excluded, could be reversed in *many* places. It had to be that way before, because pte_offset_map_lock() could only cope with a page table; but now we could reverse them to do the pte_offset_map_lock() first, and only try the other cases when it fails. That would in theory be more efficient; but whether measurably more efficient I doubt. And very easy to introduce errors on the way: my enthusiasm for such cleanups is low! But maybe there's a few places where the rearrangement would be worthwhile. > > > return false; > > } > > > > @@ -3501,6 +3494,11 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, > > > > addr = vma->vm_start + ((start_pgoff - vma->vm_pgoff) << PAGE_SHIFT); > > vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); > > + if (!vmf->pte) { > > + folio_unlock(folio); > > + folio_put(folio); > > + goto out; > > + } > > do { > > again: > > page = folio_file_page(folio, xas.xa_index); > > -- > > 2.35.3 > > These two changes affect the ret value. Before, pmd_devmap_trans_unstable() == true > made ret = VM_FAULT_NPAGE, but now ret is the default 0 value. So ret should be set > to VM_FAULT_NPAGE before goto out in the second hunk? Qi Zheng raised a similar question on the original posting, I answered https://lore.kernel.org/linux-mm/fb9a9d57-dbd7-6a6e-d1cb-8dcd64c829a6@google.com/ It's a rare case to fault here, then find pmd_devmap(*pmd), and it really doesn't matter whether we return VM_FAULT_NOPAGE or 0 for it - maybe I've left it inconsistent between THP and devmap, but it doesn't really matter. I haven't checked Matthew's v5 "new page table range API" posted today, but I expect this all looks different here anyway. Thanks a lot for checking these: they are now in 6.5-rc1, so if you find something that needs fixing, all the more important that we do fix it. Hugh
diff --git a/mm/filemap.c b/mm/filemap.c index 28b42ee848a4..9e129ad43e0d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3408,13 +3408,6 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio, if (pmd_none(*vmf->pmd)) pmd_install(mm, vmf->pmd, &vmf->prealloc_pte); - /* See comment in handle_pte_fault() */ - if (pmd_devmap_trans_unstable(vmf->pmd)) { - folio_unlock(folio); - folio_put(folio); - return true; - } - return false; } @@ -3501,6 +3494,11 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, addr = vma->vm_start + ((start_pgoff - vma->vm_pgoff) << PAGE_SHIFT); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); + if (!vmf->pte) { + folio_unlock(folio); + folio_put(folio); + goto out; + } do { again: page = folio_file_page(folio, xas.xa_index);