From: Peter Xu Date: Fri, 24 Mar 2023 14:26:20 +0000 (-0400) Subject: mm-hugetlb-fix-uffd-wr-protection-for-cow-optimization-path-v3 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=94d53addd5456af4e0300a0a1130e2ba43138c0a;p=users%2Fjedix%2Flinux-maple.git mm-hugetlb-fix-uffd-wr-protection-for-cow-optimization-path-v3 Link: https://lkml.kernel.org/r/20230324142620.2344140-1-peterx@redhat.com Reported-by: Muhammad Usama Anjum Cc: linux-stable Fixes: 166f3ecc0daf ("mm/hugetlb: hook page faults for uffd write protection") Signed-off-by: Peter Xu Signed-off-by: Andrew Morton --- diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9aea548b665c8..245038a9fe4ea 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5491,11 +5491,11 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, * Never handle CoW for uffd-wp protected pages. It should be only * handled when the uffd-wp protection is removed. * - * Note that only the CoW optimization path can trigger this and - * got skipped, because hugetlb_fault() will always resolve uffd-wp - * bit first. + * Note that only the CoW optimization path (in hugetlb_no_page()) + * can trigger this, because hugetlb_fault() will always resolve + * uffd-wp bit first. */ - if (huge_pte_uffd_wp(pte)) + if (!unshare && huge_pte_uffd_wp(pte)) return 0; /*