Skip to content

Commit 515778e

Browse files
xzpeterakpm00
authored andcommitted
mm/uffd: fix warning without PTE_MARKER_UFFD_WP compiled in
When PTE_MARKER_UFFD_WP not configured, it's still possible to reach pte marker code and trigger an warning. Add a few CONFIG_PTE_MARKER_UFFD_WP ifdefs to make sure the code won't be reached when not compiled in. Link: https://lkml.kernel.org/r/YzeR+R6b4bwBlBHh@x1n Fixes: b1f9e87 ("mm/uffd: enable write protection for shmem & hugetlbfs") Signed-off-by: Peter Xu <[email protected]> Reported-by: <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: Brian Geffon <[email protected]> Cc: Edward Liaw <[email protected]> Cc: Liu Shixin <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 28c5609 commit 515778e

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

mm/hugetlb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,6 +5096,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct
50965096
* unmapped and its refcount is dropped, so just clear pte here.
50975097
*/
50985098
if (unlikely(!pte_present(pte))) {
5099+
#ifdef CONFIG_PTE_MARKER_UFFD_WP
50995100
/*
51005101
* If the pte was wr-protected by uffd-wp in any of the
51015102
* swap forms, meanwhile the caller does not want to
@@ -5107,6 +5108,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct
51075108
set_huge_pte_at(mm, address, ptep,
51085109
make_pte_marker(PTE_MARKER_UFFD_WP));
51095110
else
5111+
#endif
51105112
huge_pte_clear(mm, address, ptep, sz);
51115113
spin_unlock(ptl);
51125114
continue;
@@ -5135,11 +5137,13 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct
51355137
tlb_remove_huge_tlb_entry(h, tlb, ptep, address);
51365138
if (huge_pte_dirty(pte))
51375139
set_page_dirty(page);
5140+
#ifdef CONFIG_PTE_MARKER_UFFD_WP
51385141
/* Leave a uffd-wp pte marker if needed */
51395142
if (huge_pte_uffd_wp(pte) &&
51405143
!(zap_flags & ZAP_FLAG_DROP_MARKER))
51415144
set_huge_pte_at(mm, address, ptep,
51425145
make_pte_marker(PTE_MARKER_UFFD_WP));
5146+
#endif
51435147
hugetlb_count_sub(pages_per_huge_page(h), mm);
51445148
page_remove_rmap(page, vma, true);
51455149

mm/memory.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,10 +1393,12 @@ zap_install_uffd_wp_if_needed(struct vm_area_struct *vma,
13931393
unsigned long addr, pte_t *pte,
13941394
struct zap_details *details, pte_t pteval)
13951395
{
1396+
#ifdef CONFIG_PTE_MARKER_UFFD_WP
13961397
if (zap_drop_file_uffd_wp(details))
13971398
return;
13981399

13991400
pte_install_uffd_wp_if_needed(vma, addr, pte, pteval);
1401+
#endif
14001402
}
14011403

14021404
static unsigned long zap_pte_range(struct mmu_gather *tlb,

mm/mprotect.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb,
267267
} else {
268268
/* It must be an none page, or what else?.. */
269269
WARN_ON_ONCE(!pte_none(oldpte));
270+
#ifdef CONFIG_PTE_MARKER_UFFD_WP
270271
if (unlikely(uffd_wp && !vma_is_anonymous(vma))) {
271272
/*
272273
* For file-backed mem, we need to be able to
@@ -278,6 +279,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb,
278279
make_pte_marker(PTE_MARKER_UFFD_WP));
279280
pages++;
280281
}
282+
#endif
281283
}
282284
} while (pte++, addr += PAGE_SIZE, addr != end);
283285
arch_leave_lazy_mmu_mode();

0 commit comments

Comments
 (0)