VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   57 Tags
author: Qi Zheng <zhengqi.arch@bytedance.com> 2021-07-23 15:50:41 -0700 committer: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2021-07-28 14:37:40 +0200 commit: 4861f6d3b90f81b4c5e3817c9092885962b369bc parent: 5d4b4d2e3c8d5bc3bf62f94a594cd02ca7e7b65c
Commit Summary:
mm: fix the deadlock in finish_fault()
Diffstat:
1 file changed, 10 insertions, 1 deletion
diff --git a/mm/memory.c b/mm/memory.c
index 3fdba3ec69c8..f2293c0df33f 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3891,8 +3891,17 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
 				return ret;
 		}
 
-		if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd)))
+		if (vmf->prealloc_pte) {
+			vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd);
+			if (likely(pmd_none(*vmf->pmd))) {
+				mm_inc_nr_ptes(vma->vm_mm);
+				pmd_populate(vma->vm_mm, vmf->pmd, vmf->prealloc_pte);
+				vmf->prealloc_pte = NULL;
+			}
+			spin_unlock(vmf->ptl);
+		} else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) {
 			return VM_FAULT_OOM;
+		}
 	}
 
 	/* See comment in handle_pte_fault() */