From 9c47c0190b0d7af4bc96b63fe568dadea7a5514e Mon Sep 17 00:00:00 2001 From: Alexander Winkowski Date: Fri, 12 Jan 2024 04:59:50 +0000 Subject: [PATCH] Revert "ANDROID: mm: prevent reads of unstable pmd during speculation" This reverts commit f87e6b8d4578ec17a96571b76f1296d93c5972bd. Change-Id: I3a896b78e77f9db5a52bcf261a35c3ec4afefb9c Signed-off-by: Alexander Winkowski --- mm/memory.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 6ad73caf3c1c..5e8c197e214c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3467,10 +3467,6 @@ static vm_fault_t __do_fault(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; vm_fault_t ret; - /* Do not check unstable pmd, if it's changed will retry later */ - if (vmf->flags & FAULT_FLAG_SPECULATIVE) - goto skip_pmd_checks; - /* * Preallocate pte before we take page_lock because this might lead to * deadlocks for memcg reclaim which waits for pages under writeback: @@ -3493,7 +3489,6 @@ static vm_fault_t __do_fault(struct vm_fault *vmf) smp_wmb(); /* See comment in __pte_alloc() */ } -skip_pmd_checks: ret = vma->vm_ops->fault(vmf); if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY | VM_FAULT_DONE_COW))) @@ -3867,8 +3862,7 @@ static vm_fault_t do_fault_around(struct vm_fault *vmf) end_pgoff = min3(end_pgoff, vma_data_pages(vmf->vma) + vmf->vma->vm_pgoff - 1, start_pgoff + nr_pages - 1); - if (!(vmf->flags & FAULT_FLAG_SPECULATIVE) && - pmd_none(*vmf->pmd)) { + if (pmd_none(*vmf->pmd)) { vmf->prealloc_pte = pte_alloc_one(vmf->vma->vm_mm); if (!vmf->prealloc_pte) goto out; @@ -4237,11 +4231,16 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) pte_t entry; vm_fault_t ret = 0; - /* Do not check unstable pmd, if it's changed will retry later */ - if (vmf->flags & FAULT_FLAG_SPECULATIVE) - goto skip_pmd_checks; - if (unlikely(pmd_none(*vmf->pmd))) { + /* + * In the case of the speculative page fault handler we abort + * the speculative path immediately as the pmd is probably + * in the way to be converted in a huge one. We will try + * again holding the mmap_sem (which implies that the collapse + * operation is done). + */ + if (vmf->flags & FAULT_FLAG_SPECULATIVE) + return VM_FAULT_RETRY; /* * Leave __pte_alloc() until later: because vm_ops->fault may * want to allocate huge page, and if we expose page table @@ -4249,7 +4248,8 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) * concurrent faults and from rmap lookups. */ vmf->pte = NULL; - } else { + } else if (!(vmf->flags & FAULT_FLAG_SPECULATIVE)) { + /* See comment in pte_alloc_one_map() */ if (pmd_devmap_trans_unstable(vmf->pmd)) return 0; /* @@ -4279,7 +4279,6 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) } } -skip_pmd_checks: if (!vmf->pte) { if (vma_is_anonymous(vmf->vma)) return do_anonymous_page(vmf);