]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
secretmem/gup: don't check if page is secretmem without reference
authorMike Rapoport <rppt@linux.ibm.com>
Thu, 22 Apr 2021 06:43:27 +0000 (16:43 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 6 May 2021 01:46:47 +0000 (11:46 +1000)
The check in gup_pte_range() whether a page belongs to a secretmem mapping
is performed before grabbing the page reference.

To avoid potential race move the check after try_grab_compound_head().

Link: https://lkml.kernel.org/r/20210420150049.14031-2-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
mm/gup.c

index c3a17b1890649d94103cae1eebe52f9c992fc6a5..6515f82b0f32bc3f4b85440db31e16dfc0e11016 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2080,13 +2080,15 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
                VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
                page = pte_page(pte);
 
-               if (page_is_secretmem(page))
-                       goto pte_unmap;
-
                head = try_grab_compound_head(page, 1, flags);
                if (!head)
                        goto pte_unmap;
 
+               if (unlikely(page_is_secretmem(page))) {
+                       put_compound_head(head, 1, flags);
+                       goto pte_unmap;
+               }
+
                if (unlikely(pte_val(pte) != pte_val(*ptep))) {
                        put_compound_head(head, 1, flags);
                        goto pte_unmap;