Merge tag 'mm-stable-2022-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / arch / s390 / include / asm / pgtable.h
index c63a05b..f019df1 100644 (file)
@@ -508,7 +508,7 @@ static inline int mm_has_pgste(struct mm_struct *mm)
 static inline int mm_is_protected(struct mm_struct *mm)
 {
 #ifdef CONFIG_PGSTE
-       if (unlikely(atomic_read(&mm->context.is_protected)))
+       if (unlikely(atomic_read(&mm->context.protected_count)))
                return 1;
 #endif
        return 0;
@@ -1165,9 +1165,22 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
        } else {
                res = ptep_xchg_lazy(mm, addr, ptep, __pte(_PAGE_INVALID));
        }
-       /* At this point the reference through the mapping is still present */
-       if (mm_is_protected(mm) && pte_present(res))
-               uv_convert_owned_from_secure(pte_val(res) & PAGE_MASK);
+       /* Nothing to do */
+       if (!mm_is_protected(mm) || !pte_present(res))
+               return res;
+       /*
+        * At this point the reference through the mapping is still present.
+        * The notifier should have destroyed all protected vCPUs at this
+        * point, so the destroy should be successful.
+        */
+       if (full && !uv_destroy_owned_page(pte_val(res) & PAGE_MASK))
+               return res;
+       /*
+        * If something went wrong and the page could not be destroyed, or
+        * if this is not a mm teardown, the slower export is used as
+        * fallback instead.
+        */
+       uv_convert_owned_from_secure(pte_val(res) & PAGE_MASK);
        return res;
 }