From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298388; b=rMcJwlNbkCVXgPOmpdc+Fo6+ST0limucFXWbt+7pEPrZmHbaosQf/VtPxy2roYYTnjiH DF77Q6uulIxNYdZsL08QEt91zxA6jpk5A6/o1c95uWoyRAP/IpfOD2HWYu9K3RanBcQ5D wWO+7R4JdC8s5onq9gbFkyUc0XJVEJ8FpalSOsiiHbLybCXfZ1w4fSuJuZl7dNAcSxTpO Asis8ry2U+BWiSTVc4wa/GsZn6VkVY+jmPmSfcEWOIx75lReZ7r4axrKU57AgRhoUHR/Y sUsBNPjalUEsCwYpWubcAnNLT2hxhdZ0wASe49hOVTdauO/61C1t/foedoQvTjfXJ3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298388; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=JvOyj2MHTqDti7l6gVN4eKh07e2QgEU9uDOpBSJlR7A=; b=WfsnSD9OfWBes70mb+GaxPZlTx+78SSgLbBG9NX3QcoF2roaL9GgSptp9bxSbHT7MeWc dZIGbAAvnuMGFwHVH24vbm6lveVLtbsgis0XZ/ej+PGk0oT34r1uMcH/hM+0FGIS0O3Nl GWXvJWO4oZSA7wAWFKmqL2hwxazRaYV3Wh1AtYtopJAB63j/m4SSRr+vHOdcvxax5VBoO itRsnOF6g6Jl0qZfJkpIOKJErp5zLaspZK2zZKSXmtRkYDiUiBIOpKKUf8mAwyt3bmRAa AKRwrUquLzqjtTcSTJK+OSAgmZG3c/IDxvwMAZCb/VxWytu6gsE3JhXlnMdXWyHvz4Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="I1Ql5g5/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D06A6606A322; Thu, 3 Dec 2026 11:46:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=I1Ql5g5/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B15B1F00898; Thu, 3 Dec 2026 11:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298388; bh=JvOyj2MHTqDti7l6gVN4eKh07e2QgEU9uDOpBSJlR7A=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=I1Ql5g5/p+cmNVCmTXn65E4KJU3OPBQmxBJsQB8RydpZzdd5YTvTFhKbPn1kUb+K4 IHFIRgJiF2yKxCXC73okIKG3gtLn/P9hvXGQwklugcq5ly6mcbyoL7tt4JCWuFbpJa dI2BNMSzJcVl7U6KTml/eAHU/57tawbs6RahLxKpEDHtyr+cwKbXORq+r/zACtRzoY b30LImNOtvAuQHXoJZ0seW+QMLF9ooyoUlN8jqSKJhgL5x/oJBpeO0kW2EoaiHkDHn +tXvWNbhdTZxGmIe8KewjqZgywhsnJpPP+knD/w1oUCZ3vUv95NzUpX4Z4o5oKf/2Z jID2F8zHWrrWg== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 12:37:58 +0100 Subject: [PATCH v2 35/35] mm/hugetlb: resolve protnone faults without a uffd bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-hugetlb_fixes_2-v2-35-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> To: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3028; i=david@kernel.org; h=from:subject:message-id; bh=iUvq3CYkkh0DiH4XV9JlLzK+47otuXwhK/RhX/BkQHo=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFQ2pf9rfs5n6g56VfKdIbINqo17JyVkT25z+JWzzer 1q9Vkm8o5SFQYyDQVZMkSUo+L7By5fraqvd+Jhh5rAygQxh4OIUgImwvGdkuLlHIGVbj17v79uz lxYf4b33pNZQ47+krpHt5t6gYxrn+xgZ5oS8Z/aqaxPTkVfgT8zOfCy0exvbCbmPc3/4Jm5vnVj FBwA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A From: Chris Mason hugetlb_fault() only restores the protection of protnone entries that have the uffd bit set, assuming that accessible VMAs cannot have other protnone entries. If such an entry existed nevertheless, any access to it would result in an endless fault loop. We are not aware of a way to trigger this: paths that drop the uffd bit (fork(), mremap(), unregistering) restore the protection, and remove_migration_pte() only drops the uffd bit for writable migration entries, which cannot be created from protnone entries. Let's be defensive and make any protnone entry in an accessible VMA accessible again, unless it is an RWP fault that has to be reported to user space, like do_numa_page() does for small folios. Signed-off-by: Chris Mason [ david: adjust comments and description ] Signed-off-by: David Hildenbrand (Arm) --- mm/hugetlb.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 92f27dd6c4604..04de7949a3862 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6383,32 +6383,33 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, } /* - * Protnone hugetlb PTEs with the uffd bit are used by - * userfaultfd RWP for access tracking. Plain PROT_NONE (without the - * marker) is not an RWP fault and is not expected on hugetlb (no - * NUMA hinting), so let normal hugetlb fault handling proceed. + * Protnone hugetlb PTEs with the uffd bit are used by userfaultfd RWP + * for access tracking. Without the bit there is nothing to report, so + * just make the PTE accessible. */ - if (pte_protnone(vmf.orig_pte) && vma_is_accessible(vma) && - huge_pte_uffd(vmf.orig_pte)) { + if (pte_protnone(vmf.orig_pte) && vma_is_accessible(vma)) { spinlock_t *ptl; pte_t pte; /* Sync: drop hugetlb locks before blocking in handle_userfault() */ - if (userfaultfd_rwp(vma) && !userfaultfd_rwp_async(vma)) + if (huge_pte_uffd(vmf.orig_pte) && userfaultfd_rwp(vma) && + !userfaultfd_rwp_async(vma)) return hugetlb_handle_userfault(&vmf, mapping, VM_UFFD_RWP); ptl = huge_pte_lock(h, mm, vmf.pte); pte = huge_ptep_get(mm, vmf.address, vmf.pte); - /* - * TODO: fix all cases where uffd PTE bits remain in VMAs that - * are no longer registered with uffd. - */ - if (pte_protnone(pte) && huge_pte_uffd(pte)) { + if (pte_same(pte, vmf.orig_pte)) { unsigned int shift = huge_page_shift(h); pte = huge_pte_modify(pte, vma->vm_page_prot); pte = arch_make_huge_pte(pte, shift, vma->vm_flags); - /* huge_pte_modify() preserves _PAGE_UFFD; drop it on resolution */ + /* + * huge_pte_modify() preserves _PAGE_UFFD; drop it on + * resolution. + * + * TODO: fix all cases where uffd PTE bits remain in VMAs + * that are no longer registered with uffd. + */ pte = huge_pte_clear_uffd(pte); pte = pte_mkyoung(pte); /* -- 2.56.1