Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5168140rwd; Tue, 23 May 2023 19:56:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7DSgB6RO8Ym3mrVgoPlvpH2lJZoSic3e6qvwseY1Oo0WSFZfs9l3u5y4+vF7UEtNkCN104 X-Received: by 2002:a17:902:6bc2:b0:1ae:6882:5bc4 with SMTP id m2-20020a1709026bc200b001ae68825bc4mr13886486plt.64.1684896963279; Tue, 23 May 2023 19:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684896963; cv=none; d=google.com; s=arc-20160816; b=LLwijFGN3HuhiQepyTlaQIcKwhyhG8kNMeQVlGD3w287hhUcSGevUiL4EtdpRseMy2 ROwSvlZLaOuRuF4NzvluF3jmbp6KVgRFsxHih7/sIevtlFkBjp52B+0Kvmab7O9gHWUk Fij7jvGrDsXtWEAGOpi6gEBBUNzZ4MU9NU2aNLiUWMvhK850j1KoQXklyuD0yFyNzxI9 ER8zOi4RsKSDriGYA5G9xiqj+mHh79PmSaVyr/N1LAOzG7hQbX0O0z5Sk9N8RjnibpRo w7oRc2TMPubQONzkTn55r/xP4m6zzsP3s/HHQ5pCv0QUbFVFhO0Ol66yJ5MUKnbizrke fttg== 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=3If+wNKDpztgamuvwXQbsQHi3AsIclBz5NcCQV3CYi4=; b=k+b2PkeUGD6EPRtFIxea31ijMWmYH2hY3uprldvzlgDwxhT3zdGDanaG4hq1g1Rk9F 7hYdKxwRVuEG+sT9JNmQjvFvtqbaSCGfDRjbJOsAR37taY8+Lh36uXG2ggRy6mzW9li2 nyeePYCzjEI2QWl58ymeWsMWFYnGceyGndPnV4ohVP4SeI5RDODJShNHRvo5vjfatE8b dHwXYhlKmBVzhwTcWmyQqjQO0oiHmFZMkm/798gM6fJTz/3rGbp77rkn5R5q9gtxKGhH 5TPkNHoxLXNekAROz8Rjpno/Cc/aDOIftRCLgj/q3/R/glLLE6nAXfIxTqOPzrFFZZIR eFUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hrm8eV4F; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 1-20020a170902ee4100b001ac762451b2si2881106plo.354.2023.05.23.19.55.48; Tue, 23 May 2023 19:56:03 -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=hrm8eV4F; 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 S239124AbjEXCor (ORCPT + 99 others); Tue, 23 May 2023 22:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjEXCoq (ORCPT ); Tue, 23 May 2023 22:44:46 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A7E189 for ; Tue, 23 May 2023 19:44:45 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-ba81f71dfefso707740276.0 for ; Tue, 23 May 2023 19:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684896284; x=1687488284; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=3If+wNKDpztgamuvwXQbsQHi3AsIclBz5NcCQV3CYi4=; b=hrm8eV4Fq6VAAV1GxKh0FyrU8o4JWflrPTKLcjcBt6GHqGBUZgjEwPtBTGs49KMeO7 E+1IyOO5I/1GKz9vC5+8+/f6AbZqhYPgs9grMTqpvaYG3v2VhmjovMDDpy/iU5jey7V0 6oqVRDxrV0HyWz3HBkEmkWT0oxlkZBfQw6wiT67vFipyzTrQQplQiiQhCCEVWvbnA0WT 76rmKqPHPE7ZcxwcwitoT7UUmP8wyfixdR3hH2X0VofCs+JWLmDuCl39lEWw2LrImLFh Dfg/3CV6de1VFP0QOdKlPEDMpdJm/yt2YKlA6wqgdE9udjCSyapNT4/WHex1qDf4EiQi brpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684896284; x=1687488284; 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=3If+wNKDpztgamuvwXQbsQHi3AsIclBz5NcCQV3CYi4=; b=EubRPJmf6TCQCdJUyI14B+KqsxszJsBpCpTqIf3gl4AUHlg5pctWH97/FGuxKwk73k jtXn6HWiUTNjlH1Ui0HnwCv+tFk4+hp8gUZCiL5scZMSzfMyTw0tcZwz7tcsMB25+JHA TOEo+ifzBde5CGH8aNcwTGMZSX72ircPrBWTV0vrP1DlIPtBIG74klmUtg2w726Qc4at s/ekF5UpfIuWSFHv5UVPG7X3Bny663wlOOAbQ04tHZAKv26AaMzZbik3Omm1ey0VzUVR P/kHAeYDtzztABFNp/TjEx8cbEkCDHwulKKjfIh0HS6uW387z8lNEXotjKtPb5QnCrSr MTqQ== X-Gm-Message-State: AC+VfDxPhsP50wqRQ8PbHVqh4CVi0hl6NOrz4mz9mp/bzH1DgYzan2zU 6b382sIQjW0nvVWVDbUaf0wz0A== X-Received: by 2002:a81:d548:0:b0:561:949d:f9a7 with SMTP id l8-20020a81d548000000b00561949df9a7mr20238915ywj.20.1684896284333; Tue, 23 May 2023 19:44:44 -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 i16-20020a0ddf10000000b0054f80928ea4sm3324271ywe.140.2023.05.23.19.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 19:44:43 -0700 (PDT) Date: Tue, 23 May 2023 19:44:40 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Qi Zheng cc: Hugh Dickins , Andrew Morton , 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: Re: [PATCH 08/31] mm/page_vma_mapped: pte_offset_map_nolock() not pte_lockptr() In-Reply-To: <10e58e7e-a52e-751d-f693-cd4e05ac10ca@linux.dev> Message-ID: <83ec98e0-d17-6d59-e276-557c13ac58ea@google.com> References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> <8fa3fb6e-2e39-cbea-c529-ee9e64c7d2d0@google.com> <10e58e7e-a52e-751d-f693-cd4e05ac10ca@linux.dev> 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: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 22 May 2023, Qi Zheng wrote: > On 2023/5/22 12:58, Hugh Dickins wrote: > > map_pte() use pte_offset_map_nolock(), to make sure of the ptl belonging > > to pte, even if pmd entry is then changed racily: page_vma_mapped_walk() > > use that instead of getting pte_lockptr() later, or restart if map_pte() > > found no page table. > > > > Signed-off-by: Hugh Dickins > > --- > > mm/page_vma_mapped.c | 28 ++++++++++++++++++++++------ > > 1 file changed, 22 insertions(+), 6 deletions(-) > > > > diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c > > index 947dc7491815..2af734274073 100644 > > --- a/mm/page_vma_mapped.c > > +++ b/mm/page_vma_mapped.c > > @@ -156,6 +168,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk > > *pvmw) > > struct vm_area_struct *vma = pvmw->vma; > > struct mm_struct *mm = vma->vm_mm; > > unsigned long end; > > + spinlock_t *ptl; > > pgd_t *pgd; > > p4d_t *p4d; > > pud_t *pud; > > @@ -257,8 +270,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk > > *pvmw) > > step_forward(pvmw, PMD_SIZE); > > continue; > > } > > - if (!map_pte(pvmw)) > > + if (!map_pte(pvmw, &ptl)) { > > + if (!pvmw->pte) > > + goto restart; > > Could pvmw->pmd be changed? Otherwise, how about just jumping to the > retry label below? > > @@ -205,6 +205,8 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk > *pvmw) > } > > pvmw->pmd = pmd_offset(pud, pvmw->address); > + > +retry: > /* > * Make sure the pmd value isn't cached in a register by the > * compiler and used as a stale value after we've observed a You're right, that could be done, and that's where I'd have inserted the label if there were none already. I just thought the fewer goto labels the better, so reused the restart already there. If you feel strongly that it's actively misleading, I can certainly make that change; but it's too rare an occurrence to be worth optimizing for. Hugh