From patchwork Mon May 22 05:01:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 97028 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1217210vqo; Sun, 21 May 2023 22:21:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DsKDrKsvkn+KuSw639kjibaIecYuCsfcP1fAYt+FWaD/2y4LWQJKfSJAwWHBxW7u4l815 X-Received: by 2002:a05:6a20:158a:b0:100:c3fe:a653 with SMTP id h10-20020a056a20158a00b00100c3fea653mr11304498pzj.29.1684732884727; Sun, 21 May 2023 22:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684732884; cv=none; d=google.com; s=arc-20160816; b=OLbA2DLlNJ/9PENyyLfNxN/VNINEAM+ScxyBkTH4b8NDL1UiXkHi3Em+CJjz3gxO4K 7KkIjcEb5QyU2nNUfmabd4CDItF6zyqR+6WgsxrzoxU4yVqOYC10EnA9+UZ5UrTuwKfH hEAbRuv4NCfxNjyfrPk7U2mfea4kLmpLZUBn7GZTHE1AhlXhZJYD6DFXVHTmwR7wGx7A A8FLPmGblNwk3jv0ZCfNHUNaiHrmBjwIgH2q9nnjxdpL9a8BKS2g9J7SSr8cUhPoNIqk KLZ5wUT/CcKFL98WgueY+yxEl6auQKafkzBE4jLjCxpuBjmOZ3xAgvyUP8A1cQZzzlmo 1doQ== 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=s/wneZk+WXTrjMA3fZuua9PXiv3fUuHnEiWoD80tgK8=; b=OyCEHsSxBOMV6gn2N7nsrvOgC1PIqvX0kKkfTzqXmiuj0wiGndWpW1ug++cXTFfc9m eysgYggy0q9OMa3TRsIgtp72NIWQkxjwSdxtV1FLDLX3BO+hRld+ASb7nkbc+wwOyjJL XCw1368gCsztDn9dZYU/KdGF8d/ReaFMjodK/0RbWdguXS/Z9vaDEdfj0EuoWbUBk3Pg dXJ195mFIPS69fHztYUModL9JPJfH7V00Z45UYDXYUWF7o0eASAGuo70g/USW/GF7Or9 Qoe9sO/5qOHrTl83kNfoWZWkijQEZJZ9xY47vLz5/u2/nluIo4ky/Px46vTDd574Yne8 qRog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Q+WLY7Ro; 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 f26-20020a63381a000000b00530743695d6si4090177pga.725.2023.05.21.22.21.11; Sun, 21 May 2023 22:21:24 -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=Q+WLY7Ro; 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 S231669AbjEVFCE (ORCPT + 99 others); Mon, 22 May 2023 01:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbjEVFCB (ORCPT ); Mon, 22 May 2023 01:02:01 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 906B592 for ; Sun, 21 May 2023 22:02:00 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-55db055b412so45888387b3.0 for ; Sun, 21 May 2023 22:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684731720; x=1687323720; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=s/wneZk+WXTrjMA3fZuua9PXiv3fUuHnEiWoD80tgK8=; b=Q+WLY7Ro5SD5yNUAGTclzTje+VDS5OJwsYctg43k8TXzrg8fckZAOFDLbOpbv+Cz4d vusZX67zn6q4S5qUq6SfyoErvRul9hzMJrB3MRNnhQ6C5pPl/f+0Ug23z4gIrshnXudw uyL2XPYtPcLeaaYEa9djIcbbIiLW16k5noNko0Ixwnf5lma2IwkwvbUb6+ol9PyhD+iA SFpbS9+EhhrldJnU+af1fSiFWnx4LWMy4hftbnHOIsp4fFcbSzoqMd7Z+gmLZKCZGF9K xNYQslTPradcxr1kOt1BAZkUVCQ1AUWpnoyxrlCIdMtfrWBTqYrF1ShOS0ygR98FffYZ BJig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684731720; x=1687323720; 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=s/wneZk+WXTrjMA3fZuua9PXiv3fUuHnEiWoD80tgK8=; b=UVhqOhp1ZjTtMF/MFt1rsG683bC2Mp/5pJngLLUlH8gPKenvlHKDWBPnolBc/NA/SD nnFLamK4e45IxjRJ/I9myHoJFtQiOHUOUrtyS14gnSyjVM0NTmOLTHoJSDQusivkcYKc HnRdOodIbuud/A3VlxK90Pn+3opdcjFbGTEJbTby680QvvHQWoYZqX6ZWBzxS/oMlkkq HcaIPTCHv8z9q8rttuNTAi8fQIjcqf8s75bQrZjWhdNLiP/KlhbLH06MqoZQRdAbOq/m B3nhtuE/he6v0kLlhZrD486NU10C+ls5nqkXFteLe13UcJUm2BWu0iTywjGuWjNXjQOr 6xcQ== X-Gm-Message-State: AC+VfDyDn6YFTb/tEBTOuP6KhM6fcwSKsl5xnaGhyeZDvz0ibPLzAnwU 1k3SyfGRWCOZ0sCwS7KWlQQyPw== X-Received: by 2002:a0d:cc45:0:b0:55a:3502:d2ca with SMTP id o66-20020a0dcc45000000b0055a3502d2camr10051671ywd.13.1684731719564; Sun, 21 May 2023 22:01:59 -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 x67-20020a81a046000000b0054fcbf35b94sm1819620ywg.87.2023.05.21.22.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 22:01:59 -0700 (PDT) Date: Sun, 21 May 2023 22:01:56 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/31] mm/pagewalk: walk_pte_range() allow for pte_offset_map() In-Reply-To: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> Message-ID: References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766570469087795655?= X-GMAIL-MSGID: =?utf-8?q?1766570469087795655?= walk_pte_range() has a no_vma option to serve walk_page_range_novma(). I don't know of any problem, but it looks safer to check for init_mm, and use pte_offset_kernel() rather than pte_offset_map() in that case: pte_offset_map()'s pmdval validation is intended for userspace. Allow for its pte_offset_map() or pte_offset_map_lock() to fail, and retry with ACTION_AGAIN if so. Add a second check for ACTION_AGAIN in walk_pmd_range(), to catch it after return from walk_pte_range(). Remove the pmd_trans_unstable() check after split_huge_pmd() in walk_pmd_range(): walk_pte_range() now handles those cases safely (and they must fail powerpc's is_hugepd() check). Signed-off-by: Hugh Dickins --- mm/pagewalk.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index cb23f8a15c13..64437105fe0d 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -46,15 +46,27 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, spinlock_t *ptl; if (walk->no_vma) { - pte = pte_offset_map(pmd, addr); - err = walk_pte_range_inner(pte, addr, end, walk); - pte_unmap(pte); + /* + * pte_offset_map() might apply user-specific validation. + */ + if (walk->mm == &init_mm) + pte = pte_offset_kernel(pmd, addr); + else + pte = pte_offset_map(pmd, addr); + if (pte) { + err = walk_pte_range_inner(pte, addr, end, walk); + if (walk->mm != &init_mm) + pte_unmap(pte); + } } else { pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); - err = walk_pte_range_inner(pte, addr, end, walk); - pte_unmap_unlock(pte, ptl); + if (pte) { + err = walk_pte_range_inner(pte, addr, end, walk); + pte_unmap_unlock(pte, ptl); + } } - + if (!pte) + walk->action = ACTION_AGAIN; return err; } @@ -141,11 +153,8 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, !(ops->pte_entry)) continue; - if (walk->vma) { + if (walk->vma) split_huge_pmd(walk->vma, pmd, addr); - if (pmd_trans_unstable(pmd)) - goto again; - } if (is_hugepd(__hugepd(pmd_val(*pmd)))) err = walk_hugepd_range((hugepd_t *)pmd, addr, next, walk, PMD_SHIFT); @@ -153,6 +162,10 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, err = walk_pte_range(pmd, addr, next, walk); if (err) break; + + if (walk->action == ACTION_AGAIN) + goto again; + } while (pmd++, addr = next, addr != end); return err;