@@ -2399,7 +2399,10 @@ EXPORT_SYMBOL(unmap_mapping_range);
23992399/*
24002400 * We enter with non-exclusive mmap_sem (to exclude vma changes,
24012401 * but allow concurrent faults), and pte mapped but not yet locked.
2402- * We return with mmap_sem still held, but pte unmapped and unlocked.
2402+ * We return with pte unmapped and unlocked.
2403+ *
2404+ * We return with the mmap_sem locked or unlocked in the same cases
2405+ * as does filemap_fault().
24032406 */
24042407static int do_swap_page (struct mm_struct * mm , struct vm_area_struct * vma ,
24052408 unsigned long address , pte_t * page_table , pmd_t * pmd ,
@@ -2688,6 +2691,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
26882691 return VM_FAULT_OOM ;
26892692}
26902693
2694+ /*
2695+ * The mmap_sem must have been held on entry, and may have been
2696+ * released depending on flags and vma->vm_ops->fault() return value.
2697+ * See filemap_fault() and __lock_page_retry().
2698+ */
26912699static int __do_fault (struct vm_area_struct * vma , unsigned long address ,
26922700 pgoff_t pgoff , unsigned int flags , struct page * * page )
26932701{
@@ -3016,6 +3024,12 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
30163024 return ret ;
30173025}
30183026
3027+ /*
3028+ * We enter with non-exclusive mmap_sem (to exclude vma changes,
3029+ * but allow concurrent faults).
3030+ * The mmap_sem may have been released depending on flags and our
3031+ * return value. See filemap_fault() and __lock_page_or_retry().
3032+ */
30193033static int do_linear_fault (struct mm_struct * mm , struct vm_area_struct * vma ,
30203034 unsigned long address , pte_t * page_table , pmd_t * pmd ,
30213035 unsigned int flags , pte_t orig_pte )
@@ -3040,7 +3054,9 @@ static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
30403054 *
30413055 * We enter with non-exclusive mmap_sem (to exclude vma changes,
30423056 * but allow concurrent faults), and pte mapped but not yet locked.
3043- * We return with mmap_sem still held, but pte unmapped and unlocked.
3057+ * We return with pte unmapped and unlocked.
3058+ * The mmap_sem may have been released depending on flags and our
3059+ * return value. See filemap_fault() and __lock_page_or_retry().
30443060 */
30453061static int do_nonlinear_fault (struct mm_struct * mm , struct vm_area_struct * vma ,
30463062 unsigned long address , pte_t * page_table , pmd_t * pmd ,
@@ -3172,7 +3188,10 @@ static int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
31723188 *
31733189 * We enter with non-exclusive mmap_sem (to exclude vma changes,
31743190 * but allow concurrent faults), and pte mapped but not yet locked.
3175- * We return with mmap_sem still held, but pte unmapped and unlocked.
3191+ * We return with pte unmapped and unlocked.
3192+ *
3193+ * The mmap_sem may have been released depending on flags and our
3194+ * return value. See filemap_fault() and __lock_page_or_retry().
31763195 */
31773196static int handle_pte_fault (struct mm_struct * mm ,
31783197 struct vm_area_struct * vma , unsigned long address ,
@@ -3232,6 +3251,9 @@ static int handle_pte_fault(struct mm_struct *mm,
32323251
32333252/*
32343253 * By the time we get here, we already hold the mm semaphore
3254+ *
3255+ * The mmap_sem may have been released depending on flags and our
3256+ * return value. See filemap_fault() and __lock_page_or_retry().
32353257 */
32363258static int __handle_mm_fault (struct mm_struct * mm , struct vm_area_struct * vma ,
32373259 unsigned long address , unsigned int flags )
@@ -3313,6 +3335,12 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
33133335 return handle_pte_fault (mm , vma , address , pte , pmd , flags );
33143336}
33153337
3338+ /*
3339+ * By the time we get here, we already hold the mm semaphore
3340+ *
3341+ * The mmap_sem may have been released depending on flags and our
3342+ * return value. See filemap_fault() and __lock_page_or_retry().
3343+ */
33163344int handle_mm_fault (struct mm_struct * mm , struct vm_area_struct * vma ,
33173345 unsigned long address , unsigned int flags )
33183346{
0 commit comments