Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5287287rwd; Mon, 12 Jun 2023 02:52:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7bKTxV20+LGnUivNKcRfOthDF1iwY9RQXF11ilr9ZF/ThaQCNZLuVIDpOVHD+VpjEkLSMw X-Received: by 2002:a92:c04f:0:b0:33b:dcbf:e711 with SMTP id o15-20020a92c04f000000b0033bdcbfe711mr7512673ilf.8.1686563534431; Mon, 12 Jun 2023 02:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686563534; cv=none; d=google.com; s=arc-20160816; b=T/9T3EJHUpMW5nSxrD/RudStWvshvA7UByIUNoxmFP/uvZa19kwoWK8Verg5e4P6d0 WezOAg/Fn8iVEThhYW/WMM4aJOantg96ImnR2fGtW5LnsR4zYj5P/i9rmV2l9L3DSQr5 14SBfeQoq0zmAh6Rij7ISDqwirQZTtOHc/q1iKbz+NVmq7T1VkI8rm7b9LMKUEJMBOxX 2npzE6SGLQ4ISki8SphAqt7NQ8yHmDwNEN7CKv8yuxAnQ2HKk3hCvB2mtfI95jzXWqM3 yCMrnSkpMv8ij3lXomMRyBDPwn5ReWxc1Wh9kgInUyXngCZ4nV9nCjA10IJnbBXZl/A5 VCQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=CqjC+C4AgR1rau0q09punpJRg3u3xND4mYNqjoFiNv8=; b=QOG5UKA4iXifFEbBTyInGoIasWiEdmUN1GaYf0YUOhcmkqCP/R3jDbxMO5iu6LRqug r+bRvOvvL5s36pMIFDHLazdVhNOAKQUXgyHf5n8PLYiTLfqYqPVmKVYilBvrO57ysJNQ AZYDWOODD8v1S2/NMspz+J+oWB8xqmXOFIa4qhZTtENxKI+HAtfkOdXzBN02Qsy1XwJO ZGBSOuP2Jy2EfFhCN1YQ4cOr6qTZepJpAAOPQhwgRvCVtGaKaqyHNpoMtVCXqLLVhBJ4 gqhoWHj3Cl138oml9BfvxcEgauqGpfejWiLWBg1dcXxXnkUaSUiZnb6uNhIjjzmsYwAz 9qOQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o27-20020a63731b000000b00542bcb3d593si6691848pgc.636.2023.06.12.02.52.02; Mon, 12 Jun 2023 02:52:14 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229964AbjFLJS2 (ORCPT + 99 others); Mon, 12 Jun 2023 05:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbjFLJRo (ORCPT ); Mon, 12 Jun 2023 05:17:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CC81420E for ; Mon, 12 Jun 2023 02:10:57 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E60EE1FB; Mon, 12 Jun 2023 02:11:41 -0700 (PDT) Received: from [192.168.68.121] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EDF8E3F663; Mon, 12 Jun 2023 02:10:51 -0700 (PDT) Message-ID: <65a42ee0-170c-ec7c-519b-e66cdd901a52@arm.com> Date: Mon, 12 Jun 2023 10:10:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH v2 28/32] mm/memory: allow pte_offset_map[_lock]() to fail To: Hugh Dickins , 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 , 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 , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230609130632.ec6ffe72fc5f7952af4a3e54@linux-foundation.org> <11a9744a-e7f-33d0-474-c2f2eb7e079@google.com> From: Ryan Roberts In-Reply-To: <11a9744a-e7f-33d0-474-c2f2eb7e079@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 09/06/2023 21:11, Hugh Dickins wrote: > 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. FWIW, I agree. Thanks, Ryan > > Hugh