Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2614111rwd; Fri, 9 Jun 2023 14:09:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4cOGF4EyhMtfw6iBi546ZJoacEHx4ztCjoIKwKKIs+Nul5K3AtrBUdpQfiKnfYo1XCI7Jb X-Received: by 2002:a05:6a20:382:b0:10f:130c:53e4 with SMTP id 2-20020a056a20038200b0010f130c53e4mr1546581pzt.41.1686344970893; Fri, 09 Jun 2023 14:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686344970; cv=none; d=google.com; s=arc-20160816; b=ZnoGze+DAEvSxH7hx/+S5db1eMvaCWoBNw2Ox3mEsq2sAhqpGnpbnHX9UpejHRHeHH QcgOSid0l0GvUOJoaKdj596PTRxRaG0Jx2psb09XuAVgz7Rj8Ek6Mpnz9nwElCVpzcAf rg2td31AssnUEwJEWvNp8YFcu8p1Vj0AeS1puC+9DwmmGB777CHHtRy/Bwt/gjycusbj Ip4Z263C5izZ0yP9otrUZtKwjP7rLDIFnxUp603iTmSuRHHomtK8DNTiznMXJZTrlYxQ 9loWSxDttWdCtC+lrlJjcctiYqxnAlxK9ds/ih0cMGMngONazyZpEi/viTaTC9BIZfQT K8lQ== 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=BNhoN+f5/2l7cZy5Z84aZKirbXfCn9RTJhC9+NCxT+I=; b=NoiEWwtUymxK4PTjYju2gSO2Q7M6mfETohhLkJfQYJqGoH/z+A+BDaScY7Jh0Uh0ZT RIrusfPsy6ycMRjfiLIVJDbcn3kSPZTyhE3Y5u+YH1EkyXjRwAth5XZMgsoChO614UM6 By9aLwfIAnxvR/tScs6gOsa8Z4qRlzLG011hvqqARd8PtP/ul5tDr5yfz7HnmRKCWyRs 3x31i2Bf+rHVJYAz8ECxxWagfX87C7Q0/J1GWVt/Co07s7g72zKDBjxTnb4lCu2ajYeg PSYOMIm6mRZICqMaoJH+FSapGXXLmO35y2tJqCFc+OWC05n/RGNYLOcic4BJ+7RnkYUE o0WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="d/6rBPd7"; 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 g30-20020aa79dde000000b0066106e1980esi3038937pfq.63.2023.06.09.14.09.16; Fri, 09 Jun 2023 14:09:30 -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="d/6rBPd7"; 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 S230519AbjFIULh (ORCPT + 99 others); Fri, 9 Jun 2023 16:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbjFIULb (ORCPT ); Fri, 9 Jun 2023 16:11:31 -0400 Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 704A31A1 for ; Fri, 9 Jun 2023 13:11:30 -0700 (PDT) Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-55b38fc0c70so1458945eaf.0 for ; Fri, 09 Jun 2023 13:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686341489; x=1688933489; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=BNhoN+f5/2l7cZy5Z84aZKirbXfCn9RTJhC9+NCxT+I=; b=d/6rBPd74W0HkXu+EUDXKlSN8o5i+l5/F1a2slQZafKk6WIPKC+wuMB7dADlBrLtyM poQQG5ScaC8fvmLhUCZ/gWgJ2zRtH2r9BnAWYzXdM4rU7YvJQBRC7IU4TT9rx69EyJvn bhsACpIFEGAzoPPyJ+wOA4XH9SOLnaEUZKbWCj3APhoigWRN+ZJyFwpi133I57LqMr49 EzVmuFEGPpqnoh0Yf5uVi5LN2K4tVOwsnTjiNeOpbpg21u6GsLbyz3+q+XIiA6kykJvi 3q3m76KPzFg3UA+XER4MD7yzah7yrXozpiQErF+7+qymD5C7n9vsHD+qXqS0M4Q1ntOo dKzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686341489; x=1688933489; 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=BNhoN+f5/2l7cZy5Z84aZKirbXfCn9RTJhC9+NCxT+I=; b=GL5uTdRt9oFNIawYLAqe4VsxUWLycpR8M04TZzrxpXG9KpWCTk9iOb1VvL8YJ+2Srm a4hv8Ig24ZQlSJpxlbdGiJMtheXrt83VTd3kW/ZIjxYNDOsCVNny1l9hWJNf5AbM5eZf k8GK9rYP2FLRPjbXGdoAir+Rvy+5fny0b8+62q5RZJnTf2raa+vwaV8N9FUzoWNMIG9x PQmpWxpFjyZTin2OFOyxHALjna32grKVtcDEATRYFJbNi5GTfiiVCx0XU+cc9DJebKrd hxlYZ8/YWjYZOZuwbNIuhvbenf4uPln5vwTHRwBUP0PHAYqpMfS5SdUoePw3wyt+OQ4y crfw== X-Gm-Message-State: AC+VfDzes0c2wMju5ov9a+ZYygVMy34bjs5HPPvWCC6sjP0KhjWcMQtg qIsSC+C5tvfcTNvcjz2V2vEKDw== X-Received: by 2002:a05:6359:1e:b0:129:cd33:9d5f with SMTP id en30-20020a056359001e00b00129cd339d5fmr2065211rwb.28.1686341489426; Fri, 09 Jun 2023 13:11:29 -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 a74-20020a0dd84d000000b005463e45458bsm808484ywe.123.2023.06.09.13.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 13:11:29 -0700 (PDT) Date: Fri, 9 Jun 2023 13:11:18 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Hugh Dickins , 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 , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 28/32] mm/memory: allow pte_offset_map[_lock]() to fail In-Reply-To: <20230609130632.ec6ffe72fc5f7952af4a3e54@linux-foundation.org> Message-ID: <11a9744a-e7f-33d0-474-c2f2eb7e079@google.com> References: <20230609130632.ec6ffe72fc5f7952af4a3e54@linux-foundation.org> 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 Fri, 9 Jun 2023, Andrew Morton wrote: > On Thu, 8 Jun 2023 18:43:38 -0700 (PDT) Hugh Dickins wrote: > > > copy_pte_range(): use pte_offset_map_nolock(), and allow for it to fail; > > but with a comment on some further assumptions that are being made there. > > > > zap_pte_range() and zap_pmd_range(): adjust their interaction so that > > a pte_offset_map_lock() failure in zap_pte_range() leads to a retry in > > zap_pmd_range(); remove call to pmd_none_or_trans_huge_or_clear_bad(). > > > > Allow pte_offset_map_lock() to fail in many functions. Update comment > > on calling pte_alloc() in do_anonymous_page(). Remove redundant calls > > to pmd_trans_unstable(), pmd_devmap_trans_unstable(), pmd_none() and > > pmd_bad(); but leave pmd_none_or_clear_bad() calls in free_pmd_range() > > and copy_pmd_range(), those do simplify the next level down. > > > > ... > > > > @@ -3728,11 +3737,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > vmf->page = pfn_swap_entry_to_page(entry); > > vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, > > vmf->address, &vmf->ptl); > > - if (unlikely(!pte_same(*vmf->pte, vmf->orig_pte))) { > > - spin_unlock(vmf->ptl); > > - goto out; > > - } > > - > > + if (unlikely(!vmf->pte || > > + !pte_same(*vmf->pte, vmf->orig_pte))) > > + goto unlock; > > /* > > * Get a page reference while we know the page can't be > > * freed. > > This hunk falls afoul of > https://lkml.kernel.org/r/20230602092949.545577-5-ryan.roberts@arm.com. > > I did this: > > @@ -3729,7 +3738,8 @@ vm_fault_t do_swap_page(struct vm_fault > vmf->page = pfn_swap_entry_to_page(entry); > vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, > vmf->address, &vmf->ptl); > - if (unlikely(!pte_same(*vmf->pte, vmf->orig_pte))) > + if (unlikely(!vmf->pte || > + !pte_same(*vmf->pte, vmf->orig_pte))) > goto unlock; > > /* Yes, that's exactly right: thanks, Andrew. Hugh