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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B4667C46CD2 for ; Tue, 30 Jan 2024 08:47:46 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TPJhd3XBzz3dTR for ; Tue, 30 Jan 2024 19:47:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=arm.com (client-ip=217.140.110.172; helo=foss.arm.com; envelope-from=ryan.roberts@arm.com; receiver=lists.ozlabs.org) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lists.ozlabs.org (Postfix) with ESMTP id 4TPJg06vtKz3cbW for ; Tue, 30 Jan 2024 19:46:18 +1100 (AEDT) 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 600E3DA7; Tue, 30 Jan 2024 00:46:31 -0800 (PST) Received: from [10.57.79.54] (unknown [10.57.79.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8B93E3F738; Tue, 30 Jan 2024 00:45:43 -0800 (PST) Message-ID: Date: Tue, 30 Jan 2024 08:45:41 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 3/9] mm/memory: further separate anon and pagecache folio handling in zap_present_pte() Content-Language: en-GB To: David Hildenbrand , linux-kernel@vger.kernel.org References: <20240129143221.263763-1-david@redhat.com> <20240129143221.263763-4-david@redhat.com> <40cfb242-ceb0-44c6-afe7-c1744825dc62@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, Alexander Gordeev , Christian Borntraeger , Arnd Bergmann , Vasily Gorbik , Peter Zijlstra , "Aneesh Kumar K.V" , linuxppc-dev@lists.ozlabs.org, Matthew Wilcox , linux-mm@kvack.org, Nick Piggin , Catalin Marinas , "Naveen N. Rao" , Andrew Morton , Will Deacon , Heiko Carstens , Sven Schnelle Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 30/01/2024 08:37, David Hildenbrand wrote: > On 30.01.24 09:31, Ryan Roberts wrote: >> On 29/01/2024 14:32, David Hildenbrand wrote: >>> We don't need up-to-date accessed-dirty information for anon folios and can >>> simply work with the ptent we already have. Also, we know the RSS counter >>> we want to update. >>> >>> We can safely move arch_check_zapped_pte() + tlb_remove_tlb_entry() + >>> zap_install_uffd_wp_if_needed() after updating the folio and RSS. >>> >>> While at it, only call zap_install_uffd_wp_if_needed() if there is even >>> any chance that pte_install_uffd_wp_if_needed() would do *something*. >>> That is, just don't bother if uffd-wp does not apply. >>> >>> Signed-off-by: David Hildenbrand >>> --- >>>   mm/memory.c | 16 +++++++++++----- >>>   1 file changed, 11 insertions(+), 5 deletions(-) >>> >>> diff --git a/mm/memory.c b/mm/memory.c >>> index 69502cdc0a7d..20bc13ab8db2 100644 >>> --- a/mm/memory.c >>> +++ b/mm/memory.c >>> @@ -1552,12 +1552,9 @@ static inline void zap_present_pte(struct mmu_gather >>> *tlb, >>>       folio = page_folio(page); >>>       if (unlikely(!should_zap_folio(details, folio))) >>>           return; >>> -    ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); >>> -    arch_check_zapped_pte(vma, ptent); >>> -    tlb_remove_tlb_entry(tlb, pte, addr); >>> -    zap_install_uffd_wp_if_needed(vma, addr, pte, details, ptent); >>>         if (!folio_test_anon(folio)) { >>> +        ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); >>>           if (pte_dirty(ptent)) { >>>               folio_mark_dirty(folio); >>>               if (tlb_delay_rmap(tlb)) { >>> @@ -1567,8 +1564,17 @@ static inline void zap_present_pte(struct mmu_gather >>> *tlb, >>>           } >>>           if (pte_young(ptent) && likely(vma_has_recency(vma))) >>>               folio_mark_accessed(folio); >>> +        rss[mm_counter(folio)]--; >>> +    } else { >>> +        /* We don't need up-to-date accessed/dirty bits. */ >>> +        ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); >>> +        rss[MM_ANONPAGES]--; >>>       } >>> -    rss[mm_counter(folio)]--; >>> +    arch_check_zapped_pte(vma, ptent); >> >> Isn't the x86 (only) implementation of this relying on the dirty bit? So doesn't >> that imply you still need get_and_clear for anon? (And in hindsight I think that >> logic would apply to the previous patch too?) > > x86 uses the encoding !writable && dirty to indicate special shadow stacks. That > is, the hw dirty bit is set by software (to create that combination), not by > hardware. > > So you don't have to sync against any hw changes of the hw dirty bit. What you > had in the original PTE you read is sufficient. > Right, got it. In that case: Reviewed-by: Ryan Roberts