Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2568834rwd; Fri, 9 Jun 2023 13:19:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5kyJrGP239KAPpZO7kEn+VQW0JtNbvyQ0zvM7d8jRGLPa+pVexQgeFucjRbsCd/T3UGYZG X-Received: by 2002:a05:6359:59d:b0:129:d242:f782 with SMTP id ee29-20020a056359059d00b00129d242f782mr2434365rwb.0.1686341985466; Fri, 09 Jun 2023 13:19:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686341985; cv=none; d=google.com; s=arc-20160816; b=U/sRova8ACM3kTO9nSUoJFYjYuIAYKfeD4ZAYzXfmGD5DyU/FBBZknAfKuelwvP9n/ ZF7kXJnzo/6UIJF3ideG6fQc6TN3F2sM1itzqSY+5SF3VC5ZJMygV3v+BJCLsbd7AqEE OA/x4RrB6WPHJPk7C1IEQlMae/59dW0mcqm4ld7r+Jmu15wmtp/XQ5DtGds67yi5gatN FIYRIaNkAxzdJMbhcqwj5cne8peoS4fW9LcDg10iBwboQ6o+bMP+u1NLdypfYHTi3qf0 tM7iv/+s1XAhFJ7vQwUIR/oN6yKJzAxeWpM6lhekAG4KOSrLb3uYubzxmcEZV4bqvKM4 D3yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=YGPC6XPL5YGiXdg8QM/flJtXTtWJWxe/OKgFadfaR5Q=; b=O9enolAllfx68v+7gePNBDJHRK6WiZOJS+VUhCJwLl9LpQDCZEyHu3M3HpNmJf1m4J ykEfsNT6fcKOm5wjzLnVBN0s84R8q8qjORWTLOoST5HtUitBPu9UQFZ1lgDpqXZ79p9O Ke3hxzyCZ5C/vhMPb/oOxOEQhRLeROm3twD/GdBT/ehFWG9eGobMrycIXZHRmX+mgpKK XIUXDqOJ0KDYmuL6ZakGVUcZQD9qY6jkP4lKqxphCVgmzoDfzjIkPxQIJ5e/i7qHA3Jl o7+HlkQCRXUWYPOsVquWcqm2u/Sc37GXxyiP49S/OtPzit/0YZfMGrq8p2QHFtrQ85tj vRrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=YqaO5bl3; 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 r21-20020a632b15000000b0051b32aa267asi3034657pgr.671.2023.06.09.13.19.31; Fri, 09 Jun 2023 13:19:45 -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=@linux-foundation.org header.s=korg header.b=YqaO5bl3; 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 S230023AbjFIUGj (ORCPT + 99 others); Fri, 9 Jun 2023 16:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjFIUGi (ORCPT ); Fri, 9 Jun 2023 16:06:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 849C33A82 for ; Fri, 9 Jun 2023 13:06:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 19298659DE for ; Fri, 9 Jun 2023 20:06:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EB81C433EF; Fri, 9 Jun 2023 20:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1686341194; bh=I5eLjVvS0j4LRy8nwugVLv1qLrwPGv6yABwGuRiB+w0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=YqaO5bl3XEMwtnhnotlvPEAgrU3xEt9NSz3dEe6LUBbD5J9rBClfs1UXqaQl2jASA zYO51MdN9A0kxbg86I8m8gM5BK/nbJMwoet5nWMDR+21lql3f94v2/WBHXsb8Mt6qt PnnuYVV0groHs6ywW6cwCI8pR/xRA4fJ9J0LVYuw= Date: Fri, 9 Jun 2023 13:06:32 -0700 From: Andrew Morton To: Hugh Dickins 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 , 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 Message-Id: <20230609130632.ec6ffe72fc5f7952af4a3e54@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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; /*