From: Barry Song Date: Fri, 7 Jun 2024 21:13:58 +0000 (+1200) Subject: mm: set pte writable while pte_soft_dirty() is true in do_swap_page() X-Git-Tag: v6.11-rc1~85^2~301 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=20dfa5b7adc5a1f8b5b7ff9b014d0bd1845c990b;p=thirdparty%2Fkernel%2Flinux.git mm: set pte writable while pte_soft_dirty() is true in do_swap_page() This patch leverages the new pte_needs_soft_dirty_wp() helper to optimize a scenario where softdirty is enabled, but the softdirty flag has already been set in do_swap_page(). In this situation, we can use pte_mkwrite instead of applying write-protection since we don't depend on write faults. Link: https://lkml.kernel.org/r/20240607211358.4660-3-21cnbao@gmail.com Signed-off-by: Barry Song Suggested-by: David Hildenbrand Acked-by: David Hildenbrand Cc: Chris Li Cc: Kairui Song Cc: Matthew Wilcox (Oracle) Cc: Minchan Kim Cc: Ryan Roberts Cc: Suren Baghdasaryan Signed-off-by: Andrew Morton --- diff --git a/mm/memory.c b/mm/memory.c index 44a81d737f1ea..d8a0b7d2e15bc 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4324,7 +4324,7 @@ check_folio: if (!folio_test_ksm(folio) && (exclusive || folio_ref_count(folio) == 1)) { if ((vma->vm_flags & VM_WRITE) && !userfaultfd_pte_wp(vma, pte) && - !vma_soft_dirty_enabled(vma)) { + !pte_needs_soft_dirty_wp(vma, pte)) { pte = pte_mkwrite(pte, vma); if (vmf->flags & FAULT_FLAG_WRITE) { pte = pte_mkdirty(pte);