From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC388C7EE45 for ; Fri, 9 Jun 2023 20:06:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbjFIUGk (ORCPT ); Fri, 9 Jun 2023 16:06:40 -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 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; /*