Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kiryl Shutsemau" <kirill@shutemov.name>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v9 10/15] mm/userfaultfd: add RWP fault delivery and expose UFFDIO_REGISTER_MODE_RWP
Date: Mon, 06 Jul 2026 09:22:45 +0000	[thread overview]
Message-ID: <20260706092246.044C21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706084805.8400-11-kirill@shutemov.name>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Infinite page fault loop (livelock) on hugetlb VMAs containing stale RWP or WP markers after UFFDIO_UNREGISTER.
--

commit 53f1ffbd6e1b1ae6560601d75e0a8a5ad93e1aa3
Author: Kiryl Shutsemau (Meta) <kas@kernel.org>

mm/userfaultfd: add RWP fault delivery and expose UFFDIO_REGISTER_MODE_RWP

This commit adds read-write protection (RWP) fault tracking to userfaultfd.
It introduces the UFFDIO_REGISTER_MODE_RWP flag and handles RWP faults at the
PTE, PMD, and hugetlb levels by delivering UFFD_PAGEFAULT_FLAG_RWP messages.

> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 4d0b6d7d9842f..f0ce2e9d4ba2d 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -6063,6 +6063,17 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
>  		goto out_mutex;
>  	}
>  
> +	/*
> +	 * 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.
> +	 */
> +	if (pte_protnone(vmf.orig_pte) && vma_is_accessible(vma) &&
> +	    userfaultfd_rwp(vma) && huge_pte_uffd(vmf.orig_pte)) {

[Severity: High]
Can this code cause an infinite page fault loop if the VMA is unregistered?

If an unprivileged user registers a hugetlb VMA with UFFDIO_REGISTER_MODE_RWP,
allows PTE markers to be placed, and then unregisters it via UFFDIO_UNREGISTER,
the PTE markers are not cleared. Subsequent memory accesses will trigger a page
fault, but since userfaultfd_rwp(vma) evaluates to false, this check is
bypassed.

For read faults, hugetlb_fault() falls through, marks the PROT_NONE PTE as
young, and returns 0 without restoring accessibility. Because the fault handler
continuously returns 0 without making the PTE accessible, the CPU retries the
instruction endlessly, resulting in a local denial of service.

This is a pre-existing issue for write faults via WP, but does this patch
introduce the same livelock for read faults via RWP? For WP, write faults skip
the UFFD_WP check and hugetlb_wp() catches the stale marker:

mm/hugetlb.c:hugetlb_wp() {
...
	if (!unshare && huge_pte_uffd(pte))
		return 0;
...
}

Because it returns 0 without upgrading the PTE to writable, the CPU retries
the instruction endlessly. Can a similar infinite loop occur here for RWP?

> +		return hugetlb_handle_userfault(&vmf, mapping, VM_UFFD_RWP);
> +	}
> +
>  	/*
>  	 * If we are going to COW/unshare the mapping later, we examine the
>  	 * pending reservations for this page now. This will ensure that any

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260706084805.8400-1-kirill@shutemov.name?part=10

  reply	other threads:[~2026-07-06  9:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06  8:47 [PATCH v9 00/15] userfaultfd: working set tracking for VM guest memory Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 01/15] mm: decouple protnone helpers from CONFIG_NUMA_BALANCING Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 02/15] mm: rename uffd-wp PTE bit macros to uffd Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 03/15] mm: rename uffd-wp PTE accessors " Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 04/15] userfaultfd: test uffd VMA flags through the vma_flags_t API Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 05/15] mm: add VM_UFFD_RWP VMA flag Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 06/15] mm: add MM_CP_UFFD_RWP change_protection() flag Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 07/15] mm: preserve RWP marker across PTE rewrites Kiryl Shutsemau
2026-07-06  9:20   ` sashiko-bot
2026-07-06  8:47 ` [PATCH v9 08/15] mm: handle VM_UFFD_RWP in khugepaged, rmap, and GUP Kiryl Shutsemau
2026-07-06  8:47 ` [PATCH v9 09/15] userfaultfd: add UFFDIO_REGISTER_MODE_RWP and UFFDIO_RWPROTECT plumbing Kiryl Shutsemau
2026-07-06  9:06   ` sashiko-bot
2026-07-06  8:47 ` [PATCH v9 10/15] mm/userfaultfd: add RWP fault delivery and expose UFFDIO_REGISTER_MODE_RWP Kiryl Shutsemau
2026-07-06  9:22   ` sashiko-bot [this message]
2026-07-06  8:48 ` [PATCH v9 11/15] mm/pagemap: add PAGE_IS_ACCESSED for RWP tracking Kiryl Shutsemau
2026-07-06  9:15   ` sashiko-bot
2026-07-06 12:57   ` Usama Arif
2026-07-06 13:52     ` Kiryl Shutsemau
2026-07-06  8:48 ` [PATCH v9 12/15] userfaultfd: add UFFD_FEATURE_RWP_ASYNC for async fault resolution Kiryl Shutsemau
2026-07-06  8:48 ` [PATCH v9 13/15] userfaultfd: add UFFDIO_SET_MODE for runtime sync/async toggle Kiryl Shutsemau
2026-07-06  9:20   ` sashiko-bot
2026-07-06  8:48 ` [PATCH v9 14/15] selftests/mm: add userfaultfd RWP tests Kiryl Shutsemau
2026-07-06  9:19   ` sashiko-bot
2026-07-06 10:49   ` [PATCH v9.1 " Kiryl Shutsemau
2026-07-06  8:48 ` [PATCH v9 15/15] Documentation/userfaultfd: document RWP working set tracking Kiryl Shutsemau
2026-07-06 10:56 ` Addressing Sashiko AI review Kiryl Shutsemau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260706092246.044C21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kirill@shutemov.name \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox