s390: allow pte_offset_map_lock() to fail
[sfrench/cifs-2.6.git] / arch / s390 / mm / gmap.c
index dc90d1eb0d554f920712929783826cd32843091b..3a2a31a15ea8ae861e264a611ee6872c417769c6 100644 (file)
@@ -2537,7 +2537,12 @@ static inline void thp_split_mm(struct mm_struct *mm)
  * Remove all empty zero pages from the mapping for lazy refaulting
  * - This must be called after mm->context.has_pgste is set, to avoid
  *   future creation of zero pages
- * - This must be called after THP was enabled
+ * - This must be called after THP was disabled.
+ *
+ * mm contracts with s390, that even if mm were to remove a page table,
+ * racing with the loop below and so causing pte_offset_map_lock() to fail,
+ * it will never insert a page table containing empty zero pages once
+ * mm_forbids_zeropage(mm) i.e. mm->context.has_pgste is set.
  */
 static int __zap_zero_pages(pmd_t *pmd, unsigned long start,
                           unsigned long end, struct mm_walk *walk)
@@ -2549,6 +2554,8 @@ static int __zap_zero_pages(pmd_t *pmd, unsigned long start,
                spinlock_t *ptl;
 
                ptep = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
+               if (!ptep)
+                       break;
                if (is_zero_pfn(pte_pfn(*ptep)))
                        ptep_xchg_direct(walk->mm, addr, ptep, __pte(_PAGE_INVALID));
                pte_unmap_unlock(ptep, ptl);